@imgly/plugin-ai-text-generation-web 0.1.10 → 0.2.1

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +207 -28
  3. package/dist/anthropic/AnthropicProvider.d.ts +7 -3
  4. package/dist/anthropic/index.mjs +10 -197
  5. package/dist/anthropic/index.mjs.map +4 -4
  6. package/dist/anthropic/sendPrompt.d.ts +1 -1
  7. package/dist/constants.d.ts +5 -0
  8. package/dist/index.d.ts +4 -1
  9. package/dist/index.mjs +196 -7
  10. package/dist/index.mjs.map +4 -4
  11. package/dist/open-ai/OpenAIProvider.d.ts +21 -0
  12. package/dist/open-ai/index.d.ts +5 -0
  13. package/dist/open-ai/index.mjs +20 -0
  14. package/dist/open-ai/index.mjs.map +7 -0
  15. package/dist/open-ai/sendPrompt.d.ts +15 -0
  16. package/dist/plugin.d.ts +4 -3
  17. package/dist/quickActions/ChangeTextTo.d.ts +29 -0
  18. package/dist/quickActions/ChangeTone.d.ts +29 -0
  19. package/dist/quickActions/Fix.d.ts +28 -0
  20. package/dist/quickActions/Improve.d.ts +28 -0
  21. package/dist/quickActions/Longer.d.ts +28 -0
  22. package/dist/quickActions/Shorter.d.ts +28 -0
  23. package/dist/quickActions/Translate.d.ts +29 -0
  24. package/dist/quickActions/types.d.ts +6 -0
  25. package/dist/types.d.ts +50 -10
  26. package/package.json +8 -3
  27. /package/dist/{anthropic/prompts → prompts}/changeTextTo.d.ts +0 -0
  28. /package/dist/{anthropic/prompts → prompts}/changeTone.d.ts +0 -0
  29. /package/dist/{anthropic/prompts → prompts}/fix.d.ts +0 -0
  30. /package/dist/{anthropic/prompts → prompts}/generateTextForSpeech.d.ts +0 -0
  31. /package/dist/{anthropic/prompts → prompts}/improve.d.ts +0 -0
  32. /package/dist/{anthropic/prompts → prompts}/longer.d.ts +0 -0
  33. /package/dist/{anthropic/prompts → prompts}/shorter.d.ts +0 -0
  34. /package/dist/{anthropic/prompts → prompts}/translate.d.ts +0 -0
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var me="@imgly/plugin-ai-text-generation",lt=`
1
+ var tt="@imgly/plugin-ai-text-generation",Hr=`
2
2
  <svg>
3
3
  <symbol
4
4
  fill="none"
