(function(){"use strict";var it=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof{}<"u"?{}:typeof self<"u"?self:{},G={},rt={get exports(){return G},set exports(r){G=r}};(function(r,i){(function(c,f){r.exports=f()})(it,function(){var c=1e3,f=6e4,y=36e5,w="millisecond",$="second",S="minute",_="hour",v="day",O="week",M="month",A="quarter",h="year",Y="date",et="Invalid Date",ht=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,mt=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,pt={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(s){var n=["th","st","nd","rd"],t=s%100;return"["+s+(n[(t-20)%10]||n[t]||n[0])+"]"}},V=function(s,n,t){var o=String(s);return!o||o.length>=n?s:""+Array(n+1-o.length).join(t)+s},$t={s:V,z:function(s){var n=-s.utcOffset(),t=Math.abs(n),o=Math.floor(t/60),e=t%60;return(n<=0?"+":"-")+V(o,2,"0")+":"+V(e,2,"0")},m:function s(n,t){if(n.date()<t.date())return-s(t,n);var o=12*(t.year()-n.year())+(t.month()-n.month()),e=n.clone().add(o,M),u=t-e<0,a=n.clone().add(o+(u?-1:1),M);return+(-(o+(t-e)/(u?e-a:a-e))||0)},a:function(s){return s<0?Math.ceil(s)||0:Math.floor(s)},p:function(s){return{M,y:h,w:O,d:v,D:Y,h:_,m:S,s:$,ms:w,Q:A}[s]||String(s||"").toLowerCase().replace(/s$/,"")},u:function(s){return s===void 0}},I="en",q={};q[I]=pt;var Z=function(s){return s instanceof U},P=function s(n,t,o){var e;if(!n)return I;if(typeof n=="string"){var u=n.toLowerCase();q[u]&&(e=u),t&&(q[u]=t,e=u);var a=n.split("-");if(!e&&a.length>1)return s(a[0])}else{var d=n.name;q[d]=n,e=d}return!o&&e&&(I=e),e||!o&&I},g=function(s,n){if(Z(s))return s.clone();var t=typeof n=="object"?n:{};return t.date=s,t.args=arguments,new U(t)},l=$t;l.l=P,l.i=Z,l.w=function(s,n){return g(s,{locale:n.$L,utc:n.$u,x:n.$x,$offset:n.$offset})};var U=function(){function s(t){this.$L=P(t.locale,null,!0),this.parse(t)}var n=s.prototype;return n.parse=function(t){this.$d=function(o){var e=o.date,u=o.utc;if(e===null)return new Date(NaN);if(l.u(e))return new Date;if(e instanceof Date)return new Date(e);if(typeof e=="string"&&!/Z$/i.test(e)){var a=e.match(ht);if(a){var d=a[2]-1||0,p=(a[7]||"0").substring(0,3);return u?new Date(Date.UTC(a[1],d,a[3]||1,a[4]||0,a[5]||0,a[6]||0,p)):new Date(a[1],d,a[3]||1,a[4]||0,a[5]||0,a[6]||0,p)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},n.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},n.$utils=function(){return l},n.isValid=function(){return this.$d.toString()!==et},n.isSame=function(t,o){var e=g(t);return this.startOf(o)<=e&&e<=this.endOf(o)},n.isAfter=function(t,o){return g(t)<this.startOf(o)},n.isBefore=function(t,o){return this.endOf(o)<g(t)},n.$g=function(t,o,e){return l.u(t)?this[o]:this.set(e,t)},n.unix=function(){return Math.floor(this.valueOf()/1e3)},n.valueOf=function(){return this.$d.getTime()},n.startOf=function(t,o){var e=this,u=!!l.u(o)||o,a=l.p(t),d=function(E,D){var C=l.w(e.$u?Date.UTC(e.$y,D,E):new Date(e.$y,D,E),e);return u?C:C.endOf(v)},p=function(E,D){return l.w(e.toDate()[E].apply(e.toDate("s"),(u?[0,0,0,0]:[23,59,59,999]).slice(D)),e)},m=this.$W,b=this.$M,x=this.$D,T="set"+(this.$u?"UTC":"");switch(a){case h:return u?d(1,0):d(31,11);case M:return u?d(1,b):d(0,b+1);case O:var k=this.$locale().weekStart||0,N=(m<k?m+7:m)-k;return d(u?x-N:x+(6-N),b);case v:case Y:return p(T+"Hours",0);case _:return p(T+"Minutes",1);case S:return p(T+"Seconds",2);case $:return p(T+"Milliseconds",3);default:return this.clone()}},n.endOf=function(t){return this.startOf(t,!1)},n.$set=function(t,o){var e,u=l.p(t),a="set"+(this.$u?"UTC":""),d=(e={},e[v]=a+"Date",e[Y]=a+"Date",e[M]=a+"Month",e[h]=a+"FullYear",e[_]=a+"Hours",e[S]=a+"Minutes",e[$]=a+"Seconds",e[w]=a+"Milliseconds",e)[u],p=u===v?this.$D+(o-this.$W):o;if(u===M||u===h){var m=this.clone().set(Y,1);m.$d[d](p),m.init(),this.$d=m.set(Y,Math.min(this.$D,m.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},n.set=function(t,o){return this.clone().$set(t,o)},n.get=function(t){return this[l.p(t)]()},n.add=function(t,o){var e,u=this;t=Number(t);var a=l.p(o),d=function(b){var x=g(u);return l.w(x.date(x.date()+Math.round(b*t)),u)};if(a===M)return this.set(M,this.$M+t);if(a===h)return this.set(h,this.$y+t);if(a===v)return d(1);if(a===O)return d(7);var p=(e={},e[S]=f,e[_]=y,e[$]=c,e)[a]||1,m=this.$d.getTime()+t*p;return l.w(m,this)},n.subtract=function(t,o){return this.add(-1*t,o)},n.format=function(t){var o=this,e=this.$locale();if(!this.isValid())return e.invalidDate||et;var u=t||"YYYY-MM-DDTHH:mm:ssZ",a=l.z(this),d=this.$H,p=this.$m,m=this.$M,b=e.weekdays,x=e.months,T=function(D,C,B,F){return D&&(D[C]||D(o,u))||B[C].slice(0,F)},k=function(D){return l.s(d%12||12,D,"0")},N=e.meridiem||function(D,C,B){var F=D<12?"AM":"PM";return B?F.toLowerCase():F},E={YY:String(this.$y).slice(-2),YYYY:this.$y,M:m+1,MM:l.s(m+1,2,"0"),MMM:T(e.monthsShort,m,x,3),MMMM:T(x,m),D:this.$D,DD:l.s(this.$D,2,"0"),d:String(this.$W),dd:T(e.weekdaysMin,this.$W,b,2),ddd:T(e.weekdaysShort,this.$W,b,3),dddd:b[this.$W],H:String(d),HH:l.s(d,2,"0"),h:k(1),hh:k(2),a:N(d,p,!0),A:N(d,p,!1),m:String(p),mm:l.s(p,2,"0"),s:String(this.$s),ss:l.s(this.$s,2,"0"),SSS:l.s(this.$ms,3,"0"),Z:a};return u.replace(mt,function(D,C){return C||E[D]||a.replace(":","")})},n.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},n.diff=function(t,o,e){var u,a=l.p(o),d=g(t),p=(d.utcOffset()-this.utcOffset())*f,m=this-d,b=l.m(this,d);return b=(u={},u[h]=b/12,u[M]=b,u[A]=b/3,u[O]=(m-p)/6048e5,u[v]=(m-p)/864e5,u[_]=m/y,u[S]=m/f,u[$]=m/c,u)[a]||m,e?b:l.a(b)},n.daysInMonth=function(){return this.endOf(M).$D},n.$locale=function(){return q[this.$L]},n.locale=function(t,o){if(!t)return this.$L;var e=this.clone(),u=P(t,o,!0);return u&&(e.$L=u),e},n.clone=function(){return l.w(this.$d,this)},n.toDate=function(){return new Date(this.valueOf())},n.toJSON=function(){return this.isValid()?this.toISOString():null},n.toISOString=function(){return this.$d.toISOString()},n.toString=function(){return this.$d.toUTCString()},s}(),nt=U.prototype;return g.prototype=nt,[["$ms",w],["$s",$],["$m",S],["$H",_],["$W",v],["$M",M],["$y",h],["$D",Y]].forEach(function(s){nt[s[1]]=function(n){return this.$g(n,s[0],s[1])}}),g.extend=function(s,n){return s.$i||(s(n,U,g),s.$i=!0),g},g.locale=P,g.isDayjs=Z,g.unix=function(s){return g(1e3*s)},g.en=q[I],g.Ls=q,g.p={},g})})(rt);const st=G;function ot(r="YYYY_MM_DD_HH_mm_ss"){return st(new Date).format(r)}function at(r,i){const c=document.createElement("a");c.setAttribute("href",r),c.setAttribute("download",i),c.click()}const Q=async(r,i,c)=>new Promise(f=>{const y=new MutationObserver(()=>{!!r.querySelector(i)==c&&(y.disconnect(),f(void 0))});y.observe(r,{childList:!0,subtree:!0}),!!r.querySelector(i)==c&&f(void 0)}),K=r=>new Promise(function(i,c){setTimeout(()=>c("Timeout"),r)}),X=(r,i)=>Promise.race([Q(r,i,!0),K(1e4)]),ut=(r,i)=>Promise.race([Q(r,i,!1),K(1e4)]),H=async(r,i,c)=>{const f=await(await fetch(i)).blob(),y=new File([f],c),w=new DataTransfer;w.items.add(y),r.querySelector("button[aria-label='Clear']")?.click(),await ut(r,"button[aria-label='Clear']");const $=r.querySelector("input[type='file']");$.value="",$.files=w.files,$.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),await X(r,"button[aria-label='Clear']")},L=(r,i)=>{r.querySelectorAll("button")[i].click()},ct=r=>{const i=r.querySelector(":scope > .label-wrap");i&&(i.classList.contains("open")||i.click())},dt=r=>{gradioApp().querySelector("#openpose3d_iframe").contentWindow.postMessage(r,"*")},z={},J={},lt=()=>{window.addEventListener("message",r=>{const{data:i}=r;if(i&&i.cmd&&i.cmd=="openpose-3d"&&i.method){const c=i.method;console.log("Method",c,r),i.type=="return"?z[c]?.(i.payload):i.type=="event"&&(console.log(J),J[c]?.(i.payload))}})},ft=r=>{Object.assign(J,r)};function W(r,...i){return new Promise((c,f)=>{const y=setTimeout(()=>{delete z[r],f({method:r,status:"Timeout"})},1e3),w=$=>{clearTimeout(y),c($)};z[r]=w,dt({cmd:"openpose-3d",method:r,type:"call",payload:i})})}const tt=()=>{const r=gradioApp().querySelector("#tab_threedopenpose");return r&&r.style.display!="none"};let R=!1,j=!1;onUiLoaded(async()=>{console.log("sd-webui-3d-open-pose-editor: onUiLoaded");const r=async(i,c,f,y,w,$,S,_,v)=>{let O=i.querySelector("#controlnet");if(O)ct(O);else{for(const h of i.querySelectorAll(".cursor-pointer > span"))h.textContent?.includes("ControlNet")&&(h.textContent?.includes("M2M")||(O=h.parentElement?.parentElement));if(!O){console.error("ControlNet element not found");return}}await X(O,'div[data-testid="image"]');const M=O.querySelectorAll('div[data-testid="image"]'),A=O.querySelector(".tab-nav");if(c&&f!=""&&f!="-"){const h=Number(f);A&&L(A,h),await H(M[h],c,"pose.png")}if(y&&w!=""&&w!="-"){const h=Number(w);A&&L(A,h),await H(M[h],y,"depth.png")}if($&&S!=""&&S!="-"){const h=Number(S);A&&L(A,h),await H(M[h],$,"normal.png")}if(_&&v!=""&&v!="-"){const h=Number(v);A&&L(A,h),await H(M[h],_,"canny.png")}};window.openpose3d={sendTxt2img:async(i,c,f,y,w,$,S,_)=>{const v=gradioApp().querySelector("#txt2img_script_container");switch_to_txt2img(),await r(v,i,c,f,y,w,$,S,_)},sendImg2img:async(i,c,f,y,w,$,S,_)=>{const v=gradioApp().querySelector("#img2img_script_container");switch_to_img2img(),await r(v,i,c,f,y,w,$,S,_)},downloadImage:(i,c)=>{if(!i)return;const f=c+"_"+ot()+".png";at(i,f)}},lt(),ft({MakeImages:async i=>{for(const[f,y]of Object.entries(i)){const w=gradioApp().querySelector(`#openpose3d_${f}_image`);await H(w,y,f+".png")}const c=gradioApp().querySelector("#openpose3d_main");L(c,1)}});for(let i=0;i<30;++i)try{await W("GetAppVersion"),R=!0;break}catch(c){if(c.status!="Timeout")throw c}if(!R){console.error("sd-webui-3d-open-pose-editor: Timeout");return}tt()||await W("Pause")}),onUiUpdate(async()=>{R&&(tt()?j&&(j=!1,await W("Resume")):j||(j=!0,await W("Pause")))})})(); | |