@imgly/plugin-ai-video-generation-web 1.73.0-rc.2 → 1.73.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,7 +1,7 @@
1
- var kr=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((c,l)=>{let u=e.locale??"en",d="",f=[];l.label!=null&&typeof l.label=="object"&&l.label[u]&&(d=l.label[u]),l.tags!=null&&typeof l.tags=="object"&&l.tags[u]&&(f=l.tags[u]);let g={...l,label:d,tags:f};return this.filterAsset(g,e)&&c.push(g),c},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,o=n+i,a=t.slice(n,o),s=o<t.length?r+1:void 0;return{assets:a,currentPage:r,nextPage:s,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(o=>{o.groups&&Array.isArray(o.groups)&&o.groups.forEach(a=>i.add(a))});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;V(e,o=>{i.add(o)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.oncomplete=()=>{this.engine.asset.assetSourceContentsChanged(this.id)},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=()=>{V(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((o,a)=>{let s=o.meta?.insertedAt||o._insertedAt||Date.now(),c=a.meta?.insertedAt||a._insertedAt||Date.now();return e==="asc"?s-c:c-s}),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,o])=>{let a={id:n,blob:o};i.put(a)}),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 V(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),V(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:o}=t;if(r&&r.trim()!==""){let a=r.trim().toLowerCase().split(" "),s=e.label?.toLowerCase()??"",c=e.tags?.map(l=>l.toLowerCase())??[];if(!a.every(l=>s.includes(l)||c.some(u=>u.includes(l))))return!1}if(i){let a=Array.isArray(i)?i:[i];if(a.length>0&&(!e.tags||!a.every(s=>e.tags?.includes(s))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(a=>e.groups?.includes(a)))||o&&o.length>0&&e.groups&&e.groups.some(a=>o.includes(a)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,o=[...e];return!r||r==="None"||(i?o.sort((a,s)=>{let c,l;return i==="id"?(c=a.id,l=s.id):(c=a.meta?.[i]??null,l=s.meta?.[i]??null),c==null?r==="Ascending"?-1:1:l==null?r==="Ascending"?1:-1:typeof c=="string"&&typeof l=="string"?r==="Ascending"?c.localeCompare(l):l.localeCompare(c):r==="Ascending"?c<l?-1:c>l?1:0:c>l?-1:c<l?1:0}):r==="Descending"&&o.reverse(),n&&o.sort((a,s)=>a.active&&!s.active?-1:!a.active&&s.active?1:0)),o}};function V(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 o=t(e[i],n);typeof o=="string"&&(e[i]=o)}else e[i]=V(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],o=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let a=t(n,o);typeof a=="string"&&(e[i]=a)}else e[i]=V(n,t,o)}return e}var Ir=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(u=>this.cesdk.engine.asset.findAssets(u,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(u=>{u?.assets&&(i=i.concat(u.assets))}),i.sort((u,d)=>{let f=u.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-f});let{page:n,perPage:o}=e,a=n*o,s=a+o,c=i.slice(a,s),l=s<i.length?n+1:void 0;return{assets:c,currentPage:n,nextPage:l,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")}};var Ar=typeof global=="object"&&global&&global.Object===Object&&global,kt=Ar,Sr=typeof self=="object"&&self&&self.Object===Object&&self,xr=kt||Sr||Function("return this")(),M=xr,Cr=M.Symbol,U=Cr,It=Object.prototype,Er=It.hasOwnProperty,$r=It.toString,X=U?U.toStringTag:void 0;function Mr(e){var t=Er.call(e,X),r=e[X];try{e[X]=void 0;var i=!0}catch{}var n=$r.call(e);return i&&(t?e[X]=r:delete e[X]),n}var jr=Mr,Tr=Object.prototype,_r=Tr.toString;function Lr(e){return _r.call(e)}var Pr=Lr,Or="[object Null]",Nr="[object Undefined]",et=U?U.toStringTag:void 0;function Dr(e){return e==null?e===void 0?Nr:Or:et&&et in Object(e)?jr(e):Pr(e)}var oe=Dr;function zr(e){return e!=null&&typeof e=="object"}var Ve=zr,Xu=Array.isArray;function Rr(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var At=Rr,Fr="[object AsyncFunction]",Vr="[object Function]",Ur="[object GeneratorFunction]",Br="[object Proxy]";function Gr(e){if(!At(e))return!1;var t=oe(e);return t==Vr||t==Ur||t==Fr||t==Br}var qr=Gr,Hr=M["__core-js_shared__"],je=Hr,tt=function(){var e=/[^.]+$/.exec(je&&je.keys&&je.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Zr(e){return!!tt&&tt in e}var Kr=Zr,Qr=Function.prototype,Yr=Qr.toString;function Wr(e){if(e!=null){try{return Yr.call(e)}catch{}try{return e+""}catch{}}return""}var z=Wr,Jr=/[\\^$.*+?()[\]{}|]/g,Xr=/^\[object .+?Constructor\]$/,ei=Function.prototype,ti=Object.prototype,ri=ei.toString,ii=ti.hasOwnProperty,ni=RegExp("^"+ri.call(ii).replace(Jr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ai(e){if(!At(e)||Kr(e))return!1;var t=qr(e)?ni:Xr;return t.test(z(e))}var oi=ai;function li(e,t){return e?.[t]}var si=li;function ui(e,t){var r=si(e,t);return oi(r)?r:void 0}var B=ui,ci=B(M,"WeakMap"),Oe=ci;function di(e,t){return e===t||e!==e&&t!==t}var gi=di,pi=9007199254740991;function fi(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=pi}var mi=fi,ec=Object.prototype,yi="[object Arguments]";function bi(e){return Ve(e)&&oe(e)==yi}var rt=bi,St=Object.prototype,hi=St.hasOwnProperty,vi=St.propertyIsEnumerable,tc=rt(function(){return arguments}())?rt:function(e){return Ve(e)&&hi.call(e,"callee")&&!vi.call(e,"callee")},xt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,it=xt&&typeof module=="object"&&module&&!module.nodeType&&module,wi=it&&it.exports===xt,nt=wi?M.Buffer:void 0,rc=nt?nt.isBuffer:void 0,ki="[object Arguments]",Ii="[object Array]",Ai="[object Boolean]",Si="[object Date]",xi="[object Error]",Ci="[object Function]",Ei="[object Map]",$i="[object Number]",Mi="[object Object]",ji="[object RegExp]",Ti="[object Set]",_i="[object String]",Li="[object WeakMap]",Pi="[object ArrayBuffer]",Oi="[object DataView]",Ni="[object Float32Array]",Di="[object Float64Array]",zi="[object Int8Array]",Ri="[object Int16Array]",Fi="[object Int32Array]",Vi="[object Uint8Array]",Ui="[object Uint8ClampedArray]",Bi="[object Uint16Array]",Gi="[object Uint32Array]",k={};k[Ni]=k[Di]=k[zi]=k[Ri]=k[Fi]=k[Vi]=k[Ui]=k[Bi]=k[Gi]=!0;k[ki]=k[Ii]=k[Pi]=k[Ai]=k[Oi]=k[Si]=k[xi]=k[Ci]=k[Ei]=k[$i]=k[Mi]=k[ji]=k[Ti]=k[_i]=k[Li]=!1;function qi(e){return Ve(e)&&mi(e.length)&&!!k[oe(e)]}var Hi=qi;function Zi(e){return function(t){return e(t)}}var Ki=Zi,Ct=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ie=Ct&&typeof module=="object"&&module&&!module.nodeType&&module,Qi=ie&&ie.exports===Ct,Te=Qi&&kt.process,Yi=function(){try{var e=ie&&ie.require&&ie.require("util").types;return e||Te&&Te.binding&&Te.binding("util")}catch{}}(),at=Yi,ot=at&&at.isTypedArray,ic=ot?Ki(ot):Hi,Wi=Object.prototype,nc=Wi.hasOwnProperty;function Ji(e,t){return function(r){return e(t(r))}}var Xi=Ji,ac=Xi(Object.keys,Object),en=Object.prototype,oc=en.hasOwnProperty,tn=B(Object,"create"),ne=tn;function rn(){this.__data__=ne?ne(null):{},this.size=0}var nn=rn;function an(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var on=an,ln="__lodash_hash_undefined__",sn=Object.prototype,un=sn.hasOwnProperty;function cn(e){var t=this.__data__;if(ne){var r=t[e];return r===ln?void 0:r}return un.call(t,e)?t[e]:void 0}var dn=cn,gn=Object.prototype,pn=gn.hasOwnProperty;function fn(e){var t=this.__data__;return ne?t[e]!==void 0:pn.call(t,e)}var mn=fn,yn="__lodash_hash_undefined__";function bn(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ne&&t===void 0?yn:t,this}var hn=bn;function G(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])}}G.prototype.clear=nn;G.prototype.delete=on;G.prototype.get=dn;G.prototype.has=mn;G.prototype.set=hn;var lt=G;function vn(){this.__data__=[],this.size=0}var wn=vn;function kn(e,t){for(var r=e.length;r--;)if(gi(e[r][0],t))return r;return-1}var ve=kn,In=Array.prototype,An=In.splice;function Sn(e){var t=this.__data__,r=ve(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():An.call(t,r,1),--this.size,!0}var xn=Sn;function Cn(e){var t=this.__data__,r=ve(t,e);return r<0?void 0:t[r][1]}var En=Cn;function $n(e){return ve(this.__data__,e)>-1}var Mn=$n;function jn(e,t){var r=this.__data__,i=ve(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var Tn=jn;function q(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])}}q.prototype.clear=wn;q.prototype.delete=xn;q.prototype.get=En;q.prototype.has=Mn;q.prototype.set=Tn;var we=q,_n=B(M,"Map"),ae=_n;function Ln(){this.size=0,this.__data__={hash:new lt,map:new(ae||we),string:new lt}}var Pn=Ln;function On(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Nn=On;function Dn(e,t){var r=e.__data__;return Nn(t)?r[typeof t=="string"?"string":"hash"]:r.map}var ke=Dn;function zn(e){var t=ke(this,e).delete(e);return this.size-=t?1:0,t}var Rn=zn;function Fn(e){return ke(this,e).get(e)}var Vn=Fn;function Un(e){return ke(this,e).has(e)}var Bn=Un;function Gn(e,t){var r=ke(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var qn=Gn;function H(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])}}H.prototype.clear=Pn;H.prototype.delete=Rn;H.prototype.get=Vn;H.prototype.has=Bn;H.prototype.set=qn;var Et=H;function Hn(){this.__data__=new we,this.size=0}var Zn=Hn;function Kn(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Qn=Kn;function Yn(e){return this.__data__.get(e)}var Wn=Yn;function Jn(e){return this.__data__.has(e)}var Xn=Jn,ea=200;function ta(e,t){var r=this.__data__;if(r instanceof we){var i=r.__data__;if(!ae||i.length<ea-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Et(i)}return r.set(e,t),this.size=r.size,this}var ra=ta;function le(e){var t=this.__data__=new we(e);this.size=t.size}le.prototype.clear=Zn;le.prototype.delete=Qn;le.prototype.get=Wn;le.prototype.has=Xn;le.prototype.set=ra;var ia=Object.prototype,lc=ia.propertyIsEnumerable,na=B(M,"DataView"),Ne=na,aa=B(M,"Promise"),De=aa,oa=B(M,"Set"),ze=oa,st="[object Map]",la="[object Object]",ut="[object Promise]",ct="[object Set]",dt="[object WeakMap]",gt="[object DataView]",sa=z(Ne),ua=z(ae),ca=z(De),da=z(ze),ga=z(Oe),F=oe;(Ne&&F(new Ne(new ArrayBuffer(1)))!=gt||ae&&F(new ae)!=st||De&&F(De.resolve())!=ut||ze&&F(new ze)!=ct||Oe&&F(new Oe)!=dt)&&(F=function(e){var t=oe(e),r=t==la?e.constructor:void 0,i=r?z(r):"";if(i)switch(i){case sa:return gt;case ua:return st;case ca:return ut;case da:return ct;case ga:return dt}return t});var sc=M.Uint8Array,pa="__lodash_hash_undefined__";function fa(e){return this.__data__.set(e,pa),this}var ma=fa;function ya(e){return this.__data__.has(e)}var ba=ya;function Re(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Et;++t<r;)this.add(e[t])}Re.prototype.add=Re.prototype.push=ma;Re.prototype.has=ba;var pt=U?U.prototype:void 0,uc=pt?pt.valueOf:void 0,ha=Object.prototype,cc=ha.hasOwnProperty,va=Object.prototype,dc=va.hasOwnProperty,gc=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),pc=new RegExp(/[A-Fa-f0-9]{1}/,"g"),fc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function $t(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),o=new Uint8Array(n),a=new Blob([o],{type:r});return URL.createObjectURL(a)}else return e}async function wa(e,t){let r=await $t(e,t);return new Promise((i,n)=>{let o=new Image;o.onload=()=>{i({width:o.width,height:o.height})},o.onerror=n,o.src=r})}async function ka(e,t,r){let i,n=t.block.getFill(e),o=t.block.getSourceSet(n,"fill/image/sourceSet"),[a]=o;if(a==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=a.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return $t(i,t)}function Ia(e){return e!==void 0}var Aa=Ia;function P(e,t){if(typeof e.i18n?.getTranslations!="function"){e.i18n.setTranslations(t);return}let r=Object.keys(t),i=e.i18n.getTranslations(r),n={};for(let o of r){let a=t[o];if(!a)continue;let s=i[o]??{},c={};for(let[l,u]of Object.entries(a))!(l in s)&&u!==void 0&&(c[l]=u);Object.keys(c).length>0&&(n[o]=c)}Object.keys(n).length>0&&e.i18n.setTranslations(n)}function se(e,t){let r=t?.i18n?.getLocale?.()||"en";return{engine:e,cesdk:t,locale:r}}function ue(e,t,r,i,n){if(t?.default!==void 0){let o=t.default;return typeof o!="function"?o:o(r)}return i!==void 0?i:n}var ce=class Mt{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 Mt),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))}},Sa=class jt{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new jt),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 xa(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let o=[],a=l=>{o.push(l)},s=async(l,u,d)=>{if(l>=t.length)return r(u,d);let f=t[l],g=async(p,y)=>s(l+1,p,y),m={...d,addDisposer:a};return f(u,m,g)},c={...n,addDisposer:a};return{result:await s(0,i,c),dispose:async()=>{for(let l=o.length-1;l>=0;l--)try{await o[l]()}catch(u){console.error("Error in disposer:",u)}o.length=0}}}}function Ca({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,o=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-o}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var Ea=Ca;var _e="ly.img.ai.temp";async function $a(e,t){return e.engine.asset.findAllSources().includes(_e)||e.engine.asset.addLocalSource(_e),e.engine.asset.apply(_e,t)}function Ma(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 Tt(){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 ja(e,t=0,r="image/jpeg",i=.8){return new Promise((n,o)=>{try{let a=document.createElement("video");a.crossOrigin="anonymous",a.style.display="none",a.addEventListener("loadedmetadata",()=>{a.currentTime=Math.min(t,a.duration),a.addEventListener("seeked",()=>{let s=document.createElement("canvas");s.width=a.videoWidth,s.height=a.videoHeight;let c=s.getContext("2d");if(!c){document.body.removeChild(a),o(new Error("Failed to create canvas context"));return}c.drawImage(a,0,0,s.width,s.height);try{let l=s.toDataURL(r,i);document.body.removeChild(a),n(l)}catch(l){document.body.removeChild(a),o(new Error(`Failed to create thumbnail: ${l instanceof Error?l.message:String(l)}`))}},{once:!0})}),a.addEventListener("error",()=>{document.body.removeChild(a),o(new Error(`Failed to load video from ${e}`))}),a.src=e,document.body.appendChild(a)}catch(a){o(a)}})}function Ta(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 Ue(e){return e instanceof Error&&e.name==="AbortError"}function _a(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function _t(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let o=e.ui.experimental.getGlobalStateValue(i);o?o!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
1
+ var Ir=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((c,l)=>{let u=e.locale??"en",d="",f=[];l.label!=null&&typeof l.label=="object"&&l.label[u]&&(d=l.label[u]),l.tags!=null&&typeof l.tags=="object"&&l.tags[u]&&(f=l.tags[u]);let g={...l,label:d,tags:f};return this.filterAsset(g,e)&&c.push(g),c},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,o=n+i,a=t.slice(n,o),s=o<t.length?r+1:void 0;return{assets:a,currentPage:r,nextPage:s,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(o=>{o.groups&&Array.isArray(o.groups)&&o.groups.forEach(a=>i.add(a))});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;V(e,o=>{i.add(o)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.oncomplete=()=>{this.engine.asset.assetSourceContentsChanged(this.id)},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=()=>{V(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((o,a)=>{let s=o.meta?.insertedAt||o._insertedAt||Date.now(),c=a.meta?.insertedAt||a._insertedAt||Date.now();return e==="asc"?s-c:c-s}),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,o])=>{let a={id:n,blob:o};i.put(a)}),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 V(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),V(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:o}=t;if(r&&r.trim()!==""){let a=r.trim().toLowerCase().split(" "),s=e.label?.toLowerCase()??"",c=e.tags?.map(l=>l.toLowerCase())??[];if(!a.every(l=>s.includes(l)||c.some(u=>u.includes(l))))return!1}if(i){let a=Array.isArray(i)?i:[i];if(a.length>0&&(!e.tags||!a.every(s=>e.tags?.includes(s))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(a=>e.groups?.includes(a)))||o&&o.length>0&&e.groups&&e.groups.some(a=>o.includes(a)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,o=[...e];return!r||r==="None"||(i?o.sort((a,s)=>{let c,l;return i==="id"?(c=a.id,l=s.id):(c=a.meta?.[i]??null,l=s.meta?.[i]??null),c==null?r==="Ascending"?-1:1:l==null?r==="Ascending"?1:-1:typeof c=="string"&&typeof l=="string"?r==="Ascending"?c.localeCompare(l):l.localeCompare(c):r==="Ascending"?c<l?-1:c>l?1:0:c>l?-1:c<l?1:0}):r==="Descending"&&o.reverse(),n&&o.sort((a,s)=>a.active&&!s.active?-1:!a.active&&s.active?1:0)),o}};function V(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 o=t(e[i],n);typeof o=="string"&&(e[i]=o)}else e[i]=V(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],o=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let a=t(n,o);typeof a=="string"&&(e[i]=a)}else e[i]=V(n,t,o)}return e}var Ar=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(u=>this.cesdk.engine.asset.findAssets(u,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(u=>{u?.assets&&(i=i.concat(u.assets))}),i.sort((u,d)=>{let f=u.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-f});let{page:n,perPage:o}=e,a=n*o,s=a+o,c=i.slice(a,s),l=s<i.length?n+1:void 0;return{assets:c,currentPage:n,nextPage:l,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")}};var Sr=typeof global=="object"&&global&&global.Object===Object&&global,It=Sr,xr=typeof self=="object"&&self&&self.Object===Object&&self,Cr=It||xr||Function("return this")(),M=Cr,Er=M.Symbol,U=Er,At=Object.prototype,$r=At.hasOwnProperty,Mr=At.toString,X=U?U.toStringTag:void 0;function jr(e){var t=$r.call(e,X),r=e[X];try{e[X]=void 0;var i=!0}catch{}var n=Mr.call(e);return i&&(t?e[X]=r:delete e[X]),n}var Tr=jr,_r=Object.prototype,Lr=_r.toString;function Pr(e){return Lr.call(e)}var Nr=Pr,Or="[object Null]",Dr="[object Undefined]",tt=U?U.toStringTag:void 0;function zr(e){return e==null?e===void 0?Dr:Or:tt&&tt in Object(e)?Tr(e):Nr(e)}var oe=zr;function Rr(e){return e!=null&&typeof e=="object"}var Ue=Rr,ec=Array.isArray;function Fr(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var St=Fr,Vr="[object AsyncFunction]",Ur="[object Function]",Br="[object GeneratorFunction]",Gr="[object Proxy]";function qr(e){if(!St(e))return!1;var t=oe(e);return t==Ur||t==Br||t==Vr||t==Gr}var Hr=qr,Zr=M["__core-js_shared__"],je=Zr,rt=function(){var e=/[^.]+$/.exec(je&&je.keys&&je.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Kr(e){return!!rt&&rt in e}var Qr=Kr,Yr=Function.prototype,Wr=Yr.toString;function Jr(e){if(e!=null){try{return Wr.call(e)}catch{}try{return e+""}catch{}}return""}var z=Jr,Xr=/[\\^$.*+?()[\]{}|]/g,ei=/^\[object .+?Constructor\]$/,ti=Function.prototype,ri=Object.prototype,ii=ti.toString,ni=ri.hasOwnProperty,ai=RegExp("^"+ii.call(ni).replace(Xr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function oi(e){if(!St(e)||Qr(e))return!1;var t=Hr(e)?ai:ei;return t.test(z(e))}var li=oi;function si(e,t){return e?.[t]}var ui=si;function ci(e,t){var r=ui(e,t);return li(r)?r:void 0}var B=ci,di=B(M,"WeakMap"),Ne=di;function gi(e,t){return e===t||e!==e&&t!==t}var pi=gi,fi=9007199254740991;function mi(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=fi}var yi=mi,tc=Object.prototype,bi="[object Arguments]";function hi(e){return Ue(e)&&oe(e)==bi}var it=hi,xt=Object.prototype,vi=xt.hasOwnProperty,wi=xt.propertyIsEnumerable,rc=it(function(){return arguments}())?it:function(e){return Ue(e)&&vi.call(e,"callee")&&!wi.call(e,"callee")},Ct=typeof exports=="object"&&exports&&!exports.nodeType&&exports,nt=Ct&&typeof module=="object"&&module&&!module.nodeType&&module,ki=nt&&nt.exports===Ct,at=ki?M.Buffer:void 0,ic=at?at.isBuffer:void 0,Ii="[object Arguments]",Ai="[object Array]",Si="[object Boolean]",xi="[object Date]",Ci="[object Error]",Ei="[object Function]",$i="[object Map]",Mi="[object Number]",ji="[object Object]",Ti="[object RegExp]",_i="[object Set]",Li="[object String]",Pi="[object WeakMap]",Ni="[object ArrayBuffer]",Oi="[object DataView]",Di="[object Float32Array]",zi="[object Float64Array]",Ri="[object Int8Array]",Fi="[object Int16Array]",Vi="[object Int32Array]",Ui="[object Uint8Array]",Bi="[object Uint8ClampedArray]",Gi="[object Uint16Array]",qi="[object Uint32Array]",w={};w[Di]=w[zi]=w[Ri]=w[Fi]=w[Vi]=w[Ui]=w[Bi]=w[Gi]=w[qi]=!0;w[Ii]=w[Ai]=w[Ni]=w[Si]=w[Oi]=w[xi]=w[Ci]=w[Ei]=w[$i]=w[Mi]=w[ji]=w[Ti]=w[_i]=w[Li]=w[Pi]=!1;function Hi(e){return Ue(e)&&yi(e.length)&&!!w[oe(e)]}var Zi=Hi;function Ki(e){return function(t){return e(t)}}var Qi=Ki,Et=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ie=Et&&typeof module=="object"&&module&&!module.nodeType&&module,Yi=ie&&ie.exports===Et,Te=Yi&&It.process,Wi=function(){try{var e=ie&&ie.require&&ie.require("util").types;return e||Te&&Te.binding&&Te.binding("util")}catch{}}(),ot=Wi,lt=ot&&ot.isTypedArray,nc=lt?Qi(lt):Zi,Ji=Object.prototype,ac=Ji.hasOwnProperty;function Xi(e,t){return function(r){return e(t(r))}}var en=Xi,oc=en(Object.keys,Object),tn=Object.prototype,lc=tn.hasOwnProperty,rn=B(Object,"create"),ne=rn;function nn(){this.__data__=ne?ne(null):{},this.size=0}var an=nn;function on(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var ln=on,sn="__lodash_hash_undefined__",un=Object.prototype,cn=un.hasOwnProperty;function dn(e){var t=this.__data__;if(ne){var r=t[e];return r===sn?void 0:r}return cn.call(t,e)?t[e]:void 0}var gn=dn,pn=Object.prototype,fn=pn.hasOwnProperty;function mn(e){var t=this.__data__;return ne?t[e]!==void 0:fn.call(t,e)}var yn=mn,bn="__lodash_hash_undefined__";function hn(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ne&&t===void 0?bn:t,this}var vn=hn;function G(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])}}G.prototype.clear=an;G.prototype.delete=ln;G.prototype.get=gn;G.prototype.has=yn;G.prototype.set=vn;var st=G;function wn(){this.__data__=[],this.size=0}var kn=wn;function In(e,t){for(var r=e.length;r--;)if(pi(e[r][0],t))return r;return-1}var ve=In,An=Array.prototype,Sn=An.splice;function xn(e){var t=this.__data__,r=ve(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Sn.call(t,r,1),--this.size,!0}var Cn=xn;function En(e){var t=this.__data__,r=ve(t,e);return r<0?void 0:t[r][1]}var $n=En;function Mn(e){return ve(this.__data__,e)>-1}var jn=Mn;function Tn(e,t){var r=this.__data__,i=ve(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var _n=Tn;function q(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])}}q.prototype.clear=kn;q.prototype.delete=Cn;q.prototype.get=$n;q.prototype.has=jn;q.prototype.set=_n;var we=q,Ln=B(M,"Map"),ae=Ln;function Pn(){this.size=0,this.__data__={hash:new st,map:new(ae||we),string:new st}}var Nn=Pn;function On(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Dn=On;function zn(e,t){var r=e.__data__;return Dn(t)?r[typeof t=="string"?"string":"hash"]:r.map}var ke=zn;function Rn(e){var t=ke(this,e).delete(e);return this.size-=t?1:0,t}var Fn=Rn;function Vn(e){return ke(this,e).get(e)}var Un=Vn;function Bn(e){return ke(this,e).has(e)}var Gn=Bn;function qn(e,t){var r=ke(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Hn=qn;function H(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])}}H.prototype.clear=Nn;H.prototype.delete=Fn;H.prototype.get=Un;H.prototype.has=Gn;H.prototype.set=Hn;var $t=H;function Zn(){this.__data__=new we,this.size=0}var Kn=Zn;function Qn(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Yn=Qn;function Wn(e){return this.__data__.get(e)}var Jn=Wn;function Xn(e){return this.__data__.has(e)}var ea=Xn,ta=200;function ra(e,t){var r=this.__data__;if(r instanceof we){var i=r.__data__;if(!ae||i.length<ta-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new $t(i)}return r.set(e,t),this.size=r.size,this}var ia=ra;function le(e){var t=this.__data__=new we(e);this.size=t.size}le.prototype.clear=Kn;le.prototype.delete=Yn;le.prototype.get=Jn;le.prototype.has=ea;le.prototype.set=ia;var na=Object.prototype,sc=na.propertyIsEnumerable,aa=B(M,"DataView"),Oe=aa,oa=B(M,"Promise"),De=oa,la=B(M,"Set"),ze=la,ut="[object Map]",sa="[object Object]",ct="[object Promise]",dt="[object Set]",gt="[object WeakMap]",pt="[object DataView]",ua=z(Oe),ca=z(ae),da=z(De),ga=z(ze),pa=z(Ne),F=oe;(Oe&&F(new Oe(new ArrayBuffer(1)))!=pt||ae&&F(new ae)!=ut||De&&F(De.resolve())!=ct||ze&&F(new ze)!=dt||Ne&&F(new Ne)!=gt)&&(F=function(e){var t=oe(e),r=t==sa?e.constructor:void 0,i=r?z(r):"";if(i)switch(i){case ua:return pt;case ca:return ut;case da:return ct;case ga:return dt;case pa:return gt}return t});var uc=M.Uint8Array,fa="__lodash_hash_undefined__";function ma(e){return this.__data__.set(e,fa),this}var ya=ma;function ba(e){return this.__data__.has(e)}var ha=ba;function Re(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new $t;++t<r;)this.add(e[t])}Re.prototype.add=Re.prototype.push=ya;Re.prototype.has=ha;var ft=U?U.prototype:void 0,cc=ft?ft.valueOf:void 0,va=Object.prototype,dc=va.hasOwnProperty,wa=Object.prototype,gc=wa.hasOwnProperty,pc=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),fc=new RegExp(/[A-Fa-f0-9]{1}/,"g"),mc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function Mt(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),o=new Uint8Array(n),a=new Blob([o],{type:r});return URL.createObjectURL(a)}else return e}async function ka(e,t){let r=await Mt(e,t);return new Promise((i,n)=>{let o=new Image;o.onload=()=>{i({width:o.width,height:o.height})},o.onerror=n,o.src=r})}async function Ia(e,t,r){let i,n=t.block.getFill(e),o=t.block.getSourceSet(n,"fill/image/sourceSet"),[a]=o;if(a==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=a.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return Mt(i,t)}function Aa(e){return e!==void 0}var Sa=Aa;function P(e,t){if(typeof e.i18n?.getTranslations!="function"){e.i18n.setTranslations(t);return}let r=Object.keys(t),i=e.i18n.getTranslations(r),n={};for(let o of r){let a=t[o];if(!a)continue;let s=i[o]??{},c={};for(let[l,u]of Object.entries(a))!(l in s)&&u!==void 0&&(c[l]=u);Object.keys(c).length>0&&(n[o]=c)}Object.keys(n).length>0&&e.i18n.setTranslations(n)}function se(e,t){let r=t?.i18n?.getLocale?.()||"en";return{engine:e,cesdk:t,locale:r}}function ue(e,t,r,i,n){if(t?.default!==void 0){let o=t.default;return typeof o!="function"?o:o(r)}return i!==void 0?i:n}var ce=class jt{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 jt),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))}},xa=class Tt{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new Tt),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 Ca(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let o=[],a=l=>{o.push(l)},s=async(l,u,d)=>{if(l>=t.length)return r(u,d);let f=t[l],g=async(p,y)=>s(l+1,p,y),m={...d,addDisposer:a};return f(u,m,g)},c={...n,addDisposer:a};return{result:await s(0,i,c),dispose:async()=>{for(let l=o.length-1;l>=0;l--)try{await o[l]()}catch(u){console.error("Error in disposer:",u)}o.length=0}}}}function Ea({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,o=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-o}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var $a=Ea;var _e="ly.img.ai.temp";async function Ma(e,t){return e.engine.asset.findAllSources().includes(_e)||e.engine.asset.addLocalSource(_e),e.engine.asset.apply(_e,t)}function ja(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 _t(){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 Ta(e,t=0,r="image/jpeg",i=.8){return new Promise((n,o)=>{try{let a=document.createElement("video");a.crossOrigin="anonymous",a.style.display="none",a.addEventListener("loadedmetadata",()=>{a.currentTime=Math.min(t,a.duration),a.addEventListener("seeked",()=>{let s=document.createElement("canvas");s.width=a.videoWidth,s.height=a.videoHeight;let c=s.getContext("2d");if(!c){document.body.removeChild(a),o(new Error("Failed to create canvas context"));return}c.drawImage(a,0,0,s.width,s.height);try{let l=s.toDataURL(r,i);document.body.removeChild(a),n(l)}catch(l){document.body.removeChild(a),o(new Error(`Failed to create thumbnail: ${l instanceof Error?l.message:String(l)}`))}},{once:!0})}),a.addEventListener("error",()=>{document.body.removeChild(a),o(new Error(`Failed to load video from ${e}`))}),a.src=e,document.body.appendChild(a)}catch(a){o(a)}})}function _a(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 Be(e){return e instanceof Error&&e.name==="AbortError"}function La(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function Lt(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let o=e.ui.experimental.getGlobalStateValue(i);o?o!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
2
2
  Plugin "${t}" is using version ${r}, but other AI plugins are using version ${o}.
3
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(o){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",o)}}function La(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 o=t.ui.isPanelOpen(r);n.Button(`${r}.dock.button`,{label:`${r}.dock.label`,isSelected:o,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(a=>{a.startsWith("ly.img.ai.")&&t.ui.closePanel(a),!o&&a==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(a)}),o?t.ui.closePanel(r):t.ui.openPanel(r)}})})}var Lt=La;function Pa(){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 Pt=Pa;function Oa(e,t){let{cesdk:r,provider:i,getInput:n,middlewareOptions:o}=t;o?.defaultPrevented()||(console.error("Generation failed:",e),Na(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:Ma(e)}))}function Na(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",o=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:o}),!0}var ft=Oa,Da="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Be=Da;function za(e,t,r){switch(t){case"image":return Ra(e,r[t]);case"video":return Fa(e,r[t]);case"sticker":return Va(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Ra(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Be,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function Fa(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Be,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function Va(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Be,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var Ua=za;async function Ba(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 Ga(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 qa(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 Ha(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 Za(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Ga(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 qa(e,t,r){let i=t.width,n=t.height,o=await ja(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:o,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function Ha(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 Za(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 Ot=Ba;function Ka(e){switch(e.userFlow){case"placeholder":return Ya(e);case"generation-only":return Qa(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function Qa(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,o=await e.getBlockInput(i);if(_(t,r))return{status:"aborted"};let a=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(_(t,r))return{status:"aborted"};if(a.status!=="success")return a;if(a.type==="async")throw new Error("Async generation is not supported in this context yet.");if(_(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let s=Tt(),c=await Ot(s,n,o,a.output),l={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,l)}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 a}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Ya(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let o=e.kind,a=await e.getBlockInput(n);if(_(t,r))return{status:"aborted"};let s=Tt(),c=Ua(s,o,a);if(i=await $a(t,c),_(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),f=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,f),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 l=await e.generate(n,{blockIds:[i],middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(_(t,r,i))return{status:"aborted"};if(l.status!=="success")return l.middlewareOptions?.defaultPrevented()||i!=null&&t.engine.block.isValid(i)&&(l.status==="aborted"?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),l;if(l.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 u=await Ot(s,o,a,l.output);if(_(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(u,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(u,i),_(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),l}catch(o){return i!=null&&t.engine.block.isValid(i)&&(Ue(o)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:o instanceof Error?o.message:String(o)}}}}function _(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var Wa=Ka;function Ge(e){return`${e}.generating`}function Ja(e){return`${e}.abort`}function Xa(e,t,r,i,n,o,a){let{builder:s,experimental:c}=e,{cesdk:l,includeHistoryLibrary:u=!0}=o,{id:d,output:{abortable:f}}=t,g=c.global(Ja(d),()=>{}),m=c.global(Ge(d),!1),p,y=m.value&&f,v=()=>{y&&(g.value(),m.setValue(!1),g.setValue(()=>{}))},A;if(o.requiredInputs!=null&&o.requiredInputs.length>0){let x=i();A=o.requiredInputs.every(h=>!x.input[h])}let S=c.global(`${d}.confirmationDialogId`,void 0);s.Section(`${d}.generate.section`,{children:()=>{s.Button(`${d}.generate`,{label:["ly.img.plugin-ai-generation-web.generate","common.generate",`panel.${d}.generate`],isLoading:m.value,color:"accent",isDisabled:A,suffix:y?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let x=l.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:h})=>{l.ui.closeDialog(h),S.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:h})=>{v(),l.ui.closeDialog(h),S.setValue(void 0)}}});S.setValue(x)}}:void 0,onClick:async()=>{p=new AbortController;let x=p.signal;await(async()=>{try{m.setValue(!0),g.setValue(()=>{a.debug&&console.log("Aborting generation"),p?.abort()});let h=await Wa({kind:t.kind,generate:r,historyAssetSourceId:o.historyAssetSourceId,userFlow:o.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:x,cesdk:l,debug:a.debug,dryRun:a.dryRun})(i().input);if(h.status==="aborted")return;if(h.status==="error"){ft(h.message,{cesdk:l,provider:t,getInput:i,middlewareOptions:h.middlewareOptions});return}if(h.status==="success"&&h.type==="sync"&&!h.middlewareOptions?.defaultPrevented()){let E=t.output.notification;eo(l,E,()=>({input:i().input,output:h.output}))}}catch(h){if(Ue(h))return;ft(h,{cesdk:l,provider:t,getInput:i})}finally{p=void 0,m.setValue(!1),g.setValue(()=>{}),S.value!=null&&(l.ui.closeDialog(S.value),S.setValue(void 0))}})()}}),t.output.generationHintText!=null&&s.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),u&&o.historyAssetLibraryEntryId!=null&&s.Library(`${d}.history.library`,{entries:[o.historyAssetLibraryEntryId]})}function eo(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",o=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:o,duration:i.duration}),!0}var Nt=Xa;async function to({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:o}=e,{id:a}=t;i.debug&&console.log(`Provider: ${a} (custom)`);let s=r.render;return c=>{let{state:l}=c,u=l(Ge(a),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:f}=s(c,{cesdk:o,isGenerating:u});return Nt(c,t,n,d,f,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var ro=to;function Dt(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 te(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=Dt(e,t.$ref),n={...te(e,i,r)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(n[o]=te(e,t[o],r));return n}if(Array.isArray(t))return t.map(i=>te(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=te(e,t[n],r));return i}return t}function io(e){return te(e,{...e})}function no(e,t=!1){let r=a=>(t&&console.log(`OpenAPI Schema validation failed: ${a}`),!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 a=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!a.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${a.join(", ")}`)}else if(Array.isArray(i.type)){for(let s of i.type)if(typeof s!="string"||!a.includes(s))return r(`Array of types contains invalid value: ${s}. Must be one of ${a.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 a of n)if(i[a]!==void 0){if(!Array.isArray(i[a]))return r(`${a} must be an array, got ${typeof i[a]}`);for(let s=0;s<i[a].length;s++){let c=i[a][s];if(typeof c!="object"||c===null)return r(`Item ${s} in ${a} must be an object, got ${c===null?"null":typeof c}`)}}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 o=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let a of o)if(i[a]!==void 0&&typeof i[a]!="number")return r(`${a} must be a number, got ${typeof i[a]}`);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 a=0;a<i.required.length;a++){let s=i.required[a];if(typeof s!="string")return r(`Item ${a} in required array must be a string, got ${typeof s}`)}}return!0}function ao(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return oo(e,t).forEach(n=>{let o=n,a=r[n]??void 0;i.push({id:o,schema:a})}),i}function oo(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),o=lo(e,t)??n;return r!=null&&typeof r=="function"&&(o=r(o)),[...new Set(o)]}function lo(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 zt=ao;function L(e,t,r,i){let n=`property.${e.id}${i?`.${i}`:""}`,o=[`ly.img.plugin-ai-${r}-generation-web.${t.id}.${n}`,`ly.img.plugin-ai-generation-web.${n}`,`ly.img.plugin-ai-${r}-generation-web.${t.id}.defaults.${n}`,`ly.img.plugin-ai-generation-web.defaults.${n}`];return i==="placeholder"&&o.push("ly.img.plugin-ai-generation-web.fallback.property.placeholder"),o}function Rt(e){let t="x-imgly-enum-labels"in e&&typeof e["x-imgly-enum-labels"]=="object"?e["x-imgly-enum-labels"]:{},r="x-imgly-enum-icons"in e&&typeof e["x-imgly-enum-icons"]=="object"?e["x-imgly-enum-icons"]:{};return{labels:t,icons:r}}function Ft(e,t,r,i,n,o,a,s){if(t.schema==null)if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null){let u={...e,providerConfig:s,config:o};return i.renderCustomProperty[t.id](u,t)}else return;let c=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null){let u={...e,providerConfig:s,config:o};return i.renderCustomProperty[t.id](u,t)}switch(l){case"string":return t.schema.enum!=null?so(e,c,r,i,n,o,a,s):Vt(e,c,r,i,n,o,a,s);case"boolean":return Ut(e,c,r,i,n,o,a,s);case"number":case"integer":return Bt(e,c,r,i,n,o,a,s);case"object":return Fe(e,c,r,i,n,o,a,s);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return uo(e,c,r,i,n,o,a,s);break}default:console.error(`Unsupported property type: ${l}`)}}function Fe(e,t,r,i,n,o,a,s){let c=zt(t.schema??{},i).reduce((l,u)=>{let d=Ft(e,u,r,i,n,o,a,s);return d!=null&&(l[u.id]=d()),l},{});return()=>({id:t.id,type:"object",value:c})}function Vt(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=L(t,r,a,"placeholder"),p=se(u,n.cesdk),y=s?.properties?.[d]??o.properties?.[d],v=ue(d,y,p,t.schema.default,""),A=l(f,v),S=co(t.schema),x=S?.component!=null&&S?.component==="TextArea"?"TextArea":"TextInput",h=m.length>0?m:void 0;return c[x](f,{inputLabel:g,...h&&{placeholder:h},...A}),()=>({id:t.id,type:"string",value:A.value})}function so(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),{labels:m,icons:p}=Rt(t.schema),y=(t.schema.enum??[]).map(E=>({id:E,label:L(t,r,a,E),icon:p[E]})),v=se(u,n.cesdk),A=s?.properties?.[d]??o.properties?.[d],S=ue(d,A,v,t.schema.default,y[0]?.id),x=S!=null?y.find(E=>E.id===S)??y[0]:y[0],h=l(f,x);return c.Select(f,{inputLabel:g,values:y,...h}),()=>({id:t.id,type:"string",value:h.value.id})}function Ut(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=se(u,n.cesdk),p=s?.properties?.[d]??o.properties?.[d],y=!!ue(d,p,m,t.schema.default,!1),v=l(f,y);return c.Checkbox(f,{inputLabel:g,...v}),()=>({id:t.id,type:"boolean",value:v.value})}function Bt(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=t.schema.minimum,p=t.schema.maximum,y=se(u,n.cesdk),v=s?.properties?.[d]??o.properties?.[d],A=t.schema.default;A==null&&(m!=null?A=m:p!=null?A=p:A=0);let S=ue(d,v,y,A,A),x=l(f,S);if(m!=null&&p!=null){let h=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(h=t.schema["x-imgly-step"]),c.Slider(f,{inputLabel:g,min:m,max:p,step:h,...x})}else c.NumberInput(f,{inputLabel:g,min:m,max:p,...x});return()=>({id:t.id,type:"integer",value:x.value})}function uo(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=t.schema.anyOf??[],p=[],y={},v={},{labels:A,icons:S}=Rt(t.schema),x=se(u,n.cesdk),h=s?.properties?.[d]??o.properties?.[d],E={string:Vt,boolean:Ut,integer:Bt,object:Fe},be=(b,$)=>b.$ref?b.$ref.split("/").pop():$.split(".").pop()??$,D=(b,$)=>({id:b,label:L(t,r,a,$),icon:S[$]??S[b]});m.forEach((b,$)=>{let w=`${r.id}.${d}.anyOf[${$}]`;if(b.$ref||b.title){let C=b.$ref?b.$ref.split("/").pop():b.title;y[w]=()=>Fe(e,{id:w,schema:{...b,title:A[C]||C}},r,i,n,o,a,s),p.push(D(w,C))}else if(b.type==="string"&&b.enum)b.enum.forEach(C=>{p.push(D(C,C))});else if(b.type&&E[b.type]){let C=E[b.type];y[w]=()=>C(e,{id:w,schema:{...b,title:b.title}},r,i,n,o,a,s);let Me=be(b,w);p.push(b.type==="string"&&!b.enum?{id:w,label:b.title||Me,icon:b.title&&S[b.title]||S[Me]}:D(w,Me))}});let he=ue(d,h,x,t.schema.default,null),$e=he!=null?p.find(b=>b.id===he)??p[0]:p[0],T=l(f,$e);if(c.Select(f,{inputLabel:g,values:p,...T}),T.value.id in y){let b=y[T.value.id]();v[T.value.id]=b}return()=>{let b=v[T.value.id];return b!=null?{...b(),id:t.id}:{id:t.id,type:"string",value:T.value.id}}}function co(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var go=Ft,po={"ly.img.plugin-ai-generation-web.fallback.property.placeholder":"","ly.img.plugin-ai-generation-web.defaults.property.prompt":"Prompt","ly.img.plugin-ai-generation-web.defaults.property.style":"Style","ly.img.plugin-ai-generation-web.defaults.property.image_size":"Image Size","ly.img.plugin-ai-generation-web.defaults.property.size":"Image Size","ly.img.plugin-ai-generation-web.defaults.property.colors":"Colors","ly.img.plugin-ai-generation-web.defaults.property.background":"Background","ly.img.plugin-ai-generation-web.defaults.property.width":"Width","ly.img.plugin-ai-generation-web.defaults.property.height":"Height","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio":"Aspect Ratio","ly.img.plugin-ai-generation-web.defaults.property.duration":"Duration","ly.img.plugin-ai-generation-web.defaults.property.resolution":"Resolution","ly.img.plugin-ai-generation-web.defaults.property.generate_audio":"Generate Audio","ly.img.plugin-ai-generation-web.defaults.property.voice_id":"Voice","ly.img.plugin-ai-generation-web.defaults.property.speed":"Speed","ly.img.plugin-ai-generation-web.defaults.property.text":"Text","ly.img.plugin-ai-generation-web.defaults.property.duration_seconds":"Duration (seconds)","ly.img.plugin-ai-generation-web.defaults.property.style.type":"Type","ly.img.plugin-ai-generation-web.defaults.property.style.type.image":"Image","ly.img.plugin-ai-generation-web.defaults.property.style.type.vector":"Vector","ly.img.plugin-ai-generation-web.defaults.property.style.type.icon":"Icon","ly.img.plugin-ai-generation-web.defaults.property.image_size.square":"Square","ly.img.plugin-ai-generation-web.defaults.property.image_size.portrait":"Portrait","ly.img.plugin-ai-generation-web.defaults.property.image_size.landscape":"Landscape","ly.img.plugin-ai-generation-web.defaults.property.background.auto":"Auto","ly.img.plugin-ai-generation-web.defaults.property.background.transparent":"Transparent","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.1:1":"1:1 (Square)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.16:9":"16:9 (Widescreen)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.9:16":"9:16 (Vertical)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.4:3":"4:3","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.3:4":"3:4","ly.img.plugin-ai-generation-web.defaults.property.resolution.720p":"720p HD","ly.img.plugin-ai-generation-web.defaults.property.resolution.1080p":"1080p Full HD"};function mt(e){return e.replace(/_/g," ").replace(/\b3d\b/gi,"3D").replace(/\b2d\b/gi,"2D").replace(/\b\w/g,t=>t.toUpperCase())}function yt(e,t,r,i){let n={},o=(l,u)=>`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${l}${u?`.${u}`:""}`,a=l=>"x-imgly-enum-labels"in l&&typeof l["x-imgly-enum-labels"]=="object"?l["x-imgly-enum-labels"]:{},s=(l,u,d)=>{l.forEach(f=>{let g=String(f),m=d[g]||mt(g);n[o(u,g)]=m})};e.forEach(l=>{if(l.schema?.title&&(n[o(l.id)]=l.schema.title),l.schema?.enum){let u=a(l.schema);s(l.schema.enum,l.id,u)}if(l.schema?.anyOf&&Array.isArray(l.schema.anyOf)){let u=a(l.schema);l.schema.anyOf.forEach(d=>{let f=d;if(f.enum&&Array.isArray(f.enum))s(f.enum,l.id,u);else if(f.$ref){let g=f.$ref.split("/").pop();g&&u[g]&&(n[o(l.id,g)]=u[g])}else if(f.title){let g=f.title,m=u[g]||mt(g);n[o(l.id,g)]=m}})}});let c={...po,...n};Object.keys(c).length>0&&P(r.cesdk,{en:c})}function bt(e){return typeof e.document=="function"?e.document():e.document}function ht(e,t,r){let i=io(e),n=Dt(i,t.inputReference);if(!no(n,r))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let o=n,a=zt(o,t);return{inputSchema:o,properties:a}}function vt(e,t,r,{options:i,provider:n,config:o,providerConfig:a},s){let{id:c}=n;return l=>{let{builder:u}=l,d=[];u.Section(`${c}.schema.section`,{children:()=>{t.forEach(p=>{let y=go(l,p,n,r,i,o,n.kind,a);y!=null&&(Array.isArray(y)?d.push(...y):d.push(y))})}});let f=d.map(p=>p()),g=p=>p.type==="object"?Object.entries(p.value).reduce((y,[v,A])=>(y[v]=g(A),y),{}):p.value,m=f.reduce((p,y)=>(p[y.id]=g(y),p),{});Nt(l,n,s,()=>({input:m}),()=>r.getBlockInput(m),{...i,requiredInputs:e.required,createPlaceholderBlock:r.userFlow==="placeholder"},o)}}async function fo(e,t){let{options:r,provider:i,panelInput:n,config:o}=e,{id:a}=i;if(n==null)return;let s=n;o.debug&&console.log(`Provider: ${a} (schema-based)`);let c=bt(s);if(!(c instanceof Promise)){let{inputSchema:g,properties:m}=ht(c,s,o.debug);return yt(m,i,r,i.kind),vt(g,m,s,e,t)}let l=null,u=null,d=`${a}.schema.loading`;function f(){l=null,u=null,r.cesdk.ui.experimental.setGlobalStateValue(d,!0),Promise.resolve(bt(s)).then(g=>{let{inputSchema:m,properties:p}=ht(g,s,o.debug);yt(p,i,r,i.kind),u=vt(m,p,s,e,t)}).catch(g=>{l=g instanceof Error?g:new Error(String(g))}).finally(()=>{r.cesdk.ui.experimental.setGlobalStateValue(d,!1)})}return f(),g=>{let{builder:m}=g;if(u!=null){u(g);return}if(l!=null){m.Section(`${a}.schema.error`,{children:()=>{m.Text(`${a}.schema.error.text`,{content:`Failed to load schema: ${l.message}`}),m.Button(`${a}.schema.error.retry`,{label:"Retry",onClick:()=>{f()}})}});return}m.Section(`${a}.schema.loading`,{children:()=>{m.Button(`${a}.schema.loading.indicator`,{label:"Loading...",isLoading:!0,isDisabled:!0})}})}}var mo=fo;async function yo(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return ro(e,t);case"schema":return mo(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var bo=yo;function ho(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 o(){let a=`${t.id}.history`;for(;n.includes(a);)a+=`-${Math.random().toString(36).substring(2,6)}`;return a}if(i==="@imgly/local"){let a=o();return r.asset.addLocalSource(a),a}if(i==="@imgly/indexedDB"){let a=o();return r.asset.addSource(new kr(a,r)),a}return i}var vo=ho;function wo(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var ko=wo,Le="@imgly/plugin-ai-generation",Io=`
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(o){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",o)}}function Pa(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 o=t.ui.isPanelOpen(r);n.Button(`${r}.dock.button`,{label:`${r}.dock.label`,isSelected:o,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(a=>{a.startsWith("ly.img.ai.")&&t.ui.closePanel(a),!o&&a==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(a)}),o?t.ui.closePanel(r):t.ui.openPanel(r)}})})}var Pt=Pa;function Na(){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 Nt=Na;function Oa(e,t){let{cesdk:r,provider:i,getInput:n,middlewareOptions:o}=t;o?.defaultPrevented()||(console.error("Generation failed:",e),Da(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:ja(e)}))}function Da(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",o=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:o}),!0}var mt=Oa,za="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Ge=za;function Ra(e,t,r){switch(t){case"image":return Fa(e,r[t]);case"video":return Va(e,r[t]);case"sticker":return Ua(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Fa(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ge,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function Va(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Ge,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function Ua(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ge,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var Ba=Ra;async function Ga(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 qa(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 Ha(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 Za(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 Ka(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function qa(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 Ha(e,t,r){let i=t.width,n=t.height,o=await Ta(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:o,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function Za(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 Ka(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 Ot=Ga;function Qa(e){switch(e.userFlow){case"placeholder":return Wa(e);case"generation-only":return Ya(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function Ya(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,o=await e.getBlockInput(i);if(_(t,r))return{status:"aborted"};let a=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(_(t,r))return{status:"aborted"};if(a.status!=="success")return a;if(a.type==="async")throw new Error("Async generation is not supported in this context yet.");if(_(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let s=_t(),c=await Ot(s,n,o,a.output),l={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,l)}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 a}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Wa(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let o=e.kind,a=await e.getBlockInput(n);if(_(t,r))return{status:"aborted"};let s=_t(),c=Ba(s,o,a);if(i=await Ma(t,c),_(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),f=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,f),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 l=await e.generate(n,{blockIds:[i],middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(_(t,r,i))return{status:"aborted"};if(l.status!=="success")return l.middlewareOptions?.defaultPrevented()||i!=null&&t.engine.block.isValid(i)&&(l.status==="aborted"?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),l;if(l.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 u=await Ot(s,o,a,l.output);if(_(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(u,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(u,i),_(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),l}catch(o){return i!=null&&t.engine.block.isValid(i)&&(Be(o)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:o instanceof Error?o.message:String(o)}}}}function _(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var Ja=Qa;function qe(e){return`${e}.generating`}function Xa(e){return`${e}.abort`}function eo(e,t,r,i,n,o,a){let{builder:s,experimental:c}=e,{cesdk:l,includeHistoryLibrary:u=!0}=o,{id:d,output:{abortable:f}}=t,g=c.global(Xa(d),()=>{}),m=c.global(qe(d),!1),p,y=m.value&&f,v=()=>{y&&(g.value(),m.setValue(!1),g.setValue(()=>{}))},I;if(o.requiredInputs!=null&&o.requiredInputs.length>0){let x=i();I=o.requiredInputs.every(h=>!x.input[h])}let S=c.global(`${d}.confirmationDialogId`,void 0);s.Section(`${d}.generate.section`,{children:()=>{s.Button(`${d}.generate`,{label:["ly.img.plugin-ai-generation-web.generate","common.generate",`panel.${d}.generate`],isLoading:m.value,color:"accent",isDisabled:I,suffix:y?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let x=l.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:h})=>{l.ui.closeDialog(h),S.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:h})=>{v(),l.ui.closeDialog(h),S.setValue(void 0)}}});S.setValue(x)}}:void 0,onClick:async()=>{p=new AbortController;let x=p.signal;await(async()=>{try{m.setValue(!0),g.setValue(()=>{a.debug&&console.log("Aborting generation"),p?.abort()});let h=await Ja({kind:t.kind,generate:r,historyAssetSourceId:o.historyAssetSourceId,userFlow:o.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:x,cesdk:l,debug:a.debug,dryRun:a.dryRun})(i().input);if(h.status==="aborted")return;if(h.status==="error"){mt(h.message,{cesdk:l,provider:t,getInput:i,middlewareOptions:h.middlewareOptions});return}if(h.status==="success"&&h.type==="sync"&&!h.middlewareOptions?.defaultPrevented()){let E=t.output.notification;to(l,E,()=>({input:i().input,output:h.output}))}}catch(h){if(Be(h))return;mt(h,{cesdk:l,provider:t,getInput:i})}finally{p=void 0,m.setValue(!1),g.setValue(()=>{}),S.value!=null&&(l.ui.closeDialog(S.value),S.setValue(void 0))}})()}}),t.output.generationHintText!=null&&s.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),u&&o.historyAssetLibraryEntryId!=null&&s.Library(`${d}.history.library`,{entries:[o.historyAssetLibraryEntryId]})}function to(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",o=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:o,duration:i.duration}),!0}var Dt=eo;function Fe(e){let{name:t}=e;return(typeof t=="function"?t():t)??e.id}async function ro({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:o}=e,{id:a}=t;i.debug&&console.log(`Provider: ${a} (custom)`);let s=r.render;return c=>{let{state:l}=c,u=l(qe(a),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:f}=s(c,{cesdk:o,isGenerating:u});return Dt(c,t,n,d,f,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var io=ro;function zt(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 te(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=zt(e,t.$ref),n={...te(e,i,r)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(n[o]=te(e,t[o],r));return n}if(Array.isArray(t))return t.map(i=>te(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=te(e,t[n],r));return i}return t}function no(e){return te(e,{...e})}function ao(e,t=!1){let r=a=>(t&&console.log(`OpenAPI Schema validation failed: ${a}`),!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 a=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!a.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${a.join(", ")}`)}else if(Array.isArray(i.type)){for(let s of i.type)if(typeof s!="string"||!a.includes(s))return r(`Array of types contains invalid value: ${s}. Must be one of ${a.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 a of n)if(i[a]!==void 0){if(!Array.isArray(i[a]))return r(`${a} must be an array, got ${typeof i[a]}`);for(let s=0;s<i[a].length;s++){let c=i[a][s];if(typeof c!="object"||c===null)return r(`Item ${s} in ${a} must be an object, got ${c===null?"null":typeof c}`)}}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 o=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let a of o)if(i[a]!==void 0&&typeof i[a]!="number")return r(`${a} must be a number, got ${typeof i[a]}`);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 a=0;a<i.required.length;a++){let s=i.required[a];if(typeof s!="string")return r(`Item ${a} in required array must be a string, got ${typeof s}`)}}return!0}function oo(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return lo(e,t).forEach(n=>{let o=n,a=r[n]??void 0;i.push({id:o,schema:a})}),i}function lo(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),o=so(e,t)??n;return r!=null&&typeof r=="function"&&(o=r(o)),[...new Set(o)]}function so(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 Rt=oo;function L(e,t,r,i){let n=`property.${e.id}${i?`.${i}`:""}`,o=[`ly.img.plugin-ai-${r}-generation-web.${t.id}.${n}`,`ly.img.plugin-ai-generation-web.${n}`,`ly.img.plugin-ai-${r}-generation-web.${t.id}.defaults.${n}`,`ly.img.plugin-ai-generation-web.defaults.${n}`];return i==="placeholder"&&o.push("ly.img.plugin-ai-generation-web.fallback.property.placeholder"),o}function Ft(e){let t="x-imgly-enum-labels"in e&&typeof e["x-imgly-enum-labels"]=="object"?e["x-imgly-enum-labels"]:{},r="x-imgly-enum-icons"in e&&typeof e["x-imgly-enum-icons"]=="object"?e["x-imgly-enum-icons"]:{};return{labels:t,icons:r}}function Vt(e,t,r,i,n,o,a,s){if(t.schema==null)if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null){let u={...e,providerConfig:s,config:o};return i.renderCustomProperty[t.id](u,t)}else return;let c=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null){let u={...e,providerConfig:s,config:o};return i.renderCustomProperty[t.id](u,t)}switch(l){case"string":return t.schema.enum!=null?uo(e,c,r,i,n,o,a,s):Ut(e,c,r,i,n,o,a,s);case"boolean":return Bt(e,c,r,i,n,o,a,s);case"number":case"integer":return Gt(e,c,r,i,n,o,a,s);case"object":return Ve(e,c,r,i,n,o,a,s);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return co(e,c,r,i,n,o,a,s);break}default:console.error(`Unsupported property type: ${l}`)}}function Ve(e,t,r,i,n,o,a,s){let c=Rt(t.schema??{},i).reduce((l,u)=>{let d=Vt(e,u,r,i,n,o,a,s);return d!=null&&(l[u.id]=d()),l},{});return()=>({id:t.id,type:"object",value:c})}function Ut(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=L(t,r,a,"placeholder"),p=se(u,n.cesdk),y=s?.properties?.[d]??o.properties?.[d],v=ue(d,y,p,t.schema.default,""),I=l(f,v),S=go(t.schema),x=S?.component!=null&&S?.component==="TextArea"?"TextArea":"TextInput",h=m.length>0?m:void 0;return c[x](f,{inputLabel:g,...h&&{placeholder:h},...I}),()=>({id:t.id,type:"string",value:I.value})}function uo(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),{labels:m,icons:p}=Ft(t.schema),y=(t.schema.enum??[]).map(E=>({id:E,label:L(t,r,a,E),icon:p[E]})),v=se(u,n.cesdk),I=s?.properties?.[d]??o.properties?.[d],S=ue(d,I,v,t.schema.default,y[0]?.id),x=S!=null?y.find(E=>E.id===S)??y[0]:y[0],h=l(f,x);return c.Select(f,{inputLabel:g,values:y,...h}),()=>({id:t.id,type:"string",value:h.value.id})}function Bt(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=se(u,n.cesdk),p=s?.properties?.[d]??o.properties?.[d],y=!!ue(d,p,m,t.schema.default,!1),v=l(f,y);return c.Checkbox(f,{inputLabel:g,...v}),()=>({id:t.id,type:"boolean",value:v.value})}function Gt(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=t.schema.minimum,p=t.schema.maximum,y=se(u,n.cesdk),v=s?.properties?.[d]??o.properties?.[d],I=t.schema.default;I==null&&(m!=null?I=m:p!=null?I=p:I=0);let S=ue(d,v,y,I,I),x=l(f,S);if(m!=null&&p!=null){let h=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(h=t.schema["x-imgly-step"]),c.Slider(f,{inputLabel:g,min:m,max:p,step:h,...x})}else c.NumberInput(f,{inputLabel:g,min:m,max:p,...x});return()=>({id:t.id,type:"integer",value:x.value})}function co(e,t,r,i,n,o,a,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=L(t,r,a),m=t.schema.anyOf??[],p=[],y={},v={},{labels:I,icons:S}=Ft(t.schema),x=se(u,n.cesdk),h=s?.properties?.[d]??o.properties?.[d],E={string:Ut,boolean:Bt,integer:Gt,object:Ve},be=(b,$)=>b.$ref?b.$ref.split("/").pop():$.split(".").pop()??$,D=(b,$)=>({id:b,label:L(t,r,a,$),icon:S[$]??S[b]});m.forEach((b,$)=>{let A=`${r.id}.${d}.anyOf[${$}]`;if(b.$ref||b.title){let C=b.$ref?b.$ref.split("/").pop():b.title;y[A]=()=>Ve(e,{id:A,schema:{...b,title:I[C]||C}},r,i,n,o,a,s),p.push(D(A,C))}else if(b.type==="string"&&b.enum)b.enum.forEach(C=>{p.push(D(C,C))});else if(b.type&&E[b.type]){let C=E[b.type];y[A]=()=>C(e,{id:A,schema:{...b,title:b.title}},r,i,n,o,a,s);let Me=be(b,A);p.push(b.type==="string"&&!b.enum?{id:A,label:b.title||Me,icon:b.title&&S[b.title]||S[Me]}:D(A,Me))}});let he=ue(d,h,x,t.schema.default,null),$e=he!=null?p.find(b=>b.id===he)??p[0]:p[0],T=l(f,$e);if(c.Select(f,{inputLabel:g,values:p,...T}),T.value.id in y){let b=y[T.value.id]();v[T.value.id]=b}return()=>{let b=v[T.value.id];return b!=null?{...b(),id:t.id}:{id:t.id,type:"string",value:T.value.id}}}function go(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var po=Vt,fo={"ly.img.plugin-ai-generation-web.fallback.property.placeholder":"","ly.img.plugin-ai-generation-web.defaults.property.prompt":"Prompt","ly.img.plugin-ai-generation-web.defaults.property.style":"Style","ly.img.plugin-ai-generation-web.defaults.property.image_size":"Image Size","ly.img.plugin-ai-generation-web.defaults.property.size":"Image Size","ly.img.plugin-ai-generation-web.defaults.property.colors":"Colors","ly.img.plugin-ai-generation-web.defaults.property.background":"Background","ly.img.plugin-ai-generation-web.defaults.property.width":"Width","ly.img.plugin-ai-generation-web.defaults.property.height":"Height","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio":"Aspect Ratio","ly.img.plugin-ai-generation-web.defaults.property.duration":"Duration","ly.img.plugin-ai-generation-web.defaults.property.resolution":"Resolution","ly.img.plugin-ai-generation-web.defaults.property.generate_audio":"Generate Audio","ly.img.plugin-ai-generation-web.defaults.property.voice_id":"Voice","ly.img.plugin-ai-generation-web.defaults.property.speed":"Speed","ly.img.plugin-ai-generation-web.defaults.property.text":"Text","ly.img.plugin-ai-generation-web.defaults.property.duration_seconds":"Duration (seconds)","ly.img.plugin-ai-generation-web.defaults.property.style.type":"Type","ly.img.plugin-ai-generation-web.defaults.property.style.type.image":"Image","ly.img.plugin-ai-generation-web.defaults.property.style.type.vector":"Vector","ly.img.plugin-ai-generation-web.defaults.property.style.type.icon":"Icon","ly.img.plugin-ai-generation-web.defaults.property.image_size.square":"Square","ly.img.plugin-ai-generation-web.defaults.property.image_size.portrait":"Portrait","ly.img.plugin-ai-generation-web.defaults.property.image_size.landscape":"Landscape","ly.img.plugin-ai-generation-web.defaults.property.background.auto":"Auto","ly.img.plugin-ai-generation-web.defaults.property.background.transparent":"Transparent","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.1:1":"1:1 (Square)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.16:9":"16:9 (Widescreen)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.9:16":"9:16 (Vertical)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.4:3":"4:3","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.3:4":"3:4","ly.img.plugin-ai-generation-web.defaults.property.resolution.720p":"720p HD","ly.img.plugin-ai-generation-web.defaults.property.resolution.1080p":"1080p Full HD"};function yt(e){return e.replace(/_/g," ").replace(/\b3d\b/gi,"3D").replace(/\b2d\b/gi,"2D").replace(/\b\w/g,t=>t.toUpperCase())}function bt(e,t,r,i){let n={},o=(l,u)=>`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${l}${u?`.${u}`:""}`,a=l=>"x-imgly-enum-labels"in l&&typeof l["x-imgly-enum-labels"]=="object"?l["x-imgly-enum-labels"]:{},s=(l,u,d)=>{l.forEach(f=>{let g=String(f),m=d[g]||yt(g);n[o(u,g)]=m})};e.forEach(l=>{if(l.schema?.title&&(n[o(l.id)]=l.schema.title),l.schema?.enum){let u=a(l.schema);s(l.schema.enum,l.id,u)}if(l.schema?.anyOf&&Array.isArray(l.schema.anyOf)){let u=a(l.schema);l.schema.anyOf.forEach(d=>{let f=d;if(f.enum&&Array.isArray(f.enum))s(f.enum,l.id,u);else if(f.$ref){let g=f.$ref.split("/").pop();g&&u[g]&&(n[o(l.id,g)]=u[g])}else if(f.title){let g=f.title,m=u[g]||yt(g);n[o(l.id,g)]=m}})}});let c={...fo,...n};Object.keys(c).length>0&&P(r.cesdk,{en:c})}function ht(e){return typeof e.document=="function"?e.document():e.document}function vt(e,t,r){let i=no(e),n=zt(i,t.inputReference);if(!ao(n,r))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let o=n,a=Rt(o,t);return{inputSchema:o,properties:a}}function wt(e,t,r,{options:i,provider:n,config:o,providerConfig:a},s){let{id:c}=n;return l=>{let{builder:u}=l,d=[];u.Section(`${c}.schema.section`,{children:()=>{t.forEach(p=>{let y=po(l,p,n,r,i,o,n.kind,a);y!=null&&(Array.isArray(y)?d.push(...y):d.push(y))})}});let f=d.map(p=>p()),g=p=>p.type==="object"?Object.entries(p.value).reduce((y,[v,I])=>(y[v]=g(I),y),{}):p.value,m=f.reduce((p,y)=>(p[y.id]=g(y),p),{});Dt(l,n,s,()=>({input:m}),()=>r.getBlockInput(m),{...i,requiredInputs:e.required,createPlaceholderBlock:r.userFlow==="placeholder"},o)}}async function mo(e,t){let{options:r,provider:i,panelInput:n,config:o}=e,{id:a}=i;if(n==null)return;let s=n;o.debug&&console.log(`Provider: ${a} (schema-based)`);let c=ht(s);if(!(c instanceof Promise)){let{inputSchema:g,properties:m}=vt(c,s,o.debug);return bt(m,i,r,i.kind),wt(g,m,s,e,t)}let l=null,u=null,d=`${a}.schema.loading`;function f(){l=null,u=null,r.cesdk.ui.experimental.setGlobalStateValue(d,!0),Promise.resolve(ht(s)).then(g=>{let{inputSchema:m,properties:p}=vt(g,s,o.debug);bt(p,i,r,i.kind),u=wt(m,p,s,e,t)}).catch(g=>{l=g instanceof Error?g:new Error(String(g))}).finally(()=>{r.cesdk.ui.experimental.setGlobalStateValue(d,!1)})}return f(),g=>{let{builder:m}=g;if(u!=null){u(g);return}if(l!=null){m.Section(`${a}.schema.error`,{children:()=>{m.Text(`${a}.schema.error.title`,{content:"ly.img.plugin-ai-generation-web.schema.error.title"}),m.Text(`${a}.schema.error.details`,{content:l.message}),m.Button(`${a}.schema.error.retry`,{label:"ly.img.plugin-ai-generation-web.schema.error.retry",onClick:()=>{f()}})}});return}m.Section(`${a}.schema.loading`,{children:()=>{m.Button(`${a}.schema.loading.indicator`,{label:"ly.img.plugin-ai-generation-web.schema.loading.label",isLoading:!0,isDisabled:!0})}})}}var yo=mo;async function bo(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return io(e,t);case"schema":return yo(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var ho=bo;function vo(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 o(){let a=`${t.id}.history`;for(;n.includes(a);)a+=`-${Math.random().toString(36).substring(2,6)}`;return a}if(i==="@imgly/local"){let a=o();return r.asset.addLocalSource(a),a}if(i==="@imgly/indexedDB"){let a=o();return r.asset.addSource(new Ir(a,r)),a}return i}var wo=vo;function ko(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var Io=ko,Le="@imgly/plugin-ai-generation",Ao=`
5
5
  <svg>
6
6
  <symbol
7
7
  fill="none"
@@ -62,8 +62,8 @@ Consider updating all AI plugins to the same version for optimal compatibility.`
62
62
 
63
63
  </symbol>
64
64
  </svg>
65
- `,Ao=Io;function So(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 Gt(2e3),await xo(t,e,r)):i(t,r)}async function xo(e,t,r){switch(t.kind){case"image":return Co(e,t,r);case"video":return Eo(e,t,r);case"text":return $o(e,t,r);case"audio":return jo(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function Co(e,t,{engine:r}){let i,n,o=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",a=o.match(/(\d+)x(\d+)/);if(a!=null)i=parseInt(a[1],10),n=parseInt(a[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[s]=t.blockIds,c=await ka(s,r),l=await wa(c,r);i=l.width,n=l.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${o.replace(" ","+").replace(`
66
- `,"+")}`}}async function Eo(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function $o(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[a]=t.blockIds;r.engine.block.isValid(a)&&(i=r.engine.block.getString(a,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let a=e.prompt,s=a.match(/text:\s*"([^"]+)"/i)||a.match(/content:\s*"([^"]+)"/i)||a.match(/"([^"]+)"/);s&&s[1]&&(i=s[1])}let n=i.length||50,o="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")o=ee(n,"translation");else if("type"in e&&typeof e.type=="string"){let a=e.type;o=ee(n,a)}else"customPrompt"in e?o=ee(n,"custom"):o=ee(n,"improved");else o=ee(n,"generated");return Mo(o,r.abortSignal)}async function*Mo(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 Gt(100)}return{kind:"text",text:e}}function ee(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,o={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."},a=o[t]||o.generated,s="";if(n<=a.length)s=a.substring(0,n);else{s=a;let c=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],l=0;for(;s.length<n;){let u=c[l%c.length];if(s.length+u.length<=n)s+=u;else{s+=u.substring(0,n-s.length);break}l++}}return r+s}async function jo(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:To(220,i),duration:i,thumbnailUrl:void 0}}function To(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 _o(i,44100)}function _o(e,t){let r=e.length,i=2,n=1,o=n*i,a=t*o,s=r*i,c=44+s,l=new ArrayBuffer(c),u=new DataView(l),d=(p,y)=>{for(let v=0;v<y.length;v++)u.setUint8(p+v,y.charCodeAt(v))};d(0,"RIFF"),u.setUint32(4,c-8,!0),d(8,"WAVE"),d(12,"fmt "),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,n,!0),u.setUint32(24,t,!0),u.setUint32(28,a,!0),u.setUint16(32,o,!0),u.setUint16(34,16,!0),d(36,"data"),u.setUint32(40,s,!0);let f=44;for(let p=0;p<r;p++){let y=Math.max(-1,Math.min(1,e[p])),v=Math.round(y*32767);u.setInt16(f,v,!0),f+=2}let g=new Uint8Array(l),m="";for(let p=0;p<g.length;p++)m+=String.fromCharCode(g[p]);return`data:audio/wav;base64,${btoa(m)}`}async function Gt(e){return new Promise(t=>{setTimeout(t,e)})}var Lo=So,Po="USER_CANCEL";function Oo(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=xa([...e.provider.output.middleware??[],...r?.middlewares??[],Ea({enable:r?.debug}),Lo({enable:r?.dryRun,kind:e.provider.kind})]),n={prevented:!1},o={blockIds:r?.blockIds,abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk,preventDefault:()=>{n.prevented=!0},defaultPrevented:()=>n.prevented};try{let{result:a}=await i(e.provider.output.generate)(t,o);return r?.abortSignal?.aborted?{status:"aborted",middlewareOptions:o}:a instanceof Error?{status:"error",message:a.message,middlewareOptions:o}:a==null?{status:"error",message:"No output generated",middlewareOptions:o}:Ta(a)?{status:"success",type:"async",output:a,middlewareOptions:o}:{status:"success",type:"sync",output:a,middlewareOptions:o}}catch(a){return Ue(a)?{status:"aborted",message:a.message,middlewareOptions:o}:a===Po?{status:"aborted",message:a,middlewareOptions:o}:{status:"error",message:a instanceof Error?a.message:String(a),middlewareOptions:o}}}}var No=Oo;async function Do(e,t,r,i){let n={...i,provider:t},o={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n,providerConfig:t.configuration};if(await t.initialize?.({...r,engine:r.cesdk.engine}),t.input?.quickActions?.supported){let d=t.kind,f=ce.get();Object.keys(t.input.quickActions.supported).forEach(g=>{if(!f.getBy({id:g,type:"quick"})[0]){let m=`ly.img.plugin-ai-${d}-generation-web.quickAction.${g}`;r.cesdk.feature.enable(m,!0)}})}let a=vo(o),s=ko(o,a);o.options.historyAssetSourceId=a,o.options.historyAssetLibraryEntryId=s;let c=No({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),l=await bo(o,c);_a(r.cesdk,"@imgly/plugin-ai-generation",Ao);let u={provider:t,panel:{builderRenderFunction:l},history:{assetSourceId:a,assetLibraryEntryId:s},generate:c};return Sa.get().register(u),u}var Pe=Do;function zo(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 o=new Ir(n,r,i);return r.engine.asset.addSource(o),o.id}var Ro=zo;function re(e,t){return[`ly.img.plugin-ai-${e}-generation-web.${t}`,`ly.img.plugin-ai-generation-web.${t}`,`ly.img.plugin-ai-generation-web.defaults.${t}`]}async function Fo(e,t,r,i){let{cesdk:n}=r;P(n,{en:{"ly.img.plugin-ai-generation-web.generate":"Generate","ly.img.plugin-ai-generation-web.defaults.fromType.label":"Input","ly.img.plugin-ai-generation-web.defaults.providerSelect.label":"Provider","ly.img.plugin-ai-generation-web.defaults.fromText.label":"Text","ly.img.plugin-ai-generation-web.defaults.fromImage.label":"Image"}});let o,a=[];if(i.debug&&console.groupCollapsed(`Initializing ${e} generation providers`),Array.isArray(t)){let l=await Promise.all(t.map(u=>Pe(e,u,r,i)));a.push(...l),o=Uo({kind:e,prefix:e,providerInitializationResults:a,cesdk:n})}else{let l=await Promise.all(t.fromText.map(d=>Pe(e,d,r,i)));a.push(...l);let u=await Promise.all(t.fromImage.map(d=>Pe(e,d,r,i)));a.push(...u),o=Vo({kind:e,prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u,cesdk:n})}i.debug&&console.groupEnd();let s=Ro({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(l=>l.history?.assetSourceId).filter(Aa)}),c;return s!=null&&(c=s,r.cesdk.ui.addAssetLibraryEntry({id:c,sourceIds:[s],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"})),{panel:{builderRenderFunction:o},history:{assetSourceId:s,assetLibraryEntryId:c},providerInitializationResults:a}}function Vo({kind:e,prefix:t,initializedFromTextProviders:r,initializedFromImageProviders:i,cesdk:n}){let o=r.length>0&&i.length>0;return a=>{let{builder:s,experimental:c,engine:l}=a,u=`ly.img.plugin-ai-${e}-generation-web.fromText`,d=n.feature.isEnabled(u,{engine:l}),f=`ly.img.plugin-ai-${e}-generation-web.fromImage`,g=n.feature.isEnabled(f,{engine:l}),m;d&&r.length>0&&(!g||i.length===0)?m="fromText":g&&i.length>0&&(!d||r.length===0)?m="fromImage":d&&g&&o&&(m="fromText");let p=c.global(`${t}.fromType`,m),y=[];p.value==="fromText"?y.push(...r):p.value==="fromImage"?y.push(...i):y.push(...r,...i);let v=r.map(({provider:w,panel:C})=>({id:w.id,label:w.name??w.id,builderRenderFunction:C?.builderRenderFunction})),A=i.map(({provider:w,panel:C})=>({id:w.id,label:w.name??w.id,builderRenderFunction:C?.builderRenderFunction})),S=a.experimental.global(`${t}.selectedProvider.fromText`,v[0]?.id),x=a.experimental.global(`${t}.selectedProvider.fromImage`,A[0]?.id),h=v.find(w=>w.id===S.value)??v[0],E=A.find(w=>w.id===x.value)??A[0],be=p.value==="fromText"?S:p.value==="fromImage"?x:void 0,D=p.value==="fromText"?h:p.value==="fromImage"?E:void 0,he=`ly.img.plugin-ai-${e}-generation-web.providerSelect`,$e=n.feature.isEnabled(he,{engine:l});if(!d&&!g){s.Section(`${t}.noInputWarning.section`,{children:()=>{s.Text(`${t}.noInputWarning.text`,{content:"No input types are enabled. Please enable at least one input type (text or image) via the Feature API."})}});return}let T=d&&g&&r.length>0&&i.length>0,b=o&&T,$=y.length>1&&$e;if((b||$)&&s.Section(`${t}.providerSelection.section`,{children:()=>{if(b&&s.ButtonGroup(`${t}.fromType.buttonGroup`,{inputLabel:re(e,"fromType.label"),children:()=>{d&&r.length>0&&s.Button(`${t}.fromType.buttonGroup.fromText`,{label:re(e,"fromText.label"),icon:p.value!=="fromText"&&wt(r,a)?"@imgly/LoadingSpinner":void 0,isActive:p.value==="fromText",onClick:()=>{p.setValue("fromText")}}),g&&i.length>0&&s.Button(`${t}.fromType.buttonGroup.fromImage`,{label:re(e,"fromImage.label"),icon:p.value!=="fromImage"&&wt(i,a)?"@imgly/LoadingSpinner":void 0,isActive:p.value==="fromImage",onClick:()=>{p.setValue("fromImage")}})}}),$){let w=p.value==="fromText"?v:p.value==="fromImage"?A:[...v,...A];be!=null&&D!=null&&s.Select(`${t}.providerSelect.select`,{inputLabel:re(e,"providerSelect.label"),values:w,value:D,setValue:C=>{be.setValue(C.id)}})}}}),y.length>1)D?.builderRenderFunction?.(a);else{let w=y[0];w&&w.panel?.builderRenderFunction?.(a)}}}function Uo({kind:e,prefix:t,providerInitializationResults:r,cesdk:i}){return n=>{let{builder:o,engine:a}=n;if(r.length===0)return;let s=`ly.img.plugin-ai-${e}-generation-web.providerSelect`;e==="audio"&&t&&(t.includes("speech")?s="ly.img.plugin-ai-audio-generation-web.speech.providerSelect":t.includes("sound")&&(s="ly.img.plugin-ai-audio-generation-web.sound.providerSelect"));let c=i.feature.isEnabled(s,{engine:a}),l=r.map(({provider:f,panel:g})=>({id:f.id,label:f.name??f.id,builderRenderFunction:g?.builderRenderFunction})),u=n.state(`${t}.selectedProvider`,l[0]?.id),d=l.find(f=>f.id===u.value)??l[0];r.length>1&&c&&u!=null&&d!=null&&o.Section(`${t}.providerSelection.section`,{children:()=>{o.Select(`${t}.providerSelect.select`,{inputLabel:re(e,"providerSelect.label"),values:l,value:d,setValue:f=>{u.setValue(f.id)}})}}),d?.builderRenderFunction?.(n)}}function wt(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Ge(r.id),!1).value)}var qt=Fo;var Bo=typeof global=="object"&&global&&global.Object===Object&&global,or=Bo,Go=typeof self=="object"&&self&&self.Object===Object&&self,qo=or||Go||Function("return this")(),j=qo,Ho=j.Symbol,K=Ho,lr=Object.prototype,Zo=lr.hasOwnProperty,Ko=lr.toString,de=K?K.toStringTag:void 0;function Qo(e){var t=Zo.call(e,de),r=e[de];try{e[de]=void 0;var i=!0}catch{}var n=Ko.call(e);return i&&(t?e[de]=r:delete e[de]),n}var Yo=Qo,Wo=Object.prototype,Jo=Wo.toString;function Xo(e){return Jo.call(e)}var el=Xo,tl="[object Null]",rl="[object Undefined]",Ht=K?K.toStringTag:void 0;function il(e){return e==null?e===void 0?rl:tl:Ht&&Ht in Object(e)?Yo(e):el(e)}var me=il;function nl(e){return e!=null&&typeof e=="object"}var Je=nl,hc=Array.isArray;function al(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var sr=al,ol="[object AsyncFunction]",ll="[object Function]",sl="[object GeneratorFunction]",ul="[object Proxy]";function cl(e){if(!sr(e))return!1;var t=me(e);return t==ll||t==sl||t==ol||t==ul}var dl=cl,gl=j["__core-js_shared__"],qe=gl,Zt=function(){var e=/[^.]+$/.exec(qe&&qe.keys&&qe.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function pl(e){return!!Zt&&Zt in e}var fl=pl,ml=Function.prototype,yl=ml.toString;function bl(e){if(e!=null){try{return yl.call(e)}catch{}try{return e+""}catch{}}return""}var R=bl,hl=/[\\^$.*+?()[\]{}|]/g,vl=/^\[object .+?Constructor\]$/,wl=Function.prototype,kl=Object.prototype,Il=wl.toString,Al=kl.hasOwnProperty,Sl=RegExp("^"+Il.call(Al).replace(hl,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function xl(e){if(!sr(e)||fl(e))return!1;var t=dl(e)?Sl:vl;return t.test(R(e))}var Cl=xl;function El(e,t){return e?.[t]}var $l=El;function Ml(e,t){var r=$l(e,t);return Cl(r)?r:void 0}var Q=Ml,jl=Q(j,"WeakMap"),Ze=jl;function Tl(e,t){return e===t||e!==e&&t!==t}var _l=Tl,Ll=9007199254740991;function Pl(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Ll}var Ol=Pl;var vc=Object.prototype;var Nl="[object Arguments]";function Dl(e){return Je(e)&&me(e)==Nl}var Kt=Dl,ur=Object.prototype,zl=ur.hasOwnProperty,Rl=ur.propertyIsEnumerable,wc=Kt(function(){return arguments}())?Kt:function(e){return Je(e)&&zl.call(e,"callee")&&!Rl.call(e,"callee")};var cr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Qt=cr&&typeof module=="object"&&module&&!module.nodeType&&module,Fl=Qt&&Qt.exports===cr,Yt=Fl?j.Buffer:void 0,kc=Yt?Yt.isBuffer:void 0;var Vl="[object Arguments]",Ul="[object Array]",Bl="[object Boolean]",Gl="[object Date]",ql="[object Error]",Hl="[object Function]",Zl="[object Map]",Kl="[object Number]",Ql="[object Object]",Yl="[object RegExp]",Wl="[object Set]",Jl="[object String]",Xl="[object WeakMap]",es="[object ArrayBuffer]",ts="[object DataView]",rs="[object Float32Array]",is="[object Float64Array]",ns="[object Int8Array]",as="[object Int16Array]",os="[object Int32Array]",ls="[object Uint8Array]",ss="[object Uint8ClampedArray]",us="[object Uint16Array]",cs="[object Uint32Array]",I={};I[rs]=I[is]=I[ns]=I[as]=I[os]=I[ls]=I[ss]=I[us]=I[cs]=!0;I[Vl]=I[Ul]=I[es]=I[Bl]=I[ts]=I[Gl]=I[ql]=I[Hl]=I[Zl]=I[Kl]=I[Ql]=I[Yl]=I[Wl]=I[Jl]=I[Xl]=!1;function ds(e){return Je(e)&&Ol(e.length)&&!!I[me(e)]}var gs=ds;function ps(e){return function(t){return e(t)}}var fs=ps,dr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ge=dr&&typeof module=="object"&&module&&!module.nodeType&&module,ms=ge&&ge.exports===dr,He=ms&&or.process,ys=function(){try{var e=ge&&ge.require&&ge.require("util").types;return e||He&&He.binding&&He.binding("util")}catch{}}(),Wt=ys,Jt=Wt&&Wt.isTypedArray,Ic=Jt?fs(Jt):gs;var bs=Object.prototype,Ac=bs.hasOwnProperty;function hs(e,t){return function(r){return e(t(r))}}var vs=hs,Sc=vs(Object.keys,Object);var ws=Object.prototype,xc=ws.hasOwnProperty;var ks=Q(Object,"create"),pe=ks;function Is(){this.__data__=pe?pe(null):{},this.size=0}var As=Is;function Ss(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var xs=Ss,Cs="__lodash_hash_undefined__",Es=Object.prototype,$s=Es.hasOwnProperty;function Ms(e){var t=this.__data__;if(pe){var r=t[e];return r===Cs?void 0:r}return $s.call(t,e)?t[e]:void 0}var js=Ms,Ts=Object.prototype,_s=Ts.hasOwnProperty;function Ls(e){var t=this.__data__;return pe?t[e]!==void 0:_s.call(t,e)}var Ps=Ls,Os="__lodash_hash_undefined__";function Ns(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=pe&&t===void 0?Os:t,this}var Ds=Ns;function Y(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])}}Y.prototype.clear=As;Y.prototype.delete=xs;Y.prototype.get=js;Y.prototype.has=Ps;Y.prototype.set=Ds;var Xt=Y;function zs(){this.__data__=[],this.size=0}var Rs=zs;function Fs(e,t){for(var r=e.length;r--;)if(_l(e[r][0],t))return r;return-1}var Ie=Fs,Vs=Array.prototype,Us=Vs.splice;function Bs(e){var t=this.__data__,r=Ie(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 Gs=Bs;function qs(e){var t=this.__data__,r=Ie(t,e);return r<0?void 0:t[r][1]}var Hs=qs;function Zs(e){return Ie(this.__data__,e)>-1}var Ks=Zs;function Qs(e,t){var r=this.__data__,i=Ie(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var Ys=Qs;function W(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])}}W.prototype.clear=Rs;W.prototype.delete=Gs;W.prototype.get=Hs;W.prototype.has=Ks;W.prototype.set=Ys;var Ae=W,Ws=Q(j,"Map"),fe=Ws;function Js(){this.size=0,this.__data__={hash:new Xt,map:new(fe||Ae),string:new Xt}}var Xs=Js;function eu(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var tu=eu;function ru(e,t){var r=e.__data__;return tu(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Se=ru;function iu(e){var t=Se(this,e).delete(e);return this.size-=t?1:0,t}var nu=iu;function au(e){return Se(this,e).get(e)}var ou=au;function lu(e){return Se(this,e).has(e)}var su=lu;function uu(e,t){var r=Se(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var cu=uu;function J(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])}}J.prototype.clear=Xs;J.prototype.delete=nu;J.prototype.get=ou;J.prototype.has=su;J.prototype.set=cu;var gr=J;function du(){this.__data__=new Ae,this.size=0}var gu=du;function pu(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var fu=pu;function mu(e){return this.__data__.get(e)}var yu=mu;function bu(e){return this.__data__.has(e)}var hu=bu,vu=200;function wu(e,t){var r=this.__data__;if(r instanceof Ae){var i=r.__data__;if(!fe||i.length<vu-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new gr(i)}return r.set(e,t),this.size=r.size,this}var ku=wu;function ye(e){var t=this.__data__=new Ae(e);this.size=t.size}ye.prototype.clear=gu;ye.prototype.delete=fu;ye.prototype.get=yu;ye.prototype.has=hu;ye.prototype.set=ku;var Iu=Object.prototype,Cc=Iu.propertyIsEnumerable;var Au=Q(j,"DataView"),Ke=Au,Su=Q(j,"Promise"),Qe=Su,xu=Q(j,"Set"),Ye=xu,er="[object Map]",Cu="[object Object]",tr="[object Promise]",rr="[object Set]",ir="[object WeakMap]",nr="[object DataView]",Eu=R(Ke),$u=R(fe),Mu=R(Qe),ju=R(Ye),Tu=R(Ze),Z=me;(Ke&&Z(new Ke(new ArrayBuffer(1)))!=nr||fe&&Z(new fe)!=er||Qe&&Z(Qe.resolve())!=tr||Ye&&Z(new Ye)!=rr||Ze&&Z(new Ze)!=ir)&&(Z=function(e){var t=me(e),r=t==Cu?e.constructor:void 0,i=r?R(r):"";if(i)switch(i){case Eu:return nr;case $u:return er;case Mu:return tr;case ju:return rr;case Tu:return ir}return t});var Ec=j.Uint8Array;var _u="__lodash_hash_undefined__";function Lu(e){return this.__data__.set(e,_u),this}var Pu=Lu;function Ou(e){return this.__data__.has(e)}var Nu=Ou;function We(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new gr;++t<r;)this.add(e[t])}We.prototype.add=We.prototype.push=Pu;We.prototype.has=Nu;var ar=K?K.prototype:void 0,$c=ar?ar.valueOf:void 0;var Du=Object.prototype,Mc=Du.hasOwnProperty;var zu=Object.prototype,jc=zu.hasOwnProperty;var Tc=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),_c=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Lc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function Ru(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),o=new Uint8Array(n),a=new Blob([o],{type:r});return URL.createObjectURL(a)}else return e}async function xe(e,t,r){let i,n=t.block.getFill(e),o=t.block.getSourceSet(n,"fill/image/sourceSet"),[a]=o;if(a==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=a.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return Ru(i,t)}function Fu(e){return e==null?[]:Array.isArray(e)?e:[e]}var Xe=Fu;function Vu(e){return e?.version?e.version.localeCompare("1.59.0",void 0,{numeric:!0,sensitivity:"base"})>=0&&typeof e.i18n?.translate=="function":!1}function Uu(e){return typeof e?.translate=="function"}function pr(e,t,r){return e&&Vu(e)&&Uu(e.i18n)?e.i18n.translate(t):r}var O="@imgly/plugin-ai-video-generation-web",Bu=["ly.img.createVideo","ly.img.animateBetweenImages"];var Ce="createVideo",fr=`ly.img.${Ce}`,Gu=`ly.img.plugin-ai-video-generation-web.quickAction.${Ce}`,mr=`ly.img.plugin-ai-video-generation-web.defaults.quickAction.${Ce}`;function qu(e,t){let r="ly.img.plugin-ai-video-generation-web",i=`quickAction.${Ce}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var Hu=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.createVideo",!0),P(e,{en:{[`${mr}`]:"Create Video...",[`${mr}.description`]:"Create a video from the image"}}),{id:fr,type:"quick",kind:"image",label:`${Gu}`,enable:Pt(),scopes:[],render:({builder:r,engine:i,close:n,providerId:o})=>{r.Button(`${fr}.button`,{label:qu(o),icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),s=await xe(a,i,{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(`${o}.image_urls`,s),n()}catch(a){console.error("Error opening video generation panel:",a)}}})}}),yr=Hu;var Ee="animateBetweenImages",br=`ly.img.${Ee}`,Zu=`ly.img.plugin-ai-video-generation-web.quickAction.${Ee}`,hr=`ly.img.plugin-ai-video-generation-web.defaults.quickAction.${Ee}`;function Ku(e,t){let r="ly.img.plugin-ai-video-generation-web",i=`quickAction.${Ee}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var Qu=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.animateBetweenImages",!0),P(e,{en:{[`${hr}`]:"Animate Between Images...",[`${hr}.description`]:"Create a video transitioning between two images"}}),{id:br,type:"quick",kind:"image",label:`${Zu}`,enable:r=>{let i=r.engine.block.findAllSelected();return i==null||i.length!==2?!1:i.every(n=>{if(r.engine.block.getType(n)!=="//ly.img.ubq/graphic"&&!r.engine.block.supportsFill(n))return!1;let o=r.engine.block.getFill(n);return!(r.engine.block.getType(o)!=="//ly.img.ubq/fill/image"||r.engine.block.getType(n)==="//ly.img.ubq/page")})},scopes:[],render:({builder:r,engine:i,close:n,providerId:o})=>{r.Button(`${br}.button`,{label:Ku(o),icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let a=i.block.findAllSelected();if(a.length!==2)throw new Error("Exactly 2 images must be selected");let[s,c]=await Promise.all(a.map(u=>xe(u,i,{throwErrorIfSvg:!0}))),l="fal-ai/veo3.1/fast/first-last-frame-to-video";e.ui.experimental.setGlobalStateValue("ly.img.ai.video-generation.selectedProvider.fromImage",l),e.ui.experimental.setGlobalStateValue(`${l}.first_frame_url`,s),e.ui.experimental.setGlobalStateValue(`${l}.last_frame_url`,c),e.ui.experimental.setGlobalStateValue("ly.img.ai.video-generation.fromType","fromImage"),e.ui.openPanel("ly.img.ai.video-generation"),n()}catch(a){console.error("Error opening video generation panel:",a),e.ui.showNotification({type:"error",message:a.message||"Failed to open video generation panel. Please try again.",duration:"medium"})}}})}}),vr=Qu;var N="ly.img.ai.video-generation";function Yu(e){return{async initialize({cesdk:t}){if(t==null)return;_t(t,O,"1.73.0-rc.2"),t.feature.enable("ly.img.plugin-ai-video-generation-web.fromText",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.fromImage",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.providerSelect",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.quickAction",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.quickAction.providerSelect",!0);let r=`${O}.action.label`;P(t,{en:{[`panel.${N}`]:"Video Generation",[`${N}.dock.label`]:"AI Video",[r]:"Generate Video","ly.img.ai.video.generation.hint":"Video generation may take up to a few minutes. This panel can be closed and you'll be notified when it's ready."}}),Wu(e);let n=ce.get().register({type:"plugin",sceneMode:"Video",id:O,pluginId:O,label:pr(t,r,"Generate Video"),labelKey:r,meta:{panelId:N},execute:()=>{t.ui.isPanelOpen(N)?t.ui.closePanel(N):t.ui.openPanel(N)}}),o=e.providers?.text2video??e.text2video,a=e.providers?.image2video??e.image2video,s=await Promise.all(Xe(o).map(d=>d({cesdk:t}))),c=await Promise.all(Xe(a).map(d=>d({cesdk:t})));if(!(s.length>0||c.length>0)){n();return}let u=await qt("video",{fromText:s,fromImage:c},{cesdk:t},e);ce.get().register(yr({cesdk:t})),ce.get().register(vr({cesdk:t})),u.panel.builderRenderFunction!=null?(t.ui.registerPanel(N,u.panel.builderRenderFunction),Lt({cesdk:t,panelId:N})):n()}}}function Wu(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 wr=Yu;var Ju=e=>({name:O,version:"1.73.0-rc.2",...wr(e)}),ed=Ju;export{Bu as DEFAULT_VIDEO_QUICK_ACTION_ORDER,ed as default};
65
+ `,So=Ao;function xo(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 qt(2e3),await Co(t,e,r)):i(t,r)}async function Co(e,t,r){switch(t.kind){case"image":return Eo(e,t,r);case"video":return $o(e,t,r);case"text":return Mo(e,t,r);case"audio":return To(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function Eo(e,t,{engine:r}){let i,n,o=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",a=o.match(/(\d+)x(\d+)/);if(a!=null)i=parseInt(a[1],10),n=parseInt(a[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[s]=t.blockIds,c=await Ia(s,r),l=await ka(c,r);i=l.width,n=l.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${o.replace(" ","+").replace(`
66
+ `,"+")}`}}async function $o(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function Mo(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[a]=t.blockIds;r.engine.block.isValid(a)&&(i=r.engine.block.getString(a,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let a=e.prompt,s=a.match(/text:\s*"([^"]+)"/i)||a.match(/content:\s*"([^"]+)"/i)||a.match(/"([^"]+)"/);s&&s[1]&&(i=s[1])}let n=i.length||50,o="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")o=ee(n,"translation");else if("type"in e&&typeof e.type=="string"){let a=e.type;o=ee(n,a)}else"customPrompt"in e?o=ee(n,"custom"):o=ee(n,"improved");else o=ee(n,"generated");return jo(o,r.abortSignal)}async function*jo(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 qt(100)}return{kind:"text",text:e}}function ee(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,o={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."},a=o[t]||o.generated,s="";if(n<=a.length)s=a.substring(0,n);else{s=a;let c=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],l=0;for(;s.length<n;){let u=c[l%c.length];if(s.length+u.length<=n)s+=u;else{s+=u.substring(0,n-s.length);break}l++}}return r+s}async function To(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:_o(220,i),duration:i,thumbnailUrl:void 0}}function _o(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 Lo(i,44100)}function Lo(e,t){let r=e.length,i=2,n=1,o=n*i,a=t*o,s=r*i,c=44+s,l=new ArrayBuffer(c),u=new DataView(l),d=(p,y)=>{for(let v=0;v<y.length;v++)u.setUint8(p+v,y.charCodeAt(v))};d(0,"RIFF"),u.setUint32(4,c-8,!0),d(8,"WAVE"),d(12,"fmt "),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,n,!0),u.setUint32(24,t,!0),u.setUint32(28,a,!0),u.setUint16(32,o,!0),u.setUint16(34,16,!0),d(36,"data"),u.setUint32(40,s,!0);let f=44;for(let p=0;p<r;p++){let y=Math.max(-1,Math.min(1,e[p])),v=Math.round(y*32767);u.setInt16(f,v,!0),f+=2}let g=new Uint8Array(l),m="";for(let p=0;p<g.length;p++)m+=String.fromCharCode(g[p]);return`data:audio/wav;base64,${btoa(m)}`}async function qt(e){return new Promise(t=>{setTimeout(t,e)})}var Po=xo,No="USER_CANCEL";function Oo(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=Ca([...e.provider.output.middleware??[],...r?.middlewares??[],$a({enable:r?.debug}),Po({enable:r?.dryRun,kind:e.provider.kind})]),n={prevented:!1},o={blockIds:r?.blockIds,abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk,preventDefault:()=>{n.prevented=!0},defaultPrevented:()=>n.prevented};try{let{result:a}=await i(e.provider.output.generate)(t,o);return r?.abortSignal?.aborted?{status:"aborted",middlewareOptions:o}:a instanceof Error?{status:"error",message:a.message,middlewareOptions:o}:a==null?{status:"error",message:"No output generated",middlewareOptions:o}:_a(a)?{status:"success",type:"async",output:a,middlewareOptions:o}:{status:"success",type:"sync",output:a,middlewareOptions:o}}catch(a){return Be(a)?{status:"aborted",message:a.message,middlewareOptions:o}:a===No?{status:"aborted",message:a,middlewareOptions:o}:{status:"error",message:a instanceof Error?a.message:String(a),middlewareOptions:o}}}}var Do=Oo;async function zo(e,t,r,i){let n={...i,provider:t},o={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n,providerConfig:t.configuration};if(await t.initialize?.({...r,engine:r.cesdk.engine}),t.input?.quickActions?.supported){let d=t.kind,f=ce.get();Object.keys(t.input.quickActions.supported).forEach(g=>{if(!f.getBy({id:g,type:"quick"})[0]){let m=`ly.img.plugin-ai-${d}-generation-web.quickAction.${g}`;r.cesdk.feature.enable(m,!0)}})}let a=wo(o),s=Io(o,a);o.options.historyAssetSourceId=a,o.options.historyAssetLibraryEntryId=s;let c=Do({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),l=await ho(o,c);La(r.cesdk,"@imgly/plugin-ai-generation",So);let u={provider:t,panel:{builderRenderFunction:l},history:{assetSourceId:a,assetLibraryEntryId:s},generate:c};return xa.get().register(u),u}var Pe=zo;function Ro(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 o=new Ar(n,r,i);return r.engine.asset.addSource(o),o.id}var Fo=Ro;function re(e,t){return[`ly.img.plugin-ai-${e}-generation-web.${t}`,`ly.img.plugin-ai-generation-web.${t}`,`ly.img.plugin-ai-generation-web.defaults.${t}`]}async function Vo(e,t,r,i){let{cesdk:n}=r;P(n,{en:{"ly.img.plugin-ai-generation-web.generate":"Generate","ly.img.plugin-ai-generation-web.defaults.fromType.label":"Input","ly.img.plugin-ai-generation-web.defaults.providerSelect.label":"Provider","ly.img.plugin-ai-generation-web.defaults.fromText.label":"Text","ly.img.plugin-ai-generation-web.defaults.fromImage.label":"Image","ly.img.plugin-ai-generation-web.schema.loading.label":"Loading\u2026","ly.img.plugin-ai-generation-web.schema.error.title":"Failed to load schema","ly.img.plugin-ai-generation-web.schema.error.retry":"Retry"}});let o,a=[];if(i.debug&&console.groupCollapsed(`Initializing ${e} generation providers`),Array.isArray(t)){let l=await Promise.all(t.map(u=>Pe(e,u,r,i)));a.push(...l),o=Bo({kind:e,prefix:e,providerInitializationResults:a,cesdk:n})}else{let l=await Promise.all(t.fromText.map(d=>Pe(e,d,r,i)));a.push(...l);let u=await Promise.all(t.fromImage.map(d=>Pe(e,d,r,i)));a.push(...u),o=Uo({kind:e,prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u,cesdk:n})}i.debug&&console.groupEnd();let s=Fo({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(l=>l.history?.assetSourceId).filter(Sa)}),c;return s!=null&&(c=s,r.cesdk.ui.addAssetLibraryEntry({id:c,sourceIds:[s],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"})),{panel:{builderRenderFunction:o},history:{assetSourceId:s,assetLibraryEntryId:c},providerInitializationResults:a}}function Uo({kind:e,prefix:t,initializedFromTextProviders:r,initializedFromImageProviders:i,cesdk:n}){let o=r.length>0&&i.length>0;return a=>{let{builder:s,experimental:c,engine:l}=a,u=`ly.img.plugin-ai-${e}-generation-web.fromText`,d=n.feature.isEnabled(u,{engine:l}),f=`ly.img.plugin-ai-${e}-generation-web.fromImage`,g=n.feature.isEnabled(f,{engine:l}),m;d&&r.length>0&&(!g||i.length===0)?m="fromText":g&&i.length>0&&(!d||r.length===0)?m="fromImage":d&&g&&o&&(m="fromText");let p=c.global(`${t}.fromType`,m),y=[];p.value==="fromText"?y.push(...r):p.value==="fromImage"?y.push(...i):y.push(...r,...i);let v=r.map(({provider:A,panel:C})=>({id:A.id,label:Fe(A),builderRenderFunction:C?.builderRenderFunction})),I=i.map(({provider:A,panel:C})=>({id:A.id,label:Fe(A),builderRenderFunction:C?.builderRenderFunction})),S=a.experimental.global(`${t}.selectedProvider.fromText`,v[0]?.id),x=a.experimental.global(`${t}.selectedProvider.fromImage`,I[0]?.id),h=v.find(A=>A.id===S.value)??v[0],E=I.find(A=>A.id===x.value)??I[0],be=p.value==="fromText"?S:p.value==="fromImage"?x:void 0,D=p.value==="fromText"?h:p.value==="fromImage"?E:void 0,he=`ly.img.plugin-ai-${e}-generation-web.providerSelect`,$e=n.feature.isEnabled(he,{engine:l});if(!d&&!g){s.Section(`${t}.noInputWarning.section`,{children:()=>{s.Text(`${t}.noInputWarning.text`,{content:"No input types are enabled. Please enable at least one input type (text or image) via the Feature API."})}});return}let T=d&&g&&r.length>0&&i.length>0,b=o&&T,$=y.length>1&&$e;if((b||$)&&s.Section(`${t}.providerSelection.section`,{children:()=>{if(b&&s.ButtonGroup(`${t}.fromType.buttonGroup`,{inputLabel:re(e,"fromType.label"),children:()=>{d&&r.length>0&&s.Button(`${t}.fromType.buttonGroup.fromText`,{label:re(e,"fromText.label"),icon:p.value!=="fromText"&&kt(r,a)?"@imgly/LoadingSpinner":void 0,isActive:p.value==="fromText",onClick:()=>{p.setValue("fromText")}}),g&&i.length>0&&s.Button(`${t}.fromType.buttonGroup.fromImage`,{label:re(e,"fromImage.label"),icon:p.value!=="fromImage"&&kt(i,a)?"@imgly/LoadingSpinner":void 0,isActive:p.value==="fromImage",onClick:()=>{p.setValue("fromImage")}})}}),$){let A=p.value==="fromText"?v:p.value==="fromImage"?I:[...v,...I];be!=null&&D!=null&&s.Select(`${t}.providerSelect.select`,{inputLabel:re(e,"providerSelect.label"),values:A,value:D,setValue:C=>{be.setValue(C.id)}})}}}),y.length>1)D?.builderRenderFunction?.(a);else{let A=y[0];A&&A.panel?.builderRenderFunction?.(a)}}}function Bo({kind:e,prefix:t,providerInitializationResults:r,cesdk:i}){return n=>{let{builder:o,engine:a}=n;if(r.length===0)return;let s=`ly.img.plugin-ai-${e}-generation-web.providerSelect`;e==="audio"&&t&&(t.includes("speech")?s="ly.img.plugin-ai-audio-generation-web.speech.providerSelect":t.includes("sound")&&(s="ly.img.plugin-ai-audio-generation-web.sound.providerSelect"));let c=i.feature.isEnabled(s,{engine:a}),l=r.map(({provider:f,panel:g})=>({id:f.id,label:Fe(f),builderRenderFunction:g?.builderRenderFunction})),u=n.state(`${t}.selectedProvider`,l[0]?.id),d=l.find(f=>f.id===u.value)??l[0];r.length>1&&c&&u!=null&&d!=null&&o.Section(`${t}.providerSelection.section`,{children:()=>{o.Select(`${t}.providerSelect.select`,{inputLabel:re(e,"providerSelect.label"),values:l,value:d,setValue:f=>{u.setValue(f.id)}})}}),d?.builderRenderFunction?.(n)}}function kt(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(qe(r.id),!1).value)}var Ht=Vo;var Go=typeof global=="object"&&global&&global.Object===Object&&global,lr=Go,qo=typeof self=="object"&&self&&self.Object===Object&&self,Ho=lr||qo||Function("return this")(),j=Ho,Zo=j.Symbol,K=Zo,sr=Object.prototype,Ko=sr.hasOwnProperty,Qo=sr.toString,de=K?K.toStringTag:void 0;function Yo(e){var t=Ko.call(e,de),r=e[de];try{e[de]=void 0;var i=!0}catch{}var n=Qo.call(e);return i&&(t?e[de]=r:delete e[de]),n}var Wo=Yo,Jo=Object.prototype,Xo=Jo.toString;function el(e){return Xo.call(e)}var tl=el,rl="[object Null]",il="[object Undefined]",Zt=K?K.toStringTag:void 0;function nl(e){return e==null?e===void 0?il:rl:Zt&&Zt in Object(e)?Wo(e):tl(e)}var me=nl;function al(e){return e!=null&&typeof e=="object"}var Xe=al,vc=Array.isArray;function ol(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var ur=ol,ll="[object AsyncFunction]",sl="[object Function]",ul="[object GeneratorFunction]",cl="[object Proxy]";function dl(e){if(!ur(e))return!1;var t=me(e);return t==sl||t==ul||t==ll||t==cl}var gl=dl,pl=j["__core-js_shared__"],He=pl,Kt=function(){var e=/[^.]+$/.exec(He&&He.keys&&He.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function fl(e){return!!Kt&&Kt in e}var ml=fl,yl=Function.prototype,bl=yl.toString;function hl(e){if(e!=null){try{return bl.call(e)}catch{}try{return e+""}catch{}}return""}var R=hl,vl=/[\\^$.*+?()[\]{}|]/g,wl=/^\[object .+?Constructor\]$/,kl=Function.prototype,Il=Object.prototype,Al=kl.toString,Sl=Il.hasOwnProperty,xl=RegExp("^"+Al.call(Sl).replace(vl,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Cl(e){if(!ur(e)||ml(e))return!1;var t=gl(e)?xl:wl;return t.test(R(e))}var El=Cl;function $l(e,t){return e?.[t]}var Ml=$l;function jl(e,t){var r=Ml(e,t);return El(r)?r:void 0}var Q=jl,Tl=Q(j,"WeakMap"),Ke=Tl;function _l(e,t){return e===t||e!==e&&t!==t}var Ll=_l,Pl=9007199254740991;function Nl(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Pl}var Ol=Nl;var wc=Object.prototype;var Dl="[object Arguments]";function zl(e){return Xe(e)&&me(e)==Dl}var Qt=zl,cr=Object.prototype,Rl=cr.hasOwnProperty,Fl=cr.propertyIsEnumerable,kc=Qt(function(){return arguments}())?Qt:function(e){return Xe(e)&&Rl.call(e,"callee")&&!Fl.call(e,"callee")};var dr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Yt=dr&&typeof module=="object"&&module&&!module.nodeType&&module,Vl=Yt&&Yt.exports===dr,Wt=Vl?j.Buffer:void 0,Ic=Wt?Wt.isBuffer:void 0;var Ul="[object Arguments]",Bl="[object Array]",Gl="[object Boolean]",ql="[object Date]",Hl="[object Error]",Zl="[object Function]",Kl="[object Map]",Ql="[object Number]",Yl="[object Object]",Wl="[object RegExp]",Jl="[object Set]",Xl="[object String]",es="[object WeakMap]",ts="[object ArrayBuffer]",rs="[object DataView]",is="[object Float32Array]",ns="[object Float64Array]",as="[object Int8Array]",os="[object Int16Array]",ls="[object Int32Array]",ss="[object Uint8Array]",us="[object Uint8ClampedArray]",cs="[object Uint16Array]",ds="[object Uint32Array]",k={};k[is]=k[ns]=k[as]=k[os]=k[ls]=k[ss]=k[us]=k[cs]=k[ds]=!0;k[Ul]=k[Bl]=k[ts]=k[Gl]=k[rs]=k[ql]=k[Hl]=k[Zl]=k[Kl]=k[Ql]=k[Yl]=k[Wl]=k[Jl]=k[Xl]=k[es]=!1;function gs(e){return Xe(e)&&Ol(e.length)&&!!k[me(e)]}var ps=gs;function fs(e){return function(t){return e(t)}}var ms=fs,gr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ge=gr&&typeof module=="object"&&module&&!module.nodeType&&module,ys=ge&&ge.exports===gr,Ze=ys&&lr.process,bs=function(){try{var e=ge&&ge.require&&ge.require("util").types;return e||Ze&&Ze.binding&&Ze.binding("util")}catch{}}(),Jt=bs,Xt=Jt&&Jt.isTypedArray,Ac=Xt?ms(Xt):ps;var hs=Object.prototype,Sc=hs.hasOwnProperty;function vs(e,t){return function(r){return e(t(r))}}var ws=vs,xc=ws(Object.keys,Object);var ks=Object.prototype,Cc=ks.hasOwnProperty;var Is=Q(Object,"create"),pe=Is;function As(){this.__data__=pe?pe(null):{},this.size=0}var Ss=As;function xs(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Cs=xs,Es="__lodash_hash_undefined__",$s=Object.prototype,Ms=$s.hasOwnProperty;function js(e){var t=this.__data__;if(pe){var r=t[e];return r===Es?void 0:r}return Ms.call(t,e)?t[e]:void 0}var Ts=js,_s=Object.prototype,Ls=_s.hasOwnProperty;function Ps(e){var t=this.__data__;return pe?t[e]!==void 0:Ls.call(t,e)}var Ns=Ps,Os="__lodash_hash_undefined__";function Ds(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=pe&&t===void 0?Os:t,this}var zs=Ds;function Y(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])}}Y.prototype.clear=Ss;Y.prototype.delete=Cs;Y.prototype.get=Ts;Y.prototype.has=Ns;Y.prototype.set=zs;var er=Y;function Rs(){this.__data__=[],this.size=0}var Fs=Rs;function Vs(e,t){for(var r=e.length;r--;)if(Ll(e[r][0],t))return r;return-1}var Ie=Vs,Us=Array.prototype,Bs=Us.splice;function Gs(e){var t=this.__data__,r=Ie(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Bs.call(t,r,1),--this.size,!0}var qs=Gs;function Hs(e){var t=this.__data__,r=Ie(t,e);return r<0?void 0:t[r][1]}var Zs=Hs;function Ks(e){return Ie(this.__data__,e)>-1}var Qs=Ks;function Ys(e,t){var r=this.__data__,i=Ie(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var Ws=Ys;function W(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])}}W.prototype.clear=Fs;W.prototype.delete=qs;W.prototype.get=Zs;W.prototype.has=Qs;W.prototype.set=Ws;var Ae=W,Js=Q(j,"Map"),fe=Js;function Xs(){this.size=0,this.__data__={hash:new er,map:new(fe||Ae),string:new er}}var eu=Xs;function tu(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var ru=tu;function iu(e,t){var r=e.__data__;return ru(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Se=iu;function nu(e){var t=Se(this,e).delete(e);return this.size-=t?1:0,t}var au=nu;function ou(e){return Se(this,e).get(e)}var lu=ou;function su(e){return Se(this,e).has(e)}var uu=su;function cu(e,t){var r=Se(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var du=cu;function J(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])}}J.prototype.clear=eu;J.prototype.delete=au;J.prototype.get=lu;J.prototype.has=uu;J.prototype.set=du;var pr=J;function gu(){this.__data__=new Ae,this.size=0}var pu=gu;function fu(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var mu=fu;function yu(e){return this.__data__.get(e)}var bu=yu;function hu(e){return this.__data__.has(e)}var vu=hu,wu=200;function ku(e,t){var r=this.__data__;if(r instanceof Ae){var i=r.__data__;if(!fe||i.length<wu-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new pr(i)}return r.set(e,t),this.size=r.size,this}var Iu=ku;function ye(e){var t=this.__data__=new Ae(e);this.size=t.size}ye.prototype.clear=pu;ye.prototype.delete=mu;ye.prototype.get=bu;ye.prototype.has=vu;ye.prototype.set=Iu;var Au=Object.prototype,Ec=Au.propertyIsEnumerable;var Su=Q(j,"DataView"),Qe=Su,xu=Q(j,"Promise"),Ye=xu,Cu=Q(j,"Set"),We=Cu,tr="[object Map]",Eu="[object Object]",rr="[object Promise]",ir="[object Set]",nr="[object WeakMap]",ar="[object DataView]",$u=R(Qe),Mu=R(fe),ju=R(Ye),Tu=R(We),_u=R(Ke),Z=me;(Qe&&Z(new Qe(new ArrayBuffer(1)))!=ar||fe&&Z(new fe)!=tr||Ye&&Z(Ye.resolve())!=rr||We&&Z(new We)!=ir||Ke&&Z(new Ke)!=nr)&&(Z=function(e){var t=me(e),r=t==Eu?e.constructor:void 0,i=r?R(r):"";if(i)switch(i){case $u:return ar;case Mu:return tr;case ju:return rr;case Tu:return ir;case _u:return nr}return t});var $c=j.Uint8Array;var Lu="__lodash_hash_undefined__";function Pu(e){return this.__data__.set(e,Lu),this}var Nu=Pu;function Ou(e){return this.__data__.has(e)}var Du=Ou;function Je(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new pr;++t<r;)this.add(e[t])}Je.prototype.add=Je.prototype.push=Nu;Je.prototype.has=Du;var or=K?K.prototype:void 0,Mc=or?or.valueOf:void 0;var zu=Object.prototype,jc=zu.hasOwnProperty;var Ru=Object.prototype,Tc=Ru.hasOwnProperty;var _c=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Lc=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Pc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function Fu(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),o=new Uint8Array(n),a=new Blob([o],{type:r});return URL.createObjectURL(a)}else return e}async function xe(e,t,r){let i,n=t.block.getFill(e),o=t.block.getSourceSet(n,"fill/image/sourceSet"),[a]=o;if(a==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=a.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return Fu(i,t)}function Vu(e){return e==null?[]:Array.isArray(e)?e:[e]}var et=Vu;function Uu(e){return e?.version?e.version.localeCompare("1.59.0",void 0,{numeric:!0,sensitivity:"base"})>=0&&typeof e.i18n?.translate=="function":!1}function Bu(e){return typeof e?.translate=="function"}function fr(e,t,r){return e&&Uu(e)&&Bu(e.i18n)?e.i18n.translate(t):r}var N="@imgly/plugin-ai-video-generation-web",Gu=["ly.img.createVideo","ly.img.animateBetweenImages"];var Ce="createVideo",mr=`ly.img.${Ce}`,qu=`ly.img.plugin-ai-video-generation-web.quickAction.${Ce}`,yr=`ly.img.plugin-ai-video-generation-web.defaults.quickAction.${Ce}`;function Hu(e,t){let r="ly.img.plugin-ai-video-generation-web",i=`quickAction.${Ce}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var Zu=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.createVideo",!0),P(e,{en:{[`${yr}`]:"Create Video...",[`${yr}.description`]:"Create a video from the image"}}),{id:mr,type:"quick",kind:"image",label:`${qu}`,enable:Nt(),scopes:[],render:({builder:r,engine:i,close:n,providerId:o})=>{r.Button(`${mr}.button`,{label:Hu(o),icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),s=await xe(a,i,{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(`${o}.image_urls`,s),n()}catch(a){console.error("Error opening video generation panel:",a)}}})}}),br=Zu;var Ee="animateBetweenImages",hr=`ly.img.${Ee}`,Ku=`ly.img.plugin-ai-video-generation-web.quickAction.${Ee}`,vr=`ly.img.plugin-ai-video-generation-web.defaults.quickAction.${Ee}`;function Qu(e,t){let r="ly.img.plugin-ai-video-generation-web",i=`quickAction.${Ee}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var Yu=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.animateBetweenImages",!0),P(e,{en:{[`${vr}`]:"Animate Between Images...",[`${vr}.description`]:"Create a video transitioning between two images"}}),{id:hr,type:"quick",kind:"image",label:`${Ku}`,enable:r=>{let i=r.engine.block.findAllSelected();return i==null||i.length!==2?!1:i.every(n=>{if(r.engine.block.getType(n)!=="//ly.img.ubq/graphic"&&!r.engine.block.supportsFill(n))return!1;let o=r.engine.block.getFill(n);return!(r.engine.block.getType(o)!=="//ly.img.ubq/fill/image"||r.engine.block.getType(n)==="//ly.img.ubq/page")})},scopes:[],render:({builder:r,engine:i,close:n,providerId:o})=>{r.Button(`${hr}.button`,{label:Qu(o),icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let a=i.block.findAllSelected();if(a.length!==2)throw new Error("Exactly 2 images must be selected");let[s,c]=await Promise.all(a.map(u=>xe(u,i,{throwErrorIfSvg:!0}))),l="fal-ai/veo3.1/fast/first-last-frame-to-video";e.ui.experimental.setGlobalStateValue("ly.img.ai.video-generation.selectedProvider.fromImage",l),e.ui.experimental.setGlobalStateValue(`${l}.first_frame_url`,s),e.ui.experimental.setGlobalStateValue(`${l}.last_frame_url`,c),e.ui.experimental.setGlobalStateValue("ly.img.ai.video-generation.fromType","fromImage"),e.ui.openPanel("ly.img.ai.video-generation"),n()}catch(a){console.error("Error opening video generation panel:",a),e.ui.showNotification({type:"error",message:a.message||"Failed to open video generation panel. Please try again.",duration:"medium"})}}})}}),wr=Yu;var O="ly.img.ai.video-generation";function Wu(e){return{async initialize({cesdk:t}){if(t==null)return;Lt(t,N,"1.73.0"),t.feature.enable("ly.img.plugin-ai-video-generation-web.fromText",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.fromImage",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.providerSelect",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.quickAction",!0),t.feature.enable("ly.img.plugin-ai-video-generation-web.quickAction.providerSelect",!0);let r=`${N}.action.label`;P(t,{en:{[`panel.${O}`]:"Video Generation",[`${O}.dock.label`]:"AI Video",[r]:"Generate Video","ly.img.ai.video.generation.hint":"Video generation may take up to a few minutes. This panel can be closed and you'll be notified when it's ready."}}),Ju(e);let n=ce.get().register({type:"plugin",sceneMode:"Video",id:N,pluginId:N,label:fr(t,r,"Generate Video"),labelKey:r,meta:{panelId:O},execute:()=>{t.ui.isPanelOpen(O)?t.ui.closePanel(O):t.ui.openPanel(O)}}),o=e.providers?.text2video??e.text2video,a=e.providers?.image2video??e.image2video,s=await Promise.all(et(o).map(d=>d({cesdk:t}))),c=await Promise.all(et(a).map(d=>d({cesdk:t})));if(!(s.length>0||c.length>0)){n();return}let u=await Ht("video",{fromText:s,fromImage:c},{cesdk:t},e);ce.get().register(br({cesdk:t})),ce.get().register(wr({cesdk:t})),u.panel.builderRenderFunction!=null?(t.ui.registerPanel(O,u.panel.builderRenderFunction),Pt({cesdk:t,panelId:O})):n()}}}function Ju(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 kr=Wu;var Xu=e=>({name:N,version:"1.73.0",...kr(e)}),td=Xu;export{Gu as DEFAULT_VIDEO_QUICK_ACTION_ORDER,td as default};
67
67
  /*! Bundled license information:
68
68
 
69
69
  lodash-es/lodash.js: