@imgly/plugin-ai-video-generation-web 0.2.4 → 0.2.5
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/CHANGELOG.md +12 -0
- package/README.md +12 -6
- package/dist/fal-ai/createFalClient.d.ts +3 -0
- package/dist/fal-ai/index.mjs +10 -10
- package/dist/fal-ai/index.mjs.map +4 -4
- package/dist/fal-ai/utils.d.ts +2 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +3 -3
- package/dist/quickActions/CreateVideo.d.ts +1 -0
- package/package.json +2 -1
package/dist/fal-ai/utils.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import CreativeEditorSDK from '@cesdk/cesdk-js';
|
|
2
|
-
|
|
2
|
+
import { FalClient } from './createFalClient';
|
|
3
|
+
export declare function uploadImageInputToFalIfNeeded(client: FalClient, imageUrl?: string, cesdk?: CreativeEditorSDK): Promise<string | undefined>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var Jt=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,l)=>{let c=e.locale??"en",d="",f=[];l.label!=null&&typeof l.label=="object"&&l.label[c]&&(d=l.label[c]),l.tags!=null&&typeof l.tags=="object"&&l.tags[c]&&(f=l.tags[c]);let g={...l,label:d,tags:f};return this.filterAsset(g,e)&&u.push(g),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),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;N(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=()=>{N(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(),u=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?s-u:u-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 N(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),N(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()??"",u=e.tags?.map(l=>l.toLowerCase())??[];if(!o.every(l=>s.includes(l)||u.some(c=>c.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 u,l;return i==="id"?(u=o.id,l=s.id):(u=o.meta?.[i]??null,l=s.meta?.[i]??null),u==null?r==="Ascending"?-1:1:l==null?r==="Ascending"?1:-1:typeof u=="string"&&typeof l=="string"?r==="Ascending"?u.localeCompare(l):l.localeCompare(u):r==="Ascending"?u<l?-1:u>l?1:0:u>l?-1:u<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 N(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]=N(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]=N(n,t,a)}return e}var Xt=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,d)=>{let f=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-f});let{page:n,perPage:a}=e,o=n*a,s=o+a,u=i.slice(o,s),l=s<i.length?n+1:void 0;return{assets:u,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 er=typeof global=="object"&&global&&global.Object===Object&&global,tt=er,tr=typeof self=="object"&&self&&self.Object===Object&&self,rr=tt||tr||Function("return this")(),x=rr,ir=x.Symbol,O=ir,rt=Object.prototype,nr=rt.hasOwnProperty,or=rt.toString,q=O?O.toStringTag:void 0;function ar(e){var t=nr.call(e,q),r=e[q];try{e[q]=void 0;var i=!0}catch{}var n=or.call(e);return i&&(t?e[q]=r:delete e[q]),n}var sr=ar,lr=Object.prototype,ur=lr.toString;function cr(e){return ur.call(e)}var dr=cr,pr="[object Null]",gr="[object Undefined]",ze=O?O.toStringTag:void 0;function fr(e){return e==null?e===void 0?gr:pr:ze&&ze in Object(e)?sr(e):dr(e)}var J=fr;function mr(e){return e!=null&&typeof e=="object"}var xe=mr,Su=Array.isArray;function br(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var it=br,yr="[object AsyncFunction]",hr="[object Function]",vr="[object GeneratorFunction]",wr="[object Proxy]";function kr(e){if(!it(e))return!1;var t=J(e);return t==hr||t==vr||t==yr||t==wr}var Ir=kr,Ar=x["__core-js_shared__"],fe=Ar,Re=function(){var e=/[^.]+$/.exec(fe&&fe.keys&&fe.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function xr(e){return!!Re&&Re in e}var Sr=xr,Cr=Function.prototype,Er=Cr.toString;function Mr(e){if(e!=null){try{return Er.call(e)}catch{}try{return e+""}catch{}}return""}var j=Mr,jr=/[\\^$.*+?()[\]{}|]/g,$r=/^\[object .+?Constructor\]$/,_r=Function.prototype,Lr=Object.prototype,Nr=_r.toString,Or=Lr.hasOwnProperty,Pr=RegExp("^"+Nr.call(Or).replace(jr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Dr(e){if(!it(e)||Sr(e))return!1;var t=Ir(e)?Pr:$r;return t.test(j(e))}var Tr=Dr;function zr(e,t){return e?.[t]}var Rr=zr;function Fr(e,t){var r=Rr(e,t);return Tr(r)?r:void 0}var P=Fr,Vr=P(x,"WeakMap"),ve=Vr;function Ur(e,t){return e===t||e!==e&&t!==t}var Br=Ur,Gr=9007199254740991;function Hr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Gr}var qr=Hr,Cu=Object.prototype,Zr="[object Arguments]";function Qr(e){return xe(e)&&J(e)==Zr}var Fe=Qr,nt=Object.prototype,Yr=nt.hasOwnProperty,Wr=nt.propertyIsEnumerable,Eu=Fe(function(){return arguments}())?Fe:function(e){return xe(e)&&Yr.call(e,"callee")&&!Wr.call(e,"callee")},ot=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ve=ot&&typeof module=="object"&&module&&!module.nodeType&&module,Kr=Ve&&Ve.exports===ot,Ue=Kr?x.Buffer:void 0,Mu=Ue?Ue.isBuffer:void 0,Jr="[object Arguments]",Xr="[object Array]",ei="[object Boolean]",ti="[object Date]",ri="[object Error]",ii="[object Function]",ni="[object Map]",oi="[object Number]",ai="[object Object]",si="[object RegExp]",li="[object Set]",ui="[object String]",ci="[object WeakMap]",di="[object ArrayBuffer]",pi="[object DataView]",gi="[object Float32Array]",fi="[object Float64Array]",mi="[object Int8Array]",bi="[object Int16Array]",yi="[object Int32Array]",hi="[object Uint8Array]",vi="[object Uint8ClampedArray]",wi="[object Uint16Array]",ki="[object Uint32Array]",v={};v[gi]=v[fi]=v[mi]=v[bi]=v[yi]=v[hi]=v[vi]=v[wi]=v[ki]=!0;v[Jr]=v[Xr]=v[di]=v[ei]=v[pi]=v[ti]=v[ri]=v[ii]=v[ni]=v[oi]=v[ai]=v[si]=v[li]=v[ui]=v[ci]=!1;function Ii(e){return xe(e)&&qr(e.length)&&!!v[J(e)]}var Ai=Ii;function xi(e){return function(t){return e(t)}}var Si=xi,at=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Y=at&&typeof module=="object"&&module&&!module.nodeType&&module,Ci=Y&&Y.exports===at,me=Ci&&tt.process,Ei=function(){try{var e=Y&&Y.require&&Y.require("util").types;return e||me&&me.binding&&me.binding("util")}catch{}}(),Be=Ei,Ge=Be&&Be.isTypedArray,ju=Ge?Si(Ge):Ai,Mi=Object.prototype,$u=Mi.hasOwnProperty;function ji(e,t){return function(r){return e(t(r))}}var $i=ji,_u=$i(Object.keys,Object),_i=Object.prototype,Lu=_i.hasOwnProperty,Li=P(Object,"create"),W=Li;function Ni(){this.__data__=W?W(null):{},this.size=0}var Oi=Ni;function Pi(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Di=Pi,Ti="__lodash_hash_undefined__",zi=Object.prototype,Ri=zi.hasOwnProperty;function Fi(e){var t=this.__data__;if(W){var r=t[e];return r===Ti?void 0:r}return Ri.call(t,e)?t[e]:void 0}var Vi=Fi,Ui=Object.prototype,Bi=Ui.hasOwnProperty;function Gi(e){var t=this.__data__;return W?t[e]!==void 0:Bi.call(t,e)}var Hi=Gi,qi="__lodash_hash_undefined__";function Zi(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=W&&t===void 0?qi:t,this}var Qi=Zi;function D(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])}}D.prototype.clear=Oi;D.prototype.delete=Di;D.prototype.get=Vi;D.prototype.has=Hi;D.prototype.set=Qi;var He=D;function Yi(){this.__data__=[],this.size=0}var Wi=Yi;function Ki(e,t){for(var r=e.length;r--;)if(Br(e[r][0],t))return r;return-1}var se=Ki,Ji=Array.prototype,Xi=Ji.splice;function en(e){var t=this.__data__,r=se(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Xi.call(t,r,1),--this.size,!0}var tn=en;function rn(e){var t=this.__data__,r=se(t,e);return r<0?void 0:t[r][1]}var nn=rn;function on(e){return se(this.__data__,e)>-1}var an=on;function sn(e,t){var r=this.__data__,i=se(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var ln=sn;function T(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}T.prototype.clear=Wi;T.prototype.delete=tn;T.prototype.get=nn;T.prototype.has=an;T.prototype.set=ln;var le=T,un=P(x,"Map"),K=un;function cn(){this.size=0,this.__data__={hash:new He,map:new(K||le),string:new He}}var dn=cn;function pn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var gn=pn;function fn(e,t){var r=e.__data__;return gn(t)?r[typeof t=="string"?"string":"hash"]:r.map}var ue=fn;function mn(e){var t=ue(this,e).delete(e);return this.size-=t?1:0,t}var bn=mn;function yn(e){return ue(this,e).get(e)}var hn=yn;function vn(e){return ue(this,e).has(e)}var wn=vn;function kn(e,t){var r=ue(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var In=kn;function z(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])}}z.prototype.clear=dn;z.prototype.delete=bn;z.prototype.get=hn;z.prototype.has=wn;z.prototype.set=In;var st=z;function An(){this.__data__=new le,this.size=0}var xn=An;function Sn(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Cn=Sn;function En(e){return this.__data__.get(e)}var Mn=En;function jn(e){return this.__data__.has(e)}var $n=jn,_n=200;function Ln(e,t){var r=this.__data__;if(r instanceof le){var i=r.__data__;if(!K||i.length<_n-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new st(i)}return r.set(e,t),this.size=r.size,this}var Nn=Ln;function X(e){var t=this.__data__=new le(e);this.size=t.size}X.prototype.clear=xn;X.prototype.delete=Cn;X.prototype.get=Mn;X.prototype.has=$n;X.prototype.set=Nn;var On=Object.prototype,Nu=On.propertyIsEnumerable,Pn=P(x,"DataView"),we=Pn,Dn=P(x,"Promise"),ke=Dn,Tn=P(x,"Set"),Ie=Tn,qe="[object Map]",zn="[object Object]",Ze="[object Promise]",Qe="[object Set]",Ye="[object WeakMap]",We="[object DataView]",Rn=j(we),Fn=j(K),Vn=j(ke),Un=j(Ie),Bn=j(ve),L=J;(we&&L(new we(new ArrayBuffer(1)))!=We||K&&L(new K)!=qe||ke&&L(ke.resolve())!=Ze||Ie&&L(new Ie)!=Qe||ve&&L(new ve)!=Ye)&&(L=function(e){var t=J(e),r=t==zn?e.constructor:void 0,i=r?j(r):"";if(i)switch(i){case Rn:return We;case Fn:return qe;case Vn:return Ze;case Un:return Qe;case Bn:return Ye}return t});var Ou=x.Uint8Array,Gn="__lodash_hash_undefined__";function Hn(e){return this.__data__.set(e,Gn),this}var qn=Hn;function Zn(e){return this.__data__.has(e)}var Qn=Zn;function Ae(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new st;++t<r;)this.add(e[t])}Ae.prototype.add=Ae.prototype.push=qn;Ae.prototype.has=Qn;var Ke=O?O.prototype:void 0,Pu=Ke?Ke.valueOf:void 0,Yn=Object.prototype,Du=Yn.hasOwnProperty,Wn=Object.prototype,Tu=Wn.hasOwnProperty,zu=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Ru=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Fu=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function lt(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function Kn(e,t){let r=await lt(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 Jn(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 lt(i,t)}function Xn(e){return e!==void 0}var eo=Xn;var Se=class ut{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 ut),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))}},to=class ct{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new ct),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 ro(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=l=>{a.push(l)},s=async(l,c,d)=>{if(l>=t.length)return r(c,d);let f=t[l],g=async(b,y)=>s(l+1,b,y),p={...d,addDisposer:o};return f(c,p,g)},u={...n,addDisposer:o};return{result:await s(0,i,u),dispose:async()=>{for(let l=a.length-1;l>=0;l--)try{await a[l]()}catch(c){console.error("Error in disposer:",c)}a.length=0}}}}function io({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 no=io;var be="ly.img.ai.temp";async function oo(e,t){return e.engine.asset.findAllSources().includes(be)||e.engine.asset.addLocalSource(be),e.engine.asset.apply(be,t)}function ao(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 dt(){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 so(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 u=s.getContext("2d");if(!u){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}u.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 lo(e){return e?e.replace(/[_-]/g," ").replace(/([A-Z])/g," $1").trim().split(" ").filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function uo(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function Ce(e){return e instanceof Error&&e.name==="AbortError"}function co(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function pt(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!
|
|
1
|
+
var nr=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((u,s)=>{let c=e.locale??"en",g="",p=[];s.label!=null&&typeof s.label=="object"&&s.label[c]&&(g=s.label[c]),s.tags!=null&&typeof s.tags=="object"&&s.tags[c]&&(p=s.tags[c]);let d={...s,label:g,tags:p};return this.filterAsset(d,e)&&u.push(d),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),l=a<t.length?r+1:void 0;return{assets:o,currentPage:r,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let r=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();r.onsuccess=()=>{let i=new Set;r.result.forEach(a=>{a.groups&&Array.isArray(a.groups)&&a.groups.forEach(o=>i.add(o))});let n=[...i];e(n)},r.onerror=()=>{t(new Error(`Failed to get groups: ${r.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),r=t.objectStore(this.assetStoreName),i=new Set;z(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=()=>{z(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let l=a.meta?.insertedAt||a._insertedAt||Date.now(),u=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?l-u:u-l}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return z(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),z(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",u=e.tags?.map(s=>s.toLowerCase())??[];if(!o.every(s=>l.includes(s)||u.some(c=>c.includes(s))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(l=>e.tags?.includes(l))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,l)=>{let u,s;return i==="id"?(u=o.id,s=l.id):(u=o.meta?.[i]??null,s=l.meta?.[i]??null),u==null?r==="Ascending"?-1:1:s==null?r==="Ascending"?1:-1:typeof u=="string"&&typeof s=="string"?r==="Ascending"?u.localeCompare(s):s.localeCompare(u):r==="Ascending"?u<s?-1:u>s?1:0:u>s?-1:u<s?1:0}):r==="Descending"&&a.reverse(),n&&a.sort((o,l)=>o.active&&!l.active?-1:!o.active&&l.active?1:0)),a}};function z(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]=z(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]=z(n,t,a)}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(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,g)=>{let p=c.meta?.insertedAt||0;return(g.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,l=o+a,u=i.slice(o,l),s=l<i.length?n+1:void 0;return{assets:u,currentPage:n,nextPage:s,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}};var ar=typeof global=="object"&&global&&global.Object===Object&&global,st=ar,sr=typeof self=="object"&&self&&self.Object===Object&&self,lr=st||sr||Function("return this")(),S=lr,ur=S.Symbol,R=ur,lt=Object.prototype,cr=lt.hasOwnProperty,dr=lt.toString,W=R?R.toStringTag:void 0;function gr(e){var t=cr.call(e,W),r=e[W];try{e[W]=void 0;var i=!0}catch{}var n=dr.call(e);return i&&(t?e[W]=r:delete e[W]),n}var pr=gr,fr=Object.prototype,mr=fr.toString;function hr(e){return mr.call(e)}var br=hr,yr="[object Null]",vr="[object Undefined]",Ge=R?R.toStringTag:void 0;function wr(e){return e==null?e===void 0?vr:yr:Ge&&Ge in Object(e)?pr(e):br(e)}var ie=wr;function kr(e){return e!=null&&typeof e=="object"}var _e=kr,Lu=Array.isArray;function Ir(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var ut=Ir,Ar="[object AsyncFunction]",Sr="[object Function]",Cr="[object GeneratorFunction]",xr="[object Proxy]";function Er(e){if(!ut(e))return!1;var t=ie(e);return t==Sr||t==Cr||t==Ar||t==xr}var Mr=Er,jr=S["__core-js_shared__"],ve=jr,He=function(){var e=/[^.]+$/.exec(ve&&ve.keys&&ve.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function _r(e){return!!He&&He in e}var $r=_r,Lr=Function.prototype,Nr=Lr.toString;function Pr(e){if(e!=null){try{return Nr.call(e)}catch{}try{return e+""}catch{}}return""}var P=Pr,Or=/[\\^$.*+?()[\]{}|]/g,Dr=/^\[object .+?Constructor\]$/,Tr=Function.prototype,zr=Object.prototype,Rr=Tr.toString,Fr=zr.hasOwnProperty,Vr=RegExp("^"+Rr.call(Fr).replace(Or,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Ur(e){if(!ut(e)||$r(e))return!1;var t=Mr(e)?Vr:Dr;return t.test(P(e))}var Br=Ur;function Gr(e,t){return e?.[t]}var Hr=Gr;function qr(e,t){var r=Hr(e,t);return Br(r)?r:void 0}var F=qr,Zr=F(S,"WeakMap"),Se=Zr;function Qr(e,t){return e===t||e!==e&&t!==t}var Yr=Qr,Wr=9007199254740991;function Kr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Wr}var Jr=Kr,Nu=Object.prototype,Xr="[object Arguments]";function ei(e){return _e(e)&&ie(e)==Xr}var qe=ei,ct=Object.prototype,ti=ct.hasOwnProperty,ri=ct.propertyIsEnumerable,Pu=qe(function(){return arguments}())?qe:function(e){return _e(e)&&ti.call(e,"callee")&&!ri.call(e,"callee")},dt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ze=dt&&typeof module=="object"&&module&&!module.nodeType&&module,ii=Ze&&Ze.exports===dt,Qe=ii?S.Buffer:void 0,Ou=Qe?Qe.isBuffer:void 0,ni="[object Arguments]",oi="[object Array]",ai="[object Boolean]",si="[object Date]",li="[object Error]",ui="[object Function]",ci="[object Map]",di="[object Number]",gi="[object Object]",pi="[object RegExp]",fi="[object Set]",mi="[object String]",hi="[object WeakMap]",bi="[object ArrayBuffer]",yi="[object DataView]",vi="[object Float32Array]",wi="[object Float64Array]",ki="[object Int8Array]",Ii="[object Int16Array]",Ai="[object Int32Array]",Si="[object Uint8Array]",Ci="[object Uint8ClampedArray]",xi="[object Uint16Array]",Ei="[object Uint32Array]",v={};v[vi]=v[wi]=v[ki]=v[Ii]=v[Ai]=v[Si]=v[Ci]=v[xi]=v[Ei]=!0;v[ni]=v[oi]=v[bi]=v[ai]=v[yi]=v[si]=v[li]=v[ui]=v[ci]=v[di]=v[gi]=v[pi]=v[fi]=v[mi]=v[hi]=!1;function Mi(e){return _e(e)&&Jr(e.length)&&!!v[ie(e)]}var ji=Mi;function _i(e){return function(t){return e(t)}}var $i=_i,gt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ee=gt&&typeof module=="object"&&module&&!module.nodeType&&module,Li=ee&&ee.exports===gt,we=Li&&st.process,Ni=function(){try{var e=ee&&ee.require&&ee.require("util").types;return e||we&&we.binding&&we.binding("util")}catch{}}(),Ye=Ni,We=Ye&&Ye.isTypedArray,Du=We?$i(We):ji,Pi=Object.prototype,Tu=Pi.hasOwnProperty;function Oi(e,t){return function(r){return e(t(r))}}var Di=Oi,zu=Di(Object.keys,Object),Ti=Object.prototype,Ru=Ti.hasOwnProperty,zi=F(Object,"create"),te=zi;function Ri(){this.__data__=te?te(null):{},this.size=0}var Fi=Ri;function Vi(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Ui=Vi,Bi="__lodash_hash_undefined__",Gi=Object.prototype,Hi=Gi.hasOwnProperty;function qi(e){var t=this.__data__;if(te){var r=t[e];return r===Bi?void 0:r}return Hi.call(t,e)?t[e]:void 0}var Zi=qi,Qi=Object.prototype,Yi=Qi.hasOwnProperty;function Wi(e){var t=this.__data__;return te?t[e]!==void 0:Yi.call(t,e)}var Ki=Wi,Ji="__lodash_hash_undefined__";function Xi(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=te&&t===void 0?Ji:t,this}var en=Xi;function V(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])}}V.prototype.clear=Fi;V.prototype.delete=Ui;V.prototype.get=Zi;V.prototype.has=Ki;V.prototype.set=en;var Ke=V;function tn(){this.__data__=[],this.size=0}var rn=tn;function nn(e,t){for(var r=e.length;r--;)if(Yr(e[r][0],t))return r;return-1}var de=nn,on=Array.prototype,an=on.splice;function sn(e){var t=this.__data__,r=de(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():an.call(t,r,1),--this.size,!0}var ln=sn;function un(e){var t=this.__data__,r=de(t,e);return r<0?void 0:t[r][1]}var cn=un;function dn(e){return de(this.__data__,e)>-1}var gn=dn;function pn(e,t){var r=this.__data__,i=de(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var fn=pn;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=rn;U.prototype.delete=ln;U.prototype.get=cn;U.prototype.has=gn;U.prototype.set=fn;var ge=U,mn=F(S,"Map"),re=mn;function hn(){this.size=0,this.__data__={hash:new Ke,map:new(re||ge),string:new Ke}}var bn=hn;function yn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var vn=yn;function wn(e,t){var r=e.__data__;return vn(t)?r[typeof t=="string"?"string":"hash"]:r.map}var pe=wn;function kn(e){var t=pe(this,e).delete(e);return this.size-=t?1:0,t}var In=kn;function An(e){return pe(this,e).get(e)}var Sn=An;function Cn(e){return pe(this,e).has(e)}var xn=Cn;function En(e,t){var r=pe(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Mn=En;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=bn;B.prototype.delete=In;B.prototype.get=Sn;B.prototype.has=xn;B.prototype.set=Mn;var pt=B;function jn(){this.__data__=new ge,this.size=0}var _n=jn;function $n(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Ln=$n;function Nn(e){return this.__data__.get(e)}var Pn=Nn;function On(e){return this.__data__.has(e)}var Dn=On,Tn=200;function zn(e,t){var r=this.__data__;if(r instanceof ge){var i=r.__data__;if(!re||i.length<Tn-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new pt(i)}return r.set(e,t),this.size=r.size,this}var Rn=zn;function ne(e){var t=this.__data__=new ge(e);this.size=t.size}ne.prototype.clear=_n;ne.prototype.delete=Ln;ne.prototype.get=Pn;ne.prototype.has=Dn;ne.prototype.set=Rn;var Fn=Object.prototype,Fu=Fn.propertyIsEnumerable,Vn=F(S,"DataView"),Ce=Vn,Un=F(S,"Promise"),xe=Un,Bn=F(S,"Set"),Ee=Bn,Je="[object Map]",Gn="[object Object]",Xe="[object Promise]",et="[object Set]",tt="[object WeakMap]",rt="[object DataView]",Hn=P(Ce),qn=P(re),Zn=P(xe),Qn=P(Ee),Yn=P(Se),T=ie;(Ce&&T(new Ce(new ArrayBuffer(1)))!=rt||re&&T(new re)!=Je||xe&&T(xe.resolve())!=Xe||Ee&&T(new Ee)!=et||Se&&T(new Se)!=tt)&&(T=function(e){var t=ie(e),r=t==Gn?e.constructor:void 0,i=r?P(r):"";if(i)switch(i){case Hn:return rt;case qn:return Je;case Zn:return Xe;case Qn:return et;case Yn:return tt}return t});var Vu=S.Uint8Array,Wn="__lodash_hash_undefined__";function Kn(e){return this.__data__.set(e,Wn),this}var Jn=Kn;function Xn(e){return this.__data__.has(e)}var eo=Xn;function Me(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new pt;++t<r;)this.add(e[t])}Me.prototype.add=Me.prototype.push=Jn;Me.prototype.has=eo;var it=R?R.prototype:void 0,Uu=it?it.valueOf:void 0,to=Object.prototype,Bu=to.hasOwnProperty,ro=Object.prototype,Gu=ro.hasOwnProperty,Hu=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),qu=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Zu=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function ft(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 io(e,t){let r=await ft(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 no(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 ft(i,t)}function oo(e){return e!==void 0}var ao=oo;var $e=class mt{constructor(){this.actions=new Map,this.subscribers=new Map}static get(){let t="__imgly_action_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new mt),r[t]}register(t){return this.actions.set(t.id,t),this.notifySubscribers(t,"registered"),()=>{this.actions.get(t.id)===t&&(this.actions.delete(t.id),this.notifySubscribers(t,"unregistered"))}}getAll(){return Array.from(this.actions.values())}getBy(t){return this.getAll().filter(r=>this.matchesFilters(r,t))}subscribe(t){return this.subscribers.set(t,null),()=>{this.subscribers.delete(t)}}subscribeBy(t,r){return this.subscribers.set(r,t),()=>{this.subscribers.delete(r)}}notifySubscribers(t,r){this.subscribers.forEach((i,n)=>{if(i===null){n(t,r);return}this.matchesFilters(t,i)&&n(t,r)})}matchesFilters(t,r){return!(r.type&&t.type!==r.type||r.pluginId&&t.type==="plugin"&&t.pluginId!==r.pluginId||r.id&&t.id!==r.id||r.kind&&(t.type!=="quick"||t.kind!==r.kind))}},so=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 lo(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=s=>{a.push(s)},l=async(s,c,g)=>{if(s>=t.length)return r(c,g);let p=t[s],d=async(f,b)=>l(s+1,f,b),m={...g,addDisposer:o};return p(c,m,d)},u={...n,addDisposer:o};return{result:await l(0,i,u),dispose:async()=>{for(let s=a.length-1;s>=0;s--)try{await a[s]()}catch(c){console.error("Error in disposer:",c)}a.length=0}}}}function uo({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 co=uo;var ke="ly.img.ai.temp";async function go(e,t){return e.engine.asset.findAllSources().includes(ke)||e.engine.asset.addLocalSource(ke),e.engine.asset.apply(ke,t)}function po(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 bt(){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 fo(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=o.videoWidth,l.height=o.videoHeight;let u=l.getContext("2d");if(!u){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}u.drawImage(o,0,0,l.width,l.height);try{let s=l.toDataURL(r,i);document.body.removeChild(o),n(s)}catch(s){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function mo(e){return typeof e=="object"&&e!==null&&"next"in e&&"return"in e&&"throw"in e&&typeof e.next=="function"&&typeof e.return=="function"&&typeof e.throw=="function"&&Symbol.asyncIterator in e&&typeof e[Symbol.asyncIterator]=="function"}function Le(e){return e instanceof Error&&e.name==="AbortError"}function ho(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function yt(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
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(a){console.debug("[IMG.LY AI Plugins] Could not check plugin version consistency:",a)}}function po(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 gt=po;function go(){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 ft=go;function fo(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),mo(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:ao(e)})}function mo(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 Je=fo,bo="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Ee=bo;function yo(e,t,r){switch(t){case"image":return ho(e,r[t]);case"video":return vo(e,r[t]);case"sticker":return wo(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function ho(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ee,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function vo(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Ee,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function wo(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Ee,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var ko=yo;async function Io(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 Ao(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 xo(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 So(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 Co(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Ao(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 xo(e,t,r){let i=t.width,n=t.height,a=await so(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 So(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 Co(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=Io;function Eo(e){switch(e.userFlow){case"placeholder":return jo(e);case"generation-only":return Mo(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function Mo(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(C(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(C(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(C(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let s=dt(),u=await mt(s,n,a,o.output),l={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.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 jo(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(C(t,r))return{status:"aborted"};let s=dt(),u=ko(s,a,o);if(i=await oo(t,u),C(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),f=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,f),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let l=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(C(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 c=await mt(s,a,o,l.output);if(C(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(c,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(c,i),C(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),l}catch(a){return i!=null&&t.engine.block.isValid(i)&&(Ce(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 C(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var $o=Eo;function Me(e){return`${e}.generating`}function _o(e){return`${e}.abort`}function Lo(e,t,r,i,n,a,o){let{builder:s,experimental:u}=e,{cesdk:l,includeHistoryLibrary:c=!0}=a,{id:d,output:{abortable:f}}=t,g=u.global(_o(d),()=>{}),p=u.global(Me(d),!1),b,y=p.value&&f,m=()=>{y&&(g.value(),p.setValue(!1),g.setValue(()=>{}))},k;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let I=i();k=a.requiredInputs.every(h=>!I.input[h])}let A=u.global(`${d}.confirmationDialogId`,void 0);s.Section(`${d}.generate.section`,{children:()=>{s.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:p.value,color:"accent",isDisabled:k,suffix:y?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let I=l.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:h})=>{l.ui.closeDialog(h),A.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:h})=>{m(),l.ui.closeDialog(h),A.setValue(void 0)}}});A.setValue(I)}}:void 0,onClick:async()=>{b=new AbortController;let I=b.signal;await(async()=>{try{p.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),b?.abort()});let h=await $o({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:I,cesdk:l,debug:o.debug,dryRun:o.dryRun})(i().input);if(h.status==="aborted")return;if(h.status==="error"){Je(h.message,{cesdk:l,provider:t,getInput:i});return}if(h.status==="success"&&h.type==="sync"){let M=t.output.notification;No(l,M,()=>({input:i().input,output:h.output}))}}catch(h){if(Ce(h))return;Je(h,{cesdk:l,provider:t,getInput:i})}finally{b=void 0,p.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})}}),c&&a.historyAssetLibraryEntryId!=null&&s.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function No(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 bt=Lo;async function Oo({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,s=r.render;return u=>{let{state:l}=u,c=l(Me(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:f}=s(u,{cesdk:a,isGenerating:c});return bt(u,t,n,d,f,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var Po=Oo;function yt(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 Q(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=yt(e,t.$ref),n={...Q(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=Q(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>Q(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=Q(e,t[n],r));return i}return t}function Do(e){return Q(e,{...e})}function To(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 u=i[o][s];if(typeof u!="object"||u===null)return r(`Item ${s} in ${o} must be an object, got ${u===null?"null":typeof u}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let 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 zo(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return Ro(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function Ro(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=Fo(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function Fo(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 ht=zo;function vt(e,t,r,i,n,a,o){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let s=t,u=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(u){case"string":return t.schema.enum!=null?Vo(e,s,r,i,n,a,o):kt(e,s,r,i,n,a,o);case"boolean":return It(e,s,r,i,n,a,o);case"number":case"integer":return At(e,s,r,i,n,a,o);case"object":return wt(e,s,r,i,n,a,o);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return Uo(e,s,r,i,n,a,o);break}default:console.error(`Unsupported property type: ${u}`)}}function wt(e,t,r,i,n,a,o){let s=ht(t.schema??{},i).reduce((u,l)=>{let c=vt(e,l,r,i,n,a,o);return c!=null&&(u[l.id]=c()),u},{});return()=>({id:t.id,type:"object",value:s})}function kt(e,t,r,i,n,a,o){let{builder:s,experimental:{global:u}}=e,{id:l}=t,c=`${r.id}.${l}`,d=[`ly.img.plugin-ai-${o}-generation-web.${r.id}.property.${t.id}`,`ly.img.plugin-ai-generation-web.property.${t.id}`,`ly.img.plugin-ai-${o}-generation-web.${r.id}.defaults.property.${t.id}`,`ly.img.plugin-ai-generation-web.defaults.property.${t.id}`],f=u(c,t.schema.default??""),g=Bo(t.schema),p=g?.component!=null&&g?.component==="TextArea"?"TextArea":"TextInput";return s[p](c,{inputLabel:d,placeholder:n.i18n?.prompt,...f}),()=>({id:t.id,type:"string",value:f.value})}function Vo(e,t,r,i,n,a,o){let{builder:s,experimental:{global:u}}=e,{id:l}=t,c=`${r.id}.${l}`,d=[`ly.img.plugin-ai-${o}-generation-web.${r.id}.property.${t.id}`,`ly.img.plugin-ai-generation-web.property.${t.id}`,`ly.img.plugin-ai-${o}-generation-web.${r.id}.defaults.property.${t.id}`,`ly.img.plugin-ai-generation-web.defaults.property.${t.id}`],f="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},g="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},p=(t.schema.enum??[]).map(m=>({id:m,label:[`ly.img.plugin-ai-${o}-generation-web.${r.id}.property.${t.id}.${m}`,`ly.img.plugin-ai-generation-web.property.${t.id}.${m}`,`ly.img.plugin-ai-${o}-generation-web.${r.id}.defaults.property.${t.id}.${m}`,`ly.img.plugin-ai-generation-web.defaults.property.${t.id}.${m}`],icon:f[m]})),b=t.schema.default!=null?p.find(m=>m.id===t.schema.default)??p[0]:p[0],y=u(c,b);return s.Select(c,{inputLabel:d,values:p,...y}),()=>({id:t.id,type:"string",value:y.value.id})}function It(e,t,r,i,n,a,o){let{builder:s,experimental:{global:u}}=e,{id:l}=t,c=`${r.id}.${l}`,d=[`ly.img.plugin-ai-${o}-generation-web.${r.id}.property.${t.id}`,`ly.img.plugin-ai-generation-web.property.${t.id}`,`ly.img.plugin-ai-${o}-generation-web.${r.id}.defaults.property.${t.id}`,`ly.img.plugin-ai-generation-web.defaults.property.${t.id}`],f=!!t.schema.default,g=u(c,f);return s.Checkbox(c,{inputLabel:d,...g}),()=>({id:t.id,type:"boolean",value:g.value})}function At(e,t,r,i,n,a,o){let{builder:s,experimental:{global:u}}=e,{id:l}=t,c=`${r.id}.${l}`,d=[`ly.img.plugin-ai-${o}-generation-web.${r.id}.property.${t.id}`,`ly.img.plugin-ai-generation-web.property.${t.id}`,`ly.img.plugin-ai-${o}-generation-web.${r.id}.defaults.property.${t.id}`,`ly.img.plugin-ai-generation-web.defaults.property.${t.id}`],f=t.schema.minimum,g=t.schema.maximum,p=t.schema.default;p==null&&(f!=null?p=f:g!=null?p=g:p=0);let b=u(c,p);if(f!=null&&g!=null){let y=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(y=t.schema["x-imgly-step"]),s.Slider(c,{inputLabel:d,min:f,max:g,step:y,...b})}else s.NumberInput(c,{inputLabel:d,min:f,max:g,...b});return()=>({id:t.id,type:"integer",value:b.value})}function Uo(e,t,r,i,n,a,o){let{builder:s,experimental:{global:u}}=e,{id:l}=t,c=`${r.id}.${l}`,d=[`ly.img.plugin-ai-${o}-generation-web.${r.id}.property.${t.id}`,`ly.img.plugin-ai-generation-web.property.${t.id}`,`ly.img.plugin-ai-${o}-generation-web.${r.id}.defaults.property.${t.id}`,`ly.img.plugin-ai-generation-web.defaults.property.${t.id}`],f=t.schema.anyOf??[],g=[],p={},b={};f.forEach((k,A)=>{let I=k.title??"common.custom",h=`${r.id}.${l}.anyOf[${A}]`,M="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},H="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};k.type==="string"?k.enum!=null?k.enum.forEach(ae=>{g.push({id:ae,label:M[ae]??lo(ae),icon:H[ae]})}):(p[h]=()=>kt(e,{id:h,schema:{...k,title:I}},r,i,n,a,o),g.push({id:h,label:M[I]??I,icon:H[I]})):k.type==="boolean"?(p[h]=()=>It(e,{id:h,schema:{...k,title:I}},r,i,n,a,o),g.push({id:h,label:M[I]??I,icon:H[I]})):k.type==="integer"?(p[h]=()=>At(e,{id:h,schema:{...k,title:I}},r,i,n,a,o),g.push({id:h,label:M[I]??I,icon:H[I]})):k.type==="array"||k.type==="object"&&(p[h]=()=>wt(e,{id:h,schema:{...k,title:I}},r,i,n,a,o),g.push({id:h,label:M[I]??I,icon:H[I]}))});let y=t.schema.default!=null?g.find(k=>k.id===t.schema.default)??g[0]:g[0],m=u(c,y);if(s.Select(c,{inputLabel:d,values:g,...m}),m.value.id in p){let k=p[m.value.id]();b[m.value.id]=k}return()=>{let k=b[m.value.id];return k!=null?{...k(),id:t.id}:{id:t.id,type:"string",value:m.value.id}}}function Bo(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Go=vt,Ho={"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 Xe(e){return e.replace(/_/g," ").replace(/\b3d\b/gi,"3D").replace(/\b2d\b/gi,"2D").replace(/\b\w/g,t=>t.toUpperCase())}function qo(e,t,r,i){let n={};e.forEach(o=>{if(o.schema?.title&&(n[`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${o.id}`]=o.schema.title),o.schema?.enum){let s="x-imgly-enum-labels"in o.schema&&typeof o.schema["x-imgly-enum-labels"]=="object"?o.schema["x-imgly-enum-labels"]:{};o.schema.enum.forEach(u=>{let l=String(u),c=s[l]||Xe(l);n[`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${o.id}.${l}`]=c})}if(o.schema?.anyOf&&Array.isArray(o.schema.anyOf)){let s="x-imgly-enum-labels"in o.schema&&typeof o.schema["x-imgly-enum-labels"]=="object"?o.schema["x-imgly-enum-labels"]:{};o.schema.anyOf.forEach(u=>{let l=u;l.enum&&Array.isArray(l.enum)&&l.enum.forEach(c=>{let d=String(c),f=s[d]||Xe(d);n[`ly.img.plugin-ai-${i}-generation-web.defaults.property.${t.id}.${o.id}.${d}`]=f})})}});let a={...Ho,...n};Object.keys(a).length>0&&r.cesdk.i18n.setTranslations({en:a})}async function Zo({options:e,provider:t,panelInput:r,config:i},n){let{id:a}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${a}`);let o=Do(r.document),s=yt(o,r.inputReference);if(!To(s,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=s,l=ht(u,r);return qo(l,t,e,t.kind),c=>{let{builder:d}=c,f=[];d.Section(`${a}.schema.section`,{children:()=>{l.forEach(y=>{let m=Go(c,y,t,r,e,i,t.kind);m!=null&&(Array.isArray(m)?f.push(...m):f.push(m))})}});let g=f.map(y=>y()),p=y=>y.type==="object"?Object.entries(y.value).reduce((m,[k,A])=>(m[k]=p(A),m),{}):y.value,b=g.reduce((y,m)=>(y[m.id]=p(m),y),{});bt(c,t,n,()=>({input:b}),()=>r.getBlockInput(b),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var Qo=Zo;async function Yo(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return Po(e,t);case"schema":return Qo(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var Wo=Yo;function Ko(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 Jt(o,r)),o}return i}var Jo=Ko;function Xo(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 ea=Xo,ye="@imgly/plugin-ai-generation",ta=`
|
|
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 bo(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 vt=bo;function yo(){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 wt=yo;function vo(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),wo(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:po(e)})}function wo(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 nt=vo,ko="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Ne=ko;function Io(e,t,r){switch(t){case"image":return Ao(e,r[t]);case"video":return So(e,r[t]);case"sticker":return Co(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Ao(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 So(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 Co(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 xo=Io;async function Eo(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 Mo(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 jo(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 _o(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 $o(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Mo(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 jo(e,t,r){let i=t.width,n=t.height,a=await fo(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 _o(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 $o(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 kt=Eo;function Lo(e){switch(e.userFlow){case"placeholder":return Po(e);case"generation-only":return No(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function No(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(j(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(j(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(j(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let l=bt(),u=await kt(l,n,a,o.output),s={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,s)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Po(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(j(t,r))return{status:"aborted"};let l=bt(),u=xo(l,a,o);if(i=await go(t,u),j(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let g=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),d=t.engine.block.duplicate(i);t.engine.block.setPositionX(d,g),t.engine.block.setPositionY(d,p),t.engine.block.destroy(i),i=d}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(j(t,r,i))return{status:"aborted"};if(s.status!=="success")return s;if(s.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let c=await kt(l,a,o,s.output);if(j(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(c,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(c,i),j(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let g={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,g)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),s}catch(a){return i!=null&&t.engine.block.isValid(i)&&(Le(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 j(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var Oo=Lo;function Pe(e){return`${e}.generating`}function Do(e){return`${e}.abort`}function To(e,t,r,i,n,a,o){let{builder:l,experimental:u}=e,{cesdk:s,includeHistoryLibrary:c=!0}=a,{id:g,output:{abortable:p}}=t,d=u.global(Do(g),()=>{}),m=u.global(Pe(g),!1),f,b=m.value&&p,y=()=>{b&&(d.value(),m.setValue(!1),d.setValue(()=>{}))},$;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let A=i();$=a.requiredInputs.every(k=>!A.input[k])}let I=u.global(`${g}.confirmationDialogId`,void 0);l.Section(`${g}.generate.section`,{children:()=>{l.Button(`${g}.generate`,{label:["common.generate",`panel.${g}.generate`],isLoading:m.value,color:"accent",isDisabled:$,suffix:b?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${g}.abort`,"common.cancel"],onClick:()=>{let A=s.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:k})=>{s.ui.closeDialog(k),I.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:k})=>{y(),s.ui.closeDialog(k),I.setValue(void 0)}}});I.setValue(A)}}:void 0,onClick:async()=>{f=new AbortController;let A=f.signal;await(async()=>{try{m.setValue(!0),d.setValue(()=>{o.debug&&console.log("Aborting generation"),f?.abort()});let k=await Oo({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:A,cesdk:s,debug:o.debug,dryRun:o.dryRun})(i().input);if(k.status==="aborted")return;if(k.status==="error"){nt(k.message,{cesdk:s,provider:t,getInput:i});return}if(k.status==="success"&&k.type==="sync"){let x=t.output.notification;zo(s,x,()=>({input:i().input,output:k.output}))}}catch(k){if(Le(k))return;nt(k,{cesdk:s,provider:t,getInput:i})}finally{f=void 0,m.setValue(!1),d.setValue(()=>{}),I.value!=null&&(s.ui.closeDialog(I.value),I.setValue(void 0))}})()}}),t.output.generationHintText!=null&&l.Text(`${g}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),c&&a.historyAssetLibraryEntryId!=null&&l.Library(`${g}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function zo(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 It=To;async function Ro({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t,l=r.render;return u=>{let{state:s}=u,c=s(Pe(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:g,getBlockInput:p}=l(u,{cesdk:a,isGenerating:c});return It(u,t,n,g,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),g}}var Fo=Ro;function At(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 J(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=At(e,t.$ref),n={...J(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=J(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>J(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=J(e,t[n],r));return i}return t}function Vo(e){return J(e,{...e})}function Uo(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let l of i.type)if(typeof l!="string"||!o.includes(l))return r(`Array of types contains invalid value: ${l}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let l=0;l<i[o].length;l++){let u=i[o][l];if(typeof u!="object"||u===null)return r(`Item ${l} in ${o} must be an object, got ${u===null?"null":typeof u}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let l=i.required[o];if(typeof l!="string")return r(`Item ${o} in required array must be a string, got ${typeof l}`)}}return!0}function Bo(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return Go(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function Go(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=Ho(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function Ho(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 St=Bo;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 xt(e,t,r,i,n,a,o){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let l=t,u=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(u){case"string":return t.schema.enum!=null?qo(e,l,r,i,n,a,o):Et(e,l,r,i,n,a,o);case"boolean":return Mt(e,l,r,i,n,a,o);case"number":case"integer":return jt(e,l,r,i,n,a,o);case"object":return je(e,l,r,i,n,a,o);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return Zo(e,l,r,i,n,a,o);break}default:console.error(`Unsupported property type: ${u}`)}}function je(e,t,r,i,n,a,o){let l=St(t.schema??{},i).reduce((u,s)=>{let c=xt(e,s,r,i,n,a,o);return c!=null&&(u[s.id]=c()),u},{});return()=>({id:t.id,type:"object",value:l})}function Et(e,t,r,i,n,a,o){let{builder:l,experimental:{global:u}}=e,{id:s}=t,c=`${r.id}.${s}`,g=N(t,r,o),p=u(c,t.schema.default??""),d=Qo(t.schema),m=d?.component!=null&&d?.component==="TextArea"?"TextArea":"TextInput";return l[m](c,{inputLabel:g,placeholder:n.i18n?.prompt,...p}),()=>({id:t.id,type:"string",value:p.value})}function qo(e,t,r,i,n,a,o){let{builder:l,experimental:{global:u}}=e,{id:s}=t,c=`${r.id}.${s}`,g=N(t,r,o),{labels:p,icons:d}=Ct(t.schema),m=(t.schema.enum??[]).map(y=>({id:y,label:N(t,r,o,y),icon:d[y]})),f=t.schema.default!=null?m.find(y=>y.id===t.schema.default)??m[0]:m[0],b=u(c,f);return l.Select(c,{inputLabel:g,values:m,...b}),()=>({id:t.id,type:"string",value:b.value.id})}function Mt(e,t,r,i,n,a,o){let{builder:l,experimental:{global:u}}=e,{id:s}=t,c=`${r.id}.${s}`,g=N(t,r,o),p=!!t.schema.default,d=u(c,p);return l.Checkbox(c,{inputLabel:g,...d}),()=>({id:t.id,type:"boolean",value:d.value})}function jt(e,t,r,i,n,a,o){let{builder:l,experimental:{global:u}}=e,{id:s}=t,c=`${r.id}.${s}`,g=N(t,r,o),p=t.schema.minimum,d=t.schema.maximum,m=t.schema.default;m==null&&(p!=null?m=p:d!=null?m=d:m=0);let f=u(c,m);if(p!=null&&d!=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(c,{inputLabel:g,min:p,max:d,step:b,...f})}else l.NumberInput(c,{inputLabel:g,min:p,max:d,...f});return()=>({id:t.id,type:"integer",value:f.value})}function Zo(e,t,r,i,n,a,o){let{builder:l,experimental:{global:u}}=e,{id:s}=t,c=`${r.id}.${s}`,g=N(t,r,o),p=t.schema.anyOf??[],d=[],m={},f={},{labels:b,icons:y}=Ct(t.schema),$={string:Et,boolean:Mt,integer:jt,object:je},I=(h,L)=>h.$ref?h.$ref.split("/").pop():L.split(".").pop()??L,A=(h,L)=>({id:h,label:N(t,r,o,L),icon:y[L]??y[h]});p.forEach((h,L)=>{let E=`${r.id}.${s}.anyOf[${L}]`;if(h.$ref||h.title){let M=h.$ref?h.$ref.split("/").pop():h.title;m[E]=()=>je(e,{id:E,schema:{...h,title:b[M]||M}},r,i,n,a,o),d.push(A(E,M))}else if(h.type==="string"&&h.enum)h.enum.forEach(M=>{d.push(A(M,M))});else if(h.type&&$[h.type]){let M=$[h.type];m[E]=()=>M(e,{id:E,schema:{...h,title:h.title}},r,i,n,a,o);let ye=I(h,E);d.push(h.type==="string"&&!h.enum?{id:E,label:h.title||ye,icon:h.title&&y[h.title]||y[ye]}:A(E,ye))}});let k=t.schema.default!=null?d.find(h=>h.id===t.schema.default)??d[0]:d[0],x=u(c,k);if(l.Select(c,{inputLabel:g,values:d,...x}),x.value.id in m){let h=m[x.value.id]();f[x.value.id]=h}return()=>{let h=f[x.value.id];return h!=null?{...h(),id:t.id}:{id:t.id,type:"string",value:x.value.id}}}function Qo(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Yo=xt,Wo={"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 Ko(e,t,r,i){let n={},a=(s,c)=>`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${s}${c?`.${c}`:""}`,o=s=>"x-imgly-enum-labels"in s&&typeof s["x-imgly-enum-labels"]=="object"?s["x-imgly-enum-labels"]:{},l=(s,c,g)=>{s.forEach(p=>{let d=String(p),m=g[d]||ot(d);n[a(c,d)]=m})};e.forEach(s=>{if(s.schema?.title&&(n[a(s.id)]=s.schema.title),s.schema?.enum){let c=o(s.schema);l(s.schema.enum,s.id,c)}if(s.schema?.anyOf&&Array.isArray(s.schema.anyOf)){let c=o(s.schema);s.schema.anyOf.forEach(g=>{let p=g;if(p.enum&&Array.isArray(p.enum))l(p.enum,s.id,c);else if(p.$ref){let d=p.$ref.split("/").pop();d&&c[d]&&(n[a(s.id,d)]=c[d])}else if(p.title){let d=p.title,m=c[d]||ot(d);n[a(s.id,d)]=m}})}});let u={...Wo,...n};Object.keys(u).length>0&&r.cesdk.i18n.setTranslations({en:u})}async function Jo({options:e,provider:t,panelInput:r,config:i},n){let{id:a}=t;if(r==null)return;i.debug&&console.log(`Registering schema-based panel input for provider ${a}`);let o=Vo(r.document),l=At(o,r.inputReference);if(!Uo(l,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=l,s=St(u,r);return Ko(s,t,e,t.kind),c=>{let{builder:g}=c,p=[];g.Section(`${a}.schema.section`,{children:()=>{s.forEach(b=>{let y=Yo(c,b,t,r,e,i,t.kind);y!=null&&(Array.isArray(y)?p.push(...y):p.push(y))})}});let d=p.map(b=>b()),m=b=>b.type==="object"?Object.entries(b.value).reduce((y,[$,I])=>(y[$]=m(I),y),{}):b.value,f=d.reduce((b,y)=>(b[y.id]=m(y),b),{});It(c,t,n,()=>({input:f}),()=>r.getBlockInput(f),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var Xo=Jo;async function ea(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return Fo(e,t);case"schema":return Xo(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var ta=ea;function ra(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 nr(o,r)),o}return i}var ia=ra;function na(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 oa=na,Ie="@imgly/plugin-ai-generation",aa=`
|
|
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="${
|
|
22
|
+
id="${Ie}/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="${
|
|
34
|
+
id="${Ie}/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="${
|
|
45
|
+
id="${Ie}/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,8 +62,8 @@ Consider updating all AI plugins to the same version for optimal compatibility.`
|
|
|
62
62
|
|
|
63
63
|
</symbol>
|
|
64
64
|
</svg>
|
|
65
|
-
`,
|
|
66
|
-
`,"+")}`}}async function aa(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function sa(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=Z(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=Z(n,o)}else"customPrompt"in e?a=Z(n,"custom"):a=Z(n,"improved");else a=Z(n,"generated");return la(a,r.abortSignal)}async function*la(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 xt(100)}return{kind:"text",text:e}}function Z(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 u=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],l=0;for(;s.length<n;){let c=u[l%u.length];if(s.length+c.length<=n)s+=c;else{s+=c.substring(0,n-s.length);break}l++}}return r+s}async function ua(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:ca(220,i),duration:i,thumbnailUrl:void 0}}function ca(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 da(i,44100)}function da(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,s=r*i,u=44+s,l=new ArrayBuffer(u),c=new DataView(l),d=(b,y)=>{for(let m=0;m<y.length;m++)c.setUint8(b+m,y.charCodeAt(m))};d(0,"RIFF"),c.setUint32(4,u-8,!0),d(8,"WAVE"),d(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,n,!0),c.setUint32(24,t,!0),c.setUint32(28,o,!0),c.setUint16(32,a,!0),c.setUint16(34,16,!0),d(36,"data"),c.setUint32(40,s,!0);let f=44;for(let b=0;b<r;b++){let y=Math.max(-1,Math.min(1,e[b])),m=Math.round(y*32767);c.setInt16(f,m,!0),f+=2}let g=new Uint8Array(l),p="";for(let b=0;b<g.length;b++)p+=String.fromCharCode(g[b]);return`data:audio/wav;base64,${btoa(p)}`}async function xt(e){return new Promise(t=>{setTimeout(t,e)})}var pa=ia,ga="USER_CANCEL";function fa(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=ro([...e.provider.output.middleware??[],...r?.middlewares??[],no({enable:r?.debug}),pa({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"}:uo(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return Ce(n)?{status:"aborted",message:n.message}:n===ga?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var ma=fa;async function ba(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n};await t.initialize?.({...r,engine:r.cesdk.engine});let o=Jo(a),s=ea(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=s;let u=ma({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),l=await Wo(a,u);co(r.cesdk,"@imgly/plugin-ai-generation",ra);let c={provider:t,panel:{builderRenderFunction:l},history:{assetSourceId:o,assetLibraryEntryId:s},generate:u};return to.get().register(c),c}var he=ba;function ya(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 Xt(n,r,i);return r.engine.asset.addSource(a),a.id}var ha=ya;async function va(e,t,r,i){let n,a=[];if(Array.isArray(t)){let u=await Promise.all(t.map(l=>he(e,l,r,i)));a.push(...u),n=ka({prefix:e,providerInitializationResults:a})}else{let u=await Promise.all(t.fromText.map(c=>he(e,c,r,i)));a.push(...u);let l=await Promise.all(t.fromImage.map(c=>he(e,c,r,i)));a.push(...l),n=wa({prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:u,initializedFromImageProviders:l})}let o=ha({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(u=>u.history?.assetSourceId).filter(eo)}),s;return o!=null&&(s=o,r.cesdk.ui.addAssetLibraryEntry({id:s,sourceIds:[o],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"})),{panel:{builderRenderFunction:n},history:{assetSourceId:o,assetLibraryEntryId:s},providerInitializationResults:a}}function wa({prefix:e,initializedFromTextProviders:t,initializedFromImageProviders:r}){let i=t.length>0&&r.length>0;return n=>{let{builder:a,experimental:o}=n,s=o.global(`${e}.fromType`,i?"fromText":void 0),u=[];s.value==="fromText"?u.push(...t):s.value==="fromImage"?u.push(...r):u.push(...t,...r);let l=t.map(({provider:p,panel:b})=>({id:p.id,label:p.name??p.id,builderRenderFunction:b?.builderRenderFunction})),c=r.map(({provider:p,panel:b})=>({id:p.id,label:p.name??p.id,builderRenderFunction:b?.builderRenderFunction})),d=n.experimental.global(`${e}.selectedProvider.fromText`,l[0]),f=n.experimental.global(`${e}.selectedProvider.fromImage`,c[0]),g=s.value==="fromText"?d:s.value==="fromImage"?f:void 0;if((i||u.length>1)&&a.Section(`${e}.providerSelection.section`,{children:()=>{if(i&&a.ButtonGroup(`${e}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{a.Button(`${e}.fromType.buttonGroup.fromText`,{label:"Text",icon:s.value!=="fromText"&&et(t,n)?"@imgly/LoadingSpinner":void 0,isActive:s.value==="fromText",onClick:()=>{s.setValue("fromText")}}),a.Button(`${e}.fromType.buttonGroup.fromImage`,{label:"Image",icon:s.value!=="fromImage"&&et(r,n)?"@imgly/LoadingSpinner":void 0,isActive:s.value==="fromImage",onClick:()=>{s.setValue("fromImage")}})}}),u.length>1){let p=s.value==="fromText"?l:s.value==="fromImage"?c:[...l,...c];g!=null&&a.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:p,...g})}}}),u.length>1)g?.value.builderRenderFunction?.(n);else{let p=u[0];p&&p.panel?.builderRenderFunction?.(n)}}}function ka({prefix:e,providerInitializationResults:t}){return r=>{let{builder:i}=r;if(t.length===0)return;let n=t.map(({provider:o,panel:s})=>({id:o.id,label:o.name??o.id,builderRenderFunction:s?.builderRenderFunction})),a=r.state(`${e}.selectedProvider`,n[0]);t.length>1&&a!=null&&i.Section(`${e}.providerSelection.section`,{children:()=>{i.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:n,...a})}}),a.value.builderRenderFunction?.(r)}}function et(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Me(r.id),!1).value)}var St=va;var Ia=typeof global=="object"&&global&&global.Object===Object&&global,Ft=Ia,Aa=typeof self=="object"&&self&&self.Object===Object&&self,xa=Ft||Aa||Function("return this")(),S=xa,Sa=S.Symbol,F=Sa,Vt=Object.prototype,Ca=Vt.hasOwnProperty,Ea=Vt.toString,ee=F?F.toStringTag:void 0;function Ma(e){var t=Ca.call(e,ee),r=e[ee];try{e[ee]=void 0;var i=!0}catch{}var n=Ea.call(e);return i&&(t?e[ee]=r:delete e[ee]),n}var ja=Ma,$a=Object.prototype,_a=$a.toString;function La(e){return _a.call(e)}var Na=La,Oa="[object Null]",Pa="[object Undefined]",Ct=F?F.toStringTag:void 0;function Da(e){return e==null?e===void 0?Pa:Oa:Ct&&Ct in Object(e)?ja(e):Na(e)}var ne=Da;function Ta(e){return e!=null&&typeof e=="object"}var De=Ta,Gu=Array.isArray;function za(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Ut=za,Ra="[object AsyncFunction]",Fa="[object Function]",Va="[object GeneratorFunction]",Ua="[object Proxy]";function Ba(e){if(!Ut(e))return!1;var t=ne(e);return t==Fa||t==Va||t==Ra||t==Ua}var Ga=Ba,Ha=S["__core-js_shared__"],je=Ha,Et=function(){var e=/[^.]+$/.exec(je&&je.keys&&je.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function qa(e){return!!Et&&Et in e}var Za=qa,Qa=Function.prototype,Ya=Qa.toString;function Wa(e){if(e!=null){try{return Ya.call(e)}catch{}try{return e+""}catch{}}return""}var $=Wa,Ka=/[\\^$.*+?()[\]{}|]/g,Ja=/^\[object .+?Constructor\]$/,Xa=Function.prototype,es=Object.prototype,ts=Xa.toString,rs=es.hasOwnProperty,is=RegExp("^"+ts.call(rs).replace(Ka,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ns(e){if(!Ut(e)||Za(e))return!1;var t=Ga(e)?is:Ja;return t.test($(e))}var os=ns;function as(e,t){return e?.[t]}var ss=as;function ls(e,t){var r=ss(e,t);return os(r)?r:void 0}var V=ls,us=V(S,"WeakMap"),_e=us;function cs(e,t){return e===t||e!==e&&t!==t}var ds=cs,ps=9007199254740991;function gs(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ps}var fs=gs;var Hu=Object.prototype;var ms="[object Arguments]";function bs(e){return De(e)&&ne(e)==ms}var Mt=bs,Bt=Object.prototype,ys=Bt.hasOwnProperty,hs=Bt.propertyIsEnumerable,qu=Mt(function(){return arguments}())?Mt:function(e){return De(e)&&ys.call(e,"callee")&&!hs.call(e,"callee")};var Gt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,jt=Gt&&typeof module=="object"&&module&&!module.nodeType&&module,vs=jt&&jt.exports===Gt,$t=vs?S.Buffer:void 0,Zu=$t?$t.isBuffer:void 0;var ws="[object Arguments]",ks="[object Array]",Is="[object Boolean]",As="[object Date]",xs="[object Error]",Ss="[object Function]",Cs="[object Map]",Es="[object Number]",Ms="[object Object]",js="[object RegExp]",$s="[object Set]",_s="[object String]",Ls="[object WeakMap]",Ns="[object ArrayBuffer]",Os="[object DataView]",Ps="[object Float32Array]",Ds="[object Float64Array]",Ts="[object Int8Array]",zs="[object Int16Array]",Rs="[object Int32Array]",Fs="[object Uint8Array]",Vs="[object Uint8ClampedArray]",Us="[object Uint16Array]",Bs="[object Uint32Array]",w={};w[Ps]=w[Ds]=w[Ts]=w[zs]=w[Rs]=w[Fs]=w[Vs]=w[Us]=w[Bs]=!0;w[ws]=w[ks]=w[Ns]=w[Is]=w[Os]=w[As]=w[xs]=w[Ss]=w[Cs]=w[Es]=w[Ms]=w[js]=w[$s]=w[_s]=w[Ls]=!1;function Gs(e){return De(e)&&fs(e.length)&&!!w[ne(e)]}var Hs=Gs;function qs(e){return function(t){return e(t)}}var Zs=qs,Ht=typeof exports=="object"&&exports&&!exports.nodeType&&exports,te=Ht&&typeof module=="object"&&module&&!module.nodeType&&module,Qs=te&&te.exports===Ht,$e=Qs&&Ft.process,Ys=function(){try{var e=te&&te.require&&te.require("util").types;return e||$e&&$e.binding&&$e.binding("util")}catch{}}(),_t=Ys,Lt=_t&&_t.isTypedArray,Qu=Lt?Zs(Lt):Hs;var Ws=Object.prototype,Yu=Ws.hasOwnProperty;function Ks(e,t){return function(r){return e(t(r))}}var Js=Ks,Wu=Js(Object.keys,Object);var Xs=Object.prototype,Ku=Xs.hasOwnProperty;var el=V(Object,"create"),re=el;function tl(){this.__data__=re?re(null):{},this.size=0}var rl=tl;function il(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var nl=il,ol="__lodash_hash_undefined__",al=Object.prototype,sl=al.hasOwnProperty;function ll(e){var t=this.__data__;if(re){var r=t[e];return r===ol?void 0:r}return sl.call(t,e)?t[e]:void 0}var ul=ll,cl=Object.prototype,dl=cl.hasOwnProperty;function pl(e){var t=this.__data__;return re?t[e]!==void 0:dl.call(t,e)}var gl=pl,fl="__lodash_hash_undefined__";function ml(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=re&&t===void 0?fl:t,this}var bl=ml;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=rl;U.prototype.delete=nl;U.prototype.get=ul;U.prototype.has=gl;U.prototype.set=bl;var Nt=U;function yl(){this.__data__=[],this.size=0}var hl=yl;function vl(e,t){for(var r=e.length;r--;)if(ds(e[r][0],t))return r;return-1}var ce=vl,wl=Array.prototype,kl=wl.splice;function Il(e){var t=this.__data__,r=ce(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():kl.call(t,r,1),--this.size,!0}var Al=Il;function xl(e){var t=this.__data__,r=ce(t,e);return r<0?void 0:t[r][1]}var Sl=xl;function Cl(e){return ce(this.__data__,e)>-1}var El=Cl;function Ml(e,t){var r=this.__data__,i=ce(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var jl=Ml;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=hl;B.prototype.delete=Al;B.prototype.get=Sl;B.prototype.has=El;B.prototype.set=jl;var de=B,$l=V(S,"Map"),ie=$l;function _l(){this.size=0,this.__data__={hash:new Nt,map:new(ie||de),string:new Nt}}var Ll=_l;function Nl(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Ol=Nl;function Pl(e,t){var r=e.__data__;return Ol(t)?r[typeof t=="string"?"string":"hash"]:r.map}var pe=Pl;function Dl(e){var t=pe(this,e).delete(e);return this.size-=t?1:0,t}var Tl=Dl;function zl(e){return pe(this,e).get(e)}var Rl=zl;function Fl(e){return pe(this,e).has(e)}var Vl=Fl;function Ul(e,t){var r=pe(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Bl=Ul;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=Ll;G.prototype.delete=Tl;G.prototype.get=Rl;G.prototype.has=Vl;G.prototype.set=Bl;var qt=G;function Gl(){this.__data__=new de,this.size=0}var Hl=Gl;function ql(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Zl=ql;function Ql(e){return this.__data__.get(e)}var Yl=Ql;function Wl(e){return this.__data__.has(e)}var Kl=Wl,Jl=200;function Xl(e,t){var r=this.__data__;if(r instanceof de){var i=r.__data__;if(!ie||i.length<Jl-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new qt(i)}return r.set(e,t),this.size=r.size,this}var eu=Xl;function oe(e){var t=this.__data__=new de(e);this.size=t.size}oe.prototype.clear=Hl;oe.prototype.delete=Zl;oe.prototype.get=Yl;oe.prototype.has=Kl;oe.prototype.set=eu;var tu=Object.prototype,Ju=tu.propertyIsEnumerable;var ru=V(S,"DataView"),Le=ru,iu=V(S,"Promise"),Ne=iu,nu=V(S,"Set"),Oe=nu,Ot="[object Map]",ou="[object Object]",Pt="[object Promise]",Dt="[object Set]",Tt="[object WeakMap]",zt="[object DataView]",au=$(Le),su=$(ie),lu=$(Ne),uu=$(Oe),cu=$(_e),R=ne;(Le&&R(new Le(new ArrayBuffer(1)))!=zt||ie&&R(new ie)!=Ot||Ne&&R(Ne.resolve())!=Pt||Oe&&R(new Oe)!=Dt||_e&&R(new _e)!=Tt)&&(R=function(e){var t=ne(e),r=t==ou?e.constructor:void 0,i=r?$(r):"";if(i)switch(i){case au:return zt;case su:return Ot;case lu:return Pt;case uu:return Dt;case cu:return Tt}return t});var Xu=S.Uint8Array;var du="__lodash_hash_undefined__";function pu(e){return this.__data__.set(e,du),this}var gu=pu;function fu(e){return this.__data__.has(e)}var mu=fu;function Pe(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new qt;++t<r;)this.add(e[t])}Pe.prototype.add=Pe.prototype.push=gu;Pe.prototype.has=mu;var Rt=F?F.prototype:void 0,ec=Rt?Rt.valueOf:void 0;var bu=Object.prototype,tc=bu.hasOwnProperty;var yu=Object.prototype,rc=yu.hasOwnProperty;var ic=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),nc=new RegExp(/[A-Fa-f0-9]{1}/,"g"),oc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function hu(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Blob([n],{type:r});return URL.createObjectURL(a)}else return e}async function Zt(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 hu(i,t)}function vu(e){return e==null?[]:Array.isArray(e)?e:[e]}var Te=vu;var _="@imgly/plugin-ai-video-generation-web",wu=["ly.img.createVideo"];var Yt="createVideo",Qt=`ly.img.${Yt}`,ge=`ly.img.plugin-ai-video-generation-web.quickAction.${Yt}`,ku=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${ge}`]:"Create Video...",[`${ge}.description`]:"Create a video from the image"}}),{id:Qt,type:"quick",kind:"image",label:`${ge}`,enable:ft(),scopes:[],render:({builder:r,engine:i,close:n,providerId:a})=>{r.Button(`${Qt}.button`,{label:`${ge}`,icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=i.block.findAllSelected(),s=await Zt(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)}}})}}),Wt=ku;var E="ly.img.ai.video-generation";function Iu(e){return{async initialize({cesdk:t}){if(t==null)return;pt(t,_,"0.2.4"),t.setTranslations({en:{[`panel.${E}`]:"Video Generation",[`${E}.dock.label`]:"AI Video"}}),Au(e);let i=Se.get().register({type:"plugin",sceneMode:"Video",id:_,pluginId:_,label:"Generate Video",meta:{panelId:E},execute:()=>{t.ui.isPanelOpen(E)?t.ui.closePanel(E):t.ui.openPanel(E)}}),n=e.providers?.text2video??e.text2video,a=e.providers?.image2video??e.image2video,o=await Promise.all(Te(n).map(c=>c({cesdk:t}))),s=await Promise.all(Te(a).map(c=>c({cesdk:t})));if(!(o.length>0||s.length>0)){i();return}let l=await St("video",{fromText:o,fromImage:s},{cesdk:t},e);Se.get().register(Wt({cesdk:t})),l.panel.builderRenderFunction!=null?(t.ui.registerPanel(E,l.panel.builderRenderFunction),gt({cesdk:t,panelId:E})):i()}}}function Au(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 Kt=Iu;var xu=e=>({name:_,version:"0.2.4",...Kt(e)}),kc=xu;export{wu as DEFAULT_VIDEO_QUICK_ACTION_ORDER,kc as default};
|
|
65
|
+
`,sa=aa;function la(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 ua(t,e,r)):i(t,r)}async function ua(e,t,r){switch(t.kind){case"image":return ca(e,t,r);case"video":return da(e,t,r);case"text":return ga(e,t,r);case"audio":return fa(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function ca(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,u=await no(l,r),s=await io(u,r);i=s.width,n=s.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
|
|
66
|
+
`,"+")}`}}async function da(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function ga(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,l=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);l&&l[1]&&(i=l[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=K(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=K(n,o)}else"customPrompt"in e?a=K(n,"custom"):a=K(n,"improved");else a=K(n,"generated");return pa(a,r.abortSignal)}async function*pa(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 K(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,l="";if(n<=o.length)l=o.substring(0,n);else{l=o;let u=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],s=0;for(;l.length<n;){let c=u[s%u.length];if(l.length+c.length<=n)l+=c;else{l+=c.substring(0,n-l.length);break}s++}}return r+l}async function fa(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:ma(220,i),duration:i,thumbnailUrl:void 0}}function ma(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 ha(i,44100)}function ha(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,l=r*i,u=44+l,s=new ArrayBuffer(u),c=new DataView(s),g=(f,b)=>{for(let y=0;y<b.length;y++)c.setUint8(f+y,b.charCodeAt(y))};g(0,"RIFF"),c.setUint32(4,u-8,!0),g(8,"WAVE"),g(12,"fmt "),c.setUint32(16,16,!0),c.setUint16(20,1,!0),c.setUint16(22,n,!0),c.setUint32(24,t,!0),c.setUint32(28,o,!0),c.setUint16(32,a,!0),c.setUint16(34,16,!0),g(36,"data"),c.setUint32(40,l,!0);let p=44;for(let f=0;f<r;f++){let b=Math.max(-1,Math.min(1,e[f])),y=Math.round(b*32767);c.setInt16(p,y,!0),p+=2}let d=new Uint8Array(s),m="";for(let f=0;f<d.length;f++)m+=String.fromCharCode(d[f]);return`data:audio/wav;base64,${btoa(m)}`}async function _t(e){return new Promise(t=>{setTimeout(t,e)})}var ba=la,ya="USER_CANCEL";function va(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=lo([...e.provider.output.middleware??[],...r?.middlewares??[],co({enable:r?.debug}),ba({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"}:mo(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return Le(n)?{status:"aborted",message:n.message}:n===ya?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var wa=va;async function ka(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n};await t.initialize?.({...r,engine:r.cesdk.engine});let o=ia(a),l=oa(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=l;let u=wa({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),s=await ta(a,u);ho(r.cesdk,"@imgly/plugin-ai-generation",sa);let c={provider:t,panel:{builderRenderFunction:s},history:{assetSourceId:o,assetLibraryEntryId:l},generate:u};return so.get().register(c),c}var Ae=ka;function Ia(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 or(n,r,i);return r.engine.asset.addSource(a),a.id}var Aa=Ia;function X(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 Sa(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 s=await Promise.all(t.map(c=>Ae(e,c,r,i)));o.push(...s),a=xa({kind:e,prefix:e,providerInitializationResults:o})}else{let s=await Promise.all(t.fromText.map(g=>Ae(e,g,r,i)));o.push(...s);let c=await Promise.all(t.fromImage.map(g=>Ae(e,g,r,i)));o.push(...c),a=Ca({kind:e,prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:s,initializedFromImageProviders:c})}let l=Aa({kind:e,cesdk:r.cesdk,historAssetSourceIds:o.map(s=>s.history?.assetSourceId).filter(ao)}),u;return l!=null&&(u=l,r.cesdk.ui.addAssetLibraryEntry({id:u,sourceIds:[l],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"})),{panel:{builderRenderFunction:a},history:{assetSourceId:l,assetLibraryEntryId:u},providerInitializationResults:o}}function Ca({kind:e,prefix:t,initializedFromTextProviders:r,initializedFromImageProviders:i}){let n=r.length>0&&i.length>0;return a=>{let{builder:o,experimental:l}=a,u=l.global(`${t}.fromType`,n?"fromText":void 0),s=[];u.value==="fromText"?s.push(...r):u.value==="fromImage"?s.push(...i):s.push(...r,...i);let c=r.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),g=i.map(({provider:f,panel:b})=>({id:f.id,label:f.name??f.id,builderRenderFunction:b?.builderRenderFunction})),p=a.experimental.global(`${t}.selectedProvider.fromText`,c[0]),d=a.experimental.global(`${t}.selectedProvider.fromImage`,g[0]),m=u.value==="fromText"?p:u.value==="fromImage"?d:void 0;if((n||s.length>1)&&o.Section(`${t}.providerSelection.section`,{children:()=>{if(n&&o.ButtonGroup(`${t}.fromType.buttonGroup`,{inputLabel:X(e,"fromType.label"),children:()=>{o.Button(`${t}.fromType.buttonGroup.fromText`,{label:X(e,"fromText.label"),icon:u.value!=="fromText"&&at(r,a)?"@imgly/LoadingSpinner":void 0,isActive:u.value==="fromText",onClick:()=>{u.setValue("fromText")}}),o.Button(`${t}.fromType.buttonGroup.fromImage`,{label:X(e,"fromImage.label"),icon:u.value!=="fromImage"&&at(i,a)?"@imgly/LoadingSpinner":void 0,isActive:u.value==="fromImage",onClick:()=>{u.setValue("fromImage")}})}}),s.length>1){let f=u.value==="fromText"?c:u.value==="fromImage"?g:[...c,...g];m!=null&&o.Select(`${t}.providerSelect.select`,{inputLabel:X(e,"providerSelect.label"),values:f,...m})}}}),s.length>1)m?.value.builderRenderFunction?.(a);else{let f=s[0];f&&f.panel?.builderRenderFunction?.(a)}}}function xa({kind:e,prefix:t,providerInitializationResults:r}){return i=>{let{builder:n}=i;if(r.length===0)return;let a=r.map(({provider:l,panel:u})=>({id:l.id,label:l.name??l.id,builderRenderFunction:u?.builderRenderFunction})),o=i.state(`${t}.selectedProvider`,a[0]);r.length>1&&o!=null&&n.Section(`${t}.providerSelection.section`,{children:()=>{n.Select(`${t}.providerSelect.select`,{inputLabel:X(e,"providerSelect.label"),values:a,...o})}}),o.value.builderRenderFunction?.(i)}}function at(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Pe(r.id),!1).value)}var $t=Sa;var Ea=typeof global=="object"&&global&&global.Object===Object&&global,qt=Ea,Ma=typeof self=="object"&&self&&self.Object===Object&&self,ja=qt||Ma||Function("return this")(),C=ja,_a=C.Symbol,H=_a,Zt=Object.prototype,$a=Zt.hasOwnProperty,La=Zt.toString,oe=H?H.toStringTag:void 0;function Na(e){var t=$a.call(e,oe),r=e[oe];try{e[oe]=void 0;var i=!0}catch{}var n=La.call(e);return i&&(t?e[oe]=r:delete e[oe]),n}var Pa=Na,Oa=Object.prototype,Da=Oa.toString;function Ta(e){return Da.call(e)}var za=Ta,Ra="[object Null]",Fa="[object Undefined]",Lt=H?H.toStringTag:void 0;function Va(e){return e==null?e===void 0?Fa:Ra:Lt&&Lt in Object(e)?Pa(e):za(e)}var ue=Va;function Ua(e){return e!=null&&typeof e=="object"}var Ue=Ua,Ku=Array.isArray;function Ba(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Qt=Ba,Ga="[object AsyncFunction]",Ha="[object Function]",qa="[object GeneratorFunction]",Za="[object Proxy]";function Qa(e){if(!Qt(e))return!1;var t=ue(e);return t==Ha||t==qa||t==Ga||t==Za}var Ya=Qa,Wa=C["__core-js_shared__"],Oe=Wa,Nt=function(){var e=/[^.]+$/.exec(Oe&&Oe.keys&&Oe.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Ka(e){return!!Nt&&Nt in e}var Ja=Ka,Xa=Function.prototype,es=Xa.toString;function ts(e){if(e!=null){try{return es.call(e)}catch{}try{return e+""}catch{}}return""}var O=ts,rs=/[\\^$.*+?()[\]{}|]/g,is=/^\[object .+?Constructor\]$/,ns=Function.prototype,os=Object.prototype,as=ns.toString,ss=os.hasOwnProperty,ls=RegExp("^"+as.call(ss).replace(rs,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function us(e){if(!Qt(e)||Ja(e))return!1;var t=Ya(e)?ls:is;return t.test(O(e))}var cs=us;function ds(e,t){return e?.[t]}var gs=ds;function ps(e,t){var r=gs(e,t);return cs(r)?r:void 0}var q=ps,fs=q(C,"WeakMap"),Te=fs;function ms(e,t){return e===t||e!==e&&t!==t}var hs=ms,bs=9007199254740991;function ys(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=bs}var vs=ys;var Ju=Object.prototype;var ws="[object Arguments]";function ks(e){return Ue(e)&&ue(e)==ws}var Pt=ks,Yt=Object.prototype,Is=Yt.hasOwnProperty,As=Yt.propertyIsEnumerable,Xu=Pt(function(){return arguments}())?Pt:function(e){return Ue(e)&&Is.call(e,"callee")&&!As.call(e,"callee")};var Wt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ot=Wt&&typeof module=="object"&&module&&!module.nodeType&&module,Ss=Ot&&Ot.exports===Wt,Dt=Ss?C.Buffer:void 0,ec=Dt?Dt.isBuffer:void 0;var Cs="[object Arguments]",xs="[object Array]",Es="[object Boolean]",Ms="[object Date]",js="[object Error]",_s="[object Function]",$s="[object Map]",Ls="[object Number]",Ns="[object Object]",Ps="[object RegExp]",Os="[object Set]",Ds="[object String]",Ts="[object WeakMap]",zs="[object ArrayBuffer]",Rs="[object DataView]",Fs="[object Float32Array]",Vs="[object Float64Array]",Us="[object Int8Array]",Bs="[object Int16Array]",Gs="[object Int32Array]",Hs="[object Uint8Array]",qs="[object Uint8ClampedArray]",Zs="[object Uint16Array]",Qs="[object Uint32Array]",w={};w[Fs]=w[Vs]=w[Us]=w[Bs]=w[Gs]=w[Hs]=w[qs]=w[Zs]=w[Qs]=!0;w[Cs]=w[xs]=w[zs]=w[Es]=w[Rs]=w[Ms]=w[js]=w[_s]=w[$s]=w[Ls]=w[Ns]=w[Ps]=w[Os]=w[Ds]=w[Ts]=!1;function Ys(e){return Ue(e)&&vs(e.length)&&!!w[ue(e)]}var Ws=Ys;function Ks(e){return function(t){return e(t)}}var Js=Ks,Kt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ae=Kt&&typeof module=="object"&&module&&!module.nodeType&&module,Xs=ae&&ae.exports===Kt,De=Xs&&qt.process,el=function(){try{var e=ae&&ae.require&&ae.require("util").types;return e||De&&De.binding&&De.binding("util")}catch{}}(),Tt=el,zt=Tt&&Tt.isTypedArray,tc=zt?Js(zt):Ws;var tl=Object.prototype,rc=tl.hasOwnProperty;function rl(e,t){return function(r){return e(t(r))}}var il=rl,ic=il(Object.keys,Object);var nl=Object.prototype,nc=nl.hasOwnProperty;var ol=q(Object,"create"),se=ol;function al(){this.__data__=se?se(null):{},this.size=0}var sl=al;function ll(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var ul=ll,cl="__lodash_hash_undefined__",dl=Object.prototype,gl=dl.hasOwnProperty;function pl(e){var t=this.__data__;if(se){var r=t[e];return r===cl?void 0:r}return gl.call(t,e)?t[e]:void 0}var fl=pl,ml=Object.prototype,hl=ml.hasOwnProperty;function bl(e){var t=this.__data__;return se?t[e]!==void 0:hl.call(t,e)}var yl=bl,vl="__lodash_hash_undefined__";function wl(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=se&&t===void 0?vl:t,this}var kl=wl;function Z(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])}}Z.prototype.clear=sl;Z.prototype.delete=ul;Z.prototype.get=fl;Z.prototype.has=yl;Z.prototype.set=kl;var Rt=Z;function Il(){this.__data__=[],this.size=0}var Al=Il;function Sl(e,t){for(var r=e.length;r--;)if(hs(e[r][0],t))return r;return-1}var fe=Sl,Cl=Array.prototype,xl=Cl.splice;function El(e){var t=this.__data__,r=fe(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():xl.call(t,r,1),--this.size,!0}var Ml=El;function jl(e){var t=this.__data__,r=fe(t,e);return r<0?void 0:t[r][1]}var _l=jl;function $l(e){return fe(this.__data__,e)>-1}var Ll=$l;function Nl(e,t){var r=this.__data__,i=fe(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var Pl=Nl;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=Al;Q.prototype.delete=Ml;Q.prototype.get=_l;Q.prototype.has=Ll;Q.prototype.set=Pl;var me=Q,Ol=q(C,"Map"),le=Ol;function Dl(){this.size=0,this.__data__={hash:new Rt,map:new(le||me),string:new Rt}}var Tl=Dl;function zl(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Rl=zl;function Fl(e,t){var r=e.__data__;return Rl(t)?r[typeof t=="string"?"string":"hash"]:r.map}var he=Fl;function Vl(e){var t=he(this,e).delete(e);return this.size-=t?1:0,t}var Ul=Vl;function Bl(e){return he(this,e).get(e)}var Gl=Bl;function Hl(e){return he(this,e).has(e)}var ql=Hl;function Zl(e,t){var r=he(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Ql=Zl;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=Tl;Y.prototype.delete=Ul;Y.prototype.get=Gl;Y.prototype.has=ql;Y.prototype.set=Ql;var Jt=Y;function Yl(){this.__data__=new me,this.size=0}var Wl=Yl;function Kl(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Jl=Kl;function Xl(e){return this.__data__.get(e)}var eu=Xl;function tu(e){return this.__data__.has(e)}var ru=tu,iu=200;function nu(e,t){var r=this.__data__;if(r instanceof me){var i=r.__data__;if(!le||i.length<iu-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Jt(i)}return r.set(e,t),this.size=r.size,this}var ou=nu;function ce(e){var t=this.__data__=new me(e);this.size=t.size}ce.prototype.clear=Wl;ce.prototype.delete=Jl;ce.prototype.get=eu;ce.prototype.has=ru;ce.prototype.set=ou;var au=Object.prototype,oc=au.propertyIsEnumerable;var su=q(C,"DataView"),ze=su,lu=q(C,"Promise"),Re=lu,uu=q(C,"Set"),Fe=uu,Ft="[object Map]",cu="[object Object]",Vt="[object Promise]",Ut="[object Set]",Bt="[object WeakMap]",Gt="[object DataView]",du=O(ze),gu=O(le),pu=O(Re),fu=O(Fe),mu=O(Te),G=ue;(ze&&G(new ze(new ArrayBuffer(1)))!=Gt||le&&G(new le)!=Ft||Re&&G(Re.resolve())!=Vt||Fe&&G(new Fe)!=Ut||Te&&G(new Te)!=Bt)&&(G=function(e){var t=ue(e),r=t==cu?e.constructor:void 0,i=r?O(r):"";if(i)switch(i){case du:return Gt;case gu:return Ft;case pu:return Vt;case fu:return Ut;case mu:return Bt}return t});var ac=C.Uint8Array;var hu="__lodash_hash_undefined__";function bu(e){return this.__data__.set(e,hu),this}var yu=bu;function vu(e){return this.__data__.has(e)}var wu=vu;function Ve(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Jt;++t<r;)this.add(e[t])}Ve.prototype.add=Ve.prototype.push=yu;Ve.prototype.has=wu;var Ht=H?H.prototype:void 0,sc=Ht?Ht.valueOf:void 0;var ku=Object.prototype,lc=ku.hasOwnProperty;var Iu=Object.prototype,uc=Iu.hasOwnProperty;var cc=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),dc=new RegExp(/[A-Fa-f0-9]{1}/,"g"),gc=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function Au(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 Xt(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 Au(i,t)}function Su(e){return e==null?[]:Array.isArray(e)?e:[e]}var Be=Su;var D="@imgly/plugin-ai-video-generation-web",Cu=["ly.img.createVideo"];var be="createVideo",er=`ly.img.${be}`,xu=`ly.img.plugin-ai-video-generation-web.quickAction.${be}`,tr=`ly.img.plugin-ai-video-generation-web.defaults.quickAction.${be}`;function Eu(e,t){let r="ly.img.plugin-ai-video-generation-web",i=`quickAction.${be}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var Mu=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${tr}`]:"Create Video...",[`${tr}.description`]:"Create a video from the image"}}),{id:er,type:"quick",kind:"image",label:`${xu}`,enable:wt(),scopes:[],render:({builder:r,engine:i,close:n,providerId:a})=>{r.Button(`${er}.button`,{label:Eu(a),icon:"@imgly/plugin-ai-generation/video",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=i.block.findAllSelected(),l=await Xt(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`,l),n()}catch(o){console.error("Error opening video generation panel:",o)}}})}}),rr=Mu;var _="ly.img.ai.video-generation";function ju(e){return{async initialize({cesdk:t}){if(t==null)return;yt(t,D,"0.2.5"),t.setTranslations({en:{[`panel.${_}`]:"Video Generation",[`${_}.dock.label`]:"AI Video"}}),_u(e);let i=$e.get().register({type:"plugin",sceneMode:"Video",id:D,pluginId:D,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(Be(n).map(c=>c({cesdk:t}))),l=await Promise.all(Be(a).map(c=>c({cesdk:t})));if(!(o.length>0||l.length>0)){i();return}let s=await $t("video",{fromText:o,fromImage:l},{cesdk:t},e);$e.get().register(rr({cesdk:t})),s.panel.builderRenderFunction!=null?(t.ui.registerPanel(_,s.panel.builderRenderFunction),vt({cesdk:t,panelId:_})):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 ir=ju;var $u=e=>({name:D,version:"0.2.5",...ir(e)}),Mc=$u;export{Cu as DEFAULT_VIDEO_QUICK_ACTION_ORDER,Mc as default};
|
|
67
67
|
/*! Bundled license information:
|
|
68
68
|
|
|
69
69
|
@imgly/plugin-ai-generation-web/dist/index.mjs:
|