@imgly/plugin-ai-video-generation-web 0.2.6 → 0.2.8

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.d.ts CHANGED
@@ -2,9 +2,7 @@ import { Output } from '@imgly/plugin-ai-generation-web';
2
2
  import { type PluginConfiguration } from './types';
3
3
  import { DEFAULT_VIDEO_QUICK_ACTION_ORDER } from './constants';
4
4
  declare const Plugin: <I, O extends Output>(pluginConfiguration: PluginConfiguration<I, O>) => {
5
- initialize: (context: import("@cesdk/engine").EnginePluginContext & {
6
- cesdk?: import("@cesdk/cesdk-js").default;
7
- }) => void;
5
+ initialize: (context: import("@cesdk/cesdk-js").EditorPluginContext) => void | Promise<void>;
8
6
  name: string;
9
7
  version: string;
10
8
  };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- var ar=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,s)=>{let u=e.locale??"en",d="",p=[];s.label!=null&&typeof s.label=="object"&&s.label[u]&&(d=s.label[u]),s.tags!=null&&typeof s.tags=="object"&&s.tags[u]&&(p=s.tags[u]);let g={...s,label:d,tags:p};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),l=o<t.length?r+1:void 0;return{assets:a,currentPage:r,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let i=new Set;r.result.forEach(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;R(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.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=()=>{R(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 l=o.meta?.insertedAt||o._insertedAt||Date.now(),c=a.meta?.insertedAt||a._insertedAt||Date.now();return e==="asc"?l-c:c-l}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,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 R(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),R(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(" "),l=e.label?.toLowerCase()??"",c=e.tags?.map(s=>s.toLowerCase())??[];if(!a.every(s=>l.includes(s)||c.some(u=>u.includes(s))))return!1}if(i){let a=Array.isArray(i)?i:[i];if(a.length>0&&(!e.tags||!a.every(l=>e.tags?.includes(l))))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,l)=>{let c,s;return i==="id"?(c=a.id,s=l.id):(c=a.meta?.[i]??null,s=l.meta?.[i]??null),c==null?r==="Ascending"?-1:1:s==null?r==="Ascending"?1:-1:typeof c=="string"&&typeof s=="string"?r==="Ascending"?c.localeCompare(s):s.localeCompare(c):r==="Ascending"?c<s?-1:c>s?1:0:c>s?-1:c<s?1:0}):r==="Descending"&&o.reverse(),n&&o.sort((a,l)=>a.active&&!l.active?-1:!a.active&&l.active?1:0)),o}};function R(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]=R(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]=R(n,t,o)}return e}var or=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 p=u.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:o}=e,a=n*o,l=a+o,c=i.slice(a,l),s=l<i.length?n+1:void 0;return{assets:c,currentPage:n,nextPage:s,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}};var sr=typeof global=="object"&&global&&global.Object===Object&&global,lt=sr,lr=typeof self=="object"&&self&&self.Object===Object&&self,ur=lt||lr||Function("return this")(),$=ur,cr=$.Symbol,F=cr,ut=Object.prototype,dr=ut.hasOwnProperty,gr=ut.toString,K=F?F.toStringTag:void 0;function pr(e){var t=dr.call(e,K),r=e[K];try{e[K]=void 0;var i=!0}catch{}var n=gr.call(e);return i&&(t?e[K]=r:delete e[K]),n}var fr=pr,mr=Object.prototype,br=mr.toString;function hr(e){return br.call(e)}var yr=hr,vr="[object Null]",wr="[object Undefined]",qe=F?F.toStringTag:void 0;function kr(e){return e==null?e===void 0?wr:vr:qe&&qe in Object(e)?fr(e):yr(e)}var ne=kr;function Ir(e){return e!=null&&typeof e=="object"}var Le=Ir,Pu=Array.isArray;function Ar(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var ct=Ar,Sr="[object AsyncFunction]",xr="[object Function]",Cr="[object GeneratorFunction]",Er="[object Proxy]";function Mr(e){if(!ct(e))return!1;var t=ne(e);return t==xr||t==Cr||t==Sr||t==Er}var jr=Mr,$r=$["__core-js_shared__"],ke=$r,He=function(){var e=/[^.]+$/.exec(ke&&ke.keys&&ke.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function _r(e){return!!He&&He in e}var Lr=_r,Pr=Function.prototype,Nr=Pr.toString;function Tr(e){if(e!=null){try{return Nr.call(e)}catch{}try{return e+""}catch{}}return""}var T=Tr,Or=/[\\^$.*+?()[\]{}|]/g,Dr=/^\[object .+?Constructor\]$/,zr=Function.prototype,Rr=Object.prototype,Fr=zr.toString,Vr=Rr.hasOwnProperty,Ur=RegExp("^"+Fr.call(Vr).replace(Or,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Br(e){if(!ct(e)||Lr(e))return!1;var t=jr(e)?Ur:Dr;return t.test(T(e))}var Gr=Br;function qr(e,t){return e?.[t]}var Hr=qr;function Zr(e,t){var r=Hr(e,t);return Gr(r)?r:void 0}var V=Zr,Qr=V($,"WeakMap"),Ce=Qr;function Yr(e,t){return e===t||e!==e&&t!==t}var Wr=Yr,Kr=9007199254740991;function Jr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Kr}var Xr=Jr,Nu=Object.prototype,ei="[object Arguments]";function ti(e){return Le(e)&&ne(e)==ei}var Ze=ti,dt=Object.prototype,ri=dt.hasOwnProperty,ii=dt.propertyIsEnumerable,Tu=Ze(function(){return arguments}())?Ze:function(e){return Le(e)&&ri.call(e,"callee")&&!ii.call(e,"callee")},gt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Qe=gt&&typeof module=="object"&&module&&!module.nodeType&&module,ni=Qe&&Qe.exports===gt,Ye=ni?$.Buffer:void 0,Ou=Ye?Ye.isBuffer:void 0,ai="[object Arguments]",oi="[object Array]",si="[object Boolean]",li="[object Date]",ui="[object Error]",ci="[object Function]",di="[object Map]",gi="[object Number]",pi="[object Object]",fi="[object RegExp]",mi="[object Set]",bi="[object String]",hi="[object WeakMap]",yi="[object ArrayBuffer]",vi="[object DataView]",wi="[object Float32Array]",ki="[object Float64Array]",Ii="[object Int8Array]",Ai="[object Int16Array]",Si="[object Int32Array]",xi="[object Uint8Array]",Ci="[object Uint8ClampedArray]",Ei="[object Uint16Array]",Mi="[object Uint32Array]",v={};v[wi]=v[ki]=v[Ii]=v[Ai]=v[Si]=v[xi]=v[Ci]=v[Ei]=v[Mi]=!0;v[ai]=v[oi]=v[yi]=v[si]=v[vi]=v[li]=v[ui]=v[ci]=v[di]=v[gi]=v[pi]=v[fi]=v[mi]=v[bi]=v[hi]=!1;function ji(e){return Le(e)&&Xr(e.length)&&!!v[ne(e)]}var $i=ji;function _i(e){return function(t){return e(t)}}var Li=_i,pt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,te=pt&&typeof module=="object"&&module&&!module.nodeType&&module,Pi=te&&te.exports===pt,Ie=Pi&&lt.process,Ni=function(){try{var e=te&&te.require&&te.require("util").types;return e||Ie&&Ie.binding&&Ie.binding("util")}catch{}}(),We=Ni,Ke=We&&We.isTypedArray,Du=Ke?Li(Ke):$i,Ti=Object.prototype,zu=Ti.hasOwnProperty;function Oi(e,t){return function(r){return e(t(r))}}var Di=Oi,Ru=Di(Object.keys,Object),zi=Object.prototype,Fu=zi.hasOwnProperty,Ri=V(Object,"create"),re=Ri;function Fi(){this.__data__=re?re(null):{},this.size=0}var Vi=Fi;function Ui(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Bi=Ui,Gi="__lodash_hash_undefined__",qi=Object.prototype,Hi=qi.hasOwnProperty;function Zi(e){var t=this.__data__;if(re){var r=t[e];return r===Gi?void 0:r}return Hi.call(t,e)?t[e]:void 0}var Qi=Zi,Yi=Object.prototype,Wi=Yi.hasOwnProperty;function Ki(e){var t=this.__data__;return re?t[e]!==void 0:Wi.call(t,e)}var Ji=Ki,Xi="__lodash_hash_undefined__";function en(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=re&&t===void 0?Xi:t,this}var tn=en;function U(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])}}U.prototype.clear=Vi;U.prototype.delete=Bi;U.prototype.get=Qi;U.prototype.has=Ji;U.prototype.set=tn;var Je=U;function rn(){this.__data__=[],this.size=0}var nn=rn;function an(e,t){for(var r=e.length;r--;)if(Wr(e[r][0],t))return r;return-1}var ge=an,on=Array.prototype,sn=on.splice;function ln(e){var t=this.__data__,r=ge(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 un=ln;function cn(e){var t=this.__data__,r=ge(t,e);return r<0?void 0:t[r][1]}var dn=cn;function gn(e){return ge(this.__data__,e)>-1}var pn=gn;function fn(e,t){var r=this.__data__,i=ge(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var mn=fn;function B(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])}}B.prototype.clear=nn;B.prototype.delete=un;B.prototype.get=dn;B.prototype.has=pn;B.prototype.set=mn;var pe=B,bn=V($,"Map"),ie=bn;function hn(){this.size=0,this.__data__={hash:new Je,map:new(ie||pe),string:new Je}}var yn=hn;function vn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var wn=vn;function kn(e,t){var r=e.__data__;return wn(t)?r[typeof t=="string"?"string":"hash"]:r.map}var fe=kn;function In(e){var t=fe(this,e).delete(e);return this.size-=t?1:0,t}var An=In;function Sn(e){return fe(this,e).get(e)}var xn=Sn;function Cn(e){return fe(this,e).has(e)}var En=Cn;function Mn(e,t){var r=fe(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var jn=Mn;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=yn;G.prototype.delete=An;G.prototype.get=xn;G.prototype.has=En;G.prototype.set=jn;var ft=G;function $n(){this.__data__=new pe,this.size=0}var _n=$n;function Ln(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Pn=Ln;function Nn(e){return this.__data__.get(e)}var Tn=Nn;function On(e){return this.__data__.has(e)}var Dn=On,zn=200;function Rn(e,t){var r=this.__data__;if(r instanceof pe){var i=r.__data__;if(!ie||i.length<zn-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new ft(i)}return r.set(e,t),this.size=r.size,this}var Fn=Rn;function ae(e){var t=this.__data__=new pe(e);this.size=t.size}ae.prototype.clear=_n;ae.prototype.delete=Pn;ae.prototype.get=Tn;ae.prototype.has=Dn;ae.prototype.set=Fn;var Vn=Object.prototype,Vu=Vn.propertyIsEnumerable,Un=V($,"DataView"),Ee=Un,Bn=V($,"Promise"),Me=Bn,Gn=V($,"Set"),je=Gn,Xe="[object Map]",qn="[object Object]",et="[object Promise]",tt="[object Set]",rt="[object WeakMap]",it="[object DataView]",Hn=T(Ee),Zn=T(ie),Qn=T(Me),Yn=T(je),Wn=T(Ce),z=ne;(Ee&&z(new Ee(new ArrayBuffer(1)))!=it||ie&&z(new ie)!=Xe||Me&&z(Me.resolve())!=et||je&&z(new je)!=tt||Ce&&z(new Ce)!=rt)&&(z=function(e){var t=ne(e),r=t==qn?e.constructor:void 0,i=r?T(r):"";if(i)switch(i){case Hn:return it;case Zn:return Xe;case Qn:return et;case Yn:return tt;case Wn:return rt}return t});var Uu=$.Uint8Array,Kn="__lodash_hash_undefined__";function Jn(e){return this.__data__.set(e,Kn),this}var Xn=Jn;function ea(e){return this.__data__.has(e)}var ta=ea;function $e(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new ft;++t<r;)this.add(e[t])}$e.prototype.add=$e.prototype.push=Xn;$e.prototype.has=ta;var nt=F?F.prototype:void 0,Bu=nt?nt.valueOf:void 0,ra=Object.prototype,Gu=ra.hasOwnProperty,ia=Object.prototype,qu=ia.hasOwnProperty,Hu=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Zu=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Qu=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 na(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 aa(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 oa(e){return e!==void 0}var sa=oa;var me=class bt{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 bt),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))}},la=class ht{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new ht),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 ua(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let o=[],a=s=>{o.push(s)},l=async(s,u,d)=>{if(s>=t.length)return r(u,d);let p=t[s],g=async(m,b)=>l(s+1,m,b),f={...d,addDisposer:a};return p(u,f,g)},c={...n,addDisposer:a};return{result:await l(0,i,c),dispose:async()=>{for(let s=o.length-1;s>=0;s--)try{await o[s]()}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 da=ca;var Ae="ly.img.ai.temp";async function ga(e,t){return e.engine.asset.findAllSources().includes(Ae)||e.engine.asset.addLocalSource(Ae),e.engine.asset.apply(Ae,t)}function pa(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 yt(){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 fa(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 l=document.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight;let c=l.getContext("2d");if(!c){document.body.removeChild(a),o(new Error("Failed to create canvas context"));return}c.drawImage(a,0,0,l.width,l.height);try{let s=l.toDataURL(r,i);document.body.removeChild(a),n(s)}catch(s){document.body.removeChild(a),o(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{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 ma(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 Pe(e){return e instanceof Error&&e.name==="AbortError"}function ba(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function vt(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
- Plugin "${t}" is using version ${r}, but other AI plugins are using version ${o}.
1
+ var dr=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,a=n+i,o=t.slice(n,a),s=a<t.length?r+1:void 0;return{assets:o,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(a=>{a.groups&&Array.isArray(a.groups)&&a.groups.forEach(o=>i.add(o))});let n=[...i];e(n)},r.onerror=()=>{t(new Error(`Failed to get groups: ${r.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),r=t.objectStore(this.assetStoreName),i=new Set;R(e,a=>{i.add(a)}),setTimeout(()=>{this.storeBlobUrls([...i])});let n={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};r.put(n),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.assetStoreName,"readwrite");r.objectStore(this.assetStoreName).delete(e),r.oncomplete=()=>{R(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let s=a.meta?.insertedAt||a._insertedAt||Date.now(),c=o.meta?.insertedAt||o._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,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return R(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),R(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),s=e.label?.toLowerCase()??"",c=e.tags?.map(l=>l.toLowerCase())??[];if(!o.every(l=>s.includes(l)||c.some(u=>u.includes(l))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(s=>e.tags?.includes(s))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,s)=>{let c,l;return i==="id"?(c=o.id,l=s.id):(c=o.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"&&a.reverse(),n&&a.sort((o,s)=>o.active&&!s.active?-1:!o.active&&s.active?1:0)),a}};function R(e,t,r=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let i=0;i<e.length;i++){let n=r?`${r}[${i}]`:`[${i}]`;if(typeof e[i]=="string"&&e[i].startsWith("blob:")){let a=t(e[i],n);typeof a=="string"&&(e[i]=a)}else e[i]=R(e[i],t,n)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],a=r?`${r}.${i}`:i;if(typeof n=="string"&&n.startsWith("blob:")){let o=t(n,a);typeof o=="string"&&(e[i]=o)}else e[i]=R(n,t,a)}return e}var gr=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:a}=e,o=n*a,s=o+a,c=i.slice(o,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 pr=typeof global=="object"&&global&&global.Object===Object&&global,ft=pr,fr=typeof self=="object"&&self&&self.Object===Object&&self,br=ft||fr||Function("return this")(),E=br,mr=E.Symbol,F=mr,bt=Object.prototype,hr=bt.hasOwnProperty,yr=bt.toString,X=F?F.toStringTag:void 0;function vr(e){var t=hr.call(e,X),r=e[X];try{e[X]=void 0;var i=!0}catch{}var n=yr.call(e);return i&&(t?e[X]=r:delete e[X]),n}var wr=vr,kr=Object.prototype,Ir=kr.toString;function Ar(e){return Ir.call(e)}var Sr=Ar,xr="[object Null]",Cr="[object Undefined]",Ke=F?F.toStringTag:void 0;function Er(e){return e==null?e===void 0?Cr:xr:Ke&&Ke in Object(e)?wr(e):Sr(e)}var ae=Er;function Mr(e){return e!=null&&typeof e=="object"}var ze=Mr,Ru=Array.isArray;function jr(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var mt=jr,$r="[object AsyncFunction]",Lr="[object Function]",_r="[object GeneratorFunction]",Pr="[object Proxy]";function Nr(e){if(!mt(e))return!1;var t=ae(e);return t==Lr||t==_r||t==$r||t==Pr}var Tr=Nr,Dr=E["__core-js_shared__"],Ee=Dr,Je=function(){var e=/[^.]+$/.exec(Ee&&Ee.keys&&Ee.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Or(e){return!!Je&&Je in e}var zr=Or,Rr=Function.prototype,Fr=Rr.toString;function Vr(e){if(e!=null){try{return Fr.call(e)}catch{}try{return e+""}catch{}}return""}var T=Vr,Ur=/[\\^$.*+?()[\]{}|]/g,Br=/^\[object .+?Constructor\]$/,Gr=Function.prototype,qr=Object.prototype,Hr=Gr.toString,Zr=qr.hasOwnProperty,Qr=RegExp("^"+Hr.call(Zr).replace(Ur,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Yr(e){if(!mt(e)||zr(e))return!1;var t=Tr(e)?Qr:Br;return t.test(T(e))}var Wr=Yr;function Kr(e,t){return e?.[t]}var Jr=Kr;function Xr(e,t){var r=Jr(e,t);return Wr(r)?r:void 0}var V=Xr,ei=V(E,"WeakMap"),_e=ei;function ti(e,t){return e===t||e!==e&&t!==t}var ri=ti,ii=9007199254740991;function ni(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ii}var oi=ni,Fu=Object.prototype,ai="[object Arguments]";function li(e){return ze(e)&&ae(e)==ai}var Xe=li,ht=Object.prototype,si=ht.hasOwnProperty,ui=ht.propertyIsEnumerable,Vu=Xe(function(){return arguments}())?Xe:function(e){return ze(e)&&si.call(e,"callee")&&!ui.call(e,"callee")},yt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,et=yt&&typeof module=="object"&&module&&!module.nodeType&&module,ci=et&&et.exports===yt,tt=ci?E.Buffer:void 0,Uu=tt?tt.isBuffer:void 0,di="[object Arguments]",gi="[object Array]",pi="[object Boolean]",fi="[object Date]",bi="[object Error]",mi="[object Function]",hi="[object Map]",yi="[object Number]",vi="[object Object]",wi="[object RegExp]",ki="[object Set]",Ii="[object String]",Ai="[object WeakMap]",Si="[object ArrayBuffer]",xi="[object DataView]",Ci="[object Float32Array]",Ei="[object Float64Array]",Mi="[object Int8Array]",ji="[object Int16Array]",$i="[object Int32Array]",Li="[object Uint8Array]",_i="[object Uint8ClampedArray]",Pi="[object Uint16Array]",Ni="[object Uint32Array]",k={};k[Ci]=k[Ei]=k[Mi]=k[ji]=k[$i]=k[Li]=k[_i]=k[Pi]=k[Ni]=!0;k[di]=k[gi]=k[Si]=k[pi]=k[xi]=k[fi]=k[bi]=k[mi]=k[hi]=k[yi]=k[vi]=k[wi]=k[ki]=k[Ii]=k[Ai]=!1;function Ti(e){return ze(e)&&oi(e.length)&&!!k[ae(e)]}var Di=Ti;function Oi(e){return function(t){return e(t)}}var zi=Oi,vt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ie=vt&&typeof module=="object"&&module&&!module.nodeType&&module,Ri=ie&&ie.exports===vt,Me=Ri&&ft.process,Fi=function(){try{var e=ie&&ie.require&&ie.require("util").types;return e||Me&&Me.binding&&Me.binding("util")}catch{}}(),rt=Fi,it=rt&&rt.isTypedArray,Bu=it?zi(it):Di,Vi=Object.prototype,Gu=Vi.hasOwnProperty;function Ui(e,t){return function(r){return e(t(r))}}var Bi=Ui,qu=Bi(Object.keys,Object),Gi=Object.prototype,Hu=Gi.hasOwnProperty,qi=V(Object,"create"),ne=qi;function Hi(){this.__data__=ne?ne(null):{},this.size=0}var Zi=Hi;function Qi(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Yi=Qi,Wi="__lodash_hash_undefined__",Ki=Object.prototype,Ji=Ki.hasOwnProperty;function Xi(e){var t=this.__data__;if(ne){var r=t[e];return r===Wi?void 0:r}return Ji.call(t,e)?t[e]:void 0}var en=Xi,tn=Object.prototype,rn=tn.hasOwnProperty;function nn(e){var t=this.__data__;return ne?t[e]!==void 0:rn.call(t,e)}var on=nn,an="__lodash_hash_undefined__";function ln(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ne&&t===void 0?an:t,this}var sn=ln;function U(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])}}U.prototype.clear=Zi;U.prototype.delete=Yi;U.prototype.get=en;U.prototype.has=on;U.prototype.set=sn;var nt=U;function un(){this.__data__=[],this.size=0}var cn=un;function dn(e,t){for(var r=e.length;r--;)if(ri(e[r][0],t))return r;return-1}var he=dn,gn=Array.prototype,pn=gn.splice;function fn(e){var t=this.__data__,r=he(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():pn.call(t,r,1),--this.size,!0}var bn=fn;function mn(e){var t=this.__data__,r=he(t,e);return r<0?void 0:t[r][1]}var hn=mn;function yn(e){return he(this.__data__,e)>-1}var vn=yn;function wn(e,t){var r=this.__data__,i=he(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var kn=wn;function B(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])}}B.prototype.clear=cn;B.prototype.delete=bn;B.prototype.get=hn;B.prototype.has=vn;B.prototype.set=kn;var ye=B,In=V(E,"Map"),oe=In;function An(){this.size=0,this.__data__={hash:new nt,map:new(oe||ye),string:new nt}}var Sn=An;function xn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Cn=xn;function En(e,t){var r=e.__data__;return Cn(t)?r[typeof t=="string"?"string":"hash"]:r.map}var ve=En;function Mn(e){var t=ve(this,e).delete(e);return this.size-=t?1:0,t}var jn=Mn;function $n(e){return ve(this,e).get(e)}var Ln=$n;function _n(e){return ve(this,e).has(e)}var Pn=_n;function Nn(e,t){var r=ve(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Tn=Nn;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=Sn;G.prototype.delete=jn;G.prototype.get=Ln;G.prototype.has=Pn;G.prototype.set=Tn;var wt=G;function Dn(){this.__data__=new ye,this.size=0}var On=Dn;function zn(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Rn=zn;function Fn(e){return this.__data__.get(e)}var Vn=Fn;function Un(e){return this.__data__.has(e)}var Bn=Un,Gn=200;function qn(e,t){var r=this.__data__;if(r instanceof ye){var i=r.__data__;if(!oe||i.length<Gn-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new wt(i)}return r.set(e,t),this.size=r.size,this}var Hn=qn;function le(e){var t=this.__data__=new ye(e);this.size=t.size}le.prototype.clear=On;le.prototype.delete=Rn;le.prototype.get=Vn;le.prototype.has=Bn;le.prototype.set=Hn;var Zn=Object.prototype,Zu=Zn.propertyIsEnumerable,Qn=V(E,"DataView"),Pe=Qn,Yn=V(E,"Promise"),Ne=Yn,Wn=V(E,"Set"),Te=Wn,ot="[object Map]",Kn="[object Object]",at="[object Promise]",lt="[object Set]",st="[object WeakMap]",ut="[object DataView]",Jn=T(Pe),Xn=T(oe),eo=T(Ne),to=T(Te),ro=T(_e),z=ae;(Pe&&z(new Pe(new ArrayBuffer(1)))!=ut||oe&&z(new oe)!=ot||Ne&&z(Ne.resolve())!=at||Te&&z(new Te)!=lt||_e&&z(new _e)!=st)&&(z=function(e){var t=ae(e),r=t==Kn?e.constructor:void 0,i=r?T(r):"";if(i)switch(i){case Jn:return ut;case Xn:return ot;case eo:return at;case to:return lt;case ro:return st}return t});var Qu=E.Uint8Array,io="__lodash_hash_undefined__";function no(e){return this.__data__.set(e,io),this}var oo=no;function ao(e){return this.__data__.has(e)}var lo=ao;function De(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new wt;++t<r;)this.add(e[t])}De.prototype.add=De.prototype.push=oo;De.prototype.has=lo;var ct=F?F.prototype:void 0,Yu=ct?ct.valueOf:void 0,so=Object.prototype,Wu=so.hasOwnProperty,uo=Object.prototype,Ku=uo.hasOwnProperty,Ju=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Xu=new RegExp(/[A-Fa-f0-9]{1}/,"g"),ec=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function kt(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Uint8Array(n),o=new Blob([a],{type:r});return URL.createObjectURL(o)}else return e}async function co(e,t){let r=await kt(e,t);return new Promise((i,n)=>{let a=new Image;a.onload=()=>{i({width:a.width,height:a.height})},a.onerror=n,a.src=r})}async function go(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return kt(i,t)}function po(e){return e!==void 0}var fo=po;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 a=t.default;return typeof a!="function"?a:a(r)}return i!==void 0?i:n}var we=class It{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 It),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))}},bo=class At{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new At),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 mo(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=l=>{a.push(l)},s=async(l,u,d)=>{if(l>=t.length)return r(u,d);let f=t[l],g=async(p,h)=>s(l+1,p,h),m={...d,addDisposer:o};return f(u,m,g)},c={...n,addDisposer:o};return{result:await s(0,i,c),dispose:async()=>{for(let l=a.length-1;l>=0;l--)try{await a[l]()}catch(u){console.error("Error in disposer:",u)}a.length=0}}}}function ho({enable:e=!0}){return async(t,r,i)=>{if(!e)return i(t,r);console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(t,null,2));let n,a=Date.now();try{return n=await i(t,r),n}finally{n!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(n,null,2))),console.groupEnd()}}}var yo=ho;var je="ly.img.ai.temp";async function vo(e,t){return e.engine.asset.findAllSources().includes(je)||e.engine.asset.addLocalSource(je),e.engine.asset.apply(je,t)}function wo(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 St(){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 ko(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let s=document.createElement("canvas");s.width=o.videoWidth,s.height=o.videoHeight;let c=s.getContext("2d");if(!c){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}c.drawImage(o,0,0,s.width,s.height);try{let l=s.toDataURL(r,i);document.body.removeChild(o),n(l)}catch(l){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${l instanceof Error?l.message:String(l)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function Io(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 Re(e){return e instanceof Error&&e.name==="AbortError"}function Ao(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function xt(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected!
2
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
3
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 ha(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 wt=ha;function ya(){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 kt=ya;function va(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),wa(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:pa(e)})}function wa(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 at=va,ka="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Ne=ka;function Ia(e,t,r){switch(t){case"image":return Aa(e,r[t]);case"video":return Sa(e,r[t]);case"sticker":return xa(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Aa(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ne,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function Sa(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Ne,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function xa(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ne,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var Ca=Ia;async function Ea(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 Ma(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 ja(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 $a(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 _a(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Ma(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 ja(e,t,r){let i=t.width,n=t.height,o=await fa(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 $a(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 _a(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 It=Ea;function La(e){switch(e.userFlow){case"placeholder":return Na(e);case"generation-only":return Pa(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function Pa(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,o=await e.getBlockInput(i);if(L(t,r))return{status:"aborted"};let a=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(L(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(L(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let l=yt(),c=await It(l,n,o,a.output),s={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,s)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return a}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Na(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let o=e.kind,a=await e.getBlockInput(n);if(L(t,r))return{status:"aborted"};let l=yt(),c=Ca(l,o,a);if(i=await ga(t,c),L(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,p),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let s=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(L(t,r,i))return{status:"aborted"};if(s.status!=="success")return s;if(s.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let u=await It(l,o,a,s.output);if(L(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),L(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"}),s}catch(o){return i!=null&&t.engine.block.isValid(i)&&(Pe(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 L(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var Ta=La;function Te(e){return`${e}.generating`}function Oa(e){return`${e}.abort`}function Da(e,t,r,i,n,o,a){let{builder:l,experimental:c}=e,{cesdk:s,includeHistoryLibrary:u=!0}=o,{id:d,output:{abortable:p}}=t,g=c.global(Oa(d),()=>{}),f=c.global(Te(d),!1),m,b=f.value&&p,y=()=>{b&&(g.value(),f.setValue(!1),g.setValue(()=>{}))},S;if(o.requiredInputs!=null&&o.requiredInputs.length>0){let x=i();S=o.requiredInputs.every(k=>!x.input[k])}let A=c.global(`${d}.confirmationDialogId`,void 0);l.Section(`${d}.generate.section`,{children:()=>{l.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:f.value,color:"accent",isDisabled:S,suffix:b?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let x=s.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:k})=>{s.ui.closeDialog(k),A.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:k})=>{y(),s.ui.closeDialog(k),A.setValue(void 0)}}});A.setValue(x)}}:void 0,onClick:async()=>{m=new AbortController;let x=m.signal;await(async()=>{try{f.setValue(!0),g.setValue(()=>{a.debug&&console.log("Aborting generation"),m?.abort()});let k=await Ta({kind:t.kind,generate:r,historyAssetSourceId:o.historyAssetSourceId,userFlow:o.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:x,cesdk:s,debug:a.debug,dryRun:a.dryRun})(i().input);if(k.status==="aborted")return;if(k.status==="error"){at(k.message,{cesdk:s,provider:t,getInput:i});return}if(k.status==="success"&&k.type==="sync"){let M=t.output.notification;za(s,M,()=>({input:i().input,output:k.output}))}}catch(k){if(Pe(k))return;at(k,{cesdk:s,provider:t,getInput:i})}finally{m=void 0,f.setValue(!1),g.setValue(()=>{}),A.value!=null&&(s.ui.closeDialog(A.value),A.setValue(void 0))}})()}}),t.output.generationHintText!=null&&l.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),u&&o.historyAssetLibraryEntryId!=null&&l.Library(`${d}.history.library`,{entries:[o.historyAssetLibraryEntryId]})}function za(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 At=Da;async function Ra({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:o}=e,{id:a}=t,l=r.render;return c=>{let{state:s}=c,u=s(Te(a),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=l(c,{cesdk:o,isGenerating:u});return At(c,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var Fa=Ra;function St(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 X(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=St(e,t.$ref),n={...X(e,i,r)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(n[o]=X(e,t[o],r));return n}if(Array.isArray(t))return t.map(i=>X(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=X(e,t[n],r));return i}return t}function Va(e){return X(e,{...e})}function Ua(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 l of i.type)if(typeof l!="string"||!a.includes(l))return r(`Array of types contains invalid value: ${l}. 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 l=0;l<i[a].length;l++){let c=i[a][l];if(typeof c!="object"||c===null)return r(`Item ${l} 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 l=i.required[a];if(typeof l!="string")return r(`Item ${a} in required array must be a string, got ${typeof l}`)}}return!0}function Ba(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return Ga(e,t).forEach(n=>{let o=n,a=r[n]??void 0;i.push({id:o,schema:a})}),i}function Ga(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=qa(e,t)??n;return r!=null&&typeof r=="function"&&(o=r(o)),[...new Set(o)]}function qa(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 xt=Ba;function N(e,t,r,i){let n=`property.${e.id}${i?`.${i}`:""}`;return[`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}`]}function Ct(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 Et(e,t,r,i,n,o,a){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let l=t,c=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(c){case"string":return t.schema.enum!=null?Ha(e,l,r,i,n,o,a):Mt(e,l,r,i,n,o,a);case"boolean":return jt(e,l,r,i,n,o,a);case"number":case"integer":return $t(e,l,r,i,n,o,a);case"object":return _e(e,l,r,i,n,o,a);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return Za(e,l,r,i,n,o,a);break}default:console.error(`Unsupported property type: ${c}`)}}function _e(e,t,r,i,n,o,a){let l=xt(t.schema??{},i).reduce((c,s)=>{let u=Et(e,s,r,i,n,o,a);return u!=null&&(c[s.id]=u()),c},{});return()=>({id:t.id,type:"object",value:l})}function Mt(e,t,r,i,n,o,a){let{builder:l,experimental:{global:c}}=e,{id:s}=t,u=`${r.id}.${s}`,d=N(t,r,a),p=c(u,t.schema.default??""),g=Qa(t.schema),f=g?.component!=null&&g?.component==="TextArea"?"TextArea":"TextInput";return l[f](u,{inputLabel:d,placeholder:n.i18n?.prompt,...p}),()=>({id:t.id,type:"string",value:p.value})}function Ha(e,t,r,i,n,o,a){let{builder:l,experimental:{global:c}}=e,{id:s}=t,u=`${r.id}.${s}`,d=N(t,r,a),{labels:p,icons:g}=Ct(t.schema),f=(t.schema.enum??[]).map(y=>({id:y,label:N(t,r,a,y),icon:g[y]})),m=t.schema.default!=null?f.find(y=>y.id===t.schema.default)??f[0]:f[0],b=c(u,m);return l.Select(u,{inputLabel:d,values:f,...b}),()=>({id:t.id,type:"string",value:b.value.id})}function jt(e,t,r,i,n,o,a){let{builder:l,experimental:{global:c}}=e,{id:s}=t,u=`${r.id}.${s}`,d=N(t,r,a),p=!!t.schema.default,g=c(u,p);return l.Checkbox(u,{inputLabel:d,...g}),()=>({id:t.id,type:"boolean",value:g.value})}function $t(e,t,r,i,n,o,a){let{builder:l,experimental:{global:c}}=e,{id:s}=t,u=`${r.id}.${s}`,d=N(t,r,a),p=t.schema.minimum,g=t.schema.maximum,f=t.schema.default;f==null&&(p!=null?f=p:g!=null?f=g:f=0);let m=c(u,f);if(p!=null&&g!=null){let b=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(b=t.schema["x-imgly-step"]),l.Slider(u,{inputLabel:d,min:p,max:g,step:b,...m})}else l.NumberInput(u,{inputLabel:d,min:p,max:g,...m});return()=>({id:t.id,type:"integer",value:m.value})}function Za(e,t,r,i,n,o,a){let{builder:l,experimental:{global:c}}=e,{id:s}=t,u=`${r.id}.${s}`,d=N(t,r,a),p=t.schema.anyOf??[],g=[],f={},m={},{labels:b,icons:y}=Ct(t.schema),S={string:Mt,boolean:jt,integer:$t,object:_e},A=(h,j)=>h.$ref?h.$ref.split("/").pop():j.split(".").pop()??j,x=(h,j)=>({id:h,label:N(t,r,a,j),icon:y[j]??y[h]});p.forEach((h,j)=>{let C=`${r.id}.${s}.anyOf[${j}]`;if(h.$ref||h.title){let E=h.$ref?h.$ref.split("/").pop():h.title;f[C]=()=>_e(e,{id:C,schema:{...h,title:b[E]||E}},r,i,n,o,a),g.push(x(C,E))}else if(h.type==="string"&&h.enum)h.enum.forEach(E=>{g.push(x(E,E))});else if(h.type&&S[h.type]){let E=S[h.type];f[C]=()=>E(e,{id:C,schema:{...h,title:h.title}},r,i,n,o,a);let I=A(h,C);g.push(h.type==="string"&&!h.enum?{id:C,label:h.title||I,icon:h.title&&y[h.title]||y[I]}:x(C,I))}});let k=t.schema.default!=null?g.find(h=>h.id===t.schema.default)??g[0]:g[0],M=c(u,k);if(l.Select(u,{inputLabel:d,values:g,...M}),M.value.id in f){let h=f[M.value.id]();m[M.value.id]=h}return()=>{let h=m[M.value.id];return h!=null?{...h(),id:t.id}:{id:t.id,type:"string",value:M.value.id}}}function Qa(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Ya=Et,Wa={"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 ot(e){return e.replace(/_/g," ").replace(/\b3d\b/gi,"3D").replace(/\b2d\b/gi,"2D").replace(/\b\w/g,t=>t.toUpperCase())}function Ka(e,t,r,i){let n={},o=(s,u)=>`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${s}${u?`.${u}`:""}`,a=s=>"x-imgly-enum-labels"in s&&typeof s["x-imgly-enum-labels"]=="object"?s["x-imgly-enum-labels"]:{},l=(s,u,d)=>{s.forEach(p=>{let g=String(p),f=d[g]||ot(g);n[o(u,g)]=f})};e.forEach(s=>{if(s.schema?.title&&(n[o(s.id)]=s.schema.title),s.schema?.enum){let u=a(s.schema);l(s.schema.enum,s.id,u)}if(s.schema?.anyOf&&Array.isArray(s.schema.anyOf)){let u=a(s.schema);s.schema.anyOf.forEach(d=>{let p=d;if(p.enum&&Array.isArray(p.enum))l(p.enum,s.id,u);else if(p.$ref){let g=p.$ref.split("/").pop();g&&u[g]&&(n[o(s.id,g)]=u[g])}else if(p.title){let g=p.title,f=u[g]||ot(g);n[o(s.id,g)]=f}})}});let c={...Wa,...n};Object.keys(c).length>0&&r.cesdk.i18n.setTranslations({en:c})}async function Ja({options:e,provider:t,panelInput:r,config:i},n){let{id:o}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${o}`);let a=Va(r.document),l=St(a,r.inputReference);if(!Ua(l,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let c=l,s=xt(c,r);return Ka(s,t,e,t.kind),u=>{let{builder:d}=u,p=[];d.Section(`${o}.schema.section`,{children:()=>{s.forEach(b=>{let y=Ya(u,b,t,r,e,i,t.kind);y!=null&&(Array.isArray(y)?p.push(...y):p.push(y))})}});let g=p.map(b=>b()),f=b=>b.type==="object"?Object.entries(b.value).reduce((y,[S,A])=>(y[S]=f(A),y),{}):b.value,m=g.reduce((b,y)=>(b[y.id]=f(y),b),{});At(u,t,n,()=>({input:m}),()=>r.getBlockInput(m),{...e,requiredInputs:c.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var Xa=Ja;async function eo(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return Fa(e,t);case"schema":return Xa(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var to=eo;function ro(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 ar(a,r)),a}return i}var io=ro;function no(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 ao=no,Se="@imgly/plugin-ai-generation",oo=`
4
+ Consider updating all AI plugins to the same version for optimal compatibility.`),e.ui.experimental.setGlobalStateValue(n,!0))):e.ui.experimental.setGlobalStateValue(i,r)}catch(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}function So(e){let{cesdk:t,panelId:r}=e;r.startsWith("ly.img.ai.")||console.warn(`Dock components for AI generation should open a panel with an id starting with "ly.img.ai." \u2013 "${r}" was provided.`);let i=`${r}.dock`;t.ui.registerComponent(i,({builder:n})=>{let a=t.ui.isPanelOpen(r);n.Button(`${r}.dock.button`,{label:`${r}.dock.label`,isSelected:a,icon:"@imgly/Sparkle",onClick:()=>{t.ui.findAllPanels().forEach(o=>{o.startsWith("ly.img.ai.")&&t.ui.closePanel(o),!a&&o==="//ly.img.panel/assetLibrary"&&t.ui.closePanel(o)}),a?t.ui.closePanel(r):t.ui.openPanel(r)}})})}var Ct=So;function xo(){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 Et=xo;function Co(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),Eo(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:wo(e)})}function Eo(e,t,r){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.failed",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"error",message:n,action:a}),!0}var dt=Co,Mo="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Fe=Mo;function jo(e,t,r){switch(t){case"image":return $o(e,r[t]);case"video":return Lo(e,r[t]);case"sticker":return _o(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function $o(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Fe,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function Lo(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Fe,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function _o(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Fe,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var Po=jo;async function No(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 To(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 Do(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 Oo(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 zo(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function To(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 Do(e,t,r){let i=t.width,n=t.height,a=await ko(r.url,0);return{id:e,label:t.label,meta:{uri:r.url,thumbUri:a,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:n}}}function Oo(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 zo(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 Mt=No;function Ro(e){switch(e.userFlow){case"placeholder":return Vo(e);case"generation-only":return Fo(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function Fo(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(L(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(L(t,r))return{status:"aborted"};if(o.status!=="success")return o;if(o.type==="async")throw new Error("Async generation is not supported in this context yet.");if(L(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let s=St(),c=await Mt(s,n,a,o.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 o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Vo(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(L(t,r))return{status:"aborted"};let s=St(),c=Po(s,a,o);if(i=await vo(t,c),L(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,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(L(t,r,i))return{status:"aborted"};if(l.status!=="success")return 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 Mt(s,a,o,l.output);if(L(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),L(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(a){return i!=null&&t.engine.block.isValid(i)&&(Re(a)?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),{status:"error",message:a instanceof Error?a.message:String(a)}}}}function L(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var Uo=Ro;function Ve(e){return`${e}.generating`}function Bo(e){return`${e}.abort`}function Go(e,t,r,i,n,a,o){let{builder:s,experimental:c}=e,{cesdk:l,includeHistoryLibrary:u=!0}=a,{id:d,output:{abortable:f}}=t,g=c.global(Bo(d),()=>{}),m=c.global(Ve(d),!1),p,h=m.value&&f,y=()=>{h&&(g.value(),m.setValue(!1),g.setValue(()=>{}))},v;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let x=i();v=a.requiredInputs.every(w=>!x.input[w])}let A=c.global(`${d}.confirmationDialogId`,void 0);s.Section(`${d}.generate.section`,{children:()=>{s.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:m.value,color:"accent",isDisabled:v,suffix:h?{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:w})=>{l.ui.closeDialog(w),A.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:w})=>{y(),l.ui.closeDialog(w),A.setValue(void 0)}}});A.setValue(x)}}:void 0,onClick:async()=>{p=new AbortController;let x=p.signal;await(async()=>{try{m.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),p?.abort()});let w=await Uo({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:x,cesdk:l,debug:o.debug,dryRun:o.dryRun})(i().input);if(w.status==="aborted")return;if(w.status==="error"){dt(w.message,{cesdk:l,provider:t,getInput:i});return}if(w.status==="success"&&w.type==="sync"){let C=t.output.notification;qo(l,C,()=>({input:i().input,output:w.output}))}}catch(w){if(Re(w))return;dt(w,{cesdk:l,provider:t,getInput:i})}finally{p=void 0,m.setValue(!1),g.setValue(()=>{}),A.value!=null&&(l.ui.closeDialog(A.value),A.setValue(void 0))}})()}}),t.output.generationHintText!=null&&s.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),u&&a.historyAssetLibraryEntryId!=null&&s.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function qo(e,t,r){let i=t?.success;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.success",a=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(r()):i.action.label,onClick:()=>{i?.action?.onClick(r())}}:void 0;return e.ui.showNotification({type:"success",message:n,action:a,duration:i.duration}),!0}var jt=Go;async function Ho({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,s=r.render;return c=>{let{state:l}=c,u=l(Ve(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:f}=s(c,{cesdk:a,isGenerating:u});return jt(c,t,n,d,f,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var Zo=Ho;function $t(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=$t(e,t.$ref),n={...te(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=te(e,t[a],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 Qo(e){return te(e,{...e})}function Yo(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let s of i.type)if(typeof s!="string"||!o.includes(s))return r(`Array of types contains invalid value: ${s}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let s=0;s<i[o].length;s++){let c=i[o][s];if(typeof c!="object"||c===null)return r(`Item ${s} in ${o} 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 a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let s=i.required[o];if(typeof s!="string")return r(`Item ${o} in required array must be a string, got ${typeof s}`)}}return!0}function Wo(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return Ko(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function Ko(e,t){let r=t.order;if(r!=null&&Array.isArray(r))return r;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,n=Object.keys(i),a=Jo(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function Jo(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 Lt=Wo;function N(e,t,r,i){let n=`property.${e.id}${i?`.${i}`:""}`;return[`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}`]}function _t(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 Pt(e,t,r,i,n,a,o,s){if(t.schema==null)if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null){let u={...e,providerConfig:s,config:a};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:a};return i.renderCustomProperty[t.id](u,t)}switch(l){case"string":return t.schema.enum!=null?Xo(e,c,r,i,n,a,o,s):Nt(e,c,r,i,n,a,o,s);case"boolean":return Tt(e,c,r,i,n,a,o,s);case"number":case"integer":return Dt(e,c,r,i,n,a,o,s);case"object":return Oe(e,c,r,i,n,a,o,s);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return ea(e,c,r,i,n,a,o,s);break}default:console.error(`Unsupported property type: ${l}`)}}function Oe(e,t,r,i,n,a,o,s){let c=Lt(t.schema??{},i).reduce((l,u)=>{let d=Pt(e,u,r,i,n,a,o,s);return d!=null&&(l[u.id]=d()),l},{});return()=>({id:t.id,type:"object",value:c})}function Nt(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=N(t,r,o),m=se(u,n.cesdk),p=s?.properties?.[d]??a.properties?.[d],h=ue(d,p,m,t.schema.default,""),y=l(f,h),v=ta(t.schema),A=v?.component!=null&&v?.component==="TextArea"?"TextArea":"TextInput";return c[A](f,{inputLabel:g,placeholder:n.i18n?.prompt,...y}),()=>({id:t.id,type:"string",value:y.value})}function Xo(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=N(t,r,o),{labels:m,icons:p}=_t(t.schema),h=(t.schema.enum??[]).map(C=>({id:C,label:N(t,r,o,C),icon:p[C]})),y=se(u,n.cesdk),v=s?.properties?.[d]??a.properties?.[d],A=ue(d,v,y,t.schema.default,h[0]?.id),x=A!=null?h.find(C=>C.id===A)??h[0]:h[0],w=l(f,x);return c.Select(f,{inputLabel:g,values:h,...w}),()=>({id:t.id,type:"string",value:w.value.id})}function Tt(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=N(t,r,o),m=se(u,n.cesdk),p=s?.properties?.[d]??a.properties?.[d],h=!!ue(d,p,m,t.schema.default,!1),y=l(f,h);return c.Checkbox(f,{inputLabel:g,...y}),()=>({id:t.id,type:"boolean",value:y.value})}function Dt(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=N(t,r,o),m=t.schema.minimum,p=t.schema.maximum,h=se(u,n.cesdk),y=s?.properties?.[d]??a.properties?.[d],v=t.schema.default;v==null&&(m!=null?v=m:p!=null?v=p:v=0);let A=ue(d,y,h,v,v),x=l(f,A);if(m!=null&&p!=null){let w=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(w=t.schema["x-imgly-step"]),c.Slider(f,{inputLabel:g,min:m,max:p,step:w,...x})}else c.NumberInput(f,{inputLabel:g,min:m,max:p,...x});return()=>({id:t.id,type:"integer",value:x.value})}function ea(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,f=`${r.id}.${d}`,g=N(t,r,o),m=t.schema.anyOf??[],p=[],h={},y={},{labels:v,icons:A}=_t(t.schema),x=se(u,n.cesdk),w=s?.properties?.[d]??a.properties?.[d],C={string:Nt,boolean:Tt,integer:Dt,object:Oe},xe=(b,P)=>b.$ref?b.$ref.split("/").pop():P.split(".").pop()??P,K=(b,P)=>({id:b,label:N(t,r,o,P),icon:A[P]??A[b]});m.forEach((b,P)=>{let j=`${r.id}.${d}.anyOf[${P}]`;if(b.$ref||b.title){let $=b.$ref?b.$ref.split("/").pop():b.title;h[j]=()=>Oe(e,{id:j,schema:{...b,title:v[$]||$}},r,i,n,a,o,s),p.push(K(j,$))}else if(b.type==="string"&&b.enum)b.enum.forEach($=>{p.push(K($,$))});else if(b.type&&C[b.type]){let $=C[b.type];h[j]=()=>$(e,{id:j,schema:{...b,title:b.title}},r,i,n,a,o,s);let Ce=xe(b,j);p.push(b.type==="string"&&!b.enum?{id:j,label:b.title||Ce,icon:b.title&&A[b.title]||A[Ce]}:K(j,Ce))}});let J=ue(d,w,x,t.schema.default,null),me=J!=null?p.find(b=>b.id===J)??p[0]:p[0],S=l(f,me);if(c.Select(f,{inputLabel:g,values:p,...S}),S.value.id in h){let b=h[S.value.id]();y[S.value.id]=b}return()=>{let b=y[S.value.id];return b!=null?{...b(),id:t.id}:{id:t.id,type:"string",value:S.value.id}}}function ta(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var ra=Pt,ia={"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 gt(e){return e.replace(/_/g," ").replace(/\b3d\b/gi,"3D").replace(/\b2d\b/gi,"2D").replace(/\b\w/g,t=>t.toUpperCase())}function na(e,t,r,i){let n={},a=(l,u)=>`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${l}${u?`.${u}`:""}`,o=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]||gt(g);n[a(u,g)]=m})};e.forEach(l=>{if(l.schema?.title&&(n[a(l.id)]=l.schema.title),l.schema?.enum){let u=o(l.schema);s(l.schema.enum,l.id,u)}if(l.schema?.anyOf&&Array.isArray(l.schema.anyOf)){let u=o(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[a(l.id,g)]=u[g])}else if(f.title){let g=f.title,m=u[g]||gt(g);n[a(l.id,g)]=m}})}});let c={...ia,...n};Object.keys(c).length>0&&r.cesdk.i18n.setTranslations({en:c})}async function oa({options:e,provider:t,panelInput:r,config:i,providerConfig:n},a){let{id:o}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${o}`);let s=Qo(r.document),c=$t(s,r.inputReference);if(!Yo(c,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let l=c,u=Lt(l,r);return na(u,t,e,t.kind),d=>{let{builder:f}=d,g=[];f.Section(`${o}.schema.section`,{children:()=>{u.forEach(y=>{let v=ra(d,y,t,r,e,i,t.kind,n);v!=null&&(Array.isArray(v)?g.push(...v):g.push(v))})}});let m=g.map(y=>y()),p=y=>y.type==="object"?Object.entries(y.value).reduce((v,[A,x])=>(v[A]=p(x),v),{}):y.value,h=m.reduce((y,v)=>(y[v.id]=p(v),y),{});jt(d,t,a,()=>({input:h}),()=>r.getBlockInput(h),{...e,requiredInputs:l.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var aa=oa;async function la(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return Zo(e,t);case"schema":return aa(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var sa=la;function ua(e){let{provider:t,options:{engine:r}}=e,i=t.output.history??"@imgly/local";if(i==null||i===!1)return;let n=r.asset.findAllSources();function a(){let o=`${t.id}.history`;for(;n.includes(o);)o+=`-${Math.random().toString(36).substring(2,6)}`;return o}if(i==="@imgly/local"){let o=a();return r.asset.addLocalSource(o),o}if(i==="@imgly/indexedDB"){let o=a();return r.asset.addSource(new dr(o,r)),o}return i}var ca=ua;function da(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 ga=da,$e="@imgly/plugin-ai-generation",pa=`
5
5
  <svg>
6
6
  <symbol
7
7
  fill="none"
@@ -19,7 +19,7 @@ Consider updating all AI plugins to the same version for optimal compatibility.`
19
19
  fill="none"
20
20
  xmlns="http://www.w3.org/2000/svg"
21
21
  viewBox="0 0 24 24"
22
- id="${Se}/image"
22
+ id="${$e}/image"
23
23
  >
24
24
  <path d="M3 16.5V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V6C21 4.34315 19.6569 3 18 3L17.999 5C18.5513 5 19 5.44772 19 6V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V16.5H3Z" fill="currentColor"/>
25
25
  <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
@@ -31,7 +31,7 @@ Consider updating all AI plugins to the same version for optimal compatibility.`
31
31
  fill="none"
32
32
  xmlns="http://www.w3.org/2000/svg"
33
33
  viewBox="0 0 24 24"
34
- id="${Se}/video"
34
+ id="${$e}/video"
35
35
  >
36
36
  <path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
37
37
  <path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
@@ -42,7 +42,7 @@ Consider updating all AI plugins to the same version for optimal compatibility.`
42
42
  fill="none"
43
43
  xmlns="http://www.w3.org/2000/svg"
44
44
  viewBox="0 0 24 24"
45
- id="${Se}/audio"
45
+ id="${$e}/audio"
46
46
  >
47
47
  <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
48
48
  <path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
@@ -62,42 +62,19 @@ Consider updating all AI plugins to the same version for optimal compatibility.`
62
62
 
63
63
  </symbol>
64
64
  </svg>
65
- `,so=oo;function lo(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 _t(2e3),await uo(t,e,r)):i(t,r)}async function uo(e,t,r){switch(t.kind){case"image":return co(e,t,r);case"video":return go(e,t,r);case"text":return po(e,t,r);case"audio":return mo(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[l]=t.blockIds,c=await aa(l,r),s=await na(c,r);i=s.width,n=s.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${o.replace(" ","+").replace(`
66
- `,"+")}`}}async function go(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function po(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,l=a.match(/text:\s*"([^"]+)"/i)||a.match(/content:\s*"([^"]+)"/i)||a.match(/"([^"]+)"/);l&&l[1]&&(i=l[1])}let n=i.length||50,o="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")o=J(n,"translation");else if("type"in e&&typeof e.type=="string"){let a=e.type;o=J(n,a)}else"customPrompt"in e?o=J(n,"custom"):o=J(n,"improved");else o=J(n,"generated");return fo(o,r.abortSignal)}async function*fo(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 _t(100)}return{kind:"text",text:e}}function J(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,l="";if(n<=a.length)l=a.substring(0,n);else{l=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."],s=0;for(;l.length<n;){let u=c[s%c.length];if(l.length+u.length<=n)l+=u;else{l+=u.substring(0,n-l.length);break}s++}}return r+l}async function mo(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:bo(220,i),duration:i,thumbnailUrl:void 0}}function bo(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 ho(i,44100)}function ho(e,t){let r=e.length,i=2,n=1,o=n*i,a=t*o,l=r*i,c=44+l,s=new ArrayBuffer(c),u=new DataView(s),d=(m,b)=>{for(let y=0;y<b.length;y++)u.setUint8(m+y,b.charCodeAt(y))};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,l,!0);let p=44;for(let m=0;m<r;m++){let b=Math.max(-1,Math.min(1,e[m])),y=Math.round(b*32767);u.setInt16(p,y,!0),p+=2}let g=new Uint8Array(s),f="";for(let m=0;m<g.length;m++)f+=String.fromCharCode(g[m]);return`data:audio/wav;base64,${btoa(f)}`}async function _t(e){return new Promise(t=>{setTimeout(t,e)})}var yo=lo,vo="USER_CANCEL";function wo(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=ua([...e.provider.output.middleware??[],...r?.middlewares??[],da({enable:r?.debug}),yo({enable:r?.dryRun,kind:e.provider.kind})]);try{let{result:n}=await i(e.provider.output.generate)(t,{abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk});return r?.abortSignal?.aborted?{status:"aborted"}:n instanceof Error?{status:"error",message:n.message}:n==null?{status:"error",message:"No output generated"}:ma(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return Pe(n)?{status:"aborted",message:n.message}:n===vo?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var ko=wo;async function Io(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};if(await t.initialize?.({...r,engine:r.cesdk.engine}),t.input?.quickActions?.supported){let d=t.kind,p=me.get();Object.keys(t.input.quickActions.supported).forEach(g=>{if(!p.getBy({id:g,type:"quick"})[0]){let f=`ly.img.plugin-ai-${d}-generation-web.quickAction.${g}`;r.cesdk.feature.enable(f,!0)}})}let a=io(o),l=ao(o,a);o.options.historyAssetSourceId=a,o.options.historyAssetLibraryEntryId=l;let c=ko({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),s=await to(o,c);ba(r.cesdk,"@imgly/plugin-ai-generation",so);let u={provider:t,panel:{builderRenderFunction:s},history:{assetSourceId:a,assetLibraryEntryId:l},generate:c};return la.get().register(u),u}var xe=Io;function Ao(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 or(n,r,i);return r.engine.asset.addSource(o),o.id}var So=Ao;function ee(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 xo(e,t,r,i){let{cesdk:n}=r;n.setTranslations({en:{"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(Array.isArray(t)){let s=await Promise.all(t.map(u=>xe(e,u,r,i)));a.push(...s),o=Eo({kind:e,prefix:e,providerInitializationResults:a,cesdk:n})}else{let s=await Promise.all(t.fromText.map(d=>xe(e,d,r,i)));a.push(...s);let u=await Promise.all(t.fromImage.map(d=>xe(e,d,r,i)));a.push(...u),o=Co({kind:e,prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:s,initializedFromImageProviders:u,cesdk:n})}let l=So({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(s=>s.history?.assetSourceId).filter(sa)}),c;return l!=null&&(c=l,r.cesdk.ui.addAssetLibraryEntry({id:c,sourceIds:[l],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"})),{panel:{builderRenderFunction:o},history:{assetSourceId:l,assetLibraryEntryId:c},providerInitializationResults:a}}function Co({kind:e,prefix:t,initializedFromTextProviders:r,initializedFromImageProviders:i,cesdk:n}){let o=r.length>0&&i.length>0;return a=>{let{builder:l,experimental:c,engine:s}=a,u=`ly.img.plugin-ai-${e}-generation-web.fromText`,d=n.feature.isEnabled(u,{engine:s}),p=`ly.img.plugin-ai-${e}-generation-web.fromImage`,g=n.feature.isEnabled(p,{engine:s}),f;d&&r.length>0&&(!g||i.length===0)?f="fromText":g&&i.length>0&&(!d||r.length===0)?f="fromImage":d&&g&&o&&(f="fromText");let m=c.global(`${t}.fromType`,f),b=[];m.value==="fromText"?b.push(...r):m.value==="fromImage"?b.push(...i):b.push(...r,...i);let y=r.map(({provider:I,panel:we})=>({id:I.id,label:I.name??I.id,builderRenderFunction:we?.builderRenderFunction})),S=i.map(({provider:I,panel:we})=>({id:I.id,label:I.name??I.id,builderRenderFunction:we?.builderRenderFunction})),A=a.experimental.global(`${t}.selectedProvider.fromText`,y[0]),x=a.experimental.global(`${t}.selectedProvider.fromImage`,S[0]),k=m.value==="fromText"?A:m.value==="fromImage"?x:void 0,M=`ly.img.plugin-ai-${e}-generation-web.providerSelect`,h=n.feature.isEnabled(M,{engine:s});if(!d&&!g){l.Section(`${t}.noInputWarning.section`,{children:()=>{l.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 j=d&&g&&r.length>0&&i.length>0,C=o&&j,E=b.length>1&&h;if((C||E)&&l.Section(`${t}.providerSelection.section`,{children:()=>{if(C&&l.ButtonGroup(`${t}.fromType.buttonGroup`,{inputLabel:ee(e,"fromType.label"),children:()=>{d&&r.length>0&&l.Button(`${t}.fromType.buttonGroup.fromText`,{label:ee(e,"fromText.label"),icon:m.value!=="fromText"&&st(r,a)?"@imgly/LoadingSpinner":void 0,isActive:m.value==="fromText",onClick:()=>{m.setValue("fromText")}}),g&&i.length>0&&l.Button(`${t}.fromType.buttonGroup.fromImage`,{label:ee(e,"fromImage.label"),icon:m.value!=="fromImage"&&st(i,a)?"@imgly/LoadingSpinner":void 0,isActive:m.value==="fromImage",onClick:()=>{m.setValue("fromImage")}})}}),E){let I=m.value==="fromText"?y:m.value==="fromImage"?S:[...y,...S];k!=null&&l.Select(`${t}.providerSelect.select`,{inputLabel:ee(e,"providerSelect.label"),values:I,...k})}}}),b.length>1)k?.value.builderRenderFunction?.(a);else{let I=b[0];I&&I.panel?.builderRenderFunction?.(a)}}}function Eo({kind:e,prefix:t,providerInitializationResults:r,cesdk:i}){return n=>{let{builder:o,engine:a}=n;if(r.length===0)return;let l=`ly.img.plugin-ai-${e}-generation-web.providerSelect`;e==="audio"&&t&&(t.includes("speech")?l="ly.img.plugin-ai-audio-generation-web.speech.providerSelect":t.includes("sound")&&(l="ly.img.plugin-ai-audio-generation-web.sound.providerSelect"));let c=i.feature.isEnabled(l,{engine:a}),s=r.map(({provider:d,panel:p})=>({id:d.id,label:d.name??d.id,builderRenderFunction:p?.builderRenderFunction})),u=n.state(`${t}.selectedProvider`,s[0]);r.length>1&&c&&u!=null&&o.Section(`${t}.providerSelection.section`,{children:()=>{o.Select(`${t}.providerSelect.select`,{inputLabel:ee(e,"providerSelect.label"),values:s,...u})}}),u.value.builderRenderFunction?.(n)}}function st(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Te(r.id),!1).value)}var Lt=xo;var Mo=typeof global=="object"&&global&&global.Object===Object&&global,Zt=Mo,jo=typeof self=="object"&&self&&self.Object===Object&&self,$o=Zt||jo||Function("return this")(),_=$o,_o=_.Symbol,H=_o,Qt=Object.prototype,Lo=Qt.hasOwnProperty,Po=Qt.toString,oe=H?H.toStringTag:void 0;function No(e){var t=Lo.call(e,oe),r=e[oe];try{e[oe]=void 0;var i=!0}catch{}var n=Po.call(e);return i&&(t?e[oe]=r:delete e[oe]),n}var To=No,Oo=Object.prototype,Do=Oo.toString;function zo(e){return Do.call(e)}var Ro=zo,Fo="[object Null]",Vo="[object Undefined]",Pt=H?H.toStringTag:void 0;function Uo(e){return e==null?e===void 0?Vo:Fo:Pt&&Pt in Object(e)?To(e):Ro(e)}var ce=Uo;function Bo(e){return e!=null&&typeof e=="object"}var Be=Bo,Ju=Array.isArray;function Go(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Yt=Go,qo="[object AsyncFunction]",Ho="[object Function]",Zo="[object GeneratorFunction]",Qo="[object Proxy]";function Yo(e){if(!Yt(e))return!1;var t=ce(e);return t==Ho||t==Zo||t==qo||t==Qo}var Wo=Yo,Ko=_["__core-js_shared__"],Oe=Ko,Nt=function(){var e=/[^.]+$/.exec(Oe&&Oe.keys&&Oe.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Jo(e){return!!Nt&&Nt in e}var Xo=Jo,es=Function.prototype,ts=es.toString;function rs(e){if(e!=null){try{return ts.call(e)}catch{}try{return e+""}catch{}}return""}var O=rs,is=/[\\^$.*+?()[\]{}|]/g,ns=/^\[object .+?Constructor\]$/,as=Function.prototype,os=Object.prototype,ss=as.toString,ls=os.hasOwnProperty,us=RegExp("^"+ss.call(ls).replace(is,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function cs(e){if(!Yt(e)||Xo(e))return!1;var t=Wo(e)?us:ns;return t.test(O(e))}var ds=cs;function gs(e,t){return e?.[t]}var ps=gs;function fs(e,t){var r=ps(e,t);return ds(r)?r:void 0}var Z=fs,ms=Z(_,"WeakMap"),ze=ms;function bs(e,t){return e===t||e!==e&&t!==t}var hs=bs,ys=9007199254740991;function vs(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ys}var ws=vs;var Xu=Object.prototype;var ks="[object Arguments]";function Is(e){return Be(e)&&ce(e)==ks}var Tt=Is,Wt=Object.prototype,As=Wt.hasOwnProperty,Ss=Wt.propertyIsEnumerable,ec=Tt(function(){return arguments}())?Tt:function(e){return Be(e)&&As.call(e,"callee")&&!Ss.call(e,"callee")};var Kt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ot=Kt&&typeof module=="object"&&module&&!module.nodeType&&module,xs=Ot&&Ot.exports===Kt,Dt=xs?_.Buffer:void 0,tc=Dt?Dt.isBuffer:void 0;var Cs="[object Arguments]",Es="[object Array]",Ms="[object Boolean]",js="[object Date]",$s="[object Error]",_s="[object Function]",Ls="[object Map]",Ps="[object Number]",Ns="[object Object]",Ts="[object RegExp]",Os="[object Set]",Ds="[object String]",zs="[object WeakMap]",Rs="[object ArrayBuffer]",Fs="[object DataView]",Vs="[object Float32Array]",Us="[object Float64Array]",Bs="[object Int8Array]",Gs="[object Int16Array]",qs="[object Int32Array]",Hs="[object Uint8Array]",Zs="[object Uint8ClampedArray]",Qs="[object Uint16Array]",Ys="[object Uint32Array]",w={};w[Vs]=w[Us]=w[Bs]=w[Gs]=w[qs]=w[Hs]=w[Zs]=w[Qs]=w[Ys]=!0;w[Cs]=w[Es]=w[Rs]=w[Ms]=w[Fs]=w[js]=w[$s]=w[_s]=w[Ls]=w[Ps]=w[Ns]=w[Ts]=w[Os]=w[Ds]=w[zs]=!1;function Ws(e){return Be(e)&&ws(e.length)&&!!w[ce(e)]}var Ks=Ws;function Js(e){return function(t){return e(t)}}var Xs=Js,Jt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,se=Jt&&typeof module=="object"&&module&&!module.nodeType&&module,el=se&&se.exports===Jt,De=el&&Zt.process,tl=function(){try{var e=se&&se.require&&se.require("util").types;return e||De&&De.binding&&De.binding("util")}catch{}}(),zt=tl,Rt=zt&&zt.isTypedArray,rc=Rt?Xs(Rt):Ks;var rl=Object.prototype,ic=rl.hasOwnProperty;function il(e,t){return function(r){return e(t(r))}}var nl=il,nc=nl(Object.keys,Object);var al=Object.prototype,ac=al.hasOwnProperty;var ol=Z(Object,"create"),le=ol;function sl(){this.__data__=le?le(null):{},this.size=0}var ll=sl;function ul(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var cl=ul,dl="__lodash_hash_undefined__",gl=Object.prototype,pl=gl.hasOwnProperty;function fl(e){var t=this.__data__;if(le){var r=t[e];return r===dl?void 0:r}return pl.call(t,e)?t[e]:void 0}var ml=fl,bl=Object.prototype,hl=bl.hasOwnProperty;function yl(e){var t=this.__data__;return le?t[e]!==void 0:hl.call(t,e)}var vl=yl,wl="__lodash_hash_undefined__";function kl(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=le&&t===void 0?wl:t,this}var Il=kl;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=ll;Q.prototype.delete=cl;Q.prototype.get=ml;Q.prototype.has=vl;Q.prototype.set=Il;var Ft=Q;function Al(){this.__data__=[],this.size=0}var Sl=Al;function xl(e,t){for(var r=e.length;r--;)if(hs(e[r][0],t))return r;return-1}var be=xl,Cl=Array.prototype,El=Cl.splice;function Ml(e){var t=this.__data__,r=be(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():El.call(t,r,1),--this.size,!0}var jl=Ml;function $l(e){var t=this.__data__,r=be(t,e);return r<0?void 0:t[r][1]}var _l=$l;function Ll(e){return be(this.__data__,e)>-1}var Pl=Ll;function Nl(e,t){var r=this.__data__,i=be(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var Tl=Nl;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=Sl;Y.prototype.delete=jl;Y.prototype.get=_l;Y.prototype.has=Pl;Y.prototype.set=Tl;var he=Y,Ol=Z(_,"Map"),ue=Ol;function Dl(){this.size=0,this.__data__={hash:new Ft,map:new(ue||he),string:new Ft}}var zl=Dl;function Rl(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Fl=Rl;function Vl(e,t){var r=e.__data__;return Fl(t)?r[typeof t=="string"?"string":"hash"]:r.map}var ye=Vl;function Ul(e){var t=ye(this,e).delete(e);return this.size-=t?1:0,t}var Bl=Ul;function Gl(e){return ye(this,e).get(e)}var ql=Gl;function Hl(e){return ye(this,e).has(e)}var Zl=Hl;function Ql(e,t){var r=ye(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Yl=Ql;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=zl;W.prototype.delete=Bl;W.prototype.get=ql;W.prototype.has=Zl;W.prototype.set=Yl;var Xt=W;function Wl(){this.__data__=new he,this.size=0}var Kl=Wl;function Jl(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Xl=Jl;function eu(e){return this.__data__.get(e)}var tu=eu;function ru(e){return this.__data__.has(e)}var iu=ru,nu=200;function au(e,t){var r=this.__data__;if(r instanceof he){var i=r.__data__;if(!ue||i.length<nu-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Xt(i)}return r.set(e,t),this.size=r.size,this}var ou=au;function de(e){var t=this.__data__=new he(e);this.size=t.size}de.prototype.clear=Kl;de.prototype.delete=Xl;de.prototype.get=tu;de.prototype.has=iu;de.prototype.set=ou;var su=Object.prototype,oc=su.propertyIsEnumerable;var lu=Z(_,"DataView"),Re=lu,uu=Z(_,"Promise"),Fe=uu,cu=Z(_,"Set"),Ve=cu,Vt="[object Map]",du="[object Object]",Ut="[object Promise]",Bt="[object Set]",Gt="[object WeakMap]",qt="[object DataView]",gu=O(Re),pu=O(ue),fu=O(Fe),mu=O(Ve),bu=O(ze),q=ce;(Re&&q(new Re(new ArrayBuffer(1)))!=qt||ue&&q(new ue)!=Vt||Fe&&q(Fe.resolve())!=Ut||Ve&&q(new Ve)!=Bt||ze&&q(new ze)!=Gt)&&(q=function(e){var t=ce(e),r=t==du?e.constructor:void 0,i=r?O(r):"";if(i)switch(i){case gu:return qt;case pu:return Vt;case fu:return Ut;case mu:return Bt;case bu:return Gt}return t});var sc=_.Uint8Array;var hu="__lodash_hash_undefined__";function yu(e){return this.__data__.set(e,hu),this}var vu=yu;function wu(e){return this.__data__.has(e)}var ku=wu;function Ue(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Xt;++t<r;)this.add(e[t])}Ue.prototype.add=Ue.prototype.push=vu;Ue.prototype.has=ku;var Ht=H?H.prototype:void 0,lc=Ht?Ht.valueOf:void 0;var Iu=Object.prototype,uc=Iu.hasOwnProperty;var Au=Object.prototype,cc=Au.hasOwnProperty;var dc=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),gc=new RegExp(/[A-Fa-f0-9]{1}/,"g"),pc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function Su(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 er(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 Su(i,t)}function xu(e){return e==null?[]:Array.isArray(e)?e:[e]}var Ge=xu;var D="@imgly/plugin-ai-video-generation-web",Cu=["ly.img.createVideo"];var ve="createVideo",tr=`ly.img.${ve}`,Eu=`ly.img.plugin-ai-video-generation-web.quickAction.${ve}`,rr=`ly.img.plugin-ai-video-generation-web.defaults.quickAction.${ve}`;function Mu(e,t){let r="ly.img.plugin-ai-video-generation-web",i=`quickAction.${ve}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var ju=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-video-generation-web.quickAction.createVideo",!0),e.i18n.setTranslations({en:{[`${rr}`]:"Create Video...",[`${rr}.description`]:"Create a video from the image"}}),{id:tr,type:"quick",kind:"image",label:`${Eu}`,enable:kt(),scopes:[],render:({builder:r,engine:i,close:n,providerId:o})=>{r.Button(`${tr}.button`,{label:Mu(o),icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[a]=i.block.findAllSelected(),l=await er(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_url`,l),n()}catch(a){console.error("Error opening video generation panel:",a)}}})}}),ir=ju;var P="ly.img.ai.video-generation";function $u(e){return{async initialize({cesdk:t}){if(t==null)return;vt(t,D,"0.2.6"),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),t.setTranslations({en:{[`panel.${P}`]:"Video Generation",[`${P}.dock.label`]:"AI Video"}}),_u(e);let i=me.get().register({type:"plugin",sceneMode:"Video",id:D,pluginId:D,label:"Generate Video",meta:{panelId:P},execute:()=>{t.ui.isPanelOpen(P)?t.ui.closePanel(P):t.ui.openPanel(P)}}),n=e.providers?.text2video??e.text2video,o=e.providers?.image2video??e.image2video,a=await Promise.all(Ge(n).map(u=>u({cesdk:t}))),l=await Promise.all(Ge(o).map(u=>u({cesdk:t})));if(!(a.length>0||l.length>0)){i();return}let s=await Lt("video",{fromText:a,fromImage:l},{cesdk:t},e);me.get().register(ir({cesdk:t})),s.panel.builderRenderFunction!=null?(t.ui.registerPanel(P,s.panel.builderRenderFunction),wt({cesdk:t,panelId:P})):i()}}}function _u(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 nr=$u;var Lu=e=>({name:D,version:"0.2.6",...nr(e)}),jc=Lu;export{Cu as DEFAULT_VIDEO_QUICK_ACTION_ORDER,jc as default};
65
+ `,fa=pa;function ba(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 Ot(2e3),await ma(t,e,r)):i(t,r)}async function ma(e,t,r){switch(t.kind){case"image":return ha(e,t,r);case"video":return ya(e,t,r);case"text":return va(e,t,r);case"audio":return ka(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function ha(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[s]=t.blockIds,c=await go(s,r),l=await co(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=${a.replace(" ","+").replace(`
66
+ `,"+")}`}}async function ya(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function va(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,s=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);s&&s[1]&&(i=s[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=ee(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=ee(n,o)}else"customPrompt"in e?a=ee(n,"custom"):a=ee(n,"improved");else a=ee(n,"generated");return wa(a,r.abortSignal)}async function*wa(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 Ot(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,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,s="";if(n<=o.length)s=o.substring(0,n);else{s=o;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 ka(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:Ia(220,i),duration:i,thumbnailUrl:void 0}}function Ia(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 Aa(i,44100)}function Aa(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,s=r*i,c=44+s,l=new ArrayBuffer(c),u=new DataView(l),d=(p,h)=>{for(let y=0;y<h.length;y++)u.setUint8(p+y,h.charCodeAt(y))};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,o,!0),u.setUint16(32,a,!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 h=Math.max(-1,Math.min(1,e[p])),y=Math.round(h*32767);u.setInt16(f,y,!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 Ot(e){return new Promise(t=>{setTimeout(t,e)})}var Sa=ba,xa="USER_CANCEL";function Ca(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=mo([...e.provider.output.middleware??[],...r?.middlewares??[],yo({enable:r?.debug}),Sa({enable:r?.dryRun,kind:e.provider.kind})]);try{let{result:n}=await i(e.provider.output.generate)(t,{abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk});return r?.abortSignal?.aborted?{status:"aborted"}:n instanceof Error?{status:"error",message:n.message}:n==null?{status:"error",message:"No output generated"}:Io(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return Re(n)?{status:"aborted",message:n.message}:n===xa?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var Ea=Ca;async function Ma(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n,providerConfig:t.configuration};if(await t.initialize?.({...r,engine:r.cesdk.engine}),t.input?.quickActions?.supported){let d=t.kind,f=we.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 o=ca(a),s=ga(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=s;let c=Ea({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),l=await sa(a,c);Ao(r.cesdk,"@imgly/plugin-ai-generation",fa);let u={provider:t,panel:{builderRenderFunction:l},history:{assetSourceId:o,assetLibraryEntryId:s},generate:c};return bo.get().register(u),u}var Le=Ma;function ja(e){let{kind:t,cesdk:r,historAssetSourceIds:i}=e,n=`ly.img.ai.${t}-generation.history`;if(r.engine.asset.findAllSources().includes(n))return n;let a=new gr(n,r,i);return r.engine.asset.addSource(a),a.id}var $a=ja;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 La(e,t,r,i){let{cesdk:n}=r;n.setTranslations({en:{"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 a,o=[];if(Array.isArray(t)){let l=await Promise.all(t.map(u=>Le(e,u,r,i)));o.push(...l),a=Pa({kind:e,prefix:e,providerInitializationResults:o,cesdk:n})}else{let l=await Promise.all(t.fromText.map(d=>Le(e,d,r,i)));o.push(...l);let u=await Promise.all(t.fromImage.map(d=>Le(e,d,r,i)));o.push(...u),a=_a({kind:e,prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u,cesdk:n})}let s=$a({kind:e,cesdk:r.cesdk,historAssetSourceIds:o.map(l=>l.history?.assetSourceId).filter(fo)}),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:a},history:{assetSourceId:s,assetLibraryEntryId:c},providerInitializationResults:o}}function _a({kind:e,prefix:t,initializedFromTextProviders:r,initializedFromImageProviders:i,cesdk:n}){let a=r.length>0&&i.length>0;return o=>{let{builder:s,experimental:c,engine:l}=o,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&&a&&(m="fromText");let p=c.global(`${t}.fromType`,m),h=[];p.value==="fromText"?h.push(...r):p.value==="fromImage"?h.push(...i):h.push(...r,...i);let y=r.map(({provider:S,panel:b})=>({id:S.id,label:S.name??S.id,builderRenderFunction:b?.builderRenderFunction})),v=i.map(({provider:S,panel:b})=>({id:S.id,label:S.name??S.id,builderRenderFunction:b?.builderRenderFunction})),A=o.experimental.global(`${t}.selectedProvider.fromText`,y[0]),x=o.experimental.global(`${t}.selectedProvider.fromImage`,v[0]),w=p.value==="fromText"?A:p.value==="fromImage"?x:void 0,C=`ly.img.plugin-ai-${e}-generation-web.providerSelect`,xe=n.feature.isEnabled(C,{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 K=d&&g&&r.length>0&&i.length>0,J=a&&K,me=h.length>1&&xe;if((J||me)&&s.Section(`${t}.providerSelection.section`,{children:()=>{if(J&&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"&&pt(r,o)?"@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"&&pt(i,o)?"@imgly/LoadingSpinner":void 0,isActive:p.value==="fromImage",onClick:()=>{p.setValue("fromImage")}})}}),me){let S=p.value==="fromText"?y:p.value==="fromImage"?v:[...y,...v];w!=null&&s.Select(`${t}.providerSelect.select`,{inputLabel:re(e,"providerSelect.label"),values:S,...w})}}}),h.length>1)w?.value.builderRenderFunction?.(o);else{let S=h[0];S&&S.panel?.builderRenderFunction?.(o)}}}function Pa({kind:e,prefix:t,providerInitializationResults:r,cesdk:i}){return n=>{let{builder:a,engine:o}=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:o}),l=r.map(({provider:d,panel:f})=>({id:d.id,label:d.name??d.id,builderRenderFunction:f?.builderRenderFunction})),u=n.state(`${t}.selectedProvider`,l[0]);r.length>1&&c&&u!=null&&a.Section(`${t}.providerSelection.section`,{children:()=>{a.Select(`${t}.providerSelect.select`,{inputLabel:re(e,"providerSelect.label"),values:l,...u})}}),u.value.builderRenderFunction?.(n)}}function pt(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Ve(r.id),!1).value)}var zt=La;var Na=typeof global=="object"&&global&&global.Object===Object&&global,Xt=Na,Ta=typeof self=="object"&&self&&self.Object===Object&&self,Da=Xt||Ta||Function("return this")(),M=Da,Oa=M.Symbol,H=Oa,er=Object.prototype,za=er.hasOwnProperty,Ra=er.toString,ce=H?H.toStringTag:void 0;function Fa(e){var t=za.call(e,ce),r=e[ce];try{e[ce]=void 0;var i=!0}catch{}var n=Ra.call(e);return i&&(t?e[ce]=r:delete e[ce]),n}var Va=Fa,Ua=Object.prototype,Ba=Ua.toString;function Ga(e){return Ba.call(e)}var qa=Ga,Ha="[object Null]",Za="[object Undefined]",Rt=H?H.toStringTag:void 0;function Qa(e){return e==null?e===void 0?Za:Ha:Rt&&Rt in Object(e)?Va(e):qa(e)}var fe=Qa;function Ya(e){return e!=null&&typeof e=="object"}var Ye=Ya,nc=Array.isArray;function Wa(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var tr=Wa,Ka="[object AsyncFunction]",Ja="[object Function]",Xa="[object GeneratorFunction]",el="[object Proxy]";function tl(e){if(!tr(e))return!1;var t=fe(e);return t==Ja||t==Xa||t==Ka||t==el}var rl=tl,il=M["__core-js_shared__"],Ue=il,Ft=function(){var e=/[^.]+$/.exec(Ue&&Ue.keys&&Ue.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function nl(e){return!!Ft&&Ft in e}var ol=nl,al=Function.prototype,ll=al.toString;function sl(e){if(e!=null){try{return ll.call(e)}catch{}try{return e+""}catch{}}return""}var D=sl,ul=/[\\^$.*+?()[\]{}|]/g,cl=/^\[object .+?Constructor\]$/,dl=Function.prototype,gl=Object.prototype,pl=dl.toString,fl=gl.hasOwnProperty,bl=RegExp("^"+pl.call(fl).replace(ul,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ml(e){if(!tr(e)||ol(e))return!1;var t=rl(e)?bl:cl;return t.test(D(e))}var hl=ml;function yl(e,t){return e?.[t]}var vl=yl;function wl(e,t){var r=vl(e,t);return hl(r)?r:void 0}var Z=wl,kl=Z(M,"WeakMap"),Ge=kl;function Il(e,t){return e===t||e!==e&&t!==t}var Al=Il,Sl=9007199254740991;function xl(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Sl}var Cl=xl;var oc=Object.prototype;var El="[object Arguments]";function Ml(e){return Ye(e)&&fe(e)==El}var Vt=Ml,rr=Object.prototype,jl=rr.hasOwnProperty,$l=rr.propertyIsEnumerable,ac=Vt(function(){return arguments}())?Vt:function(e){return Ye(e)&&jl.call(e,"callee")&&!$l.call(e,"callee")};var ir=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ut=ir&&typeof module=="object"&&module&&!module.nodeType&&module,Ll=Ut&&Ut.exports===ir,Bt=Ll?M.Buffer:void 0,lc=Bt?Bt.isBuffer:void 0;var _l="[object Arguments]",Pl="[object Array]",Nl="[object Boolean]",Tl="[object Date]",Dl="[object Error]",Ol="[object Function]",zl="[object Map]",Rl="[object Number]",Fl="[object Object]",Vl="[object RegExp]",Ul="[object Set]",Bl="[object String]",Gl="[object WeakMap]",ql="[object ArrayBuffer]",Hl="[object DataView]",Zl="[object Float32Array]",Ql="[object Float64Array]",Yl="[object Int8Array]",Wl="[object Int16Array]",Kl="[object Int32Array]",Jl="[object Uint8Array]",Xl="[object Uint8ClampedArray]",es="[object Uint16Array]",ts="[object Uint32Array]",I={};I[Zl]=I[Ql]=I[Yl]=I[Wl]=I[Kl]=I[Jl]=I[Xl]=I[es]=I[ts]=!0;I[_l]=I[Pl]=I[ql]=I[Nl]=I[Hl]=I[Tl]=I[Dl]=I[Ol]=I[zl]=I[Rl]=I[Fl]=I[Vl]=I[Ul]=I[Bl]=I[Gl]=!1;function rs(e){return Ye(e)&&Cl(e.length)&&!!I[fe(e)]}var is=rs;function ns(e){return function(t){return e(t)}}var os=ns,nr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,de=nr&&typeof module=="object"&&module&&!module.nodeType&&module,as=de&&de.exports===nr,Be=as&&Xt.process,ls=function(){try{var e=de&&de.require&&de.require("util").types;return e||Be&&Be.binding&&Be.binding("util")}catch{}}(),Gt=ls,qt=Gt&&Gt.isTypedArray,sc=qt?os(qt):is;var ss=Object.prototype,uc=ss.hasOwnProperty;function us(e,t){return function(r){return e(t(r))}}var cs=us,cc=cs(Object.keys,Object);var ds=Object.prototype,dc=ds.hasOwnProperty;var gs=Z(Object,"create"),ge=gs;function ps(){this.__data__=ge?ge(null):{},this.size=0}var fs=ps;function bs(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var ms=bs,hs="__lodash_hash_undefined__",ys=Object.prototype,vs=ys.hasOwnProperty;function ws(e){var t=this.__data__;if(ge){var r=t[e];return r===hs?void 0:r}return vs.call(t,e)?t[e]:void 0}var ks=ws,Is=Object.prototype,As=Is.hasOwnProperty;function Ss(e){var t=this.__data__;return ge?t[e]!==void 0:As.call(t,e)}var xs=Ss,Cs="__lodash_hash_undefined__";function Es(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ge&&t===void 0?Cs:t,this}var Ms=Es;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=fs;Q.prototype.delete=ms;Q.prototype.get=ks;Q.prototype.has=xs;Q.prototype.set=Ms;var Ht=Q;function js(){this.__data__=[],this.size=0}var $s=js;function Ls(e,t){for(var r=e.length;r--;)if(Al(e[r][0],t))return r;return-1}var ke=Ls,_s=Array.prototype,Ps=_s.splice;function Ns(e){var t=this.__data__,r=ke(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Ps.call(t,r,1),--this.size,!0}var Ts=Ns;function Ds(e){var t=this.__data__,r=ke(t,e);return r<0?void 0:t[r][1]}var Os=Ds;function zs(e){return ke(this.__data__,e)>-1}var Rs=zs;function Fs(e,t){var r=this.__data__,i=ke(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var Vs=Fs;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=$s;Y.prototype.delete=Ts;Y.prototype.get=Os;Y.prototype.has=Rs;Y.prototype.set=Vs;var Ie=Y,Us=Z(M,"Map"),pe=Us;function Bs(){this.size=0,this.__data__={hash:new Ht,map:new(pe||Ie),string:new Ht}}var Gs=Bs;function qs(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Hs=qs;function Zs(e,t){var r=e.__data__;return Hs(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Ae=Zs;function Qs(e){var t=Ae(this,e).delete(e);return this.size-=t?1:0,t}var Ys=Qs;function Ws(e){return Ae(this,e).get(e)}var Ks=Ws;function Js(e){return Ae(this,e).has(e)}var Xs=Js;function eu(e,t){var r=Ae(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var tu=eu;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=Gs;W.prototype.delete=Ys;W.prototype.get=Ks;W.prototype.has=Xs;W.prototype.set=tu;var or=W;function ru(){this.__data__=new Ie,this.size=0}var iu=ru;function nu(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var ou=nu;function au(e){return this.__data__.get(e)}var lu=au;function su(e){return this.__data__.has(e)}var uu=su,cu=200;function du(e,t){var r=this.__data__;if(r instanceof Ie){var i=r.__data__;if(!pe||i.length<cu-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new or(i)}return r.set(e,t),this.size=r.size,this}var gu=du;function be(e){var t=this.__data__=new Ie(e);this.size=t.size}be.prototype.clear=iu;be.prototype.delete=ou;be.prototype.get=lu;be.prototype.has=uu;be.prototype.set=gu;var pu=Object.prototype,gc=pu.propertyIsEnumerable;var fu=Z(M,"DataView"),qe=fu,bu=Z(M,"Promise"),He=bu,mu=Z(M,"Set"),Ze=mu,Zt="[object Map]",hu="[object Object]",Qt="[object Promise]",Yt="[object Set]",Wt="[object WeakMap]",Kt="[object DataView]",yu=D(qe),vu=D(pe),wu=D(He),ku=D(Ze),Iu=D(Ge),q=fe;(qe&&q(new qe(new ArrayBuffer(1)))!=Kt||pe&&q(new pe)!=Zt||He&&q(He.resolve())!=Qt||Ze&&q(new Ze)!=Yt||Ge&&q(new Ge)!=Wt)&&(q=function(e){var t=fe(e),r=t==hu?e.constructor:void 0,i=r?D(r):"";if(i)switch(i){case yu:return Kt;case vu:return Zt;case wu:return Qt;case ku:return Yt;case Iu:return Wt}return t});var pc=M.Uint8Array;var Au="__lodash_hash_undefined__";function Su(e){return this.__data__.set(e,Au),this}var xu=Su;function Cu(e){return this.__data__.has(e)}var Eu=Cu;function Qe(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new or;++t<r;)this.add(e[t])}Qe.prototype.add=Qe.prototype.push=xu;Qe.prototype.has=Eu;var Jt=H?H.prototype:void 0,fc=Jt?Jt.valueOf:void 0;var Mu=Object.prototype,bc=Mu.hasOwnProperty;var ju=Object.prototype,mc=ju.hasOwnProperty;var hc=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),yc=new RegExp(/[A-Fa-f0-9]{1}/,"g"),vc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function $u(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Uint8Array(n),o=new Blob([a],{type:r});return URL.createObjectURL(o)}else return e}async function ar(e,t,r){let i,n=t.block.getFill(e),a=t.block.getSourceSet(n,"fill/image/sourceSet"),[o]=a;if(o==null){if(i=t.block.getString(n,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=o.uri;if(r?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return $u(i,t)}function Lu(e){return e==null?[]:Array.isArray(e)?e:[e]}var We=Lu;var O="@imgly/plugin-ai-video-generation-web",_u=["ly.img.createVideo"];var Se="createVideo",lr=`ly.img.${Se}`,Pu=`ly.img.plugin-ai-video-generation-web.quickAction.${Se}`,sr=`ly.img.plugin-ai-video-generation-web.defaults.quickAction.${Se}`;function Nu(e,t){let r="ly.img.plugin-ai-video-generation-web",i=`quickAction.${Se}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var Tu=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-video-generation-web.quickAction.createVideo",!0),e.i18n.setTranslations({en:{[`${sr}`]:"Create Video...",[`${sr}.description`]:"Create a video from the image"}}),{id:lr,type:"quick",kind:"image",label:`${Pu}`,enable:Et(),scopes:[],render:({builder:r,engine:i,close:n,providerId:a})=>{r.Button(`${lr}.button`,{label:Nu(a),icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=i.block.findAllSelected(),s=await ar(o,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(`${a}.image_url`,s),n()}catch(o){console.error("Error opening video generation panel:",o)}}})}}),ur=Tu;var _="ly.img.ai.video-generation";function Du(e){return{async initialize({cesdk:t}){if(t==null)return;xt(t,O,"0.2.8"),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),t.setTranslations({en:{[`panel.${_}`]:"Video Generation",[`${_}.dock.label`]:"AI Video"}}),Ou(e);let i=we.get().register({type:"plugin",sceneMode:"Video",id:O,pluginId:O,label:"Generate Video",meta:{panelId:_},execute:()=>{t.ui.isPanelOpen(_)?t.ui.closePanel(_):t.ui.openPanel(_)}}),n=e.providers?.text2video??e.text2video,a=e.providers?.image2video??e.image2video,o=await Promise.all(We(n).map(u=>u({cesdk:t}))),s=await Promise.all(We(a).map(u=>u({cesdk:t})));if(!(o.length>0||s.length>0)){i();return}let l=await zt("video",{fromText:o,fromImage:s},{cesdk:t},e);we.get().register(ur({cesdk:t})),l.panel.builderRenderFunction!=null?(t.ui.registerPanel(_,l.panel.builderRenderFunction),Ct({cesdk:t,panelId:_})):i()}}}function Ou(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 cr=Du;var zu=e=>({name:O,version:"0.2.8",...cr(e)}),Tc=zu;export{_u as DEFAULT_VIDEO_QUICK_ACTION_ORDER,Tc as default};
67
67
  /*! Bundled license information:
68
68
 
69
- @imgly/plugin-ai-generation-web/dist/index.mjs:
70
- (*! Bundled license information:
71
-
72
- @imgly/plugin-utils/dist/index.mjs:
73
- (*! Bundled license information:
74
-
75
- lodash-es/lodash.js:
76
- (**
77
- * @license
78
- * Lodash (Custom Build) <https://lodash.com/>
79
- * Build: `lodash modularize exports="es" -o ./`
80
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
81
- * Released under MIT license <https://lodash.com/license>
82
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
83
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
84
- *)
85
- *)
86
- *)
87
-
88
- @imgly/plugin-utils/dist/index.mjs:
89
- (*! Bundled license information:
90
-
91
- lodash-es/lodash.js:
92
- (**
93
- * @license
94
- * Lodash (Custom Build) <https://lodash.com/>
95
- * Build: `lodash modularize exports="es" -o ./`
96
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
97
- * Released under MIT license <https://lodash.com/license>
98
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
99
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
100
- *)
101
- *)
69
+ lodash-es/lodash.js:
70
+ (**
71
+ * @license
72
+ * Lodash (Custom Build) <https://lodash.com/>
73
+ * Build: `lodash modularize exports="es" -o ./`
74
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
75
+ * Released under MIT license <https://lodash.com/license>
76
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
77
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
78
+ *)
102
79
  */
103
80
  //# sourceMappingURL=index.mjs.map