@imgly/plugin-ai-apps-web 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,7 @@
1
- var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=typeof self=="object"&&self&&self.Object===Object&&self,Bl=qn||Vl||Function("return this")(),z=Bl,Fl=z.Symbol,J=Fl,Qn=Object.prototype,Gl=Qn.hasOwnProperty,Rl=Qn.toString,Be=J?J.toStringTag:void 0;function ql(e){var t=Gl.call(e,Be),n=e[Be];try{e[Be]=void 0;var r=!0}catch{}var a=Rl.call(e);return r&&(t?e[Be]=n:delete e[Be]),a}var Ql=ql,Hl=Object.prototype,Yl=Hl.toString;function Zl(e){return Yl.call(e)}var Wl=Zl,Kl="[object Null]",Jl="[object Undefined]",Tn=J?J.toStringTag:void 0;function Xl(e){return e==null?e===void 0?Jl:Kl:Tn&&Tn in Object(e)?Ql(e):Wl(e)}var qe=Xl;function es(e){return e!=null&&typeof e=="object"}var hr=es,Iw=Array.isArray;function ts(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Hn=ts,rs="[object AsyncFunction]",ns="[object Function]",is="[object GeneratorFunction]",os="[object Proxy]";function as(e){if(!Hn(e))return!1;var t=qe(e);return t==ns||t==is||t==rs||t==os}var ls=as,ss=z["__core-js_shared__"],cr=ss,$n=function(){var e=/[^.]+$/.exec(cr&&cr.keys&&cr.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function us(e){return!!$n&&$n in e}var cs=us,ds=Function.prototype,gs=ds.toString;function ps(e){if(e!=null){try{return gs.call(e)}catch{}try{return e+""}catch{}}return""}var R=ps,ms=/[\\^$.*+?()[\]{}|]/g,fs=/^\[object .+?Constructor\]$/,ys=Function.prototype,bs=Object.prototype,hs=ys.toString,vs=bs.hasOwnProperty,ks=RegExp("^"+hs.call(vs).replace(ms,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ws(e){if(!Hn(e)||cs(e))return!1;var t=ls(e)?ks:fs;return t.test(R(e))}var Cs=ws;function Ms(e,t){return e?.[t]}var Is=Ms;function xs(e,t){var n=Is(e,t);return Cs(n)?n:void 0}var X=xs,As=X(z,"WeakMap"),pr=As;function Ss(e,t){return e===t||e!==e&&t!==t}var Es=Ss,js=9007199254740991;function Ls(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=js}var Ts=Ls,xw=Object.prototype,$s="[object Arguments]";function Ns(e){return hr(e)&&qe(e)==$s}var Nn=Ns,Yn=Object.prototype,Ds=Yn.hasOwnProperty,Os=Yn.propertyIsEnumerable,Aw=Nn(function(){return arguments}())?Nn:function(e){return hr(e)&&Ds.call(e,"callee")&&!Os.call(e,"callee")},Zn=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Dn=Zn&&typeof module=="object"&&module&&!module.nodeType&&module,_s=Dn&&Dn.exports===Zn,On=_s?z.Buffer:void 0,Sw=On?On.isBuffer:void 0,Ps="[object Arguments]",zs="[object Array]",Us="[object Boolean]",Vs="[object Date]",Bs="[object Error]",Fs="[object Function]",Gs="[object Map]",Rs="[object Number]",qs="[object Object]",Qs="[object RegExp]",Hs="[object Set]",Ys="[object String]",Zs="[object WeakMap]",Ws="[object ArrayBuffer]",Ks="[object DataView]",Js="[object Float32Array]",Xs="[object Float64Array]",eu="[object Int8Array]",tu="[object Int16Array]",ru="[object Int32Array]",nu="[object Uint8Array]",iu="[object Uint8ClampedArray]",ou="[object Uint16Array]",au="[object Uint32Array]",A={};A[Js]=A[Xs]=A[eu]=A[tu]=A[ru]=A[nu]=A[iu]=A[ou]=A[au]=!0;A[Ps]=A[zs]=A[Ws]=A[Us]=A[Ks]=A[Vs]=A[Bs]=A[Fs]=A[Gs]=A[Rs]=A[qs]=A[Qs]=A[Hs]=A[Ys]=A[Zs]=!1;function lu(e){return hr(e)&&Ts(e.length)&&!!A[qe(e)]}var su=lu;function uu(e){return function(t){return e(t)}}var cu=uu,Wn=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Fe=Wn&&typeof module=="object"&&module&&!module.nodeType&&module,du=Fe&&Fe.exports===Wn,dr=du&&qn.process,gu=function(){try{var e=Fe&&Fe.require&&Fe.require("util").types;return e||dr&&dr.binding&&dr.binding("util")}catch{}}(),_n=gu,Pn=_n&&_n.isTypedArray,Ew=Pn?cu(Pn):su,pu=Object.prototype,jw=pu.hasOwnProperty;function mu(e,t){return function(n){return e(t(n))}}var fu=mu,Lw=fu(Object.keys,Object),yu=Object.prototype,Tw=yu.hasOwnProperty,bu=X(Object,"create"),Ge=bu;function hu(){this.__data__=Ge?Ge(null):{},this.size=0}var vu=hu;function ku(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var wu=ku,Cu="__lodash_hash_undefined__",Mu=Object.prototype,Iu=Mu.hasOwnProperty;function xu(e){var t=this.__data__;if(Ge){var n=t[e];return n===Cu?void 0:n}return Iu.call(t,e)?t[e]:void 0}var Au=xu,Su=Object.prototype,Eu=Su.hasOwnProperty;function ju(e){var t=this.__data__;return Ge?t[e]!==void 0:Eu.call(t,e)}var Lu=ju,Tu="__lodash_hash_undefined__";function $u(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Ge&&t===void 0?Tu:t,this}var Nu=$u;function ee(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ee.prototype.clear=vu;ee.prototype.delete=wu;ee.prototype.get=Au;ee.prototype.has=Lu;ee.prototype.set=Nu;var zn=ee;function Du(){this.__data__=[],this.size=0}var Ou=Du;function _u(e,t){for(var n=e.length;n--;)if(Es(e[n][0],t))return n;return-1}var _t=_u,Pu=Array.prototype,zu=Pu.splice;function Uu(e){var t=this.__data__,n=_t(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():zu.call(t,n,1),--this.size,!0}var Vu=Uu;function Bu(e){var t=this.__data__,n=_t(t,e);return n<0?void 0:t[n][1]}var Fu=Bu;function Gu(e){return _t(this.__data__,e)>-1}var Ru=Gu;function qu(e,t){var n=this.__data__,r=_t(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var Qu=qu;function te(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}te.prototype.clear=Ou;te.prototype.delete=Vu;te.prototype.get=Fu;te.prototype.has=Ru;te.prototype.set=Qu;var Pt=te,Hu=X(z,"Map"),Re=Hu;function Yu(){this.size=0,this.__data__={hash:new zn,map:new(Re||Pt),string:new zn}}var Zu=Yu;function Wu(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Ku=Wu;function Ju(e,t){var n=e.__data__;return Ku(t)?n[typeof t=="string"?"string":"hash"]:n.map}var zt=Ju;function Xu(e){var t=zt(this,e).delete(e);return this.size-=t?1:0,t}var ec=Xu;function tc(e){return zt(this,e).get(e)}var rc=tc;function nc(e){return zt(this,e).has(e)}var ic=nc;function oc(e,t){var n=zt(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var ac=oc;function re(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}re.prototype.clear=Zu;re.prototype.delete=ec;re.prototype.get=rc;re.prototype.has=ic;re.prototype.set=ac;var Kn=re;function lc(){this.__data__=new Pt,this.size=0}var sc=lc;function uc(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var cc=uc;function dc(e){return this.__data__.get(e)}var gc=dc;function pc(e){return this.__data__.has(e)}var mc=pc,fc=200;function yc(e,t){var n=this.__data__;if(n instanceof Pt){var r=n.__data__;if(!Re||r.length<fc-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Kn(r)}return n.set(e,t),this.size=n.size,this}var bc=yc;function Qe(e){var t=this.__data__=new Pt(e);this.size=t.size}Qe.prototype.clear=sc;Qe.prototype.delete=cc;Qe.prototype.get=gc;Qe.prototype.has=mc;Qe.prototype.set=bc;var hc=Object.prototype,$w=hc.propertyIsEnumerable,vc=X(z,"DataView"),mr=vc,kc=X(z,"Promise"),fr=kc,wc=X(z,"Set"),yr=wc,Un="[object Map]",Cc="[object Object]",Vn="[object Promise]",Bn="[object Set]",Fn="[object WeakMap]",Gn="[object DataView]",Mc=R(mr),Ic=R(Re),xc=R(fr),Ac=R(yr),Sc=R(pr),K=qe;(mr&&K(new mr(new ArrayBuffer(1)))!=Gn||Re&&K(new Re)!=Un||fr&&K(fr.resolve())!=Vn||yr&&K(new yr)!=Bn||pr&&K(new pr)!=Fn)&&(K=function(e){var t=qe(e),n=t==Cc?e.constructor:void 0,r=n?R(n):"";if(r)switch(r){case Mc:return Gn;case Ic:return Un;case xc:return Vn;case Ac:return Bn;case Sc:return Fn}return t});var Nw=z.Uint8Array,Ec="__lodash_hash_undefined__";function jc(e){return this.__data__.set(e,Ec),this}var Lc=jc;function Tc(e){return this.__data__.has(e)}var $c=Tc;function br(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Kn;++t<n;)this.add(e[t])}br.prototype.add=br.prototype.push=Lc;br.prototype.has=$c;var Rn=J?J.prototype:void 0,Dw=Rn?Rn.valueOf:void 0,Nc=Object.prototype,Ow=Nc.hasOwnProperty,Dc=Object.prototype,_w=Dc.hasOwnProperty,Pw=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),zw=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Uw=new RegExp(/[A-Fa-f0-9]{2}/,"g");var Oc="ly.img.ai";function Ut(e){return`${Oc}/${e}`}var gr="@imgly/plugin-ai-generation",Vw=`
1
+ var Ag=typeof global=="object"&&global&&global.Object===Object&&global,Ml=Ag,Mg=typeof self=="object"&&self&&self.Object===Object&&self,jg=Ml||Mg||Function("return this")(),B=jg,Sg=B.Symbol,De=Sg,jl=Object.prototype,Eg=jl.hasOwnProperty,_g=jl.toString,sr=De?De.toStringTag:void 0;function Lg(e){var t=Eg.call(e,sr),r=e[sr];try{e[sr]=void 0;var i=!0}catch{}var n=_g.call(e);return i&&(t?e[sr]=r:delete e[sr]),n}var Tg=Lg,$g=Object.prototype,Ng=$g.toString;function Og(e){return Ng.call(e)}var Dg=Og,Pg="[object Null]",zg="[object Undefined]",pl=De?De.toStringTag:void 0;function Ug(e){return e==null?e===void 0?zg:Pg:pl&&pl in Object(e)?Tg(e):Dg(e)}var pr=Ug;function Rg(e){return e!=null&&typeof e=="object"}var Zn=Rg,NQ=Array.isArray;function Fg(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Sl=Fg,Vg="[object AsyncFunction]",Bg="[object Function]",Gg="[object GeneratorFunction]",qg="[object Proxy]";function Yg(e){if(!Sl(e))return!1;var t=pr(e);return t==Bg||t==Gg||t==Vg||t==qg}var Hg=Yg,Zg=B["__core-js_shared__"],Fn=Zg,gl=function(){var e=/[^.]+$/.exec(Fn&&Fn.keys&&Fn.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Qg(e){return!!gl&&gl in e}var Wg=Qg,Kg=Function.prototype,Jg=Kg.toString;function Xg(e){if(e!=null){try{return Jg.call(e)}catch{}try{return e+""}catch{}}return""}var ve=Xg,ef=/[\\^$.*+?()[\]{}|]/g,tf=/^\[object .+?Constructor\]$/,rf=Function.prototype,nf=Object.prototype,of=rf.toString,af=nf.hasOwnProperty,lf=RegExp("^"+of.call(af).replace(ef,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function sf(e){if(!Sl(e)||Wg(e))return!1;var t=Hg(e)?lf:tf;return t.test(ve(e))}var uf=sf;function cf(e,t){return e?.[t]}var df=cf;function pf(e,t){var r=df(e,t);return uf(r)?r:void 0}var Pe=pf,gf=Pe(B,"WeakMap"),Bn=gf;function ff(e,t){return e===t||e!==e&&t!==t}var hf=ff,mf=9007199254740991;function yf(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=mf}var bf=yf;var OQ=Object.prototype;var vf="[object Arguments]";function wf(e){return Zn(e)&&pr(e)==vf}var fl=wf,El=Object.prototype,kf=El.hasOwnProperty,xf=El.propertyIsEnumerable,DQ=fl(function(){return arguments}())?fl:function(e){return Zn(e)&&kf.call(e,"callee")&&!xf.call(e,"callee")};var _l=typeof exports=="object"&&exports&&!exports.nodeType&&exports,hl=_l&&typeof module=="object"&&module&&!module.nodeType&&module,If=hl&&hl.exports===_l,ml=If?B.Buffer:void 0,PQ=ml?ml.isBuffer:void 0;var Cf="[object Arguments]",Af="[object Array]",Mf="[object Boolean]",jf="[object Date]",Sf="[object Error]",Ef="[object Function]",_f="[object Map]",Lf="[object Number]",Tf="[object Object]",$f="[object RegExp]",Nf="[object Set]",Of="[object String]",Df="[object WeakMap]",Pf="[object ArrayBuffer]",zf="[object DataView]",Uf="[object Float32Array]",Rf="[object Float64Array]",Ff="[object Int8Array]",Vf="[object Int16Array]",Bf="[object Int32Array]",Gf="[object Uint8Array]",qf="[object Uint8ClampedArray]",Yf="[object Uint16Array]",Hf="[object Uint32Array]",A={};A[Uf]=A[Rf]=A[Ff]=A[Vf]=A[Bf]=A[Gf]=A[qf]=A[Yf]=A[Hf]=!0;A[Cf]=A[Af]=A[Pf]=A[Mf]=A[zf]=A[jf]=A[Sf]=A[Ef]=A[_f]=A[Lf]=A[Tf]=A[$f]=A[Nf]=A[Of]=A[Df]=!1;function Zf(e){return Zn(e)&&bf(e.length)&&!!A[pr(e)]}var Qf=Zf;function Wf(e){return function(t){return e(t)}}var Kf=Wf,Ll=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ur=Ll&&typeof module=="object"&&module&&!module.nodeType&&module,Jf=ur&&ur.exports===Ll,Vn=Jf&&Ml.process,Xf=function(){try{var e=ur&&ur.require&&ur.require("util").types;return e||Vn&&Vn.binding&&Vn.binding("util")}catch{}}(),yl=Xf,bl=yl&&yl.isTypedArray,zQ=bl?Kf(bl):Qf;var eh=Object.prototype,UQ=eh.hasOwnProperty;function th(e,t){return function(r){return e(t(r))}}var rh=th,RQ=rh(Object.keys,Object);var ih=Object.prototype,FQ=ih.hasOwnProperty;var nh=Pe(Object,"create"),cr=nh;function oh(){this.__data__=cr?cr(null):{},this.size=0}var ah=oh;function lh(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var sh=lh,uh="__lodash_hash_undefined__",ch=Object.prototype,dh=ch.hasOwnProperty;function ph(e){var t=this.__data__;if(cr){var r=t[e];return r===uh?void 0:r}return dh.call(t,e)?t[e]:void 0}var gh=ph,fh=Object.prototype,hh=fh.hasOwnProperty;function mh(e){var t=this.__data__;return cr?t[e]!==void 0:hh.call(t,e)}var yh=mh,bh="__lodash_hash_undefined__";function vh(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=cr&&t===void 0?bh:t,this}var wh=vh;function ze(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}ze.prototype.clear=ah;ze.prototype.delete=sh;ze.prototype.get=gh;ze.prototype.has=yh;ze.prototype.set=wh;var vl=ze;function kh(){this.__data__=[],this.size=0}var xh=kh;function Ih(e,t){for(var r=e.length;r--;)if(hf(e[r][0],t))return r;return-1}var qi=Ih,Ch=Array.prototype,Ah=Ch.splice;function Mh(e){var t=this.__data__,r=qi(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Ah.call(t,r,1),--this.size,!0}var jh=Mh;function Sh(e){var t=this.__data__,r=qi(t,e);return r<0?void 0:t[r][1]}var Eh=Sh;function _h(e){return qi(this.__data__,e)>-1}var Lh=_h;function Th(e,t){var r=this.__data__,i=qi(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var $h=Th;function Ue(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Ue.prototype.clear=xh;Ue.prototype.delete=jh;Ue.prototype.get=Eh;Ue.prototype.has=Lh;Ue.prototype.set=$h;var Yi=Ue,Nh=Pe(B,"Map"),dr=Nh;function Oh(){this.size=0,this.__data__={hash:new vl,map:new(dr||Yi),string:new vl}}var Dh=Oh;function Ph(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var zh=Ph;function Uh(e,t){var r=e.__data__;return zh(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Hi=Uh;function Rh(e){var t=Hi(this,e).delete(e);return this.size-=t?1:0,t}var Fh=Rh;function Vh(e){return Hi(this,e).get(e)}var Bh=Vh;function Gh(e){return Hi(this,e).has(e)}var qh=Gh;function Yh(e,t){var r=Hi(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Hh=Yh;function Re(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Re.prototype.clear=Dh;Re.prototype.delete=Fh;Re.prototype.get=Bh;Re.prototype.has=qh;Re.prototype.set=Hh;var Tl=Re;function Zh(){this.__data__=new Yi,this.size=0}var Qh=Zh;function Wh(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Kh=Wh;function Jh(e){return this.__data__.get(e)}var Xh=Jh;function em(e){return this.__data__.has(e)}var tm=em,rm=200;function im(e,t){var r=this.__data__;if(r instanceof Yi){var i=r.__data__;if(!dr||i.length<rm-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Tl(i)}return r.set(e,t),this.size=r.size,this}var nm=im;function gr(e){var t=this.__data__=new Yi(e);this.size=t.size}gr.prototype.clear=Qh;gr.prototype.delete=Kh;gr.prototype.get=Xh;gr.prototype.has=tm;gr.prototype.set=nm;var om=Object.prototype,VQ=om.propertyIsEnumerable;var am=Pe(B,"DataView"),Gn=am,lm=Pe(B,"Promise"),qn=lm,sm=Pe(B,"Set"),Yn=sm,wl="[object Map]",um="[object Object]",kl="[object Promise]",xl="[object Set]",Il="[object WeakMap]",Cl="[object DataView]",cm=ve(Gn),dm=ve(dr),pm=ve(qn),gm=ve(Yn),fm=ve(Bn),Oe=pr;(Gn&&Oe(new Gn(new ArrayBuffer(1)))!=Cl||dr&&Oe(new dr)!=wl||qn&&Oe(qn.resolve())!=kl||Yn&&Oe(new Yn)!=xl||Bn&&Oe(new Bn)!=Il)&&(Oe=function(e){var t=pr(e),r=t==um?e.constructor:void 0,i=r?ve(r):"";if(i)switch(i){case cm:return Cl;case dm:return wl;case pm:return kl;case gm:return xl;case fm:return Il}return t});var BQ=B.Uint8Array;var hm="__lodash_hash_undefined__";function mm(e){return this.__data__.set(e,hm),this}var ym=mm;function bm(e){return this.__data__.has(e)}var vm=bm;function Hn(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Tl;++t<r;)this.add(e[t])}Hn.prototype.add=Hn.prototype.push=ym;Hn.prototype.has=vm;var Al=De?De.prototype:void 0,GQ=Al?Al.valueOf:void 0;var wm=Object.prototype,qQ=wm.hasOwnProperty;var km=Object.prototype,YQ=km.hasOwnProperty;var HQ=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),ZQ=new RegExp(/[A-Fa-f0-9]{1}/,"g"),QQ=new RegExp(/[A-Fa-f0-9]{2}/,"g");function xm(e){return e!==void 0}var $l=xm;var Im=typeof global=="object"&&global&&global.Object===Object&&global,Zl=Im,Cm=typeof self=="object"&&self&&self.Object===Object&&self,Am=Zl||Cm||Function("return this")(),G=Am,Mm=G.Symbol,Ve=Mm,Ql=Object.prototype,jm=Ql.hasOwnProperty,Sm=Ql.toString,fr=Ve?Ve.toStringTag:void 0;function Em(e){var t=jm.call(e,fr),r=e[fr];try{e[fr]=void 0;var i=!0}catch{}var n=Sm.call(e);return i&&(t?e[fr]=r:delete e[fr]),n}var _m=Em,Lm=Object.prototype,Tm=Lm.toString;function $m(e){return Tm.call(e)}var Nm=$m,Om="[object Null]",Dm="[object Undefined]",Nl=Ve?Ve.toStringTag:void 0;function Pm(e){return e==null?e===void 0?Dm:Om:Nl&&Nl in Object(e)?_m(e):Nm(e)}var br=Pm;function zm(e){return e!=null&&typeof e=="object"}var io=zm,KQ=Array.isArray;function Um(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Wl=Um,Rm="[object AsyncFunction]",Fm="[object Function]",Vm="[object GeneratorFunction]",Bm="[object Proxy]";function Gm(e){if(!Wl(e))return!1;var t=br(e);return t==Fm||t==Vm||t==Rm||t==Bm}var qm=Gm,Ym=G["__core-js_shared__"],Qn=Ym,Ol=function(){var e=/[^.]+$/.exec(Qn&&Qn.keys&&Qn.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Hm(e){return!!Ol&&Ol in e}var Zm=Hm,Qm=Function.prototype,Wm=Qm.toString;function Km(e){if(e!=null){try{return Wm.call(e)}catch{}try{return e+""}catch{}}return""}var we=Km,Jm=/[\\^$.*+?()[\]{}|]/g,Xm=/^\[object .+?Constructor\]$/,ey=Function.prototype,ty=Object.prototype,ry=ey.toString,iy=ty.hasOwnProperty,ny=RegExp("^"+ry.call(iy).replace(Jm,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function oy(e){if(!Wl(e)||Zm(e))return!1;var t=qm(e)?ny:Xm;return t.test(we(e))}var ay=oy;function ly(e,t){return e?.[t]}var sy=ly;function uy(e,t){var r=sy(e,t);return ay(r)?r:void 0}var Be=uy,cy=Be(G,"WeakMap"),Jn=cy;function dy(e,t){return e===t||e!==e&&t!==t}var py=dy,gy=9007199254740991;function fy(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=gy}var hy=fy,JQ=Object.prototype,my="[object Arguments]";function yy(e){return io(e)&&br(e)==my}var Dl=yy,Kl=Object.prototype,by=Kl.hasOwnProperty,vy=Kl.propertyIsEnumerable,XQ=Dl(function(){return arguments}())?Dl:function(e){return io(e)&&by.call(e,"callee")&&!vy.call(e,"callee")},Jl=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Pl=Jl&&typeof module=="object"&&module&&!module.nodeType&&module,wy=Pl&&Pl.exports===Jl,zl=wy?G.Buffer:void 0,eW=zl?zl.isBuffer:void 0,ky="[object Arguments]",xy="[object Array]",Iy="[object Boolean]",Cy="[object Date]",Ay="[object Error]",My="[object Function]",jy="[object Map]",Sy="[object Number]",Ey="[object Object]",_y="[object RegExp]",Ly="[object Set]",Ty="[object String]",$y="[object WeakMap]",Ny="[object ArrayBuffer]",Oy="[object DataView]",Dy="[object Float32Array]",Py="[object Float64Array]",zy="[object Int8Array]",Uy="[object Int16Array]",Ry="[object Int32Array]",Fy="[object Uint8Array]",Vy="[object Uint8ClampedArray]",By="[object Uint16Array]",Gy="[object Uint32Array]",M={};M[Dy]=M[Py]=M[zy]=M[Uy]=M[Ry]=M[Fy]=M[Vy]=M[By]=M[Gy]=!0;M[ky]=M[xy]=M[Ny]=M[Iy]=M[Oy]=M[Cy]=M[Ay]=M[My]=M[jy]=M[Sy]=M[Ey]=M[_y]=M[Ly]=M[Ty]=M[$y]=!1;function qy(e){return io(e)&&hy(e.length)&&!!M[br(e)]}var Yy=qy;function Hy(e){return function(t){return e(t)}}var Zy=Hy,Xl=typeof exports=="object"&&exports&&!exports.nodeType&&exports,hr=Xl&&typeof module=="object"&&module&&!module.nodeType&&module,Qy=hr&&hr.exports===Xl,Wn=Qy&&Zl.process,Wy=function(){try{var e=hr&&hr.require&&hr.require("util").types;return e||Wn&&Wn.binding&&Wn.binding("util")}catch{}}(),Ul=Wy,Rl=Ul&&Ul.isTypedArray,tW=Rl?Zy(Rl):Yy,Ky=Object.prototype,rW=Ky.hasOwnProperty;function Jy(e,t){return function(r){return e(t(r))}}var Xy=Jy,iW=Xy(Object.keys,Object),eb=Object.prototype,nW=eb.hasOwnProperty,tb=Be(Object,"create"),mr=tb;function rb(){this.__data__=mr?mr(null):{},this.size=0}var ib=rb;function nb(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var ob=nb,ab="__lodash_hash_undefined__",lb=Object.prototype,sb=lb.hasOwnProperty;function ub(e){var t=this.__data__;if(mr){var r=t[e];return r===ab?void 0:r}return sb.call(t,e)?t[e]:void 0}var cb=ub,db=Object.prototype,pb=db.hasOwnProperty;function gb(e){var t=this.__data__;return mr?t[e]!==void 0:pb.call(t,e)}var fb=gb,hb="__lodash_hash_undefined__";function mb(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=mr&&t===void 0?hb:t,this}var yb=mb;function Ge(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Ge.prototype.clear=ib;Ge.prototype.delete=ob;Ge.prototype.get=cb;Ge.prototype.has=fb;Ge.prototype.set=yb;var Fl=Ge;function bb(){this.__data__=[],this.size=0}var vb=bb;function wb(e,t){for(var r=e.length;r--;)if(py(e[r][0],t))return r;return-1}var Zi=wb,kb=Array.prototype,xb=kb.splice;function Ib(e){var t=this.__data__,r=Zi(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():xb.call(t,r,1),--this.size,!0}var Cb=Ib;function Ab(e){var t=this.__data__,r=Zi(t,e);return r<0?void 0:t[r][1]}var Mb=Ab;function jb(e){return Zi(this.__data__,e)>-1}var Sb=jb;function Eb(e,t){var r=this.__data__,i=Zi(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var _b=Eb;function qe(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}qe.prototype.clear=vb;qe.prototype.delete=Cb;qe.prototype.get=Mb;qe.prototype.has=Sb;qe.prototype.set=_b;var Qi=qe,Lb=Be(G,"Map"),yr=Lb;function Tb(){this.size=0,this.__data__={hash:new Fl,map:new(yr||Qi),string:new Fl}}var $b=Tb;function Nb(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Ob=Nb;function Db(e,t){var r=e.__data__;return Ob(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Wi=Db;function Pb(e){var t=Wi(this,e).delete(e);return this.size-=t?1:0,t}var zb=Pb;function Ub(e){return Wi(this,e).get(e)}var Rb=Ub;function Fb(e){return Wi(this,e).has(e)}var Vb=Fb;function Bb(e,t){var r=Wi(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Gb=Bb;function Ye(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Ye.prototype.clear=$b;Ye.prototype.delete=zb;Ye.prototype.get=Rb;Ye.prototype.has=Vb;Ye.prototype.set=Gb;var es=Ye;function qb(){this.__data__=new Qi,this.size=0}var Yb=qb;function Hb(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Zb=Hb;function Qb(e){return this.__data__.get(e)}var Wb=Qb;function Kb(e){return this.__data__.has(e)}var Jb=Kb,Xb=200;function e0(e,t){var r=this.__data__;if(r instanceof Qi){var i=r.__data__;if(!yr||i.length<Xb-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new es(i)}return r.set(e,t),this.size=r.size,this}var t0=e0;function vr(e){var t=this.__data__=new Qi(e);this.size=t.size}vr.prototype.clear=Yb;vr.prototype.delete=Zb;vr.prototype.get=Wb;vr.prototype.has=Jb;vr.prototype.set=t0;var r0=Object.prototype,oW=r0.propertyIsEnumerable,i0=Be(G,"DataView"),Xn=i0,n0=Be(G,"Promise"),eo=n0,o0=Be(G,"Set"),to=o0,Vl="[object Map]",a0="[object Object]",Bl="[object Promise]",Gl="[object Set]",ql="[object WeakMap]",Yl="[object DataView]",l0=we(Xn),s0=we(yr),u0=we(eo),c0=we(to),d0=we(Jn),Fe=br;(Xn&&Fe(new Xn(new ArrayBuffer(1)))!=Yl||yr&&Fe(new yr)!=Vl||eo&&Fe(eo.resolve())!=Bl||to&&Fe(new to)!=Gl||Jn&&Fe(new Jn)!=ql)&&(Fe=function(e){var t=br(e),r=t==a0?e.constructor:void 0,i=r?we(r):"";if(i)switch(i){case l0:return Yl;case s0:return Vl;case u0:return Bl;case c0:return Gl;case d0:return ql}return t});var aW=G.Uint8Array,p0="__lodash_hash_undefined__";function g0(e){return this.__data__.set(e,p0),this}var f0=g0;function h0(e){return this.__data__.has(e)}var m0=h0;function ro(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new es;++t<r;)this.add(e[t])}ro.prototype.add=ro.prototype.push=f0;ro.prototype.has=m0;var Hl=Ve?Ve.prototype:void 0,lW=Hl?Hl.valueOf:void 0,y0=Object.prototype,sW=y0.hasOwnProperty,b0=Object.prototype,uW=b0.hasOwnProperty,cW=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),dW=new RegExp(/[A-Fa-f0-9]{1}/,"g"),pW=new RegExp(/[A-Fa-f0-9]{2}/,"g");var Ki=class ts{constructor(){this.actions=new Map,this.subscribers=new Map}static get(){let t="__imgly_action_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new ts),r[t]}register(t){return this.actions.set(t.id,t),this.notifySubscribers(t,"registered"),()=>{this.actions.get(t.id)===t&&(this.actions.delete(t.id),this.notifySubscribers(t,"unregistered"))}}getAll(){return Array.from(this.actions.values())}getBy(t){return this.getAll().filter(r=>this.matchesFilters(r,t))}subscribe(t){return this.subscribers.set(t,null),()=>{this.subscribers.delete(t)}}subscribeBy(t,r){return this.subscribers.set(r,t),()=>{this.subscribers.delete(r)}}notifySubscribers(t,r){this.subscribers.forEach((i,n)=>{if(i===null){n(t,r);return}this.matchesFilters(t,i)&&n(t,r)})}matchesFilters(t,r){return!(r.type&&t.type!==r.type||r.pluginId&&t.type==="plugin"&&t.pluginId!==r.pluginId||r.id&&t.id!==r.id||r.kind&&(t.type!=="quick"||t.kind!==r.kind))}};var v0="ly.img.ai";function rs(e){return`${v0}.${e}`}function is(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
2
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
3
+ This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version.
4
+ Consider updating all AI plugins to the same version for optimal compatibility.`),e.ui.experimental.setGlobalStateValue(n,!0))):e.ui.experimental.setGlobalStateValue(i,r)}catch(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}var Kn="@imgly/plugin-ai-generation",gW=`
2
5
  <svg>
3
6
  <symbol
4
7
  fill="none"
@@ -16,7 +19,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
16
19
  fill="none"
17
20
  xmlns="http://www.w3.org/2000/svg"
18
21
  viewBox="0 0 24 24"
19
- id="${gr}/image"
22
+ id="${Kn}/image"
20
23
  >
21
24
  <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
22
25
  <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
@@ -28,7 +31,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
28
31
  fill="none"
29
32
  xmlns="http://www.w3.org/2000/svg"
30
33
  viewBox="0 0 24 24"
31
- id="${gr}/video"
34
+ id="${Kn}/video"
32
35
  >
33
36
  <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
34
37
  <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
@@ -39,7 +42,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
39
42
  fill="none"
40
43
  xmlns="http://www.w3.org/2000/svg"
41
44
  viewBox="0 0 24 24"
42
- id="${gr}/audio"
45
+ id="${Kn}/audio"
43
46
  >
44
47
  <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
45
48
  <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
@@ -59,8 +62,10 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
59
62
 
60
63
  </symbol>
61
64
  </svg>
62
- `;var _c=class{constructor(e,t,n){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=n?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=n?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let n=indexedDB.open(this.dbName,this.dbVersion);n.onerror=r=>{t(new Error(`Failed to open IndexedDB: ${r.target.error}`))},n.onupgradeneeded=r=>{let a=r.target.result;a.objectStoreNames.contains(this.assetStoreName)||a.createObjectStore(this.assetStoreName,{keyPath:"id"}),a.objectStoreNames.contains(this.blobStoreName)||a.createObjectStore(this.blobStoreName,{keyPath:"id"})},n.onsuccess=r=>{this.db=r.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",g=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(g=s.tags[c]);let f={...s,label:d,tags:g};return this.filterAsset(f,e)&&u.push(f),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:n,perPage:r}=e,a=n*r,o=a+r,i=t.slice(a,o),l=o<t.length?n+1:void 0;return{assets:i,currentPage:n,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let n=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();n.onsuccess=()=>{let r=new Set;n.result.forEach(o=>{o.groups&&Array.isArray(o.groups)&&o.groups.forEach(i=>r.add(i))});let a=[...r];e(a)},n.onerror=()=>{t(new Error(`Failed to get groups: ${n.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),n=t.objectStore(this.assetStoreName),r=new Set;ie(e,o=>{r.add(o)}),setTimeout(()=>{this.storeBlobUrls([...r])});let a={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};n.put(a),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.assetStoreName,"readwrite");n.objectStore(this.assetStoreName).delete(e),n.oncomplete=()=>{ie(t,r=>{this.removeBlob(r)}),this.engine.asset.assetSourceContentsChanged(this.id)},n.onerror=()=>{console.error(`Failed to remove asset: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let a=r.result;a.sort((o,i)=>{let l=o.meta?.insertedAt||o._insertedAt||Date.now(),u=i.meta?.insertedAt||i._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(a)},r.onerror=()=>{n(new Error(`Failed to get assets: ${r.error}`))}})}async getAsset(e){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async getBlob(e){return new Promise((t,n)=>{let r=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async n=>{let r=await(await fetch(n)).blob();t[n]=r})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.blobStoreName,"readwrite"),r=n.objectStore(this.blobStoreName);Object.entries(t).forEach(([a,o])=>{let i={id:a,blob:o};r.put(i)}),n.onerror=()=>{console.error(`Failed to add blobs: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async restoreBlobUrls(e){let t={},n=new Set;return ie(e,r=>{n.add(r)}),await Promise.all([...n].map(async r=>{let a=await this.createBlobUrlFromStore(r);t[r]=a})),ie(e,r=>t[r]??r)}filterAsset(e,t){let{query:n,tags:r,groups:a,excludeGroups:o}=t;if(n&&n.trim()!==""){let i=n.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!i.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(r){let i=Array.isArray(r)?r:[r];if(i.length>0&&(!e.tags||!i.every(l=>e.tags?.includes(l))))return!1}return!(a&&a.length>0&&(!e.groups||!a.some(i=>e.groups?.includes(i)))||o&&o.length>0&&e.groups&&e.groups.some(i=>o.includes(i)))}sortAssets(e,t){let{sortingOrder:n,sortKey:r,sortActiveFirst:a}=t,o=[...e];return!n||n==="None"||(r?o.sort((i,l)=>{let u,s;return r==="id"?(u=i.id,s=l.id):(u=i.meta?.[r]??null,s=l.meta?.[r]??null),u==null?n==="Ascending"?-1:1:s==null?n==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?n==="Ascending"?u.localeCompare(s):s.localeCompare(u):n==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):n==="Descending"&&o.reverse(),a&&o.sort((i,l)=>i.active&&!l.active?-1:!i.active&&l.active?1:0)),o}};function ie(e,t,n=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let r=0;r<e.length;r++){let a=n?`${n}[${r}]`:`[${r}]`;if(typeof e[r]=="string"&&e[r].startsWith("blob:")){let o=t(e[r],a);typeof o=="string"&&(e[r]=o)}else e[r]=ie(e[r],t,a)}return e}for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)){let a=e[r],o=n?`${n}.${r}`:r;if(typeof a=="string"&&a.startsWith("blob:")){let i=t(a,o);typeof i=="string"&&(e[r]=i)}else e[r]=ie(a,t,o)}return e}var Pc=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},yi=Pc,zc=typeof global=="object"&&global&&global.Object===Object&&global,bi=zc,Uc=typeof self=="object"&&self&&self.Object===Object&&self,Vc=bi||Uc||Function("return this")(),U=Vc,Bc=U.Symbol,oe=Bc,hi=Object.prototype,Fc=hi.hasOwnProperty,Gc=hi.toString,He=oe?oe.toStringTag:void 0;function Rc(e){var t=Fc.call(e,He),n=e[He];try{e[He]=void 0;var r=!0}catch{}var a=Gc.call(e);return r&&(t?e[He]=n:delete e[He]),a}var qc=Rc,Qc=Object.prototype,Hc=Qc.toString;function Yc(e){return Hc.call(e)}var Zc=Yc,Wc="[object Null]",Kc="[object Undefined]",Jn=oe?oe.toStringTag:void 0;function Jc(e){return e==null?e===void 0?Kc:Wc:Jn&&Jn in Object(e)?qc(e):Zc(e)}var et=Jc;function Xc(e){return e!=null&&typeof e=="object"}var Tr=Xc,Fw=Array.isArray;function e1(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var vi=e1,t1="[object AsyncFunction]",r1="[object Function]",n1="[object GeneratorFunction]",i1="[object Proxy]";function o1(e){if(!vi(e))return!1;var t=et(e);return t==r1||t==n1||t==t1||t==i1}var a1=o1,l1=U["__core-js_shared__"],vr=l1,Xn=function(){var e=/[^.]+$/.exec(vr&&vr.keys&&vr.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function s1(e){return!!Xn&&Xn in e}var u1=s1,c1=Function.prototype,d1=c1.toString;function g1(e){if(e!=null){try{return d1.call(e)}catch{}try{return e+""}catch{}}return""}var q=g1,p1=/[\\^$.*+?()[\]{}|]/g,m1=/^\[object .+?Constructor\]$/,f1=Function.prototype,y1=Object.prototype,b1=f1.toString,h1=y1.hasOwnProperty,v1=RegExp("^"+b1.call(h1).replace(p1,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function k1(e){if(!vi(e)||u1(e))return!1;var t=a1(e)?v1:m1;return t.test(q(e))}var w1=k1;function C1(e,t){return e?.[t]}var M1=C1;function I1(e,t){var n=M1(e,t);return w1(n)?n:void 0}var le=I1,x1=le(U,"WeakMap"),xr=x1;function A1(e,t){return e===t||e!==e&&t!==t}var S1=A1,E1=9007199254740991;function j1(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=E1}var L1=j1,Gw=Object.prototype,T1="[object Arguments]";function $1(e){return Tr(e)&&et(e)==T1}var ei=$1,ki=Object.prototype,N1=ki.hasOwnProperty,D1=ki.propertyIsEnumerable,Rw=ei(function(){return arguments}())?ei:function(e){return Tr(e)&&N1.call(e,"callee")&&!D1.call(e,"callee")},wi=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ti=wi&&typeof module=="object"&&module&&!module.nodeType&&module,O1=ti&&ti.exports===wi,ri=O1?U.Buffer:void 0,qw=ri?ri.isBuffer:void 0,_1="[object Arguments]",P1="[object Array]",z1="[object Boolean]",U1="[object Date]",V1="[object Error]",B1="[object Function]",F1="[object Map]",G1="[object Number]",R1="[object Object]",q1="[object RegExp]",Q1="[object Set]",H1="[object String]",Y1="[object WeakMap]",Z1="[object ArrayBuffer]",W1="[object DataView]",K1="[object Float32Array]",J1="[object Float64Array]",X1="[object Int8Array]",ed="[object Int16Array]",td="[object Int32Array]",rd="[object Uint8Array]",nd="[object Uint8ClampedArray]",id="[object Uint16Array]",od="[object Uint32Array]",S={};S[K1]=S[J1]=S[X1]=S[ed]=S[td]=S[rd]=S[nd]=S[id]=S[od]=!0;S[_1]=S[P1]=S[Z1]=S[z1]=S[W1]=S[U1]=S[V1]=S[B1]=S[F1]=S[G1]=S[R1]=S[q1]=S[Q1]=S[H1]=S[Y1]=!1;function ad(e){return Tr(e)&&L1(e.length)&&!!S[et(e)]}var ld=ad;function sd(e){return function(t){return e(t)}}var ud=sd,Ci=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ke=Ci&&typeof module=="object"&&module&&!module.nodeType&&module,cd=Ke&&Ke.exports===Ci,kr=cd&&bi.process,dd=function(){try{var e=Ke&&Ke.require&&Ke.require("util").types;return e||kr&&kr.binding&&kr.binding("util")}catch{}}(),ni=dd,ii=ni&&ni.isTypedArray,Qw=ii?ud(ii):ld,gd=Object.prototype,Hw=gd.hasOwnProperty;function pd(e,t){return function(n){return e(t(n))}}var md=pd,Yw=md(Object.keys,Object),fd=Object.prototype,Zw=fd.hasOwnProperty,yd=le(Object,"create"),Je=yd;function bd(){this.__data__=Je?Je(null):{},this.size=0}var hd=bd;function vd(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var kd=vd,wd="__lodash_hash_undefined__",Cd=Object.prototype,Md=Cd.hasOwnProperty;function Id(e){var t=this.__data__;if(Je){var n=t[e];return n===wd?void 0:n}return Md.call(t,e)?t[e]:void 0}var xd=Id,Ad=Object.prototype,Sd=Ad.hasOwnProperty;function Ed(e){var t=this.__data__;return Je?t[e]!==void 0:Sd.call(t,e)}var jd=Ed,Ld="__lodash_hash_undefined__";function Td(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Je&&t===void 0?Ld:t,this}var $d=Td;function se(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}se.prototype.clear=hd;se.prototype.delete=kd;se.prototype.get=xd;se.prototype.has=jd;se.prototype.set=$d;var oi=se;function Nd(){this.__data__=[],this.size=0}var Dd=Nd;function Od(e,t){for(var n=e.length;n--;)if(S1(e[n][0],t))return n;return-1}var Ft=Od,_d=Array.prototype,Pd=_d.splice;function zd(e){var t=this.__data__,n=Ft(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():Pd.call(t,n,1),--this.size,!0}var Ud=zd;function Vd(e){var t=this.__data__,n=Ft(t,e);return n<0?void 0:t[n][1]}var Bd=Vd;function Fd(e){return Ft(this.__data__,e)>-1}var Gd=Fd;function Rd(e,t){var n=this.__data__,r=Ft(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var qd=Rd;function ue(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ue.prototype.clear=Dd;ue.prototype.delete=Ud;ue.prototype.get=Bd;ue.prototype.has=Gd;ue.prototype.set=qd;var Gt=ue,Qd=le(U,"Map"),Xe=Qd;function Hd(){this.size=0,this.__data__={hash:new oi,map:new(Xe||Gt),string:new oi}}var Yd=Hd;function Zd(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Wd=Zd;function Kd(e,t){var n=e.__data__;return Wd(t)?n[typeof t=="string"?"string":"hash"]:n.map}var Rt=Kd;function Jd(e){var t=Rt(this,e).delete(e);return this.size-=t?1:0,t}var Xd=Jd;function eg(e){return Rt(this,e).get(e)}var tg=eg;function rg(e){return Rt(this,e).has(e)}var ng=rg;function ig(e,t){var n=Rt(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var og=ig;function ce(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ce.prototype.clear=Yd;ce.prototype.delete=Xd;ce.prototype.get=tg;ce.prototype.has=ng;ce.prototype.set=og;var Mi=ce;function ag(){this.__data__=new Gt,this.size=0}var lg=ag;function sg(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var ug=sg;function cg(e){return this.__data__.get(e)}var dg=cg;function gg(e){return this.__data__.has(e)}var pg=gg,mg=200;function fg(e,t){var n=this.__data__;if(n instanceof Gt){var r=n.__data__;if(!Xe||r.length<mg-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Mi(r)}return n.set(e,t),this.size=n.size,this}var yg=fg;function tt(e){var t=this.__data__=new Gt(e);this.size=t.size}tt.prototype.clear=lg;tt.prototype.delete=ug;tt.prototype.get=dg;tt.prototype.has=pg;tt.prototype.set=yg;var bg=Object.prototype,Ww=bg.propertyIsEnumerable,hg=le(U,"DataView"),Ar=hg,vg=le(U,"Promise"),Sr=vg,kg=le(U,"Set"),Er=kg,ai="[object Map]",wg="[object Object]",li="[object Promise]",si="[object Set]",ui="[object WeakMap]",ci="[object DataView]",Cg=q(Ar),Mg=q(Xe),Ig=q(Sr),xg=q(Er),Ag=q(xr),ne=et;(Ar&&ne(new Ar(new ArrayBuffer(1)))!=ci||Xe&&ne(new Xe)!=ai||Sr&&ne(Sr.resolve())!=li||Er&&ne(new Er)!=si||xr&&ne(new xr)!=ui)&&(ne=function(e){var t=et(e),n=t==wg?e.constructor:void 0,r=n?q(n):"";if(r)switch(r){case Cg:return ci;case Mg:return ai;case Ig:return li;case xg:return si;case Ag:return ui}return t});var Kw=U.Uint8Array,Sg="__lodash_hash_undefined__";function Eg(e){return this.__data__.set(e,Sg),this}var jg=Eg;function Lg(e){return this.__data__.has(e)}var Tg=Lg;function jr(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Mi;++t<n;)this.add(e[t])}jr.prototype.add=jr.prototype.push=jg;jr.prototype.has=Tg;var di=oe?oe.prototype:void 0,Jw=di?di.valueOf:void 0,$g=Object.prototype,Xw=$g.hasOwnProperty,Ng=Object.prototype,eC=Ng.hasOwnProperty,tC=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),rC=new RegExp(/[A-Fa-f0-9]{1}/,"g"),nC=new RegExp(/[A-Fa-f0-9]{2}/,"g");function Dg(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function Ii(e,t){if(e.startsWith("buffer:")){let n=await t.editor.getMimeType(e),r=t.editor.getBufferLength(e),a=t.editor.getBufferData(e,0,r),o=new Blob([a],{type:n});return URL.createObjectURL(o)}else return e}async function Lr(e,t){let n=await Ii(e,t);return new Promise((r,a)=>{let o=new Image;o.onload=()=>{r({width:o.width,height:o.height})},o.onerror=a,o.src=n})}async function Og(e,t,n){let r,a=t.block.getFill(e),o=t.block.getSourceSet(a,"fill/image/sourceSet"),[i]=o;if(i==null){if(r=t.block.getString(a,"fill/image/imageFileURI"),r==null)throw new Error("No image source/uri found")}else r=i.uri;if(n?.throwErrorIfSvg&&await t.editor.getMimeType(r)==="image/svg+xml")throw new Error("SVG images are not supported");return Ii(r,t)}function xi(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let n=t.substring(2).split("/"),r=e;for(let a of n){if(r==null)throw new Error(`Invalid reference path: ${t}`);r=r[a]}if(r===void 0)throw new Error(`Reference not found: ${t}`);return r}function Ze(e,t,n=new Set){if(t==null||n.has(t))return t;if(n.add(t),t.$ref&&typeof t.$ref=="string"){let r=xi(e,t.$ref),a={...Ze(e,r,n)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(a[o]=Ze(e,t[o],n));return a}if(Array.isArray(t))return t.map(r=>Ze(e,r,n));if(typeof t=="object"){let r={};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=Ze(e,t[a],n));return r}return t}function _g(e){return Ze(e,{...e})}function Pg(e,t=!1){let n=i=>(t&&console.log(`OpenAPI Schema validation failed: ${i}`),!1);if(typeof e!="object"||e===null)return n(`Input is ${e===null?"null":typeof e}, not an object`);let r=e;if(!(typeof r.type=="string"||Array.isArray(r.enum)||typeof r.properties=="object"||typeof r.items=="object"||typeof r.allOf=="object"||typeof r.anyOf=="object"||typeof r.oneOf=="object"||typeof r.not=="object"))return n("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(r.type!==void 0){let i=["string","number","integer","boolean","array","object","null"];if(typeof r.type=="string"){if(!i.includes(r.type))return n(`Invalid type: ${r.type}. Must be one of ${i.join(", ")}`)}else if(Array.isArray(r.type)){for(let l of r.type)if(typeof l!="string"||!i.includes(l))return n(`Array of types contains invalid value: ${l}. Must be one of ${i.join(", ")}`)}else return n(`Type must be a string or array of strings, got ${typeof r.type}`)}if(r.items!==void 0&&(typeof r.items!="object"||r.items===null))return n(`Items must be an object, got ${r.items===null?"null":typeof r.items}`);if(r.properties!==void 0&&(typeof r.properties!="object"||r.properties===null))return n(`Properties must be an object, got ${r.properties===null?"null":typeof r.properties}`);let a=["allOf","anyOf","oneOf"];for(let i of a)if(r[i]!==void 0){if(!Array.isArray(r[i]))return n(`${i} must be an array, got ${typeof r[i]}`);for(let l=0;l<r[i].length;l++){let u=r[i][l];if(typeof u!="object"||u===null)return n(`Item ${l} in ${i} must be an object, got ${u===null?"null":typeof u}`)}}if(r.not!==void 0&&(typeof r.not!="object"||r.not===null))return n(`'not' must be an object, got ${r.not===null?"null":typeof r.not}`);if(r.additionalProperties!==void 0&&typeof r.additionalProperties!="boolean"&&(typeof r.additionalProperties!="object"||r.additionalProperties===null))return n(`additionalProperties must be a boolean or an object, got ${r.additionalProperties===null?"null":typeof r.additionalProperties}`);if(r.format!==void 0&&typeof r.format!="string")return n(`format must be a string, got ${typeof r.format}`);let o=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let i of o)if(r[i]!==void 0&&typeof r[i]!="number")return n(`${i} must be a number, got ${typeof r[i]}`);if(r.minLength!==void 0&&(typeof r.minLength!="number"||r.minLength<0))return n(`minLength must be a non-negative number, got ${typeof r.minLength=="number"?r.minLength:typeof r.minLength}`);if(r.maxLength!==void 0&&(typeof r.maxLength!="number"||r.maxLength<0))return n(`maxLength must be a non-negative number, got ${typeof r.maxLength=="number"?r.maxLength:typeof r.maxLength}`);if(r.pattern!==void 0&&typeof r.pattern!="string")return n(`pattern must be a string, got ${typeof r.pattern}`);if(r.minItems!==void 0&&(typeof r.minItems!="number"||r.minItems<0))return n(`minItems must be a non-negative number, got ${typeof r.minItems=="number"?r.minItems:typeof r.minItems}`);if(r.maxItems!==void 0&&(typeof r.maxItems!="number"||r.maxItems<0))return n(`maxItems must be a non-negative number, got ${typeof r.maxItems=="number"?r.maxItems:typeof r.maxItems}`);if(r.uniqueItems!==void 0&&typeof r.uniqueItems!="boolean")return n(`uniqueItems must be a boolean, got ${typeof r.uniqueItems}`);if(r.minProperties!==void 0&&(typeof r.minProperties!="number"||r.minProperties<0))return n(`minProperties must be a non-negative number, got ${typeof r.minProperties=="number"?r.minProperties:typeof r.minProperties}`);if(r.maxProperties!==void 0&&(typeof r.maxProperties!="number"||r.maxProperties<0))return n(`maxProperties must be a non-negative number, got ${typeof r.maxProperties=="number"?r.maxProperties:typeof r.maxProperties}`);if(r.required!==void 0){if(!Array.isArray(r.required))return n(`required must be an array, got ${typeof r.required}`);for(let i=0;i<r.required.length;i++){let l=r.required[i];if(typeof l!="string")return n(`Item ${i} in required array must be a string, got ${typeof l}`)}}return!0}function zg(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let n=e.properties,r=[];return Ug(e,t).forEach(a=>{let o=a,i=n[a]??void 0;r.push({id:o,schema:i})}),r}function Ug(e,t){let n=t.order;if(n!=null&&Array.isArray(n))return n;if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,a=Object.keys(r),o=Vg(e,t)??a;return n!=null&&typeof n=="function"&&(o=n(o)),[...new Set(o)]}function Vg(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let n=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(r=>r in e);return n==null?void 0:e[n]}var Ai=zg,Bg="ly.img.ai",wr="ly.img.ai/temp";async function Fg(e,t){return e.engine.asset.findAllSources().includes(wr)||e.engine.asset.addLocalSource(wr),e.engine.asset.apply(wr,t)}function Si(e){return`${Bg}/${e}`}function Gg(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let n=e;return"message"in n&&typeof n.message=="string"?n.message:"cause"in n&&typeof n.cause=="string"?n.cause:"detail"in n&&typeof n.detail=="object"&&n.detail!==null&&"message"in n.detail&&typeof n.detail.message=="string"?n.detail.message:"error"in n&&typeof n.error=="object"&&n.error!==null&&"message"in n.error&&typeof n.error.message=="string"?n.error.message:t}return typeof e=="string"?e:String(e)||t}function Rg(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function qg(e,t=0,n="image/jpeg",r=.8){return new Promise((a,o)=>{try{let i=document.createElement("video");i.crossOrigin="anonymous",i.style.display="none",i.addEventListener("loadedmetadata",()=>{i.currentTime=Math.min(t,i.duration),i.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=i.videoWidth,l.height=i.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(i),o(new Error("Failed to create canvas context"));return}u.drawImage(i,0,0,l.width,l.height);try{let s=l.toDataURL(n,r);document.body.removeChild(i),a(s)}catch(s){document.body.removeChild(i),o(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),i.addEventListener("error",()=>{document.body.removeChild(i),o(new Error(`Failed to load video from ${e}`))}),i.src=e,document.body.appendChild(i)}catch(i){o(i)}})}function Ei(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function $r(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function ae(e){return e instanceof Error&&e.name==="AbortError"}function ji(e,t,n,r,a,o){if(t.schema==null)return r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null?r.renderCustomProperty[t.id](e,t):void 0;let i=t,l=t.schema.type;if(r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null)return r.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?Qg(e,i,n,r,a,o):Ti(e,i,n,r,a,o);case"boolean":return $i(e,i,n,r,a,o);case"number":case"integer":return Ni(e,i,n,r,a,o);case"object":return Li(e,i,n,r,a,o);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return Hg(e,i,n,r,a,o);break}default:console.error(`Unsupported property type: ${l}`)}}function Li(e,t,n,r,a,o){let i=Ai(t.schema??{},r).reduce((l,u)=>{let s=ji(e,u,n,r,a,o);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:i})}function Ti(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),g=Yg(t.schema),f=g?.component!=null&&g?.component==="TextArea"?"TextArea":"TextInput";return i[f](s,{inputLabel:c,placeholder:a.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function Qg(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},g="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},f=(t.schema.enum??[]).map(b=>({id:b,label:d[b]??Ei(b),icon:g[b]})),v=t.schema.default!=null?f.find(b=>b.id===t.schema.default)??f[0]:f[0],w=l(s,v);return i.Select(s,{inputLabel:c,values:f,...w}),()=>({id:t.id,type:"string",value:w.value.id})}function $i(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,g=l(s,d);return i.Checkbox(s,{inputLabel:c,...g}),()=>({id:t.id,type:"boolean",value:g.value})}function Ni(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,g=t.schema.maximum,f=t.schema.default;f==null&&(d!=null?f=d:g!=null?f=g:f=0);let v=l(s,f);if(d!=null&&g!=null){let w=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(w=t.schema["x-imgly-step"]),i.Slider(s,{inputLabel:c,min:d,max:g,step:w,...v})}else i.NumberInput(s,{inputLabel:c,min:d,max:g,...v});return()=>({id:t.id,type:"integer",value:v.value})}function Hg(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],g=[],f={},v={};d.forEach((p,h)=>{let m=p.title??"common.custom",y=`${n.id}.${u}.anyOf[${h}]`,k="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},C="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};p.type==="string"?p.enum!=null?p.enum.forEach(M=>{g.push({id:M,label:k[M]??Ei(M),icon:C[M]})}):(f[y]=()=>Ti(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="boolean"?(f[y]=()=>$i(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="integer"?(f[y]=()=>Ni(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="array"||p.type==="object"&&(f[y]=()=>Li(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]}))});let w=t.schema.default!=null?g.find(p=>p.id===t.schema.default)??g[0]:g[0],b=l(s,w);if(i.Select(s,{inputLabel:c,values:g,...b}),b.value.id in f){let p=f[b.value.id]();v[b.value.id]=p}return()=>{let p=v[b.value.id];return p!=null?{...p(),id:t.id}:{id:t.id,type:"string",value:b.value.id}}}function Yg(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Zg=ji,Wg="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Di=Wg;function Kg(e,t,n){switch(t){case"image":return Jg(e,n[t]);case"video":return Xg(e,n[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Jg(e,t){let n=t.width,r=t.height;return{id:e,meta:{previewUri:Di,fillType:"//ly.img.ubq/fill/image",kind:"image",width:n,height:r}}}function Xg(e,t){let n=t.width,r=t.height;return{id:e,label:t.label,meta:{previewUri:Di,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:n,height:r}}}var ep=Kg;async function tp(e,t,n,r){switch(t){case"image":{if(r.kind!=="image")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: image)`);return rp(e,n[t],r)}case"video":{if(r.kind!=="video")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: video)`);return np(e,n[t],r)}case"audio":{if(r.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: audio)`);return ip(e,n[t],r)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function rp(e,t,n){let r=t.width,a=t.height;return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:a},payload:{sourceSet:[{uri:n.url,width:r,height:a}]}}}async function np(e,t,n){let r=t.width,a=t.height,o=await qg(n.url,0);return{id:e,label:t.label,meta:{uri:n.url,thumbUri:o,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:a}}}function ip(e,t,n){return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:n.duration.toString()}}}var gi=tp;function Oi(e){let t=e.filter(n=>!!n);return n=>async(r,a)=>{let o=[],i=s=>{o.push(s)},l=async(s,c,d)=>{if(s>=t.length)return n(c,d);let g=t[s],f=async(w,b)=>l(s+1,w,b),v={...d,addDisposer:i};return g(c,v,f)},u={...a,addDisposer:i};return{result:await l(0,r,u),dispose:async()=>{for(let s=o.length-1;s>=0;s--)try{await o[s]()}catch(c){console.error("Error in disposer:",c)}o.length=0}}}}function op(){return async(e,t,n)=>{console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(e,null,2));let r,a=Date.now();try{return r=await n(e,t),r}finally{r!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(r,null,2))),console.groupEnd()}}}var _i=op;function ap(e){return async(t,n)=>(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await cp(2e3),await lp(t,e,n))}async function lp(e,t,n){switch(t.kind){case"image":return sp(e,t,n);case"video":return up(e,t,n);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function sp(e,t,{engine:n}){let r,a,o=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",i=o.match(/(\d+)x(\d+)/);if(i!=null)r=parseInt(i[1],10),a=parseInt(i[2],10);else if(t.blockInputs!=null&&(r=t.blockInputs.image.width,a=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await Og(l,n),s=await Lr(u,n);r=s.width,a=s.height}else r=512,a=512;return{kind:"image",url:`https://placehold.co/${r}x${a}/000000/FFF?text=${o.replace(" ","+").replace(`
63
- `,"+")}`}}async function up(e,t,n){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function cp(e){return new Promise(t=>{setTimeout(t,e)})}var Pi=ap;async function dp(e,t,n,r,a,o,i){let{cesdk:l,createPlaceholderBlock:u,historyAssetSourceId:s}=a,c;try{o.debug&&console.group(`Starting Generation for '${e}'`);let d=t(),g=await n(d.input),f=Rg(),v;if(u){if(v=ep(f,e,g),o.debug&&console.log("Adding as asset to scene:",JSON.stringify(v,void 0,2)),c=await Fg(l,v),c!=null&&r.kind==="video"){let h=l.engine.block.getPositionX(c),m=l.engine.block.getPositionY(c),y=l.engine.block.duplicate(c);l.engine.block.setPositionX(y,h),l.engine.block.setPositionY(y,m),l.engine.block.destroy(c),c=y}if(Vt(l,i,c))return{status:"aborted"};if(c==null)throw new Error("Could not create placeholder block");l.engine.block.setState(c,{type:"Pending",progress:0})}let w=Oi([...r.output.middleware??[],o.debug?_i():void 0,o.dryRun?Pi({kind:r.kind,blockInputs:g}):void 0]),{result:b}=await w(r.output.generate)(d.input,{abortSignal:i,engine:a.engine,cesdk:l});if($r(b))throw new Error("Streaming generation is not supported yet from a panel");if(Vt(l,i,c))return{status:"aborted"};if(b==null)throw new Error("Generation failed");o.debug&&console.log("Generated output:",JSON.stringify(b,void 0,2));let p;if(c!=null&&l.engine.block.isValid(c)&&(p=await gi(f,e,g,b),o.debug&&console.log("Updating asset in scene:",JSON.stringify(p,void 0,2)),await l.engine.asset.defaultApplyAssetToBlock(p,c)),Vt(l,i,c))return{status:"aborted"};if(s!=null){if(p==null&&(p=await gi(f,e,g,b),Vt(l,i,c)))return{status:"aborted"};let h={...p,id:`${Date.now()}-${p.id}`,label:p.label!=null?{en:p.label}:{},tags:{}};l.engine.asset.addAssetToSource(s,h)}return c!=null&&l.engine.block.isValid(c)&&l.engine.block.setState(c,{type:"Ready"}),{status:"success",output:b}}catch(d){throw c!=null&&l.engine.block.isValid(c)&&(ae(d)?l.engine.block.destroy(c):l.engine.block.setState(c,{type:"Error",error:"Unknown"})),d}finally{o.debug&&console.groupEnd()}}function Vt(e,t,n){return t.aborted?(n!=null&&e.engine.block.isValid(n)&&e.engine.block.destroy(n),!0):!1}var gp=dp;function pp(e,t,n){let{cesdk:r,provider:a,getInput:o}=t;n.onError!=null&&typeof n.onError=="function"?n.onError(e):(console.error("Generation failed:",e),mp(r,a.output.notification,()=>({input:o?.().input,error:e}))||r.ui.showNotification({type:"error",message:Gg(e)}))}function mp(e,t,n){let r=t?.error;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.failed",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"error",message:a,action:o}),!0}var We=pp;function Bt(e){return`${e}.generating`}function fp(e){return`${e}.abort`}function yp(e,t,n,r,a,o){let{builder:i,experimental:l}=e,{cesdk:u,includeHistoryLibrary:s=!0}=a,{id:c,output:{abortable:d}}=t,g=l.global(fp(c),()=>{}),f=l.global(Bt(c),!1),v,w=f.value&&d,b=()=>{w&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},p;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let m=n();p=a.requiredInputs.every(y=>!m.input[y])}let h=l.global(`${c}.confirmationDialogId`,void 0);i.Section(`${c}.generate.section`,{children:()=>{i.Button(`${c}.generate`,{label:["common.ai-generation.generate",`panel.${c}.generate`],isLoading:f.value,color:"accent",isDisabled:p,suffix:w?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${c}.abort`,"common.cancel"],onClick:()=>{let m=u.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{u.ui.closeDialog(y),h.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{b(),u.ui.closeDialog(y),h.setValue(void 0)}}});h.setValue(m)}}:void 0,onClick:async()=>{v=new AbortController;let m=v.signal,y=async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),v?.abort()});let k=await gp(t.kind,n,r,t,a,o,m);if(k.status==="aborted")return;let C=t.output.notification;bp(u,C,()=>({input:n().input,output:k.output}))}catch(k){if(ae(k))return;We(k,{cesdk:u,provider:t,getInput:n},o)}finally{v=void 0,f.setValue(!1),g.setValue(()=>{}),h.value!=null&&(u.ui.closeDialog(h.value),h.setValue(void 0))}};o.middleware!=null?await o.middleware(y,{provider:t,abort:b}):await y()}}),t.output.generationHintText!=null&&i.Text(`${c}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),s&&a.historyAssetLibraryEntryId!=null&&i.Library(`${c}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function bp(e,t,n){let r=t?.success;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.success",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"success",message:a,action:o,duration:r.duration}),!0}var zi=yp;async function hp(e,t,n,r){let{cesdk:a}=n,{id:o}=e;r.debug&&console.log(`Registering schema-based panel input for provider ${o}`);let i=_g(t.document),l=xi(i,t.inputReference);if(!Pg(l,r.debug))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=Ai(u,t),c=d=>{let{builder:g}=d,f=[];g.Section(`${o}.schema.section`,{children:()=>{s.forEach(p=>{let h=Zg(d,p,e,t,n,r);h!=null&&(Array.isArray(h)?f.push(...h):f.push(h))})}});let v=f.map(p=>p()),w=p=>p.type==="object"?Object.entries(p.value).reduce((h,[m,y])=>(h[m]=w(y),h),{}):p.value,b=v.reduce((p,h)=>(p[h.id]=w(h),p),{});zi(d,e,()=>({input:b}),()=>t.getBlockInput(b),{...n,requiredInputs:u.required,createPlaceholderBlock:t.userFlow==="placeholder"},r)};return a.ui.registerPanel(Si(o),c),c}var vp=hp;async function kp(e,t,n,r){let{cesdk:a}=n,{id:o}=e,i=t.render,l=u=>{let{state:s}=u,c=s(Bt(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:g}=i(u,{cesdk:a,isGenerating:c});return zi(u,e,d,g,{...n,includeHistoryLibrary:t.includeHistoryLibrary??!0,createPlaceholderBlock:t.userFlow==="placeholder"},r),d};return a.ui.registerPanel(Si(o),l),l}var wp=kp,Cr="@imgly/plugin-ai-generation",Cp=`
65
+ `;var w0=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",p=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(p=s.tags[c]);let g={...s,label:d,tags:p};return this.filterAsset(g,e)&&u.push(g),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),l=a<t.length?r+1:void 0;return{assets:o,currentPage:r,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let i=new Set;r.result.forEach(a=>{a.groups&&Array.isArray(a.groups)&&a.groups.forEach(o=>i.add(o))});let n=[...i];e(n)},r.onerror=()=>{t(new Error(`Failed to get groups: ${r.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),r=t.objectStore(this.assetStoreName),i=new Set;Qe(e,a=>{i.add(a)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.assetStoreName,"readwrite");r.objectStore(this.assetStoreName).delete(e),r.oncomplete=()=>{Qe(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let l=a.meta?.insertedAt||a._insertedAt||Date.now(),u=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return Qe(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),Qe(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!o.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(l=>e.tags?.includes(l))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,l)=>{let u,s;return i==="id"?(u=o.id,s=l.id):(u=o.meta?.[i]??null,s=l.meta?.[i]??null),u==null?r==="Ascending"?-1:1:s==null?r==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?r==="Ascending"?u.localeCompare(s):s.localeCompare(u):r==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):r==="Descending"&&a.reverse(),n&&a.sort((o,l)=>o.active&&!l.active?-1:!o.active&&l.active?1:0)),a}};function Qe(e,t,r=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let i=0;i<e.length;i++){let n=r?`${r}[${i}]`:`[${i}]`;if(typeof e[i]=="string"&&e[i].startsWith("blob:")){let a=t(e[i],n);typeof a=="string"&&(e[i]=a)}else e[i]=Qe(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],a=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let o=t(n,a);typeof o=="string"&&(e[i]=o)}else e[i]=Qe(n,t,a)}return e}var k0=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,d)=>{let p=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,l=o+a,u=i.slice(o,l),s=l<i.length?n+1:void 0;return{assets:u,currentPage:n,nextPage:s,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}},x0=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},Ps=x0,I0=typeof global=="object"&&global&&global.Object===Object&&global,zs=I0,C0=typeof self=="object"&&self&&self.Object===Object&&self,A0=zs||C0||Function("return this")(),H=A0,M0=H.Symbol,We=M0,Us=Object.prototype,j0=Us.hasOwnProperty,S0=Us.toString,wr=We?We.toStringTag:void 0;function E0(e){var t=j0.call(e,wr),r=e[wr];try{e[wr]=void 0;var i=!0}catch{}var n=S0.call(e);return i&&(t?e[wr]=r:delete e[wr]),n}var _0=E0,L0=Object.prototype,T0=L0.toString;function $0(e){return T0.call(e)}var N0=$0,O0="[object Null]",D0="[object Undefined]",ns=We?We.toStringTag:void 0;function P0(e){return e==null?e===void 0?D0:O0:ns&&ns in Object(e)?_0(e):N0(e)}var Nr=P0;function z0(e){return e!=null&&typeof e=="object"}var Co=z0,hW=Array.isArray;function U0(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Rs=U0,R0="[object AsyncFunction]",F0="[object Function]",V0="[object GeneratorFunction]",B0="[object Proxy]";function G0(e){if(!Rs(e))return!1;var t=Nr(e);return t==F0||t==V0||t==R0||t==B0}var q0=G0,Y0=H["__core-js_shared__"],no=Y0,os=function(){var e=/[^.]+$/.exec(no&&no.keys&&no.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function H0(e){return!!os&&os in e}var Z0=H0,Q0=Function.prototype,W0=Q0.toString;function K0(e){if(e!=null){try{return W0.call(e)}catch{}try{return e+""}catch{}}return""}var xe=K0,J0=/[\\^$.*+?()[\]{}|]/g,X0=/^\[object .+?Constructor\]$/,e2=Function.prototype,t2=Object.prototype,r2=e2.toString,i2=t2.hasOwnProperty,n2=RegExp("^"+r2.call(i2).replace(J0,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function o2(e){if(!Rs(e)||Z0(e))return!1;var t=q0(e)?n2:X0;return t.test(xe(e))}var a2=o2;function l2(e,t){return e?.[t]}var s2=l2;function u2(e,t){var r=s2(e,t);return a2(r)?r:void 0}var Je=u2,c2=Je(H,"WeakMap"),go=c2;function d2(e,t){return e===t||e!==e&&t!==t}var p2=d2,g2=9007199254740991;function f2(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=g2}var h2=f2,mW=Object.prototype,m2="[object Arguments]";function y2(e){return Co(e)&&Nr(e)==m2}var as=y2,Fs=Object.prototype,b2=Fs.hasOwnProperty,v2=Fs.propertyIsEnumerable,yW=as(function(){return arguments}())?as:function(e){return Co(e)&&b2.call(e,"callee")&&!v2.call(e,"callee")},Vs=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ls=Vs&&typeof module=="object"&&module&&!module.nodeType&&module,w2=ls&&ls.exports===Vs,ss=w2?H.Buffer:void 0,bW=ss?ss.isBuffer:void 0,k2="[object Arguments]",x2="[object Array]",I2="[object Boolean]",C2="[object Date]",A2="[object Error]",M2="[object Function]",j2="[object Map]",S2="[object Number]",E2="[object Object]",_2="[object RegExp]",L2="[object Set]",T2="[object String]",$2="[object WeakMap]",N2="[object ArrayBuffer]",O2="[object DataView]",D2="[object Float32Array]",P2="[object Float64Array]",z2="[object Int8Array]",U2="[object Int16Array]",R2="[object Int32Array]",F2="[object Uint8Array]",V2="[object Uint8ClampedArray]",B2="[object Uint16Array]",G2="[object Uint32Array]",j={};j[D2]=j[P2]=j[z2]=j[U2]=j[R2]=j[F2]=j[V2]=j[B2]=j[G2]=!0;j[k2]=j[x2]=j[N2]=j[I2]=j[O2]=j[C2]=j[A2]=j[M2]=j[j2]=j[S2]=j[E2]=j[_2]=j[L2]=j[T2]=j[$2]=!1;function q2(e){return Co(e)&&h2(e.length)&&!!j[Nr(e)]}var Y2=q2;function H2(e){return function(t){return e(t)}}var Z2=H2,Bs=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Sr=Bs&&typeof module=="object"&&module&&!module.nodeType&&module,Q2=Sr&&Sr.exports===Bs,oo=Q2&&zs.process,W2=function(){try{var e=Sr&&Sr.require&&Sr.require("util").types;return e||oo&&oo.binding&&oo.binding("util")}catch{}}(),us=W2,cs=us&&us.isTypedArray,vW=cs?Z2(cs):Y2,K2=Object.prototype,wW=K2.hasOwnProperty;function J2(e,t){return function(r){return e(t(r))}}var X2=J2,kW=X2(Object.keys,Object),e4=Object.prototype,xW=e4.hasOwnProperty,t4=Je(Object,"create"),_r=t4;function r4(){this.__data__=_r?_r(null):{},this.size=0}var i4=r4;function n4(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var o4=n4,a4="__lodash_hash_undefined__",l4=Object.prototype,s4=l4.hasOwnProperty;function u4(e){var t=this.__data__;if(_r){var r=t[e];return r===a4?void 0:r}return s4.call(t,e)?t[e]:void 0}var c4=u4,d4=Object.prototype,p4=d4.hasOwnProperty;function g4(e){var t=this.__data__;return _r?t[e]!==void 0:p4.call(t,e)}var f4=g4,h4="__lodash_hash_undefined__";function m4(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=_r&&t===void 0?h4:t,this}var y4=m4;function Xe(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Xe.prototype.clear=i4;Xe.prototype.delete=o4;Xe.prototype.get=c4;Xe.prototype.has=f4;Xe.prototype.set=y4;var ds=Xe;function b4(){this.__data__=[],this.size=0}var v4=b4;function w4(e,t){for(var r=e.length;r--;)if(p2(e[r][0],t))return r;return-1}var Xi=w4,k4=Array.prototype,x4=k4.splice;function I4(e){var t=this.__data__,r=Xi(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():x4.call(t,r,1),--this.size,!0}var C4=I4;function A4(e){var t=this.__data__,r=Xi(t,e);return r<0?void 0:t[r][1]}var M4=A4;function j4(e){return Xi(this.__data__,e)>-1}var S4=j4;function E4(e,t){var r=this.__data__,i=Xi(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var _4=E4;function et(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}et.prototype.clear=v4;et.prototype.delete=C4;et.prototype.get=M4;et.prototype.has=S4;et.prototype.set=_4;var en=et,L4=Je(H,"Map"),Lr=L4;function T4(){this.size=0,this.__data__={hash:new ds,map:new(Lr||en),string:new ds}}var $4=T4;function N4(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var O4=N4;function D4(e,t){var r=e.__data__;return O4(t)?r[typeof t=="string"?"string":"hash"]:r.map}var tn=D4;function P4(e){var t=tn(this,e).delete(e);return this.size-=t?1:0,t}var z4=P4;function U4(e){return tn(this,e).get(e)}var R4=U4;function F4(e){return tn(this,e).has(e)}var V4=F4;function B4(e,t){var r=tn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var G4=B4;function tt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}tt.prototype.clear=$4;tt.prototype.delete=z4;tt.prototype.get=R4;tt.prototype.has=V4;tt.prototype.set=G4;var Gs=tt;function q4(){this.__data__=new en,this.size=0}var Y4=q4;function H4(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Z4=H4;function Q4(e){return this.__data__.get(e)}var W4=Q4;function K4(e){return this.__data__.has(e)}var J4=K4,X4=200;function e5(e,t){var r=this.__data__;if(r instanceof en){var i=r.__data__;if(!Lr||i.length<X4-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Gs(i)}return r.set(e,t),this.size=r.size,this}var t5=e5;function Or(e){var t=this.__data__=new en(e);this.size=t.size}Or.prototype.clear=Y4;Or.prototype.delete=Z4;Or.prototype.get=W4;Or.prototype.has=J4;Or.prototype.set=t5;var r5=Object.prototype,IW=r5.propertyIsEnumerable,i5=Je(H,"DataView"),fo=i5,n5=Je(H,"Promise"),ho=n5,o5=Je(H,"Set"),mo=o5,ps="[object Map]",a5="[object Object]",gs="[object Promise]",fs="[object Set]",hs="[object WeakMap]",ms="[object DataView]",l5=xe(fo),s5=xe(Lr),u5=xe(ho),c5=xe(mo),d5=xe(go),He=Nr;(fo&&He(new fo(new ArrayBuffer(1)))!=ms||Lr&&He(new Lr)!=ps||ho&&He(ho.resolve())!=gs||mo&&He(new mo)!=fs||go&&He(new go)!=hs)&&(He=function(e){var t=Nr(e),r=t==a5?e.constructor:void 0,i=r?xe(r):"";if(i)switch(i){case l5:return ms;case s5:return ps;case u5:return gs;case c5:return fs;case d5:return hs}return t});var CW=H.Uint8Array,p5="__lodash_hash_undefined__";function g5(e){return this.__data__.set(e,p5),this}var f5=g5;function h5(e){return this.__data__.has(e)}var m5=h5;function yo(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Gs;++t<r;)this.add(e[t])}yo.prototype.add=yo.prototype.push=f5;yo.prototype.has=m5;var ys=We?We.prototype:void 0,AW=ys?ys.valueOf:void 0,y5=Object.prototype,MW=y5.hasOwnProperty,b5=Object.prototype,jW=b5.hasOwnProperty,SW=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),EW=new RegExp(/[A-Fa-f0-9]{1}/,"g"),_W=new RegExp(/[A-Fa-f0-9]{2}/,"g");function v5(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function qs(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function bo(e,t){let r=await qs(e,t);return new Promise((i,n)=>{let a=new Image;a.onload=()=>{i({width:a.width,height:a.height})},a.onerror=n,a.src=r})}async function w5(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return qs(i,t)}function k5(e){return e!==void 0}var rn=k5,Ys=class Hs{constructor(){this.actions=new Map,this.subscribers=new Map}static get(){let t="__imgly_action_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new Hs),r[t]}register(t){return this.actions.set(t.id,t),this.notifySubscribers(t,"registered"),()=>{this.actions.get(t.id)===t&&(this.actions.delete(t.id),this.notifySubscribers(t,"unregistered"))}}getAll(){return Array.from(this.actions.values())}getBy(t){return this.getAll().filter(r=>this.matchesFilters(r,t))}subscribe(t){return this.subscribers.set(t,null),()=>{this.subscribers.delete(t)}}subscribeBy(t,r){return this.subscribers.set(r,t),()=>{this.subscribers.delete(r)}}notifySubscribers(t,r){this.subscribers.forEach((i,n)=>{if(i===null){n(t,r);return}this.matchesFilters(t,i)&&n(t,r)})}matchesFilters(t,r){return!(r.type&&t.type!==r.type||r.pluginId&&t.type==="plugin"&&t.pluginId!==r.pluginId||r.id&&t.id!==r.id||r.kind&&(t.type!=="quick"||t.kind!==r.kind))}},Zs=class Qs{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new Qs),r[t]}register(t){return this.providers.has(t.provider.id)&&console.warn(`Provider with ID "${t.provider.id}" is already registered`),this.providers.set(t.provider.id,t),()=>{this.providers.get(t.provider.id)===t&&this.providers.delete(t.provider.id)}}getAll(){return Array.from(this.providers.values())}getById(t){return this.providers.get(t)}getByKind(t){return this.getAll().filter(({provider:r})=>r.kind===t)}};function x5(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=s=>{a.push(s)},l=async(s,c,d)=>{if(s>=t.length)return r(c,d);let p=t[s],g=async(b,m)=>l(s+1,b,m),f={...d,addDisposer:o};return p(c,f,g)},u={...n,addDisposer:o};return{result:await l(0,i,u),dispose:async()=>{for(let s=a.length-1;s>=0;s--)try{await a[s]()}catch(c){console.error("Error in disposer:",c)}a.length=0}}}}function I5({enable:e=!0}){return async(t,r,i)=>{if(!e)return i(t,r);console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(t,null,2));let n,a=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var C5=I5,ao="ly.img.ai.temp";async function A5(e,t){return e.engine.asset.findAllSources().includes(ao)||e.engine.asset.addLocalSource(ao),e.engine.asset.apply(ao,t)}function M5(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let r=e;return"message"in r&&typeof r.message=="string"?r.message:"cause"in r&&typeof r.cause=="string"?r.cause:"detail"in r&&typeof r.detail=="object"&&r.detail!==null&&"message"in r.detail&&typeof r.detail.message=="string"?r.detail.message:"error"in r&&typeof r.error=="object"&&r.error!==null&&"message"in r.error&&typeof r.error.message=="string"?r.error.message:t}return typeof e=="string"?e:String(e)||t}function Ws(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function j5(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=o.videoWidth,l.height=o.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}u.drawImage(o,0,0,l.width,l.height);try{let s=l.toDataURL(r,i);document.body.removeChild(o),n(s)}catch(s){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function Ks(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function S5(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function Ao(e){return e instanceof Error&&e.name==="AbortError"}function E5(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function _5(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
66
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
67
+ This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version.
68
+ Consider updating all AI plugins to the same version for optimal compatibility.`),e.ui.experimental.setGlobalStateValue(n,!0))):e.ui.experimental.setGlobalStateValue(i,r)}catch(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}function L5(e){let{cesdk:t,panelId:r}=e;r.startsWith("ly.img.ai.")||console.warn(`Dock components for AI generation should open a panel with an id starting with "ly.img.ai." \u2013 "${r}" was provided.`);let i=`${r}.dock`;t.ui.registerComponent(i,({builder:n})=>{let a=t.ui.isPanelOpen(r);n.Button(`${r}.dock.button`,{label:`${r}.dock.label`,isSelected:a,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(o=>{o.startsWith("ly.img.ai.")&&t.ui.closePanel(o),!a&&o==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(o)}),a?t.ui.closePanel(r):t.ui.openPanel(r)}})})}var T5=L5;function $5(){return({engine:e})=>{let t=e.block.findAllSelected();if(t==null||t.length!==1)return!1;let[r]=t;if(!e.block.supportsFill(r)||e.block.getKind(r)==="sticker"||!["//ly.img.ubq/graphic","//ly.img.ubq/page"].includes(e.block.getType(r)))return!1;let i=e.block.getFill(r);return e.block.getType(i)==="//ly.img.ubq/fill/image"}}var Dr=$5;function N5(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),O5(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:M5(e)})}function O5(e,t,r){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.failed",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"error",message:n,action:a}),!0}var bs=N5,D5="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Mo=D5;function P5(e,t,r){switch(t){case"image":return z5(e,r[t]);case"video":return U5(e,r[t]);case"sticker":return R5(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function z5(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Mo,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function U5(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Mo,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function R5(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Mo,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var F5=P5;async function V5(e,t,r,i){switch(t){case"image":{if(i.kind!=="image")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: image)`);return B5(e,r[t],i)}case"video":{if(i.kind!=="video")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: video)`);return G5(e,r[t],i)}case"audio":{if(i.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: audio)`);return q5(e,r[t],i)}case"sticker":{if(i.kind!=="sticker")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: sticker)`);return Y5(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function B5(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}async function G5(e,t,r){let i=t.width,n=t.height,a=await j5(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:a,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function q5(e,t,r){return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:r.duration.toString()}}}function Y5(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}var Js=V5;function H5(e){switch(e.userFlow){case"placeholder":return Q5(e);case"generation-only":return Z5(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function Z5(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(ue(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(ue(t,r))return{status:"aborted"};if(o.status!=="success")return o;if(o.type==="async")throw new Error("Async generation is not supported in this context yet.");if(ue(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let l=Ws(),u=await Js(l,n,a,o.output),s={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,s)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Q5(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(ue(t,r))return{status:"aborted"};let l=Ws(),u=F5(l,a,o);if(i=await A5(t,u),ue(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,p),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let s=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(ue(t,r,i))return{status:"aborted"};if(s.status!=="success")return s;if(s.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let c=await Js(l,a,o,s.output);if(ue(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(c,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(c,i),ue(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),s}catch(a){return i!=null&&t.engine.block.isValid(i)&&(Ao(a)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:a instanceof Error?a.message:String(a)}}}}function ue(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var W5=H5;function jo(e){return`${e}.generating`}function K5(e){return`${e}.abort`}function J5(e,t,r,i,n,a,o){let{builder:l,experimental:u}=e,{cesdk:s,includeHistoryLibrary:c=!0}=a,{id:d,output:{abortable:p}}=t,g=u.global(K5(d),()=>{}),f=u.global(jo(d),!1),b,m=f.value&&p,h=()=>{m&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},x;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let v=i();x=a.requiredInputs.every(y=>!v.input[y])}let w=u.global(`${d}.confirmationDialogId`,void 0);l.Section(`${d}.generate.section`,{children:()=>{l.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:f.value,color:"accent",isDisabled:x,suffix:m?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let v=s.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{s.ui.closeDialog(y),w.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{h(),s.ui.closeDialog(y),w.setValue(void 0)}}});w.setValue(v)}}:void 0,onClick:async()=>{b=new AbortController;let v=b.signal;await(async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),b?.abort()});let y=await W5({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:v,cesdk:s,debug:o.debug,dryRun:o.dryRun})(i().input);if(y.status==="aborted")return;if(y.status==="error"){bs(y.message,{cesdk:s,provider:t,getInput:i});return}if(y.status==="success"&&y.type==="sync"){let k=t.output.notification;X5(s,k,()=>({input:i().input,output:y.output}))}}catch(y){if(Ao(y))return;bs(y,{cesdk:s,provider:t,getInput:i})}finally{b=void 0,f.setValue(!1),g.setValue(()=>{}),w.value!=null&&(s.ui.closeDialog(w.value),w.setValue(void 0))}})()}}),t.output.generationHintText!=null&&l.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),c&&a.historyAssetLibraryEntryId!=null&&l.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function X5(e,t,r){let i=t?.success;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.success",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"success",message:n,action:a,duration:i.duration}),!0}var Xs=J5;async function e9({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,l=r.render;return u=>{let{state:s}=u,c=s(jo(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=l(u,{cesdk:a,isGenerating:c});return Xs(u,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var t9=e9;function eu(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let r=t.substring(2).split("/"),i=e;for(let n of r){if(i==null)throw new Error(`Invalid reference path: ${t}`);i=i[n]}if(i===void 0)throw new Error(`Reference not found: ${t}`);return i}function jr(e,t,r=new Set){if(t==null||r.has(t))return t;if(r.add(t),t.$ref&&typeof t.$ref=="string"){let i=eu(e,t.$ref),n={...jr(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=jr(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>jr(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=jr(e,t[n],r));return i}return t}function r9(e){return jr(e,{...e})}function i9(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let l of i.type)if(typeof l!="string"||!o.includes(l))return r(`Array of types contains invalid value: ${l}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let l=0;l<i[o].length;l++){let u=i[o][l];if(typeof u!="object"||u===null)return r(`Item ${l} in ${o} must be an object, got ${u===null?"null":typeof u}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let l=i.required[o];if(typeof l!="string")return r(`Item ${o} in required array must be a string, got ${typeof l}`)}}return!0}function n9(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return o9(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function o9(e,t){let r=t.order;if(r!=null&&Array.isArray(r))return r;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,n=Object.keys(i),a=a9(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function a9(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let r=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return r==null?void 0:e[r]}var tu=n9;function ru(e,t,r,i,n,a){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let o=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?l9(e,o,r,i,n,a):nu(e,o,r,i,n,a);case"boolean":return ou(e,o,r,i,n,a);case"number":case"integer":return au(e,o,r,i,n,a);case"object":return iu(e,o,r,i,n,a);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return s9(e,o,r,i,n,a);break}default:console.error(`Unsupported property type: ${l}`)}}function iu(e,t,r,i,n,a){let o=tu(t.schema??{},i).reduce((l,u)=>{let s=ru(e,u,r,i,n,a);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:o})}function nu(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),p=u9(t.schema),g=p?.component!=null&&p?.component==="TextArea"?"TextArea":"TextInput";return o[g](s,{inputLabel:c,placeholder:n.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function l9(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},p="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},g=(t.schema.enum??[]).map(m=>({id:m,label:d[m]??Ks(m),icon:p[m]})),f=t.schema.default!=null?g.find(m=>m.id===t.schema.default)??g[0]:g[0],b=l(s,f);return o.Select(s,{inputLabel:c,values:g,...b}),()=>({id:t.id,type:"string",value:b.value.id})}function ou(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,p=l(s,d);return o.Checkbox(s,{inputLabel:c,...p}),()=>({id:t.id,type:"boolean",value:p.value})}function au(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,p=t.schema.maximum,g=t.schema.default;g==null&&(d!=null?g=d:p!=null?g=p:g=0);let f=l(s,g);if(d!=null&&p!=null){let b=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(b=t.schema["x-imgly-step"]),o.Slider(s,{inputLabel:c,min:d,max:p,step:b,...f})}else o.NumberInput(s,{inputLabel:c,min:d,max:p,...f});return()=>({id:t.id,type:"integer",value:f.value})}function s9(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],p=[],g={},f={};d.forEach((h,x)=>{let w=h.title??"common.custom",v=`${r.id}.${u}.anyOf[${x}]`,y="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},k="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};h.type==="string"?h.enum!=null?h.enum.forEach(I=>{p.push({id:I,label:y[I]??Ks(I),icon:k[I]})}):(g[v]=()=>nu(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="boolean"?(g[v]=()=>ou(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="integer"?(g[v]=()=>au(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="array"||h.type==="object"&&(g[v]=()=>iu(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]}))});let b=t.schema.default!=null?p.find(h=>h.id===t.schema.default)??p[0]:p[0],m=l(s,b);if(o.Select(s,{inputLabel:c,values:p,...m}),m.value.id in g){let h=g[m.value.id]();f[m.value.id]=h}return()=>{let h=f[m.value.id];return h!=null?{...h(),id:t.id}:{id:t.id,type:"string",value:m.value.id}}}function u9(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var c9=ru;async function d9({options:e,provider:t,panelInput:r,config:i},n){let{id:a}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${a}`);let o=r9(r.document),l=eu(o,r.inputReference);if(!i9(l,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=tu(u,r);return c=>{let{builder:d}=c,p=[];d.Section(`${a}.schema.section`,{children:()=>{s.forEach(m=>{let h=c9(c,m,t,r,e,i);h!=null&&(Array.isArray(h)?p.push(...h):p.push(h))})}});let g=p.map(m=>m()),f=m=>m.type==="object"?Object.entries(m.value).reduce((h,[x,w])=>(h[x]=f(w),h),{}):m.value,b=g.reduce((m,h)=>(m[h.id]=f(h),m),{});Xs(c,t,n,()=>({input:b}),()=>r.getBlockInput(b),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var p9=d9;async function g9(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return t9(e,t);case"schema":return p9(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var f9=g9;function h9(e){let{provider:t,options:{engine:r}}=e,i=t.output.history??"@imgly/local";if(i==null||i===!1)return;let n=r.asset.findAllSources();function a(){let o=`${t.id}.history`;for(;n.includes(o);)o+=`-${Math.random().toString(36).substring(2,6)}`;return o}if(i==="@imgly/local"){let o=a();return r.asset.addLocalSource(o),o}if(i==="@imgly/indexedDB"){let o=a();return r.asset.addSource(new w0(o,r)),o}return i}var m9=h9;function y9(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history.entry`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var b9=y9,lo="@imgly/plugin-ai-generation",v9=`
64
69
  <svg>
65
70
  <symbol
66
71
  fill="none"
@@ -78,7 +83,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
78
83
  fill="none"
79
84
  xmlns="http://www.w3.org/2000/svg"
80
85
  viewBox="0 0 24 24"
81
- id="${Cr}/image"
86
+ id="${lo}/image"
82
87
  >
83
88
  <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
84
89
  <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
@@ -90,7 +95,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
90
95
  fill="none"
91
96
  xmlns="http://www.w3.org/2000/svg"
92
97
  viewBox="0 0 24 24"
93
- id="${Cr}/video"
98
+ id="${lo}/video"
94
99
  >
95
100
  <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
96
101
  <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
@@ -101,7 +106,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
101
106
  fill="none"
102
107
  xmlns="http://www.w3.org/2000/svg"
103
108
  viewBox="0 0 24 24"
104
- id="${Cr}/audio"
109
+ id="${lo}/audio"
105
110
  >
106
111
  <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
107
112
  <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
@@ -121,7 +126,8 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
121
126
 
122
127
  </symbol>
123
128
  </svg>
124
- `,Mp=Cp,pi="ly.img.ai.quickAction.order",Ye="ly.img.ai.quickAction.actions";function Ip(e,t){return{id:t,setQuickActionMenuOrder:n=>{e.ui.experimental.setGlobalStateValue(`${pi}.${t}`,n)},getQuickActionMenuOrder:()=>e.ui.experimental.getGlobalStateValue(`${pi}.${t}`,[]),registerQuickAction:n=>{if(!e.ui.experimental.hasGlobalStateValue(`${Ye}.${t}`))e.ui.experimental.setGlobalStateValue(`${Ye}.${t}`,{[n.id]:n});else{let r=e.ui.experimental.getGlobalStateValue(`${Ye}.${t}`,{});e.ui.experimental.setGlobalStateValue(`${Ye}.${t}`,{...r,[n.id]:n})}},getQuickAction:n=>e.ui.experimental.getGlobalStateValue(`${Ye}.${t}`,{})[n]}}var xp=Ip,Mr="ly.img.ai.inference.editMode",Ui="ly.img.ai.inference.metadata";function Vi(e){return`ly.img.ai.quickAction.${e.quickActionMenuId}.${e.quickActionId}`}function Ap(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((n,r)=>(r==="ly.img.separator"&&n.length>0&&n[n.length-1]==="ly.img.separator"||n.push(r),n),[])}function Sp({alwaysOnTop:e=!0,disableClipping:t=!0}){return async(n,r,a)=>{let o={},i={},l=e||t?r.blockIds??r.engine.block.findAllSelected():[];return l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&(o[u]=r.engine.block.isAlwaysOnTop(u),r.engine.block.setAlwaysOnTop(u,!0)),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&(i[s]=r.engine.block.isClipped(s),r.engine.block.setClipped(s,!1))}}),r.addDisposer(async()=>{l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&r.engine.block.setAlwaysOnTop(u,o[u]),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&i[s]!=null&&r.engine.block.setClipped(s,i[s])}})}),await a(n,r)}}var Ep=Sp;function jp({pending:e=!0}){return async(t,n,r)=>{let a=e?n.blockIds??n.engine.block.findAllSelected():[];try{return a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Pending",progress:0})}),await r(t,n)}finally{a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Ready"})})}}}var Lp=jp;function Tp({editMode:e,automaticallyUnlock:t=!1}){return async(n,r,a)=>{let o=r.blockIds??r.engine.block.findAllSelected(),i=()=>{};t||r.addDisposer(async()=>{i?.()});try{return i=$p(r.engine,o,e),await a(n,r)}catch(l){throw ae(l)&&i(),l}finally{t&&i()}}}function $p(e,t,n){let r=e.editor.getGlobalScope("editor/select"),a=e.editor.getEditMode();l(),e.editor.setGlobalScope("editor/select","Deny"),e.editor.setEditMode(n);let o=e.editor.createHistory(),i=e.editor.getActiveHistory();e.editor.setActiveHistory(o);function l(){e.block.findAllSelected().forEach(c=>{t.includes(c)||e.block.setSelected(c,!1)}),t.forEach(c=>{e.block.setSelected(c,!0)})}let u=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&e.editor.setEditMode(n)}),s=e.block.onSelectionChanged(l);return()=>{r!=null&&e.editor.setGlobalScope("editor/select",r),e.editor.setEditMode(a),e.editor.setActiveHistory(i),e.editor.destroyHistory(o),s(),u()}}var Np=Tp;function Dp(e,t){switch(t.kind){case"text":return Op(e,t);case"image":return _p(e,t);case"video":return Pp(e,t);case"audio":return zp(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function Op(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t,o=r.map(s=>n.engine.block.getString(s,"text/text")),i;if($r(e)){let s="";for await(let c of e){if(a.aborted)break;typeof c=="string"?s=c:c.kind==="text"&&(s=c.text),r.forEach(d=>{n.engine.block.setString(d,"text/text",s)}),i={kind:"text",text:s}}}else i=e;if(i==null||i.kind!=="text")throw new Error("Output kind from generation is not text");let l=()=>{t.blockIds.forEach(s=>{t.cesdk.engine.block.setString(s,"text/text",i.text)})},u=()=>{t.blockIds.forEach((s,c)=>{t.cesdk.engine.block.setString(s,"text/text",o[c])})};return{consumedGenerationResult:i,applyCallbacks:{onBefore:u,onAfter:l,onCancel:u,onApply:()=>{l(),t.cesdk.engine.editor.addUndoStep()}}}}async function _p(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t;if(r.length!==1)throw new Error("Only one block is supported for image generation");let[o]=r,i=n.engine.block.getFill(o),l=n.engine.block.getSourceSet(i,"fill/image/sourceSet"),[u]=l,s;u==null&&(s=n.engine.block.getString(i,"fill/image/imageFileURI"));let c=await n.engine.editor.getMimeType(u?.uri??s),d=await Lr(u?.uri??s,t.cesdk.engine),g=d.width/d.height;if(a.throwIfAborted(),c==="image/svg+xml")throw new Error("SVG images are not supported");let f=n.engine.block.getCropScaleX(o),v=n.engine.block.getCropScaleY(o),w=n.engine.block.getCropTranslationX(o),b=n.engine.block.getCropTranslationY(o),p=n.engine.block.getCropRotation(o),h=()=>{n.engine.block.setCropScaleX(o,f),n.engine.block.setCropScaleY(o,v),n.engine.block.setCropTranslationX(o,w),n.engine.block.setCropTranslationY(o,b),n.engine.block.setCropRotation(o,p)};if($r(e))throw new Error("Streaming generation is not supported yet from a panel");if(e.kind!=="image"||typeof e.url!="string")throw new Error("Output kind from generation is not an image");let m=e.url,y=await n.engine.editor.getMimeType(m),k=await Up(n,m,y),C=await Lr(k,t.cesdk.engine),M=C.width/C.height,I=Math.abs(g-M)>.001,x=u?[{uri:k,width:C.width,height:C.height}]:void 0,$=k;x==null?n.engine.block.setString(i,"fill/image/imageFileURI",$):(n.engine.block.setString(i,"fill/image/imageFileURI",""),n.engine.block.setSourceSet(i,"fill/image/sourceSet",x)),I?n.engine.block.setContentFillMode(o,"Cover"):h();let D=()=>{if(l==null||l.length===0){if(s==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",s)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",l);h()},O=()=>{if(x==null){if($==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",$)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",x);I?n.engine.block.setContentFillMode(o,"Cover"):h()};return{consumedGenerationResult:e,applyCallbacks:{onBefore:D,onAfter:O,onCancel:()=>{D()},onApply:()=>{O(),t.cesdk.engine.editor.addUndoStep()}}}}async function Pp(e,t){throw new Error("Function not implemented.")}async function zp(e,t){throw new Error("Function not implemented.")}async function Up(e,t,n){let r=await(await fetch(t)).blob(),a=new File([r],`image.${Dg(n)}`,{type:n}),o=await e.unstable_upload(a,()=>{});return o?.meta?.uri??(console.warn("Failed to upload image:",o),t)}var Vp=Dp;function Bp({editMode:e,automaticallyUnlock:t=!1,showNotification:n=!0}){return async(r,a,o)=>{let i=a.blockIds??a.engine.block.findAllSelected(),l=()=>{};t||a.addDisposer(async()=>{l?.()});try{l=Fp(a.engine,i,e);let u=await o(r,a);if(n){let s=a.engine.block.findAllSelected();i.some(c=>s.includes(c))||a.cesdk?.ui.showNotification({type:"success",message:"AI generation complete",action:{label:"Select",onClick:()=>{i.forEach(c=>{a.engine.block.select(c)})}}})}return u}catch(u){throw ae(u)&&l(),u}finally{t&&l()}}}function Fp(e,t,n){function r(){let i=e.block.findAllSelected();return t.some(l=>i.includes(l))}let a=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&r()&&e.editor.setEditMode(n)}),o=e.block.onSelectionChanged(()=>{r()?e.editor.setEditMode(n):e.editor.setEditMode("Transform")});return r()&&e.editor.setEditMode(n),()=>{o(),a(),e.editor.setEditMode("Transform")}}var Gp=Bp;async function Rp(e,t){let{cesdk:n,input:r,blockIds:a,provider:o,quickAction:i,confirmationComponentId:l,abortSignal:u}=e;i.confirmation&&n.ui.setCanvasMenuOrder([l],{editMode:Mr});let s=new yi(n.engine,Ui);a.forEach(p=>{s.set(p,{status:"processing",quickActionId:i.id})});let c={cesdk:n,engine:n.engine,abortSignal:u},d=Oi([...o.output.middleware??[],t.debug?_i():void 0,Lp({}),...i.confirmation?[i.lockDuringConfirmation?Np({editMode:Mr}):Gp({editMode:Mr}),i.confirmation&&Ep({})]:[],t.dryRun?Pi({kind:o.kind,blockIds:a}):void 0]),{result:g,dispose:f}=await d(o.output.generate)(r,c),{consumedGenerationResult:v,applyCallbacks:w}=await Vp(g,{abortSignal:u,kind:o.kind,blockIds:a,cesdk:n});i.confirmation?a.forEach(p=>{s.set(p,{status:"confirmation",quickActionId:i.id})}):(w.onApply(),a.forEach(p=>{s.clear(p)}));let b=()=>{f(),a.forEach(p=>{s.clear(p)})};return u.addEventListener("abort",b),{dispose:b,returnValue:v,applyCallbacks:w}}var mi=Rp;function qp(e,t){let{cesdk:n,quickActionMenu:r,provider:a}=e,o=`ly.img.ai.${r.id}`,i=`${o}.confirmation`;n.setTranslations({en:{[`${i}.apply`]:"Apply",[`${i}.before`]:"Before",[`${i}.after`]:"After",[`${o}.cancel`]:"Cancel",[`${o}.processing`]:"Generating..."}});let l=`${i}.canvasnMenu`,u={unlock:()=>{},abort:()=>{},applyCallbacks:void 0},s=()=>{let d=new AbortController,g=d.signal;return u.abort=()=>{d.abort()},g};n.ui.registerComponent(l,({builder:d,engine:g,state:f})=>{let v=g.block.findAllSelected();if(v.length===0)return null;let w=new yi(n.engine,Ui),b=w.get(v[0]);if(b==null)return null;let p=()=>{v.forEach(h=>{w.clear(h)})};switch(b.status){case"processing":{d.Button(`${o}.spinner`,{label:[`ly.img.ai.inference.${b.quickActionId}.processing`,`${o}.cancel`],isLoading:!0}),d.Separator(`${o}.separator`),d.Button(`${o}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.abort(),p()}});break}case"confirmation":{let h=f(`${i}.comparing`,"after"),m=u.applyCallbacks?.onCancel;m!=null&&d.Button(`${i}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.unlock(),m(),p()}});let y=u.applyCallbacks?.onBefore,k=u.applyCallbacks?.onAfter;y!=null&&k!=null&&d.ButtonGroup(`${i}.compare`,{children:()=>{d.Button(`${i}.compare.before`,{label:`${i}.before`,variant:"regular",isActive:h.value==="before",onClick:()=>{y(),h.setValue("before")}}),d.Button(`${i}.compare.after`,{label:`${i}.after`,variant:"regular",isActive:h.value==="after",onClick:()=>{k(),h.setValue("after")}})}});let C=u.applyCallbacks?.onApply;C!=null&&d.Button(`${i}.apply`,{icon:"@imgly/Checkmark",tooltip:`${i}.apply`,color:"accent",isDisabled:h.value!=="after",onClick:()=>{u.unlock(),p(),n.engine.editor._update(),C()}});break}default:}});let c=`${o}.canvasMenu`;return n.ui.registerComponent(c,d=>{let g=d.engine.block.findAllSelected(),f=g.every(m=>d.engine.block.getState(m).type==="Ready"),v=r.getQuickActionMenuOrder().map(m=>{if(m==="ly.img.separator")return m;let y=r.getQuickAction(m);if(y==null||!n.feature.isEnabled(Vi({quickActionId:m,quickActionMenuId:r.id}),{engine:d.engine}))return null;let k=y.scopes;return k!=null&&k.length>0&&!g.every(C=>k.every(M=>d.engine.block.isAllowedByScope(C,M)))?null:y}).filter(m=>m!=null);if(v=Ap(v),v.length===0||v.every(m=>m==="ly.img.separator"))return null;let{builder:w,experimental:b,state:p}=d,h=p(`${o}.toggleExpandedState`,void 0);b.builder.Popover(`${o}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!f,trailingIcon:null,children:({close:m})=>{w.Section(`${o}.popover.section`,{children:()=>{if(h.value!=null){let y=h.value,k=r.getQuickAction(y);if(k!=null&&k.renderExpanded!=null){k.renderExpanded(d,{blockIds:g,closeMenu:m,toggleExpand:()=>{h.setValue(void 0)},handleGenerationError:C=>{We(C,{cesdk:n,provider:a},t)},generate:async(C,M)=>{try{let{returnValue:I,applyCallbacks:x,dispose:$}=await mi({input:C,quickAction:k,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:M?.blockIds??g,confirmationComponentId:l},t);return u.unlock=$,u.applyCallbacks=x,I}catch(I){throw ae(I)||We(I,{cesdk:n,provider:a},t),I}}});return}}b.builder.Menu(`${o}.menu`,{children:()=>{v.forEach(y=>{y==="ly.img.separator"?w.Separator(`${o}.separator.${Math.random().toString()}`):y.render(d,{blockIds:g,closeMenu:m,handleGenerationError:k=>{We(k,{cesdk:n,provider:a},t)},toggleExpand:()=>{h.setValue(y.id)},generate:async(k,C)=>{try{let{returnValue:M,applyCallbacks:I,dispose:x}=await mi({input:k,quickAction:y,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:C?.blockIds??g,confirmationComponentId:l},t);return u.unlock=x,u.applyCallbacks=I,M}catch(M){throw ae(M)||We(M,{cesdk:n,provider:a},t),M}}})})}})}})}})}),{canvasMenuComponentId:c}}var Qp=qp;async function Hp(e,t,n){await e.initialize?.(t);let r=await Zp(t.engine,e.id,e.output.history??"@imgly/local");if(t.cesdk==null)return{};let a=r?`${e.id}.history.entry`:void 0,o={...t,cesdk:t.cesdk,historyAssetSourceId:r,historyAssetLibraryEntryId:a,i18n:{prompt:"common.ai-generation.prompt.placeholder"}};a!=null&&r!=null&&t.cesdk.ui.addAssetLibraryEntry({id:a,sourceIds:[r],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),t.cesdk.i18n.setTranslations({en:{"common.ai-generation.success":"Generation Successful","common.ai-generation.failed":"Generation Failed","common.ai-generation.generate":"Generate","common.ai-generation.prompt.placeholder":"Describe what you want to create...",[`panel.${e.id}`]:Yp(e)}});let i="@imgly/plugin-ai-generation.iconSetAdded";return t.cesdk.ui.experimental.hasGlobalStateValue(i)||(t.cesdk.ui.addIconSet("@imgly/plugin-ai-generation",Mp),t.cesdk.ui.experimental.setGlobalStateValue(i,!0)),{renderBuilderFunctions:await Wp(e,o,n)}}function Yp(e){if(e.name!=null)return e.name;switch(e.kind){case"image":return"Generate Image";case"video":return"Generate Video";case"audio":return"Generate Audio";default:return"Generate Asset"}}async function Zp(e,t,n){if(!(n==null||n===!1)){if(n==="@imgly/local"){let r=`${t}.history`;return e.asset.addLocalSource(r),r}if(n==="@imgly/indexedDB"){let r=`${t}.history`;return e.asset.addSource(new _c(r,e)),r}return n}}async function Wp(e,t,n){let r={panel:void 0};return e.input?.panel!=null&&(r.panel=await Kp(e,e.input.panel,t,n)),e.input?.quickActions!=null&&(n.debug&&console.log(`Initializing quick actions for provider '${e.kind}' (${e.id})`),Jp(e,e.input.quickActions,t,n)),r}async function Kp(e,t,n,r){switch(t.type){case"custom":return wp(e,t,n,r);case"schema":return vp(e,t,n,r);default:r.debug&&console.warn(`Invalid panel input type '${t.type}' - skipping`)}}async function Jp(e,t,n,r){let{cesdk:a}=n,o={};t.actions.forEach(i=>{let l=i.kind??e.kind;o[l]==null&&(o[l]=xp(a,l));let u=o[l],s=i.enable??!0;a.feature.enable(Vi({quickActionId:i.id,quickActionMenuId:l}),s),u.registerQuickAction(i),r.debug&&console.log(`Registered quick action: '${i.id}' (v${i.version}) to menu '${l}'`)}),Object.values(o).forEach(i=>{let{canvasMenuComponentId:l}=Qp({cesdk:a,quickActionMenu:i,provider:e},r);r.debug&&console.log(`Registered quick action menu component: ${l}`)})}var fi=Hp;function Xp(e){let{cesdk:t,panelId:n}=e;n.startsWith("ly.img.ai/")&&console.warn(`Dock components for AI generation should open a panel with an id starting with "ly.img.ai/" \u2013 "${n}" was provided.`);let r=`${n}.dock`;t.ui.registerComponent(r,({builder:a})=>{let o=t.ui.isPanelOpen(n);a.Button(`${n}.dock.button`,{label:`${n}.dock.label`,isSelected:o,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(i=>{i.startsWith("ly.img.ai/")&&t.ui.closePanel(i),!o&&i==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(i)}),o?t.ui.closePanel(n):t.ui.openPanel(n)}})})}var em=Xp,tm="@imgly/plugin-ai-image-generation",rm=`
129
+ `,w9=v9;function k9(e){return async(t,r,i)=>e.enable?(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await lu(2e3),await x9(t,e,r)):i(t,r)}async function x9(e,t,r){switch(t.kind){case"image":return I9(e,t,r);case"video":return C9(e,t,r);case"text":return A9(e,t,r);case"audio":return j9(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function I9(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await w5(l,r),s=await bo(u,r);i=s.width,n=s.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
130
+ `,"+")}`}}async function C9(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function A9(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,l=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);l&&l[1]&&(i=l[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=kr(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=kr(n,o)}else"customPrompt"in e?a=kr(n,"custom"):a=kr(n,"improved");else a=kr(n,"generated");return M9(a,r.abortSignal)}async function*M9(e,t){let r=Math.max(1,Math.ceil(e.length/20)),i=0;for(;i<e.length;){if(t?.aborted)return;let n=Math.min(i+r,e.length);yield{kind:"text",text:e.substring(0,n)},i=n,i<e.length&&await lu(100)}return{kind:"text",text:e}}function kr(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,l="";if(n<=o.length)l=o.substring(0,n);else{l=o;let u=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],s=0;for(;l.length<n;){let c=u[s%u.length];if(l.length+c.length<=n)l+=c;else{l+=c.substring(0,n-l.length);break}s++}}return r+l}async function j9(e,t,r){let i=3;if(e!=null&&typeof e=="object"){if("duration"in e&&typeof e.duration=="number")i=e.duration;else if("prompt"in e&&typeof e.prompt=="string"){let n=e.prompt.match(/(\d+)\s*(?:seconds?|secs?|s)\b/i);n&&(i=parseInt(n[1],10))}}return t.blockInputs?.audio?.duration&&(i=t.blockInputs.audio.duration),{kind:"audio",url:S9(220,i),duration:i,thumbnailUrl:void 0}}function S9(e,t){let r=Math.floor(44100*t),i=new Float32Array(r);for(let n=0;n<r;n++)i[n]=Math.sin(2*Math.PI*e*n/44100);return E9(i,44100)}function E9(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,l=r*i,u=44+l,s=new ArrayBuffer(u),c=new DataView(s),d=(b,m)=>{for(let h=0;h<m.length;h++)c.setUint8(b+h,m.charCodeAt(h))};d(0,"RIFF"),c.setUint32(4,u-8,!0),d(8,"WAVE"),d(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,n,!0),c.setUint32(24,t,!0),c.setUint32(28,o,!0),c.setUint16(32,a,!0),c.setUint16(34,16,!0),d(36,"data"),c.setUint32(40,l,!0);let p=44;for(let b=0;b<r;b++){let m=Math.max(-1,Math.min(1,e[b])),h=Math.round(m*32767);c.setInt16(p,h,!0),p+=2}let g=new Uint8Array(s),f="";for(let b=0;b<g.length;b++)f+=String.fromCharCode(g[b]);return`data:audio/wav;base64,${btoa(f)}`}async function lu(e){return new Promise(t=>{setTimeout(t,e)})}var _9=k9,su="USER_CANCEL";function L9(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=x5([...e.provider.output.middleware??[],...r?.middlewares??[],C5({enable:r?.debug}),_9({enable:r?.dryRun,kind:e.provider.kind})]);try{let{result:n}=await i(e.provider.output.generate)(t,{abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk});return r?.abortSignal?.aborted?{status:"aborted"}:n instanceof Error?{status:"error",message:n.message}:n==null?{status:"error",message:"No output generated"}:S5(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return Ao(n)?{status:"aborted",message:n.message}:n===su?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var T9=L9;async function $9(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n};await t.initialize?.({...r,engine:r.cesdk.engine});let o=m9(a),l=b9(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=l;let u=T9({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),s=await f9(a,u);E5(r.cesdk,"@imgly/plugin-ai-generation",w9);let c={provider:t,panel:{builderRenderFunction:s},history:{assetSourceId:o,assetLibraryEntryId:l},generate:u};return Zs.get().register(c),c}var so=$9;function N9(e){let{kind:t,cesdk:r,historAssetSourceIds:i}=e,n=`ly.img.ai.${t}-generation.history`;if(r.engine.asset.findAllSources().includes(n))return n;let a=new k0(n,r,i);return r.engine.asset.addSource(a),a.id}var O9=N9;async function D9(e,t,r,i){let n,a=[];if(Array.isArray(t)){let l=await Promise.all(t.map(u=>so(e,u,r,i)));a.push(...l),n=z9({prefix:e,providerInitializationResults:a})}else{let l=await Promise.all(t.fromText.map(s=>so(e,s,r,i)));a.push(...l);let u=await Promise.all(t.fromImage.map(s=>so(e,s,r,i)));a.push(...u),n=P9({prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u})}let o=O9({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(l=>l.history?.assetSourceId).filter(rn)});return{panel:{builderRenderFunction:n},history:{assetSourceId:o},providerInitializationResults:a}}function P9({prefix:e,initializedFromTextProviders:t,initializedFromImageProviders:r}){let i=t.length>0&&r.length>0;return n=>{let{builder:a,experimental:o}=n,l=o.global(`${e}.fromType`,i?"fromText":void 0),u=[];l.value==="fromText"?u.push(...t):l.value==="fromImage"?u.push(...r):u.push(...t,...r);let s=t.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),c=r.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),d=n.experimental.global(`${e}.selectedProvider.fromText`,s[0]),p=n.experimental.global(`${e}.selectedProvider.fromImage`,c[0]),g=l.value==="fromText"?d:l.value==="fromImage"?p:void 0;if((i||u.length>1)&&a.Section(`${e}.providerSelection.section`,{children:()=>{if(i&&a.ButtonGroup(`${e}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{a.Button(`${e}.fromType.buttonGroup.fromText`,{label:"Text",icon:l.value!=="fromText"&&vs(t,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromText",onClick:()=>{l.setValue("fromText")}}),a.Button(`${e}.fromType.buttonGroup.fromImage`,{label:"Image",icon:l.value!=="fromImage"&&vs(r,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromImage",onClick:()=>{l.setValue("fromImage")}})}}),u.length>1){let f=l.value==="fromText"?s:l.value==="fromImage"?c:[...s,...c];g!=null&&a.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:f,...g})}}}),u.length>1)g?.value.builderRenderFunction?.(n);else{let f=u[0];f&&f.panel?.builderRenderFunction?.(n)}}}function z9({prefix:e,providerInitializationResults:t}){return r=>{let{builder:i}=r;if(t.length===0)return;let n=t.map(({provider:o,panel:l})=>({id:o.id,label:o.name??o.id,builderRenderFunction:l?.builderRenderFunction})),a=r.state(`${e}.selectedProvider`,n[0]);t.length>1&&a!=null&&i.Section(`${e}.providerSelection.section`,{children:()=>{i.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:n,...a})}}),a.value.builderRenderFunction?.(r)}}function vs(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(jo(r.id),!1).value)}var U9=D9,nn="ly.img.ai.editMode",uu="ly.img.ai.metadata";async function R9(e){let t=`ly.img.ai.${e.kind}.confirmation`;e.cesdk?.i18n.setTranslations({en:{"ly.img.ai.processing":"Generating...",[`${t}.cancel`]:"Cancel Generation",[`${t}.apply`]:"Apply Generation",[`${t}.before`]:"Before",[`${t}.after`]:"After"}});let r=i=>{let{engine:n,builder:a,state:o,payload:l}=i;if(l==null)return;let u=n.block.findAllSelected();if(u.length===0)return null;let s=new Ps(n,uu),c=s.get(u[0]);if(c==null)return null;let d=()=>{u.forEach(p=>{s.clear(p)})};switch(c.status){case"processing":{a.Button(`${t}.spinner`,{label:[`ly.img.ai.${c.quickActionId}.processing`,"ly.img.ai.processing"],isLoading:!0}),a.Separator(`${t}.separator`),a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{l.onCancelGeneration?.(),d()}});break}case"confirmation":{let p=o(`${t}.comparing`,"after"),g=l.applyCallbacks?.onCancel;g!=null&&a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{g(),d()}});let f=l.applyCallbacks?.onBefore,b=l.applyCallbacks?.onAfter;f!=null&&b!=null&&a.ButtonGroup(`${t}.compare`,{children:()=>{a.Button(`${t}.compare.before`,{label:`${t}.before`,variant:"regular",isActive:p.value==="before",onClick:()=>{f(),p.setValue("before")}}),a.Button(`${t}.compare.after`,{label:`${t}.after`,variant:"regular",isActive:p.value==="after",onClick:()=>{b(),p.setValue("after")}})}});let m=l.applyCallbacks?.onApply;m!=null&&a.Button(`${t}.apply`,{icon:"@imgly/Checkmark",tooltip:`${t}.apply`,color:"accent",isDisabled:p.value!=="after",onClick:()=>{d(),cesdk?.engine.editor._update(),m()}});break}default:}};return Promise.resolve(r)}var F9=R9;function V9(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((r,i)=>(i==="ly.img.separator"&&r.length>0&&r[r.length-1]==="ly.img.separator"||r.push(i),r),[])}var B9=V9;function G9(e){return`ly.img.ai.${e}.canvasMenu`}var q9=G9;function Y9(e){let{kind:t,cesdk:r,payload:i,defaultOrder:n}=e,a=q9(t);if(i==null||!Array.isArray(i.children)){let o=r.ui.getCanvasMenuOrder().find(({id:l})=>l===a);return o!=null&&Array.isArray(o.children)?o.children:n??[]}return i.children.filter(o=>typeof o=="string")}var H9=Y9;function Z9(e,t){if(t.blockIds.some(r=>!t.cesdk.engine.block.isValid(r)))return Promise.resolve({applyCallbacks:{onBefore:()=>{},onAfter:()=>{},onCancel:()=>{},onApply:()=>{}}});switch(t.kind){case"text":return Q9(e,t);case"image":return W9(e,t);case"video":return K9(e,t);case"audio":return J9(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function Q9(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t,a=i.map(s=>r.engine.block.getString(s,"text/text")),o;if(e.type==="async"){let s="";for await(let c of e.output){if(n?.aborted)break;typeof c=="string"?s=c:c.kind==="text"&&(s=c.text),i.forEach(d=>{r.engine.block.setString(d,"text/text",s)}),o={kind:"text",text:s}}}else o=e.output;if(o==null||o.kind!=="text")throw new Error("Output kind from generation is not text");e.type==="sync"&&i.forEach(s=>{r.engine.block.setString(s,"text/text",o.text)});let l=()=>{t.blockIds.forEach(s=>{t.cesdk.engine.block.setString(s,"text/text",o.text)})},u=()=>{t.blockIds.forEach((s,c)=>{t.cesdk.engine.block.setString(s,"text/text",a[c])})};return{applyCallbacks:{onBefore:u,onAfter:l,onCancel:u,onApply:()=>{l(),t.cesdk.engine.editor.addUndoStep()}}}}async function W9(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t;if(i.length!==1)throw new Error("Only one block is supported for image generation");let[a]=i,o=r.engine.block.getFill(a),l=r.engine.block.getSourceSet(o,"fill/image/sourceSet"),[u]=l,s;u==null&&(s=r.engine.block.getString(o,"fill/image/imageFileURI"));let c=await r.engine.editor.getMimeType(u?.uri??s),d=await bo(u?.uri??s,t.cesdk.engine),p=d.width/d.height;if(n?.throwIfAborted(),c==="image/svg+xml")throw new Error("SVG images are not supported");let g=r.engine.block.getCropScaleX(a),f=r.engine.block.getCropScaleY(a),b=r.engine.block.getCropTranslationX(a),m=r.engine.block.getCropTranslationY(a),h=r.engine.block.getCropRotation(a),x=()=>{r.engine.block.setCropScaleX(a,g),r.engine.block.setCropScaleY(a,f),r.engine.block.setCropTranslationX(a,b),r.engine.block.setCropTranslationY(a,m),r.engine.block.setCropRotation(a,h)};if(e.type==="async")throw new Error("Streaming generation is not supported yet from a panel");if(e.output.kind!=="image"||typeof e.output.url!="string")throw new Error("Output kind from generation is not an image");let w=e.output.url,v=await r.engine.editor.getMimeType(w),y=await X9(r,w,v),k=await bo(y,t.cesdk.engine),I=k.width/k.height,U=Math.abs(p-I)>.001,C=u?[{uri:y,width:k.width,height:k.height}]:void 0,be=y;C==null?r.engine.block.setString(o,"fill/image/imageFileURI",be):(r.engine.block.setString(o,"fill/image/imageFileURI",""),r.engine.block.setSourceSet(o,"fill/image/sourceSet",C)),await r.engine.block.forceLoadResources([o]),U?r.engine.block.setContentFillMode(a,"Cover"):x();let ar=()=>{if(l==null||l.length===0){if(s==null)throw new Error("No image URI found");r.engine.block.setString(o,"fill/image/imageFileURI",s)}else r.engine.block.setSourceSet(o,"fill/image/sourceSet",l);x()},lr=()=>{if(C==null){if(be==null)throw new Error("No image URI found");r.engine.block.setString(o,"fill/image/imageFileURI",be)}else r.engine.block.setSourceSet(o,"fill/image/sourceSet",C);U?r.engine.block.setContentFillMode(a,"Cover"):x()};return{applyCallbacks:{onBefore:ar,onAfter:lr,onCancel:()=>{ar()},onApply:()=>{lr(),t.cesdk.engine.editor.addUndoStep()}}}}async function K9(e,t){throw new Error("Function not implemented.")}async function J9(e,t){throw new Error("Function not implemented.")}async function X9(e,t,r){let i=await(await fetch(t)).blob(),n=new File([i],`image.${v5(r)}`,{type:r}),a=await e.unstable_upload(n,()=>{});return a?.meta?.uri??(console.warn("Failed to upload image:",a),t)}var e3=Z9;function t3(e){let{engine:t,blockIdsToLock:r,editModeToLockTo:i}=e;function n(){let u=t.block.findAllSelected();return r.some(s=>u.includes(s))}let a=t.editor.onStateChanged(()=>{t.editor.getEditMode()!==i&&n()&&t.editor.setEditMode(i)}),o=t.block.onSelectionChanged(()=>{n()?t.editor.setEditMode(i):t.editor.setEditMode("Transform")});n()&&t.editor.setEditMode(i);let l=!1;return()=>{l||(o(),a(),t.editor.setEditMode("Transform"),l=!0)}}var r3=t3,i3=class cu{constructor(){this.actions=new Map}static get(){let t="__imgly_callbacks_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new cu),r[t]}register(t,r){let i=this.actions.get(t)??{};this.actions.set(t,{...i,...r})}get(t){return this.actions.get(t)??{}}},ke=i3;function n3(e){return async(t,r)=>{let i=r?.blockIds??e.blockIds;if(e.providerInitializationResult==null)return e.debug&&console.warn("[Generate] No provider initialization result found for quick action. Returning abortion status."),{status:"aborted"};let n=e.providerInitializationResult?.provider.input?.quickActions?.supported?.[e.quickAction.id];if(n==null)throw new Error("[Generate] Quick action input mapping failed. Ensure the provider supports this quick action.");let a=typeof n=="object"&&n!==null&&"mapInput"in n?n.mapInput:c=>c;e.close();let o=new AbortController,l=AbortSignal.any([e.abortSignal,o.signal].filter(rn)),u=new Ps(e.cesdk.engine,uu),s=e.lock??!0?r3({engine:e.cesdk.engine,editModeToLockTo:nn,blockIdsToLock:i}):()=>{};i.forEach(c=>{ke.get().register(c,{onCancelGeneration:()=>{o.abort(su),s(),e.cesdk.engine.block.isValid(c)&&(e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Ready"}),u.clear(c))}})}),i?.forEach(c=>{u.set(c,{status:"processing",quickActionId:e.quickAction.id})}),i.forEach(c=>{e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Pending",progress:0})});try{let c=await e.providerInitializationResult.generate(a(t),{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:l}),d=c.status;switch(d){case"success":{let{applyCallbacks:p}=await e3(c,{kind:e.providerInitializationResult.provider.kind,blockIds:i,cesdk:e.cesdk,abortSignal:l});if(i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&e.cesdk.engine.block.setState(g,{type:"Ready"})}),e.confirmation){i.forEach(f=>{u.set(f,{status:"confirmation",quickActionId:e.quickAction.id})});let g={...p,onApply:async()=>{p.onApply(),s()},onCancel:()=>{p.onCancel(),s()}};i.forEach(f=>{ke.get().register(f,{applyCallbacks:g})})}else i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&u.clear(g)}),p.onApply(),s();return c}case"aborted":return e.debug&&console.log("Generation was aborted"),s(),i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&u.clear(p)}),c;case"error":return s(),i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&u.clear(p)}),console.error(`[Generate]: ${c.message}`),c;default:throw new Error(`[Generate] Unknown result status ${d}.`)}}catch(c){throw e.cesdk.ui.showNotification({type:"error",message:"A technical issue has occurred."}),s(),i.forEach(d=>{e.cesdk.engine.block.isValid(d)&&u.clear(d)}),c}finally{i.forEach(c=>{e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Ready"})})}}}var ws=n3;function o3(e){let t=`ly.img.ai.${e.kind}}`;e.cesdk.i18n.setTranslations({en:{[`${t}.quickActionMenu.providerSelect.label`]:"Provider"}});let r=i=>{if(i.engine.editor.getEditMode()===nn)return;let n=i.engine.block.findAllSelected();if(n.length===0)return;let{payload:a}=i,o=H9({kind:e.kind,cesdk:e.cesdk,payload:a,defaultOrder:e.defaultOrder})??[];if(o.length===0)return;let l=a3(o).filter(v=>{if(v==="ly.img.separator")return!0;let y=v.scopes;if(y!=null&&y.length>0&&!n.every(k=>y.every(I=>e.engine.block.isAllowedByScope(k,I))))return!1;if(v.enable!=null){if(typeof v.enable=="function")return v.enable({engine:e.engine});if(typeof v.enable=="boolean")return v.enable}return!0}),u=[],s=e.providerInitializationResults.reduce((v,y)=>{if(y.provider.kind!==e.kind)return v;let k=l.map(I=>{if(I==="ly.img.separator")return I;if(y.provider.input?.quickActions?.supported?.[I.id]!=null)return{definition:I};{let U=Zs.get().getAll().filter(C=>C.provider.kind!==e.kind&&C.provider.id!==y.provider.id).find(C=>C.provider.input?.quickActions?.supported?.[I.id]!=null);if(U!=null){let C={definition:I,providerInitializationResult:U};return u.push(C),C}else return}}).filter(rn);return k=B9(k),k.length===0||k.every(I=>I==="ly.img.separator")||k.every(I=>I==="ly.img.separator"||I.providerInitializationResult!=null)||v.push({providerInitializationResult:y,quickActions:k}),v},[]);if(s.length===0)if(u.length>0){let v=new Map;u.forEach(k=>{let I=k.definition.id;v.has(I)||v.set(I,k)});let y=Array.from(v.values());s.push({providerInitializationResult:y[0].providerInitializationResult??e.providerInitializationResults[0],quickActions:y})}else return;let c=s.map(({providerInitializationResult:v})=>({id:v.provider.id,label:v.provider.name??v.provider.id})),d=i.experimental.global(`${t}.currentProvider`,c[0]),p=s.find(({providerInitializationResult:{provider:{id:v}}})=>v===d.value?.id),g=n.every(v=>i.engine.block.getState(v).type==="Ready"),{builder:f,experimental:b,state:m}=i,h=m(`${t}.isGenerating`,!1),x=m(`${t}.toggleExpandedState`,void 0),w=async(v,y,k)=>{h.setValue(!0);try{return await k(v,y)}finally{h.setValue(!1)}};b.builder.Popover(`${t}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!g,isLoading:h.value,trailingIcon:null,children:({close:v})=>{f.Section(`${t}.popover.section`,{children:()=>{if(x.value!==void 0){let y=p?.quickActions.find(k=>k!=="ly.img.separator"&&k.definition.id===x.value);return y!=null&&y.definition.render!=null?y.definition.render({...i,toggleExpand:()=>{x.setValue(void 0)},isExpanded:!0,generate:ws({blockIds:n,providerInitializationResult:y.providerInitializationResult??p?.providerInitializationResult,quickAction:y.definition,middlewares:[w],confirmation:y.definition.defaults?.confirmation??!0,close:v,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:v,providerId:d.value.id}):void 0}x.value==null&&c.length>1&&(f.Select(`${t}.providerSelect.select`,{inputLabel:`${t}.quickActionMenu.providerSelect.label`,values:c,...d}),f.Separator(`${t}.providerSelect.separator`)),b.builder.Menu(`${t}.menu`,{children:()=>{p?.quickActions.forEach(y=>{if(y==="ly.img.separator"){f.Separator(`${t}.separator.${Math.random().toString()}`);return}y.definition.render!=null&&y.definition.render({...i,toggleExpand:()=>{x.setValue(y.definition.id)},isExpanded:!1,generate:ws({blockIds:n,providerInitializationResult:y.providerInitializationResult??p?.providerInitializationResult,quickAction:y.definition,middlewares:[w],confirmation:y.definition.defaults?.confirmation??!0,close:v,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:v,providerId:d.value.id})})}})}})}})};return Promise.resolve(r)}function a3(e){return e.map(t=>t==="ly.img.separator"?t:Ys.get().getBy({id:t,type:"quick"})[0]).filter(rn)}var l3=o3;async function s3(e){let t=await l3({kind:e.kind,providerInitializationResults:e.providerInitializationResults,cesdk:e.cesdk,engine:e.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:e.defaultOrder}),r=await F9({kind:e.kind,cesdk:e.cesdk});return{renderFunction:i=>{let{engine:n}=i;if(n.editor.getEditMode()===nn){let a=i.engine.block.findAllSelected();r({...i,payload:{...i.payload??{},applyCallbacks:{onBefore:()=>{a.forEach(o=>{ke.get().get(o).applyCallbacks?.onBefore?.()})},onAfter:()=>{a.forEach(o=>{ke.get().get(o).applyCallbacks?.onAfter?.()})},onCancel:()=>{a.forEach(o=>{ke.get().get(o).applyCallbacks?.onCancel?.()})},onApply:()=>{a.forEach(o=>{ke.get().get(o).applyCallbacks?.onApply?.()})}},onCancelGeneration:()=>{a.forEach(o=>{ke.get().get(o).onCancelGeneration?.()})}}});return}t(i)}}}var u3=s3,c3="@imgly/plugin-ai-image-generation",d3=`
125
131
  <svg>
126
132
  <symbol
127
133
  fill="none"
@@ -135,8 +141,10 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
135
141
 
136
142
  </symbol>
137
143
  </svg>
138
- `,nm=rm,im="@imgly/plugin-ai-image-generation-web",_="ly.img.ai/image-generation",Ir="ly.img.ai.image-generation.fromType";function om(e){return{async initialize({cesdk:t}){if(t==null)return;let n={debug:e.debug??!1,dryRun:e.dryRun??!1,middleware:e.middleware};t.ui.addIconSet(tm,nm),t.setTranslations({en:{[`panel.${_}`]:"Image Generation","ly.img.ai.image-generation.success":"Image Generation Successful","ly.img.ai.image-generation.success.action":"Show"}});let r=e?.text2image,a=e?.image2image,o=await r?.({cesdk:t}),i=await a?.({cesdk:t});function l(c){if(t!=null)return{success:{show:()=>{let d=t?.ui.isPanelOpen(_),g=t.ui.experimental.getGlobalStateValue(Ir,"fromText")===c;return!d||!g},message:"ly.img.ai.image-generation.success",action:{label:"ly.img.ai.image-generation.success.action",onClick:()=>{t.ui.experimental.setGlobalStateValue(Ir,c),t.ui.openPanel(_)}},duration:"long"}}}o!=null&&(o.output.notification=l("fromText")),i!=null&&(i.output.notification=l("fromImage"));let u=o!=null?await fi(o,{cesdk:t,engine:t.engine},n):void 0,s=i!=null?await fi(i,{cesdk:t,engine:t.engine},n):void 0;if(u?.renderBuilderFunctions?.panel==null&&s?.renderBuilderFunctions?.panel==null){n.debug&&console.log("No providers are initialized \u2013 doing nothing");return}if(u?.renderBuilderFunctions?.panel!=null&&s?.renderBuilderFunctions?.panel!=null)t.ui.registerPanel(_,c=>{let{builder:d,experimental:g}=c,f=g.global(Ir,"fromText");switch(d.Section(`${_}.fromType.section`,{children:()=>{d.ButtonGroup(`${_}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{d.Button(`${_}.fromType.buttonGroup.fromText`,{label:"Text",icon:f.value!=="fromText"&&o!=null&&g.global(Bt(o.id),!1).value?"@imgly/LoadingSpinner":void 0,isActive:f.value==="fromText",onClick:()=>{f.setValue("fromText")}}),d.Button(`${_}.fromType.buttonGroup.fromImage`,{label:"Image",icon:f.value!=="fromImage"&&i!=null&&g.global(Bt(i.id),!1).value?"@imgly/LoadingSpinner":void 0,isActive:f.value==="fromImage",onClick:()=>{f.setValue("fromImage")}})}})}}),f.value){case"fromText":{u?.renderBuilderFunctions?.panel?.(c);break}case"fromImage":{s?.renderBuilderFunctions?.panel?.(c);break}default:}});else{let c=u?.renderBuilderFunctions?.panel??s?.renderBuilderFunctions?.panel;if(c==null)return;t.ui.registerPanel(_,c),t.i18n.setTranslations({en:{[`${_}.dock.label`]:"AI Image"}}),em({cesdk:t,panelId:_})}}}}var am=om,lm=e=>({name:im,version:"0.1.9",...am(e)}),Bi=lm;var sm=class{constructor(e,t,n){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=n?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=n?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let n=indexedDB.open(this.dbName,this.dbVersion);n.onerror=r=>{t(new Error(`Failed to open IndexedDB: ${r.target.error}`))},n.onupgradeneeded=r=>{let a=r.target.result;a.objectStoreNames.contains(this.assetStoreName)||a.createObjectStore(this.assetStoreName,{keyPath:"id"}),a.objectStoreNames.contains(this.blobStoreName)||a.createObjectStore(this.blobStoreName,{keyPath:"id"})},n.onsuccess=r=>{this.db=r.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",g=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(g=s.tags[c]);let f={...s,label:d,tags:g};return this.filterAsset(f,e)&&u.push(f),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:n,perPage:r}=e,a=n*r,o=a+r,i=t.slice(a,o),l=o<t.length?n+1:void 0;return{assets:i,currentPage:n,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let n=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();n.onsuccess=()=>{let r=new Set;n.result.forEach(o=>{o.groups&&Array.isArray(o.groups)&&o.groups.forEach(i=>r.add(i))});let a=[...r];e(a)},n.onerror=()=>{t(new Error(`Failed to get groups: ${n.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),n=t.objectStore(this.assetStoreName),r=new Set;ge(e,o=>{r.add(o)}),setTimeout(()=>{this.storeBlobUrls([...r])});let a={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};n.put(a),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.assetStoreName,"readwrite");n.objectStore(this.assetStoreName).delete(e),n.oncomplete=()=>{ge(t,r=>{this.removeBlob(r)}),this.engine.asset.assetSourceContentsChanged(this.id)},n.onerror=()=>{console.error(`Failed to remove asset: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let a=r.result;a.sort((o,i)=>{let l=o.meta?.insertedAt||o._insertedAt||Date.now(),u=i.meta?.insertedAt||i._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(a)},r.onerror=()=>{n(new Error(`Failed to get assets: ${r.error}`))}})}async getAsset(e){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async getBlob(e){return new Promise((t,n)=>{let r=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async n=>{let r=await(await fetch(n)).blob();t[n]=r})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.blobStoreName,"readwrite"),r=n.objectStore(this.blobStoreName);Object.entries(t).forEach(([a,o])=>{let i={id:a,blob:o};r.put(i)}),n.onerror=()=>{console.error(`Failed to add blobs: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async restoreBlobUrls(e){let t={},n=new Set;return ge(e,r=>{n.add(r)}),await Promise.all([...n].map(async r=>{let a=await this.createBlobUrlFromStore(r);t[r]=a})),ge(e,r=>t[r]??r)}filterAsset(e,t){let{query:n,tags:r,groups:a,excludeGroups:o}=t;if(n&&n.trim()!==""){let i=n.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!i.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(r){let i=Array.isArray(r)?r:[r];if(i.length>0&&(!e.tags||!i.every(l=>e.tags?.includes(l))))return!1}return!(a&&a.length>0&&(!e.groups||!a.some(i=>e.groups?.includes(i)))||o&&o.length>0&&e.groups&&e.groups.some(i=>o.includes(i)))}sortAssets(e,t){let{sortingOrder:n,sortKey:r,sortActiveFirst:a}=t,o=[...e];return!n||n==="None"||(r?o.sort((i,l)=>{let u,s;return r==="id"?(u=i.id,s=l.id):(u=i.meta?.[r]??null,s=l.meta?.[r]??null),u==null?n==="Ascending"?-1:1:s==null?n==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?n==="Ascending"?u.localeCompare(s):s.localeCompare(u):n==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):n==="Descending"&&o.reverse(),a&&o.sort((i,l)=>i.active&&!l.active?-1:!i.active&&l.active?1:0)),o}};function ge(e,t,n=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let r=0;r<e.length;r++){let a=n?`${n}[${r}]`:`[${r}]`;if(typeof e[r]=="string"&&e[r].startsWith("blob:")){let o=t(e[r],a);typeof o=="string"&&(e[r]=o)}else e[r]=ge(e[r],t,a)}return e}for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)){let a=e[r],o=n?`${n}.${r}`:r;if(typeof a=="string"&&a.startsWith("blob:")){let i=t(a,o);typeof i=="string"&&(e[r]=i)}else e[r]=ge(a,t,o)}return e}var um=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},ao=um,cm=typeof global=="object"&&global&&global.Object===Object&&global,lo=cm,dm=typeof self=="object"&&self&&self.Object===Object&&self,gm=lo||dm||Function("return this")(),V=gm,pm=V.Symbol,pe=pm,so=Object.prototype,mm=so.hasOwnProperty,fm=so.toString,rt=pe?pe.toStringTag:void 0;function ym(e){var t=mm.call(e,rt),n=e[rt];try{e[rt]=void 0;var r=!0}catch{}var a=fm.call(e);return r&&(t?e[rt]=n:delete e[rt]),a}var bm=ym,hm=Object.prototype,vm=hm.toString;function km(e){return vm.call(e)}var wm=km,Cm="[object Null]",Mm="[object Undefined]",Fi=pe?pe.toStringTag:void 0;function Im(e){return e==null?e===void 0?Mm:Cm:Fi&&Fi in Object(e)?bm(e):wm(e)}var ut=Im;function xm(e){return e!=null&&typeof e=="object"}var qr=xm,lC=Array.isArray;function Am(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var uo=Am,Sm="[object AsyncFunction]",Em="[object Function]",jm="[object GeneratorFunction]",Lm="[object Proxy]";function Tm(e){if(!uo(e))return!1;var t=ut(e);return t==Em||t==jm||t==Sm||t==Lm}var $m=Tm,Nm=V["__core-js_shared__"],Nr=Nm,Gi=function(){var e=/[^.]+$/.exec(Nr&&Nr.keys&&Nr.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Dm(e){return!!Gi&&Gi in e}var Om=Dm,_m=Function.prototype,Pm=_m.toString;function zm(e){if(e!=null){try{return Pm.call(e)}catch{}try{return e+""}catch{}}return""}var Q=zm,Um=/[\\^$.*+?()[\]{}|]/g,Vm=/^\[object .+?Constructor\]$/,Bm=Function.prototype,Fm=Object.prototype,Gm=Bm.toString,Rm=Fm.hasOwnProperty,qm=RegExp("^"+Gm.call(Rm).replace(Um,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Qm(e){if(!uo(e)||Om(e))return!1;var t=$m(e)?qm:Vm;return t.test(Q(e))}var Hm=Qm;function Ym(e,t){return e?.[t]}var Zm=Ym;function Wm(e,t){var n=Zm(e,t);return Hm(n)?n:void 0}var fe=Wm,Km=fe(V,"WeakMap"),Ur=Km;function Jm(e,t){return e===t||e!==e&&t!==t}var Xm=Jm,ef=9007199254740991;function tf(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ef}var rf=tf,sC=Object.prototype,nf="[object Arguments]";function of(e){return qr(e)&&ut(e)==nf}var Ri=of,co=Object.prototype,af=co.hasOwnProperty,lf=co.propertyIsEnumerable,uC=Ri(function(){return arguments}())?Ri:function(e){return qr(e)&&af.call(e,"callee")&&!lf.call(e,"callee")},go=typeof exports=="object"&&exports&&!exports.nodeType&&exports,qi=go&&typeof module=="object"&&module&&!module.nodeType&&module,sf=qi&&qi.exports===go,Qi=sf?V.Buffer:void 0,cC=Qi?Qi.isBuffer:void 0,uf="[object Arguments]",cf="[object Array]",df="[object Boolean]",gf="[object Date]",pf="[object Error]",mf="[object Function]",ff="[object Map]",yf="[object Number]",bf="[object Object]",hf="[object RegExp]",vf="[object Set]",kf="[object String]",wf="[object WeakMap]",Cf="[object ArrayBuffer]",Mf="[object DataView]",If="[object Float32Array]",xf="[object Float64Array]",Af="[object Int8Array]",Sf="[object Int16Array]",Ef="[object Int32Array]",jf="[object Uint8Array]",Lf="[object Uint8ClampedArray]",Tf="[object Uint16Array]",$f="[object Uint32Array]",E={};E[If]=E[xf]=E[Af]=E[Sf]=E[Ef]=E[jf]=E[Lf]=E[Tf]=E[$f]=!0;E[uf]=E[cf]=E[Cf]=E[df]=E[Mf]=E[gf]=E[pf]=E[mf]=E[ff]=E[yf]=E[bf]=E[hf]=E[vf]=E[kf]=E[wf]=!1;function Nf(e){return qr(e)&&rf(e.length)&&!!E[ut(e)]}var Df=Nf;function Of(e){return function(t){return e(t)}}var _f=Of,po=typeof exports=="object"&&exports&&!exports.nodeType&&exports,at=po&&typeof module=="object"&&module&&!module.nodeType&&module,Pf=at&&at.exports===po,Dr=Pf&&lo.process,zf=function(){try{var e=at&&at.require&&at.require("util").types;return e||Dr&&Dr.binding&&Dr.binding("util")}catch{}}(),Hi=zf,Yi=Hi&&Hi.isTypedArray,dC=Yi?_f(Yi):Df,Uf=Object.prototype,gC=Uf.hasOwnProperty;function Vf(e,t){return function(n){return e(t(n))}}var Bf=Vf,pC=Bf(Object.keys,Object),Ff=Object.prototype,mC=Ff.hasOwnProperty,Gf=fe(Object,"create"),lt=Gf;function Rf(){this.__data__=lt?lt(null):{},this.size=0}var qf=Rf;function Qf(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Hf=Qf,Yf="__lodash_hash_undefined__",Zf=Object.prototype,Wf=Zf.hasOwnProperty;function Kf(e){var t=this.__data__;if(lt){var n=t[e];return n===Yf?void 0:n}return Wf.call(t,e)?t[e]:void 0}var Jf=Kf,Xf=Object.prototype,e2=Xf.hasOwnProperty;function t2(e){var t=this.__data__;return lt?t[e]!==void 0:e2.call(t,e)}var r2=t2,n2="__lodash_hash_undefined__";function i2(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=lt&&t===void 0?n2:t,this}var o2=i2;function ye(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ye.prototype.clear=qf;ye.prototype.delete=Hf;ye.prototype.get=Jf;ye.prototype.has=r2;ye.prototype.set=o2;var Zi=ye;function a2(){this.__data__=[],this.size=0}var l2=a2;function s2(e,t){for(var n=e.length;n--;)if(Xm(e[n][0],t))return n;return-1}var Ht=s2,u2=Array.prototype,c2=u2.splice;function d2(e){var t=this.__data__,n=Ht(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():c2.call(t,n,1),--this.size,!0}var g2=d2;function p2(e){var t=this.__data__,n=Ht(t,e);return n<0?void 0:t[n][1]}var m2=p2;function f2(e){return Ht(this.__data__,e)>-1}var y2=f2;function b2(e,t){var n=this.__data__,r=Ht(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var h2=b2;function be(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}be.prototype.clear=l2;be.prototype.delete=g2;be.prototype.get=m2;be.prototype.has=y2;be.prototype.set=h2;var Yt=be,v2=fe(V,"Map"),st=v2;function k2(){this.size=0,this.__data__={hash:new Zi,map:new(st||Yt),string:new Zi}}var w2=k2;function C2(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var M2=C2;function I2(e,t){var n=e.__data__;return M2(t)?n[typeof t=="string"?"string":"hash"]:n.map}var Zt=I2;function x2(e){var t=Zt(this,e).delete(e);return this.size-=t?1:0,t}var A2=x2;function S2(e){return Zt(this,e).get(e)}var E2=S2;function j2(e){return Zt(this,e).has(e)}var L2=j2;function T2(e,t){var n=Zt(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var $2=T2;function he(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}he.prototype.clear=w2;he.prototype.delete=A2;he.prototype.get=E2;he.prototype.has=L2;he.prototype.set=$2;var mo=he;function N2(){this.__data__=new Yt,this.size=0}var D2=N2;function O2(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var _2=O2;function P2(e){return this.__data__.get(e)}var z2=P2;function U2(e){return this.__data__.has(e)}var V2=U2,B2=200;function F2(e,t){var n=this.__data__;if(n instanceof Yt){var r=n.__data__;if(!st||r.length<B2-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new mo(r)}return n.set(e,t),this.size=n.size,this}var G2=F2;function ct(e){var t=this.__data__=new Yt(e);this.size=t.size}ct.prototype.clear=D2;ct.prototype.delete=_2;ct.prototype.get=z2;ct.prototype.has=V2;ct.prototype.set=G2;var R2=Object.prototype,fC=R2.propertyIsEnumerable,q2=fe(V,"DataView"),Vr=q2,Q2=fe(V,"Promise"),Br=Q2,H2=fe(V,"Set"),Fr=H2,Wi="[object Map]",Y2="[object Object]",Ki="[object Promise]",Ji="[object Set]",Xi="[object WeakMap]",eo="[object DataView]",Z2=Q(Vr),W2=Q(st),K2=Q(Br),J2=Q(Fr),X2=Q(Ur),de=ut;(Vr&&de(new Vr(new ArrayBuffer(1)))!=eo||st&&de(new st)!=Wi||Br&&de(Br.resolve())!=Ki||Fr&&de(new Fr)!=Ji||Ur&&de(new Ur)!=Xi)&&(de=function(e){var t=ut(e),n=t==Y2?e.constructor:void 0,r=n?Q(n):"";if(r)switch(r){case Z2:return eo;case W2:return Wi;case K2:return Ki;case J2:return Ji;case X2:return Xi}return t});var yC=V.Uint8Array,ey="__lodash_hash_undefined__";function ty(e){return this.__data__.set(e,ey),this}var ry=ty;function ny(e){return this.__data__.has(e)}var iy=ny;function Gr(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new mo;++t<n;)this.add(e[t])}Gr.prototype.add=Gr.prototype.push=ry;Gr.prototype.has=iy;var to=pe?pe.prototype:void 0,bC=to?to.valueOf:void 0,oy=Object.prototype,hC=oy.hasOwnProperty,ay=Object.prototype,vC=ay.hasOwnProperty,kC=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),wC=new RegExp(/[A-Fa-f0-9]{1}/,"g"),CC=new RegExp(/[A-Fa-f0-9]{2}/,"g");function ly(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function fo(e,t){if(e.startsWith("buffer:")){let n=await t.editor.getMimeType(e),r=t.editor.getBufferLength(e),a=t.editor.getBufferData(e,0,r),o=new Blob([a],{type:n});return URL.createObjectURL(o)}else return e}async function Rr(e,t){let n=await fo(e,t);return new Promise((r,a)=>{let o=new Image;o.onload=()=>{r({width:o.width,height:o.height})},o.onerror=a,o.src=n})}async function sy(e,t,n){let r,a=t.block.getFill(e),o=t.block.getSourceSet(a,"fill/image/sourceSet"),[i]=o;if(i==null){if(r=t.block.getString(a,"fill/image/imageFileURI"),r==null)throw new Error("No image source/uri found")}else r=i.uri;if(n?.throwErrorIfSvg&&await t.editor.getMimeType(r)==="image/svg+xml")throw new Error("SVG images are not supported");return fo(r,t)}function yo(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let n=t.substring(2).split("/"),r=e;for(let a of n){if(r==null)throw new Error(`Invalid reference path: ${t}`);r=r[a]}if(r===void 0)throw new Error(`Reference not found: ${t}`);return r}function it(e,t,n=new Set){if(t==null||n.has(t))return t;if(n.add(t),t.$ref&&typeof t.$ref=="string"){let r=yo(e,t.$ref),a={...it(e,r,n)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(a[o]=it(e,t[o],n));return a}if(Array.isArray(t))return t.map(r=>it(e,r,n));if(typeof t=="object"){let r={};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=it(e,t[a],n));return r}return t}function uy(e){return it(e,{...e})}function cy(e,t=!1){let n=i=>(t&&console.log(`OpenAPI Schema validation failed: ${i}`),!1);if(typeof e!="object"||e===null)return n(`Input is ${e===null?"null":typeof e}, not an object`);let r=e;if(!(typeof r.type=="string"||Array.isArray(r.enum)||typeof r.properties=="object"||typeof r.items=="object"||typeof r.allOf=="object"||typeof r.anyOf=="object"||typeof r.oneOf=="object"||typeof r.not=="object"))return n("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(r.type!==void 0){let i=["string","number","integer","boolean","array","object","null"];if(typeof r.type=="string"){if(!i.includes(r.type))return n(`Invalid type: ${r.type}. Must be one of ${i.join(", ")}`)}else if(Array.isArray(r.type)){for(let l of r.type)if(typeof l!="string"||!i.includes(l))return n(`Array of types contains invalid value: ${l}. Must be one of ${i.join(", ")}`)}else return n(`Type must be a string or array of strings, got ${typeof r.type}`)}if(r.items!==void 0&&(typeof r.items!="object"||r.items===null))return n(`Items must be an object, got ${r.items===null?"null":typeof r.items}`);if(r.properties!==void 0&&(typeof r.properties!="object"||r.properties===null))return n(`Properties must be an object, got ${r.properties===null?"null":typeof r.properties}`);let a=["allOf","anyOf","oneOf"];for(let i of a)if(r[i]!==void 0){if(!Array.isArray(r[i]))return n(`${i} must be an array, got ${typeof r[i]}`);for(let l=0;l<r[i].length;l++){let u=r[i][l];if(typeof u!="object"||u===null)return n(`Item ${l} in ${i} must be an object, got ${u===null?"null":typeof u}`)}}if(r.not!==void 0&&(typeof r.not!="object"||r.not===null))return n(`'not' must be an object, got ${r.not===null?"null":typeof r.not}`);if(r.additionalProperties!==void 0&&typeof r.additionalProperties!="boolean"&&(typeof r.additionalProperties!="object"||r.additionalProperties===null))return n(`additionalProperties must be a boolean or an object, got ${r.additionalProperties===null?"null":typeof r.additionalProperties}`);if(r.format!==void 0&&typeof r.format!="string")return n(`format must be a string, got ${typeof r.format}`);let o=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let i of o)if(r[i]!==void 0&&typeof r[i]!="number")return n(`${i} must be a number, got ${typeof r[i]}`);if(r.minLength!==void 0&&(typeof r.minLength!="number"||r.minLength<0))return n(`minLength must be a non-negative number, got ${typeof r.minLength=="number"?r.minLength:typeof r.minLength}`);if(r.maxLength!==void 0&&(typeof r.maxLength!="number"||r.maxLength<0))return n(`maxLength must be a non-negative number, got ${typeof r.maxLength=="number"?r.maxLength:typeof r.maxLength}`);if(r.pattern!==void 0&&typeof r.pattern!="string")return n(`pattern must be a string, got ${typeof r.pattern}`);if(r.minItems!==void 0&&(typeof r.minItems!="number"||r.minItems<0))return n(`minItems must be a non-negative number, got ${typeof r.minItems=="number"?r.minItems:typeof r.minItems}`);if(r.maxItems!==void 0&&(typeof r.maxItems!="number"||r.maxItems<0))return n(`maxItems must be a non-negative number, got ${typeof r.maxItems=="number"?r.maxItems:typeof r.maxItems}`);if(r.uniqueItems!==void 0&&typeof r.uniqueItems!="boolean")return n(`uniqueItems must be a boolean, got ${typeof r.uniqueItems}`);if(r.minProperties!==void 0&&(typeof r.minProperties!="number"||r.minProperties<0))return n(`minProperties must be a non-negative number, got ${typeof r.minProperties=="number"?r.minProperties:typeof r.minProperties}`);if(r.maxProperties!==void 0&&(typeof r.maxProperties!="number"||r.maxProperties<0))return n(`maxProperties must be a non-negative number, got ${typeof r.maxProperties=="number"?r.maxProperties:typeof r.maxProperties}`);if(r.required!==void 0){if(!Array.isArray(r.required))return n(`required must be an array, got ${typeof r.required}`);for(let i=0;i<r.required.length;i++){let l=r.required[i];if(typeof l!="string")return n(`Item ${i} in required array must be a string, got ${typeof l}`)}}return!0}function dy(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let n=e.properties,r=[];return gy(e,t).forEach(a=>{let o=a,i=n[a]??void 0;r.push({id:o,schema:i})}),r}function gy(e,t){let n=t.order;if(n!=null&&Array.isArray(n))return n;if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,a=Object.keys(r),o=py(e,t)??a;return n!=null&&typeof n=="function"&&(o=n(o)),[...new Set(o)]}function py(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let n=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(r=>r in e);return n==null?void 0:e[n]}var bo=dy,my="ly.img.ai",Or="ly.img.ai/temp";async function fy(e,t){return e.engine.asset.findAllSources().includes(Or)||e.engine.asset.addLocalSource(Or),e.engine.asset.apply(Or,t)}function ho(e){return`${my}/${e}`}function yy(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let n=e;return"message"in n&&typeof n.message=="string"?n.message:"cause"in n&&typeof n.cause=="string"?n.cause:"detail"in n&&typeof n.detail=="object"&&n.detail!==null&&"message"in n.detail&&typeof n.detail.message=="string"?n.detail.message:"error"in n&&typeof n.error=="object"&&n.error!==null&&"message"in n.error&&typeof n.error.message=="string"?n.error.message:t}return typeof e=="string"?e:String(e)||t}function by(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function hy(e,t=0,n="image/jpeg",r=.8){return new Promise((a,o)=>{try{let i=document.createElement("video");i.crossOrigin="anonymous",i.style.display="none",i.addEventListener("loadedmetadata",()=>{i.currentTime=Math.min(t,i.duration),i.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=i.videoWidth,l.height=i.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(i),o(new Error("Failed to create canvas context"));return}u.drawImage(i,0,0,l.width,l.height);try{let s=l.toDataURL(n,r);document.body.removeChild(i),a(s)}catch(s){document.body.removeChild(i),o(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),i.addEventListener("error",()=>{document.body.removeChild(i),o(new Error(`Failed to load video from ${e}`))}),i.src=e,document.body.appendChild(i)}catch(i){o(i)}})}function vo(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function Qr(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function me(e){return e instanceof Error&&e.name==="AbortError"}function ko(e,t,n,r,a,o){if(t.schema==null)return r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null?r.renderCustomProperty[t.id](e,t):void 0;let i=t,l=t.schema.type;if(r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null)return r.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?vy(e,i,n,r,a,o):Co(e,i,n,r,a,o);case"boolean":return Mo(e,i,n,r,a,o);case"number":case"integer":return Io(e,i,n,r,a,o);case"object":return wo(e,i,n,r,a,o);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return ky(e,i,n,r,a,o);break}default:console.error(`Unsupported property type: ${l}`)}}function wo(e,t,n,r,a,o){let i=bo(t.schema??{},r).reduce((l,u)=>{let s=ko(e,u,n,r,a,o);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:i})}function Co(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),g=wy(t.schema),f=g?.component!=null&&g?.component==="TextArea"?"TextArea":"TextInput";return i[f](s,{inputLabel:c,placeholder:a.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function vy(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},g="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},f=(t.schema.enum??[]).map(b=>({id:b,label:d[b]??vo(b),icon:g[b]})),v=t.schema.default!=null?f.find(b=>b.id===t.schema.default)??f[0]:f[0],w=l(s,v);return i.Select(s,{inputLabel:c,values:f,...w}),()=>({id:t.id,type:"string",value:w.value.id})}function Mo(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,g=l(s,d);return i.Checkbox(s,{inputLabel:c,...g}),()=>({id:t.id,type:"boolean",value:g.value})}function Io(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,g=t.schema.maximum,f=t.schema.default;f==null&&(d!=null?f=d:g!=null?f=g:f=0);let v=l(s,f);if(d!=null&&g!=null){let w=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(w=t.schema["x-imgly-step"]),i.Slider(s,{inputLabel:c,min:d,max:g,step:w,...v})}else i.NumberInput(s,{inputLabel:c,min:d,max:g,...v});return()=>({id:t.id,type:"integer",value:v.value})}function ky(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],g=[],f={},v={};d.forEach((p,h)=>{let m=p.title??"common.custom",y=`${n.id}.${u}.anyOf[${h}]`,k="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},C="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};p.type==="string"?p.enum!=null?p.enum.forEach(M=>{g.push({id:M,label:k[M]??vo(M),icon:C[M]})}):(f[y]=()=>Co(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="boolean"?(f[y]=()=>Mo(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="integer"?(f[y]=()=>Io(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="array"||p.type==="object"&&(f[y]=()=>wo(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]}))});let w=t.schema.default!=null?g.find(p=>p.id===t.schema.default)??g[0]:g[0],b=l(s,w);if(i.Select(s,{inputLabel:c,values:g,...b}),b.value.id in f){let p=f[b.value.id]();v[b.value.id]=p}return()=>{let p=v[b.value.id];return p!=null?{...p(),id:t.id}:{id:t.id,type:"string",value:b.value.id}}}function wy(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Cy=ko,My="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",xo=My;function Iy(e,t,n){switch(t){case"image":return xy(e,n[t]);case"video":return Ay(e,n[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function xy(e,t){let n=t.width,r=t.height;return{id:e,meta:{previewUri:xo,fillType:"//ly.img.ubq/fill/image",kind:"image",width:n,height:r}}}function Ay(e,t){let n=t.width,r=t.height;return{id:e,label:t.label,meta:{previewUri:xo,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:n,height:r}}}var Sy=Iy;async function Ey(e,t,n,r){switch(t){case"image":{if(r.kind!=="image")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: image)`);return jy(e,n[t],r)}case"video":{if(r.kind!=="video")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: video)`);return Ly(e,n[t],r)}case"audio":{if(r.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: audio)`);return Ty(e,n[t],r)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function jy(e,t,n){let r=t.width,a=t.height;return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:a},payload:{sourceSet:[{uri:n.url,width:r,height:a}]}}}async function Ly(e,t,n){let r=t.width,a=t.height,o=await hy(n.url,0);return{id:e,label:t.label,meta:{uri:n.url,thumbUri:o,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:a}}}function Ty(e,t,n){return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:n.duration.toString()}}}var ro=Ey;function Ao(e){let t=e.filter(n=>!!n);return n=>async(r,a)=>{let o=[],i=s=>{o.push(s)},l=async(s,c,d)=>{if(s>=t.length)return n(c,d);let g=t[s],f=async(w,b)=>l(s+1,w,b),v={...d,addDisposer:i};return g(c,v,f)},u={...a,addDisposer:i};return{result:await l(0,r,u),dispose:async()=>{for(let s=o.length-1;s>=0;s--)try{await o[s]()}catch(c){console.error("Error in disposer:",c)}o.length=0}}}}function $y(){return async(e,t,n)=>{console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(e,null,2));let r,a=Date.now();try{return r=await n(e,t),r}finally{r!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(r,null,2))),console.groupEnd()}}}var So=$y;function Ny(e){return async(t,n)=>(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await Py(2e3),await Dy(t,e,n))}async function Dy(e,t,n){switch(t.kind){case"image":return Oy(e,t,n);case"video":return _y(e,t,n);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function Oy(e,t,{engine:n}){let r,a,o=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",i=o.match(/(\d+)x(\d+)/);if(i!=null)r=parseInt(i[1],10),a=parseInt(i[2],10);else if(t.blockInputs!=null&&(r=t.blockInputs.image.width,a=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await sy(l,n),s=await Rr(u,n);r=s.width,a=s.height}else r=512,a=512;return{kind:"image",url:`https://placehold.co/${r}x${a}/000000/FFF?text=${o.replace(" ","+").replace(`
139
- `,"+")}`}}async function _y(e,t,n){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function Py(e){return new Promise(t=>{setTimeout(t,e)})}var Eo=Ny;async function zy(e,t,n,r,a,o,i){let{cesdk:l,createPlaceholderBlock:u,historyAssetSourceId:s}=a,c;try{o.debug&&console.group(`Starting Generation for '${e}'`);let d=t(),g=await n(d.input),f=by(),v;if(u){if(v=Sy(f,e,g),o.debug&&console.log("Adding as asset to scene:",JSON.stringify(v,void 0,2)),c=await fy(l,v),c!=null&&r.kind==="video"){let h=l.engine.block.getPositionX(c),m=l.engine.block.getPositionY(c),y=l.engine.block.duplicate(c);l.engine.block.setPositionX(y,h),l.engine.block.setPositionY(y,m),l.engine.block.destroy(c),c=y}if(qt(l,i,c))return{status:"aborted"};if(c==null)throw new Error("Could not create placeholder block");l.engine.block.setState(c,{type:"Pending",progress:0})}let w=Ao([...r.output.middleware??[],o.debug?So():void 0,o.dryRun?Eo({kind:r.kind,blockInputs:g}):void 0]),{result:b}=await w(r.output.generate)(d.input,{abortSignal:i,engine:a.engine,cesdk:l});if(Qr(b))throw new Error("Streaming generation is not supported yet from a panel");if(qt(l,i,c))return{status:"aborted"};if(b==null)throw new Error("Generation failed");o.debug&&console.log("Generated output:",JSON.stringify(b,void 0,2));let p;if(c!=null&&l.engine.block.isValid(c)&&(p=await ro(f,e,g,b),o.debug&&console.log("Updating asset in scene:",JSON.stringify(p,void 0,2)),await l.engine.asset.defaultApplyAssetToBlock(p,c)),qt(l,i,c))return{status:"aborted"};if(s!=null){if(p==null&&(p=await ro(f,e,g,b),qt(l,i,c)))return{status:"aborted"};let h={...p,id:`${Date.now()}-${p.id}`,label:p.label!=null?{en:p.label}:{},tags:{}};l.engine.asset.addAssetToSource(s,h)}return c!=null&&l.engine.block.isValid(c)&&l.engine.block.setState(c,{type:"Ready"}),{status:"success",output:b}}catch(d){throw c!=null&&l.engine.block.isValid(c)&&(me(d)?l.engine.block.destroy(c):l.engine.block.setState(c,{type:"Error",error:"Unknown"})),d}finally{o.debug&&console.groupEnd()}}function qt(e,t,n){return t.aborted?(n!=null&&e.engine.block.isValid(n)&&e.engine.block.destroy(n),!0):!1}var Uy=zy;function Vy(e,t,n){let{cesdk:r,provider:a,getInput:o}=t;n.onError!=null&&typeof n.onError=="function"?n.onError(e):(console.error("Generation failed:",e),By(r,a.output.notification,()=>({input:o?.().input,error:e}))||r.ui.showNotification({type:"error",message:yy(e)}))}function By(e,t,n){let r=t?.error;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.failed",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"error",message:a,action:o}),!0}var ot=Vy;function Qt(e){return`${e}.generating`}function Fy(e){return`${e}.abort`}function Gy(e,t,n,r,a,o){let{builder:i,experimental:l}=e,{cesdk:u,includeHistoryLibrary:s=!0}=a,{id:c,output:{abortable:d}}=t,g=l.global(Fy(c),()=>{}),f=l.global(Qt(c),!1),v,w=f.value&&d,b=()=>{w&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},p;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let m=n();p=a.requiredInputs.every(y=>!m.input[y])}let h=l.global(`${c}.confirmationDialogId`,void 0);i.Section(`${c}.generate.section`,{children:()=>{i.Button(`${c}.generate`,{label:["common.ai-generation.generate",`panel.${c}.generate`],isLoading:f.value,color:"accent",isDisabled:p,suffix:w?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${c}.abort`,"common.cancel"],onClick:()=>{let m=u.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{u.ui.closeDialog(y),h.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{b(),u.ui.closeDialog(y),h.setValue(void 0)}}});h.setValue(m)}}:void 0,onClick:async()=>{v=new AbortController;let m=v.signal,y=async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),v?.abort()});let k=await Uy(t.kind,n,r,t,a,o,m);if(k.status==="aborted")return;let C=t.output.notification;Ry(u,C,()=>({input:n().input,output:k.output}))}catch(k){if(me(k))return;ot(k,{cesdk:u,provider:t,getInput:n},o)}finally{v=void 0,f.setValue(!1),g.setValue(()=>{}),h.value!=null&&(u.ui.closeDialog(h.value),h.setValue(void 0))}};o.middleware!=null?await o.middleware(y,{provider:t,abort:b}):await y()}}),t.output.generationHintText!=null&&i.Text(`${c}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),s&&a.historyAssetLibraryEntryId!=null&&i.Library(`${c}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function Ry(e,t,n){let r=t?.success;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.success",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"success",message:a,action:o,duration:r.duration}),!0}var jo=Gy;async function qy(e,t,n,r){let{cesdk:a}=n,{id:o}=e;r.debug&&console.log(`Registering schema-based panel input for provider ${o}`);let i=uy(t.document),l=yo(i,t.inputReference);if(!cy(l,r.debug))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=bo(u,t),c=d=>{let{builder:g}=d,f=[];g.Section(`${o}.schema.section`,{children:()=>{s.forEach(p=>{let h=Cy(d,p,e,t,n,r);h!=null&&(Array.isArray(h)?f.push(...h):f.push(h))})}});let v=f.map(p=>p()),w=p=>p.type==="object"?Object.entries(p.value).reduce((h,[m,y])=>(h[m]=w(y),h),{}):p.value,b=v.reduce((p,h)=>(p[h.id]=w(h),p),{});jo(d,e,()=>({input:b}),()=>t.getBlockInput(b),{...n,requiredInputs:u.required,createPlaceholderBlock:t.userFlow==="placeholder"},r)};return a.ui.registerPanel(ho(o),c),c}var Qy=qy;async function Hy(e,t,n,r){let{cesdk:a}=n,{id:o}=e,i=t.render,l=u=>{let{state:s}=u,c=s(Qt(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:g}=i(u,{cesdk:a,isGenerating:c});return jo(u,e,d,g,{...n,includeHistoryLibrary:t.includeHistoryLibrary??!0,createPlaceholderBlock:t.userFlow==="placeholder"},r),d};return a.ui.registerPanel(ho(o),l),l}var Yy=Hy,_r="@imgly/plugin-ai-generation",Zy=`
144
+ `,p3=d3,g3=typeof global=="object"&&global&&global.Object===Object&&global,du=g3,f3=typeof self=="object"&&self&&self.Object===Object&&self,h3=du||f3||Function("return this")(),Z=h3,m3=Z.Symbol,Ke=m3,pu=Object.prototype,y3=pu.hasOwnProperty,b3=pu.toString,xr=Ke?Ke.toStringTag:void 0;function v3(e){var t=y3.call(e,xr),r=e[xr];try{e[xr]=void 0;var i=!0}catch{}var n=b3.call(e);return i&&(t?e[xr]=r:delete e[xr]),n}var w3=v3,k3=Object.prototype,x3=k3.toString;function I3(e){return x3.call(e)}var C3=I3,A3="[object Null]",M3="[object Undefined]",ks=Ke?Ke.toStringTag:void 0;function j3(e){return e==null?e===void 0?M3:A3:ks&&ks in Object(e)?w3(e):C3(e)}var Pr=j3;function S3(e){return e!=null&&typeof e=="object"}var So=S3,LW=Array.isArray;function E3(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var gu=E3,_3="[object AsyncFunction]",L3="[object Function]",T3="[object GeneratorFunction]",$3="[object Proxy]";function N3(e){if(!gu(e))return!1;var t=Pr(e);return t==L3||t==T3||t==_3||t==$3}var O3=N3,D3=Z["__core-js_shared__"],uo=D3,xs=function(){var e=/[^.]+$/.exec(uo&&uo.keys&&uo.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function P3(e){return!!xs&&xs in e}var z3=P3,U3=Function.prototype,R3=U3.toString;function F3(e){if(e!=null){try{return R3.call(e)}catch{}try{return e+""}catch{}}return""}var Ie=F3,V3=/[\\^$.*+?()[\]{}|]/g,B3=/^\[object .+?Constructor\]$/,G3=Function.prototype,q3=Object.prototype,Y3=G3.toString,H3=q3.hasOwnProperty,Z3=RegExp("^"+Y3.call(H3).replace(V3,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Q3(e){if(!gu(e)||z3(e))return!1;var t=O3(e)?Z3:B3;return t.test(Ie(e))}var W3=Q3;function K3(e,t){return e?.[t]}var J3=K3;function X3(e,t){var r=J3(e,t);return W3(r)?r:void 0}var rt=X3,e7=rt(Z,"WeakMap"),vo=e7;function t7(e,t){return e===t||e!==e&&t!==t}var r7=t7,i7=9007199254740991;function n7(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=i7}var o7=n7,TW=Object.prototype,a7="[object Arguments]";function l7(e){return So(e)&&Pr(e)==a7}var Is=l7,fu=Object.prototype,s7=fu.hasOwnProperty,u7=fu.propertyIsEnumerable,$W=Is(function(){return arguments}())?Is:function(e){return So(e)&&s7.call(e,"callee")&&!u7.call(e,"callee")},hu=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Cs=hu&&typeof module=="object"&&module&&!module.nodeType&&module,c7=Cs&&Cs.exports===hu,As=c7?Z.Buffer:void 0,NW=As?As.isBuffer:void 0,d7="[object Arguments]",p7="[object Array]",g7="[object Boolean]",f7="[object Date]",h7="[object Error]",m7="[object Function]",y7="[object Map]",b7="[object Number]",v7="[object Object]",w7="[object RegExp]",k7="[object Set]",x7="[object String]",I7="[object WeakMap]",C7="[object ArrayBuffer]",A7="[object DataView]",M7="[object Float32Array]",j7="[object Float64Array]",S7="[object Int8Array]",E7="[object Int16Array]",_7="[object Int32Array]",L7="[object Uint8Array]",T7="[object Uint8ClampedArray]",$7="[object Uint16Array]",N7="[object Uint32Array]",S={};S[M7]=S[j7]=S[S7]=S[E7]=S[_7]=S[L7]=S[T7]=S[$7]=S[N7]=!0;S[d7]=S[p7]=S[C7]=S[g7]=S[A7]=S[f7]=S[h7]=S[m7]=S[y7]=S[b7]=S[v7]=S[w7]=S[k7]=S[x7]=S[I7]=!1;function O7(e){return So(e)&&o7(e.length)&&!!S[Pr(e)]}var D7=O7;function P7(e){return function(t){return e(t)}}var z7=P7,mu=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Er=mu&&typeof module=="object"&&module&&!module.nodeType&&module,U7=Er&&Er.exports===mu,co=U7&&du.process,R7=function(){try{var e=Er&&Er.require&&Er.require("util").types;return e||co&&co.binding&&co.binding("util")}catch{}}(),Ms=R7,js=Ms&&Ms.isTypedArray,OW=js?z7(js):D7,F7=Object.prototype,DW=F7.hasOwnProperty;function V7(e,t){return function(r){return e(t(r))}}var B7=V7,PW=B7(Object.keys,Object),G7=Object.prototype,zW=G7.hasOwnProperty,q7=rt(Object,"create"),Tr=q7;function Y7(){this.__data__=Tr?Tr(null):{},this.size=0}var H7=Y7;function Z7(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Q7=Z7,W7="__lodash_hash_undefined__",K7=Object.prototype,J7=K7.hasOwnProperty;function X7(e){var t=this.__data__;if(Tr){var r=t[e];return r===W7?void 0:r}return J7.call(t,e)?t[e]:void 0}var e8=X7,t8=Object.prototype,r8=t8.hasOwnProperty;function i8(e){var t=this.__data__;return Tr?t[e]!==void 0:r8.call(t,e)}var n8=i8,o8="__lodash_hash_undefined__";function a8(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Tr&&t===void 0?o8:t,this}var l8=a8;function it(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}it.prototype.clear=H7;it.prototype.delete=Q7;it.prototype.get=e8;it.prototype.has=n8;it.prototype.set=l8;var Ss=it;function s8(){this.__data__=[],this.size=0}var u8=s8;function c8(e,t){for(var r=e.length;r--;)if(r7(e[r][0],t))return r;return-1}var on=c8,d8=Array.prototype,p8=d8.splice;function g8(e){var t=this.__data__,r=on(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():p8.call(t,r,1),--this.size,!0}var f8=g8;function h8(e){var t=this.__data__,r=on(t,e);return r<0?void 0:t[r][1]}var m8=h8;function y8(e){return on(this.__data__,e)>-1}var b8=y8;function v8(e,t){var r=this.__data__,i=on(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var w8=v8;function nt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}nt.prototype.clear=u8;nt.prototype.delete=f8;nt.prototype.get=m8;nt.prototype.has=b8;nt.prototype.set=w8;var an=nt,k8=rt(Z,"Map"),$r=k8;function x8(){this.size=0,this.__data__={hash:new Ss,map:new($r||an),string:new Ss}}var I8=x8;function C8(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var A8=C8;function M8(e,t){var r=e.__data__;return A8(t)?r[typeof t=="string"?"string":"hash"]:r.map}var ln=M8;function j8(e){var t=ln(this,e).delete(e);return this.size-=t?1:0,t}var S8=j8;function E8(e){return ln(this,e).get(e)}var _8=E8;function L8(e){return ln(this,e).has(e)}var T8=L8;function $8(e,t){var r=ln(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var N8=$8;function ot(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}ot.prototype.clear=I8;ot.prototype.delete=S8;ot.prototype.get=_8;ot.prototype.has=T8;ot.prototype.set=N8;var yu=ot;function O8(){this.__data__=new an,this.size=0}var D8=O8;function P8(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var z8=P8;function U8(e){return this.__data__.get(e)}var R8=U8;function F8(e){return this.__data__.has(e)}var V8=F8,B8=200;function G8(e,t){var r=this.__data__;if(r instanceof an){var i=r.__data__;if(!$r||i.length<B8-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new yu(i)}return r.set(e,t),this.size=r.size,this}var q8=G8;function zr(e){var t=this.__data__=new an(e);this.size=t.size}zr.prototype.clear=D8;zr.prototype.delete=z8;zr.prototype.get=R8;zr.prototype.has=V8;zr.prototype.set=q8;var Y8=Object.prototype,UW=Y8.propertyIsEnumerable,H8=rt(Z,"DataView"),wo=H8,Z8=rt(Z,"Promise"),ko=Z8,Q8=rt(Z,"Set"),xo=Q8,Es="[object Map]",W8="[object Object]",_s="[object Promise]",Ls="[object Set]",Ts="[object WeakMap]",$s="[object DataView]",K8=Ie(wo),J8=Ie($r),X8=Ie(ko),ev=Ie(xo),tv=Ie(vo),Ze=Pr;(wo&&Ze(new wo(new ArrayBuffer(1)))!=$s||$r&&Ze(new $r)!=Es||ko&&Ze(ko.resolve())!=_s||xo&&Ze(new xo)!=Ls||vo&&Ze(new vo)!=Ts)&&(Ze=function(e){var t=Pr(e),r=t==W8?e.constructor:void 0,i=r?Ie(r):"";if(i)switch(i){case K8:return $s;case J8:return Es;case X8:return _s;case ev:return Ls;case tv:return Ts}return t});var RW=Z.Uint8Array,rv="__lodash_hash_undefined__";function iv(e){return this.__data__.set(e,rv),this}var nv=iv;function ov(e){return this.__data__.has(e)}var av=ov;function Io(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new yu;++t<r;)this.add(e[t])}Io.prototype.add=Io.prototype.push=nv;Io.prototype.has=av;var Ns=Ke?Ke.prototype:void 0,FW=Ns?Ns.valueOf:void 0,lv=Object.prototype,VW=lv.hasOwnProperty,sv=Object.prototype,BW=sv.hasOwnProperty,GW=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),qW=new RegExp(/[A-Fa-f0-9]{1}/,"g"),YW=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function uv(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function at(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return uv(i,t)}function cv(e){return e==null?[]:Array.isArray(e)?e:[e]}var Os=cv,Ji="@imgly/plugin-ai-image-generation-web",dv=["ly.img.gpt-image-1.changeStyleLibrary","ly.img.styleTransfer","ly.img.artistTransfer","ly.img.separator","ly.img.editImage","ly.img.swapBackground","ly.img.createVariant","ly.img.combineImages","ly.img.separator","ly.img.remixPage","ly.img.separator","ly.img.createVideo"],bu="editImage",ie=`ly.img.${bu}`,R=`ly.img.ai.quickAction.image.${bu}`,pv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${R}.label`]:"Edit Image...",[`${R}.description`]:"Change image based on description",[`${R}.prompt.label`]:"Edit Image...",[`${R}.prompt.placeholder`]:'e.g. "Add a sunset"',[`${R}.apply`]:"Change"}}),{id:ie,type:"quick",kind:"image",label:`${R}.label`,description:`${R}.description`,enable:Dr(),scopes:["fill/change"],render:({builder:t,experimental:r,isExpanded:i,toggleExpand:n,generate:a,engine:o,state:l,close:u})=>{if(i){let s=l(`${ie}.prompt`,"");t.TextArea(`${ie}.prompt`,{inputLabel:`${R}.prompt.label`,placeholder:`${R}.prompt.placeholder`,...s}),t.Separator(`${ie}.separator`),r.builder.ButtonRow(`${ie}.footer`,{justifyContent:"space-between",children:()=>{t.Button(`${ie}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:n}),t.Button(`${ie}.footer.apply`,{label:`${R}.apply`,icon:"@imgly/MagicWand",color:"accent",isDisabled:s.value.length===0,onClick:async()=>{try{let c=s.value;if(!c)return;let[d]=o.block.findAllSelected(),p=await at(d,o,{throwErrorIfSvg:!0});await a({prompt:c,uri:p}),n(),u()}catch(c){console.error("Generation error:",c),e.ui.showNotification({type:"error",message:c.message||"Failed to edit image. Please try again.",duration:"medium"})}}})}})}else t.Button(`${ie}.button`,{label:`${R}.label`,icon:"@imgly/plugin-ai-generation/image",labelAlignment:"left",variant:"plain",onClick:n})}}),gv=pv,vu="swapBackground",ne=`ly.img.${vu}`,F=`ly.img.ai.quickAction.image.${vu}`,fv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${F}.label`]:"Swap Background...",[`${F}.description`]:"Change the background of the image",[`${F}.prompt.label`]:"Swap Background...",[`${F}.prompt.placeholder`]:'e.g. "A sunset over mountains"',[`${F}.apply`]:"Change"}}),{id:ne,type:"quick",kind:"image",label:`${F}.label`,description:`${F}.description`,enable:Dr(),scopes:["fill/change"],render:({builder:t,experimental:r,isExpanded:i,toggleExpand:n,generate:a,engine:o,state:l,close:u})=>{if(i){let s=l(`${ne}.prompt`,"");t.TextArea(`${ne}.prompt`,{inputLabel:`${F}.prompt.label`,placeholder:`${F}.prompt.placeholder`,...s}),t.Separator(`${ne}.separator`),r.builder.ButtonRow(`${ne}.footer`,{justifyContent:"space-between",children:()=>{t.Button(`${ne}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:n}),t.Button(`${ne}.footer.apply`,{label:`${F}.apply`,icon:"@imgly/MagicWand",color:"accent",isDisabled:s.value.length===0,onClick:async()=>{try{let c=s.value;if(!c)return;let[d]=o.block.findAllSelected(),p=await at(d,o,{throwErrorIfSvg:!0});await a({prompt:`Swap the background to ${c}`,uri:p}),n(),u()}catch(c){console.error("Generation error:",c),e.ui.showNotification({type:"error",message:c.message||"Failed to swap background. Please try again.",duration:"medium"})}}})}})}else t.Button(`${ne}.button`,{label:`${F}.label`,icon:"@imgly/plugin-ai-generation/image",labelAlignment:"left",variant:"plain",onClick:n})}}),hv=fv,wu="styleTransfer",Ir=`ly.img.${wu}`,Cr=`ly.img.ai.quickAction.image.${wu}`,mv=[{id:"water",label:"Watercolor Painting",prompt:"Convert to watercolor painting."},{id:"oil",label:"Oil Painting",prompt:"Render in oil painting style."},{id:"charcoal",label:"Charcoal Sketch",prompt:"Transform into a charcoal sketch."},{id:"pencil",label:"Pencil Drawing",prompt:"Apply pencil drawing effect."},{id:"pastel",label:"Pastel Artwork",prompt:"Make it look like a pastel artwork."},{id:"ink",label:"Ink Wash",prompt:"Turn into a classic ink wash painting."},{id:"stained-glass",label:"Stained Glass Window",prompt:"Stylize as a stained glass window."},{id:"japanese",label:"Japanese Woodblock Print",prompt:"Repaint as a traditional Japanese woodblock print."}],yv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Cr}.label`]:"Change Art Style",[`${Cr}.description`]:"Transform image into different art styles"}}),{id:Ir,type:"quick",kind:"image",label:`${Cr}.label`,description:`${Cr}.description`,enable:Dr(),scopes:["fill/change"],render:({builder:t,experimental:r,generate:i,engine:n,close:a})=>{r.builder.Popover(`${Ir}.popover`,{label:`${Cr}.label`,icon:"@imgly/Appearance",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{t.Section(`${Ir}.popover.section`,{children:()=>{r.builder.Menu(`${Ir}.popover.menu`,{children:()=>{mv.forEach(o=>{t.Button(`${Ir}.popover.menu.${o.id}`,{label:o.label,labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[l]=n.block.findAllSelected(),u=await at(l,n,{throwErrorIfSvg:!0});await i({style:o.prompt,uri:u}),a()}catch(l){console.error("Generation error:",l),e.ui.showNotification({type:"error",message:l.message||"Failed to apply style transfer. Please try again.",duration:"medium"})}}})})}})}})}})}}),bv=yv,ku="artistTransfer",Ar=`ly.img.${ku}`,Mr=`ly.img.ai.quickAction.image.${ku}`,vv=[{id:"van-gogh",label:"Van Gogh",prompt:"Render this image in the style of Vincent van Gogh, using expressive brushstrokes and swirling motion."},{id:"monet",label:"Monet",prompt:"Transform this image into the soft, impressionistic style of Claude Monet with natural light and delicate color blending."},{id:"picasso",label:"Picasso",prompt:"Apply a Pablo Picasso cubist style with abstract geometry and fragmented shapes."},{id:"dali",label:"Dal\xED",prompt:"Make this image resemble Salvador Dal\xED's surrealist style, with dreamlike distortion and soft shadows."},{id:"matisse",label:"Matisse",prompt:"Stylize the image using Henri Matisse's bold colors and simplified, flowing shapes."},{id:"warhol",label:"Warhol",prompt:"Convert this image into Andy Warhol's pop art style with flat colors, repetition, and bold outlines."},{id:"michelangelo",label:"Michelangelo",prompt:"Render the image in the classical Renaissance style of Michelangelo, with dramatic anatomy and fresco-like detail."},{id:"da-vinci",label:"Da Vinci",prompt:"Make this image look like a Leonardo da Vinci painting, using soft transitions, balanced composition, and natural tones."},{id:"rembrandt",label:"Rembrandt",prompt:"Apply Rembrandt's style with rich contrast, warm tones, and dramatic use of light and shadow."},{id:"mondrian",label:"Mondrian",prompt:"Transform the image into Piet Mondrian's abstract geometric style with grids and primary colors."},{id:"kahlo",label:"Frida Kahlo",prompt:"Stylize this image in the expressive, symbolic style of Frida Kahlo with vivid colors and surreal framing."},{id:"hokusai",label:"Hokusai",prompt:"Render the image in the style of Hokusai, using bold outlines, flat color, and traditional Japanese woodblock aesthetics."}],wv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Mr}.label`]:"Painted By",[`${Mr}.description`]:"Transform image in the style of famous artists"}}),{id:Ar,type:"quick",kind:"image",label:`${Mr}.label`,description:`${Mr}.description`,enable:Dr(),scopes:["fill/change"],render:({builder:t,experimental:r,generate:i,engine:n,close:a})=>{r.builder.Popover(`${Ar}.popover`,{label:`${Mr}.label`,icon:"@imgly/Appearance",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{t.Section(`${Ar}.popover.section`,{children:()=>{r.builder.Menu(`${Ar}.popover.menu`,{children:()=>{vv.forEach(o=>{t.Button(`${Ar}.popover.menu.${o.id}`,{label:o.label,labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[l]=n.block.findAllSelected(),u=await at(l,n,{throwErrorIfSvg:!0});await i({artist:o.prompt,uri:u}),a()}catch(l){console.error("Generation error:",l),e.ui.showNotification({type:"error",message:l.message||"Failed to apply artist style. Please try again.",duration:"medium"})}}})})}})}})}})}}),kv=wv,xu="createVariant",oe=`ly.img.${xu}`,V=`ly.img.ai.quickAction.image.${xu}`,xv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${V}.label`]:"Create Variant...",[`${V}.description`]:"Create a variation of the image",[`${V}.prompt.label`]:"Create Variant...",[`${V}.prompt.placeholder`]:'e.g. "Make it more colorful"',[`${V}.apply`]:"Create"}}),{id:oe,type:"quick",kind:"image",defaults:{confirmation:!1,lock:!1},label:`${V}.label`,description:`${V}.description`,enable:t=>{if(!Dr()(t))return!1;let[r]=t.engine.block.findAllSelected();return!(!e.feature.isEnabled("ly.img.duplicate",{engine:t.engine})||!t.engine.block.isAllowedByScope(r,"lifecycle/duplicate"))},scopes:["fill/change","lifecycle/duplicate"],render:({builder:t,experimental:r,isExpanded:i,toggleExpand:n,generate:a,engine:o,state:l,close:u})=>{if(i){let s=l(`${oe}.prompt`,"");t.TextArea(`${oe}.prompt`,{inputLabel:`${V}.prompt.label`,placeholder:`${V}.prompt.placeholder`,...s}),t.Separator(`${oe}.separator`),r.builder.ButtonRow(`${oe}.footer`,{justifyContent:"space-between",children:()=>{t.Button(`${oe}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:n}),t.Button(`${oe}.footer.apply`,{label:`${V}.apply`,icon:"@imgly/MagicWand",color:"accent",isDisabled:s.value.length===0,onClick:async()=>{try{let c=s.value;if(!c)return;let[d]=o.block.findAllSelected(),p=o.block.getType(d),g=o.block.duplicate(d);p==="//ly.img.ubq/page"&&o.block.getChildren(g).forEach(m=>{o.block.destroy(m)}),o.block.setSelected(d,!1),o.block.setSelected(g,!0);let f=o.block.getParent(g);if(f==null)throw new Error("Parent not found");if(!(f!=null&&o.block.getType(f)==="//ly.img.ubq/track"&&o.block.isPageDurationSource(f))&&p!=="//ly.img.ubq/page"){let m=o.block.getWidth(f),h=o.block.getHeight(f),x=.02*Math.min(m,h)*1;o.block.setPositionX(g,o.block.getPositionX(g)+x),o.block.setPositionY(g,o.block.getPositionY(g)+x)}let b=await at(g,o,{throwErrorIfSvg:!0});await a({prompt:c,uri:b},{blockIds:[g]}),n(),u()}catch(c){console.error("Generation error:",c),e.ui.showNotification({type:"error",message:c.message||"Failed to create variant. Please try again.",duration:"medium"})}}})}})}else t.Button(`${oe}.button`,{label:`${V}.label`,icon:"@imgly/ImageVariation",labelAlignment:"left",variant:"plain",onClick:n})}}),Iv=xv,Iu="combineImages",ae=`ly.img.${Iu}`,q=`ly.img.ai.quickAction.${Iu}`,Cv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${q}.apply`]:"Combine",[`${q}`]:"Combine Images...",[`${q}.prompt.inputLabel`]:"Image Combination Instructions",[`${q}.prompt.placeholder`]:"e.g., add character to the left of the mountain scene"}}),{id:ae,type:"quick",kind:"image",defaults:{confirmation:!1,lock:!1},label:`${q}`,description:"Combine multiple images with instructions",enable:t=>{let r=t.engine.block.findAllSelected();return r==null||r.length<2?!1:r.every(i=>{if(t.engine.block.getType(i)!=="//ly.img.ubq/graphic"&&!t.engine.block.supportsFill(i))return!1;let n=t.engine.block.getFill(i);if(t.engine.block.getType(n)!=="//ly.img.ubq/fill/image"||!e.feature.isEnabled("ly.img.duplicate",{engine:t.engine})||!t.engine.block.isAllowedByScope(i,"lifecycle/duplicate"))return!1;let a=t.engine.block.getParent(i);return!(a!=null&&t.engine.block.getType(a)==="//ly.img.ubq/track"&&t.engine.block.isPageDurationSource(a)||t.engine.block.getType(i)==="//ly.img.ubq/page")})},scopes:["lifecycle/duplicate","fill/change"],render:({builder:t,experimental:r,isExpanded:i,toggleExpand:n,generate:a,engine:o,state:l,close:u})=>{if(i){let s=l(`${ae}.prompt`,"");t.TextArea(`${ae}.prompt`,{inputLabel:`${q}.prompt.inputLabel`,placeholder:`${q}.prompt.placeholder`,...s}),t.Separator(`${ae}.separator`),r.builder.ButtonRow(`${ae}.footer`,{justifyContent:"space-between",children:()=>{t.Button(`${ae}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:n}),t.Button(`${ae}.footer.apply`,{label:`${q}.apply`,icon:"@imgly/MagicWand",color:"accent",isDisabled:s.value.length===0,onClick:async()=>{try{let c=s.value;if(!c)return;let d=o.block.findAllSelected(),p=o.block.duplicate(d[0]);d.forEach(w=>{o.block.setSelected(w,!1)}),o.block.setSelected(p,!0);let g=o.block.getParent(p);if(g==null)throw new Error("Parent not found");let f=1,b=o.block.getWidth(g),m=o.block.getHeight(g),h=.02*Math.min(b,m)*f;o.block.setPositionX(p,o.block.getPositionX(p)+h),o.block.setPositionY(p,o.block.getPositionY(p)+h);let x=await Promise.all(d.map(w=>at(w,o,{throwErrorIfSvg:!0})));await a({prompt:c,uris:x,exportFromBlockIds:d},{blockIds:[p]}),n(),u()}catch(c){console.error("Generation error:",c),e.ui.showNotification({type:"error",message:c.message||"Failed to combine images. Please try again.",duration:"medium"})}}})}})}else t.Button(`${ae}.button`,{label:`${q}`,icon:"@imgly/ImageVariation",labelAlignment:"left",variant:"plain",onClick:n})}}),Av=Cv,Cu="remixPage",Ds=`ly.img.${Cu}`,po=`ly.img.ai.quickAction.${Cu}`,Mv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${po}`]:"Turn Page into Image"}}),{id:Ds,type:"quick",kind:"image",defaults:{confirmation:!1,lock:!1},label:`${po}`,description:"Convert the page into a single image",enable:({engine:t})=>{let r=t.block.findAllSelected();if(r.length!==1)return!1;let i=r[0];return t.block.getType(i)==="//ly.img.ubq/page"},scopes:["lifecycle/duplicate"],render:({builder:t,generate:r,engine:i,close:n})=>{t.Button(`${Ds}.button`,{label:`${po}`,icon:"@imgly/Sparkle",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),o=await i.block.export(a),l=URL.createObjectURL(o),u=i.block.duplicate(a);i.block.getChildren(u).forEach(m=>{i.block.destroy(m)}),i.block.setSelected(a,!1);let s=i.block.getFrameWidth(a),c=i.block.getFrameHeight(a),d=i.block.getPositionX(a),p=i.block.getPositionY(a),g=i.block.createShape("rect"),f=i.block.create("graphic");i.block.setShape(f,g),i.block.appendChild(u,f),i.block.setWidth(f,s),i.block.setHeight(f,c),i.block.setPositionX(f,d),i.block.setPositionY(f,p);let b=i.block.createFill("image");i.block.setFill(f,b),i.block.setString(b,"fill/image/imageFileURI",l),i.block.setSelected(f,!0),i.scene.zoomToBlock(f),await r({prompt:"Follow instructions but don't add the instructions for the image",uri:l},{blockIds:[f]}),n()}catch(a){console.error("Generation error:",a),e.ui.showNotification({type:"error",message:a.message||"Failed to remix page. Please try again.",duration:"medium"})}}})}}),jv=Mv,Au="remixPageWithPrompt",le=`ly.img.${Au}`,Y=`ly.img.ai.quickAction.${Au}`,Sv=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Y}`]:"Remix Page...",[`${Y}.prompt.inputLabel`]:"Remix Page Prompt",[`${Y}.prompt.placeholder`]:"e.g. rearrange the layout to...",[`${Y}.apply`]:"Remix"}}),{id:le,type:"quick",kind:"image",defaults:{confirmation:!1,lock:!1},label:`${Y}`,description:"Remix the page with custom instructions",enable:({engine:t})=>{let r=t.block.findAllSelected();if(r.length!==1)return!1;let i=r[0];return t.block.getType(i)==="//ly.img.ubq/page"},scopes:["lifecycle/duplicate"],render:({builder:t,experimental:r,isExpanded:i,toggleExpand:n,generate:a,engine:o,state:l,close:u})=>{if(i){let s=l(`${le}.prompt`,"");t.TextArea(`${le}.prompt`,{inputLabel:`${Y}.prompt.inputLabel`,placeholder:`${Y}.prompt.placeholder`,...s}),t.Separator(`${le}.separator`),r.builder.ButtonRow(`${le}.footer`,{justifyContent:"space-between",children:()=>{t.Button(`${le}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:n}),t.Button(`${le}.footer.apply`,{label:`${Y}.apply`,icon:"@imgly/MagicWand",color:"accent",isDisabled:s.value.length===0,onClick:async()=>{try{let c=s.value;if(!c)return;let[d]=o.block.findAllSelected(),p=await o.block.export(d),g=URL.createObjectURL(p),f=o.block.duplicate(d);o.block.getChildren(f).forEach(k=>{o.block.destroy(k)}),o.block.setSelected(d,!1);let b=o.block.getFrameWidth(d),m=o.block.getFrameHeight(d),h=o.block.getPositionX(d),x=o.block.getPositionY(d),w=o.block.createShape("rect"),v=o.block.create("graphic");o.block.setShape(v,w),o.block.appendChild(f,v),o.block.setWidth(v,b),o.block.setHeight(v,m),o.block.setPositionX(v,h),o.block.setPositionY(v,x);let y=o.block.createFill("image");o.block.setFill(v,y),o.block.setString(y,"fill/image/imageFileURI",g),o.block.setSelected(v,!0),o.scene.zoomToBlock(v),await a({prompt:c,uri:g},{blockIds:[v]}),n(),u()}catch(c){console.error("Generation error:",c),e.ui.showNotification({type:"error",message:c.message||"Failed to remix page. Please try again.",duration:"medium"})}}})}})}else t.Button(`${le}.button`,{label:`${Y}`,icon:"@imgly/Sparkle",labelAlignment:"left",variant:"plain",onClick:n})}}),Ev=Sv,se="ly.img.ai.image-generation";function _v(e){return{async initialize({cesdk:t}){if(t==null)return;_5(t,Ji,"0.2.0");let r=Ys.get(),i=r.register({type:"plugin",sceneMode:"Design",id:Ji,pluginId:Ji,label:"Generate Image",meta:{panelId:se},execute:()=>{t.ui.isPanelOpen(se)?t.ui.closePanel(se):t.ui.openPanel(se)}});t.ui.addIconSet(c3,p3),t.i18n.setTranslations({en:{[`panel.${se}`]:"Image Generation",[`${se}.dock.label`]:"AI Image"}}),Lv(e),r.register(gv({cesdk:t})),r.register(hv({cesdk:t})),r.register(bv({cesdk:t})),r.register(kv({cesdk:t})),r.register(Iv({cesdk:t})),r.register(Av({cesdk:t})),r.register(jv({cesdk:t})),r.register(Ev({cesdk:t}));let n=e.providers?.text2image??e.text2image,a=e.providers?.image2image??e.image2image,o=await Promise.all(Os(n).map(c=>c({cesdk:t}))),l=await Promise.all(Os(a).map(c=>c({cesdk:t}))),u=await U9("image",{fromText:o,fromImage:l},{cesdk:t},e),s=await u3({kind:"image",providerInitializationResults:u.providerInitializationResults,cesdk:t,engine:t.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:dv});u.history?.assetSourceId!=null,s.renderFunction!=null&&(t.ui.registerComponent("ly.img.ai.image.canvasMenu",s.renderFunction),t.ui.setCanvasMenuOrder(["ly.img.ai.image.canvasMenu"],{editMode:nn})),u.panel.builderRenderFunction!=null?(t.ui.registerPanel(se,u.panel.builderRenderFunction),T5({cesdk:t,panelId:se})):i()}}}function Lv(e){e.debug&&(e.providers?.text2image!=null&&e.text2image!=null&&console.warn("[ImageGeneration]: Both `providers.text2image` and `text2image` configuration is provided. Since `text2image` is deprecated, only `providers.text2image` will be used."),e.providers?.image2image!=null&&e.image2image!=null&&console.warn("[ImageGeneration]: Both `providers.image2image` and `image2image` configuration is provided. Since `image2image` is deprecated, only `providers.image2image` will be used."))}var Tv=_v,$v=e=>({name:Ji,version:"0.2.0",...Tv(e)}),Mu=$v;var Nv=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",p=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(p=s.tags[c]);let g={...s,label:d,tags:p};return this.filterAsset(g,e)&&u.push(g),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),l=a<t.length?r+1:void 0;return{assets:o,currentPage:r,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let i=new Set;r.result.forEach(a=>{a.groups&&Array.isArray(a.groups)&&a.groups.forEach(o=>i.add(o))});let n=[...i];e(n)},r.onerror=()=>{t(new Error(`Failed to get groups: ${r.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),r=t.objectStore(this.assetStoreName),i=new Set;ut(e,a=>{i.add(a)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.assetStoreName,"readwrite");r.objectStore(this.assetStoreName).delete(e),r.oncomplete=()=>{ut(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let l=a.meta?.insertedAt||a._insertedAt||Date.now(),u=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return ut(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),ut(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!o.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(l=>e.tags?.includes(l))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,l)=>{let u,s;return i==="id"?(u=o.id,s=l.id):(u=o.meta?.[i]??null,s=l.meta?.[i]??null),u==null?r==="Ascending"?-1:1:s==null?r==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?r==="Ascending"?u.localeCompare(s):s.localeCompare(u):r==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):r==="Descending"&&a.reverse(),n&&a.sort((o,l)=>o.active&&!l.active?-1:!o.active&&l.active?1:0)),a}};function ut(e,t,r=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let i=0;i<e.length;i++){let n=r?`${r}[${i}]`:`[${i}]`;if(typeof e[i]=="string"&&e[i].startsWith("blob:")){let a=t(e[i],n);typeof a=="string"&&(e[i]=a)}else e[i]=ut(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],a=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let o=t(n,a);typeof o=="string"&&(e[i]=o)}else e[i]=ut(n,t,a)}return e}var Ov=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,d)=>{let p=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,l=o+a,u=i.slice(o,l),s=l<i.length?n+1:void 0;return{assets:u,currentPage:n,nextPage:s,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}},Dv=typeof global=="object"&&global&&global.Object===Object&&global,ac=Dv,Pv=typeof self=="object"&&self&&self.Object===Object&&self,zv=ac||Pv||Function("return this")(),Q=zv,Uv=Q.Symbol,ct=Uv,lc=Object.prototype,Rv=lc.hasOwnProperty,Fv=lc.toString,Ur=ct?ct.toStringTag:void 0;function Vv(e){var t=Rv.call(e,Ur),r=e[Ur];try{e[Ur]=void 0;var i=!0}catch{}var n=Fv.call(e);return i&&(t?e[Ur]=r:delete e[Ur]),n}var Bv=Vv,Gv=Object.prototype,qv=Gv.toString;function Yv(e){return qv.call(e)}var Hv=Yv,Zv="[object Null]",Qv="[object Undefined]",ju=ct?ct.toStringTag:void 0;function Wv(e){return e==null?e===void 0?Qv:Zv:ju&&ju in Object(e)?Bv(e):Hv(e)}var Wr=Wv;function Kv(e){return e!=null&&typeof e=="object"}var Yo=Kv,KW=Array.isArray;function Jv(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var sc=Jv,Xv="[object AsyncFunction]",e6="[object Function]",t6="[object GeneratorFunction]",r6="[object Proxy]";function i6(e){if(!sc(e))return!1;var t=Wr(e);return t==e6||t==t6||t==Xv||t==r6}var n6=i6,o6=Q["__core-js_shared__"],Eo=o6,Su=function(){var e=/[^.]+$/.exec(Eo&&Eo.keys&&Eo.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function a6(e){return!!Su&&Su in e}var l6=a6,s6=Function.prototype,u6=s6.toString;function c6(e){if(e!=null){try{return u6.call(e)}catch{}try{return e+""}catch{}}return""}var Ce=c6,d6=/[\\^$.*+?()[\]{}|]/g,p6=/^\[object .+?Constructor\]$/,g6=Function.prototype,f6=Object.prototype,h6=g6.toString,m6=f6.hasOwnProperty,y6=RegExp("^"+h6.call(m6).replace(d6,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function b6(e){if(!sc(e)||l6(e))return!1;var t=n6(e)?y6:p6;return t.test(Ce(e))}var v6=b6;function w6(e,t){return e?.[t]}var k6=w6;function x6(e,t){var r=k6(e,t);return v6(r)?r:void 0}var pt=x6,I6=pt(Q,"WeakMap"),Do=I6;function C6(e,t){return e===t||e!==e&&t!==t}var A6=C6,M6=9007199254740991;function j6(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=M6}var S6=j6,JW=Object.prototype,E6="[object Arguments]";function _6(e){return Yo(e)&&Wr(e)==E6}var Eu=_6,uc=Object.prototype,L6=uc.hasOwnProperty,T6=uc.propertyIsEnumerable,XW=Eu(function(){return arguments}())?Eu:function(e){return Yo(e)&&L6.call(e,"callee")&&!T6.call(e,"callee")},cc=typeof exports=="object"&&exports&&!exports.nodeType&&exports,_u=cc&&typeof module=="object"&&module&&!module.nodeType&&module,$6=_u&&_u.exports===cc,Lu=$6?Q.Buffer:void 0,eK=Lu?Lu.isBuffer:void 0,N6="[object Arguments]",O6="[object Array]",D6="[object Boolean]",P6="[object Date]",z6="[object Error]",U6="[object Function]",R6="[object Map]",F6="[object Number]",V6="[object Object]",B6="[object RegExp]",G6="[object Set]",q6="[object String]",Y6="[object WeakMap]",H6="[object ArrayBuffer]",Z6="[object DataView]",Q6="[object Float32Array]",W6="[object Float64Array]",K6="[object Int8Array]",J6="[object Int16Array]",X6="[object Int32Array]",ew="[object Uint8Array]",tw="[object Uint8ClampedArray]",rw="[object Uint16Array]",iw="[object Uint32Array]",E={};E[Q6]=E[W6]=E[K6]=E[J6]=E[X6]=E[ew]=E[tw]=E[rw]=E[iw]=!0;E[N6]=E[O6]=E[H6]=E[D6]=E[Z6]=E[P6]=E[z6]=E[U6]=E[R6]=E[F6]=E[V6]=E[B6]=E[G6]=E[q6]=E[Y6]=!1;function nw(e){return Yo(e)&&S6(e.length)&&!!E[Wr(e)]}var ow=nw;function aw(e){return function(t){return e(t)}}var lw=aw,dc=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Gr=dc&&typeof module=="object"&&module&&!module.nodeType&&module,sw=Gr&&Gr.exports===dc,_o=sw&&ac.process,uw=function(){try{var e=Gr&&Gr.require&&Gr.require("util").types;return e||_o&&_o.binding&&_o.binding("util")}catch{}}(),Tu=uw,$u=Tu&&Tu.isTypedArray,tK=$u?lw($u):ow,cw=Object.prototype,rK=cw.hasOwnProperty;function dw(e,t){return function(r){return e(t(r))}}var pw=dw,iK=pw(Object.keys,Object),gw=Object.prototype,nK=gw.hasOwnProperty,fw=pt(Object,"create"),Yr=fw;function hw(){this.__data__=Yr?Yr(null):{},this.size=0}var mw=hw;function yw(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var bw=yw,vw="__lodash_hash_undefined__",ww=Object.prototype,kw=ww.hasOwnProperty;function xw(e){var t=this.__data__;if(Yr){var r=t[e];return r===vw?void 0:r}return kw.call(t,e)?t[e]:void 0}var Iw=xw,Cw=Object.prototype,Aw=Cw.hasOwnProperty;function Mw(e){var t=this.__data__;return Yr?t[e]!==void 0:Aw.call(t,e)}var jw=Mw,Sw="__lodash_hash_undefined__";function Ew(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Yr&&t===void 0?Sw:t,this}var _w=Ew;function gt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}gt.prototype.clear=mw;gt.prototype.delete=bw;gt.prototype.get=Iw;gt.prototype.has=jw;gt.prototype.set=_w;var Nu=gt;function Lw(){this.__data__=[],this.size=0}var Tw=Lw;function $w(e,t){for(var r=e.length;r--;)if(A6(e[r][0],t))return r;return-1}var un=$w,Nw=Array.prototype,Ow=Nw.splice;function Dw(e){var t=this.__data__,r=un(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Ow.call(t,r,1),--this.size,!0}var Pw=Dw;function zw(e){var t=this.__data__,r=un(t,e);return r<0?void 0:t[r][1]}var Uw=zw;function Rw(e){return un(this.__data__,e)>-1}var Fw=Rw;function Vw(e,t){var r=this.__data__,i=un(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var Bw=Vw;function ft(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}ft.prototype.clear=Tw;ft.prototype.delete=Pw;ft.prototype.get=Uw;ft.prototype.has=Fw;ft.prototype.set=Bw;var cn=ft,Gw=pt(Q,"Map"),Hr=Gw;function qw(){this.size=0,this.__data__={hash:new Nu,map:new(Hr||cn),string:new Nu}}var Yw=qw;function Hw(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Zw=Hw;function Qw(e,t){var r=e.__data__;return Zw(t)?r[typeof t=="string"?"string":"hash"]:r.map}var dn=Qw;function Ww(e){var t=dn(this,e).delete(e);return this.size-=t?1:0,t}var Kw=Ww;function Jw(e){return dn(this,e).get(e)}var Xw=Jw;function ek(e){return dn(this,e).has(e)}var tk=ek;function rk(e,t){var r=dn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var ik=rk;function ht(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}ht.prototype.clear=Yw;ht.prototype.delete=Kw;ht.prototype.get=Xw;ht.prototype.has=tk;ht.prototype.set=ik;var pc=ht;function nk(){this.__data__=new cn,this.size=0}var ok=nk;function ak(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var lk=ak;function sk(e){return this.__data__.get(e)}var uk=sk;function ck(e){return this.__data__.has(e)}var dk=ck,pk=200;function gk(e,t){var r=this.__data__;if(r instanceof cn){var i=r.__data__;if(!Hr||i.length<pk-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new pc(i)}return r.set(e,t),this.size=r.size,this}var fk=gk;function Kr(e){var t=this.__data__=new cn(e);this.size=t.size}Kr.prototype.clear=ok;Kr.prototype.delete=lk;Kr.prototype.get=uk;Kr.prototype.has=dk;Kr.prototype.set=fk;var hk=Object.prototype,oK=hk.propertyIsEnumerable,mk=pt(Q,"DataView"),Po=mk,yk=pt(Q,"Promise"),zo=yk,bk=pt(Q,"Set"),Uo=bk,Ou="[object Map]",vk="[object Object]",Du="[object Promise]",Pu="[object Set]",zu="[object WeakMap]",Uu="[object DataView]",wk=Ce(Po),kk=Ce(Hr),xk=Ce(zo),Ik=Ce(Uo),Ck=Ce(Do),lt=Wr;(Po&&lt(new Po(new ArrayBuffer(1)))!=Uu||Hr&&lt(new Hr)!=Ou||zo&&lt(zo.resolve())!=Du||Uo&&lt(new Uo)!=Pu||Do&&lt(new Do)!=zu)&&(lt=function(e){var t=Wr(e),r=t==vk?e.constructor:void 0,i=r?Ce(r):"";if(i)switch(i){case wk:return Uu;case kk:return Ou;case xk:return Du;case Ik:return Pu;case Ck:return zu}return t});var aK=Q.Uint8Array,Ak="__lodash_hash_undefined__";function Mk(e){return this.__data__.set(e,Ak),this}var jk=Mk;function Sk(e){return this.__data__.has(e)}var Ek=Sk;function Ro(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new pc;++t<r;)this.add(e[t])}Ro.prototype.add=Ro.prototype.push=jk;Ro.prototype.has=Ek;var Ru=ct?ct.prototype:void 0,lK=Ru?Ru.valueOf:void 0,_k=Object.prototype,sK=_k.hasOwnProperty,Lk=Object.prototype,uK=Lk.hasOwnProperty,cK=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),dK=new RegExp(/[A-Fa-f0-9]{1}/,"g"),pK=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function gc(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function Tk(e,t){let r=await gc(e,t);return new Promise((i,n)=>{let a=new Image;a.onload=()=>{i({width:a.width,height:a.height})},a.onerror=n,a.src=r})}async function $k(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return gc(i,t)}function Nk(e){return e!==void 0}var Ok=Nk,Fu=class fc{constructor(){this.actions=new Map,this.subscribers=new Map}static get(){let t="__imgly_action_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new fc),r[t]}register(t){return this.actions.set(t.id,t),this.notifySubscribers(t,"registered"),()=>{this.actions.get(t.id)===t&&(this.actions.delete(t.id),this.notifySubscribers(t,"unregistered"))}}getAll(){return Array.from(this.actions.values())}getBy(t){return this.getAll().filter(r=>this.matchesFilters(r,t))}subscribe(t){return this.subscribers.set(t,null),()=>{this.subscribers.delete(t)}}subscribeBy(t,r){return this.subscribers.set(r,t),()=>{this.subscribers.delete(r)}}notifySubscribers(t,r){this.subscribers.forEach((i,n)=>{if(i===null){n(t,r);return}this.matchesFilters(t,i)&&n(t,r)})}matchesFilters(t,r){return!(r.type&&t.type!==r.type||r.pluginId&&t.type==="plugin"&&t.pluginId!==r.pluginId||r.id&&t.id!==r.id||r.kind&&(t.type!=="quick"||t.kind!==r.kind))}},Dk=class hc{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new hc),r[t]}register(t){return this.providers.has(t.provider.id)&&console.warn(`Provider with ID "${t.provider.id}" is already registered`),this.providers.set(t.provider.id,t),()=>{this.providers.get(t.provider.id)===t&&this.providers.delete(t.provider.id)}}getAll(){return Array.from(this.providers.values())}getById(t){return this.providers.get(t)}getByKind(t){return this.getAll().filter(({provider:r})=>r.kind===t)}};function Pk(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=s=>{a.push(s)},l=async(s,c,d)=>{if(s>=t.length)return r(c,d);let p=t[s],g=async(b,m)=>l(s+1,b,m),f={...d,addDisposer:o};return p(c,f,g)},u={...n,addDisposer:o};return{result:await l(0,i,u),dispose:async()=>{for(let s=a.length-1;s>=0;s--)try{await a[s]()}catch(c){console.error("Error in disposer:",c)}a.length=0}}}}function zk({enable:e=!0}){return async(t,r,i)=>{if(!e)return i(t,r);console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(t,null,2));let n,a=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var Uk=zk,Lo="ly.img.ai.temp";async function Rk(e,t){return e.engine.asset.findAllSources().includes(Lo)||e.engine.asset.addLocalSource(Lo),e.engine.asset.apply(Lo,t)}function Fk(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let r=e;return"message"in r&&typeof r.message=="string"?r.message:"cause"in r&&typeof r.cause=="string"?r.cause:"detail"in r&&typeof r.detail=="object"&&r.detail!==null&&"message"in r.detail&&typeof r.detail.message=="string"?r.detail.message:"error"in r&&typeof r.error=="object"&&r.error!==null&&"message"in r.error&&typeof r.error.message=="string"?r.error.message:t}return typeof e=="string"?e:String(e)||t}function mc(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function Vk(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=o.videoWidth,l.height=o.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}u.drawImage(o,0,0,l.width,l.height);try{let s=l.toDataURL(r,i);document.body.removeChild(o),n(s)}catch(s){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function yc(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function Bk(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function Ho(e){return e instanceof Error&&e.name==="AbortError"}function Gk(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function qk(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
145
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
146
+ This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version.
147
+ Consider updating all AI plugins to the same version for optimal compatibility.`),e.ui.experimental.setGlobalStateValue(n,!0))):e.ui.experimental.setGlobalStateValue(i,r)}catch(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}function Yk(e){let{cesdk:t,panelId:r}=e;r.startsWith("ly.img.ai.")||console.warn(`Dock components for AI generation should open a panel with an id starting with "ly.img.ai." \u2013 "${r}" was provided.`);let i=`${r}.dock`;t.ui.registerComponent(i,({builder:n})=>{let a=t.ui.isPanelOpen(r);n.Button(`${r}.dock.button`,{label:`${r}.dock.label`,isSelected:a,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(o=>{o.startsWith("ly.img.ai.")&&t.ui.closePanel(o),!a&&o==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(o)}),a?t.ui.closePanel(r):t.ui.openPanel(r)}})})}var Hk=Yk;function Zk(){return({engine:e})=>{let t=e.block.findAllSelected();if(t==null||t.length!==1)return!1;let[r]=t;if(!e.block.supportsFill(r)||e.block.getKind(r)==="sticker"||!["//ly.img.ubq/graphic","//ly.img.ubq/page"].includes(e.block.getType(r)))return!1;let i=e.block.getFill(r);return e.block.getType(i)==="//ly.img.ubq/fill/image"}}var Qk=Zk;function Wk(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),Kk(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:Fk(e)})}function Kk(e,t,r){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.failed",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"error",message:n,action:a}),!0}var Vu=Wk,Jk="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Zo=Jk;function Xk(e,t,r){switch(t){case"image":return ex(e,r[t]);case"video":return tx(e,r[t]);case"sticker":return rx(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function ex(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Zo,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function tx(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Zo,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function rx(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Zo,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var ix=Xk;async function nx(e,t,r,i){switch(t){case"image":{if(i.kind!=="image")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: image)`);return ox(e,r[t],i)}case"video":{if(i.kind!=="video")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: video)`);return ax(e,r[t],i)}case"audio":{if(i.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: audio)`);return lx(e,r[t],i)}case"sticker":{if(i.kind!=="sticker")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: sticker)`);return sx(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function ox(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}async function ax(e,t,r){let i=t.width,n=t.height,a=await Vk(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:a,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function lx(e,t,r){return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:r.duration.toString()}}}function sx(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}var bc=nx;function ux(e){switch(e.userFlow){case"placeholder":return dx(e);case"generation-only":return cx(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function cx(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(de(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(de(t,r))return{status:"aborted"};if(o.status!=="success")return o;if(o.type==="async")throw new Error("Async generation is not supported in this context yet.");if(de(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let l=mc(),u=await bc(l,n,a,o.output),s={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,s)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function dx(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(de(t,r))return{status:"aborted"};let l=mc(),u=ix(l,a,o);if(i=await Rk(t,u),de(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,p),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let s=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(de(t,r,i))return{status:"aborted"};if(s.status!=="success")return s;if(s.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let c=await bc(l,a,o,s.output);if(de(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(c,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(c,i),de(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),s}catch(a){return i!=null&&t.engine.block.isValid(i)&&(Ho(a)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:a instanceof Error?a.message:String(a)}}}}function de(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var px=ux;function Qo(e){return`${e}.generating`}function gx(e){return`${e}.abort`}function fx(e,t,r,i,n,a,o){let{builder:l,experimental:u}=e,{cesdk:s,includeHistoryLibrary:c=!0}=a,{id:d,output:{abortable:p}}=t,g=u.global(gx(d),()=>{}),f=u.global(Qo(d),!1),b,m=f.value&&p,h=()=>{m&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},x;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let v=i();x=a.requiredInputs.every(y=>!v.input[y])}let w=u.global(`${d}.confirmationDialogId`,void 0);l.Section(`${d}.generate.section`,{children:()=>{l.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:f.value,color:"accent",isDisabled:x,suffix:m?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let v=s.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{s.ui.closeDialog(y),w.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{h(),s.ui.closeDialog(y),w.setValue(void 0)}}});w.setValue(v)}}:void 0,onClick:async()=>{b=new AbortController;let v=b.signal;await(async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),b?.abort()});let y=await px({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:v,cesdk:s,debug:o.debug,dryRun:o.dryRun})(i().input);if(y.status==="aborted")return;if(y.status==="error"){Vu(y.message,{cesdk:s,provider:t,getInput:i});return}if(y.status==="success"&&y.type==="sync"){let k=t.output.notification;hx(s,k,()=>({input:i().input,output:y.output}))}}catch(y){if(Ho(y))return;Vu(y,{cesdk:s,provider:t,getInput:i})}finally{b=void 0,f.setValue(!1),g.setValue(()=>{}),w.value!=null&&(s.ui.closeDialog(w.value),w.setValue(void 0))}})()}}),t.output.generationHintText!=null&&l.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),c&&a.historyAssetLibraryEntryId!=null&&l.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function hx(e,t,r){let i=t?.success;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.success",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"success",message:n,action:a,duration:i.duration}),!0}var vc=fx;async function mx({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,l=r.render;return u=>{let{state:s}=u,c=s(Qo(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=l(u,{cesdk:a,isGenerating:c});return vc(u,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var yx=mx;function wc(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let r=t.substring(2).split("/"),i=e;for(let n of r){if(i==null)throw new Error(`Invalid reference path: ${t}`);i=i[n]}if(i===void 0)throw new Error(`Reference not found: ${t}`);return i}function Br(e,t,r=new Set){if(t==null||r.has(t))return t;if(r.add(t),t.$ref&&typeof t.$ref=="string"){let i=wc(e,t.$ref),n={...Br(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=Br(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>Br(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=Br(e,t[n],r));return i}return t}function bx(e){return Br(e,{...e})}function vx(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let l of i.type)if(typeof l!="string"||!o.includes(l))return r(`Array of types contains invalid value: ${l}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let l=0;l<i[o].length;l++){let u=i[o][l];if(typeof u!="object"||u===null)return r(`Item ${l} in ${o} must be an object, got ${u===null?"null":typeof u}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let l=i.required[o];if(typeof l!="string")return r(`Item ${o} in required array must be a string, got ${typeof l}`)}}return!0}function wx(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return kx(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function kx(e,t){let r=t.order;if(r!=null&&Array.isArray(r))return r;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,n=Object.keys(i),a=xx(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function xx(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let r=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return r==null?void 0:e[r]}var kc=wx;function xc(e,t,r,i,n,a){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let o=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?Ix(e,o,r,i,n,a):Cc(e,o,r,i,n,a);case"boolean":return Ac(e,o,r,i,n,a);case"number":case"integer":return Mc(e,o,r,i,n,a);case"object":return Ic(e,o,r,i,n,a);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return Cx(e,o,r,i,n,a);break}default:console.error(`Unsupported property type: ${l}`)}}function Ic(e,t,r,i,n,a){let o=kc(t.schema??{},i).reduce((l,u)=>{let s=xc(e,u,r,i,n,a);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:o})}function Cc(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),p=Ax(t.schema),g=p?.component!=null&&p?.component==="TextArea"?"TextArea":"TextInput";return o[g](s,{inputLabel:c,placeholder:n.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function Ix(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},p="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},g=(t.schema.enum??[]).map(m=>({id:m,label:d[m]??yc(m),icon:p[m]})),f=t.schema.default!=null?g.find(m=>m.id===t.schema.default)??g[0]:g[0],b=l(s,f);return o.Select(s,{inputLabel:c,values:g,...b}),()=>({id:t.id,type:"string",value:b.value.id})}function Ac(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,p=l(s,d);return o.Checkbox(s,{inputLabel:c,...p}),()=>({id:t.id,type:"boolean",value:p.value})}function Mc(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,p=t.schema.maximum,g=t.schema.default;g==null&&(d!=null?g=d:p!=null?g=p:g=0);let f=l(s,g);if(d!=null&&p!=null){let b=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(b=t.schema["x-imgly-step"]),o.Slider(s,{inputLabel:c,min:d,max:p,step:b,...f})}else o.NumberInput(s,{inputLabel:c,min:d,max:p,...f});return()=>({id:t.id,type:"integer",value:f.value})}function Cx(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],p=[],g={},f={};d.forEach((h,x)=>{let w=h.title??"common.custom",v=`${r.id}.${u}.anyOf[${x}]`,y="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},k="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};h.type==="string"?h.enum!=null?h.enum.forEach(I=>{p.push({id:I,label:y[I]??yc(I),icon:k[I]})}):(g[v]=()=>Cc(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="boolean"?(g[v]=()=>Ac(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="integer"?(g[v]=()=>Mc(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="array"||h.type==="object"&&(g[v]=()=>Ic(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]}))});let b=t.schema.default!=null?p.find(h=>h.id===t.schema.default)??p[0]:p[0],m=l(s,b);if(o.Select(s,{inputLabel:c,values:p,...m}),m.value.id in g){let h=g[m.value.id]();f[m.value.id]=h}return()=>{let h=f[m.value.id];return h!=null?{...h(),id:t.id}:{id:t.id,type:"string",value:m.value.id}}}function Ax(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Mx=xc;async function jx({options:e,provider:t,panelInput:r,config:i},n){let{id:a}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${a}`);let o=bx(r.document),l=wc(o,r.inputReference);if(!vx(l,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=kc(u,r);return c=>{let{builder:d}=c,p=[];d.Section(`${a}.schema.section`,{children:()=>{s.forEach(m=>{let h=Mx(c,m,t,r,e,i);h!=null&&(Array.isArray(h)?p.push(...h):p.push(h))})}});let g=p.map(m=>m()),f=m=>m.type==="object"?Object.entries(m.value).reduce((h,[x,w])=>(h[x]=f(w),h),{}):m.value,b=g.reduce((m,h)=>(m[h.id]=f(h),m),{});vc(c,t,n,()=>({input:b}),()=>r.getBlockInput(b),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var Sx=jx;async function Ex(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return yx(e,t);case"schema":return Sx(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var _x=Ex;function Lx(e){let{provider:t,options:{engine:r}}=e,i=t.output.history??"@imgly/local";if(i==null||i===!1)return;let n=r.asset.findAllSources();function a(){let o=`${t.id}.history`;for(;n.includes(o);)o+=`-${Math.random().toString(36).substring(2,6)}`;return o}if(i==="@imgly/local"){let o=a();return r.asset.addLocalSource(o),o}if(i==="@imgly/indexedDB"){let o=a();return r.asset.addSource(new Nv(o,r)),o}return i}var Tx=Lx;function $x(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history.entry`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var Nx=$x,To="@imgly/plugin-ai-generation",Ox=`
140
148
  <svg>
141
149
  <symbol
142
150
  fill="none"
@@ -154,7 +162,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
154
162
  fill="none"
155
163
  xmlns="http://www.w3.org/2000/svg"
156
164
  viewBox="0 0 24 24"
157
- id="${_r}/image"
165
+ id="${To}/image"
158
166
  >
159
167
  <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
160
168
  <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
@@ -166,7 +174,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
166
174
  fill="none"
167
175
  xmlns="http://www.w3.org/2000/svg"
168
176
  viewBox="0 0 24 24"
169
- id="${_r}/video"
177
+ id="${To}/video"
170
178
  >
171
179
  <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
172
180
  <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
@@ -177,7 +185,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
177
185
  fill="none"
178
186
  xmlns="http://www.w3.org/2000/svg"
179
187
  viewBox="0 0 24 24"
180
- id="${_r}/audio"
188
+ id="${To}/audio"
181
189
  >
182
190
  <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
183
191
  <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
@@ -197,8 +205,11 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
197
205
 
198
206
  </symbol>
199
207
  </svg>
200
- `,Wy=Zy,no="ly.img.ai.quickAction.order",nt="ly.img.ai.quickAction.actions";function Ky(e,t){return{id:t,setQuickActionMenuOrder:n=>{e.ui.experimental.setGlobalStateValue(`${no}.${t}`,n)},getQuickActionMenuOrder:()=>e.ui.experimental.getGlobalStateValue(`${no}.${t}`,[]),registerQuickAction:n=>{if(!e.ui.experimental.hasGlobalStateValue(`${nt}.${t}`))e.ui.experimental.setGlobalStateValue(`${nt}.${t}`,{[n.id]:n});else{let r=e.ui.experimental.getGlobalStateValue(`${nt}.${t}`,{});e.ui.experimental.setGlobalStateValue(`${nt}.${t}`,{...r,[n.id]:n})}},getQuickAction:n=>e.ui.experimental.getGlobalStateValue(`${nt}.${t}`,{})[n]}}var Jy=Ky,Pr="ly.img.ai.inference.editMode",Lo="ly.img.ai.inference.metadata";function To(e){return`ly.img.ai.quickAction.${e.quickActionMenuId}.${e.quickActionId}`}function Xy(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((n,r)=>(r==="ly.img.separator"&&n.length>0&&n[n.length-1]==="ly.img.separator"||n.push(r),n),[])}function e0({alwaysOnTop:e=!0,disableClipping:t=!0}){return async(n,r,a)=>{let o={},i={},l=e||t?r.blockIds??r.engine.block.findAllSelected():[];return l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&(o[u]=r.engine.block.isAlwaysOnTop(u),r.engine.block.setAlwaysOnTop(u,!0)),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&(i[s]=r.engine.block.isClipped(s),r.engine.block.setClipped(s,!1))}}),r.addDisposer(async()=>{l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&r.engine.block.setAlwaysOnTop(u,o[u]),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&i[s]!=null&&r.engine.block.setClipped(s,i[s])}})}),await a(n,r)}}var t0=e0;function r0({pending:e=!0}){return async(t,n,r)=>{let a=e?n.blockIds??n.engine.block.findAllSelected():[];try{return a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Pending",progress:0})}),await r(t,n)}finally{a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Ready"})})}}}var n0=r0;function i0({editMode:e,automaticallyUnlock:t=!1}){return async(n,r,a)=>{let o=r.blockIds??r.engine.block.findAllSelected(),i=()=>{};t||r.addDisposer(async()=>{i?.()});try{return i=o0(r.engine,o,e),await a(n,r)}catch(l){throw me(l)&&i(),l}finally{t&&i()}}}function o0(e,t,n){let r=e.editor.getGlobalScope("editor/select"),a=e.editor.getEditMode();l(),e.editor.setGlobalScope("editor/select","Deny"),e.editor.setEditMode(n);let o=e.editor.createHistory(),i=e.editor.getActiveHistory();e.editor.setActiveHistory(o);function l(){e.block.findAllSelected().forEach(c=>{t.includes(c)||e.block.setSelected(c,!1)}),t.forEach(c=>{e.block.setSelected(c,!0)})}let u=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&e.editor.setEditMode(n)}),s=e.block.onSelectionChanged(l);return()=>{r!=null&&e.editor.setGlobalScope("editor/select",r),e.editor.setEditMode(a),e.editor.setActiveHistory(i),e.editor.destroyHistory(o),s(),u()}}var a0=i0;function l0(e,t){switch(t.kind){case"text":return s0(e,t);case"image":return u0(e,t);case"video":return c0(e,t);case"audio":return d0(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function s0(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t,o=r.map(s=>n.engine.block.getString(s,"text/text")),i;if(Qr(e)){let s="";for await(let c of e){if(a.aborted)break;typeof c=="string"?s=c:c.kind==="text"&&(s=c.text),r.forEach(d=>{n.engine.block.setString(d,"text/text",s)}),i={kind:"text",text:s}}}else i=e;if(i==null||i.kind!=="text")throw new Error("Output kind from generation is not text");let l=()=>{t.blockIds.forEach(s=>{t.cesdk.engine.block.setString(s,"text/text",i.text)})},u=()=>{t.blockIds.forEach((s,c)=>{t.cesdk.engine.block.setString(s,"text/text",o[c])})};return{consumedGenerationResult:i,applyCallbacks:{onBefore:u,onAfter:l,onCancel:u,onApply:()=>{l(),t.cesdk.engine.editor.addUndoStep()}}}}async function u0(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t;if(r.length!==1)throw new Error("Only one block is supported for image generation");let[o]=r,i=n.engine.block.getFill(o),l=n.engine.block.getSourceSet(i,"fill/image/sourceSet"),[u]=l,s;u==null&&(s=n.engine.block.getString(i,"fill/image/imageFileURI"));let c=await n.engine.editor.getMimeType(u?.uri??s),d=await Rr(u?.uri??s,t.cesdk.engine),g=d.width/d.height;if(a.throwIfAborted(),c==="image/svg+xml")throw new Error("SVG images are not supported");let f=n.engine.block.getCropScaleX(o),v=n.engine.block.getCropScaleY(o),w=n.engine.block.getCropTranslationX(o),b=n.engine.block.getCropTranslationY(o),p=n.engine.block.getCropRotation(o),h=()=>{n.engine.block.setCropScaleX(o,f),n.engine.block.setCropScaleY(o,v),n.engine.block.setCropTranslationX(o,w),n.engine.block.setCropTranslationY(o,b),n.engine.block.setCropRotation(o,p)};if(Qr(e))throw new Error("Streaming generation is not supported yet from a panel");if(e.kind!=="image"||typeof e.url!="string")throw new Error("Output kind from generation is not an image");let m=e.url,y=await n.engine.editor.getMimeType(m),k=await g0(n,m,y),C=await Rr(k,t.cesdk.engine),M=C.width/C.height,I=Math.abs(g-M)>.001,x=u?[{uri:k,width:C.width,height:C.height}]:void 0,$=k;x==null?n.engine.block.setString(i,"fill/image/imageFileURI",$):(n.engine.block.setString(i,"fill/image/imageFileURI",""),n.engine.block.setSourceSet(i,"fill/image/sourceSet",x)),I?n.engine.block.setContentFillMode(o,"Cover"):h();let D=()=>{if(l==null||l.length===0){if(s==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",s)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",l);h()},O=()=>{if(x==null){if($==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",$)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",x);I?n.engine.block.setContentFillMode(o,"Cover"):h()};return{consumedGenerationResult:e,applyCallbacks:{onBefore:D,onAfter:O,onCancel:()=>{D()},onApply:()=>{O(),t.cesdk.engine.editor.addUndoStep()}}}}async function c0(e,t){throw new Error("Function not implemented.")}async function d0(e,t){throw new Error("Function not implemented.")}async function g0(e,t,n){let r=await(await fetch(t)).blob(),a=new File([r],`image.${ly(n)}`,{type:n}),o=await e.unstable_upload(a,()=>{});return o?.meta?.uri??(console.warn("Failed to upload image:",o),t)}var p0=l0;function m0({editMode:e,automaticallyUnlock:t=!1,showNotification:n=!0}){return async(r,a,o)=>{let i=a.blockIds??a.engine.block.findAllSelected(),l=()=>{};t||a.addDisposer(async()=>{l?.()});try{l=f0(a.engine,i,e);let u=await o(r,a);if(n){let s=a.engine.block.findAllSelected();i.some(c=>s.includes(c))||a.cesdk?.ui.showNotification({type:"success",message:"AI generation complete",action:{label:"Select",onClick:()=>{i.forEach(c=>{a.engine.block.select(c)})}}})}return u}catch(u){throw me(u)&&l(),u}finally{t&&l()}}}function f0(e,t,n){function r(){let i=e.block.findAllSelected();return t.some(l=>i.includes(l))}let a=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&r()&&e.editor.setEditMode(n)}),o=e.block.onSelectionChanged(()=>{r()?e.editor.setEditMode(n):e.editor.setEditMode("Transform")});return r()&&e.editor.setEditMode(n),()=>{o(),a(),e.editor.setEditMode("Transform")}}var y0=m0;async function b0(e,t){let{cesdk:n,input:r,blockIds:a,provider:o,quickAction:i,confirmationComponentId:l,abortSignal:u}=e;i.confirmation&&n.ui.setCanvasMenuOrder([l],{editMode:Pr});let s=new ao(n.engine,Lo);a.forEach(p=>{s.set(p,{status:"processing",quickActionId:i.id})});let c={cesdk:n,engine:n.engine,abortSignal:u},d=Ao([...o.output.middleware??[],t.debug?So():void 0,n0({}),...i.confirmation?[i.lockDuringConfirmation?a0({editMode:Pr}):y0({editMode:Pr}),i.confirmation&&t0({})]:[],t.dryRun?Eo({kind:o.kind,blockIds:a}):void 0]),{result:g,dispose:f}=await d(o.output.generate)(r,c),{consumedGenerationResult:v,applyCallbacks:w}=await p0(g,{abortSignal:u,kind:o.kind,blockIds:a,cesdk:n});i.confirmation?a.forEach(p=>{s.set(p,{status:"confirmation",quickActionId:i.id})}):(w.onApply(),a.forEach(p=>{s.clear(p)}));let b=()=>{f(),a.forEach(p=>{s.clear(p)})};return u.addEventListener("abort",b),{dispose:b,returnValue:v,applyCallbacks:w}}var io=b0;function h0(e,t){let{cesdk:n,quickActionMenu:r,provider:a}=e,o=`ly.img.ai.${r.id}`,i=`${o}.confirmation`;n.setTranslations({en:{[`${i}.apply`]:"Apply",[`${i}.before`]:"Before",[`${i}.after`]:"After",[`${o}.cancel`]:"Cancel",[`${o}.processing`]:"Generating..."}});let l=`${i}.canvasnMenu`,u={unlock:()=>{},abort:()=>{},applyCallbacks:void 0},s=()=>{let d=new AbortController,g=d.signal;return u.abort=()=>{d.abort()},g};n.ui.registerComponent(l,({builder:d,engine:g,state:f})=>{let v=g.block.findAllSelected();if(v.length===0)return null;let w=new ao(n.engine,Lo),b=w.get(v[0]);if(b==null)return null;let p=()=>{v.forEach(h=>{w.clear(h)})};switch(b.status){case"processing":{d.Button(`${o}.spinner`,{label:[`ly.img.ai.inference.${b.quickActionId}.processing`,`${o}.cancel`],isLoading:!0}),d.Separator(`${o}.separator`),d.Button(`${o}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.abort(),p()}});break}case"confirmation":{let h=f(`${i}.comparing`,"after"),m=u.applyCallbacks?.onCancel;m!=null&&d.Button(`${i}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.unlock(),m(),p()}});let y=u.applyCallbacks?.onBefore,k=u.applyCallbacks?.onAfter;y!=null&&k!=null&&d.ButtonGroup(`${i}.compare`,{children:()=>{d.Button(`${i}.compare.before`,{label:`${i}.before`,variant:"regular",isActive:h.value==="before",onClick:()=>{y(),h.setValue("before")}}),d.Button(`${i}.compare.after`,{label:`${i}.after`,variant:"regular",isActive:h.value==="after",onClick:()=>{k(),h.setValue("after")}})}});let C=u.applyCallbacks?.onApply;C!=null&&d.Button(`${i}.apply`,{icon:"@imgly/Checkmark",tooltip:`${i}.apply`,color:"accent",isDisabled:h.value!=="after",onClick:()=>{u.unlock(),p(),n.engine.editor._update(),C()}});break}default:}});let c=`${o}.canvasMenu`;return n.ui.registerComponent(c,d=>{let g=d.engine.block.findAllSelected(),f=g.every(m=>d.engine.block.getState(m).type==="Ready"),v=r.getQuickActionMenuOrder().map(m=>{if(m==="ly.img.separator")return m;let y=r.getQuickAction(m);if(y==null||!n.feature.isEnabled(To({quickActionId:m,quickActionMenuId:r.id}),{engine:d.engine}))return null;let k=y.scopes;return k!=null&&k.length>0&&!g.every(C=>k.every(M=>d.engine.block.isAllowedByScope(C,M)))?null:y}).filter(m=>m!=null);if(v=Xy(v),v.length===0||v.every(m=>m==="ly.img.separator"))return null;let{builder:w,experimental:b,state:p}=d,h=p(`${o}.toggleExpandedState`,void 0);b.builder.Popover(`${o}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!f,trailingIcon:null,children:({close:m})=>{w.Section(`${o}.popover.section`,{children:()=>{if(h.value!=null){let y=h.value,k=r.getQuickAction(y);if(k!=null&&k.renderExpanded!=null){k.renderExpanded(d,{blockIds:g,closeMenu:m,toggleExpand:()=>{h.setValue(void 0)},handleGenerationError:C=>{ot(C,{cesdk:n,provider:a},t)},generate:async(C,M)=>{try{let{returnValue:I,applyCallbacks:x,dispose:$}=await io({input:C,quickAction:k,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:M?.blockIds??g,confirmationComponentId:l},t);return u.unlock=$,u.applyCallbacks=x,I}catch(I){throw me(I)||ot(I,{cesdk:n,provider:a},t),I}}});return}}b.builder.Menu(`${o}.menu`,{children:()=>{v.forEach(y=>{y==="ly.img.separator"?w.Separator(`${o}.separator.${Math.random().toString()}`):y.render(d,{blockIds:g,closeMenu:m,handleGenerationError:k=>{ot(k,{cesdk:n,provider:a},t)},toggleExpand:()=>{h.setValue(y.id)},generate:async(k,C)=>{try{let{returnValue:M,applyCallbacks:I,dispose:x}=await io({input:k,quickAction:y,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:C?.blockIds??g,confirmationComponentId:l},t);return u.unlock=x,u.applyCallbacks=I,M}catch(M){throw me(M)||ot(M,{cesdk:n,provider:a},t),M}}})})}})}})}})}),{canvasMenuComponentId:c}}var v0=h0;async function k0(e,t,n){await e.initialize?.(t);let r=await C0(t.engine,e.id,e.output.history??"@imgly/local");if(t.cesdk==null)return{};let a=r?`${e.id}.history.entry`:void 0,o={...t,cesdk:t.cesdk,historyAssetSourceId:r,historyAssetLibraryEntryId:a,i18n:{prompt:"common.ai-generation.prompt.placeholder"}};a!=null&&r!=null&&t.cesdk.ui.addAssetLibraryEntry({id:a,sourceIds:[r],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),t.cesdk.i18n.setTranslations({en:{"common.ai-generation.success":"Generation Successful","common.ai-generation.failed":"Generation Failed","common.ai-generation.generate":"Generate","common.ai-generation.prompt.placeholder":"Describe what you want to create...",[`panel.${e.id}`]:w0(e)}});let i="@imgly/plugin-ai-generation.iconSetAdded";return t.cesdk.ui.experimental.hasGlobalStateValue(i)||(t.cesdk.ui.addIconSet("@imgly/plugin-ai-generation",Wy),t.cesdk.ui.experimental.setGlobalStateValue(i,!0)),{renderBuilderFunctions:await M0(e,o,n)}}function w0(e){if(e.name!=null)return e.name;switch(e.kind){case"image":return"Generate Image";case"video":return"Generate Video";case"audio":return"Generate Audio";default:return"Generate Asset"}}async function C0(e,t,n){if(!(n==null||n===!1)){if(n==="@imgly/local"){let r=`${t}.history`;return e.asset.addLocalSource(r),r}if(n==="@imgly/indexedDB"){let r=`${t}.history`;return e.asset.addSource(new sm(r,e)),r}return n}}async function M0(e,t,n){let r={panel:void 0};return e.input?.panel!=null&&(r.panel=await I0(e,e.input.panel,t,n)),e.input?.quickActions!=null&&(n.debug&&console.log(`Initializing quick actions for provider '${e.kind}' (${e.id})`),x0(e,e.input.quickActions,t,n)),r}async function I0(e,t,n,r){switch(t.type){case"custom":return Yy(e,t,n,r);case"schema":return Qy(e,t,n,r);default:r.debug&&console.warn(`Invalid panel input type '${t.type}' - skipping`)}}async function x0(e,t,n,r){let{cesdk:a}=n,o={};t.actions.forEach(i=>{let l=i.kind??e.kind;o[l]==null&&(o[l]=Jy(a,l));let u=o[l],s=i.enable??!0;a.feature.enable(To({quickActionId:i.id,quickActionMenuId:l}),s),u.registerQuickAction(i),r.debug&&console.log(`Registered quick action: '${i.id}' (v${i.version}) to menu '${l}'`)}),Object.values(o).forEach(i=>{let{canvasMenuComponentId:l}=v0({cesdk:a,quickActionMenu:i,provider:e},r);r.debug&&console.log(`Registered quick action menu component: ${l}`)})}var oo=k0;function A0(e){let{cesdk:t,panelId:n}=e;n.startsWith("ly.img.ai/")&&console.warn(`Dock components for AI generation should open a panel with an id starting with "ly.img.ai/" \u2013 "${n}" was provided.`);let r=`${n}.dock`;t.ui.registerComponent(r,({builder:a})=>{let o=t.ui.isPanelOpen(n);a.Button(`${n}.dock.button`,{label:`${n}.dock.label`,isSelected:o,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(i=>{i.startsWith("ly.img.ai/")&&t.ui.closePanel(i),!o&&i==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(i)}),o?t.ui.closePanel(n):t.ui.openPanel(n)}})})}var S0=A0,E0="@imgly/plugin-ai-video-generation-web",P="ly.img.ai/video-generation",zr="ly.img.ai.video-generation.fromType";function j0(e){return{async initialize({cesdk:t}){if(t==null)return;let n={debug:e.debug??!1,dryRun:e.dryRun??!1,middleware:e.middleware};t.setTranslations({en:{[`panel.${P}`]:"Video Generation","ly.img.ai.video-generation.success":"Video Generation Successful","ly.img.ai.video-generation.success.action":"Show"}});let r=e?.text2video,a=e?.image2video,o=await r?.({cesdk:t}),i=await a?.({cesdk:t});function l(c){if(t!=null)return{success:{show:()=>{let d=t?.ui.isPanelOpen(P),g=t.ui.experimental.getGlobalStateValue(zr)===c;return!d||!g},message:"ly.img.ai.video-generation.success",action:{label:"ly.img.ai.video-generation.success.action",onClick:()=>{t.ui.experimental.setGlobalStateValue(zr,c),t.ui.openPanel(P)}},duration:"long"}}}o!=null&&(o.output.notification=l("fromText")),i!=null&&(i.output.notification=l("fromImage"));let u=o!=null?await oo(o,{cesdk:t,engine:t.engine},n):void 0,s=i!=null?await oo(i,{cesdk:t,engine:t.engine},n):void 0;if(u?.renderBuilderFunctions?.panel==null&&s?.renderBuilderFunctions?.panel==null){n.debug&&console.log("No providers are initialized \u2013 doing nothing");return}if(u?.renderBuilderFunctions?.panel!=null&&s?.renderBuilderFunctions?.panel!=null)t.ui.registerPanel(P,c=>{let{builder:d,experimental:g}=c,f=g.global(zr,"fromText");switch(d.Section(`${P}.fromType.section`,{children:()=>{d.ButtonGroup(`${P}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{d.Button(`${P}.fromType.buttonGroup.fromText`,{label:"Text",icon:f.value!=="fromText"&&o!=null&&g.global(Qt(o.id),!1).value?"@imgly/LoadingSpinner":void 0,isActive:f.value==="fromText",onClick:()=>{f.setValue("fromText")}}),d.Button(`${P}.fromType.buttonGroup.fromImage`,{label:"Image",icon:f.value!=="fromImage"&&i!=null&&g.global(Qt(i.id),!1).value?"@imgly/LoadingSpinner":void 0,isActive:f.value==="fromImage",onClick:()=>{f.setValue("fromImage")}})}})}}),f.value){case"fromText":{u?.renderBuilderFunctions?.panel?.(c);break}case"fromImage":{s?.renderBuilderFunctions?.panel?.(c);break}default:}});else{let c=u?.renderBuilderFunctions?.panel??s?.renderBuilderFunctions?.panel;if(c==null)return;t.ui.registerPanel(P,c),t.i18n.setTranslations({en:{[`${P}.dock.label`]:"AI Video"}}),S0({cesdk:t,panelId:P})}}}}var L0=j0,T0=e=>({name:E0,version:"0.1.9",...L0(e)}),$o=T0;var $0=class{constructor(e,t,n){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=n?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=n?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let n=indexedDB.open(this.dbName,this.dbVersion);n.onerror=r=>{t(new Error(`Failed to open IndexedDB: ${r.target.error}`))},n.onupgradeneeded=r=>{let a=r.target.result;a.objectStoreNames.contains(this.assetStoreName)||a.createObjectStore(this.assetStoreName,{keyPath:"id"}),a.objectStoreNames.contains(this.blobStoreName)||a.createObjectStore(this.blobStoreName,{keyPath:"id"})},n.onsuccess=r=>{this.db=r.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",g=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(g=s.tags[c]);let f={...s,label:d,tags:g};return this.filterAsset(f,e)&&u.push(f),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:n,perPage:r}=e,a=n*r,o=a+r,i=t.slice(a,o),l=o<t.length?n+1:void 0;return{assets:i,currentPage:n,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let n=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();n.onsuccess=()=>{let r=new Set;n.result.forEach(o=>{o.groups&&Array.isArray(o.groups)&&o.groups.forEach(i=>r.add(i))});let a=[...r];e(a)},n.onerror=()=>{t(new Error(`Failed to get groups: ${n.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),n=t.objectStore(this.assetStoreName),r=new Set;ke(e,o=>{r.add(o)}),setTimeout(()=>{this.storeBlobUrls([...r])});let a={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};n.put(a),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.assetStoreName,"readwrite");n.objectStore(this.assetStoreName).delete(e),n.oncomplete=()=>{ke(t,r=>{this.removeBlob(r)}),this.engine.asset.assetSourceContentsChanged(this.id)},n.onerror=()=>{console.error(`Failed to remove asset: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let a=r.result;a.sort((o,i)=>{let l=o.meta?.insertedAt||o._insertedAt||Date.now(),u=i.meta?.insertedAt||i._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(a)},r.onerror=()=>{n(new Error(`Failed to get assets: ${r.error}`))}})}async getAsset(e){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async getBlob(e){return new Promise((t,n)=>{let r=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async n=>{let r=await(await fetch(n)).blob();t[n]=r})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.blobStoreName,"readwrite"),r=n.objectStore(this.blobStoreName);Object.entries(t).forEach(([a,o])=>{let i={id:a,blob:o};r.put(i)}),n.onerror=()=>{console.error(`Failed to add blobs: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async restoreBlobUrls(e){let t={},n=new Set;return ke(e,r=>{n.add(r)}),await Promise.all([...n].map(async r=>{let a=await this.createBlobUrlFromStore(r);t[r]=a})),ke(e,r=>t[r]??r)}filterAsset(e,t){let{query:n,tags:r,groups:a,excludeGroups:o}=t;if(n&&n.trim()!==""){let i=n.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!i.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(r){let i=Array.isArray(r)?r:[r];if(i.length>0&&(!e.tags||!i.every(l=>e.tags?.includes(l))))return!1}return!(a&&a.length>0&&(!e.groups||!a.some(i=>e.groups?.includes(i)))||o&&o.length>0&&e.groups&&e.groups.some(i=>o.includes(i)))}sortAssets(e,t){let{sortingOrder:n,sortKey:r,sortActiveFirst:a}=t,o=[...e];return!n||n==="None"||(r?o.sort((i,l)=>{let u,s;return r==="id"?(u=i.id,s=l.id):(u=i.meta?.[r]??null,s=l.meta?.[r]??null),u==null?n==="Ascending"?-1:1:s==null?n==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?n==="Ascending"?u.localeCompare(s):s.localeCompare(u):n==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):n==="Descending"&&o.reverse(),a&&o.sort((i,l)=>i.active&&!l.active?-1:!i.active&&l.active?1:0)),o}};function ke(e,t,n=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let r=0;r<e.length;r++){let a=n?`${n}[${r}]`:`[${r}]`;if(typeof e[r]=="string"&&e[r].startsWith("blob:")){let o=t(e[r],a);typeof o=="string"&&(e[r]=o)}else e[r]=ke(e[r],t,a)}return e}for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)){let a=e[r],o=n?`${n}.${r}`:r;if(typeof a=="string"&&a.startsWith("blob:")){let i=t(a,o);typeof i=="string"&&(e[r]=i)}else e[r]=ke(a,t,o)}return e}var N0=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},Ko=N0,D0=typeof global=="object"&&global&&global.Object===Object&&global,Jo=D0,O0=typeof self=="object"&&self&&self.Object===Object&&self,_0=Jo||O0||Function("return this")(),B=_0,P0=B.Symbol,we=P0,Xo=Object.prototype,z0=Xo.hasOwnProperty,U0=Xo.toString,dt=we?we.toStringTag:void 0;function V0(e){var t=z0.call(e,dt),n=e[dt];try{e[dt]=void 0;var r=!0}catch{}var a=U0.call(e);return r&&(t?e[dt]=n:delete e[dt]),a}var B0=V0,F0=Object.prototype,G0=F0.toString;function R0(e){return G0.call(e)}var q0=R0,Q0="[object Null]",H0="[object Undefined]",No=we?we.toStringTag:void 0;function Y0(e){return e==null?e===void 0?H0:Q0:No&&No in Object(e)?B0(e):q0(e)}var vt=Y0;function Z0(e){return e!=null&&typeof e=="object"}var on=Z0,AC=Array.isArray;function W0(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var ea=W0,K0="[object AsyncFunction]",J0="[object Function]",X0="[object GeneratorFunction]",eb="[object Proxy]";function tb(e){if(!ea(e))return!1;var t=vt(e);return t==J0||t==X0||t==K0||t==eb}var rb=tb,nb=B["__core-js_shared__"],Hr=nb,Do=function(){var e=/[^.]+$/.exec(Hr&&Hr.keys&&Hr.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function ib(e){return!!Do&&Do in e}var ob=ib,ab=Function.prototype,lb=ab.toString;function sb(e){if(e!=null){try{return lb.call(e)}catch{}try{return e+""}catch{}}return""}var H=sb,ub=/[\\^$.*+?()[\]{}|]/g,cb=/^\[object .+?Constructor\]$/,db=Function.prototype,gb=Object.prototype,pb=db.toString,mb=gb.hasOwnProperty,fb=RegExp("^"+pb.call(mb).replace(ub,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function yb(e){if(!ea(e)||ob(e))return!1;var t=rb(e)?fb:cb;return t.test(H(e))}var bb=yb;function hb(e,t){return e?.[t]}var vb=hb;function kb(e,t){var n=vb(e,t);return bb(n)?n:void 0}var Me=kb,wb=Me(B,"WeakMap"),Jr=wb;function Cb(e,t){return e===t||e!==e&&t!==t}var Mb=Cb,Ib=9007199254740991;function xb(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Ib}var Ab=xb,SC=Object.prototype,Sb="[object Arguments]";function Eb(e){return on(e)&&vt(e)==Sb}var Oo=Eb,ta=Object.prototype,jb=ta.hasOwnProperty,Lb=ta.propertyIsEnumerable,EC=Oo(function(){return arguments}())?Oo:function(e){return on(e)&&jb.call(e,"callee")&&!Lb.call(e,"callee")},ra=typeof exports=="object"&&exports&&!exports.nodeType&&exports,_o=ra&&typeof module=="object"&&module&&!module.nodeType&&module,Tb=_o&&_o.exports===ra,Po=Tb?B.Buffer:void 0,jC=Po?Po.isBuffer:void 0,$b="[object Arguments]",Nb="[object Array]",Db="[object Boolean]",Ob="[object Date]",_b="[object Error]",Pb="[object Function]",zb="[object Map]",Ub="[object Number]",Vb="[object Object]",Bb="[object RegExp]",Fb="[object Set]",Gb="[object String]",Rb="[object WeakMap]",qb="[object ArrayBuffer]",Qb="[object DataView]",Hb="[object Float32Array]",Yb="[object Float64Array]",Zb="[object Int8Array]",Wb="[object Int16Array]",Kb="[object Int32Array]",Jb="[object Uint8Array]",Xb="[object Uint8ClampedArray]",eh="[object Uint16Array]",th="[object Uint32Array]",j={};j[Hb]=j[Yb]=j[Zb]=j[Wb]=j[Kb]=j[Jb]=j[Xb]=j[eh]=j[th]=!0;j[$b]=j[Nb]=j[qb]=j[Db]=j[Qb]=j[Ob]=j[_b]=j[Pb]=j[zb]=j[Ub]=j[Vb]=j[Bb]=j[Fb]=j[Gb]=j[Rb]=!1;function rh(e){return on(e)&&Ab(e.length)&&!!j[vt(e)]}var nh=rh;function ih(e){return function(t){return e(t)}}var oh=ih,na=typeof exports=="object"&&exports&&!exports.nodeType&&exports,yt=na&&typeof module=="object"&&module&&!module.nodeType&&module,ah=yt&&yt.exports===na,Yr=ah&&Jo.process,lh=function(){try{var e=yt&&yt.require&&yt.require("util").types;return e||Yr&&Yr.binding&&Yr.binding("util")}catch{}}(),zo=lh,Uo=zo&&zo.isTypedArray,LC=Uo?oh(Uo):nh,sh=Object.prototype,TC=sh.hasOwnProperty;function uh(e,t){return function(n){return e(t(n))}}var ch=uh,$C=ch(Object.keys,Object),dh=Object.prototype,NC=dh.hasOwnProperty,gh=Me(Object,"create"),bt=gh;function ph(){this.__data__=bt?bt(null):{},this.size=0}var mh=ph;function fh(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var yh=fh,bh="__lodash_hash_undefined__",hh=Object.prototype,vh=hh.hasOwnProperty;function kh(e){var t=this.__data__;if(bt){var n=t[e];return n===bh?void 0:n}return vh.call(t,e)?t[e]:void 0}var wh=kh,Ch=Object.prototype,Mh=Ch.hasOwnProperty;function Ih(e){var t=this.__data__;return bt?t[e]!==void 0:Mh.call(t,e)}var xh=Ih,Ah="__lodash_hash_undefined__";function Sh(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=bt&&t===void 0?Ah:t,this}var Eh=Sh;function Ie(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ie.prototype.clear=mh;Ie.prototype.delete=yh;Ie.prototype.get=wh;Ie.prototype.has=xh;Ie.prototype.set=Eh;var Vo=Ie;function jh(){this.__data__=[],this.size=0}var Lh=jh;function Th(e,t){for(var n=e.length;n--;)if(Mb(e[n][0],t))return n;return-1}var Jt=Th,$h=Array.prototype,Nh=$h.splice;function Dh(e){var t=this.__data__,n=Jt(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():Nh.call(t,n,1),--this.size,!0}var Oh=Dh;function _h(e){var t=this.__data__,n=Jt(t,e);return n<0?void 0:t[n][1]}var Ph=_h;function zh(e){return Jt(this.__data__,e)>-1}var Uh=zh;function Vh(e,t){var n=this.__data__,r=Jt(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var Bh=Vh;function xe(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}xe.prototype.clear=Lh;xe.prototype.delete=Oh;xe.prototype.get=Ph;xe.prototype.has=Uh;xe.prototype.set=Bh;var Xt=xe,Fh=Me(B,"Map"),ht=Fh;function Gh(){this.size=0,this.__data__={hash:new Vo,map:new(ht||Xt),string:new Vo}}var Rh=Gh;function qh(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Qh=qh;function Hh(e,t){var n=e.__data__;return Qh(t)?n[typeof t=="string"?"string":"hash"]:n.map}var er=Hh;function Yh(e){var t=er(this,e).delete(e);return this.size-=t?1:0,t}var Zh=Yh;function Wh(e){return er(this,e).get(e)}var Kh=Wh;function Jh(e){return er(this,e).has(e)}var Xh=Jh;function e4(e,t){var n=er(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var t4=e4;function Ae(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ae.prototype.clear=Rh;Ae.prototype.delete=Zh;Ae.prototype.get=Kh;Ae.prototype.has=Xh;Ae.prototype.set=t4;var ia=Ae;function r4(){this.__data__=new Xt,this.size=0}var n4=r4;function i4(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var o4=i4;function a4(e){return this.__data__.get(e)}var l4=a4;function s4(e){return this.__data__.has(e)}var u4=s4,c4=200;function d4(e,t){var n=this.__data__;if(n instanceof Xt){var r=n.__data__;if(!ht||r.length<c4-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new ia(r)}return n.set(e,t),this.size=n.size,this}var g4=d4;function kt(e){var t=this.__data__=new Xt(e);this.size=t.size}kt.prototype.clear=n4;kt.prototype.delete=o4;kt.prototype.get=l4;kt.prototype.has=u4;kt.prototype.set=g4;var p4=Object.prototype,DC=p4.propertyIsEnumerable,m4=Me(B,"DataView"),Xr=m4,f4=Me(B,"Promise"),en=f4,y4=Me(B,"Set"),tn=y4,Bo="[object Map]",b4="[object Object]",Fo="[object Promise]",Go="[object Set]",Ro="[object WeakMap]",qo="[object DataView]",h4=H(Xr),v4=H(ht),k4=H(en),w4=H(tn),C4=H(Jr),ve=vt;(Xr&&ve(new Xr(new ArrayBuffer(1)))!=qo||ht&&ve(new ht)!=Bo||en&&ve(en.resolve())!=Fo||tn&&ve(new tn)!=Go||Jr&&ve(new Jr)!=Ro)&&(ve=function(e){var t=vt(e),n=t==b4?e.constructor:void 0,r=n?H(n):"";if(r)switch(r){case h4:return qo;case v4:return Bo;case k4:return Fo;case w4:return Go;case C4:return Ro}return t});var OC=B.Uint8Array,M4="__lodash_hash_undefined__";function I4(e){return this.__data__.set(e,M4),this}var x4=I4;function A4(e){return this.__data__.has(e)}var S4=A4;function rn(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new ia;++t<n;)this.add(e[t])}rn.prototype.add=rn.prototype.push=x4;rn.prototype.has=S4;var Qo=we?we.prototype:void 0,_C=Qo?Qo.valueOf:void 0,E4=Object.prototype,PC=E4.hasOwnProperty,j4=Object.prototype,zC=j4.hasOwnProperty,UC=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),VC=new RegExp(/[A-Fa-f0-9]{1}/,"g"),BC=new RegExp(/[A-Fa-f0-9]{2}/,"g");function L4(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function oa(e,t){if(e.startsWith("buffer:")){let n=await t.editor.getMimeType(e),r=t.editor.getBufferLength(e),a=t.editor.getBufferData(e,0,r),o=new Blob([a],{type:n});return URL.createObjectURL(o)}else return e}async function nn(e,t){let n=await oa(e,t);return new Promise((r,a)=>{let o=new Image;o.onload=()=>{r({width:o.width,height:o.height})},o.onerror=a,o.src=n})}async function T4(e,t,n){let r,a=t.block.getFill(e),o=t.block.getSourceSet(a,"fill/image/sourceSet"),[i]=o;if(i==null){if(r=t.block.getString(a,"fill/image/imageFileURI"),r==null)throw new Error("No image source/uri found")}else r=i.uri;if(n?.throwErrorIfSvg&&await t.editor.getMimeType(r)==="image/svg+xml")throw new Error("SVG images are not supported");return oa(r,t)}function aa(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let n=t.substring(2).split("/"),r=e;for(let a of n){if(r==null)throw new Error(`Invalid reference path: ${t}`);r=r[a]}if(r===void 0)throw new Error(`Reference not found: ${t}`);return r}function mt(e,t,n=new Set){if(t==null||n.has(t))return t;if(n.add(t),t.$ref&&typeof t.$ref=="string"){let r=aa(e,t.$ref),a={...mt(e,r,n)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(a[o]=mt(e,t[o],n));return a}if(Array.isArray(t))return t.map(r=>mt(e,r,n));if(typeof t=="object"){let r={};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=mt(e,t[a],n));return r}return t}function $4(e){return mt(e,{...e})}function N4(e,t=!1){let n=i=>(t&&console.log(`OpenAPI Schema validation failed: ${i}`),!1);if(typeof e!="object"||e===null)return n(`Input is ${e===null?"null":typeof e}, not an object`);let r=e;if(!(typeof r.type=="string"||Array.isArray(r.enum)||typeof r.properties=="object"||typeof r.items=="object"||typeof r.allOf=="object"||typeof r.anyOf=="object"||typeof r.oneOf=="object"||typeof r.not=="object"))return n("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(r.type!==void 0){let i=["string","number","integer","boolean","array","object","null"];if(typeof r.type=="string"){if(!i.includes(r.type))return n(`Invalid type: ${r.type}. Must be one of ${i.join(", ")}`)}else if(Array.isArray(r.type)){for(let l of r.type)if(typeof l!="string"||!i.includes(l))return n(`Array of types contains invalid value: ${l}. Must be one of ${i.join(", ")}`)}else return n(`Type must be a string or array of strings, got ${typeof r.type}`)}if(r.items!==void 0&&(typeof r.items!="object"||r.items===null))return n(`Items must be an object, got ${r.items===null?"null":typeof r.items}`);if(r.properties!==void 0&&(typeof r.properties!="object"||r.properties===null))return n(`Properties must be an object, got ${r.properties===null?"null":typeof r.properties}`);let a=["allOf","anyOf","oneOf"];for(let i of a)if(r[i]!==void 0){if(!Array.isArray(r[i]))return n(`${i} must be an array, got ${typeof r[i]}`);for(let l=0;l<r[i].length;l++){let u=r[i][l];if(typeof u!="object"||u===null)return n(`Item ${l} in ${i} must be an object, got ${u===null?"null":typeof u}`)}}if(r.not!==void 0&&(typeof r.not!="object"||r.not===null))return n(`'not' must be an object, got ${r.not===null?"null":typeof r.not}`);if(r.additionalProperties!==void 0&&typeof r.additionalProperties!="boolean"&&(typeof r.additionalProperties!="object"||r.additionalProperties===null))return n(`additionalProperties must be a boolean or an object, got ${r.additionalProperties===null?"null":typeof r.additionalProperties}`);if(r.format!==void 0&&typeof r.format!="string")return n(`format must be a string, got ${typeof r.format}`);let o=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let i of o)if(r[i]!==void 0&&typeof r[i]!="number")return n(`${i} must be a number, got ${typeof r[i]}`);if(r.minLength!==void 0&&(typeof r.minLength!="number"||r.minLength<0))return n(`minLength must be a non-negative number, got ${typeof r.minLength=="number"?r.minLength:typeof r.minLength}`);if(r.maxLength!==void 0&&(typeof r.maxLength!="number"||r.maxLength<0))return n(`maxLength must be a non-negative number, got ${typeof r.maxLength=="number"?r.maxLength:typeof r.maxLength}`);if(r.pattern!==void 0&&typeof r.pattern!="string")return n(`pattern must be a string, got ${typeof r.pattern}`);if(r.minItems!==void 0&&(typeof r.minItems!="number"||r.minItems<0))return n(`minItems must be a non-negative number, got ${typeof r.minItems=="number"?r.minItems:typeof r.minItems}`);if(r.maxItems!==void 0&&(typeof r.maxItems!="number"||r.maxItems<0))return n(`maxItems must be a non-negative number, got ${typeof r.maxItems=="number"?r.maxItems:typeof r.maxItems}`);if(r.uniqueItems!==void 0&&typeof r.uniqueItems!="boolean")return n(`uniqueItems must be a boolean, got ${typeof r.uniqueItems}`);if(r.minProperties!==void 0&&(typeof r.minProperties!="number"||r.minProperties<0))return n(`minProperties must be a non-negative number, got ${typeof r.minProperties=="number"?r.minProperties:typeof r.minProperties}`);if(r.maxProperties!==void 0&&(typeof r.maxProperties!="number"||r.maxProperties<0))return n(`maxProperties must be a non-negative number, got ${typeof r.maxProperties=="number"?r.maxProperties:typeof r.maxProperties}`);if(r.required!==void 0){if(!Array.isArray(r.required))return n(`required must be an array, got ${typeof r.required}`);for(let i=0;i<r.required.length;i++){let l=r.required[i];if(typeof l!="string")return n(`Item ${i} in required array must be a string, got ${typeof l}`)}}return!0}function D4(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let n=e.properties,r=[];return O4(e,t).forEach(a=>{let o=a,i=n[a]??void 0;r.push({id:o,schema:i})}),r}function O4(e,t){let n=t.order;if(n!=null&&Array.isArray(n))return n;if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,a=Object.keys(r),o=_4(e,t)??a;return n!=null&&typeof n=="function"&&(o=n(o)),[...new Set(o)]}function _4(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let n=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(r=>r in e);return n==null?void 0:e[n]}var la=D4,P4="ly.img.ai",Zr="ly.img.ai/temp";async function z4(e,t){return e.engine.asset.findAllSources().includes(Zr)||e.engine.asset.addLocalSource(Zr),e.engine.asset.apply(Zr,t)}function sa(e){return`${P4}/${e}`}function U4(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let n=e;return"message"in n&&typeof n.message=="string"?n.message:"cause"in n&&typeof n.cause=="string"?n.cause:"detail"in n&&typeof n.detail=="object"&&n.detail!==null&&"message"in n.detail&&typeof n.detail.message=="string"?n.detail.message:"error"in n&&typeof n.error=="object"&&n.error!==null&&"message"in n.error&&typeof n.error.message=="string"?n.error.message:t}return typeof e=="string"?e:String(e)||t}function V4(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function B4(e,t=0,n="image/jpeg",r=.8){return new Promise((a,o)=>{try{let i=document.createElement("video");i.crossOrigin="anonymous",i.style.display="none",i.addEventListener("loadedmetadata",()=>{i.currentTime=Math.min(t,i.duration),i.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=i.videoWidth,l.height=i.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(i),o(new Error("Failed to create canvas context"));return}u.drawImage(i,0,0,l.width,l.height);try{let s=l.toDataURL(n,r);document.body.removeChild(i),a(s)}catch(s){document.body.removeChild(i),o(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),i.addEventListener("error",()=>{document.body.removeChild(i),o(new Error(`Failed to load video from ${e}`))}),i.src=e,document.body.appendChild(i)}catch(i){o(i)}})}function ua(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function an(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function Ce(e){return e instanceof Error&&e.name==="AbortError"}function ca(e,t,n,r,a,o){if(t.schema==null)return r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null?r.renderCustomProperty[t.id](e,t):void 0;let i=t,l=t.schema.type;if(r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null)return r.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?F4(e,i,n,r,a,o):ga(e,i,n,r,a,o);case"boolean":return pa(e,i,n,r,a,o);case"number":case"integer":return ma(e,i,n,r,a,o);case"object":return da(e,i,n,r,a,o);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return G4(e,i,n,r,a,o);break}default:console.error(`Unsupported property type: ${l}`)}}function da(e,t,n,r,a,o){let i=la(t.schema??{},r).reduce((l,u)=>{let s=ca(e,u,n,r,a,o);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:i})}function ga(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),g=R4(t.schema),f=g?.component!=null&&g?.component==="TextArea"?"TextArea":"TextInput";return i[f](s,{inputLabel:c,placeholder:a.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function F4(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},g="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},f=(t.schema.enum??[]).map(b=>({id:b,label:d[b]??ua(b),icon:g[b]})),v=t.schema.default!=null?f.find(b=>b.id===t.schema.default)??f[0]:f[0],w=l(s,v);return i.Select(s,{inputLabel:c,values:f,...w}),()=>({id:t.id,type:"string",value:w.value.id})}function pa(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,g=l(s,d);return i.Checkbox(s,{inputLabel:c,...g}),()=>({id:t.id,type:"boolean",value:g.value})}function ma(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,g=t.schema.maximum,f=t.schema.default;f==null&&(d!=null?f=d:g!=null?f=g:f=0);let v=l(s,f);if(d!=null&&g!=null){let w=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(w=t.schema["x-imgly-step"]),i.Slider(s,{inputLabel:c,min:d,max:g,step:w,...v})}else i.NumberInput(s,{inputLabel:c,min:d,max:g,...v});return()=>({id:t.id,type:"integer",value:v.value})}function G4(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],g=[],f={},v={};d.forEach((p,h)=>{let m=p.title??"common.custom",y=`${n.id}.${u}.anyOf[${h}]`,k="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},C="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};p.type==="string"?p.enum!=null?p.enum.forEach(M=>{g.push({id:M,label:k[M]??ua(M),icon:C[M]})}):(f[y]=()=>ga(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="boolean"?(f[y]=()=>pa(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="integer"?(f[y]=()=>ma(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="array"||p.type==="object"&&(f[y]=()=>da(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]}))});let w=t.schema.default!=null?g.find(p=>p.id===t.schema.default)??g[0]:g[0],b=l(s,w);if(i.Select(s,{inputLabel:c,values:g,...b}),b.value.id in f){let p=f[b.value.id]();v[b.value.id]=p}return()=>{let p=v[b.value.id];return p!=null?{...p(),id:t.id}:{id:t.id,type:"string",value:b.value.id}}}function R4(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var q4=ca,Q4="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",fa=Q4;function H4(e,t,n){switch(t){case"image":return Y4(e,n[t]);case"video":return Z4(e,n[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Y4(e,t){let n=t.width,r=t.height;return{id:e,meta:{previewUri:fa,fillType:"//ly.img.ubq/fill/image",kind:"image",width:n,height:r}}}function Z4(e,t){let n=t.width,r=t.height;return{id:e,label:t.label,meta:{previewUri:fa,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:n,height:r}}}var W4=H4;async function K4(e,t,n,r){switch(t){case"image":{if(r.kind!=="image")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: image)`);return J4(e,n[t],r)}case"video":{if(r.kind!=="video")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: video)`);return X4(e,n[t],r)}case"audio":{if(r.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: audio)`);return e5(e,n[t],r)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function J4(e,t,n){let r=t.width,a=t.height;return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:a},payload:{sourceSet:[{uri:n.url,width:r,height:a}]}}}async function X4(e,t,n){let r=t.width,a=t.height,o=await B4(n.url,0);return{id:e,label:t.label,meta:{uri:n.url,thumbUri:o,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:a}}}function e5(e,t,n){return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:n.duration.toString()}}}var Ho=K4;function ya(e){let t=e.filter(n=>!!n);return n=>async(r,a)=>{let o=[],i=s=>{o.push(s)},l=async(s,c,d)=>{if(s>=t.length)return n(c,d);let g=t[s],f=async(w,b)=>l(s+1,w,b),v={...d,addDisposer:i};return g(c,v,f)},u={...a,addDisposer:i};return{result:await l(0,r,u),dispose:async()=>{for(let s=o.length-1;s>=0;s--)try{await o[s]()}catch(c){console.error("Error in disposer:",c)}o.length=0}}}}function t5(){return async(e,t,n)=>{console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(e,null,2));let r,a=Date.now();try{return r=await n(e,t),r}finally{r!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(r,null,2))),console.groupEnd()}}}var ba=t5;function r5(e){return async(t,n)=>(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await a5(2e3),await n5(t,e,n))}async function n5(e,t,n){switch(t.kind){case"image":return i5(e,t,n);case"video":return o5(e,t,n);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function i5(e,t,{engine:n}){let r,a,o=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",i=o.match(/(\d+)x(\d+)/);if(i!=null)r=parseInt(i[1],10),a=parseInt(i[2],10);else if(t.blockInputs!=null&&(r=t.blockInputs.image.width,a=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await T4(l,n),s=await nn(u,n);r=s.width,a=s.height}else r=512,a=512;return{kind:"image",url:`https://placehold.co/${r}x${a}/000000/FFF?text=${o.replace(" ","+").replace(`
201
- `,"+")}`}}async function o5(e,t,n){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function a5(e){return new Promise(t=>{setTimeout(t,e)})}var ha=r5;async function l5(e,t,n,r,a,o,i){let{cesdk:l,createPlaceholderBlock:u,historyAssetSourceId:s}=a,c;try{o.debug&&console.group(`Starting Generation for '${e}'`);let d=t(),g=await n(d.input),f=V4(),v;if(u){if(v=W4(f,e,g),o.debug&&console.log("Adding as asset to scene:",JSON.stringify(v,void 0,2)),c=await z4(l,v),c!=null&&r.kind==="video"){let h=l.engine.block.getPositionX(c),m=l.engine.block.getPositionY(c),y=l.engine.block.duplicate(c);l.engine.block.setPositionX(y,h),l.engine.block.setPositionY(y,m),l.engine.block.destroy(c),c=y}if(Wt(l,i,c))return{status:"aborted"};if(c==null)throw new Error("Could not create placeholder block");l.engine.block.setState(c,{type:"Pending",progress:0})}let w=ya([...r.output.middleware??[],o.debug?ba():void 0,o.dryRun?ha({kind:r.kind,blockInputs:g}):void 0]),{result:b}=await w(r.output.generate)(d.input,{abortSignal:i,engine:a.engine,cesdk:l});if(an(b))throw new Error("Streaming generation is not supported yet from a panel");if(Wt(l,i,c))return{status:"aborted"};if(b==null)throw new Error("Generation failed");o.debug&&console.log("Generated output:",JSON.stringify(b,void 0,2));let p;if(c!=null&&l.engine.block.isValid(c)&&(p=await Ho(f,e,g,b),o.debug&&console.log("Updating asset in scene:",JSON.stringify(p,void 0,2)),await l.engine.asset.defaultApplyAssetToBlock(p,c)),Wt(l,i,c))return{status:"aborted"};if(s!=null){if(p==null&&(p=await Ho(f,e,g,b),Wt(l,i,c)))return{status:"aborted"};let h={...p,id:`${Date.now()}-${p.id}`,label:p.label!=null?{en:p.label}:{},tags:{}};l.engine.asset.addAssetToSource(s,h)}return c!=null&&l.engine.block.isValid(c)&&l.engine.block.setState(c,{type:"Ready"}),{status:"success",output:b}}catch(d){throw c!=null&&l.engine.block.isValid(c)&&(Ce(d)?l.engine.block.destroy(c):l.engine.block.setState(c,{type:"Error",error:"Unknown"})),d}finally{o.debug&&console.groupEnd()}}function Wt(e,t,n){return t.aborted?(n!=null&&e.engine.block.isValid(n)&&e.engine.block.destroy(n),!0):!1}var s5=l5;function u5(e,t,n){let{cesdk:r,provider:a,getInput:o}=t;n.onError!=null&&typeof n.onError=="function"?n.onError(e):(console.error("Generation failed:",e),c5(r,a.output.notification,()=>({input:o?.().input,error:e}))||r.ui.showNotification({type:"error",message:U4(e)}))}function c5(e,t,n){let r=t?.error;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.failed",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"error",message:a,action:o}),!0}var ft=u5;function va(e){return`${e}.generating`}function d5(e){return`${e}.abort`}function g5(e,t,n,r,a,o){let{builder:i,experimental:l}=e,{cesdk:u,includeHistoryLibrary:s=!0}=a,{id:c,output:{abortable:d}}=t,g=l.global(d5(c),()=>{}),f=l.global(va(c),!1),v,w=f.value&&d,b=()=>{w&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},p;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let m=n();p=a.requiredInputs.every(y=>!m.input[y])}let h=l.global(`${c}.confirmationDialogId`,void 0);i.Section(`${c}.generate.section`,{children:()=>{i.Button(`${c}.generate`,{label:["common.ai-generation.generate",`panel.${c}.generate`],isLoading:f.value,color:"accent",isDisabled:p,suffix:w?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${c}.abort`,"common.cancel"],onClick:()=>{let m=u.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{u.ui.closeDialog(y),h.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{b(),u.ui.closeDialog(y),h.setValue(void 0)}}});h.setValue(m)}}:void 0,onClick:async()=>{v=new AbortController;let m=v.signal,y=async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),v?.abort()});let k=await s5(t.kind,n,r,t,a,o,m);if(k.status==="aborted")return;let C=t.output.notification;p5(u,C,()=>({input:n().input,output:k.output}))}catch(k){if(Ce(k))return;ft(k,{cesdk:u,provider:t,getInput:n},o)}finally{v=void 0,f.setValue(!1),g.setValue(()=>{}),h.value!=null&&(u.ui.closeDialog(h.value),h.setValue(void 0))}};o.middleware!=null?await o.middleware(y,{provider:t,abort:b}):await y()}}),t.output.generationHintText!=null&&i.Text(`${c}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),s&&a.historyAssetLibraryEntryId!=null&&i.Library(`${c}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function p5(e,t,n){let r=t?.success;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.success",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"success",message:a,action:o,duration:r.duration}),!0}var ka=g5;async function m5(e,t,n,r){let{cesdk:a}=n,{id:o}=e;r.debug&&console.log(`Registering schema-based panel input for provider ${o}`);let i=$4(t.document),l=aa(i,t.inputReference);if(!N4(l,r.debug))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=la(u,t),c=d=>{let{builder:g}=d,f=[];g.Section(`${o}.schema.section`,{children:()=>{s.forEach(p=>{let h=q4(d,p,e,t,n,r);h!=null&&(Array.isArray(h)?f.push(...h):f.push(h))})}});let v=f.map(p=>p()),w=p=>p.type==="object"?Object.entries(p.value).reduce((h,[m,y])=>(h[m]=w(y),h),{}):p.value,b=v.reduce((p,h)=>(p[h.id]=w(h),p),{});ka(d,e,()=>({input:b}),()=>t.getBlockInput(b),{...n,requiredInputs:u.required,createPlaceholderBlock:t.userFlow==="placeholder"},r)};return a.ui.registerPanel(sa(o),c),c}var f5=m5;async function y5(e,t,n,r){let{cesdk:a}=n,{id:o}=e,i=t.render,l=u=>{let{state:s}=u,c=s(va(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:g}=i(u,{cesdk:a,isGenerating:c});return ka(u,e,d,g,{...n,includeHistoryLibrary:t.includeHistoryLibrary??!0,createPlaceholderBlock:t.userFlow==="placeholder"},r),d};return a.ui.registerPanel(sa(o),l),l}var b5=y5,Wr="@imgly/plugin-ai-generation",h5=`
208
+ `,Dx=Ox;function Px(e){return async(t,r,i)=>e.enable?(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await jc(2e3),await zx(t,e,r)):i(t,r)}async function zx(e,t,r){switch(t.kind){case"image":return Ux(e,t,r);case"video":return Rx(e,t,r);case"text":return Fx(e,t,r);case"audio":return Bx(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function Ux(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await $k(l,r),s=await Tk(u,r);i=s.width,n=s.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
209
+ `,"+")}`}}async function Rx(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function Fx(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,l=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);l&&l[1]&&(i=l[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=Rr(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=Rr(n,o)}else"customPrompt"in e?a=Rr(n,"custom"):a=Rr(n,"improved");else a=Rr(n,"generated");return Vx(a,r.abortSignal)}async function*Vx(e,t){let r=Math.max(1,Math.ceil(e.length/20)),i=0;for(;i<e.length;){if(t?.aborted)return;let n=Math.min(i+r,e.length);yield{kind:"text",text:e.substring(0,n)},i=n,i<e.length&&await jc(100)}return{kind:"text",text:e}}function Rr(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,l="";if(n<=o.length)l=o.substring(0,n);else{l=o;let u=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],s=0;for(;l.length<n;){let c=u[s%u.length];if(l.length+c.length<=n)l+=c;else{l+=c.substring(0,n-l.length);break}s++}}return r+l}async function Bx(e,t,r){let i=3;if(e!=null&&typeof e=="object"){if("duration"in e&&typeof e.duration=="number")i=e.duration;else if("prompt"in e&&typeof e.prompt=="string"){let n=e.prompt.match(/(\d+)\s*(?:seconds?|secs?|s)\b/i);n&&(i=parseInt(n[1],10))}}return t.blockInputs?.audio?.duration&&(i=t.blockInputs.audio.duration),{kind:"audio",url:Gx(220,i),duration:i,thumbnailUrl:void 0}}function Gx(e,t){let r=Math.floor(44100*t),i=new Float32Array(r);for(let n=0;n<r;n++)i[n]=Math.sin(2*Math.PI*e*n/44100);return qx(i,44100)}function qx(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,l=r*i,u=44+l,s=new ArrayBuffer(u),c=new DataView(s),d=(b,m)=>{for(let h=0;h<m.length;h++)c.setUint8(b+h,m.charCodeAt(h))};d(0,"RIFF"),c.setUint32(4,u-8,!0),d(8,"WAVE"),d(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,n,!0),c.setUint32(24,t,!0),c.setUint32(28,o,!0),c.setUint16(32,a,!0),c.setUint16(34,16,!0),d(36,"data"),c.setUint32(40,l,!0);let p=44;for(let b=0;b<r;b++){let m=Math.max(-1,Math.min(1,e[b])),h=Math.round(m*32767);c.setInt16(p,h,!0),p+=2}let g=new Uint8Array(s),f="";for(let b=0;b<g.length;b++)f+=String.fromCharCode(g[b]);return`data:audio/wav;base64,${btoa(f)}`}async function jc(e){return new Promise(t=>{setTimeout(t,e)})}var Yx=Px,Hx="USER_CANCEL";function Zx(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=Pk([...e.provider.output.middleware??[],...r?.middlewares??[],Uk({enable:r?.debug}),Yx({enable:r?.dryRun,kind:e.provider.kind})]);try{let{result:n}=await i(e.provider.output.generate)(t,{abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk});return r?.abortSignal?.aborted?{status:"aborted"}:n instanceof Error?{status:"error",message:n.message}:n==null?{status:"error",message:"No output generated"}:Bk(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return Ho(n)?{status:"aborted",message:n.message}:n===Hx?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var Qx=Zx;async function Wx(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n};await t.initialize?.({...r,engine:r.cesdk.engine});let o=Tx(a),l=Nx(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=l;let u=Qx({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),s=await _x(a,u);Gk(r.cesdk,"@imgly/plugin-ai-generation",Dx);let c={provider:t,panel:{builderRenderFunction:s},history:{assetSourceId:o,assetLibraryEntryId:l},generate:u};return Dk.get().register(c),c}var $o=Wx;function Kx(e){let{kind:t,cesdk:r,historAssetSourceIds:i}=e,n=`ly.img.ai.${t}-generation.history`;if(r.engine.asset.findAllSources().includes(n))return n;let a=new Ov(n,r,i);return r.engine.asset.addSource(a),a.id}var Jx=Kx;async function Xx(e,t,r,i){let n,a=[];if(Array.isArray(t)){let l=await Promise.all(t.map(u=>$o(e,u,r,i)));a.push(...l),n=tI({prefix:e,providerInitializationResults:a})}else{let l=await Promise.all(t.fromText.map(s=>$o(e,s,r,i)));a.push(...l);let u=await Promise.all(t.fromImage.map(s=>$o(e,s,r,i)));a.push(...u),n=eI({prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u})}let o=Jx({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(l=>l.history?.assetSourceId).filter(Ok)});return{panel:{builderRenderFunction:n},history:{assetSourceId:o},providerInitializationResults:a}}function eI({prefix:e,initializedFromTextProviders:t,initializedFromImageProviders:r}){let i=t.length>0&&r.length>0;return n=>{let{builder:a,experimental:o}=n,l=o.global(`${e}.fromType`,i?"fromText":void 0),u=[];l.value==="fromText"?u.push(...t):l.value==="fromImage"?u.push(...r):u.push(...t,...r);let s=t.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),c=r.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),d=n.experimental.global(`${e}.selectedProvider.fromText`,s[0]),p=n.experimental.global(`${e}.selectedProvider.fromImage`,c[0]),g=l.value==="fromText"?d:l.value==="fromImage"?p:void 0;if((i||u.length>1)&&a.Section(`${e}.providerSelection.section`,{children:()=>{if(i&&a.ButtonGroup(`${e}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{a.Button(`${e}.fromType.buttonGroup.fromText`,{label:"Text",icon:l.value!=="fromText"&&Bu(t,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromText",onClick:()=>{l.setValue("fromText")}}),a.Button(`${e}.fromType.buttonGroup.fromImage`,{label:"Image",icon:l.value!=="fromImage"&&Bu(r,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromImage",onClick:()=>{l.setValue("fromImage")}})}}),u.length>1){let f=l.value==="fromText"?s:l.value==="fromImage"?c:[...s,...c];g!=null&&a.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:f,...g})}}}),u.length>1)g?.value.builderRenderFunction?.(n);else{let f=u[0];f&&f.panel?.builderRenderFunction?.(n)}}}function tI({prefix:e,providerInitializationResults:t}){return r=>{let{builder:i}=r;if(t.length===0)return;let n=t.map(({provider:o,panel:l})=>({id:o.id,label:o.name??o.id,builderRenderFunction:l?.builderRenderFunction})),a=r.state(`${e}.selectedProvider`,n[0]);t.length>1&&a!=null&&i.Section(`${e}.providerSelection.section`,{children:()=>{i.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:n,...a})}}),a.value.builderRenderFunction?.(r)}}function Bu(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Qo(r.id),!1).value)}var rI=Xx,iI=typeof global=="object"&&global&&global.Object===Object&&global,Sc=iI,nI=typeof self=="object"&&self&&self.Object===Object&&self,oI=Sc||nI||Function("return this")(),W=oI,aI=W.Symbol,dt=aI,Ec=Object.prototype,lI=Ec.hasOwnProperty,sI=Ec.toString,Fr=dt?dt.toStringTag:void 0;function uI(e){var t=lI.call(e,Fr),r=e[Fr];try{e[Fr]=void 0;var i=!0}catch{}var n=sI.call(e);return i&&(t?e[Fr]=r:delete e[Fr]),n}var cI=uI,dI=Object.prototype,pI=dI.toString;function gI(e){return pI.call(e)}var fI=gI,hI="[object Null]",mI="[object Undefined]",Gu=dt?dt.toStringTag:void 0;function yI(e){return e==null?e===void 0?mI:hI:Gu&&Gu in Object(e)?cI(e):fI(e)}var Jr=yI;function bI(e){return e!=null&&typeof e=="object"}var Wo=bI,gK=Array.isArray;function vI(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var _c=vI,wI="[object AsyncFunction]",kI="[object Function]",xI="[object GeneratorFunction]",II="[object Proxy]";function CI(e){if(!_c(e))return!1;var t=Jr(e);return t==kI||t==xI||t==wI||t==II}var AI=CI,MI=W["__core-js_shared__"],No=MI,qu=function(){var e=/[^.]+$/.exec(No&&No.keys&&No.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function jI(e){return!!qu&&qu in e}var SI=jI,EI=Function.prototype,_I=EI.toString;function LI(e){if(e!=null){try{return _I.call(e)}catch{}try{return e+""}catch{}}return""}var Ae=LI,TI=/[\\^$.*+?()[\]{}|]/g,$I=/^\[object .+?Constructor\]$/,NI=Function.prototype,OI=Object.prototype,DI=NI.toString,PI=OI.hasOwnProperty,zI=RegExp("^"+DI.call(PI).replace(TI,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function UI(e){if(!_c(e)||SI(e))return!1;var t=AI(e)?zI:$I;return t.test(Ae(e))}var RI=UI;function FI(e,t){return e?.[t]}var VI=FI;function BI(e,t){var r=VI(e,t);return RI(r)?r:void 0}var mt=BI,GI=mt(W,"WeakMap"),Fo=GI;function qI(e,t){return e===t||e!==e&&t!==t}var YI=qI,HI=9007199254740991;function ZI(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=HI}var QI=ZI,fK=Object.prototype,WI="[object Arguments]";function KI(e){return Wo(e)&&Jr(e)==WI}var Yu=KI,Lc=Object.prototype,JI=Lc.hasOwnProperty,XI=Lc.propertyIsEnumerable,hK=Yu(function(){return arguments}())?Yu:function(e){return Wo(e)&&JI.call(e,"callee")&&!XI.call(e,"callee")},Tc=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Hu=Tc&&typeof module=="object"&&module&&!module.nodeType&&module,eC=Hu&&Hu.exports===Tc,Zu=eC?W.Buffer:void 0,mK=Zu?Zu.isBuffer:void 0,tC="[object Arguments]",rC="[object Array]",iC="[object Boolean]",nC="[object Date]",oC="[object Error]",aC="[object Function]",lC="[object Map]",sC="[object Number]",uC="[object Object]",cC="[object RegExp]",dC="[object Set]",pC="[object String]",gC="[object WeakMap]",fC="[object ArrayBuffer]",hC="[object DataView]",mC="[object Float32Array]",yC="[object Float64Array]",bC="[object Int8Array]",vC="[object Int16Array]",wC="[object Int32Array]",kC="[object Uint8Array]",xC="[object Uint8ClampedArray]",IC="[object Uint16Array]",CC="[object Uint32Array]",_={};_[mC]=_[yC]=_[bC]=_[vC]=_[wC]=_[kC]=_[xC]=_[IC]=_[CC]=!0;_[tC]=_[rC]=_[fC]=_[iC]=_[hC]=_[nC]=_[oC]=_[aC]=_[lC]=_[sC]=_[uC]=_[cC]=_[dC]=_[pC]=_[gC]=!1;function AC(e){return Wo(e)&&QI(e.length)&&!!_[Jr(e)]}var MC=AC;function jC(e){return function(t){return e(t)}}var SC=jC,$c=typeof exports=="object"&&exports&&!exports.nodeType&&exports,qr=$c&&typeof module=="object"&&module&&!module.nodeType&&module,EC=qr&&qr.exports===$c,Oo=EC&&Sc.process,_C=function(){try{var e=qr&&qr.require&&qr.require("util").types;return e||Oo&&Oo.binding&&Oo.binding("util")}catch{}}(),Qu=_C,Wu=Qu&&Qu.isTypedArray,yK=Wu?SC(Wu):MC,LC=Object.prototype,bK=LC.hasOwnProperty;function TC(e,t){return function(r){return e(t(r))}}var $C=TC,vK=$C(Object.keys,Object),NC=Object.prototype,wK=NC.hasOwnProperty,OC=mt(Object,"create"),Zr=OC;function DC(){this.__data__=Zr?Zr(null):{},this.size=0}var PC=DC;function zC(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var UC=zC,RC="__lodash_hash_undefined__",FC=Object.prototype,VC=FC.hasOwnProperty;function BC(e){var t=this.__data__;if(Zr){var r=t[e];return r===RC?void 0:r}return VC.call(t,e)?t[e]:void 0}var GC=BC,qC=Object.prototype,YC=qC.hasOwnProperty;function HC(e){var t=this.__data__;return Zr?t[e]!==void 0:YC.call(t,e)}var ZC=HC,QC="__lodash_hash_undefined__";function WC(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Zr&&t===void 0?QC:t,this}var KC=WC;function yt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}yt.prototype.clear=PC;yt.prototype.delete=UC;yt.prototype.get=GC;yt.prototype.has=ZC;yt.prototype.set=KC;var Ku=yt;function JC(){this.__data__=[],this.size=0}var XC=JC;function eA(e,t){for(var r=e.length;r--;)if(YI(e[r][0],t))return r;return-1}var pn=eA,tA=Array.prototype,rA=tA.splice;function iA(e){var t=this.__data__,r=pn(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():rA.call(t,r,1),--this.size,!0}var nA=iA;function oA(e){var t=this.__data__,r=pn(t,e);return r<0?void 0:t[r][1]}var aA=oA;function lA(e){return pn(this.__data__,e)>-1}var sA=lA;function uA(e,t){var r=this.__data__,i=pn(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var cA=uA;function bt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}bt.prototype.clear=XC;bt.prototype.delete=nA;bt.prototype.get=aA;bt.prototype.has=sA;bt.prototype.set=cA;var gn=bt,dA=mt(W,"Map"),Qr=dA;function pA(){this.size=0,this.__data__={hash:new Ku,map:new(Qr||gn),string:new Ku}}var gA=pA;function fA(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var hA=fA;function mA(e,t){var r=e.__data__;return hA(t)?r[typeof t=="string"?"string":"hash"]:r.map}var fn=mA;function yA(e){var t=fn(this,e).delete(e);return this.size-=t?1:0,t}var bA=yA;function vA(e){return fn(this,e).get(e)}var wA=vA;function kA(e){return fn(this,e).has(e)}var xA=kA;function IA(e,t){var r=fn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var CA=IA;function vt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}vt.prototype.clear=gA;vt.prototype.delete=bA;vt.prototype.get=wA;vt.prototype.has=xA;vt.prototype.set=CA;var Nc=vt;function AA(){this.__data__=new gn,this.size=0}var MA=AA;function jA(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var SA=jA;function EA(e){return this.__data__.get(e)}var _A=EA;function LA(e){return this.__data__.has(e)}var TA=LA,$A=200;function NA(e,t){var r=this.__data__;if(r instanceof gn){var i=r.__data__;if(!Qr||i.length<$A-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Nc(i)}return r.set(e,t),this.size=r.size,this}var OA=NA;function Xr(e){var t=this.__data__=new gn(e);this.size=t.size}Xr.prototype.clear=MA;Xr.prototype.delete=SA;Xr.prototype.get=_A;Xr.prototype.has=TA;Xr.prototype.set=OA;var DA=Object.prototype,kK=DA.propertyIsEnumerable,PA=mt(W,"DataView"),Vo=PA,zA=mt(W,"Promise"),Bo=zA,UA=mt(W,"Set"),Go=UA,Ju="[object Map]",RA="[object Object]",Xu="[object Promise]",ec="[object Set]",tc="[object WeakMap]",rc="[object DataView]",FA=Ae(Vo),VA=Ae(Qr),BA=Ae(Bo),GA=Ae(Go),qA=Ae(Fo),st=Jr;(Vo&&st(new Vo(new ArrayBuffer(1)))!=rc||Qr&&st(new Qr)!=Ju||Bo&&st(Bo.resolve())!=Xu||Go&&st(new Go)!=ec||Fo&&st(new Fo)!=tc)&&(st=function(e){var t=Jr(e),r=t==RA?e.constructor:void 0,i=r?Ae(r):"";if(i)switch(i){case FA:return rc;case VA:return Ju;case BA:return Xu;case GA:return ec;case qA:return tc}return t});var xK=W.Uint8Array,YA="__lodash_hash_undefined__";function HA(e){return this.__data__.set(e,YA),this}var ZA=HA;function QA(e){return this.__data__.has(e)}var WA=QA;function qo(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Nc;++t<r;)this.add(e[t])}qo.prototype.add=qo.prototype.push=ZA;qo.prototype.has=WA;var ic=dt?dt.prototype:void 0,IK=ic?ic.valueOf:void 0,KA=Object.prototype,CK=KA.hasOwnProperty,JA=Object.prototype,AK=JA.hasOwnProperty,MK=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),jK=new RegExp(/[A-Fa-f0-9]{1}/,"g"),SK=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function XA(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function eM(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return XA(i,t)}function tM(e){return e==null?[]:Array.isArray(e)?e:[e]}var nc=tM,sn="@imgly/plugin-ai-video-generation-web";var Oc="createVideo",oc=`ly.img.${Oc}`,Vr=`ly.img.ai.quickAction.video.${Oc}`,rM=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Vr}.label`]:"Create Video...",[`${Vr}.description`]:"Create a video from the image"}}),{id:oc,type:"quick",kind:"image",label:`${Vr}.label`,description:`${Vr}.description`,enable:Qk(),scopes:[],render:({builder:t,engine:r,close:i,providerId:n})=>{t.Button(`${oc}.button`,{label:`${Vr}.label`,icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=r.block.findAllSelected(),o=await eM(a,r,{throwErrorIfSvg:!0});e.ui.openPanel("ly.img.ai.video-generation"),e.ui.experimental.setGlobalStateValue("ly.img.ai.video-generation.fromType","fromImage"),e.ui.experimental.setGlobalStateValue(`${n}.image_url`,o),i()}catch(a){console.error("Error opening video generation panel:",a)}}})}}),iM=rM,ce="ly.img.ai.video-generation";function nM(e){return{async initialize({cesdk:t}){if(t==null)return;qk(t,sn,"0.2.0"),t.setTranslations({en:{[`panel.${ce}`]:"Video Generation",[`${ce}.dock.label`]:"AI Video"}}),oM(e);let r=Fu.get().register({type:"plugin",sceneMode:"Video",id:sn,pluginId:sn,label:"Generate Video",meta:{panelId:ce},execute:()=>{t.ui.isPanelOpen(ce)?t.ui.closePanel(ce):t.ui.openPanel(ce)}}),i=e.providers?.text2video??e.text2video,n=e.providers?.image2video??e.image2video,a=await Promise.all(nc(i).map(u=>u({cesdk:t}))),o=await Promise.all(nc(n).map(u=>u({cesdk:t}))),l=await rI("video",{fromText:a,fromImage:o},{cesdk:t},e);Fu.get().register(iM({cesdk:t})),l.panel.builderRenderFunction!=null?(t.ui.registerPanel(ce,l.panel.builderRenderFunction),Hk({cesdk:t,panelId:ce})):r()}}}function oM(e){e.debug&&(e.providers?.text2video!=null&&e.text2video!=null&&console.warn("[VideoGeneration]: Both `providers.text2video` and `text2video` configuration is provided. Since `text2video` is deprecated, only `providers.text2video` will be used."),e.providers?.image2video!=null&&e.image2video!=null&&console.warn("[VideoGeneration]: Both `providers.image2video` and `image2video` configuration is provided. Since `image2video` is deprecated, only `providers.image2video` will be used."))}var aM=nM,lM=e=>({name:sn,version:"0.2.0",...aM(e)}),Dc=lM;var sM=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",p=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(p=s.tags[c]);let g={...s,label:d,tags:p};return this.filterAsset(g,e)&&u.push(g),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),l=a<t.length?r+1:void 0;return{assets:o,currentPage:r,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let i=new Set;r.result.forEach(a=>{a.groups&&Array.isArray(a.groups)&&a.groups.forEach(o=>i.add(o))});let n=[...i];e(n)},r.onerror=()=>{t(new Error(`Failed to get groups: ${r.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),r=t.objectStore(this.assetStoreName),i=new Set;It(e,a=>{i.add(a)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.assetStoreName,"readwrite");r.objectStore(this.assetStoreName).delete(e),r.oncomplete=()=>{It(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let l=a.meta?.insertedAt||a._insertedAt||Date.now(),u=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return It(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),It(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!o.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(l=>e.tags?.includes(l))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,l)=>{let u,s;return i==="id"?(u=o.id,s=l.id):(u=o.meta?.[i]??null,s=l.meta?.[i]??null),u==null?r==="Ascending"?-1:1:s==null?r==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?r==="Ascending"?u.localeCompare(s):s.localeCompare(u):r==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):r==="Descending"&&a.reverse(),n&&a.sort((o,l)=>o.active&&!l.active?-1:!o.active&&l.active?1:0)),a}};function It(e,t,r=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let i=0;i<e.length;i++){let n=r?`${r}[${i}]`:`[${i}]`;if(typeof e[i]=="string"&&e[i].startsWith("blob:")){let a=t(e[i],n);typeof a=="string"&&(e[i]=a)}else e[i]=It(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],a=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let o=t(n,a);typeof o=="string"&&(e[i]=o)}else e[i]=It(n,t,a)}return e}var uM=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,d)=>{let p=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,l=o+a,u=i.slice(o,l),s=l<i.length?n+1:void 0;return{assets:u,currentPage:n,nextPage:s,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}},cM=typeof global=="object"&&global&&global.Object===Object&&global,md=cM,dM=typeof self=="object"&&self&&self.Object===Object&&self,pM=md||dM||Function("return this")(),K=pM,gM=K.Symbol,Ct=gM,yd=Object.prototype,fM=yd.hasOwnProperty,hM=yd.toString,ei=Ct?Ct.toStringTag:void 0;function mM(e){var t=fM.call(e,ei),r=e[ei];try{e[ei]=void 0;var i=!0}catch{}var n=hM.call(e);return i&&(t?e[ei]=r:delete e[ei]),n}var yM=mM,bM=Object.prototype,vM=bM.toString;function wM(e){return vM.call(e)}var kM=wM,xM="[object Null]",IM="[object Undefined]",Pc=Ct?Ct.toStringTag:void 0;function CM(e){return e==null?e===void 0?IM:xM:Pc&&Pc in Object(e)?yM(e):kM(e)}var ci=CM;function AM(e){return e!=null&&typeof e=="object"}var fa=AM,TK=Array.isArray;function MM(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var bd=MM,jM="[object AsyncFunction]",SM="[object Function]",EM="[object GeneratorFunction]",_M="[object Proxy]";function LM(e){if(!bd(e))return!1;var t=ci(e);return t==SM||t==EM||t==jM||t==_M}var TM=LM,$M=K["__core-js_shared__"],Ko=$M,zc=function(){var e=/[^.]+$/.exec(Ko&&Ko.keys&&Ko.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function NM(e){return!!zc&&zc in e}var OM=NM,DM=Function.prototype,PM=DM.toString;function zM(e){if(e!=null){try{return PM.call(e)}catch{}try{return e+""}catch{}}return""}var Se=zM,UM=/[\\^$.*+?()[\]{}|]/g,RM=/^\[object .+?Constructor\]$/,FM=Function.prototype,VM=Object.prototype,BM=FM.toString,GM=VM.hasOwnProperty,qM=RegExp("^"+BM.call(GM).replace(UM,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function YM(e){if(!bd(e)||OM(e))return!1;var t=TM(e)?qM:RM;return t.test(Se(e))}var HM=YM;function ZM(e,t){return e?.[t]}var QM=ZM;function WM(e,t){var r=QM(e,t);return HM(r)?r:void 0}var Mt=WM,KM=Mt(K,"WeakMap"),na=KM;function JM(e,t){return e===t||e!==e&&t!==t}var XM=JM,ej=9007199254740991;function tj(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ej}var rj=tj,$K=Object.prototype,ij="[object Arguments]";function nj(e){return fa(e)&&ci(e)==ij}var Uc=nj,vd=Object.prototype,oj=vd.hasOwnProperty,aj=vd.propertyIsEnumerable,NK=Uc(function(){return arguments}())?Uc:function(e){return fa(e)&&oj.call(e,"callee")&&!aj.call(e,"callee")},wd=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Rc=wd&&typeof module=="object"&&module&&!module.nodeType&&module,lj=Rc&&Rc.exports===wd,Fc=lj?K.Buffer:void 0,OK=Fc?Fc.isBuffer:void 0,sj="[object Arguments]",uj="[object Array]",cj="[object Boolean]",dj="[object Date]",pj="[object Error]",gj="[object Function]",fj="[object Map]",hj="[object Number]",mj="[object Object]",yj="[object RegExp]",bj="[object Set]",vj="[object String]",wj="[object WeakMap]",kj="[object ArrayBuffer]",xj="[object DataView]",Ij="[object Float32Array]",Cj="[object Float64Array]",Aj="[object Int8Array]",Mj="[object Int16Array]",jj="[object Int32Array]",Sj="[object Uint8Array]",Ej="[object Uint8ClampedArray]",_j="[object Uint16Array]",Lj="[object Uint32Array]",L={};L[Ij]=L[Cj]=L[Aj]=L[Mj]=L[jj]=L[Sj]=L[Ej]=L[_j]=L[Lj]=!0;L[sj]=L[uj]=L[kj]=L[cj]=L[xj]=L[dj]=L[pj]=L[gj]=L[fj]=L[hj]=L[mj]=L[yj]=L[bj]=L[vj]=L[wj]=!1;function Tj(e){return fa(e)&&rj(e.length)&&!!L[ci(e)]}var $j=Tj;function Nj(e){return function(t){return e(t)}}var Oj=Nj,kd=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ni=kd&&typeof module=="object"&&module&&!module.nodeType&&module,Dj=ni&&ni.exports===kd,Jo=Dj&&md.process,Pj=function(){try{var e=ni&&ni.require&&ni.require("util").types;return e||Jo&&Jo.binding&&Jo.binding("util")}catch{}}(),Vc=Pj,Bc=Vc&&Vc.isTypedArray,DK=Bc?Oj(Bc):$j,zj=Object.prototype,PK=zj.hasOwnProperty;function Uj(e,t){return function(r){return e(t(r))}}var Rj=Uj,zK=Rj(Object.keys,Object),Fj=Object.prototype,UK=Fj.hasOwnProperty,Vj=Mt(Object,"create"),ai=Vj;function Bj(){this.__data__=ai?ai(null):{},this.size=0}var Gj=Bj;function qj(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Yj=qj,Hj="__lodash_hash_undefined__",Zj=Object.prototype,Qj=Zj.hasOwnProperty;function Wj(e){var t=this.__data__;if(ai){var r=t[e];return r===Hj?void 0:r}return Qj.call(t,e)?t[e]:void 0}var Kj=Wj,Jj=Object.prototype,Xj=Jj.hasOwnProperty;function eS(e){var t=this.__data__;return ai?t[e]!==void 0:Xj.call(t,e)}var tS=eS,rS="__lodash_hash_undefined__";function iS(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ai&&t===void 0?rS:t,this}var nS=iS;function jt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}jt.prototype.clear=Gj;jt.prototype.delete=Yj;jt.prototype.get=Kj;jt.prototype.has=tS;jt.prototype.set=nS;var Gc=jt;function oS(){this.__data__=[],this.size=0}var aS=oS;function lS(e,t){for(var r=e.length;r--;)if(XM(e[r][0],t))return r;return-1}var hn=lS,sS=Array.prototype,uS=sS.splice;function cS(e){var t=this.__data__,r=hn(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():uS.call(t,r,1),--this.size,!0}var dS=cS;function pS(e){var t=this.__data__,r=hn(t,e);return r<0?void 0:t[r][1]}var gS=pS;function fS(e){return hn(this.__data__,e)>-1}var hS=fS;function mS(e,t){var r=this.__data__,i=hn(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var yS=mS;function St(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}St.prototype.clear=aS;St.prototype.delete=dS;St.prototype.get=gS;St.prototype.has=hS;St.prototype.set=yS;var mn=St,bS=Mt(K,"Map"),li=bS;function vS(){this.size=0,this.__data__={hash:new Gc,map:new(li||mn),string:new Gc}}var wS=vS;function kS(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var xS=kS;function IS(e,t){var r=e.__data__;return xS(t)?r[typeof t=="string"?"string":"hash"]:r.map}var yn=IS;function CS(e){var t=yn(this,e).delete(e);return this.size-=t?1:0,t}var AS=CS;function MS(e){return yn(this,e).get(e)}var jS=MS;function SS(e){return yn(this,e).has(e)}var ES=SS;function _S(e,t){var r=yn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var LS=_S;function Et(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Et.prototype.clear=wS;Et.prototype.delete=AS;Et.prototype.get=jS;Et.prototype.has=ES;Et.prototype.set=LS;var xd=Et;function TS(){this.__data__=new mn,this.size=0}var $S=TS;function NS(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var OS=NS;function DS(e){return this.__data__.get(e)}var PS=DS;function zS(e){return this.__data__.has(e)}var US=zS,RS=200;function FS(e,t){var r=this.__data__;if(r instanceof mn){var i=r.__data__;if(!li||i.length<RS-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new xd(i)}return r.set(e,t),this.size=r.size,this}var VS=FS;function di(e){var t=this.__data__=new mn(e);this.size=t.size}di.prototype.clear=$S;di.prototype.delete=OS;di.prototype.get=PS;di.prototype.has=US;di.prototype.set=VS;var BS=Object.prototype,RK=BS.propertyIsEnumerable,GS=Mt(K,"DataView"),oa=GS,qS=Mt(K,"Promise"),aa=qS,YS=Mt(K,"Set"),la=YS,qc="[object Map]",HS="[object Object]",Yc="[object Promise]",Hc="[object Set]",Zc="[object WeakMap]",Qc="[object DataView]",ZS=Se(oa),QS=Se(li),WS=Se(aa),KS=Se(la),JS=Se(na),wt=ci;(oa&&wt(new oa(new ArrayBuffer(1)))!=Qc||li&&wt(new li)!=qc||aa&&wt(aa.resolve())!=Yc||la&&wt(new la)!=Hc||na&&wt(new na)!=Zc)&&(wt=function(e){var t=ci(e),r=t==HS?e.constructor:void 0,i=r?Se(r):"";if(i)switch(i){case ZS:return Qc;case QS:return qc;case WS:return Yc;case KS:return Hc;case JS:return Zc}return t});var FK=K.Uint8Array,XS="__lodash_hash_undefined__";function eE(e){return this.__data__.set(e,XS),this}var tE=eE;function rE(e){return this.__data__.has(e)}var iE=rE;function sa(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new xd;++t<r;)this.add(e[t])}sa.prototype.add=sa.prototype.push=tE;sa.prototype.has=iE;var Wc=Ct?Ct.prototype:void 0,VK=Wc?Wc.valueOf:void 0,nE=Object.prototype,BK=nE.hasOwnProperty,oE=Object.prototype,GK=oE.hasOwnProperty,qK=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),YK=new RegExp(/[A-Fa-f0-9]{1}/,"g"),HK=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function Id(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function aE(e,t){let r=await Id(e,t);return new Promise((i,n)=>{let a=new Image;a.onload=()=>{i({width:a.width,height:a.height})},a.onerror=n,a.src=r})}async function lE(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return Id(i,t)}function sE(e){return e!==void 0}var uE=sE,cE=class Cd{constructor(){this.actions=new Map,this.subscribers=new Map}static get(){let t="__imgly_action_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new Cd),r[t]}register(t){return this.actions.set(t.id,t),this.notifySubscribers(t,"registered"),()=>{this.actions.get(t.id)===t&&(this.actions.delete(t.id),this.notifySubscribers(t,"unregistered"))}}getAll(){return Array.from(this.actions.values())}getBy(t){return this.getAll().filter(r=>this.matchesFilters(r,t))}subscribe(t){return this.subscribers.set(t,null),()=>{this.subscribers.delete(t)}}subscribeBy(t,r){return this.subscribers.set(r,t),()=>{this.subscribers.delete(r)}}notifySubscribers(t,r){this.subscribers.forEach((i,n)=>{if(i===null){n(t,r);return}this.matchesFilters(t,i)&&n(t,r)})}matchesFilters(t,r){return!(r.type&&t.type!==r.type||r.pluginId&&t.type==="plugin"&&t.pluginId!==r.pluginId||r.id&&t.id!==r.id||r.kind&&(t.type!=="quick"||t.kind!==r.kind))}},dE=class Ad{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new Ad),r[t]}register(t){return this.providers.has(t.provider.id)&&console.warn(`Provider with ID "${t.provider.id}" is already registered`),this.providers.set(t.provider.id,t),()=>{this.providers.get(t.provider.id)===t&&this.providers.delete(t.provider.id)}}getAll(){return Array.from(this.providers.values())}getById(t){return this.providers.get(t)}getByKind(t){return this.getAll().filter(({provider:r})=>r.kind===t)}};function pE(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=s=>{a.push(s)},l=async(s,c,d)=>{if(s>=t.length)return r(c,d);let p=t[s],g=async(b,m)=>l(s+1,b,m),f={...d,addDisposer:o};return p(c,f,g)},u={...n,addDisposer:o};return{result:await l(0,i,u),dispose:async()=>{for(let s=a.length-1;s>=0;s--)try{await a[s]()}catch(c){console.error("Error in disposer:",c)}a.length=0}}}}function gE({enable:e=!0}){return async(t,r,i)=>{if(!e)return i(t,r);console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(t,null,2));let n,a=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var fE=gE,Xo="ly.img.ai.temp";async function hE(e,t){return e.engine.asset.findAllSources().includes(Xo)||e.engine.asset.addLocalSource(Xo),e.engine.asset.apply(Xo,t)}function mE(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let r=e;return"message"in r&&typeof r.message=="string"?r.message:"cause"in r&&typeof r.cause=="string"?r.cause:"detail"in r&&typeof r.detail=="object"&&r.detail!==null&&"message"in r.detail&&typeof r.detail.message=="string"?r.detail.message:"error"in r&&typeof r.error=="object"&&r.error!==null&&"message"in r.error&&typeof r.error.message=="string"?r.error.message:t}return typeof e=="string"?e:String(e)||t}function Md(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function yE(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=o.videoWidth,l.height=o.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}u.drawImage(o,0,0,l.width,l.height);try{let s=l.toDataURL(r,i);document.body.removeChild(o),n(s)}catch(s){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function jd(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function bE(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function ha(e){return e instanceof Error&&e.name==="AbortError"}function vE(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function wE(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
210
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
211
+ This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version.
212
+ Consider updating all AI plugins to the same version for optimal compatibility.`),e.ui.experimental.setGlobalStateValue(n,!0))):e.ui.experimental.setGlobalStateValue(i,r)}catch(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}function kE(e){let{cesdk:t,panelId:r}=e;r.startsWith("ly.img.ai.")||console.warn(`Dock components for AI generation should open a panel with an id starting with "ly.img.ai." \u2013 "${r}" was provided.`);let i=`${r}.dock`;t.ui.registerComponent(i,({builder:n})=>{let a=t.ui.isPanelOpen(r);n.Button(`${r}.dock.button`,{label:`${r}.dock.label`,isSelected:a,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(o=>{o.startsWith("ly.img.ai.")&&t.ui.closePanel(o),!a&&o==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(o)}),a?t.ui.closePanel(r):t.ui.openPanel(r)}})})}var Kc=kE;function xE(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),IE(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:mE(e)})}function IE(e,t,r){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.failed",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"error",message:n,action:a}),!0}var Jc=xE,CE="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",ma=CE;function AE(e,t,r){switch(t){case"image":return ME(e,r[t]);case"video":return jE(e,r[t]);case"sticker":return SE(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function ME(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:ma,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function jE(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:ma,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function SE(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:ma,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var EE=AE;async function _E(e,t,r,i){switch(t){case"image":{if(i.kind!=="image")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: image)`);return LE(e,r[t],i)}case"video":{if(i.kind!=="video")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: video)`);return TE(e,r[t],i)}case"audio":{if(i.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: audio)`);return $E(e,r[t],i)}case"sticker":{if(i.kind!=="sticker")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: sticker)`);return NE(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function LE(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}async function TE(e,t,r){let i=t.width,n=t.height,a=await yE(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:a,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function $E(e,t,r){return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:r.duration.toString()}}}function NE(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}var Sd=_E;function OE(e){switch(e.userFlow){case"placeholder":return PE(e);case"generation-only":return DE(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function DE(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(pe(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(pe(t,r))return{status:"aborted"};if(o.status!=="success")return o;if(o.type==="async")throw new Error("Async generation is not supported in this context yet.");if(pe(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let l=Md(),u=await Sd(l,n,a,o.output),s={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,s)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function PE(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(pe(t,r))return{status:"aborted"};let l=Md(),u=EE(l,a,o);if(i=await hE(t,u),pe(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,p),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let s=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(pe(t,r,i))return{status:"aborted"};if(s.status!=="success")return s;if(s.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let c=await Sd(l,a,o,s.output);if(pe(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(c,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(c,i),pe(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),s}catch(a){return i!=null&&t.engine.block.isValid(i)&&(ha(a)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:a instanceof Error?a.message:String(a)}}}}function pe(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var zE=OE;function ya(e){return`${e}.generating`}function UE(e){return`${e}.abort`}function RE(e,t,r,i,n,a,o){let{builder:l,experimental:u}=e,{cesdk:s,includeHistoryLibrary:c=!0}=a,{id:d,output:{abortable:p}}=t,g=u.global(UE(d),()=>{}),f=u.global(ya(d),!1),b,m=f.value&&p,h=()=>{m&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},x;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let v=i();x=a.requiredInputs.every(y=>!v.input[y])}let w=u.global(`${d}.confirmationDialogId`,void 0);l.Section(`${d}.generate.section`,{children:()=>{l.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:f.value,color:"accent",isDisabled:x,suffix:m?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let v=s.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{s.ui.closeDialog(y),w.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{h(),s.ui.closeDialog(y),w.setValue(void 0)}}});w.setValue(v)}}:void 0,onClick:async()=>{b=new AbortController;let v=b.signal;await(async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),b?.abort()});let y=await zE({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:v,cesdk:s,debug:o.debug,dryRun:o.dryRun})(i().input);if(y.status==="aborted")return;if(y.status==="error"){Jc(y.message,{cesdk:s,provider:t,getInput:i});return}if(y.status==="success"&&y.type==="sync"){let k=t.output.notification;FE(s,k,()=>({input:i().input,output:y.output}))}}catch(y){if(ha(y))return;Jc(y,{cesdk:s,provider:t,getInput:i})}finally{b=void 0,f.setValue(!1),g.setValue(()=>{}),w.value!=null&&(s.ui.closeDialog(w.value),w.setValue(void 0))}})()}}),t.output.generationHintText!=null&&l.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),c&&a.historyAssetLibraryEntryId!=null&&l.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function FE(e,t,r){let i=t?.success;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.success",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"success",message:n,action:a,duration:i.duration}),!0}var Ed=RE;async function VE({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,l=r.render;return u=>{let{state:s}=u,c=s(ya(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=l(u,{cesdk:a,isGenerating:c});return Ed(u,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var BE=VE;function _d(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let r=t.substring(2).split("/"),i=e;for(let n of r){if(i==null)throw new Error(`Invalid reference path: ${t}`);i=i[n]}if(i===void 0)throw new Error(`Reference not found: ${t}`);return i}function ii(e,t,r=new Set){if(t==null||r.has(t))return t;if(r.add(t),t.$ref&&typeof t.$ref=="string"){let i=_d(e,t.$ref),n={...ii(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=ii(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>ii(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=ii(e,t[n],r));return i}return t}function GE(e){return ii(e,{...e})}function qE(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let l of i.type)if(typeof l!="string"||!o.includes(l))return r(`Array of types contains invalid value: ${l}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let l=0;l<i[o].length;l++){let u=i[o][l];if(typeof u!="object"||u===null)return r(`Item ${l} in ${o} must be an object, got ${u===null?"null":typeof u}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let l=i.required[o];if(typeof l!="string")return r(`Item ${o} in required array must be a string, got ${typeof l}`)}}return!0}function YE(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return HE(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function HE(e,t){let r=t.order;if(r!=null&&Array.isArray(r))return r;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,n=Object.keys(i),a=ZE(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function ZE(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let r=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return r==null?void 0:e[r]}var Ld=YE;function Td(e,t,r,i,n,a){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let o=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?QE(e,o,r,i,n,a):Nd(e,o,r,i,n,a);case"boolean":return Od(e,o,r,i,n,a);case"number":case"integer":return Dd(e,o,r,i,n,a);case"object":return $d(e,o,r,i,n,a);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return WE(e,o,r,i,n,a);break}default:console.error(`Unsupported property type: ${l}`)}}function $d(e,t,r,i,n,a){let o=Ld(t.schema??{},i).reduce((l,u)=>{let s=Td(e,u,r,i,n,a);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:o})}function Nd(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),p=KE(t.schema),g=p?.component!=null&&p?.component==="TextArea"?"TextArea":"TextInput";return o[g](s,{inputLabel:c,placeholder:n.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function QE(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},p="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},g=(t.schema.enum??[]).map(m=>({id:m,label:d[m]??jd(m),icon:p[m]})),f=t.schema.default!=null?g.find(m=>m.id===t.schema.default)??g[0]:g[0],b=l(s,f);return o.Select(s,{inputLabel:c,values:g,...b}),()=>({id:t.id,type:"string",value:b.value.id})}function Od(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,p=l(s,d);return o.Checkbox(s,{inputLabel:c,...p}),()=>({id:t.id,type:"boolean",value:p.value})}function Dd(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,p=t.schema.maximum,g=t.schema.default;g==null&&(d!=null?g=d:p!=null?g=p:g=0);let f=l(s,g);if(d!=null&&p!=null){let b=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(b=t.schema["x-imgly-step"]),o.Slider(s,{inputLabel:c,min:d,max:p,step:b,...f})}else o.NumberInput(s,{inputLabel:c,min:d,max:p,...f});return()=>({id:t.id,type:"integer",value:f.value})}function WE(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],p=[],g={},f={};d.forEach((h,x)=>{let w=h.title??"common.custom",v=`${r.id}.${u}.anyOf[${x}]`,y="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},k="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};h.type==="string"?h.enum!=null?h.enum.forEach(I=>{p.push({id:I,label:y[I]??jd(I),icon:k[I]})}):(g[v]=()=>Nd(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="boolean"?(g[v]=()=>Od(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="integer"?(g[v]=()=>Dd(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="array"||h.type==="object"&&(g[v]=()=>$d(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]}))});let b=t.schema.default!=null?p.find(h=>h.id===t.schema.default)??p[0]:p[0],m=l(s,b);if(o.Select(s,{inputLabel:c,values:p,...m}),m.value.id in g){let h=g[m.value.id]();f[m.value.id]=h}return()=>{let h=f[m.value.id];return h!=null?{...h(),id:t.id}:{id:t.id,type:"string",value:m.value.id}}}function KE(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var JE=Td;async function XE({options:e,provider:t,panelInput:r,config:i},n){let{id:a}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${a}`);let o=GE(r.document),l=_d(o,r.inputReference);if(!qE(l,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=Ld(u,r);return c=>{let{builder:d}=c,p=[];d.Section(`${a}.schema.section`,{children:()=>{s.forEach(m=>{let h=JE(c,m,t,r,e,i);h!=null&&(Array.isArray(h)?p.push(...h):p.push(h))})}});let g=p.map(m=>m()),f=m=>m.type==="object"?Object.entries(m.value).reduce((h,[x,w])=>(h[x]=f(w),h),{}):m.value,b=g.reduce((m,h)=>(m[h.id]=f(h),m),{});Ed(c,t,n,()=>({input:b}),()=>r.getBlockInput(b),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var e_=XE;async function t_(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return BE(e,t);case"schema":return e_(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var r_=t_;function i_(e){let{provider:t,options:{engine:r}}=e,i=t.output.history??"@imgly/local";if(i==null||i===!1)return;let n=r.asset.findAllSources();function a(){let o=`${t.id}.history`;for(;n.includes(o);)o+=`-${Math.random().toString(36).substring(2,6)}`;return o}if(i==="@imgly/local"){let o=a();return r.asset.addLocalSource(o),o}if(i==="@imgly/indexedDB"){let o=a();return r.asset.addSource(new sM(o,r)),o}return i}var n_=i_;function o_(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history.entry`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var a_=o_,ea="@imgly/plugin-ai-generation",l_=`
202
213
  <svg>
203
214
  <symbol
204
215
  fill="none"
@@ -216,7 +227,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
216
227
  fill="none"
217
228
  xmlns="http://www.w3.org/2000/svg"
218
229
  viewBox="0 0 24 24"
219
- id="${Wr}/image"
230
+ id="${ea}/image"
220
231
  >
221
232
  <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
222
233
  <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
@@ -228,7 +239,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
228
239
  fill="none"
229
240
  xmlns="http://www.w3.org/2000/svg"
230
241
  viewBox="0 0 24 24"
231
- id="${Wr}/video"
242
+ id="${ea}/video"
232
243
  >
233
244
  <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
234
245
  <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
@@ -239,7 +250,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
239
250
  fill="none"
240
251
  xmlns="http://www.w3.org/2000/svg"
241
252
  viewBox="0 0 24 24"
242
- id="${Wr}/audio"
253
+ id="${ea}/audio"
243
254
  >
244
255
  <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
245
256
  <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
@@ -259,7 +270,8 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
259
270
 
260
271
  </symbol>
261
272
  </svg>
262
- `,v5=h5,Yo="ly.img.ai.quickAction.order",gt="ly.img.ai.quickAction.actions";function k5(e,t){return{id:t,setQuickActionMenuOrder:n=>{e.ui.experimental.setGlobalStateValue(`${Yo}.${t}`,n)},getQuickActionMenuOrder:()=>e.ui.experimental.getGlobalStateValue(`${Yo}.${t}`,[]),registerQuickAction:n=>{if(!e.ui.experimental.hasGlobalStateValue(`${gt}.${t}`))e.ui.experimental.setGlobalStateValue(`${gt}.${t}`,{[n.id]:n});else{let r=e.ui.experimental.getGlobalStateValue(`${gt}.${t}`,{});e.ui.experimental.setGlobalStateValue(`${gt}.${t}`,{...r,[n.id]:n})}},getQuickAction:n=>e.ui.experimental.getGlobalStateValue(`${gt}.${t}`,{})[n]}}var wa=k5,Kr="ly.img.ai.inference.editMode",Ca="ly.img.ai.inference.metadata";function Ma(e){return`ly.img.ai.quickAction.${e.quickActionMenuId}.${e.quickActionId}`}function w5(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((n,r)=>(r==="ly.img.separator"&&n.length>0&&n[n.length-1]==="ly.img.separator"||n.push(r),n),[])}function C5({alwaysOnTop:e=!0,disableClipping:t=!0}){return async(n,r,a)=>{let o={},i={},l=e||t?r.blockIds??r.engine.block.findAllSelected():[];return l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&(o[u]=r.engine.block.isAlwaysOnTop(u),r.engine.block.setAlwaysOnTop(u,!0)),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&(i[s]=r.engine.block.isClipped(s),r.engine.block.setClipped(s,!1))}}),r.addDisposer(async()=>{l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&r.engine.block.setAlwaysOnTop(u,o[u]),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&i[s]!=null&&r.engine.block.setClipped(s,i[s])}})}),await a(n,r)}}var M5=C5;function I5({pending:e=!0}){return async(t,n,r)=>{let a=e?n.blockIds??n.engine.block.findAllSelected():[];try{return a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Pending",progress:0})}),await r(t,n)}finally{a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Ready"})})}}}var x5=I5;function A5({editMode:e,automaticallyUnlock:t=!1}){return async(n,r,a)=>{let o=r.blockIds??r.engine.block.findAllSelected(),i=()=>{};t||r.addDisposer(async()=>{i?.()});try{return i=S5(r.engine,o,e),await a(n,r)}catch(l){throw Ce(l)&&i(),l}finally{t&&i()}}}function S5(e,t,n){let r=e.editor.getGlobalScope("editor/select"),a=e.editor.getEditMode();l(),e.editor.setGlobalScope("editor/select","Deny"),e.editor.setEditMode(n);let o=e.editor.createHistory(),i=e.editor.getActiveHistory();e.editor.setActiveHistory(o);function l(){e.block.findAllSelected().forEach(c=>{t.includes(c)||e.block.setSelected(c,!1)}),t.forEach(c=>{e.block.setSelected(c,!0)})}let u=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&e.editor.setEditMode(n)}),s=e.block.onSelectionChanged(l);return()=>{r!=null&&e.editor.setGlobalScope("editor/select",r),e.editor.setEditMode(a),e.editor.setActiveHistory(i),e.editor.destroyHistory(o),s(),u()}}var E5=A5;function j5(e,t){switch(t.kind){case"text":return L5(e,t);case"image":return T5(e,t);case"video":return $5(e,t);case"audio":return N5(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function L5(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t,o=r.map(s=>n.engine.block.getString(s,"text/text")),i;if(an(e)){let s="";for await(let c of e){if(a.aborted)break;typeof c=="string"?s=c:c.kind==="text"&&(s=c.text),r.forEach(d=>{n.engine.block.setString(d,"text/text",s)}),i={kind:"text",text:s}}}else i=e;if(i==null||i.kind!=="text")throw new Error("Output kind from generation is not text");let l=()=>{t.blockIds.forEach(s=>{t.cesdk.engine.block.setString(s,"text/text",i.text)})},u=()=>{t.blockIds.forEach((s,c)=>{t.cesdk.engine.block.setString(s,"text/text",o[c])})};return{consumedGenerationResult:i,applyCallbacks:{onBefore:u,onAfter:l,onCancel:u,onApply:()=>{l(),t.cesdk.engine.editor.addUndoStep()}}}}async function T5(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t;if(r.length!==1)throw new Error("Only one block is supported for image generation");let[o]=r,i=n.engine.block.getFill(o),l=n.engine.block.getSourceSet(i,"fill/image/sourceSet"),[u]=l,s;u==null&&(s=n.engine.block.getString(i,"fill/image/imageFileURI"));let c=await n.engine.editor.getMimeType(u?.uri??s),d=await nn(u?.uri??s,t.cesdk.engine),g=d.width/d.height;if(a.throwIfAborted(),c==="image/svg+xml")throw new Error("SVG images are not supported");let f=n.engine.block.getCropScaleX(o),v=n.engine.block.getCropScaleY(o),w=n.engine.block.getCropTranslationX(o),b=n.engine.block.getCropTranslationY(o),p=n.engine.block.getCropRotation(o),h=()=>{n.engine.block.setCropScaleX(o,f),n.engine.block.setCropScaleY(o,v),n.engine.block.setCropTranslationX(o,w),n.engine.block.setCropTranslationY(o,b),n.engine.block.setCropRotation(o,p)};if(an(e))throw new Error("Streaming generation is not supported yet from a panel");if(e.kind!=="image"||typeof e.url!="string")throw new Error("Output kind from generation is not an image");let m=e.url,y=await n.engine.editor.getMimeType(m),k=await D5(n,m,y),C=await nn(k,t.cesdk.engine),M=C.width/C.height,I=Math.abs(g-M)>.001,x=u?[{uri:k,width:C.width,height:C.height}]:void 0,$=k;x==null?n.engine.block.setString(i,"fill/image/imageFileURI",$):(n.engine.block.setString(i,"fill/image/imageFileURI",""),n.engine.block.setSourceSet(i,"fill/image/sourceSet",x)),I?n.engine.block.setContentFillMode(o,"Cover"):h();let D=()=>{if(l==null||l.length===0){if(s==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",s)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",l);h()},O=()=>{if(x==null){if($==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",$)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",x);I?n.engine.block.setContentFillMode(o,"Cover"):h()};return{consumedGenerationResult:e,applyCallbacks:{onBefore:D,onAfter:O,onCancel:()=>{D()},onApply:()=>{O(),t.cesdk.engine.editor.addUndoStep()}}}}async function $5(e,t){throw new Error("Function not implemented.")}async function N5(e,t){throw new Error("Function not implemented.")}async function D5(e,t,n){let r=await(await fetch(t)).blob(),a=new File([r],`image.${L4(n)}`,{type:n}),o=await e.unstable_upload(a,()=>{});return o?.meta?.uri??(console.warn("Failed to upload image:",o),t)}var O5=j5;function _5({editMode:e,automaticallyUnlock:t=!1,showNotification:n=!0}){return async(r,a,o)=>{let i=a.blockIds??a.engine.block.findAllSelected(),l=()=>{};t||a.addDisposer(async()=>{l?.()});try{l=P5(a.engine,i,e);let u=await o(r,a);if(n){let s=a.engine.block.findAllSelected();i.some(c=>s.includes(c))||a.cesdk?.ui.showNotification({type:"success",message:"AI generation complete",action:{label:"Select",onClick:()=>{i.forEach(c=>{a.engine.block.select(c)})}}})}return u}catch(u){throw Ce(u)&&l(),u}finally{t&&l()}}}function P5(e,t,n){function r(){let i=e.block.findAllSelected();return t.some(l=>i.includes(l))}let a=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&r()&&e.editor.setEditMode(n)}),o=e.block.onSelectionChanged(()=>{r()?e.editor.setEditMode(n):e.editor.setEditMode("Transform")});return r()&&e.editor.setEditMode(n),()=>{o(),a(),e.editor.setEditMode("Transform")}}var z5=_5;async function U5(e,t){let{cesdk:n,input:r,blockIds:a,provider:o,quickAction:i,confirmationComponentId:l,abortSignal:u}=e;i.confirmation&&n.ui.setCanvasMenuOrder([l],{editMode:Kr});let s=new Ko(n.engine,Ca);a.forEach(p=>{s.set(p,{status:"processing",quickActionId:i.id})});let c={cesdk:n,engine:n.engine,abortSignal:u},d=ya([...o.output.middleware??[],t.debug?ba():void 0,x5({}),...i.confirmation?[i.lockDuringConfirmation?E5({editMode:Kr}):z5({editMode:Kr}),i.confirmation&&M5({})]:[],t.dryRun?ha({kind:o.kind,blockIds:a}):void 0]),{result:g,dispose:f}=await d(o.output.generate)(r,c),{consumedGenerationResult:v,applyCallbacks:w}=await O5(g,{abortSignal:u,kind:o.kind,blockIds:a,cesdk:n});i.confirmation?a.forEach(p=>{s.set(p,{status:"confirmation",quickActionId:i.id})}):(w.onApply(),a.forEach(p=>{s.clear(p)}));let b=()=>{f(),a.forEach(p=>{s.clear(p)})};return u.addEventListener("abort",b),{dispose:b,returnValue:v,applyCallbacks:w}}var Zo=U5;function V5(e,t){let{cesdk:n,quickActionMenu:r,provider:a}=e,o=`ly.img.ai.${r.id}`,i=`${o}.confirmation`;n.setTranslations({en:{[`${i}.apply`]:"Apply",[`${i}.before`]:"Before",[`${i}.after`]:"After",[`${o}.cancel`]:"Cancel",[`${o}.processing`]:"Generating..."}});let l=`${i}.canvasnMenu`,u={unlock:()=>{},abort:()=>{},applyCallbacks:void 0},s=()=>{let d=new AbortController,g=d.signal;return u.abort=()=>{d.abort()},g};n.ui.registerComponent(l,({builder:d,engine:g,state:f})=>{let v=g.block.findAllSelected();if(v.length===0)return null;let w=new Ko(n.engine,Ca),b=w.get(v[0]);if(b==null)return null;let p=()=>{v.forEach(h=>{w.clear(h)})};switch(b.status){case"processing":{d.Button(`${o}.spinner`,{label:[`ly.img.ai.inference.${b.quickActionId}.processing`,`${o}.cancel`],isLoading:!0}),d.Separator(`${o}.separator`),d.Button(`${o}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.abort(),p()}});break}case"confirmation":{let h=f(`${i}.comparing`,"after"),m=u.applyCallbacks?.onCancel;m!=null&&d.Button(`${i}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.unlock(),m(),p()}});let y=u.applyCallbacks?.onBefore,k=u.applyCallbacks?.onAfter;y!=null&&k!=null&&d.ButtonGroup(`${i}.compare`,{children:()=>{d.Button(`${i}.compare.before`,{label:`${i}.before`,variant:"regular",isActive:h.value==="before",onClick:()=>{y(),h.setValue("before")}}),d.Button(`${i}.compare.after`,{label:`${i}.after`,variant:"regular",isActive:h.value==="after",onClick:()=>{k(),h.setValue("after")}})}});let C=u.applyCallbacks?.onApply;C!=null&&d.Button(`${i}.apply`,{icon:"@imgly/Checkmark",tooltip:`${i}.apply`,color:"accent",isDisabled:h.value!=="after",onClick:()=>{u.unlock(),p(),n.engine.editor._update(),C()}});break}default:}});let c=`${o}.canvasMenu`;return n.ui.registerComponent(c,d=>{let g=d.engine.block.findAllSelected(),f=g.every(m=>d.engine.block.getState(m).type==="Ready"),v=r.getQuickActionMenuOrder().map(m=>{if(m==="ly.img.separator")return m;let y=r.getQuickAction(m);if(y==null||!n.feature.isEnabled(Ma({quickActionId:m,quickActionMenuId:r.id}),{engine:d.engine}))return null;let k=y.scopes;return k!=null&&k.length>0&&!g.every(C=>k.every(M=>d.engine.block.isAllowedByScope(C,M)))?null:y}).filter(m=>m!=null);if(v=w5(v),v.length===0||v.every(m=>m==="ly.img.separator"))return null;let{builder:w,experimental:b,state:p}=d,h=p(`${o}.toggleExpandedState`,void 0);b.builder.Popover(`${o}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!f,trailingIcon:null,children:({close:m})=>{w.Section(`${o}.popover.section`,{children:()=>{if(h.value!=null){let y=h.value,k=r.getQuickAction(y);if(k!=null&&k.renderExpanded!=null){k.renderExpanded(d,{blockIds:g,closeMenu:m,toggleExpand:()=>{h.setValue(void 0)},handleGenerationError:C=>{ft(C,{cesdk:n,provider:a},t)},generate:async(C,M)=>{try{let{returnValue:I,applyCallbacks:x,dispose:$}=await Zo({input:C,quickAction:k,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:M?.blockIds??g,confirmationComponentId:l},t);return u.unlock=$,u.applyCallbacks=x,I}catch(I){throw Ce(I)||ft(I,{cesdk:n,provider:a},t),I}}});return}}b.builder.Menu(`${o}.menu`,{children:()=>{v.forEach(y=>{y==="ly.img.separator"?w.Separator(`${o}.separator.${Math.random().toString()}`):y.render(d,{blockIds:g,closeMenu:m,handleGenerationError:k=>{ft(k,{cesdk:n,provider:a},t)},toggleExpand:()=>{h.setValue(y.id)},generate:async(k,C)=>{try{let{returnValue:M,applyCallbacks:I,dispose:x}=await Zo({input:k,quickAction:y,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:C?.blockIds??g,confirmationComponentId:l},t);return u.unlock=x,u.applyCallbacks=I,M}catch(M){throw Ce(M)||ft(M,{cesdk:n,provider:a},t),M}}})})}})}})}})}),{canvasMenuComponentId:c}}var B5=V5;async function F5(e,t,n){await e.initialize?.(t);let r=await R5(t.engine,e.id,e.output.history??"@imgly/local");if(t.cesdk==null)return{};let a=r?`${e.id}.history.entry`:void 0,o={...t,cesdk:t.cesdk,historyAssetSourceId:r,historyAssetLibraryEntryId:a,i18n:{prompt:"common.ai-generation.prompt.placeholder"}};a!=null&&r!=null&&t.cesdk.ui.addAssetLibraryEntry({id:a,sourceIds:[r],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),t.cesdk.i18n.setTranslations({en:{"common.ai-generation.success":"Generation Successful","common.ai-generation.failed":"Generation Failed","common.ai-generation.generate":"Generate","common.ai-generation.prompt.placeholder":"Describe what you want to create...",[`panel.${e.id}`]:G5(e)}});let i="@imgly/plugin-ai-generation.iconSetAdded";return t.cesdk.ui.experimental.hasGlobalStateValue(i)||(t.cesdk.ui.addIconSet("@imgly/plugin-ai-generation",v5),t.cesdk.ui.experimental.setGlobalStateValue(i,!0)),{renderBuilderFunctions:await q5(e,o,n)}}function G5(e){if(e.name!=null)return e.name;switch(e.kind){case"image":return"Generate Image";case"video":return"Generate Video";case"audio":return"Generate Audio";default:return"Generate Asset"}}async function R5(e,t,n){if(!(n==null||n===!1)){if(n==="@imgly/local"){let r=`${t}.history`;return e.asset.addLocalSource(r),r}if(n==="@imgly/indexedDB"){let r=`${t}.history`;return e.asset.addSource(new $0(r,e)),r}return n}}async function q5(e,t,n){let r={panel:void 0};return e.input?.panel!=null&&(r.panel=await Q5(e,e.input.panel,t,n)),e.input?.quickActions!=null&&(n.debug&&console.log(`Initializing quick actions for provider '${e.kind}' (${e.id})`),H5(e,e.input.quickActions,t,n)),r}async function Q5(e,t,n,r){switch(t.type){case"custom":return b5(e,t,n,r);case"schema":return f5(e,t,n,r);default:r.debug&&console.warn(`Invalid panel input type '${t.type}' - skipping`)}}async function H5(e,t,n,r){let{cesdk:a}=n,o={};t.actions.forEach(i=>{let l=i.kind??e.kind;o[l]==null&&(o[l]=wa(a,l));let u=o[l],s=i.enable??!0;a.feature.enable(Ma({quickActionId:i.id,quickActionMenuId:l}),s),u.registerQuickAction(i),r.debug&&console.log(`Registered quick action: '${i.id}' (v${i.version}) to menu '${l}'`)}),Object.values(o).forEach(i=>{let{canvasMenuComponentId:l}=B5({cesdk:a,quickActionMenu:i,provider:e},r);r.debug&&console.log(`Registered quick action menu component: ${l}`)})}var Wo=F5,Y5="@imgly/plugin-ai-audio-generation-web",pt="ly.img.ai/audio-generation/speech",Kt="ly.img.ai/audio-generation/sound";function Z5(e){return{async initialize({cesdk:t}){if(t==null)return;let n={debug:e.debug??!1,dryRun:e.dryRun??!1,middleware:e.middleware};t.setTranslations({en:{[`panel.${pt}`]:"AI Voice",[`panel.${Kt}`]:"Sound Generation","ly.img.ai.audio-generation.speech.success":"Generation Successful","ly.img.ai.audio-generation.speech.success.action":"Show","ly.img.ai.audio-generation.sound.success":"Sound Generation Successful","ly.img.ai.audio-generation.sound.success.action":"Show"}});let r=e?.text2speech,a=e?.text2sound,o=await r?.({cesdk:t}),i=await a?.({cesdk:t});o!=null&&(o.output.notification={success:{show:()=>!t?.ui.isPanelOpen(pt),message:"ly.img.ai.audio-generation.speech.success",action:{label:"ly.img.ai.audio-generation.speech.success.action",onClick:()=>{t.ui.openPanel(pt)}},duration:"long"}}),i!=null&&(i.output.notification={success:{show:()=>!t?.ui.isPanelOpen(Kt),message:"ly.img.ai.audio-generation.sound.success",action:{label:"ly.img.ai.audio-generation.sound.success.action",onClick:()=>{t.ui.openPanel(Kt)}}}});let l=o!=null?await Wo(o,{cesdk:t,engine:t.engine},n):void 0,u=i!=null?await Wo(i,{cesdk:t,engine:t.engine},n):void 0;u?.renderBuilderFunctions?.panel!=null&&t.ui.registerPanel(Kt,u.renderBuilderFunctions.panel),l?.renderBuilderFunctions?.panel!=null&&(W5(t,s=>{t.ui.openPanel(pt),t.ui.experimental.setGlobalStateValue(`${o?.id}.prompt`,s)}),t.ui.registerPanel(pt,l.renderBuilderFunctions.panel))}}}function W5(e,t){let n=wa(e,"text"),r="generateSpeech";n.registerQuickAction({id:r,version:"1",confirmation:!1,enable:({engine:a})=>{let o=a.block.findAllSelected();if(o.length!==1)return!1;let[i]=o;return a.block.getType(i)==="//ly.img.ubq/text"},render:({builder:a},o)=>{a.Button(r,{icon:"@imgly/Audio",variant:"plain",labelAlignment:"left",label:"AI Voice...",onClick:()=>{let[i]=e.engine.block.findAllSelected(),l=e.engine.block.getString(i,"text/text");t(l),o.closeMenu()}})}}),n.setQuickActionMenuOrder([...n.getQuickActionMenuOrder(),"ly.img.separator",r])}var K5=Z5,J5=e=>({name:Y5,version:"0.1.9",...K5(e)}),Ia=J5;var X5="@imgly/plugin-ai-text-generation",e9=`
273
+ `,s_=l_;function u_(e){return async(t,r,i)=>e.enable?(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await Pd(2e3),await c_(t,e,r)):i(t,r)}async function c_(e,t,r){switch(t.kind){case"image":return d_(e,t,r);case"video":return p_(e,t,r);case"text":return g_(e,t,r);case"audio":return h_(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function d_(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await lE(l,r),s=await aE(u,r);i=s.width,n=s.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
274
+ `,"+")}`}}async function p_(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function g_(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,l=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);l&&l[1]&&(i=l[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=ti(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=ti(n,o)}else"customPrompt"in e?a=ti(n,"custom"):a=ti(n,"improved");else a=ti(n,"generated");return f_(a,r.abortSignal)}async function*f_(e,t){let r=Math.max(1,Math.ceil(e.length/20)),i=0;for(;i<e.length;){if(t?.aborted)return;let n=Math.min(i+r,e.length);yield{kind:"text",text:e.substring(0,n)},i=n,i<e.length&&await Pd(100)}return{kind:"text",text:e}}function ti(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,l="";if(n<=o.length)l=o.substring(0,n);else{l=o;let u=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],s=0;for(;l.length<n;){let c=u[s%u.length];if(l.length+c.length<=n)l+=c;else{l+=c.substring(0,n-l.length);break}s++}}return r+l}async function h_(e,t,r){let i=3;if(e!=null&&typeof e=="object"){if("duration"in e&&typeof e.duration=="number")i=e.duration;else if("prompt"in e&&typeof e.prompt=="string"){let n=e.prompt.match(/(\d+)\s*(?:seconds?|secs?|s)\b/i);n&&(i=parseInt(n[1],10))}}return t.blockInputs?.audio?.duration&&(i=t.blockInputs.audio.duration),{kind:"audio",url:m_(220,i),duration:i,thumbnailUrl:void 0}}function m_(e,t){let r=Math.floor(44100*t),i=new Float32Array(r);for(let n=0;n<r;n++)i[n]=Math.sin(2*Math.PI*e*n/44100);return y_(i,44100)}function y_(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,l=r*i,u=44+l,s=new ArrayBuffer(u),c=new DataView(s),d=(b,m)=>{for(let h=0;h<m.length;h++)c.setUint8(b+h,m.charCodeAt(h))};d(0,"RIFF"),c.setUint32(4,u-8,!0),d(8,"WAVE"),d(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,n,!0),c.setUint32(24,t,!0),c.setUint32(28,o,!0),c.setUint16(32,a,!0),c.setUint16(34,16,!0),d(36,"data"),c.setUint32(40,l,!0);let p=44;for(let b=0;b<r;b++){let m=Math.max(-1,Math.min(1,e[b])),h=Math.round(m*32767);c.setInt16(p,h,!0),p+=2}let g=new Uint8Array(s),f="";for(let b=0;b<g.length;b++)f+=String.fromCharCode(g[b]);return`data:audio/wav;base64,${btoa(f)}`}async function Pd(e){return new Promise(t=>{setTimeout(t,e)})}var b_=u_,v_="USER_CANCEL";function w_(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=pE([...e.provider.output.middleware??[],...r?.middlewares??[],fE({enable:r?.debug}),b_({enable:r?.dryRun,kind:e.provider.kind})]);try{let{result:n}=await i(e.provider.output.generate)(t,{abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk});return r?.abortSignal?.aborted?{status:"aborted"}:n instanceof Error?{status:"error",message:n.message}:n==null?{status:"error",message:"No output generated"}:bE(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return ha(n)?{status:"aborted",message:n.message}:n===v_?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var k_=w_;async function x_(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n};await t.initialize?.({...r,engine:r.cesdk.engine});let o=n_(a),l=a_(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=l;let u=k_({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),s=await r_(a,u);vE(r.cesdk,"@imgly/plugin-ai-generation",s_);let c={provider:t,panel:{builderRenderFunction:s},history:{assetSourceId:o,assetLibraryEntryId:l},generate:u};return dE.get().register(c),c}var ta=x_;function I_(e){let{kind:t,cesdk:r,historAssetSourceIds:i}=e,n=`ly.img.ai.${t}-generation.history`;if(r.engine.asset.findAllSources().includes(n))return n;let a=new uM(n,r,i);return r.engine.asset.addSource(a),a.id}var C_=I_;async function A_(e,t,r,i){let n,a=[];if(Array.isArray(t)){let l=await Promise.all(t.map(u=>ta(e,u,r,i)));a.push(...l),n=j_({prefix:e,providerInitializationResults:a})}else{let l=await Promise.all(t.fromText.map(s=>ta(e,s,r,i)));a.push(...l);let u=await Promise.all(t.fromImage.map(s=>ta(e,s,r,i)));a.push(...u),n=M_({prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u})}let o=C_({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(l=>l.history?.assetSourceId).filter(uE)});return{panel:{builderRenderFunction:n},history:{assetSourceId:o},providerInitializationResults:a}}function M_({prefix:e,initializedFromTextProviders:t,initializedFromImageProviders:r}){let i=t.length>0&&r.length>0;return n=>{let{builder:a,experimental:o}=n,l=o.global(`${e}.fromType`,i?"fromText":void 0),u=[];l.value==="fromText"?u.push(...t):l.value==="fromImage"?u.push(...r):u.push(...t,...r);let s=t.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),c=r.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),d=n.experimental.global(`${e}.selectedProvider.fromText`,s[0]),p=n.experimental.global(`${e}.selectedProvider.fromImage`,c[0]),g=l.value==="fromText"?d:l.value==="fromImage"?p:void 0;if((i||u.length>1)&&a.Section(`${e}.providerSelection.section`,{children:()=>{if(i&&a.ButtonGroup(`${e}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{a.Button(`${e}.fromType.buttonGroup.fromText`,{label:"Text",icon:l.value!=="fromText"&&Xc(t,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromText",onClick:()=>{l.setValue("fromText")}}),a.Button(`${e}.fromType.buttonGroup.fromImage`,{label:"Image",icon:l.value!=="fromImage"&&Xc(r,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromImage",onClick:()=>{l.setValue("fromImage")}})}}),u.length>1){let f=l.value==="fromText"?s:l.value==="fromImage"?c:[...s,...c];g!=null&&a.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:f,...g})}}}),u.length>1)g?.value.builderRenderFunction?.(n);else{let f=u[0];f&&f.panel?.builderRenderFunction?.(n)}}}function j_({prefix:e,providerInitializationResults:t}){return r=>{let{builder:i}=r;if(t.length===0)return;let n=t.map(({provider:o,panel:l})=>({id:o.id,label:o.name??o.id,builderRenderFunction:l?.builderRenderFunction})),a=r.state(`${e}.selectedProvider`,n[0]);t.length>1&&a!=null&&i.Section(`${e}.providerSelection.section`,{children:()=>{i.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:n,...a})}}),a.value.builderRenderFunction?.(r)}}function Xc(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(ya(r.id),!1).value)}var ed=A_,S_=typeof global=="object"&&global&&global.Object===Object&&global,zd=S_,E_=typeof self=="object"&&self&&self.Object===Object&&self,__=zd||E_||Function("return this")(),J=__,L_=J.Symbol,At=L_,Ud=Object.prototype,T_=Ud.hasOwnProperty,$_=Ud.toString,ri=At?At.toStringTag:void 0;function N_(e){var t=T_.call(e,ri),r=e[ri];try{e[ri]=void 0;var i=!0}catch{}var n=$_.call(e);return i&&(t?e[ri]=r:delete e[ri]),n}var O_=N_,D_=Object.prototype,P_=D_.toString;function z_(e){return P_.call(e)}var U_=z_,R_="[object Null]",F_="[object Undefined]",td=At?At.toStringTag:void 0;function V_(e){return e==null?e===void 0?F_:R_:td&&td in Object(e)?O_(e):U_(e)}var pi=V_;function B_(e){return e!=null&&typeof e=="object"}var ba=B_,ZK=Array.isArray;function G_(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Rd=G_,q_="[object AsyncFunction]",Y_="[object Function]",H_="[object GeneratorFunction]",Z_="[object Proxy]";function Q_(e){if(!Rd(e))return!1;var t=pi(e);return t==Y_||t==H_||t==q_||t==Z_}var W_=Q_,K_=J["__core-js_shared__"],ra=K_,rd=function(){var e=/[^.]+$/.exec(ra&&ra.keys&&ra.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function J_(e){return!!rd&&rd in e}var X_=J_,eL=Function.prototype,tL=eL.toString;function rL(e){if(e!=null){try{return tL.call(e)}catch{}try{return e+""}catch{}}return""}var Ee=rL,iL=/[\\^$.*+?()[\]{}|]/g,nL=/^\[object .+?Constructor\]$/,oL=Function.prototype,aL=Object.prototype,lL=oL.toString,sL=aL.hasOwnProperty,uL=RegExp("^"+lL.call(sL).replace(iL,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function cL(e){if(!Rd(e)||X_(e))return!1;var t=W_(e)?uL:nL;return t.test(Ee(e))}var dL=cL;function pL(e,t){return e?.[t]}var gL=pL;function fL(e,t){var r=gL(e,t);return dL(r)?r:void 0}var _t=fL,hL=_t(J,"WeakMap"),ua=hL;function mL(e,t){return e===t||e!==e&&t!==t}var yL=mL,bL=9007199254740991;function vL(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=bL}var wL=vL,QK=Object.prototype,kL="[object Arguments]";function xL(e){return ba(e)&&pi(e)==kL}var id=xL,Fd=Object.prototype,IL=Fd.hasOwnProperty,CL=Fd.propertyIsEnumerable,WK=id(function(){return arguments}())?id:function(e){return ba(e)&&IL.call(e,"callee")&&!CL.call(e,"callee")},Vd=typeof exports=="object"&&exports&&!exports.nodeType&&exports,nd=Vd&&typeof module=="object"&&module&&!module.nodeType&&module,AL=nd&&nd.exports===Vd,od=AL?J.Buffer:void 0,KK=od?od.isBuffer:void 0,ML="[object Arguments]",jL="[object Array]",SL="[object Boolean]",EL="[object Date]",_L="[object Error]",LL="[object Function]",TL="[object Map]",$L="[object Number]",NL="[object Object]",OL="[object RegExp]",DL="[object Set]",PL="[object String]",zL="[object WeakMap]",UL="[object ArrayBuffer]",RL="[object DataView]",FL="[object Float32Array]",VL="[object Float64Array]",BL="[object Int8Array]",GL="[object Int16Array]",qL="[object Int32Array]",YL="[object Uint8Array]",HL="[object Uint8ClampedArray]",ZL="[object Uint16Array]",QL="[object Uint32Array]",T={};T[FL]=T[VL]=T[BL]=T[GL]=T[qL]=T[YL]=T[HL]=T[ZL]=T[QL]=!0;T[ML]=T[jL]=T[UL]=T[SL]=T[RL]=T[EL]=T[_L]=T[LL]=T[TL]=T[$L]=T[NL]=T[OL]=T[DL]=T[PL]=T[zL]=!1;function WL(e){return ba(e)&&wL(e.length)&&!!T[pi(e)]}var KL=WL;function JL(e){return function(t){return e(t)}}var XL=JL,Bd=typeof exports=="object"&&exports&&!exports.nodeType&&exports,oi=Bd&&typeof module=="object"&&module&&!module.nodeType&&module,eT=oi&&oi.exports===Bd,ia=eT&&zd.process,tT=function(){try{var e=oi&&oi.require&&oi.require("util").types;return e||ia&&ia.binding&&ia.binding("util")}catch{}}(),ad=tT,ld=ad&&ad.isTypedArray,JK=ld?XL(ld):KL,rT=Object.prototype,XK=rT.hasOwnProperty;function iT(e,t){return function(r){return e(t(r))}}var nT=iT,eJ=nT(Object.keys,Object),oT=Object.prototype,tJ=oT.hasOwnProperty,aT=_t(Object,"create"),si=aT;function lT(){this.__data__=si?si(null):{},this.size=0}var sT=lT;function uT(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var cT=uT,dT="__lodash_hash_undefined__",pT=Object.prototype,gT=pT.hasOwnProperty;function fT(e){var t=this.__data__;if(si){var r=t[e];return r===dT?void 0:r}return gT.call(t,e)?t[e]:void 0}var hT=fT,mT=Object.prototype,yT=mT.hasOwnProperty;function bT(e){var t=this.__data__;return si?t[e]!==void 0:yT.call(t,e)}var vT=bT,wT="__lodash_hash_undefined__";function kT(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=si&&t===void 0?wT:t,this}var xT=kT;function Lt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Lt.prototype.clear=sT;Lt.prototype.delete=cT;Lt.prototype.get=hT;Lt.prototype.has=vT;Lt.prototype.set=xT;var sd=Lt;function IT(){this.__data__=[],this.size=0}var CT=IT;function AT(e,t){for(var r=e.length;r--;)if(yL(e[r][0],t))return r;return-1}var bn=AT,MT=Array.prototype,jT=MT.splice;function ST(e){var t=this.__data__,r=bn(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():jT.call(t,r,1),--this.size,!0}var ET=ST;function _T(e){var t=this.__data__,r=bn(t,e);return r<0?void 0:t[r][1]}var LT=_T;function TT(e){return bn(this.__data__,e)>-1}var $T=TT;function NT(e,t){var r=this.__data__,i=bn(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var OT=NT;function Tt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Tt.prototype.clear=CT;Tt.prototype.delete=ET;Tt.prototype.get=LT;Tt.prototype.has=$T;Tt.prototype.set=OT;var vn=Tt,DT=_t(J,"Map"),ui=DT;function PT(){this.size=0,this.__data__={hash:new sd,map:new(ui||vn),string:new sd}}var zT=PT;function UT(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var RT=UT;function FT(e,t){var r=e.__data__;return RT(t)?r[typeof t=="string"?"string":"hash"]:r.map}var wn=FT;function VT(e){var t=wn(this,e).delete(e);return this.size-=t?1:0,t}var BT=VT;function GT(e){return wn(this,e).get(e)}var qT=GT;function YT(e){return wn(this,e).has(e)}var HT=YT;function ZT(e,t){var r=wn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var QT=ZT;function $t(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}$t.prototype.clear=zT;$t.prototype.delete=BT;$t.prototype.get=qT;$t.prototype.has=HT;$t.prototype.set=QT;var Gd=$t;function WT(){this.__data__=new vn,this.size=0}var KT=WT;function JT(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var XT=JT;function e$(e){return this.__data__.get(e)}var t$=e$;function r$(e){return this.__data__.has(e)}var i$=r$,n$=200;function o$(e,t){var r=this.__data__;if(r instanceof vn){var i=r.__data__;if(!ui||i.length<n$-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Gd(i)}return r.set(e,t),this.size=r.size,this}var a$=o$;function gi(e){var t=this.__data__=new vn(e);this.size=t.size}gi.prototype.clear=KT;gi.prototype.delete=XT;gi.prototype.get=t$;gi.prototype.has=i$;gi.prototype.set=a$;var l$=Object.prototype,rJ=l$.propertyIsEnumerable,s$=_t(J,"DataView"),ca=s$,u$=_t(J,"Promise"),da=u$,c$=_t(J,"Set"),pa=c$,ud="[object Map]",d$="[object Object]",cd="[object Promise]",dd="[object Set]",pd="[object WeakMap]",gd="[object DataView]",p$=Ee(ca),g$=Ee(ui),f$=Ee(da),h$=Ee(pa),m$=Ee(ua),kt=pi;(ca&&kt(new ca(new ArrayBuffer(1)))!=gd||ui&&kt(new ui)!=ud||da&&kt(da.resolve())!=cd||pa&&kt(new pa)!=dd||ua&&kt(new ua)!=pd)&&(kt=function(e){var t=pi(e),r=t==d$?e.constructor:void 0,i=r?Ee(r):"";if(i)switch(i){case p$:return gd;case g$:return ud;case f$:return cd;case h$:return dd;case m$:return pd}return t});var iJ=J.Uint8Array,y$="__lodash_hash_undefined__";function b$(e){return this.__data__.set(e,y$),this}var v$=b$;function w$(e){return this.__data__.has(e)}var k$=w$;function ga(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Gd;++t<r;)this.add(e[t])}ga.prototype.add=ga.prototype.push=v$;ga.prototype.has=k$;var fd=At?At.prototype:void 0,nJ=fd?fd.valueOf:void 0,x$=Object.prototype,oJ=x$.hasOwnProperty,I$=Object.prototype,aJ=I$.hasOwnProperty,lJ=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),sJ=new RegExp(/[A-Fa-f0-9]{1}/,"g"),uJ=new RegExp(/[A-Fa-f0-9]{2}/,"g");function C$(e){return e==null?[]:Array.isArray(e)?e:[e]}var hd=C$,xt="@imgly/plugin-ai-audio-generation-web",Me="ly.img.ai.audio-generation.speech",je="ly.img.ai.audio-generation.sound";function A$(e){return{async initialize({cesdk:t}){if(t==null)return;wE(t,xt,"0.2.0"),t.setTranslations({en:{[`panel.${Me}`]:"AI Voice",[`panel.${je}`]:"Sound Generation"}}),M$(e);let r=cE.get(),i=r.register({type:"plugin",sceneMode:"Video",id:`${xt}/sound`,pluginId:xt,label:"Generate Sound",meta:{panelId:je},execute:()=>{t.ui.isPanelOpen(je)?t.ui.closePanel(je):t.ui.openPanel(je)}}),n=r.register({type:"plugin",sceneMode:"Video",id:`${xt}/speech`,pluginId:xt,label:"AI Voice",meta:{panelId:Me},execute:()=>{t.ui.isPanelOpen(Me)?t.ui.closePanel(Me):t.ui.openPanel(Me)}}),a=e.providers?.text2speech??e.text2speech,o=e.providers?.text2sound??e.text2sound,l=await Promise.all(hd(a).map(d=>d({cesdk:t}))),u=await Promise.all(hd(o).map(d=>d({cesdk:t}))),s=await ed("audio",l,{cesdk:t},e),c=await ed("audio",u,{cesdk:t},e);c.panel.builderRenderFunction!=null?(t.ui.registerPanel(je,c.panel.builderRenderFunction),Kc({cesdk:t,panelId:je})):i(),s.panel.builderRenderFunction!=null?(t.ui.registerPanel(Me,s.panel.builderRenderFunction),Kc({cesdk:t,panelId:Me})):n()}}}function M$(e){e.debug&&(e.providers?.text2speech!=null&&e.text2speech!=null&&console.warn("[AudioGeneration]: Both `providers.text2speech` and `text2speech` configuration is provided. Since `text2speech` is deprecated, only `providers.text2speech` will be used."),e.providers?.text2sound!=null&&e.text2sound!=null&&console.warn("[AudioGeneration]: Both `providers.text2sound` and `text2sound` configuration is provided. Since `text2sound` is deprecated, only `providers.text2sound` will be used."))}var j$=A$,S$=e=>({name:xt,version:"0.2.0",...j$(e)}),qd=S$;var E$="@imgly/plugin-ai-text-generation",_$=`
263
275
  <svg>
264
276
  <symbol
265
277
  fill="none"
@@ -335,8 +347,10 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
335
347
  <path d="M3.72318 6.44728C3.63105 6.26302 3.3681 6.26302 3.27597 6.44728L3.03684 6.92554C3.01265 6.97392 2.97343 7.01314 2.92505 7.03733L2.44677 7.27652C2.26252 7.36866 2.26254 7.63161 2.44681 7.72373L2.92503 7.9628C2.97342 7.98699 3.01266 8.02622 3.03685 8.07461L3.27597 8.55285C3.3681 8.73711 3.63105 8.73711 3.72318 8.55285L3.96231 8.0746C3.9865 8.02622 4.02573 7.98699 4.07411 7.9628L4.55236 7.72367C4.73663 7.63154 4.73663 7.36859 4.55236 7.27646L4.07411 7.03733C4.02573 7.01314 3.9865 6.97391 3.96231 6.92553L3.72318 6.44728Z" fill="currentColor"/>
336
348
  </symbol>
337
349
  </svg>
338
- `,t9=e9,r9=class{constructor(e,t,n){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=n?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=n?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let n=indexedDB.open(this.dbName,this.dbVersion);n.onerror=r=>{t(new Error(`Failed to open IndexedDB: ${r.target.error}`))},n.onupgradeneeded=r=>{let a=r.target.result;a.objectStoreNames.contains(this.assetStoreName)||a.createObjectStore(this.assetStoreName,{keyPath:"id"}),a.objectStoreNames.contains(this.blobStoreName)||a.createObjectStore(this.blobStoreName,{keyPath:"id"})},n.onsuccess=r=>{this.db=r.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",g=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(g=s.tags[c]);let f={...s,label:d,tags:g};return this.filterAsset(f,e)&&u.push(f),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:n,perPage:r}=e,a=n*r,o=a+r,i=t.slice(a,o),l=o<t.length?n+1:void 0;return{assets:i,currentPage:n,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let n=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();n.onsuccess=()=>{let r=new Set;n.result.forEach(o=>{o.groups&&Array.isArray(o.groups)&&o.groups.forEach(i=>r.add(i))});let a=[...r];e(a)},n.onerror=()=>{t(new Error(`Failed to get groups: ${n.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),n=t.objectStore(this.assetStoreName),r=new Set;Ee(e,o=>{r.add(o)}),setTimeout(()=>{this.storeBlobUrls([...r])});let a={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};n.put(a),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.assetStoreName,"readwrite");n.objectStore(this.assetStoreName).delete(e),n.oncomplete=()=>{Ee(t,r=>{this.removeBlob(r)}),this.engine.asset.assetSourceContentsChanged(this.id)},n.onerror=()=>{console.error(`Failed to remove asset: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let a=r.result;a.sort((o,i)=>{let l=o.meta?.insertedAt||o._insertedAt||Date.now(),u=i.meta?.insertedAt||i._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(a)},r.onerror=()=>{n(new Error(`Failed to get assets: ${r.error}`))}})}async getAsset(e){return new Promise((t,n)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async getBlob(e){return new Promise((t,n)=>{let r=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);r.onsuccess=()=>{t(r.result)},r.onerror=()=>{n(new Error(`Failed to get blob: ${r.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async n=>{let r=await(await fetch(n)).blob();t[n]=r})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.blobStoreName,"readwrite"),r=n.objectStore(this.blobStoreName);Object.entries(t).forEach(([a,o])=>{let i={id:a,blob:o};r.put(i)}),n.onerror=()=>{console.error(`Failed to add blobs: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async restoreBlobUrls(e){let t={},n=new Set;return Ee(e,r=>{n.add(r)}),await Promise.all([...n].map(async r=>{let a=await this.createBlobUrlFromStore(r);t[r]=a})),Ee(e,r=>t[r]??r)}filterAsset(e,t){let{query:n,tags:r,groups:a,excludeGroups:o}=t;if(n&&n.trim()!==""){let i=n.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!i.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(r){let i=Array.isArray(r)?r:[r];if(i.length>0&&(!e.tags||!i.every(l=>e.tags?.includes(l))))return!1}return!(a&&a.length>0&&(!e.groups||!a.some(i=>e.groups?.includes(i)))||o&&o.length>0&&e.groups&&e.groups.some(i=>o.includes(i)))}sortAssets(e,t){let{sortingOrder:n,sortKey:r,sortActiveFirst:a}=t,o=[...e];return!n||n==="None"||(r?o.sort((i,l)=>{let u,s;return r==="id"?(u=i.id,s=l.id):(u=i.meta?.[r]??null,s=l.meta?.[r]??null),u==null?n==="Ascending"?-1:1:s==null?n==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?n==="Ascending"?u.localeCompare(s):s.localeCompare(u):n==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):n==="Descending"&&o.reverse(),a&&o.sort((i,l)=>i.active&&!l.active?-1:!i.active&&l.active?1:0)),o}};function Ee(e,t,n=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let r=0;r<e.length;r++){let a=n?`${n}[${r}]`:`[${r}]`;if(typeof e[r]=="string"&&e[r].startsWith("blob:")){let o=t(e[r],a);typeof o=="string"&&(e[r]=o)}else e[r]=Ee(e[r],t,a)}return e}for(let r in e)if(Object.prototype.hasOwnProperty.call(e,r)){let a=e[r],o=n?`${n}.${r}`:r;if(typeof a=="string"&&a.startsWith("blob:")){let i=t(a,o);typeof i=="string"&&(e[r]=i)}else e[r]=Ee(a,t,o)}return e}var n9=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},Fa=n9,i9=typeof global=="object"&&global&&global.Object===Object&&global,Ga=i9,o9=typeof self=="object"&&self&&self.Object===Object&&self,a9=Ga||o9||Function("return this")(),F=a9,l9=F.Symbol,je=l9,Ra=Object.prototype,s9=Ra.hasOwnProperty,u9=Ra.toString,wt=je?je.toStringTag:void 0;function c9(e){var t=s9.call(e,wt),n=e[wt];try{e[wt]=void 0;var r=!0}catch{}var a=u9.call(e);return r&&(t?e[wt]=n:delete e[wt]),a}var d9=c9,g9=Object.prototype,p9=g9.toString;function m9(e){return p9.call(e)}var f9=m9,y9="[object Null]",b9="[object Undefined]",xa=je?je.toStringTag:void 0;function h9(e){return e==null?e===void 0?b9:y9:xa&&xa in Object(e)?d9(e):f9(e)}var Et=h9;function v9(e){return e!=null&&typeof e=="object"}var hn=v9,qC=Array.isArray;function k9(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var qa=k9,w9="[object AsyncFunction]",C9="[object Function]",M9="[object GeneratorFunction]",I9="[object Proxy]";function x9(e){if(!qa(e))return!1;var t=Et(e);return t==C9||t==M9||t==w9||t==I9}var A9=x9,S9=F["__core-js_shared__"],ln=S9,Aa=function(){var e=/[^.]+$/.exec(ln&&ln.keys&&ln.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function E9(e){return!!Aa&&Aa in e}var j9=E9,L9=Function.prototype,T9=L9.toString;function $9(e){if(e!=null){try{return T9.call(e)}catch{}try{return e+""}catch{}}return""}var Y=$9,N9=/[\\^$.*+?()[\]{}|]/g,D9=/^\[object .+?Constructor\]$/,O9=Function.prototype,_9=Object.prototype,P9=O9.toString,z9=_9.hasOwnProperty,U9=RegExp("^"+P9.call(z9).replace(N9,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function V9(e){if(!qa(e)||j9(e))return!1;var t=A9(e)?U9:D9;return t.test(Y(e))}var B9=V9;function F9(e,t){return e?.[t]}var G9=F9;function R9(e,t){var n=G9(e,t);return B9(n)?n:void 0}var Te=R9,q9=Te(F,"WeakMap"),gn=q9;function Q9(e,t){return e===t||e!==e&&t!==t}var H9=Q9,Y9=9007199254740991;function Z9(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Y9}var W9=Z9,QC=Object.prototype,K9="[object Arguments]";function J9(e){return hn(e)&&Et(e)==K9}var Sa=J9,Qa=Object.prototype,X9=Qa.hasOwnProperty,e3=Qa.propertyIsEnumerable,HC=Sa(function(){return arguments}())?Sa:function(e){return hn(e)&&X9.call(e,"callee")&&!e3.call(e,"callee")},Ha=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ea=Ha&&typeof module=="object"&&module&&!module.nodeType&&module,t3=Ea&&Ea.exports===Ha,ja=t3?F.Buffer:void 0,YC=ja?ja.isBuffer:void 0,r3="[object Arguments]",n3="[object Array]",i3="[object Boolean]",o3="[object Date]",a3="[object Error]",l3="[object Function]",s3="[object Map]",u3="[object Number]",c3="[object Object]",d3="[object RegExp]",g3="[object Set]",p3="[object String]",m3="[object WeakMap]",f3="[object ArrayBuffer]",y3="[object DataView]",b3="[object Float32Array]",h3="[object Float64Array]",v3="[object Int8Array]",k3="[object Int16Array]",w3="[object Int32Array]",C3="[object Uint8Array]",M3="[object Uint8ClampedArray]",I3="[object Uint16Array]",x3="[object Uint32Array]",L={};L[b3]=L[h3]=L[v3]=L[k3]=L[w3]=L[C3]=L[M3]=L[I3]=L[x3]=!0;L[r3]=L[n3]=L[f3]=L[i3]=L[y3]=L[o3]=L[a3]=L[l3]=L[s3]=L[u3]=L[c3]=L[d3]=L[g3]=L[p3]=L[m3]=!1;function A3(e){return hn(e)&&W9(e.length)&&!!L[Et(e)]}var S3=A3;function E3(e){return function(t){return e(t)}}var j3=E3,Ya=typeof exports=="object"&&exports&&!exports.nodeType&&exports,xt=Ya&&typeof module=="object"&&module&&!module.nodeType&&module,L3=xt&&xt.exports===Ya,sn=L3&&Ga.process,T3=function(){try{var e=xt&&xt.require&&xt.require("util").types;return e||sn&&sn.binding&&sn.binding("util")}catch{}}(),La=T3,Ta=La&&La.isTypedArray,ZC=Ta?j3(Ta):S3,$3=Object.prototype,WC=$3.hasOwnProperty;function N3(e,t){return function(n){return e(t(n))}}var D3=N3,KC=D3(Object.keys,Object),O3=Object.prototype,JC=O3.hasOwnProperty,_3=Te(Object,"create"),At=_3;function P3(){this.__data__=At?At(null):{},this.size=0}var z3=P3;function U3(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var V3=U3,B3="__lodash_hash_undefined__",F3=Object.prototype,G3=F3.hasOwnProperty;function R3(e){var t=this.__data__;if(At){var n=t[e];return n===B3?void 0:n}return G3.call(t,e)?t[e]:void 0}var q3=R3,Q3=Object.prototype,H3=Q3.hasOwnProperty;function Y3(e){var t=this.__data__;return At?t[e]!==void 0:H3.call(t,e)}var Z3=Y3,W3="__lodash_hash_undefined__";function K3(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=At&&t===void 0?W3:t,this}var J3=K3;function $e(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}$e.prototype.clear=z3;$e.prototype.delete=V3;$e.prototype.get=q3;$e.prototype.has=Z3;$e.prototype.set=J3;var $a=$e;function X3(){this.__data__=[],this.size=0}var e7=X3;function t7(e,t){for(var n=e.length;n--;)if(H9(e[n][0],t))return n;return-1}var rr=t7,r7=Array.prototype,n7=r7.splice;function i7(e){var t=this.__data__,n=rr(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():n7.call(t,n,1),--this.size,!0}var o7=i7;function a7(e){var t=this.__data__,n=rr(t,e);return n<0?void 0:t[n][1]}var l7=a7;function s7(e){return rr(this.__data__,e)>-1}var u7=s7;function c7(e,t){var n=this.__data__,r=rr(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var d7=c7;function Ne(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ne.prototype.clear=e7;Ne.prototype.delete=o7;Ne.prototype.get=l7;Ne.prototype.has=u7;Ne.prototype.set=d7;var nr=Ne,g7=Te(F,"Map"),St=g7;function p7(){this.size=0,this.__data__={hash:new $a,map:new(St||nr),string:new $a}}var m7=p7;function f7(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var y7=f7;function b7(e,t){var n=e.__data__;return y7(t)?n[typeof t=="string"?"string":"hash"]:n.map}var ir=b7;function h7(e){var t=ir(this,e).delete(e);return this.size-=t?1:0,t}var v7=h7;function k7(e){return ir(this,e).get(e)}var w7=k7;function C7(e){return ir(this,e).has(e)}var M7=C7;function I7(e,t){var n=ir(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var x7=I7;function De(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}De.prototype.clear=m7;De.prototype.delete=v7;De.prototype.get=w7;De.prototype.has=M7;De.prototype.set=x7;var Za=De;function A7(){this.__data__=new nr,this.size=0}var S7=A7;function E7(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var j7=E7;function L7(e){return this.__data__.get(e)}var T7=L7;function $7(e){return this.__data__.has(e)}var N7=$7,D7=200;function O7(e,t){var n=this.__data__;if(n instanceof nr){var r=n.__data__;if(!St||r.length<D7-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Za(r)}return n.set(e,t),this.size=n.size,this}var _7=O7;function jt(e){var t=this.__data__=new nr(e);this.size=t.size}jt.prototype.clear=S7;jt.prototype.delete=j7;jt.prototype.get=T7;jt.prototype.has=N7;jt.prototype.set=_7;var P7=Object.prototype,XC=P7.propertyIsEnumerable,z7=Te(F,"DataView"),pn=z7,U7=Te(F,"Promise"),mn=U7,V7=Te(F,"Set"),fn=V7,Na="[object Map]",B7="[object Object]",Da="[object Promise]",Oa="[object Set]",_a="[object WeakMap]",Pa="[object DataView]",F7=Y(pn),G7=Y(St),R7=Y(mn),q7=Y(fn),Q7=Y(gn),Se=Et;(pn&&Se(new pn(new ArrayBuffer(1)))!=Pa||St&&Se(new St)!=Na||mn&&Se(mn.resolve())!=Da||fn&&Se(new fn)!=Oa||gn&&Se(new gn)!=_a)&&(Se=function(e){var t=Et(e),n=t==B7?e.constructor:void 0,r=n?Y(n):"";if(r)switch(r){case F7:return Pa;case G7:return Na;case R7:return Da;case q7:return Oa;case Q7:return _a}return t});var eM=F.Uint8Array,H7="__lodash_hash_undefined__";function Y7(e){return this.__data__.set(e,H7),this}var Z7=Y7;function W7(e){return this.__data__.has(e)}var K7=W7;function yn(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Za;++t<n;)this.add(e[t])}yn.prototype.add=yn.prototype.push=Z7;yn.prototype.has=K7;var za=je?je.prototype:void 0,tM=za?za.valueOf:void 0,J7=Object.prototype,rM=J7.hasOwnProperty,X7=Object.prototype,nM=X7.hasOwnProperty,iM=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),oM=new RegExp(/[A-Fa-f0-9]{1}/,"g"),aM=new RegExp(/[A-Fa-f0-9]{2}/,"g");function e8(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function Wa(e,t){if(e.startsWith("buffer:")){let n=await t.editor.getMimeType(e),r=t.editor.getBufferLength(e),a=t.editor.getBufferData(e,0,r),o=new Blob([a],{type:n});return URL.createObjectURL(o)}else return e}async function bn(e,t){let n=await Wa(e,t);return new Promise((r,a)=>{let o=new Image;o.onload=()=>{r({width:o.width,height:o.height})},o.onerror=a,o.src=n})}async function t8(e,t,n){let r,a=t.block.getFill(e),o=t.block.getSourceSet(a,"fill/image/sourceSet"),[i]=o;if(i==null){if(r=t.block.getString(a,"fill/image/imageFileURI"),r==null)throw new Error("No image source/uri found")}else r=i.uri;if(n?.throwErrorIfSvg&&await t.editor.getMimeType(r)==="image/svg+xml")throw new Error("SVG images are not supported");return Wa(r,t)}function Ka(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let n=t.substring(2).split("/"),r=e;for(let a of n){if(r==null)throw new Error(`Invalid reference path: ${t}`);r=r[a]}if(r===void 0)throw new Error(`Reference not found: ${t}`);return r}function Mt(e,t,n=new Set){if(t==null||n.has(t))return t;if(n.add(t),t.$ref&&typeof t.$ref=="string"){let r=Ka(e,t.$ref),a={...Mt(e,r,n)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(a[o]=Mt(e,t[o],n));return a}if(Array.isArray(t))return t.map(r=>Mt(e,r,n));if(typeof t=="object"){let r={};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=Mt(e,t[a],n));return r}return t}function r8(e){return Mt(e,{...e})}function n8(e,t=!1){let n=i=>(t&&console.log(`OpenAPI Schema validation failed: ${i}`),!1);if(typeof e!="object"||e===null)return n(`Input is ${e===null?"null":typeof e}, not an object`);let r=e;if(!(typeof r.type=="string"||Array.isArray(r.enum)||typeof r.properties=="object"||typeof r.items=="object"||typeof r.allOf=="object"||typeof r.anyOf=="object"||typeof r.oneOf=="object"||typeof r.not=="object"))return n("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(r.type!==void 0){let i=["string","number","integer","boolean","array","object","null"];if(typeof r.type=="string"){if(!i.includes(r.type))return n(`Invalid type: ${r.type}. Must be one of ${i.join(", ")}`)}else if(Array.isArray(r.type)){for(let l of r.type)if(typeof l!="string"||!i.includes(l))return n(`Array of types contains invalid value: ${l}. Must be one of ${i.join(", ")}`)}else return n(`Type must be a string or array of strings, got ${typeof r.type}`)}if(r.items!==void 0&&(typeof r.items!="object"||r.items===null))return n(`Items must be an object, got ${r.items===null?"null":typeof r.items}`);if(r.properties!==void 0&&(typeof r.properties!="object"||r.properties===null))return n(`Properties must be an object, got ${r.properties===null?"null":typeof r.properties}`);let a=["allOf","anyOf","oneOf"];for(let i of a)if(r[i]!==void 0){if(!Array.isArray(r[i]))return n(`${i} must be an array, got ${typeof r[i]}`);for(let l=0;l<r[i].length;l++){let u=r[i][l];if(typeof u!="object"||u===null)return n(`Item ${l} in ${i} must be an object, got ${u===null?"null":typeof u}`)}}if(r.not!==void 0&&(typeof r.not!="object"||r.not===null))return n(`'not' must be an object, got ${r.not===null?"null":typeof r.not}`);if(r.additionalProperties!==void 0&&typeof r.additionalProperties!="boolean"&&(typeof r.additionalProperties!="object"||r.additionalProperties===null))return n(`additionalProperties must be a boolean or an object, got ${r.additionalProperties===null?"null":typeof r.additionalProperties}`);if(r.format!==void 0&&typeof r.format!="string")return n(`format must be a string, got ${typeof r.format}`);let o=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let i of o)if(r[i]!==void 0&&typeof r[i]!="number")return n(`${i} must be a number, got ${typeof r[i]}`);if(r.minLength!==void 0&&(typeof r.minLength!="number"||r.minLength<0))return n(`minLength must be a non-negative number, got ${typeof r.minLength=="number"?r.minLength:typeof r.minLength}`);if(r.maxLength!==void 0&&(typeof r.maxLength!="number"||r.maxLength<0))return n(`maxLength must be a non-negative number, got ${typeof r.maxLength=="number"?r.maxLength:typeof r.maxLength}`);if(r.pattern!==void 0&&typeof r.pattern!="string")return n(`pattern must be a string, got ${typeof r.pattern}`);if(r.minItems!==void 0&&(typeof r.minItems!="number"||r.minItems<0))return n(`minItems must be a non-negative number, got ${typeof r.minItems=="number"?r.minItems:typeof r.minItems}`);if(r.maxItems!==void 0&&(typeof r.maxItems!="number"||r.maxItems<0))return n(`maxItems must be a non-negative number, got ${typeof r.maxItems=="number"?r.maxItems:typeof r.maxItems}`);if(r.uniqueItems!==void 0&&typeof r.uniqueItems!="boolean")return n(`uniqueItems must be a boolean, got ${typeof r.uniqueItems}`);if(r.minProperties!==void 0&&(typeof r.minProperties!="number"||r.minProperties<0))return n(`minProperties must be a non-negative number, got ${typeof r.minProperties=="number"?r.minProperties:typeof r.minProperties}`);if(r.maxProperties!==void 0&&(typeof r.maxProperties!="number"||r.maxProperties<0))return n(`maxProperties must be a non-negative number, got ${typeof r.maxProperties=="number"?r.maxProperties:typeof r.maxProperties}`);if(r.required!==void 0){if(!Array.isArray(r.required))return n(`required must be an array, got ${typeof r.required}`);for(let i=0;i<r.required.length;i++){let l=r.required[i];if(typeof l!="string")return n(`Item ${i} in required array must be a string, got ${typeof l}`)}}return!0}function i8(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let n=e.properties,r=[];return o8(e,t).forEach(a=>{let o=a,i=n[a]??void 0;r.push({id:o,schema:i})}),r}function o8(e,t){let n=t.order;if(n!=null&&Array.isArray(n))return n;if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,a=Object.keys(r),o=a8(e,t)??a;return n!=null&&typeof n=="function"&&(o=n(o)),[...new Set(o)]}function a8(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let n=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(r=>r in e);return n==null?void 0:e[n]}var Ja=i8,l8="ly.img.ai",un="ly.img.ai/temp";async function s8(e,t){return e.engine.asset.findAllSources().includes(un)||e.engine.asset.addLocalSource(un),e.engine.asset.apply(un,t)}function Xa(e){return`${l8}/${e}`}function u8(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let n=e;return"message"in n&&typeof n.message=="string"?n.message:"cause"in n&&typeof n.cause=="string"?n.cause:"detail"in n&&typeof n.detail=="object"&&n.detail!==null&&"message"in n.detail&&typeof n.detail.message=="string"?n.detail.message:"error"in n&&typeof n.error=="object"&&n.error!==null&&"message"in n.error&&typeof n.error.message=="string"?n.error.message:t}return typeof e=="string"?e:String(e)||t}function c8(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function d8(e,t=0,n="image/jpeg",r=.8){return new Promise((a,o)=>{try{let i=document.createElement("video");i.crossOrigin="anonymous",i.style.display="none",i.addEventListener("loadedmetadata",()=>{i.currentTime=Math.min(t,i.duration),i.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=i.videoWidth,l.height=i.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(i),o(new Error("Failed to create canvas context"));return}u.drawImage(i,0,0,l.width,l.height);try{let s=l.toDataURL(n,r);document.body.removeChild(i),a(s)}catch(s){document.body.removeChild(i),o(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),i.addEventListener("error",()=>{document.body.removeChild(i),o(new Error(`Failed to load video from ${e}`))}),i.src=e,document.body.appendChild(i)}catch(i){o(i)}})}function el(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function vn(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function Le(e){return e instanceof Error&&e.name==="AbortError"}function tl(e,t,n,r,a,o){if(t.schema==null)return r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null?r.renderCustomProperty[t.id](e,t):void 0;let i=t,l=t.schema.type;if(r.renderCustomProperty!=null&&r.renderCustomProperty[t.id]!=null)return r.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?g8(e,i,n,r,a,o):nl(e,i,n,r,a,o);case"boolean":return il(e,i,n,r,a,o);case"number":case"integer":return ol(e,i,n,r,a,o);case"object":return rl(e,i,n,r,a,o);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return p8(e,i,n,r,a,o);break}default:console.error(`Unsupported property type: ${l}`)}}function rl(e,t,n,r,a,o){let i=Ja(t.schema??{},r).reduce((l,u)=>{let s=tl(e,u,n,r,a,o);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:i})}function nl(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),g=m8(t.schema),f=g?.component!=null&&g?.component==="TextArea"?"TextArea":"TextInput";return i[f](s,{inputLabel:c,placeholder:a.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function g8(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},g="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},f=(t.schema.enum??[]).map(b=>({id:b,label:d[b]??el(b),icon:g[b]})),v=t.schema.default!=null?f.find(b=>b.id===t.schema.default)??f[0]:f[0],w=l(s,v);return i.Select(s,{inputLabel:c,values:f,...w}),()=>({id:t.id,type:"string",value:w.value.id})}function il(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,g=l(s,d);return i.Checkbox(s,{inputLabel:c,...g}),()=>({id:t.id,type:"boolean",value:g.value})}function ol(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,g=t.schema.maximum,f=t.schema.default;f==null&&(d!=null?f=d:g!=null?f=g:f=0);let v=l(s,f);if(d!=null&&g!=null){let w=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(w=t.schema["x-imgly-step"]),i.Slider(s,{inputLabel:c,min:d,max:g,step:w,...v})}else i.NumberInput(s,{inputLabel:c,min:d,max:g,...v});return()=>({id:t.id,type:"integer",value:v.value})}function p8(e,t,n,r,a,o){let{builder:i,experimental:{global:l}}=e,{id:u}=t,s=`${n.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],g=[],f={},v={};d.forEach((p,h)=>{let m=p.title??"common.custom",y=`${n.id}.${u}.anyOf[${h}]`,k="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},C="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};p.type==="string"?p.enum!=null?p.enum.forEach(M=>{g.push({id:M,label:k[M]??el(M),icon:C[M]})}):(f[y]=()=>nl(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="boolean"?(f[y]=()=>il(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="integer"?(f[y]=()=>ol(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]})):p.type==="array"||p.type==="object"&&(f[y]=()=>rl(e,{id:y,schema:{...p,title:m}},n,r,a,o),g.push({id:y,label:k[m]??m,icon:C[m]}))});let w=t.schema.default!=null?g.find(p=>p.id===t.schema.default)??g[0]:g[0],b=l(s,w);if(i.Select(s,{inputLabel:c,values:g,...b}),b.value.id in f){let p=f[b.value.id]();v[b.value.id]=p}return()=>{let p=v[b.value.id];return p!=null?{...p(),id:t.id}:{id:t.id,type:"string",value:b.value.id}}}function m8(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var f8=tl,y8="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",al=y8;function b8(e,t,n){switch(t){case"image":return h8(e,n[t]);case"video":return v8(e,n[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function h8(e,t){let n=t.width,r=t.height;return{id:e,meta:{previewUri:al,fillType:"//ly.img.ubq/fill/image",kind:"image",width:n,height:r}}}function v8(e,t){let n=t.width,r=t.height;return{id:e,label:t.label,meta:{previewUri:al,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:n,height:r}}}var k8=b8;async function w8(e,t,n,r){switch(t){case"image":{if(r.kind!=="image")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: image)`);return C8(e,n[t],r)}case"video":{if(r.kind!=="video")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: video)`);return M8(e,n[t],r)}case"audio":{if(r.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${r.kind} (expected: audio)`);return I8(e,n[t],r)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function C8(e,t,n){let r=t.width,a=t.height;return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:a},payload:{sourceSet:[{uri:n.url,width:r,height:a}]}}}async function M8(e,t,n){let r=t.width,a=t.height,o=await d8(n.url,0);return{id:e,label:t.label,meta:{uri:n.url,thumbUri:o,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:a}}}function I8(e,t,n){return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:n.duration.toString()}}}var Ua=w8;function ll(e){let t=e.filter(n=>!!n);return n=>async(r,a)=>{let o=[],i=s=>{o.push(s)},l=async(s,c,d)=>{if(s>=t.length)return n(c,d);let g=t[s],f=async(w,b)=>l(s+1,w,b),v={...d,addDisposer:i};return g(c,v,f)},u={...a,addDisposer:i};return{result:await l(0,r,u),dispose:async()=>{for(let s=o.length-1;s>=0;s--)try{await o[s]()}catch(c){console.error("Error in disposer:",c)}o.length=0}}}}function x8(){return async(e,t,n)=>{console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(e,null,2));let r,a=Date.now();try{return r=await n(e,t),r}finally{r!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(r,null,2))),console.groupEnd()}}}var sl=x8;function A8(e){return async(t,n)=>(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await L8(2e3),await S8(t,e,n))}async function S8(e,t,n){switch(t.kind){case"image":return E8(e,t,n);case"video":return j8(e,t,n);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function E8(e,t,{engine:n}){let r,a,o=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",i=o.match(/(\d+)x(\d+)/);if(i!=null)r=parseInt(i[1],10),a=parseInt(i[2],10);else if(t.blockInputs!=null&&(r=t.blockInputs.image.width,a=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await t8(l,n),s=await bn(u,n);r=s.width,a=s.height}else r=512,a=512;return{kind:"image",url:`https://placehold.co/${r}x${a}/000000/FFF?text=${o.replace(" ","+").replace(`
339
- `,"+")}`}}async function j8(e,t,n){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function L8(e){return new Promise(t=>{setTimeout(t,e)})}var ul=A8;async function T8(e,t,n,r,a,o,i){let{cesdk:l,createPlaceholderBlock:u,historyAssetSourceId:s}=a,c;try{o.debug&&console.group(`Starting Generation for '${e}'`);let d=t(),g=await n(d.input),f=c8(),v;if(u){if(v=k8(f,e,g),o.debug&&console.log("Adding as asset to scene:",JSON.stringify(v,void 0,2)),c=await s8(l,v),c!=null&&r.kind==="video"){let h=l.engine.block.getPositionX(c),m=l.engine.block.getPositionY(c),y=l.engine.block.duplicate(c);l.engine.block.setPositionX(y,h),l.engine.block.setPositionY(y,m),l.engine.block.destroy(c),c=y}if(tr(l,i,c))return{status:"aborted"};if(c==null)throw new Error("Could not create placeholder block");l.engine.block.setState(c,{type:"Pending",progress:0})}let w=ll([...r.output.middleware??[],o.debug?sl():void 0,o.dryRun?ul({kind:r.kind,blockInputs:g}):void 0]),{result:b}=await w(r.output.generate)(d.input,{abortSignal:i,engine:a.engine,cesdk:l});if(vn(b))throw new Error("Streaming generation is not supported yet from a panel");if(tr(l,i,c))return{status:"aborted"};if(b==null)throw new Error("Generation failed");o.debug&&console.log("Generated output:",JSON.stringify(b,void 0,2));let p;if(c!=null&&l.engine.block.isValid(c)&&(p=await Ua(f,e,g,b),o.debug&&console.log("Updating asset in scene:",JSON.stringify(p,void 0,2)),await l.engine.asset.defaultApplyAssetToBlock(p,c)),tr(l,i,c))return{status:"aborted"};if(s!=null){if(p==null&&(p=await Ua(f,e,g,b),tr(l,i,c)))return{status:"aborted"};let h={...p,id:`${Date.now()}-${p.id}`,label:p.label!=null?{en:p.label}:{},tags:{}};l.engine.asset.addAssetToSource(s,h)}return c!=null&&l.engine.block.isValid(c)&&l.engine.block.setState(c,{type:"Ready"}),{status:"success",output:b}}catch(d){throw c!=null&&l.engine.block.isValid(c)&&(Le(d)?l.engine.block.destroy(c):l.engine.block.setState(c,{type:"Error",error:"Unknown"})),d}finally{o.debug&&console.groupEnd()}}function tr(e,t,n){return t.aborted?(n!=null&&e.engine.block.isValid(n)&&e.engine.block.destroy(n),!0):!1}var $8=T8;function N8(e,t,n){let{cesdk:r,provider:a,getInput:o}=t;n.onError!=null&&typeof n.onError=="function"?n.onError(e):(console.error("Generation failed:",e),D8(r,a.output.notification,()=>({input:o?.().input,error:e}))||r.ui.showNotification({type:"error",message:u8(e)}))}function D8(e,t,n){let r=t?.error;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.failed",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"error",message:a,action:o}),!0}var It=N8;function cl(e){return`${e}.generating`}function O8(e){return`${e}.abort`}function _8(e,t,n,r,a,o){let{builder:i,experimental:l}=e,{cesdk:u,includeHistoryLibrary:s=!0}=a,{id:c,output:{abortable:d}}=t,g=l.global(O8(c),()=>{}),f=l.global(cl(c),!1),v,w=f.value&&d,b=()=>{w&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},p;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let m=n();p=a.requiredInputs.every(y=>!m.input[y])}let h=l.global(`${c}.confirmationDialogId`,void 0);i.Section(`${c}.generate.section`,{children:()=>{i.Button(`${c}.generate`,{label:["common.ai-generation.generate",`panel.${c}.generate`],isLoading:f.value,color:"accent",isDisabled:p,suffix:w?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${c}.abort`,"common.cancel"],onClick:()=>{let m=u.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{u.ui.closeDialog(y),h.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{b(),u.ui.closeDialog(y),h.setValue(void 0)}}});h.setValue(m)}}:void 0,onClick:async()=>{v=new AbortController;let m=v.signal,y=async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),v?.abort()});let k=await $8(t.kind,n,r,t,a,o,m);if(k.status==="aborted")return;let C=t.output.notification;P8(u,C,()=>({input:n().input,output:k.output}))}catch(k){if(Le(k))return;It(k,{cesdk:u,provider:t,getInput:n},o)}finally{v=void 0,f.setValue(!1),g.setValue(()=>{}),h.value!=null&&(u.ui.closeDialog(h.value),h.setValue(void 0))}};o.middleware!=null?await o.middleware(y,{provider:t,abort:b}):await y()}}),t.output.generationHintText!=null&&i.Text(`${c}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),s&&a.historyAssetLibraryEntryId!=null&&i.Library(`${c}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function P8(e,t,n){let r=t?.success;if(r==null||!(typeof r.show=="function"?r.show(n()):r.show))return!1;let a=typeof r.message=="function"?r.message(n()):r.message??"common.ai-generation.success",o=r.action!=null?{label:typeof r.action.label=="function"?r.action.label(n()):r.action.label,onClick:()=>{r?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"success",message:a,action:o,duration:r.duration}),!0}var dl=_8;async function z8(e,t,n,r){let{cesdk:a}=n,{id:o}=e;r.debug&&console.log(`Registering schema-based panel input for provider ${o}`);let i=r8(t.document),l=Ka(i,t.inputReference);if(!n8(l,r.debug))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=Ja(u,t),c=d=>{let{builder:g}=d,f=[];g.Section(`${o}.schema.section`,{children:()=>{s.forEach(p=>{let h=f8(d,p,e,t,n,r);h!=null&&(Array.isArray(h)?f.push(...h):f.push(h))})}});let v=f.map(p=>p()),w=p=>p.type==="object"?Object.entries(p.value).reduce((h,[m,y])=>(h[m]=w(y),h),{}):p.value,b=v.reduce((p,h)=>(p[h.id]=w(h),p),{});dl(d,e,()=>({input:b}),()=>t.getBlockInput(b),{...n,requiredInputs:u.required,createPlaceholderBlock:t.userFlow==="placeholder"},r)};return a.ui.registerPanel(Xa(o),c),c}var U8=z8;async function V8(e,t,n,r){let{cesdk:a}=n,{id:o}=e,i=t.render,l=u=>{let{state:s}=u,c=s(cl(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:g}=i(u,{cesdk:a,isGenerating:c});return dl(u,e,d,g,{...n,includeHistoryLibrary:t.includeHistoryLibrary??!0,createPlaceholderBlock:t.userFlow==="placeholder"},r),d};return a.ui.registerPanel(Xa(o),l),l}var B8=V8,cn="@imgly/plugin-ai-generation",F8=`
350
+ `,L$=_$,T$=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",p=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(p=s.tags[c]);let g={...s,label:d,tags:p};return this.filterAsset(g,e)&&u.push(g),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),l=a<t.length?r+1:void 0;return{assets:o,currentPage:r,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let i=new Set;r.result.forEach(a=>{a.groups&&Array.isArray(a.groups)&&a.groups.forEach(o=>i.add(o))});let n=[...i];e(n)},r.onerror=()=>{t(new Error(`Failed to get groups: ${r.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),r=t.objectStore(this.assetStoreName),i=new Set;Dt(e,a=>{i.add(a)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.assetStoreName,"readwrite");r.objectStore(this.assetStoreName).delete(e),r.oncomplete=()=>{Dt(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let l=a.meta?.insertedAt||a._insertedAt||Date.now(),u=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return Dt(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),Dt(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!o.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(l=>e.tags?.includes(l))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,l)=>{let u,s;return i==="id"?(u=o.id,s=l.id):(u=o.meta?.[i]??null,s=l.meta?.[i]??null),u==null?r==="Ascending"?-1:1:s==null?r==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?r==="Ascending"?u.localeCompare(s):s.localeCompare(u):r==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):r==="Descending"&&a.reverse(),n&&a.sort((o,l)=>o.active&&!l.active?-1:!o.active&&l.active?1:0)),a}};function Dt(e,t,r=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let i=0;i<e.length;i++){let n=r?`${r}[${i}]`:`[${i}]`;if(typeof e[i]=="string"&&e[i].startsWith("blob:")){let a=t(e[i],n);typeof a=="string"&&(e[i]=a)}else e[i]=Dt(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],a=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let o=t(n,a);typeof o=="string"&&(e[i]=o)}else e[i]=Dt(n,t,a)}return e}var $$=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,d)=>{let p=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,l=o+a,u=i.slice(o,l),s=l<i.length?n+1:void 0;return{assets:u,currentPage:n,nextPage:s,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}},N$=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},j1=N$,O$=typeof global=="object"&&global&&global.Object===Object&&global,S1=O$,D$=typeof self=="object"&&self&&self.Object===Object&&self,P$=S1||D$||Function("return this")(),X=P$,z$=X.Symbol,Pt=z$,E1=Object.prototype,U$=E1.hasOwnProperty,R$=E1.toString,fi=Pt?Pt.toStringTag:void 0;function F$(e){var t=U$.call(e,fi),r=e[fi];try{e[fi]=void 0;var i=!0}catch{}var n=R$.call(e);return i&&(t?e[fi]=r:delete e[fi]),n}var V$=F$,B$=Object.prototype,G$=B$.toString;function q$(e){return G$.call(e)}var Y$=q$,H$="[object Null]",Z$="[object Undefined]",Yd=Pt?Pt.toStringTag:void 0;function Q$(e){return e==null?e===void 0?Z$:H$:Yd&&Yd in Object(e)?V$(e):Y$(e)}var Mi=Q$;function W$(e){return e!=null&&typeof e=="object"}var Pa=W$,gJ=Array.isArray;function K$(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var _1=K$,J$="[object AsyncFunction]",X$="[object Function]",eN="[object GeneratorFunction]",tN="[object Proxy]";function rN(e){if(!_1(e))return!1;var t=Mi(e);return t==X$||t==eN||t==J$||t==tN}var iN=rN,nN=X["__core-js_shared__"],va=nN,Hd=function(){var e=/[^.]+$/.exec(va&&va.keys&&va.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function oN(e){return!!Hd&&Hd in e}var aN=oN,lN=Function.prototype,sN=lN.toString;function uN(e){if(e!=null){try{return sN.call(e)}catch{}try{return e+""}catch{}}return""}var Le=uN,cN=/[\\^$.*+?()[\]{}|]/g,dN=/^\[object .+?Constructor\]$/,pN=Function.prototype,gN=Object.prototype,fN=pN.toString,hN=gN.hasOwnProperty,mN=RegExp("^"+fN.call(hN).replace(cN,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function yN(e){if(!_1(e)||aN(e))return!1;var t=iN(e)?mN:dN;return t.test(Le(e))}var bN=yN;function vN(e,t){return e?.[t]}var wN=vN;function kN(e,t){var r=wN(e,t);return bN(r)?r:void 0}var Ut=kN,xN=Ut(X,"WeakMap"),Ma=xN;function IN(e,t){return e===t||e!==e&&t!==t}var CN=IN,AN=9007199254740991;function MN(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=AN}var jN=MN,fJ=Object.prototype,SN="[object Arguments]";function EN(e){return Pa(e)&&Mi(e)==SN}var Zd=EN,L1=Object.prototype,_N=L1.hasOwnProperty,LN=L1.propertyIsEnumerable,hJ=Zd(function(){return arguments}())?Zd:function(e){return Pa(e)&&_N.call(e,"callee")&&!LN.call(e,"callee")},T1=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Qd=T1&&typeof module=="object"&&module&&!module.nodeType&&module,TN=Qd&&Qd.exports===T1,Wd=TN?X.Buffer:void 0,mJ=Wd?Wd.isBuffer:void 0,$N="[object Arguments]",NN="[object Array]",ON="[object Boolean]",DN="[object Date]",PN="[object Error]",zN="[object Function]",UN="[object Map]",RN="[object Number]",FN="[object Object]",VN="[object RegExp]",BN="[object Set]",GN="[object String]",qN="[object WeakMap]",YN="[object ArrayBuffer]",HN="[object DataView]",ZN="[object Float32Array]",QN="[object Float64Array]",WN="[object Int8Array]",KN="[object Int16Array]",JN="[object Int32Array]",XN="[object Uint8Array]",eO="[object Uint8ClampedArray]",tO="[object Uint16Array]",rO="[object Uint32Array]",$={};$[ZN]=$[QN]=$[WN]=$[KN]=$[JN]=$[XN]=$[eO]=$[tO]=$[rO]=!0;$[$N]=$[NN]=$[YN]=$[ON]=$[HN]=$[DN]=$[PN]=$[zN]=$[UN]=$[RN]=$[FN]=$[VN]=$[BN]=$[GN]=$[qN]=!1;function iO(e){return Pa(e)&&jN(e.length)&&!!$[Mi(e)]}var nO=iO;function oO(e){return function(t){return e(t)}}var aO=oO,$1=typeof exports=="object"&&exports&&!exports.nodeType&&exports,wi=$1&&typeof module=="object"&&module&&!module.nodeType&&module,lO=wi&&wi.exports===$1,wa=lO&&S1.process,sO=function(){try{var e=wi&&wi.require&&wi.require("util").types;return e||wa&&wa.binding&&wa.binding("util")}catch{}}(),Kd=sO,Jd=Kd&&Kd.isTypedArray,yJ=Jd?aO(Jd):nO,uO=Object.prototype,bJ=uO.hasOwnProperty;function cO(e,t){return function(r){return e(t(r))}}var dO=cO,vJ=dO(Object.keys,Object),pO=Object.prototype,wJ=pO.hasOwnProperty,gO=Ut(Object,"create"),xi=gO;function fO(){this.__data__=xi?xi(null):{},this.size=0}var hO=fO;function mO(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var yO=mO,bO="__lodash_hash_undefined__",vO=Object.prototype,wO=vO.hasOwnProperty;function kO(e){var t=this.__data__;if(xi){var r=t[e];return r===bO?void 0:r}return wO.call(t,e)?t[e]:void 0}var xO=kO,IO=Object.prototype,CO=IO.hasOwnProperty;function AO(e){var t=this.__data__;return xi?t[e]!==void 0:CO.call(t,e)}var MO=AO,jO="__lodash_hash_undefined__";function SO(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=xi&&t===void 0?jO:t,this}var EO=SO;function Rt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Rt.prototype.clear=hO;Rt.prototype.delete=yO;Rt.prototype.get=xO;Rt.prototype.has=MO;Rt.prototype.set=EO;var Xd=Rt;function _O(){this.__data__=[],this.size=0}var LO=_O;function TO(e,t){for(var r=e.length;r--;)if(CN(e[r][0],t))return r;return-1}var Mn=TO,$O=Array.prototype,NO=$O.splice;function OO(e){var t=this.__data__,r=Mn(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():NO.call(t,r,1),--this.size,!0}var DO=OO;function PO(e){var t=this.__data__,r=Mn(t,e);return r<0?void 0:t[r][1]}var zO=PO;function UO(e){return Mn(this.__data__,e)>-1}var RO=UO;function FO(e,t){var r=this.__data__,i=Mn(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var VO=FO;function Ft(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Ft.prototype.clear=LO;Ft.prototype.delete=DO;Ft.prototype.get=zO;Ft.prototype.has=RO;Ft.prototype.set=VO;var jn=Ft,BO=Ut(X,"Map"),Ii=BO;function GO(){this.size=0,this.__data__={hash:new Xd,map:new(Ii||jn),string:new Xd}}var qO=GO;function YO(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var HO=YO;function ZO(e,t){var r=e.__data__;return HO(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Sn=ZO;function QO(e){var t=Sn(this,e).delete(e);return this.size-=t?1:0,t}var WO=QO;function KO(e){return Sn(this,e).get(e)}var JO=KO;function XO(e){return Sn(this,e).has(e)}var eD=XO;function tD(e,t){var r=Sn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var rD=tD;function Vt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Vt.prototype.clear=qO;Vt.prototype.delete=WO;Vt.prototype.get=JO;Vt.prototype.has=eD;Vt.prototype.set=rD;var N1=Vt;function iD(){this.__data__=new jn,this.size=0}var nD=iD;function oD(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var aD=oD;function lD(e){return this.__data__.get(e)}var sD=lD;function uD(e){return this.__data__.has(e)}var cD=uD,dD=200;function pD(e,t){var r=this.__data__;if(r instanceof jn){var i=r.__data__;if(!Ii||i.length<dD-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new N1(i)}return r.set(e,t),this.size=r.size,this}var gD=pD;function ji(e){var t=this.__data__=new jn(e);this.size=t.size}ji.prototype.clear=nD;ji.prototype.delete=aD;ji.prototype.get=sD;ji.prototype.has=cD;ji.prototype.set=gD;var fD=Object.prototype,kJ=fD.propertyIsEnumerable,hD=Ut(X,"DataView"),ja=hD,mD=Ut(X,"Promise"),Sa=mD,yD=Ut(X,"Set"),Ea=yD,e1="[object Map]",bD="[object Object]",t1="[object Promise]",r1="[object Set]",i1="[object WeakMap]",n1="[object DataView]",vD=Le(ja),wD=Le(Ii),kD=Le(Sa),xD=Le(Ea),ID=Le(Ma),Nt=Mi;(ja&&Nt(new ja(new ArrayBuffer(1)))!=n1||Ii&&Nt(new Ii)!=e1||Sa&&Nt(Sa.resolve())!=t1||Ea&&Nt(new Ea)!=r1||Ma&&Nt(new Ma)!=i1)&&(Nt=function(e){var t=Mi(e),r=t==bD?e.constructor:void 0,i=r?Le(r):"";if(i)switch(i){case vD:return n1;case wD:return e1;case kD:return t1;case xD:return r1;case ID:return i1}return t});var xJ=X.Uint8Array,CD="__lodash_hash_undefined__";function AD(e){return this.__data__.set(e,CD),this}var MD=AD;function jD(e){return this.__data__.has(e)}var SD=jD;function _a(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new N1;++t<r;)this.add(e[t])}_a.prototype.add=_a.prototype.push=MD;_a.prototype.has=SD;var o1=Pt?Pt.prototype:void 0,IJ=o1?o1.valueOf:void 0,ED=Object.prototype,CJ=ED.hasOwnProperty,_D=Object.prototype,AJ=_D.hasOwnProperty,MJ=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),jJ=new RegExp(/[A-Fa-f0-9]{1}/,"g"),SJ=new RegExp(/[A-Fa-f0-9]{2}/,"g");function LD(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function O1(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function La(e,t){let r=await O1(e,t);return new Promise((i,n)=>{let a=new Image;a.onload=()=>{i({width:a.width,height:a.height})},a.onerror=n,a.src=r})}async function TD(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return O1(i,t)}function $D(e){return e!==void 0}var En=$D,D1=class P1{constructor(){this.actions=new Map,this.subscribers=new Map}static get(){let t="__imgly_action_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new P1),r[t]}register(t){return this.actions.set(t.id,t),this.notifySubscribers(t,"registered"),()=>{this.actions.get(t.id)===t&&(this.actions.delete(t.id),this.notifySubscribers(t,"unregistered"))}}getAll(){return Array.from(this.actions.values())}getBy(t){return this.getAll().filter(r=>this.matchesFilters(r,t))}subscribe(t){return this.subscribers.set(t,null),()=>{this.subscribers.delete(t)}}subscribeBy(t,r){return this.subscribers.set(r,t),()=>{this.subscribers.delete(r)}}notifySubscribers(t,r){this.subscribers.forEach((i,n)=>{if(i===null){n(t,r);return}this.matchesFilters(t,i)&&n(t,r)})}matchesFilters(t,r){return!(r.type&&t.type!==r.type||r.pluginId&&t.type==="plugin"&&t.pluginId!==r.pluginId||r.id&&t.id!==r.id||r.kind&&(t.type!=="quick"||t.kind!==r.kind))}},z1=class U1{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new U1),r[t]}register(t){return this.providers.has(t.provider.id)&&console.warn(`Provider with ID "${t.provider.id}" is already registered`),this.providers.set(t.provider.id,t),()=>{this.providers.get(t.provider.id)===t&&this.providers.delete(t.provider.id)}}getAll(){return Array.from(this.providers.values())}getById(t){return this.providers.get(t)}getByKind(t){return this.getAll().filter(({provider:r})=>r.kind===t)}};function ND(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=s=>{a.push(s)},l=async(s,c,d)=>{if(s>=t.length)return r(c,d);let p=t[s],g=async(b,m)=>l(s+1,b,m),f={...d,addDisposer:o};return p(c,f,g)},u={...n,addDisposer:o};return{result:await l(0,i,u),dispose:async()=>{for(let s=a.length-1;s>=0;s--)try{await a[s]()}catch(c){console.error("Error in disposer:",c)}a.length=0}}}}function OD({enable:e=!0}){return async(t,r,i)=>{if(!e)return i(t,r);console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(t,null,2));let n,a=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var DD=OD,ka="ly.img.ai.temp";async function PD(e,t){return e.engine.asset.findAllSources().includes(ka)||e.engine.asset.addLocalSource(ka),e.engine.asset.apply(ka,t)}function zD(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let r=e;return"message"in r&&typeof r.message=="string"?r.message:"cause"in r&&typeof r.cause=="string"?r.cause:"detail"in r&&typeof r.detail=="object"&&r.detail!==null&&"message"in r.detail&&typeof r.detail.message=="string"?r.detail.message:"error"in r&&typeof r.error=="object"&&r.error!==null&&"message"in r.error&&typeof r.error.message=="string"?r.error.message:t}return typeof e=="string"?e:String(e)||t}function R1(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function UD(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=o.videoWidth,l.height=o.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}u.drawImage(o,0,0,l.width,l.height);try{let s=l.toDataURL(r,i);document.body.removeChild(o),n(s)}catch(s){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function F1(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function RD(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function za(e){return e instanceof Error&&e.name==="AbortError"}function FD(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function VD(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
351
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
352
+ This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version.
353
+ Consider updating all AI plugins to the same version for optimal compatibility.`),e.ui.experimental.setGlobalStateValue(n,!0))):e.ui.experimental.setGlobalStateValue(i,r)}catch(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}function BD(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),GD(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:zD(e)})}function GD(e,t,r){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.failed",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"error",message:n,action:a}),!0}var a1=BD,qD="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Ua=qD;function YD(e,t,r){switch(t){case"image":return HD(e,r[t]);case"video":return ZD(e,r[t]);case"sticker":return QD(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function HD(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ua,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function ZD(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Ua,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function QD(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ua,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var WD=YD;async function KD(e,t,r,i){switch(t){case"image":{if(i.kind!=="image")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: image)`);return JD(e,r[t],i)}case"video":{if(i.kind!=="video")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: video)`);return XD(e,r[t],i)}case"audio":{if(i.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: audio)`);return eP(e,r[t],i)}case"sticker":{if(i.kind!=="sticker")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: sticker)`);return tP(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function JD(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}async function XD(e,t,r){let i=t.width,n=t.height,a=await UD(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:a,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function eP(e,t,r){return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:r.duration.toString()}}}function tP(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}var V1=KD;function rP(e){switch(e.userFlow){case"placeholder":return nP(e);case"generation-only":return iP(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function iP(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(he(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(he(t,r))return{status:"aborted"};if(o.status!=="success")return o;if(o.type==="async")throw new Error("Async generation is not supported in this context yet.");if(he(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let l=R1(),u=await V1(l,n,a,o.output),s={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,s)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function nP(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(he(t,r))return{status:"aborted"};let l=R1(),u=WD(l,a,o);if(i=await PD(t,u),he(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,p),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let s=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(he(t,r,i))return{status:"aborted"};if(s.status!=="success")return s;if(s.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let c=await V1(l,a,o,s.output);if(he(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(c,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(c,i),he(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),s}catch(a){return i!=null&&t.engine.block.isValid(i)&&(za(a)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:a instanceof Error?a.message:String(a)}}}}function he(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var oP=rP;function Ra(e){return`${e}.generating`}function aP(e){return`${e}.abort`}function lP(e,t,r,i,n,a,o){let{builder:l,experimental:u}=e,{cesdk:s,includeHistoryLibrary:c=!0}=a,{id:d,output:{abortable:p}}=t,g=u.global(aP(d),()=>{}),f=u.global(Ra(d),!1),b,m=f.value&&p,h=()=>{m&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},x;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let v=i();x=a.requiredInputs.every(y=>!v.input[y])}let w=u.global(`${d}.confirmationDialogId`,void 0);l.Section(`${d}.generate.section`,{children:()=>{l.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:f.value,color:"accent",isDisabled:x,suffix:m?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let v=s.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{s.ui.closeDialog(y),w.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{h(),s.ui.closeDialog(y),w.setValue(void 0)}}});w.setValue(v)}}:void 0,onClick:async()=>{b=new AbortController;let v=b.signal;await(async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),b?.abort()});let y=await oP({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:v,cesdk:s,debug:o.debug,dryRun:o.dryRun})(i().input);if(y.status==="aborted")return;if(y.status==="error"){a1(y.message,{cesdk:s,provider:t,getInput:i});return}if(y.status==="success"&&y.type==="sync"){let k=t.output.notification;sP(s,k,()=>({input:i().input,output:y.output}))}}catch(y){if(za(y))return;a1(y,{cesdk:s,provider:t,getInput:i})}finally{b=void 0,f.setValue(!1),g.setValue(()=>{}),w.value!=null&&(s.ui.closeDialog(w.value),w.setValue(void 0))}})()}}),t.output.generationHintText!=null&&l.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),c&&a.historyAssetLibraryEntryId!=null&&l.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function sP(e,t,r){let i=t?.success;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.success",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"success",message:n,action:a,duration:i.duration}),!0}var B1=lP;async function uP({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,l=r.render;return u=>{let{state:s}=u,c=s(Ra(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=l(u,{cesdk:a,isGenerating:c});return B1(u,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var cP=uP;function G1(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let r=t.substring(2).split("/"),i=e;for(let n of r){if(i==null)throw new Error(`Invalid reference path: ${t}`);i=i[n]}if(i===void 0)throw new Error(`Reference not found: ${t}`);return i}function vi(e,t,r=new Set){if(t==null||r.has(t))return t;if(r.add(t),t.$ref&&typeof t.$ref=="string"){let i=G1(e,t.$ref),n={...vi(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=vi(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>vi(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=vi(e,t[n],r));return i}return t}function dP(e){return vi(e,{...e})}function pP(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let l of i.type)if(typeof l!="string"||!o.includes(l))return r(`Array of types contains invalid value: ${l}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let l=0;l<i[o].length;l++){let u=i[o][l];if(typeof u!="object"||u===null)return r(`Item ${l} in ${o} must be an object, got ${u===null?"null":typeof u}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let l=i.required[o];if(typeof l!="string")return r(`Item ${o} in required array must be a string, got ${typeof l}`)}}return!0}function gP(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return fP(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function fP(e,t){let r=t.order;if(r!=null&&Array.isArray(r))return r;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,n=Object.keys(i),a=hP(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function hP(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let r=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return r==null?void 0:e[r]}var q1=gP;function Y1(e,t,r,i,n,a){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let o=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?mP(e,o,r,i,n,a):Z1(e,o,r,i,n,a);case"boolean":return Q1(e,o,r,i,n,a);case"number":case"integer":return W1(e,o,r,i,n,a);case"object":return H1(e,o,r,i,n,a);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return yP(e,o,r,i,n,a);break}default:console.error(`Unsupported property type: ${l}`)}}function H1(e,t,r,i,n,a){let o=q1(t.schema??{},i).reduce((l,u)=>{let s=Y1(e,u,r,i,n,a);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:o})}function Z1(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),p=bP(t.schema),g=p?.component!=null&&p?.component==="TextArea"?"TextArea":"TextInput";return o[g](s,{inputLabel:c,placeholder:n.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function mP(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},p="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},g=(t.schema.enum??[]).map(m=>({id:m,label:d[m]??F1(m),icon:p[m]})),f=t.schema.default!=null?g.find(m=>m.id===t.schema.default)??g[0]:g[0],b=l(s,f);return o.Select(s,{inputLabel:c,values:g,...b}),()=>({id:t.id,type:"string",value:b.value.id})}function Q1(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,p=l(s,d);return o.Checkbox(s,{inputLabel:c,...p}),()=>({id:t.id,type:"boolean",value:p.value})}function W1(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,p=t.schema.maximum,g=t.schema.default;g==null&&(d!=null?g=d:p!=null?g=p:g=0);let f=l(s,g);if(d!=null&&p!=null){let b=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(b=t.schema["x-imgly-step"]),o.Slider(s,{inputLabel:c,min:d,max:p,step:b,...f})}else o.NumberInput(s,{inputLabel:c,min:d,max:p,...f});return()=>({id:t.id,type:"integer",value:f.value})}function yP(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],p=[],g={},f={};d.forEach((h,x)=>{let w=h.title??"common.custom",v=`${r.id}.${u}.anyOf[${x}]`,y="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},k="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};h.type==="string"?h.enum!=null?h.enum.forEach(I=>{p.push({id:I,label:y[I]??F1(I),icon:k[I]})}):(g[v]=()=>Z1(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="boolean"?(g[v]=()=>Q1(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="integer"?(g[v]=()=>W1(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="array"||h.type==="object"&&(g[v]=()=>H1(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]}))});let b=t.schema.default!=null?p.find(h=>h.id===t.schema.default)??p[0]:p[0],m=l(s,b);if(o.Select(s,{inputLabel:c,values:p,...m}),m.value.id in g){let h=g[m.value.id]();f[m.value.id]=h}return()=>{let h=f[m.value.id];return h!=null?{...h(),id:t.id}:{id:t.id,type:"string",value:m.value.id}}}function bP(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var vP=Y1;async function wP({options:e,provider:t,panelInput:r,config:i},n){let{id:a}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${a}`);let o=dP(r.document),l=G1(o,r.inputReference);if(!pP(l,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=q1(u,r);return c=>{let{builder:d}=c,p=[];d.Section(`${a}.schema.section`,{children:()=>{s.forEach(m=>{let h=vP(c,m,t,r,e,i);h!=null&&(Array.isArray(h)?p.push(...h):p.push(h))})}});let g=p.map(m=>m()),f=m=>m.type==="object"?Object.entries(m.value).reduce((h,[x,w])=>(h[x]=f(w),h),{}):m.value,b=g.reduce((m,h)=>(m[h.id]=f(h),m),{});B1(c,t,n,()=>({input:b}),()=>r.getBlockInput(b),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var kP=wP;async function xP(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return cP(e,t);case"schema":return kP(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var IP=xP;function CP(e){let{provider:t,options:{engine:r}}=e,i=t.output.history??"@imgly/local";if(i==null||i===!1)return;let n=r.asset.findAllSources();function a(){let o=`${t.id}.history`;for(;n.includes(o);)o+=`-${Math.random().toString(36).substring(2,6)}`;return o}if(i==="@imgly/local"){let o=a();return r.asset.addLocalSource(o),o}if(i==="@imgly/indexedDB"){let o=a();return r.asset.addSource(new T$(o,r)),o}return i}var AP=CP;function MP(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history.entry`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var jP=MP,xa="@imgly/plugin-ai-generation",SP=`
340
354
  <svg>
341
355
  <symbol
342
356
  fill="none"
@@ -354,7 +368,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
354
368
  fill="none"
355
369
  xmlns="http://www.w3.org/2000/svg"
356
370
  viewBox="0 0 24 24"
357
- id="${cn}/image"
371
+ id="${xa}/image"
358
372
  >
359
373
  <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
360
374
  <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
@@ -366,7 +380,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
366
380
  fill="none"
367
381
  xmlns="http://www.w3.org/2000/svg"
368
382
  viewBox="0 0 24 24"
369
- id="${cn}/video"
383
+ id="${xa}/video"
370
384
  >
371
385
  <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
372
386
  <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
@@ -377,7 +391,7 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
377
391
  fill="none"
378
392
  xmlns="http://www.w3.org/2000/svg"
379
393
  viewBox="0 0 24 24"
380
- id="${cn}/audio"
394
+ id="${xa}/audio"
381
395
  >
382
396
  <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
383
397
  <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
@@ -397,9 +411,275 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
397
411
 
398
412
  </symbol>
399
413
  </svg>
400
- `,G8=F8,Va="ly.img.ai.quickAction.order",Ct="ly.img.ai.quickAction.actions";function R8(e,t){return{id:t,setQuickActionMenuOrder:n=>{e.ui.experimental.setGlobalStateValue(`${Va}.${t}`,n)},getQuickActionMenuOrder:()=>e.ui.experimental.getGlobalStateValue(`${Va}.${t}`,[]),registerQuickAction:n=>{if(!e.ui.experimental.hasGlobalStateValue(`${Ct}.${t}`))e.ui.experimental.setGlobalStateValue(`${Ct}.${t}`,{[n.id]:n});else{let r=e.ui.experimental.getGlobalStateValue(`${Ct}.${t}`,{});e.ui.experimental.setGlobalStateValue(`${Ct}.${t}`,{...r,[n.id]:n})}},getQuickAction:n=>e.ui.experimental.getGlobalStateValue(`${Ct}.${t}`,{})[n]}}var gl=R8,dn="ly.img.ai.inference.editMode",pl="ly.img.ai.inference.metadata";function ml(e){return`ly.img.ai.quickAction.${e.quickActionMenuId}.${e.quickActionId}`}function q8(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((n,r)=>(r==="ly.img.separator"&&n.length>0&&n[n.length-1]==="ly.img.separator"||n.push(r),n),[])}function Q8({alwaysOnTop:e=!0,disableClipping:t=!0}){return async(n,r,a)=>{let o={},i={},l=e||t?r.blockIds??r.engine.block.findAllSelected():[];return l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&(o[u]=r.engine.block.isAlwaysOnTop(u),r.engine.block.setAlwaysOnTop(u,!0)),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&(i[s]=r.engine.block.isClipped(s),r.engine.block.setClipped(s,!1))}}),r.addDisposer(async()=>{l.forEach(u=>{if(r.engine.block.isValid(u)&&e&&r.engine.block.setAlwaysOnTop(u,o[u]),t){let s=r.engine.block.getParent(u);s!=null&&r.engine.block.getType(s)!=="//ly.img.ubq/scene"&&i[s]!=null&&r.engine.block.setClipped(s,i[s])}})}),await a(n,r)}}var H8=Q8;function Y8({pending:e=!0}){return async(t,n,r)=>{let a=e?n.blockIds??n.engine.block.findAllSelected():[];try{return a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Pending",progress:0})}),await r(t,n)}finally{a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Ready"})})}}}var Z8=Y8;function W8({editMode:e,automaticallyUnlock:t=!1}){return async(n,r,a)=>{let o=r.blockIds??r.engine.block.findAllSelected(),i=()=>{};t||r.addDisposer(async()=>{i?.()});try{return i=K8(r.engine,o,e),await a(n,r)}catch(l){throw Le(l)&&i(),l}finally{t&&i()}}}function K8(e,t,n){let r=e.editor.getGlobalScope("editor/select"),a=e.editor.getEditMode();l(),e.editor.setGlobalScope("editor/select","Deny"),e.editor.setEditMode(n);let o=e.editor.createHistory(),i=e.editor.getActiveHistory();e.editor.setActiveHistory(o);function l(){e.block.findAllSelected().forEach(c=>{t.includes(c)||e.block.setSelected(c,!1)}),t.forEach(c=>{e.block.setSelected(c,!0)})}let u=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&e.editor.setEditMode(n)}),s=e.block.onSelectionChanged(l);return()=>{r!=null&&e.editor.setGlobalScope("editor/select",r),e.editor.setEditMode(a),e.editor.setActiveHistory(i),e.editor.destroyHistory(o),s(),u()}}var J8=W8;function X8(e,t){switch(t.kind){case"text":return e6(e,t);case"image":return t6(e,t);case"video":return r6(e,t);case"audio":return n6(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function e6(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t,o=r.map(s=>n.engine.block.getString(s,"text/text")),i;if(vn(e)){let s="";for await(let c of e){if(a.aborted)break;typeof c=="string"?s=c:c.kind==="text"&&(s=c.text),r.forEach(d=>{n.engine.block.setString(d,"text/text",s)}),i={kind:"text",text:s}}}else i=e;if(i==null||i.kind!=="text")throw new Error("Output kind from generation is not text");let l=()=>{t.blockIds.forEach(s=>{t.cesdk.engine.block.setString(s,"text/text",i.text)})},u=()=>{t.blockIds.forEach((s,c)=>{t.cesdk.engine.block.setString(s,"text/text",o[c])})};return{consumedGenerationResult:i,applyCallbacks:{onBefore:u,onAfter:l,onCancel:u,onApply:()=>{l(),t.cesdk.engine.editor.addUndoStep()}}}}async function t6(e,t){let{cesdk:n,blockIds:r,abortSignal:a}=t;if(r.length!==1)throw new Error("Only one block is supported for image generation");let[o]=r,i=n.engine.block.getFill(o),l=n.engine.block.getSourceSet(i,"fill/image/sourceSet"),[u]=l,s;u==null&&(s=n.engine.block.getString(i,"fill/image/imageFileURI"));let c=await n.engine.editor.getMimeType(u?.uri??s),d=await bn(u?.uri??s,t.cesdk.engine),g=d.width/d.height;if(a.throwIfAborted(),c==="image/svg+xml")throw new Error("SVG images are not supported");let f=n.engine.block.getCropScaleX(o),v=n.engine.block.getCropScaleY(o),w=n.engine.block.getCropTranslationX(o),b=n.engine.block.getCropTranslationY(o),p=n.engine.block.getCropRotation(o),h=()=>{n.engine.block.setCropScaleX(o,f),n.engine.block.setCropScaleY(o,v),n.engine.block.setCropTranslationX(o,w),n.engine.block.setCropTranslationY(o,b),n.engine.block.setCropRotation(o,p)};if(vn(e))throw new Error("Streaming generation is not supported yet from a panel");if(e.kind!=="image"||typeof e.url!="string")throw new Error("Output kind from generation is not an image");let m=e.url,y=await n.engine.editor.getMimeType(m),k=await i6(n,m,y),C=await bn(k,t.cesdk.engine),M=C.width/C.height,I=Math.abs(g-M)>.001,x=u?[{uri:k,width:C.width,height:C.height}]:void 0,$=k;x==null?n.engine.block.setString(i,"fill/image/imageFileURI",$):(n.engine.block.setString(i,"fill/image/imageFileURI",""),n.engine.block.setSourceSet(i,"fill/image/sourceSet",x)),I?n.engine.block.setContentFillMode(o,"Cover"):h();let D=()=>{if(l==null||l.length===0){if(s==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",s)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",l);h()},O=()=>{if(x==null){if($==null)throw new Error("No image URI found");n.engine.block.setString(i,"fill/image/imageFileURI",$)}else n.engine.block.setSourceSet(i,"fill/image/sourceSet",x);I?n.engine.block.setContentFillMode(o,"Cover"):h()};return{consumedGenerationResult:e,applyCallbacks:{onBefore:D,onAfter:O,onCancel:()=>{D()},onApply:()=>{O(),t.cesdk.engine.editor.addUndoStep()}}}}async function r6(e,t){throw new Error("Function not implemented.")}async function n6(e,t){throw new Error("Function not implemented.")}async function i6(e,t,n){let r=await(await fetch(t)).blob(),a=new File([r],`image.${e8(n)}`,{type:n}),o=await e.unstable_upload(a,()=>{});return o?.meta?.uri??(console.warn("Failed to upload image:",o),t)}var o6=X8;function a6({editMode:e,automaticallyUnlock:t=!1,showNotification:n=!0}){return async(r,a,o)=>{let i=a.blockIds??a.engine.block.findAllSelected(),l=()=>{};t||a.addDisposer(async()=>{l?.()});try{l=l6(a.engine,i,e);let u=await o(r,a);if(n){let s=a.engine.block.findAllSelected();i.some(c=>s.includes(c))||a.cesdk?.ui.showNotification({type:"success",message:"AI generation complete",action:{label:"Select",onClick:()=>{i.forEach(c=>{a.engine.block.select(c)})}}})}return u}catch(u){throw Le(u)&&l(),u}finally{t&&l()}}}function l6(e,t,n){function r(){let i=e.block.findAllSelected();return t.some(l=>i.includes(l))}let a=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&r()&&e.editor.setEditMode(n)}),o=e.block.onSelectionChanged(()=>{r()?e.editor.setEditMode(n):e.editor.setEditMode("Transform")});return r()&&e.editor.setEditMode(n),()=>{o(),a(),e.editor.setEditMode("Transform")}}var s6=a6;async function u6(e,t){let{cesdk:n,input:r,blockIds:a,provider:o,quickAction:i,confirmationComponentId:l,abortSignal:u}=e;i.confirmation&&n.ui.setCanvasMenuOrder([l],{editMode:dn});let s=new Fa(n.engine,pl);a.forEach(p=>{s.set(p,{status:"processing",quickActionId:i.id})});let c={cesdk:n,engine:n.engine,abortSignal:u},d=ll([...o.output.middleware??[],t.debug?sl():void 0,Z8({}),...i.confirmation?[i.lockDuringConfirmation?J8({editMode:dn}):s6({editMode:dn}),i.confirmation&&H8({})]:[],t.dryRun?ul({kind:o.kind,blockIds:a}):void 0]),{result:g,dispose:f}=await d(o.output.generate)(r,c),{consumedGenerationResult:v,applyCallbacks:w}=await o6(g,{abortSignal:u,kind:o.kind,blockIds:a,cesdk:n});i.confirmation?a.forEach(p=>{s.set(p,{status:"confirmation",quickActionId:i.id})}):(w.onApply(),a.forEach(p=>{s.clear(p)}));let b=()=>{f(),a.forEach(p=>{s.clear(p)})};return u.addEventListener("abort",b),{dispose:b,returnValue:v,applyCallbacks:w}}var Ba=u6;function c6(e,t){let{cesdk:n,quickActionMenu:r,provider:a}=e,o=`ly.img.ai.${r.id}`,i=`${o}.confirmation`;n.setTranslations({en:{[`${i}.apply`]:"Apply",[`${i}.before`]:"Before",[`${i}.after`]:"After",[`${o}.cancel`]:"Cancel",[`${o}.processing`]:"Generating..."}});let l=`${i}.canvasnMenu`,u={unlock:()=>{},abort:()=>{},applyCallbacks:void 0},s=()=>{let d=new AbortController,g=d.signal;return u.abort=()=>{d.abort()},g};n.ui.registerComponent(l,({builder:d,engine:g,state:f})=>{let v=g.block.findAllSelected();if(v.length===0)return null;let w=new Fa(n.engine,pl),b=w.get(v[0]);if(b==null)return null;let p=()=>{v.forEach(h=>{w.clear(h)})};switch(b.status){case"processing":{d.Button(`${o}.spinner`,{label:[`ly.img.ai.inference.${b.quickActionId}.processing`,`${o}.cancel`],isLoading:!0}),d.Separator(`${o}.separator`),d.Button(`${o}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.abort(),p()}});break}case"confirmation":{let h=f(`${i}.comparing`,"after"),m=u.applyCallbacks?.onCancel;m!=null&&d.Button(`${i}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{u.unlock(),m(),p()}});let y=u.applyCallbacks?.onBefore,k=u.applyCallbacks?.onAfter;y!=null&&k!=null&&d.ButtonGroup(`${i}.compare`,{children:()=>{d.Button(`${i}.compare.before`,{label:`${i}.before`,variant:"regular",isActive:h.value==="before",onClick:()=>{y(),h.setValue("before")}}),d.Button(`${i}.compare.after`,{label:`${i}.after`,variant:"regular",isActive:h.value==="after",onClick:()=>{k(),h.setValue("after")}})}});let C=u.applyCallbacks?.onApply;C!=null&&d.Button(`${i}.apply`,{icon:"@imgly/Checkmark",tooltip:`${i}.apply`,color:"accent",isDisabled:h.value!=="after",onClick:()=>{u.unlock(),p(),n.engine.editor._update(),C()}});break}default:}});let c=`${o}.canvasMenu`;return n.ui.registerComponent(c,d=>{let g=d.engine.block.findAllSelected(),f=g.every(m=>d.engine.block.getState(m).type==="Ready"),v=r.getQuickActionMenuOrder().map(m=>{if(m==="ly.img.separator")return m;let y=r.getQuickAction(m);if(y==null||!n.feature.isEnabled(ml({quickActionId:m,quickActionMenuId:r.id}),{engine:d.engine}))return null;let k=y.scopes;return k!=null&&k.length>0&&!g.every(C=>k.every(M=>d.engine.block.isAllowedByScope(C,M)))?null:y}).filter(m=>m!=null);if(v=q8(v),v.length===0||v.every(m=>m==="ly.img.separator"))return null;let{builder:w,experimental:b,state:p}=d,h=p(`${o}.toggleExpandedState`,void 0);b.builder.Popover(`${o}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!f,trailingIcon:null,children:({close:m})=>{w.Section(`${o}.popover.section`,{children:()=>{if(h.value!=null){let y=h.value,k=r.getQuickAction(y);if(k!=null&&k.renderExpanded!=null){k.renderExpanded(d,{blockIds:g,closeMenu:m,toggleExpand:()=>{h.setValue(void 0)},handleGenerationError:C=>{It(C,{cesdk:n,provider:a},t)},generate:async(C,M)=>{try{let{returnValue:I,applyCallbacks:x,dispose:$}=await Ba({input:C,quickAction:k,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:M?.blockIds??g,confirmationComponentId:l},t);return u.unlock=$,u.applyCallbacks=x,I}catch(I){throw Le(I)||It(I,{cesdk:n,provider:a},t),I}}});return}}b.builder.Menu(`${o}.menu`,{children:()=>{v.forEach(y=>{y==="ly.img.separator"?w.Separator(`${o}.separator.${Math.random().toString()}`):y.render(d,{blockIds:g,closeMenu:m,handleGenerationError:k=>{It(k,{cesdk:n,provider:a},t)},toggleExpand:()=>{h.setValue(y.id)},generate:async(k,C)=>{try{let{returnValue:M,applyCallbacks:I,dispose:x}=await Ba({input:k,quickAction:y,quickActionMenu:r,provider:a,cesdk:n,abortSignal:s(),blockIds:C?.blockIds??g,confirmationComponentId:l},t);return u.unlock=x,u.applyCallbacks=I,M}catch(M){throw Le(M)||It(M,{cesdk:n,provider:a},t),M}}})})}})}})}})}),{canvasMenuComponentId:c}}var d6=c6;async function g6(e,t,n){await e.initialize?.(t);let r=await m6(t.engine,e.id,e.output.history??"@imgly/local");if(t.cesdk==null)return{};let a=r?`${e.id}.history.entry`:void 0,o={...t,cesdk:t.cesdk,historyAssetSourceId:r,historyAssetLibraryEntryId:a,i18n:{prompt:"common.ai-generation.prompt.placeholder"}};a!=null&&r!=null&&t.cesdk.ui.addAssetLibraryEntry({id:a,sourceIds:[r],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),t.cesdk.i18n.setTranslations({en:{"common.ai-generation.success":"Generation Successful","common.ai-generation.failed":"Generation Failed","common.ai-generation.generate":"Generate","common.ai-generation.prompt.placeholder":"Describe what you want to create...",[`panel.${e.id}`]:p6(e)}});let i="@imgly/plugin-ai-generation.iconSetAdded";return t.cesdk.ui.experimental.hasGlobalStateValue(i)||(t.cesdk.ui.addIconSet("@imgly/plugin-ai-generation",G8),t.cesdk.ui.experimental.setGlobalStateValue(i,!0)),{renderBuilderFunctions:await f6(e,o,n)}}function p6(e){if(e.name!=null)return e.name;switch(e.kind){case"image":return"Generate Image";case"video":return"Generate Video";case"audio":return"Generate Audio";default:return"Generate Asset"}}async function m6(e,t,n){if(!(n==null||n===!1)){if(n==="@imgly/local"){let r=`${t}.history`;return e.asset.addLocalSource(r),r}if(n==="@imgly/indexedDB"){let r=`${t}.history`;return e.asset.addSource(new r9(r,e)),r}return n}}async function f6(e,t,n){let r={panel:void 0};return e.input?.panel!=null&&(r.panel=await y6(e,e.input.panel,t,n)),e.input?.quickActions!=null&&(n.debug&&console.log(`Initializing quick actions for provider '${e.kind}' (${e.id})`),b6(e,e.input.quickActions,t,n)),r}async function y6(e,t,n,r){switch(t.type){case"custom":return B8(e,t,n,r);case"schema":return U8(e,t,n,r);default:r.debug&&console.warn(`Invalid panel input type '${t.type}' - skipping`)}}async function b6(e,t,n,r){let{cesdk:a}=n,o={};t.actions.forEach(i=>{let l=i.kind??e.kind;o[l]==null&&(o[l]=gl(a,l));let u=o[l],s=i.enable??!0;a.feature.enable(ml({quickActionId:i.id,quickActionMenuId:l}),s),u.registerQuickAction(i),r.debug&&console.log(`Registered quick action: '${i.id}' (v${i.version}) to menu '${l}'`)}),Object.values(o).forEach(i=>{let{canvasMenuComponentId:l}=d6({cesdk:a,quickActionMenu:i,provider:e},r);r.debug&&console.log(`Registered quick action menu component: ${l}`)})}var h6=g6,v6="@imgly/plugin-ai-text-generation-web",k6=e=>({async initialize({cesdk:t}){if(t==null)return;let n=await e.provider?.({cesdk:t});h6(n,{cesdk:t,engine:t.engine},{debug:e.debug??!1,dryRun:!1});let r=gl(t,"text");r.setQuickActionMenuOrder(["improve","fix","shorter","longer","ly.img.separator","changeTone","translate","ly.img.separator","changeTextTo",...r.getQuickActionMenuOrder()]),t.ui.addIconSet(X5,t9),t.setTranslations({en:{"ly.img.ai.inference.apply":"Apply","ly.img.ai.inference.cancel":"Cancel","ly.img.ai.inference.improve":"Improve Writing","ly.img.ai.inference.improve.processing":"Improving Writing...","ly.img.ai.inference.fix":"Fix Spelling & Grammar","ly.img.ai.inference.fix.processing":"Fixing spelling & grammar...","ly.img.ai.inference.longer":"Make Longer","ly.img.ai.inference.longer.processing":"Making longer...","ly.img.ai.inference.shorter":"Make Shorter","ly.img.ai.inference.shorter.processing":"Making shorter...","ly.img.ai.inference.changeTone":"Change Tone","ly.img.ai.inference.changeTone.processing":"Changing tone...","ly.img.ai.inference.changeTone.type.professional":"Professional","ly.img.ai.inference.changeTone.type.casual":"Casual","ly.img.ai.inference.changeTone.type.friendly":"Friendly","ly.img.ai.inference.changeTone.type.serious":"Serious","ly.img.ai.inference.changeTone.type.humorous":"Humorous","ly.img.ai.inference.changeTone.type.optimistic":"Optimistic","ly.img.ai.inference.translate":"Translate","ly.img.ai.inference.translate.processing":"Translating...","ly.img.ai.inference.changeTextTo":"Change Text to...","ly.img.ai.inference.changeTextTo.processing":"Changing text..."}})}}),w6=e=>({name:v6,version:"0.1.9",...k6(e)}),fl=w6;var Sn=class{constructor(e,t,n){this.id=e,this.cesdk=t,this.assetSourceIds=n}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),n=await Promise.all(t),r=[];n.forEach(c=>{c?.assets&&(r=r.concat(c.assets))}),r.sort((c,d)=>{let g=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-g});let{page:a,perPage:o}=e,i=a*o,l=i+o,u=r.slice(i,l),s=l<r.length?a+1:void 0;return{assets:u,currentPage:a,nextPage:s,total:r.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(r=>this.cesdk.engine.asset.getGroups(r)),t=await Promise.all(e),n=new Set;return t.forEach(r=>{r.forEach(a=>n.add(a))}),Array.from(n)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}};var C6=typeof global=="object"&&global&&global.Object===Object&&global,Ll=C6,M6=typeof self=="object"&&self&&self.Object===Object&&self,I6=Ll||M6||Function("return this")(),G=I6,x6=G.Symbol,_e=x6,Tl=Object.prototype,A6=Tl.hasOwnProperty,S6=Tl.toString,Lt=_e?_e.toStringTag:void 0;function E6(e){var t=A6.call(e,Lt),n=e[Lt];try{e[Lt]=void 0;var r=!0}catch{}var a=S6.call(e);return r&&(t?e[Lt]=n:delete e[Lt]),a}var j6=E6,L6=Object.prototype,T6=L6.toString;function $6(e){return T6.call(e)}var N6=$6,D6="[object Null]",O6="[object Undefined]",yl=_e?_e.toStringTag:void 0;function _6(e){return e==null?e===void 0?O6:D6:yl&&yl in Object(e)?j6(e):N6(e)}var Dt=_6;function P6(e){return e!=null&&typeof e=="object"}var En=P6,cM=Array.isArray;function z6(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var $l=z6,U6="[object AsyncFunction]",V6="[object Function]",B6="[object GeneratorFunction]",F6="[object Proxy]";function G6(e){if(!$l(e))return!1;var t=Dt(e);return t==V6||t==B6||t==U6||t==F6}var R6=G6,q6=G["__core-js_shared__"],kn=q6,bl=function(){var e=/[^.]+$/.exec(kn&&kn.keys&&kn.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Q6(e){return!!bl&&bl in e}var H6=Q6,Y6=Function.prototype,Z6=Y6.toString;function W6(e){if(e!=null){try{return Z6.call(e)}catch{}try{return e+""}catch{}}return""}var Z=W6,K6=/[\\^$.*+?()[\]{}|]/g,J6=/^\[object .+?Constructor\]$/,X6=Function.prototype,ev=Object.prototype,tv=X6.toString,rv=ev.hasOwnProperty,nv=RegExp("^"+tv.call(rv).replace(K6,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function iv(e){if(!$l(e)||H6(e))return!1;var t=R6(e)?nv:J6;return t.test(Z(e))}var ov=iv;function av(e,t){return e?.[t]}var lv=av;function sv(e,t){var n=lv(e,t);return ov(n)?n:void 0}var Pe=sv,uv=Pe(G,"WeakMap"),Cn=uv;function cv(e,t){return e===t||e!==e&&t!==t}var dv=cv,gv=9007199254740991;function pv(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=gv}var mv=pv;var dM=Object.prototype;var fv="[object Arguments]";function yv(e){return En(e)&&Dt(e)==fv}var hl=yv,Nl=Object.prototype,bv=Nl.hasOwnProperty,hv=Nl.propertyIsEnumerable,gM=hl(function(){return arguments}())?hl:function(e){return En(e)&&bv.call(e,"callee")&&!hv.call(e,"callee")};var Dl=typeof exports=="object"&&exports&&!exports.nodeType&&exports,vl=Dl&&typeof module=="object"&&module&&!module.nodeType&&module,vv=vl&&vl.exports===Dl,kl=vv?G.Buffer:void 0,pM=kl?kl.isBuffer:void 0;var kv="[object Arguments]",wv="[object Array]",Cv="[object Boolean]",Mv="[object Date]",Iv="[object Error]",xv="[object Function]",Av="[object Map]",Sv="[object Number]",Ev="[object Object]",jv="[object RegExp]",Lv="[object Set]",Tv="[object String]",$v="[object WeakMap]",Nv="[object ArrayBuffer]",Dv="[object DataView]",Ov="[object Float32Array]",_v="[object Float64Array]",Pv="[object Int8Array]",zv="[object Int16Array]",Uv="[object Int32Array]",Vv="[object Uint8Array]",Bv="[object Uint8ClampedArray]",Fv="[object Uint16Array]",Gv="[object Uint32Array]",T={};T[Ov]=T[_v]=T[Pv]=T[zv]=T[Uv]=T[Vv]=T[Bv]=T[Fv]=T[Gv]=!0;T[kv]=T[wv]=T[Nv]=T[Cv]=T[Dv]=T[Mv]=T[Iv]=T[xv]=T[Av]=T[Sv]=T[Ev]=T[jv]=T[Lv]=T[Tv]=T[$v]=!1;function Rv(e){return En(e)&&mv(e.length)&&!!T[Dt(e)]}var qv=Rv;function Qv(e){return function(t){return e(t)}}var Hv=Qv,Ol=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Tt=Ol&&typeof module=="object"&&module&&!module.nodeType&&module,Yv=Tt&&Tt.exports===Ol,wn=Yv&&Ll.process,Zv=function(){try{var e=Tt&&Tt.require&&Tt.require("util").types;return e||wn&&wn.binding&&wn.binding("util")}catch{}}(),wl=Zv,Cl=wl&&wl.isTypedArray,mM=Cl?Hv(Cl):qv;var Wv=Object.prototype,fM=Wv.hasOwnProperty;function Kv(e,t){return function(n){return e(t(n))}}var Jv=Kv,yM=Jv(Object.keys,Object);var Xv=Object.prototype,bM=Xv.hasOwnProperty;var ek=Pe(Object,"create"),$t=ek;function tk(){this.__data__=$t?$t(null):{},this.size=0}var rk=tk;function nk(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var ik=nk,ok="__lodash_hash_undefined__",ak=Object.prototype,lk=ak.hasOwnProperty;function sk(e){var t=this.__data__;if($t){var n=t[e];return n===ok?void 0:n}return lk.call(t,e)?t[e]:void 0}var uk=sk,ck=Object.prototype,dk=ck.hasOwnProperty;function gk(e){var t=this.__data__;return $t?t[e]!==void 0:dk.call(t,e)}var pk=gk,mk="__lodash_hash_undefined__";function fk(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=$t&&t===void 0?mk:t,this}var yk=fk;function ze(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ze.prototype.clear=rk;ze.prototype.delete=ik;ze.prototype.get=uk;ze.prototype.has=pk;ze.prototype.set=yk;var Ml=ze;function bk(){this.__data__=[],this.size=0}var hk=bk;function vk(e,t){for(var n=e.length;n--;)if(dv(e[n][0],t))return n;return-1}var or=vk,kk=Array.prototype,wk=kk.splice;function Ck(e){var t=this.__data__,n=or(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():wk.call(t,n,1),--this.size,!0}var Mk=Ck;function Ik(e){var t=this.__data__,n=or(t,e);return n<0?void 0:t[n][1]}var xk=Ik;function Ak(e){return or(this.__data__,e)>-1}var Sk=Ak;function Ek(e,t){var n=this.__data__,r=or(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var jk=Ek;function Ue(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ue.prototype.clear=hk;Ue.prototype.delete=Mk;Ue.prototype.get=xk;Ue.prototype.has=Sk;Ue.prototype.set=jk;var ar=Ue,Lk=Pe(G,"Map"),Nt=Lk;function Tk(){this.size=0,this.__data__={hash:new Ml,map:new(Nt||ar),string:new Ml}}var $k=Tk;function Nk(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Dk=Nk;function Ok(e,t){var n=e.__data__;return Dk(t)?n[typeof t=="string"?"string":"hash"]:n.map}var lr=Ok;function _k(e){var t=lr(this,e).delete(e);return this.size-=t?1:0,t}var Pk=_k;function zk(e){return lr(this,e).get(e)}var Uk=zk;function Vk(e){return lr(this,e).has(e)}var Bk=Vk;function Fk(e,t){var n=lr(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var Gk=Fk;function Ve(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ve.prototype.clear=$k;Ve.prototype.delete=Pk;Ve.prototype.get=Uk;Ve.prototype.has=Bk;Ve.prototype.set=Gk;var _l=Ve;function Rk(){this.__data__=new ar,this.size=0}var qk=Rk;function Qk(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var Hk=Qk;function Yk(e){return this.__data__.get(e)}var Zk=Yk;function Wk(e){return this.__data__.has(e)}var Kk=Wk,Jk=200;function Xk(e,t){var n=this.__data__;if(n instanceof ar){var r=n.__data__;if(!Nt||r.length<Jk-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new _l(r)}return n.set(e,t),this.size=n.size,this}var ew=Xk;function Ot(e){var t=this.__data__=new ar(e);this.size=t.size}Ot.prototype.clear=qk;Ot.prototype.delete=Hk;Ot.prototype.get=Zk;Ot.prototype.has=Kk;Ot.prototype.set=ew;var tw=Object.prototype,hM=tw.propertyIsEnumerable;var rw=Pe(G,"DataView"),Mn=rw,nw=Pe(G,"Promise"),In=nw,iw=Pe(G,"Set"),xn=iw,Il="[object Map]",ow="[object Object]",xl="[object Promise]",Al="[object Set]",Sl="[object WeakMap]",El="[object DataView]",aw=Z(Mn),lw=Z(Nt),sw=Z(In),uw=Z(xn),cw=Z(Cn),Oe=Dt;(Mn&&Oe(new Mn(new ArrayBuffer(1)))!=El||Nt&&Oe(new Nt)!=Il||In&&Oe(In.resolve())!=xl||xn&&Oe(new xn)!=Al||Cn&&Oe(new Cn)!=Sl)&&(Oe=function(e){var t=Dt(e),n=t==ow?e.constructor:void 0,r=n?Z(n):"";if(r)switch(r){case aw:return El;case lw:return Il;case sw:return xl;case uw:return Al;case cw:return Sl}return t});var vM=G.Uint8Array;var dw="__lodash_hash_undefined__";function gw(e){return this.__data__.set(e,dw),this}var pw=gw;function mw(e){return this.__data__.has(e)}var fw=mw;function An(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new _l;++t<n;)this.add(e[t])}An.prototype.add=An.prototype.push=pw;An.prototype.has=fw;var jl=_e?_e.prototype:void 0,kM=jl?jl.valueOf:void 0;var yw=Object.prototype,wM=yw.hasOwnProperty;var bw=Object.prototype,CM=bw.hasOwnProperty;var MM=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),IM=new RegExp(/[A-Fa-f0-9]{1}/,"g"),xM=new RegExp(/[A-Fa-f0-9]{2}/,"g");var jn=class{constructor(t,n,r=[]){this.id=t,this.assets=[...r],this.activeAssetIds=new Set,this.loaderDisposer={},this.cesdk=n}async findAssets(t){let{page:n,perPage:r,locale:a="en",sortActiveFirst:o,query:i,tags:l,groups:u,excludeGroups:s,sortingOrder:c,sortKey:d}=t,g=[...this.assets];if(u&&u.length>0&&(g=g.filter(m=>m.groups&&u.some(y=>m.groups?.includes(y)))),s&&s.length>0&&(g=g.filter(m=>!m.groups||!s.some(y=>m.groups?.includes(y)))),i){let m=i.toLowerCase();g=g.filter(y=>{let k=y.label?.[a]?.toLowerCase(),C=y.tags?.[a]||[];return k&&k.includes(m)||C.some(M=>M.toLowerCase().includes(m))})}if(l&&l.length>0){let m=Array.isArray(l)?l:[l];g=g.filter(y=>{let k=y.tags?.[a]||[];return m.some(C=>k.includes(C))})}o&&g.sort((m,y)=>{let k=this.activeAssetIds.has(m.id),C=this.activeAssetIds.has(y.id);return k&&!C?-1:!k&&C?1:0}),d&&d!=="id"?g.sort((m,y)=>{let k=m.meta?.[d],C=y.meta?.[d];return k===void 0?1:C===void 0?-1:typeof k=="string"&&typeof C=="string"?c==="Descending"?C.localeCompare(k):k.localeCompare(C):typeof k=="number"&&typeof C=="number"?c==="Descending"?C-k:k-C:0}):d==="id"&&g.sort((m,y)=>c==="Descending"?y.id.localeCompare(m.id):m.id.localeCompare(y.id));let f=g.length,v=n*r,w=v+r,p=g.slice(v,w).map(m=>({id:m.id,groups:m.groups,meta:m.meta,payload:m.payload,locale:a,label:m.label?.[a],tags:m.tags?.[a],active:this.activeAssetIds.has(m.id)})),h=w<f?n+1:void 0;return{assets:p,currentPage:n,nextPage:h,total:f}}updateLabel(t,n,r){this.assets.forEach(a=>{a.id===t&&(a.label=a.label||{},a.label[r]=n(a.label[r]))})}getLabel(t,n){let r=this.assets.find(a=>a.id===t);if(r!=null)return r.label?.[n]}setAssetActive(t){this.activeAssetIds.add(t)}setAssetLoading(t,n){if(n){let r=this.getLabel(t,"en")??"",a=hw(o=>this.cesdk.engine.asset===null?!1:(this.updateLabel(t,()=>`${o} ${r}`,"en"),this.cesdk.engine.asset.assetSourceContentsChanged(this.id),!0));this.loaderDisposer[t]=()=>{this.updateLabel(t,()=>r,"en"),a()}}else this.loaderDisposer[t]?.(),this.loaderDisposer[t]=void 0}setAssetInactive(t){this.activeAssetIds.delete(t),this.loaderDisposer[t]?.(),this.loaderDisposer[t]=void 0}clearActiveAssets(){this.activeAssetIds.clear(),Object.values(this.loaderDisposer).forEach(t=>{t?.()}),this.loaderDisposer={}}isAssetActive(t){return this.activeAssetIds.has(t)}addAsset(t){let n=this.assets.findIndex(r=>r.id===t.id);n>=0?this.assets[n]=t:this.assets.push(t)}removeAsset(t){let n=this.assets.findIndex(r=>r.id===t);n!==-1&&(this.assets.splice(n,1),this.activeAssetIds.delete(t))}async getGroups(){let t=new Set;return this.assets.forEach(n=>{n.groups&&n.groups.forEach(r=>t.add(r))}),Array.from(t)}getSupportedMimeTypes(){return["image/jpeg","image/png","image/svg+xml","image/webp","video/mp4","audio/mpeg"]}};function Pl(e,t,n=[]){return new jn(e,t,n)}function hw(e,t=200){let n=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],r=0,a=setInterval(()=>{let o=n[r];r=(r+1)%n.length,e(o)||clearInterval(a)},t);return()=>{clearInterval(a)}}var Ln="ly.img.ai.apps";var N=Ut("apps"),sr=512,ur=128,zl=e=>({async initialize({cesdk:t}){if(t==null)return;let n=t.engine.scene.getMode()==="Video",{providers:r,baseURL:a="https://cdn.img.ly/assets/plugins/plugin-ai-apps-web/v1/"}=e,{activeAssetSource:o}=await vw(t,{isVideoMode:n,baseURL:a,debug:e.debug}),i=await W(t,o,r.text2text),l=await W(t,o,r.text2image),u=await W(t,o,r.image2image),s,c,d,g;n&&(s=await W(t,o,r.text2video),c=await W(t,o,r.image2video),d=await W(t,o,r.text2speech),g=await W(t,o,r.text2sound),t.addPlugin($o({text2video:s,image2video:c,debug:e.debug,dryRun:e.dryRun})),t.addPlugin(Ia({text2speech:d,text2sound:g,debug:e.debug,dryRun:e.dryRun}))),i!=null&&t.addPlugin(fl({provider:i,debug:e.debug})),t.addPlugin(Bi({text2image:l,image2image:u,debug:e.debug,dryRun:e.dryRun})),ww(t,{text2text:i,text2image:l,image2image:u,text2video:s,image2video:c,text2speech:d,text2sound:g},n),Cw(t)}});async function W(e,t,n){if(n==null)return;let r=await n({cesdk:e});if(t!=null){let a=async(o,i,l)=>{let u=`${r.kind}-generation`;r.kind==="audio"&&(r.id.includes("sound")?u="audio-generation/sound":r.id.includes("speech")&&(u="audio-generation/speech")),e.ui.experimental.setGlobalStateValue(`${N}.isGenerating`,!0),t.setAssetLoading(u,!0),e.engine.asset.assetSourceContentsChanged(N);try{return await l(o,i)}finally{e.engine.asset.assetSourceContentsChanged(N),t.setAssetLoading(u,!1),e.ui.experimental.setGlobalStateValue(`${N}.isGenerating`,!1)}};r.output.middleware=[...r.output.middleware??[],a]}return()=>Promise.resolve(r)}async function vw(e,t){let{isVideoMode:n,debug:r,baseURL:a}=t;kw(e);let o;n&&(o=Pl(N,e,[{id:"image-generation",label:{en:"Generate Image"},meta:{label:"Generate Image",thumbUri:`${a}GenerateImage.png`,width:sr,height:ur}},{id:"video-generation",label:{en:"Generate Video"},meta:{label:"Generate Video",thumbUri:`${a}GenerateVideo.png`,width:sr,height:ur}},{id:"audio-generation/sound",label:{en:"Generate Sound"},meta:{label:"Generate Sound",thumbUri:`${a}GenerateSound.png`,width:sr,height:ur}},{id:"audio-generation/speech",label:{en:"AI Voice"},meta:{label:"AI Voice",thumbUri:`${a}AIVoice.png`,width:sr,height:ur}}]),e.engine.asset.addSource(o),e.ui.registerPanel(N,({builder:l})=>{l.Library(N,{entries:[N],onSelect:async u=>{e.ui.openPanel(Ut(u.id))}})}),e.ui.addAssetLibraryEntry({id:N,sourceIds:[N],gridColumns:1,gridItemHeight:"auto",gridBackgroundType:"cover",cardLabel:({label:l})=>l,cardLabelPosition:()=>"inside"}));let i=`${N}.dock`;return n?(r&&console.log("Registering AI App Dock Button",i),e.ui.registerComponent(i,({builder:l,experimental:u})=>{let s=e.ui.isPanelOpen(N),c=u.global(`${N}.isGenerating`,!1);l.Button(`${N}.dock.button`,{label:"AI",isSelected:s,icon:c.value?"@imgly/LoadingSpinner":"@imgly/Sparkle",onClick:()=>{e.ui.findAllPanels().forEach(d=>{d.startsWith("ly.img.ai/")&&e.ui.closePanel(d),!s&&d==="//ly.img.panel/assetLibrary"&&e.ui.closePanel(d)}),s?e.ui.closePanel(N):e.ui.openPanel(N)}})})):e.ui.registerComponent(i,({builder:l,experimental:u})=>{let s=Ut("image-generation"),c=u.global(`${N}.isGenerating`,!1),d=e.ui.isPanelOpen(s);l.Button(`${N}.dock.button`,{label:"AI",isSelected:d,icon:c.value?"@imgly/LoadingSpinner":"@imgly/Sparkle",onClick:()=>{d?e.ui.closePanel(s):e.ui.openPanel(s)}})}),{activeAssetSource:o}}function kw(e){e.ui.registerComponent("ly.img.assetLibrary.dock",({builder:{Button:t},engine:n,payload:r})=>{let a="\n\nPlease provide a payload with entries, e.g. \n```\n{ id: 'ly.img.assetLibrary.dock', entries: ['ly.img.image', 'ly.img.video'] }\n```";if(!r||r.id!=="ly.img.assetLibrary.dock"){console.warn(`No payload found for 'ly.img.assetLibrary.dock'${a}`);return}let{id:o,key:i,label:l,icon:u,entries:s}=r;if(s==null||!Array.isArray(s)){console.warn(`No valid entries value found for 'ly.img.assetLibrary.dock'${a}`);return}if(s.some(b=>typeof b!="string")){console.warn(`Entries value for 'ly.img.assetLibrary.dock' need to be all strings referring to asset library entries${a}`);return}l!=null&&typeof l!="string"&&console.warn("Label for 'ly.img.assetLibrary.dock' must be a string if provided");let c=n.scene.getMode(),d=s.filter(b=>{let p=e.ui.getAssetLibraryEntry(b);if(p==null)return!1;let h=p.sceneMode;return typeof h=="string"?p.sceneMode===c||p.sceneMode==="All":typeof h=="function"?p.sourceIds.some(m=>{let y=h(e.version.startsWith("1.51.")?m:{sourceId:m});return y===c||y==="All"}):!0});if(d.length===0)return;let g=l;g==null&&(g=`libraries.${o}.label`);let f=e.ui.isPanelOpen("//ly.img.panel/assetLibrary",{payload:{entries:d,title:g}}),v=e.ui.isPanelOpen("//ly.img.panel/assetLibrary.replace"),w=u;w==null&&d.length===1&&(w=e.ui.getAssetLibraryEntry(d[0])?.icon),t(i??o,{label:g,icon:w,isDisabled:v,isSelected:f,onClick:()=>{f?e.ui.closePanel("//ly.img.panel/assetLibrary"):(e.ui.findAllPanels().forEach(b=>{(b===N||b.startsWith("ly.img.ai/"))&&e.ui.closePanel(b)}),e.ui.openPanel("//ly.img.panel/assetLibrary",{payload:{entries:d,title:g}}))}})})}async function ww(e,t,n){let r=await t.text2image?.({cesdk:e}),a=await t.image2image?.({cesdk:e}),o=new Sn("ly.img.ai/image-generation.history",e,[r!=null?`${r.id}.history`:void 0,a!=null?`${a?.id}.history`:void 0].filter(Boolean));e.engine.asset.addSource(o);let i=e.ui.getAssetLibraryEntry("ly.img.image");if(i!=null&&e.ui.updateAssetLibraryEntry("ly.img.image",{sourceIds:[...i.sourceIds,"ly.img.ai/image-generation.history"]}),!n)return;let l=await t.text2video?.({cesdk:e}),u=await t.image2video?.({cesdk:e}),s=new Sn("ly.img.ai/video-generation.history",e,[l!=null?`${l.id}.history`:void 0,u!=null?`${u?.id}.history`:void 0].filter(Boolean));e.engine.asset.addSource(s);let c=e.ui.getAssetLibraryEntry("ly.img.video");c!=null&&e.ui.updateAssetLibraryEntry("ly.img.video",{sourceIds:[...c.sourceIds,"ly.img.ai/video-generation.history"]});let d=await t.text2speech?.({cesdk:e}),g=await t.text2sound?.({cesdk:e}),f=e.ui.getAssetLibraryEntry("ly.img.audio"),v=[d!=null?`${d.id}.history`:void 0,g!=null?`${g.id}.history`:void 0].filter(Boolean);f!=null&&e.ui.updateAssetLibraryEntry("ly.img.audio",{sourceIds:[...f.sourceIds,...v]})}function Cw(e){e.i18n.setTranslations({en:{"panel.ly.img.ai.generation.confirmCancel.content":"Are you sure you want to cancel the generation?","panel.ly.img.ai.generation.confirmCancel.confirm":"Cancel Generation","panel.ly.img.ai/apps":"AI","panel.ly.img.ai/fal-ai/gemini-flash-edit.imageSelection":"Select Image To Change","panel.gpt-image-1.imageSelection":"Select Image To Change","panel.ly.img.ai/elevenlabs":"AI Voice","panel.ly.img.ai/demo.video":"Generate Video","panel.ly.img.ai/demo.image":"Generate Image","panel.fal-ai/minimax/video-01-live/image-to-video.imageSelection":"Select Image To Generate","panel.ly.img.ai/fal-ai/minimax/video-01-live/image-to-video.imageSelection":"Select Image To Generate","panel.fal-ai/gemini-flash-edit.imageSelection":"Select Image To Generate","libraries.ly.img.ai/fal-ai/recraft-v3.history.label":"Generated From Text","libraries.ly.img.ai/fal-ai/gemini-flash-edit.history.label":"Generated From Image","libraries.ly.img.ai/fal-ai/pixverse/v3.5/text-to-video.history.label":"Generated From Text","libraries.ly.img.ai/fal-ai/minimax/video-01-live/image-to-video.history.label":"Generated From Image","libraries.elevenlabs/monolingual/v1.history.label":"AI Voice","libraries.elevenlabs/sound-generation.history.label":"Generated Sound","libraries.ly.img.ai/image-generation.history.label":"AI Generated Images","libraries.ly.img.ai/video-generation.history.label":"AI Generated Videos"}})}var Mw=e=>({name:Ln,version:"0.1.9",...zl(e)}),RM=Mw;export{RM as default};
414
+ `,EP=SP;function _P(e){return async(t,r,i)=>e.enable?(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await K1(2e3),await LP(t,e,r)):i(t,r)}async function LP(e,t,r){switch(t.kind){case"image":return TP(e,t,r);case"video":return $P(e,t,r);case"text":return NP(e,t,r);case"audio":return DP(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function TP(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await TD(l,r),s=await La(u,r);i=s.width,n=s.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
415
+ `,"+")}`}}async function $P(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function NP(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,l=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);l&&l[1]&&(i=l[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=hi(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=hi(n,o)}else"customPrompt"in e?a=hi(n,"custom"):a=hi(n,"improved");else a=hi(n,"generated");return OP(a,r.abortSignal)}async function*OP(e,t){let r=Math.max(1,Math.ceil(e.length/20)),i=0;for(;i<e.length;){if(t?.aborted)return;let n=Math.min(i+r,e.length);yield{kind:"text",text:e.substring(0,n)},i=n,i<e.length&&await K1(100)}return{kind:"text",text:e}}function hi(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,l="";if(n<=o.length)l=o.substring(0,n);else{l=o;let u=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],s=0;for(;l.length<n;){let c=u[s%u.length];if(l.length+c.length<=n)l+=c;else{l+=c.substring(0,n-l.length);break}s++}}return r+l}async function DP(e,t,r){let i=3;if(e!=null&&typeof e=="object"){if("duration"in e&&typeof e.duration=="number")i=e.duration;else if("prompt"in e&&typeof e.prompt=="string"){let n=e.prompt.match(/(\d+)\s*(?:seconds?|secs?|s)\b/i);n&&(i=parseInt(n[1],10))}}return t.blockInputs?.audio?.duration&&(i=t.blockInputs.audio.duration),{kind:"audio",url:PP(220,i),duration:i,thumbnailUrl:void 0}}function PP(e,t){let r=Math.floor(44100*t),i=new Float32Array(r);for(let n=0;n<r;n++)i[n]=Math.sin(2*Math.PI*e*n/44100);return zP(i,44100)}function zP(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,l=r*i,u=44+l,s=new ArrayBuffer(u),c=new DataView(s),d=(b,m)=>{for(let h=0;h<m.length;h++)c.setUint8(b+h,m.charCodeAt(h))};d(0,"RIFF"),c.setUint32(4,u-8,!0),d(8,"WAVE"),d(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,n,!0),c.setUint32(24,t,!0),c.setUint32(28,o,!0),c.setUint16(32,a,!0),c.setUint16(34,16,!0),d(36,"data"),c.setUint32(40,l,!0);let p=44;for(let b=0;b<r;b++){let m=Math.max(-1,Math.min(1,e[b])),h=Math.round(m*32767);c.setInt16(p,h,!0),p+=2}let g=new Uint8Array(s),f="";for(let b=0;b<g.length;b++)f+=String.fromCharCode(g[b]);return`data:audio/wav;base64,${btoa(f)}`}async function K1(e){return new Promise(t=>{setTimeout(t,e)})}var UP=_P,J1="USER_CANCEL";function RP(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=ND([...e.provider.output.middleware??[],...r?.middlewares??[],DD({enable:r?.debug}),UP({enable:r?.dryRun,kind:e.provider.kind})]);try{let{result:n}=await i(e.provider.output.generate)(t,{abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk});return r?.abortSignal?.aborted?{status:"aborted"}:n instanceof Error?{status:"error",message:n.message}:n==null?{status:"error",message:"No output generated"}:RD(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return za(n)?{status:"aborted",message:n.message}:n===J1?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var FP=RP;async function VP(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n};await t.initialize?.({...r,engine:r.cesdk.engine});let o=AP(a),l=jP(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=l;let u=FP({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),s=await IP(a,u);FD(r.cesdk,"@imgly/plugin-ai-generation",EP);let c={provider:t,panel:{builderRenderFunction:s},history:{assetSourceId:o,assetLibraryEntryId:l},generate:u};return z1.get().register(c),c}var Ia=VP;function BP(e){let{kind:t,cesdk:r,historAssetSourceIds:i}=e,n=`ly.img.ai.${t}-generation.history`;if(r.engine.asset.findAllSources().includes(n))return n;let a=new $$(n,r,i);return r.engine.asset.addSource(a),a.id}var GP=BP;async function qP(e,t,r,i){let n,a=[];if(Array.isArray(t)){let l=await Promise.all(t.map(u=>Ia(e,u,r,i)));a.push(...l),n=HP({prefix:e,providerInitializationResults:a})}else{let l=await Promise.all(t.fromText.map(s=>Ia(e,s,r,i)));a.push(...l);let u=await Promise.all(t.fromImage.map(s=>Ia(e,s,r,i)));a.push(...u),n=YP({prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u})}let o=GP({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(l=>l.history?.assetSourceId).filter(En)});return{panel:{builderRenderFunction:n},history:{assetSourceId:o},providerInitializationResults:a}}function YP({prefix:e,initializedFromTextProviders:t,initializedFromImageProviders:r}){let i=t.length>0&&r.length>0;return n=>{let{builder:a,experimental:o}=n,l=o.global(`${e}.fromType`,i?"fromText":void 0),u=[];l.value==="fromText"?u.push(...t):l.value==="fromImage"?u.push(...r):u.push(...t,...r);let s=t.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),c=r.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),d=n.experimental.global(`${e}.selectedProvider.fromText`,s[0]),p=n.experimental.global(`${e}.selectedProvider.fromImage`,c[0]),g=l.value==="fromText"?d:l.value==="fromImage"?p:void 0;if((i||u.length>1)&&a.Section(`${e}.providerSelection.section`,{children:()=>{if(i&&a.ButtonGroup(`${e}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{a.Button(`${e}.fromType.buttonGroup.fromText`,{label:"Text",icon:l.value!=="fromText"&&l1(t,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromText",onClick:()=>{l.setValue("fromText")}}),a.Button(`${e}.fromType.buttonGroup.fromImage`,{label:"Image",icon:l.value!=="fromImage"&&l1(r,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromImage",onClick:()=>{l.setValue("fromImage")}})}}),u.length>1){let f=l.value==="fromText"?s:l.value==="fromImage"?c:[...s,...c];g!=null&&a.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:f,...g})}}}),u.length>1)g?.value.builderRenderFunction?.(n);else{let f=u[0];f&&f.panel?.builderRenderFunction?.(n)}}}function HP({prefix:e,providerInitializationResults:t}){return r=>{let{builder:i}=r;if(t.length===0)return;let n=t.map(({provider:o,panel:l})=>({id:o.id,label:o.name??o.id,builderRenderFunction:l?.builderRenderFunction})),a=r.state(`${e}.selectedProvider`,n[0]);t.length>1&&a!=null&&i.Section(`${e}.providerSelection.section`,{children:()=>{i.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:n,...a})}}),a.value.builderRenderFunction?.(r)}}function l1(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Ra(r.id),!1).value)}var ZP=qP,_n="ly.img.ai.editMode",X1="ly.img.ai.metadata";async function QP(e){let t=`ly.img.ai.${e.kind}.confirmation`;e.cesdk?.i18n.setTranslations({en:{"ly.img.ai.processing":"Generating...",[`${t}.cancel`]:"Cancel Generation",[`${t}.apply`]:"Apply Generation",[`${t}.before`]:"Before",[`${t}.after`]:"After"}});let r=i=>{let{engine:n,builder:a,state:o,payload:l}=i;if(l==null)return;let u=n.block.findAllSelected();if(u.length===0)return null;let s=new j1(n,X1),c=s.get(u[0]);if(c==null)return null;let d=()=>{u.forEach(p=>{s.clear(p)})};switch(c.status){case"processing":{a.Button(`${t}.spinner`,{label:[`ly.img.ai.${c.quickActionId}.processing`,"ly.img.ai.processing"],isLoading:!0}),a.Separator(`${t}.separator`),a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{l.onCancelGeneration?.(),d()}});break}case"confirmation":{let p=o(`${t}.comparing`,"after"),g=l.applyCallbacks?.onCancel;g!=null&&a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{g(),d()}});let f=l.applyCallbacks?.onBefore,b=l.applyCallbacks?.onAfter;f!=null&&b!=null&&a.ButtonGroup(`${t}.compare`,{children:()=>{a.Button(`${t}.compare.before`,{label:`${t}.before`,variant:"regular",isActive:p.value==="before",onClick:()=>{f(),p.setValue("before")}}),a.Button(`${t}.compare.after`,{label:`${t}.after`,variant:"regular",isActive:p.value==="after",onClick:()=>{b(),p.setValue("after")}})}});let m=l.applyCallbacks?.onApply;m!=null&&a.Button(`${t}.apply`,{icon:"@imgly/Checkmark",tooltip:`${t}.apply`,color:"accent",isDisabled:p.value!=="after",onClick:()=>{d(),cesdk?.engine.editor._update(),m()}});break}default:}};return Promise.resolve(r)}var WP=QP;function KP(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((r,i)=>(i==="ly.img.separator"&&r.length>0&&r[r.length-1]==="ly.img.separator"||r.push(i),r),[])}var JP=KP;function XP(e){return`ly.img.ai.${e}.canvasMenu`}var ez=XP;function tz(e){let{kind:t,cesdk:r,payload:i,defaultOrder:n}=e,a=ez(t);if(i==null||!Array.isArray(i.children)){let o=r.ui.getCanvasMenuOrder().find(({id:l})=>l===a);return o!=null&&Array.isArray(o.children)?o.children:n??[]}return i.children.filter(o=>typeof o=="string")}var rz=tz;function iz(e,t){if(t.blockIds.some(r=>!t.cesdk.engine.block.isValid(r)))return Promise.resolve({applyCallbacks:{onBefore:()=>{},onAfter:()=>{},onCancel:()=>{},onApply:()=>{}}});switch(t.kind){case"text":return nz(e,t);case"image":return oz(e,t);case"video":return az(e,t);case"audio":return lz(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function nz(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t,a=i.map(s=>r.engine.block.getString(s,"text/text")),o;if(e.type==="async"){let s="";for await(let c of e.output){if(n?.aborted)break;typeof c=="string"?s=c:c.kind==="text"&&(s=c.text),i.forEach(d=>{r.engine.block.setString(d,"text/text",s)}),o={kind:"text",text:s}}}else o=e.output;if(o==null||o.kind!=="text")throw new Error("Output kind from generation is not text");e.type==="sync"&&i.forEach(s=>{r.engine.block.setString(s,"text/text",o.text)});let l=()=>{t.blockIds.forEach(s=>{t.cesdk.engine.block.setString(s,"text/text",o.text)})},u=()=>{t.blockIds.forEach((s,c)=>{t.cesdk.engine.block.setString(s,"text/text",a[c])})};return{applyCallbacks:{onBefore:u,onAfter:l,onCancel:u,onApply:()=>{l(),t.cesdk.engine.editor.addUndoStep()}}}}async function oz(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t;if(i.length!==1)throw new Error("Only one block is supported for image generation");let[a]=i,o=r.engine.block.getFill(a),l=r.engine.block.getSourceSet(o,"fill/image/sourceSet"),[u]=l,s;u==null&&(s=r.engine.block.getString(o,"fill/image/imageFileURI"));let c=await r.engine.editor.getMimeType(u?.uri??s),d=await La(u?.uri??s,t.cesdk.engine),p=d.width/d.height;if(n?.throwIfAborted(),c==="image/svg+xml")throw new Error("SVG images are not supported");let g=r.engine.block.getCropScaleX(a),f=r.engine.block.getCropScaleY(a),b=r.engine.block.getCropTranslationX(a),m=r.engine.block.getCropTranslationY(a),h=r.engine.block.getCropRotation(a),x=()=>{r.engine.block.setCropScaleX(a,g),r.engine.block.setCropScaleY(a,f),r.engine.block.setCropTranslationX(a,b),r.engine.block.setCropTranslationY(a,m),r.engine.block.setCropRotation(a,h)};if(e.type==="async")throw new Error("Streaming generation is not supported yet from a panel");if(e.output.kind!=="image"||typeof e.output.url!="string")throw new Error("Output kind from generation is not an image");let w=e.output.url,v=await r.engine.editor.getMimeType(w),y=await sz(r,w,v),k=await La(y,t.cesdk.engine),I=k.width/k.height,U=Math.abs(p-I)>.001,C=u?[{uri:y,width:k.width,height:k.height}]:void 0,be=y;C==null?r.engine.block.setString(o,"fill/image/imageFileURI",be):(r.engine.block.setString(o,"fill/image/imageFileURI",""),r.engine.block.setSourceSet(o,"fill/image/sourceSet",C)),await r.engine.block.forceLoadResources([o]),U?r.engine.block.setContentFillMode(a,"Cover"):x();let ar=()=>{if(l==null||l.length===0){if(s==null)throw new Error("No image URI found");r.engine.block.setString(o,"fill/image/imageFileURI",s)}else r.engine.block.setSourceSet(o,"fill/image/sourceSet",l);x()},lr=()=>{if(C==null){if(be==null)throw new Error("No image URI found");r.engine.block.setString(o,"fill/image/imageFileURI",be)}else r.engine.block.setSourceSet(o,"fill/image/sourceSet",C);U?r.engine.block.setContentFillMode(a,"Cover"):x()};return{applyCallbacks:{onBefore:ar,onAfter:lr,onCancel:()=>{ar()},onApply:()=>{lr(),t.cesdk.engine.editor.addUndoStep()}}}}async function az(e,t){throw new Error("Function not implemented.")}async function lz(e,t){throw new Error("Function not implemented.")}async function sz(e,t,r){let i=await(await fetch(t)).blob(),n=new File([i],`image.${LD(r)}`,{type:r}),a=await e.unstable_upload(n,()=>{});return a?.meta?.uri??(console.warn("Failed to upload image:",a),t)}var uz=iz;function cz(e){let{engine:t,blockIdsToLock:r,editModeToLockTo:i}=e;function n(){let u=t.block.findAllSelected();return r.some(s=>u.includes(s))}let a=t.editor.onStateChanged(()=>{t.editor.getEditMode()!==i&&n()&&t.editor.setEditMode(i)}),o=t.block.onSelectionChanged(()=>{n()?t.editor.setEditMode(i):t.editor.setEditMode("Transform")});n()&&t.editor.setEditMode(i);let l=!1;return()=>{l||(o(),a(),t.editor.setEditMode("Transform"),l=!0)}}var dz=cz,pz=class ep{constructor(){this.actions=new Map}static get(){let t="__imgly_callbacks_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new ep),r[t]}register(t,r){let i=this.actions.get(t)??{};this.actions.set(t,{...i,...r})}get(t){return this.actions.get(t)??{}}},_e=pz;function gz(e){return async(t,r)=>{let i=r?.blockIds??e.blockIds;if(e.providerInitializationResult==null)return e.debug&&console.warn("[Generate] No provider initialization result found for quick action. Returning abortion status."),{status:"aborted"};let n=e.providerInitializationResult?.provider.input?.quickActions?.supported?.[e.quickAction.id];if(n==null)throw new Error("[Generate] Quick action input mapping failed. Ensure the provider supports this quick action.");let a=typeof n=="object"&&n!==null&&"mapInput"in n?n.mapInput:c=>c;e.close();let o=new AbortController,l=AbortSignal.any([e.abortSignal,o.signal].filter(En)),u=new j1(e.cesdk.engine,X1),s=e.lock??!0?dz({engine:e.cesdk.engine,editModeToLockTo:_n,blockIdsToLock:i}):()=>{};i.forEach(c=>{_e.get().register(c,{onCancelGeneration:()=>{o.abort(J1),s(),e.cesdk.engine.block.isValid(c)&&(e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Ready"}),u.clear(c))}})}),i?.forEach(c=>{u.set(c,{status:"processing",quickActionId:e.quickAction.id})}),i.forEach(c=>{e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Pending",progress:0})});try{let c=await e.providerInitializationResult.generate(a(t),{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:l}),d=c.status;switch(d){case"success":{let{applyCallbacks:p}=await uz(c,{kind:e.providerInitializationResult.provider.kind,blockIds:i,cesdk:e.cesdk,abortSignal:l});if(i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&e.cesdk.engine.block.setState(g,{type:"Ready"})}),e.confirmation){i.forEach(f=>{u.set(f,{status:"confirmation",quickActionId:e.quickAction.id})});let g={...p,onApply:async()=>{p.onApply(),s()},onCancel:()=>{p.onCancel(),s()}};i.forEach(f=>{_e.get().register(f,{applyCallbacks:g})})}else i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&u.clear(g)}),p.onApply(),s();return c}case"aborted":return e.debug&&console.log("Generation was aborted"),s(),i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&u.clear(p)}),c;case"error":return s(),i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&u.clear(p)}),console.error(`[Generate]: ${c.message}`),c;default:throw new Error(`[Generate] Unknown result status ${d}.`)}}catch(c){throw e.cesdk.ui.showNotification({type:"error",message:"A technical issue has occurred."}),s(),i.forEach(d=>{e.cesdk.engine.block.isValid(d)&&u.clear(d)}),c}finally{i.forEach(c=>{e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Ready"})})}}}var s1=gz;function fz(e){let t=`ly.img.ai.${e.kind}}`;e.cesdk.i18n.setTranslations({en:{[`${t}.quickActionMenu.providerSelect.label`]:"Provider"}});let r=i=>{if(i.engine.editor.getEditMode()===_n)return;let n=i.engine.block.findAllSelected();if(n.length===0)return;let{payload:a}=i,o=rz({kind:e.kind,cesdk:e.cesdk,payload:a,defaultOrder:e.defaultOrder})??[];if(o.length===0)return;let l=hz(o).filter(v=>{if(v==="ly.img.separator")return!0;let y=v.scopes;if(y!=null&&y.length>0&&!n.every(k=>y.every(I=>e.engine.block.isAllowedByScope(k,I))))return!1;if(v.enable!=null){if(typeof v.enable=="function")return v.enable({engine:e.engine});if(typeof v.enable=="boolean")return v.enable}return!0}),u=[],s=e.providerInitializationResults.reduce((v,y)=>{if(y.provider.kind!==e.kind)return v;let k=l.map(I=>{if(I==="ly.img.separator")return I;if(y.provider.input?.quickActions?.supported?.[I.id]!=null)return{definition:I};{let U=z1.get().getAll().filter(C=>C.provider.kind!==e.kind&&C.provider.id!==y.provider.id).find(C=>C.provider.input?.quickActions?.supported?.[I.id]!=null);if(U!=null){let C={definition:I,providerInitializationResult:U};return u.push(C),C}else return}}).filter(En);return k=JP(k),k.length===0||k.every(I=>I==="ly.img.separator")||k.every(I=>I==="ly.img.separator"||I.providerInitializationResult!=null)||v.push({providerInitializationResult:y,quickActions:k}),v},[]);if(s.length===0)if(u.length>0){let v=new Map;u.forEach(k=>{let I=k.definition.id;v.has(I)||v.set(I,k)});let y=Array.from(v.values());s.push({providerInitializationResult:y[0].providerInitializationResult??e.providerInitializationResults[0],quickActions:y})}else return;let c=s.map(({providerInitializationResult:v})=>({id:v.provider.id,label:v.provider.name??v.provider.id})),d=i.experimental.global(`${t}.currentProvider`,c[0]),p=s.find(({providerInitializationResult:{provider:{id:v}}})=>v===d.value?.id),g=n.every(v=>i.engine.block.getState(v).type==="Ready"),{builder:f,experimental:b,state:m}=i,h=m(`${t}.isGenerating`,!1),x=m(`${t}.toggleExpandedState`,void 0),w=async(v,y,k)=>{h.setValue(!0);try{return await k(v,y)}finally{h.setValue(!1)}};b.builder.Popover(`${t}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!g,isLoading:h.value,trailingIcon:null,children:({close:v})=>{f.Section(`${t}.popover.section`,{children:()=>{if(x.value!==void 0){let y=p?.quickActions.find(k=>k!=="ly.img.separator"&&k.definition.id===x.value);return y!=null&&y.definition.render!=null?y.definition.render({...i,toggleExpand:()=>{x.setValue(void 0)},isExpanded:!0,generate:s1({blockIds:n,providerInitializationResult:y.providerInitializationResult??p?.providerInitializationResult,quickAction:y.definition,middlewares:[w],confirmation:y.definition.defaults?.confirmation??!0,close:v,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:v,providerId:d.value.id}):void 0}x.value==null&&c.length>1&&(f.Select(`${t}.providerSelect.select`,{inputLabel:`${t}.quickActionMenu.providerSelect.label`,values:c,...d}),f.Separator(`${t}.providerSelect.separator`)),b.builder.Menu(`${t}.menu`,{children:()=>{p?.quickActions.forEach(y=>{if(y==="ly.img.separator"){f.Separator(`${t}.separator.${Math.random().toString()}`);return}y.definition.render!=null&&y.definition.render({...i,toggleExpand:()=>{x.setValue(y.definition.id)},isExpanded:!1,generate:s1({blockIds:n,providerInitializationResult:y.providerInitializationResult??p?.providerInitializationResult,quickAction:y.definition,middlewares:[w],confirmation:y.definition.defaults?.confirmation??!0,close:v,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:v,providerId:d.value.id})})}})}})}})};return Promise.resolve(r)}function hz(e){return e.map(t=>t==="ly.img.separator"?t:D1.get().getBy({id:t,type:"quick"})[0]).filter(En)}var mz=fz;async function yz(e){let t=await mz({kind:e.kind,providerInitializationResults:e.providerInitializationResults,cesdk:e.cesdk,engine:e.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:e.defaultOrder}),r=await WP({kind:e.kind,cesdk:e.cesdk});return{renderFunction:i=>{let{engine:n}=i;if(n.editor.getEditMode()===_n){let a=i.engine.block.findAllSelected();r({...i,payload:{...i.payload??{},applyCallbacks:{onBefore:()=>{a.forEach(o=>{_e.get().get(o).applyCallbacks?.onBefore?.()})},onAfter:()=>{a.forEach(o=>{_e.get().get(o).applyCallbacks?.onAfter?.()})},onCancel:()=>{a.forEach(o=>{_e.get().get(o).applyCallbacks?.onCancel?.()})},onApply:()=>{a.forEach(o=>{_e.get().get(o).applyCallbacks?.onApply?.()})}},onCancelGeneration:()=>{a.forEach(o=>{_e.get().get(o).onCancelGeneration?.()})}}});return}t(i)}}}var bz=yz,vz=typeof global=="object"&&global&&global.Object===Object&&global,tp=vz,wz=typeof self=="object"&&self&&self.Object===Object&&self,kz=tp||wz||Function("return this")(),ee=kz,xz=ee.Symbol,zt=xz,rp=Object.prototype,Iz=rp.hasOwnProperty,Cz=rp.toString,mi=zt?zt.toStringTag:void 0;function Az(e){var t=Iz.call(e,mi),r=e[mi];try{e[mi]=void 0;var i=!0}catch{}var n=Cz.call(e);return i&&(t?e[mi]=r:delete e[mi]),n}var Mz=Az,jz=Object.prototype,Sz=jz.toString;function Ez(e){return Sz.call(e)}var _z=Ez,Lz="[object Null]",Tz="[object Undefined]",u1=zt?zt.toStringTag:void 0;function $z(e){return e==null?e===void 0?Tz:Lz:u1&&u1 in Object(e)?Mz(e):_z(e)}var Si=$z;function Nz(e){return e!=null&&typeof e=="object"}var Fa=Nz,EJ=Array.isArray;function Oz(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var ip=Oz,Dz="[object AsyncFunction]",Pz="[object Function]",zz="[object GeneratorFunction]",Uz="[object Proxy]";function Rz(e){if(!ip(e))return!1;var t=Si(e);return t==Pz||t==zz||t==Dz||t==Uz}var Fz=Rz,Vz=ee["__core-js_shared__"],Ca=Vz,c1=function(){var e=/[^.]+$/.exec(Ca&&Ca.keys&&Ca.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Bz(e){return!!c1&&c1 in e}var Gz=Bz,qz=Function.prototype,Yz=qz.toString;function Hz(e){if(e!=null){try{return Yz.call(e)}catch{}try{return e+""}catch{}}return""}var Te=Hz,Zz=/[\\^$.*+?()[\]{}|]/g,Qz=/^\[object .+?Constructor\]$/,Wz=Function.prototype,Kz=Object.prototype,Jz=Wz.toString,Xz=Kz.hasOwnProperty,eU=RegExp("^"+Jz.call(Xz).replace(Zz,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function tU(e){if(!ip(e)||Gz(e))return!1;var t=Fz(e)?eU:Qz;return t.test(Te(e))}var rU=tU;function iU(e,t){return e?.[t]}var nU=iU;function oU(e,t){var r=nU(e,t);return rU(r)?r:void 0}var Bt=oU,aU=Bt(ee,"WeakMap"),Ta=aU;function lU(e,t){return e===t||e!==e&&t!==t}var sU=lU,uU=9007199254740991;function cU(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=uU}var dU=cU,_J=Object.prototype,pU="[object Arguments]";function gU(e){return Fa(e)&&Si(e)==pU}var d1=gU,np=Object.prototype,fU=np.hasOwnProperty,hU=np.propertyIsEnumerable,LJ=d1(function(){return arguments}())?d1:function(e){return Fa(e)&&fU.call(e,"callee")&&!hU.call(e,"callee")},op=typeof exports=="object"&&exports&&!exports.nodeType&&exports,p1=op&&typeof module=="object"&&module&&!module.nodeType&&module,mU=p1&&p1.exports===op,g1=mU?ee.Buffer:void 0,TJ=g1?g1.isBuffer:void 0,yU="[object Arguments]",bU="[object Array]",vU="[object Boolean]",wU="[object Date]",kU="[object Error]",xU="[object Function]",IU="[object Map]",CU="[object Number]",AU="[object Object]",MU="[object RegExp]",jU="[object Set]",SU="[object String]",EU="[object WeakMap]",_U="[object ArrayBuffer]",LU="[object DataView]",TU="[object Float32Array]",$U="[object Float64Array]",NU="[object Int8Array]",OU="[object Int16Array]",DU="[object Int32Array]",PU="[object Uint8Array]",zU="[object Uint8ClampedArray]",UU="[object Uint16Array]",RU="[object Uint32Array]",N={};N[TU]=N[$U]=N[NU]=N[OU]=N[DU]=N[PU]=N[zU]=N[UU]=N[RU]=!0;N[yU]=N[bU]=N[_U]=N[vU]=N[LU]=N[wU]=N[kU]=N[xU]=N[IU]=N[CU]=N[AU]=N[MU]=N[jU]=N[SU]=N[EU]=!1;function FU(e){return Fa(e)&&dU(e.length)&&!!N[Si(e)]}var VU=FU;function BU(e){return function(t){return e(t)}}var GU=BU,ap=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ki=ap&&typeof module=="object"&&module&&!module.nodeType&&module,qU=ki&&ki.exports===ap,Aa=qU&&tp.process,YU=function(){try{var e=ki&&ki.require&&ki.require("util").types;return e||Aa&&Aa.binding&&Aa.binding("util")}catch{}}(),f1=YU,h1=f1&&f1.isTypedArray,$J=h1?GU(h1):VU,HU=Object.prototype,NJ=HU.hasOwnProperty;function ZU(e,t){return function(r){return e(t(r))}}var QU=ZU,OJ=QU(Object.keys,Object),WU=Object.prototype,DJ=WU.hasOwnProperty,KU=Bt(Object,"create"),Ci=KU;function JU(){this.__data__=Ci?Ci(null):{},this.size=0}var XU=JU;function eR(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var tR=eR,rR="__lodash_hash_undefined__",iR=Object.prototype,nR=iR.hasOwnProperty;function oR(e){var t=this.__data__;if(Ci){var r=t[e];return r===rR?void 0:r}return nR.call(t,e)?t[e]:void 0}var aR=oR,lR=Object.prototype,sR=lR.hasOwnProperty;function uR(e){var t=this.__data__;return Ci?t[e]!==void 0:sR.call(t,e)}var cR=uR,dR="__lodash_hash_undefined__";function pR(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Ci&&t===void 0?dR:t,this}var gR=pR;function Gt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Gt.prototype.clear=XU;Gt.prototype.delete=tR;Gt.prototype.get=aR;Gt.prototype.has=cR;Gt.prototype.set=gR;var m1=Gt;function fR(){this.__data__=[],this.size=0}var hR=fR;function mR(e,t){for(var r=e.length;r--;)if(sU(e[r][0],t))return r;return-1}var Ln=mR,yR=Array.prototype,bR=yR.splice;function vR(e){var t=this.__data__,r=Ln(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():bR.call(t,r,1),--this.size,!0}var wR=vR;function kR(e){var t=this.__data__,r=Ln(t,e);return r<0?void 0:t[r][1]}var xR=kR;function IR(e){return Ln(this.__data__,e)>-1}var CR=IR;function AR(e,t){var r=this.__data__,i=Ln(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var MR=AR;function qt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}qt.prototype.clear=hR;qt.prototype.delete=wR;qt.prototype.get=xR;qt.prototype.has=CR;qt.prototype.set=MR;var Tn=qt,jR=Bt(ee,"Map"),Ai=jR;function SR(){this.size=0,this.__data__={hash:new m1,map:new(Ai||Tn),string:new m1}}var ER=SR;function _R(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var LR=_R;function TR(e,t){var r=e.__data__;return LR(t)?r[typeof t=="string"?"string":"hash"]:r.map}var $n=TR;function $R(e){var t=$n(this,e).delete(e);return this.size-=t?1:0,t}var NR=$R;function OR(e){return $n(this,e).get(e)}var DR=OR;function PR(e){return $n(this,e).has(e)}var zR=PR;function UR(e,t){var r=$n(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var RR=UR;function Yt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Yt.prototype.clear=ER;Yt.prototype.delete=NR;Yt.prototype.get=DR;Yt.prototype.has=zR;Yt.prototype.set=RR;var lp=Yt;function FR(){this.__data__=new Tn,this.size=0}var VR=FR;function BR(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var GR=BR;function qR(e){return this.__data__.get(e)}var YR=qR;function HR(e){return this.__data__.has(e)}var ZR=HR,QR=200;function WR(e,t){var r=this.__data__;if(r instanceof Tn){var i=r.__data__;if(!Ai||i.length<QR-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new lp(i)}return r.set(e,t),this.size=r.size,this}var KR=WR;function Ei(e){var t=this.__data__=new Tn(e);this.size=t.size}Ei.prototype.clear=VR;Ei.prototype.delete=GR;Ei.prototype.get=YR;Ei.prototype.has=ZR;Ei.prototype.set=KR;var JR=Object.prototype,PJ=JR.propertyIsEnumerable,XR=Bt(ee,"DataView"),$a=XR,eF=Bt(ee,"Promise"),Na=eF,tF=Bt(ee,"Set"),Oa=tF,y1="[object Map]",rF="[object Object]",b1="[object Promise]",v1="[object Set]",w1="[object WeakMap]",k1="[object DataView]",iF=Te($a),nF=Te(Ai),oF=Te(Na),aF=Te(Oa),lF=Te(Ta),Ot=Si;($a&&Ot(new $a(new ArrayBuffer(1)))!=k1||Ai&&Ot(new Ai)!=y1||Na&&Ot(Na.resolve())!=b1||Oa&&Ot(new Oa)!=v1||Ta&&Ot(new Ta)!=w1)&&(Ot=function(e){var t=Si(e),r=t==rF?e.constructor:void 0,i=r?Te(r):"";if(i)switch(i){case iF:return k1;case nF:return y1;case oF:return b1;case aF:return v1;case lF:return w1}return t});var zJ=ee.Uint8Array,sF="__lodash_hash_undefined__";function uF(e){return this.__data__.set(e,sF),this}var cF=uF;function dF(e){return this.__data__.has(e)}var pF=dF;function Da(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new lp;++t<r;)this.add(e[t])}Da.prototype.add=Da.prototype.push=cF;Da.prototype.has=pF;var x1=zt?zt.prototype:void 0,UJ=x1?x1.valueOf:void 0,gF=Object.prototype,RJ=gF.hasOwnProperty,fF=Object.prototype,FJ=fF.hasOwnProperty,VJ=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),BJ=new RegExp(/[A-Fa-f0-9]{1}/,"g"),GJ=new RegExp(/[A-Fa-f0-9]{2}/,"g");function hF(e){return e==null?[]:Array.isArray(e)?e:[e]}var mF=hF;function yF(e){return`
416
+ You are an AI writing assistant tasked with improving a given text based on a specific type of improvement requested. Your goal is to enhance the text while maintaining its original meaning and intent.
417
+
418
+ Here is the original text you will be working with:
419
+
420
+ <original_text>
421
+ ${e}
422
+ </original_text>
423
+
424
+ Please follow these steps to improve the text:
425
+
426
+ 1. Carefully read and analyze the original text.
427
+ 2. Consider the specific improvement type requested and how it applies to the given text.
428
+ 3. Make the necessary changes to improve the text according to the requested improvement type. This may include:
429
+ - Rephrasing sentences
430
+ - Adjusting vocabulary
431
+ - Restructuring paragraphs
432
+ - Adding or removing content as appropriate
433
+ 4. Ensure that the improved version maintains the original meaning and intent of the text.
434
+ 5. Return the improved text without any additional commentary or explanation.
435
+ 6. If there is nothing to improve, simply return the original text without any changes.
436
+ 7. If you cannot make any meaningful improvements, return the original text as is.
437
+
438
+ Once you have made the improvements, only return the improved text and nothing else.
439
+ `}var bF=yF,sp="improve",I1=`ly.img.${sp}`,kn=`ly.img.ai.quickAction.text.${sp}`,vF=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${kn}.label`]:"Improve Writing"}}),{id:I1,type:"quick",kind:"text",scopes:["text/edit"],label:`${kn}.label`,description:`${kn}.label`,enable:({engine:t})=>{let r=t.block.findAllSelected();if(r==null||r.length!==1)return!1;let[i]=r;return t.block.getType(i)==="//ly.img.ubq/text"},render:({builder:t,generate:r,engine:i,close:n})=>{t.Button(`${I1}.button`,{label:`${kn}.label`,icon:"@imgly/Sparkle",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),o=i.block.getString(a,"text/text");await r({prompt:bF(o)}),n()}catch(a){console.error("Generation error:",a),e.ui.showNotification({type:"error",message:a.message||"Failed to improve text. Please try again.",duration:"medium"})}}})}}),wF=vF;function kF(e){return`
440
+ You are tasked with fixing spelling and grammar errors in a given text. Your goal is to improve the text while maintaining its original meaning and style. Here is the text you need to correct:
441
+
442
+ <original_text>
443
+ ${e}
444
+ </original_text>
445
+
446
+ Please follow these steps to complete the task:
447
+
448
+ 1. Carefully read through the text and identify any spelling or grammatical errors.
449
+
450
+ 2. Correct all spelling mistakes, including typos and incorrectly spelled words.
451
+
452
+ 3. Fix grammatical errors, including:
453
+ - Incorrect verb tenses
454
+ - Subject-verb agreement issues
455
+ - Improper use of articles (a, an, the)
456
+ - Incorrect word usage
457
+ - Run-on sentences or sentence fragments
458
+ - Punctuation errors
459
+
460
+ 4. Ensure proper capitalization, especially at the beginning of sentences and for proper nouns.
461
+
462
+ 5. Maintain the original meaning and tone of the text. Do not add or remove information, or change the author's intended message.
463
+
464
+ 6. Make sure the corrected text flows naturally and is easy to read.
465
+
466
+ After making the necessary corrections, please provide only the improved output and nothing else.
467
+
468
+ Remember to preserve the original structure and formatting of the text as much as possible while making your corrections.
469
+ `}var xF=kF,up="fix",C1=`ly.img.${up}`,xn=`ly.img.ai.quickAction.text.${up}`,IF=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${xn}.label`]:"Fix Spelling & Grammar"}}),{id:C1,type:"quick",kind:"text",scopes:["text/edit"],label:`${xn}.label`,description:`${xn}.label`,enable:({engine:t})=>{let r=t.block.findAllSelected();if(r==null||r.length!==1)return!1;let[i]=r;return t.block.getType(i)==="//ly.img.ubq/text"},render:({builder:t,generate:r,engine:i,close:n})=>{t.Button(`${C1}.button`,{label:`${xn}.label`,icon:"@imgly/CheckmarkAll",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),o=i.block.getString(a,"text/text");await r({prompt:xF(o)}),n()}catch(a){console.error("Generation error:",a),e.ui.showNotification({type:"error",message:a.message||"Failed to fix text. Please try again.",duration:"medium"})}}})}}),CF=IF;function AF(e){return`
470
+ You will be given a text to shorten. Your task is to reduce the length of the text by 30% to 50% while maintaining its original voice, perspective, and key information. This is not a summary - you should preserve the style and tone of the original text.
471
+
472
+ Here is the original text:
473
+
474
+ <original_text>
475
+ ${e}
476
+ </original_text>
477
+
478
+ To complete this task, follow these steps:
479
+
480
+ 1. Carefully read and analyze the text, paying attention to its style, tone, and main points.
481
+
482
+ 2. Identify areas where the text can be condensed without losing essential information or altering the author's voice.
483
+
484
+ 3. Begin shortening the text by:
485
+ - Removing redundant or repetitive information
486
+ - Simplifying complex sentences
487
+ - Eliminating unnecessary examples or elaborations
488
+ - Combining related ideas into more concise statements
489
+
490
+ 4. As you shorten, continuously check that you are:
491
+ - Maintaining the original voice and perspective
492
+ - Keeping all crucial information
493
+ - Preserving the flow and coherence of the text
494
+
495
+ 5. Aim to reduce the length by 30% to 50% of the original. If you find yourself shortening less than 30%, look for additional opportunities to condense. If you're reducing more than 50%, ensure you haven't cut too much important content.
496
+
497
+ 6. Once you've finished shortening, review the text to ensure it still reads smoothly and retains the essence of the original.
498
+
499
+ Provide only the shortened version of the text in your response, without any additional comments, tags or explanations.
500
+ `}var MF=AF,cp="shorter",A1=`ly.img.${cp}`,In=`ly.img.ai.quickAction.text.${cp}`,jF=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${In}.label`]:"Make Shorter"}}),{id:A1,type:"quick",kind:"text",scopes:["text/edit"],label:`${In}.label`,description:`${In}.label`,enable:({engine:t})=>{let r=t.block.findAllSelected();if(r==null||r.length!==1)return!1;let[i]=r;return t.block.getType(i)==="//ly.img.ubq/text"},render:({builder:t,generate:r,engine:i,close:n})=>{t.Button(`${A1}.button`,{label:`${In}.label`,icon:"@imgly/TextShorter",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),o=i.block.getString(a,"text/text");await r({prompt:MF(o)}),n()}catch(a){console.error("Generation error:",a),e.ui.showNotification({type:"error",message:a.message||"Failed to make text shorter. Please try again.",duration:"medium"})}}})}}),SF=jF;function EF(e){return`
501
+ You are tasked with expanding a given text to make it longer. Here's how to proceed:
502
+
503
+ First, you will be provided with the original text:
504
+
505
+ <original_text>
506
+ ${e}
507
+ </original_text>
508
+
509
+ To expand the text:
510
+
511
+ 1. Analyze the original text to understand its main ideas, tone, and style.
512
+ 2. Identify areas where you can add more detail, examples, or explanations.
513
+ 3. Expand on these areas by:
514
+ - Providing more context or background information
515
+ - Adding relevant examples or anecdotes
516
+ - Elaborating on key points
517
+ - Introducing related concepts or ideas
518
+ - Explaining implications or consequences of the main ideas
519
+ 4. Ensure that the expanded text length is not exceeding the original text by more than 50%.
520
+ 5. Always expand the text, even if it is a single word. Explain the word with a few short sentences in that case. If the text is empty, make up a short sentence.
521
+
522
+ Guidelines:
523
+
524
+ - Maintain the original tone and style of the text.
525
+ - Ensure all additions are relevant to the main topic.
526
+ - Keep the flow of the text natural and coherent.
527
+ - Do not contradict any information in the original text.
528
+
529
+ Only return the longer text and nothing else.
530
+
531
+ Make sure to only return the expanded text and nothing else. Do not include any additional information or comments in your response about what you have done.
532
+
533
+ Do not add the original text or the original_text tags to the response.
534
+ `}var _F=EF,dp="longer",M1=`ly.img.${dp}`,Cn=`ly.img.ai.quickAction.text.${dp}`,LF=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Cn}.label`]:"Make Longer"}}),{id:M1,type:"quick",kind:"text",scopes:["text/edit"],label:`${Cn}.label`,description:`${Cn}.label`,enable:({engine:t})=>{let r=t.block.findAllSelected();if(r==null||r.length!==1)return!1;let[i]=r;return t.block.getType(i)==="//ly.img.ubq/text"},render:({builder:t,generate:r,engine:i,close:n})=>{t.Button(`${M1}.button`,{label:`${Cn}.label`,icon:"@imgly/TextLonger",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),o=i.block.getString(a,"text/text");await r({prompt:_F(o)}),n()}catch(a){console.error("Generation error:",a),e.ui.showNotification({type:"error",message:a.message||"Failed to make text longer. Please try again.",duration:"medium"})}}})}}),TF=LF;function $F(e,t){return`
535
+ You will be given a piece of text and a desired tone. Your task is to rewrite the text to match the desired tone while preserving the original meaning and key information. Here's how to proceed:
536
+
537
+ First, you will be provided with the original text:
538
+ <original_text>
539
+ ${e}
540
+ </original_text>
541
+
542
+ The desired tone for the rewritten text is:
543
+ <desired_tone>
544
+ ${t}
545
+ </desired_tone>
546
+
547
+ To change the tone of the text:
548
+ 1. Analyze the current tone and style of the original text.
549
+ 2. Identify the key information and main ideas in the original text.
550
+ 3. Consider the characteristics of the desired tone (e.g., formal, casual, humorous, professional, etc.).
551
+ 4. Rewrite the text, adapting the language, vocabulary, and sentence structure to match the desired tone while maintaining the original meaning and key information.
552
+ 5. Ensure that the rewritten text flows naturally and coherently.
553
+ 6. Only return the rewritten text without any additional commentary, tags or explanation.
554
+
555
+ Now, rewrite the text to match the desired tone. Your response should contain only the rewritten text, without any additional explanations or comments. Do not use any tags in your response.
556
+ `}var NF=$F,pp="changeTone",yi=`ly.img.${pp}`,P=`ly.img.ai.quickAction.text.${pp}`,OF=[{id:"professional",label:`${P}.type.professional`},{id:"casual",label:`${P}.type.casual`},{id:"friendly",label:`${P}.type.friendly`},{id:"serious",label:`${P}.type.serious`},{id:"humorous",label:`${P}.type.humorous`},{id:"optimistic",label:`${P}.type.optimistic`}],DF=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${P}.label`]:"Change Tone",[`${P}.type.professional`]:"Professional",[`${P}.type.casual`]:"Casual",[`${P}.type.friendly`]:"Friendly",[`${P}.type.serious`]:"Serious",[`${P}.type.humorous`]:"Humorous",[`${P}.type.optimistic`]:"Optimistic"}}),{id:yi,type:"quick",kind:"text",scopes:["text/edit"],label:`${P}.label`,description:`${P}.label`,enable:({engine:t})=>{let r=t.block.findAllSelected();if(r==null||r.length!==1)return!1;let[i]=r;return t.block.getType(i)==="//ly.img.ubq/text"},render:({builder:t,generate:r,engine:i,close:n,experimental:a})=>{a.builder.Popover(`${yi}.popover`,{label:`${P}.label`,icon:"@imgly/Microphone",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{t.Section(`${yi}.popover.section`,{children:()=>{a.builder.Menu(`${yi}.popover.menu`,{children:()=>{OF.forEach(o=>{t.Button(`${yi}.popover.menu.${o.id}`,{label:o.label,labelAlignment:"left",variant:"plain",onClick:async()=>{try{n();let[l]=i.block.findAllSelected(),u=i.block.getString(l,"text/text");await r({prompt:NF(u,o.id),type:o.id})}catch(l){console.error("Generation error:",l),e.ui.showNotification({type:"error",message:l.message||"Failed to change tone. Please try again.",duration:"medium"})}}})})}})}})}})}}),PF=DF,Va={en_US:"English (US)",en_UK:"English (UK)",es:"Spanish",fr:"French",de:"German",pt:"Portuguese",it:"Italian",ru:"Russian",zh:"Mandarin Chinese",ja:"Japanese"},zF=Object.keys(Va);function UF(e,t){let r=Va[t]||t;return`
557
+ You are a translation AI. Your task is to translate the given text into the specified target language. Follow these steps:
558
+
559
+ 1. Here is the source text to be translated:
560
+ <source_text>
561
+ ${e}
562
+ </source_text>
563
+
564
+ 2. The target language for translation is:
565
+ <target_language>
566
+ ${r}
567
+ </target_language>
568
+
569
+ 3. Translate the source text into the target language. Ensure that you maintain the original meaning, tone, and style as closely as possible while adapting to the linguistic and cultural norms of the target language.
570
+
571
+ 4. Return only the translated text, without any additional comments, explanations, or metadata. Do not include the original text or any other information in your response.
572
+ `}var RF=UF,gp="translate",bi=`ly.img.${gp}`,An=`ly.img.ai.quickAction.text.${gp}`,FF=zF.map(e=>({id:e,label:Va[e]})),VF=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${An}.label`]:"Translate"}}),{id:bi,type:"quick",kind:"text",scopes:["text/edit"],label:`${An}.label`,description:`${An}.label`,enable:({engine:t})=>{let r=t.block.findAllSelected();if(r==null||r.length!==1)return!1;let[i]=r;return t.block.getType(i)==="//ly.img.ubq/text"},render:({builder:t,generate:r,engine:i,close:n,experimental:a})=>{a.builder.Popover(`${bi}.popover`,{label:`${An}.label`,icon:"@imgly/Language",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{t.Section(`${bi}.popover.section`,{children:()=>{a.builder.Menu(`${bi}.popover.menu`,{children:()=>{FF.forEach(o=>{t.Button(`${bi}.popover.menu.${o.id}`,{label:o.label,labelAlignment:"left",variant:"plain",onClick:async()=>{try{n();let[l]=i.block.findAllSelected(),u=i.block.getString(l,"text/text");await r({prompt:RF(u,o.id),language:o.id})}catch(l){console.error("Generation error:",l),e.ui.showNotification({type:"error",message:l.message||"Failed to translate text. Please try again.",duration:"medium"})}}})})}})}})}})}}),BF=VF;function GF(e,t){return`
573
+ You will be given an original text and a custom prompt addition that specifies how to change the text. Your task is to modify the original text according to the prompt and return only the new, modified text.
574
+
575
+ Here is the original text:
576
+ <original_text>
577
+ ${e}
578
+ </original_text>
579
+
580
+ The custom prompt addition is:
581
+ <change_text_to>
582
+ ${t}
583
+ </change_text_to>
584
+
585
+ Please modify the original text according to the "Change Text to..." prompt. Only return the new, modified text without any additional commentary or explanation. Your entire response should be the modified text itself, with no other content.
586
+ `}var qF=GF,fp="changeTextTo",ge=`ly.img.${fp}`,fe=`ly.img.ai.quickAction.text.${fp}`,YF=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${fe}.label`]:"Change Text to...",[`${fe}.prompt.label`]:"Change Text to...",[`${fe}.prompt.placeholder`]:'e.g. "a list of bullet points", "a formal announcement"'}}),{id:ge,type:"quick",kind:"text",scopes:["text/edit"],label:`${fe}.label`,description:`${fe}.label`,enable:({engine:t})=>{let r=t.block.findAllSelected();if(r==null||r.length!==1)return!1;let[i]=r;return t.block.getType(i)==="//ly.img.ubq/text"},render:({builder:t,experimental:r,isExpanded:i,toggleExpand:n,generate:a,engine:o,state:l,close:u})=>{if(i){let s=l(`${ge}.prompt`,"");t.TextArea(`${ge}.prompt`,{inputLabel:`${fe}.prompt.label`,placeholder:`${fe}.prompt.placeholder`,...s}),t.Separator(`${ge}.separator`),r.builder.ButtonRow(`${ge}.footer`,{justifyContent:"space-between",children:()=>{t.Button(`${ge}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:n}),t.Button(`${ge}.footer.apply`,{label:"common.apply",icon:"@imgly/MagicWand",color:"accent",isDisabled:s.value.length===0,onClick:async()=>{try{let c=s.value;if(!c)return;let[d]=o.block.findAllSelected(),p=o.block.getString(d,"text/text");await a({prompt:qF(p,c),customPrompt:c}),n(),u()}catch(c){console.error("Generation error:",c),e.ui.showNotification({type:"error",message:c.message||"Failed to change text. Please try again.",duration:"medium"})}}})}})}else t.Button(`${ge}.button`,{label:`${fe}.label`,icon:"@imgly/MagicWand",labelAlignment:"left",variant:"plain",onClick:n})}}),HF=YF,hp="@imgly/plugin-ai-text-generation-web",ZF=["ly.img.improve","ly.img.fix","ly.img.shorter","ly.img.longer","ly.img.separator","ly.img.changeTone","ly.img.translate","ly.img.separator","ly.img.changeTextTo"];function QF(e){return{async initialize({cesdk:t}){if(t==null)return;VD(t,hp,"0.2.0"),t.ui.addIconSet(E$,L$),t.i18n.setTranslations({en:{"common.apply":"Apply","common.back":"Back"}}),WF(e);let r=D1.get();r.register(wF({cesdk:t})),r.register(CF({cesdk:t})),r.register(SF({cesdk:t})),r.register(TF({cesdk:t})),r.register(PF({cesdk:t})),r.register(BF({cesdk:t})),r.register(HF({cesdk:t}));let i=e.providers?.text2text??e.provider,n=await Promise.all(mF(i).map(l=>l({cesdk:t}))),a=await ZP("text",{fromText:n,fromImage:[]},{cesdk:t},e),o=await bz({kind:"text",providerInitializationResults:a.providerInitializationResults,cesdk:t,engine:t.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:ZF});o.renderFunction!=null&&(t.ui.registerComponent("ly.img.ai.text.canvasMenu",o.renderFunction),t.ui.setCanvasMenuOrder(["ly.img.ai.text.canvasMenu"],{editMode:_n}))}}}function WF(e){e.debug&&e.providers?.text2text!=null&&e.provider!=null&&console.warn("[TextGeneration]: Both `providers.text2text` and `provider` configuration is provided. Since `provider` is deprecated, only `providers.text2text` will be used.")}var KF=QF,JF=e=>({name:hp,version:"0.2.0",...KF(e)}),mp=JF;var XF=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",d="",p=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(d=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(p=s.tags[c]);let g={...s,label:d,tags:p};return this.filterAsset(g,e)&&u.push(g),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),l=a<t.length?r+1:void 0;return{assets:o,currentPage:r,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let i=new Set;r.result.forEach(a=>{a.groups&&Array.isArray(a.groups)&&a.groups.forEach(o=>i.add(o))});let n=[...i];e(n)},r.onerror=()=>{t(new Error(`Failed to get groups: ${r.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),r=t.objectStore(this.assetStoreName),i=new Set;Qt(e,a=>{i.add(a)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.assetStoreName,"readwrite");r.objectStore(this.assetStoreName).delete(e),r.oncomplete=()=>{Qt(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let l=a.meta?.insertedAt||a._insertedAt||Date.now(),u=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return Qt(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),Qt(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!o.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(l=>e.tags?.includes(l))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,l)=>{let u,s;return i==="id"?(u=o.id,s=l.id):(u=o.meta?.[i]??null,s=l.meta?.[i]??null),u==null?r==="Ascending"?-1:1:s==null?r==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?r==="Ascending"?u.localeCompare(s):s.localeCompare(u):r==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):r==="Descending"&&a.reverse(),n&&a.sort((o,l)=>o.active&&!l.active?-1:!o.active&&l.active?1:0)),a}};function Qt(e,t,r=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let i=0;i<e.length;i++){let n=r?`${r}[${i}]`:`[${i}]`;if(typeof e[i]=="string"&&e[i].startsWith("blob:")){let a=t(e[i],n);typeof a=="string"&&(e[i]=a)}else e[i]=Qt(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],a=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let o=t(n,a);typeof o=="string"&&(e[i]=o)}else e[i]=Qt(n,t,a)}return e}var eV=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,d)=>{let p=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,l=o+a,u=i.slice(o,l),s=l<i.length?n+1:void 0;return{assets:u,currentPage:n,nextPage:s,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}},tV=typeof global=="object"&&global&&global.Object===Object&&global,Hp=tV,rV=typeof self=="object"&&self&&self.Object===Object&&self,iV=Hp||rV||Function("return this")(),te=iV,nV=te.Symbol,Wt=nV,Zp=Object.prototype,oV=Zp.hasOwnProperty,aV=Zp.toString,_i=Wt?Wt.toStringTag:void 0;function lV(e){var t=oV.call(e,_i),r=e[_i];try{e[_i]=void 0;var i=!0}catch{}var n=aV.call(e);return i&&(t?e[_i]=r:delete e[_i]),n}var sV=lV,uV=Object.prototype,cV=uV.toString;function dV(e){return cV.call(e)}var pV=dV,gV="[object Null]",fV="[object Undefined]",yp=Wt?Wt.toStringTag:void 0;function hV(e){return e==null?e===void 0?fV:gV:yp&&yp in Object(e)?sV(e):pV(e)}var Ri=hV;function mV(e){return e!=null&&typeof e=="object"}var al=mV,QJ=Array.isArray;function yV(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Qp=yV,bV="[object AsyncFunction]",vV="[object Function]",wV="[object GeneratorFunction]",kV="[object Proxy]";function xV(e){if(!Qp(e))return!1;var t=Ri(e);return t==vV||t==wV||t==bV||t==kV}var IV=xV,CV=te["__core-js_shared__"],Ba=CV,bp=function(){var e=/[^.]+$/.exec(Ba&&Ba.keys&&Ba.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function AV(e){return!!bp&&bp in e}var MV=AV,jV=Function.prototype,SV=jV.toString;function EV(e){if(e!=null){try{return SV.call(e)}catch{}try{return e+""}catch{}}return""}var $e=EV,_V=/[\\^$.*+?()[\]{}|]/g,LV=/^\[object .+?Constructor\]$/,TV=Function.prototype,$V=Object.prototype,NV=TV.toString,OV=$V.hasOwnProperty,DV=RegExp("^"+NV.call(OV).replace(_V,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function PV(e){if(!Qp(e)||MV(e))return!1;var t=IV(e)?DV:LV;return t.test($e(e))}var zV=PV;function UV(e,t){return e?.[t]}var RV=UV;function FV(e,t){var r=RV(e,t);return zV(r)?r:void 0}var Jt=FV,VV=Jt(te,"WeakMap"),Wa=VV;function BV(e,t){return e===t||e!==e&&t!==t}var GV=BV,qV=9007199254740991;function YV(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=qV}var HV=YV,WJ=Object.prototype,ZV="[object Arguments]";function QV(e){return al(e)&&Ri(e)==ZV}var vp=QV,Wp=Object.prototype,WV=Wp.hasOwnProperty,KV=Wp.propertyIsEnumerable,KJ=vp(function(){return arguments}())?vp:function(e){return al(e)&&WV.call(e,"callee")&&!KV.call(e,"callee")},Kp=typeof exports=="object"&&exports&&!exports.nodeType&&exports,wp=Kp&&typeof module=="object"&&module&&!module.nodeType&&module,JV=wp&&wp.exports===Kp,kp=JV?te.Buffer:void 0,JJ=kp?kp.isBuffer:void 0,XV="[object Arguments]",eB="[object Array]",tB="[object Boolean]",rB="[object Date]",iB="[object Error]",nB="[object Function]",oB="[object Map]",aB="[object Number]",lB="[object Object]",sB="[object RegExp]",uB="[object Set]",cB="[object String]",dB="[object WeakMap]",pB="[object ArrayBuffer]",gB="[object DataView]",fB="[object Float32Array]",hB="[object Float64Array]",mB="[object Int8Array]",yB="[object Int16Array]",bB="[object Int32Array]",vB="[object Uint8Array]",wB="[object Uint8ClampedArray]",kB="[object Uint16Array]",xB="[object Uint32Array]",O={};O[fB]=O[hB]=O[mB]=O[yB]=O[bB]=O[vB]=O[wB]=O[kB]=O[xB]=!0;O[XV]=O[eB]=O[pB]=O[tB]=O[gB]=O[rB]=O[iB]=O[nB]=O[oB]=O[aB]=O[lB]=O[sB]=O[uB]=O[cB]=O[dB]=!1;function IB(e){return al(e)&&HV(e.length)&&!!O[Ri(e)]}var CB=IB;function AB(e){return function(t){return e(t)}}var MB=AB,Jp=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ni=Jp&&typeof module=="object"&&module&&!module.nodeType&&module,jB=Ni&&Ni.exports===Jp,Ga=jB&&Hp.process,SB=function(){try{var e=Ni&&Ni.require&&Ni.require("util").types;return e||Ga&&Ga.binding&&Ga.binding("util")}catch{}}(),xp=SB,Ip=xp&&xp.isTypedArray,XJ=Ip?MB(Ip):CB,EB=Object.prototype,eX=EB.hasOwnProperty;function _B(e,t){return function(r){return e(t(r))}}var LB=_B,tX=LB(Object.keys,Object),TB=Object.prototype,rX=TB.hasOwnProperty,$B=Jt(Object,"create"),Di=$B;function NB(){this.__data__=Di?Di(null):{},this.size=0}var OB=NB;function DB(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var PB=DB,zB="__lodash_hash_undefined__",UB=Object.prototype,RB=UB.hasOwnProperty;function FB(e){var t=this.__data__;if(Di){var r=t[e];return r===zB?void 0:r}return RB.call(t,e)?t[e]:void 0}var VB=FB,BB=Object.prototype,GB=BB.hasOwnProperty;function qB(e){var t=this.__data__;return Di?t[e]!==void 0:GB.call(t,e)}var YB=qB,HB="__lodash_hash_undefined__";function ZB(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Di&&t===void 0?HB:t,this}var QB=ZB;function Xt(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Xt.prototype.clear=OB;Xt.prototype.delete=PB;Xt.prototype.get=VB;Xt.prototype.has=YB;Xt.prototype.set=QB;var Cp=Xt;function WB(){this.__data__=[],this.size=0}var KB=WB;function JB(e,t){for(var r=e.length;r--;)if(GV(e[r][0],t))return r;return-1}var On=JB,XB=Array.prototype,eG=XB.splice;function tG(e){var t=this.__data__,r=On(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():eG.call(t,r,1),--this.size,!0}var rG=tG;function iG(e){var t=this.__data__,r=On(t,e);return r<0?void 0:t[r][1]}var nG=iG;function oG(e){return On(this.__data__,e)>-1}var aG=oG;function lG(e,t){var r=this.__data__,i=On(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var sG=lG;function er(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}er.prototype.clear=KB;er.prototype.delete=rG;er.prototype.get=nG;er.prototype.has=aG;er.prototype.set=sG;var Dn=er,uG=Jt(te,"Map"),Pi=uG;function cG(){this.size=0,this.__data__={hash:new Cp,map:new(Pi||Dn),string:new Cp}}var dG=cG;function pG(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var gG=pG;function fG(e,t){var r=e.__data__;return gG(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Pn=fG;function hG(e){var t=Pn(this,e).delete(e);return this.size-=t?1:0,t}var mG=hG;function yG(e){return Pn(this,e).get(e)}var bG=yG;function vG(e){return Pn(this,e).has(e)}var wG=vG;function kG(e,t){var r=Pn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var xG=kG;function tr(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}tr.prototype.clear=dG;tr.prototype.delete=mG;tr.prototype.get=bG;tr.prototype.has=wG;tr.prototype.set=xG;var Xp=tr;function IG(){this.__data__=new Dn,this.size=0}var CG=IG;function AG(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var MG=AG;function jG(e){return this.__data__.get(e)}var SG=jG;function EG(e){return this.__data__.has(e)}var _G=EG,LG=200;function TG(e,t){var r=this.__data__;if(r instanceof Dn){var i=r.__data__;if(!Pi||i.length<LG-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Xp(i)}return r.set(e,t),this.size=r.size,this}var $G=TG;function Fi(e){var t=this.__data__=new Dn(e);this.size=t.size}Fi.prototype.clear=CG;Fi.prototype.delete=MG;Fi.prototype.get=SG;Fi.prototype.has=_G;Fi.prototype.set=$G;var NG=Object.prototype,iX=NG.propertyIsEnumerable,OG=Jt(te,"DataView"),Ka=OG,DG=Jt(te,"Promise"),Ja=DG,PG=Jt(te,"Set"),Xa=PG,Ap="[object Map]",zG="[object Object]",Mp="[object Promise]",jp="[object Set]",Sp="[object WeakMap]",Ep="[object DataView]",UG=$e(Ka),RG=$e(Pi),FG=$e(Ja),VG=$e(Xa),BG=$e(Wa),Ht=Ri;(Ka&&Ht(new Ka(new ArrayBuffer(1)))!=Ep||Pi&&Ht(new Pi)!=Ap||Ja&&Ht(Ja.resolve())!=Mp||Xa&&Ht(new Xa)!=jp||Wa&&Ht(new Wa)!=Sp)&&(Ht=function(e){var t=Ri(e),r=t==zG?e.constructor:void 0,i=r?$e(r):"";if(i)switch(i){case UG:return Ep;case RG:return Ap;case FG:return Mp;case VG:return jp;case BG:return Sp}return t});var nX=te.Uint8Array,GG="__lodash_hash_undefined__";function qG(e){return this.__data__.set(e,GG),this}var YG=qG;function HG(e){return this.__data__.has(e)}var ZG=HG;function el(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Xp;++t<r;)this.add(e[t])}el.prototype.add=el.prototype.push=YG;el.prototype.has=ZG;var _p=Wt?Wt.prototype:void 0,oX=_p?_p.valueOf:void 0,QG=Object.prototype,aX=QG.hasOwnProperty,WG=Object.prototype,lX=WG.hasOwnProperty,sX=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),uX=new RegExp(/[A-Fa-f0-9]{1}/,"g"),cX=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function eg(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function KG(e,t){let r=await eg(e,t);return new Promise((i,n)=>{let a=new Image;a.onload=()=>{i({width:a.width,height:a.height})},a.onerror=n,a.src=r})}async function JG(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return eg(i,t)}function XG(e){return e!==void 0}var eq=XG,tq=class tg{constructor(){this.actions=new Map,this.subscribers=new Map}static get(){let t="__imgly_action_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new tg),r[t]}register(t){return this.actions.set(t.id,t),this.notifySubscribers(t,"registered"),()=>{this.actions.get(t.id)===t&&(this.actions.delete(t.id),this.notifySubscribers(t,"unregistered"))}}getAll(){return Array.from(this.actions.values())}getBy(t){return this.getAll().filter(r=>this.matchesFilters(r,t))}subscribe(t){return this.subscribers.set(t,null),()=>{this.subscribers.delete(t)}}subscribeBy(t,r){return this.subscribers.set(r,t),()=>{this.subscribers.delete(r)}}notifySubscribers(t,r){this.subscribers.forEach((i,n)=>{if(i===null){n(t,r);return}this.matchesFilters(t,i)&&n(t,r)})}matchesFilters(t,r){return!(r.type&&t.type!==r.type||r.pluginId&&t.type==="plugin"&&t.pluginId!==r.pluginId||r.id&&t.id!==r.id||r.kind&&(t.type!=="quick"||t.kind!==r.kind))}},rq=class rg{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new rg),r[t]}register(t){return this.providers.has(t.provider.id)&&console.warn(`Provider with ID "${t.provider.id}" is already registered`),this.providers.set(t.provider.id,t),()=>{this.providers.get(t.provider.id)===t&&this.providers.delete(t.provider.id)}}getAll(){return Array.from(this.providers.values())}getById(t){return this.providers.get(t)}getByKind(t){return this.getAll().filter(({provider:r})=>r.kind===t)}};function iq(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=s=>{a.push(s)},l=async(s,c,d)=>{if(s>=t.length)return r(c,d);let p=t[s],g=async(b,m)=>l(s+1,b,m),f={...d,addDisposer:o};return p(c,f,g)},u={...n,addDisposer:o};return{result:await l(0,i,u),dispose:async()=>{for(let s=a.length-1;s>=0;s--)try{await a[s]()}catch(c){console.error("Error in disposer:",c)}a.length=0}}}}function nq({enable:e=!0}){return async(t,r,i)=>{if(!e)return i(t,r);console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(t,null,2));let n,a=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var oq=nq,qa="ly.img.ai.temp";async function aq(e,t){return e.engine.asset.findAllSources().includes(qa)||e.engine.asset.addLocalSource(qa),e.engine.asset.apply(qa,t)}function lq(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let r=e;return"message"in r&&typeof r.message=="string"?r.message:"cause"in r&&typeof r.cause=="string"?r.cause:"detail"in r&&typeof r.detail=="object"&&r.detail!==null&&"message"in r.detail&&typeof r.detail.message=="string"?r.detail.message:"error"in r&&typeof r.error=="object"&&r.error!==null&&"message"in r.error&&typeof r.error.message=="string"?r.error.message:t}return typeof e=="string"?e:String(e)||t}function ig(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function sq(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=o.videoWidth,l.height=o.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}u.drawImage(o,0,0,l.width,l.height);try{let s=l.toDataURL(r,i);document.body.removeChild(o),n(s)}catch(s){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function ng(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function uq(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function ll(e){return e instanceof Error&&e.name==="AbortError"}function cq(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function dq(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
587
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
588
+ This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version.
589
+ Consider updating all AI plugins to the same version for optimal compatibility.`),e.ui.experimental.setGlobalStateValue(n,!0))):e.ui.experimental.setGlobalStateValue(i,r)}catch(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}function pq(e){let{cesdk:t,panelId:r}=e;r.startsWith("ly.img.ai.")||console.warn(`Dock components for AI generation should open a panel with an id starting with "ly.img.ai." \u2013 "${r}" was provided.`);let i=`${r}.dock`;t.ui.registerComponent(i,({builder:n})=>{let a=t.ui.isPanelOpen(r);n.Button(`${r}.dock.button`,{label:`${r}.dock.label`,isSelected:a,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(o=>{o.startsWith("ly.img.ai.")&&t.ui.closePanel(o),!a&&o==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(o)}),a?t.ui.closePanel(r):t.ui.openPanel(r)}})})}var gq=pq;function fq(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),hq(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:lq(e)})}function hq(e,t,r){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.failed",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"error",message:n,action:a}),!0}var Lp=fq,mq="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",sl=mq;function yq(e,t,r){switch(t){case"image":return bq(e,r[t]);case"video":return vq(e,r[t]);case"sticker":return wq(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function bq(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:sl,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function vq(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:sl,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function wq(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:sl,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var kq=yq;async function xq(e,t,r,i){switch(t){case"image":{if(i.kind!=="image")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: image)`);return Iq(e,r[t],i)}case"video":{if(i.kind!=="video")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: video)`);return Cq(e,r[t],i)}case"audio":{if(i.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: audio)`);return Aq(e,r[t],i)}case"sticker":{if(i.kind!=="sticker")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: sticker)`);return Mq(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Iq(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}async function Cq(e,t,r){let i=t.width,n=t.height,a=await sq(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:a,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function Aq(e,t,r){return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:r.duration.toString()}}}function Mq(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}var og=xq;function jq(e){switch(e.userFlow){case"placeholder":return Eq(e);case"generation-only":return Sq(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function Sq(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(ye(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(ye(t,r))return{status:"aborted"};if(o.status!=="success")return o;if(o.type==="async")throw new Error("Async generation is not supported in this context yet.");if(ye(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let l=ig(),u=await og(l,n,a,o.output),s={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,s)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Eq(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(ye(t,r))return{status:"aborted"};let l=ig(),u=kq(l,a,o);if(i=await aq(t,u),ye(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,p),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let s=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(ye(t,r,i))return{status:"aborted"};if(s.status!=="success")return s;if(s.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let c=await og(l,a,o,s.output);if(ye(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(c,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(c,i),ye(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),s}catch(a){return i!=null&&t.engine.block.isValid(i)&&(ll(a)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:a instanceof Error?a.message:String(a)}}}}function ye(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var _q=jq;function ul(e){return`${e}.generating`}function Lq(e){return`${e}.abort`}function Tq(e,t,r,i,n,a,o){let{builder:l,experimental:u}=e,{cesdk:s,includeHistoryLibrary:c=!0}=a,{id:d,output:{abortable:p}}=t,g=u.global(Lq(d),()=>{}),f=u.global(ul(d),!1),b,m=f.value&&p,h=()=>{m&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},x;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let v=i();x=a.requiredInputs.every(y=>!v.input[y])}let w=u.global(`${d}.confirmationDialogId`,void 0);l.Section(`${d}.generate.section`,{children:()=>{l.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:f.value,color:"accent",isDisabled:x,suffix:m?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let v=s.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:y})=>{s.ui.closeDialog(y),w.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:y})=>{h(),s.ui.closeDialog(y),w.setValue(void 0)}}});w.setValue(v)}}:void 0,onClick:async()=>{b=new AbortController;let v=b.signal;await(async()=>{try{f.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),b?.abort()});let y=await _q({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:v,cesdk:s,debug:o.debug,dryRun:o.dryRun})(i().input);if(y.status==="aborted")return;if(y.status==="error"){Lp(y.message,{cesdk:s,provider:t,getInput:i});return}if(y.status==="success"&&y.type==="sync"){let k=t.output.notification;$q(s,k,()=>({input:i().input,output:y.output}))}}catch(y){if(ll(y))return;Lp(y,{cesdk:s,provider:t,getInput:i})}finally{b=void 0,f.setValue(!1),g.setValue(()=>{}),w.value!=null&&(s.ui.closeDialog(w.value),w.setValue(void 0))}})()}}),t.output.generationHintText!=null&&l.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),c&&a.historyAssetLibraryEntryId!=null&&l.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function $q(e,t,r){let i=t?.success;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.success",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"success",message:n,action:a,duration:i.duration}),!0}var ag=Tq;async function Nq({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,l=r.render;return u=>{let{state:s}=u,c=s(ul(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=l(u,{cesdk:a,isGenerating:c});return ag(u,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var Oq=Nq;function lg(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let r=t.substring(2).split("/"),i=e;for(let n of r){if(i==null)throw new Error(`Invalid reference path: ${t}`);i=i[n]}if(i===void 0)throw new Error(`Reference not found: ${t}`);return i}function $i(e,t,r=new Set){if(t==null||r.has(t))return t;if(r.add(t),t.$ref&&typeof t.$ref=="string"){let i=lg(e,t.$ref),n={...$i(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=$i(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>$i(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=$i(e,t[n],r));return i}return t}function Dq(e){return $i(e,{...e})}function Pq(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let l of i.type)if(typeof l!="string"||!o.includes(l))return r(`Array of types contains invalid value: ${l}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let l=0;l<i[o].length;l++){let u=i[o][l];if(typeof u!="object"||u===null)return r(`Item ${l} in ${o} must be an object, got ${u===null?"null":typeof u}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let l=i.required[o];if(typeof l!="string")return r(`Item ${o} in required array must be a string, got ${typeof l}`)}}return!0}function zq(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return Uq(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function Uq(e,t){let r=t.order;if(r!=null&&Array.isArray(r))return r;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,n=Object.keys(i),a=Rq(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function Rq(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let r=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return r==null?void 0:e[r]}var sg=zq;function ug(e,t,r,i,n,a){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let o=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?Fq(e,o,r,i,n,a):dg(e,o,r,i,n,a);case"boolean":return pg(e,o,r,i,n,a);case"number":case"integer":return gg(e,o,r,i,n,a);case"object":return cg(e,o,r,i,n,a);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return Vq(e,o,r,i,n,a);break}default:console.error(`Unsupported property type: ${l}`)}}function cg(e,t,r,i,n,a){let o=sg(t.schema??{},i).reduce((l,u)=>{let s=ug(e,u,r,i,n,a);return s!=null&&(l[u.id]=s()),l},{});return()=>({id:t.id,type:"object",value:o})}function dg(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=l(s,t.schema.default??""),p=Bq(t.schema),g=p?.component!=null&&p?.component==="TextArea"?"TextArea":"TextInput";return o[g](s,{inputLabel:c,placeholder:n.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function Fq(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},p="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},g=(t.schema.enum??[]).map(m=>({id:m,label:d[m]??ng(m),icon:p[m]})),f=t.schema.default!=null?g.find(m=>m.id===t.schema.default)??g[0]:g[0],b=l(s,f);return o.Select(s,{inputLabel:c,values:g,...b}),()=>({id:t.id,type:"string",value:b.value.id})}function pg(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=!!t.schema.default,p=l(s,d);return o.Checkbox(s,{inputLabel:c,...p}),()=>({id:t.id,type:"boolean",value:p.value})}function gg(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.minimum,p=t.schema.maximum,g=t.schema.default;g==null&&(d!=null?g=d:p!=null?g=p:g=0);let f=l(s,g);if(d!=null&&p!=null){let b=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(b=t.schema["x-imgly-step"]),o.Slider(s,{inputLabel:c,min:d,max:p,step:b,...f})}else o.NumberInput(s,{inputLabel:c,min:d,max:p,...f});return()=>({id:t.id,type:"integer",value:f.value})}function Vq(e,t,r,i,n,a){let{builder:o,experimental:{global:l}}=e,{id:u}=t,s=`${r.id}.${u}`,c=t.schema.title??s,d=t.schema.anyOf??[],p=[],g={},f={};d.forEach((h,x)=>{let w=h.title??"common.custom",v=`${r.id}.${u}.anyOf[${x}]`,y="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},k="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};h.type==="string"?h.enum!=null?h.enum.forEach(I=>{p.push({id:I,label:y[I]??ng(I),icon:k[I]})}):(g[v]=()=>dg(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="boolean"?(g[v]=()=>pg(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="integer"?(g[v]=()=>gg(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]})):h.type==="array"||h.type==="object"&&(g[v]=()=>cg(e,{id:v,schema:{...h,title:w}},r,i,n,a),p.push({id:v,label:y[w]??w,icon:k[w]}))});let b=t.schema.default!=null?p.find(h=>h.id===t.schema.default)??p[0]:p[0],m=l(s,b);if(o.Select(s,{inputLabel:c,values:p,...m}),m.value.id in g){let h=g[m.value.id]();f[m.value.id]=h}return()=>{let h=f[m.value.id];return h!=null?{...h(),id:t.id}:{id:t.id,type:"string",value:m.value.id}}}function Bq(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Gq=ug;async function qq({options:e,provider:t,panelInput:r,config:i},n){let{id:a}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${a}`);let o=Dq(r.document),l=lg(o,r.inputReference);if(!Pq(l,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=sg(u,r);return c=>{let{builder:d}=c,p=[];d.Section(`${a}.schema.section`,{children:()=>{s.forEach(m=>{let h=Gq(c,m,t,r,e,i);h!=null&&(Array.isArray(h)?p.push(...h):p.push(h))})}});let g=p.map(m=>m()),f=m=>m.type==="object"?Object.entries(m.value).reduce((h,[x,w])=>(h[x]=f(w),h),{}):m.value,b=g.reduce((m,h)=>(m[h.id]=f(h),m),{});ag(c,t,n,()=>({input:b}),()=>r.getBlockInput(b),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var Yq=qq;async function Hq(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return Oq(e,t);case"schema":return Yq(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var Zq=Hq;function Qq(e){let{provider:t,options:{engine:r}}=e,i=t.output.history??"@imgly/local";if(i==null||i===!1)return;let n=r.asset.findAllSources();function a(){let o=`${t.id}.history`;for(;n.includes(o);)o+=`-${Math.random().toString(36).substring(2,6)}`;return o}if(i==="@imgly/local"){let o=a();return r.asset.addLocalSource(o),o}if(i==="@imgly/indexedDB"){let o=a();return r.asset.addSource(new XF(o,r)),o}return i}var Wq=Qq;function Kq(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history.entry`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var Jq=Kq,Ya="@imgly/plugin-ai-generation",Xq=`
590
+ <svg>
591
+ <symbol
592
+ fill="none"
593
+ xmlns="http://www.w3.org/2000/svg"
594
+ viewBox="0 0 24 24"
595
+ id="@imgly/Sparkle"
596
+ >
597
+ <path d="M5.35545 2.06745C5.24149 1.72556 4.7579 1.72556 4.64394 2.06745L4.05898 3.82232C4.02166 3.93429 3.9338 4.02215 3.82184 4.05948L2.06694 4.64459C1.72506 4.75858 1.72509 5.24217 2.06699 5.3561L3.82179 5.9409C3.93378 5.97822 4.02166 6.06609 4.05899 6.17808L4.64394 7.93291C4.7579 8.2748 5.24149 8.2748 5.35545 7.93291L5.9404 6.17806C5.97773 6.06608 6.06559 5.97821 6.17757 5.94089L7.93242 5.35594C8.27431 5.24198 8.27431 4.75839 7.93242 4.64442L6.17757 4.05947C6.06559 4.02215 5.97773 3.93428 5.9404 3.8223L5.35545 2.06745Z" fill="currentColor"/>
598
+ <path d="M17.9632 3.23614C17.8026 2.80788 17.1968 2.80788 17.0362 3.23614L16.0787 5.78951C16.0285 5.92337 15.9229 6.02899 15.789 6.07918L13.2356 7.0367C12.8074 7.19729 12.8074 7.80307 13.2356 7.96366L15.789 8.92118C15.9229 8.97138 16.0285 9.077 16.0787 9.21085L17.0362 11.7642C17.1968 12.1925 17.8026 12.1925 17.9632 11.7642L18.9207 9.21086C18.9709 9.077 19.0765 8.97138 19.2104 8.92118L21.7637 7.96366C22.192 7.80307 22.192 7.1973 21.7637 7.0367L19.2104 6.07918C19.0765 6.02899 18.9709 5.92337 18.9207 5.78951L17.9632 3.23614Z" fill="currentColor"/>
599
+ <path d="M9.30058 7.82012C9.54712 7.1791 10.454 7.1791 10.7006 7.82012L12.3809 12.189C12.4571 12.3871 12.6136 12.5436 12.8117 12.6198L17.1806 14.3001C17.8216 14.5466 17.8216 15.4536 17.1806 15.7001L12.8117 17.3804C12.6136 17.4566 12.4571 17.6131 12.3809 17.8112L10.7006 22.1801C10.454 22.8211 9.54712 22.8211 9.30058 22.1801L7.62024 17.8112C7.54406 17.6131 7.38754 17.4566 7.18947 17.3804L2.82061 15.7001C2.17959 15.4536 2.17959 14.5466 2.82061 14.3001L7.18947 12.6198C7.38754 12.5436 7.54406 12.3871 7.62024 12.189L9.30058 7.82012Z" fill="currentColor"/>
600
+
601
+ </symbol>
602
+
603
+ <symbol
604
+ fill="none"
605
+ xmlns="http://www.w3.org/2000/svg"
606
+ viewBox="0 0 24 24"
607
+ id="${Ya}/image"
608
+ >
609
+ <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
610
+ <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
611
+ <path d="M6.40053 5.38488C6.52538 5.06832 6.97338 5.06832 7.09823 5.38488L8.17455 8.11392C8.21267 8.21057 8.28917 8.28707 8.38582 8.32519L11.1149 9.40151C11.4314 9.52636 11.4314 9.97436 11.1149 10.0992L8.38582 11.1755C8.28917 11.2136 8.21267 11.2901 8.17455 11.3868L7.09823 14.1158C6.97338 14.4324 6.52538 14.4324 6.40053 14.1158L5.32421 11.3868C5.2861 11.2901 5.20959 11.2136 5.11295 11.1755L2.3839 10.0992C2.06735 9.97436 2.06735 9.52636 2.3839 9.40151L5.11295 8.32519C5.20959 8.28707 5.2861 8.21057 5.32421 8.11392L6.40053 5.38488Z" fill="currentColor"/>
612
+ <path d="M18.9994 16.5008V18.0004C18.9994 18.5526 18.5517 19.0004 17.9994 19.0004H9.33302L14.3753 11.4369C14.6722 10.9916 15.3266 10.9916 15.6234 11.4369L18.9994 16.5008Z" fill="currentColor"/>
613
+
614
+ </symbol>
615
+ <symbol
616
+ fill="none"
617
+ xmlns="http://www.w3.org/2000/svg"
618
+ viewBox="0 0 24 24"
619
+ id="${Ya}/video"
620
+ >
621
+ <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
622
+ <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
623
+ <path d="M18.9019 3.3845C19.0267 3.06795 19.4747 3.06795 19.5996 3.3845L20.6759 6.11355C20.714 6.2102 20.7905 6.2867 20.8872 6.32482L23.6162 7.40114C23.9328 7.52598 23.9328 7.97399 23.6162 8.09883L20.8872 9.17515C20.7905 9.21327 20.714 9.28977 20.6759 9.38642L19.5996 12.1155C19.4747 12.432 19.0267 12.432 18.9019 12.1155L17.8255 9.38642C17.7874 9.28977 17.7109 9.21327 17.6143 9.17515L14.8852 8.09883C14.5687 7.97399 14.5687 7.52598 14.8852 7.40114L17.6143 6.32482C17.7109 6.2867 17.7874 6.2102 17.8255 6.11355L18.9019 3.3845Z" fill="currentColor"/>
624
+ <path d="M14.9994 13.2862C15.5089 12.8859 15.5089 12.1141 14.9995 11.7137L10.618 8.27047C9.96188 7.75485 9.00011 8.22225 9.00011 9.05673L9.00011 15.9429C9.00011 16.7773 9.96185 17.2448 10.618 16.7292L14.9994 13.2862Z" fill="currentColor"/>
625
+ </symbol>
626
+ <symbol
627
+ fill="none"
628
+ xmlns="http://www.w3.org/2000/svg"
629
+ viewBox="0 0 24 24"
630
+ id="${Ya}/audio"
631
+ >
632
+ <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
633
+ <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
634
+ <path d="M19.5996 4.3845C19.4747 4.06795 19.0267 4.06795 18.9019 4.3845L17.8255 7.11355C17.7874 7.2102 17.7109 7.2867 17.6143 7.32482L14.8852 8.40114C14.5687 8.52598 14.5687 8.97399 14.8852 9.09883L17.6143 10.1752C17.7109 10.2133 17.7874 10.2898 17.8255 10.3864L18.9019 13.1155C19.0267 13.432 19.4747 13.432 19.5996 13.1155L20.6759 10.3864C20.714 10.2898 20.7905 10.2133 20.8872 10.1752L23.6162 9.09883C23.9328 8.97399 23.9328 8.52598 23.6162 8.40114L20.8872 7.32482C20.7905 7.2867 20.714 7.2102 20.6759 7.11355L19.5996 4.3845Z" fill="currentColor"/>
635
+ </symbol>
636
+ <symbol
637
+ fill="none"
638
+ xmlns="http://www.w3.org/2000/svg"
639
+ viewBox="0 0 24 24"
640
+ id="@imgly/MixingPlate"
641
+ >
642
+ <path d="M9.75 9C10.5784 9 11.25 8.32843 11.25 7.5C11.25 6.67157 10.5784 6 9.75 6C8.92157 6 8.25 6.67157 8.25 7.5C8.25 8.32843 8.92157 9 9.75 9Z" fill="currentColor"/>
643
+ <path d="M7 13C7.82843 13 8.5 12.3284 8.5 11.5C8.5 10.6716 7.82843 10 7 10C6.17157 10 5.5 10.6716 5.5 11.5C5.5 12.3284 6.17157 13 7 13Z" fill="currentColor"/>
644
+ <path d="M15.75 7.5C15.75 8.32843 15.0784 9 14.25 9C13.4216 9 12.75 8.32843 12.75 7.5C12.75 6.67157 13.4216 6 14.25 6C15.0784 6 15.75 6.67157 15.75 7.5Z" fill="currentColor"/>
645
+ <path d="M17 13C17.8284 13 18.5 12.3284 18.5 11.5C18.5 10.6716 17.8284 10 17 10C16.1716 10 15.5 10.6716 15.5 11.5C15.5 12.3284 16.1716 13 17 13Z" fill="currentColor"/>
646
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M8.26309 2.77709C10.6681 1.77921 13.4829 1.7322 15.9209 2.64297C18.1572 3.47923 20.0876 5.09285 21.1766 7.28598C22.3395 9.62772 22.4889 13.1077 20.3864 15.2982C19.2693 16.4621 17.7657 16.9982 16.0026 16.9997C15.7897 16.9997 15.5555 16.9864 15.3497 16.9745C15.309 16.9722 15.2694 16.9699 15.2313 16.9679C14.9817 16.9542 14.761 16.9455 14.5569 16.9539C14.124 16.9718 13.9598 17.0612 13.89 17.1324C13.718 17.3081 13.6946 17.6672 13.8854 17.8895C14.2899 18.3608 14.5016 18.9277 14.5016 19.5497C14.5016 20.2206 14.3086 20.9011 13.7542 21.3896C13.2471 21.837 12.6082 21.9997 11.9635 21.9997C10.6049 21.9997 9.31155 21.7367 8.0934 21.2067C6.89058 20.6831 5.84501 19.9687 4.94363 19.0666C4.04281 18.1651 3.31836 17.107 2.79369 15.8978C1.72761 13.4409 1.72662 10.5261 2.81247 8.07034C3.88024 5.65548 5.84206 3.78161 8.26309 2.77709ZM15.2207 4.51639C13.2556 3.78239 10.9651 3.82132 9.02956 4.62439C7.06888 5.43791 5.49559 6.94785 4.64163 8.87914C3.78373 10.8194 3.78253 13.1522 4.62841 15.1017C5.05312 16.0805 5.63511 16.9291 6.35838 17.6529C7.08102 18.3761 7.91671 18.9484 8.89123 19.3728C9.8492 19.7895 10.87 19.9997 11.9635 19.9997C12.2815 19.9997 12.394 19.9225 12.431 19.8899L12.4319 19.8891C12.4367 19.8849 12.4487 19.8743 12.4631 19.8359C12.4799 19.7911 12.5016 19.7024 12.5016 19.5497C12.5016 19.4091 12.4633 19.3034 12.3677 19.192C11.5353 18.222 11.5272 16.6868 12.4611 15.7331C13.0741 15.1071 13.8844 14.98 14.4745 14.9556C14.7819 14.943 15.085 14.9568 15.3409 14.9709C15.3906 14.9736 15.4379 14.9763 15.4832 14.9788C15.6876 14.9904 15.8508 14.9997 16.0009 14.9997C17.3405 14.9986 18.2792 14.6054 18.9435 13.9133C20.2633 12.5382 20.3186 10.055 19.3853 8.1755C18.5436 6.48051 17.0293 5.19281 15.2207 4.51639Z" fill="currentColor"/>
647
+
648
+ </symbol>
649
+ </svg>
650
+ `,eY=Xq;function tY(e){return async(t,r,i)=>e.enable?(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await fg(2e3),await rY(t,e,r)):i(t,r)}async function rY(e,t,r){switch(t.kind){case"image":return iY(e,t,r);case"video":return nY(e,t,r);case"text":return oY(e,t,r);case"audio":return lY(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function iY(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await JG(l,r),s=await KG(u,r);i=s.width,n=s.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
651
+ `,"+")}`}}async function nY(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function oY(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,l=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);l&&l[1]&&(i=l[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=Li(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=Li(n,o)}else"customPrompt"in e?a=Li(n,"custom"):a=Li(n,"improved");else a=Li(n,"generated");return aY(a,r.abortSignal)}async function*aY(e,t){let r=Math.max(1,Math.ceil(e.length/20)),i=0;for(;i<e.length;){if(t?.aborted)return;let n=Math.min(i+r,e.length);yield{kind:"text",text:e.substring(0,n)},i=n,i<e.length&&await fg(100)}return{kind:"text",text:e}}function Li(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,l="";if(n<=o.length)l=o.substring(0,n);else{l=o;let u=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],s=0;for(;l.length<n;){let c=u[s%u.length];if(l.length+c.length<=n)l+=c;else{l+=c.substring(0,n-l.length);break}s++}}return r+l}async function lY(e,t,r){let i=3;if(e!=null&&typeof e=="object"){if("duration"in e&&typeof e.duration=="number")i=e.duration;else if("prompt"in e&&typeof e.prompt=="string"){let n=e.prompt.match(/(\d+)\s*(?:seconds?|secs?|s)\b/i);n&&(i=parseInt(n[1],10))}}return t.blockInputs?.audio?.duration&&(i=t.blockInputs.audio.duration),{kind:"audio",url:sY(220,i),duration:i,thumbnailUrl:void 0}}function sY(e,t){let r=Math.floor(44100*t),i=new Float32Array(r);for(let n=0;n<r;n++)i[n]=Math.sin(2*Math.PI*e*n/44100);return uY(i,44100)}function uY(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,l=r*i,u=44+l,s=new ArrayBuffer(u),c=new DataView(s),d=(b,m)=>{for(let h=0;h<m.length;h++)c.setUint8(b+h,m.charCodeAt(h))};d(0,"RIFF"),c.setUint32(4,u-8,!0),d(8,"WAVE"),d(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,n,!0),c.setUint32(24,t,!0),c.setUint32(28,o,!0),c.setUint16(32,a,!0),c.setUint16(34,16,!0),d(36,"data"),c.setUint32(40,l,!0);let p=44;for(let b=0;b<r;b++){let m=Math.max(-1,Math.min(1,e[b])),h=Math.round(m*32767);c.setInt16(p,h,!0),p+=2}let g=new Uint8Array(s),f="";for(let b=0;b<g.length;b++)f+=String.fromCharCode(g[b]);return`data:audio/wav;base64,${btoa(f)}`}async function fg(e){return new Promise(t=>{setTimeout(t,e)})}var cY=tY,dY="USER_CANCEL";function pY(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=iq([...e.provider.output.middleware??[],...r?.middlewares??[],oq({enable:r?.debug}),cY({enable:r?.dryRun,kind:e.provider.kind})]);try{let{result:n}=await i(e.provider.output.generate)(t,{abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk});return r?.abortSignal?.aborted?{status:"aborted"}:n instanceof Error?{status:"error",message:n.message}:n==null?{status:"error",message:"No output generated"}:uq(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return ll(n)?{status:"aborted",message:n.message}:n===dY?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var gY=pY;async function fY(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n};await t.initialize?.({...r,engine:r.cesdk.engine});let o=Wq(a),l=Jq(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=l;let u=gY({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),s=await Zq(a,u);cq(r.cesdk,"@imgly/plugin-ai-generation",eY);let c={provider:t,panel:{builderRenderFunction:s},history:{assetSourceId:o,assetLibraryEntryId:l},generate:u};return rq.get().register(c),c}var Ha=fY;function hY(e){let{kind:t,cesdk:r,historAssetSourceIds:i}=e,n=`ly.img.ai.${t}-generation.history`;if(r.engine.asset.findAllSources().includes(n))return n;let a=new eV(n,r,i);return r.engine.asset.addSource(a),a.id}var mY=hY;async function yY(e,t,r,i){let n,a=[];if(Array.isArray(t)){let l=await Promise.all(t.map(u=>Ha(e,u,r,i)));a.push(...l),n=vY({prefix:e,providerInitializationResults:a})}else{let l=await Promise.all(t.fromText.map(s=>Ha(e,s,r,i)));a.push(...l);let u=await Promise.all(t.fromImage.map(s=>Ha(e,s,r,i)));a.push(...u),n=bY({prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u})}let o=mY({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(l=>l.history?.assetSourceId).filter(eq)});return{panel:{builderRenderFunction:n},history:{assetSourceId:o},providerInitializationResults:a}}function bY({prefix:e,initializedFromTextProviders:t,initializedFromImageProviders:r}){let i=t.length>0&&r.length>0;return n=>{let{builder:a,experimental:o}=n,l=o.global(`${e}.fromType`,i?"fromText":void 0),u=[];l.value==="fromText"?u.push(...t):l.value==="fromImage"?u.push(...r):u.push(...t,...r);let s=t.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),c=r.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),d=n.experimental.global(`${e}.selectedProvider.fromText`,s[0]),p=n.experimental.global(`${e}.selectedProvider.fromImage`,c[0]),g=l.value==="fromText"?d:l.value==="fromImage"?p:void 0;if((i||u.length>1)&&a.Section(`${e}.providerSelection.section`,{children:()=>{if(i&&a.ButtonGroup(`${e}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{a.Button(`${e}.fromType.buttonGroup.fromText`,{label:"Text",icon:l.value!=="fromText"&&Tp(t,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromText",onClick:()=>{l.setValue("fromText")}}),a.Button(`${e}.fromType.buttonGroup.fromImage`,{label:"Image",icon:l.value!=="fromImage"&&Tp(r,n)?"@imgly/LoadingSpinner":void 0,isActive:l.value==="fromImage",onClick:()=>{l.setValue("fromImage")}})}}),u.length>1){let f=l.value==="fromText"?s:l.value==="fromImage"?c:[...s,...c];g!=null&&a.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:f,...g})}}}),u.length>1)g?.value.builderRenderFunction?.(n);else{let f=u[0];f&&f.panel?.builderRenderFunction?.(n)}}}function vY({prefix:e,providerInitializationResults:t}){return r=>{let{builder:i}=r;if(t.length===0)return;let n=t.map(({provider:o,panel:l})=>({id:o.id,label:o.name??o.id,builderRenderFunction:l?.builderRenderFunction})),a=r.state(`${e}.selectedProvider`,n[0]);t.length>1&&a!=null&&i.Section(`${e}.providerSelection.section`,{children:()=>{i.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:n,...a})}}),a.value.builderRenderFunction?.(r)}}function Tp(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(ul(r.id),!1).value)}var wY=yY,kY="@imgly/plugin-ai-sticker-generation",xY=`
652
+ <svg>
653
+ <symbol
654
+ fill="none"
655
+ xmlns="http://www.w3.org/2000/svg"
656
+ viewBox="0 0 24 24"
657
+ id="@imgly/StickerVariation"
658
+ >
659
+ <path d="M4.5 4H13.5C13.7761 4 14 4.22386 14 4.5V5H16V4.5C16 3.11929 14.8807 2 13.5 2H4.5C3.11929 2 2 3.11929 2 4.5V13.5C2 14.8807 3.11929 16 4.5 16H5V14H4.5C4.22386 14 4 13.7761 4 13.5V4.5C4 4.22386 4.22386 4 4.5 4Z" fill="currentColor"/>
660
+ <path d="M15.9375 13.625C16.8695 13.625 17.625 12.8695 17.625 11.9375C17.625 11.0055 16.8695 10.25 15.9375 10.25C15.0055 10.25 14.25 11.0055 14.25 11.9375C14.25 12.8695 15.0055 13.625 15.9375 13.625Z" fill="currentColor"/>
661
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M9.5 7C8.11929 7 7 8.11929 7 9.5V18.5C7 19.8807 8.11929 21 9.5 21H18.5C19.8807 21 21 19.8807 21 18.5V9.5C21 8.11929 19.8807 7 18.5 7H9.5ZM9 9.5C9 9.22386 9.22386 9 9.5 9H18.5C18.7761 9 19 9.22386 19 9.5V18.5C19 18.7761 18.7761 19 18.5 19H16.3351L12.7198 13.5771C12.4972 13.2432 12.0064 13.2432 11.7838 13.5771L9 17.7528V9.5Z" fill="currentColor"/>
662
+
663
+ </symbol>
664
+ </svg>
665
+ `,IY=xY,CY=typeof global=="object"&&global&&global.Object===Object&&global,hg=CY,AY=typeof self=="object"&&self&&self.Object===Object&&self,MY=hg||AY||Function("return this")(),re=MY,jY=re.Symbol,Kt=jY,mg=Object.prototype,SY=mg.hasOwnProperty,EY=mg.toString,Ti=Kt?Kt.toStringTag:void 0;function _Y(e){var t=SY.call(e,Ti),r=e[Ti];try{e[Ti]=void 0;var i=!0}catch{}var n=EY.call(e);return i&&(t?e[Ti]=r:delete e[Ti]),n}var LY=_Y,TY=Object.prototype,$Y=TY.toString;function NY(e){return $Y.call(e)}var OY=NY,DY="[object Null]",PY="[object Undefined]",$p=Kt?Kt.toStringTag:void 0;function zY(e){return e==null?e===void 0?PY:DY:$p&&$p in Object(e)?LY(e):OY(e)}var Vi=zY;function UY(e){return e!=null&&typeof e=="object"}var cl=UY,dX=Array.isArray;function RY(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var yg=RY,FY="[object AsyncFunction]",VY="[object Function]",BY="[object GeneratorFunction]",GY="[object Proxy]";function qY(e){if(!yg(e))return!1;var t=Vi(e);return t==VY||t==BY||t==FY||t==GY}var YY=qY,HY=re["__core-js_shared__"],Za=HY,Np=function(){var e=/[^.]+$/.exec(Za&&Za.keys&&Za.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function ZY(e){return!!Np&&Np in e}var QY=ZY,WY=Function.prototype,KY=WY.toString;function JY(e){if(e!=null){try{return KY.call(e)}catch{}try{return e+""}catch{}}return""}var Ne=JY,XY=/[\\^$.*+?()[\]{}|]/g,eH=/^\[object .+?Constructor\]$/,tH=Function.prototype,rH=Object.prototype,iH=tH.toString,nH=rH.hasOwnProperty,oH=RegExp("^"+iH.call(nH).replace(XY,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function aH(e){if(!yg(e)||QY(e))return!1;var t=YY(e)?oH:eH;return t.test(Ne(e))}var lH=aH;function sH(e,t){return e?.[t]}var uH=sH;function cH(e,t){var r=uH(e,t);return lH(r)?r:void 0}var rr=cH,dH=rr(re,"WeakMap"),tl=dH;function pH(e,t){return e===t||e!==e&&t!==t}var gH=pH,fH=9007199254740991;function hH(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=fH}var mH=hH,pX=Object.prototype,yH="[object Arguments]";function bH(e){return cl(e)&&Vi(e)==yH}var Op=bH,bg=Object.prototype,vH=bg.hasOwnProperty,wH=bg.propertyIsEnumerable,gX=Op(function(){return arguments}())?Op:function(e){return cl(e)&&vH.call(e,"callee")&&!wH.call(e,"callee")},vg=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Dp=vg&&typeof module=="object"&&module&&!module.nodeType&&module,kH=Dp&&Dp.exports===vg,Pp=kH?re.Buffer:void 0,fX=Pp?Pp.isBuffer:void 0,xH="[object Arguments]",IH="[object Array]",CH="[object Boolean]",AH="[object Date]",MH="[object Error]",jH="[object Function]",SH="[object Map]",EH="[object Number]",_H="[object Object]",LH="[object RegExp]",TH="[object Set]",$H="[object String]",NH="[object WeakMap]",OH="[object ArrayBuffer]",DH="[object DataView]",PH="[object Float32Array]",zH="[object Float64Array]",UH="[object Int8Array]",RH="[object Int16Array]",FH="[object Int32Array]",VH="[object Uint8Array]",BH="[object Uint8ClampedArray]",GH="[object Uint16Array]",qH="[object Uint32Array]",D={};D[PH]=D[zH]=D[UH]=D[RH]=D[FH]=D[VH]=D[BH]=D[GH]=D[qH]=!0;D[xH]=D[IH]=D[OH]=D[CH]=D[DH]=D[AH]=D[MH]=D[jH]=D[SH]=D[EH]=D[_H]=D[LH]=D[TH]=D[$H]=D[NH]=!1;function YH(e){return cl(e)&&mH(e.length)&&!!D[Vi(e)]}var HH=YH;function ZH(e){return function(t){return e(t)}}var QH=ZH,wg=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Oi=wg&&typeof module=="object"&&module&&!module.nodeType&&module,WH=Oi&&Oi.exports===wg,Qa=WH&&hg.process,KH=function(){try{var e=Oi&&Oi.require&&Oi.require("util").types;return e||Qa&&Qa.binding&&Qa.binding("util")}catch{}}(),zp=KH,Up=zp&&zp.isTypedArray,hX=Up?QH(Up):HH,JH=Object.prototype,mX=JH.hasOwnProperty;function XH(e,t){return function(r){return e(t(r))}}var eZ=XH,yX=eZ(Object.keys,Object),tZ=Object.prototype,bX=tZ.hasOwnProperty,rZ=rr(Object,"create"),zi=rZ;function iZ(){this.__data__=zi?zi(null):{},this.size=0}var nZ=iZ;function oZ(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var aZ=oZ,lZ="__lodash_hash_undefined__",sZ=Object.prototype,uZ=sZ.hasOwnProperty;function cZ(e){var t=this.__data__;if(zi){var r=t[e];return r===lZ?void 0:r}return uZ.call(t,e)?t[e]:void 0}var dZ=cZ,pZ=Object.prototype,gZ=pZ.hasOwnProperty;function fZ(e){var t=this.__data__;return zi?t[e]!==void 0:gZ.call(t,e)}var hZ=fZ,mZ="__lodash_hash_undefined__";function yZ(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=zi&&t===void 0?mZ:t,this}var bZ=yZ;function ir(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}ir.prototype.clear=nZ;ir.prototype.delete=aZ;ir.prototype.get=dZ;ir.prototype.has=hZ;ir.prototype.set=bZ;var Rp=ir;function vZ(){this.__data__=[],this.size=0}var wZ=vZ;function kZ(e,t){for(var r=e.length;r--;)if(gH(e[r][0],t))return r;return-1}var zn=kZ,xZ=Array.prototype,IZ=xZ.splice;function CZ(e){var t=this.__data__,r=zn(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():IZ.call(t,r,1),--this.size,!0}var AZ=CZ;function MZ(e){var t=this.__data__,r=zn(t,e);return r<0?void 0:t[r][1]}var jZ=MZ;function SZ(e){return zn(this.__data__,e)>-1}var EZ=SZ;function _Z(e,t){var r=this.__data__,i=zn(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var LZ=_Z;function nr(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}nr.prototype.clear=wZ;nr.prototype.delete=AZ;nr.prototype.get=jZ;nr.prototype.has=EZ;nr.prototype.set=LZ;var Un=nr,TZ=rr(re,"Map"),Ui=TZ;function $Z(){this.size=0,this.__data__={hash:new Rp,map:new(Ui||Un),string:new Rp}}var NZ=$Z;function OZ(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var DZ=OZ;function PZ(e,t){var r=e.__data__;return DZ(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Rn=PZ;function zZ(e){var t=Rn(this,e).delete(e);return this.size-=t?1:0,t}var UZ=zZ;function RZ(e){return Rn(this,e).get(e)}var FZ=RZ;function VZ(e){return Rn(this,e).has(e)}var BZ=VZ;function GZ(e,t){var r=Rn(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var qZ=GZ;function or(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}or.prototype.clear=NZ;or.prototype.delete=UZ;or.prototype.get=FZ;or.prototype.has=BZ;or.prototype.set=qZ;var kg=or;function YZ(){this.__data__=new Un,this.size=0}var HZ=YZ;function ZZ(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var QZ=ZZ;function WZ(e){return this.__data__.get(e)}var KZ=WZ;function JZ(e){return this.__data__.has(e)}var XZ=JZ,eQ=200;function tQ(e,t){var r=this.__data__;if(r instanceof Un){var i=r.__data__;if(!Ui||i.length<eQ-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new kg(i)}return r.set(e,t),this.size=r.size,this}var rQ=tQ;function Bi(e){var t=this.__data__=new Un(e);this.size=t.size}Bi.prototype.clear=HZ;Bi.prototype.delete=QZ;Bi.prototype.get=KZ;Bi.prototype.has=XZ;Bi.prototype.set=rQ;var iQ=Object.prototype,vX=iQ.propertyIsEnumerable,nQ=rr(re,"DataView"),rl=nQ,oQ=rr(re,"Promise"),il=oQ,aQ=rr(re,"Set"),nl=aQ,Fp="[object Map]",lQ="[object Object]",Vp="[object Promise]",Bp="[object Set]",Gp="[object WeakMap]",qp="[object DataView]",sQ=Ne(rl),uQ=Ne(Ui),cQ=Ne(il),dQ=Ne(nl),pQ=Ne(tl),Zt=Vi;(rl&&Zt(new rl(new ArrayBuffer(1)))!=qp||Ui&&Zt(new Ui)!=Fp||il&&Zt(il.resolve())!=Vp||nl&&Zt(new nl)!=Bp||tl&&Zt(new tl)!=Gp)&&(Zt=function(e){var t=Vi(e),r=t==lQ?e.constructor:void 0,i=r?Ne(r):"";if(i)switch(i){case sQ:return qp;case uQ:return Fp;case cQ:return Vp;case dQ:return Bp;case pQ:return Gp}return t});var wX=re.Uint8Array,gQ="__lodash_hash_undefined__";function fQ(e){return this.__data__.set(e,gQ),this}var hQ=fQ;function mQ(e){return this.__data__.has(e)}var yQ=mQ;function ol(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new kg;++t<r;)this.add(e[t])}ol.prototype.add=ol.prototype.push=hQ;ol.prototype.has=yQ;var Yp=Kt?Kt.prototype:void 0,kX=Yp?Yp.valueOf:void 0,bQ=Object.prototype,xX=bQ.hasOwnProperty,vQ=Object.prototype,IX=vQ.hasOwnProperty,CX=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),AX=new RegExp(/[A-Fa-f0-9]{1}/,"g"),MX=new RegExp(/[A-Fa-f0-9]{2}/,"g");function wQ(e){return e==null?[]:Array.isArray(e)?e:[e]}var kQ=wQ,Nn="@imgly/plugin-ai-sticker-generation-web",me="ly.img.ai.sticker-generation";function xQ(e){return{async initialize({cesdk:t}){if(t==null)return;dq(t,Nn,"0.2.0");let r=tq.get().register({type:"plugin",sceneMode:"Design",id:Nn,pluginId:Nn,label:"Generate Sticker",meta:{panelId:me},execute:()=>{t.ui.isPanelOpen(me)?t.ui.closePanel(me):t.ui.openPanel(me)}});t.ui.addIconSet(kY,IY),t.i18n.setTranslations({en:{[`panel.${me}`]:"Sticker Generation",[`${me}.dock.label`]:"AI Sticker"}});let i=e.providers?.text2sticker,n=await Promise.all(kQ(i).map(o=>o({cesdk:t}))),a=await wY("sticker",{fromText:n,fromImage:[]},{cesdk:t},e);a.history?.assetSourceId!=null,a.panel.builderRenderFunction!=null?(t.ui.registerPanel(me,a.panel.builderRenderFunction),gq({cesdk:t,panelId:me})):r()}}}var IQ=xQ,CQ=e=>({name:Nn,version:"0.2.0",...IQ(e)}),xg=CQ;var dl=class{constructor(t,r,i=[]){this.id=t,this.assetsOrProvider=i,this.activeAssetIds=new Set,this.loaderDisposer={},this.cesdk=r}getCurrentAssets(){return typeof this.assetsOrProvider=="function"?this.assetsOrProvider():this.assetsOrProvider}async findAssets(t){let{page:r,perPage:i,locale:n="en",sortActiveFirst:a,query:o,tags:l,groups:u,excludeGroups:s,sortingOrder:c,sortKey:d}=t,p=[...this.getCurrentAssets()];if(u&&u.length>0&&(p=p.filter(w=>w.groups&&u.some(v=>w.groups?.includes(v)))),s&&s.length>0&&(p=p.filter(w=>!w.groups||!s.some(v=>w.groups?.includes(v)))),o){let w=o.toLowerCase();p=p.filter(v=>{let y=v.label?.[n]?.toLowerCase(),k=v.tags?.[n]||[];return y&&y.includes(w)||k.some(I=>I.toLowerCase().includes(w))})}if(l&&l.length>0){let w=Array.isArray(l)?l:[l];p=p.filter(v=>{let y=v.tags?.[n]||[];return w.some(k=>y.includes(k))})}a&&p.sort((w,v)=>{let y=this.activeAssetIds.has(w.id),k=this.activeAssetIds.has(v.id);return y&&!k?-1:!y&&k?1:0}),d&&d!=="id"?p.sort((w,v)=>{let y=w.meta?.[d],k=v.meta?.[d];return y===void 0?1:k===void 0?-1:typeof y=="string"&&typeof k=="string"?c==="Descending"?k.localeCompare(y):y.localeCompare(k):typeof y=="number"&&typeof k=="number"?c==="Descending"?k-y:y-k:0}):d==="id"&&p.sort((w,v)=>c==="Descending"?v.id.localeCompare(w.id):w.id.localeCompare(v.id));let g=p.length,f=r*i,b=f+i,h=p.slice(f,b).map(w=>({id:w.id,groups:w.groups,meta:w.meta,payload:w.payload,locale:n,label:w.label?.[n],tags:w.tags?.[n],active:this.activeAssetIds.has(w.id)})),x=b<g?r+1:void 0;return{assets:h,currentPage:r,nextPage:x,total:g}}updateLabel(t,r,i){if(typeof this.assetsOrProvider=="function"){console.warn("Cannot update label on dynamic asset provider");return}this.assetsOrProvider.forEach(n=>{n.id===t&&(n.label=n.label||{},n.label[i]=r(n.label[i]))})}getLabel(t,r){let i=this.getCurrentAssets().find(n=>n.id===t);if(i!=null)return i.label?.[r]}setAssetActive(t){this.activeAssetIds.add(t)}setAssetLoading(t,r){if(r){let i=this.getLabel(t,"en")??"",n=AQ(a=>this.cesdk.engine.asset===null?!1:(this.updateLabel(t,()=>`${a} ${i}`,"en"),this.cesdk.engine.asset.assetSourceContentsChanged(this.id),!0));this.loaderDisposer[t]=()=>{this.updateLabel(t,()=>i,"en"),n()}}else this.loaderDisposer[t]?.(),this.loaderDisposer[t]=void 0}setAssetInactive(t){this.activeAssetIds.delete(t),this.loaderDisposer[t]?.(),this.loaderDisposer[t]=void 0}clearActiveAssets(){this.activeAssetIds.clear(),Object.values(this.loaderDisposer).forEach(t=>{t?.()}),this.loaderDisposer={}}isAssetActive(t){return this.activeAssetIds.has(t)}addAsset(t){if(typeof this.assetsOrProvider=="function"){console.warn("Cannot add asset to dynamic asset provider");return}let r=this.assetsOrProvider.findIndex(i=>i.id===t.id);r>=0?this.assetsOrProvider[r]=t:this.assetsOrProvider.push(t)}removeAsset(t){if(typeof this.assetsOrProvider=="function"){console.warn("Cannot remove asset from dynamic asset provider");return}let r=this.assetsOrProvider.findIndex(i=>i.id===t);r!==-1&&(this.assetsOrProvider.splice(r,1),this.activeAssetIds.delete(t))}async getGroups(){let t=new Set;return this.getCurrentAssets().forEach(r=>{r.groups&&r.groups.forEach(i=>t.add(i))}),Array.from(t)}getSupportedMimeTypes(){return["image/jpeg","image/png","image/svg+xml","image/webp","video/mp4","audio/mpeg"]}};function Ig(e,t,r=[]){return new dl(e,t,r)}function AQ(e,t=200){let r=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],i=0,n=setInterval(()=>{let a=r[i];i=(i+1)%r.length,e(a)||clearInterval(n)},t);return()=>{clearInterval(n)}}var Gi="ly.img.ai.apps";var z=rs("apps"),MQ=512,jQ=128,Cg=e=>({async initialize({cesdk:t}){if(t==null)return;is(t,Gi,"0.2.0");let{providers:r}=e;t.addPlugin(mp({providers:{text2text:r.text2text},debug:e.debug,dryRun:e.dryRun})),t.addPlugin(Mu({providers:{text2image:r.text2image,image2image:r.image2image},debug:e.debug,dryRun:e.dryRun})),t.addPlugin(Dc({providers:{text2video:r.text2video,image2video:r.image2video},debug:e.debug,dryRun:e.dryRun})),t.addPlugin(qd({providers:{text2speech:r.text2speech,text2sound:r.text2sound},debug:e.debug,dryRun:e.dryRun})),t.addPlugin(xg({providers:{text2sticker:r.text2sticker},debug:e.debug,dryRun:e.dryRun})),TQ(t),SQ(t,{...e,baseURL:e.baseURL??"https://cdn.img.ly/assets/plugins/plugin-ai-apps-web/v1/"})}});function SQ(e,t){LQ(e);let r=EQ(e,t);e.engine.asset.addSource(r),e.ui.registerPanel(z,({builder:n})=>{n.Library(z,{entries:[z],onSelect:async a=>{Ki.get().getBy({id:a.id,type:"plugin"}).forEach(o=>{o.execute()})}})}),e.ui.addAssetLibraryEntry({id:z,sourceIds:[z],gridColumns:1,gridItemHeight:"auto",gridBackgroundType:"cover",cardLabel:({label:n})=>n,cardLabelPosition:()=>"inside"});let i=`${z}.dock`;e.ui.registerComponent(i,({builder:n,experimental:a})=>{let o=r.getCurrentAssets();if(o.length===0)return;let l=o.length===1?Ki.get().getBy({id:o[0].id,type:"plugin"})[0]:void 0,u=l?.meta?.panelId??z,s=e.ui.isPanelOpen(u),c=a.global(`${z}.isGenerating`,!1);n.Button(`${z}.dock.button`,{label:"AI",isSelected:s,icon:c.value?"@imgly/LoadingSpinner":"@imgly/Sparkle",onClick:()=>{e.ui.findAllPanels().forEach(d=>{d.startsWith("ly.img.ai.")&&d!==u&&e.ui.closePanel(d),!s&&d==="//ly.img.panel/assetLibrary"&&e.ui.closePanel(d)}),l!=null?l.execute():s?e.ui.closePanel(z):e.ui.openPanel(z)}})})}function EQ(e,t){let r=Ki.get(),i=Ig(z,e,()=>{let a=e.engine.scene.getMode();return r.getBy({type:"plugin"}).map(({id:o,label:l,sceneMode:u})=>a==="Design"&&u==="Video"?void 0:{id:o,label:{en:l??o},meta:{sceneMode:u,thumbUri:t.baseURL!=null?_Q(t.baseURL,o):void 0,width:MQ,height:jQ}}).filter($l)}),n=r.subscribeBy({type:"plugin"},()=>{if(e?.engine?.asset?.assetSourceContentsChanged==null){n();return}e.engine.asset.assetSourceContentsChanged(z)});return i}function _Q(e,t){switch(t){case"@imgly/plugin-ai-image-generation-web":return`${e}GenerateImage.png`;case"@imgly/plugin-ai-video-generation-web":return`${e}GenerateVideo.png`;case"@imgly/plugin-ai-audio-generation-web/sound":return`${e}GenerateSound.png`;case"@imgly/plugin-ai-audio-generation-web/speech":return`${e}AIVoice.png`;case"@imgly/plugin-ai-sticker-generation-web":return`${e}GenerateSticker.png`;default:return`${e}GenerateImage.png`}}function LQ(e){e.ui.registerComponent("ly.img.assetLibrary.dock",({builder:{Button:t},engine:r,payload:i})=>{let n="\n\nPlease provide a payload with entries, e.g. \n```\n{ id: 'ly.img.assetLibrary.dock', entries: ['ly.img.image', 'ly.img.video'] }\n```";if(!i||i.id!=="ly.img.assetLibrary.dock"){console.warn(`No payload found for 'ly.img.assetLibrary.dock'${n}`);return}let{id:a,key:o,label:l,icon:u,entries:s}=i;if(s==null||!Array.isArray(s)){console.warn(`No valid entries value found for 'ly.img.assetLibrary.dock'${n}`);return}if(s.some(m=>typeof m!="string")){console.warn(`Entries value for 'ly.img.assetLibrary.dock' need to be all strings referring to asset library entries${n}`);return}l!=null&&typeof l!="string"&&console.warn("Label for 'ly.img.assetLibrary.dock' must be a string if provided");let c=r.scene.getMode(),d=s.filter(m=>{let h=e.ui.getAssetLibraryEntry(m);if(h==null)return!1;let x=h.sceneMode;return typeof x=="string"?h.sceneMode===c||h.sceneMode==="All":typeof x=="function"?h.sourceIds.some(w=>{let v=x(e.version.startsWith("1.51.")?w:{sourceId:w});return v===c||v==="All"}):!0});if(d.length===0)return;let p=l;p==null&&(p=`libraries.${a}.label`);let g=e.ui.isPanelOpen("//ly.img.panel/assetLibrary",{payload:{entries:d,title:p}}),f=e.ui.isPanelOpen("//ly.img.panel/assetLibrary.replace"),b=u;b==null&&d.length===1&&(b=e.ui.getAssetLibraryEntry(d[0])?.icon),t(o??a,{label:p,icon:b,isDisabled:f,isSelected:g,onClick:()=>{g?e.ui.closePanel("//ly.img.panel/assetLibrary"):(e.ui.findAllPanels().forEach(m=>{(m===z||m.startsWith("ly.img.ai."))&&e.ui.closePanel(m)}),e.ui.openPanel("//ly.img.panel/assetLibrary",{payload:{entries:d,title:p}}))}})})}function TQ(e){e.i18n.setTranslations({en:{"common.generate":"Generate","panel.ly.img.ai.generation.confirmCancel.content":"Are you sure you want to cancel the generation?","panel.ly.img.ai.generation.confirmCancel.confirm":"Cancel Generation","panel.ly.img.ai.apps":"AI","panel.ly.img.ai.demo.video":"Generate Video","panel.ly.img.ai.demo.image":"Generate Image","libraries.ly.img.ai.image-generation.history.label":"AI Generated Images","libraries.ly.img.ai.video-generation.history.label":"AI Generated Videos","libraries.ly.img.ai.audio-generation.history.label":"AI Generated Audio","libraries.ly.img.ai.sticker-generation.history.label":"AI Generated Stickers"}})}var $Q=e=>({name:Gi,version:"0.2.0",...Cg(e)}),GX=$Q;export{GX as default};
401
666
  /*! Bundled license information:
402
667
 
668
+ @imgly/plugin-utils/dist/index.mjs:
669
+ (*! Bundled license information:
670
+
671
+ lodash-es/lodash.js:
672
+ (**
673
+ * @license
674
+ * Lodash (Custom Build) <https://lodash.com/>
675
+ * Build: `lodash modularize exports="es" -o ./`
676
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
677
+ * Released under MIT license <https://lodash.com/license>
678
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
679
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
680
+ *)
681
+ *)
682
+
403
683
  @imgly/plugin-ai-generation-web/dist/index.mjs:
404
684
  (*! Bundled license information:
405
685
 
@@ -440,6 +720,21 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
440
720
  *)
441
721
  *)
442
722
  *)
723
+
724
+ @imgly/plugin-utils/dist/index.mjs:
725
+ (*! Bundled license information:
726
+
727
+ lodash-es/lodash.js:
728
+ (**
729
+ * @license
730
+ * Lodash (Custom Build) <https://lodash.com/>
731
+ * Build: `lodash modularize exports="es" -o ./`
732
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
733
+ * Released under MIT license <https://lodash.com/license>
734
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
735
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
736
+ *)
737
+ *)
443
738
  *)
444
739
 
445
740
  @imgly/plugin-ai-video-generation-web/dist/index.mjs:
@@ -463,6 +758,21 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
463
758
  *)
464
759
  *)
465
760
  *)
761
+
762
+ @imgly/plugin-utils/dist/index.mjs:
763
+ (*! Bundled license information:
764
+
765
+ lodash-es/lodash.js:
766
+ (**
767
+ * @license
768
+ * Lodash (Custom Build) <https://lodash.com/>
769
+ * Build: `lodash modularize exports="es" -o ./`
770
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
771
+ * Released under MIT license <https://lodash.com/license>
772
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
773
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
774
+ *)
775
+ *)
466
776
  *)
467
777
 
468
778
  @imgly/plugin-ai-audio-generation-web/dist/index.mjs:
@@ -486,6 +796,21 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
486
796
  *)
487
797
  *)
488
798
  *)
799
+
800
+ @imgly/plugin-utils/dist/index.mjs:
801
+ (*! Bundled license information:
802
+
803
+ lodash-es/lodash.js:
804
+ (**
805
+ * @license
806
+ * Lodash (Custom Build) <https://lodash.com/>
807
+ * Build: `lodash modularize exports="es" -o ./`
808
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
809
+ * Released under MIT license <https://lodash.com/license>
810
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
811
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
812
+ *)
813
+ *)
489
814
  *)
490
815
 
491
816
  @imgly/plugin-ai-text-generation-web/dist/index.mjs:
@@ -509,21 +834,59 @@ var Ul=typeof global=="object"&&global&&global.Object===Object&&global,qn=Ul,Vl=
509
834
  *)
510
835
  *)
511
836
  *)
837
+
838
+ @imgly/plugin-utils/dist/index.mjs:
839
+ (*! Bundled license information:
840
+
841
+ lodash-es/lodash.js:
842
+ (**
843
+ * @license
844
+ * Lodash (Custom Build) <https://lodash.com/>
845
+ * Build: `lodash modularize exports="es" -o ./`
846
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
847
+ * Released under MIT license <https://lodash.com/license>
848
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
849
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
850
+ *)
851
+ *)
512
852
  *)
513
853
 
514
- @imgly/plugin-utils/dist/index.mjs:
854
+ @imgly/plugin-ai-sticker-generation-web/dist/index.mjs:
515
855
  (*! Bundled license information:
516
856
 
517
- lodash-es/lodash.js:
518
- (**
519
- * @license
520
- * Lodash (Custom Build) <https://lodash.com/>
521
- * Build: `lodash modularize exports="es" -o ./`
522
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
523
- * Released under MIT license <https://lodash.com/license>
524
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
525
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
526
- *)
857
+ @imgly/plugin-ai-generation-web/dist/index.mjs:
858
+ (*! Bundled license information:
859
+
860
+ @imgly/plugin-utils/dist/index.mjs:
861
+ (*! Bundled license information:
862
+
863
+ lodash-es/lodash.js:
864
+ (**
865
+ * @license
866
+ * Lodash (Custom Build) <https://lodash.com/>
867
+ * Build: `lodash modularize exports="es" -o ./`
868
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
869
+ * Released under MIT license <https://lodash.com/license>
870
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
871
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
872
+ *)
873
+ *)
874
+ *)
875
+
876
+ @imgly/plugin-utils/dist/index.mjs:
877
+ (*! Bundled license information:
878
+
879
+ lodash-es/lodash.js:
880
+ (**
881
+ * @license
882
+ * Lodash (Custom Build) <https://lodash.com/>
883
+ * Build: `lodash modularize exports="es" -o ./`
884
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
885
+ * Released under MIT license <https://lodash.com/license>
886
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
887
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
888
+ *)
889
+ *)
527
890
  *)
528
891
  */
529
892
  //# sourceMappingURL=index.mjs.map