IOPaint/lama_cleaner/app/build/static/js/main.5fe518c4.chunk.js
2022-07-24 10:30:52 +08:00

1 line
45 KiB
JavaScript

(this["webpackJsonplama-cleaner"]=this["webpackJsonplama-cleaner"]||[]).push([[0],{57:function(e,t,n){},62:function(e,t,n){"use strict";n.r(t);var a=n(0),c=n.n(a),i=n(12),r=n.n(i),o=(n(57),n(9)),s=n(2),l=n(66),u=n(49),d=n(11),j=n.n(d),b=n(15);var h=n(3),f=n(10),p=n(44),O=n.n(p),v=n(16),g=n(23),m=n(1),x=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(m.jsxs)(g.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(m.jsxs)(g.g,{className:"select-trigger",style:{width:t},ref:s,children:[Object(m.jsx)(g.h,{}),Object(m.jsx)(g.b,{children:"up"===c?Object(m.jsx)(v.d,{}):Object(m.jsx)(v.c,{})})]}),Object(m.jsx)(g.a,{className:"select-content",children:Object(m.jsx)(g.i,{className:"select-viewport",children:i.map((function(e){return Object(m.jsxs)(g.c,{value:e,className:"select-item",children:[Object(m.jsx)(g.e,{children:e}),Object(m.jsx)(g.d,{className:"select-item-indicator",children:Object(m.jsx)(v.b,{})})]},e)}))})})]})};x.defaultProps={chevronDirection:"down",autoFocusAfterClose:!0};var w=x,y=n(4),C=["value","onValue"],k=c.a.forwardRef((function(e,t){var n=e.value,a=e.onValue,c=Object(y.a)(e,C);return Object(m.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"}))})),S=n(27),M=function(e){var t=e.content,n=e.children;return Object(m.jsx)(S.d,{children:Object(m.jsxs)(S.c,{children:[Object(m.jsx)(S.e,{className:"tooltip-trigger",children:n}),Object(m.jsxs)(S.b,{className:"tooltip-content",children:[t,Object(m.jsx)(S.a,{className:"tooltip-arrow"})]})]})})};var L=function(e){var t=e.title,n=e.titleSuffix,a=e.desc,c=e.input,i=e.optionDesc,r=e.className;return Object(m.jsxs)("div",{className:"setting-block ".concat(r),children:[Object(m.jsxs)("div",{className:"setting-block-content",children:[Object(m.jsx)("div",{className:"setting-block-content-title",children:Object(m.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[a?Object(m.jsx)(M,{content:Object(m.jsx)("div",{style:{maxWidth:400},children:a}),children:Object(m.jsx)("span",{children:t})}):Object(m.jsx)("span",{children:t}),n]})}),c]}),i&&Object(m.jsx)("div",{className:"option-desc",children:i})]})};var N,I,z=function(e){var t=e.title,n=e.desc,a=e.value,c=e.suffix,i=e.onValue;return Object(m.jsx)(L,{className:"sub-setting-block",title:t,desc:n,input:Object(m.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"8px"},children:[Object(m.jsx)(k,{style:{width:"80px"},value:"".concat(a),onValue:i}),c&&Object(m.jsx)("span",{children:c})]})})};!function(e){e.ORIGINAL="Original",e.RESIZE="Resize",e.CROP="Crop"}(N||(N={})),function(e){e.ddim="ddim",e.plms="plms"}(I||(I={}));var D,E,T=function(){var e=Object(o.d)(U),t=Object(s.a)(e,2),n=t[0],a=t[1],c=function(e){a({hdStrategy:e})},i=function(e){var t=0===e.length?0:parseInt(e,10);a({hdStrategyResizeLimit:t})},r=function(e){var t=0===e.length?0:parseInt(e,10);a({hdStrategyCropTrigerSize:t})},l=function(e){var t=0===e.length?0:parseInt(e,10);a({hdStrategyCropMargin:t})},u=function(){return Object(m.jsxs)("div",{children:["Use original picture, suitable for picture size below 2K. Try"," ",Object(m.jsx)("div",{tabIndex:0,role:"button",className:"inline-tip",onClick:function(){return c(N.RESIZE)},children:"Resize"})," or ",Object(m.jsx)("div",{tabIndex:0,role:"button",className:"inline-tip",onClick:function(){return c(N.CROP)},children:"Crop"})," ","if you didn't get good results or have GPU memory issue."]})};return Object(m.jsx)(L,{className:"hd-setting-block",title:"High Resolution Strategy",input:Object(m.jsx)(w,{width:80,value:n.hdStrategy,options:Object.values(N),onChange:function(e){return c(e)}}),optionDesc:function(){switch(n.hdStrategy){case N.ORIGINAL:return u();case N.CROP:return Object(m.jsxs)(m.Fragment,{children:[Object(m.jsx)("div",{children:"Crop masking area from the original image to do inpainting."}),Object(m.jsx)(z,{title:"Trigger size",value:"".concat(n.hdStrategyCropTrigerSize),suffix:"pixel",onValue:r}),Object(m.jsx)(z,{title:"Crop margin",value:"".concat(n.hdStrategyCropMargin),suffix:"pixel",onValue:l})]});case N.RESIZE:return Object(m.jsxs)(m.Fragment,{children:[Object(m.jsx)("div",{children:"Resize the longer side of the image to a specific size, then do inpainting on the resized image."}),Object(m.jsx)(z,{title:"Size limit",value:"".concat(n.hdStrategyResizeLimit),suffix:"pixel",onValue:i})]});default:return u()}}()})};!function(e){e.LAMA="lama",e.LDM="ldm",e.ZITS="zits"}(E||(E={}));var Z,R=Object(o.b)({key:"fileState",default:void 0}),A=Object(o.b)({key:"toastState",default:{open:!1,desc:"",state:"default",duration:3e3}}),H=Object(o.b)({key:"shortcutsState",default:!1}),P=(D={},Object(f.a)(D,E.LAMA,{hdStrategy:N.RESIZE,hdStrategyResizeLimit:2048,hdStrategyCropTrigerSize:2048,hdStrategyCropMargin:128}),Object(f.a)(D,E.LDM,{hdStrategy:N.CROP,hdStrategyResizeLimit:1080,hdStrategyCropTrigerSize:1080,hdStrategyCropMargin:128}),Object(f.a)(D,E.ZITS,{hdStrategy:N.CROP,hdStrategyResizeLimit:1024,hdStrategyCropTrigerSize:1024,hdStrategyCropMargin:128}),D),V={show:!1,downloadMask:!1,graduallyInpainting:!0,runInpaintingManually:!1,model:E.LAMA,hdSettings:P,ldmSteps:25,ldmSampler:I.plms,zitsWireframe:!0},W="settingsState2",F=Object(o.b)({key:W,default:V,effects:[(Z=W,function(e){var t=e.setSelf,n=e.onSet,a=localStorage.getItem(Z);if(null!=a){var c=JSON.parse(a);c.show=!1,t(O.a.merge(O.a.cloneDeep(V),c))}n((function(e,t,n){return n?localStorage.removeItem(Z):localStorage.setItem(Z,JSON.stringify(e))}))})]}),U=Object(o.c)({key:"hdSettings",get:function(e){var t=(0,e.get)(F);return t.hdSettings[t.model]},set:function(e,t){var n=e.get,a=e.set,c=n(F),i=c.hdSettings[c.model],r=Object(h.a)(Object(h.a)({},i),t);a(F,Object(h.a)(Object(h.a)({},c),{},{hdSettings:Object(h.a)(Object(h.a)({},c.hdSettings),{},Object(f.a)({},c.model,r))}))}}),B=n(7),K=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 G(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=K();function d(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(b.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 p(e){return O.apply(this,arguments)}function O(){return(O=Object(b.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;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,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=B.a,e.next=18,v(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 v(e){return g.apply(this,arguments)}function g(){return(g=Object(b.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,x(t);case 3:a=e.sent;case 4:if(!(a.length>0)){e.next=11;break}return n.push.apply(n,Object(B.a)(a)),e.next=8,x(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 x(e){return w.apply(this,arguments)}function w(){return(w=Object(b.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(b.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,p(t.dataTransfer.items);case 3:n=e.sent,r(!1),d(n[0]);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return Object(m.jsx)("label",{htmlFor:l,className:"file-select-label",children:Object(m.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(m.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&&d(n)},accept:"image/png, image/jpeg"}),Object(m.jsx)("p",{className:"file-select-message",children:"desktop"===u?"Click here or drag an image file":"Tap here to load your picture"})]})})}var _=function(){var e=Object(o.f)(R);return Object(m.jsxs)("div",{className:"landing-page",children:[Object(m.jsxs)("h1",{children:["Image inpainting powered by \ud83e\udd99",Object(m.jsx)("a",{href:"https://github.com/saic-mdal/lama",children:"LaMa"})]}),Object(m.jsx)("div",{className:"landing-file-selector",children:Object(m.jsx)(G,{onSelection:function(){var t=Object(b.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)}}()})})]})},J=Object(o.b)({key:"themeState",default:"light"}),$=function(){var e=Object(o.d)(J),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(m.jsx)("div",{className:"theme-toggle-ui",children:Object(m.jsx)("div",{className:"theme-btn",onClick:function(){c("light"===n?"dark":"light")},role:"button",tabIndex:0,"aria-hidden":"true",children:"light"===n?Object(m.jsx)(v.h,{}):Object(m.jsx)(v.i,{style:{color:"#ffcc00"}})})})},Y=n(45),Q=n(65),X=n(47);function q(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 ee(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}))}function te(e){return 1===e.nativeEvent.button}function ne(e,t,n){return fetch(e).then((function(e){return e.arrayBuffer()})).then((function(e){return new File([e],t,{type:n})}))}var ae="".concat("");function ce(e,t,n,a){return ie.apply(this,arguments)}function ie(){return ie=Object(b.a)(j.a.mark((function e(t,n,a,c){var i,r,o,s;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(i=new FormData).append("image",t),r=q(n),i.append("mask",r),o=a.hdSettings[a.model],i.append("ldmSteps",a.ldmSteps.toString()),i.append("ldmSampler",a.ldmSampler.toString()),i.append("zitsWireframe",a.zitsWireframe.toString()),i.append("hdStrategy",o.hdStrategy),i.append("hdStrategyCropMargin",o.hdStrategyCropMargin.toString()),i.append("hdStrategyCropTrigerSize",o.hdStrategyCropTrigerSize.toString()),i.append("hdStrategyResizeLimit",o.hdStrategyResizeLimit.toString()),void 0===c?i.append("sizeLimit","1080"):i.append("sizeLimit",c),e.next=15,fetch("".concat(ae,"/inpaint"),{method:"POST",body:i}).then(function(){var e=Object(b.a)(j.a.mark((function e(t){return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.ok){e.next=2;break}return e.abrupt("return",t.blob());case 2:throw new Error("Something went wrong on server side.");case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}());case 15:return s=e.sent,e.abrupt("return",URL.createObjectURL(s));case 17:case"end":return e.stop()}}),e)}))),ie.apply(this,arguments)}function re(e){var t=new FormData;return t.append("name",e),fetch("".concat(ae,"/model"),{method:"POST",body:t})}function oe(){return fetch("".concat(ae,"/model"),{method:"GET"})}var se=function(e){var t=e.children,n=e.className,a=e.disabled,c=e.icon,i=e.toolTip,r=e.tooltipPosition,o=e.onKeyDown,s=e.onClick,l=e.onDown,u=e.onUp,d=e.style;return Object(m.jsxs)("div",{role:"button","data-tooltip":i,style:d,onKeyDown:o,onClick:function(e){e.currentTarget.blur(),null===s||void 0===s||s()},onPointerDown:function(e){null===l||void 0===l||l(e.nativeEvent)},onPointerUp:function(e){null===u||void 0===u||u(e.nativeEvent)},tabIndex:-1,className:["btn-primary",t?"btn-primary-content":"",!0===a?"btn-primary-disabled":"",i?"info-tooltip":"",r?"info-tooltip-".concat(r):"",n].join(" "),children:[c,t?Object(m.jsx)("span",{children:t}):null]})};se.defaultProps={disabled:!1};var le=se;function ue(e){var t=e.value,n=e.onChange,a=e.onClick,c=e.label,i=e.min,r=e.max,o=((r||100)-(i||0))/100;return Object(m.jsxs)("div",{className:"editor-brush-slider",children:[Object(m.jsx)("span",{children:c}),Object(m.jsx)("input",{type:"range",step:o,min:i,max:r,value:t,onChange:function(e){e.preventDefault(),e.stopPropagation(),n(parseInt(e.currentTarget.value,10))},onClick:a})]})}var de=["720","1080","2000","Original"];function je(e){var t=e.originalHeight,n=e.originalWidth,c=e.onChange,i=Object(a.useState)("Original"),r=Object(s.a)(i,2),o=r[0],l=r[1],u=Math.max(n,t),d=Object(a.useCallback)((function(e){if("Original"===e)return"".concat(n,"x").concat(t);var a=parseInt(e,10)/u;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,u]),j=Object(a.useCallback)((function(){for(var e=[],t=0;t<de.length;t+=1)"Original"===de[t]&&e.push(d(de[t])),parseInt(de[t],10)<u&&e.push(d(de[t]));return e}),[u,d]);return Object(m.jsx)(w,{width:100,autoFocusAfterClose:!1,value:d(o.toString()),options:j(),onChange:function(e){var a=e.split("x");n>t?(l(a[0]),c(parseInt(a[0],10))):(l(a[1]),c(parseInt(a[1],10)))},chevronDirection:"up"})}var be="#ffcc00bb";function he(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:be;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 fe(e){var t=e.nativeEvent;return{x:t.offsetX,y:t.offsetY}}function pe(e){var t=e.file,n=Object(o.e)(F),c=Object(o.d)(A),i=Object(s.a)(c,2),r=(i[0],i[1]),u=Object(a.useState)(40),d=Object(s.a)(u,2),h=d[0],f=d[1],p=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),O=Object(s.a)(p,2),g=O[0],x=O[1],w=Object(a.useState)([]),y=Object(s.a)(w,2),C=y[0],k=y[1],S=Object(a.useState)(),M=Object(s.a)(S,2),L=M[0],N=M[1],I=Object(a.useState)((function(){return document.createElement("canvas")})),z=Object(s.a)(I,1)[0],D=Object(a.useState)([]),E=Object(s.a)(D,2),T=E[0],Z=E[1],R=Object(a.useState)([]),H=Object(s.a)(R,2),P=H[0],V=H[1],W=Object(a.useState)({x:-1,y:-1}),U=Object(s.a)(W,2),K=U[0],G=K.x,_=K.y,J=U[1],$=Object(a.useState)(!1),q=Object(s.a)($,2),ae=q[0],ie=q[1],re=Object(a.useState)(!1),oe=Object(s.a)(re,2),se=oe[0],de=oe[1],be=Object(a.useState)(!1),pe=Object(s.a)(be,2),Oe=pe[0],ve=pe[1],ge=Object(a.useState)(!1),me=Object(s.a)(ge,2),xe=me[0],we=me[1],ye=Object(a.useState)(!1),Ce=Object(s.a)(ye,2),ke=Ce[0],Se=Ce[1],Me=Object(a.useState)(1),Le=Object(s.a)(Me,2),Ne=Le[0],Ie=Le[1],ze=Object(a.useState)(!1),De=Object(s.a)(ze,2),Ee=De[0],Te=De[1],Ze=Object(a.useState)(1),Re=Object(s.a)(Ze,2),Ae=Re[0],He=Re[1],Pe=Object(a.useState)(1080),Ve=Object(s.a)(Pe,2),We=Ve[0],Fe=Ve[1],Ue=Object(Q.a)(),Be=Ue.width/2,Ke=Ue.height/2,Ge=Object(a.useRef)(),_e=Object(a.useState)(!1),Je=Object(s.a)(_e,2),$e=Je[0],Ye=Je[1],Qe=Object(a.useState)(!1),Xe=Object(s.a)(Qe,2),qe=Xe[0],et=Xe[1],tt=Object(a.useState)(!1),nt=Object(s.a)(tt,2),at=nt[0],ct=nt[1],it=Object(a.useState)(0),rt=Object(s.a)(it,2),ot=rt[0],st=rt[1],lt=Object(a.useState)([]),ut=Object(s.a)(lt,2),dt=ut[0],jt=ut[1],bt=Object(a.useState)([]),ht=Object(s.a)(bt,2),ft=ht[0],pt=ht[1],Ot=Object(a.useState)([]),vt=Object(s.a)(Ot,2),gt=vt[0],mt=vt[1],xt=Object(a.useCallback)((function(e,t){L&&(L.clearRect(0,0,L.canvas.width,L.canvas.height),L.drawImage(e,0,0,g.naturalWidth,g.naturalHeight),he(L,t))}),[L,g]),wt=function(e){if(!(null===L||void 0===L?void 0:L.canvas.width)||!(null===L||void 0===L?void 0:L.canvas.height))throw new Error("canvas has invalid size");z.width=null===L||void 0===L?void 0:L.canvas.width,z.height=null===L||void 0===L?void 0:L.canvas.height;var t=z.getContext("2d");if(!t)throw new Error("could not retrieve mask canvas");e.forEach((function(e){he(t,e,"white")}))},yt=function(){var e=Object(b.a)(j.a.mark((function e(){var a,c,i,o,s,l;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Ct()){e.next=2;break}return e.abrupt("return");case 2:if(a=[].concat(Object(B.a)(T),[P]),V([]),et(!1),Se(!0),n.graduallyInpainting?wt([P]):wt(a),c=t,!(!0===n.graduallyInpainting&&C.length>0)){e.next=14;break}return console.info("gradually inpainting on last result"),i=C[C.length-1],e.next=13,ne(i.currentSrc,t.name,t.type);case 13:c=e.sent;case 14:return e.prev=14,e.next=17,ce(c,z.toDataURL(),n,We.toString());case 17:if(o=e.sent){e.next=20;break}throw new Error("empty response");case 20:return s=new Image,e.next=23,ee(s,o);case 23:l=[].concat(Object(B.a)(C),[s]),k(l),xt(s,[]),Z(a),Nt(),e.next=34;break;case 30:e.prev=30,e.t0=e.catch(14),r({open:!0,desc:e.t0.message?e.t0.message:e.t0.toString(),state:"error",duration:2e3}),St([]);case 34:Se(!1);case 35:case"end":return e.stop()}}),e,null,[[14,30]])})));return function(){return e.apply(this,arguments)}}(),Ct=function(){return 0!==P.length},kt=function(){return 0!==C.length},St=Object(a.useCallback)((function(e){0===C.length?xt(g,e):xt(C[C.length-1],e)}),[g,C,xt]),Mt=function(e){return"Control"===e.key||"Meta"===e.key};Object(X.a)(Mt,(function(){at&&(ke||(ct(!1),n.runInpaintingManually||yt()))}),{event:"keyup"},[ke,at,Ct]),Object(X.a)(Mt,(function(){ke||ct(!0)}),{event:"keydown"},[ke]),Object(a.useEffect)((function(){if(x){var e=Ue.width/g.naturalWidth,t=(Ue.height-200)/g.naturalHeight,n=1;if((e<1||t<1)&&(n=Math.min(e,t)),He(n),Ie(n),(null===L||void 0===L?void 0:L.canvas)&&(L.canvas.width=g.naturalWidth,L.canvas.height=g.naturalHeight,St([])),!$e){var a;null===(a=Ge.current)||void 0===a||a.centerView(n,1),Ye(!0);var c=Math.max(g.width,g.height);Fe(c)}}}),[null===L||void 0===L?void 0:L.canvas,Ge,g,x,Ue,$e,St]);var Lt=Object(a.useCallback)((function(){if(Ae&&g&&Ue){var e=Ge.current;if(e){var t=(Ue.width-g.width*Ae)/2,n=(Ue.height-g.height*Ae)/2;e.setTransform(t,n,Ae,200,"easeOutQuad"),e.state.scale=Ae,Ie(Ae),Te(!1)}}}),[Ge,Ue,g,g.width,Ue.height,Ae]),Nt=function(){pt([]),mt([]),jt([])};Object(a.useEffect)((function(){return window.addEventListener("resize",(function(){Lt()})),function(){window.removeEventListener("resize",(function(){Lt()}))}}),[Ue,Lt]);Object(X.a)("Escape",(function(){ke||(qe||at?(et(!1),V([]),St([])):Lt())}),{event:"keydown"},[qe,ke,at,Lt,St]);var It=Object(a.useCallback)((function(){if(0!==P.length){var e=P.pop(),t=[].concat(Object(B.a)(ft),[e]);pt(t);var n=Object(B.a)(P);V(n),St(n)}}),[P,ft,St]),zt=Object(a.useCallback)((function(){if(C.length){var e=T.pop();mt([].concat(Object(B.a)(gt),[e])),pt([]),Z(Object(B.a)(T)),V([]),et(!1);var t=C.pop();jt([].concat(Object(B.a)(dt),[t]));var n=Object(B.a)(C);k(n),0===n.length?xt(g,[]):xt(n[n.length-1],[])}}),[xt,C,dt,gt,T,g]),Dt=function(){n.runInpaintingManually&&0!==P.length?It():zt()};Object(X.a)((function(e){var t=(e.metaKey||e.ctrlKey)&&!e.shiftKey&&"z"===e.key;return"Tab"===e.key&&e.preventDefault(),!!t&&(e.preventDefault(),console.log("undo"),!0)}),Dt,void 0,[It,zt]);var Et=Object(a.useCallback)((function(){if(0!==ft.length){var e=ft.pop();pt(Object(B.a)(ft));var t=[].concat(Object(B.a)(P),[e]);V(t),St(t)}}),[P,ft,St]),Tt=Object(a.useCallback)((function(){if(0!==dt.length){var e=gt.pop();mt(Object(B.a)(gt)),Z([].concat(Object(B.a)(T),[e])),V([]),et(!1);var t=dt.pop(),n=[].concat(Object(B.a)(C),[t]);k(n),xt(n[n.length-1],[])}}),[xt,C,dt,gt,T,g]),Zt=function(){n.runInpaintingManually&&0!==ft.length?Et():Tt()};Object(X.a)((function(e){var t=(e.metaKey||e.ctrlKey)&&e.shiftKey&&"z"===e.key.toLowerCase();return"Tab"===e.key&&e.preventDefault(),!!t&&(e.preventDefault(),console.log("redo"),!0)}),Zt,void 0,[Et,Tt]);Object(l.a)("Tab",(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),kt()&&we((function(){return window.setTimeout((function(){st(100)}),10),!0}))}),(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),kt()&&(st(0),window.setTimeout((function(){we(!1)}),350))}));var Rt=function(e){e===ae||Oe||ie(e)},At=Object(a.useCallback)((function(){return Oe?"grab":ae?"none":void 0}),[ae,Oe]);Object(l.a)("[",(function(){f((function(e){return e>10?e-10:e<=10&&e>0?e-5:e}))})),Object(l.a)("]",(function(){f((function(e){return e+10}))})),Object(l.a)("R",(function(){n.runInpaintingManually&&Ct()&&yt()})),Object(l.a)(" ",(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),ie(!1),ve(!0)}),(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),ie(!0),ve(!1)}));var Ht=function(e,t){var n=function(){var e,t,n=Ae;return void 0!==(null===(e=Ge.current)||void 0===e?void 0:e.state.scale)&&(n=null===(t=Ge.current)||void 0===t?void 0:t.state.scale),n}();return{width:"".concat(h*n,"px"),height:"".concat(h*n,"px"),left:"".concat(e,"px"),top:"".concat(t,"px"),transform:"translate(-50%, -50%)"}};return Object(m.jsxs)("div",{className:"editor-container","aria-hidden":"true",onMouseMove:function(e){var t=e.nativeEvent;J({x:t.pageX,y:t.pageY})},onMouseUp:function(e){(te(e)&&ve(!1),Oe)||g.src&&(null===L||void 0===L?void 0:L.canvas)&&(ke||qe&&(at||n.runInpaintingManually?et(!1):yt()))},children:[Object(m.jsx)(Y.b,{ref:function(e){e&&(Ge.current=e)},panning:{disabled:!Oe,velocityDisabled:!0},wheel:{step:.05},centerZoomedOut:!0,alignmentAnimation:{disabled:!0},limitToBounds:!1,doubleClick:{disabled:!0},initialScale:Ae,minScale:Ae,onPanning:function(e){Ee||Te(!0)},onZoom:function(e){Ie(e.state.scale)},children:Object(m.jsx)(Y.a,{contentClass:ke?"editor-canvas-loading":"",contentStyle:{visibility:$e?"visible":"hidden"},children:Object(m.jsxs)("div",{className:"editor-canvas-container",children:[Object(m.jsx)("canvas",{className:"editor-canvas",style:{cursor:At(),clipPath:"inset(0 ".concat(ot,"% 0 0)"),transition:"clip-path 350ms ease-in-out"},onContextMenu:function(e){e.preventDefault()},onMouseOver:function(){Rt(!0),de(!1)},onFocus:function(){return Rt(!0)},onMouseLeave:function(){return Rt(!1)},onMouseDown:function(e){if(!Oe&&(g.src&&(null===L||void 0===L?void 0:L.canvas)&&!ke&&!function(e){return 2===e.nativeEvent.button}(e)))if(te(e))ve(!0);else{et(!0);var t=[];(at||n.runInpaintingManually)&&(t=Object(B.a)(P)),t.push({size:h,pts:[fe(e)]}),V(t),St(t)}},onMouseMove:function(e){if(!Oe&&qe&&0!==P.length){var t=Object(B.a)(P);t[t.length-1].pts.push(fe(e)),V(t),St(t)}},ref:function(e){if(e&&!L){var t=e.getContext("2d");t&&N(t)}}}),Object(m.jsxs)("div",{className:"original-image-container",style:{width:"".concat(g.naturalWidth,"px"),height:"".concat(g.naturalHeight,"px")},children:[xe&&Object(m.jsx)("div",{className:"editor-slider",style:{marginRight:"".concat(ot,"%")}}),Object(m.jsx)("img",{className:"original-image",src:g.src,alt:"original",style:{width:"".concat(g.naturalWidth,"px"),height:"".concat(g.naturalHeight,"px")}})]})]})})}),ae&&!ke&&!Oe&&Object(m.jsx)("div",{className:"brush-shape",style:Ht(G,_)}),se&&Object(m.jsx)("div",{className:"brush-shape",style:Ht(Be,Ke)}),Object(m.jsxs)("div",{className:"editor-toolkit-panel",children:[Object(m.jsx)(je,{onChange:function(e){Fe(e)},originalWidth:g.naturalWidth,originalHeight:g.naturalHeight}),Object(m.jsx)(ue,{label:"Brush",min:10,max:150,value:h,onChange:function(e){f(e),se||(de(!0),window.setTimeout((function(){de(!1)}),1e4))},onClick:function(){return de(!1)}}),Object(m.jsxs)("div",{className:"editor-toolkit-btns",children:[Object(m.jsx)(le,{toolTip:"Reset Zoom & Pan",tooltipPosition:"top",icon:Object(m.jsx)(v.a,{}),disabled:Ne===Ae&&!1===Ee,onClick:Lt}),Object(m.jsx)(le,{toolTip:"Undo",tooltipPosition:"top",icon:Object(m.jsx)("svg",{width:"19",height:"9",viewBox:"0 0 19 9",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(m.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:Dt,disabled:function(){if(ke)return!0;if(C.length>0)return!1;if(n.runInpaintingManually){if(0===P.length)return!0}else if(0===C.length)return!0;return!1}()}),Object(m.jsx)(le,{toolTip:"Redo",tooltipPosition:"top",icon:Object(m.jsx)("svg",{width:"19",height:"9",viewBox:"0 0 19 9",fill:"none",xmlns:"http://www.w3.org/2000/svg",transform:"scale(-1,1)",children:Object(m.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:Zt,disabled:function(){if(ke)return!0;if(dt.length>0)return!1;if(n.runInpaintingManually){if(0===ft.length)return!0}else if(0===dt.length)return!0;return!1}()}),Object(m.jsx)(le,{toolTip:"Show Original",tooltipPosition:"top",icon:Object(m.jsx)(v.g,{}),className:xe?"eyeicon-active":"",onDown:function(e){e.preventDefault(),we((function(){return window.setTimeout((function(){st(100)}),10),!0}))},onUp:function(){st(0),window.setTimeout((function(){we(!1)}),350)},disabled:0===C.length}),Object(m.jsx)(le,{toolTip:"Save Image",tooltipPosition:"top",icon:Object(m.jsx)(v.e,{}),disabled:!C.length,onClick:function(){var e=t.name.replace(/(\.[\w\d_-]+)$/i,"_cleanup$1");if(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)}(C[C.length-1].currentSrc,e),n.downloadMask){var a=t.name.replace(/(\.[\w\d_-]+)$/i,"_mask$1");a=a.replace(/\.[^/.]+$/,".jpg"),wt(T);var c=document.createElement("a");c.download=a,c.href=z.toDataURL("image/jpeg"),c.click()}}}),n.runInpaintingManually&&Object(m.jsx)(le,{toolTip:"Run Inpainting",tooltipPosition:"top",icon:Object(m.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(m.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:!Ct()||ke,onClick:function(){!ke&&Ct()&&yt()}})]})]})]})}var Oe=n(26),ve=c.a.forwardRef((function(e,t){var n=e.show,a=e.children,c=e.onClose,i=e.className,r=e.title;return Object(m.jsx)(Oe.d,{open:n,onOpenChange:function(e){e||null===c||void 0===c||c()},children:Object(m.jsxs)(Oe.c,{children:[Object(m.jsx)(Oe.b,{className:"modal-mask"}),Object(m.jsxs)(Oe.a,{ref:t,className:"modal ".concat(i),children:[Object(m.jsxs)("div",{className:"modal-header",children:[Object(m.jsx)(Oe.e,{children:r}),Object(m.jsx)(le,{icon:Object(m.jsx)(v.k,{}),onClick:c})]}),a]})]})})}));function ge(e){var t=e.content,n=e.keys;return Object(m.jsxs)("div",{className:"shortcut-option",children:[Object(m.jsx)("div",{className:"shortcut-description",children:t}),Object(m.jsx)("div",{style:{display:"flex",justifySelf:"end",gap:"8px"},children:n.map((function(e,t){return Object(m.jsx)("div",{className:"shortcut-key",children:e},e)}))})]})}var me=/macintosh|mac os x/i.test(navigator.userAgent),xe=(/windows|win32/i.test(navigator.userAgent),me?"Cmd":"Ctrl");function we(){var e=Object(o.d)(H),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(m.jsx)(ve,{onClose:function(){a(!1)},title:"Hotkeys",className:"modal-shortcuts",show:n,children:Object(m.jsxs)("div",{className:"shortcut-options",children:[Object(m.jsx)(ge,{content:"Multi-Stroke Mask Drawing",keys:["Hold ".concat(xe)]}),Object(m.jsx)(ge,{content:"Cancel Mask Drawing",keys:["Esc"]}),Object(m.jsx)(ge,{content:"Run Inpainting Manually",keys:["Shift","R"]}),Object(m.jsx)(ge,{content:"Undo Inpainting",keys:[xe,"Z"]}),Object(m.jsx)(ge,{content:"Redo Inpainting",keys:[xe,"Shift","Z"]}),Object(m.jsx)(ge,{content:"View Original Image",keys:["Hold Tab"]}),Object(m.jsx)(ge,{content:"Pan",keys:["Space + Drag"]}),Object(m.jsx)(ge,{content:"Reset Zoom/Pan",keys:["Esc"]}),Object(m.jsx)(ge,{content:"Decrease Brush Size",keys:["["]}),Object(m.jsx)(ge,{content:"Increase Brush Size",keys:["]"]}),Object(m.jsx)(ge,{content:"Toggle Dark Mode",keys:["Shift","D"]}),Object(m.jsx)(ge,{content:"Toggle Hotkeys Panel",keys:["H"]})]})})}var ye=n(46),Ce=["className"],ke=["className"],Se=c.a.forwardRef((function(e,t){var n=e.className,a=Object(y.a)(e,Ce);return Object(m.jsx)(ye.a,Object(h.a)(Object(h.a)({},a),{},{ref:t,className:"switch-root ".concat(n)}))})),Me=c.a.forwardRef((function(e,t){var n=e.className,a=Object(y.a)(e,ke);return Object(m.jsx)(ye.b,Object(h.a)(Object(h.a)({},a),{},{ref:t,className:"switch-thumb ".concat(n)}))})),Le=function(){var e=Object(o.d)(F),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(m.jsx)(L,{title:"Manual Inpainting Mode",input:Object(m.jsx)(Se,{checked:n.runInpaintingManually,onCheckedChange:function(e){a((function(t){return Object(h.a)(Object(h.a)({},t),{},{runInpaintingManually:e})}))},children:Object(m.jsx)(Me,{})})})};var Ne=function(){var e=Object(o.d)(F),t=Object(s.a)(e,2),n=t[0],a=t[1],c=function(e,t,n){return Object(m.jsx)("div",{style:{display:"flex",gap:"12px"},children:Object(m.jsx)(M,{content:n,children:Object(m.jsx)("a",{className:"model-desc-link",href:n,target:"_blank",rel:"noreferrer noopener",children:Object(m.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(m.jsx)("path",{d:"M7.49933 0.25C3.49635 0.25 0.25 3.49593 0.25 7.50024C0.25 10.703 2.32715 13.4206 5.2081 14.3797C5.57084 14.446 5.70302 14.2222 5.70302 14.0299C5.70302 13.8576 5.69679 13.4019 5.69323 12.797C3.67661 13.235 3.25112 11.825 3.25112 11.825C2.92132 10.9874 2.44599 10.7644 2.44599 10.7644C1.78773 10.3149 2.49584 10.3238 2.49584 10.3238C3.22353 10.375 3.60629 11.0711 3.60629 11.0711C4.25298 12.1788 5.30335 11.8588 5.71638 11.6732C5.78225 11.205 5.96962 10.8854 6.17658 10.7043C4.56675 10.5209 2.87415 9.89918 2.87415 7.12104C2.87415 6.32925 3.15677 5.68257 3.62053 5.17563C3.54576 4.99226 3.29697 4.25521 3.69174 3.25691C3.69174 3.25691 4.30015 3.06196 5.68522 3.99973C6.26337 3.83906 6.8838 3.75895 7.50022 3.75583C8.1162 3.75895 8.73619 3.83906 9.31523 3.99973C10.6994 3.06196 11.3069 3.25691 11.3069 3.25691C11.7026 4.25521 11.4538 4.99226 11.3795 5.17563C11.8441 5.68257 12.1245 6.32925 12.1245 7.12104C12.1245 9.9063 10.4292 10.5192 8.81452 10.6985C9.07444 10.9224 9.30633 11.3648 9.30633 12.0413C9.30633 13.0102 9.29742 13.7922 9.29742 14.0299C9.29742 14.2239 9.42828 14.4496 9.79591 14.3788C12.6746 13.4179 14.75 10.7025 14.75 7.50024C14.75 3.49593 11.5036 0.25 7.49933 0.25Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd"})})})})})},i=function(){return Object(m.jsxs)(m.Fragment,{children:[Object(m.jsx)(z,{title:"Steps",value:"".concat(n.ldmSteps),desc:"Large steps result in better result, but more time-consuming",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})}))}}),Object(m.jsx)(L,{className:"sub-setting-block",title:"Sampler",input:Object(m.jsx)(w,{width:80,value:n.ldmSampler,options:Object.values(I),onChange:function(e){return t=e,void a((function(e){return Object(h.a)(Object(h.a)({},e),{},{ldmSampler:t})}));var t}})})]})};return Object(m.jsx)(L,{className:"model-setting-block",title:"Model",titleSuffix:function(){switch(n.model){case E.LAMA:return c(0,0,"https://github.com/saic-mdal/lama");case E.LDM:return c(0,0,"https://github.com/CompVis/latent-diffusion");case E.ZITS:return c(0,0,"https://github.com/DQiaole/ZITS_inpainting");default:return Object(m.jsx)(m.Fragment,{})}}(),input:Object(m.jsx)(w,{width:80,value:n.model,options:Object.values(E),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 E.LAMA:return;case E.LDM:return i();case E.ZITS:return Object(m.jsx)("div",{children:Object(m.jsx)(L,{className:"sub-setting-block",title:"Wireframe",desc:"Enable edge and line detect",input:Object(m.jsx)(Se,{checked:n.zitsWireframe,onCheckedChange:function(e){a((function(t){return Object(h.a)(Object(h.a)({},t),{},{zitsWireframe:e})}))},children:Object(m.jsx)(Me,{})})})});default:return Object(m.jsx)(m.Fragment,{})}}()})},Ie=function(){var e=Object(o.d)(F),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(m.jsx)(L,{title:"Gradually Inpainting",desc:"If checked, perform inpainting on the last result, otherwise, always run the model on the initial image.",input:Object(m.jsx)(Se,{checked:n.graduallyInpainting,onCheckedChange:function(e){a((function(t){return Object(h.a)(Object(h.a)({},t),{},{graduallyInpainting:e})}))},children:Object(m.jsx)(Me,{})})})},ze=function(){var e=Object(o.d)(F),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(m.jsx)(L,{title:"Download Mask",desc:"Download inpainting result and mask",input:Object(m.jsx)(Se,{checked:n.downloadMask,onCheckedChange:function(e){a((function(t){return Object(h.a)(Object(h.a)({},t),{},{downloadMask:e})}))},children:Object(m.jsx)(Me,{})})})};function De(e){var t=e.onClose,n=Object(o.d)(F),a=Object(s.a)(n,2),c=a[0],i=a[1];return Object(m.jsxs)(ve,{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(m.jsx)(Le,{}),Object(m.jsx)(Ie,{}),Object(m.jsx)(ze,{}),Object(m.jsx)(Ne,{}),Object(m.jsx)(T,{})]})}var Ee=n(32),Te=["state","desc"],Ze=function(){return Object(m.jsx)("span",{className:"loading-icon",children:Object(m.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(m.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"6"}),Object(m.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"22"}),Object(m.jsx)("line",{x1:"4.93",y1:"4.93",x2:"7.76",y2:"7.76"}),Object(m.jsx)("line",{x1:"16.24",y1:"16.24",x2:"19.07",y2:"19.07"}),Object(m.jsx)("line",{x1:"2",y1:"12",x2:"6",y2:"12"}),Object(m.jsx)("line",{x1:"18",y1:"12",x2:"22",y2:"12"}),Object(m.jsx)("line",{x1:"4.93",y1:"19.07",x2:"7.76",y2:"16.24"}),Object(m.jsx)("line",{x1:"16.24",y1:"7.76",x2:"19.07",y2:"4.93"})]})})},Re=a.forwardRef((function(e,t){var n=e.state,a=e.desc,c=Object(y.a)(e,Te);return Object(m.jsxs)(Ee.b,{children:[Object(m.jsxs)(Ee.c,Object(h.a)(Object(h.a)({},c),{},{ref:t,className:"toast-root ".concat(n),children:[Object(m.jsx)("div",{className:"toast-icon",children:function(){switch(n){case"error":return Object(m.jsx)(v.f,{className:"error-icon"});case"success":return Object(m.jsx)(v.b,{className:"success-icon"});case"loading":return Object(m.jsx)(Ze,{});default:return Object(m.jsx)(m.Fragment,{})}}()}),Object(m.jsx)(Ee.a,{className:"toast-desc",children:a})]})),Object(m.jsx)(Ee.d,{className:"toast-viewpoint"})]})}));Re.defaultProps={desc:"",state:"loading"};var Ae=Re,He=function(e){var t=e.file,n=Object(o.d)(F),c=Object(s.a)(n,2),i=c[0],r=c[1],l=Object(o.d)(A),u=Object(s.a)(l,2),d=u[0],f=u[1],p=function(){var e=Object(b.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,oe().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(ae,"/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}),re(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 s}),e)})));return function(){return e.apply(this,arguments)}}();return Object(a.useEffect)((function(){oe().then((function(e){return e.text()})).then((function(e){r((function(t){return Object(h.a)(Object(h.a)({},t),{},{model:e})}))}))}),[r]),Object(m.jsxs)(m.Fragment,{children:[Object(m.jsx)(pe,{file:t}),Object(m.jsx)(De,{onClose:p}),Object(m.jsx)(we,{}),Object(m.jsx)(Ae,Object(h.a)(Object(h.a)({},d),{},{onOpenChange:function(e){f((function(t){return Object(h.a)(Object(h.a)({},t),{},{open:e})}))}}))]})},Pe=function(){var e=Object(o.d)(H),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(m.jsx)("div",{className:"shortcuts",children:Object(m.jsx)(le,{onClick:c,toolTip:"Hotkeys",tooltipPosition:"bottom",disabled:n,style:{border:0},icon:Object(m.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(m.jsx)("rect",{x:"0",y:"0",width:"16",height:"16",fill:"none",stroke:"none"}),Object(m.jsxs)("g",{fill:"currentColor",children:[Object(m.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(m.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"})]})]})})})},Ve=function(){var e=Object(o.d)(F),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(m.jsx)("div",{children:Object(m.jsx)(le,{onClick:function(){a(Object(h.a)(Object(h.a)({},n),{},{show:!n.show}))},toolTip:"Settings",tooltipPosition:"bottom",style:{border:0},icon:Object(m.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(m.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(m.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})})},We=function(){var e=Object(o.d)(R),t=Object(s.a)(e,2),n=t[0],c=t[1],i=K(),r=Object(a.useState)("file-upload-".concat(Math.random().toString())),l=Object(s.a)(r,1)[0];return Object(m.jsxs)("header",{children:[Object(m.jsx)("div",{style:{visibility:n?"visible":"hidden"},children:Object(m.jsx)("label",{htmlFor:l,children:Object(m.jsxs)(le,{icon:Object(m.jsx)(v.j,{}),style:{border:0},children:[Object(m.jsx)("input",{style:{display:"none"},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&&c(n)},accept:"image/png, image/jpeg"}),"desktop"===i?"Upload New":void 0]})})}),Object(m.jsxs)("div",{className:"header-icons-wrapper",children:[Object(m.jsx)($,{}),n&&Object(m.jsxs)("div",{className:"header-icons",children:[Object(m.jsx)(Pe,{}),Object(m.jsx)(Ve,{})]})]})]})};!function(){function e(){return e=Object(b.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 Fe=function(){var e=Object(o.d)(R),t=Object(s.a)(e,2),n=t[0],c=t[1],i=Object(o.d)(J),r=Object(s.a)(i,2),d=r[0],h=r[1],f=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(b.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}();Object(a.useEffect)((function(){c(f)}),[f,c]),Object(l.a)("D",(function(e){null===e||void 0===e||e.preventDefault(),h("light"===d?"dark":"light")})),Object(a.useEffect)((function(){document.body.setAttribute("data-theme",d)}),[d]);var p=Object(a.useMemo)((function(){return Object(u.a)()}),[n]);return Object(m.jsxs)("div",{className:"lama-cleaner",children:[Object(m.jsx)(We,{}),n?Object(m.jsx)(He,{file:n},p):Object(m.jsx)(_,{})]})};r.a.render(Object(m.jsx)(c.a.StrictMode,{children:Object(m.jsx)(o.a,{children:Object(m.jsx)(Fe,{})})}),document.getElementById("root"))}},[[62,1,2]]]);