@@ -74,8 +74,10 @@ var me="@imgly/plugin-ai-text-generation",lt=`
74
74
  <path d="M3.72318 6.44728C3.63105 6.26302 3.3681 6.26302 3.27597 6.44728L3.03684 6.92554C3.01265 6.97392 2.97343 7.01314 2.92505 7.03733L2.44677 7.27652C2.26252 7.36866 2.26254 7.63161 2.44681 7.72373L2.92503 7.9628C2.97342 7.98699 3.01266 8.02622 3.03685 8.07461L3.27597 8.55285C3.3681 8.73711 3.63105 8.73711 3.72318 8.55285L3.96231 8.0746C3.9865 8.02622 4.02573 7.98699 4.07411 7.9628L4.55236 7.72367C4.73663 7.63154 4.73663 7.36859 4.55236 7.27646L4.07411 7.03733C4.02573 7.01314 3.9865 6.97391 3.96231 6.92553L3.72318 6.44728Z" fill="currentColor"/>
75
75
  </symbol>
76
76
  </svg>
77
- `,ye=lt;var st=class{constructor(e,t,n){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=n?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=n?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let n=indexedDB.open(this.dbName,this.dbVersion);n.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},n.onupgradeneeded=i=>{let a=i.target.result;a.objectStoreNames.contains(this.assetStoreName)||a.createObjectStore(this.assetStoreName,{keyPath:"id"}),a.objectStoreNames.contains(this.blobStoreName)||a.createObjectStore(this.blobStoreName,{keyPath:"id"})},n.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((c,s)=>{let u=e.locale??"en",d="",g=[];s.label!=null&&typeof s.label=="object"&&s.label[u]&&(d=s.label[u]),s.tags!=null&&typeof s.tags=="object"&&s.tags[u]&&(g=s.tags[u]);let m={...s,label:d,tags:g};return this.filterAsset(m,e)&&c.push(m),c},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:n,perPage:i}=e,a=n*i,o=a+i,r=t.slice(a,o),l=o<t.length?n+1:void 0;return{assets:r,currentPage:n,nextPage:l,total:t.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){if(await this.initialize(),!this.db)throw new Error("Database not initialized");return new Promise((e,t)=>{let n=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();n.onsuccess=()=>{let i=new Set;n.result.forEach(o=>{o.groups&&Array.isArray(o.groups)&&o.groups.forEach(r=>i.add(r))});let a=[...i];e(a)},n.onerror=()=>{t(new Error(`Failed to get groups: ${n.error}`))}})}addAsset(e){this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.assetStoreName,"readwrite"),n=t.objectStore(this.assetStoreName),i=new Set;$(e,o=>{i.add(o)}),setTimeout(()=>{this.storeBlobUrls([...i])});let a={...e,meta:{...e.meta,insertedAt:e.meta?.insertedAt||Date.now()}};n.put(a),t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.assetStoreName,"readwrite");n.objectStore(this.assetStoreName).delete(e),n.oncomplete=()=>{$(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},n.onerror=()=>{console.error(`Failed to remove asset: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,n)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let a=i.result;a.sort((o,r)=>{let l=o.meta?.insertedAt||o._insertedAt||Date.now(),c=r.meta?.insertedAt||r._insertedAt||Date.now();return e==="asc"?l-c:c-l}),t(a)},i.onerror=()=>{n(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,n)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{n(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,n)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{n(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 n=>{let i=await(await fetch(n)).blob();t[n]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let n=this.db.transaction(this.blobStoreName,"readwrite"),i=n.objectStore(this.blobStoreName);Object.entries(t).forEach(([a,o])=>{let r={id:a,blob:o};i.put(r)}),n.onerror=()=>{console.error(`Failed to add blobs: ${n.error}`)}}).catch(n=>{console.error("Error initializing database:",n)})}async restoreBlobUrls(e){let t={},n=new Set;return $(e,i=>{n.add(i)}),await Promise.all([...n].map(async i=>{let a=await this.createBlobUrlFromStore(i);t[i]=a})),$(e,i=>t[i]??i)}filterAsset(e,t){let{query:n,tags:i,groups:a,excludeGroups:o}=t;if(n&&n.trim()!==""){let r=n.trim().toLowerCase().split(" "),l=e.label?.toLowerCase()??"",c=e.tags?.map(s=>s.toLowerCase())??[];if(!r.every(s=>l.includes(s)||c.some(u=>u.includes(s))))return!1}if(i){let r=Array.isArray(i)?i:[i];if(r.length>0&&(!e.tags||!r.every(l=>e.tags?.includes(l))))return!1}return!(a&&a.length>0&&(!e.groups||!a.some(r=>e.groups?.includes(r)))||o&&o.length>0&&e.groups&&e.groups.some(r=>o.includes(r)))}sortAssets(e,t){let{sortingOrder:n,sortKey:i,sortActiveFirst:a}=t,o=[...e];return!n||n==="None"||(i?o.sort((r,l)=>{let c,s;return i==="id"?(c=r.id,s=l.id):(c=r.meta?.[i]??null,s=l.meta?.[i]??null),c==null?n==="Ascending"?-1:1:s==null?n==="Ascending"?1:-1:typeof c=="string"&&typeof s=="string"?n==="Ascending"?c.localeCompare(s):s.localeCompare(c):n==="Ascending"?c<s?-1:c>s?1:0:c>s?-1:c<s?1:0}):n==="Descending"&&o.reverse(),a&&o.sort((r,l)=>r.active&&!l.active?-1:!r.active&&l.active?1:0)),o}};function $(e,t,n=""){if(e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let i=0;i<e.length;i++){let a=n?`${n}[${i}]`:`[${i}]`;if(typeof e[i]=="string"&&e[i].startsWith("blob:")){let o=t(e[i],a);typeof o=="string"&&(e[i]=o)}else e[i]=$(e[i],t,a)}return e}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let a=e[i],o=n?`${n}.${i}`:i;if(typeof a=="string"&&a.startsWith("blob:")){let r=t(a,o);typeof r=="string"&&(e[i]=r)}else e[i]=$(a,t,o)}return e}var ct=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},Ne=ct,ut=typeof global=="object"&&global&&global.Object===Object&&global,De=ut,dt=typeof self=="object"&&self&&self.Object===Object&&self,pt=De||dt||Function("return this")(),x=pt,gt=x.Symbol,j=gt,Oe=Object.prototype,mt=Oe.hasOwnProperty,yt=Oe.toString,z=j?j.toStringTag:void 0;function ft(e){var t=mt.call(e,z),n=e[z];try{e[z]=void 0;var i=!0}catch{}var a=yt.call(e);return i&&(t?e[z]=n:delete e[z]),a}var bt=ft,ht=Object.prototype,kt=ht.toString;function vt(e){return kt.call(e)}var wt=vt,Ct="[object Null]",At="[object Undefined]",fe=j?j.toStringTag:void 0;function It(e){return e==null?e===void 0?At:Ct:fe&&fe in Object(e)?bt(e):wt(e)}var G=It;function Mt(e){return e!=null&&typeof e=="object"}var se=Mt,Eo=Array.isArray;function xt(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Pe=xt,Lt="[object AsyncFunction]",Et="[object Function]",St="[object GeneratorFunction]",$t="[object Proxy]";function jt(e){if(!Pe(e))return!1;var t=G(e);return t==Et||t==St||t==Lt||t==$t}var Tt=jt,Nt=x["__core-js_shared__"],K=Nt,be=function(){var e=/[^.]+$/.exec(K&&K.keys&&K.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Dt(e){return!!be&&be in e}var Ot=Dt,Pt=Function.prototype,_t=Pt.toString;function zt(e){if(e!=null){try{return _t.call(e)}catch{}try{return e+""}catch{}}return""}var E=zt,Ut=/[\\^$.*+?()[\]{}|]/g,qt=/^\[object .+?Constructor\]$/,Vt=Function.prototype,Bt=Object.prototype,Qt=Vt.toString,Ft=Bt.hasOwnProperty,Gt=RegExp("^"+Qt.call(Ft).replace(Ut,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Rt(e){if(!Pe(e)||Ot(e))return!1;var t=Tt(e)?Gt:qt;return t.test(E(e))}var Ht=Rt;function Zt(e,t){return e?.[t]}var Yt=Zt;function Wt(e,t){var n=Yt(e,t);return Ht(n)?n:void 0}var N=Wt,Kt=N(x,"WeakMap"),ie=Kt;function Jt(e,t){return e===t||e!==e&&t!==t}var Xt=Jt,ei=9007199254740991;function ti(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ei}var ii=ti,So=Object.prototype,ni="[object Arguments]";function ri(e){return se(e)&&G(e)==ni}var he=ri,_e=Object.prototype,oi=_e.hasOwnProperty,ai=_e.propertyIsEnumerable,$o=he(function(){return arguments}())?he:function(e){return se(e)&&oi.call(e,"callee")&&!ai.call(e,"callee")},ze=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ke=ze&&typeof module=="object"&&module&&!module.nodeType&&module,li=ke&&ke.exports===ze,ve=li?x.Buffer:void 0,jo=ve?ve.isBuffer:void 0,si="[object Arguments]",ci="[object Array]",ui="[object Boolean]",di="[object Date]",pi="[object Error]",gi="[object Function]",mi="[object Map]",yi="[object Number]",fi="[object Object]",bi="[object RegExp]",hi="[object Set]",ki="[object String]",vi="[object WeakMap]",wi="[object ArrayBuffer]",Ci="[object DataView]",Ai="[object Float32Array]",Ii="[object Float64Array]",Mi="[object Int8Array]",xi="[object Int16Array]",Li="[object Int32Array]",Ei="[object Uint8Array]",Si="[object Uint8ClampedArray]",$i="[object Uint16Array]",ji="[object Uint32Array]",C={};C[Ai]=C[Ii]=C[Mi]=C[xi]=C[Li]=C[Ei]=C[Si]=C[$i]=C[ji]=!0;C[si]=C[ci]=C[wi]=C[ui]=C[Ci]=C[di]=C[pi]=C[gi]=C[mi]=C[yi]=C[fi]=C[bi]=C[hi]=C[ki]=C[vi]=!1;function Ti(e){return se(e)&&ii(e.length)&&!!C[G(e)]}var Ni=Ti;function Di(e){return function(t){return e(t)}}var Oi=Di,Ue=typeof exports=="object"&&exports&&!exports.nodeType&&exports,B=Ue&&typeof module=="object"&&module&&!module.nodeType&&module,Pi=B&&B.exports===Ue,J=Pi&&De.process,_i=function(){try{var e=B&&B.require&&B.require("util").types;return e||J&&J.binding&&J.binding("util")}catch{}}(),we=_i,Ce=we&&we.isTypedArray,To=Ce?Oi(Ce):Ni,zi=Object.prototype,No=zi.hasOwnProperty;function Ui(e,t){return function(n){return e(t(n))}}var qi=Ui,Do=qi(Object.keys,Object),Vi=Object.prototype,Oo=Vi.hasOwnProperty,Bi=N(Object,"create"),Q=Bi;function Qi(){this.__data__=Q?Q(null):{},this.size=0}var Fi=Qi;function Gi(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Ri=Gi,Hi="__lodash_hash_undefined__",Zi=Object.prototype,Yi=Zi.hasOwnProperty;function Wi(e){var t=this.__data__;if(Q){var n=t[e];return n===Hi?void 0:n}return Yi.call(t,e)?t[e]:void 0}var Ki=Wi,Ji=Object.prototype,Xi=Ji.hasOwnProperty;function en(e){var t=this.__data__;return Q?t[e]!==void 0:Xi.call(t,e)}var tn=en,nn="__lodash_hash_undefined__";function rn(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Q&&t===void 0?nn:t,this}var on=rn;function D(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var i=e[t];this.set(i[0],i[1])}}D.prototype.clear=Fi;D.prototype.delete=Ri;D.prototype.get=Ki;D.prototype.has=tn;D.prototype.set=on;var Ae=D;function an(){this.__data__=[],this.size=0}var ln=an;function sn(e,t){for(var n=e.length;n--;)if(Xt(e[n][0],t))return n;return-1}var Z=sn,cn=Array.prototype,un=cn.splice;function dn(e){var t=this.__data__,n=Z(t,e);if(n<0)return!1;var i=t.length-1;return n==i?t.pop():un.call(t,n,1),--this.size,!0}var pn=dn;function gn(e){var t=this.__data__,n=Z(t,e);return n<0?void 0:t[n][1]}var mn=gn;function yn(e){return Z(this.__data__,e)>-1}var fn=yn;function bn(e,t){var n=this.__data__,i=Z(n,e);return i<0?(++this.size,n.push([e,t])):n[i][1]=t,this}var hn=bn;function O(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var i=e[t];this.set(i[0],i[1])}}O.prototype.clear=ln;O.prototype.delete=pn;O.prototype.get=mn;O.prototype.has=fn;O.prototype.set=hn;var Y=O,kn=N(x,"Map"),F=kn;function vn(){this.size=0,this.__data__={hash:new Ae,map:new(F||Y),string:new Ae}}var wn=vn;function Cn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var An=Cn;function In(e,t){var n=e.__data__;return An(t)?n[typeof t=="string"?"string":"hash"]:n.map}var W=In;function Mn(e){var t=W(this,e).delete(e);return this.size-=t?1:0,t}var xn=Mn;function Ln(e){return W(this,e).get(e)}var En=Ln;function Sn(e){return W(this,e).has(e)}var $n=Sn;function jn(e,t){var n=W(this,e),i=n.size;return n.set(e,t),this.size+=n.size==i?0:1,this}var Tn=jn;function P(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var i=e[t];this.set(i[0],i[1])}}P.prototype.clear=wn;P.prototype.delete=xn;P.prototype.get=En;P.prototype.has=$n;P.prototype.set=Tn;var qe=P;function Nn(){this.__data__=new Y,this.size=0}var Dn=Nn;function On(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var Pn=On;function _n(e){return this.__data__.get(e)}var zn=_n;function Un(e){return this.__data__.has(e)}var qn=Un,Vn=200;function Bn(e,t){var n=this.__data__;if(n instanceof Y){var i=n.__data__;if(!F||i.length<Vn-1)return i.push([e,t]),this.size=++n.size,this;n=this.__data__=new qe(i)}return n.set(e,t),this.size=n.size,this}var Qn=Bn;function R(e){var t=this.__data__=new Y(e);this.size=t.size}R.prototype.clear=Dn;R.prototype.delete=Pn;R.prototype.get=zn;R.prototype.has=qn;R.prototype.set=Qn;var Fn=Object.prototype,Po=Fn.propertyIsEnumerable,Gn=N(x,"DataView"),ne=Gn,Rn=N(x,"Promise"),re=Rn,Hn=N(x,"Set"),oe=Hn,Ie="[object Map]",Zn="[object Object]",Me="[object Promise]",xe="[object Set]",Le="[object WeakMap]",Ee="[object DataView]",Yn=E(ne),Wn=E(F),Kn=E(re),Jn=E(oe),Xn=E(ie),S=G;(ne&&S(new ne(new ArrayBuffer(1)))!=Ee||F&&S(new F)!=Ie||re&&S(re.resolve())!=Me||oe&&S(new oe)!=xe||ie&&S(new ie)!=Le)&&(S=function(e){var t=G(e),n=t==Zn?e.constructor:void 0,i=n?E(n):"";if(i)switch(i){case Yn:return Ee;case Wn:return Ie;case Kn:return Me;case Jn:return xe;case Xn:return Le}return t});var _o=x.Uint8Array,er="__lodash_hash_undefined__";function tr(e){return this.__data__.set(e,er),this}var ir=tr;function nr(e){return this.__data__.has(e)}var rr=nr;function ae(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new qe;++t<n;)this.add(e[t])}ae.prototype.add=ae.prototype.push=ir;ae.prototype.has=rr;var Se=j?j.prototype:void 0,zo=Se?Se.valueOf:void 0,or=Object.prototype,Uo=or.hasOwnProperty,ar=Object.prototype,qo=ar.hasOwnProperty,Vo=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Bo=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Qo=new RegExp(/[A-Fa-f0-9]{2}/,"g");function lr(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function Ve(e,t){if(e.startsWith("buffer:")){let n=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),a=t.editor.getBufferData(e,0,i),o=new Blob([a],{type:n});return URL.createObjectURL(o)}else return e}async function le(e,t){let n=await Ve(e,t);return new Promise((i,a)=>{let o=new Image;o.onload=()=>{i({width:o.width,height:o.height})},o.onerror=a,o.src=n})}async function sr(e,t,n){let i,a=t.block.getFill(e),o=t.block.getSourceSet(a,"fill/image/sourceSet"),[r]=o;if(r==null){if(i=t.block.getString(a,"fill/image/imageFileURI"),i==null)throw new Error("No image source/uri found")}else i=r.uri;if(n?.throwErrorIfSvg&&await t.editor.getMimeType(i)==="image/svg+xml")throw new Error("SVG images are not supported");return Ve(i,t)}function Be(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let n=t.substring(2).split("/"),i=e;for(let a of n){if(i==null)throw new Error(`Invalid reference path: ${t}`);i=i[a]}if(i===void 0)throw new Error(`Reference not found: ${t}`);return i}function q(e,t,n=new Set){if(t==null||n.has(t))return t;if(n.add(t),t.$ref&&typeof t.$ref=="string"){let i=Be(e,t.$ref),a={...q(e,i,n)};for(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&o!=="$ref"&&(a[o]=q(e,t[o],n));return a}if(Array.isArray(t))return t.map(i=>q(e,i,n));if(typeof t=="object"){let i={};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&(i[a]=q(e,t[a],n));return i}return t}function cr(e){return q(e,{...e})}function ur(e,t=!1){let n=r=>(t&&console.log(`OpenAPI Schema validation failed: ${r}`),!1);if(typeof e!="object"||e===null)return n(`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 n("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let r=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!r.includes(i.type))return n(`Invalid type: ${i.type}. Must be one of ${r.join(", ")}`)}else if(Array.isArray(i.type)){for(let l of i.type)if(typeof l!="string"||!r.includes(l))return n(`Array of types contains invalid value: ${l}. Must be one of ${r.join(", ")}`)}else return n(`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 n(`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 n(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let a=["allOf","anyOf","oneOf"];for(let r of a)if(i[r]!==void 0){if(!Array.isArray(i[r]))return n(`${r} must be an array, got ${typeof i[r]}`);for(let l=0;l<i[r].length;l++){let c=i[r][l];if(typeof c!="object"||c===null)return n(`Item ${l} in ${r} must be an object, got ${c===null?"null":typeof c}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return n(`'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 n(`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 n(`format must be a string, got ${typeof i.format}`);let o=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let r of o)if(i[r]!==void 0&&typeof i[r]!="number")return n(`${r} must be a number, got ${typeof i[r]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return n(`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 n(`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 n(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return n(`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 n(`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 n(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return n(`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 n(`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 n(`required must be an array, got ${typeof i.required}`);for(let r=0;r<i.required.length;r++){let l=i.required[r];if(typeof l!="string")return n(`Item ${r} in required array must be a string, got ${typeof l}`)}}return!0}function dr(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let n=e.properties,i=[];return pr(e,t).forEach(a=>{let o=a,r=n[a]??void 0;i.push({id:o,schema:r})}),i}function pr(e,t){let n=t.order;if(n!=null&&Array.isArray(n))return n;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,a=Object.keys(i),o=gr(e,t)??a;return n!=null&&typeof n=="function"&&(o=n(o)),[...new Set(o)]}function gr(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let n=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return n==null?void 0:e[n]}var Qe=dr,mr="ly.img.ai",X="ly.img.ai/temp";async function yr(e,t){return e.engine.asset.findAllSources().includes(X)||e.engine.asset.addLocalSource(X),e.engine.asset.apply(X,t)}function Fe(e){return`${mr}/${e}`}function fr(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let n=e;return"message"in n&&typeof n.message=="string"?n.message:"cause"in n&&typeof n.cause=="string"?n.cause:"detail"in n&&typeof n.detail=="object"&&n.detail!==null&&"message"in n.detail&&typeof n.detail.message=="string"?n.detail.message:"error"in n&&typeof n.error=="object"&&n.error!==null&&"message"in n.error&&typeof n.error.message=="string"?n.error.message:t}return typeof e=="string"?e:String(e)||t}function br(){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 hr(e,t=0,n="image/jpeg",i=.8){return new Promise((a,o)=>{try{let r=document.createElement("video");r.crossOrigin="anonymous",r.style.display="none",r.addEventListener("loadedmetadata",()=>{r.currentTime=Math.min(t,r.duration),r.addEventListener("seeked",()=>{let l=document.createElement("canvas");l.width=r.videoWidth,l.height=r.videoHeight;let c=l.getContext("2d");if(!c){document.body.removeChild(r),o(new Error("Failed to create canvas context"));return}c.drawImage(r,0,0,l.width,l.height);try{let s=l.toDataURL(n,i);document.body.removeChild(r),a(s)}catch(s){document.body.removeChild(r),o(new Error(`Failed to create thumbnail: ${s instanceof Error?s.message:String(s)}`))}},{once:!0})}),r.addEventListener("error",()=>{document.body.removeChild(r),o(new Error(`Failed to load video from ${e}`))}),r.src=e,document.body.appendChild(r)}catch(r){o(r)}})}function Ge(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 ce(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 T(e){return e instanceof Error&&e.name==="AbortError"}function Re(e,t,n,i,a,o){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let r=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(l){case"string":return t.schema.enum!=null?kr(e,r,n,i,a,o):Ze(e,r,n,i,a,o);case"boolean":return Ye(e,r,n,i,a,o);case"number":case"integer":return We(e,r,n,i,a,o);case"object":return He(e,r,n,i,a,o);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return vr(e,r,n,i,a,o);break}default:console.error(`Unsupported property type: ${l}`)}}function He(e,t,n,i,a,o){let r=Qe(t.schema??{},i).reduce((l,c)=>{let s=Re(e,c,n,i,a,o);return s!=null&&(l[c.id]=s()),l},{});return()=>({id:t.id,type:"object",value:r})}function Ze(e,t,n,i,a,o){let{builder:r,experimental:{global:l}}=e,{id:c}=t,s=`${n.id}.${c}`,u=t.schema.title??s,d=l(s,t.schema.default??""),g=wr(t.schema),m=g?.component!=null&&g?.component==="TextArea"?"TextArea":"TextInput";return r[m](s,{inputLabel:u,placeholder:a.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function kr(e,t,n,i,a,o){let{builder:r,experimental:{global:l}}=e,{id:c}=t,s=`${n.id}.${c}`,u=t.schema.title??s,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},g="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},m=(t.schema.enum??[]).map(b=>({id:b,label:d[b]??Ge(b),icon:g[b]})),k=t.schema.default!=null?m.find(b=>b.id===t.schema.default)??m[0]:m[0],w=l(s,k);return r.Select(s,{inputLabel:u,values:m,...w}),()=>({id:t.id,type:"string",value:w.value.id})}function Ye(e,t,n,i,a,o){let{builder:r,experimental:{global:l}}=e,{id:c}=t,s=`${n.id}.${c}`,u=t.schema.title??s,d=!!t.schema.default,g=l(s,d);return r.Checkbox(s,{inputLabel:u,...g}),()=>({id:t.id,type:"boolean",value:g.value})}function We(e,t,n,i,a,o){let{builder:r,experimental:{global:l}}=e,{id:c}=t,s=`${n.id}.${c}`,u=t.schema.title??s,d=t.schema.minimum,g=t.schema.maximum,m=t.schema.default;m==null&&(d!=null?m=d:g!=null?m=g:m=0);let k=l(s,m);if(d!=null&&g!=null){let w=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(w=t.schema["x-imgly-step"]),r.Slider(s,{inputLabel:u,min:d,max:g,step:w,...k})}else r.NumberInput(s,{inputLabel:u,min:d,max:g,...k});return()=>({id:t.id,type:"integer",value:k.value})}function vr(e,t,n,i,a,o){let{builder:r,experimental:{global:l}}=e,{id:c}=t,s=`${n.id}.${c}`,u=t.schema.title??s,d=t.schema.anyOf??[],g=[],m={},k={};d.forEach((p,h)=>{let y=p.title??"common.custom",f=`${n.id}.${c}.anyOf[${h}]`,v="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},A="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};p.type==="string"?p.enum!=null?p.enum.forEach(I=>{g.push({id:I,label:v[I]??Ge(I),icon:A[I]})}):(m[f]=()=>Ze(e,{id:f,schema:{...p,title:y}},n,i,a,o),g.push({id:f,label:v[y]??y,icon:A[y]})):p.type==="boolean"?(m[f]=()=>Ye(e,{id:f,schema:{...p,title:y}},n,i,a,o),g.push({id:f,label:v[y]??y,icon:A[y]})):p.type==="integer"?(m[f]=()=>We(e,{id:f,schema:{...p,title:y}},n,i,a,o),g.push({id:f,label:v[y]??y,icon:A[y]})):p.type==="array"||p.type==="object"&&(m[f]=()=>He(e,{id:f,schema:{...p,title:y}},n,i,a,o),g.push({id:f,label:v[y]??y,icon:A[y]}))});let w=t.schema.default!=null?g.find(p=>p.id===t.schema.default)??g[0]:g[0],b=l(s,w);if(r.Select(s,{inputLabel:u,values:g,...b}),b.value.id in m){let p=m[b.value.id]();k[b.value.id]=p}return()=>{let p=k[b.value.id];return p!=null?{...p(),id:t.id}:{id:t.id,type:"string",value:b.value.id}}}function wr(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Cr=Re,Ar="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Ke=Ar;function Ir(e,t,n){switch(t){case"image":return Mr(e,n[t]);case"video":return xr(e,n[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Mr(e,t){let n=t.width,i=t.height;return{id:e,meta:{previewUri:Ke,fillType:"//ly.img.ubq/fill/image",kind:"image",width:n,height:i}}}function xr(e,t){let n=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Ke,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:n,height:i}}}var Lr=Ir;async function Er(e,t,n,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 Sr(e,n[t],i)}case"video":{if(i.kind!=="video")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: video)`);return $r(e,n[t],i)}case"audio":{if(i.kind!=="audio")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: audio)`);return jr(e,n[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Sr(e,t,n){let i=t.width,a=t.height;return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:i,height:a},payload:{sourceSet:[{uri:n.url,width:i,height:a}]}}}async function $r(e,t,n){let i=t.width,a=t.height,o=await hr(n.url,0);return{id:e,label:t.label,meta:{uri:n.url,thumbUri:o,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:i,height:a}}}function jr(e,t,n){return{id:e,label:t.label,meta:{uri:n.url,thumbUri:n.thumbnailUrl,blockType:"//ly.img.ubq/audio",mimeType:"audio/x-m4a",duration:n.duration.toString()}}}var $e=Er;function Je(e){let t=e.filter(n=>!!n);return n=>async(i,a)=>{let o=[],r=s=>{o.push(s)},l=async(s,u,d)=>{if(s>=t.length)return n(u,d);let g=t[s],m=async(w,b)=>l(s+1,w,b),k={...d,addDisposer:r};return g(u,k,m)},c={...a,addDisposer:r};return{result:await l(0,i,c),dispose:async()=>{for(let s=o.length-1;s>=0;s--)try{await o[s]()}catch(u){console.error("Error in disposer:",u)}o.length=0}}}}function Tr(){return async(e,t,n)=>{console.group("[GENERATION]"),console.log("Generating with input:",JSON.stringify(e,null,2));let i,a=Date.now();try{return i=await n(e,t),i}finally{i!=null&&(console.log(`Generation took ${Date.now()-a}ms`),console.log("Generation result:",JSON.stringify(i,null,2))),console.groupEnd()}}}var Xe=Tr;function Nr(e){return async(t,n)=>(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await _r(2e3),await Dr(t,e,n))}async function Dr(e,t,n){switch(t.kind){case"image":return Or(e,t,n);case"video":return Pr(e,t,n);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function Or(e,t,{engine:n}){let i,a,o=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",r=o.match(/(\d+)x(\d+)/);if(r!=null)i=parseInt(r[1],10),a=parseInt(r[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,a=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[l]=t.blockIds,c=await sr(l,n),s=await le(c,n);i=s.width,a=s.height}else i=512,a=512;return{kind:"image",url:`https://placehold.co/${i}x${a}/000000/FFF?text=${o.replace(" ","+").replace(`
78
- `,"+")}`}}async function Pr(e,t,n){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function _r(e){return new Promise(t=>{setTimeout(t,e)})}var et=Nr;async function zr(e,t,n,i,a,o,r){let{cesdk:l,createPlaceholderBlock:c,historyAssetSourceId:s}=a,u;try{o.debug&&console.group(`Starting Generation for '${e}'`);let d=t(),g=await n(d.input),m=br(),k;if(c){if(k=Lr(m,e,g),o.debug&&console.log("Adding as asset to scene:",JSON.stringify(k,void 0,2)),u=await yr(l,k),u!=null&&i.kind==="video"){let h=l.engine.block.getPositionX(u),y=l.engine.block.getPositionY(u),f=l.engine.block.duplicate(u);l.engine.block.setPositionX(f,h),l.engine.block.setPositionY(f,y),l.engine.block.destroy(u),u=f}if(H(l,r,u))return{status:"aborted"};if(u==null)throw new Error("Could not create placeholder block");l.engine.block.setState(u,{type:"Pending",progress:0})}let w=Je([...i.output.middleware??[],o.debug?Xe():void 0,o.dryRun?et({kind:i.kind,blockInputs:g}):void 0]),{result:b}=await w(i.output.generate)(d.input,{abortSignal:r,engine:a.engine,cesdk:l});if(ce(b))throw new Error("Streaming generation is not supported yet from a panel");if(H(l,r,u))return{status:"aborted"};if(b==null)throw new Error("Generation failed");o.debug&&console.log("Generated output:",JSON.stringify(b,void 0,2));let p;if(u!=null&&l.engine.block.isValid(u)&&(p=await $e(m,e,g,b),o.debug&&console.log("Updating asset in scene:",JSON.stringify(p,void 0,2)),await l.engine.asset.defaultApplyAssetToBlock(p,u)),H(l,r,u))return{status:"aborted"};if(s!=null){if(p==null&&(p=await $e(m,e,g,b),H(l,r,u)))return{status:"aborted"};let h={...p,id:`${Date.now()}-${p.id}`,label:p.label!=null?{en:p.label}:{},tags:{}};l.engine.asset.addAssetToSource(s,h)}return u!=null&&l.engine.block.isValid(u)&&l.engine.block.setState(u,{type:"Ready"}),{status:"success",output:b}}catch(d){throw u!=null&&l.engine.block.isValid(u)&&(T(d)?l.engine.block.destroy(u):l.engine.block.setState(u,{type:"Error",error:"Unknown"})),d}finally{o.debug&&console.groupEnd()}}function H(e,t,n){return t.aborted?(n!=null&&e.engine.block.isValid(n)&&e.engine.block.destroy(n),!0):!1}var Ur=zr;function qr(e,t,n){let{cesdk:i,provider:a,getInput:o}=t;n.onError!=null&&typeof n.onError=="function"?n.onError(e):(console.error("Generation failed:",e),Vr(i,a.output.notification,()=>({input:o?.().input,error:e}))||i.ui.showNotification({type:"error",message:fr(e)}))}function Vr(e,t,n){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(n()):i.show))return!1;let a=typeof i.message=="function"?i.message(n()):i.message??"common.ai-generation.failed",o=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(n()):i.action.label,onClick:()=>{i?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"error",message:a,action:o}),!0}var V=qr;function tt(e){return`${e}.generating`}function Br(e){return`${e}.abort`}function Qr(e,t,n,i,a,o){let{builder:r,experimental:l}=e,{cesdk:c,includeHistoryLibrary:s=!0}=a,{id:u,output:{abortable:d}}=t,g=l.global(Br(u),()=>{}),m=l.global(tt(u),!1),k,w=m.value&&d,b=()=>{w&&(g.value(),m.setValue(!1),g.setValue(()=>{}))},p;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let y=n();p=a.requiredInputs.every(f=>!y.input[f])}let h=l.global(`${u}.confirmationDialogId`,void 0);r.Section(`${u}.generate.section`,{children:()=>{r.Button(`${u}.generate`,{label:["common.ai-generation.generate",`panel.${u}.generate`],isLoading:m.value,color:"accent",isDisabled:p,suffix:w?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${u}.abort`,"common.cancel"],onClick:()=>{let y=c.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:f})=>{c.ui.closeDialog(f),h.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:f})=>{b(),c.ui.closeDialog(f),h.setValue(void 0)}}});h.setValue(y)}}:void 0,onClick:async()=>{k=new AbortController;let y=k.signal,f=async()=>{try{m.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),k?.abort()});let v=await Ur(t.kind,n,i,t,a,o,y);if(v.status==="aborted")return;let A=t.output.notification;Fr(c,A,()=>({input:n().input,output:v.output}))}catch(v){if(T(v))return;V(v,{cesdk:c,provider:t,getInput:n},o)}finally{k=void 0,m.setValue(!1),g.setValue(()=>{}),h.value!=null&&(c.ui.closeDialog(h.value),h.setValue(void 0))}};o.middleware!=null?await o.middleware(f,{provider:t,abort:b}):await f()}}),t.output.generationHintText!=null&&r.Text(`${u}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),s&&a.historyAssetLibraryEntryId!=null&&r.Library(`${u}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function Fr(e,t,n){let i=t?.success;if(i==null||!(typeof i.show=="function"?i.show(n()):i.show))return!1;let a=typeof i.message=="function"?i.message(n()):i.message??"common.ai-generation.success",o=i.action!=null?{label:typeof i.action.label=="function"?i.action.label(n()):i.action.label,onClick:()=>{i?.action?.onClick(n())}}:void 0;return e.ui.showNotification({type:"success",message:a,action:o,duration:i.duration}),!0}var it=Qr;async function Gr(e,t,n,i){let{cesdk:a}=n,{id:o}=e;i.debug&&console.log(`Registering schema-based panel input for provider ${o}`);let r=cr(t.document),l=Be(r,t.inputReference);if(!ur(l,i.debug))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let c=l,s=Qe(c,t),u=d=>{let{builder:g}=d,m=[];g.Section(`${o}.schema.section`,{children:()=>{s.forEach(p=>{let h=Cr(d,p,e,t,n,i);h!=null&&(Array.isArray(h)?m.push(...h):m.push(h))})}});let k=m.map(p=>p()),w=p=>p.type==="object"?Object.entries(p.value).reduce((h,[y,f])=>(h[y]=w(f),h),{}):p.value,b=k.reduce((p,h)=>(p[h.id]=w(h),p),{});it(d,e,()=>({input:b}),()=>t.getBlockInput(b),{...n,requiredInputs:c.required,createPlaceholderBlock:t.userFlow==="placeholder"},i)};return a.ui.registerPanel(Fe(o),u),u}var Rr=Gr;async function Hr(e,t,n,i){let{cesdk:a}=n,{id:o}=e,r=t.render,l=c=>{let{state:s}=c,u=s(tt(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:g}=r(c,{cesdk:a,isGenerating:u});return it(c,e,d,g,{...n,includeHistoryLibrary:t.includeHistoryLibrary??!0,createPlaceholderBlock:t.userFlow==="placeholder"},i),d};return a.ui.registerPanel(Fe(o),l),l}var Zr=Hr,ee="@imgly/plugin-ai-generation",Yr=`
77
+ `,rt=Hr;var qr=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="",p=[];l.label!=null&&typeof l.label=="object"&&l.label[c]&&(d=l.label[c]),l.tags!=null&&typeof l.tags=="object"&&l.tags[c]&&(p=l.tags[c]);let g={...l,label:d,tags:p};return this.filterAsset(g,e)&&u.push(g),u},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,a=n+i,o=t.slice(n,a),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;O(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=()=>{O(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 O(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),O(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 O(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]=O(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]=O(n,t,a)}return e}var Qr=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(c=>this.cesdk.engine.asset.findAssets(c,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(c=>{c?.assets&&(i=i.concat(c.assets))}),i.sort((c,d)=>{let p=c.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,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")}},Zr=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},wt=Zr,Yr=typeof global=="object"&&global&&global.Object===Object&&global,kt=Yr,Kr=typeof self=="object"&&self&&self.Object===Object&&self,Wr=kt||Kr||Function("return this")(),E=Wr,Xr=E.Symbol,R=Xr,xt=Object.prototype,Jr=xt.hasOwnProperty,ei=xt.toString,K=R?R.toStringTag:void 0;function ti(e){var t=Jr.call(e,K),r=e[K];try{e[K]=void 0;var i=!0}catch{}var n=ei.call(e);return i&&(t?e[K]=r:delete e[K]),n}var ri=ti,ii=Object.prototype,ni=ii.toString;function oi(e){return ni.call(e)}var ai=oi,si="[object Null]",li="[object Undefined]",it=R?R.toStringTag:void 0;function ui(e){return e==null?e===void 0?li:si:it&&it in Object(e)?ri(e):ai(e)}var re=ui;function ci(e){return e!=null&&typeof e=="object"}var Fe=ci,Yc=Array.isArray;function di(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var It=di,pi="[object AsyncFunction]",gi="[object Function]",fi="[object GeneratorFunction]",mi="[object Proxy]";function hi(e){if(!It(e))return!1;var t=re(e);return t==gi||t==fi||t==pi||t==mi}var yi=hi,bi=E["__core-js_shared__"],Le=bi,nt=function(){var e=/[^.]+$/.exec(Le&&Le.keys&&Le.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function vi(e){return!!nt&&nt in e}var wi=vi,ki=Function.prototype,xi=ki.toString;function Ii(e){if(e!=null){try{return xi.call(e)}catch{}try{return e+""}catch{}}return""}var N=Ii,Ci=/[\\^$.*+?()[\]{}|]/g,Ai=/^\[object .+?Constructor\]$/,Si=Function.prototype,Mi=Object.prototype,Ei=Si.toString,Li=Mi.hasOwnProperty,Ti=RegExp("^"+Ei.call(Li).replace(Ci,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ji(e){if(!It(e)||wi(e))return!1;var t=yi(e)?Ti:Ai;return t.test(N(e))}var _i=ji;function $i(e,t){return e?.[t]}var Ni=$i;function Di(e,t){var r=Ni(e,t);return _i(r)?r:void 0}var z=Di,Pi=z(E,"WeakMap"),Ne=Pi;function Oi(e,t){return e===t||e!==e&&t!==t}var Ri=Oi,zi=9007199254740991;function Fi(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=zi}var Ui=Fi,Kc=Object.prototype,Vi="[object Arguments]";function Bi(e){return Fe(e)&&re(e)==Vi}var ot=Bi,Ct=Object.prototype,Gi=Ct.hasOwnProperty,Hi=Ct.propertyIsEnumerable,Wc=ot(function(){return arguments}())?ot:function(e){return Fe(e)&&Gi.call(e,"callee")&&!Hi.call(e,"callee")},At=typeof exports=="object"&&exports&&!exports.nodeType&&exports,at=At&&typeof module=="object"&&module&&!module.nodeType&&module,qi=at&&at.exports===At,st=qi?E.Buffer:void 0,Xc=st?st.isBuffer:void 0,Qi="[object Arguments]",Zi="[object Array]",Yi="[object Boolean]",Ki="[object Date]",Wi="[object Error]",Xi="[object Function]",Ji="[object Map]",en="[object Number]",tn="[object Object]",rn="[object RegExp]",nn="[object Set]",on="[object String]",an="[object WeakMap]",sn="[object ArrayBuffer]",ln="[object DataView]",un="[object Float32Array]",cn="[object Float64Array]",dn="[object Int8Array]",pn="[object Int16Array]",gn="[object Int32Array]",fn="[object Uint8Array]",mn="[object Uint8ClampedArray]",hn="[object Uint16Array]",yn="[object Uint32Array]",x={};x[un]=x[cn]=x[dn]=x[pn]=x[gn]=x[fn]=x[mn]=x[hn]=x[yn]=!0;x[Qi]=x[Zi]=x[sn]=x[Yi]=x[ln]=x[Ki]=x[Wi]=x[Xi]=x[Ji]=x[en]=x[tn]=x[rn]=x[nn]=x[on]=x[an]=!1;function bn(e){return Fe(e)&&Ui(e.length)&&!!x[re(e)]}var vn=bn;function wn(e){return function(t){return e(t)}}var kn=wn,St=typeof exports=="object"&&exports&&!exports.nodeType&&exports,J=St&&typeof module=="object"&&module&&!module.nodeType&&module,xn=J&&J.exports===St,Te=xn&&kt.process,In=function(){try{var e=J&&J.require&&J.require("util").types;return e||Te&&Te.binding&&Te.binding("util")}catch{}}(),lt=In,ut=lt&&lt.isTypedArray,Jc=ut?kn(ut):vn,Cn=Object.prototype,ed=Cn.hasOwnProperty;function An(e,t){return function(r){return e(t(r))}}var Sn=An,td=Sn(Object.keys,Object),Mn=Object.prototype,rd=Mn.hasOwnProperty,En=z(Object,"create"),ee=En;function Ln(){this.__data__=ee?ee(null):{},this.size=0}var Tn=Ln;function jn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var _n=jn,$n="__lodash_hash_undefined__",Nn=Object.prototype,Dn=Nn.hasOwnProperty;function Pn(e){var t=this.__data__;if(ee){var r=t[e];return r===$n?void 0:r}return Dn.call(t,e)?t[e]:void 0}var On=Pn,Rn=Object.prototype,zn=Rn.hasOwnProperty;function Fn(e){var t=this.__data__;return ee?t[e]!==void 0:zn.call(t,e)}var Un=Fn,Vn="__lodash_hash_undefined__";function Bn(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ee&&t===void 0?Vn:t,this}var Gn=Bn;function F(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])}}F.prototype.clear=Tn;F.prototype.delete=_n;F.prototype.get=On;F.prototype.has=Un;F.prototype.set=Gn;var ct=F;function Hn(){this.__data__=[],this.size=0}var qn=Hn;function Qn(e,t){for(var r=e.length;r--;)if(Ri(e[r][0],t))return r;return-1}var fe=Qn,Zn=Array.prototype,Yn=Zn.splice;function Kn(e){var t=this.__data__,r=fe(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Yn.call(t,r,1),--this.size,!0}var Wn=Kn;function Xn(e){var t=this.__data__,r=fe(t,e);return r<0?void 0:t[r][1]}var Jn=Xn;function eo(e){return fe(this.__data__,e)>-1}var to=eo;function ro(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 io=ro;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=qn;U.prototype.delete=Wn;U.prototype.get=Jn;U.prototype.has=to;U.prototype.set=io;var me=U,no=z(E,"Map"),te=no;function oo(){this.size=0,this.__data__={hash:new ct,map:new(te||me),string:new ct}}var ao=oo;function so(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var lo=so;function uo(e,t){var r=e.__data__;return lo(t)?r[typeof t=="string"?"string":"hash"]:r.map}var he=uo;function co(e){var t=he(this,e).delete(e);return this.size-=t?1:0,t}var po=co;function go(e){return he(this,e).get(e)}var fo=go;function mo(e){return he(this,e).has(e)}var ho=mo;function yo(e,t){var r=he(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var bo=yo;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=ao;V.prototype.delete=po;V.prototype.get=fo;V.prototype.has=ho;V.prototype.set=bo;var Mt=V;function vo(){this.__data__=new me,this.size=0}var wo=vo;function ko(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var xo=ko;function Io(e){return this.__data__.get(e)}var Co=Io;function Ao(e){return this.__data__.has(e)}var So=Ao,Mo=200;function Eo(e,t){var r=this.__data__;if(r instanceof me){var i=r.__data__;if(!te||i.length<Mo-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Mt(i)}return r.set(e,t),this.size=r.size,this}var Lo=Eo;function ie(e){var t=this.__data__=new me(e);this.size=t.size}ie.prototype.clear=wo;ie.prototype.delete=xo;ie.prototype.get=Co;ie.prototype.has=So;ie.prototype.set=Lo;var To=Object.prototype,id=To.propertyIsEnumerable,jo=z(E,"DataView"),De=jo,_o=z(E,"Promise"),Pe=_o,$o=z(E,"Set"),Oe=$o,dt="[object Map]",No="[object Object]",pt="[object Promise]",gt="[object Set]",ft="[object WeakMap]",mt="[object DataView]",Do=N(De),Po=N(te),Oo=N(Pe),Ro=N(Oe),zo=N(Ne),P=re;(De&&P(new De(new ArrayBuffer(1)))!=mt||te&&P(new te)!=dt||Pe&&P(Pe.resolve())!=pt||Oe&&P(new Oe)!=gt||Ne&&P(new Ne)!=ft)&&(P=function(e){var t=re(e),r=t==No?e.constructor:void 0,i=r?N(r):"";if(i)switch(i){case Do:return mt;case Po:return dt;case Oo:return pt;case Ro:return gt;case zo:return ft}return t});var nd=E.Uint8Array,Fo="__lodash_hash_undefined__";function Uo(e){return this.__data__.set(e,Fo),this}var Vo=Uo;function Bo(e){return this.__data__.has(e)}var Go=Bo;function Re(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Mt;++t<r;)this.add(e[t])}Re.prototype.add=Re.prototype.push=Vo;Re.prototype.has=Go;var ht=R?R.prototype:void 0,od=ht?ht.valueOf:void 0,Ho=Object.prototype,ad=Ho.hasOwnProperty,qo=Object.prototype,sd=qo.hasOwnProperty,ld=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),ud=new RegExp(/[A-Fa-f0-9]{1}/,"g"),cd=new RegExp(/[A-Fa-f0-9]{2}/,"g");function Qo(e){return{"image/png":"png","image/jpeg":"jpg","image/webp":"webp","image/gif":"gif","image/svg+xml":"svg"}[e]??"png"}async function Et(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 ze(e,t){let r=await Et(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 Zo(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 Et(i,t)}function Yo(e){return e!==void 0}var ye=Yo;var Ue=class Lt{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 Lt),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))}},Tt=class jt{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new jt),r[t]}register(t){return this.providers.has(t.provider.id)&&console.warn(`Provider with ID "${t.provider.id}" is already registered`),this.providers.set(t.provider.id,t),()=>{this.providers.get(t.provider.id)===t&&this.providers.delete(t.provider.id)}}getAll(){return Array.from(this.providers.values())}getById(t){return this.providers.get(t)}getByKind(t){return this.getAll().filter(({provider:r})=>r.kind===t)}};function Ko(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 p=t[l],g=async(v,b)=>s(l+1,v,b),h={...d,addDisposer:o};return p(c,h,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 Wo({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 Xo=Wo;var je="ly.img.ai.temp";async function Jo(e,t){return e.engine.asset.findAllSources().includes(je)||e.engine.asset.addLocalSource(je),e.engine.asset.apply(je,t)}function ea(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let r=e;return"message"in r&&typeof r.message=="string"?r.message:"cause"in r&&typeof r.cause=="string"?r.cause:"detail"in r&&typeof r.detail=="object"&&r.detail!==null&&"message"in r.detail&&typeof r.detail.message=="string"?r.detail.message:"error"in r&&typeof r.error=="object"&&r.error!==null&&"message"in r.error&&typeof r.error.message=="string"?r.error.message:t}return typeof e=="string"?e:String(e)||t}function _t(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function ta(e,t=0,r="image/jpeg",i=.8){return new Promise((n,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 $t(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 ra(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 Ve(e){return e instanceof Error&&e.name==="AbortError"}function ia(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function Nt(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!
78
+ Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}.
79
+ This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version.
80
+ 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 na(e,t){let{cesdk:r,provider:i,getInput:n}=t;console.error("Generation failed:",e),oa(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:ea(e)})}function oa(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 yt=na,aa="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",Be=aa;function sa(e,t,r){switch(t){case"image":return la(e,r[t]);case"video":return ua(e,r[t]);case"sticker":return ca(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function la(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Be,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function ua(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:Be,mimeType:"video/mp4",kind:"video",fillType:"//ly.img.ubq/fill/video",duration:t.duration.toString(),width:r,height:i}}}function ca(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:Be,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var da=sa;async function pa(e,t,r,i){switch(t){case"image":{if(i.kind!=="image")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: image)`);return ga(e,r[t],i)}case"video":{if(i.kind!=="video")throw new Error(`Output kind does not match the expected type: ${i.kind} (expected: video)`);return fa(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 ma(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 ha(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function ga(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"image",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}async function fa(e,t,r){let i=t.width,n=t.height,a=await ta(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 ma(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 ha(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 Dt=pa;function ya(e){switch(e.userFlow){case"placeholder":return va(e);case"generation-only":return ba(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function ba(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(T(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(T(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(T(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let s=_t(),u=await Dt(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 va(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(T(t,r))return{status:"aborted"};let s=_t(),u=da(s,a,o);if(i=await Jo(t,u),T(t,r,i))return{status:"aborted"};if(i!=null&&e.kind==="video"){let d=t.engine.block.getPositionX(i),p=t.engine.block.getPositionY(i),g=t.engine.block.duplicate(i);t.engine.block.setPositionX(g,d),t.engine.block.setPositionY(g,p),t.engine.block.destroy(i),i=g}if(i==null)throw new Error("Could not create placeholder block");t.engine.block.setState(i,{type:"Pending",progress:0});let l=await e.generate(n,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(T(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 Dt(s,a,o,l.output);if(T(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),T(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)&&(Ve(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 T(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var wa=ya;function Ge(e){return`${e}.generating`}function ka(e){return`${e}.abort`}function xa(e,t,r,i,n,a,o){let{builder:s,experimental:u}=e,{cesdk:l,includeHistoryLibrary:c=!0}=a,{id:d,output:{abortable:p}}=t,g=u.global(ka(d),()=>{}),h=u.global(Ge(d),!1),v,b=h.value&&p,y=()=>{b&&(g.value(),h.setValue(!1),g.setValue(()=>{}))},A;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let m=i();A=a.requiredInputs.every(f=>!m.input[f])}let w=u.global(`${d}.confirmationDialogId`,void 0);s.Section(`${d}.generate.section`,{children:()=>{s.Button(`${d}.generate`,{label:["common.generate",`panel.${d}.generate`],isLoading:h.value,color:"accent",isDisabled:A,suffix:b?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let m=l.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:f})=>{l.ui.closeDialog(f),w.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:f})=>{y(),l.ui.closeDialog(f),w.setValue(void 0)}}});w.setValue(m)}}:void 0,onClick:async()=>{v=new AbortController;let m=v.signal;await(async()=>{try{h.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),v?.abort()});let f=await wa({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:m,cesdk:l,debug:o.debug,dryRun:o.dryRun})(i().input);if(f.status==="aborted")return;if(f.status==="error"){yt(f.message,{cesdk:l,provider:t,getInput:i});return}if(f.status==="success"&&f.type==="sync"){let k=t.output.notification;Ia(l,k,()=>({input:i().input,output:f.output}))}}catch(f){if(Ve(f))return;yt(f,{cesdk:l,provider:t,getInput:i})}finally{v=void 0,h.setValue(!1),g.setValue(()=>{}),w.value!=null&&(l.ui.closeDialog(w.value),w.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 Ia(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 Pt=xa;async function Ca({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(Ge(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=s(u,{cesdk:a,isGenerating:c});return Pt(u,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var Aa=Ca;function Ot(e,t){if(!t.startsWith("#/"))throw new Error(`External references are not supported: ${t}`);let r=t.substring(2).split("/"),i=e;for(let n of r){if(i==null)throw new Error(`Invalid reference path: ${t}`);i=i[n]}if(i===void 0)throw new Error(`Reference not found: ${t}`);return i}function X(e,t,r=new Set){if(t==null||r.has(t))return t;if(r.add(t),t.$ref&&typeof t.$ref=="string"){let i=Ot(e,t.$ref),n={...X(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=X(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>X(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=X(e,t[n],r));return i}return t}function Sa(e){return X(e,{...e})}function Ma(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 Ea(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return La(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function La(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=Ta(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function Ta(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let r=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return r==null?void 0:e[r]}var Rt=Ea;function zt(e,t,r,i,n,a){if(t.schema==null)return i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null?i.renderCustomProperty[t.id](e,t):void 0;let o=t,s=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null)return i.renderCustomProperty[t.id](e,t);switch(s){case"string":return t.schema.enum!=null?ja(e,o,r,i,n,a):Ut(e,o,r,i,n,a);case"boolean":return Vt(e,o,r,i,n,a);case"number":case"integer":return Bt(e,o,r,i,n,a);case"object":return Ft(e,o,r,i,n,a);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return _a(e,o,r,i,n,a);break}default:console.error(`Unsupported property type: ${s}`)}}function Ft(e,t,r,i,n,a){let o=Rt(t.schema??{},i).reduce((s,u)=>{let l=zt(e,u,r,i,n,a);return l!=null&&(s[u.id]=l()),s},{});return()=>({id:t.id,type:"object",value:o})}function Ut(e,t,r,i,n,a){let{builder:o,experimental:{global:s}}=e,{id:u}=t,l=`${r.id}.${u}`,c=t.schema.title??l,d=s(l,t.schema.default??""),p=$a(t.schema),g=p?.component!=null&&p?.component==="TextArea"?"TextArea":"TextInput";return o[g](l,{inputLabel:c,placeholder:n.i18n?.prompt,...d}),()=>({id:t.id,type:"string",value:d.value})}function ja(e,t,r,i,n,a){let{builder:o,experimental:{global:s}}=e,{id:u}=t,l=`${r.id}.${u}`,c=t.schema.title??l,d=t.schema.enum!=null&&"x-imgly-enum-labels"in t.schema.enum&&typeof t.schema.enum["x-imgly-enum-labels"]=="object"?t.schema.enum["x-imgly-enum-labels"]:"x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},p="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{},g=(t.schema.enum??[]).map(b=>({id:b,label:d[b]??$t(b),icon:p[b]})),h=t.schema.default!=null?g.find(b=>b.id===t.schema.default)??g[0]:g[0],v=s(l,h);return o.Select(l,{inputLabel:c,values:g,...v}),()=>({id:t.id,type:"string",value:v.value.id})}function Vt(e,t,r,i,n,a){let{builder:o,experimental:{global:s}}=e,{id:u}=t,l=`${r.id}.${u}`,c=t.schema.title??l,d=!!t.schema.default,p=s(l,d);return o.Checkbox(l,{inputLabel:c,...p}),()=>({id:t.id,type:"boolean",value:p.value})}function Bt(e,t,r,i,n,a){let{builder:o,experimental:{global:s}}=e,{id:u}=t,l=`${r.id}.${u}`,c=t.schema.title??l,d=t.schema.minimum,p=t.schema.maximum,g=t.schema.default;g==null&&(d!=null?g=d:p!=null?g=p:g=0);let h=s(l,g);if(d!=null&&p!=null){let v=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(v=t.schema["x-imgly-step"]),o.Slider(l,{inputLabel:c,min:d,max:p,step:v,...h})}else o.NumberInput(l,{inputLabel:c,min:d,max:p,...h});return()=>({id:t.id,type:"integer",value:h.value})}function _a(e,t,r,i,n,a){let{builder:o,experimental:{global:s}}=e,{id:u}=t,l=`${r.id}.${u}`,c=t.schema.title??l,d=t.schema.anyOf??[],p=[],g={},h={};d.forEach((y,A)=>{let w=y.title??"common.custom",m=`${r.id}.${u}.anyOf[${A}]`,f="x-imgly-enum-labels"in t.schema&&typeof t.schema["x-imgly-enum-labels"]=="object"?t.schema["x-imgly-enum-labels"]:{},k="x-imgly-enum-icons"in t.schema&&typeof t.schema["x-imgly-enum-icons"]=="object"?t.schema["x-imgly-enum-icons"]:{};y.type==="string"?y.enum!=null?y.enum.forEach(C=>{p.push({id:C,label:f[C]??$t(C),icon:k[C]})}):(g[m]=()=>Ut(e,{id:m,schema:{...y,title:w}},r,i,n,a),p.push({id:m,label:f[w]??w,icon:k[w]})):y.type==="boolean"?(g[m]=()=>Vt(e,{id:m,schema:{...y,title:w}},r,i,n,a),p.push({id:m,label:f[w]??w,icon:k[w]})):y.type==="integer"?(g[m]=()=>Bt(e,{id:m,schema:{...y,title:w}},r,i,n,a),p.push({id:m,label:f[w]??w,icon:k[w]})):y.type==="array"||y.type==="object"&&(g[m]=()=>Ft(e,{id:m,schema:{...y,title:w}},r,i,n,a),p.push({id:m,label:f[w]??w,icon:k[w]}))});let v=t.schema.default!=null?p.find(y=>y.id===t.schema.default)??p[0]:p[0],b=s(l,v);if(o.Select(l,{inputLabel:c,values:p,...b}),b.value.id in g){let y=g[b.value.id]();h[b.value.id]=y}return()=>{let y=h[b.value.id];return y!=null?{...y(),id:t.id}:{id:t.id,type:"string",value:b.value.id}}}function $a(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Na=zt;async function Da({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=Sa(r.document),s=Ot(o,r.inputReference);if(!Ma(s,i.debug))throw new Error(`Input reference '${r.inputReference}' does not resolve to a valid OpenAPI schema`);let u=s,l=Rt(u,r);return c=>{let{builder:d}=c,p=[];d.Section(`${a}.schema.section`,{children:()=>{l.forEach(b=>{let y=Na(c,b,t,r,e,i);y!=null&&(Array.isArray(y)?p.push(...y):p.push(y))})}});let g=p.map(b=>b()),h=b=>b.type==="object"?Object.entries(b.value).reduce((y,[A,w])=>(y[A]=h(w),y),{}):b.value,v=g.reduce((b,y)=>(b[y.id]=h(y),b),{});Pt(c,t,n,()=>({input:v}),()=>r.getBlockInput(v),{...e,requiredInputs:u.required,createPlaceholderBlock:r.userFlow==="placeholder"},i)}}var Pa=Da;async function Oa(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return Aa(e,t);case"schema":return Pa(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var Ra=Oa;function za(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 qr(o,r)),o}return i}var Fa=za;function Ua(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history.entry`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var Va=Ua,_e="@imgly/plugin-ai-generation",Ba=`
79
81
  <svg>
80
82
  <symbol
81
83
  fill="none"
@@ -93,7 +95,7 @@ var me="@imgly/plugin-ai-text-generation",lt=`
93
95
  fill="none"
94
96
  xmlns="http://www.w3.org/2000/svg"
95
97
  viewBox="0 0 24 24"
96
- id="${ee}/image"
98
+ id="${_e}/image"
97
99
  >
98
100
  <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"/>
99
101
  <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"/>
@@ -105,7 +107,7 @@ var me="@imgly/plugin-ai-text-generation",lt=`
105
107
  fill="none"
106
108
  xmlns="http://www.w3.org/2000/svg"
107
109
  viewBox="0 0 24 24"
108
- id="${ee}/video"
110
+ id="${_e}/video"
109
111
  >
110
112
  <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"/>
111
113
  <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"/>
@@ -116,7 +118,7 @@ var me="@imgly/plugin-ai-text-generation",lt=`
116
118
  fill="none"
117
119
  xmlns="http://www.w3.org/2000/svg"
118
120
  viewBox="0 0 24 24"
119
- id="${ee}/audio"
121
+ id="${_e}/audio"
120
122
  >
121
123
  <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"/>
122
124
  <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"/>
@@ -136,7 +138,179 @@ var me="@imgly/plugin-ai-text-generation",lt=`
136
138
 
137
139
  </symbol>
138
140
  </svg>
139
- `,Wr=Yr,je="ly.img.ai.quickAction.order",U="ly.img.ai.quickAction.actions";function Kr(e,t){return{id:t,setQuickActionMenuOrder:n=>{e.ui.experimental.setGlobalStateValue(`${je}.${t}`,n)},getQuickActionMenuOrder:()=>e.ui.experimental.getGlobalStateValue(`${je}.${t}`,[]),registerQuickAction:n=>{if(!e.ui.experimental.hasGlobalStateValue(`${U}.${t}`))e.ui.experimental.setGlobalStateValue(`${U}.${t}`,{[n.id]:n});else{let i=e.ui.experimental.getGlobalStateValue(`${U}.${t}`,{});e.ui.experimental.setGlobalStateValue(`${U}.${t}`,{...i,[n.id]:n})}},getQuickAction:n=>e.ui.experimental.getGlobalStateValue(`${U}.${t}`,{})[n]}}var ue=Kr,te="ly.img.ai.inference.editMode",nt="ly.img.ai.inference.metadata";function rt(e){return`ly.img.ai.quickAction.${e.quickActionMenuId}.${e.quickActionId}`}function Jr(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((n,i)=>(i==="ly.img.separator"&&n.length>0&&n[n.length-1]==="ly.img.separator"||n.push(i),n),[])}function Xr({alwaysOnTop:e=!0,disableClipping:t=!0}){return async(n,i,a)=>{let o={},r={},l=e||t?i.blockIds??i.engine.block.findAllSelected():[];return l.forEach(c=>{if(i.engine.block.isValid(c)&&e&&(o[c]=i.engine.block.isAlwaysOnTop(c),i.engine.block.setAlwaysOnTop(c,!0)),t){let s=i.engine.block.getParent(c);s!=null&&i.engine.block.getType(s)!=="//ly.img.ubq/scene"&&(r[s]=i.engine.block.isClipped(s),i.engine.block.setClipped(s,!1))}}),i.addDisposer(async()=>{l.forEach(c=>{if(i.engine.block.isValid(c)&&e&&i.engine.block.setAlwaysOnTop(c,o[c]),t){let s=i.engine.block.getParent(c);s!=null&&i.engine.block.getType(s)!=="//ly.img.ubq/scene"&&r[s]!=null&&i.engine.block.setClipped(s,r[s])}})}),await a(n,i)}}var eo=Xr;function to({pending:e=!0}){return async(t,n,i)=>{let a=e?n.blockIds??n.engine.block.findAllSelected():[];try{return a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Pending",progress:0})}),await i(t,n)}finally{a.forEach(o=>{n.engine.block.isValid(o)&&n.engine.block.setState(o,{type:"Ready"})})}}}var io=to;function no({editMode:e,automaticallyUnlock:t=!1}){return async(n,i,a)=>{let o=i.blockIds??i.engine.block.findAllSelected(),r=()=>{};t||i.addDisposer(async()=>{r?.()});try{return r=ro(i.engine,o,e),await a(n,i)}catch(l){throw T(l)&&r(),l}finally{t&&r()}}}function ro(e,t,n){let i=e.editor.getGlobalScope("editor/select"),a=e.editor.getEditMode();l(),e.editor.setGlobalScope("editor/select","Deny"),e.editor.setEditMode(n);let o=e.editor.createHistory(),r=e.editor.getActiveHistory();e.editor.setActiveHistory(o);function l(){e.block.findAllSelected().forEach(u=>{t.includes(u)||e.block.setSelected(u,!1)}),t.forEach(u=>{e.block.setSelected(u,!0)})}let c=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&e.editor.setEditMode(n)}),s=e.block.onSelectionChanged(l);return()=>{i!=null&&e.editor.setGlobalScope("editor/select",i),e.editor.setEditMode(a),e.editor.setActiveHistory(r),e.editor.destroyHistory(o),s(),c()}}var oo=no;function ao(e,t){switch(t.kind){case"text":return lo(e,t);case"image":return so(e,t);case"video":return co(e,t);case"audio":return uo(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function lo(e,t){let{cesdk:n,blockIds:i,abortSignal:a}=t,o=i.map(s=>n.engine.block.getString(s,"text/text")),r;if(ce(e)){let s="";for await(let u of e){if(a.aborted)break;typeof u=="string"?s=u:u.kind==="text"&&(s=u.text),i.forEach(d=>{n.engine.block.setString(d,"text/text",s)}),r={kind:"text",text:s}}}else r=e;if(r==null||r.kind!=="text")throw new Error("Output kind from generation is not text");let l=()=>{t.blockIds.forEach(s=>{t.cesdk.engine.block.setString(s,"text/text",r.text)})},c=()=>{t.blockIds.forEach((s,u)=>{t.cesdk.engine.block.setString(s,"text/text",o[u])})};return{consumedGenerationResult:r,applyCallbacks:{onBefore:c,onAfter:l,onCancel:c,onApply:()=>{l(),t.cesdk.engine.editor.addUndoStep()}}}}async function so(e,t){let{cesdk:n,blockIds:i,abortSignal:a}=t;if(i.length!==1)throw new Error("Only one block is supported for image generation");let[o]=i,r=n.engine.block.getFill(o),l=n.engine.block.getSourceSet(r,"fill/image/sourceSet"),[c]=l,s;c==null&&(s=n.engine.block.getString(r,"fill/image/imageFileURI"));let u=await n.engine.editor.getMimeType(c?.uri??s),d=await le(c?.uri??s,t.cesdk.engine),g=d.width/d.height;if(a.throwIfAborted(),u==="image/svg+xml")throw new Error("SVG images are not supported");let m=n.engine.block.getCropScaleX(o),k=n.engine.block.getCropScaleY(o),w=n.engine.block.getCropTranslationX(o),b=n.engine.block.getCropTranslationY(o),p=n.engine.block.getCropRotation(o),h=()=>{n.engine.block.setCropScaleX(o,m),n.engine.block.setCropScaleY(o,k),n.engine.block.setCropTranslationX(o,w),n.engine.block.setCropTranslationY(o,b),n.engine.block.setCropRotation(o,p)};if(ce(e))throw new Error("Streaming generation is not supported yet from a panel");if(e.kind!=="image"||typeof e.url!="string")throw new Error("Output kind from generation is not an image");let y=e.url,f=await n.engine.editor.getMimeType(y),v=await po(n,y,f),A=await le(v,t.cesdk.engine),I=A.width/A.height,M=Math.abs(g-I)>.001,L=c?[{uri:v,width:A.width,height:A.height}]:void 0,_=v;L==null?n.engine.block.setString(r,"fill/image/imageFileURI",_):(n.engine.block.setString(r,"fill/image/imageFileURI",""),n.engine.block.setSourceSet(r,"fill/image/sourceSet",L)),M?n.engine.block.setContentFillMode(o,"Cover"):h();let pe=()=>{if(l==null||l.length===0){if(s==null)throw new Error("No image URI found");n.engine.block.setString(r,"fill/image/imageFileURI",s)}else n.engine.block.setSourceSet(r,"fill/image/sourceSet",l);h()},ge=()=>{if(L==null){if(_==null)throw new Error("No image URI found");n.engine.block.setString(r,"fill/image/imageFileURI",_)}else n.engine.block.setSourceSet(r,"fill/image/sourceSet",L);M?n.engine.block.setContentFillMode(o,"Cover"):h()};return{consumedGenerationResult:e,applyCallbacks:{onBefore:pe,onAfter:ge,onCancel:()=>{pe()},onApply:()=>{ge(),t.cesdk.engine.editor.addUndoStep()}}}}async function co(e,t){throw new Error("Function not implemented.")}async function uo(e,t){throw new Error("Function not implemented.")}async function po(e,t,n){let i=await(await fetch(t)).blob(),a=new File([i],`image.${lr(n)}`,{type:n}),o=await e.unstable_upload(a,()=>{});return o?.meta?.uri??(console.warn("Failed to upload image:",o),t)}var go=ao;function mo({editMode:e,automaticallyUnlock:t=!1,showNotification:n=!0}){return async(i,a,o)=>{let r=a.blockIds??a.engine.block.findAllSelected(),l=()=>{};t||a.addDisposer(async()=>{l?.()});try{l=yo(a.engine,r,e);let c=await o(i,a);if(n){let s=a.engine.block.findAllSelected();r.some(u=>s.includes(u))||a.cesdk?.ui.showNotification({type:"success",message:"AI generation complete",action:{label:"Select",onClick:()=>{r.forEach(u=>{a.engine.block.select(u)})}}})}return c}catch(c){throw T(c)&&l(),c}finally{t&&l()}}}function yo(e,t,n){function i(){let r=e.block.findAllSelected();return t.some(l=>r.includes(l))}let a=e.editor.onStateChanged(()=>{e.editor.getEditMode()!==n&&i()&&e.editor.setEditMode(n)}),o=e.block.onSelectionChanged(()=>{i()?e.editor.setEditMode(n):e.editor.setEditMode("Transform")});return i()&&e.editor.setEditMode(n),()=>{o(),a(),e.editor.setEditMode("Transform")}}var fo=mo;async function bo(e,t){let{cesdk:n,input:i,blockIds:a,provider:o,quickAction:r,confirmationComponentId:l,abortSignal:c}=e;r.confirmation&&n.ui.setCanvasMenuOrder([l],{editMode:te});let s=new Ne(n.engine,nt);a.forEach(p=>{s.set(p,{status:"processing",quickActionId:r.id})});let u={cesdk:n,engine:n.engine,abortSignal:c},d=Je([...o.output.middleware??[],t.debug?Xe():void 0,io({}),...r.confirmation?[r.lockDuringConfirmation?oo({editMode:te}):fo({editMode:te}),r.confirmation&&eo({})]:[],t.dryRun?et({kind:o.kind,blockIds:a}):void 0]),{result:g,dispose:m}=await d(o.output.generate)(i,u),{consumedGenerationResult:k,applyCallbacks:w}=await go(g,{abortSignal:c,kind:o.kind,blockIds:a,cesdk:n});r.confirmation?a.forEach(p=>{s.set(p,{status:"confirmation",quickActionId:r.id})}):(w.onApply(),a.forEach(p=>{s.clear(p)}));let b=()=>{m(),a.forEach(p=>{s.clear(p)})};return c.addEventListener("abort",b),{dispose:b,returnValue:k,applyCallbacks:w}}var Te=bo;function ho(e,t){let{cesdk:n,quickActionMenu:i,provider:a}=e,o=`ly.img.ai.${i.id}`,r=`${o}.confirmation`;n.setTranslations({en:{[`${r}.apply`]:"Apply",[`${r}.before`]:"Before",[`${r}.after`]:"After",[`${o}.cancel`]:"Cancel",[`${o}.processing`]:"Generating..."}});let l=`${r}.canvasnMenu`,c={unlock:()=>{},abort:()=>{},applyCallbacks:void 0},s=()=>{let d=new AbortController,g=d.signal;return c.abort=()=>{d.abort()},g};n.ui.registerComponent(l,({builder:d,engine:g,state:m})=>{let k=g.block.findAllSelected();if(k.length===0)return null;let w=new Ne(n.engine,nt),b=w.get(k[0]);if(b==null)return null;let p=()=>{k.forEach(h=>{w.clear(h)})};switch(b.status){case"processing":{d.Button(`${o}.spinner`,{label:[`ly.img.ai.inference.${b.quickActionId}.processing`,`${o}.cancel`],isLoading:!0}),d.Separator(`${o}.separator`),d.Button(`${o}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{c.abort(),p()}});break}case"confirmation":{let h=m(`${r}.comparing`,"after"),y=c.applyCallbacks?.onCancel;y!=null&&d.Button(`${r}.cancel`,{icon:"@imgly/Cross",tooltip:`${o}.cancel`,onClick:()=>{c.unlock(),y(),p()}});let f=c.applyCallbacks?.onBefore,v=c.applyCallbacks?.onAfter;f!=null&&v!=null&&d.ButtonGroup(`${r}.compare`,{children:()=>{d.Button(`${r}.compare.before`,{label:`${r}.before`,variant:"regular",isActive:h.value==="before",onClick:()=>{f(),h.setValue("before")}}),d.Button(`${r}.compare.after`,{label:`${r}.after`,variant:"regular",isActive:h.value==="after",onClick:()=>{v(),h.setValue("after")}})}});let A=c.applyCallbacks?.onApply;A!=null&&d.Button(`${r}.apply`,{icon:"@imgly/Checkmark",tooltip:`${r}.apply`,color:"accent",isDisabled:h.value!=="after",onClick:()=>{c.unlock(),p(),n.engine.editor._update(),A()}});break}default:}});let u=`${o}.canvasMenu`;return n.ui.registerComponent(u,d=>{let g=d.engine.block.findAllSelected(),m=g.every(y=>d.engine.block.getState(y).type==="Ready"),k=i.getQuickActionMenuOrder().map(y=>{if(y==="ly.img.separator")return y;let f=i.getQuickAction(y);if(f==null||!n.feature.isEnabled(rt({quickActionId:y,quickActionMenuId:i.id}),{engine:d.engine}))return null;let v=f.scopes;return v!=null&&v.length>0&&!g.every(A=>v.every(I=>d.engine.block.isAllowedByScope(A,I)))?null:f}).filter(y=>y!=null);if(k=Jr(k),k.length===0||k.every(y=>y==="ly.img.separator"))return null;let{builder:w,experimental:b,state:p}=d,h=p(`${o}.toggleExpandedState`,void 0);b.builder.Popover(`${o}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!m,trailingIcon:null,children:({close:y})=>{w.Section(`${o}.popover.section`,{children:()=>{if(h.value!=null){let f=h.value,v=i.getQuickAction(f);if(v!=null&&v.renderExpanded!=null){v.renderExpanded(d,{blockIds:g,closeMenu:y,toggleExpand:()=>{h.setValue(void 0)},handleGenerationError:A=>{V(A,{cesdk:n,provider:a},t)},generate:async(A,I)=>{try{let{returnValue:M,applyCallbacks:L,dispose:_}=await Te({input:A,quickAction:v,quickActionMenu:i,provider:a,cesdk:n,abortSignal:s(),blockIds:I?.blockIds??g,confirmationComponentId:l},t);return c.unlock=_,c.applyCallbacks=L,M}catch(M){throw T(M)||V(M,{cesdk:n,provider:a},t),M}}});return}}b.builder.Menu(`${o}.menu`,{children:()=>{k.forEach(f=>{f==="ly.img.separator"?w.Separator(`${o}.separator.${Math.random().toString()}`):f.render(d,{blockIds:g,closeMenu:y,handleGenerationError:v=>{V(v,{cesdk:n,provider:a},t)},toggleExpand:()=>{h.setValue(f.id)},generate:async(v,A)=>{try{let{returnValue:I,applyCallbacks:M,dispose:L}=await Te({input:v,quickAction:f,quickActionMenu:i,provider:a,cesdk:n,abortSignal:s(),blockIds:A?.blockIds??g,confirmationComponentId:l},t);return c.unlock=L,c.applyCallbacks=M,I}catch(I){throw T(I)||V(I,{cesdk:n,provider:a},t),I}}})})}})}})}})}),{canvasMenuComponentId:u}}var ko=ho;async function vo(e,t,n){await e.initialize?.(t);let i=await Co(t.engine,e.id,e.output.history??"@imgly/local");if(t.cesdk==null)return{};let a=i?`${e.id}.history.entry`:void 0,o={...t,cesdk:t.cesdk,historyAssetSourceId:i,historyAssetLibraryEntryId:a,i18n:{prompt:"common.ai-generation.prompt.placeholder"}};a!=null&&i!=null&&t.cesdk.ui.addAssetLibraryEntry({id:a,sourceIds:[i],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),t.cesdk.i18n.setTranslations({en:{"common.ai-generation.success":"Generation Successful","common.ai-generation.failed":"Generation Failed","common.ai-generation.generate":"Generate","common.ai-generation.prompt.placeholder":"Describe what you want to create...",[`panel.${e.id}`]:wo(e)}});let r="@imgly/plugin-ai-generation.iconSetAdded";return t.cesdk.ui.experimental.hasGlobalStateValue(r)||(t.cesdk.ui.addIconSet("@imgly/plugin-ai-generation",Wr),t.cesdk.ui.experimental.setGlobalStateValue(r,!0)),{renderBuilderFunctions:await Ao(e,o,n)}}function wo(e){if(e.name!=null)return e.name;switch(e.kind){case"image":return"Generate Image";case"video":return"Generate Video";case"audio":return"Generate Audio";default:return"Generate Asset"}}async function Co(e,t,n){if(!(n==null||n===!1)){if(n==="@imgly/local"){let i=`${t}.history`;return e.asset.addLocalSource(i),i}if(n==="@imgly/indexedDB"){let i=`${t}.history`;return e.asset.addSource(new st(i,e)),i}return n}}async function Ao(e,t,n){let i={panel:void 0};return e.input?.panel!=null&&(i.panel=await Io(e,e.input.panel,t,n)),e.input?.quickActions!=null&&(n.debug&&console.log(`Initializing quick actions for provider '${e.kind}' (${e.id})`),Mo(e,e.input.quickActions,t,n)),i}async function Io(e,t,n,i){switch(t.type){case"custom":return Zr(e,t,n,i);case"schema":return Rr(e,t,n,i);default:i.debug&&console.warn(`Invalid panel input type '${t.type}' - skipping`)}}async function Mo(e,t,n,i){let{cesdk:a}=n,o={};t.actions.forEach(r=>{let l=r.kind??e.kind;o[l]==null&&(o[l]=ue(a,l));let c=o[l],s=r.enable??!0;a.feature.enable(rt({quickActionId:r.id,quickActionMenuId:l}),s),c.registerQuickAction(r),i.debug&&console.log(`Registered quick action: '${r.id}' (v${r.version}) to menu '${l}'`)}),Object.values(o).forEach(r=>{let{canvasMenuComponentId:l}=ko({cesdk:a,quickActionMenu:r,provider:e},i);i.debug&&console.log(`Registered quick action menu component: ${l}`)})}var ot=vo;var de="@imgly/plugin-ai-text-generation-web";var at=e=>({async initialize({cesdk:t}){if(t==null)return;let n=await e.provider?.({cesdk:t});ot(n,{cesdk:t,engine:t.engine},{debug:e.debug??!1,dryRun:!1});let i=ue(t,"text");i.setQuickActionMenuOrder(["improve","fix","shorter","longer","ly.img.separator","changeTone","translate","ly.img.separator","changeTextTo",...i.getQuickActionMenuOrder()]),t.ui.addIconSet(me,ye),t.setTranslations({en:{"ly.img.ai.inference.apply":"Apply","ly.img.ai.inference.cancel":"Cancel","ly.img.ai.inference.improve":"Improve Writing","ly.img.ai.inference.improve.processing":"Improving Writing...","ly.img.ai.inference.fix":"Fix Spelling & Grammar","ly.img.ai.inference.fix.processing":"Fixing spelling & grammar...","ly.img.ai.inference.longer":"Make Longer","ly.img.ai.inference.longer.processing":"Making longer...","ly.img.ai.inference.shorter":"Make Shorter","ly.img.ai.inference.shorter.processing":"Making shorter...","ly.img.ai.inference.changeTone":"Change Tone","ly.img.ai.inference.changeTone.processing":"Changing tone...","ly.img.ai.inference.changeTone.type.professional":"Professional","ly.img.ai.inference.changeTone.type.casual":"Casual","ly.img.ai.inference.changeTone.type.friendly":"Friendly","ly.img.ai.inference.changeTone.type.serious":"Serious","ly.img.ai.inference.changeTone.type.humorous":"Humorous","ly.img.ai.inference.changeTone.type.optimistic":"Optimistic","ly.img.ai.inference.translate":"Translate","ly.img.ai.inference.translate.processing":"Translating...","ly.img.ai.inference.changeTextTo":"Change Text to...","ly.img.ai.inference.changeTextTo.processing":"Changing text..."}})}});var xo=e=>({name:de,version:"0.1.10",...at(e)}),Xo=xo;export{Xo as default};
141
+ `,Ga=Ba;function Ha(e){return async(t,r,i)=>e.enable?(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await Gt(2e3),await qa(t,e,r)):i(t,r)}async function qa(e,t,r){switch(t.kind){case"image":return Qa(e,t,r);case"video":return Za(e,t,r);case"text":return Ya(e,t,r);case"audio":return Wa(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function Qa(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[s]=t.blockIds,u=await Zo(s,r),l=await ze(u,r);i=l.width,n=l.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
142
+ `,"+")}`}}async function Za(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function Ya(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=W(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=W(n,o)}else"customPrompt"in e?a=W(n,"custom"):a=W(n,"improved");else a=W(n,"generated");return Ka(a,r.abortSignal)}async function*Ka(e,t){let r=Math.max(1,Math.ceil(e.length/20)),i=0;for(;i<e.length;){if(t?.aborted)return;let n=Math.min(i+r,e.length);yield{kind:"text",text:e.substring(0,n)},i=n,i<e.length&&await Gt(100)}return{kind:"text",text:e}}function W(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 Wa(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:Xa(220,i),duration:i,thumbnailUrl:void 0}}function Xa(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 Ja(i,44100)}function Ja(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=(v,b)=>{for(let y=0;y<b.length;y++)c.setUint8(v+y,b.charCodeAt(y))};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 p=44;for(let v=0;v<r;v++){let b=Math.max(-1,Math.min(1,e[v])),y=Math.round(b*32767);c.setInt16(p,y,!0),p+=2}let g=new Uint8Array(l),h="";for(let v=0;v<g.length;v++)h+=String.fromCharCode(g[v]);return`data:audio/wav;base64,${btoa(h)}`}async function Gt(e){return new Promise(t=>{setTimeout(t,e)})}var es=Ha,Ht="USER_CANCEL";function ts(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=Ko([...e.provider.output.middleware??[],...r?.middlewares??[],Xo({enable:r?.debug}),es({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"}:ra(n)?{status:"success",type:"async",output:n}:{status:"success",type:"sync",output:n}}catch(n){return Ve(n)?{status:"aborted",message:n.message}:n===Ht?{status:"aborted",message:n}:{status:"error",message:n instanceof Error?n.message:String(n)}}}}var rs=ts;async function is(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=Fa(a),s=Va(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=s;let u=rs({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),l=await Ra(a,u);ia(r.cesdk,"@imgly/plugin-ai-generation",Ga);let c={provider:t,panel:{builderRenderFunction:l},history:{assetSourceId:o,assetLibraryEntryId:s},generate:u};return Tt.get().register(c),c}var $e=is;function ns(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 Qr(n,r,i);return r.engine.asset.addSource(a),a.id}var os=ns;async function as(e,t,r,i){let n,a=[];if(Array.isArray(t)){let s=await Promise.all(t.map(u=>$e(e,u,r,i)));a.push(...s),n=ls({prefix:e,providerInitializationResults:a})}else{let s=await Promise.all(t.fromText.map(l=>$e(e,l,r,i)));a.push(...s);let u=await Promise.all(t.fromImage.map(l=>$e(e,l,r,i)));a.push(...u),n=ss({prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:s,initializedFromImageProviders:u})}let o=os({kind:e,cesdk:r.cesdk,historAssetSourceIds:a.map(s=>s.history?.assetSourceId).filter(ye)});return{panel:{builderRenderFunction:n},history:{assetSourceId:o},providerInitializationResults:a}}function ss({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:h,panel:v})=>({id:h.id,label:h.name??h.id,builderRenderFunction:v?.builderRenderFunction})),c=r.map(({provider:h,panel:v})=>({id:h.id,label:h.name??h.id,builderRenderFunction:v?.builderRenderFunction})),d=n.experimental.global(`${e}.selectedProvider.fromText`,l[0]),p=n.experimental.global(`${e}.selectedProvider.fromImage`,c[0]),g=s.value==="fromText"?d:s.value==="fromImage"?p:void 0;if((i||u.length>1)&&a.Section(`${e}.providerSelection.section`,{children:()=>{if(i&&a.ButtonGroup(`${e}.fromType.buttonGroup`,{inputLabel:"Input",children:()=>{a.Button(`${e}.fromType.buttonGroup.fromText`,{label:"Text",icon:s.value!=="fromText"&&bt(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"&&bt(r,n)?"@imgly/LoadingSpinner":void 0,isActive:s.value==="fromImage",onClick:()=>{s.setValue("fromImage")}})}}),u.length>1){let h=s.value==="fromText"?l:s.value==="fromImage"?c:[...l,...c];g!=null&&a.Select(`${e}.providerSelect.select`,{inputLabel:"Provider",values:h,...g})}}}),u.length>1)g?.value.builderRenderFunction?.(n);else{let h=u[0];h&&h.panel?.builderRenderFunction?.(n)}}}function ls({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 bt(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(Ge(r.id),!1).value)}var qt=as,ne="ly.img.ai.editMode",Qt="ly.img.ai.metadata";async function us(e){let t=`ly.img.ai.${e.kind}.confirmation`;e.cesdk?.i18n.setTranslations({en:{"ly.img.ai.processing":"Generating...",[`${t}.cancel`]:"Cancel Generation",[`${t}.apply`]:"Apply Generation",[`${t}.before`]:"Before",[`${t}.after`]:"After"}});let r=i=>{let{engine:n,builder:a,state:o,payload:s}=i;if(s==null)return;let u=n.block.findAllSelected();if(u.length===0)return null;let l=new wt(n,Qt),c=l.get(u[0]);if(c==null)return null;let d=()=>{u.forEach(p=>{l.clear(p)})};switch(c.status){case"processing":{a.Button(`${t}.spinner`,{label:[`ly.img.ai.${c.quickActionId}.processing`,"ly.img.ai.processing"],isLoading:!0}),a.Separator(`${t}.separator`),a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{s.onCancelGeneration?.(),d()}});break}case"confirmation":{let p=o(`${t}.comparing`,"after"),g=s.applyCallbacks?.onCancel;g!=null&&a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{g(),d()}});let h=s.applyCallbacks?.onBefore,v=s.applyCallbacks?.onAfter;h!=null&&v!=null&&a.ButtonGroup(`${t}.compare`,{children:()=>{a.Button(`${t}.compare.before`,{label:`${t}.before`,variant:"regular",isActive:p.value==="before",onClick:()=>{h(),p.setValue("before")}}),a.Button(`${t}.compare.after`,{label:`${t}.after`,variant:"regular",isActive:p.value==="after",onClick:()=>{v(),p.setValue("after")}})}});let b=s.applyCallbacks?.onApply;b!=null&&a.Button(`${t}.apply`,{icon:"@imgly/Checkmark",tooltip:`${t}.apply`,color:"accent",isDisabled:p.value!=="after",onClick:()=>{d(),cesdk?.engine.editor._update(),b()}});break}default:}};return Promise.resolve(r)}var cs=us;function ds(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((r,i)=>(i==="ly.img.separator"&&r.length>0&&r[r.length-1]==="ly.img.separator"||r.push(i),r),[])}var ps=ds;function gs(e){return`ly.img.ai.${e}.canvasMenu`}var fs=gs;function ms(e){let{kind:t,cesdk:r,payload:i,defaultOrder:n}=e,a=fs(t);if(i==null||!Array.isArray(i.children)){let o=r.ui.getCanvasMenuOrder().find(({id:s})=>s===a);return o!=null&&Array.isArray(o.children)?o.children:n??[]}return i.children.filter(o=>typeof o=="string")}var hs=ms;function ys(e,t){if(t.blockIds.some(r=>!t.cesdk.engine.block.isValid(r)))return Promise.resolve({applyCallbacks:{onBefore:()=>{},onAfter:()=>{},onCancel:()=>{},onApply:()=>{}}});switch(t.kind){case"text":return bs(e,t);case"image":return vs(e,t);case"video":return ws(e,t);case"audio":return ks(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function bs(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t,a=i.map(l=>r.engine.block.getString(l,"text/text")),o;if(e.type==="async"){let l="";for await(let c of e.output){if(n?.aborted)break;typeof c=="string"?l=c:c.kind==="text"&&(l=c.text),i.forEach(d=>{r.engine.block.setString(d,"text/text",l)}),o={kind:"text",text:l}}}else o=e.output;if(o==null||o.kind!=="text")throw new Error("Output kind from generation is not text");e.type==="sync"&&i.forEach(l=>{r.engine.block.setString(l,"text/text",o.text)});let s=()=>{t.blockIds.forEach(l=>{t.cesdk.engine.block.setString(l,"text/text",o.text)})},u=()=>{t.blockIds.forEach((l,c)=>{t.cesdk.engine.block.setString(l,"text/text",a[c])})};return{applyCallbacks:{onBefore:u,onAfter:s,onCancel:u,onApply:()=>{s(),t.cesdk.engine.editor.addUndoStep()}}}}async function vs(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t;if(i.length!==1)throw new Error("Only one block is supported for image generation");let[a]=i,o=r.engine.block.getFill(a),s=r.engine.block.getSourceSet(o,"fill/image/sourceSet"),[u]=s,l;u==null&&(l=r.engine.block.getString(o,"fill/image/imageFileURI"));let c=await r.engine.editor.getMimeType(u?.uri??l),d=await ze(u?.uri??l,t.cesdk.engine),p=d.width/d.height;if(n?.throwIfAborted(),c==="image/svg+xml")throw new Error("SVG images are not supported");let g=r.engine.block.getCropScaleX(a),h=r.engine.block.getCropScaleY(a),v=r.engine.block.getCropTranslationX(a),b=r.engine.block.getCropTranslationY(a),y=r.engine.block.getCropRotation(a),A=()=>{r.engine.block.setCropScaleX(a,g),r.engine.block.setCropScaleY(a,h),r.engine.block.setCropTranslationX(a,v),r.engine.block.setCropTranslationY(a,b),r.engine.block.setCropRotation(a,y)};if(e.type==="async")throw new Error("Streaming generation is not supported yet from a panel");if(e.output.kind!=="image"||typeof e.output.url!="string")throw new Error("Output kind from generation is not an image");let w=e.output.url,m=await r.engine.editor.getMimeType(w),f=await xs(r,w,m),k=await ze(f,t.cesdk.engine),C=k.width/k.height,Y=Math.abs(p-C)>.001,M=u?[{uri:f,width:k.width,height:k.height}]:void 0,Ee=f;M==null?r.engine.block.setString(o,"fill/image/imageFileURI",Ee):(r.engine.block.setString(o,"fill/image/imageFileURI",""),r.engine.block.setSourceSet(o,"fill/image/sourceSet",M)),await r.engine.block.forceLoadResources([o]),Y?r.engine.block.setContentFillMode(a,"Cover"):A();let Je=()=>{if(s==null||s.length===0){if(l==null)throw new Error("No image URI found");r.engine.block.setString(o,"fill/image/imageFileURI",l)}else r.engine.block.setSourceSet(o,"fill/image/sourceSet",s);A()},et=()=>{if(M==null){if(Ee==null)throw new Error("No image URI found");r.engine.block.setString(o,"fill/image/imageFileURI",Ee)}else r.engine.block.setSourceSet(o,"fill/image/sourceSet",M);Y?r.engine.block.setContentFillMode(a,"Cover"):A()};return{applyCallbacks:{onBefore:Je,onAfter:et,onCancel:()=>{Je()},onApply:()=>{et(),t.cesdk.engine.editor.addUndoStep()}}}}async function ws(e,t){throw new Error("Function not implemented.")}async function ks(e,t){throw new Error("Function not implemented.")}async function xs(e,t,r){let i=await(await fetch(t)).blob(),n=new File([i],`image.${Qo(r)}`,{type:r}),a=await e.unstable_upload(n,()=>{});return a?.meta?.uri??(console.warn("Failed to upload image:",a),t)}var Is=ys;function Cs(e){let{engine:t,blockIdsToLock:r,editModeToLockTo:i}=e;function n(){let u=t.block.findAllSelected();return r.some(l=>u.includes(l))}let a=t.editor.onStateChanged(()=>{t.editor.getEditMode()!==i&&n()&&t.editor.setEditMode(i)}),o=t.block.onSelectionChanged(()=>{n()?t.editor.setEditMode(i):t.editor.setEditMode("Transform")});n()&&t.editor.setEditMode(i);let s=!1;return()=>{s||(o(),a(),t.editor.setEditMode("Transform"),s=!0)}}var As=Cs,Ss=class Zt{constructor(){this.actions=new Map}static get(){let t="__imgly_callbacks_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new Zt),r[t]}register(t,r){let i=this.actions.get(t)??{};this.actions.set(t,{...i,...r})}get(t){return this.actions.get(t)??{}}},$=Ss;function Ms(e){return async(t,r)=>{let i=r?.blockIds??e.blockIds;if(e.providerInitializationResult==null)return e.debug&&console.warn("[Generate] No provider initialization result found for quick action. Returning abortion status."),{status:"aborted"};let n=e.providerInitializationResult?.provider.input?.quickActions?.supported?.[e.quickAction.id];if(n==null)throw new Error("[Generate] Quick action input mapping failed. Ensure the provider supports this quick action.");let a=typeof n=="object"&&n!==null&&"mapInput"in n?n.mapInput:c=>c;e.close();let o=new AbortController,s=AbortSignal.any([e.abortSignal,o.signal].filter(ye)),u=new wt(e.cesdk.engine,Qt),l=e.lock??!0?As({engine:e.cesdk.engine,editModeToLockTo:ne,blockIdsToLock:i}):()=>{};i.forEach(c=>{$.get().register(c,{onCancelGeneration:()=>{o.abort(Ht),l(),e.cesdk.engine.block.isValid(c)&&(e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Ready"}),u.clear(c))}})}),i?.forEach(c=>{u.set(c,{status:"processing",quickActionId:e.quickAction.id})}),i.forEach(c=>{e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Pending",progress:0})});try{let c=await e.providerInitializationResult.generate(a(t),{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:s}),d=c.status;switch(d){case"success":{let{applyCallbacks:p}=await Is(c,{kind:e.providerInitializationResult.provider.kind,blockIds:i,cesdk:e.cesdk,abortSignal:s});if(i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&e.cesdk.engine.block.setState(g,{type:"Ready"})}),e.confirmation){i.forEach(h=>{u.set(h,{status:"confirmation",quickActionId:e.quickAction.id})});let g={...p,onApply:async()=>{p.onApply(),l()},onCancel:()=>{p.onCancel(),l()}};i.forEach(h=>{$.get().register(h,{applyCallbacks:g})})}else i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&u.clear(g)}),p.onApply(),l();return c}case"aborted":return e.debug&&console.log("Generation was aborted"),l(),i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&u.clear(p)}),c;case"error":return l(),i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&u.clear(p)}),console.error(`[Generate]: ${c.message}`),c;default:throw new Error(`[Generate] Unknown result status ${d}.`)}}catch(c){throw e.cesdk.ui.showNotification({type:"error",message:"A technical issue has occurred."}),l(),i.forEach(d=>{e.cesdk.engine.block.isValid(d)&&u.clear(d)}),c}finally{i.forEach(c=>{e.cesdk.engine.block.isValid(c)&&e.cesdk.engine.block.setState(c,{type:"Ready"})})}}}var vt=Ms;function Es(e){let t=`ly.img.ai.${e.kind}}`;e.cesdk.i18n.setTranslations({en:{[`${t}.quickActionMenu.providerSelect.label`]:"Provider"}});let r=i=>{if(i.engine.editor.getEditMode()===ne)return;let n=i.engine.block.findAllSelected();if(n.length===0)return;let{payload:a}=i,o=hs({kind:e.kind,cesdk:e.cesdk,payload:a,defaultOrder:e.defaultOrder})??[];if(o.length===0)return;let s=Ls(o).filter(m=>{if(m==="ly.img.separator")return!0;let f=m.scopes;if(f!=null&&f.length>0&&!n.every(k=>f.every(C=>e.engine.block.isAllowedByScope(k,C))))return!1;if(m.enable!=null){if(typeof m.enable=="function")return m.enable({engine:e.engine});if(typeof m.enable=="boolean")return m.enable}return!0}),u=[],l=e.providerInitializationResults.reduce((m,f)=>{if(f.provider.kind!==e.kind)return m;let k=s.map(C=>{if(C==="ly.img.separator")return C;if(f.provider.input?.quickActions?.supported?.[C.id]!=null)return{definition:C};{let Y=Tt.get().getAll().filter(M=>M.provider.kind!==e.kind&&M.provider.id!==f.provider.id).find(M=>M.provider.input?.quickActions?.supported?.[C.id]!=null);if(Y!=null){let M={definition:C,providerInitializationResult:Y};return u.push(M),M}else return}}).filter(ye);return k=ps(k),k.length===0||k.every(C=>C==="ly.img.separator")||k.every(C=>C==="ly.img.separator"||C.providerInitializationResult!=null)||m.push({providerInitializationResult:f,quickActions:k}),m},[]);if(l.length===0)if(u.length>0){let m=new Map;u.forEach(k=>{let C=k.definition.id;m.has(C)||m.set(C,k)});let f=Array.from(m.values());l.push({providerInitializationResult:f[0].providerInitializationResult??e.providerInitializationResults[0],quickActions:f})}else return;let c=l.map(({providerInitializationResult:m})=>({id:m.provider.id,label:m.provider.name??m.provider.id})),d=i.experimental.global(`${t}.currentProvider`,c[0]),p=l.find(({providerInitializationResult:{provider:{id:m}}})=>m===d.value?.id),g=n.every(m=>i.engine.block.getState(m).type==="Ready"),{builder:h,experimental:v,state:b}=i,y=b(`${t}.isGenerating`,!1),A=b(`${t}.toggleExpandedState`,void 0),w=async(m,f,k)=>{y.setValue(!0);try{return await k(m,f)}finally{y.setValue(!1)}};v.builder.Popover(`${t}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!g,isLoading:y.value,trailingIcon:null,children:({close:m})=>{h.Section(`${t}.popover.section`,{children:()=>{if(A.value!==void 0){let f=p?.quickActions.find(k=>k!=="ly.img.separator"&&k.definition.id===A.value);return f!=null&&f.definition.render!=null?f.definition.render({...i,toggleExpand:()=>{A.setValue(void 0)},isExpanded:!0,generate:vt({blockIds:n,providerInitializationResult:f.providerInitializationResult??p?.providerInitializationResult,quickAction:f.definition,middlewares:[w],confirmation:f.definition.defaults?.confirmation??!0,close:m,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:m,providerId:d.value.id}):void 0}A.value==null&&c.length>1&&(h.Select(`${t}.providerSelect.select`,{inputLabel:`${t}.quickActionMenu.providerSelect.label`,values:c,...d}),h.Separator(`${t}.providerSelect.separator`)),v.builder.Menu(`${t}.menu`,{children:()=>{p?.quickActions.forEach(f=>{if(f==="ly.img.separator"){h.Separator(`${t}.separator.${Math.random().toString()}`);return}f.definition.render!=null&&f.definition.render({...i,toggleExpand:()=>{A.setValue(f.definition.id)},isExpanded:!1,generate:vt({blockIds:n,providerInitializationResult:f.providerInitializationResult??p?.providerInitializationResult,quickAction:f.definition,middlewares:[w],confirmation:f.definition.defaults?.confirmation??!0,close:m,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:m,providerId:d.value.id})})}})}})}})};return Promise.resolve(r)}function Ls(e){return e.map(t=>t==="ly.img.separator"?t:Ue.get().getBy({id:t,type:"quick"})[0]).filter(ye)}var Ts=Es;async function js(e){let t=await Ts({kind:e.kind,providerInitializationResults:e.providerInitializationResults,cesdk:e.cesdk,engine:e.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:e.defaultOrder}),r=await cs({kind:e.kind,cesdk:e.cesdk});return{renderFunction:i=>{let{engine:n}=i;if(n.editor.getEditMode()===ne){let a=i.engine.block.findAllSelected();r({...i,payload:{...i.payload??{},applyCallbacks:{onBefore:()=>{a.forEach(o=>{$.get().get(o).applyCallbacks?.onBefore?.()})},onAfter:()=>{a.forEach(o=>{$.get().get(o).applyCallbacks?.onAfter?.()})},onCancel:()=>{a.forEach(o=>{$.get().get(o).applyCallbacks?.onCancel?.()})},onApply:()=>{a.forEach(o=>{$.get().get(o).applyCallbacks?.onApply?.()})}},onCancelGeneration:()=>{a.forEach(o=>{$.get().get(o).onCancelGeneration?.()})}}});return}t(i)}}}var Yt=js;var _s=typeof global=="object"&&global&&global.Object===Object&&global,cr=_s,$s=typeof self=="object"&&self&&self.Object===Object&&self,Ns=cr||$s||Function("return this")(),L=Ns,Ds=L.Symbol,G=Ds,dr=Object.prototype,Ps=dr.hasOwnProperty,Os=dr.toString,oe=G?G.toStringTag:void 0;function Rs(e){var t=Ps.call(e,oe),r=e[oe];try{e[oe]=void 0;var i=!0}catch{}var n=Os.call(e);return i&&(t?e[oe]=r:delete e[oe]),n}var zs=Rs,Fs=Object.prototype,Us=Fs.toString;function Vs(e){return Us.call(e)}var Bs=Vs,Gs="[object Null]",Hs="[object Undefined]",Kt=G?G.toStringTag:void 0;function qs(e){return e==null?e===void 0?Hs:Gs:Kt&&Kt in Object(e)?zs(e):Bs(e)}var ue=qs;function Qs(e){return e!=null&&typeof e=="object"}var Xe=Qs,md=Array.isArray;function Zs(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var pr=Zs,Ys="[object AsyncFunction]",Ks="[object Function]",Ws="[object GeneratorFunction]",Xs="[object Proxy]";function Js(e){if(!pr(e))return!1;var t=ue(e);return t==Ks||t==Ws||t==Ys||t==Xs}var el=Js,tl=L["__core-js_shared__"],He=tl,Wt=function(){var e=/[^.]+$/.exec(He&&He.keys&&He.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function rl(e){return!!Wt&&Wt in e}var il=rl,nl=Function.prototype,ol=nl.toString;function al(e){if(e!=null){try{return ol.call(e)}catch{}try{return e+""}catch{}}return""}var D=al,sl=/[\\^$.*+?()[\]{}|]/g,ll=/^\[object .+?Constructor\]$/,ul=Function.prototype,cl=Object.prototype,dl=ul.toString,pl=cl.hasOwnProperty,gl=RegExp("^"+dl.call(pl).replace(sl,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function fl(e){if(!pr(e)||il(e))return!1;var t=el(e)?gl:ll;return t.test(D(e))}var ml=fl;function hl(e,t){return e?.[t]}var yl=hl;function bl(e,t){var r=yl(e,t);return ml(r)?r:void 0}var H=bl,vl=H(L,"WeakMap"),Qe=vl;function wl(e,t){return e===t||e!==e&&t!==t}var kl=wl,xl=9007199254740991;function Il(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=xl}var Cl=Il;var hd=Object.prototype;var Al="[object Arguments]";function Sl(e){return Xe(e)&&ue(e)==Al}var Xt=Sl,gr=Object.prototype,Ml=gr.hasOwnProperty,El=gr.propertyIsEnumerable,yd=Xt(function(){return arguments}())?Xt:function(e){return Xe(e)&&Ml.call(e,"callee")&&!El.call(e,"callee")};var fr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Jt=fr&&typeof module=="object"&&module&&!module.nodeType&&module,Ll=Jt&&Jt.exports===fr,er=Ll?L.Buffer:void 0,bd=er?er.isBuffer:void 0;var Tl="[object Arguments]",jl="[object Array]",_l="[object Boolean]",$l="[object Date]",Nl="[object Error]",Dl="[object Function]",Pl="[object Map]",Ol="[object Number]",Rl="[object Object]",zl="[object RegExp]",Fl="[object Set]",Ul="[object String]",Vl="[object WeakMap]",Bl="[object ArrayBuffer]",Gl="[object DataView]",Hl="[object Float32Array]",ql="[object Float64Array]",Ql="[object Int8Array]",Zl="[object Int16Array]",Yl="[object Int32Array]",Kl="[object Uint8Array]",Wl="[object Uint8ClampedArray]",Xl="[object Uint16Array]",Jl="[object Uint32Array]",I={};I[Hl]=I[ql]=I[Ql]=I[Zl]=I[Yl]=I[Kl]=I[Wl]=I[Xl]=I[Jl]=!0;I[Tl]=I[jl]=I[Bl]=I[_l]=I[Gl]=I[$l]=I[Nl]=I[Dl]=I[Pl]=I[Ol]=I[Rl]=I[zl]=I[Fl]=I[Ul]=I[Vl]=!1;function eu(e){return Xe(e)&&Cl(e.length)&&!!I[ue(e)]}var tu=eu;function ru(e){return function(t){return e(t)}}var iu=ru,mr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ae=mr&&typeof module=="object"&&module&&!module.nodeType&&module,nu=ae&&ae.exports===mr,qe=nu&&cr.process,ou=function(){try{var e=ae&&ae.require&&ae.require("util").types;return e||qe&&qe.binding&&qe.binding("util")}catch{}}(),tr=ou,rr=tr&&tr.isTypedArray,vd=rr?iu(rr):tu;var au=Object.prototype,wd=au.hasOwnProperty;function su(e,t){return function(r){return e(t(r))}}var lu=su,kd=lu(Object.keys,Object);var uu=Object.prototype,xd=uu.hasOwnProperty;var cu=H(Object,"create"),se=cu;function du(){this.__data__=se?se(null):{},this.size=0}var pu=du;function gu(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var fu=gu,mu="__lodash_hash_undefined__",hu=Object.prototype,yu=hu.hasOwnProperty;function bu(e){var t=this.__data__;if(se){var r=t[e];return r===mu?void 0:r}return yu.call(t,e)?t[e]:void 0}var vu=bu,wu=Object.prototype,ku=wu.hasOwnProperty;function xu(e){var t=this.__data__;return se?t[e]!==void 0:ku.call(t,e)}var Iu=xu,Cu="__lodash_hash_undefined__";function Au(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=se&&t===void 0?Cu:t,this}var Su=Au;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=pu;q.prototype.delete=fu;q.prototype.get=vu;q.prototype.has=Iu;q.prototype.set=Su;var ir=q;function Mu(){this.__data__=[],this.size=0}var Eu=Mu;function Lu(e,t){for(var r=e.length;r--;)if(kl(e[r][0],t))return r;return-1}var be=Lu,Tu=Array.prototype,ju=Tu.splice;function _u(e){var t=this.__data__,r=be(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():ju.call(t,r,1),--this.size,!0}var $u=_u;function Nu(e){var t=this.__data__,r=be(t,e);return r<0?void 0:t[r][1]}var Du=Nu;function Pu(e){return be(this.__data__,e)>-1}var Ou=Pu;function Ru(e,t){var r=this.__data__,i=be(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var zu=Ru;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=Eu;Q.prototype.delete=$u;Q.prototype.get=Du;Q.prototype.has=Ou;Q.prototype.set=zu;var ve=Q,Fu=H(L,"Map"),le=Fu;function Uu(){this.size=0,this.__data__={hash:new ir,map:new(le||ve),string:new ir}}var Vu=Uu;function Bu(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Gu=Bu;function Hu(e,t){var r=e.__data__;return Gu(t)?r[typeof t=="string"?"string":"hash"]:r.map}var we=Hu;function qu(e){var t=we(this,e).delete(e);return this.size-=t?1:0,t}var Qu=qu;function Zu(e){return we(this,e).get(e)}var Yu=Zu;function Ku(e){return we(this,e).has(e)}var Wu=Ku;function Xu(e,t){var r=we(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Ju=Xu;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=Vu;Z.prototype.delete=Qu;Z.prototype.get=Yu;Z.prototype.has=Wu;Z.prototype.set=Ju;var hr=Z;function ec(){this.__data__=new ve,this.size=0}var tc=ec;function rc(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var ic=rc;function nc(e){return this.__data__.get(e)}var oc=nc;function ac(e){return this.__data__.has(e)}var sc=ac,lc=200;function uc(e,t){var r=this.__data__;if(r instanceof ve){var i=r.__data__;if(!le||i.length<lc-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new hr(i)}return r.set(e,t),this.size=r.size,this}var cc=uc;function ce(e){var t=this.__data__=new ve(e);this.size=t.size}ce.prototype.clear=tc;ce.prototype.delete=ic;ce.prototype.get=oc;ce.prototype.has=sc;ce.prototype.set=cc;var dc=Object.prototype,Id=dc.propertyIsEnumerable;var pc=H(L,"DataView"),Ze=pc,gc=H(L,"Promise"),Ye=gc,fc=H(L,"Set"),Ke=fc,nr="[object Map]",mc="[object Object]",or="[object Promise]",ar="[object Set]",sr="[object WeakMap]",lr="[object DataView]",hc=D(Ze),yc=D(le),bc=D(Ye),vc=D(Ke),wc=D(Qe),B=ue;(Ze&&B(new Ze(new ArrayBuffer(1)))!=lr||le&&B(new le)!=nr||Ye&&B(Ye.resolve())!=or||Ke&&B(new Ke)!=ar||Qe&&B(new Qe)!=sr)&&(B=function(e){var t=ue(e),r=t==mc?e.constructor:void 0,i=r?D(r):"";if(i)switch(i){case hc:return lr;case yc:return nr;case bc:return or;case vc:return ar;case wc:return sr}return t});var Cd=L.Uint8Array;var kc="__lodash_hash_undefined__";function xc(e){return this.__data__.set(e,kc),this}var Ic=xc;function Cc(e){return this.__data__.has(e)}var Ac=Cc;function We(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new hr;++t<r;)this.add(e[t])}We.prototype.add=We.prototype.push=Ic;We.prototype.has=Ac;var ur=G?G.prototype:void 0,Ad=ur?ur.valueOf:void 0;var Sc=Object.prototype,Sd=Sc.hasOwnProperty;var Mc=Object.prototype,Md=Mc.hasOwnProperty;var Ed=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Ld=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Td=new RegExp(/[A-Fa-f0-9]{2}/,"g");function Ec(e){return e==null?[]:Array.isArray(e)?e:[e]}var yr=Ec;function Lc(e){return`
143
+ You are an AI writing assistant tasked with improving a given text based on a specific type of improvement requested. Your goal is to enhance the text while maintaining its original meaning and intent.
144
+
145
+ Here is the original text you will be working with:
146
+
147
+ <original_text>
148
+ ${e}
149
+ </original_text>
150
+
151
+ Please follow these steps to improve the text:
152
+
153
+ 1. Carefully read and analyze the original text.
154
+ 2. Consider the specific improvement type requested and how it applies to the given text.
155
+ 3. Make the necessary changes to improve the text according to the requested improvement type. This may include:
156
+ - Rephrasing sentences
157
+ - Adjusting vocabulary
158
+ - Restructuring paragraphs
159
+ - Adding or removing content as appropriate
160
+ 4. Ensure that the improved version maintains the original meaning and intent of the text.
161
+ 5. Return the improved text without any additional commentary or explanation.
162
+ 6. If there is nothing to improve, simply return the original text without any changes.
163
+ 7. If you cannot make any meaningful improvements, return the original text as is.
164
+
165
+ Once you have made the improvements, only return the improved text and nothing else.
166
+ `}var br=Lc;var wr="improve",vr=`ly.img.${wr}`,ke=`ly.img.ai.quickAction.text.${wr}`,Tc=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${ke}.label`]:"Improve Writing"}}),{id:vr,type:"quick",kind:"text",scopes:["text/edit"],label:`${ke}.label`,description:`${ke}.label`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a})=>{r.Button(`${vr}.button`,{label:`${ke}.label`,icon:"@imgly/Sparkle",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=n.block.findAllSelected(),s=n.block.getString(o,"text/text");await i({prompt:br(s)}),a()}catch(o){console.error("Generation error:",o),e.ui.showNotification({type:"error",message:o.message||"Failed to improve text. Please try again.",duration:"medium"})}}})}}),kr=Tc;function jc(e){return`
167
+ You are tasked with fixing spelling and grammar errors in a given text. Your goal is to improve the text while maintaining its original meaning and style. Here is the text you need to correct:
168
+
169
+ <original_text>
170
+ ${e}
171
+ </original_text>
172
+
173
+ Please follow these steps to complete the task:
174
+
175
+ 1. Carefully read through the text and identify any spelling or grammatical errors.
176
+
177
+ 2. Correct all spelling mistakes, including typos and incorrectly spelled words.
178
+
179
+ 3. Fix grammatical errors, including:
180
+ - Incorrect verb tenses
181
+ - Subject-verb agreement issues
182
+ - Improper use of articles (a, an, the)
183
+ - Incorrect word usage
184
+ - Run-on sentences or sentence fragments
185
+ - Punctuation errors
186
+
187
+ 4. Ensure proper capitalization, especially at the beginning of sentences and for proper nouns.
188
+
189
+ 5. Maintain the original meaning and tone of the text. Do not add or remove information, or change the author's intended message.
190
+
191
+ 6. Make sure the corrected text flows naturally and is easy to read.
192
+
193
+ After making the necessary corrections, please provide only the improved output and nothing else.
194
+
195
+ Remember to preserve the original structure and formatting of the text as much as possible while making your corrections.
196
+ `}var xr=jc;var Cr="fix",Ir=`ly.img.${Cr}`,xe=`ly.img.ai.quickAction.text.${Cr}`,_c=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${xe}.label`]:"Fix Spelling & Grammar"}}),{id:Ir,type:"quick",kind:"text",scopes:["text/edit"],label:`${xe}.label`,description:`${xe}.label`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a})=>{r.Button(`${Ir}.button`,{label:`${xe}.label`,icon:"@imgly/CheckmarkAll",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=n.block.findAllSelected(),s=n.block.getString(o,"text/text");await i({prompt:xr(s)}),a()}catch(o){console.error("Generation error:",o),e.ui.showNotification({type:"error",message:o.message||"Failed to fix text. Please try again.",duration:"medium"})}}})}}),Ar=_c;function $c(e){return`
197
+ You will be given a text to shorten. Your task is to reduce the length of the text by 30% to 50% while maintaining its original voice, perspective, and key information. This is not a summary - you should preserve the style and tone of the original text.
198
+
199
+ Here is the original text:
200
+
201
+ <original_text>
202
+ ${e}
203
+ </original_text>
204
+
205
+ To complete this task, follow these steps:
206
+
207
+ 1. Carefully read and analyze the text, paying attention to its style, tone, and main points.
208
+
209
+ 2. Identify areas where the text can be condensed without losing essential information or altering the author's voice.
210
+
211
+ 3. Begin shortening the text by:
212
+ - Removing redundant or repetitive information
213
+ - Simplifying complex sentences
214
+ - Eliminating unnecessary examples or elaborations
215
+ - Combining related ideas into more concise statements
216
+
217
+ 4. As you shorten, continuously check that you are:
218
+ - Maintaining the original voice and perspective
219
+ - Keeping all crucial information
220
+ - Preserving the flow and coherence of the text
221
+
222
+ 5. Aim to reduce the length by 30% to 50% of the original. If you find yourself shortening less than 30%, look for additional opportunities to condense. If you're reducing more than 50%, ensure you haven't cut too much important content.
223
+
224
+ 6. Once you've finished shortening, review the text to ensure it still reads smoothly and retains the essence of the original.
225
+
226
+ Provide only the shortened version of the text in your response, without any additional comments, tags or explanations.
227
+ `}var Sr=$c;var Er="shorter",Mr=`ly.img.${Er}`,Ie=`ly.img.ai.quickAction.text.${Er}`,Nc=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Ie}.label`]:"Make Shorter"}}),{id:Mr,type:"quick",kind:"text",scopes:["text/edit"],label:`${Ie}.label`,description:`${Ie}.label`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a})=>{r.Button(`${Mr}.button`,{label:`${Ie}.label`,icon:"@imgly/TextShorter",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=n.block.findAllSelected(),s=n.block.getString(o,"text/text");await i({prompt:Sr(s)}),a()}catch(o){console.error("Generation error:",o),e.ui.showNotification({type:"error",message:o.message||"Failed to make text shorter. Please try again.",duration:"medium"})}}})}}),Lr=Nc;function Dc(e){return`
228
+ You are tasked with expanding a given text to make it longer. Here's how to proceed:
229
+
230
+ First, you will be provided with the original text:
231
+
232
+ <original_text>
233
+ ${e}
234
+ </original_text>
235
+
236
+ To expand the text:
237
+
238
+ 1. Analyze the original text to understand its main ideas, tone, and style.
239
+ 2. Identify areas where you can add more detail, examples, or explanations.
240
+ 3. Expand on these areas by:
241
+ - Providing more context or background information
242
+ - Adding relevant examples or anecdotes
243
+ - Elaborating on key points
244
+ - Introducing related concepts or ideas
245
+ - Explaining implications or consequences of the main ideas
246
+ 4. Ensure that the expanded text length is not exceeding the original text by more than 50%.
247
+ 5. Always expand the text, even if it is a single word. Explain the word with a few short sentences in that case. If the text is empty, make up a short sentence.
248
+
249
+ Guidelines:
250
+
251
+ - Maintain the original tone and style of the text.
252
+ - Ensure all additions are relevant to the main topic.
253
+ - Keep the flow of the text natural and coherent.
254
+ - Do not contradict any information in the original text.
255
+
256
+ Only return the longer text and nothing else.
257
+
258
+ Make sure to only return the expanded text and nothing else. Do not include any additional information or comments in your response about what you have done.
259
+
260
+ Do not add the original text or the original_text tags to the response.
261
+ `}var Tr=Dc;var _r="longer",jr=`ly.img.${_r}`,Ce=`ly.img.ai.quickAction.text.${_r}`,Pc=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Ce}.label`]:"Make Longer"}}),{id:jr,type:"quick",kind:"text",scopes:["text/edit"],label:`${Ce}.label`,description:`${Ce}.label`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a})=>{r.Button(`${jr}.button`,{label:`${Ce}.label`,icon:"@imgly/TextLonger",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=n.block.findAllSelected(),s=n.block.getString(o,"text/text");await i({prompt:Tr(s)}),a()}catch(o){console.error("Generation error:",o),e.ui.showNotification({type:"error",message:o.message||"Failed to make text longer. Please try again.",duration:"medium"})}}})}}),$r=Pc;function Oc(e,t){return`
262
+ You will be given a piece of text and a desired tone. Your task is to rewrite the text to match the desired tone while preserving the original meaning and key information. Here's how to proceed:
263
+
264
+ First, you will be provided with the original text:
265
+ <original_text>
266
+ ${e}
267
+ </original_text>
268
+
269
+ The desired tone for the rewritten text is:
270
+ <desired_tone>
271
+ ${t}
272
+ </desired_tone>
273
+
274
+ To change the tone of the text:
275
+ 1. Analyze the current tone and style of the original text.
276
+ 2. Identify the key information and main ideas in the original text.
277
+ 3. Consider the characteristics of the desired tone (e.g., formal, casual, humorous, professional, etc.).
278
+ 4. Rewrite the text, adapting the language, vocabulary, and sentence structure to match the desired tone while maintaining the original meaning and key information.
279
+ 5. Ensure that the rewritten text flows naturally and coherently.
280
+ 6. Only return the rewritten text without any additional commentary, tags or explanation.
281
+
282
+ Now, rewrite the text to match the desired tone. Your response should contain only the rewritten text, without any additional explanations or comments. Do not use any tags in your response.
283
+ `}var Nr=Oc;var Dr="changeTone",de=`ly.img.${Dr}`,S=`ly.img.ai.quickAction.text.${Dr}`,Rc=[{id:"professional",label:`${S}.type.professional`},{id:"casual",label:`${S}.type.casual`},{id:"friendly",label:`${S}.type.friendly`},{id:"serious",label:`${S}.type.serious`},{id:"humorous",label:`${S}.type.humorous`},{id:"optimistic",label:`${S}.type.optimistic`}],zc=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${S}.label`]:"Change Tone",[`${S}.type.professional`]:"Professional",[`${S}.type.casual`]:"Casual",[`${S}.type.friendly`]:"Friendly",[`${S}.type.serious`]:"Serious",[`${S}.type.humorous`]:"Humorous",[`${S}.type.optimistic`]:"Optimistic"}}),{id:de,type:"quick",kind:"text",scopes:["text/edit"],label:`${S}.label`,description:`${S}.label`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,experimental:o})=>{o.builder.Popover(`${de}.popover`,{label:`${S}.label`,icon:"@imgly/Microphone",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{r.Section(`${de}.popover.section`,{children:()=>{o.builder.Menu(`${de}.popover.menu`,{children:()=>{Rc.forEach(s=>{r.Button(`${de}.popover.menu.${s.id}`,{label:s.label,labelAlignment:"left",variant:"plain",onClick:async()=>{try{a();let[u]=n.block.findAllSelected(),l=n.block.getString(u,"text/text");await i({prompt:Nr(l,s.id),type:s.id})}catch(u){console.error("Generation error:",u),e.ui.showNotification({type:"error",message:u.message||"Failed to change tone. Please try again.",duration:"medium"})}}})})}})}})}})}}),Pr=zc;var Ae={en_US:"English (US)",en_UK:"English (UK)",es:"Spanish",fr:"French",de:"German",pt:"Portuguese",it:"Italian",ru:"Russian",zh:"Mandarin Chinese",ja:"Japanese"},Or=Object.keys(Ae);function Fc(e,t){let r=Ae[t]||t;return`
284
+ You are a translation AI. Your task is to translate the given text into the specified target language. Follow these steps:
285
+
286
+ 1. Here is the source text to be translated:
287
+ <source_text>
288
+ ${e}
289
+ </source_text>
290
+
291
+ 2. The target language for translation is:
292
+ <target_language>
293
+ ${r}
294
+ </target_language>
295
+
296
+ 3. Translate the source text into the target language. Ensure that you maintain the original meaning, tone, and style as closely as possible while adapting to the linguistic and cultural norms of the target language.
297
+
298
+ 4. Return only the translated text, without any additional comments, explanations, or metadata. Do not include the original text or any other information in your response.
299
+ `}var Rr=Fc;var zr="translate",pe=`ly.img.${zr}`,Se=`ly.img.ai.quickAction.text.${zr}`,Uc=Or.map(e=>({id:e,label:Ae[e]})),Vc=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${Se}.label`]:"Translate"}}),{id:pe,type:"quick",kind:"text",scopes:["text/edit"],label:`${Se}.label`,description:`${Se}.label`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,experimental:o})=>{o.builder.Popover(`${pe}.popover`,{label:`${Se}.label`,icon:"@imgly/Language",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{r.Section(`${pe}.popover.section`,{children:()=>{o.builder.Menu(`${pe}.popover.menu`,{children:()=>{Uc.forEach(s=>{r.Button(`${pe}.popover.menu.${s.id}`,{label:s.label,labelAlignment:"left",variant:"plain",onClick:async()=>{try{a();let[u]=n.block.findAllSelected(),l=n.block.getString(u,"text/text");await i({prompt:Rr(l,s.id),language:s.id})}catch(u){console.error("Generation error:",u),e.ui.showNotification({type:"error",message:u.message||"Failed to translate text. Please try again.",duration:"medium"})}}})})}})}})}})}}),Fr=Vc;function Bc(e,t){return`
300
+ You will be given an original text and a custom prompt addition that specifies how to change the text. Your task is to modify the original text according to the prompt and return only the new, modified text.
301
+
302
+ Here is the original text:
303
+ <original_text>
304
+ ${e}
305
+ </original_text>
306
+
307
+ The custom prompt addition is:
308
+ <change_text_to>
309
+ ${t}
310
+ </change_text_to>
311
+
312
+ Please modify the original text according to the "Change Text to..." prompt. Only return the new, modified text without any additional commentary or explanation. Your entire response should be the modified text itself, with no other content.
313
+ `}var Ur=Bc;var Vr="changeTextTo",j=`ly.img.${Vr}`,_=`ly.img.ai.quickAction.text.${Vr}`,Gc=({cesdk:e})=>(e.i18n.setTranslations({en:{[`${_}.label`]:"Change Text to...",[`${_}.prompt.label`]:"Change Text to...",[`${_}.prompt.placeholder`]:'e.g. "a list of bullet points", "a formal announcement"'}}),{id:j,type:"quick",kind:"text",scopes:["text/edit"],label:`${_}.label`,description:`${_}.label`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,experimental:i,isExpanded:n,toggleExpand:a,generate:o,engine:s,state:u,close:l})=>{if(n){let c=u(`${j}.prompt`,"");r.TextArea(`${j}.prompt`,{inputLabel:`${_}.prompt.label`,placeholder:`${_}.prompt.placeholder`,...c}),r.Separator(`${j}.separator`),i.builder.ButtonRow(`${j}.footer`,{justifyContent:"space-between",children:()=>{r.Button(`${j}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:a}),r.Button(`${j}.footer.apply`,{label:"common.apply",icon:"@imgly/MagicWand",color:"accent",isDisabled:c.value.length===0,onClick:async()=>{try{let d=c.value;if(!d)return;let[p]=s.block.findAllSelected(),g=s.block.getString(p,"text/text");await o({prompt:Ur(g,d),customPrompt:d}),a(),l()}catch(d){console.error("Generation error:",d),e.ui.showNotification({type:"error",message:d.message||"Failed to change text. Please try again.",duration:"medium"})}}})}})}else r.Button(`${j}.button`,{label:`${_}.label`,icon:"@imgly/MagicWand",labelAlignment:"left",variant:"plain",onClick:a})}}),Br=Gc;var ge="@imgly/plugin-ai-text-generation-web",Me=["ly.img.improve","ly.img.fix","ly.img.shorter","ly.img.longer","ly.img.separator","ly.img.changeTone","ly.img.translate","ly.img.separator","ly.img.changeTextTo"];function Hc(e){return{async initialize({cesdk:t}){if(t==null)return;Nt(t,ge,"0.2.1"),t.ui.addIconSet(tt,rt),t.i18n.setTranslations({en:{"common.apply":"Apply","common.back":"Back"}}),qc(e);let r=Ue.get();r.register(kr({cesdk:t})),r.register(Ar({cesdk:t})),r.register(Lr({cesdk:t})),r.register($r({cesdk:t})),r.register(Pr({cesdk:t})),r.register(Fr({cesdk:t})),r.register(Br({cesdk:t}));let i=e.providers?.text2text??e.provider,n=await Promise.all(yr(i).map(u=>u({cesdk:t})));if(!(n.length>0))return;let o=await qt("text",{fromText:n,fromImage:[]},{cesdk:t},e),s=await Yt({kind:"text",providerInitializationResults:o.providerInitializationResults,cesdk:t,engine:t.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:Me});s.renderFunction!=null&&(t.ui.registerComponent("ly.img.ai.text.canvasMenu",s.renderFunction),t.ui.setCanvasMenuOrder(["ly.img.ai.text.canvasMenu"],{editMode:ne}))}}}function qc(e){e.debug&&e.providers?.text2text!=null&&e.provider!=null&&console.warn("[TextGeneration]: Both `providers.text2text` and `provider` configuration is provided. Since `provider` is deprecated, only `providers.text2text` will be used.")}var Gr=Hc;var Qc=e=>({name:ge,version:"0.2.1",...Gr(e)}),m1=Qc;export{Me as DEFAULT_TEXT_QUICK_ACTION_ORDER,m1 as default};
140
314
  /*! Bundled license information:
141
315
 
142
316
  @imgly/plugin-ai-generation-web/dist/index.mjs:
@@ -157,5 +331,20 @@ var me="@imgly/plugin-ai-text-generation",lt=`
157
331
  *)
158
332
  *)
159
333
  *)
334
+
335
+ @imgly/plugin-utils/dist/index.mjs:
336
+ (*! Bundled license information:
337
+
338
+ lodash-es/lodash.js:
339
+ (**
340
+ * @license
341
+ * Lodash (Custom Build) <https://lodash.com/>
342
+ * Build: `lodash modularize exports="es" -o ./`
343
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
344
+ * Released under MIT license <https://lodash.com/license>
345
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
346
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
347
+ *)
348
+ *)
160
349
  */
161
350
  //# sourceMappingURL=index.mjs.map