IOPaint/lama_cleaner/app/build/static/js/main.ecfc8ee6.chunk.js
2022-04-19 21:35:52 +08:00

1 line
36 KiB
JavaScript

(this["webpackJsonplama-cleaner"]=this["webpackJsonplama-cleaner"]||[]).push([[0],{27:function(e,t,n){},30:function(e,t,n){"use strict";n.r(t);var a=n(0),c=n.n(a),i=n(12),r=n.n(i),s=(n(27),n(5)),o=n(2),l=n(33),u=n(4),d=n.n(u),j=n(8);var h=n(3),b=n(31),f=n(9),v=n(1);function p(e){var t=e.minWidth,n=e.chevronDirection,c=e.value,i=e.options,r=e.onChange,s=Object(a.useState)(!1),l=Object(o.a)(s,2),u=l[0],d=l[1],j=Object(a.useRef)(null);Object(b.a)(j,(function(){d(!1)}));return Object(v.jsxs)("div",{className:"selector",ref:j,style:{minWidth:t},children:[Object(v.jsxs)("div",{className:"selector-main",role:"button",onClick:function(){d((function(e){return!e}))},"aria-hidden":"true",children:[Object(v.jsx)("p",{children:c}),Object(v.jsx)("div",{className:"selector-icon",children:"up"===n?Object(v.jsx)(f.e,{}):Object(v.jsx)(f.d,{})})]}),u&&Object(v.jsx)("div",{className:"selector-options",children:i.map((function(e,t){return Object(v.jsx)("div",{className:"selector-option",role:"button",tabIndex:0,onClick:function(e){return function(e,t){var n=e.target.textContent.split("x");r(n[0]),d(!1)}(e)},"aria-hidden":"true",children:e},e)}))})]})}p.defaultProps={minWidth:128,chevronDirection:"down"};var O=p,x=n(6),m=["value","onValue"],g=c.a.forwardRef((function(e,t){var n=e.value,a=e.onValue,c=Object(x.a)(e,m);return Object(v.jsx)("input",Object(h.a)(Object(h.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(v.jsxs)("div",{className:"setting-block ".concat(i),children:[Object(v.jsxs)("div",{className:"setting-block-content",children:[Object(v.jsxs)("div",{className:"setting-block-content-title",children:[Object(v.jsx)("span",{children:t}),n&&Object(v.jsx)("span",{className:"setting-block-desc",children:n})]}),a]}),c&&Object(v.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(v.jsx)(w,{className:"sub-setting-block",title:t,input:Object(v.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"8px"},children:[Object(v.jsx)(g,{style:{width:"80px"},value:"".concat(n),onValue:c}),a&&Object(v.jsx)("span",{children:a})]})})};!function(e){e.ORIGINAL="Original",e.RESIZE="Resize",e.CROP="Crop"}(y||(y={}));var S,C=function(){var e=Object(s.c)(I),t=Object(o.a)(e,2),n=t[0],a=t[1],c=function(e){a((function(t){return Object(h.a)(Object(h.a)({},t),{},{hdStrategy:e})}))},i=function(e){var t=0===e.length?0:parseInt(e,10);a((function(e){return Object(h.a)(Object(h.a)({},e),{},{hdStrategyResizeLimit:t})}))},r=function(e){var t=0===e.length?0:parseInt(e,10);a((function(e){return Object(h.a)(Object(h.a)({},e),{},{hdStrategyCropTrigerSize:t})}))},l=function(e){var t=0===e.length?0:parseInt(e,10);a((function(e){return Object(h.a)(Object(h.a)({},e),{},{hdStrategyCropMargin:t})}))},u=function(){return Object(v.jsxs)("div",{children:["Use the original resolution of the picture, suitable for picture size below 2K. Try"," ",Object(v.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(v.jsx)(w,{className:"hd-setting-block",title:"High Resolution Strategy",input:Object(v.jsx)(O,{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(v.jsxs)("div",{children:[Object(v.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(v.jsx)(k,{title:"Trigger size",value:"".concat(n.hdStrategyCropTrigerSize),suffix:"pixel",onValue:r}),Object(v.jsx)(k,{title:"Crop margin",value:"".concat(n.hdStrategyCropMargin),suffix:"pixel",onValue:l})]});case y.RESIZE:return Object(v.jsxs)("div",{children:[Object(v.jsx)("div",{children:"Resize the longer side of the image to a specific size(keep ratio), then do inpainting on the resized image."}),Object(v.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 N,z=function(){var e=Object(s.c)(I),t=Object(o.a)(e,2),n=t[0],a=t[1],c=function(e,t,n){return Object(v.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[Object(v.jsx)("a",{className:"model-desc-link",href:t,target:"_blank",rel:"noreferrer noopener",children:e}),Object(v.jsx)("a",{className:"model-desc-link",href:n,target:"_blank",rel:"noreferrer noopener",children:n})]})};return Object(v.jsx)(w,{className:"model-setting-block",title:"Inpainting Model",input:Object(v.jsx)(O,{value:n.model,options:Object.values(S),onChange:function(e){return t=e,void a((function(e){return Object(h.a)(Object(h.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(v.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(v.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(h.a)(Object(h.a)({},e),{},{ldmSteps:t})}))}})]});default:return Object(v.jsx)(v.Fragment,{})}}()})},M=Object(s.b)({key:"fileState",default:void 0}),E=Object(s.b)({key:"toastState",default:{open:!1,desc:"",state:"default",duration:3e3}}),L=Object(s.b)({key:"shortcutsState",default:!1}),D={show:!1,saveImageBesideOrigin:!1,model:S.LAMA,ldmSteps:50,hdStrategy:y.RESIZE,hdStrategyResizeLimit:2048,hdStrategyCropTrigerSize:2048,hdStrategyCropMargin:128},I=Object(s.b)({key:"settingsState",default:D,effects:[(N="settingsState",function(e){var t=e.setSelf,n=e.onSet,a=localStorage.getItem(N);if(null!=a){var c=JSON.parse(a);c.show=!1,t(c)}n((function(e,t,n){return n?localStorage.removeItem(N):localStorage.setItem(N,JSON.stringify(e))}))})]}),R=n(7),T=function(){var e=Object(a.useState)(window.innerWidth),t=Object(o.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(o.a)(n,2),i=c[0],r=c[1],s=Object(a.useState)("file-upload-".concat(Math.random().toString())),l=Object(o.a)(s,1)[0],u=T();function h(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 b(e){return f.apply(this,arguments)}function f(){return(f=Object(j.a)(d.a.mark((function e(t){return d.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 p(e){return O.apply(this,arguments)}function O(){return(O=Object(j.a)(d.a.mark((function e(t){var n,a,c,i,r;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=[],a=[],c=0;c<t.length;c+=1)a.push(t[c].webkitGetAsEntry());case 3:if(!(a.length>0)){e.next=23;break}if(!(null===(i=a.shift())||void 0===i?void 0:i.isFile)){e.next=12;break}return e.next=8,b(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,x(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 x(e){return m.apply(this,arguments)}function m(){return(m=Object(j.a)(d.a.mark((function e(t){var n,a;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=[],e.next=3,g(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,g(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 g(e){return w.apply(this,arguments)}function w(){return(w=Object(j.a)(d.a.mark((function e(t){return d.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(j.a)(d.a.mark((function e(t){var n;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.preventDefault(),e.next=3,p(t.dataTransfer.items);case 3:n=e.sent,r(!1),h(n[0]);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return Object(v.jsx)("label",{htmlFor:l,className:"file-select-label",children:Object(v.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(v.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&&h(n)},accept:"image/png, image/jpeg"}),Object(v.jsx)("p",{className:"file-select-message",children:"desktop"===u?"Click here or drag an image file":"Tap here to load your picture"})]})})}var H=function(){var e=Object(s.e)(M);return Object(v.jsxs)("div",{className:"landing-page",children:[Object(v.jsxs)("h1",{children:["Image inpainting powered by \ud83e\udd99",Object(v.jsx)("a",{href:"https://github.com/saic-mdal/lama",children:"LaMa"})]}),Object(v.jsx)("div",{className:"landing-file-selector",children:Object(v.jsx)(A,{onSelection:function(){var t=Object(j.a)(d.a.mark((function t(n){return d.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(s.b)({key:"themeState",default:"light"}),V=function(){var e=Object(s.c)(P),t=Object(o.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(v.jsx)("div",{className:"theme-toggle-ui",children:Object(v.jsx)("div",{className:"theme-btn",onClick:function(){c("light"===n?"dark":"light")},role:"button",tabIndex:0,"aria-hidden":"true",children:"light"===n?Object(v.jsx)(f.i,{}):Object(v.jsx)(f.j,{style:{color:"#ffcc00"}})})})},W=n(21),Z=n(32),U=n(22);function B(e){for(var t=e.split(",")[0].split(":")[1].split(";")[0],n=atob(e.split(",")[1]),a=[],c=0;c<n.length;c+=1)a.push(n.charCodeAt(c));return new Blob([new Uint8Array(a)],{type:t})}function F(e,t){return new Promise((function(n,a){var c=e.src,i=e;i.onload=n,i.onerror=function(e){i.src=c,a(e)},i.src=t}))}var G="".concat("");function J(e,t,n,a){return K.apply(this,arguments)}function K(){return K=Object(j.a)(d.a.mark((function e(t,n,a,c){var i,r,s;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(i=new FormData).append("image",t),r=B(n),i.append("mask",r),i.append("ldmSteps",a.ldmSteps.toString()),i.append("hdStrategy",a.hdStrategy),i.append("hdStrategyCropMargin",a.hdStrategyCropMargin.toString()),i.append("hdStrategyCropTrigerSize",a.hdStrategyCropTrigerSize.toString()),i.append("hdStrategyResizeLimit",a.hdStrategyResizeLimit.toString()),void 0===c?i.append("sizeLimit","1080"):i.append("sizeLimit",c),e.next=12,fetch("".concat(G,"/inpaint"),{method:"POST",body:i}).then(function(){var e=Object(j.a)(d.a.mark((function e(t){return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.blob());case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}());case 12:return s=e.sent,e.abrupt("return",URL.createObjectURL(s));case 14:case"end":return e.stop()}}),e)}))),K.apply(this,arguments)}function _(e){var t=new FormData;return t.append("name",e),fetch("".concat(G,"/model"),{method:"POST",body:t})}function Y(){return fetch("".concat(G,"/model"),{method:"GET"})}function X(e){var t=e.children,n=e.className,a=e.disabled,c=e.icon,i=e.onKeyDown,r=e.onClick,s=e.onDown,o=e.onUp,l=e.style;return Object(v.jsxs)("div",{role:"button",style:l,onKeyDown:i,onClick:function(e){e.currentTarget.blur(),null===r||void 0===r||r()},onPointerDown:function(e){null===s||void 0===s||s(e.nativeEvent)},onPointerUp:function(e){null===o||void 0===o||o(e.nativeEvent)},tabIndex:-1,className:["btn-primary",t?"btn-primary-content":"",a?"btn-primary-disabled":"",n].join(" "),children:[c,t?Object(v.jsx)("span",{children:t}):null]})}function $(e){var t=e.value,n=e.onChange,a=e.label,c=e.min,i=e.max,r=((i||100)-(c||0))/100;return Object(v.jsxs)("div",{className:"editor-brush-slider",children:[Object(v.jsx)("span",{children:a}),Object(v.jsx)("input",{type:"range",step:r,min:c,max:i,value:t,onChange:function(e){e.preventDefault(),e.stopPropagation(),n(parseInt(e.currentTarget.value,10))}})]})}var Q=["720","1080","2000","Original"];function q(e){var t=e.originalHeight,n=e.originalWidth,c=e.onChange,i=Object(a.useState)(!1),r=Object(o.a)(i,2),s=r[0],l=r[1],u=Object(a.useRef)(null),d=Object(a.useState)("Original"),j=Object(o.a)(d,2),h=j[0],p=j[1],O=Math.max(n,t),x=Object(a.useCallback)((function(){for(var e=[],t=0;t<Q.length;t+=1)"Original"===Q[t]&&e.push(Q[t]),parseInt(Q[t],10)<O&&e.push(Q[t]);return e}),[O]),m=Object(a.useCallback)((function(e){if("Original"===e)return"".concat(n,"x").concat(t);var a=parseInt(e,10)/O;if(n>t){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,O]);Object(b.a)(u,(function(){l(!1)}));var g=function(e){var a=e.target.textContent.split("x");n>t?(p(a[0]),c(a[0])):(p(a[1]),c(a[1])),l(!s)};return Object(v.jsxs)("div",{className:"editor-size-selector",ref:u,children:[Object(v.jsxs)("div",{className:"editor-size-selector-main",role:"button",tabIndex:0,onClick:function(){l((function(e){return!e}))},"aria-hidden":"true",children:[Object(v.jsx)("p",{children:m(h.toString())}),Object(v.jsx)("div",{className:"editor-size-selector-icon",children:Object(v.jsx)(f.e,{})})]}),s&&Object(v.jsx)("div",{className:"editor-size-options",children:x().map((function(e){return Object(v.jsx)("div",{className:"editor-size-option",role:"button",tabIndex:0,onClick:g,"aria-hidden":"true",children:m(e)},e)}))})]})}var ee="#ffcc00bb";function te(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ee;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 ne(e){var t=e.file,n=Object(s.d)(I),c=Object(a.useState)(40),i=Object(o.a)(c,2),r=i[0],u=i[1],h=function(e){var t=Object(a.useState)(new Image),n=Object(o.a)(t,1)[0],c=Object(a.useState)(!1),i=Object(o.a)(c,2),r=i[0],s=i[1];return Object(a.useEffect)((function(){return n.onload=function(){s(!0)},s(!1),n.src=URL.createObjectURL(e),function(){n.onload=null}}),[e,n]),[n,r]}(t),b=Object(o.a)(h,2),p=b[0],O=b[1],x=Object(a.useState)([]),m=Object(o.a)(x,2),g=m[0],w=m[1],y=Object(a.useState)(),k=Object(o.a)(y,2),S=k[0],C=k[1],N=Object(a.useState)((function(){return document.createElement("canvas")})),z=Object(o.a)(N,1)[0],M=Object(a.useState)([{pts:[]}]),E=Object(o.a)(M,2),L=E[0],D=E[1],T=Object(a.useState)([{pts:[]}]),A=Object(o.a)(T,2),H=A[0],P=A[1],V=Object(a.useState)([]),B=Object(o.a)(V,2),G=B[0],K=B[1],_=Object(a.useState)({x:-1,y:-1}),Y=Object(o.a)(_,2),Q=Y[0],ee=Q.x,ne=Q.y,ae=Y[1],ce=Object(a.useState)(!1),ie=Object(o.a)(ce,2),re=ie[0],se=ie[1],oe=Object(a.useState)(!1),le=Object(o.a)(oe,2),ue=le[0],de=le[1],je=Object(a.useState)(!1),he=Object(o.a)(je,2),be=he[0],fe=he[1],ve=Object(a.useState)(!1),pe=Object(o.a)(ve,2),Oe=pe[0],xe=pe[1],me=Object(a.useState)(1),ge=Object(o.a)(me,2),we=ge[0],ye=ge[1],ke=Object(a.useState)(1),Se=Object(o.a)(ke,2),Ce=Se[0],Ne=Se[1],ze=Object(a.useState)(1080),Me=Object(o.a)(ze,2),Ee=Me[0],Le=Me[1],De=Object(Z.a)(),Ie=Object(a.useRef)(),Re=Object(a.useState)(!1),Te=Object(o.a)(Re,2),Ae=Te[0],He=Te[1],Pe=Object(a.useState)(!1),Ve=Object(o.a)(Pe,2),We=Ve[0],Ze=Ve[1],Ue=Object(a.useState)(!1),Be=Object(o.a)(Ue,2),Fe=Be[0],Ge=Be[1],Je=Object(a.useState)(0),Ke=Object(o.a)(Je,2),_e=Ke[0],Ye=Ke[1],Xe=Object(a.useCallback)((function(){if(S){S.clearRect(0,0,S.canvas.width,S.canvas.height);var e=g[g.length-1];(null===e||void 0===e?void 0:e.src)?S.drawImage(e,0,0,p.naturalWidth,p.naturalHeight):S.drawImage(p,0,0),te(S,H)}}),[S,H,p,g]),$e=Object(a.useCallback)((function(){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");z.width=null===S||void 0===S?void 0:S.canvas.width,z.height=null===S||void 0===S?void 0:S.canvas.height;var e=z.getContext("2d");if(!e)throw new Error("could not retrieve mask canvas");te(e,L,"white")}),[null===S||void 0===S?void 0:S.canvas.height,null===S||void 0===S?void 0:S.canvas.width,L,z]),Qe=Object(a.useCallback)(Object(j.a)(d.a.mark((function e(){var a,c;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return xe(!0),$e(),e.prev=2,e.next=5,J(t,z.toDataURL(),n,Ee.toString());case 5:if(a=e.sent){e.next=8;break}throw new Error("empty response");case 8:return c=new Image,e.next=11,F(c,a);case 11:g.push(c),L.push({pts:[]}),w(Object(R.a)(g)),D(Object(R.a)(L)),G.push(H.length),K(G),H.length=0,P([{pts:[]}]),e.next=24;break;case 21:e.prev=21,e.t0=e.catch(2),alert(e.t0.message?e.t0.message:e.t0.toString());case 24:xe(!1),Xe();case 26:case"end":return e.stop()}}),e,null,[[2,21]])}))),[Xe,t,L,H,z,$e,g,Ee,G,n]),qe=function(){return 0!==H.length&&0!==H[0].pts.length},et=function(){return 0!==g.length},tt=function(){Ze(!1),H.length=0,P([{pts:[]}])},nt=function(e){return"Control"===e.key||"Meta"===e.key};Object(U.a)(nt,(function(){Fe&&(Oe||(Ge(!1),qe()&&Qe()))}),{event:"keyup"},[Oe,Fe,qe]),Object(U.a)(nt,(function(){Oe||Ge(!0)}),{event:"keydown"},[Oe]),Object(a.useEffect)((function(){if(O){var e=De.width/p.naturalWidth,t=(De.height-200)/p.naturalHeight,n=1;(e<1||t<1)&&(n=Math.min(e,t)),Ne(n),ye(n);var a,c=Math.max(p.width,p.height);if(Le(c),(null===S||void 0===S?void 0:S.canvas)&&(S.canvas.width=p.naturalWidth,S.canvas.height=p.naturalHeight),!Ae)null===(a=Ie.current)||void 0===a||a.centerView(n,1),He(!0);Xe()}}),[null===S||void 0===S?void 0:S.canvas,Xe,Ie,p,O,De,Ae]);var at=Object(a.useCallback)((function(){if(Ce&&p&&De){var e=Ie.current;if(!e)throw new Error("no viewport");var t=(De.width-p.width*Ce)/2,n=(De.height-p.height*Ce)/2;e.setTransform(t,n,Ce,200,"easeOutQuad"),e.state.scale=Ce,ye(Ce)}}),[Ie,Ce,p,De]);Object(a.useEffect)((function(){return window.addEventListener("resize",(function(){at()})),function(){window.removeEventListener("resize",(function(){at()}))}}),[De,at]);Object(U.a)("Escape",(function(){Oe||(We||Fe?tt():at())}),{event:"keydown"},[We,Oe,Fe,at,tt]);var ct=function(e,t){H[H.length-1].pts.push({x:e,y:t}),L[L.length-1].pts.push({x:e,y:t}),Xe()},it=function(){if(g.length&&G.length){for(var e=L,t=G[G.length-1],n=0;n<=t;n+=1)e.pop();D([].concat(Object(R.a)(e),[{pts:[]}])),G.pop(),K(G);var a=g;a.pop(),w(Object(R.a)(a))}};Object(U.a)((function(e){var t=(e.metaKey||e.ctrlKey)&&"z"===e.key;return"Tab"===e.key&&e.preventDefault(),!!t&&(e.preventDefault(),!0)}),it),Object(l.a)("Tab",(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),et()&&fe((function(){return window.setTimeout((function(){Ye(100)}),10),!0}))}),(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),et()&&(Ye(0),window.setTimeout((function(){fe(!1)}),350))}));var rt=function(e){e===re||ue||se(e)},st=Object(a.useCallback)((function(){return ue?"grab":re?"none":void 0}),[re,ue]);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)(" ",(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),se(!1),de(!0)}),(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),se(!0),de(!1)}));return Object(v.jsxs)("div",{className:"editor-container","aria-hidden":"true",onMouseMove:function(e){var t=e.nativeEvent;ae({x:t.pageX,y:t.pageY})},onMouseUp:function(){if(!ue&&(p.src&&(null===S||void 0===S?void 0:S.canvas)&&!Oe&&We)){if(Ze(!1),Fe)return L.push({pts:[]}),D(Object(R.a)(L)),H.push({pts:[]}),void P(Object(R.a)(H));0!==H.length&&0!==H[0].pts.length&&Qe()}},children:[Object(v.jsx)(W.b,{ref:function(e){e&&(Ie.current=e)},panning:{disabled:!ue,velocityDisabled:!0},wheel:{step:.05},centerZoomedOut:!0,alignmentAnimation:{disabled:!0},limitToBounds:!1,doubleClick:{disabled:!0},initialScale:Ce,minScale:Ce,onZoom:function(e){ye(e.state.scale)},children:Object(v.jsx)(W.a,{contentClass:Oe?"editor-canvas-loading":"",contentStyle:{visibility:Ae?"visible":"hidden"},children:Object(v.jsxs)("div",{className:"editor-canvas-container",children:[Object(v.jsx)("canvas",{className:"editor-canvas",style:{cursor:st(),clipPath:"inset(0 ".concat(_e,"% 0 0)"),transition:"clip-path 350ms ease-in-out"},onContextMenu:function(e){e.preventDefault()},onMouseOver:function(){return rt(!0)},onFocus:function(){return rt(!0)},onMouseLeave:function(){return rt(!1)},onMouseDown:function(e){if(!ue&&(p.src&&(null===S||void 0===S?void 0:S.canvas)&&!Oe)){Ze(!0),H[H.length-1].size=r,L[L.length-1].size=r;var t=e.nativeEvent;ct(t.offsetX,t.offsetY)}},onMouseMove:function(e){if(!ue&&We){var t=e.nativeEvent,n=t.offsetX,a=t.offsetY;ct(n,a)}},ref:function(e){if(e&&!S){var t=e.getContext("2d");t&&C(t)}}}),Object(v.jsxs)("div",{className:"original-image-container",style:{width:"".concat(p.naturalWidth,"px"),height:"".concat(p.naturalHeight,"px")},children:[be&&Object(v.jsx)("div",{className:"editor-slider",style:{marginRight:"".concat(_e,"%")}}),Object(v.jsx)("img",{className:"original-image",src:p.src,alt:"original",style:{width:"".concat(p.naturalWidth,"px"),height:"".concat(p.naturalHeight,"px")}})]})]})})}),re&&!Oe&&!ue&&Object(v.jsx)("div",{className:"brush-shape",style:function(){var e=function(){var e,t,n=Ce;return void 0!==(null===(e=Ie.current)||void 0===e?void 0:e.state.scale)&&(n=null===(t=Ie.current)||void 0===t?void 0:t.state.scale),n}();return{width:"".concat(r*e,"px"),height:"".concat(r*e,"px"),left:"".concat(ee,"px"),top:"".concat(ne,"px"),transform:"translate(-50%, -50%)"}}()}),Object(v.jsxs)("div",{className:"editor-toolkit-panel",children:[Object(v.jsx)(q,{onChange:function(e){Le(e)},originalWidth:p.naturalWidth,originalHeight:p.naturalHeight}),Object(v.jsx)($,{label:"Brush",min:10,max:150,value:r,onChange:u}),Object(v.jsxs)("div",{className:"editor-toolkit-btns",children:[Object(v.jsx)(X,{icon:Object(v.jsx)(f.b,{}),disabled:we===Ce,onClick:at}),Object(v.jsx)(X,{icon:Object(v.jsx)("svg",{width:"19",height:"9",viewBox:"0 0 19 9",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(v.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:it,disabled:0===g.length}),Object(v.jsx)(X,{icon:Object(v.jsx)(f.h,{}),className:be?"eyeicon-active":"",onDown:function(e){e.preventDefault(),fe((function(){return window.setTimeout((function(){Ye(100)}),10),!0}))},onUp:function(){Ye(0),window.setTimeout((function(){fe(!1)}),350)},disabled:0===g.length,children:void 0}),Object(v.jsx)(X,{icon:Object(v.jsx)(f.f,{}),disabled:!g.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)}(g[g.length-1].currentSrc,e)},children:void 0})]})]})]})}function ae(e){var t=e.show,n=e.children,c=e.onClose,i=e.className,r=e.title,s=Object(a.useRef)(null);return Object(b.a)(s,(function(){t&&(null===c||void 0===c||c())})),Object(l.a)("Escape",(function(e){t&&(null===c||void 0===c||c())})),Object(v.jsx)("div",{className:"modal-mask",style:{visibility:!0===t?"visible":"hidden"},children:Object(v.jsxs)("div",{ref:s,className:"modal ".concat(i),children:[Object(v.jsxs)("div",{className:"modal-header",children:[Object(v.jsx)("h2",{children:r}),Object(v.jsx)(X,{icon:Object(v.jsx)(f.k,{}),onClick:c})]}),n]})})}function ce(e){var t=e.children,n=e.content;return Object(v.jsxs)("div",{className:"shortcut-option",children:[Object(v.jsx)("div",{className:"shortcut-description",children:n}),Object(v.jsx)("div",{className:"shortcut-key",children:t})]})}function ie(){var e=Object(s.c)(L),t=Object(o.a)(e,2),n=t[0],a=t[1];return Object(v.jsx)(ae,{onClose:function(){a(!1)},title:"Hotkeys",className:"modal-shortcuts",show:n,children:Object(v.jsxs)("div",{className:"shortcut-options",children:[Object(v.jsx)(ce,{content:"Enable multi-stroke mask drawing",children:Object(v.jsx)("p",{children:"Hold Cmd/Ctrl"})}),Object(v.jsx)(ce,{content:"Undo inpainting",children:Object(v.jsx)("p",{children:"Cmd/Ctrl + Z"})}),Object(v.jsx)(ce,{content:"Pan",children:Object(v.jsx)("p",{children:"Space & Drag"})}),Object(v.jsx)(ce,{content:"View original image",children:Object(v.jsx)("p",{children:"Hold Tab"})}),Object(v.jsx)(ce,{content:"Reset zoom/pan",children:Object(v.jsx)("p",{children:"Esc"})}),Object(v.jsx)(ce,{content:"Cancel mask drawing",children:Object(v.jsx)("p",{children:"Esc"})}),Object(v.jsx)(ce,{content:"Decrease Brush Size",children:Object(v.jsx)("p",{children:"["})}),Object(v.jsx)(ce,{content:"Increase Brush Size",children:Object(v.jsx)("p",{children:"]"})}),Object(v.jsx)(ce,{content:"Toggle Dark Mode",children:Object(v.jsx)("p",{children:"Shift + D"})}),Object(v.jsx)(ce,{content:"Toggle Hotkeys Panel",children:Object(v.jsx)("p",{children:"H"})})]})})}function re(e){var t=e.onClose,n=Object(s.c)(I),a=Object(o.a)(n,2),c=a[0],i=a[1];return Object(v.jsxs)(ae,{onClose:function(){i((function(e){return Object(h.a)(Object(h.a)({},e),{},{show:!1})})),t()},title:"Settings",className:"modal-setting",show:c.show,children:[Object(v.jsx)(z,{}),Object(v.jsx)(C,{})]})}var se=n(16),oe=["state","desc"],le=function(){return Object(v.jsx)("span",{className:"loading-icon",children:Object(v.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(v.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"6"}),Object(v.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"22"}),Object(v.jsx)("line",{x1:"4.93",y1:"4.93",x2:"7.76",y2:"7.76"}),Object(v.jsx)("line",{x1:"16.24",y1:"16.24",x2:"19.07",y2:"19.07"}),Object(v.jsx)("line",{x1:"2",y1:"12",x2:"6",y2:"12"}),Object(v.jsx)("line",{x1:"18",y1:"12",x2:"22",y2:"12"}),Object(v.jsx)("line",{x1:"4.93",y1:"19.07",x2:"7.76",y2:"16.24"}),Object(v.jsx)("line",{x1:"16.24",y1:"7.76",x2:"19.07",y2:"4.93"})]})})},ue=a.forwardRef((function(e,t){var n=e.state,a=e.desc,c=Object(x.a)(e,oe);return Object(v.jsxs)(se.b,{children:[Object(v.jsxs)(se.c,Object(h.a)(Object(h.a)({},c),{},{ref:t,className:"toast-root ".concat(n),children:[Object(v.jsx)("div",{className:"toast-icon",children:function(){switch(n){case"error":return Object(v.jsx)(f.g,{className:"error-icon"});case"success":return Object(v.jsx)(f.c,{className:"success-icon"});case"loading":return Object(v.jsx)(le,{});default:return Object(v.jsx)(v.Fragment,{})}}()}),Object(v.jsx)(se.a,{className:"toast-desc",children:a})]})),Object(v.jsx)(se.d,{className:"toast-viewpoint"})]})}));ue.defaultProps={desc:"",state:"loading"};var de=ue,je=function(e){var t=e.file,n=Object(s.c)(I),c=Object(o.a)(n,2),i=c[0],r=c[1],l=Object(s.c)(E),u=Object(o.a)(l,2),b=u[0],f=u[1],p=function(){var e=Object(j.a)(d.a.mark((function e(){var t,n,a,c,s;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Y().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,(o=i.model,fetch("".concat(G,"/model_downloaded/").concat(o),{method:"GET"})).then((function(e){return e.text()}));case 7:n=e.sent,a=i.model,c="Switching to ".concat(a," model"),s=3e3,"False"===n&&(c="Downloading ".concat(a," model, this may take a while"),s=9999999999),f({open:!0,desc:c,state:"loading",duration:s}),_(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(h.a)(Object(h.a)({},e),{},{model:t})}))}));case 14:case"end":return e.stop()}var o}),e)})));return function(){return e.apply(this,arguments)}}();return Object(a.useEffect)((function(){Y().then((function(e){return e.text()})).then((function(e){r((function(t){return Object(h.a)(Object(h.a)({},t),{},{model:e})}))}))}),[]),Object(v.jsxs)(v.Fragment,{children:[Object(v.jsx)(ne,{file:t}),Object(v.jsx)(re,{onClose:p}),Object(v.jsx)(ie,{}),Object(v.jsx)(de,Object(h.a)(Object(h.a)({},b),{},{onOpenChange:function(e){f((function(t){return Object(h.a)(Object(h.a)({},t),{},{open:e})}))}}))]})},he=function(){var e=Object(s.c)(L),t=Object(o.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(v.jsx)("div",{className:"shortcuts",children:Object(v.jsx)(X,{onClick:c,disabled:n,style:{border:0},icon:Object(v.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(v.jsx)("rect",{x:"0",y:"0",width:"16",height:"16",fill:"none",stroke:"none"}),Object(v.jsxs)("g",{fill:"currentColor",children:[Object(v.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(v.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"})]})]})})})},be=function(){var e=Object(s.c)(I),t=Object(o.a)(e,2),n=t[0],a=t[1];return Object(v.jsx)("div",{children:Object(v.jsx)(X,{onClick:function(){a(Object(h.a)(Object(h.a)({},n),{},{show:!n.show}))},style:{border:0},icon:Object(v.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(v.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(v.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})})},fe=function(){var e=Object(s.c)(M),t=Object(o.a)(e,2),n=t[0],a=t[1],c=T();return Object(v.jsxs)("header",{children:[Object(v.jsx)("div",{style:{visibility:n?"visible":"hidden"},children:Object(v.jsx)(X,{icon:Object(v.jsx)(f.a,{}),onClick:function(){a(void 0)},style:{border:0},children:"desktop"===c?"Start New":void 0})}),Object(v.jsxs)("div",{className:"header-icons-wrapper",children:[Object(v.jsxs)("div",{className:"header-icons",style:{visibility:n?"visible":"hidden"},children:[Object(v.jsx)(be,{}),Object(v.jsx)(he,{})]}),Object(v.jsx)(V,{})]})]})};!function(){function e(){return e=Object(j.a)(d.a.mark((function e(){var t,n,a=arguments;return d.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 ve=function(){var e=Object(s.c)(M),t=Object(o.a)(e,2),n=t[0],c=t[1],i=Object(s.c)(P),r=Object(o.a)(i,2),u=r[0],h=r[1],b=function(){var e=Object(a.useState)(),t=Object(o.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(j.a)(d.a.mark((function e(t){var n,a,i,r;return d.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(b)}),[b,c]),Object(l.a)("D",(function(e){null===e||void 0===e||e.preventDefault(),h("light"===u?"dark":"light")})),Object(v.jsxs)("div",{className:"lama-cleaner","data-theme":u,children:[Object(v.jsx)(fe,{}),n?Object(v.jsx)(je,{file:n}):Object(v.jsx)(H,{})]})};r.a.render(Object(v.jsx)(c.a.StrictMode,{children:Object(v.jsx)(s.a,{children:Object(v.jsx)(ve,{})})}),document.getElementById("root"))}},[[30,1,2]]]);