UNPKG

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

Version:

AI text generation plugin for the CE.SDK editor

328 lines 124 kB
var mt="@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>
`,ht=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="",g=[];l.label!=null&&typeof l.label=="object"&&l.label[u]&&(d=l.label[u]),l.tags!=null&&typeof l.tags=="object"&&l.tags[u]&&(g=l.tags[u]);let p={...l,label:d,tags:g};return this.filterAsset(p,e)&&c.push(p),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 g=u.meta?.insertedAt||0;return(d.meta?.insertedAt||0)-g});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,gi=typeof self=="object"&&self&&self.Object===Object&&self,pi=zt||gi||Function("return this")(),N=pi,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]",yt=Q?Q.toStringTag:void 0;function Ci(e){return e==null?e===void 0?Ai:Ii:yt&&yt in Object(e)?bi(e):xi(e)}var ge=Ci;function Si(e){return e!=null&&typeof e=="object"}var rt=Si,Cd=Array.isArray;function $i(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Vt=$i,Ei="[object AsyncFunction]",Ti="[object Function]",Li="[object GeneratorFunction]",Mi="[object Proxy]";function _i(e){if(!Vt(e))return!1;var t=ge(e);return t==Ti||t==Li||t==Ei||t==Mi}var ji=_i,Pi=N["__core-js_shared__"],Be=Pi,bt=function(){var e=/[^.]+$/.exec(Be&&Be.keys&&Be.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Di(e){return!!bt&&bt 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,qi=Vi.toString,Gi=Bi.hasOwnProperty,Hi=RegExp("^"+qi.call(Gi).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,Ji=Z(N,"WeakMap"),Ze=Ji;function Xi(e,t){return e===t||e!==e&&t!==t}var en=Xi,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 rt(e)&&ge(e)==on}var vt=an,Bt=Object.prototype,ln=Bt.hasOwnProperty,sn=Bt.propertyIsEnumerable,$d=vt(function(){return arguments}())?vt:function(e){return rt(e)&&ln.call(e,"callee")&&!sn.call(e,"callee")},qt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,wt=qt&&typeof module=="object"&&module&&!module.nodeType&&module,un=wt&&wt.exports===qt,kt=un?N.Buffer:void 0,Ed=kt?kt.isBuffer:void 0,cn="[object Arguments]",dn="[object Array]",gn="[object Boolean]",pn="[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]",Tn="[object Int32Array]",Ln="[object Uint8Array]",Mn="[object Uint8ClampedArray]",_n="[object Uint16Array]",jn="[object Uint32Array]",S={};S[Cn]=S[Sn]=S[$n]=S[En]=S[Tn]=S[Ln]=S[Mn]=S[_n]=S[jn]=!0;S[cn]=S[dn]=S[In]=S[gn]=S[An]=S[pn]=S[fn]=S[mn]=S[hn]=S[yn]=S[bn]=S[vn]=S[wn]=S[kn]=S[xn]=!1;function Pn(e){return rt(e)&&nn(e.length)&&!!S[ge(e)]}var Dn=Pn;function Nn(e){return function(t){return e(t)}}var On=Nn,Gt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,se=Gt&&typeof module=="object"&&module&&!module.nodeType&&module,Rn=se&&se.exports===Gt,qe=Rn&&zt.process,Fn=function(){try{var e=se&&se.require&&se.require("util").types;return e||qe&&qe.binding&&qe.binding("util")}catch{}}(),xt=Fn,It=xt&&xt.isTypedArray,Td=It?On(It):Dn,zn=Object.prototype,Ld=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,qn=Z(Object,"create"),ue=qn;function Gn(){this.__data__=ue?ue(null):{},this.size=0}var Hn=Gn;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 Jn(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 Xn=Jn,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=Xn;Y.prototype.has=io;Y.prototype.set=ao;var At=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,go=co.splice;function po(e){var t=this.__data__,r=Se(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():go.call(t,r,1),--this.size,!0}var fo=po;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 At,map:new(ce||$e),string:new At}}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 To(e){return Ee(this,e).get(e)}var Lo=To;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=Lo;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 qo(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 Go=qo;function pe(e){var t=this.__data__=new $e(e);this.size=t.size}pe.prototype.clear=No;pe.prototype.delete=Ro;pe.prototype.get=zo;pe.prototype.has=Vo;pe.prototype.set=Go;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,Ct="[object Map]",Ko="[object Object]",St="[object Promise]",$t="[object Set]",Et="[object WeakMap]",Tt="[object DataView]",Wo=V(Ye),Jo=V(ce),Xo=V(Ke),ea=V(We),ta=V(Ze),G=ge;(Ye&&G(new Ye(new ArrayBuffer(1)))!=Tt||ce&&G(new ce)!=Ct||Ke&&G(Ke.resolve())!=St||We&&G(new We)!=$t||Ze&&G(new Ze)!=Et)&&(G=function(e){var t=ge(e),r=t==Ko?e.constructor:void 0,i=r?V(r):"";if(i)switch(i){case Wo:return Tt;case Jo:return Ct;case Xo:return St;case ea:return $t;case ta:return Et}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 Je(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Ht;++t<r;)this.add(e[t])}Je.prototype.add=Je.prototype.push=na;Je.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 Xe(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 Te=ca;function L(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 Le=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 g=t[l],p=async(f,y)=>s(l+1,f,y),h={...d,addDisposer:o};return g(u,h,p)},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 ga({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 pa=ga;var Ge="ly.img.ai.temp";async function fa(e,t){return e.engine.asset.findAllSources().includes(Ge)||e.engine.asset.addLocalSource(Ge),e.engine.asset.apply(Ge,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 it(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 Jt(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,duration:i.duration}),!0}var et=va,ka="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIzIiBoZWlnaHQ9IjMyMyIgdmlld0JveD0iMCAwIDMyMyAzMjMiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjMiIGhlaWdodD0iMzIzIiBmaWxsPSIjRTlFQkVEIi8+CjxnIG9wYWNpdHk9IjAuMyI+CjxwYXRoIGQ9Ik0xMTYgMTg0VjE5MS41QzExNiAxOTkuNzg0IDEyMi43MTYgMjA2LjUgMTMxIDIwNi41SDE5MUMxOTkuMjg0IDIwNi41IDIwNiAxOTkuNzg0IDIwNiAxOTEuNVYxMzEuNUMyMDYgMTIzLjIxNiAxOTkuMjg0IDExNi41IDE5MSAxMTYuNUwxOTAuOTk1IDEyNi41QzE5My43NTcgMTI2LjUgMTk2IDEyOC43MzkgMTk2IDEzMS41VjE5MS41QzE5NiAxOTQuMjYxIDE5My43NjEgMTk2LjUgMTkxIDE5Ni41SDEzMUMxMjguMjM5IDE5Ni41IDEyNiAxOTQuMjYxIDEyNiAxOTEuNVYxODRIMTE2WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTY2LjQ5NCAxMDUuOTI0QzE2NS44NjkgMTA0LjM0MiAxNjMuNjI5IDEwNC4zNDIgMTYzLjAwNSAxMDUuOTI0TDE1OS43NDUgMTE0LjE5MUMxNTkuNTU0IDExNC42NzQgMTU5LjE3MiAxMTUuMDU3IDE1OC42ODggMTE1LjI0N0wxNTAuNDIyIDExOC41MDhDMTQ4LjgzOSAxMTkuMTMyIDE0OC44MzkgMTIxLjM3MiAxNTAuNDIyIDEyMS45OTZMMTU4LjY4OCAxMjUuMjU2QzE1OS4xNzIgMTI1LjQ0NyAxNTkuNTU0IDEyNS44MjkgMTU5Ljc0NSAxMjYuMzEzTDE2My4wMDUgMTM0LjU3OUMxNjMuNjI5IDEzNi4xNjIgMTY1Ljg2OSAxMzYuMTYyIDE2Ni40OTQgMTM0LjU3OUwxNjkuNzU0IDEyNi4zMTNDMTY5Ljk0NCAxMjUuODI5IDE3MC4zMjcgMTI1LjQ0NyAxNzAuODEgMTI1LjI1NkwxNzkuMDc3IDEyMS45OTZDMTgwLjY2IDEyMS4zNzIgMTgwLjY2IDExOS4xMzIgMTc5LjA3NyAxMTguNTA4TDE3MC44MSAxMTUuMjQ3QzE3MC4zMjcgMTE1LjA1NyAxNjkuOTQ0IDExNC42NzQgMTY5Ljc1NCAxMTQuMTkxTDE2Ni40OTQgMTA1LjkyNFoiIGZpbGw9IiM4RjhGOEYiLz4KPHBhdGggZD0iTTEzMy4wMDUgMTI4LjQyNEMxMzMuNjI5IDEyNi44NDIgMTM1Ljg2OSAxMjYuODQyIDEzNi40OTQgMTI4LjQyNEwxNDEuODc1IDE0Mi4wN0MxNDIuMDY2IDE0Mi41NTMgMTQyLjQ0OCAxNDIuOTM1IDE0Mi45MzIgMTQzLjEyNkwxNTYuNTc3IDE0OC41MDhDMTU4LjE2IDE0OS4xMzIgMTU4LjE2IDE1MS4zNzIgMTU2LjU3NyAxNTEuOTk2TDE0Mi45MzIgMTU3LjM3OEMxNDIuNDQ4IDE1Ny41NjggMTQyLjA2NiAxNTcuOTUxIDE0MS44NzUgMTU4LjQzNEwxMzYuNDk0IDE3Mi4wNzlDMTM1Ljg2OSAxNzMuNjYyIDEzMy42MjkgMTczLjY2MiAxMzMuMDA1IDE3Mi4wNzlMMTI3LjYyMyAxNTguNDM0QzEyNy40MzMgMTU3Ljk1MSAxMjcuMDUgMTU3LjU2OCAxMjYuNTY3IDE1Ny4zNzhMMTEyLjkyMiAxNTEuOTk2QzExMS4zMzkgMTUxLjM3MiAxMTEuMzM5IDE0OS4xMzIgMTEyLjkyMiAxNDguNTA4TDEyNi41NjcgMTQzLjEyNkMxMjcuMDUgMTQyLjkzNSAxMjcuNDMzIDE0Mi41NTMgMTI3LjYyMyAxNDIuMDdMMTMzLjAwNSAxMjguNDI0WiIgZmlsbD0iIzhGOEY4RiIvPgo8cGF0aCBkPSJNMTk1Ljk5OSAxODQuMDA0VjE5MS41MDJDMTk1Ljk5OSAxOTQuMjYzIDE5My43NjEgMTk2LjUwMiAxOTAuOTk5IDE5Ni41MDJIMTQ3LjY2OEwxNzIuODc5IDE1OC42ODRDMTc0LjM2MyAxNTYuNDU4IDE3Ny42MzUgMTU2LjQ1OCAxNzkuMTIgMTU4LjY4NEwxOTUuOTk5IDE4NC4wMDRaIiBmaWxsPSIjOEY4RjhGIi8+CjwvZz4KPC9zdmc+Cg==",nt=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:nt,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:nt,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:nt,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 Ta(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 La(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 Ta(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 La(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 Xt=$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 Xt(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),error: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),g=t.engine.block.getPositionY(i),p=t.engine.block.duplicate(i);t.engine.block.setPositionX(p,d),t.engine.block.setPositionY(p,g),t.engine.block.destroy(i),i=p}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 i!=null&&t.engine.block.isValid(i)&&(l.status==="aborted"||l.middlewareOptions?.defaultPrevented()?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 Xt(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)&&(it(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),error: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 ot(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:g}}=t,p=c.global(Na(d),()=>{}),h=c.global(ot(d),!1),f,y=h.value&&g,b=()=>{y&&(p.value(),h.setValue(!1),p.setValue(()=>{}))},I;if(a.requiredInputs!=null&&a.requiredInputs.length>0){let A=i();I=a.requiredInputs.some(m=>!A.input[m])}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:h.value,color:"accent",isDisabled:I,suffix:y?{icon:"@imgly/Cross",color:"danger",tooltip:[`panel.${d}.abort`,"common.cancel"],onClick:()=>{let A=l.ui.showDialog({type:"warning",content:"panel.ly.img.ai.generation.confirmCancel.content",cancel:{label:"common.close",onClick:({id:m})=>{l.ui.closeDialog(m),x.setValue(void 0)}},actions:{label:"panel.ly.img.ai.generation.confirmCancel.confirm",color:"danger",onClick:({id:m})=>{b(),l.ui.closeDialog(m),x.setValue(void 0)}}});x.setValue(A)}}:void 0,onClick:async()=>{f=new AbortController;let A=f.signal;await(async()=>{try{h.setValue(!0),p.setValue(()=>{o.debug&&console.log("Aborting generation"),f?.abort()});let m=await Da({kind:t.kind,generate:r,historyAssetSourceId:a.historyAssetSourceId,userFlow:a.createPlaceholderBlock?"placeholder":"generation-only",getBlockInput:n,abortSignal:A,cesdk:l,debug:o.debug,dryRun:o.dryRun})(i().input);if(m.status==="aborted")return;if(m.status==="error"){et(m.error??m.message,{cesdk:l,provider:t,getInput:i,middlewareOptions:m.middlewareOptions});return}if(m.status==="success"&&m.type==="sync"&&!m.middlewareOptions?.defaultPrevented()){let v=t.output.notification;Ra(l,v,()=>({input:i().input,output:m.output}))}}catch(m){if(it(m))return;et(m,{cesdk:l,provider:t,getInput:i})}finally{f=void 0,h.setValue(!1),p.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(ot(o),{isGenerating:!1,abort:()=>{}}).value.isGenerating,{getInput:d,getBlockInput:g}=s(c,{cesdk:a,isGenerating:u});return er(c,t,n,d,g,{...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 qa(e,t).forEach(n=>{let a=n,o=r[n]??void 0;i.push({id:a,schema:o})}),i}function qa(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=Ga(e,t)??n;return r!=null&&typeof r=="function"&&(a=r(a)),[...new Set(a)]}function Ga(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 tt(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 tt(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,g=`${r.id}.${d}`,p=F(t,r,o),h=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(g,b),x=Za(t.schema),A=x?.component!=null&&x?.component==="TextArea"?"TextArea":"TextInput",m=h.length>0?h:void 0;return c[A](g,{inputLabel:p,...m&&{placeholder:m},...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,g=`${r.id}.${d}`,p=F(t,r,o),{labels:h,icons:f}=ir(t.schema),y=(t.schema.enum??[]).map(v=>({id:v,label:F(t,r,o,v),icon:f[v]})),b=fe(u,n.cesdk),I=s?.properties?.[d]??a.properties?.[d],x=me(d,I,b,t.schema.default,y[0]?.id),A=x!=null?y.find(v=>v.id===x)??y[0]:y[0],m=l(g,A);return c.Select(g,{inputLabel:p,values:y,...m}),()=>({id:t.id,type:"string",value:m.value.id})}function ar(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,g=`${r.id}.${d}`,p=F(t,r,o),h=fe(u,n.cesdk),f=s?.properties?.[d]??a.properties?.[d],y=!!me(d,f,h,t.schema.default,!1),b=l(g,y);return c.Checkbox(g,{inputLabel:p,...b}),()=>({id:t.id,type:"boolean",value:b.value})}function lr(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,g=`${r.id}.${d}`,p=F(t,r,o),h=t.schema.minimum,f=t.schema.maximum,y=fe(u,n.cesdk),b=s?.properties?.[d]??a.properties?.[d],I=t.schema.default;I==null&&(h!=null?I=h:f!=null?I=f:I=0);let x=me(d,b,y,I,I),A=l(g,x);if(h!=null&&f!=null){let m=t.schema.type==="number"?.1:1;"x-imgly-step"in t.schema&&typeof t.schema["x-imgly-step"]=="number"&&(m=t.schema["x-imgly-step"]),c.Slider(g,{inputLabel:p,min:h,max:f,step:m,...A})}else c.NumberInput(g,{inputLabel:p,min:h,max:f,...A});return()=>({id:t.id,type:"integer",value:A.value})}function Qa(e,t,r,i,n,a,o,s){let{builder:c,experimental:{global:l},engine:u}=e,{id:d}=t,g=`${r.id}.${d}`,p=F(t,r,o),h=t.schema.anyOf??[],f=[],y={},b={},{labels:I,icons:x}=ir(t.schema),A=fe(u,n.cesdk),m=s?.properties?.[d]??a.properties?.[d],v={string:or,boolean:ar,integer:lr,object:tt},C=(k,P)=>k.$ref?k.$ref.split("/").pop():P.split(".").pop()??P,w=(k,P)=>({id:k,label:F(t,r,o,P),icon:x[P]??x[k]});h.forEach((k,P)=>{let T=`${r.id}.${d}.anyOf[${P}]`;if(k.$ref||k.title){let j=k.$ref?k.$ref.split("/").pop():k.title;y[T]=()=>tt(e,{id:T,schema:{...k,title:I[j]||j}},r,i,n,a,o,s),f.push(w(T,j))}else if(k.type==="string"&&k.enum)k.enum.forEach(j=>{f.push(w(j,j))});else if(k.type&&v[k.type]){let j=v[k.type];y[T]=()=>j(e,{id:T,schema:{...k,title:k.title}},r,i,n,a,o,s);let Ve=C(k,T);f.push(k.type==="string"&&!k.enum?{id:T,label:k.title||Ve,icon:k.title&&x[k.title]||x[Ve]}:w(T,Ve))}});let M=me(d,m,A,t.schema.default,null),E=M!=null?f.find(k=>k.id===M)??f[0]:f[0],_=l(g,E);if(c.Select(g,{inputLabel:p,values:f,..._}),_.value.id in y){let k=y[_.value.id]();b[_.value.id]=k}return()=>{let k=b[_.value.id];return k!=null?{...k(),id:t.id}:{id:t.id,type:"string",value:_.value.id}}}function Za(e){if("x-imgly-builder"in e)return e["x-imgly-builder"]}var Ya=nr,Ka={"ly.img.plugin-ai-generation-web.fallback.property.placeholder":"","ly.img.plugin-ai-generation-web.defaults.property.prompt":"Prompt","ly.img.plugin-ai-generation-web.defaults.property.style":"Style","ly.img.plugin-ai-generation-web.defaults.property.image_size":"Image Size","ly.img.plugin-ai-generation-web.defaults.property.size":"Image Size","ly.img.plugin-ai-generation-web.defaults.property.colors":"Colors","ly.img.plugin-ai-generation-web.defaults.property.background":"Background","ly.img.plugin-ai-generation-web.defaults.property.width":"Width","ly.img.plugin-ai-generation-web.defaults.property.height":"Height","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio":"Aspect Ratio","ly.img.plugin-ai-generation-web.defaults.property.duration":"Duration","ly.img.plugin-ai-generation-web.defaults.property.resolution":"Resolution","ly.img.plugin-ai-generation-web.defaults.property.generate_audio":"Generate Audio","ly.img.plugin-ai-generation-web.defaults.property.voice_id":"Voice","ly.img.plugin-ai-generation-web.defaults.property.speed":"Speed","ly.img.plugin-ai-generation-web.defaults.property.text":"Text","ly.img.plugin-ai-generation-web.defaults.property.duration_seconds":"Duration (seconds)","ly.img.plugin-ai-generation-web.defaults.property.style.type":"Type","ly.img.plugin-ai-generation-web.defaults.property.style.type.image":"Image","ly.img.plugin-ai-generation-web.defaults.property.style.type.vector":"Vector","ly.img.plugin-ai-generation-web.defaults.property.style.type.icon":"Icon","ly.img.plugin-ai-generation-web.defaults.property.image_size.square":"Square","ly.img.plugin-ai-generation-web.defaults.property.image_size.portrait":"Portrait","ly.img.plugin-ai-generation-web.defaults.property.image_size.landscape":"Landscape","ly.img.plugin-ai-generation-web.defaults.property.background.auto":"Auto","ly.img.plugin-ai-generation-web.defaults.property.background.transparent":"Transparent","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.1:1":"1:1 (Square)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.16:9":"16:9 (Widescreen)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.9:16":"9:16 (Vertical)","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.4:3":"4:3","ly.img.plugin-ai-generation-web.defaults.property.aspect_ratio.3:4":"3:4","ly.img.plugin-ai-generation-web.defaults.property.resolution.720p":"720p HD","ly.img.plugin-ai-generation-web.defaults.property.resolution.1080p":"1080p Full HD"};function Mt(e){return e.replace(/_/g," ").replace(/\b3d\b/gi,"3D").replace(/\b2d\b/gi,"2D").replace(/\b\w/g,t=>t.toUpperCase())}function _t(e,t,r,i){let n={},a=(l,u)=>`ly.img.plugin-ai-${i}-generation-web.${t.id}.defaults.property.${l}${u?`.${u}`:""}`,o=l=>"x-imgly-enum-labels"in l&&typeof l["x-imgly-enum-labels"]=="object"?l["x-imgly-enum-labels"]:{},s=(l,u,d)=>{l.forEach(g=>{let p=String(g),h=d[p]||Mt(p);n[a(u,p)]=h})};e.forEach(l=>{if(l.schema?.title&&(n[a(l.id)]=l.schema.title),l.schema?.enum){let u=o(l.schema);s(l.schema.enum,l.id,u)}if(l.schema?.anyOf&&Array.isArray(l.schema.anyOf)){let u=o(l.schema);l.schema.anyOf.forEach(d=>{let g=d;if(g.enum&&Array.isArray(g.enum))s(g.enum,l.id,u);else if(g.$ref){let p=g.$ref.split("/").pop();p&&u[p]&&(n[a(l.id,p)]=u[p])}else if(g.title){let p=g.title,h=u[p]||Mt(p);n[a(l.id,p)]=h}})}});let c={...Ka,...n};Object.keys(c).length>0&&L(r.cesdk,{en:c})}function jt(e){return typeof e.document=="function"?e.document():e.document}function Pt(e,t,r){let i=Ua(e),n=tr(i,t.inputReference);if(!Va(n,r))throw new Error(`Input reference '${t.inputReference}' does not resolve to a valid OpenAPI schema`);let a=n,o=rr(a,t);return{inputSchema:a,properties:o}}function Dt(e,t,r,{options:i,provider:n,config:a,providerConfig:o},s){let{id:c}=n;return l=>{let{builder:u}=l,d=[];u.Section(`${c}.schema.section`,{children:()=>{t.forEach(y=>{let b=Ya(l,y,n,r,i,a,n.kind,o);b!=null&&(Array.isArray(b)?d.push(...b):d.push(b))})}});let g=d.map(y=>y()),p=y=>y.type==="object"?Object.entries(y.value).reduce((b,[I,x])=>(b[I]=p(x),b),{}):y.value,h=g.reduce((y,b)=>(y[b.id]=p(b),y),{}),f=[...new Set([...e.required??[],...g.filter(y=>y.required).map(y=>y.id)])];er(l,n,s,()=>({input:h}),()=>r.getBlockInput(h),{...i,requiredInputs:f,createPlaceholderBlock:r.userFlow==="placeholder"},a)}}async function Wa(e,t){let{options:r,provider:i,panelInput:n,config:a}=e,{id:o}=i;if(n==null)return;let s=n;a.debug&&console.log(`Provider: ${o} (schema-based)`);let c=jt(s);if(!(c instanceof Promise)){let{inputSchema:p,properties:h}=Pt(c,s,a.debug);return _t(h,i,r,i.kind),Dt(p,h,s,e,t)}let l=null,u=null,d=`${o}.schema.loading`;function g(){l=null,u=null,r.cesdk.ui.experimental.setGlobalStateValue(d,!0),Promise.resolve(jt(s)).then(p=>{let{inputSchema:h,properties:f}=Pt(p,s,a.debug);_t(f,i,r,i.kind),u=Dt(h,f,s,e,t)}).catch(p=>{l=p instanceof Error?p:new Error(String(p))}).finally(()=>{r.cesdk.ui.experimental.setGlobalStateValue(d,!1)})}return g(),p=>{let{builder:h}=p;if(u!=null){u(p);return}if(l!=null){h.Section(`${o}.schema.error`,{children:()=>{h.Text(`${o}.schema.error.title`,{content:"ly.img.plugin-ai-generation-web.schema.error.title"}),h.Text(`${o}.schema.error.details`,{content:l.message}),h.Button(`${o}.schema.error.retry`,{label:"ly.img.plugin-ai-generation-web.schema.error.retry",onClick:()=>{g()}})}});return}h.Spinner(`${o}.schema.loading`,{label:"ly.img.plugin-ai-generation-web.schema.loading.label"})}}var Ja=Wa;async function Xa(e,t){if(e.panelInput!=null)switch(e.panelInput.type){case"custom":return za(e,t);case"schema":return Ja(e,t);default:e.config.debug&&console.warn(`Invalid panel input type '${panelInput.type}' - skipping`)}}var el=Xa;function tl(e){let{provider:t,options:{engine:r}}=e,i=t.output.history??"@imgly/local";if(i==null||i===!1)return;let n=r.asset.findAllSources();function a(){let o=`${t.id}.history`;for(;n.includes(o);)o+=`-${Math.random().toString(36).substring(2,6)}`;return o}if(i==="@imgly/local"){let o=a();return r.asset.addLocalSource(o),o}if(i==="@imgly/indexedDB"){let o=a();return r.asset.addSource(new si(o,r)),o}return i}var rl=tl;function il(e,t){if(t==null||!t)return;let r=`${e.provider.id}.history`;return e.options.cesdk.ui.addAssetLibraryEntry({id:r,sourceIds:[t],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"}),r}var nl=il,He="@imgly/plugin-ai-generation",ol=`
<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="${He}/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.53819C11.7104 2.63483 11.6339 2.71134 11.5372 2.74945L9.8839 3.40151C9.56735 3.52636 9.56734 3.97436 9.8839 4.09921L11.5372 4.75126C11.6339 4.78938 11.7104 4.86588 11.7485 4.96253L12.4005 6.61584C12.5254 6.93239 12.9734 6.9324 13.0982 6.61584L13.7503 4.96253C13.7884 4.86588 13.8649 4.78938 13.9616 4.75126L15.6149 4.09921C15.9314 3.97436 15.9314 3.52636 15.6149 3.40151L13.9616 2.74945C13.8649 2.71134 13.7884 2.63483 13.7503 2.53819L13.0982 0.884877Z" fill="currentColor"/>
<path d="M6.40053 5.38488C6.52538 5.06832 6.97338 5.06832 7.09823 5.38488L8.17455 8.11392C8.21267 8.21057 8.28917 8.28707 8.38582 8.32519L11.1149 9.40151C11.4314 9.52636 11.4314 9.97436 11.1149 10.0992L8.38582 11.1755C8.28917 11.2136 8.21267 11.2901 8.17455 11.3868L7.09823 14.1158C6.97338 14.4324 6.52538 14.4324 6.40053 14.1158L5.32421 11.3868C5.2861 11.2901 5.20959 11.2136 5.11295 11.1755L2.3839 10.0992C2.06735 9.97436 2.06735 9.52636 2.3839 9.40151L5.11295 8.32519C5.20959 8.28707 5.2861 8.21057 5.32421 8.11392L6.40053 5.38488Z" fill="currentColor"/>
<path d="M18.9994 16.5008V18.0004C18.9994 18.5526 18.5517 19.0004 17.9994 19.0004H9.33302L14.3753 11.4369C14.6722 10.9916 15.3266 10.9916 15.6234 11.4369L18.9994 16.5008Z" fill="currentColor"/>

  </symbol>
  <symbol
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
    viewBox="0 0 24 24"
    id="${He}/video"
  >
<path d="M6 3C4.34315 3 3 4.34315 3 6V18C3 19.6569 4.34315 21 6 21H18C19.6569 21 21 19.6569 21 18V16.5H19V18C19 18.5523 18.5523 19 18 19H6C5.44772 19 5 18.5523 5 18V6C5 5.44772 5.44772 5 6 5V3Z" fill="currentColor"/>
<path d="M10.9025 0.8839C11.0273 0.567345 11.4753 0.567346 11.6002 0.883901L12.2522 2.53721C12.2904 2.63386 12.3669 2.71036 12.4635 2.74848L14.1168 3.40053C14.4334 3.52538 14.4334 3.97338 14.1168 4.09823L12.4635 4.75029C12.3669 4.7884 12.2904 4.86491 12.2522 4.96155L11.6002 6.61486C11.4753 6.93142 11.0273 6.93142 10.9025 6.61486L10.2504 4.96155C10.2123 4.86491 10.1358 4.7884 10.0392 4.75029L8.38585 4.09823C8.0693 3.97338 8.0693 3.52538 8.38585 3.40053L10.0392 2.74848C10.1358 2.71036 10.2123 2.63386 10.2504 2.53721L10.9025 0.8839Z" fill="currentColor"/>
<path d="M18.9019 3.3845C19.0267 3.06795 19.4747 3.06795 19.5996 3.3845L20.6759 6.11355C20.714 6.2102 20.7905 6.2867 20.8872 6.32482L23.6162 7.40114C23.9328 7.52598 23.9328 7.97399 23.6162 8.09883L20.8872 9.17515C20.7905 9.21327 20.714 9.28977 20.6759 9.38642L19.5996 12.1155C19.4747 12.432 19.0267 12.432 18.9019 12.1155L17.8255 9.38642C17.7874 9.28977 17.7109 9.21327 17.6143 9.17515L14.8852 8.09883C14.5687 7.97399 14.5687 7.52598 14.8852 7.40114L17.6143 6.32482C17.7109 6.2867 17.7874 6.2102 17.8255 6.11355L18.9019 3.3845Z" fill="currentColor"/>
<path d="M14.9994 13.2862C15.5089 12.8859 15.5089 12.1141 14.9995 11.7137L10.618 8.27047C9.96188 7.75485 9.00011 8.22225 9.00011 9.05673L9.00011 15.9429C9.00011 16.7773 9.96185 17.2448 10.618 16.7292L14.9994 13.2862Z" fill="currentColor"/>
  </symbol>
  <symbol
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
    viewBox="0 0 24 24"
    id="${He}/audio"
  >
  <path d="M6 3.80273C4.2066 4.84016 3 6.77919 3 9.00004V12.8153C3 15.931 5.39501 18.4873 8.44444 18.7436V20.9645C8.44444 22.2198 9.89427 22.9198 10.8773 22.1392L15.1265 18.7647H15.5C17.8285 18.7647 19.8472 17.4384 20.8417 15.5H18.4187C17.6889 16.2784 16.6512 16.7647 15.5 16.7647H14.9522C14.6134 16.7647 14.2846 16.8794 14.0193 17.0901L10.4444 19.929V18.2597C10.4444 17.4341 9.77513 16.7647 8.9495 16.7647C7.80494 16.7647 6.77409 16.2779 6.05276 15.5H6V15.4419C5.37798 14.7439 5 13.8237 5 12.8153V9.00004C5 7.98559 5.37764 7.05935 6 6.35422V3.80273Z" fill="currentColor"/>
<path d="M11.6002 1.8839C11.4753 1.56735 11.0273 1.56735 10.9025 1.8839L10.2504 3.53721C10.2123 3.63386 10.1358 3.71036 10.0392 3.74848L8.38585 4.40053C8.0693 4.52538 8.0693 4.97338 8.38585 5.09823L10.0392 5.75029C10.1358 5.7884 10.2123 5.86491 10.2504 5.96155L10.9025 7.61486C11.0273 7.93142 11.4753 7.93142 11.6002 7.61486L12.2522 5.96155C12.2904 5.86491 12.3669 5.7884 12.4635 5.75029L14.1168 5.09823C14.4334 4.97338 14.4334 4.52538 14.1168 4.40053L12.4635 3.74848C12.3669 3.71036 12.2904 3.63386 12.2522 3.53721L11.6002 1.8839Z" fill="currentColor"/>
<path d="M19.5996 4.3845C19.4747 4.06795 19.0267 4.06795 18.9019 4.3845L17.8255 7.11355C17.7874 7.2102 17.7109 7.2867 17.6143 7.32482L14.8852 8.40114C14.5687 8.52598 14.5687 8.97399 14.8852 9.09883L17.6143 10.1752C17.7109 10.2133 17.7874 10.2898 17.8255 10.3864L18.9019 13.1155C19.0267 13.432 19.4747 13.432 19.5996 13.1155L20.6759 10.3864C20.714 10.2898 20.7905 10.2133 20.8872 10.1752L23.6162 9.09883C23.9328 8.97399 23.9328 8.52598 23.6162 8.40114L20.8872 7.32482C20.7905 7.2867 20.714 7.2102 20.6759 7.11355L19.5996 4.3845Z" fill="currentColor"/>
  </symbol>
  <symbol
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
    viewBox="0 0 24 24"
    id="@imgly/MixingPlate"
  >
  <path d="M9.75 9C10.5784 9 11.25 8.32843 11.25 7.5C11.25 6.67157 10.5784 6 9.75 6C8.92157 6 8.25 6.67157 8.25 7.5C8.25 8.32843 8.92157 9 9.75 9Z" fill="currentColor"/>
<path d="M7 13C7.82843 13 8.5 12.3284 8.5 11.5C8.5 10.6716 7.82843 10 7 10C6.17157 10 5.5 10.6716 5.5 11.5C5.5 12.3284 6.17157 13 7 13Z" fill="currentColor"/>
<path d="M15.75 7.5C15.75 8.32843 15.0784 9 14.25 9C13.4216 9 12.75 8.32843 12.75 7.5C12.75 6.67157 13.4216 6 14.25 6C15.0784 6 15.75 6.67157 15.75 7.5Z" fill="currentColor"/>
<path d="M17 13C17.8284 13 18.5 12.3284 18.5 11.5C18.5 10.6716 17.8284 10 17 10C16.1716 10 15.5 10.6716 15.5 11.5C15.5 12.3284 16.1716 13 17 13Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.26309 2.77709C10.6681 1.77921 13.4829 1.7322 15.9209 2.64297C18.1572 3.47923 20.0876 5.09285 21.1766 7.28598C22.3395 9.62772 22.4889 13.1077 20.3864 15.2982C19.2693 16.4621 17.7657 16.9982 16.0026 16.9997C15.7897 16.9997 15.5555 16.9864 15.3497 16.9745C15.309 16.9722 15.2694 16.9699 15.2313 16.9679C14.9817 16.9542 14.761 16.9455 14.5569 16.9539C14.124 16.9718 13.9598 17.0612 13.89 17.1324C13.718 17.3081 13.6946 17.6672 13.8854 17.8895C14.2899 18.3608 14.5016 18.9277 14.5016 19.5497C14.5016 20.2206 14.3086 20.9011 13.7542 21.3896C13.2471 21.837 12.6082 21.9997 11.9635 21.9997C10.6049 21.9997 9.31155 21.7367 8.0934 21.2067C6.89058 20.6831 5.84501 19.9687 4.94363 19.0666C4.04281 18.1651 3.31836 17.107 2.79369 15.8978C1.72761 13.4409 1.72662 10.5261 2.81247 8.07034C3.88024 5.65548 5.84206 3.78161 8.26309 2.77709ZM15.2207 4.51639C13.2556 3.78239 10.9651 3.82132 9.02956 4.62439C7.06888 5.43791 5.49559 6.94785 4.64163 8.87914C3.78373 10.8194 3.78253 13.1522 4.62841 15.1017C5.05312 16.0805 5.63511 16.9291 6.35838 17.6529C7.08102 18.3761 7.91671 18.9484 8.89123 19.3728C9.8492 19.7895 10.87 19.9997 11.9635 19.9997C12.2815 19.9997 12.394 19.9225 12.431 19.8899L12.4319 19.8891C12.4367 19.8849 12.4487 19.8743 12.4631 19.8359C12.4799 19.7911 12.5016 19.7024 12.5016 19.5497C12.5016 19.4091 12.4633 19.3034 12.3677 19.192C11.5353 18.222 11.5272 16.6868 12.4611 15.7331C13.0741 15.1071 13.8844 14.98 14.4745 14.9556C14.7819 14.943 15.085 14.9568 15.3409 14.9709C15.3906 14.9736 15.4379 14.9763 15.4832 14.9788C15.6876 14.9904 15.8508 14.9997 16.0009 14.9997C17.3405 14.9986 18.2792 14.6054 18.9435 13.9133C20.2633 12.5382 20.3186 10.055 19.3853 8.1755C18.5436 6.48051 17.0293 5.19281 15.2207 4.51639Z" fill="currentColor"/>

  </symbol>
</svg>
`,al=ol;function ll(e){return async(t,r,i)=>e.enable?(console.log(`[DRY RUN]: Requesting dummy AI generation for kind '${e.kind}' with inputs: `,JSON.stringify(t,void 0,2)),await sr(2e3),await sl(t,e,r)):i(t,r)}async function sl(e,t,r){switch(t.kind){case"image":return ul(e,t,r);case"video":return cl(e,t,r);case"text":return dl(e,t,r);case"audio":return pl(e,t,r);default:throw new Error(`Unsupported output kind for creating dry run output: ${t.kind}`)}}async function ul(e,t,{engine:r}){let i,n,a=e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"?e.prompt:"AI Generated Image",o=a.match(/(\d+)x(\d+)/);if(o!=null)i=parseInt(o[1],10),n=parseInt(o[2],10);else if(t.blockInputs!=null&&(i=t.blockInputs.image.width,n=t.blockInputs.image.height),t.blockIds!=null&&Array.isArray(t.blockIds)&&t.blockIds.length>0){let[s]=t.blockIds,c=await ua(s,r),l=await Xe(c,r);i=l.width,n=l.height}else i=512,n=512;return{kind:"image",url:`https://placehold.co/${i}x${n}/000000/FFF?text=${a.replace(" ","+").replace(`
`,"+")}`}}async function cl(e,t,r){return Promise.resolve({kind:"video",url:"https://storage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4"})}async function dl(e,t,r){let i="";if(t.blockIds&&t.blockIds.length>0){let[o]=t.blockIds;r.engine.block.isValid(o)&&(i=r.engine.block.getString(o,"text/text"))}if(!i&&e!=null&&typeof e=="object"&&"prompt"in e&&typeof e.prompt=="string"){let o=e.prompt,s=o.match(/text:\s*"([^"]+)"/i)||o.match(/content:\s*"([^"]+)"/i)||o.match(/"([^"]+)"/);s&&s[1]&&(i=s[1])}let n=i.length||50,a="";if(e!=null&&typeof e=="object")if("language"in e&&typeof e.language=="string")a=oe(n,"translation");else if("type"in e&&typeof e.type=="string"){let o=e.type;a=oe(n,o)}else"customPrompt"in e?a=oe(n,"custom"):a=oe(n,"improved");else a=oe(n,"generated");return gl(a,r.abortSignal)}async function*gl(e,t){let r=Math.max(1,Math.ceil(e.length/20)),i=0;for(;i<e.length;){if(t?.aborted)return;let n=Math.min(i+r,e.length);yield{kind:"text",text:e.substring(0,n)},i=n,i<e.length&&await sr(100)}return{kind:"text",text:e}}function oe(e,t){let r="[DRY RUN - Dummy Text] ",i=r.length;if(e<=i)return r.substring(0,e);let n=e-i,a={translation:"Ceci est un texte fictif traduit qui maintient la longueur approximative.",professional:"Enhanced professional content with improved clarity and structure.",casual:"Relaxed, friendly text that keeps things simple and approachable.",formal:"Refined formal documentation that preserves original structure.",humorous:"Amusing content that brings lighthearted fun to the text.",improved:"Enhanced text that demonstrates better clarity and readability.",custom:"Customized content reflecting the requested modifications.",generated:"AI-generated content maintaining original length and structure."},o=a[t]||a.generated,s="";if(n<=o.length)s=o.substring(0,n);else{s=o;let c=[" Additional content continues with similar phrasing."," Further elaboration maintains the established tone."," Extended content preserves the original style."," Continued text follows the same pattern."],l=0;for(;s.length<n;){let u=c[l%c.length];if(s.length+u.length<=n)s+=u;else{s+=u.substring(0,n-s.length);break}l++}}return r+s}async function pl(e,t,r){let i=3;if(e!=null&&typeof e=="object"){if("duration"in e&&typeof e.duration=="number")i=e.duration;else if("prompt"in e&&typeof e.prompt=="string"){let n=e.prompt.match(/(\d+)\s*(?:seconds?|secs?|s)\b/i);n&&(i=parseInt(n[1],10))}}return t.blockInputs?.audio?.duration&&(i=t.blockInputs.audio.duration),{kind:"audio",url:fl(220,i),duration:i,thumbnailUrl:void 0}}function fl(e,t){let r=Math.floor(44100*t),i=new Float32Array(r);for(let n=0;n<r;n++)i[n]=Math.sin(2*Math.PI*e*n/44100);return ml(i,44100)}function ml(e,t){let r=e.length,i=2,n=1,a=n*i,o=t*a,s=r*i,c=44+s,l=new ArrayBuffer(c),u=new DataView(l),d=(f,y)=>{for(let b=0;b<y.length;b++)u.setUint8(f+b,y.charCodeAt(b))};d(0,"RIFF"),u.setUint32(4,c-8,!0),d(8,"WAVE"),d(12,"fmt "),u.setUint32(16,16,!0),u.setUint16(20,1,!0),u.setUint16(22,n,!0),u.setUint32(24,t,!0),u.setUint32(28,o,!0),u.setUint16(32,a,!0),u.setUint16(34,16,!0),d(36,"data"),u.setUint32(40,s,!0);let g=44;for(let f=0;f<r;f++){let y=Math.max(-1,Math.min(1,e[f])),b=Math.round(y*32767);u.setInt16(g,b,!0),g+=2}let p=new Uint8Array(l),h="";for(let f=0;f<p.length;f++)h+=String.fromCharCode(p[f]);return`data:audio/wav;base64,${btoa(h)}`}async function sr(e){return new Promise(t=>{setTimeout(t,e)})}var hl=ll,ur="USER_CANCEL";function yl(e){return async(t,r)=>{if(r?.abortSignal?.aborted)return{status:"aborted"};let i=da([...e.provider.output.middleware??[],...r?.middlewares??[],pa({enable:r?.debug}),hl({enable:r?.dryRun,kind:e.provider.kind})]),n={prevented:!1},a={blockIds:r?.blockIds,abortSignal:r?.abortSignal,engine:e.engine,cesdk:e.cesdk,preventDefault:()=>{n.prevented=!0},defaultPrevented:()=>n.prevented};try{let{result:o}=await i(e.provider.output.generate)(t,a);return r?.abortSignal?.aborted?{status:"aborted",middlewareOptions:a}:o instanceof Error?{status:"error",message:o.message,error:o,middlewareOptions:a}:o==null?{status:"error",message:"No output generated",middlewareOptions:a}:ya(o)?{status:"success",type:"async",output:o,middlewareOptions:a}:{status:"success",type:"sync",output:o,middlewareOptions:a}}catch(o){return it(o)?{status:"aborted",message:o.message,middlewareOptions:a}:o===ur?{status:"aborted",message:o,middlewareOptions:a}:{status:"error",message:o instanceof Error?o.message:String(o),error:o,middlewareOptions:a}}}}var bl=yl;async function vl(e,t,r,i){let n={...i,provider:t},a={provider:t,panelInput:t.input?.panel,options:{cesdk:r.cesdk,engine:r.cesdk.engine},config:n,providerConfig:t.configuration};if(await t.initialize?.({...r,engine:r.cesdk.engine}),t.input?.quickActions?.supported){let d=t.kind,g=Le.get();Object.keys(t.input.quickActions.supported).forEach(p=>{if(!g.getBy({id:p,type:"quick"})[0]){let h=`ly.img.plugin-ai-${d}-generation-web.quickAction.${p}`;r.cesdk.feature.enable(h,!0)}})}let o=rl(a),s=nl(a,o);a.options.historyAssetSourceId=o,a.options.historyAssetLibraryEntryId=s;let c=bl({provider:t,cesdk:r.cesdk,engine:r.cesdk.engine}),l=await el(a,c);ba(r.cesdk,"@imgly/plugin-ai-generation",al);let u={provider:t,panel:{builderRenderFunction:l},history:{assetSourceId:o,assetLibraryEntryId:s},generate:c};return Yt.get().register(u),u}var Qe=vl;function wl(e){let{kind:t,cesdk:r,historAssetSourceIds:i}=e,n=`ly.img.ai.${t}-generation.history`;if(r.engine.asset.findAllSources().includes(n))return n;let a=new ui(n,r,i);return r.engine.asset.addSource(a),a.id}var kl=wl;function le(e,t){return[`ly.img.plugin-ai-${e}-generation-web.${t}`,`ly.img.plugin-ai-generation-web.${t}`,`ly.img.plugin-ai-generation-web.defaults.${t}`]}async function xl(e,t,r,i){let{cesdk:n}=r;L(n,{en:{"ly.img.plugin-ai-generation-web.generate":"Generate","ly.img.plugin-ai-generation-web.defaults.fromType.label":"Input","ly.img.plugin-ai-generation-web.defaults.providerSelect.label":"Provider","ly.img.plugin-ai-generation-web.defaults.fromText.label":"Text","ly.img.plugin-ai-generation-web.defaults.fromImage.label":"Image","ly.img.plugin-ai-generation-web.schema.loading.label":"Loading\u2026","ly.img.plugin-ai-generation-web.schema.error.title":"Failed to load schema","ly.img.plugin-ai-generation-web.schema.error.retry":"Retry","common.ai-generation.failed":"We couldn't generate the asset. Please try again.","ly.img.ai.error.insufficientCredits":"You've run out of AI credits. Generation is unavailable until more credits are available.","ly.img.ai.error.unauthorized":"AI generation isn't authorized. Please sign in again or contact support.","ly.img.ai.error.notAvailable":"This AI model isn't available on your current plan.","ly.img.ai.error.invalidRequest":"This request couldn't be processed. Please adjust your input and try again.","ly.img.ai.error.serviceUnavailable":"The AI service is temporarily unavailable. Please try again shortly.","ly.img.ai.error.network":"We couldn't reach the AI service. Please check your connection and try again."}});let a,o=[];if(i.debug&&console.groupCollapsed(`Initializing ${e} generation providers`),Array.isArray(t)){let l=await Promise.all(t.map(u=>Qe(e,u,r,i)));o.push(...l),a=Al({kind:e,prefix:e,providerInitializationResults:o,cesdk:n})}else{let l=await Promise.all(t.fromText.map(d=>Qe(e,d,r,i)));o.push(...l);let u=await Promise.all(t.fromImage.map(d=>Qe(e,d,r,i)));o.push(...u),a=Il({kind:e,prefix:`ly.img.ai.${e}-generation`,initializedFromTextProviders:l,initializedFromImageProviders:u,cesdk:n})}i.debug&&console.groupEnd();let s=kl({kind:e,cesdk:r.cesdk,historAssetSourceIds:o.map(l=>l.history?.assetSourceId).filter(Te)}),c;return s!=null&&(c=s,r.cesdk.ui.addAssetLibraryEntry({id:c,sourceIds:[s],sortBy:{sortKey:"insertedAt",sortingOrder:"Descending"},canRemove:!0,gridItemHeight:"square",gridBackgroundType:"cover"})),{panel:{builderRenderFunction:a},history:{assetSourceId:s,assetLibraryEntryId:c},providerInitializationResults:o}}function Il({kind:e,prefix:t,initializedFromTextProviders:r,initializedFromImageProviders:i,cesdk:n}){let a=r.length>0&&i.length>0;return o=>{let{builder:s,experimental:c,engine:l}=o,u=`ly.img.plugin-ai-${e}-generation-web.fromText`,d=n.feature.isEnabled(u,{engine:l}),g=`ly.img.plugin-ai-${e}-generation-web.fromImage`,p=n.feature.isEnabled(g,{engine:l}),h;d&&r.length>0&&(!p||i.length===0)?h="fromText":p&&i.length>0&&(!d||r.length===0)?h="fromImage":d&&p&&a&&(h="fromText");let f=c.global(`${t}.fromType`,h),y=[];f.value==="fromText"?y.push(...r):f.value==="fromImage"?y.push(...i):y.push(...r,...i);let b=r.map(({provider:T,panel:j})=>({id:T.id,label:de(T),builderRenderFunction:j?.builderRenderFunction})),I=i.map(({provider:T,panel:j})=>({id:T.id,label:de(T),builderRenderFunction:j?.builderRenderFunction})),x=o.experimental.global(`${t}.selectedProvider.fromText`,b[0]?.id),A=o.experimental.global(`${t}.selectedProvider.fromImage`,I[0]?.id),m=b.find(T=>T.id===x.value)??b[0],v=I.find(T=>T.id===A.value)??I[0],C=f.value==="fromText"?x:f.value==="fromImage"?A:void 0,w=f.value==="fromText"?m:f.value==="fromImage"?v:void 0,M=`ly.img.plugin-ai-${e}-generation-web.providerSelect`,E=n.feature.isEnabled(M,{engine:l});if(!d&&!p){s.Section(`${t}.noInputWarning.section`,{children:()=>{s.Text(`${t}.noInputWarning.text`,{content:"No input types are enabled. Please enable at least one input type (text or image) via the Feature API."})}});return}let _=d&&p&&r.length>0&&i.length>0,k=a&&_,P=y.length>1&&E;if((k||P)&&s.Section(`${t}.providerSelection.section`,{children:()=>{if(k&&s.ButtonGroup(`${t}.fromType.buttonGroup`,{inputLabel:le(e,"fromType.label"),children:()=>{d&&r.length>0&&s.Button(`${t}.fromType.buttonGroup.fromText`,{label:le(e,"fromText.label"),icon:f.value!=="fromText"&&Nt(r,o)?"@imgly/LoadingSpinner":void 0,isActive:f.value==="fromText",onClick:()=>{f.setValue("fromText")}}),p&&i.length>0&&s.Button(`${t}.fromType.buttonGroup.fromImage`,{label:le(e,"fromImage.label"),icon:f.value!=="fromImage"&&Nt(i,o)?"@imgly/LoadingSpinner":void 0,isActive:f.value==="fromImage",onClick:()=>{f.setValue("fromImage")}})}}),P){let T=f.value==="fromText"?b:f.value==="fromImage"?I:[...b,...I];C!=null&&w!=null&&s.Select(`${t}.providerSelect.select`,{inputLabel:le(e,"providerSelect.label"),values:T,value:w,setValue:j=>{C.setValue(j.id)}})}}}),y.length>1)w?.builderRenderFunction?.(o);else{let T=y[0];T&&T.panel?.builderRenderFunction?.(o)}}}function Al({kind:e,prefix:t,providerInitializationResults:r,cesdk:i}){return n=>{let{builder:a,engine:o}=n;if(r.length===0)return;let s=`ly.img.plugin-ai-${e}-generation-web.providerSelect`;e==="audio"&&t&&(t.includes("speech")?s="ly.img.plugin-ai-audio-generation-web.speech.providerSelect":t.includes("sound")&&(s="ly.img.plugin-ai-audio-generation-web.sound.providerSelect"));let c=i.feature.isEnabled(s,{engine:o}),l=r.map(({provider:g,panel:p})=>({id:g.id,label:de(g),builderRenderFunction:p?.builderRenderFunction})),u=n.state(`${t}.selectedProvider`,l[0]?.id),d=l.find(g=>g.id===u.value)??l[0];r.length>1&&c&&u!=null&&d!=null&&a.Section(`${t}.providerSelection.section`,{children:()=>{a.Select(`${t}.providerSelect.select`,{inputLabel:le(e,"providerSelect.label"),values:l,value:d,setValue:g=>{u.setValue(g.id)}})}}),d?.builderRenderFunction?.(n)}}function Nt(e,t){return e.length===0?!1:e.some(({provider:r})=>r.id==null?!1:t.experimental.global(ot(r.id),!1).value)}var cr=xl,he="ly.img.ai.editMode",dr="ly.img.ai.metadata";async function Cl(e){let t=`ly.img.ai.${e.kind}.confirmation`;e.cesdk&&L(e.cesdk,{en:{"ly.img.ai.processing":"Generating...",[`${t}.cancel`]:"Cancel Generation",[`${t}.apply`]:"Apply Generation",[`${t}.before`]:"Before",[`${t}.after`]:"After"}});let r=i=>{let{engine:n,builder:a,state:o,payload:s}=i;if(s==null)return;let c=n.block.findAllSelected();if(c.length===0)return null;let l=new Ft(n,dr),u=l.get(c[0]);if(u==null)return null;let d=()=>{c.forEach(g=>{l.clear(g)})};switch(u.status){case"processing":{a.Button(`${t}.spinner`,{label:[`ly.img.ai.${u.quickActionId}.processing`,"ly.img.ai.processing"],isLoading:!0}),a.Separator(`${t}.separator`),a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{s.onCancelGeneration?.(),d()}});break}case"confirmation":{let g=o(`${t}.comparing`,"after"),p=s.applyCallbacks?.onCancel;p!=null&&a.Button(`${t}.cancel`,{icon:"@imgly/Cross",tooltip:`${t}.cancel`,onClick:()=>{p(),d()}});let h=s.applyCallbacks?.onBefore,f=s.applyCallbacks?.onAfter;h!=null&&f!=null&&a.ButtonGroup(`${t}.compare`,{children:()=>{a.Button(`${t}.compare.before`,{label:`${t}.before`,variant:"regular",isActive:g.value==="before",onClick:()=>{h(),g.setValue("before")}}),a.Button(`${t}.compare.after`,{label:`${t}.after`,variant:"regular",isActive:g.value==="after",onClick:()=>{f(),g.setValue("after")}})}});let y=s.applyCallbacks?.onApply;y!=null&&a.Button(`${t}.apply`,{icon:"@imgly/Checkmark",tooltip:`${t}.apply`,color:"accent",isDisabled:g.value!=="after",onClick:()=>{d();let b=e.cesdk.engine.editor;typeof b._update=="function"&&b._update(),y()}});break}default:}};return Promise.resolve(r)}var Sl=Cl;function $l(e){if(e.length===0)return[];let t=[...e];for(;t.length>0&&t[0]==="ly.img.separator";)t.shift();for(;t.length>0&&t[t.length-1]==="ly.img.separator";)t.pop();return t.reduce((r,i)=>(i==="ly.img.separator"&&r.length>0&&r[r.length-1]==="ly.img.separator"||r.push(i),r),[])}var El=$l;function Tl(e){return`ly.img.ai.${e}.canvasMenu`}var Ll=Tl;function Ml(e){if(typeof e=="string")return e;if(e!=null&&typeof e=="object"&&"id"in e&&typeof e.id=="string")return e.id}function Ot(e){let t=[];for(let r of e){let i=Ml(r);i!=null&&t.push(i)}return t}function _l(e){let{kind:t,cesdk:r,payload:i,defaultOrder:n}=e,a=Ll(t);if(i==null||!Array.isArray(i.children)){let o=r.ui.getCanvasMenuOrder().find(({id:s})=>s===a);return o!=null&&Array.isArray(o.children)?Ot(o.children):n??[]}return Ot(i.children)}var jl=_l;function Pl(e,t){if(t.blockIds.some(r=>!t.cesdk.engine.block.isValid(r)))return Promise.resolve({applyCallbacks:{onBefore:()=>{},onAfter:()=>{},onCancel:()=>{},onApply:()=>{}}});switch(t.kind){case"text":return Dl(e,t);case"image":return Nl(e,t);case"video":return Ol(e,t);case"audio":return Rl(e,t);default:throw new Error(`Unsupported output kind for quick actions: ${t.kind}`)}}async function Dl(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t,a=i.map(l=>r.engine.block.getString(l,"text/text")),o;if(e.type==="async"){let l="";for await(let u of e.output){if(n?.aborted)break;typeof u=="string"?l=u:u.kind==="text"&&(l=u.text),i.forEach(d=>{r.engine.block.setString(d,"text/text",l)}),o={kind:"text",text:l}}}else o=e.output;if(o==null||o.kind!=="text")throw new Error("Output kind from generation is not text");e.type==="sync"&&i.forEach(l=>{r.engine.block.setString(l,"text/text",o.text)});let s=()=>{t.blockIds.forEach(l=>{t.cesdk.engine.block.setString(l,"text/text",o.text)})},c=()=>{t.blockIds.forEach((l,u)=>{t.cesdk.engine.block.setString(l,"text/text",a[u])})};return{applyCallbacks:{onBefore:c,onAfter:s,onCancel:c,onApply:()=>{s(),t.cesdk.engine.editor.addUndoStep()}}}}async function Nl(e,t){let{cesdk:r,blockIds:i,abortSignal:n}=t;if(i.length!==1)throw new Error("Only one block is supported for image generation");let[a]=i,o=r.engine.block.getFill(a),s=r.engine.block.getSourceSet(o,"fill/image/sourceSet"),[c]=s,l=r.engine.block.getString(o,"fill/image/imageFileURI"),u=r.engine.block.getString(o,"fill/image/previewFileURI"),d=r.engine.block.getContentFillMode(a),g=await r.engine.editor.getMimeType(c?.uri??l),p=await Xe(c?.uri??l,t.cesdk.engine),h=p.width/p.height;if(n?.throwIfAborted(),g==="image/svg+xml")throw new Error("SVG images are not supported");let f=r.engine.block.getCropScaleX(a),y=r.engine.block.getCropScaleY(a),b=r.engine.block.getCropTranslationX(a),I=r.engine.block.getCropTranslationY(a),x=r.engine.block.getCropRotation(a),A=()=>{r.engine.block.setCropScaleX(a,f),r.engine.block.setCropScaleY(a,y),r.engine.block.setCropTranslationX(a,b),r.engine.block.setCropTranslationY(a,I),r.engine.block.setCropRotation(a,x),r.engine.block.setContentFillMode(a,d)};if(e.type==="async")throw new Error("Streaming generation is not supported yet from a panel");if(e.output.kind!=="image"||typeof e.output.url!="string")throw new Error("Output kind from generation is not an image");let m=e.output.url,v=await Xe(m,t.cesdk.engine),C=v.width/v.height,w=Math.abs(h-C)>.001,M=c?[{uri:m,width:v.width,height:v.height}]:void 0,E=m,_=()=>{M==null?r.engine.block.setString(o,"fill/image/imageFileURI",E):(r.engine.block.setString(o,"fill/image/imageFileURI",""),r.engine.block.setSourceSet(o,"fill/image/sourceSet",M)),r.engine.block.setString(o,"fill/image/previewFileURI","")};_(),await r.engine.block.forceLoadResources([o]),w?r.engine.block.setContentFillMode(a,"Cover"):A();let k=()=>{if(s==null||s.length===0){if(l==null)throw new Error("No image URI found");r.engine.block.setString(o,"fill/image/imageFileURI",l)}else r.engine.block.setSourceSet(o,"fill/image/sourceSet",s),r.engine.block.setString(o,"fill/image/imageFileURI",l);r.engine.block.setString(o,"fill/image/previewFileURI",u),A()},P=()=>{_(),w?r.engine.block.setContentFillMode(a,"Cover"):A()};return{applyCallbacks:{onBefore:k,onAfter:P,onCancel:()=>{k()},onApply:()=>{P(),t.cesdk.engine.editor.addUndoStep()}}}}async function Ol(e,t){throw new Error("Function not implemented.")}async function Rl(e,t){throw new Error("Function not implemented.")}var Fl=Pl;function zl(e){let{engine:t,blockIdsToLock:r,editModeToLockTo:i}=e;function n(){let c=t.block.findAllSelected();return r.some(l=>c.includes(l))}let a=t.editor.onStateChanged(()=>{t.editor.getEditMode()!==i&&n()&&t.editor.setEditMode(i)}),o=t.block.onSelectionChanged(()=>{n()?t.editor.setEditMode(i):t.editor.setEditMode("Transform")});n()&&t.editor.setEditMode(i);let s=!1;return()=>{s||(o(),a(),t.editor.setEditMode("Transform"),s=!0)}}var Ul=zl,Vl=class gr{constructor(){this.actions=new Map}static get(){let t="__imgly_callbacks_registry__",r=typeof window<"u"?window:globalThis;return r[t]||(r[t]=new gr),r[t]}register(t,r){let i=this.actions.get(t)??{};this.actions.set(t,{...i,...r})}get(t){return this.actions.get(t)??{}}},U=Vl;function Bl(e){return async(t,r)=>{let i=r?.blockIds??e.blockIds;if(e.providerInitializationResult==null)return e.debug&&console.warn("[Generate] No provider initialization result found for quick action. Returning abortion status."),{status:"aborted"};let n=e.providerInitializationResult?.provider.input?.quickActions?.supported?.[e.quickAction.id];if(n==null)throw new Error("[Generate] Quick action input mapping failed. Ensure the provider supports this quick action.");let a=typeof n=="object"&&n!==null&&"mapInput"in n?n.mapInput:u=>u;e.close();let o=new AbortController,s=AbortSignal.any([e.abortSignal,o.signal].filter(Te)),c=new Ft(e.cesdk.engine,dr),l=e.lock??!0?Ul({engine:e.cesdk.engine,editModeToLockTo:he,blockIdsToLock:i}):()=>{};i.forEach(u=>{U.get().register(u,{onCancelGeneration:()=>{o.abort(ur),l(),e.cesdk.engine.block.isValid(u)&&(e.cesdk.engine.block.isValid(u)&&e.cesdk.engine.block.setState(u,{type:"Ready"}),c.clear(u))}})}),i?.forEach(u=>{c.set(u,{status:"processing",quickActionId:e.quickAction.id})}),i.forEach(u=>{e.cesdk.engine.block.isValid(u)&&e.cesdk.engine.block.setState(u,{type:"Pending",progress:0})});try{let u=await e.providerInitializationResult.generate(a(t),{blockIds:i,middlewares:[...e.middlewares??[]],debug:e.debug,dryRun:e.dryRun,abortSignal:s}),d=u.status;switch(d){case"success":{let{applyCallbacks:g}=await Fl(u,{kind:e.providerInitializationResult.provider.kind,blockIds:i,cesdk:e.cesdk,abortSignal:s});if(i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&e.cesdk.engine.block.setState(p,{type:"Ready"})}),e.confirmation){i.forEach(h=>{c.set(h,{status:"confirmation",quickActionId:e.quickAction.id})});let p={...g,onApply:async()=>{g.onApply(),l()},onCancel:()=>{g.onCancel(),l()}};i.forEach(h=>{U.get().register(h,{applyCallbacks:p})})}else i.forEach(p=>{e.cesdk.engine.block.isValid(p)&&c.clear(p)}),g.onApply(),l();return u}case"aborted":return e.debug&&console.log("Generation was aborted"),l(),i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&c.clear(g)}),u;case"error":return l(),i.forEach(g=>{e.cesdk.engine.block.isValid(g)&&c.clear(g)}),et(u.error??u.message,{cesdk:e.cesdk,provider:e.providerInitializationResult.provider,middlewareOptions:u.middlewareOptions}),u;default:throw new Error(`[Generate] Unknown result status ${d}.`)}}catch(u){throw e.cesdk.ui.showNotification({type:"error",message:"A technical issue has occurred."}),l(),i.forEach(d=>{e.cesdk.engine.block.isValid(d)&&c.clear(d)}),u}finally{i.forEach(u=>{e.cesdk.engine.block.isValid(u)&&e.cesdk.engine.block.setState(u,{type:"Ready"})})}}}var Rt=Bl;function ql(e){let t=`ly.img.ai.${e.kind}}`;L(e.cesdk,{en:{"ly.img.plugin-ai-generation-web.defaults.quickAction.providerSelect.label":"Provider"}});let r=i=>{if(i.engine.editor.getEditMode()===he)return;let n=i.engine.block.findAllSelected();if(n.length===0)return;let a=`ly.img.plugin-ai-${e.kind}-generation-web.quickAction`;if(!e.cesdk.feature.isEnabled(a,{engine:e.engine}))return;let{payload:o}=i,s=jl({kind:e.kind,cesdk:e.cesdk,payload:o,defaultOrder:e.defaultOrder})??[];if(s.length===0)return;let c=Gl(s).filter(m=>{if(m==="ly.img.separator")return!0;let v=m.id.replace("ly.img.",""),C=`ly.img.plugin-ai-${e.kind}-generation-web.quickAction.${v}`;if(!e.cesdk.feature.isEnabled(C,{engine:e.engine}))return!1;let w=m.scopes;if(w!=null&&w.length>0&&!n.every(M=>w.every(E=>e.engine.block.isAllowedByScope(M,E))))return!1;if(m.enable!=null){if(typeof m.enable=="function")return m.enable({engine:e.engine});if(typeof m.enable=="boolean")return m.enable}return!0}),l=[],u=e.providerInitializationResults.reduce((m,v)=>{if(v.provider.kind!==e.kind)return m;let C=c.map(w=>{if(w==="ly.img.separator")return w;if(v.provider.input?.quickActions?.supported?.[w.id]!=null)return{definition:w};{let M=Yt.get().getAll().filter(E=>E.provider.kind!==e.kind&&E.provider.id!==v.provider.id).find(E=>E.provider.input?.quickActions?.supported?.[w.id]!=null);if(M!=null){let E={definition:w,providerInitializationResult:M};return l.push(E),E}else return}}).filter(Te);return C=El(C),C.length===0||C.every(w=>w==="ly.img.separator")||C.every(w=>w==="ly.img.separator"||w.providerInitializationResult!=null)||m.push({providerInitializationResult:v,quickActions:C}),m},[]);if(u.length===0)if(l.length>0){let m=new Map;l.forEach(C=>{let w=C.definition.id;m.has(w)||m.set(w,C)});let v=Array.from(m.values());u.push({providerInitializationResult:v[0].providerInitializationResult??e.providerInitializationResults[0],quickActions:v})}else return;let d=u.map(({providerInitializationResult:m})=>({id:m.provider.id,label:de(m.provider)})),g=i.experimental.global(`${t}.currentProvider`,d[0]),p=u.find(({providerInitializationResult:{provider:{id:m}}})=>m===g.value?.id),h=n.every(m=>i.engine.block.getState(m).type==="Ready"),{builder:f,experimental:y,state:b}=i,I=b(`${t}.isGenerating`,!1),x=b(`${t}.toggleExpandedState`,void 0),A=async(m,v,C)=>{I.setValue(!0);try{return await C(m,v)}finally{I.setValue(!1)}};y.builder.Popover(`${t}.popover`,{icon:"@imgly/Sparkle",variant:"plain",isDisabled:!h,isLoading:I.value,trailingIcon:null,children:({close:m})=>{if(x.value!==void 0){let v=p?.quickActions.find(E=>E!=="ly.img.separator"&&E.definition.id===x.value);if(v==null||v.definition.render==null)return;let C=u.filter(({quickActions:E})=>E.some(_=>_!=="ly.img.separator"&&_.definition.id===v.definition.id)).map(({providerInitializationResult:E})=>({id:E.provider.id,label:de(E.provider)})),w=`ly.img.plugin-ai-${e.kind}-generation-web.quickAction.providerSelect`,M=e.cesdk.feature.isEnabled(w,{engine:e.engine});C.length>1&&M&&f.Section(`${t}.popover.expanded.header`,{children:()=>{f.Select(`${t}.expanded.providerSelect.select`,{inputLabel:[`ly.img.plugin-ai-${e.kind}-generation-web.quickAction.providerSelect.label`,"ly.img.plugin-ai-generation-web.defaults.quickAction.providerSelect.label"],values:C,...g})}}),f.Section(`${t}.popover.expanded.section`,{children:()=>v.definition.render({...i,toggleExpand:()=>{x.setValue(void 0)},isExpanded:!0,generate:Rt({blockIds:n,providerInitializationResult:v.providerInitializationResult??p?.providerInitializationResult,quickAction:v.definition,middlewares:[A],confirmation:v.definition.defaults?.confirmation??!0,lock:v.definition.defaults?.lock??!0,close:m,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:m,providerId:g.value.id})})}else{let v=`ly.img.plugin-ai-${e.kind}-generation-web.quickAction.providerSelect`,C=e.cesdk.feature.isEnabled(v,{engine:e.engine});d.length>1&&C&&f.Section(`${t}.popover.header`,{children:()=>{f.Select(`${t}.providerSelect.select`,{inputLabel:[`ly.img.plugin-ai-${e.kind}-generation-web.quickAction.providerSelect.label`,"ly.img.plugin-ai-generation-web.defaults.quickAction.providerSelect.label"],values:d,...g})}}),f.Section(`${t}.popover.section`,{children:()=>{y.builder.Menu(`${t}.menu`,{children:()=>{p?.quickActions.forEach(w=>{if(w==="ly.img.separator"){f.Separator(`${t}.separator.${Math.random().toString()}`);return}w.definition.render!=null&&w.definition.render({...i,toggleExpand:()=>{x.setValue(w.definition.id)},isExpanded:!1,generate:Rt({blockIds:n,providerInitializationResult:w.providerInitializationResult??p?.providerInitializationResult,quickAction:w.definition,middlewares:[A],confirmation:w.definition.defaults?.confirmation??!0,close:m,cesdk:e.cesdk,debug:e.debug,dryRun:e.dryRun}),close:m,providerId:g.value.id})})}})}})}}})};return Promise.resolve(r)}function Gl(e){return e.map(t=>t==="ly.img.separator"?t:Le.get().getBy({id:t,type:"quick"})[0]).filter(Te)}var Hl=ql;async function Ql(e){let t=await Hl({kind:e.kind,providerInitializationResults:e.providerInitializationResults,cesdk:e.cesdk,engine:e.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:e.defaultOrder}),r=await Sl({kind:e.kind,cesdk:e.cesdk});return{renderFunction:i=>{let{engine:n}=i;if(n.editor.getEditMode()===he){let a=i.engine.block.findAllSelected();r({...i,payload:{...i.payload??{},applyCallbacks:{onBefore:()=>{a.forEach(o=>{U.get().get(o).applyCallbacks?.onBefore?.()})},onAfter:()=>{a.forEach(o=>{U.get().get(o).applyCallbacks?.onAfter?.()})},onCancel:()=>{a.forEach(o=>{U.get().get(o).applyCallbacks?.onCancel?.()})},onApply:()=>{a.forEach(o=>{U.get().get(o).applyCallbacks?.onApply?.()})}},onCancelGeneration:()=>{a.forEach(o=>{U.get().get(o).onCancelGeneration?.()})}}});return}t(i)}}}var pr=Ql;var Ud=5*60*1e3;var Zl=typeof global=="object"&&global&&global.Object===Object&&global,Er=Zl,Yl=typeof self=="object"&&self&&self.Object===Object&&self,Kl=Er||Yl||Function("return this")(),O=Kl,Wl=O.Symbol,X=Wl,Tr=Object.prototype,Jl=Tr.hasOwnProperty,Xl=Tr.toString,ye=X?X.toStringTag:void 0;function es(e){var t=Jl.call(e,ye),r=e[ye];try{e[ye]=void 0;var i=!0}catch{}var n=Xl.call(e);return i&&(t?e[ye]=r:delete e[ye]),n}var ts=es,rs=Object.prototype,is=rs.toString;function ns(e){return is.call(e)}var os=ns,as="[object Null]",ls="[object Undefined]",fr=X?X.toStringTag:void 0;function ss(e){return e==null?e===void 0?ls:as:fr&&fr in Object(e)?ts(e):os(e)}var ke=ss;function us(e){return e!=null&&typeof e=="object"}var pt=us,Hd=Array.isArray;function cs(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Lr=cs,ds="[object AsyncFunction]",gs="[object Function]",ps="[object GeneratorFunction]",fs="[object Proxy]";function ms(e){if(!Lr(e))return!1;var t=ke(e);return t==gs||t==ps||t==ds||t==fs}var hs=ms,ys=O["__core-js_shared__"],at=ys,mr=function(){var e=/[^.]+$/.exec(at&&at.keys&&at.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function bs(e){return!!mr&&mr in e}var vs=bs,ws=Function.prototype,ks=ws.toString;function xs(e){if(e!=null){try{return ks.call(e)}catch{}try{return e+""}catch{}}return""}var B=xs,Is=/[\\^$.*+?()[\]{}|]/g,As=/^\[object .+?Constructor\]$/,Cs=Function.prototype,Ss=Object.prototype,$s=Cs.toString,Es=Ss.hasOwnProperty,Ts=RegExp("^"+$s.call(Es).replace(Is,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Ls(e){if(!Lr(e)||vs(e))return!1;var t=hs(e)?Ts:As;return t.test(B(e))}var Ms=Ls;function _s(e,t){return e?.[t]}var js=_s;function Ps(e,t){var r=js(e,t);return Ms(r)?r:void 0}var ee=Ps,Ds=ee(O,"WeakMap"),st=Ds;function Ns(e,t){return e===t||e!==e&&t!==t}var Os=Ns,Rs=9007199254740991;function Fs(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Rs}var zs=Fs;var Qd=Object.prototype;var Us="[object Arguments]";function Vs(e){return pt(e)&&ke(e)==Us}var hr=Vs,Mr=Object.prototype,Bs=Mr.hasOwnProperty,qs=Mr.propertyIsEnumerable,Zd=hr(function(){return arguments}())?hr:function(e){return pt(e)&&Bs.call(e,"callee")&&!qs.call(e,"callee")};var _r=typeof exports=="object"&&exports&&!exports.nodeType&&exports,yr=_r&&typeof module=="object"&&module&&!module.nodeType&&module,Gs=yr&&yr.exports===_r,br=Gs?O.Buffer:void 0,Yd=br?br.isBuffer:void 0;var Hs="[object Arguments]",Qs="[object Array]",Zs="[object Boolean]",Ys="[object Date]",Ks="[object Error]",Ws="[object Function]",Js="[object Map]",Xs="[object Number]",eu="[object Object]",tu="[object RegExp]",ru="[object Set]",iu="[object String]",nu="[object WeakMap]",ou="[object ArrayBuffer]",au="[object DataView]",lu="[object Float32Array]",su="[object Float64Array]",uu="[object Int8Array]",cu="[object Int16Array]",du="[object Int32Array]",gu="[object Uint8Array]",pu="[object Uint8ClampedArray]",fu="[object Uint16Array]",mu="[object Uint32Array]",$={};$[lu]=$[su]=$[uu]=$[cu]=$[du]=$[gu]=$[pu]=$[fu]=$[mu]=!0;$[Hs]=$[Qs]=$[ou]=$[Zs]=$[au]=$[Ys]=$[Ks]=$[Ws]=$[Js]=$[Xs]=$[eu]=$[tu]=$[ru]=$[iu]=$[nu]=!1;function hu(e){return pt(e)&&zs(e.length)&&!!$[ke(e)]}var yu=hu;function bu(e){return function(t){return e(t)}}var vu=bu,jr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,be=jr&&typeof module=="object"&&module&&!module.nodeType&&module,wu=be&&be.exports===jr,lt=wu&&Er.process,ku=function(){try{var e=be&&be.require&&be.require("util").types;return e||lt&&lt.binding&&lt.binding("util")}catch{}}(),vr=ku,wr=vr&&vr.isTypedArray,Kd=wr?vu(wr):yu;var xu=Object.prototype,Wd=xu.hasOwnProperty;function Iu(e,t){return function(r){return e(t(r))}}var Au=Iu,Jd=Au(Object.keys,Object);var Cu=Object.prototype,Xd=Cu.hasOwnProperty;var Su=ee(Object,"create"),ve=Su;function $u(){this.__data__=ve?ve(null):{},this.size=0}var Eu=$u;function Tu(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Lu=Tu,Mu="__lodash_hash_undefined__",_u=Object.prototype,ju=_u.hasOwnProperty;function Pu(e){var t=this.__data__;if(ve){var r=t[e];return r===Mu?void 0:r}return ju.call(t,e)?t[e]:void 0}var Du=Pu,Nu=Object.prototype,Ou=Nu.hasOwnProperty;function Ru(e){var t=this.__data__;return ve?t[e]!==void 0:Ou.call(t,e)}var Fu=Ru,zu="__lodash_hash_undefined__";function Uu(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=ve&&t===void 0?zu:t,this}var Vu=Uu;function te(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])}}te.prototype.clear=Eu;te.prototype.delete=Lu;te.prototype.get=Du;te.prototype.has=Fu;te.prototype.set=Vu;var kr=te;function Bu(){this.__data__=[],this.size=0}var qu=Bu;function Gu(e,t){for(var r=e.length;r--;)if(Os(e[r][0],t))return r;return-1}var Me=Gu,Hu=Array.prototype,Qu=Hu.splice;function Zu(e){var t=this.__data__,r=Me(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():Qu.call(t,r,1),--this.size,!0}var Yu=Zu;function Ku(e){var t=this.__data__,r=Me(t,e);return r<0?void 0:t[r][1]}var Wu=Ku;function Ju(e){return Me(this.__data__,e)>-1}var Xu=Ju;function ec(e,t){var r=this.__data__,i=Me(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}var tc=ec;function re(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])}}re.prototype.clear=qu;re.prototype.delete=Yu;re.prototype.get=Wu;re.prototype.has=Xu;re.prototype.set=tc;var _e=re,rc=ee(O,"Map"),we=rc;function ic(){this.size=0,this.__data__={hash:new kr,map:new(we||_e),string:new kr}}var nc=ic;function oc(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var ac=oc;function lc(e,t){var r=e.__data__;return ac(t)?r[typeof t=="string"?"string":"hash"]:r.map}var je=lc;function sc(e){var t=je(this,e).delete(e);return this.size-=t?1:0,t}var uc=sc;function cc(e){return je(this,e).get(e)}var dc=cc;function gc(e){return je(this,e).has(e)}var pc=gc;function fc(e,t){var r=je(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}var mc=fc;function ie(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])}}ie.prototype.clear=nc;ie.prototype.delete=uc;ie.prototype.get=dc;ie.prototype.has=pc;ie.prototype.set=mc;var Pr=ie;function hc(){this.__data__=new _e,this.size=0}var yc=hc;function bc(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var vc=bc;function wc(e){return this.__data__.get(e)}var kc=wc;function xc(e){return this.__data__.has(e)}var Ic=xc,Ac=200;function Cc(e,t){var r=this.__data__;if(r instanceof _e){var i=r.__data__;if(!we||i.length<Ac-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Pr(i)}return r.set(e,t),this.size=r.size,this}var Sc=Cc;function xe(e){var t=this.__data__=new _e(e);this.size=t.size}xe.prototype.clear=yc;xe.prototype.delete=vc;xe.prototype.get=kc;xe.prototype.has=Ic;xe.prototype.set=Sc;var $c=Object.prototype,eg=$c.propertyIsEnumerable;var Ec=ee(O,"DataView"),ut=Ec,Tc=ee(O,"Promise"),ct=Tc,Lc=ee(O,"Set"),dt=Lc,xr="[object Map]",Mc="[object Object]",Ir="[object Promise]",Ar="[object Set]",Cr="[object WeakMap]",Sr="[object DataView]",_c=B(ut),jc=B(we),Pc=B(ct),Dc=B(dt),Nc=B(st),J=ke;(ut&&J(new ut(new ArrayBuffer(1)))!=Sr||we&&J(new we)!=xr||ct&&J(ct.resolve())!=Ir||dt&&J(new dt)!=Ar||st&&J(new st)!=Cr)&&(J=function(e){var t=ke(e),r=t==Mc?e.constructor:void 0,i=r?B(r):"";if(i)switch(i){case _c:return Sr;case jc:return xr;case Pc:return Ir;case Dc:return Ar;case Nc:return Cr}return t});var tg=O.Uint8Array;var Oc="__lodash_hash_undefined__";function Rc(e){return this.__data__.set(e,Oc),this}var Fc=Rc;function zc(e){return this.__data__.has(e)}var Uc=zc;function gt(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Pr;++t<r;)this.add(e[t])}gt.prototype.add=gt.prototype.push=Fc;gt.prototype.has=Uc;var $r=X?X.prototype:void 0,rg=$r?$r.valueOf:void 0;var Vc=Object.prototype,ig=Vc.hasOwnProperty;var Bc=Object.prototype,ng=Bc.hasOwnProperty;var og=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),ag=new RegExp(/[A-Fa-f0-9]{1}/,"g"),lg=new RegExp(/[A-Fa-f0-9]{2}/,"g");function qc(e){return e==null?[]:Array.isArray(e)?e:[e]}var Dr=qc;function Gc(e){return`
You are an AI writing assistant tasked with improving a given text based on a specific type of improvement requested. Your goal is to enhance the text while maintaining its original meaning and intent.

Here is the original text you will be working with:

<original_text>
${e}
</original_text>

Please follow these steps to improve the text:

1. Carefully read and analyze the original text.
2. Consider the specific improvement type requested and how it applies to the given text.
3. Make the necessary changes to improve the text according to the requested improvement type. This may include:
   - Rephrasing sentences
   - Adjusting vocabulary
   - Restructuring paragraphs
   - Adding or removing content as appropriate
4. Ensure that the improved version maintains the original meaning and intent of the text.
5. Return the improved text without any additional commentary or explanation.
6. If there is nothing to improve, simply return the original text without any changes.
7. If you cannot make any meaningful improvements, return the original text as is.

Once you have made the improvements, only return the improved text and nothing else.
`}var Nr=Gc;var Pe="improve",Or=`ly.img.${Pe}`,Hc=`ly.img.plugin-ai-text-generation-web.quickAction.${Pe}`,Qc=`ly.img.plugin-ai-text-generation-web.defaults.quickAction.${Pe}`;function Zc(e,t){let r="ly.img.plugin-ai-text-generation-web",i=`quickAction.${Pe}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var Yc=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.improve",!0),L(e,{en:{[`${Qc}`]:"Improve Writing"}}),{id:Or,type:"quick",kind:"text",scopes:["text/edit"],label:`${Hc}`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,providerId:o})=>{r.Button(`${Or}.button`,{label:Zc(o),icon:"@imgly/Sparkle",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[s]=n.block.findAllSelected(),c=n.block.getString(s,"text/text");await i({prompt:Nr(c)}),a()}catch(s){console.error("Generation error:",s),e.ui.showNotification({type:"error",message:s.message||"Failed to improve text. Please try again.",duration:"medium"})}}})}}),Rr=Yc;function Kc(e){return`
You are tasked with fixing spelling and grammar errors in a given text. Your goal is to improve the text while maintaining its original meaning and style. Here is the text you need to correct:

<original_text>
${e}
</original_text>

Please follow these steps to complete the task:

1. Carefully read through the text and identify any spelling or grammatical errors.

2. Correct all spelling mistakes, including typos and incorrectly spelled words.

3. Fix grammatical errors, including:
   - Incorrect verb tenses
   - Subject-verb agreement issues
   - Improper use of articles (a, an, the)
   - Incorrect word usage
   - Run-on sentences or sentence fragments
   - Punctuation errors

4. Ensure proper capitalization, especially at the beginning of sentences and for proper nouns.

5. Maintain the original meaning and tone of the text. Do not add or remove information, or change the author's intended message.

6. Make sure the corrected text flows naturally and is easy to read.

After making the necessary corrections, please provide only the improved output and nothing else.

Remember to preserve the original structure and formatting of the text as much as possible while making your corrections.
`}var Fr=Kc;var De="fix",zr=`ly.img.${De}`,Wc=`ly.img.plugin-ai-text-generation-web.quickAction.${De}`,Jc=`ly.img.plugin-ai-text-generation-web.defaults.quickAction.${De}`;function Xc(e,t){let r="ly.img.plugin-ai-text-generation-web",i=`quickAction.${De}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var ed=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.fix",!0),L(e,{en:{[`${Jc}`]:"Fix Spelling & Grammar"}}),{id:zr,type:"quick",kind:"text",scopes:["text/edit"],label:`${Wc}`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,providerId:o})=>{r.Button(`${zr}.button`,{label:Xc(o),icon:"@imgly/CheckmarkAll",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[s]=n.block.findAllSelected(),c=n.block.getString(s,"text/text");await i({prompt:Fr(c)}),a()}catch(s){console.error("Generation error:",s),e.ui.showNotification({type:"error",message:s.message||"Failed to fix text. Please try again.",duration:"medium"})}}})}}),Ur=ed;function td(e){return`
You will be given a text to shorten. Your task is to reduce the length of the text by 30% to 50% while maintaining its original voice, perspective, and key information. This is not a summary - you should preserve the style and tone of the original text.

Here is the original text:

<original_text>
${e}
</original_text>

To complete this task, follow these steps:

1. Carefully read and analyze the text, paying attention to its style, tone, and main points.

2. Identify areas where the text can be condensed without losing essential information or altering the author's voice.

3. Begin shortening the text by:
   - Removing redundant or repetitive information
   - Simplifying complex sentences
   - Eliminating unnecessary examples or elaborations
   - Combining related ideas into more concise statements

4. As you shorten, continuously check that you are:
   - Maintaining the original voice and perspective
   - Keeping all crucial information
   - Preserving the flow and coherence of the text

5. Aim to reduce the length by 30% to 50% of the original. If you find yourself shortening less than 30%, look for additional opportunities to condense. If you're reducing more than 50%, ensure you haven't cut too much important content.

6. Once you've finished shortening, review the text to ensure it still reads smoothly and retains the essence of the original.

Provide only the shortened version of the text in your response, without any additional comments, tags or explanations.
`}var Vr=td;var Ne="shorter",Br=`ly.img.${Ne}`,rd=`ly.img.plugin-ai-text-generation-web.quickAction.${Ne}`,id=`ly.img.plugin-ai-text-generation-web.defaults.quickAction.${Ne}`;function nd(e,t){let r="ly.img.plugin-ai-text-generation-web",i=`quickAction.${Ne}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var od=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.shorter",!0),L(e,{en:{[`${id}`]:"Make Shorter"}}),{id:Br,type:"quick",kind:"text",scopes:["text/edit"],label:`${rd}`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,providerId:o})=>{r.Button(`${Br}.button`,{label:nd(o),icon:"@imgly/TextShorter",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[s]=n.block.findAllSelected(),c=n.block.getString(s,"text/text");await i({prompt:Vr(c)}),a()}catch(s){console.error("Generation error:",s),e.ui.showNotification({type:"error",message:s.message||"Failed to make text shorter. Please try again.",duration:"medium"})}}})}}),qr=od;function ad(e){return`
You are tasked with expanding a given text to make it longer. Here's how to proceed:

First, you will be provided with the original text:

<original_text>
${e}
</original_text>

To expand the text:

1. Analyze the original text to understand its main ideas, tone, and style.
2. Identify areas where you can add more detail, examples, or explanations.
3. Expand on these areas by:
   - Providing more context or background information
   - Adding relevant examples or anecdotes
   - Elaborating on key points
   - Introducing related concepts or ideas
   - Explaining implications or consequences of the main ideas
4. Ensure that the expanded text length is not exceeding the original text by more than 50%.
5. Always expand the text, even if it is a single word. Explain the word with a few short sentences in that case. If the text is empty, make up a short sentence.

Guidelines:

- Maintain the original tone and style of the text.
- Ensure all additions are relevant to the main topic.
- Keep the flow of the text natural and coherent.
- Do not contradict any information in the original text.

Only return the longer text and nothing else.

Make sure to only return the expanded text and nothing else. Do not include any additional information or comments in your response about what you have done.

Do not add the original text or the original_text tags to the response.
`}var Gr=ad;var Oe="longer",Hr=`ly.img.${Oe}`,ld=`ly.img.plugin-ai-text-generation-web.quickAction.${Oe}`,sd=`ly.img.plugin-ai-text-generation-web.defaults.quickAction.${Oe}`;function ud(e,t){let r="ly.img.plugin-ai-text-generation-web",i=`quickAction.${Oe}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var cd=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.longer",!0),L(e,{en:{[`${sd}`]:"Make Longer"}}),{id:Hr,type:"quick",kind:"text",scopes:["text/edit"],label:`${ld}`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,providerId:o})=>{r.Button(`${Hr}.button`,{label:ud(o),icon:"@imgly/TextLonger",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[s]=n.block.findAllSelected(),c=n.block.getString(s,"text/text");await i({prompt:Gr(c)}),a()}catch(s){console.error("Generation error:",s),e.ui.showNotification({type:"error",message:s.message||"Failed to make text longer. Please try again.",duration:"medium"})}}})}}),Qr=cd;function dd(e,t){return`
You will be given a piece of text and a desired tone. Your task is to rewrite the text to match the desired tone while preserving the original meaning and key information. Here's how to proceed:

First, you will be provided with the original text:
<original_text>
${e}
</original_text>

The desired tone for the rewritten text is:
<desired_tone>
${t}
</desired_tone>

To change the tone of the text:
1. Analyze the current tone and style of the original text.
2. Identify the key information and main ideas in the original text.
3. Consider the characteristics of the desired tone (e.g., formal, casual, humorous, professional, etc.).
4. Rewrite the text, adapting the language, vocabulary, and sentence structure to match the desired tone while maintaining the original meaning and key information.
5. Ensure that the rewritten text flows naturally and coherently.
6. Only return the rewritten text without any additional commentary, tags or explanation.

Now, rewrite the text to match the desired tone. Your response should contain only the rewritten text, without any additional explanations or comments. Do not use any tags in your response.
`}var Zr=dd;var Re="changeTone",Ie=`ly.img.${Re}`,gd=`ly.img.plugin-ai-text-generation-web.quickAction.${Re}`,q=`ly.img.plugin-ai-text-generation-web.defaults.quickAction.${Re}`;function Yr(e,t){let r="ly.img.plugin-ai-text-generation-web",i=`quickAction.${Re}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var pd=[{id:"professional"},{id:"casual"},{id:"friendly"},{id:"serious"},{id:"humorous"},{id:"optimistic"}],fd=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.changeTone",!0),L(e,{en:{[`${q}`]:"Change Tone",[`${q}.professional`]:"Professional",[`${q}.casual`]:"Casual",[`${q}.friendly`]:"Friendly",[`${q}.serious`]:"Serious",[`${q}.humorous`]:"Humorous",[`${q}.optimistic`]:"Optimistic"}}),{id:Ie,type:"quick",kind:"text",scopes:["text/edit"],label:`${gd}`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,experimental:o,providerId:s})=>{o.builder.Popover(`${Ie}.popover`,{label:Yr(s),icon:"@imgly/Microphone",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{r.Section(`${Ie}.popover.section`,{children:()=>{o.builder.Menu(`${Ie}.popover.menu`,{children:()=>{pd.forEach(c=>{r.Button(`${Ie}.popover.menu.${c.id}`,{label:Yr(s,c.id),labelAlignment:"left",variant:"plain",onClick:async()=>{try{a();let[l]=n.block.findAllSelected(),u=n.block.getString(l,"text/text");await i({prompt:Zr(u,c.id),type:c.id})}catch(l){console.error("Generation error:",l),e.ui.showNotification({type:"error",message:l.message||"Failed to change tone. Please try again.",duration:"medium"})}}})})}})}})}})}}),Kr=fd;var Wr={en_US:"English (US)",en_UK:"English (UK)",es:"Spanish",fr:"French",de:"German",pt:"Portuguese",it:"Italian",ru:"Russian",zh:"Mandarin Chinese",ja:"Japanese"},Jr=Object.keys(Wr);function md(e,t){let r=Wr[t]||t;return`
You are a translation AI. Your task is to translate the given text into the specified target language. Follow these steps:

1. Here is the source text to be translated:
<source_text>
${e}
</source_text>

2. The target language for translation is:
<target_language>
${r}
</target_language>

3. Translate the source text into the target language. Ensure that you maintain the original meaning, tone, and style as closely as possible while adapting to the linguistic and cultural norms of the target language.

4. Return only the translated text, without any additional comments, explanations, or metadata. Do not include the original text or any other information in your response.
`}var Xr=md;var Fe="translate",Ae=`ly.img.${Fe}`,hd=`ly.img.plugin-ai-text-generation-web.quickAction.${Fe}`,D=`ly.img.plugin-ai-text-generation-web.defaults.quickAction.${Fe}`;function ei(e,t){let r="ly.img.plugin-ai-text-generation-web",i=`quickAction.${Fe}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var yd=Jr.map(e=>({id:e})),bd=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.translate",!0),L(e,{en:{[`${D}`]:"Translate",[`${D}.en_US`]:"English (US)",[`${D}.en_UK`]:"English (UK)",[`${D}.es`]:"Spanish",[`${D}.fr`]:"French",[`${D}.de`]:"German",[`${D}.pt`]:"Portuguese",[`${D}.it`]:"Italian",[`${D}.ru`]:"Russian",[`${D}.zh`]:"Mandarin Chinese",[`${D}.ja`]:"Japanese"}}),{id:Ae,type:"quick",kind:"text",scopes:["text/edit"],label:`${hd}`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,generate:i,engine:n,close:a,experimental:o,providerId:s})=>{o.builder.Popover(`${Ae}.popover`,{label:ei(s),icon:"@imgly/Language",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{r.Section(`${Ae}.popover.section`,{children:()=>{o.builder.Menu(`${Ae}.popover.menu`,{children:()=>{yd.forEach(c=>{r.Button(`${Ae}.popover.menu.${c.id}`,{label:ei(s,c.id),labelAlignment:"left",variant:"plain",onClick:async()=>{try{a();let[l]=n.block.findAllSelected(),u=n.block.getString(l,"text/text");await i({prompt:Xr(u,c.id),language:c.id})}catch(l){console.error("Generation error:",l),e.ui.showNotification({type:"error",message:l.message||"Failed to translate text. Please try again.",duration:"medium"})}}})})}})}})}})}}),ti=bd;function vd(e,t){return`
You will be given an original text and a custom prompt addition that specifies how to change the text. Your task is to modify the original text according to the prompt and return only the new, modified text.

Here is the original text:
<original_text>
${e}
</original_text>

The custom prompt addition is:
<change_text_to>
${t}
</change_text_to>

Please modify the original text according to the "Change Text to..." prompt. Only return the new, modified text without any additional commentary or explanation. Your entire response should be the modified text itself, with no other content.
`}var ri=vd;var ze="changeTextTo",z=`ly.img.${ze}`,ii=`ly.img.plugin-ai-text-generation-web.quickAction.${ze}`,ni=`ly.img.plugin-ai-text-generation-web.defaults.quickAction.${ze}`;function ft(e,t){let r="ly.img.plugin-ai-text-generation-web",i=`quickAction.${ze}`,n=t?`${i}.${t}`:i;return[`${r}.${e}.${n}`,`${r}.${n}`,`${r}.${e}.defaults.${n}`,`${r}.defaults.${n}`]}var wd=({cesdk:e})=>(e.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.changeTextTo",!0),L(e,{en:{[`${ni}`]:"Change Text to...",[`${ni}.prompt`]:"Change Text to...",[`${ii}.prompt.placeholder`]:'e.g. "a list of bullet points", "a formal announcement"'}}),{id:z,type:"quick",kind:"text",scopes:["text/edit"],label:`${ii}`,enable:({engine:r})=>{let i=r.block.findAllSelected();if(i==null||i.length!==1)return!1;let[n]=i;return r.block.getType(n)==="//ly.img.ubq/text"},render:({builder:r,experimental:i,isExpanded:n,toggleExpand:a,generate:o,engine:s,state:c,close:l,providerId:u})=>{if(n){let d=c(`${z}.prompt`,"");r.TextArea(`${z}.prompt`,{inputLabel:ft(u,"prompt"),placeholder:ft(u,"prompt.placeholder")[1],...d}),r.Separator(`${z}.separator`),i.builder.ButtonRow(`${z}.footer`,{justifyContent:"space-between",children:()=>{r.Button(`${z}.footer.cancel`,{label:"common.back",icon:"@imgly/ChevronLeft",onClick:a}),r.Button(`${z}.footer.apply`,{label:"common.apply",icon:"@imgly/MagicWand",color:"accent",isDisabled:d.value.length===0,onClick:async()=>{try{let g=d.value;if(!g)return;let[p]=s.block.findAllSelected(),h=s.block.getString(p,"text/text");await o({prompt:ri(h,g),customPrompt:g}),a(),l()}catch(g){console.error("Generation error:",g),e.ui.showNotification({type:"error",message:g.message||"Failed to change text. Please try again.",duration:"medium"})}}})}})}else r.Button(`${z}.button`,{label:ft(u),icon:"@imgly/MagicWand",labelAlignment:"left",variant:"plain",onClick:a})}}),oi=wd;var Ce="@imgly/plugin-ai-text-generation-web",Ue=["ly.img.improve","ly.img.fix","ly.img.shorter","ly.img.longer","ly.img.separator","ly.img.changeTone","ly.img.translate","ly.img.separator","ly.img.changeTextTo"];function kd(e){return{async initialize({cesdk:t}){if(t==null)return;Jt(t,Ce,"1.81.0"),t.feature.enable("ly.img.plugin-ai-text-generation-web.providerSelect",!0),t.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction",!0),t.feature.enable("ly.img.plugin-ai-text-generation-web.quickAction.providerSelect",!0),t.ui.addIconSet(mt,ht),L(t,{en:{"common.apply":"Apply","common.back":"Back"}}),xd(e);let r=Le.get();r.register(Rr({cesdk:t})),r.register(Ur({cesdk:t})),r.register(qr({cesdk:t})),r.register(Qr({cesdk:t})),r.register(Kr({cesdk:t})),r.register(ti({cesdk:t})),r.register(oi({cesdk:t}));let i=e.providers?.text2text??e.provider,n=await Promise.all(Dr(i).map(c=>c({cesdk:t})));if(!(n.length>0))return;let o=await cr("text",{fromText:n,fromImage:[]},{cesdk:t},e),s=await pr({kind:"text",providerInitializationResults:o.providerInitializationResults,cesdk:t,engine:t.engine,debug:e.debug,dryRun:e.dryRun,defaultOrder:Ue});s.renderFunction!=null&&(t.ui.registerComponent("ly.img.ai.text.canvasMenu",s.renderFunction),t.ui.setCanvasMenuOrder(["ly.img.ai.text.canvasMenu"],{editMode:he}))}}}function xd(e){e.debug&&e.providers?.text2text!=null&&e.provider!=null&&console.warn("[TextGeneration]: Both `providers.text2text` and `provider` configuration is provided. Since `provider` is deprecated, only `providers.text2text` will be used.")}var ai=kd;var Id=e=>({name:Ce,version:"1.81.0",...ai(e)}),ap=Id;export{Ue as DEFAULT_TEXT_QUICK_ACTION_ORDER,ap as default};
/*! Bundled license information:

lodash-es/lodash.js:
  (**
   * @license
   * Lodash (Custom Build) <https://lodash.com/>
   * Build: `lodash modularize exports="es" -o ./`
   * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
   * Released under MIT license <https://lodash.com/license>
   * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
   * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
   *)
*/
//# sourceMappingURL=index.mjs.map