@cesdk/cesdk-js 1.75.0-rc.5 → 1.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cesdk/cesdk-js",
3
- "version": "1.75.0-rc.5",
3
+ "version": "1.75.0",
4
4
  "module": "./index.js",
5
5
  "type": "module",
6
6
  "types": "./index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "license": "SEE LICENSE IN LICENSE.md",
41
41
  "readme": "README.md",
42
42
  "dependencies": {
43
- "@cesdk/engine": "1.75.0-rc.5"
43
+ "@cesdk/engine": "1.75.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@angular/common": ">=14.0.0",
@@ -331,6 +331,28 @@ declare interface FiltersAssetSourceConfig {
331
331
  assetLibraryEntries?: Record<string, AssetEntryId | AssetEntryId[]>;
332
332
  }
333
333
 
334
+ /** @public */
335
+ export declare const IMAGE_COLORS_SOURCE_ID = "ly.img.colors.imageColors";
336
+
337
+ /** @public */
338
+ export declare class ImageColorsAssetSource implements EditorPlugin {
339
+ name: string;
340
+ version: string;
341
+ private readonly assetLibraryEntries;
342
+ private addedSourceId;
343
+ private translate;
344
+ constructor(config?: ImageColorsAssetSourceConfig);
345
+ initialize({ engine, cesdk }: EditorPluginContext): Promise<void>;
346
+ cleanup({ engine, cesdk }: EditorPluginContext): void;
347
+ private findAssets;
348
+ private getGroups;
349
+ }
350
+
351
+ /** @public */
352
+ declare interface ImageColorsAssetSourceConfig {
353
+ assetLibraryEntries?: string[];
354
+ }
355
+
334
356
  /**
335
357
  * Known page preset asset ID patterns for GLOB matching.
336
358
  * Organized by platform and print categories.
package/plugins/index.js CHANGED
@@ -1 +1 @@
1
- import CreativeEditorSDK from"@cesdk/cesdk-js";var e=class{constructor(e={}){this.config=e}name="cesdk-blur-asset-source";version=CreativeEditorSDK.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.blur":["ly.img.blur"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.blur";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import s from"@cesdk/cesdk-js";var t="ly.img.caption.presets",r=["backgroundColor/enabled","backgroundColor/color","backgroundColor/cornerRadius","backgroundColor/paddingBottom","backgroundColor/paddingLeft","backgroundColor/paddingRight","backgroundColor/paddingTop","blend/mode","dropShadow/enabled","dropShadow/color","dropShadow/offset/x","dropShadow/offset/y","dropShadow/blurRadius/x","dropShadow/blurRadius/y","dropShadow/clip","fill/enabled","fill/solid/color","opacity","stroke/enabled","stroke/color","stroke/width","stroke/style","stroke/position","stroke/cornerGeometry","{{blockType}}/typeface","{{blockType}}/fontSize","{{blockType}}/horizontalAlignment","{{blockType}}/verticalAlignment","{{blockType}}/letterSpacing","{{blockType}}/lineHeight","{{blockType}}/automaticFontSizeEnabled","{{blockType}}/maxAutomaticFontSize","{{blockType}}/minAutomaticFontSize","{{blockType}}/paragraphSpacing"];function i(e){const s=e.scene.getCurrentPage();if(null!=s)return e.block.getChildren(s).find(s=>"//ly.img.ubq/captionTrack"===e.block.getType(s))}function o(e){const s=i(e);if(null==s)return 1;try{const t=e.block.getMetadata(s,"previousScale"),r=parseFloat(t);return Number.isNaN(r)?1:r}catch(e){return 1}}function n(e,s,t){const r=o(e),n=e.block.getTextFontSizes(s)[0]/r,a=Math.round(n*t);if(e.block.setTextFontSize(s,a),e.block.isStrokeEnabled(s)){const i=e.block.getStrokeWidth(s)/r*t;e.block.setStrokeWidth(s,i)}if(e.block.isDropShadowEnabled(s)){const i=e.block.getDropShadowOffsetX(s)/r,o=e.block.getDropShadowOffsetY(s)/r,n=e.block.getDropShadowBlurRadiusX(s)/r,a=e.block.getDropShadowBlurRadiusY(s)/r;e.block.setDropShadowOffsetX(s,i*t),e.block.setDropShadowOffsetY(s,o*t),e.block.setDropShadowBlurRadiusX(s,n*t),e.block.setDropShadowBlurRadiusY(s,a*t)}!function(e,s){const t=i(e);null!=t&&e.block.setMetadata(t,"previousScale",s.toString())}(e,t)}var a=class{engine;assets=[];customFetchImpl;baseURL;constructor(e,s,t){this.engine=e,this.baseURL=s,this.customFetchImpl=t??window.fetch.bind(window)}async initialize(){await this.fetchAssets(),this.createSource()}async fetchAssets(){const e=function(...e){return e.map((e,s)=>0===s?e.replace(/\/$/,""):e.replace(/^\//,"").replace(/\/$/,"")).join("/")}(this.baseURL,`/${t}/content.json`);try{const s=await this.customFetchImpl(e);if(!s.ok)throw new Error(s.statusText);const r=await s.json();if(void 0===r.assets)throw new Error(`Invalid content.json for assets: ${t}`);this.assets=r.assets.map(e=>(e.meta&&Object.entries(e.meta).forEach(([s,t])=>{const r=t.toString();if(r.includes("{{base_url}}")){const t=r.replace("{{base_url}}",this.baseURL).replace(/([^:])\/\/+/g,"$1/");e.meta&&(e.meta[s]=t)}}),e))}catch(e){console.warn("Could not load caption presets:",e),this.assets=[]}}createSource(){if(new Set(this.engine.asset.findAllSources()).has(t))return;const e={id:t,findAssets:e=>{const{page:s,perPage:r,excludeGroups:n,groups:a,locale:c="en",query:d,sortActiveFirst:l,sortKey:u,sortingOrder:g,tags:h}=e,f=i(this.engine),p=null!=f&&this.engine.block.hasMetadata(f,"activePreset")?this.engine.block.getMetadata(f,"activePreset"):void 0;let y=[...this.assets];if(a&&a.length>0&&(y=y.filter(e=>e.groups?.some(e=>a.includes(e)))),d&&""!==d.trim()){const e=d.toLowerCase().trim();y=y.filter(s=>(s.label?.[c]?.toLowerCase()||"").includes(e))}h&&h.length>0&&(y=y.filter(e=>(e.tags?.[c]??[]).some(e=>h.includes(e)))),n&&n.length>0&&(y=y.filter(e=>!(e.groups??[]).some(e=>n.includes(e)))),"label"===u&&"None"!==g&&y.sort((e,s)=>{const t=e.label?.[c]?.toLocaleLowerCase()||"",r=s.label?.[c]?.toLocaleLowerCase()||"";return t<r?"Ascending"===g?-1:1:t>r?"Ascending"===g?1:-1:0}),l&&p&&y.sort((e,s)=>e.id===p?-1:s.id===p?1:0);const b=y.length,m=s*r,A=m+r,k=y.slice(m,A).map(e=>{const s=e.payload?.properties?.map(e=>"caption/scale"===e.property?{...e,value:o(this.engine)}:e);return{id:e.id,label:e.label?.[c],active:e.id===p,context:{id:t},meta:e.meta,groups:e.groups,tags:e.tags?.[c],payload:{...e.payload,properties:s},locale:c}});return Promise.resolve({assets:k,total:b,currentPage:s})},getGroups:()=>{const e=new Set;return this.assets.forEach(s=>{s.groups&&s.groups.forEach(s=>{e.add(s)})}),Promise.resolve(Array.from(e))},removeAsset:e=>{const s=this.assets.findIndex(s=>s.id===e);-1!==s&&this.assets.splice(s,1)},addAsset:e=>{const s=this.assets.findIndex(s=>s.id===e.id);-1!==s?this.assets[s]=e:this.assets.push(e)},applyAssetToBlock:(e,s)=>this.applyPreset(e,s),applyAssetProperty:(e,s)=>this.applyProperty(e,s),fetchAsset:async(e,s)=>new Promise(t=>{const r=this.assets.find(s=>s.id===e);if(null==r)t(null);else{const e=s?.locale??"en",n=i(this.engine),a=null!=n&&this.engine.block.hasMetadata(n,"activePreset")?this.engine.block.getMetadata(n,"activePreset"):void 0,c=r.payload?.properties?.map(e=>"caption/scale"===e.property?{...e,value:o(this.engine)}:e);t({id:r.id,label:r.label?.[e],active:r.id===a,meta:r.meta,groups:r.groups,tags:r.tags?.[e],payload:{...r.payload,properties:c}})}})};this.engine.asset.addSource(e)}async applyPreset(e,s){const o=e?.meta?.uri;if(null==o)throw new Error(`The asset ${e.id} does not have a preset block URL.`);const n=await this.customFetchImpl(o);if(!n.ok)throw new Error(`Failed to fetch the preset block from ${o}`);const a=await n.text(),[c]=await this.engine.block.loadFromString(a),d=null!=c?this.engine.block.getType(c):void 0;if("//ly.img.ubq/text"!==d&&"//ly.img.ubq/caption"!==d)return;const l=i(this.engine),u=null!=l?this.engine.block.getChildren(l):[];r.forEach(e=>{const t=e.replace("{{blockType}}","//ly.img.ubq/text"===d?"text":"caption"),r=this.engine.block.getPropertyType(t),i=e.replace("{{blockType}}","caption");switch(r){case"Int":{const e=this.engine.block.getInt(c,t);this.engine.block.setInt(s,i,e);break}case"Float":{const e=this.engine.block.getFloat(c,t);this.engine.block.setFloat(s,i,e);break}case"Double":{const e=this.engine.block.getDouble(c,t);this.engine.block.setDouble(s,i,e);break}case"Bool":{const e=this.engine.block.getBool(c,t);this.engine.block.setBool(s,i,e);break}case"Enum":{if("stroke/position"===t)break;const e=this.engine.block.getEnum(c,t);this.engine.block.setEnum(s,i,e);break}case"Color":{if("fill/solid/color"===t){const[e]=this.engine.block.getTextColors(c);this.engine.block.setColor(s,i,e),"Text"===this.engine.editor.getEditMode()&&this.engine.editor.setEditMode("Transform"),this.engine.block.setTextColor(s,e);break}const e=this.engine.block.getColor(c,t);this.engine.block.setColor(s,i,e);break}case"String":{if("text/typeface"===t||"caption/typeface"===t){const e=this.engine.block.getTypeface(c);this.engine.block.setTypeface(s,e);break}const e=this.engine.block.getString(c,t);this.engine.block.setString(s,i,e);break}}}),e.payload?.properties?.forEach(async s=>{"Color"===s.type&&await this.applyProperty(e,s)});const[g]=this.engine.block.getTextFontWeights(c);null!=g&&this.engine.block.setTextFontWeight(s,g);const[h]=this.engine.block.getTextFontStyles(c);null!=h&&this.engine.block.setTextFontStyle(s,h),function(e,s,t){const r={in:e.block.getInAnimation(s),loop:e.block.getLoopAnimation(s),out:e.block.getOutAnimation(s)},i=(s,t)=>{const i=r[t],o=(()=>{switch(t){case"in":return e.block.getInAnimation(s);case"loop":return e.block.getLoopAnimation(s);case"out":return e.block.getOutAnimation(s);default:return}})();if(null!=o&&e.block.isValid(o)&&e.block.destroy(o),e.block.isValid(i)){const r=e.block.duplicate(i);switch(t){case"in":e.block.setInAnimation(s,r);break;case"loop":e.block.setLoopAnimation(s,r);break;case"out":e.block.setOutAnimation(s,r)}}};t.forEach(e=>{i(e,"in"),i(e,"loop"),i(e,"out")})}(this.engine,c,u),null!=l&&this.engine.block.setMetadata(l,"activePreset",e.id),this.engine.block.destroy(c),this.engine.editor.addUndoStep(),this.engine.asset.assetSourceContentsChanged(t)}async applyProperty(e,s){const r=i(this.engine);if(null==r)return;const[o]=this.engine.block.findAllSelected(),a="//ly.img.ubq/caption"===(null!=o?this.engine.block.getType(o):void 0)?o:this.engine.block.getChildren(r)[0];if(null!=a){switch(s.type){case"Color":if("fill/solid/color"===s.property){this.engine.block.setColor(a,s.property,s.value),this.engine.block.setTextColor(a,s.value);break}this.engine.block.setColor(a,s.property,s.value);break;case"Int":this.engine.block.setInt(a,s.property,s.value);break;case"Float":if("caption/scale"===s.property){n(this.engine,a,s.value);break}this.engine.block.setFloat(a,s.property,s.value);break;case"Double":this.engine.block.setDouble(a,s.property,s.value);break;case"Boolean":this.engine.block.setBool(a,s.property,s.value);break;case"Enum":this.engine.block.setEnum(a,s.property,s.value);break;case"String":this.engine.block.setString(a,s.property,s.value)}this.assets=function(e,s,t){return e.map(e=>{if("caption/scale"===t.property){const s=e.payload?.properties?.map(e=>"caption/scale"===e.property?{...e,value:t.value}:e);return{...e,payload:{...e.payload,properties:s}}}if(e.id===s.id){const s=e.payload?.properties?.map(e=>e.property===t.property?{...e,value:t.value}:e);return{...e,payload:{...e.payload,properties:s}}}return e})}(this.assets,e,s),this.engine.asset.assetSourceContentsChanged(t)}}},c=class{constructor(e={}){this.config=e}name="cesdk-caption-presets-asset-source";version=s.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.caption.presets":["ly.img.library.captionPresets"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new a(e,r,this.config.customFetchImpl);await i.initialize();const o="ly.img.caption.presets";if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}},d=class{constructor(e={}){this.config=e}name="cesdk-color-palette-asset-source";version="1.61";addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.color.palette":["ly.img.colors"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.color.palette";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import l from"@cesdk/cesdk-js";var u=class{constructor(e={}){this.config=e}name="cesdk-crop-presets-asset-source";version=l.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.crop.presets":["ly.img.cropPresets"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.crop.presets";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import g from"@cesdk/cesdk-js";var h=class{constructor(e={}){this.config=e}name="cesdk-demo-asset-sources";version=g.version;addedAssetSourceIds=[];globToRegex(e){const s=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${s}$`,"i")}sourceMatchesAnyPattern(e,s){return s.some(s=>{if(s===e||s.startsWith(`${e}.`))return!0;return this.globToRegex(s).test(e)})}filterAssetSources(e,s){return e.filter(e=>this.sourceMatchesAnyPattern(e,s))}filterMatchersForSource(e,s){return s.filter(s=>{if(s===e||s.startsWith(`${e}.`))return!0;return this.globToRegex(s).test(e)})}getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.image":["ly.img.image"],"ly.img.video":["ly.img.video"],"ly.img.audio":["ly.img.audio"],"ly.img.templates":["ly.img.templates"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o=["ly.img.audio","ly.img.video","ly.img.image","ly.img.templates"],n=this.config.include?this.filterAssetSources(o,this.config.include):o;for(const s of n)if(!i.has(s)){const t=`${r}${s}/content.json`,i=this.config.include?this.filterMatchersForSource(s,this.config.include):void 0;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:i}),this.addedAssetSourceIds.push(s)}if(s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));for(const e of this.addedAssetSourceIds){const t=this.getAssetLibraryEntries(e);for(const r of t)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:s})=>[...new Set([...s,e])]})}}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import f from"@cesdk/cesdk-js";var p=class{constructor(e={}){this.config=e}name="cesdk-effects-asset-source";version=f.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.effect":["ly.img.effect"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.effect";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import y from"@cesdk/cesdk-js";var b=class{constructor(e={}){this.config=e}name="cesdk-filters-asset-source";version=y.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.filter":["ly.img.filter"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.filter";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import m from"@cesdk/cesdk-js";var A=class{constructor(e={}){this.config=e}name="cesdk-page-presets-asset-source";version=m.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.page.presets":["ly.img.pagePresets"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.page.presets";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import k from"@cesdk/cesdk-js";var S="ly.img.templates.premium",L=class{constructor(e={}){this.config=e}name="cesdk-premium-asset-sources";version=k.version;sourceAdded=!1;globToRegex(e){const s=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${s}$`,"i")}filterMatchersForSource(e){return e.filter(e=>{if(e===S||e.startsWith(`${S}.`))return!0;return this.globToRegex(e).test(S)})}getAssetLibraryEntries(){if(this.config.assetLibraryEntries?.[S]){const e=this.config.assetLibraryEntries[S];return Array.isArray(e)?e:[e]}return["ly.img.templates"]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/");if(!new Set(e.asset.findAllSources()).has(S)){e.asset.addLocalSource(S,void 0,async s=>{if(s.meta?.uri)return await e.scene.loadFromArchiveURL(s.meta.uri),e.scene.get()??void 0});const s=`${r}${S}/content.json`,t=this.config.include?this.filterMatchersForSource(this.config.include):void 0;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:t}),this.sourceAdded=!0}if(s&&(s.onReset(()=>this.cleanup({engine:e,cesdk:s})),this.sourceAdded)){const e=this.getAssetLibraryEntries();for(const t of e)s.ui.updateAssetLibraryEntry(t,{sourceIds:({currentIds:e})=>[...new Set([...e,S])]})}}cleanup({engine:e,cesdk:s}){if(this.sourceAdded){if(s){const e=this.getAssetLibraryEntries();for(const t of e)s.ui.updateAssetLibraryEntry(t,{sourceIds:({currentIds:e})=>e.filter(e=>e!==S)})}try{e.asset.removeSource(S)}catch(e){console.warn("Unable to remove source with id: ",S)}this.sourceAdded=!1}}};import w from"@cesdk/cesdk-js";var E=class{constructor(e={}){this.config=e}name="cesdk-sticker-asset-source";version=w.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.sticker":["ly.img.sticker"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.sticker";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import I from"@cesdk/cesdk-js";var v=class{constructor(e={}){this.config=e}name="cesdk-text-asset-source";version=I.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.text":["ly.img.text"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.text";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import R from"@cesdk/cesdk-js";var U=class{constructor(e={}){this.config=e}name="cesdk-text-component-asset-source";version=R.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.text.components":["ly.img.text"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.text.components";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import $ from"@cesdk/cesdk-js";var C=class{constructor(e={}){this.config=e}name="cesdk-typeface-asset-source";version=$.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.typeface":["ly.img.typefaces"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.typeface";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};import x from"@cesdk/cesdk-js";var T=[{id:"ly.img.image.upload",mimeTypes:["image/jpeg","image/png","image/webp","image/svg+xml","image/bmp","image/gif","image/apng"],assetLibraryEntries:["ly.img.image","ly.img.upload"]},{id:"ly.img.video.upload",mimeTypes:["application/json","video/mp4","video/quicktime","video/webm","video/matroska","image/gif","image/apng"],assetLibraryEntries:["ly.img.video","ly.img.upload"]},{id:"ly.img.audio.upload",mimeTypes:["audio/mpeg","audio/mp3","audio/x-m4a","audio/wav"],assetLibraryEntries:["ly.img.audio","ly.img.upload"]}],F=class{constructor(e={}){this.config=e}name="cesdk-upload-asset-sources";version=x.version;addedAssetSourceIds=[];addedLibraryEntryMappings=new Map;isExplicitMode(){return this.config.include?.some(e=>"string"==typeof e)??!1}getExplicitIncludes(){return this.config.include?new Set(this.config.include.filter(e=>"string"==typeof e)):new Set}getCustomizations(){return this.config.include?this.config.include.filter(e=>"object"==typeof e):[]}getAssetLibraryEntries(e){return e?Array.isArray(e)?e:[e]:[]}async initialize({engine:e,cesdk:s}){const t=new Set(e.asset.findAllSources()),r=this.isExplicitMode(),i=this.getExplicitIncludes(),o=this.getCustomizations(),n=new Map;if(r)for(const e of T)i.has(e.id)&&n.set(e.id,e);else for(const e of T)n.set(e.id,e);for(const e of o){const s=n.get(e.id);s?n.set(e.id,{...s,...e}):n.set(e.id,e)}const a=Array.from(n.values());for(const r of a){const{id:i,mimeTypes:o,assetLibraryEntries:n}=r;if(!t.has(i)&&(e.asset.addLocalSource(i,o),this.addedAssetSourceIds.push(i),s)){const e=this.getAssetLibraryEntries(n);this.addedLibraryEntryMappings.set(i,e);for(const t of e)s.ui.updateAssetLibraryEntry(t,{sourceIds:({currentIds:e})=>[...new Set([...e,i])]})}}s&&s.onReset(()=>this.cleanup({engine:e,cesdk:s}))}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.addedLibraryEntryMappings.get(t)??[];for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[],this.addedLibraryEntryMappings.clear()}};import P from"@cesdk/cesdk-js";var j=class{constructor(e={}){this.config=e}name="cesdk-vectorshape-asset-source";version=P.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const s=this.config.assetLibraryEntries[e];return Array.isArray(s)?s:[s]}return{"ly.img.vector.shape":["ly.img.vector.shape","ly.img.shape.replace"]}[e]||[]}async initialize({engine:e,cesdk:s}){const t=this.config.baseURL||s?.getBaseURL()||e.editor.getSetting("basePath");if(!t)throw new Error("Cannot determine baseURL");const r=t.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.vector.shape";if(!i.has(o)){const s=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),s){s.onReset(()=>this.cleanup({engine:e,cesdk:s}));const t=this.getAssetLibraryEntries(o);for(const e of t)s.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:s}){for(const t of this.addedAssetSourceIds){if(s){const e=this.getAssetLibraryEntries(t);for(const r of e)s.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==t)})}try{e.asset.removeSource(t)}catch(e){console.warn("Unable to remove source with id: ",t)}}this.addedAssetSourceIds=[]}};export{e as BlurAssetSource,c as CaptionPresetsAssetSource,d as ColorPaletteAssetSource,u as CropPresetsAssetSource,h as DemoAssetSources,p as EffectsAssetSource,b as FiltersAssetSource,A as PagePresetsAssetSource,L as PremiumTemplatesAssetSource,E as StickerAssetSource,v as TextAssetSource,U as TextComponentAssetSource,C as TypefaceAssetSource,F as UploadAssetSources,j as VectorShapeAssetSource};
1
+ import CreativeEditorSDK from"@cesdk/cesdk-js";var e="ly.img.colors.imageColors",t=class{name="cesdk-image-colors-asset-source";version=CreativeEditorSDK.version;assetLibraryEntries;addedSourceId=null;translate;constructor(e={}){this.assetLibraryEntries=e.assetLibraryEntries??["ly.img.colors"]}async initialize({engine:t,cesdk:i}){if(this.translate=i?e=>i.i18n.translate(e):void 0,t.asset.findAllSources().includes(e)||t.asset.addSource({id:e,findAssets:e=>this.findAssets(t,e),getGroups:()=>this.getGroups(t)}),this.addedSourceId=e,i){for(const t of this.assetLibraryEntries)i.ui.updateAssetLibraryEntry(t,{sourceIds:({currentIds:t,engine:s})=>r(s)?Array.from(new Set([...t,e])):t.filter(t=>t!==e),title:s()});i.onReset(()=>this.cleanup({engine:t,cesdk:i}))}}cleanup({engine:t,cesdk:s}){if(s)for(const t of this.assetLibraryEntries)s.ui.updateAssetLibraryEntry(t,{sourceIds:({currentIds:t})=>t.filter(t=>t!==e)});if(null!=this.addedSourceId){try{t.asset.removeSource(this.addedSourceId)}catch(e){console.warn(`Unable to remove source with id: ${this.addedSourceId}`,e)}this.addedSourceId=null}n.delete(t)}async findAssets(e,t){const s=function(e){if(null==e)return null;const t=Array.isArray(e)?e:[e];return 0===t.length?null:new Set(t)}(t?.groups),r=function(e){if(null==e)return[];const t=e.toLowerCase().match(/\w+/g);return t??[]}(t?.query),i=(await a(e,this.translate)).filter(({group:e})=>null==s||s.has(e)).flatMap(({assets:e})=>e).filter(e=>function(e,t){if(0===t.length)return!0;const s=function(e){const t=[],s=e.payload?.color;if(null!=s)switch(s.colorSpace){case"sRGB":{const e=function(e,t,s){const r=e=>Math.round(255*Math.max(0,Math.min(1,e))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(s)}`}(s.r,s.g,s.b);t.push(e,e.slice(1));break}case"CMYK":t.push("c",String(Math.round(100*s.c)),"m",String(Math.round(100*s.m)),"y",String(Math.round(100*s.y)),"k",String(Math.round(100*s.k)));break;case"SpotColor":t.push(s.name.toLowerCase())}for(const s of e.groups??[]){const e=s.toLowerCase().match(/\w+/g);null!=e&&t.push(...e)}return t}(e);return t.every(e=>s.some(t=>t.includes(e)))}(e,r));return{assets:i,total:i.length,currentPage:0,nextPage:void 0}}async getGroups(e){return(await a(e,this.translate)).map(({group:e})=>e)}};function s(){return({sourceId:t,group:s})=>{if(null!=s&&t===e)return s}}function r(e){return e.block.findByType("graphic").some(t=>i(e,t))}function i(e,t){try{if(!e.block.hasFill(t)||!e.block.isFillEnabled(t))return!1;const s=e.block.getFill(t);return"//ly.img.ubq/fill/image"===e.block.getType(s)}catch{return!1}}function o(e,t){let s;try{s=e.block.getFill(t)}catch{return null}try{const t=e.block.getString(s,"fill/image/imageFileURI");if(t.length>0)return`uri:${t}`}catch{}try{const t=e.block.getSourceSet(s,"fill/image/sourceSet").map(e=>e.uri).filter(e=>e.length>0).sort().join("|");if(t.length>0)return`set:${t}`}catch{}try{const t=e.block.getString(s,"fill/image/externalReference");if(t.length>0)return`ref:${t}`}catch{}return null}var n=new WeakMap;function a(e,t){const s=n.get(e),r=Date.now();if(null!=s&&r-s.createdAt<250)return s.palette;const a=async function(e,t){const s=e.block.findByType("graphic"),r=new Map,n={count:0},a=[],l=new Set;for(const u of s){if(!i(e,u))continue;const s=o(e,u);if(null!=s){if(l.has(s))continue;l.add(s)}const g=[],h=new Set,f=c(e,u,r,n,t);try{const t=await e.block.getDominantColors(u,{count:5,ignoreWhite:!0});for(const{r:e,g:s,b:r}of t)d(g,h,{colorSpace:"sRGB",r:e,g:s,b:r},f)}catch(e){console.warn(`[ImageColors] Failed to extract colors from block ${u}:`,e)}g.length>0&&a.push({group:f,assets:g})}return a}(e,t);return n.set(e,{palette:a,createdAt:r}),a}function c(e,t,s,r,i){const o=function(e,t){try{const s=e.block.getName(t);if(s&&s.trim().length>0)return s.trim()}catch{}try{const s=e.block.getMetadata(t,"fallback-name");if(s&&s.trim().length>0)return s.trim()}catch{}return null}(e,t),n=o??function(e,t){const s="libraries.ly.img.colors.imageColors.unnamedBlock",r=`Image ${e}`;if(null==t)return r;const i=t(s);return i===s||0===i.length?r:i.replace(/\{\{\s*n\s*\}\}/g,String(e))}(++r.count,i),a=s.get(n)??0;return s.set(n,a+1),0===a?n:`${n} (${a+1})`}function d(t,s,r,i){const o=function(e){switch(e.colorSpace){case"sRGB":return`rgb:${e.r.toFixed(3)},${e.g.toFixed(3)},${e.b.toFixed(3)}`;case"CMYK":return`cmyk:${e.c.toFixed(3)},${e.m.toFixed(3)},${e.y.toFixed(3)},${e.k.toFixed(3)}`;case"SpotColor":return`spot:${e.name} ${e.externalReference}`;default:return`unknown:${e.colorSpace}`}}(r);s.has(o)||(s.add(o),t.push({id:`${e}.${encodeURIComponent(i)}.${o}`,payload:{color:r},groups:[i]}))}import l from"@cesdk/cesdk-js";var u=class{constructor(e={}){this.config=e}name="cesdk-blur-asset-source";version=l.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.blur":["ly.img.blur"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.blur";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import g from"@cesdk/cesdk-js";var h="ly.img.caption.presets",f=["backgroundColor/enabled","backgroundColor/color","backgroundColor/cornerRadius","backgroundColor/paddingBottom","backgroundColor/paddingLeft","backgroundColor/paddingRight","backgroundColor/paddingTop","blend/mode","dropShadow/enabled","dropShadow/color","dropShadow/offset/x","dropShadow/offset/y","dropShadow/blurRadius/x","dropShadow/blurRadius/y","dropShadow/clip","fill/enabled","fill/solid/color","opacity","stroke/enabled","stroke/color","stroke/width","stroke/style","stroke/position","stroke/cornerGeometry","{{blockType}}/typeface","{{blockType}}/fontSize","{{blockType}}/horizontalAlignment","{{blockType}}/verticalAlignment","{{blockType}}/letterSpacing","{{blockType}}/lineHeight","{{blockType}}/automaticFontSizeEnabled","{{blockType}}/maxAutomaticFontSize","{{blockType}}/minAutomaticFontSize","{{blockType}}/paragraphSpacing"];function p(e){const t=e.scene.getCurrentPage();if(null!=t)return e.block.getChildren(t).find(t=>"//ly.img.ubq/captionTrack"===e.block.getType(t))}function y(e){const t=p(e);if(null==t)return 1;try{const s=e.block.getMetadata(t,"previousScale"),r=parseFloat(s);return Number.isNaN(r)?1:r}catch(e){return 1}}function b(e,t,s){const r=y(e),i=e.block.getTextFontSizes(t)[0]/r,o=Math.round(i*s);if(e.block.setTextFontSize(t,o),e.block.isStrokeEnabled(t)){const i=e.block.getStrokeWidth(t)/r*s;e.block.setStrokeWidth(t,i)}if(e.block.isDropShadowEnabled(t)){const i=e.block.getDropShadowOffsetX(t)/r,o=e.block.getDropShadowOffsetY(t)/r,n=e.block.getDropShadowBlurRadiusX(t)/r,a=e.block.getDropShadowBlurRadiusY(t)/r;e.block.setDropShadowOffsetX(t,i*s),e.block.setDropShadowOffsetY(t,o*s),e.block.setDropShadowBlurRadiusX(t,n*s),e.block.setDropShadowBlurRadiusY(t,a*s)}!function(e,t){const s=p(e);null!=s&&e.block.setMetadata(s,"previousScale",t.toString())}(e,s)}var m=class{engine;assets=[];customFetchImpl;baseURL;constructor(e,t,s){this.engine=e,this.baseURL=t,this.customFetchImpl=s??window.fetch.bind(window)}async initialize(){await this.fetchAssets(),this.createSource()}async fetchAssets(){const e=function(...e){return e.map((e,t)=>0===t?e.replace(/\/$/,""):e.replace(/^\//,"").replace(/\/$/,"")).join("/")}(this.baseURL,`/${h}/content.json`);try{const t=await this.customFetchImpl(e);if(!t.ok)throw new Error(t.statusText);const s=await t.json();if(void 0===s.assets)throw new Error(`Invalid content.json for assets: ${h}`);this.assets=s.assets.map(e=>(e.meta&&Object.entries(e.meta).forEach(([t,s])=>{const r=s.toString();if(r.includes("{{base_url}}")){const s=r.replace("{{base_url}}",this.baseURL).replace(/([^:])\/\/+/g,"$1/");e.meta&&(e.meta[t]=s)}}),e))}catch(e){console.warn("Could not load caption presets:",e),this.assets=[]}}createSource(){if(new Set(this.engine.asset.findAllSources()).has(h))return;const e={id:h,findAssets:e=>{const{page:t,perPage:s,excludeGroups:r,groups:i,locale:o="en",query:n,sortActiveFirst:a,sortKey:c,sortingOrder:d,tags:l}=e,u=p(this.engine),g=null!=u&&this.engine.block.hasMetadata(u,"activePreset")?this.engine.block.getMetadata(u,"activePreset"):void 0;let f=[...this.assets];if(i&&i.length>0&&(f=f.filter(e=>e.groups?.some(e=>i.includes(e)))),n&&""!==n.trim()){const e=n.toLowerCase().trim();f=f.filter(t=>(t.label?.[o]?.toLowerCase()||"").includes(e))}l&&l.length>0&&(f=f.filter(e=>(e.tags?.[o]??[]).some(e=>l.includes(e)))),r&&r.length>0&&(f=f.filter(e=>!(e.groups??[]).some(e=>r.includes(e)))),"label"===c&&"None"!==d&&f.sort((e,t)=>{const s=e.label?.[o]?.toLocaleLowerCase()||"",r=t.label?.[o]?.toLocaleLowerCase()||"";return s<r?"Ascending"===d?-1:1:s>r?"Ascending"===d?1:-1:0}),a&&g&&f.sort((e,t)=>e.id===g?-1:t.id===g?1:0);const b=f.length,m=t*s,k=m+s,S=f.slice(m,k).map(e=>{const t=e.payload?.properties?.map(e=>"caption/scale"===e.property?{...e,value:y(this.engine)}:e);return{id:e.id,label:e.label?.[o],active:e.id===g,context:{id:h},meta:e.meta,groups:e.groups,tags:e.tags?.[o],payload:{...e.payload,properties:t},locale:o}});return Promise.resolve({assets:S,total:b,currentPage:t})},getGroups:()=>{const e=new Set;return this.assets.forEach(t=>{t.groups&&t.groups.forEach(t=>{e.add(t)})}),Promise.resolve(Array.from(e))},removeAsset:e=>{const t=this.assets.findIndex(t=>t.id===e);-1!==t&&this.assets.splice(t,1)},addAsset:e=>{const t=this.assets.findIndex(t=>t.id===e.id);-1!==t?this.assets[t]=e:this.assets.push(e)},applyAssetToBlock:(e,t)=>this.applyPreset(e,t),applyAssetProperty:(e,t)=>this.applyProperty(e,t),fetchAsset:async(e,t)=>new Promise(s=>{const r=this.assets.find(t=>t.id===e);if(null==r)s(null);else{const e=t?.locale??"en",i=p(this.engine),o=null!=i&&this.engine.block.hasMetadata(i,"activePreset")?this.engine.block.getMetadata(i,"activePreset"):void 0,n=r.payload?.properties?.map(e=>"caption/scale"===e.property?{...e,value:y(this.engine)}:e);s({id:r.id,label:r.label?.[e],active:r.id===o,meta:r.meta,groups:r.groups,tags:r.tags?.[e],payload:{...r.payload,properties:n}})}})};this.engine.asset.addSource(e)}async applyPreset(e,t){const s=e?.meta?.uri;if(null==s)throw new Error(`The asset ${e.id} does not have a preset block URL.`);const r=await this.customFetchImpl(s);if(!r.ok)throw new Error(`Failed to fetch the preset block from ${s}`);const i=await r.text(),[o]=await this.engine.block.loadFromString(i),n=null!=o?this.engine.block.getType(o):void 0;if("//ly.img.ubq/text"!==n&&"//ly.img.ubq/caption"!==n)return;const a=p(this.engine),c=null!=a?this.engine.block.getChildren(a):[];f.forEach(e=>{const s=e.replace("{{blockType}}","//ly.img.ubq/text"===n?"text":"caption"),r=this.engine.block.getPropertyType(s),i=e.replace("{{blockType}}","caption");switch(r){case"Int":{const e=this.engine.block.getInt(o,s);this.engine.block.setInt(t,i,e);break}case"Float":{const e=this.engine.block.getFloat(o,s);this.engine.block.setFloat(t,i,e);break}case"Double":{const e=this.engine.block.getDouble(o,s);this.engine.block.setDouble(t,i,e);break}case"Bool":{const e=this.engine.block.getBool(o,s);this.engine.block.setBool(t,i,e);break}case"Enum":{if("stroke/position"===s)break;const e=this.engine.block.getEnum(o,s);this.engine.block.setEnum(t,i,e);break}case"Color":{if("fill/solid/color"===s){const[e]=this.engine.block.getTextColors(o);this.engine.block.setColor(t,i,e),"Text"===this.engine.editor.getEditMode()&&this.engine.editor.setEditMode("Transform"),this.engine.block.setTextColor(t,e);break}const e=this.engine.block.getColor(o,s);this.engine.block.setColor(t,i,e);break}case"String":{if("text/typeface"===s||"caption/typeface"===s){const e=this.engine.block.getTypeface(o);this.engine.block.setTypeface(t,e);break}const e=this.engine.block.getString(o,s);this.engine.block.setString(t,i,e);break}}}),e.payload?.properties?.forEach(async t=>{"Color"===t.type&&await this.applyProperty(e,t)});const[d]=this.engine.block.getTextFontWeights(o);null!=d&&this.engine.block.setTextFontWeight(t,d);const[l]=this.engine.block.getTextFontStyles(o);null!=l&&this.engine.block.setTextFontStyle(t,l),function(e,t,s){const r={in:e.block.getInAnimation(t),loop:e.block.getLoopAnimation(t),out:e.block.getOutAnimation(t)},i=(t,s)=>{const i=r[s],o=(()=>{switch(s){case"in":return e.block.getInAnimation(t);case"loop":return e.block.getLoopAnimation(t);case"out":return e.block.getOutAnimation(t);default:return}})();if(null!=o&&e.block.isValid(o)&&e.block.destroy(o),e.block.isValid(i)){const r=e.block.duplicate(i);switch(s){case"in":e.block.setInAnimation(t,r);break;case"loop":e.block.setLoopAnimation(t,r);break;case"out":e.block.setOutAnimation(t,r)}}};s.forEach(e=>{i(e,"in"),i(e,"loop"),i(e,"out")})}(this.engine,o,c),null!=a&&this.engine.block.setMetadata(a,"activePreset",e.id),this.engine.block.destroy(o),this.engine.editor.addUndoStep(),this.engine.asset.assetSourceContentsChanged(h)}async applyProperty(e,t){const s=p(this.engine);if(null==s)return;const[r]=this.engine.block.findAllSelected(),i="//ly.img.ubq/caption"===(null!=r?this.engine.block.getType(r):void 0)?r:this.engine.block.getChildren(s)[0];if(null!=i){switch(t.type){case"Color":if("fill/solid/color"===t.property){this.engine.block.setColor(i,t.property,t.value),this.engine.block.setTextColor(i,t.value);break}this.engine.block.setColor(i,t.property,t.value);break;case"Int":this.engine.block.setInt(i,t.property,t.value);break;case"Float":if("caption/scale"===t.property){b(this.engine,i,t.value);break}this.engine.block.setFloat(i,t.property,t.value);break;case"Double":this.engine.block.setDouble(i,t.property,t.value);break;case"Boolean":this.engine.block.setBool(i,t.property,t.value);break;case"Enum":this.engine.block.setEnum(i,t.property,t.value);break;case"String":this.engine.block.setString(i,t.property,t.value)}this.assets=function(e,t,s){return e.map(e=>{if("caption/scale"===s.property){const t=e.payload?.properties?.map(e=>"caption/scale"===e.property?{...e,value:s.value}:e);return{...e,payload:{...e.payload,properties:t}}}if(e.id===t.id){const t=e.payload?.properties?.map(e=>e.property===s.property?{...e,value:s.value}:e);return{...e,payload:{...e.payload,properties:t}}}return e})}(this.assets,e,t),this.engine.asset.assetSourceContentsChanged(h)}}},k=class{constructor(e={}){this.config=e}name="cesdk-caption-presets-asset-source";version=g.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.caption.presets":["ly.img.library.captionPresets"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new m(e,r,this.config.customFetchImpl);await i.initialize();const o="ly.img.caption.presets";if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import S from"@cesdk/cesdk-js";var A=class{constructor(e={}){this.config=e}name="cesdk-color-palette-asset-source";version=S.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.color.palette":["ly.img.colors"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.color.palette";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import L from"@cesdk/cesdk-js";var w=class{constructor(e={}){this.config=e}name="cesdk-crop-presets-asset-source";version=L.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.crop.presets":["ly.img.cropPresets"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.crop.presets";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import I from"@cesdk/cesdk-js";var E=class{constructor(e={}){this.config=e}name="cesdk-demo-asset-sources";version=I.version;addedAssetSourceIds=[];globToRegex(e){const t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${t}$`,"i")}sourceMatchesAnyPattern(e,t){return t.some(t=>{if(t===e||t.startsWith(`${e}.`))return!0;return this.globToRegex(t).test(e)})}filterAssetSources(e,t){return e.filter(e=>this.sourceMatchesAnyPattern(e,t))}filterMatchersForSource(e,t){return t.filter(t=>{if(t===e||t.startsWith(`${e}.`))return!0;return this.globToRegex(t).test(e)})}getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.image":["ly.img.image"],"ly.img.video":["ly.img.video"],"ly.img.audio":["ly.img.audio"],"ly.img.templates":["ly.img.templates"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o=["ly.img.audio","ly.img.video","ly.img.image","ly.img.templates"],n=this.config.include?this.filterAssetSources(o,this.config.include):o;for(const t of n)if(!i.has(t)){const s=`${r}${t}/content.json`,i=this.config.include?this.filterMatchersForSource(t,this.config.include):void 0;await e.asset.addLocalAssetSourceFromJSONURI(s,{matcher:i}),this.addedAssetSourceIds.push(t)}if(t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));for(const e of this.addedAssetSourceIds){const s=this.getAssetLibraryEntries(e);for(const r of s)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:t})=>[...new Set([...t,e])]})}}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import v from"@cesdk/cesdk-js";var R=class{constructor(e={}){this.config=e}name="cesdk-effects-asset-source";version=v.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.effect":["ly.img.effect"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.effect";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import $ from"@cesdk/cesdk-js";var U=class{constructor(e={}){this.config=e}name="cesdk-filters-asset-source";version=$.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.filter":["ly.img.filter"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.filter";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import C from"@cesdk/cesdk-js";var x=class{constructor(e={}){this.config=e}name="cesdk-page-presets-asset-source";version=C.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.page.presets":["ly.img.pagePresets"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.page.presets";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import F from"@cesdk/cesdk-js";var T="ly.img.templates.premium",P=class{constructor(e={}){this.config=e}name="cesdk-premium-asset-sources";version=F.version;sourceAdded=!1;globToRegex(e){const t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,".");return new RegExp(`^${t}$`,"i")}filterMatchersForSource(e){return e.filter(e=>{if(e===T||e.startsWith(`${T}.`))return!0;return this.globToRegex(e).test(T)})}getAssetLibraryEntries(){if(this.config.assetLibraryEntries?.[T]){const e=this.config.assetLibraryEntries[T];return Array.isArray(e)?e:[e]}return["ly.img.templates"]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/");if(!new Set(e.asset.findAllSources()).has(T)){e.asset.addLocalSource(T,void 0,async t=>{if(t.meta?.uri)return await e.scene.loadFromArchiveURL(t.meta.uri),e.scene.get()??void 0});const t=`${r}${T}/content.json`,s=this.config.include?this.filterMatchersForSource(this.config.include):void 0;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:s}),this.sourceAdded=!0}if(t&&(t.onReset(()=>this.cleanup({engine:e,cesdk:t})),this.sourceAdded)){const e=this.getAssetLibraryEntries();for(const s of e)t.ui.updateAssetLibraryEntry(s,{sourceIds:({currentIds:e})=>[...new Set([...e,T])]})}}cleanup({engine:e,cesdk:t}){if(this.sourceAdded){if(t){const e=this.getAssetLibraryEntries();for(const s of e)t.ui.updateAssetLibraryEntry(s,{sourceIds:({currentIds:e})=>e.filter(e=>e!==T)})}try{e.asset.removeSource(T)}catch(e){console.warn("Unable to remove source with id: ",T)}this.sourceAdded=!1}}};import j from"@cesdk/cesdk-js";var M=class{constructor(e={}){this.config=e}name="cesdk-sticker-asset-source";version=j.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.sticker":["ly.img.sticker"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.sticker";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import B from"@cesdk/cesdk-js";var z=class{constructor(e={}){this.config=e}name="cesdk-text-asset-source";version=B.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.text":["ly.img.text"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.text";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import O from"@cesdk/cesdk-js";var N=class{constructor(e={}){this.config=e}name="cesdk-text-component-asset-source";version=O.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.text.components":["ly.img.text"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.text.components";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import D from"@cesdk/cesdk-js";var J=class{constructor(e={}){this.config=e}name="cesdk-typeface-asset-source";version=D.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.typeface":["ly.img.typefaces"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.typeface";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};import q from"@cesdk/cesdk-js";var G=[{id:"ly.img.image.upload",mimeTypes:["image/jpeg","image/png","image/webp","image/svg+xml","image/bmp","image/gif","image/apng"],assetLibraryEntries:["ly.img.image","ly.img.upload"]},{id:"ly.img.video.upload",mimeTypes:["application/json","video/mp4","video/quicktime","video/webm","video/matroska","image/gif","image/apng"],assetLibraryEntries:["ly.img.video","ly.img.upload"]},{id:"ly.img.audio.upload",mimeTypes:["audio/mpeg","audio/mp3","audio/x-m4a","audio/wav"],assetLibraryEntries:["ly.img.audio","ly.img.upload"]}],W=class{constructor(e={}){this.config=e}name="cesdk-upload-asset-sources";version=q.version;addedAssetSourceIds=[];addedLibraryEntryMappings=new Map;isExplicitMode(){return this.config.include?.some(e=>"string"==typeof e)??!1}getExplicitIncludes(){return this.config.include?new Set(this.config.include.filter(e=>"string"==typeof e)):new Set}getCustomizations(){return this.config.include?this.config.include.filter(e=>"object"==typeof e):[]}getAssetLibraryEntries(e){return e?Array.isArray(e)?e:[e]:[]}async initialize({engine:e,cesdk:t}){const s=new Set(e.asset.findAllSources()),r=this.isExplicitMode(),i=this.getExplicitIncludes(),o=this.getCustomizations(),n=new Map;if(r)for(const e of G)i.has(e.id)&&n.set(e.id,e);else for(const e of G)n.set(e.id,e);for(const e of o){const t=n.get(e.id);t?n.set(e.id,{...t,...e}):n.set(e.id,e)}const a=Array.from(n.values());for(const r of a){const{id:i,mimeTypes:o,assetLibraryEntries:n}=r;if(!s.has(i)&&(e.asset.addLocalSource(i,o),this.addedAssetSourceIds.push(i),t)){const e=this.getAssetLibraryEntries(n);this.addedLibraryEntryMappings.set(i,e);for(const s of e)t.ui.updateAssetLibraryEntry(s,{sourceIds:({currentIds:e})=>[...new Set([...e,i])]})}}t&&t.onReset(()=>this.cleanup({engine:e,cesdk:t}))}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.addedLibraryEntryMappings.get(s)??[];for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[],this.addedLibraryEntryMappings.clear()}};import Y from"@cesdk/cesdk-js";var X=class{constructor(e={}){this.config=e}name="cesdk-vectorshape-asset-source";version=Y.version;addedAssetSourceIds=[];getAssetLibraryEntries(e){if(this.config.assetLibraryEntries?.[e]){const t=this.config.assetLibraryEntries[e];return Array.isArray(t)?t:[t]}return{"ly.img.vector.shape":["ly.img.vector.shape","ly.img.shape.replace"]}[e]||[]}async initialize({engine:e,cesdk:t}){const s=this.config.baseURL||t?.getBaseURL()||e.editor.getSetting("basePath");if(!s)throw new Error("Cannot determine baseURL");const r=s.replace(/\/*$/,"/"),i=new Set(e.asset.findAllSources()),o="ly.img.vector.shape";if(!i.has(o)){const t=`${r}${o}/content.json`;await e.asset.addLocalAssetSourceFromJSONURI(t,{matcher:this.config.include})}if(this.addedAssetSourceIds.push(o),t){t.onReset(()=>this.cleanup({engine:e,cesdk:t}));const s=this.getAssetLibraryEntries(o);for(const e of s)t.ui.updateAssetLibraryEntry(e,{sourceIds:({currentIds:e})=>[...new Set([...e,o])]})}}cleanup({engine:e,cesdk:t}){for(const s of this.addedAssetSourceIds){if(t){const e=this.getAssetLibraryEntries(s);for(const r of e)t.ui.updateAssetLibraryEntry(r,{sourceIds:({currentIds:e})=>e.filter(e=>e!==s)})}try{e.asset.removeSource(s)}catch(e){console.warn("Unable to remove source with id: ",s)}}this.addedAssetSourceIds=[]}};export{u as BlurAssetSource,k as CaptionPresetsAssetSource,A as ColorPaletteAssetSource,w as CropPresetsAssetSource,E as DemoAssetSources,R as EffectsAssetSource,U as FiltersAssetSource,e as IMAGE_COLORS_SOURCE_ID,t as ImageColorsAssetSource,x as PagePresetsAssetSource,P as PremiumTemplatesAssetSource,M as StickerAssetSource,z as TextAssetSource,N as TextComponentAssetSource,J as TypefaceAssetSource,W as UploadAssetSources,X as VectorShapeAssetSource};
package/react/index.d.ts CHANGED
@@ -16,7 +16,7 @@ import { RefAttributes } from 'react';
16
16
  * ```tsx
17
17
  * import CreativeEditor from '@cesdk/cesdk-js/react';
18
18
  * import {
19
- * BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
19
+ * ImageColorsAssetSource, BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
20
20
  * DemoAssetSources, EffectsAssetSource, FiltersAssetSource,
21
21
  * PagePresetsAssetSource, StickerAssetSource, TextAssetSource,
22
22
  * TextComponentAssetSource, TypefaceAssetSource, UploadAssetSources,
@@ -31,6 +31,7 @@ import { RefAttributes } from 'react';
31
31
  * baseURL: 'https://your-cdn-url/assets',
32
32
  * }}
33
33
  * init={async (cesdk) => {
34
+ * await cesdk.addPlugin(new ImageColorsAssetSource());
34
35
  * await cesdk.addPlugin(new ColorPaletteAssetSource());
35
36
  * await cesdk.addPlugin(new TypefaceAssetSource());
36
37
  * await cesdk.addPlugin(new TextAssetSource());
@@ -57,7 +58,7 @@ import { RefAttributes } from 'react';
57
58
  * ```tsx
58
59
  * import CreativeEditor from '@cesdk/cesdk-js/react';
59
60
  * import {
60
- * BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
61
+ * ImageColorsAssetSource, BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
61
62
  * DemoAssetSources, EffectsAssetSource, FiltersAssetSource,
62
63
  * PagePresetsAssetSource, StickerAssetSource, TextAssetSource,
63
64
  * TextComponentAssetSource, TypefaceAssetSource, UploadAssetSources,
@@ -72,6 +73,7 @@ import { RefAttributes } from 'react';
72
73
  * baseURL: 'https://your-cdn-url/assets',
73
74
  * }}
74
75
  * init={async (cesdk) => {
76
+ * await cesdk.addPlugin(new ImageColorsAssetSource());
75
77
  * await cesdk.addPlugin(new ColorPaletteAssetSource());
76
78
  * await cesdk.addPlugin(new TypefaceAssetSource());
77
79
  * await cesdk.addPlugin(new TextAssetSource());
package/vue/index.d.ts CHANGED
@@ -27,7 +27,7 @@ import { PropType } from 'vue';
27
27
  * <script setup lang="ts">
28
28
  * import CreativeEditor from '@cesdk/cesdk-js/vue';
29
29
  * import {
30
- * BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
30
+ * ImageColorsAssetSource, BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
31
31
  * DemoAssetSources, EffectsAssetSource, FiltersAssetSource,
32
32
  * PagePresetsAssetSource, StickerAssetSource, TextAssetSource,
33
33
  * TextComponentAssetSource, TypefaceAssetSource, UploadAssetSources,
@@ -35,6 +35,7 @@ import { PropType } from 'vue';
35
35
  * } from '@cesdk/cesdk-js/plugins';
36
36
  *
37
37
  * const initEditor = async (cesdk) => {
38
+ * await cesdk.addPlugin(new ImageColorsAssetSource());
38
39
  * await cesdk.addPlugin(new ColorPaletteAssetSource());
39
40
  * await cesdk.addPlugin(new TypefaceAssetSource());
40
41
  * await cesdk.addPlugin(new TextAssetSource());
@@ -75,7 +76,7 @@ import { PropType } from 'vue';
75
76
  * type CreativeEditorLoadingState
76
77
  * } from '@cesdk/cesdk-js/vue';
77
78
  * import {
78
- * BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
79
+ * ImageColorsAssetSource, BlurAssetSource, ColorPaletteAssetSource, CropPresetsAssetSource,
79
80
  * DemoAssetSources, EffectsAssetSource, FiltersAssetSource,
80
81
  * PagePresetsAssetSource, StickerAssetSource, TextAssetSource,
81
82
  * TextComponentAssetSource, TypefaceAssetSource, UploadAssetSources,
@@ -83,6 +84,7 @@ import { PropType } from 'vue';
83
84
  * } from '@cesdk/cesdk-js/plugins';
84
85
  *
85
86
  * const initEditor = async (cesdk) => {
87
+ * await cesdk.addPlugin(new ImageColorsAssetSource());
86
88
  * await cesdk.addPlugin(new ColorPaletteAssetSource());
87
89
  * await cesdk.addPlugin(new TypefaceAssetSource());
88
90
  * await cesdk.addPlugin(new TextAssetSource());