UNPKG

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

Version:

AI text generation plugin for the CE.SDK editor

99 lines (93 loc) 74.2 kB
var me="@imgly/plugin-ai-text-generation",lt=` <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> `,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(` `,"+")}`}}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=` <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="${ee}/image" > <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"/> <path d="M13.0982 0.884877C12.9734 0.568323 12.5254 0.568322 12.4005 0.884876L11.7485 2.53819C