@imgly/plugin-perfectlyclear-web 1.77.0-rc.2 → 1.77.0-rc.3
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 +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var pt=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
|
-
`,it=Wa;var qa="presets/sd.preset",nt="pfc_wasm_certificate",G=class{constructor(t){this.options=t;this.pfcModule=null;this.pfc=null;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){if(this.initPromise!=null)return this.initPromise;this.initPromise=(async()=>{let t=await this.loadPfcModule(),r=this.options.cacheCertificate!==!1?Ya(nt):null,a={distDir:"./dist",modelsDir:`${this.baseURL}models`,clientAPIKey:this.options.apiKey,urlGetCertificate:this.options.certificateURL??tt,pfcWasmCertificate:r,pfcAiServerUrl:"",inference:t.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)},n=new t.Pfc,o=await n.init(a);this.pfc=n,this.options.cacheCertificate!==!1&&typeof o=="string"&&o.length>0&&Ja(nt,o),await this.loadPresets(),this.initialized=!0})();try{await this.initPromise}finally{this.initPromise=null}}}async loadPresets(){if(this.pfc==null)return;let t=`${this.baseURL}${qa}`,r=await fetch(t,{mode:"cors"});if(!r.ok)throw new Error(`Failed to fetch Perfectly Clear presets: ${r.status} ${t}`);await this.pfc.loadScenePresets(await r.text())}async enhance(t,{quality:r=.95}={}){if(this.initialized||await this.init(),this.pfcModule==null||this.pfc==null)throw new Error("ImageEnhancer: Perfectly Clear module failed to load");let i=await Qa(t),a=this.pfc.createImage(i);if(a==null)throw new Error("Failed to create Perfectly Clear image");try{let n=this.pfcModule.PFCFEATURE.CALC_ALL|this.pfcModule.PFCFEATURE.CALC_NOTINTCALC|this.pfcModule.PFCFEATURE.CALC_FAEHISPEED,o=this.pfcModule.PFCFEATURE.CALC_SCENE_DETECTION|this.pfcModule.PFCFEATURE.CALC_SKINTONE|this.pfcModule.PFCFEATURE.CALC_AICOLOR|this.pfcModule.PFCFEATURE.CALC_DYNAMIC;await this.pfc.createProfile(a,n,o);let s=this.pfc.createParam();if(s==null)throw new Error("Failed to create Perfectly Clear parameters");this.pfc.setParam(s,this.pfcModule.PFCPRESETID.PRESET_NONE),a.sceneId!==void 0&&this.pfc.readScenePreset(s,a.sceneId),await this.pfc.apply(a,s);let c=a.image.getImageData(),l=new OffscreenCanvas(i.width,i.height),f=l.getContext("2d");if(f==null)throw new Error("Failed to create OffscreenCanvas 2D context");let d=new ImageData(new Uint8ClampedArray(c),i.width,i.height);return f.putImageData(d,0,0),await l.convertToBlob({type:t.type||"image/jpeg",quality:r})}finally{await this.pfc.deleteImage(a)}}async terminate(){this.pfc?.workerPool!=null&&this.pfc.workerPool.terminate(),this.pfc=null,this.initialized=!1}};async function Qa(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 Ya(e){try{return typeof localStorage<"u"?localStorage.getItem(e):null}catch{return null}}function Ja(e,t){try{typeof localStorage<"u"&&localStorage.setItem(e,t)}catch{}}var at=1024;async function ot(e,t,r,i){return ge(e,t,r,{processFill:async a=>{let n=a.initialSourceSet,o=eo(n);if(o==null)throw new Error("No source found");let s=await lt(o.uri,t),c=await i.enhance(s),l=await ct(c,o.uri,t);return n.map(f=>({...f,uri:l}))},commitProcessing:(a,n)=>{let o=n.fillId;t.engine.block.setSourceSet(o,"fill/image/sourceSet",a);let s=[...a].sort((c,l)=>c.width*c.height-l.width*l.height)[0];s!=null&&t.engine.block.setString(o,"fill/image/previewFileURI",s.uri)}})}async function st(e,t,r,i){return ge(e,t,r,{processFill:async a=>{let n=await lt(a.initialImageFileURI,t),o=await i.enhance(n);return ct(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","")}})}async function lt(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 ct(e,t,r){let i=Xa(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 Xa(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 eo(e){if(e.length===0)return;let t=e.filter(r=>r.width>=at&&r.height>=at);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 to,setDefaultTranslations as ro}from"@imgly/plugin-ai-generation-web";var pe="ly.img.perfectlyClear.enhanceImage",ut="ly.img.plugin-perfectlyclear-web.quickAction.enhanceImage",de="ly.img.plugin-perfectlyclear-web.defaults.quickAction.enhanceImage";function te({cesdk:e,onTriggerStandalone:t}){return e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.perfectlyClear.enhanceImage",!0),ro(e,{en:{[`${de}`]:"Enhance Image",[`${de}.description`]:"Automatically enhance the image with Perfectly Clear."}}),{id:pe,type:"quick",kind:"image",label:ut,enable:to(),scopes:["fill/change"],render:({builder:r,engine:i,generate:a,close:n})=>{r.Button(`${pe}.button`,{label:[ut,de],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),c=i.block.getString(s,"fill/image/imageFileURI")||i.block.getSourceSet(s,"fill/image/sourceSet")[0]?.uri||"";if(c==="")throw new Error("No image URI found on selected block");await a({uri:c}),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 he(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??et,certificateURL:e.certificateURL,numWorkers:e.numWorkers,cacheCertificate:e.cacheCertificate,pageHostname:e.pageHostname});t.ui.addIconSet(rt,it),Je(t,{pluginId:E,process:(n,o)=>{no(t,n,o,r)}});let{translationsKeys:i}=Xe(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"}}),io.get().register(te({cesdk:t,onTriggerStandalone:n=>{ao(t,n)}}))}}}async function no(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 ot(t,e,r,i):await st(t,e,r,i)}function ao(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 oo=e=>({name:E,version:"1.77.0-rc.
|
|
9
|
+
`,it=Wa;var qa="presets/sd.preset",nt="pfc_wasm_certificate",G=class{constructor(t){this.options=t;this.pfcModule=null;this.pfc=null;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){if(this.initPromise!=null)return this.initPromise;this.initPromise=(async()=>{let t=await this.loadPfcModule(),r=this.options.cacheCertificate!==!1?Ya(nt):null,a={distDir:"./dist",modelsDir:`${this.baseURL}models`,clientAPIKey:this.options.apiKey,urlGetCertificate:this.options.certificateURL??tt,pfcWasmCertificate:r,pfcAiServerUrl:"",inference:t.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)},n=new t.Pfc,o=await n.init(a);this.pfc=n,this.options.cacheCertificate!==!1&&typeof o=="string"&&o.length>0&&Ja(nt,o),await this.loadPresets(),this.initialized=!0})();try{await this.initPromise}finally{this.initPromise=null}}}async loadPresets(){if(this.pfc==null)return;let t=`${this.baseURL}${qa}`,r=await fetch(t,{mode:"cors"});if(!r.ok)throw new Error(`Failed to fetch Perfectly Clear presets: ${r.status} ${t}`);await this.pfc.loadScenePresets(await r.text())}async enhance(t,{quality:r=.95}={}){if(this.initialized||await this.init(),this.pfcModule==null||this.pfc==null)throw new Error("ImageEnhancer: Perfectly Clear module failed to load");let i=await Qa(t),a=this.pfc.createImage(i);if(a==null)throw new Error("Failed to create Perfectly Clear image");try{let n=this.pfcModule.PFCFEATURE.CALC_ALL|this.pfcModule.PFCFEATURE.CALC_NOTINTCALC|this.pfcModule.PFCFEATURE.CALC_FAEHISPEED,o=this.pfcModule.PFCFEATURE.CALC_SCENE_DETECTION|this.pfcModule.PFCFEATURE.CALC_SKINTONE|this.pfcModule.PFCFEATURE.CALC_AICOLOR|this.pfcModule.PFCFEATURE.CALC_DYNAMIC;await this.pfc.createProfile(a,n,o);let s=this.pfc.createParam();if(s==null)throw new Error("Failed to create Perfectly Clear parameters");this.pfc.setParam(s,this.pfcModule.PFCPRESETID.PRESET_NONE),a.sceneId!==void 0&&this.pfc.readScenePreset(s,a.sceneId),await this.pfc.apply(a,s);let c=a.image.getImageData(),l=new OffscreenCanvas(i.width,i.height),f=l.getContext("2d");if(f==null)throw new Error("Failed to create OffscreenCanvas 2D context");let d=new ImageData(new Uint8ClampedArray(c),i.width,i.height);return f.putImageData(d,0,0),await l.convertToBlob({type:t.type||"image/jpeg",quality:r})}finally{await this.pfc.deleteImage(a)}}async terminate(){this.pfc?.workerPool!=null&&this.pfc.workerPool.terminate(),this.pfc=null,this.initialized=!1}};async function Qa(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 Ya(e){try{return typeof localStorage<"u"?localStorage.getItem(e):null}catch{return null}}function Ja(e,t){try{typeof localStorage<"u"&&localStorage.setItem(e,t)}catch{}}var at=1024;async function ot(e,t,r,i){return ge(e,t,r,{processFill:async a=>{let n=a.initialSourceSet,o=eo(n);if(o==null)throw new Error("No source found");let s=await lt(o.uri,t),c=await i.enhance(s),l=await ct(c,o.uri,t);return n.map(f=>({...f,uri:l}))},commitProcessing:(a,n)=>{let o=n.fillId;t.engine.block.setSourceSet(o,"fill/image/sourceSet",a);let s=[...a].sort((c,l)=>c.width*c.height-l.width*l.height)[0];s!=null&&t.engine.block.setString(o,"fill/image/previewFileURI",s.uri)}})}async function st(e,t,r,i){return ge(e,t,r,{processFill:async a=>{let n=await lt(a.initialImageFileURI,t),o=await i.enhance(n);return ct(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","")}})}async function lt(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 ct(e,t,r){let i=Xa(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 Xa(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 eo(e){if(e.length===0)return;let t=e.filter(r=>r.width>=at&&r.height>=at);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 to,setDefaultTranslations as ro}from"@imgly/plugin-ai-generation-web";var pe="ly.img.perfectlyClear.enhanceImage",ut="ly.img.plugin-perfectlyclear-web.quickAction.enhanceImage",de="ly.img.plugin-perfectlyclear-web.defaults.quickAction.enhanceImage";function te({cesdk:e,onTriggerStandalone:t}){return e.feature.enable("ly.img.plugin-ai-image-generation-web.quickAction.perfectlyClear.enhanceImage",!0),ro(e,{en:{[`${de}`]:"Enhance Image",[`${de}.description`]:"Automatically enhance the image with Perfectly Clear."}}),{id:pe,type:"quick",kind:"image",label:ut,enable:to(),scopes:["fill/change"],render:({builder:r,engine:i,generate:a,close:n})=>{r.Button(`${pe}.button`,{label:[ut,de],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),c=i.block.getString(s,"fill/image/imageFileURI")||i.block.getSourceSet(s,"fill/image/sourceSet")[0]?.uri||"";if(c==="")throw new Error("No image URI found on selected block");await a({uri:c}),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 he(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??et,certificateURL:e.certificateURL,numWorkers:e.numWorkers,cacheCertificate:e.cacheCertificate,pageHostname:e.pageHostname});t.ui.addIconSet(rt,it),Je(t,{pluginId:E,process:(n,o)=>{no(t,n,o,r)}});let{translationsKeys:i}=Xe(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"}}),io.get().register(te({cesdk:t,onTriggerStandalone:n=>{ao(t,n)}}))}}}async function no(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 ot(t,e,r,i):await st(t,e,r,i)}function ao(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 oo=e=>({name:E,version:"1.77.0-rc.3",...he(e)}),Do=oo;export{pe as ENHANCE_IMAGE_ACTION_ID,G as ImageEnhancer,E as PLUGIN_ID,te as createEnhanceImageQuickAction,Do as default};
|
|
10
10
|
/*! Bundled license information:
|
|
11
11
|
|
|
12
12
|
lodash-es/lodash.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imgly/plugin-perfectlyclear-web",
|
|
3
|
-
"version": "1.77.0-rc.
|
|
3
|
+
"version": "1.77.0-rc.3",
|
|
4
4
|
"description": "Perfectly Clear (eyeQ) image enhancement plugin for the CE.SDK editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CE.SDK",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dist/"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@imgly/plugin-ai-generation-web": "1.77.0-rc.
|
|
40
|
+
"@imgly/plugin-ai-generation-web": "1.77.0-rc.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"chalk": "^5.4.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@imgly/plugin-utils": "0.0.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@cesdk/cesdk-js": "^1.77.0-rc.
|
|
51
|
+
"@cesdk/cesdk-js": "^1.77.0-rc.3"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"start": "npm run watch",
|