IOPaint/lama_cleaner/app/build/static/js/main.6b34bb53.chunk.js
2022-06-29 21:56:39 +08:00

1 line
44 KiB
JavaScript

(this["webpackJsonplama-cleaner"]=this["webpackJsonplama-cleaner"]||[]).push([[0],{54:function(e,t,n){},57: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(54),n(11)),s=n(3),l=n(61),u=n(46),j=n(10),d=n.n(j),b=n(13);var h=n(2),f=n(14),p=n(22),O=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(O.jsxs)(p.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(O.jsxs)(p.g,{className:"select-trigger",style:{width:t},ref:s,children:[Object(O.jsx)(p.h,{}),Object(O.jsx)(p.b,{children:"up"===c?Object(O.jsx)(f.d,{}):Object(O.jsx)(f.c,{})})]}),Object(O.jsx)(p.a,{className:"select-content",children:Object(O.jsx)(p.i,{className:"select-viewport",children:i.map((function(e){return Object(O.jsxs)(p.c,{value:e,className:"select-item",children:[Object(O.jsx)(p.e,{children:e}),Object(O.jsx)(p.d,{className:"select-item-indicator",children:Object(O.jsx)(f.b,{})})]},e)}))})})]})};v.defaultProps={chevronDirection:"down",autoFocusAfterClose:!0};var g=v,m=n(4),x=["value","onValue"],w=c.a.forwardRef((function(e,t){var n=e.value,a=e.onValue,c=Object(m.a)(e,x);return Object(O.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"}))})),y=n(26),C=function(e){var t=e.content,n=e.children;return Object(O.jsx)(y.d,{children:Object(O.jsxs)(y.c,{children:[Object(O.jsx)(y.e,{className:"tooltip-trigger",children:n}),Object(O.jsxs)(y.b,{className:"tooltip-content",children:[t,Object(O.jsx)(y.a,{className:"tooltip-arrow"})]})]})})};var k=function(e){var t=e.title,n=e.desc,a=e.input,c=e.optionDesc,i=e.className;return Object(O.jsxs)("div",{className:"setting-block ".concat(i),children:[Object(O.jsxs)("div",{className:"setting-block-content",children:[Object(O.jsxs)("div",{className:"setting-block-content-title",children:[Object(O.jsx)("span",{children:t}),n&&Object(O.jsx)(C,{content:Object(O.jsx)("div",{style:{width:400},children:n}),children:Object(O.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(O.jsx)("path",{d:"M0.877075 7.49972C0.877075 3.84204 3.84222 0.876892 7.49991 0.876892C11.1576 0.876892 14.1227 3.84204 14.1227 7.49972C14.1227 11.1574 11.1576 14.1226 7.49991 14.1226C3.84222 14.1226 0.877075 11.1574 0.877075 7.49972ZM7.49991 1.82689C4.36689 1.82689 1.82708 4.36671 1.82708 7.49972C1.82708 10.6327 4.36689 13.1726 7.49991 13.1726C10.6329 13.1726 13.1727 10.6327 13.1727 7.49972C13.1727 4.36671 10.6329 1.82689 7.49991 1.82689ZM8.24993 10.5C8.24993 10.9142 7.91414 11.25 7.49993 11.25C7.08571 11.25 6.74993 10.9142 6.74993 10.5C6.74993 10.0858 7.08571 9.75 7.49993 9.75C7.91414 9.75 8.24993 10.0858 8.24993 10.5ZM6.05003 6.25C6.05003 5.57211 6.63511 4.925 7.50003 4.925C8.36496 4.925 8.95003 5.57211 8.95003 6.25C8.95003 6.74118 8.68002 6.99212 8.21447 7.27494C8.16251 7.30651 8.10258 7.34131 8.03847 7.37854L8.03841 7.37858C7.85521 7.48497 7.63788 7.61119 7.47449 7.73849C7.23214 7.92732 6.95003 8.23198 6.95003 8.7C6.95004 9.00376 7.19628 9.25 7.50004 9.25C7.8024 9.25 8.04778 9.00601 8.05002 8.70417L8.05056 8.7033C8.05924 8.6896 8.08493 8.65735 8.15058 8.6062C8.25207 8.52712 8.36508 8.46163 8.51567 8.37436L8.51571 8.37433C8.59422 8.32883 8.68296 8.27741 8.78559 8.21506C9.32004 7.89038 10.05 7.35382 10.05 6.25C10.05 4.92789 8.93511 3.825 7.50003 3.825C6.06496 3.825 4.95003 4.92789 4.95003 6.25C4.95003 6.55376 5.19628 6.8 5.50003 6.8C5.80379 6.8 6.05003 6.55376 6.05003 6.25Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd"})})})]}),a]}),c&&Object(O.jsx)("div",{className:"option-desc",children:c})]})};var S,M,L=function(e){var t=e.title,n=e.value,a=e.suffix,c=e.onValue;return Object(O.jsx)(k,{className:"sub-setting-block",title:t,input:Object(O.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:"8px"},children:[Object(O.jsx)(w,{style:{width:"80px"},value:"".concat(n),onValue:c}),a&&Object(O.jsx)("span",{children:a})]})})};!function(e){e.ORIGINAL="Original",e.RESIZE="Resize",e.CROP="Crop"}(S||(S={})),function(e){e.ddim="ddim",e.plms="plms"}(M||(M={}));var N,I=function(){var e=Object(o.c)(H),t=Object(s.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(O.jsxs)("div",{children:["Use the original resolution of the picture, suitable for picture size below 2K. Try"," ",Object(O.jsx)("div",{tabIndex:0,role:"button",className:"inline-tip",onClick:function(){return c(S.RESIZE)},children:"Resize Strategy"})," ","if you do not get good results on high resolution images."]})};return Object(O.jsx)(k,{className:"hd-setting-block",title:"High Resolution Strategy",input:Object(O.jsx)(g,{width:80,value:n.hdStrategy,options:Object.values(S),onChange:function(e){return c(e)}}),optionDesc:function(){switch(n.hdStrategy){case S.ORIGINAL:return u();case S.CROP:return Object(O.jsxs)("div",{children:[Object(O.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(O.jsx)(L,{title:"Trigger size",value:"".concat(n.hdStrategyCropTrigerSize),suffix:"pixel",onValue:r}),Object(O.jsx)(L,{title:"Crop margin",value:"".concat(n.hdStrategyCropMargin),suffix:"pixel",onValue:l})]});case S.RESIZE:return Object(O.jsxs)("div",{children:[Object(O.jsx)("div",{children:"Resize the longer side of the image to a specific size(keep ratio), then do inpainting on the resized image."}),Object(O.jsx)(L,{title:"Size limit",value:"".concat(n.hdStrategyResizeLimit),suffix:"pixel",onValue:i})]});default:return u()}}()})};!function(e){e.LAMA="lama",e.LDM="ldm"}(N||(N={}));var z,E=function(){var e=Object(o.c)(H),t=Object(s.a)(e,2),n=t[0],a=t[1],c=function(e,t,n){return Object(O.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[Object(O.jsx)("a",{className:"model-desc-link",href:t,target:"_blank",rel:"noreferrer noopener",children:e}),Object(O.jsx)("a",{className:"model-desc-link",href:n,target:"_blank",rel:"noreferrer noopener",children:n})]})},i=function(){return Object(O.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(O.jsx)(L,{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})}))}}),Object(O.jsx)(k,{className:"sub-setting-block",title:"Sampler",input:Object(O.jsx)(g,{width:80,value:n.ldmSampler,options:Object.values(M),onChange:function(e){return t=e,void a((function(e){return Object(h.a)(Object(h.a)({},e),{},{ldmSampler:t})}));var t}})})]})};return Object(O.jsx)(k,{className:"model-setting-block",title:"Inpainting Model",input:Object(O.jsx)(g,{width:80,value:n.model,options:Object.values(N),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 N.LAMA:return c("Resolution-robust Large Mask Inpainting with Fourier Convolutions","https://arxiv.org/abs/2109.07161","https://github.com/saic-mdal/lama");case N.LDM:return i();default:return Object(O.jsx)(O.Fragment,{})}}()})},D=Object(o.b)({key:"fileState",default:void 0}),Z=Object(o.b)({key:"toastState",default:{open:!1,desc:"",state:"default",duration:3e3}}),R=Object(o.b)({key:"shortcutsState",default:!1}),T={show:!1,graduallyInpainting:!0,runInpaintingManually:!1,model:N.LAMA,ldmSteps:50,ldmSampler:M.plms,hdStrategy:S.RESIZE,hdStrategyResizeLimit:2048,hdStrategyCropTrigerSize:2048,hdStrategyCropMargin:128},H=Object(o.b)({key:"settingsState",default:T,effects:[(z="settingsState",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(Object(h.a)(Object(h.a)({},T),c))}n((function(e,t,n){return n?localStorage.removeItem(z):localStorage.setItem(z,JSON.stringify(e))}))})]}),V=n(6),A=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 P(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=A();function j(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)(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 v.apply(this,arguments)}function v(){return(v=Object(b.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,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=V.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 m.apply(this,arguments)}function m(){return(m=Object(b.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,x(t);case 3:a=e.sent;case 4:if(!(a.length>0)){e.next=11;break}return n.push.apply(n,Object(V.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)(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(b.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),j(n[0]);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return Object(O.jsx)("label",{htmlFor:l,className:"file-select-label",children:Object(O.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(O.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&&j(n)},accept:"image/png, image/jpeg"}),Object(O.jsx)("p",{className:"file-select-message",children:"desktop"===u?"Click here or drag an image file":"Tap here to load your picture"})]})})}var F=function(){var e=Object(o.e)(D);return Object(O.jsxs)("div",{className:"landing-page",children:[Object(O.jsxs)("h1",{children:["Image inpainting powered by \ud83e\udd99",Object(O.jsx)("a",{href:"https://github.com/saic-mdal/lama",children:"LaMa"})]}),Object(O.jsx)("div",{className:"landing-file-selector",children:Object(O.jsx)(P,{onSelection:function(){var t=Object(b.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)}}()})})]})},B=Object(o.b)({key:"themeState",default:"light"}),U=function(){var e=Object(o.c)(B),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(O.jsx)("div",{className:"theme-toggle-ui",children:Object(O.jsx)("div",{className:"theme-btn",onClick:function(){c("light"===n?"dark":"light")},role:"button",tabIndex:0,"aria-hidden":"true",children:"light"===n?Object(O.jsx)(f.h,{}):Object(O.jsx)(f.i,{style:{color:"#ffcc00"}})})})},W=n(42),K=n(60),G=n(44);function J(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 _(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 Y(e){return 1===e.nativeEvent.button}function X(e,t,n){return fetch(e).then((function(e){return e.arrayBuffer()})).then((function(e){return new File([e],t,{type:n})}))}var $="".concat("");function Q(e,t,n,a){return q.apply(this,arguments)}function q(){return q=Object(b.a)(d.a.mark((function e(t,n,a,c){var i,r,o;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(i=new FormData).append("image",t),r=J(n),i.append("mask",r),i.append("ldmSteps",a.ldmSteps.toString()),i.append("ldmSampler",a.ldmSampler.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=13,fetch("".concat($,"/inpaint"),{method:"POST",body:i}).then(function(){var e=Object(b.a)(d.a.mark((function e(t){return d.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 13:return o=e.sent,e.abrupt("return",URL.createObjectURL(o));case 15:case"end":return e.stop()}}),e)}))),q.apply(this,arguments)}function ee(e){var t=new FormData;return t.append("name",e),fetch("".concat($,"/model"),{method:"POST",body:t})}function te(){return fetch("".concat($,"/model"),{method:"GET"})}var ne=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,j=e.style;return Object(O.jsxs)("div",{role:"button","data-tooltip":i,style:j,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(O.jsx)("span",{children:t}):null]})};ne.defaultProps={disabled:!1};var ae=ne;function ce(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(O.jsxs)("div",{className:"editor-brush-slider",children:[Object(O.jsx)("span",{children:c}),Object(O.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 ie=["720","1080","2000","Original"];function re(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),j=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]),d=Object(a.useCallback)((function(){for(var e=[],t=0;t<ie.length;t+=1)"Original"===ie[t]&&e.push(j(ie[t])),parseInt(ie[t],10)<u&&e.push(j(ie[t]));return e}),[u,j]);return Object(O.jsx)(g,{width:100,autoFocusAfterClose:!1,value:j(o.toString()),options:d(),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 oe="#ffcc00bb";function se(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:oe;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 le(e){var t=e.nativeEvent;return{x:t.offsetX,y:t.offsetY}}function ue(e){var t=e.file,n=Object(o.d)(H),c=Object(o.c)(Z),i=Object(s.a)(c,2),r=(i[0],i[1]),u=Object(a.useState)(40),j=Object(s.a)(u,2),h=j[0],p=j[1],v=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),g=Object(s.a)(v,2),m=g[0],x=g[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],E=Object(a.useState)([]),D=Object(s.a)(E,2),R=D[0],T=D[1],A=Object(a.useState)([]),P=Object(s.a)(A,2),F=P[0],B=P[1],U=Object(a.useState)({x:-1,y:-1}),J=Object(s.a)(U,2),$=J[0],q=$.x,ee=$.y,te=J[1],ne=Object(a.useState)(!1),ie=Object(s.a)(ne,2),oe=ie[0],ue=ie[1],je=Object(a.useState)(!1),de=Object(s.a)(je,2),be=de[0],he=de[1],fe=Object(a.useState)(!1),pe=Object(s.a)(fe,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),Ee=Object(s.a)(ze,2),De=Ee[0],Ze=Ee[1],Re=Object(a.useState)(1),Te=Object(s.a)(Re,2),He=Te[0],Ve=Te[1],Ae=Object(a.useState)(1080),Pe=Object(s.a)(Ae,2),Fe=Pe[0],Be=Pe[1],Ue=Object(K.a)(),We=Ue.width/2,Ke=Ue.height/2,Ge=Object(a.useRef)(),Je=Object(a.useState)(!1),_e=Object(s.a)(Je,2),Ye=_e[0],Xe=_e[1],$e=Object(a.useState)(!1),Qe=Object(s.a)($e,2),qe=Qe[0],et=Qe[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),jt=ut[0],dt=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,m.naturalWidth,m.naturalHeight),se(L,t))}),[L,m]),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){se(t,e,"white")}))},yt=function(){var e=Object(b.a)(d.a.mark((function e(){var a,c,i,o,s,l;return d.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(V.a)(R),[F]),B([]),et(!1),Se(!0),n.graduallyInpainting?wt([F]):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,X(i.currentSrc,t.name,t.type);case 13:c=e.sent;case 14:return e.prev=14,e.next=17,Q(c,z.toDataURL(),n,Fe.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,_(s,o);case 23:l=[].concat(Object(V.a)(C),[s]),k(l),xt(s,[]),T(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!==F.length},kt=function(){return 0!==C.length},St=Object(a.useCallback)((function(e){0===C.length?xt(m,e):xt(C[C.length-1],e)}),[m,C,xt]),Mt=function(e){return"Control"===e.key||"Meta"===e.key};Object(G.a)(Mt,(function(){at&&(ke||(ct(!1),n.runInpaintingManually||yt()))}),{event:"keyup"},[ke,at,Ct]),Object(G.a)(Mt,(function(){ke||ct(!0)}),{event:"keydown"},[ke]),Object(a.useEffect)((function(){if(x){var e=Ue.width/m.naturalWidth,t=(Ue.height-200)/m.naturalHeight,n=1;if((e<1||t<1)&&(n=Math.min(e,t)),Ve(n),Ie(n),(null===L||void 0===L?void 0:L.canvas)&&(L.canvas.width=m.naturalWidth,L.canvas.height=m.naturalHeight,St([])),!Ye){var a;null===(a=Ge.current)||void 0===a||a.centerView(n,1),Xe(!0);var c=Math.max(m.width,m.height);Be(c)}}}),[null===L||void 0===L?void 0:L.canvas,Ge,m,x,Ue,Ye,St]);var Lt=Object(a.useCallback)((function(){if(He&&m&&Ue){var e=Ge.current;if(e){var t=(Ue.width-m.width*He)/2,n=(Ue.height-m.height*He)/2;e.setTransform(t,n,He,200,"easeOutQuad"),e.state.scale=He,Ie(He),Ze(!1)}}}),[Ge,Ue,m,m.width,Ue.height,He]),Nt=function(){pt([]),mt([]),dt([])};Object(a.useEffect)((function(){return window.addEventListener("resize",(function(){Lt()})),function(){window.removeEventListener("resize",(function(){Lt()}))}}),[Ue,Lt]);Object(G.a)("Escape",(function(){ke||(qe||at?(et(!1),B([]),St([])):Lt())}),{event:"keydown"},[qe,ke,at,Lt,St]);var It=Object(a.useCallback)((function(){if(0!==F.length){var e=F.pop(),t=[].concat(Object(V.a)(ft),[e]);pt(t);var n=Object(V.a)(F);B(n),St(n)}}),[F,ft,St]),zt=Object(a.useCallback)((function(){if(C.length){var e=R.pop();mt([].concat(Object(V.a)(gt),[e])),pt([]),T(Object(V.a)(R)),B([]),et(!1);var t=C.pop();dt([].concat(Object(V.a)(jt),[t]));var n=Object(V.a)(C);k(n),0===n.length?xt(m,[]):xt(n[n.length-1],[])}}),[xt,C,jt,gt,R,m]),Et=function(){n.runInpaintingManually&&0!==F.length?It():zt()};Object(G.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)}),Et,void 0,[It,zt]);var Dt=Object(a.useCallback)((function(){if(0!==ft.length){var e=ft.pop();pt(Object(V.a)(ft));var t=[].concat(Object(V.a)(F),[e]);B(t),St(t)}}),[F,ft,St]),Zt=Object(a.useCallback)((function(){if(0!==jt.length){var e=gt.pop();mt(Object(V.a)(gt)),T([].concat(Object(V.a)(R),[e])),B([]),et(!1);var t=jt.pop(),n=[].concat(Object(V.a)(C),[t]);k(n),xt(n[n.length-1],[])}}),[xt,C,jt,gt,R,m]),Rt=function(){n.runInpaintingManually&&0!==ft.length?Dt():Zt()};Object(G.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("redo"),!0)}),Rt,void 0,[Dt,Zt]);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 Tt=function(e){e===oe||Oe||ue(e)},Ht=Object(a.useCallback)((function(){return Oe?"grab":oe?"none":void 0}),[oe,Oe]);Object(l.a)("[",(function(){p((function(e){return e>10?e-10:e<=10&&e>0?e-5:e}))})),Object(l.a)("]",(function(){p((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(),ue(!1),ve(!0)}),(function(e){null===e||void 0===e||e.preventDefault(),null===e||void 0===e||e.stopPropagation(),ue(!0),ve(!1)}));var Vt=function(e,t){var n=function(){var e,t,n=He;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(O.jsxs)("div",{className:"editor-container","aria-hidden":"true",onMouseMove:function(e){var t=e.nativeEvent;te({x:t.pageX,y:t.pageY})},onMouseUp:function(e){(Y(e)&&ve(!1),Oe)||m.src&&(null===L||void 0===L?void 0:L.canvas)&&(ke||qe&&(at||n.runInpaintingManually?et(!1):yt()))},children:[Object(O.jsx)(W.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:He,minScale:He,onPanning:function(e){De||Ze(!0)},onZoom:function(e){Ie(e.state.scale)},children:Object(O.jsx)(W.a,{contentClass:ke?"editor-canvas-loading":"",contentStyle:{visibility:Ye?"visible":"hidden"},children:Object(O.jsxs)("div",{className:"editor-canvas-container",children:[Object(O.jsx)("canvas",{className:"editor-canvas",style:{cursor:Ht(),clipPath:"inset(0 ".concat(ot,"% 0 0)"),transition:"clip-path 350ms ease-in-out"},onContextMenu:function(e){e.preventDefault()},onMouseOver:function(){Tt(!0),he(!1)},onFocus:function(){return Tt(!0)},onMouseLeave:function(){return Tt(!1)},onMouseDown:function(e){if(!Oe&&(m.src&&(null===L||void 0===L?void 0:L.canvas)&&!ke&&!function(e){return 2===e.nativeEvent.button}(e)))if(Y(e))ve(!0);else{et(!0);var t=[];(at||n.runInpaintingManually)&&(t=Object(V.a)(F)),t.push({size:h,pts:[le(e)]}),B(t),St(t)}},onMouseMove:function(e){if(!Oe&&qe&&0!==F.length){var t=Object(V.a)(F);t[t.length-1].pts.push(le(e)),B(t),St(t)}},ref:function(e){if(e&&!L){var t=e.getContext("2d");t&&N(t)}}}),Object(O.jsxs)("div",{className:"original-image-container",style:{width:"".concat(m.naturalWidth,"px"),height:"".concat(m.naturalHeight,"px")},children:[xe&&Object(O.jsx)("div",{className:"editor-slider",style:{marginRight:"".concat(ot,"%")}}),Object(O.jsx)("img",{className:"original-image",src:m.src,alt:"original",style:{width:"".concat(m.naturalWidth,"px"),height:"".concat(m.naturalHeight,"px")}})]})]})})}),oe&&!ke&&!Oe&&Object(O.jsx)("div",{className:"brush-shape",style:Vt(q,ee)}),be&&Object(O.jsx)("div",{className:"brush-shape",style:Vt(We,Ke)}),Object(O.jsxs)("div",{className:"editor-toolkit-panel",children:[Object(O.jsx)(re,{onChange:function(e){Be(e)},originalWidth:m.naturalWidth,originalHeight:m.naturalHeight}),Object(O.jsx)(ce,{label:"Brush",min:10,max:150,value:h,onChange:function(e){p(e),be||(he(!0),window.setTimeout((function(){he(!1)}),1e4))},onClick:function(){return he(!1)}}),Object(O.jsxs)("div",{className:"editor-toolkit-btns",children:[Object(O.jsx)(ae,{toolTip:"Reset Zoom & Pan",tooltipPosition:"top",icon:Object(O.jsx)(f.a,{}),disabled:Ne===He&&!1===De,onClick:Lt}),Object(O.jsx)(ae,{toolTip:"Undo",tooltipPosition:"top",icon:Object(O.jsx)("svg",{width:"19",height:"9",viewBox:"0 0 19 9",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(O.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:Et,disabled:function(){if(ke)return!0;if(C.length>0)return!1;if(n.runInpaintingManually){if(0===F.length)return!0}else if(0===C.length)return!0;return!1}()}),Object(O.jsx)(ae,{toolTip:"Redo",tooltipPosition:"top",icon:Object(O.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(O.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:Rt,disabled:function(){if(ke)return!0;if(jt.length>0)return!1;if(n.runInpaintingManually){if(0===ft.length)return!0}else if(0===jt.length)return!0;return!1}()}),Object(O.jsx)(ae,{toolTip:"Show Original",tooltipPosition:"top",icon:Object(O.jsx)(f.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(O.jsx)(ae,{toolTip:"Save Image",tooltipPosition:"top",icon:Object(O.jsx)(f.e,{}),disabled:!C.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)}(C[C.length-1].currentSrc,e)}}),n.runInpaintingManually&&Object(O.jsx)(ae,{toolTip:"Run Inpainting",tooltipPosition:"top",icon:Object(O.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:Object(O.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 je=n(27),de=c.a.forwardRef((function(e,t){var n=e.show,a=e.children,c=e.onClose,i=e.className,r=e.title;return Object(O.jsx)(je.d,{open:n,onOpenChange:function(e){e||null===c||void 0===c||c()},children:Object(O.jsxs)(je.c,{children:[Object(O.jsx)(je.b,{className:"modal-mask"}),Object(O.jsxs)(je.a,{ref:t,className:"modal ".concat(i),children:[Object(O.jsxs)("div",{className:"modal-header",children:[Object(O.jsx)(je.e,{children:r}),Object(O.jsx)(ae,{icon:Object(O.jsx)(f.k,{}),onClick:c})]}),a]})]})})}));function be(e){var t=e.content,n=e.keys;return Object(O.jsxs)("div",{className:"shortcut-option",children:[Object(O.jsx)("div",{className:"shortcut-description",children:t}),Object(O.jsx)("div",{style:{display:"flex",justifySelf:"end",gap:"8px"},children:n.map((function(e,t){return Object(O.jsx)("div",{className:"shortcut-key",children:e},e)}))})]})}var he=/macintosh|mac os x/i.test(navigator.userAgent),fe=(/windows|win32/i.test(navigator.userAgent),he?"Cmd":"Ctrl");function pe(){var e=Object(o.c)(R),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(O.jsx)(de,{onClose:function(){a(!1)},title:"Hotkeys",className:"modal-shortcuts",show:n,children:Object(O.jsxs)("div",{className:"shortcut-options",children:[Object(O.jsx)(be,{content:"Enable Multi-Stroke Mask Drawing",keys:["Hold ".concat(fe)]}),Object(O.jsx)(be,{content:"Undo Inpainting",keys:[fe,"Z"]}),Object(O.jsx)(be,{content:"Pan",keys:["Space & Drag"]}),Object(O.jsx)(be,{content:"View Original Image",keys:["Hold Tab"]}),Object(O.jsx)(be,{content:"Reset Zoom/Pan",keys:["Esc"]}),Object(O.jsx)(be,{content:"Cancel Mask Drawing",keys:["Esc"]}),Object(O.jsx)(be,{content:"Run Inpainting Manually",keys:["Shift","R"]}),Object(O.jsx)(be,{content:"Decrease Brush Size",keys:["["]}),Object(O.jsx)(be,{content:"Increase Brush Size",keys:["]"]}),Object(O.jsx)(be,{content:"Toggle Dark Mode",keys:["Shift","D"]}),Object(O.jsx)(be,{content:"Toggle Hotkeys Panel",keys:["H"]})]})})}var Oe=n(43),ve=["className"],ge=["className"],me=c.a.forwardRef((function(e,t){var n=e.className,a=Object(m.a)(e,ve);return Object(O.jsx)(Oe.a,Object(h.a)(Object(h.a)({},a),{},{ref:t,className:"switch-root ".concat(n)}))})),xe=c.a.forwardRef((function(e,t){var n=e.className,a=Object(m.a)(e,ge);return Object(O.jsx)(Oe.b,Object(h.a)(Object(h.a)({},a),{},{ref:t,className:"switch-thumb ".concat(n)}))})),we=function(){var e=Object(o.c)(H),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(O.jsx)(k,{title:"Manual Inpainting Mode",input:Object(O.jsx)(me,{checked:n.runInpaintingManually,onCheckedChange:function(e){a((function(t){return Object(h.a)(Object(h.a)({},t),{},{runInpaintingManually:e})}))},children:Object(O.jsx)(xe,{})})})},ye=function(){var e=Object(o.c)(H),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(O.jsx)(k,{title:"Gradually Inpainting",desc:"If checked, perform inpainting on the last result, otherwise, always run the model on the initial image.",input:Object(O.jsx)(me,{checked:n.graduallyInpainting,onCheckedChange:function(e){a((function(t){return Object(h.a)(Object(h.a)({},t),{},{graduallyInpainting:e})}))},children:Object(O.jsx)(xe,{})})})};function Ce(e){var t=e.onClose,n=Object(o.c)(H),a=Object(s.a)(n,2),c=a[0],i=a[1];return Object(O.jsxs)(de,{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(O.jsx)(we,{}),Object(O.jsx)(ye,{}),Object(O.jsx)(E,{}),Object(O.jsx)(I,{})]})}var ke=n(32),Se=["state","desc"],Me=function(){return Object(O.jsx)("span",{className:"loading-icon",children:Object(O.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(O.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"6"}),Object(O.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"22"}),Object(O.jsx)("line",{x1:"4.93",y1:"4.93",x2:"7.76",y2:"7.76"}),Object(O.jsx)("line",{x1:"16.24",y1:"16.24",x2:"19.07",y2:"19.07"}),Object(O.jsx)("line",{x1:"2",y1:"12",x2:"6",y2:"12"}),Object(O.jsx)("line",{x1:"18",y1:"12",x2:"22",y2:"12"}),Object(O.jsx)("line",{x1:"4.93",y1:"19.07",x2:"7.76",y2:"16.24"}),Object(O.jsx)("line",{x1:"16.24",y1:"7.76",x2:"19.07",y2:"4.93"})]})})},Le=a.forwardRef((function(e,t){var n=e.state,a=e.desc,c=Object(m.a)(e,Se);return Object(O.jsxs)(ke.b,{children:[Object(O.jsxs)(ke.c,Object(h.a)(Object(h.a)({},c),{},{ref:t,className:"toast-root ".concat(n),children:[Object(O.jsx)("div",{className:"toast-icon",children:function(){switch(n){case"error":return Object(O.jsx)(f.f,{className:"error-icon"});case"success":return Object(O.jsx)(f.b,{className:"success-icon"});case"loading":return Object(O.jsx)(Me,{});default:return Object(O.jsx)(O.Fragment,{})}}()}),Object(O.jsx)(ke.a,{className:"toast-desc",children:a})]})),Object(O.jsx)(ke.d,{className:"toast-viewpoint"})]})}));Le.defaultProps={desc:"",state:"loading"};var Ne=Le,Ie=function(e){var t=e.file,n=Object(o.c)(H),c=Object(s.a)(n,2),i=c[0],r=c[1],l=Object(o.c)(Z),u=Object(s.a)(l,2),j=u[0],f=u[1],p=function(){var e=Object(b.a)(d.a.mark((function e(){var t,n,a,c,o;return d.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,te().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($,"/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}),ee(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(){te().then((function(e){return e.text()})).then((function(e){r((function(t){return Object(h.a)(Object(h.a)({},t),{},{model:e})}))}))}),[r]),Object(O.jsxs)(O.Fragment,{children:[Object(O.jsx)(ue,{file:t}),Object(O.jsx)(Ce,{onClose:p}),Object(O.jsx)(pe,{}),Object(O.jsx)(Ne,Object(h.a)(Object(h.a)({},j),{},{onOpenChange:function(e){f((function(t){return Object(h.a)(Object(h.a)({},t),{},{open:e})}))}}))]})},ze=function(){var e=Object(o.c)(R),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(O.jsx)("div",{className:"shortcuts",children:Object(O.jsx)(ae,{onClick:c,toolTip:"Hotkeys",tooltipPosition:"bottom",disabled:n,style:{border:0},icon:Object(O.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(O.jsx)("rect",{x:"0",y:"0",width:"16",height:"16",fill:"none",stroke:"none"}),Object(O.jsxs)("g",{fill:"currentColor",children:[Object(O.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(O.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"})]})]})})})},Ee=function(){var e=Object(o.c)(H),t=Object(s.a)(e,2),n=t[0],a=t[1];return Object(O.jsx)("div",{children:Object(O.jsx)(ae,{onClick:function(){a(Object(h.a)(Object(h.a)({},n),{},{show:!n.show}))},toolTip:"Settings",tooltipPosition:"bottom",style:{border:0},icon:Object(O.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(O.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(O.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})})},De=function(){var e=Object(o.c)(D),t=Object(s.a)(e,2),n=t[0],c=t[1],i=A(),r=Object(a.useState)("file-upload-".concat(Math.random().toString())),l=Object(s.a)(r,1)[0];return Object(O.jsxs)("header",{children:[Object(O.jsx)("div",{style:{visibility:n?"visible":"hidden"},children:Object(O.jsx)("label",{htmlFor:l,children:Object(O.jsxs)(ae,{icon:Object(O.jsx)(f.j,{}),style:{border:0},children:[Object(O.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(O.jsxs)("div",{className:"header-icons-wrapper",children:[Object(O.jsx)(U,{}),n&&Object(O.jsxs)("div",{className:"header-icons",children:[Object(O.jsx)(ze,{}),Object(O.jsx)(Ee,{})]})]})]})};!function(){function e(){return e=Object(b.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 Ze=function(){var e=Object(o.c)(D),t=Object(s.a)(e,2),n=t[0],c=t[1],i=Object(o.c)(B),r=Object(s.a)(i,2),j=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)(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}();Object(a.useEffect)((function(){c(f)}),[f,c]),Object(l.a)("D",(function(e){null===e||void 0===e||e.preventDefault(),h("light"===j?"dark":"light")})),Object(a.useEffect)((function(){document.body.setAttribute("data-theme",j)}),[j]);var p=Object(a.useMemo)((function(){return Object(u.a)()}),[n]);return Object(O.jsxs)("div",{className:"lama-cleaner",children:[Object(O.jsx)(De,{}),n?Object(O.jsx)(Ie,{file:n},p):Object(O.jsx)(F,{})]})};r.a.render(Object(O.jsx)(c.a.StrictMode,{children:Object(O.jsx)(o.a,{children:Object(O.jsx)(Ze,{})})}),document.getElementById("root"))}},[[57,1,2]]]);