UNPKG

@imgly/plugin-ai-text-generation-web

Version:

AI text generation plugin for the CE.SDK editor

80 lines (76 loc) 123 kB
var ft="@imgly/plugin-ai-text-generation",li=` <svg> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/Sparkle" > <path d="M5.35545 2.06745C5.24149 1.72556 4.7579 1.72556 4.64394 2.06745L4.05898 3.82232C4.02166 3.93429 3.9338 4.02215 3.82184 4.05948L2.06694 4.64459C1.72506 4.75858 1.72509 5.24217 2.06699 5.3561L3.82179 5.9409C3.93378 5.97822 4.02166 6.06609 4.05899 6.17808L4.64394 7.93291C4.7579 8.2748 5.24149 8.2748 5.35545 7.93291L5.9404 6.17806C5.97773 6.06608 6.06559 5.97821 6.17757 5.94089L7.93242 5.35594C8.27431 5.24198 8.27431 4.75839 7.93242 4.64442L6.17757 4.05947C6.06559 4.02215 5.97773 3.93428 5.9404 3.8223L5.35545 2.06745Z" fill="currentColor"/> <path d="M17.9632 3.23614C17.8026 2.80788 17.1968 2.80788 17.0362 3.23614L16.0787 5.78951C16.0285 5.92337 15.9229 6.02899 15.789 6.07918L13.2356 7.0367C12.8074 7.19729 12.8074 7.80307 13.2356 7.96366L15.789 8.92118C15.9229 8.97138 16.0285 9.077 16.0787 9.21085L17.0362 11.7642C17.1968 12.1925 17.8026 12.1925 17.9632 11.7642L18.9207 9.21086C18.9709 9.077 19.0765 8.97138 19.2104 8.92118L21.7637 7.96366C22.192 7.80307 22.192 7.1973 21.7637 7.0367L19.2104 6.07918C19.0765 6.02899 18.9709 5.92337 18.9207 5.78951L17.9632 3.23614Z" fill="currentColor"/> <path d="M9.30058 7.82012C9.54712 7.1791 10.454 7.1791 10.7006 7.82012L12.3809 12.189C12.4571 12.3871 12.6136 12.5436 12.8117 12.6198L17.1806 14.3001C17.8216 14.5466 17.8216 15.4536 17.1806 15.7001L12.8117 17.3804C12.6136 17.4566 12.4571 17.6131 12.3809 17.8112L10.7006 22.1801C10.454 22.8211 9.54712 22.8211 9.30058 22.1801L7.62024 17.8112C7.54406 17.6131 7.38754 17.4566 7.18947 17.3804L2.82061 15.7001C2.17959 15.4536 2.17959 14.5466 2.82061 14.3001L7.18947 12.6198C7.38754 12.5436 7.54406 12.3871 7.62024 12.189L9.30058 7.82012Z" fill="currentColor"/> </symbol> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/Language" > <path fill-rule="evenodd" clip-rule="evenodd" d="M12.1188 12.8768L11.4719 14.6133L9.1 12.2414L5.35 15.9914L4.14309 14.7845L7.96452 11.0156C7.04982 9.98423 6.31561 8.84524 5.77623 7.64087L5.71314 7.5H7.42861L7.45649 7.55438C7.89377 8.40744 8.44158 9.21897 9.09989 9.96235C10.1004 8.82939 10.8479 7.5455 11.336 6.1925H3V4.5H8.25V3H9.95V4.5H15.2V6.2H12.976C12.4276 7.93841 11.5121 9.58156 10.2367 11.017L12.1188 12.8768Z" fill="currentColor"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M16.5371 11.0469L20.2764 21H18.2803L17.5324 18.7852H13.8155L13.0713 21H11.082L14.8008 11.0469H16.5371ZM14.314 17.3018H17.0316L15.6695 13.2679L14.314 17.3018Z" fill="currentColor"/> </symbol> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/Microphone" > <path d="M22.0009 8C22.0009 9.42939 21.5011 10.742 20.6667 11.7727C19.2294 10.8473 17.4614 9.56645 15.9479 8.053C14.4345 6.53955 13.1536 4.77155 12.2282 3.33426C13.2589 2.49984 14.5715 2 16.0009 2C19.3146 2 22.0009 4.68629 22.0009 8Z" fill="currentColor"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M10.0009 8C10.0009 6.67122 10.4329 5.44332 11.164 4.44907C12.1058 5.88166 13.3791 7.60552 14.8873 9.11366C16.3954 10.6218 18.1193 11.8951 19.5519 12.8369C18.5576 13.568 17.3297 14 16.0009 14C15.7709 14 15.5439 13.9871 15.3206 13.9619L11.9933 16.876C11.9983 16.9166 12.0009 16.958 12.0009 17V22C12.0009 22.5523 11.5532 23 11.0009 23C10.4486 23 10.0009 22.5523 10.0009 22V18.621L6.70661 21.5063C5.91426 22.2002 4.71947 22.1607 3.97468 21.4159L2.58384 20.0251C1.83905 19.2803 1.79955 18.0855 2.49353 17.2932L10.0388 8.67822C10.0138 8.4556 10.0009 8.2293 10.0009 8ZM10.7488 10.9032L3.99805 18.6109L5.38889 20.0017L13.0963 13.2513C12.1106 12.7049 11.2949 11.889 10.7488 10.9032Z" fill="currentColor"/> </symbol> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/TextLonger" > <path d="M21 3H3V5H21V3Z" fill="currentColor"/> <path d="M21 8H3V10H21V8Z" fill="currentColor"/> <path d="M3 13H21V15H3V13Z" fill="currentColor"/> <path d="M14 18H3V20H14V18Z" fill="currentColor"/ </symbol> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/TextShorter" > <path d="M21 8H3V10H21V8Z" fill="currentColor"/> <path d="M13 13H3V15H13V13Z" fill="currentColor"/> </symbol> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/CheckmarkAll" > <path d="M16.4052 6.84412L14.8434 5.59473L6.82422 15.6187L2.79961 12.6003L1.59961 14.2003L6.39961 17.8003C6.83171 18.1244 7.44307 18.0468 7.78048 17.625L16.4052 6.84412Z" fill="currentColor"/> <path d="M22.4052 6.84412L20.8434 5.59473L12.8242 15.6187L11.7996 14.8503L10.5996 16.4503L12.3996 17.8003C12.8317 18.1244 13.4431 18.0468 13.7805 17.625L22.4052 6.84412Z" fill="currentColor"/> </symbol> <symbol fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="@imgly/MagicWand" > <path d="M7.27597 1.94728C7.3681 1.76302 7.63105 1.76302 7.72318 1.94728L8.46231 3.42553C8.4865 3.47391 8.52573 3.51314 8.57411 3.53733L10.0524 4.27646C10.2366 4.36859 10.2366 4.63154 10.0524 4.72367L8.57411 5.4628C8.52573 5.48699 8.4865 5.52622 8.46231 5.5746L7.72318 7.05285C7.63105 7.23711 7.3681 7.23711 7.27597 7.05285L6.53685 5.57461C6.51266 5.52622 6.47342 5.48699 6.42503 5.4628L4.94681 4.72382C4.76254 4.63171 4.76252 4.36875 4.94677 4.27661L6.42505 3.53733C6.47343 3.51314 6.51265 3.47391 6.53684 3.42554L7.27597 1.94728Z" fill="currentColor"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M8.99943 9.0857C8.21838 9.86675 8.21838 11.1331 8.99943 11.9141L18.0854 21.0001C18.8665 21.7812 20.1329 21.7811 20.9139 21L22.4996 19.4141C23.2805 18.633 23.2805 17.3668 22.4995 16.5858L13.4136 7.49991C12.6326 6.71886 11.3663 6.71887 10.5852 7.49991L8.99943 9.0857ZM10.4136 10.4999L11.9994 8.91413L15.0427 11.9574L13.4569 13.5432L10.4136 10.4999Z" fill="currentColor"/> <path d="M4.72318 10.4473C4.63105 10.263 4.3681 10.263 4.27597 10.4473L3.70351 11.5922C3.67932 11.6406 3.64009 11.6798 3.59172 11.704L2.44677 12.2766C2.26252 12.3687 2.26254 12.6317 2.44681 12.7238L3.5917 13.2961C3.64009 13.3203 3.67932 13.3596 3.70352 13.4079L4.27597 14.5529C4.3681 14.7371 4.63105 14.7371 4.72318 14.5529L5.29564 13.4079C5.31983 13.3596 5.35906 13.3203 5.40745 13.2961L6.55236 12.7237C6.73663 12.6315 6.73662 12.3686 6.55236 12.2765L5.40745 11.704C5.35906 11.6798 5.31983 11.6406 5.29564 11.5922L4.72318 10.4473Z" fill="currentColor"/> <path d="M13.276 3.44728C13.3681 3.26302 13.6311 3.26302 13.7232 3.44728L13.9623 3.92553C13.9865 3.97391 14.0257 4.01314 14.0741 4.03733L14.5524 4.27646C14.7366 4.36859 14.7366 4.63154 14.5524 4.72367L14.0741 4.9628C14.0257 4.98699 13.9865 5.02622 13.9623 5.0746L13.7232 5.55285C13.6311 5.73711 13.3681 5.73711 13.276 5.55285L13.0368 5.07461C13.0127 5.02622 12.9734 4.98699 12.925 4.9628L12.4468 4.72373C12.2625 4.63161 12.2625 4.36866 12.4468 4.27652L12.9251 4.03733C12.9734 4.01314 13.0127 3.97391 13.0368 3.92554L13.276 3.44728Z" fill="currentColor"/> <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"/> </symbol> </svg> `,mt=li;var si=class{constructor(e,t,r){this.assetStoreName="assets",this.blobStoreName="blobs",this.db=null,this.id=e,this.engine=t,this.dbName=r?.dbName??`ly.img.assetSource/${e}`,this.dbVersion=r?.dbVersion??1}async initialize(){if(!this.db)return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,this.dbVersion);r.onerror=i=>{t(new Error(`Failed to open IndexedDB: ${i.target.error}`))},r.onupgradeneeded=i=>{let n=i.target.result;n.objectStoreNames.contains(this.assetStoreName)||n.createObjectStore(this.assetStoreName,{keyPath:"id"}),n.objectStoreNames.contains(this.blobStoreName)||n.createObjectStore(this.blobStoreName,{keyPath:"id"})},r.onsuccess=i=>{this.db=i.target.result,e()}})}close(){this.db&&(this.db.close(),this.db=null)}async findAssets(e){if(await this.initialize(),!this.db)throw new Error("Database not initialized");try{let t=(await this.getAllAssets("asc")).reduce((c,l)=>{let u=e.locale??"en",d="",p=[];l.label!=null&&typeof l.label=="object"&&l.label[u]&&(d=l.label[u]),l.tags!=null&&typeof l.tags=="object"&&l.tags[u]&&(p=l.tags[u]);let g={...l,label:d,tags:p};return this.filterAsset(g,e)&&c.push(g),c},[]);t=await this.restoreBlobUrls(t),t=this.sortAssets(t,e);let{page:r,perPage:i}=e,n=r*i,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;H(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.oncomplete=()=>{this.engine.asset.assetSourceContentsChanged(this.id)},t.onerror=()=>{console.error(`Failed to add asset: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async removeAsset(e){let t=await this.getAsset(e);return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.assetStoreName,"readwrite");r.objectStore(this.assetStoreName).delete(e),r.oncomplete=()=>{H(t,i=>{this.removeBlob(i)}),this.engine.asset.assetSourceContentsChanged(this.id)},r.onerror=()=>{console.error(`Failed to remove asset: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async removeBlob(e){return this.initialize().then(()=>{if(!this.db)throw new Error("Database not initialized");let t=this.db.transaction(this.blobStoreName,"readwrite");t.objectStore(this.blobStoreName).delete(e),t.onerror=()=>{console.error(`Failed to remove blob: ${t.error}`)}}).catch(t=>{console.error("Error initializing database:",t)})}async getAllAssets(e="desc"){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).getAll();i.onsuccess=()=>{let n=i.result;n.sort((a,o)=>{let s=a.meta?.insertedAt||a._insertedAt||Date.now(),c=o.meta?.insertedAt||o._insertedAt||Date.now();return e==="asc"?s-c:c-s}),t(n)},i.onerror=()=>{r(new Error(`Failed to get assets: ${i.error}`))}})}async getAsset(e){return new Promise((t,r)=>{let i=this.db.transaction(this.assetStoreName,"readonly").objectStore(this.assetStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async getBlob(e){return new Promise((t,r)=>{let i=this.db.transaction(this.blobStoreName,"readonly").objectStore(this.blobStoreName).get(e);i.onsuccess=()=>{t(i.result)},i.onerror=()=>{r(new Error(`Failed to get blob: ${i.error}`))}})}async createBlobUrlFromStore(e){let t=await this.getBlob(e);return t!=null?URL.createObjectURL(t.blob):e}async storeBlobUrls(e){let t={};return await Promise.all(e.map(async r=>{let i=await(await fetch(r)).blob();t[r]=i})),this.initialize().then(async()=>{if(!this.db)throw new Error("Database not initialized");let r=this.db.transaction(this.blobStoreName,"readwrite"),i=r.objectStore(this.blobStoreName);Object.entries(t).forEach(([n,a])=>{let o={id:n,blob:a};i.put(o)}),r.onerror=()=>{console.error(`Failed to add blobs: ${r.error}`)}}).catch(r=>{console.error("Error initializing database:",r)})}async restoreBlobUrls(e){let t={},r=new Set;return H(e,i=>{r.add(i)}),await Promise.all([...r].map(async i=>{let n=await this.createBlobUrlFromStore(i);t[i]=n})),H(e,i=>t[i]??i)}filterAsset(e,t){let{query:r,tags:i,groups:n,excludeGroups:a}=t;if(r&&r.trim()!==""){let o=r.trim().toLowerCase().split(" "),s=e.label?.toLowerCase()??"",c=e.tags?.map(l=>l.toLowerCase())??[];if(!o.every(l=>s.includes(l)||c.some(u=>u.includes(l))))return!1}if(i){let o=Array.isArray(i)?i:[i];if(o.length>0&&(!e.tags||!o.every(s=>e.tags?.includes(s))))return!1}return!(n&&n.length>0&&(!e.groups||!n.some(o=>e.groups?.includes(o)))||a&&a.length>0&&e.groups&&e.groups.some(o=>a.includes(o)))}sortAssets(e,t){let{sortingOrder:r,sortKey:i,sortActiveFirst:n}=t,a=[...e];return!r||r==="None"||(i?a.sort((o,s)=>{let c,l;return i==="id"?(c=o.id,l=s.id):(c=o.meta?.[i]??null,l=s.meta?.[i]??null),c==null?r==="Ascending"?-1:1:l==null?r==="Ascending"?1:-1:typeof c=="string"&&typeof l=="string"?r==="Ascending"?c.localeCompare(l):l.localeCompare(c):r==="Ascending"?c<l?-1:c>l?1:0:c>l?-1:c<l?1:0}):r==="Descending"&&a.reverse(),n&&a.sort((o,s)=>o.active&&!s.active?-1:!o.active&&s.active?1:0)),a}};function H(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]=H(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]=H(n,t,a)}return e}var ui=class{constructor(e,t,r){this.id=e,this.cesdk=t,this.assetSourceIds=r}async findAssets(e){try{let t=this.assetSourceIds.map(u=>this.cesdk.engine.asset.findAssets(u,{...e,perPage:9999,page:0})),r=await Promise.all(t),i=[];r.forEach(u=>{u?.assets&&(i=i.concat(u.assets))}),i.sort((u,d)=>{let p=u.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-p});let{page:n,perPage:a}=e,o=n*a,s=o+a,c=i.slice(o,s),l=s<i.length?n+1:void 0;return{assets:c,currentPage:n,nextPage:l,total:i.length}}catch(t){console.error("Error finding assets:",t);return}}async getGroups(){let e=this.assetSourceIds.map(i=>this.cesdk.engine.asset.getGroups(i)),t=await Promise.all(e),r=new Set;return t.forEach(i=>{i.forEach(n=>r.add(n))}),Array.from(r)}addAsset(e){throw new Error("AggregatedAssetSource does not support adding assets")}removeAsset(e){throw new Error("AggregatedAssetSource does not support removing assets")}},ci=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)}},Ft=ci,di=typeof global=="object"&&global&&global.Object===Object&&global,zt=di,pi=typeof self=="object"&&self&&self.Object===Object&&self,gi=zt||pi||Function("return this")(),N=gi,fi=N.Symbol,Q=fi,Ut=Object.prototype,mi=Ut.hasOwnProperty,hi=Ut.toString,ne=Q?Q.toStringTag:void 0;function yi(e){var t=mi.call(e,ne),r=e[ne];try{e[ne]=void 0;var i=!0}catch{}var n=hi.call(e);return i&&(t?e[ne]=r:delete e[ne]),n}var bi=yi,vi=Object.prototype,wi=vi.toString;function ki(e){return wi.call(e)}var xi=ki,Ii="[object Null]",Ai="[object Undefined]",ht=Q?Q.toStringTag:void 0;function Ci(e){return e==null?e===void 0?Ai:Ii:ht&&ht in Object(e)?bi(e):xi(e)}var pe=Ci;function Si(e){return e!=null&&typeof e=="object"}var tt=Si,Cd=Array.isArray;function $i(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Vt=$i,Ei="[object AsyncFunction]",Li="[object Function]",Ti="[object GeneratorFunction]",Mi="[object Proxy]";function _i(e){if(!Vt(e))return!1;var t=pe(e);return t==Li||t==Ti||t==Ei||t==Mi}var ji=_i,Pi=N["__core-js_shared__"],Be=Pi,yt=function(){var e=/[^.]+$/.exec(Be&&Be.keys&&Be.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Di(e){return!!yt&&yt in e}var Ni=Di,Oi=Function.prototype,Ri=Oi.toString;function Fi(e){if(e!=null){try{return Ri.call(e)}catch{}try{return e+""}catch{}}return""}var V=Fi,zi=/[\\^$.*+?()[\]{}|]/g,Ui=/^\[object .+?Constructor\]$/,Vi=Function.prototype,Bi=Object.prototype,Gi=Vi.toString,qi=Bi.hasOwnProperty,Hi=RegExp("^"+Gi.call(qi).replace(zi,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Qi(e){if(!Vt(e)||Ni(e))return!1;var t=ji(e)?Hi:Ui;return t.test(V(e))}var Zi=Qi;function Yi(e,t){return e?.[t]}var Ki=Yi;function Wi(e,t){var r=Ki(e,t);return Zi(r)?r:void 0}var Z=Wi,Xi=Z(N,"WeakMap"),Ze=Xi;function Ji(e,t){return e===t||e!==e&&t!==t}var en=Ji,tn=9007199254740991;function rn(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=tn}var nn=rn,Sd=Object.prototype,on="[object Arguments]";function an(e){return tt(e)&&pe(e)==on}var bt=an,Bt=Object.prototype,ln=Bt.hasOwnProperty,sn=Bt.propertyIsEnumerable,$d=bt(function(){return arguments}())?bt:function(e){return tt(e)&&ln.call(e,"callee")&&!sn.call(e,"callee")},Gt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,vt=Gt&&typeof module=="object"&&module&&!module.nodeType&&module,un=vt&&vt.exports===Gt,wt=un?N.Buffer:void 0,Ed=wt?wt.isBuffer:void 0,cn="[object Arguments]",dn="[object Array]",pn="[object Boolean]",gn="[object Date]",fn="[object Error]",mn="[object Function]",hn="[object Map]",yn="[object Number]",bn="[object Object]",vn="[object RegExp]",wn="[object Set]",kn="[object String]",xn="[object WeakMap]",In="[object ArrayBuffer]",An="[object DataView]",Cn="[object Float32Array]",Sn="[object Float64Array]",$n="[object Int8Array]",En="[object Int16Array]",Ln="[object Int32Array]",Tn="[object Uint8Array]",Mn="[object Uint8ClampedArray]",_n="[object Uint16Array]",jn="[object Uint32Array]",S={};S[Cn]=S[Sn]=S[$n]=S[En]=S[Ln]=S[Tn]=S[Mn]=S[_n]=S[jn]=!0;S[cn]=S[dn]=S[In]=S[pn]=S[An]=S[gn]=S[fn]=S[mn]=S[hn]=S[yn]=S[bn]=S[vn]=S[wn]=S[kn]=S[xn]=!1;function Pn(e){return tt(e)&&nn(e.length)&&!!S[pe(e)]}var Dn=Pn;function Nn(e){return function(t){return e(t)}}var On=Nn,qt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,se=qt&&typeof module=="object"&&module&&!module.nodeType&&module,Rn=se&&se.exports===qt,Ge=Rn&&zt.process,Fn=function(){try{var e=se&&se.require&&se.require("util").types;return e||Ge&&Ge.binding&&Ge.binding("util")}catch{}}(),kt=Fn,xt=kt&&kt.isTypedArray,Ld=xt?On(xt):Dn,zn=Object.prototype,Td=zn.hasOwnProperty;function Un(e,t){return function(r){return e(t(r))}}var Vn=Un,Md=Vn(Object.keys,Object),Bn=Object.prototype,_d=Bn.hasOwnProperty,Gn=Z(Object,"create"),ue=Gn;function qn(){this.__data__=ue?ue(null):{},this.size=0}var Hn=qn;function Qn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Zn=Qn,Yn="__lodash_hash_undefined__",Kn=Object.prototype,Wn=Kn.hasOwnProperty;function Xn(e){var t=this.__data__;if(ue){var r=t[e];return r===Yn?void 0:r}return Wn.call(t,e)?t[e]:void 0}var Jn=Xn,eo=Object.prototype,to=eo.hasOwnProperty;function ro(e){var t=this.__data__;return ue?t[e]!==void 0:to.call(t,e)}var io=ro,no="__lodash_hash_undefined__";function oo(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ue&&t===void 0?no:t,this}var ao=oo;function Y(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Y.prototype.clear=Hn;Y.prototype.delete=Zn;Y.prototype.get=Jn;Y.prototype.has=io;Y.prototype.set=ao;var It=Y;function lo(){this.__data__=[],this.size=0}var so=lo;function uo(e,t){for(var r=e.length;r--;)if(en(e[r][0],t))return r;return-1}var Se=uo,co=Array.prototype,po=co.splice;function go(e){var t=this.__data__,r=Se(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():po.call(t,r,1),--this.size,!0}var fo=go;function mo(e){var t=this.__data__,r=Se(t,e);return r<0?void 0:t[r][1]}var ho=mo;function yo(e){return Se(this.__data__,e)>-1}var bo=yo;function vo(e,t){var r=this.__data__,i=Se(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var wo=vo;function K(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])}}K.prototype.clear=so;K.prototype.delete=fo;K.prototype.get=ho;K.prototype.has=bo;K.prototype.set=wo;var $e=K,ko=Z(N,"Map"),ce=ko;function xo(){this.size=0,this.__data__={hash:new It,map:new(ce||$e),string:new It}}var Io=xo;function Ao(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Co=Ao;function So(e,t){var r=e.__data__;return Co(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Ee=So;function $o(e){var t=Ee(this,e).delete(e);return this.size-=t?1:0,t}var Eo=$o;function Lo(e){return Ee(this,e).get(e)}var To=Lo;function Mo(e){return Ee(this,e).has(e)}var _o=Mo;function jo(e,t){var r=Ee(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var Po=jo;function W(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}W.prototype.clear=Io;W.prototype.delete=Eo;W.prototype.get=To;W.prototype.has=_o;W.prototype.set=Po;var Ht=W;function Do(){this.__data__=new $e,this.size=0}var No=Do;function Oo(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Ro=Oo;function Fo(e){return this.__data__.get(e)}var zo=Fo;function Uo(e){return this.__data__.has(e)}var Vo=Uo,Bo=200;function Go(e,t){var r=this.__data__;if(r instanceof $e){var i=r.__data__;if(!ce||i.length<Bo-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Ht(i)}return r.set(e,t),this.size=r.size,this}var qo=Go;function ge(e){var t=this.__data__=new $e(e);this.size=t.size}ge.prototype.clear=No;ge.prototype.delete=Ro;ge.prototype.get=zo;ge.prototype.has=Vo;ge.prototype.set=qo;var Ho=Object.prototype,jd=Ho.propertyIsEnumerable,Qo=Z(N,"DataView"),Ye=Qo,Zo=Z(N,"Promise"),Ke=Zo,Yo=Z(N,"Set"),We=Yo,At="[object Map]",Ko="[object Object]",Ct="[object Promise]",St="[object Set]",$t="[object WeakMap]",Et="[object DataView]",Wo=V(Ye),Xo=V(ce),Jo=V(Ke),ea=V(We),ta=V(Ze),q=pe;(Ye&&q(new Ye(new ArrayBuffer(1)))!=Et||ce&&q(new ce)!=At||Ke&&q(Ke.resolve())!=Ct||We&&q(new We)!=St||Ze&&q(new Ze)!=$t)&&(q=function(e){var t=pe(e),r=t==Ko?e.constructor:void 0,i=r?V(r):"";if(i)switch(i){case Wo:return Et;case Xo:return At;case Jo:return Ct;case ea:return St;case ta:return $t}return t});var Pd=N.Uint8Array,ra="__lodash_hash_undefined__";function ia(e){return this.__data__.set(e,ra),this}var na=ia;function oa(e){return this.__data__.has(e)}var aa=oa;function Xe(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Ht;++t<r;)this.add(e[t])}Xe.prototype.add=Xe.prototype.push=na;Xe.prototype.has=aa;var Lt=Q?Q.prototype:void 0,Dd=Lt?Lt.valueOf:void 0,la=Object.prototype,Nd=la.hasOwnProperty,sa=Object.prototype,Od=sa.hasOwnProperty,Rd=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Fd=new RegExp(/[A-Fa-f0-9]{1}/,"g"),zd=new RegExp(/[A-Fa-f0-9]{2}/,"g");async function Qt(e,t){if(e.startsWith("buffer:")){let r=await t.editor.getMimeType(e),i=t.editor.getBufferLength(e),n=t.editor.getBufferData(e,0,i),a=new Uint8Array(n),o=new Blob([a],{type:r});return URL.createObjectURL(o)}else return e}async function Je(e,t){let r=await Qt(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 ua(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 Qt(i,t)}function ca(e){return e!==void 0}var Le=ca;function T(e,t){if(typeof e.i18n?.getTranslations!="function"){e.i18n.setTranslations(t);return}let r=Object.keys(t),i=e.i18n.getTranslations(r),n={};for(let a of r){let o=t[a];if(!o)continue;let s=i[a]??{},c={};for(let[l,u]of Object.entries(o))!(l in s)&&u!==void 0&&(c[l]=u);Object.keys(c).length>0&&(n[a]=c)}Object.keys(n).length>0&&e.i18n.setTranslations(n)}function fe(e,t){let r=t?.i18n?.getLocale?.()||"en";return{engine:e,cesdk:t,locale:r}}function me(e,t,r,i,n){if(t?.default!==void 0){let a=t.default;return typeof a!="function"?a:a(r)}return i!==void 0?i:n}var Te=class Zt{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 Zt),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))}},Yt=class Kt{constructor(){this.providers=new Map}static get(){let t="__imgly_provider_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new Kt),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 da(e){let t=e.filter(r=>!!r);return r=>async(i,n)=>{let a=[],o=l=>{a.push(l)},s=async(l,u,d)=>{if(l>=t.length)return r(u,d);let p=t[l],g=async(f,y)=>s(l+1,f,y),m={...d,addDisposer:o};return p(u,m,g)},c={...n,addDisposer:o};return{result:await s(0,i,c),dispose:async()=>{for(let l=a.length-1;l>=0;l--)try{await a[l]()}catch(u){console.error("Error in disposer:",u)}a.length=0}}}}function pa({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 ga=pa;var qe="ly.img.ai.temp";async function fa(e,t){return e.engine.asset.findAllSources().includes(qe)||e.engine.asset.addLocalSource(qe),e.engine.asset.apply(qe,t)}function ma(e,t="We encountered an unknown error while generating the asset. Please try again."){if(e===null)return t;if(e instanceof Error)return e.message;if(typeof e=="object"){let r=e;return"message"in r&&typeof r.message=="string"?r.message:"cause"in r&&typeof r.cause=="string"?r.cause:"detail"in r&&typeof r.detail=="object"&&r.detail!==null&&"message"in r.detail&&typeof r.detail.message=="string"?r.detail.message:"error"in r&&typeof r.error=="object"&&r.error!==null&&"message"in r.error&&typeof r.error.message=="string"?r.error.message:t}return typeof e=="string"?e:String(e)||t}function Wt(){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 ha(e,t=0,r="image/jpeg",i=.8){return new Promise((n,a)=>{try{let o=document.createElement("video");o.crossOrigin="anonymous",o.style.display="none",o.addEventListener("loadedmetadata",()=>{o.currentTime=Math.min(t,o.duration),o.addEventListener("seeked",()=>{let s=document.createElement("canvas");s.width=o.videoWidth,s.height=o.videoHeight;let c=s.getContext("2d");if(!c){document.body.removeChild(o),a(new Error("Failed to create canvas context"));return}c.drawImage(o,0,0,s.width,s.height);try{let l=s.toDataURL(r,i);document.body.removeChild(o),n(l)}catch(l){document.body.removeChild(o),a(new Error(`Failed to create thumbnail: ${l instanceof Error?l.message:String(l)}`))}},{once:!0})}),o.addEventListener("error",()=>{document.body.removeChild(o),a(new Error(`Failed to load video from ${e}`))}),o.src=e,document.body.appendChild(o)}catch(o){a(o)}})}function ya(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 rt(e){return e instanceof Error&&e.name==="AbortError"}function ba(e,t,r){let i=`${t}.iconSetAdded`;e.ui.experimental.hasGlobalStateValue(i)||(e.ui.addIconSet(t,r),e.ui.experimental.setGlobalStateValue(i,!0))}function Xt(e,t,r){let i="ai-plugin-version",n="ai-plugin-version-warning-shown";try{let a=e.ui.experimental.getGlobalStateValue(i);a?a!==r&&(e.ui.experimental.getGlobalStateValue(n,!1)||(console.warn(`[IMG.LY AI Plugins] Version mismatch detected! Plugin "${t}" is using version ${r}, but other AI plugins are using version ${a}. This may cause compatibility issues. Please ensure all AI plugins (@imgly/plugin-ai-*) use the same version. 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 va(e,t){let{cesdk:r,provider:i,getInput:n,middlewareOptions:a}=t;a?.defaultPrevented()||(console.error("Generation failed:",e),wa(r,i.output.notification,()=>({input:n?.().input,error:e}))||r.ui.showNotification({type:"error",message:ma(e)}))}function wa(e,t,r){let i=t?.error;if(i==null||!(typeof i.show=="function"?i.show(r()):i.show))return!1;let n=typeof i.message=="function"?i.message(r()):i.message??"common.ai-generation.failed",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 Tt=va,ka="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",it=ka;function xa(e,t,r){switch(t){case"image":return Ia(e,r[t]);case"video":return Aa(e,r[t]);case"sticker":return Ca(e,r[t]);default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Ia(e,t){let r=t.width,i=t.height;return{id:e,meta:{previewUri:it,fillType:"//ly.img.ubq/fill/image",kind:"image",width:r,height:i}}}function Aa(e,t){let r=t.width,i=t.height;return{id:e,label:t.label,meta:{previewUri:it,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:it,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:r,height:i}}}var Sa=xa;async function $a(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 Ea(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 La(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 Ta(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 Ma(e,r[t],i)}default:throw new Error(`Unsupported output kind for creating placeholder block: ${t}`)}}function Ea(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 La(e,t,r){let i=t.width,n=t.height,a=await ha(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 Ta(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 Ma(e,t,r){let i=t.width,n=t.height;return{id:e,label:t.label,meta:{uri:r.url,thumbUri:r.url,fillType:"//ly.img.ubq/fill/image",kind:"sticker",width:i,height:n},payload:{sourceSet:[{uri:r.url,width:i,height:n}]}}}var Jt=$a;function _a(e){switch(e.userFlow){case"placeholder":return Pa(e);case"generation-only":return ja(e);default:throw new Error(`Unknown user flow: ${e.userFlow}. Expected 'placeholder' or 'generation-only'.`)}}function ja(e){let{cesdk:t,abortSignal:r}=e;return async i=>{try{let n=e.kind,a=await e.getBlockInput(i);if(R(t,r))return{status:"aborted"};let o=await e.generate(i,{middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(R(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(R(t,r))return{status:"aborted"};if(e.historyAssetSourceId!=null){let s=Wt(),c=await Jt(s,n,a,o.output),l={...c,id:`${Date.now()}-${c.id}`,label:c.label!=null?{en:c.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,l)}else e.debug&&console.log("No asset source ID found in history and generation only was requested. Doing nothing. If no middleware is adding functionality this could be a bug.");return o}catch(n){return{status:"error",message:n instanceof Error?n.message:String(n)}}}}function Pa(e){let{cesdk:t,abortSignal:r}=e,i;return async n=>{try{let a=e.kind,o=await e.getBlockInput(n);if(R(t,r))return{status:"aborted"};let s=Wt(),c=Sa(s,a,o);if(i=await fa(t,c),R(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,{blockIds:[i],middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:r});if(R(t,r,i))return{status:"aborted"};if(l.status!=="success")return l.middlewareOptions?.defaultPrevented()||i!=null&&t.engine.block.isValid(i)&&(l.status==="aborted"?t.engine.block.destroy(i):t.engine.block.setState(i,{type:"Error",error:"Unknown"})),l;if(l.type==="async")throw new Error("Async generation is not supported in this context yet.");if(!t.engine.block.isValid(i))return{status:"aborted",message:"Placeholder block was destroyed before generation completed."};let u=await Jt(s,a,o,l.output);if(R(t,r,i))return{status:"aborted"};if(e.debug&&console.log("Updating placeholder in scene:",JSON.stringify(u,void 0,2)),await t.engine.asset.defaultApplyAssetToBlock(u,i),R(t,r,i))return{status:"aborted"};if(e.historyAssetSourceId!=null){let d={...u,id:`${Date.now()}-${u.id}`,label:u.label!=null?{en:u.label}:{},tags:{}};t.engine.asset.addAssetToSource(e.historyAssetSourceId,d)}return t.engine.block.isValid(i)&&t.engine.block.setState(i,{type:"Ready"}),l}catch(a){return i!=null&&t.engine.block.isValid(i)&&(rt(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 R(e,t,r){return t.aborted?(r!=null&&e.engine.block.isValid(r)&&e.engine.block.destroy(r),!0):!1}var Da=_a;function nt(e){return`${e}.generating`}function Na(e){return`${e}.abort`}function Oa(e,t,r,i,n,a,o){let{builder:s,experimental:c}=e,{cesdk:l,includeHistoryLibrary:u=!0}=a,{id:d,output:{abortable:p}}=t,g=c.global(Na(d),()=>{}),m=c.global(nt(d),!1),f,y=m.value&&p,b=()=>{y&&(g.value(),m.setValue(!1),g.setValue(()=>{}))},I;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let C=i();I=a.requiredInputs.some(h=>!C.input[h])}let x=c.global(`${d}.confirmationDialogId`,void 0);s.Section(`${d}.generate.section`,{children:()=>{s.Button(`${d}.generate`,{label:["ly.img.plugin-ai-generation-web.generate","common.generate",`panel.${d}.generate`],isLoading:m.value,color:"accent",isDisabled:I,suffix:y?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let C=l.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:h})=>{l.ui.closeDialog(h),x.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:h})=>{b(),l.ui.closeDialog(h),x.setValue(void 0)}}});x.setValue(C)}}:void 0,onClick:async()=>{f=new AbortController;let C=f.signal;await(async()=>{try{m.setValue(!0),g.setValue(()=>{o.debug&&console.log("Aborting generation"),f?.abort()});let h=await Da({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:C,cesdk:l,debug:o.debug,dryRun:o.dryRun})(i().input);if(h.status==="aborted")return;if(h.status==="error"){Tt(h.message,{cesdk:l,provider:t,getInput:i,middlewareOptions:h.middlewareOptions});return}if(h.status==="success"&&h.type==="sync"&&!h.middlewareOptions?.defaultPrevented()){let w=t.output.notification;Ra(l,w,()=>({input:i().input,output:h.output}))}}catch(h){if(rt(h))return;Tt(h,{cesdk:l,provider:t,getInput:i})}finally{f=void 0,m.setValue(!1),g.setValue(()=>{}),x.value!=null&&(l.ui.closeDialog(x.value),x.setValue(void 0))}})()}}),t.output.generationHintText!=null&&s.Text(`${d}.generation-hint`,{align:"center",content:t.output.generationHintText})}}),u&&a.historyAssetLibraryEntryId!=null&&s.Library(`${d}.history.library`,{entries:[a.historyAssetLibraryEntryId]})}function Ra(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 er=Oa;function de(e){let{name:t}=e;return(typeof t=="function"?t():t)??e.id}async function Fa({options:e,provider:t,panelInput:r,config:i},n){if(r==null)return;let{cesdk:a}=e,{id:o}=t;i.debug&&console.log(`Provider: ${o} (custom)`);let s=r.render;return c=>{let{state:l}=c,u=l(nt(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:p}=s(c,{cesdk:a,isGenerating:u});return er(c,t,n,d,p,{...e,includeHistoryLibrary:r.includeHistoryLibrary??!0,createPlaceholderBlock:r.userFlow==="placeholder"},i),d}}var za=Fa;function tr(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 ae(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=tr(e,t.$ref),n={...ae(e,i,r)};for(let a in t)Object.prototype.hasOwnProperty.call(t,a)&&a!=="$ref"&&(n[a]=ae(e,t[a],r));return n}if(Array.isArray(t))return t.map(i=>ae(e,i,r));if(typeof t=="object"){let i={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=ae(e,t[n],r));return i}return t}function Ua(e){return ae(e,{...e})}function Va(e,t=!1){let r=o=>(t&&console.log(`OpenAPI Schema validation failed: ${o}`),!1);if(typeof e!="object"||e===null)return r(`Input is ${e===null?"null":typeof e}, not an object`);let i=e;if(!(typeof i.type=="string"||Array.isArray(i.enum)||typeof i.properties=="object"||typeof i.items=="object"||typeof i.allOf=="object"||typeof i.anyOf=="object"||typeof i.oneOf=="object"||typeof i.not=="object"))return r("Missing required schema-defining properties (type, enum, properties, items, allOf, anyOf, oneOf, not)");if(i.type!==void 0){let o=["string","number","integer","boolean","array","object","null"];if(typeof i.type=="string"){if(!o.includes(i.type))return r(`Invalid type: ${i.type}. Must be one of ${o.join(", ")}`)}else if(Array.isArray(i.type)){for(let s of i.type)if(typeof s!="string"||!o.includes(s))return r(`Array of types contains invalid value: ${s}. Must be one of ${o.join(", ")}`)}else return r(`Type must be a string or array of strings, got ${typeof i.type}`)}if(i.items!==void 0&&(typeof i.items!="object"||i.items===null))return r(`Items must be an object, got ${i.items===null?"null":typeof i.items}`);if(i.properties!==void 0&&(typeof i.properties!="object"||i.properties===null))return r(`Properties must be an object, got ${i.properties===null?"null":typeof i.properties}`);let n=["allOf","anyOf","oneOf"];for(let o of n)if(i[o]!==void 0){if(!Array.isArray(i[o]))return r(`${o} must be an array, got ${typeof i[o]}`);for(let s=0;s<i[o].length;s++){let c=i[o][s];if(typeof c!="object"||c===null)return r(`Item ${s} in ${o} must be an object, got ${c===null?"null":typeof c}`)}}if(i.not!==void 0&&(typeof i.not!="object"||i.not===null))return r(`'not' must be an object, got ${i.not===null?"null":typeof i.not}`);if(i.additionalProperties!==void 0&&typeof i.additionalProperties!="boolean"&&(typeof i.additionalProperties!="object"||i.additionalProperties===null))return r(`additionalProperties must be a boolean or an object, got ${i.additionalProperties===null?"null":typeof i.additionalProperties}`);if(i.format!==void 0&&typeof i.format!="string")return r(`format must be a string, got ${typeof i.format}`);let a=["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf"];for(let o of a)if(i[o]!==void 0&&typeof i[o]!="number")return r(`${o} must be a number, got ${typeof i[o]}`);if(i.minLength!==void 0&&(typeof i.minLength!="number"||i.minLength<0))return r(`minLength must be a non-negative number, got ${typeof i.minLength=="number"?i.minLength:typeof i.minLength}`);if(i.maxLength!==void 0&&(typeof i.maxLength!="number"||i.maxLength<0))return r(`maxLength must be a non-negative number, got ${typeof i.maxLength=="number"?i.maxLength:typeof i.maxLength}`);if(i.pattern!==void 0&&typeof i.pattern!="string")return r(`pattern must be a string, got ${typeof i.pattern}`);if(i.minItems!==void 0&&(typeof i.minItems!="number"||i.minItems<0))return r(`minItems must be a non-negative number, got ${typeof i.minItems=="number"?i.minItems:typeof i.minItems}`);if(i.maxItems!==void 0&&(typeof i.maxItems!="number"||i.maxItems<0))return r(`maxItems must be a non-negative number, got ${typeof i.maxItems=="number"?i.maxItems:typeof i.maxItems}`);if(i.uniqueItems!==void 0&&typeof i.uniqueItems!="boolean")return r(`uniqueItems must be a boolean, got ${typeof i.uniqueItems}`);if(i.minProperties!==void 0&&(typeof i.minProperties!="number"||i.minProperties<0))return r(`minProperties must be a non-negative number, got ${typeof i.minProperties=="number"?i.minProperties:typeof i.minProperties}`);if(i.maxProperties!==void 0&&(typeof i.maxProperties!="number"||i.maxProperties<0))return r(`maxProperties must be a non-negative number, got ${typeof i.maxProperties=="number"?i.maxProperties:typeof i.maxProperties}`);if(i.required!==void 0){if(!Array.isArray(i.required))return r(`required must be an array, got ${typeof i.required}`);for(let o=0;o<i.required.length;o++){let s=i.required[o];if(typeof s!="string")return r(`Item ${o} in required array must be a string, got ${typeof s}`)}}return!0}function Ba(e,t){if(e.properties==null)throw new Error("Input schema must have properties");let r=e.properties,i=[];return Ga(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function Ga(e,t){let r=t.order;if(r!=null&&Array.isArray(r))return r;if(e.properties==null)throw new Error("Input schema must have properties");let i=e.properties,n=Object.keys(i),a=qa(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function qa(e,t){if(t.orderExtensionKeyword==null)return;if(typeof t.orderExtensionKeyword!="string"&&!Array.isArray(t.orderExtensionKeyword))throw new Error("orderExtensionKeyword must be a string or an array of strings");let r=(typeof t.orderExtensionKeyword=="string"?[t.orderExtensionKeyword]:t.orderExtensionKeyword).find(i=>i in e);return r==null?void 0:e[r]}var rr=Ba;function F(e,t,r,i){let n=`property.${e.id}${i?`.${i}`:""}`,a=[`ly.img.plugin-ai-${r}-generation-web.${t.id}.${n}`,`ly.img.plugin-ai-generation-web.${n}`,`ly.img.plugin-ai-${r}-generation-web.${t.id}.defaults.${n}`,`ly.img.plugin-ai-generation-web.defaults.${n}`];return i==="placeholder"&&a.push("ly.img.plugin-ai-generation-web.fallback.property.placeholder"),a}function ir(e){let t="x-imgly-enum-labels"in e&&typeof e["x-imgly-enum-labels"]=="object"?e["x-imgly-enum-labels"]:{},r="x-imgly-enum-icons"in e&&typeof e["x-imgly-enum-icons"]=="object"?e["x-imgly-enum-icons"]:{};return{labels:t,icons:r}}function nr(e,t,r,i,n,a,o,s){if(t.schema==null)if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null){let u={...e,providerConfig:s,config:a};return i.renderCustomProperty[t.id](u,t)}else return;let c=t,l=t.schema.type;if(i.renderCustomProperty!=null&&i.renderCustomProperty[t.id]!=null){let u={...e,providerConfig:s,config:a};return i.renderCustomProperty[t.id](u,t)}switch(l){case"string":return t.schema.enum!=null?Ha(e,c,r,i,n,a,o,s):or(e,c,r,i,n,a,o,s);case"boolean":return ar(e,c,r,i,n,a,o,s);case"number":case"integer":return lr(e,c,r,i,n,a,o,s);case"object":return et(e,c,r,i,n,a,o,s);case"array":break;case void 0:{if(t.schema.anyOf!=null&&Array.isArray(t.schema.anyOf))return Qa(e,c,r,i,n,a,o,s);break}default:console.error(`Unsupported property type: ${l}`)}}function et(e,t,r,i,n,a,o,s){let c=rr(t.schema??{},i).reduce((l,u)=>{let d=nr(e,u,r,i,n,a,o,s);return d!=null&&(l[u.id]=d()),l},{});return()=>({id:t.id,type:"object",value:c})}function or(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,p=`${r.id}.${d}`,g=F(t,r,o),m=F(t,r,o,"placeholder"),f=fe(u,n.cesdk),y=s?.properties?.[d]??a.properties?.[d],b=me(d,y,f,t.schema.default,""),I=l(p,b),x=Za(t.schema),C=x?.component!=null&&x?.component==="TextArea"?"TextArea":"TextInput",h=m.length>0?m:void 0;return c[C](p,{inputLabel:g,...h&&{placeholder:h},...I}),()=>({id:t.id,type:"string",value:I.value})}function Ha(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,p=`${r.id}.${d}`,g=F(t,r,o),{labels:m,icons:f}=ir(t.schema),y=(t.schema.enum??[]).map(w=>({id:w,label:F(t,r,o,w),icon:f[w]})),b=fe(u,n.cesdk),I=s?.properties?.[d]??a.properties?.[d],x=me(d,I,b,t.schema.default,y[0]?.id),C=x!=null?y.find(w=>w.id===x)??y[0]:y[0],h=l(p,C);return c.Selec