@imgly/plugin-perfectlyclear-web 1.86.0-nightly.20261102 → 1.86.0-rc.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/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ var bt=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.en
6
6
  <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"/>
7
7
  </symbol>
8
8
  </svg>
9
- `,ot=Ya;var Ja="presets/sd.preset",st="pfc_wasm_certificate",re=()=>new DOMException("ImageEnhancer: terminated","AbortError"),ie=class{constructor(){this.stopped=!1;this.listeners=new Set}stop(){this.stopped=!0,this.listeners.forEach(t=>t(re())),this.listeners.clear()}run(t,r){return this.stopped?Promise.reject(re()):new Promise((i,a)=>{this.listeners.add(a);let n;try{n=t()}catch(o){n=Promise.reject(o)}n.then(i,a).finally(()=>{this.listeners.delete(a),this.stopped&&r?.()})})}},G=class{constructor(t){this.options=t;this.pfcModule=null;this.pfc=null;this.signal=new ie;this.initialized=!1;this.initPromise=null}get baseURL(){let t=this.options.baseURL.endsWith("/")?this.options.baseURL:`${this.options.baseURL}/`;if(typeof location>"u")return t;try{return new URL(t,location.href).href}catch{return t}}async loadPfcModule(){if(this.pfcModule!=null)return this.pfcModule;let r=await import(/* @vite-ignore */ /* webpackIgnore: true */ `${this.baseURL}pfc.mjs`);return this.pfcModule=r,r}async init(){if(this.initialized)return;if(this.initPromise!=null)return this.initPromise;let{signal:t}=this,r=(async()=>{let i=await t.run(()=>this.loadPfcModule()),a=this.options.cacheCertificate!==!1?eo(st):null,o={distDir:"./dist",modelsDir:`${this.baseURL}models`,clientAPIKey:this.options.apiKey,urlGetCertificate:this.options.certificateURL??nt,pfcWasmCertificate:a,pfcAiServerUrl:"",inference:i.InferenceOption.local,numWorkers:this.options.numWorkers??4,assetsBaseURL:this.baseURL,assetsBaseUrl:this.baseURL,workerProxyBase:"",pageHostname:this.options.pageHostname??(typeof location<"u"?location.hostname:void 0)},s=new i.Pfc;try{let l=()=>te(s),c=await t.run(()=>s.init(o),l);this.options.cacheCertificate!==!1&&typeof c=="string"&&c.length>0&&to(st,c);let u=await t.run(()=>this.fetchPresets());if(await t.run(()=>s.loadScenePresets(u),l),t.stopped)throw re()}catch(l){throw te(s),l}this.pfc=s,this.initialized=!0})();this.initPromise=r;try{await r}finally{this.initPromise===r&&(this.initPromise=null)}}async fetchPresets(){let t=`${this.baseURL}${Ja}`,r=await fetch(t,{mode:"cors"});if(!r.ok)throw new Error(`Failed to fetch Perfectly Clear presets: ${r.status} ${t}`);return r.text()}async enhance(t,{quality:r=.95}={}){if(this.initialized||await this.init(),this.pfcModule==null)throw new Error("ImageEnhancer: Perfectly Clear module failed to load");let{pfc:i,signal:a}=this;if(i==null)throw re();let n=()=>te(i),o=await a.run(()=>Xa(t)),s=i.createImage(o);if(s==null)throw new Error("Failed to create Perfectly Clear image");try{let l=this.pfcModule.PFCFEATURE.CALC_ALL|this.pfcModule.PFCFEATURE.CALC_NOTINTCALC|this.pfcModule.PFCFEATURE.CALC_FAEHISPEED,c=this.pfcModule.PFCFEATURE.CALC_SCENE_DETECTION|this.pfcModule.PFCFEATURE.CALC_SKINTONE|this.pfcModule.PFCFEATURE.CALC_AICOLOR|this.pfcModule.PFCFEATURE.CALC_DYNAMIC;await a.run(()=>i.createProfile(s,l,c),n);let u=i.createParam();if(u==null)throw new Error("Failed to create Perfectly Clear parameters");i.setParam(u,this.pfcModule.PFCPRESETID.PRESET_NONE),s.sceneId!==void 0&&i.readScenePreset(u,s.sceneId),await a.run(()=>i.apply(s,u),n);let d=s.image.getImageData(),f=new OffscreenCanvas(o.width,o.height),p=f.getContext("2d");if(p==null)throw new Error("Failed to create OffscreenCanvas 2D context");let m=new ImageData(new Uint8ClampedArray(d),o.width,o.height);return p.putImageData(m,0,0),await f.convertToBlob({type:t.type||"image/jpeg",quality:r})}finally{await a.run(()=>i.deleteImage(s),n).catch(l=>{if(!a.stopped)throw l})}}async terminate(){this.signal.stop(),this.signal=new ie,this.initPromise=null,this.pfc!=null&&te(this.pfc),this.pfc=null,this.initialized=!1}};function te(e){e.workerPoolInference?.terminate(),e.workerPool?.terminate()}async function Xa(e){let t=await createImageBitmap(e),r=new OffscreenCanvas(t.width,t.height),i=r.getContext("2d");if(i==null)throw new Error("Failed to create OffscreenCanvas 2D context");return i.drawImage(t,0,0),i.getImageData(0,0,r.width,r.height)}function eo(e){try{return typeof localStorage<"u"?localStorage.getItem(e):null}catch{return null}}function to(e,t){try{typeof localStorage<"u"&&localStorage.setItem(e,t)}catch{}}var lt=1024;async function ct(e,t,r,i){return pe(e,t,r,{processFill:async a=>{let n=a.initialSourceSet,o=io(n);if(o==null)throw new Error("No source found");let s=await ft(o.uri,t),l=await i.enhance(s),c=await gt(l,o.uri,t);return n.map(u=>({...u,uri:c}))},commitProcessing:(a,n)=>{let o=n.fillId;t.engine.block.setSourceSet(o,"fill/image/sourceSet",a);let s=[...a].sort((l,c)=>l.width*l.height-c.width*c.height)[0];s!=null&&t.engine.block.setString(o,"fill/image/previewFileURI",s.uri)}},"1.86.0-nightly.20261102")}async function ut(e,t,r,i){return pe(e,t,r,{processFill:async a=>{let n=await ft(a.initialImageFileURI,t),o=await i.enhance(n);return gt(o,a.initialImageFileURI,t)},commitProcessing:(a,n)=>{let o=n.fillId;t.engine.block.setString(o,"fill/image/imageFileURI",a),t.engine.block.setString(o,"fill/image/previewFileURI","")}},"1.86.0-nightly.20261102")}async function ft(e,t){if(e.startsWith("buffer:")){let i=await t.engine.editor.getMimeType(e),a=t.engine.editor.getBufferLength(e),n=t.engine.editor.getBufferData(e,0,a);return new Blob([new Uint8Array(n)],{type:i})}let r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch image: ${r.status} ${e}`);return r.blob()}async function gt(e,t,r){let i=ro(t)??"enhanced.jpg",n=(await r.unstable_upload(new File([e],i,{type:e.type}),()=>{})).meta?.uri;if(n==null)throw new Error("Could not upload enhanced image");return n}function ro(e){try{let r=new URL(e).pathname.split("/"),i=r[r.length-1];return i&&i.trim()!==""?i:void 0}catch{let t=e.split("/"),r=t[t.length-1];return r&&r.trim()!==""?r:void 0}}function io(e){if(e.length===0)return;let t=e.filter(r=>r.width>=lt&&r.height>=lt);return t.length>0?t.sort((r,i)=>r.width*r.height-i.width*i.height)[0]:[...e].sort((r,i)=>i.width*i.height-r.width*r.height)[0]}import{enableQuickActionForImageFill as no,setDefaultTranslations as ao}from"@imgly/plugin-ai-generation-web";var be="ly.img.perfectlyClear.enhanceImage",dt="ly.img.plugin-perfectlyclear-web.quickAction.enhanceImage",me="ly.img.plugin-perfectlyclear-web.defaults.quickAction.enhanceImage";function ne({cesdk:e,onTriggerStandalone:t}){return e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.perfectlyClear.enhanceImage",!0),ao(e,{en:{[`${me}`]:"Enhance Image",[`${me}.description`]:"Automatically enhance the image with Perfectly Clear."}}),{id:be,type:"quick",kind:"image",label:dt,enable:no(),scopes:["fill/change"],render:({builder:r,engine:i,generate:a,close:n})=>{r.Button(`${be}.button`,{label:[dt,me],icon:"@imgly/plugin-perfectlyclear/enhance",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=i.block.findAllSelected();if(o==null)return;if(t!=null){t(o),n();return}let s=i.block.getFill(o),l=i.block.getString(s,"fill/image/imageFileURI")||i.block.getSourceSet(s,"fill/image/sourceSet")[0]?.uri||"";if(l==="")throw new Error("No image URI found on selected block");await a({uri:l}),n()}catch(o){console.error("Perfectly Clear enhancement failed:",o),e.ui.showNotification({type:"error",message:o.message||"Failed to enhance image. Please try again.",duration:"medium"})}}})}}}function ve(e){if(typeof e.apiKey!="string"||e.apiKey.length===0)throw new Error(`${E}: 'apiKey' is required. Obtain an API key from Perfectly Clear and pass it via the plugin configuration.`);return{initialize({cesdk:t}){if(t==null)return;let r=new G({apiKey:e.apiKey,baseURL:e.baseURL??it,certificateURL:e.certificateURL,numWorkers:e.numWorkers,cacheCertificate:e.cacheCertificate,pageHostname:e.pageHostname});t.ui.addIconSet(at,ot),tt(t,{pluginId:E,process:(n,o)=>{so(t,n,o,r)}});let{translationsKeys:i}=rt(t,{pluginId:E,icon:"@imgly/plugin-perfectlyclear/enhance"});t.setTranslations({en:{[i.inspectorBarLabel]:"Enhance",[i.navigationBarLabel]:"Enhance",[i.canvasBarLabel]:"Enhance",[i.canvasMenuLabel]:"Enhance",[i.dockLabel]:"Enhance"}}),oo.get().register(ne({cesdk:t,onTriggerStandalone:n=>{lo(t,n)}}))}}}async function so(e,t,r,i){let a=e.engine.block;if(!a.hasFill(t))throw new Error("Block does not support fill");let n=a.getFill(t),o=a.getSourceSet(n,"fill/image/sourceSet"),s=a.getString(n,"fill/image/imageFileURI");if(o.length===0&&s==="")throw new Error("No source or image file URI found");o.length>0?await ct(t,e,r,i):await ut(t,e,r,i)}function lo(e,t){let r=new ee(e.engine,E),i=r.get(t);(i.status==="IDLE"||i.status==="ERROR"||i.status==="PROCESSED")&&r.set(t,{status:"PENDING"})}var co=e=>({name:E,version:"1.86.0-nightly.20261102",...ve(e)}),No=co;export{be as ENHANCE_IMAGE_ACTION_ID,G as ImageEnhancer,E as PLUGIN_ID,ne as createEnhanceImageQuickAction,No as default};
9
+ `,ot=Ya;var Ja="presets/sd.preset",st="pfc_wasm_certificate",re=()=>new DOMException("ImageEnhancer: terminated","AbortError"),ie=class{constructor(){this.stopped=!1;this.listeners=new Set}stop(){this.stopped=!0,this.listeners.forEach(t=>t(re())),this.listeners.clear()}run(t,r){return this.stopped?Promise.reject(re()):new Promise((i,a)=>{this.listeners.add(a);let n;try{n=t()}catch(o){n=Promise.reject(o)}n.then(i,a).finally(()=>{this.listeners.delete(a),this.stopped&&r?.()})})}},G=class{constructor(t){this.options=t;this.pfcModule=null;this.pfc=null;this.signal=new ie;this.initialized=!1;this.initPromise=null}get baseURL(){let t=this.options.baseURL.endsWith("/")?this.options.baseURL:`${this.options.baseURL}/`;if(typeof location>"u")return t;try{return new URL(t,location.href).href}catch{return t}}async loadPfcModule(){if(this.pfcModule!=null)return this.pfcModule;let r=await import(/* @vite-ignore */ /* webpackIgnore: true */ `${this.baseURL}pfc.mjs`);return this.pfcModule=r,r}async init(){if(this.initialized)return;if(this.initPromise!=null)return this.initPromise;let{signal:t}=this,r=(async()=>{let i=await t.run(()=>this.loadPfcModule()),a=this.options.cacheCertificate!==!1?eo(st):null,o={distDir:"./dist",modelsDir:`${this.baseURL}models`,clientAPIKey:this.options.apiKey,urlGetCertificate:this.options.certificateURL??nt,pfcWasmCertificate:a,pfcAiServerUrl:"",inference:i.InferenceOption.local,numWorkers:this.options.numWorkers??4,assetsBaseURL:this.baseURL,assetsBaseUrl:this.baseURL,workerProxyBase:"",pageHostname:this.options.pageHostname??(typeof location<"u"?location.hostname:void 0)},s=new i.Pfc;try{let l=()=>te(s),c=await t.run(()=>s.init(o),l);this.options.cacheCertificate!==!1&&typeof c=="string"&&c.length>0&&to(st,c);let u=await t.run(()=>this.fetchPresets());if(await t.run(()=>s.loadScenePresets(u),l),t.stopped)throw re()}catch(l){throw te(s),l}this.pfc=s,this.initialized=!0})();this.initPromise=r;try{await r}finally{this.initPromise===r&&(this.initPromise=null)}}async fetchPresets(){let t=`${this.baseURL}${Ja}`,r=await fetch(t,{mode:"cors"});if(!r.ok)throw new Error(`Failed to fetch Perfectly Clear presets: ${r.status} ${t}`);return r.text()}async enhance(t,{quality:r=.95}={}){if(this.initialized||await this.init(),this.pfcModule==null)throw new Error("ImageEnhancer: Perfectly Clear module failed to load");let{pfc:i,signal:a}=this;if(i==null)throw re();let n=()=>te(i),o=await a.run(()=>Xa(t)),s=i.createImage(o);if(s==null)throw new Error("Failed to create Perfectly Clear image");try{let l=this.pfcModule.PFCFEATURE.CALC_ALL|this.pfcModule.PFCFEATURE.CALC_NOTINTCALC|this.pfcModule.PFCFEATURE.CALC_FAEHISPEED,c=this.pfcModule.PFCFEATURE.CALC_SCENE_DETECTION|this.pfcModule.PFCFEATURE.CALC_SKINTONE|this.pfcModule.PFCFEATURE.CALC_AICOLOR|this.pfcModule.PFCFEATURE.CALC_DYNAMIC;await a.run(()=>i.createProfile(s,l,c),n);let u=i.createParam();if(u==null)throw new Error("Failed to create Perfectly Clear parameters");i.setParam(u,this.pfcModule.PFCPRESETID.PRESET_NONE),s.sceneId!==void 0&&i.readScenePreset(u,s.sceneId),await a.run(()=>i.apply(s,u),n);let d=s.image.getImageData(),f=new OffscreenCanvas(o.width,o.height),p=f.getContext("2d");if(p==null)throw new Error("Failed to create OffscreenCanvas 2D context");let m=new ImageData(new Uint8ClampedArray(d),o.width,o.height);return p.putImageData(m,0,0),await f.convertToBlob({type:t.type||"image/jpeg",quality:r})}finally{await a.run(()=>i.deleteImage(s),n).catch(l=>{if(!a.stopped)throw l})}}async terminate(){this.signal.stop(),this.signal=new ie,this.initPromise=null,this.pfc!=null&&te(this.pfc),this.pfc=null,this.initialized=!1}};function te(e){e.workerPoolInference?.terminate(),e.workerPool?.terminate()}async function Xa(e){let t=await createImageBitmap(e),r=new OffscreenCanvas(t.width,t.height),i=r.getContext("2d");if(i==null)throw new Error("Failed to create OffscreenCanvas 2D context");return i.drawImage(t,0,0),i.getImageData(0,0,r.width,r.height)}function eo(e){try{return typeof localStorage<"u"?localStorage.getItem(e):null}catch{return null}}function to(e,t){try{typeof localStorage<"u"&&localStorage.setItem(e,t)}catch{}}var lt=1024;async function ct(e,t,r,i){return pe(e,t,r,{processFill:async a=>{let n=a.initialSourceSet,o=io(n);if(o==null)throw new Error("No source found");let s=await ft(o.uri,t),l=await i.enhance(s),c=await gt(l,o.uri,t);return n.map(u=>({...u,uri:c}))},commitProcessing:(a,n)=>{let o=n.fillId;t.engine.block.setSourceSet(o,"fill/image/sourceSet",a);let s=[...a].sort((l,c)=>l.width*l.height-c.width*c.height)[0];s!=null&&t.engine.block.setString(o,"fill/image/previewFileURI",s.uri)}},"1.86.0-rc.0")}async function ut(e,t,r,i){return pe(e,t,r,{processFill:async a=>{let n=await ft(a.initialImageFileURI,t),o=await i.enhance(n);return gt(o,a.initialImageFileURI,t)},commitProcessing:(a,n)=>{let o=n.fillId;t.engine.block.setString(o,"fill/image/imageFileURI",a),t.engine.block.setString(o,"fill/image/previewFileURI","")}},"1.86.0-rc.0")}async function ft(e,t){if(e.startsWith("buffer:")){let i=await t.engine.editor.getMimeType(e),a=t.engine.editor.getBufferLength(e),n=t.engine.editor.getBufferData(e,0,a);return new Blob([new Uint8Array(n)],{type:i})}let r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch image: ${r.status} ${e}`);return r.blob()}async function gt(e,t,r){let i=ro(t)??"enhanced.jpg",n=(await r.unstable_upload(new File([e],i,{type:e.type}),()=>{})).meta?.uri;if(n==null)throw new Error("Could not upload enhanced image");return n}function ro(e){try{let r=new URL(e).pathname.split("/"),i=r[r.length-1];return i&&i.trim()!==""?i:void 0}catch{let t=e.split("/"),r=t[t.length-1];return r&&r.trim()!==""?r:void 0}}function io(e){if(e.length===0)return;let t=e.filter(r=>r.width>=lt&&r.height>=lt);return t.length>0?t.sort((r,i)=>r.width*r.height-i.width*i.height)[0]:[...e].sort((r,i)=>i.width*i.height-r.width*r.height)[0]}import{enableQuickActionForImageFill as no,setDefaultTranslations as ao}from"@imgly/plugin-ai-generation-web";var be="ly.img.perfectlyClear.enhanceImage",dt="ly.img.plugin-perfectlyclear-web.quickAction.enhanceImage",me="ly.img.plugin-perfectlyclear-web.defaults.quickAction.enhanceImage";function ne({cesdk:e,onTriggerStandalone:t}){return e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.perfectlyClear.enhanceImage",!0),ao(e,{en:{[`${me}`]:"Enhance Image",[`${me}.description`]:"Automatically enhance the image with Perfectly Clear."}}),{id:be,type:"quick",kind:"image",label:dt,enable:no(),scopes:["fill/change"],render:({builder:r,engine:i,generate:a,close:n})=>{r.Button(`${be}.button`,{label:[dt,me],icon:"@imgly/plugin-perfectlyclear/enhance",labelAlignment:"left",variant:"plain",onClick:async()=>{try{let[o]=i.block.findAllSelected();if(o==null)return;if(t!=null){t(o),n();return}let s=i.block.getFill(o),l=i.block.getString(s,"fill/image/imageFileURI")||i.block.getSourceSet(s,"fill/image/sourceSet")[0]?.uri||"";if(l==="")throw new Error("No image URI found on selected block");await a({uri:l}),n()}catch(o){console.error("Perfectly Clear enhancement failed:",o),e.ui.showNotification({type:"error",message:o.message||"Failed to enhance image. Please try again.",duration:"medium"})}}})}}}function ve(e){if(typeof e.apiKey!="string"||e.apiKey.length===0)throw new Error(`${E}: 'apiKey' is required. Obtain an API key from Perfectly Clear and pass it via the plugin configuration.`);return{initialize({cesdk:t}){if(t==null)return;let r=new G({apiKey:e.apiKey,baseURL:e.baseURL??it,certificateURL:e.certificateURL,numWorkers:e.numWorkers,cacheCertificate:e.cacheCertificate,pageHostname:e.pageHostname});t.ui.addIconSet(at,ot),tt(t,{pluginId:E,process:(n,o)=>{so(t,n,o,r)}});let{translationsKeys:i}=rt(t,{pluginId:E,icon:"@imgly/plugin-perfectlyclear/enhance"});t.setTranslations({en:{[i.inspectorBarLabel]:"Enhance",[i.navigationBarLabel]:"Enhance",[i.canvasBarLabel]:"Enhance",[i.canvasMenuLabel]:"Enhance",[i.dockLabel]:"Enhance"}}),oo.get().register(ne({cesdk:t,onTriggerStandalone:n=>{lo(t,n)}}))}}}async function so(e,t,r,i){let a=e.engine.block;if(!a.hasFill(t))throw new Error("Block does not support fill");let n=a.getFill(t),o=a.getSourceSet(n,"fill/image/sourceSet"),s=a.getString(n,"fill/image/imageFileURI");if(o.length===0&&s==="")throw new Error("No source or image file URI found");o.length>0?await ct(t,e,r,i):await ut(t,e,r,i)}function lo(e,t){let r=new ee(e.engine,E),i=r.get(t);(i.status==="IDLE"||i.status==="ERROR"||i.status==="PROCESSED")&&r.set(t,{status:"PENDING"})}var co=e=>({name:E,version:"1.86.0-rc.0",...ve(e)}),No=co;export{be as ENHANCE_IMAGE_ACTION_ID,G as ImageEnhancer,E as PLUGIN_ID,ne as createEnhanceImageQuickAction,No as default};
10
10
  /*! Bundled license information:
11
11
 
12
12
  lodash-es/lodash.js: