(this["webpackJsonplama-cleaner"]=this["webpackJsonplama-cleaner"]||[]).push([[0],{48:function(e,t,n){},51:function(e,t,n){"use strict";n.r(t);var a=n(0),c=n.n(a),i=n(15),r=n.n(i),o=(n(48),n(10)),s=n(2),l=n(55),u=n(8),j=n.n(u),d=n(14);var b=n(3),h=n(16),f=n(21),p=n(1),v=function(e){var t=e.width,n=e.value,c=e.chevronDirection,i=e.options,r=e.autoFocusAfterClose,o=e.onChange,s=Object(a.useRef)(null);return Object(p.jsxs)(f.f,{value:n,onValueChange:o,onOpenChange:function(e){e||r||window.setTimeout((function(){var e;null===s||void 0===s||null===(e=s.current)||void 0===e||e.blur()}),100)},children:[Object(p.jsxs)(f.g,{className:"select-trigger",style:{width:t},ref:s,children:[Object(p.jsx)(f.h,{}),Object(p.jsx)(f.b,{children:"up"===c?Object(p.jsx)(h.e,{}):Object(p.jsx)(h.d,{})})]}),Object(p.jsx)(f.a,{className:"select-content",children:Object(p.jsx)(f.i,{className:"select-viewport",children:i.map((function(e){return Object(p.jsxs)(f.c,{value:e,className:"select-item",children:[Object(p.jsx)(f.e,{children:e}),Object(p.jsx)(f.d,{className:"select-item-indicator",children:Object(p.jsx)(h.c,{})})]},e)}))})})]})};v.defaultProps={chevronDirection:"down",autoFocusAfterClose:!0};var O=v,g=n(4),x=["value","onValue"],m=c.a.forwardRef((function(e,t){var n=e.value,a=e.onValue,c=Object(g.a)(e,x);return Object(p.jsx)("input",Object(b.a)(Object(b.a)({value:n,onInput:function(e){var t=e.target.value.replace(/\D/g,"");null===a||void 0===a||a(t)},className:"number-input"},c),{},{ref:t,type:"text"}))}));var w=function(e){var t=e.title,n=e.desc,a=e.input,c=e.optionDesc,i=e.className;return Object(p.jsxs)("div",{className:"setting-block ".concat(i),children:[Object(p.jsxs)("div",{className:"setting-block-content",children:[Object(p.jsxs)("div",{className:"setting-block-content-title",children:[Object(p.jsx)("span",{children:t}),n&&Object(p.jsx)("span",{className:"setting-block-desc",children:n})]}),a]}),c&&Object(p.jsx)("div",{className:"option-desc",children:c})]})};var y,k=function(e){var t=e.title,n=e.value,a=e.suffix,c=e.onValue;return Object(p.jsx)(w,{className:"sub-setting-block",title:t,input:Object(p.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"8px"},children:[Object(p.jsx)(m,{style:{width:"80px"},value:"".concat(n),onValue:c}),a&&Object(p.jsx)("span",{children:a})]})})};!function(e){e.ORIGINAL="Original",e.RESIZE="Resize",e.CROP="Crop"}(y||(y={}));var S,C=function(){var e=Object(o.c)(D),t=Object(s.a)(e,2),n=t[0],a=t[1],c=function(e){a((function(t){return Object(b.a)(Object(b.a)({},t),{},{hdStrategy:e})}))},i=function(e){var t=0===e.length?0:parseInt(e,10);a((function(e){return Object(b.a)(Object(b.a)({},e),{},{hdStrategyResizeLimit:t})}))},r=function(e){var t=0===e.length?0:parseInt(e,10);a((function(e){return Object(b.a)(Object(b.a)({},e),{},{hdStrategyCropTrigerSize:t})}))},l=function(e){var t=0===e.length?0:parseInt(e,10);a((function(e){return Object(b.a)(Object(b.a)({},e),{},{hdStrategyCropMargin:t})}))},u=function(){return Object(p.jsxs)("div",{children:["Use the original resolution of the picture, suitable for picture size below 2K. Try"," ",Object(p.jsx)("div",{tabIndex:0,role:"button",className:"inline-tip",onClick:function(){return c(y.RESIZE)},children:"Resize Strategy"})," ","if you do not get good results on high resolution images."]})};return Object(p.jsx)(w,{className:"hd-setting-block",title:"High Resolution Strategy",input:Object(p.jsx)(O,{width:80,value:n.hdStrategy,options:Object.values(y),onChange:function(e){return c(e)}}),optionDesc:function(){switch(n.hdStrategy){case y.ORIGINAL:return u();case y.CROP:return Object(p.jsxs)("div",{children:[Object(p.jsx)("div",{children:"Crop masking area from the original image to do inpainting, and paste the result back. Mainly for performance and memory reasons on high resolution image."}),Object(p.jsx)(k,{title:"Trigger size",value:"".concat(n.hdStrategyCropTrigerSize),suffix:"pixel",onValue:r}),Object(p.jsx)(k,{title:"Crop margin",value:"".concat(n.hdStrategyCropMargin),suffix:"pixel",onValue:l})]});case y.RESIZE:return Object(p.jsxs)("div",{children:[Object(p.jsx)("div",{children:"Resize the longer side of the image to a specific size(keep ratio), then do inpainting on the resized image."}),Object(p.jsx)(k,{title:"Size limit",value:"".concat(n.hdStrategyResizeLimit),suffix:"pixel",onValue:i})]});default:return u()}}()})};!function(e){e.LAMA="lama",e.LDM="ldm"}(S||(S={}));var M,L=function(){var e=Object(o.c)(D),t=Object(s.a)(e,2),n=t[0],a=t[1],c=function(e,t,n){return Object(p.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[Object(p.jsx)("a",{className:"model-desc-link",href:t,target:"_blank",rel:"noreferrer noopener",children:e}),Object(p.jsx)("a",{className:"model-desc-link",href:n,target:"_blank",rel:"noreferrer noopener",children:n})]})};return Object(p.jsx)(w,{className:"model-setting-block",title:"Inpainting Model",input:Object(p.jsx)(O,{width:80,value:n.model,options:Object.values(S),onChange:function(e){return t=e,void a((function(e){return Object(b.a)(Object(b.a)({},e),{},{model:t})}));var t}}),optionDesc:function(){switch(n.model){case S.LAMA:return c("Resolution-robust Large Mask Inpainting with Fourier Convolutions","https://arxiv.org/abs/2109.07161","https://github.com/saic-mdal/lama");case S.LDM:return Object(p.jsxs)("div",{children:[c("High-Resolution Image Synthesis with Latent Diffusion Models","https://arxiv.org/abs/2112.10752","https://github.com/CompVis/latent-diffusion"),Object(p.jsx)(k,{title:"Steps",value:"".concat(n.ldmSteps),onValue:function(e){var t=0===e.length?0:parseInt(e,10);a((function(e){return Object(b.a)(Object(b.a)({},e),{},{ldmSteps:t})}))}})]});default:return Object(p.jsx)(p.Fragment,{})}}()})},N=Object(o.b)({key:"fileState",default:void 0}),z=Object(o.b)({key:"toastState",default:{open:!1,desc:"",state:"default",duration:3e3}}),I=Object(o.b)({key:"shortcutsState",default:!1}),E={show:!1,runInpaintingManually:!1,model:S.LAMA,ldmSteps:50,hdStrategy:y.RESIZE,hdStrategyResizeLimit:2048,hdStrategyCropTrigerSize:2048,hdStrategyCropMargin:128},D=Object(o.b)({key:"settingsState",default:E,effects:[(M="settingsState",function(e){var t=e.setSelf,n=e.onSet,a=localStorage.getItem(M);if(null!=a){var c=JSON.parse(a);c.show=!1,t(c)}n((function(e,t,n){return n?localStorage.removeItem(M):localStorage.setItem(M,JSON.stringify(e))}))})]}),R=n(9),T=function(){var e=Object(a.useState)(window.innerWidth),t=Object(s.a)(e,2),n=t[0],c=t[1],i=Object(a.useCallback)((function(){c(window.innerWidth)}),[]);return Object(a.useEffect)((function(){return window.addEventListener("resize",i),function(){window.removeEventListener("resize",i)}})),n<768?"mobile":n>=768&&n<1224?"tablet":n>=1224?"desktop":void 0};function A(e){var t=e.onSelection,n=Object(a.useState)(!1),c=Object(s.a)(n,2),i=c[0],r=c[1],o=Object(a.useState)("file-upload-".concat(Math.random().toString())),l=Object(s.a)(o,1)[0],u=T();function b(e){if(e&&e.type.match("image.*"))try{if(e.size>20971520)throw new Error("file too large");t(e)}catch(n){alert("error: ".concat(n.message))}}function h(e){return f.apply(this,arguments)}function f(){return(f=Object(d.a)(j.a.mark((function e(t){return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){t.file((function(t){return e(t)}))})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function v(e){return O.apply(this,arguments)}function O(){return(O=Object(d.a)(j.a.mark((function e(t){var n,a,c,i,r;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=[],a=[],c=0;c0)){e.next=23;break}if(!(null===(i=a.shift())||void 0===i?void 0:i.isFile)){e.next=12;break}return e.next=8,h(i);case 8:r=e.sent,n.push(r),e.next=21;break;case 12:if(!(null===i||void 0===i?void 0:i.isDirectory)){e.next=21;break}return e.t0=a.push,e.t1=a,e.t2=R.a,e.next=18,g(i.createReader());case 18:e.t3=e.sent,e.t4=(0,e.t2)(e.t3),e.t0.apply.call(e.t0,e.t1,e.t4);case 21:e.next=3;break;case 23:return e.abrupt("return",n);case 24:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function g(e){return x.apply(this,arguments)}function x(){return(x=Object(d.a)(j.a.mark((function e(t){var n,a;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=[],e.next=3,m(t);case 3:a=e.sent;case 4:if(!(a.length>0)){e.next=11;break}return n.push.apply(n,Object(R.a)(a)),e.next=8,m(t);case 8:a=e.sent,e.next=4;break;case 11:return e.abrupt("return",n);case 12:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function m(e){return w.apply(this,arguments)}function w(){return(w=Object(d.a)(j.a.mark((function e(t){return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,n){t.readEntries(e,n)})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function y(){return(y=Object(d.a)(j.a.mark((function e(t){var n;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.preventDefault(),e.next=3,v(t.dataTransfer.items);case 3:n=e.sent,r(!1),b(n[0]);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return Object(p.jsx)("label",{htmlFor:l,className:"file-select-label",children:Object(p.jsxs)("div",{className:["file-select-container",i?"file-select-label-hover":""].join(" "),onDrop:function(e){return y.apply(this,arguments)},onDragOver:function(e){e.stopPropagation(),e.preventDefault(),r(!0)},onDragLeave:function(){return r(!1)},children:[Object(p.jsx)("input",{id:l,name:l,type:"file",onChange:function(e){var t,n=null===(t=e.currentTarget.files)||void 0===t?void 0:t[0];n&&b(n)},accept:"image/png, image/jpeg"}),Object(p.jsx)("p",{className:"file-select-message",children:"desktop"===u?"Click here or drag an image file":"Tap here to load your picture"})]})})}var Z=function(){var e=Object(o.e)(N);return Object(p.jsxs)("div",{className:"landing-page",children:[Object(p.jsxs)("h1",{children:["Image inpainting powered by \ud83e\udd99",Object(p.jsx)("a",{href:"https://github.com/saic-mdal/lama",children:"LaMa"})]}),Object(p.jsx)("div",{className:"landing-file-selector",children:Object(p.jsx)(A,{onSelection:function(){var t=Object(d.a)(j.a.mark((function t(n){return j.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e(n);case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()})})]})},P=Object(o.b)({key:"themeState",default:"light"}),H=function(){var e=Object(o.c)(P),t=Object(s.a)(e,2),n=t[0],c=t[1];Object(a.useEffect)((function(){window.matchMedia("(prefers-color-scheme: dark)").matches?c("dark"):c("light")}),[c]);return Object(p.jsx)("div",{className:"theme-toggle-ui",children:Object(p.jsx)("div",{className:"theme-btn",onClick:function(){c("light"===n?"dark":"light")},role:"button",tabIndex:0,"aria-hidden":"true",children:"light"===n?Object(p.jsx)(h.i,{}):Object(p.jsx)(h.j,{style:{color:"#ffcc00"}})})})},V=n(38),F=n(54),W=n(40);function U(e){for(var t=e.split(",")[0].split(":")[1].split(";")[0],n=atob(e.split(",")[1]),a=[],c=0;ct){var c=Math.ceil(t*a);return"".concat(e,"x").concat(c)}var i=Math.ceil(n*a);return"".concat(i,"x").concat(e)}),[n,t,u]),d=Object(a.useCallback)((function(){for(var e=[],t=0;tt?(l(a[0]),c(parseInt(a[0],10))):(l(a[1]),c(parseInt(a[1],10)))},chevronDirection:"up"})}var ne="#ffcc00bb";function ae(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ne;e.strokeStyle=n,e.lineCap="round",e.lineJoin="round",t.forEach((function(t){(null===t||void 0===t?void 0:t.pts.length)&&t.size&&(e.lineWidth=t.size,e.beginPath(),e.moveTo(t.pts[0].x,t.pts[0].y),t.pts.forEach((function(t){return e.lineTo(t.x,t.y)})),e.stroke())}))}function ce(e){var t=e.nativeEvent;return{x:t.offsetX,y:t.offsetY}}function ie(e){var t=e.file,n=Object(o.d)(D),c=Object(a.useState)(40),i=Object(s.a)(c,2),r=i[0],u=i[1],b=function(e){var t=Object(a.useState)(new Image),n=Object(s.a)(t,1)[0],c=Object(a.useState)(!1),i=Object(s.a)(c,2),r=i[0],o=i[1];return Object(a.useEffect)((function(){return n.onload=function(){o(!0)},o(!1),n.src=URL.createObjectURL(e),function(){n.onload=null}}),[e,n]),[n,r]}(t),f=Object(s.a)(b,2),v=f[0],O=f[1],g=Object(a.useState)([]),x=Object(s.a)(g,2),m=x[0],w=x[1],y=Object(a.useState)(),k=Object(s.a)(y,2),S=k[0],C=k[1],M=Object(a.useState)((function(){return document.createElement("canvas")})),L=Object(s.a)(M,1)[0],N=Object(a.useState)([]),z=Object(s.a)(N,2),I=z[0],E=z[1],T=Object(a.useState)([]),A=Object(s.a)(T,2),Z=A[0],P=A[1],H=Object(a.useState)({x:-1,y:-1}),U=Object(s.a)(H,2),J=U[0],_=J.x,Y=J.y,X=U[1],$=Object(a.useState)(!1),ee=Object(s.a)($,2),ne=ee[0],ie=ee[1],re=Object(a.useState)(!1),oe=Object(s.a)(re,2),se=oe[0],le=oe[1],ue=Object(a.useState)(!1),je=Object(s.a)(ue,2),de=je[0],be=je[1],he=Object(a.useState)(!1),fe=Object(s.a)(he,2),pe=fe[0],ve=fe[1],Oe=Object(a.useState)(!1),ge=Object(s.a)(Oe,2),xe=ge[0],me=ge[1],we=Object(a.useState)(1),ye=Object(s.a)(we,2),ke=ye[0],Se=ye[1],Ce=Object(a.useState)(!1),Me=Object(s.a)(Ce,2),Le=Me[0],Ne=Me[1],ze=Object(a.useState)(1),Ie=Object(s.a)(ze,2),Ee=Ie[0],De=Ie[1],Re=Object(a.useState)(1080),Te=Object(s.a)(Re,2),Ae=Te[0],Ze=Te[1],Pe=Object(F.a)(),He=Pe.width/2,Ve=Pe.height/2,Fe=Object(a.useRef)(),We=Object(a.useState)(!1),Ue=Object(s.a)(We,2),Be=Ue[0],Ge=Ue[1],Je=Object(a.useState)(!1),Ke=Object(s.a)(Je,2),_e=Ke[0],Ye=Ke[1],Xe=Object(a.useState)(!1),$e=Object(s.a)(Xe,2),Qe=$e[0],qe=$e[1],et=Object(a.useState)(0),tt=Object(s.a)(et,2),nt=tt[0],at=tt[1],ct=Object(a.useCallback)((function(e,t){S&&(S.clearRect(0,0,S.canvas.width,S.canvas.height),S.drawImage(e,0,0,v.naturalWidth,v.naturalHeight),ae(S,t))}),[S,v]),it=function(e){if(!(null===S||void 0===S?void 0:S.canvas.width)||!(null===S||void 0===S?void 0:S.canvas.height))throw new Error("canvas has invalid size");L.width=null===S||void 0===S?void 0:S.canvas.width,L.height=null===S||void 0===S?void 0:S.canvas.height;var t=L.getContext("2d");if(!t)throw new Error("could not retrieve mask canvas");e.forEach((function(e){ae(t,e,"white")}))},rt=function(){var e=Object(d.a)(j.a.mark((function e(){var a,c,i,r;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(ot()){e.next=2;break}return e.abrupt("return");case 2:return a=[].concat(Object(R.a)(I),[Z]),E(a),P([]),Ye(!1),me(!0),it(a),e.prev=8,e.next=11,K(t,L.toDataURL(),n,Ae.toString());case 11:if(c=e.sent){e.next=14;break}throw new Error("empty response");case 14:return i=new Image,e.next=17,B(i,c);case 17:r=[].concat(Object(R.a)(m),[i]),w(r),ct(i,[]),e.next=25;break;case 22:e.prev=22,e.t0=e.catch(8),alert(e.t0.message?e.t0.message:e.t0.toString());case 25:me(!1);case 26:case"end":return e.stop()}}),e,null,[[8,22]])})));return function(){return e.apply(this,arguments)}}(),ot=function(){return 0!==Z.length},st=function(){return 0!==m.length},lt=Object(a.useCallback)((function(e){0===m.length?ct(v,e):ct(m[m.length-1],e)}),[v,m,ct]),ut=function(e){return"Control"===e.key||"Meta"===e.key};Object(W.a)(ut,(function(){Qe&&(xe||(qe(!1),n.runInpaintingManually||rt()))}),{event:"keyup"},[xe,Qe,ot]),Object(W.a)(ut,(function(){xe||qe(!0)}),{event:"keydown"},[xe]),Object(a.useEffect)((function(){if(O){var e=Pe.width/v.naturalWidth,t=(Pe.height-200)/v.naturalHeight,n=1;(e<1||t<1)&&(n=Math.min(e,t)),De(n),Se(n);var a,c=Math.max(v.width,v.height);if(Ze(c),(null===S||void 0===S?void 0:S.canvas)&&(S.canvas.width=v.naturalWidth,S.canvas.height=v.naturalHeight,lt([])),!Be)null===(a=Fe.current)||void 0===a||a.centerView(n,1),Ge(!0)}}),[null===S||void 0===S?void 0:S.canvas,Fe,v,O,Pe,Be,lt]);var jt=Object(a.useCallback)((function(){if(Ee&&v&&Pe){var e=Fe.current;if(!e)throw new Error("no viewport");var t=(Pe.width-v.width*Ee)/2,n=(Pe.height-v.height*Ee)/2;e.setTransform(t,n,Ee,200,"easeOutQuad"),e.state.scale=Ee,Se(Ee),Ne(!1)}}),[Fe,Ee,v,Pe]);Object(a.useEffect)((function(){return window.addEventListener("resize",(function(){jt()})),function(){window.removeEventListener("resize",(function(){jt()}))}}),[Pe,jt]);Object(W.a)("Escape",(function(){xe||(_e||Qe?(Ye(!1),P([]),lt([])):jt())}),{event:"keydown"},[_e,xe,Qe,jt,lt]);var dt=Object(a.useCallback)((function(){if(0!==Z.length){var e=Z.slice(0,Z.length-1);P(e),lt(e)}}),[Z,lt]),bt=Object(a.useCallback)((function(){if(m.length){var e=I.slice(0,I.length-1);E(e),P([]),Ye(!1);var t=m.slice(0,m.length-1);w(t),0===t.length?ct(v,[]):ct(t[t.length-1],[])}}),[ct,m,I,v]),ht=function(){n.runInpaintingManually&&0!==Z.length?dt():bt()};Object(W.a)((function(e){var t=(e.metaKey||e.ctrlKey)&&"z"===e.key;return"Tab"===e.key&&e.preventDefault(),!!t&&(e.preventDefault(),!0)}),ht,void 0,[dt,bt]);Object(l.a)("Tab",(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),st()&&ve((function(){return window.setTimeout((function(){at(100)}),10),!0}))}),(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),st()&&(at(0),window.setTimeout((function(){ve(!1)}),350))}));var ft=function(e){e===ne||de||ie(e)},pt=Object(a.useCallback)((function(){return de?"grab":ne?"none":void 0}),[ne,de]);Object(l.a)("[",(function(){u((function(e){return e>10?e-10:e<=10&&e>0?e-5:e}))})),Object(l.a)("]",(function(){u((function(e){return e+10}))})),Object(l.a)("R",(function(){n.runInpaintingManually&&ot()&&rt()})),Object(l.a)(" ",(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),ie(!1),be(!0)}),(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),ie(!0),be(!1)}));var vt=function(e,t){var n=function(){var e,t,n=Ee;return void 0!==(null===(e=Fe.current)||void 0===e?void 0:e.state.scale)&&(n=null===(t=Fe.current)||void 0===t?void 0:t.state.scale),n}();return{width:"".concat(r*n,"px"),height:"".concat(r*n,"px"),left:"".concat(e,"px"),top:"".concat(t,"px"),transform:"translate(-50%, -50%)"}};return Object(p.jsxs)("div",{className:"editor-container","aria-hidden":"true",onMouseMove:function(e){var t=e.nativeEvent;X({x:t.pageX,y:t.pageY})},onMouseUp:function(e){(G(e)&&be(!1),de)||v.src&&(null===S||void 0===S?void 0:S.canvas)&&(xe||_e&&(Qe||n.runInpaintingManually?Ye(!1):rt()))},children:[Object(p.jsx)(V.b,{ref:function(e){e&&(Fe.current=e)},panning:{disabled:!de,velocityDisabled:!0},wheel:{step:.05},centerZoomedOut:!0,alignmentAnimation:{disabled:!0},limitToBounds:!1,doubleClick:{disabled:!0},initialScale:Ee,minScale:Ee,onPanning:function(e){Le||Ne(!0)},onZoom:function(e){Se(e.state.scale)},children:Object(p.jsx)(V.a,{contentClass:xe?"editor-canvas-loading":"",contentStyle:{visibility:Be?"visible":"hidden"},children:Object(p.jsxs)("div",{className:"editor-canvas-container",children:[Object(p.jsx)("canvas",{className:"editor-canvas",style:{cursor:pt(),clipPath:"inset(0 ".concat(nt,"% 0 0)"),transition:"clip-path 350ms ease-in-out"},onContextMenu:function(e){e.preventDefault()},onMouseOver:function(){ft(!0),le(!1)},onFocus:function(){return ft(!0)},onMouseLeave:function(){return ft(!1)},onMouseDown:function(e){if(!de&&(v.src&&(null===S||void 0===S?void 0:S.canvas)&&!xe&&!function(e){return 2===e.nativeEvent.button}(e)))if(G(e))be(!0);else{Ye(!0);var t=[];(Qe||n.runInpaintingManually)&&(t=Object(R.a)(Z)),t.push({size:r,pts:[ce(e)]}),P(t),lt(t)}},onMouseMove:function(e){if(!de&&_e&&0!==Z.length){var t=Object(R.a)(Z);t[t.length-1].pts.push(ce(e)),P(t),lt(t)}},ref:function(e){if(e&&!S){var t=e.getContext("2d");t&&C(t)}}}),Object(p.jsxs)("div",{className:"original-image-container",style:{width:"".concat(v.naturalWidth,"px"),height:"".concat(v.naturalHeight,"px")},children:[pe&&Object(p.jsx)("div",{className:"editor-slider",style:{marginRight:"".concat(nt,"%")}}),Object(p.jsx)("img",{className:"original-image",src:v.src,alt:"original",style:{width:"".concat(v.naturalWidth,"px"),height:"".concat(v.naturalHeight,"px")}})]})]})})}),ne&&!xe&&!de&&Object(p.jsx)("div",{className:"brush-shape",style:vt(_,Y)}),se&&Object(p.jsx)("div",{className:"brush-shape",style:vt(He,Ve)}),Object(p.jsxs)("div",{className:"editor-toolkit-panel",children:[Object(p.jsx)(te,{onChange:function(e){Ze(e)},originalWidth:v.naturalWidth,originalHeight:v.naturalHeight}),Object(p.jsx)(q,{label:"Brush",min:10,max:150,value:r,onChange:function(e){u(e),se||(le(!0),window.setTimeout((function(){le(!1)}),1e4))},onClick:function(){return le(!1)}}),Object(p.jsxs)("div",{className:"editor-toolkit-btns",children:[Object(p.jsx)(Q,{toolTip:"Reset Zoom & Pan",tooltipPosition:"top",icon:Object(p.jsx)(h.b,{}),disabled:ke===Ee&&!1===Le,onClick:jt}),Object(p.jsx)(Q,{toolTip:"Undo",tooltipPosition:"top",icon:Object(p.jsx)("svg",{width:"19",height:"9",viewBox:"0 0 19 9",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(p.jsx)("path",{d:"M2 1C2 0.447715 1.55228 0 1 0C0.447715 0 0 0.447715 0 1H2ZM1 8H0V9H1V8ZM8 9C8.55228 9 9 8.55229 9 8C9 7.44771 8.55228 7 8 7V9ZM16.5963 7.42809C16.8327 7.92721 17.429 8.14016 17.9281 7.90374C18.4272 7.66731 18.6402 7.07103 18.4037 6.57191L16.5963 7.42809ZM16.9468 5.83205L17.8505 5.40396L16.9468 5.83205ZM0 1V8H2V1H0ZM1 9H8V7H1V9ZM1.66896 8.74329L6.66896 4.24329L5.33104 2.75671L0.331035 7.25671L1.66896 8.74329ZM16.043 6.26014L16.5963 7.42809L18.4037 6.57191L17.8505 5.40396L16.043 6.26014ZM6.65079 4.25926C9.67554 1.66661 14.3376 2.65979 16.043 6.26014L17.8505 5.40396C15.5805 0.61182 9.37523 -0.710131 5.34921 2.74074L6.65079 4.25926Z",fill:"currentColor"})}),onClick:ht,disabled:function(){if(m.length>0)return!1;if(n.runInpaintingManually){if(0===Z.length)return!0}else if(0===m.length)return!0;return!1}()}),Object(p.jsx)(Q,{toolTip:"Show Original",tooltipPosition:"top",icon:Object(p.jsx)(h.h,{}),className:pe?"eyeicon-active":"",onDown:function(e){e.preventDefault(),ve((function(){return window.setTimeout((function(){at(100)}),10),!0}))},onUp:function(){at(0),window.setTimeout((function(){ve(!1)}),350)},disabled:0===m.length}),Object(p.jsx)(Q,{toolTip:"Save Image",tooltipPosition:"top",icon:Object(p.jsx)(h.f,{}),disabled:!m.length,onClick:function(){var e=t.name.replace(/(\.[\w\d_-]+)$/i,"_cleanup$1");!function(e,t){var n=document.createElement("a");n.href=e,n.download=t,n.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window})),setTimeout((function(){n.remove()}),100)}(m[m.length-1].currentSrc,e)}}),n.runInpaintingManually&&Object(p.jsx)(Q,{toolTip:"Run Inpainting",tooltipPosition:"top",icon:Object(p.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(p.jsx)("path",{d:"M2 13L1.34921 12.2407C1.16773 12.3963 1.04797 12.6117 1.01163 12.8479L2 13ZM22.5 4L23.49 4.14142C23.5309 3.85444 23.4454 3.5638 23.2555 3.3448C23.0655 3.1258 22.7899 3 22.5 3V4ZM12.5 4V3C12.2613 3 12.0305 3.08539 11.8492 3.24074L12.5 4ZM1 19.5L0.0116283 19.3479C-0.0327373 19.6363 0.051055 19.9297 0.241035 20.1511C0.431014 20.3726 0.708231 20.5 1 20.5V19.5ZM11.5 19.5V20.5C11.7373 20.5 11.9668 20.4156 12.1476 20.2619L11.5 19.5ZM21.5 11L22.1476 11.7619C22.3337 11.6038 22.4554 11.3831 22.49 11.1414L21.5 11ZM2 14H12.5V12H2V14ZM13.169 13.7433L23.169 4.74329L21.831 3.25671L11.831 12.2567L13.169 13.7433ZM22.5 3H12.5V5H22.5V3ZM11.8492 3.24074L1.34921 12.2407L2.65079 13.7593L13.1508 4.75926L11.8492 3.24074ZM1.01163 12.8479L0.0116283 19.3479L1.98837 19.6521L2.98837 13.1521L1.01163 12.8479ZM1 20.5H11.5V18.5H1V20.5ZM12.4884 19.6521L13.4884 13.1521L11.5116 12.8479L10.5116 19.3479L12.4884 19.6521ZM21.51 3.85858L20.51 10.8586L22.49 11.1414L23.49 4.14142L21.51 3.85858ZM20.8524 10.2381L10.8524 18.7381L12.1476 20.2619L22.1476 11.7619L20.8524 10.2381Z",fill:"currentColor"})}),disabled:!ot()||xe,onClick:function(){!xe&&ot()&&rt()}})]})]})]})}var re=n(25),oe=c.a.forwardRef((function(e,t){var n=e.show,a=e.children,c=e.onClose,i=e.className,r=e.title;return Object(p.jsx)(re.d,{open:n,onOpenChange:function(e){e||null===c||void 0===c||c()},children:Object(p.jsxs)(re.c,{children:[Object(p.jsx)(re.b,{className:"modal-mask"}),Object(p.jsxs)(re.a,{ref:t,className:"modal ".concat(i),children:[Object(p.jsxs)("div",{className:"modal-header",children:[Object(p.jsx)(re.e,{children:r}),Object(p.jsx)(Q,{icon:Object(p.jsx)(h.k,{}),onClick:c})]}),a]})]})})}));function se(e){var t=e.content,n=e.keys;return Object(p.jsxs)("div",{className:"shortcut-option",children:[Object(p.jsx)("div",{className:"shortcut-description",children:t}),Object(p.jsx)("div",{style:{display:"flex",justifySelf:"end",gap:"8px"},children:n.map((function(e,t){return Object(p.jsx)("div",{className:"shortcut-key",children:e},e)}))})]})}var le=/macintosh|mac os x/i.test(navigator.userAgent),ue=(/windows|win32/i.test(navigator.userAgent),le?"Cmd":"Ctrl");function je(){var e=Object(o.c)(I),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(p.jsx)(oe,{onClose:function(){a(!1)},title:"Hotkeys",className:"modal-shortcuts",show:n,children:Object(p.jsxs)("div",{className:"shortcut-options",children:[Object(p.jsx)(se,{content:"Enable Multi-Stroke Mask Drawing",keys:["Hold ".concat(ue)]}),Object(p.jsx)(se,{content:"Undo Inpainting",keys:[ue,"Z"]}),Object(p.jsx)(se,{content:"Pan",keys:["Space & Drag"]}),Object(p.jsx)(se,{content:"View Original Image",keys:["Hold Tag"]}),Object(p.jsx)(se,{content:"Reset Zoom/Pan",keys:["Esc"]}),Object(p.jsx)(se,{content:"Cancel Mask Drawing",keys:["Esc"]}),Object(p.jsx)(se,{content:"Run Inpainting Manually",keys:["Shift","R"]}),Object(p.jsx)(se,{content:"Decrease Brush Size",keys:["["]}),Object(p.jsx)(se,{content:"Increase Brush Size",keys:["]"]}),Object(p.jsx)(se,{content:"Toggle Dark Mode",keys:["Shift","D"]}),Object(p.jsx)(se,{content:"Toggle Hotkeys Panel",keys:["H"]})]})})}var de=n(39),be=["className"],he=["className"],fe=c.a.forwardRef((function(e,t){var n=e.className,a=Object(g.a)(e,be);return Object(p.jsx)(de.a,Object(b.a)(Object(b.a)({},a),{},{ref:t,className:"switch-root ".concat(n)}))})),pe=c.a.forwardRef((function(e,t){var n=e.className,a=Object(g.a)(e,he);return Object(p.jsx)(de.b,Object(b.a)(Object(b.a)({},a),{},{ref:t,className:"switch-thumb ".concat(n)}))})),ve=function(){var e=Object(o.c)(D),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(p.jsx)(w,{title:"Manual Inpainting Mode",input:Object(p.jsx)(fe,{checked:n.runInpaintingManually,onCheckedChange:function(e){a((function(t){return Object(b.a)(Object(b.a)({},t),{},{runInpaintingManually:e})}))},children:Object(p.jsx)(pe,{})})})};function Oe(e){var t=e.onClose,n=Object(o.c)(D),a=Object(s.a)(n,2),c=a[0],i=a[1];return Object(p.jsxs)(oe,{onClose:function(){i((function(e){return Object(b.a)(Object(b.a)({},e),{},{show:!1})})),t()},title:"Settings",className:"modal-setting",show:c.show,children:[Object(p.jsx)(ve,{}),Object(p.jsx)(L,{}),Object(p.jsx)(C,{})]})}var ge=n(28),xe=["state","desc"],me=function(){return Object(p.jsx)("span",{className:"loading-icon",children:Object(p.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Object(p.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"6"}),Object(p.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"22"}),Object(p.jsx)("line",{x1:"4.93",y1:"4.93",x2:"7.76",y2:"7.76"}),Object(p.jsx)("line",{x1:"16.24",y1:"16.24",x2:"19.07",y2:"19.07"}),Object(p.jsx)("line",{x1:"2",y1:"12",x2:"6",y2:"12"}),Object(p.jsx)("line",{x1:"18",y1:"12",x2:"22",y2:"12"}),Object(p.jsx)("line",{x1:"4.93",y1:"19.07",x2:"7.76",y2:"16.24"}),Object(p.jsx)("line",{x1:"16.24",y1:"7.76",x2:"19.07",y2:"4.93"})]})})},we=a.forwardRef((function(e,t){var n=e.state,a=e.desc,c=Object(g.a)(e,xe);return Object(p.jsxs)(ge.b,{children:[Object(p.jsxs)(ge.c,Object(b.a)(Object(b.a)({},c),{},{ref:t,className:"toast-root ".concat(n),children:[Object(p.jsx)("div",{className:"toast-icon",children:function(){switch(n){case"error":return Object(p.jsx)(h.g,{className:"error-icon"});case"success":return Object(p.jsx)(h.c,{className:"success-icon"});case"loading":return Object(p.jsx)(me,{});default:return Object(p.jsx)(p.Fragment,{})}}()}),Object(p.jsx)(ge.a,{className:"toast-desc",children:a})]})),Object(p.jsx)(ge.d,{className:"toast-viewpoint"})]})}));we.defaultProps={desc:"",state:"loading"};var ye=we,ke=function(e){var t=e.file,n=Object(o.c)(D),c=Object(s.a)(n,2),i=c[0],r=c[1],l=Object(o.c)(z),u=Object(s.a)(l,2),h=u[0],f=u[1],v=function(){var e=Object(d.a)(j.a.mark((function e(){var t,n,a,c,o;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,X().then((function(e){return e.text()}));case 2:if((t=e.sent)!==i.model){e.next=5;break}return e.abrupt("return");case 5:return e.next=7,(s=i.model,fetch("".concat(J,"/model_downloaded/").concat(s),{method:"GET"})).then((function(e){return e.text()}));case 7:n=e.sent,a=i.model,c="Switching to ".concat(a," model"),o=3e3,"False"===n&&(c="Downloading ".concat(a," model, this may take a while"),o=9999999999),f({open:!0,desc:c,state:"loading",duration:o}),Y(a).then((function(e){if(!e.ok)throw new Error("Server error");f({open:!0,desc:"Switch to ".concat(a," model success"),state:"success",duration:3e3})})).catch((function(){f({open:!0,desc:"Switch to ".concat(a," model failed"),state:"error",duration:3e3}),r((function(e){return Object(b.a)(Object(b.a)({},e),{},{model:t})}))}));case 14:case"end":return e.stop()}var s}),e)})));return function(){return e.apply(this,arguments)}}();return Object(a.useEffect)((function(){X().then((function(e){return e.text()})).then((function(e){r((function(t){return Object(b.a)(Object(b.a)({},t),{},{model:e})}))}))}),[r]),Object(p.jsxs)(p.Fragment,{children:[Object(p.jsx)(ie,{file:t}),Object(p.jsx)(Oe,{onClose:v}),Object(p.jsx)(je,{}),Object(p.jsx)(ye,Object(b.a)(Object(b.a)({},h),{},{onOpenChange:function(e){f((function(t){return Object(b.a)(Object(b.a)({},t),{},{open:e})}))}}))]})},Se=function(){var e=Object(o.c)(I),t=Object(s.a)(e,2),n=t[0],a=t[1],c=function(){a((function(e){return!e}))};return Object(l.a)("h",(function(e){null===e||void 0===e||e.preventDefault(),c()})),Object(p.jsx)("div",{className:"shortcuts",children:Object(p.jsx)(Q,{onClick:c,toolTip:"Hotkeys",tooltipPosition:"bottom",disabled:n,style:{border:0},icon:Object(p.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",role:"img",width:"28",height:"28",preserveAspectRatio:"xMidYMid meet",viewBox:"0 0 16 16",children:[Object(p.jsx)("rect",{x:"0",y:"0",width:"16",height:"16",fill:"none",stroke:"none"}),Object(p.jsxs)("g",{fill:"currentColor",children:[Object(p.jsx)("path",{d:"M14 5a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h12zM2 4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H2z"}),Object(p.jsx)("path",{d:"M13 10.25a.25.25 0 0 1 .25-.25h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5a.25.25 0 0 1-.25-.25v-.5zm0-2a.25.25 0 0 1 .25-.25h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5a.25.25 0 0 1-.25-.25v-.5zm-5 0A.25.25 0 0 1 8.25 8h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5A.25.25 0 0 1 8 8.75v-.5zm2 0a.25.25 0 0 1 .25-.25h1.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-1.5a.25.25 0 0 1-.25-.25v-.5zm1 2a.25.25 0 0 1 .25-.25h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5a.25.25 0 0 1-.25-.25v-.5zm-5-2A.25.25 0 0 1 6.25 8h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5A.25.25 0 0 1 6 8.75v-.5zm-2 0A.25.25 0 0 1 4.25 8h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5A.25.25 0 0 1 4 8.75v-.5zm-2 0A.25.25 0 0 1 2.25 8h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5A.25.25 0 0 1 2 8.75v-.5zm11-2a.25.25 0 0 1 .25-.25h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5a.25.25 0 0 1-.25-.25v-.5zm-2 0a.25.25 0 0 1 .25-.25h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5a.25.25 0 0 1-.25-.25v-.5zm-2 0A.25.25 0 0 1 9.25 6h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5A.25.25 0 0 1 9 6.75v-.5zm-2 0A.25.25 0 0 1 7.25 6h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5A.25.25 0 0 1 7 6.75v-.5zm-2 0A.25.25 0 0 1 5.25 6h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5A.25.25 0 0 1 5 6.75v-.5zm-3 0A.25.25 0 0 1 2.25 6h1.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-1.5A.25.25 0 0 1 2 6.75v-.5zm0 4a.25.25 0 0 1 .25-.25h.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-.5a.25.25 0 0 1-.25-.25v-.5zm2 0a.25.25 0 0 1 .25-.25h5.5a.25.25 0 0 1 .25.25v.5a.25.25 0 0 1-.25.25h-5.5a.25.25 0 0 1-.25-.25v-.5z"})]})]})})})},Ce=function(){var e=Object(o.c)(D),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(p.jsx)("div",{children:Object(p.jsx)(Q,{onClick:function(){a(Object(b.a)(Object(b.a)({},n),{},{show:!n.show}))},toolTip:"Settings",tooltipPosition:"bottom",style:{border:0},icon:Object(p.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",role:"img",width:"28",height:"28",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:[Object(p.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),Object(p.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})})},Me=function(){var e=Object(o.c)(N),t=Object(s.a)(e,2),n=t[0],a=t[1],c=T();return Object(p.jsxs)("header",{children:[Object(p.jsx)("div",{style:{visibility:n?"visible":"hidden"},children:Object(p.jsx)(Q,{icon:Object(p.jsx)(h.a,{}),onClick:function(){a(void 0)},style:{border:0},children:"desktop"===c?"Start New":void 0})}),Object(p.jsxs)("div",{className:"header-icons-wrapper",children:[Object(p.jsx)(H,{}),n&&Object(p.jsxs)("div",{className:"header-icons",children:[Object(p.jsx)(Se,{}),Object(p.jsx)(Ce,{})]})]})]})};!function(){function e(){return e=Object(d.a)(j.a.mark((function e(){var t,n,a=arguments;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=a.length>0&&void 0!==a[0]?a[0]:"",e.next=3,fetch(t,{method:"GET",cache:"no-cache"});case 3:return n=e.sent,e.abrupt("return",n.json());case 5:case"end":return e.stop()}}),e)}))),e.apply(this,arguments)}var t=function(){(function(){return e.apply(this,arguments)})(document.location+"/flaskwebgui-keep-server-alive").then((function(e){return e}))};document.addEventListener("DOMContentLoaded",(function(){t(),setInterval(t,3e3)}))}();var Le=function(){var e=Object(o.c)(N),t=Object(s.a)(e,2),n=t[0],c=t[1],i=Object(o.c)(P),r=Object(s.a)(i,2),u=r[0],b=r[1],h=function(){var e=Object(a.useState)(),t=Object(s.a)(e,2),n=t[0],c=t[1],i=Object(a.useCallback)((function(){var e=new Headers;e.append("pragma","no-cache"),e.append("cache-control","no-cache"),fetch("/inputimage",{headers:e}).then(function(){var e=Object(d.a)(j.a.mark((function e(t){var n,a,i,r;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=null===(n=t.headers.get("content-disposition"))||void 0===n?void 0:n.split("filename=")[1].split(";")[0],e.next=3,t.blob();case 3:(i=e.sent)&&i.type.startsWith("image")&&(r=new File([i],void 0!==a?a:"inputImage"),c(r));case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}())}),[c]);return Object(a.useEffect)((function(){i()}),[i]),n}();return Object(a.useEffect)((function(){c(h)}),[h,c]),Object(l.a)("D",(function(e){null===e||void 0===e||e.preventDefault(),b("light"===u?"dark":"light")})),Object(a.useEffect)((function(){document.body.setAttribute("data-theme",u)}),[u]),Object(p.jsxs)("div",{className:"lama-cleaner",children:[Object(p.jsx)(Me,{}),n?Object(p.jsx)(ke,{file:n}):Object(p.jsx)(Z,{})]})};r.a.render(Object(p.jsx)(c.a.StrictMode,{children:Object(p.jsx)(o.a,{children:Object(p.jsx)(Le,{})})}),document.getElementById("root"))}},[[51,1,2]]]);