@imgly/plugin-background-removal-web 0.3.0-rc.1 → 0.3.0-rc.2
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var dt=class{constructor(e,t){this.cesdk=e,this.key=t}hasData(e){return this.cesdk.engine.block.isValid(e)&&this.cesdk.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.cesdk.engine.block.getMetadata(e,this.key))}set(e,t){this.cesdk.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.cesdk.engine.block.hasMetadata(e,this.key)&&this.cesdk.engine.block.removeMetadata(e,this.key)}},ct=dt,mt=typeof global=="object"&&global&&global.Object===Object&&global,Be=mt,xt=typeof self=="object"&&self&&self.Object===Object&&self,gt=Be||xt||Function("return this")(),S=gt,vt=S.Symbol,R=vt,De=Object.prototype,ht=De.hasOwnProperty,bt=De.toString,N=R?R.toStringTag:void 0;function yt(e){var t=ht.call(e,N),r=e[N];try{e[N]=void 0;var a=!0}catch{}var i=bt.call(e);return a&&(t?e[N]=r:delete e[N]),i}var St=yt,_t=Object.prototype,It=_t.toString;function kt(e){return It.call(e)}var jt=kt,Ot="[object Null]",wt="[object Undefined]",ce=R?R.toStringTag:void 0;function Rt(e){return e==null?e===void 0?wt:Ot:ce&&ce in Object(e)?St(e):jt(e)}var z=Rt;function Et(e){return e!=null&&typeof e=="object"}var T=Et,Pt=Array.isArray,$=Pt;function Ft(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Ne=Ft,Ct="[object AsyncFunction]",At="[object Function]",Bt="[object GeneratorFunction]",Dt="[object Proxy]";function Nt(e){if(!Ne(e))return!1;var t=z(e);return t==At||t==Bt||t==Ct||t==Dt}var Ue=Nt,Ut=S["__core-js_shared__"],Z=Ut,me=function(){var e=/[^.]+$/.exec(Z&&Z.keys&&Z.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Tt(e){return!!me&&me in e}var Mt=Tt,Lt=Function.prototype,zt=Lt.toString;function Wt(e){if(e!=null){try{return zt.call(e)}catch{}try{return e+""}catch{}}return""}var j=Wt,Gt=/[\\^$.*+?()[\]{}|]/g,Vt=/^\[object .+?Constructor\]$/,$t=Function.prototype,qt=Object.prototype,Kt=$t.toString,Jt=qt.hasOwnProperty,Xt=RegExp("^"+Kt.call(Jt).replace(Gt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Yt(e){if(!Ne(e)||Mt(e))return!1;var t=Ue(e)?Xt:Vt;return t.test(j(e))}var Ht=Yt;function Qt(e,t){return e?.[t]}var Zt=Qt;function er(e,t){var r=Zt(e,t);return Ht(r)?r:void 0}var E=er,tr=E(S,"WeakMap"),oe=tr,rr=9007199254740991,ar=/^(?:0|[1-9]\d*)$/;function or(e,t){var r=typeof e;return t=t??rr,!!t&&(r=="number"||r!="symbol"&&ar.test(e))&&e>-1&&e%1==0&&e<t}var ir=or;function nr(e,t){return e===t||e!==e&&t!==t}var Te=nr,fr=9007199254740991;function sr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=fr}var Me=sr;function lr(e){return e!=null&&Me(e.length)&&!Ue(e)}var ur=lr,pr=Object.prototype;function dr(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||pr;return e===r}var cr=dr;function mr(e,t){for(var r=-1,a=Array(e);++r<e;)a[r]=t(r);return a}var xr=mr,gr="[object Arguments]";function vr(e){return T(e)&&z(e)==gr}var xe=vr,Le=Object.prototype,hr=Le.hasOwnProperty,br=Le.propertyIsEnumerable,yr=xe(function(){return arguments}())?xe:function(e){return T(e)&&hr.call(e,"callee")&&!br.call(e,"callee")},Sr=yr;function _r(){return!1}var Ir=_r,ze=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ge=ze&&typeof module=="object"&&module&&!module.nodeType&&module,kr=ge&&ge.exports===ze,ve=kr?S.Buffer:void 0,jr=ve?ve.isBuffer:void 0,Or=jr||Ir,ie=Or,wr="[object Arguments]",Rr="[object Array]",Er="[object Boolean]",Pr="[object Date]",Fr="[object Error]",Cr="[object Function]",Ar="[object Map]",Br="[object Number]",Dr="[object Object]",Nr="[object RegExp]",Ur="[object Set]",Tr="[object String]",Mr="[object WeakMap]",Lr="[object ArrayBuffer]",zr="[object DataView]",Wr="[object Float32Array]",Gr="[object Float64Array]",Vr="[object Int8Array]",$r="[object Int16Array]",qr="[object Int32Array]",Kr="[object Uint8Array]",Jr="[object Uint8ClampedArray]",Xr="[object Uint16Array]",Yr="[object Uint32Array]",c={};c[Wr]=c[Gr]=c[Vr]=c[$r]=c[qr]=c[Kr]=c[Jr]=c[Xr]=c[Yr]=!0;c[wr]=c[Rr]=c[Lr]=c[Er]=c[zr]=c[Pr]=c[Fr]=c[Cr]=c[Ar]=c[Br]=c[Dr]=c[Nr]=c[Ur]=c[Tr]=c[Mr]=!1;function Hr(e){return T(e)&&Me(e.length)&&!!c[z(e)]}var Qr=Hr;function Zr(e){return function(t){return e(t)}}var ea=Zr,We=typeof exports=="object"&&exports&&!exports.nodeType&&exports,U=We&&typeof module=="object"&&module&&!module.nodeType&&module,ta=U&&U.exports===We,ee=ta&&Be.process,ra=function(){try{var e=U&&U.require&&U.require("util").types;return e||ee&&ee.binding&&ee.binding("util")}catch{}}(),he=ra,be=he&&he.isTypedArray,aa=be?ea(be):Qr,Ge=aa,oa=Object.prototype,ia=oa.hasOwnProperty;function na(e,t){var r=$(e),a=!r&&Sr(e),i=!r&&!a&&ie(e),o=!r&&!a&&!i&&Ge(e),n=r||a||i||o,f=n?xr(e.length,String):[],l=f.length;for(var s in e)(t||ia.call(e,s))&&!(n&&(s=="length"||i&&(s=="offset"||s=="parent")||o&&(s=="buffer"||s=="byteLength"||s=="byteOffset")||ir(s,l)))&&f.push(s);return f}var fa=na;function sa(e,t){return function(r){return e(t(r))}}var la=sa,ua=la(Object.keys,Object),pa=ua,da=Object.prototype,ca=da.hasOwnProperty;function ma(e){if(!cr(e))return pa(e);var t=[];for(var r in Object(e))ca.call(e,r)&&r!="constructor"&&t.push(r);return t}var xa=ma;function ga(e){return ur(e)?fa(e):xa(e)}var va=ga,ha=E(Object,"create"),M=ha;function ba(){this.__data__=M?M(null):{},this.size=0}var ya=ba;function Sa(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var _a=Sa,Ia="__lodash_hash_undefined__",ka=Object.prototype,ja=ka.hasOwnProperty;function Oa(e){var t=this.__data__;if(M){var r=t[e];return r===Ia?void 0:r}return ja.call(t,e)?t[e]:void 0}var wa=Oa,Ra=Object.prototype,Ea=Ra.hasOwnProperty;function Pa(e){var t=this.__data__;return M?t[e]!==void 0:Ea.call(t,e)}var Fa=Pa,Ca="__lodash_hash_undefined__";function Aa(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=M&&t===void 0?Ca:t,this}var Ba=Aa;function P(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}P.prototype.clear=ya;P.prototype.delete=_a;P.prototype.get=wa;P.prototype.has=Fa;P.prototype.set=Ba;var ye=P;function Da(){this.__data__=[],this.size=0}var Na=Da;function Ua(e,t){for(var r=e.length;r--;)if(Te(e[r][0],t))return r;return-1}var K=Ua,Ta=Array.prototype,Ma=Ta.splice;function La(e){var t=this.__data__,r=K(t,e);if(r<0)return!1;var a=t.length-1;return r==a?t.pop():Ma.call(t,r,1),--this.size,!0}var za=La;function Wa(e){var t=this.__data__,r=K(t,e);return r<0?void 0:t[r][1]}var Ga=Wa;function Va(e){return K(this.__data__,e)>-1}var $a=Va;function qa(e,t){var r=this.__data__,a=K(r,e);return a<0?(++this.size,r.push([e,t])):r[a][1]=t,this}var Ka=qa;function F(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}F.prototype.clear=Na;F.prototype.delete=za;F.prototype.get=Ga;F.prototype.has=$a;F.prototype.set=Ka;var J=F,Ja=E(S,"Map"),L=Ja;function Xa(){this.size=0,this.__data__={hash:new ye,map:new(L||J),string:new ye}}var Ya=Xa;function Ha(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Qa=Ha;function Za(e,t){var r=e.__data__;return Qa(t)?r[typeof t=="string"?"string":"hash"]:r.map}var X=Za;function eo(e){var t=X(this,e).delete(e);return this.size-=t?1:0,t}var to=eo;function ro(e){return X(this,e).get(e)}var ao=ro;function oo(e){return X(this,e).has(e)}var io=oo;function no(e,t){var r=X(this,e),a=r.size;return r.set(e,t),this.size+=r.size==a?0:1,this}var fo=no;function C(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}C.prototype.clear=Ya;C.prototype.delete=to;C.prototype.get=ao;C.prototype.has=io;C.prototype.set=fo;var Ve=C;function so(e,t){for(var r=-1,a=t.length,i=e.length;++r<a;)e[i+r]=t[r];return e}var lo=so;function uo(){this.__data__=new J,this.size=0}var po=uo;function co(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var mo=co;function xo(e){return this.__data__.get(e)}var go=xo;function vo(e){return this.__data__.has(e)}var ho=vo,bo=200;function yo(e,t){var r=this.__data__;if(r instanceof J){var a=r.__data__;if(!L||a.length<bo-1)return a.push([e,t]),this.size=++r.size,this;r=this.__data__=new Ve(a)}return r.set(e,t),this.size=r.size,this}var So=yo;function A(e){var t=this.__data__=new J(e);this.size=t.size}A.prototype.clear=po;A.prototype.delete=mo;A.prototype.get=go;A.prototype.has=ho;A.prototype.set=So;var te=A;function _o(e,t){for(var r=-1,a=e==null?0:e.length,i=0,o=[];++r<a;){var n=e[r];t(n,r,e)&&(o[i++]=n)}return o}var Io=_o;function ko(){return[]}var jo=ko,Oo=Object.prototype,wo=Oo.propertyIsEnumerable,Se=Object.getOwnPropertySymbols,Ro=Se?function(e){return e==null?[]:(e=Object(e),Io(Se(e),function(t){return wo.call(e,t)}))}:jo,Eo=Ro;function Po(e,t,r){var a=t(e);return $(e)?a:lo(a,r(e))}var Fo=Po;function Co(e){return Fo(e,va,Eo)}var _e=Co,Ao=E(S,"DataView"),ne=Ao,Bo=E(S,"Promise"),fe=Bo,Do=E(S,"Set"),se=Do,Ie="[object Map]",No="[object Object]",ke="[object Promise]",je="[object Set]",Oe="[object WeakMap]",we="[object DataView]",Uo=j(ne),To=j(L),Mo=j(fe),Lo=j(se),zo=j(oe),k=z;(ne&&k(new ne(new ArrayBuffer(1)))!=we||L&&k(new L)!=Ie||fe&&k(fe.resolve())!=ke||se&&k(new se)!=je||oe&&k(new oe)!=Oe)&&(k=function(e){var t=z(e),r=t==No?e.constructor:void 0,a=r?j(r):"";if(a)switch(a){case Uo:return we;case To:return Ie;case Mo:return ke;case Lo:return je;case zo:return Oe}return t});var Re=k,Wo=S.Uint8Array,Ee=Wo,Go="__lodash_hash_undefined__";function Vo(e){return this.__data__.set(e,Go),this}var $o=Vo;function qo(e){return this.__data__.has(e)}var Ko=qo;function q(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Ve;++t<r;)this.add(e[t])}q.prototype.add=q.prototype.push=$o;q.prototype.has=Ko;var Jo=q;function Xo(e,t){for(var r=-1,a=e==null?0:e.length;++r<a;)if(t(e[r],r,e))return!0;return!1}var Yo=Xo;function Ho(e,t){return e.has(t)}var Qo=Ho,Zo=1,ei=2;function ti(e,t,r,a,i,o){var n=r&Zo,f=e.length,l=t.length;if(f!=l&&!(n&&l>f))return!1;var s=o.get(e),d=o.get(t);if(s&&d)return s==t&&d==e;var p=-1,u=!0,m=r&ei?new Jo:void 0;for(o.set(e,t),o.set(t,e);++p<f;){var g=e[p],v=t[p];if(a)var b=n?a(v,g,p,t,e,o):a(g,v,p,e,t,o);if(b!==void 0){if(b)continue;u=!1;break}if(m){if(!Yo(t,function(h,y){if(!Qo(m,y)&&(g===h||i(g,h,r,a,o)))return m.push(y)})){u=!1;break}}else if(!(g===v||i(g,v,r,a,o))){u=!1;break}}return o.delete(e),o.delete(t),u}var $e=ti;function ri(e){var t=-1,r=Array(e.size);return e.forEach(function(a,i){r[++t]=[i,a]}),r}var ai=ri;function oi(e){var t=-1,r=Array(e.size);return e.forEach(function(a){r[++t]=a}),r}var ii=oi,ni=1,fi=2,si="[object Boolean]",li="[object Date]",ui="[object Error]",pi="[object Map]",di="[object Number]",ci="[object RegExp]",mi="[object Set]",xi="[object String]",gi="[object Symbol]",vi="[object ArrayBuffer]",hi="[object DataView]",Pe=R?R.prototype:void 0,re=Pe?Pe.valueOf:void 0;function bi(e,t,r,a,i,o,n){switch(r){case hi:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case vi:return!(e.byteLength!=t.byteLength||!o(new Ee(e),new Ee(t)));case si:case li:case di:return Te(+e,+t);case ui:return e.name==t.name&&e.message==t.message;case ci:case xi:return e==t+"";case pi:var f=ai;case mi:var l=a∋if(f||(f=ii),e.size!=t.size&&!l)return!1;var s=n.get(e);if(s)return s==t;a|=fi,n.set(e,t);var d=$e(f(e),f(t),a,i,o,n);return n.delete(e),d;case gi:if(re)return re.call(e)==re.call(t)}return!1}var yi=bi,Si=1,_i=Object.prototype,Ii=_i.hasOwnProperty;function ki(e,t,r,a,i,o){var n=r&Si,f=_e(e),l=f.length,s=_e(t),d=s.length;if(l!=d&&!n)return!1;for(var p=l;p--;){var u=f[p];if(!(n?u in t:Ii.call(t,u)))return!1}var m=o.get(e),g=o.get(t);if(m&&g)return m==t&&g==e;var v=!0;o.set(e,t),o.set(t,e);for(var b=n;++p<l;){u=f[p];var h=e[u],y=t[u];if(a)var G=n?a(y,h,u,t,e,o):a(h,y,u,e,t,o);if(!(G===void 0?h===y||i(h,y,r,a,o):G)){v=!1;break}b||(b=u=="constructor")}if(v&&!b){var w=e.constructor,_=t.constructor;w!=_&&"constructor"in e&&"constructor"in t&&!(typeof w=="function"&&w instanceof w&&typeof _=="function"&&_ instanceof _)&&(v=!1)}return o.delete(e),o.delete(t),v}var ji=ki,Oi=1,Fe="[object Arguments]",Ce="[object Array]",V="[object Object]",wi=Object.prototype,Ae=wi.hasOwnProperty;function Ri(e,t,r,a,i,o){var n=$(e),f=$(t),l=n?Ce:Re(e),s=f?Ce:Re(t);l=l==Fe?V:l,s=s==Fe?V:s;var d=l==V,p=s==V,u=l==s;if(u&&ie(e)){if(!ie(t))return!1;n=!0,d=!1}if(u&&!d)return o||(o=new te),n||Ge(e)?$e(e,t,r,a,i,o):yi(e,t,l,r,a,i,o);if(!(r&Oi)){var m=d&&Ae.call(e,"__wrapped__"),g=p&&Ae.call(t,"__wrapped__");if(m||g){var v=m?e.value():e,b=g?t.value():t;return o||(o=new te),i(v,b,r,a,o)}}return u?(o||(o=new te),ji(e,t,r,a,i,o)):!1}var Ei=Ri;function qe(e,t,r,a,i){return e===t?!0:e==null||t==null||!T(e)&&!T(t)?e!==e&&t!==t:Ei(e,t,r,a,qe,i)}var Pi=qe;function Fi(e,t){return Pi(e,t)}var ae=Fi,Ci=class extends ct{get(e){return super.get(e)??{status:"IDLE"}}isDuplicate(e){if(!this.cesdk.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING"||t.status==="ERROR"||!this.cesdk.engine.block.hasFill(e))return!1;let r=this.cesdk.engine.block.getFill(e);return!(t.blockId===e||t.fillId===r)}fixDuplicate(e){let t=this.cesdk.engine.block.getFill(e),r=this.get(e);r.status==="IDLE"||r.status==="PENDING"||r.status==="ERROR"||(this.set(e,{...r,blockId:e,fillId:t}),r.status==="PROCESSING"&&(this.recoverInitialImageData(e),this.clear(e)))}isConsistent(e){if(!this.cesdk.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING")return!0;if(!this.cesdk.engine.block.hasFill(e))return!1;let r=this.cesdk.engine.block.getFill(e);if(r==null||e!==t.blockId||r!==t.fillId)return!1;let a=this.cesdk.engine.block.getSourceSet(r,"fill/image/sourceSet"),i=this.cesdk.engine.block.getString(r,"fill/image/imageFileURI");if(a.length===0&&!i&&t.status==="PROCESSING")return!0;if(a?.length>0){let o=t.initialSourceSet;if(t.status==="PROCESSED"){if(!ae(a,t.processed)&&!ae(a,o))return!1}else if(!ae(a,o))return!1}else if(t.status==="PROCESSED"){if(i!==t.initialImageFileURI&&i!==t.processed)return!1}else if(i!==t.initialImageFileURI)return!1;return!0}recoverInitialImageData(e){if(!this.cesdk.engine.block.hasFill(e))return;let t=this.get(e);if(t.status==="PENDING"||t.status==="IDLE")return;let r=t.initialSourceSet,a=t.initialImageFileURI,i=t.initialPreviewFileURI,o=this.getValidFill(e,t);o!=null&&(a&&this.cesdk.engine.block.setString(o,"fill/image/imageFileURI",a),i&&this.cesdk.engine.block.setString(o,"fill/image/previewFileURI",i),r.length>0&&this.cesdk.engine.block.setSourceSet(o,"fill/image/sourceSet",r))}getValidFill(e,t){if(!this.cesdk.engine.block.isValid(e)||!this.cesdk.engine.block.hasFill(e)||e!==t.blockId)return;let r=this.cesdk.engine.block.getFill(e);if(r===t.fillId)return r}},Ke=Ci;async function le(e,t,r,a,i){let o=e.engine.block;if(!o.hasFill(t))throw new Error("Block has no fill to process");let n=o.getFill(t),f=o.getSourceSet(n,"fill/image/sourceSet"),l=o.getString(n,"fill/image/imageFileURI"),s=o.getString(n,"fill/image/previewFileURI");try{o.setString(n,"fill/image/imageFileURI",""),o.setSourceSet(n,"fill/image/sourceSet",[]),r.set(t,{...r.get(t),version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"PROCESSING"});let d=f.sort((u,m)=>m.width*m.height-u.height*u.width),p=f.length>0?d[0].uri:l;if(s||o.setString(n,"fill/image/previewFileURI",p),f.length>0){let u=await a(f);if(r.get(t).status!=="PROCESSING"||!r.isConsistent(t)||r.get(t).status!=="PROCESSING"||!r.isConsistent(t)||u==null)return;if(u.every(m=>m==null))throw new Error("Empty source set after processing fill");r.set(t,{version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"PROCESSED",processed:u}),o.setSourceSet(n,"fill/image/sourceSet",u),o.setString(n,"fill/image/previewFileURI","")}else{let u=await i(p);if(r.get(t).status!=="PROCESSING"||!r.isConsistent(t)||r.get(t).status!=="PROCESSING"||!r.isConsistent(t))return;if(u==null)throw new Error("Could not upload fill processed data");r.set(t,{version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"PROCESSED",processed:u}),o.setString(n,"fill/image/imageFileURI",u),o.setString(n,"fill/image/previewFileURI","")}e.engine.editor.addUndoStep()}catch(d){e.engine.block.isValid(t)&&(r.set(t,{version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"ERROR"}),r.recoverInitialImageData(t)),d!=null&&typeof d=="object"&&"message"in d&&typeof d.message=="string"&&e.ui.showNotification({type:"error",message:d.message}),console.log(d)}}function Je(e){return`${e}.fillProcessing.feature`}function Ai(e){return`${e}.fillProcessing.canvasMenu`}function Bi(e){return`plugin.${e}.fillProcessing.canvasMenu.button.label`}function Xe(e,{pluginId:t,process:r}){let a=Je(t),i=new Ke(e,t);return Di(e,i,a),e.engine.event.subscribe([],async o=>{o.forEach(n=>{let f=n.block;if(!(!e.engine.block.isValid(f)||!i.hasData(f))){if(n.type==="Created")i.isDuplicate(f)&&i.fixDuplicate(f);else if(n.type==="Updated")switch(i.get(f).status){case"PENDING":{e.feature.unstable_isEnabled(a,{engine:e.engine})&&e.engine.block.isAllowedByScope(f,"fill/change")&&r(f,i);break}case"PROCESSING":case"PROCESSED":{i.isConsistent(f)||i.clear(f);break}default:}}})}),{featureId:a}}function Di(e,t,r){e.feature.unstable_enable(r,({engine:a})=>{let i=a.block.findAllSelected();if(i.length!==1)return!1;let[o]=i;if(!e.engine.block.isVisible(o))return!1;if(e.engine.block.hasFill(o)){if(e.engine.block.getKind(o)==="sticker")return!1;let n=e.engine.block.getFill(o);if(e.engine.block.getType(n)!=="//ly.img.ubq/fill/image")return!1;let f=a.block.getString(n,"fill/image/imageFileURI");return a.block.getSourceSet(n,"fill/image/sourceSet").length>0||f!==""?!0:t.get(o).status==="PROCESSING"}return!1})}function Ye(e,t){let{pluginId:r,locations:a}=t,i=new Ke(e,r),o=Ai(r),n=Bi(r),f=Je(r);return a?.includes("canvasMenu")&&e.ui.unstable_setCanvasMenuOrder([o,...e.ui.unstable_getCanvasMenuOrder()]),e.ui.unstable_registerComponent(o,({builder:{Button:l},engine:s})=>{if(!e.feature.unstable_isEnabled(f,{engine:s}))return;let[d]=s.block.findAllSelected();if(!e.engine.block.isAllowedByScope(d,"fill/change"))return;let p=i.get(d),u=p.status==="PROCESSING",m=p.status==="PENDING"||p.status==="PROCESSING",g;if(u&&p.progress){let{current:b,total:h}=p.progress;g=b/h*100}let v=`${o}.button`;l(v,{label:n,icon:t.icon,isLoading:u,isDisabled:m,loadingProgress:g,onClick:()=>{(p.status==="IDLE"||p.status==="ERROR"||p.status==="PROCESSED")&&i.set(d,{status:"PENDING"})}})}),{canvasMenuComponentId:o,translationsKeys:{canvasMenuLabel:n}}}import{applySegmentationMask as gn,removeBackground as vn,segmentForeground as hn}from"@imgly/background-removal";var Ni=typeof global=="object"&&global&&global.Object===Object&&global,He=Ni;var Ui=typeof self=="object"&&self&&self.Object===Object&&self,Ti=He||Ui||Function("return this")(),Y=Ti;var Mi=Y.Symbol,B=Mi;var Qe=Object.prototype,Li=Qe.hasOwnProperty,zi=Qe.toString,W=B?B.toStringTag:void 0;function Wi(e){var t=Li.call(e,W),r=e[W];try{e[W]=void 0;var a=!0}catch{}var i=zi.call(e);return a&&(t?e[W]=r:delete e[W]),i}var Ze=Wi;var Gi=Object.prototype,Vi=Gi.toString;function $i(e){return Vi.call(e)}var et=$i;var qi="[object Null]",Ki="[object Undefined]",tt=B?B.toStringTag:void 0;function Ji(e){return e==null?e===void 0?Ki:qi:tt&&tt in Object(e)?Ze(e):et(e)}var rt=Ji;function Xi(e){return e!=null&&typeof e=="object"}var at=Xi;var Yi="[object Symbol]";function Hi(e){return typeof e=="symbol"||at(e)&&rt(e)==Yi}var ot=Hi;var Qi=/\s/;function Zi(e){for(var t=e.length;t--&&Qi.test(e.charAt(t)););return t}var it=Zi;var en=/^\s+/;function tn(e){return e&&e.slice(0,it(e)+1).replace(en,"")}var nt=tn;function rn(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var O=rn;var ft=NaN,an=/^[-+]0x[0-9a-f]+$/i,on=/^0b[01]+$/i,nn=/^0o[0-7]+$/i,fn=parseInt;function sn(e){if(typeof e=="number")return e;if(ot(e))return ft;if(O(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=O(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=nt(e);var r=on.test(e);return r||nn.test(e)?fn(e.slice(2),r?2:8):an.test(e)?ft:+e}var ue=sn;var ln=function(){return Y.Date.now()},H=ln;var un="Expected a function",pn=Math.max,dn=Math.min;function cn(e,t,r){var a,i,o,n,f,l,s=0,d=!1,p=!1,u=!0;if(typeof e!="function")throw new TypeError(un);t=ue(t)||0,O(r)&&(d=!!r.leading,p="maxWait"in r,o=p?pn(ue(r.maxWait)||0,t):o,u="trailing"in r?!!r.trailing:u);function m(x){var I=a,D=i;return a=i=void 0,s=x,n=e.apply(D,I),n}function g(x){return s=x,f=setTimeout(h,t),d?m(x):n}function v(x){var I=x-l,D=x-s,de=t-I;return p?dn(de,o-D):de}function b(x){var I=x-l,D=x-s;return l===void 0||I>=t||I<0||p&&D>=o}function h(){var x=H();if(b(x))return y(x);f=setTimeout(h,v(x))}function y(x){return f=void 0,u&&a?m(x):(a=i=void 0,n)}function G(){f!==void 0&&clearTimeout(f),s=0,a=l=i=f=void 0}function w(){return f===void 0?n:y(H())}function _(){var x=H(),I=b(x);if(a=arguments,i=this,l=x,I){if(f===void 0)return g(l);if(p)return clearTimeout(f),f=setTimeout(h,t),m(l)}return f===void 0&&(f=setTimeout(h,t)),n}return _.cancel=G,_.flush=w,_}var st=cn;var mn="Expected a function";function xn(e,t,r){var a=!0,i=!0;if(typeof e!="function")throw new TypeError(mn);return O(r)&&(a="leading"in r?!!r.leading:a,i="trailing"in r?!!r.trailing:i),st(e,t,{leading:a,maxWait:t,trailing:i})}var pe=xn;async function ut(e,t,r,a){switch(a.type){case"@imgly/background-removal":{let i=a.configuration??{},o={device:"gpu",...i,progress:pe((n,f,l)=>{let s=r.get(t);s.status!=="PROCESSING"||!r.isConsistent(t)||(i.progress?.(n,f,l),r.set(t,{...s,progress:{key:n,current:f,total:l}}))},100)};le(e,t,r,async n=>{let f=n[0].uri,l=await hn(f,i);return await Promise.all(n.map(async d=>{let p=await gn(d.uri,l,o),u=await lt(p,d.uri,e);return{...d,uri:u}}))},async n=>{let f=await vn(n,o);return await lt(f,n,e)});break}case"custom":{le(e,t,r,a.processSourceSet,a.processImageFileURI);break}default:throw new Error("Unknown background removal provider")}}async function lt(e,t,r){let i=new URL(t).pathname.split("/"),o=i[i.length-1],f=(await r.unstable_upload(new File([e],o,{type:e.type}),()=>{})).meta?.uri;if(f==null)throw new Error("Could not upload processed fill");return f}var Q="@imgly/plugin-background-removal-web",pt=(e={})=>({initialize(){},update(){},initializeUserInterface({cesdk:t}){Xe(t,{pluginId:Q,process:(a,i)=>{ut(t,a,i,e.provider??{type:"@imgly/background-removal"})}});let{translationsKeys:r}=Ye(t,{pluginId:Q,icon:"@imgly/icons/BGRemove",locations:e.ui?.locations});t.setTranslations({en:{[r.canvasMenuLabel]:"BG Removal"}})}});var bn=e=>({name:Q,version:"0.3.0-rc.1",...pt(e)}),cf=bn;export{cf as default};
|
|
1
|
+
var dt=class{constructor(e,t){this.cesdk=e,this.key=t}hasData(e){return this.cesdk.engine.block.isValid(e)&&this.cesdk.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.cesdk.engine.block.getMetadata(e,this.key))}set(e,t){this.cesdk.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.cesdk.engine.block.hasMetadata(e,this.key)&&this.cesdk.engine.block.removeMetadata(e,this.key)}},ct=dt,mt=typeof global=="object"&&global&&global.Object===Object&&global,Be=mt,xt=typeof self=="object"&&self&&self.Object===Object&&self,gt=Be||xt||Function("return this")(),S=gt,vt=S.Symbol,R=vt,De=Object.prototype,ht=De.hasOwnProperty,bt=De.toString,N=R?R.toStringTag:void 0;function yt(e){var t=ht.call(e,N),r=e[N];try{e[N]=void 0;var a=!0}catch{}var i=bt.call(e);return a&&(t?e[N]=r:delete e[N]),i}var St=yt,_t=Object.prototype,It=_t.toString;function kt(e){return It.call(e)}var jt=kt,Ot="[object Null]",wt="[object Undefined]",ce=R?R.toStringTag:void 0;function Rt(e){return e==null?e===void 0?wt:Ot:ce&&ce in Object(e)?St(e):jt(e)}var z=Rt;function Et(e){return e!=null&&typeof e=="object"}var T=Et,Pt=Array.isArray,$=Pt;function Ft(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Ne=Ft,Ct="[object AsyncFunction]",At="[object Function]",Bt="[object GeneratorFunction]",Dt="[object Proxy]";function Nt(e){if(!Ne(e))return!1;var t=z(e);return t==At||t==Bt||t==Ct||t==Dt}var Ue=Nt,Ut=S["__core-js_shared__"],Z=Ut,me=function(){var e=/[^.]+$/.exec(Z&&Z.keys&&Z.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Tt(e){return!!me&&me in e}var Mt=Tt,Lt=Function.prototype,zt=Lt.toString;function Wt(e){if(e!=null){try{return zt.call(e)}catch{}try{return e+""}catch{}}return""}var j=Wt,Gt=/[\\^$.*+?()[\]{}|]/g,Vt=/^\[object .+?Constructor\]$/,$t=Function.prototype,qt=Object.prototype,Kt=$t.toString,Jt=qt.hasOwnProperty,Xt=RegExp("^"+Kt.call(Jt).replace(Gt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Yt(e){if(!Ne(e)||Mt(e))return!1;var t=Ue(e)?Xt:Vt;return t.test(j(e))}var Ht=Yt;function Qt(e,t){return e?.[t]}var Zt=Qt;function er(e,t){var r=Zt(e,t);return Ht(r)?r:void 0}var E=er,tr=E(S,"WeakMap"),oe=tr,rr=9007199254740991,ar=/^(?:0|[1-9]\d*)$/;function or(e,t){var r=typeof e;return t=t??rr,!!t&&(r=="number"||r!="symbol"&&ar.test(e))&&e>-1&&e%1==0&&e<t}var ir=or;function nr(e,t){return e===t||e!==e&&t!==t}var Te=nr,fr=9007199254740991;function sr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=fr}var Me=sr;function lr(e){return e!=null&&Me(e.length)&&!Ue(e)}var ur=lr,pr=Object.prototype;function dr(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||pr;return e===r}var cr=dr;function mr(e,t){for(var r=-1,a=Array(e);++r<e;)a[r]=t(r);return a}var xr=mr,gr="[object Arguments]";function vr(e){return T(e)&&z(e)==gr}var xe=vr,Le=Object.prototype,hr=Le.hasOwnProperty,br=Le.propertyIsEnumerable,yr=xe(function(){return arguments}())?xe:function(e){return T(e)&&hr.call(e,"callee")&&!br.call(e,"callee")},Sr=yr;function _r(){return!1}var Ir=_r,ze=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ge=ze&&typeof module=="object"&&module&&!module.nodeType&&module,kr=ge&&ge.exports===ze,ve=kr?S.Buffer:void 0,jr=ve?ve.isBuffer:void 0,Or=jr||Ir,ie=Or,wr="[object Arguments]",Rr="[object Array]",Er="[object Boolean]",Pr="[object Date]",Fr="[object Error]",Cr="[object Function]",Ar="[object Map]",Br="[object Number]",Dr="[object Object]",Nr="[object RegExp]",Ur="[object Set]",Tr="[object String]",Mr="[object WeakMap]",Lr="[object ArrayBuffer]",zr="[object DataView]",Wr="[object Float32Array]",Gr="[object Float64Array]",Vr="[object Int8Array]",$r="[object Int16Array]",qr="[object Int32Array]",Kr="[object Uint8Array]",Jr="[object Uint8ClampedArray]",Xr="[object Uint16Array]",Yr="[object Uint32Array]",c={};c[Wr]=c[Gr]=c[Vr]=c[$r]=c[qr]=c[Kr]=c[Jr]=c[Xr]=c[Yr]=!0;c[wr]=c[Rr]=c[Lr]=c[Er]=c[zr]=c[Pr]=c[Fr]=c[Cr]=c[Ar]=c[Br]=c[Dr]=c[Nr]=c[Ur]=c[Tr]=c[Mr]=!1;function Hr(e){return T(e)&&Me(e.length)&&!!c[z(e)]}var Qr=Hr;function Zr(e){return function(t){return e(t)}}var ea=Zr,We=typeof exports=="object"&&exports&&!exports.nodeType&&exports,U=We&&typeof module=="object"&&module&&!module.nodeType&&module,ta=U&&U.exports===We,ee=ta&&Be.process,ra=function(){try{var e=U&&U.require&&U.require("util").types;return e||ee&&ee.binding&&ee.binding("util")}catch{}}(),he=ra,be=he&&he.isTypedArray,aa=be?ea(be):Qr,Ge=aa,oa=Object.prototype,ia=oa.hasOwnProperty;function na(e,t){var r=$(e),a=!r&&Sr(e),i=!r&&!a&&ie(e),o=!r&&!a&&!i&&Ge(e),n=r||a||i||o,f=n?xr(e.length,String):[],l=f.length;for(var s in e)(t||ia.call(e,s))&&!(n&&(s=="length"||i&&(s=="offset"||s=="parent")||o&&(s=="buffer"||s=="byteLength"||s=="byteOffset")||ir(s,l)))&&f.push(s);return f}var fa=na;function sa(e,t){return function(r){return e(t(r))}}var la=sa,ua=la(Object.keys,Object),pa=ua,da=Object.prototype,ca=da.hasOwnProperty;function ma(e){if(!cr(e))return pa(e);var t=[];for(var r in Object(e))ca.call(e,r)&&r!="constructor"&&t.push(r);return t}var xa=ma;function ga(e){return ur(e)?fa(e):xa(e)}var va=ga,ha=E(Object,"create"),M=ha;function ba(){this.__data__=M?M(null):{},this.size=0}var ya=ba;function Sa(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var _a=Sa,Ia="__lodash_hash_undefined__",ka=Object.prototype,ja=ka.hasOwnProperty;function Oa(e){var t=this.__data__;if(M){var r=t[e];return r===Ia?void 0:r}return ja.call(t,e)?t[e]:void 0}var wa=Oa,Ra=Object.prototype,Ea=Ra.hasOwnProperty;function Pa(e){var t=this.__data__;return M?t[e]!==void 0:Ea.call(t,e)}var Fa=Pa,Ca="__lodash_hash_undefined__";function Aa(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=M&&t===void 0?Ca:t,this}var Ba=Aa;function P(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}P.prototype.clear=ya;P.prototype.delete=_a;P.prototype.get=wa;P.prototype.has=Fa;P.prototype.set=Ba;var ye=P;function Da(){this.__data__=[],this.size=0}var Na=Da;function Ua(e,t){for(var r=e.length;r--;)if(Te(e[r][0],t))return r;return-1}var K=Ua,Ta=Array.prototype,Ma=Ta.splice;function La(e){var t=this.__data__,r=K(t,e);if(r<0)return!1;var a=t.length-1;return r==a?t.pop():Ma.call(t,r,1),--this.size,!0}var za=La;function Wa(e){var t=this.__data__,r=K(t,e);return r<0?void 0:t[r][1]}var Ga=Wa;function Va(e){return K(this.__data__,e)>-1}var $a=Va;function qa(e,t){var r=this.__data__,a=K(r,e);return a<0?(++this.size,r.push([e,t])):r[a][1]=t,this}var Ka=qa;function F(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}F.prototype.clear=Na;F.prototype.delete=za;F.prototype.get=Ga;F.prototype.has=$a;F.prototype.set=Ka;var J=F,Ja=E(S,"Map"),L=Ja;function Xa(){this.size=0,this.__data__={hash:new ye,map:new(L||J),string:new ye}}var Ya=Xa;function Ha(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var Qa=Ha;function Za(e,t){var r=e.__data__;return Qa(t)?r[typeof t=="string"?"string":"hash"]:r.map}var X=Za;function eo(e){var t=X(this,e).delete(e);return this.size-=t?1:0,t}var to=eo;function ro(e){return X(this,e).get(e)}var ao=ro;function oo(e){return X(this,e).has(e)}var io=oo;function no(e,t){var r=X(this,e),a=r.size;return r.set(e,t),this.size+=r.size==a?0:1,this}var fo=no;function C(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}C.prototype.clear=Ya;C.prototype.delete=to;C.prototype.get=ao;C.prototype.has=io;C.prototype.set=fo;var Ve=C;function so(e,t){for(var r=-1,a=t.length,i=e.length;++r<a;)e[i+r]=t[r];return e}var lo=so;function uo(){this.__data__=new J,this.size=0}var po=uo;function co(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var mo=co;function xo(e){return this.__data__.get(e)}var go=xo;function vo(e){return this.__data__.has(e)}var ho=vo,bo=200;function yo(e,t){var r=this.__data__;if(r instanceof J){var a=r.__data__;if(!L||a.length<bo-1)return a.push([e,t]),this.size=++r.size,this;r=this.__data__=new Ve(a)}return r.set(e,t),this.size=r.size,this}var So=yo;function A(e){var t=this.__data__=new J(e);this.size=t.size}A.prototype.clear=po;A.prototype.delete=mo;A.prototype.get=go;A.prototype.has=ho;A.prototype.set=So;var te=A;function _o(e,t){for(var r=-1,a=e==null?0:e.length,i=0,o=[];++r<a;){var n=e[r];t(n,r,e)&&(o[i++]=n)}return o}var Io=_o;function ko(){return[]}var jo=ko,Oo=Object.prototype,wo=Oo.propertyIsEnumerable,Se=Object.getOwnPropertySymbols,Ro=Se?function(e){return e==null?[]:(e=Object(e),Io(Se(e),function(t){return wo.call(e,t)}))}:jo,Eo=Ro;function Po(e,t,r){var a=t(e);return $(e)?a:lo(a,r(e))}var Fo=Po;function Co(e){return Fo(e,va,Eo)}var _e=Co,Ao=E(S,"DataView"),ne=Ao,Bo=E(S,"Promise"),fe=Bo,Do=E(S,"Set"),se=Do,Ie="[object Map]",No="[object Object]",ke="[object Promise]",je="[object Set]",Oe="[object WeakMap]",we="[object DataView]",Uo=j(ne),To=j(L),Mo=j(fe),Lo=j(se),zo=j(oe),k=z;(ne&&k(new ne(new ArrayBuffer(1)))!=we||L&&k(new L)!=Ie||fe&&k(fe.resolve())!=ke||se&&k(new se)!=je||oe&&k(new oe)!=Oe)&&(k=function(e){var t=z(e),r=t==No?e.constructor:void 0,a=r?j(r):"";if(a)switch(a){case Uo:return we;case To:return Ie;case Mo:return ke;case Lo:return je;case zo:return Oe}return t});var Re=k,Wo=S.Uint8Array,Ee=Wo,Go="__lodash_hash_undefined__";function Vo(e){return this.__data__.set(e,Go),this}var $o=Vo;function qo(e){return this.__data__.has(e)}var Ko=qo;function q(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Ve;++t<r;)this.add(e[t])}q.prototype.add=q.prototype.push=$o;q.prototype.has=Ko;var Jo=q;function Xo(e,t){for(var r=-1,a=e==null?0:e.length;++r<a;)if(t(e[r],r,e))return!0;return!1}var Yo=Xo;function Ho(e,t){return e.has(t)}var Qo=Ho,Zo=1,ei=2;function ti(e,t,r,a,i,o){var n=r&Zo,f=e.length,l=t.length;if(f!=l&&!(n&&l>f))return!1;var s=o.get(e),d=o.get(t);if(s&&d)return s==t&&d==e;var p=-1,u=!0,m=r&ei?new Jo:void 0;for(o.set(e,t),o.set(t,e);++p<f;){var g=e[p],v=t[p];if(a)var b=n?a(v,g,p,t,e,o):a(g,v,p,e,t,o);if(b!==void 0){if(b)continue;u=!1;break}if(m){if(!Yo(t,function(h,y){if(!Qo(m,y)&&(g===h||i(g,h,r,a,o)))return m.push(y)})){u=!1;break}}else if(!(g===v||i(g,v,r,a,o))){u=!1;break}}return o.delete(e),o.delete(t),u}var $e=ti;function ri(e){var t=-1,r=Array(e.size);return e.forEach(function(a,i){r[++t]=[i,a]}),r}var ai=ri;function oi(e){var t=-1,r=Array(e.size);return e.forEach(function(a){r[++t]=a}),r}var ii=oi,ni=1,fi=2,si="[object Boolean]",li="[object Date]",ui="[object Error]",pi="[object Map]",di="[object Number]",ci="[object RegExp]",mi="[object Set]",xi="[object String]",gi="[object Symbol]",vi="[object ArrayBuffer]",hi="[object DataView]",Pe=R?R.prototype:void 0,re=Pe?Pe.valueOf:void 0;function bi(e,t,r,a,i,o,n){switch(r){case hi:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case vi:return!(e.byteLength!=t.byteLength||!o(new Ee(e),new Ee(t)));case si:case li:case di:return Te(+e,+t);case ui:return e.name==t.name&&e.message==t.message;case ci:case xi:return e==t+"";case pi:var f=ai;case mi:var l=a∋if(f||(f=ii),e.size!=t.size&&!l)return!1;var s=n.get(e);if(s)return s==t;a|=fi,n.set(e,t);var d=$e(f(e),f(t),a,i,o,n);return n.delete(e),d;case gi:if(re)return re.call(e)==re.call(t)}return!1}var yi=bi,Si=1,_i=Object.prototype,Ii=_i.hasOwnProperty;function ki(e,t,r,a,i,o){var n=r&Si,f=_e(e),l=f.length,s=_e(t),d=s.length;if(l!=d&&!n)return!1;for(var p=l;p--;){var u=f[p];if(!(n?u in t:Ii.call(t,u)))return!1}var m=o.get(e),g=o.get(t);if(m&&g)return m==t&&g==e;var v=!0;o.set(e,t),o.set(t,e);for(var b=n;++p<l;){u=f[p];var h=e[u],y=t[u];if(a)var G=n?a(y,h,u,t,e,o):a(h,y,u,e,t,o);if(!(G===void 0?h===y||i(h,y,r,a,o):G)){v=!1;break}b||(b=u=="constructor")}if(v&&!b){var w=e.constructor,_=t.constructor;w!=_&&"constructor"in e&&"constructor"in t&&!(typeof w=="function"&&w instanceof w&&typeof _=="function"&&_ instanceof _)&&(v=!1)}return o.delete(e),o.delete(t),v}var ji=ki,Oi=1,Fe="[object Arguments]",Ce="[object Array]",V="[object Object]",wi=Object.prototype,Ae=wi.hasOwnProperty;function Ri(e,t,r,a,i,o){var n=$(e),f=$(t),l=n?Ce:Re(e),s=f?Ce:Re(t);l=l==Fe?V:l,s=s==Fe?V:s;var d=l==V,p=s==V,u=l==s;if(u&&ie(e)){if(!ie(t))return!1;n=!0,d=!1}if(u&&!d)return o||(o=new te),n||Ge(e)?$e(e,t,r,a,i,o):yi(e,t,l,r,a,i,o);if(!(r&Oi)){var m=d&&Ae.call(e,"__wrapped__"),g=p&&Ae.call(t,"__wrapped__");if(m||g){var v=m?e.value():e,b=g?t.value():t;return o||(o=new te),i(v,b,r,a,o)}}return u?(o||(o=new te),ji(e,t,r,a,i,o)):!1}var Ei=Ri;function qe(e,t,r,a,i){return e===t?!0:e==null||t==null||!T(e)&&!T(t)?e!==e&&t!==t:Ei(e,t,r,a,qe,i)}var Pi=qe;function Fi(e,t){return Pi(e,t)}var ae=Fi,Ci=class extends ct{get(e){return super.get(e)??{status:"IDLE"}}isDuplicate(e){if(!this.cesdk.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING"||t.status==="ERROR"||!this.cesdk.engine.block.hasFill(e))return!1;let r=this.cesdk.engine.block.getFill(e);return!(t.blockId===e||t.fillId===r)}fixDuplicate(e){let t=this.cesdk.engine.block.getFill(e),r=this.get(e);r.status==="IDLE"||r.status==="PENDING"||r.status==="ERROR"||(this.set(e,{...r,blockId:e,fillId:t}),r.status==="PROCESSING"&&(this.recoverInitialImageData(e),this.clear(e)))}isConsistent(e){if(!this.cesdk.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING")return!0;if(!this.cesdk.engine.block.hasFill(e))return!1;let r=this.cesdk.engine.block.getFill(e);if(r==null||e!==t.blockId||r!==t.fillId)return!1;let a=this.cesdk.engine.block.getSourceSet(r,"fill/image/sourceSet"),i=this.cesdk.engine.block.getString(r,"fill/image/imageFileURI");if(a.length===0&&!i&&t.status==="PROCESSING")return!0;if(a?.length>0){let o=t.initialSourceSet;if(t.status==="PROCESSED"){if(!ae(a,t.processed)&&!ae(a,o))return!1}else if(!ae(a,o))return!1}else if(t.status==="PROCESSED"){if(i!==t.initialImageFileURI&&i!==t.processed)return!1}else if(i!==t.initialImageFileURI)return!1;return!0}recoverInitialImageData(e){if(!this.cesdk.engine.block.hasFill(e))return;let t=this.get(e);if(t.status==="PENDING"||t.status==="IDLE")return;let r=t.initialSourceSet,a=t.initialImageFileURI,i=t.initialPreviewFileURI,o=this.getValidFill(e,t);o!=null&&(a&&this.cesdk.engine.block.setString(o,"fill/image/imageFileURI",a),i&&this.cesdk.engine.block.setString(o,"fill/image/previewFileURI",i),r.length>0&&this.cesdk.engine.block.setSourceSet(o,"fill/image/sourceSet",r))}getValidFill(e,t){if(!this.cesdk.engine.block.isValid(e)||!this.cesdk.engine.block.hasFill(e)||e!==t.blockId)return;let r=this.cesdk.engine.block.getFill(e);if(r===t.fillId)return r}},Ke=Ci;async function le(e,t,r,a,i){let o=e.engine.block;if(!o.hasFill(t))throw new Error("Block has no fill to process");let n=o.getFill(t),f=o.getSourceSet(n,"fill/image/sourceSet"),l=o.getString(n,"fill/image/imageFileURI"),s=o.getString(n,"fill/image/previewFileURI");try{o.setString(n,"fill/image/imageFileURI",""),o.setSourceSet(n,"fill/image/sourceSet",[]),r.set(t,{...r.get(t),version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"PROCESSING"});let d=f.sort((u,m)=>m.width*m.height-u.height*u.width),p=f.length>0?d[0].uri:l;if(s||o.setString(n,"fill/image/previewFileURI",p),f.length>0){let u=await a(f);if(r.get(t).status!=="PROCESSING"||!r.isConsistent(t)||r.get(t).status!=="PROCESSING"||!r.isConsistent(t)||u==null)return;if(u.every(m=>m==null))throw new Error("Empty source set after processing fill");r.set(t,{version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"PROCESSED",processed:u}),o.setSourceSet(n,"fill/image/sourceSet",u),o.setString(n,"fill/image/previewFileURI","")}else{let u=await i(p);if(r.get(t).status!=="PROCESSING"||!r.isConsistent(t)||r.get(t).status!=="PROCESSING"||!r.isConsistent(t))return;if(u==null)throw new Error("Could not upload fill processed data");r.set(t,{version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"PROCESSED",processed:u}),o.setString(n,"fill/image/imageFileURI",u),o.setString(n,"fill/image/previewFileURI","")}e.engine.editor.addUndoStep()}catch(d){e.engine.block.isValid(t)&&(r.set(t,{version:"0.0.0",initialSourceSet:f,initialImageFileURI:l,initialPreviewFileURI:s,blockId:t,fillId:n,status:"ERROR"}),r.recoverInitialImageData(t)),d!=null&&typeof d=="object"&&"message"in d&&typeof d.message=="string"&&e.ui.showNotification({type:"error",message:d.message}),console.log(d)}}function Je(e){return`${e}.fillProcessing.feature`}function Ai(e){return`${e}.fillProcessing.canvasMenu`}function Bi(e){return`plugin.${e}.fillProcessing.canvasMenu.button.label`}function Xe(e,{pluginId:t,process:r}){let a=Je(t),i=new Ke(e,t);return Di(e,i,a),e.engine.event.subscribe([],async o=>{o.forEach(n=>{let f=n.block;if(!(!e.engine.block.isValid(f)||!i.hasData(f))){if(n.type==="Created")i.isDuplicate(f)&&i.fixDuplicate(f);else if(n.type==="Updated")switch(i.get(f).status){case"PENDING":{e.feature.unstable_isEnabled(a,{engine:e.engine})&&e.engine.block.isAllowedByScope(f,"fill/change")&&r(f,i);break}case"PROCESSING":case"PROCESSED":{i.isConsistent(f)||i.clear(f);break}default:}}})}),{featureId:a}}function Di(e,t,r){e.feature.unstable_enable(r,({engine:a})=>{let i=a.block.findAllSelected();if(i.length!==1)return!1;let[o]=i;if(!e.engine.block.isVisible(o))return!1;if(e.engine.block.hasFill(o)){if(e.engine.block.getKind(o)==="sticker")return!1;let n=e.engine.block.getFill(o);if(e.engine.block.getType(n)!=="//ly.img.ubq/fill/image")return!1;let f=a.block.getString(n,"fill/image/imageFileURI");return a.block.getSourceSet(n,"fill/image/sourceSet").length>0||f!==""?!0:t.get(o).status==="PROCESSING"}return!1})}function Ye(e,t){let{pluginId:r,locations:a}=t,i=new Ke(e,r),o=Ai(r),n=Bi(r),f=Je(r);return a?.includes("canvasMenu")&&e.ui.unstable_setCanvasMenuOrder([o,...e.ui.unstable_getCanvasMenuOrder()]),e.ui.unstable_registerComponent(o,({builder:{Button:l},engine:s})=>{if(!e.feature.unstable_isEnabled(f,{engine:s}))return;let[d]=s.block.findAllSelected();if(!e.engine.block.isAllowedByScope(d,"fill/change"))return;let p=i.get(d),u=p.status==="PROCESSING",m=p.status==="PENDING"||p.status==="PROCESSING",g;if(u&&p.progress){let{current:b,total:h}=p.progress;g=b/h*100}let v=`${o}.button`;l(v,{label:n,icon:t.icon,isLoading:u,isDisabled:m,loadingProgress:g,onClick:()=>{(p.status==="IDLE"||p.status==="ERROR"||p.status==="PROCESSED")&&i.set(d,{status:"PENDING"})}})}),{canvasMenuComponentId:o,translationsKeys:{canvasMenuLabel:n}}}import{applySegmentationMask as gn,removeBackground as vn,segmentForeground as hn}from"@imgly/background-removal";var Ni=typeof global=="object"&&global&&global.Object===Object&&global,He=Ni;var Ui=typeof self=="object"&&self&&self.Object===Object&&self,Ti=He||Ui||Function("return this")(),Y=Ti;var Mi=Y.Symbol,B=Mi;var Qe=Object.prototype,Li=Qe.hasOwnProperty,zi=Qe.toString,W=B?B.toStringTag:void 0;function Wi(e){var t=Li.call(e,W),r=e[W];try{e[W]=void 0;var a=!0}catch{}var i=zi.call(e);return a&&(t?e[W]=r:delete e[W]),i}var Ze=Wi;var Gi=Object.prototype,Vi=Gi.toString;function $i(e){return Vi.call(e)}var et=$i;var qi="[object Null]",Ki="[object Undefined]",tt=B?B.toStringTag:void 0;function Ji(e){return e==null?e===void 0?Ki:qi:tt&&tt in Object(e)?Ze(e):et(e)}var rt=Ji;function Xi(e){return e!=null&&typeof e=="object"}var at=Xi;var Yi="[object Symbol]";function Hi(e){return typeof e=="symbol"||at(e)&&rt(e)==Yi}var ot=Hi;var Qi=/\s/;function Zi(e){for(var t=e.length;t--&&Qi.test(e.charAt(t)););return t}var it=Zi;var en=/^\s+/;function tn(e){return e&&e.slice(0,it(e)+1).replace(en,"")}var nt=tn;function rn(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var O=rn;var ft=NaN,an=/^[-+]0x[0-9a-f]+$/i,on=/^0b[01]+$/i,nn=/^0o[0-7]+$/i,fn=parseInt;function sn(e){if(typeof e=="number")return e;if(ot(e))return ft;if(O(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=O(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=nt(e);var r=on.test(e);return r||nn.test(e)?fn(e.slice(2),r?2:8):an.test(e)?ft:+e}var ue=sn;var ln=function(){return Y.Date.now()},H=ln;var un="Expected a function",pn=Math.max,dn=Math.min;function cn(e,t,r){var a,i,o,n,f,l,s=0,d=!1,p=!1,u=!0;if(typeof e!="function")throw new TypeError(un);t=ue(t)||0,O(r)&&(d=!!r.leading,p="maxWait"in r,o=p?pn(ue(r.maxWait)||0,t):o,u="trailing"in r?!!r.trailing:u);function m(x){var I=a,D=i;return a=i=void 0,s=x,n=e.apply(D,I),n}function g(x){return s=x,f=setTimeout(h,t),d?m(x):n}function v(x){var I=x-l,D=x-s,de=t-I;return p?dn(de,o-D):de}function b(x){var I=x-l,D=x-s;return l===void 0||I>=t||I<0||p&&D>=o}function h(){var x=H();if(b(x))return y(x);f=setTimeout(h,v(x))}function y(x){return f=void 0,u&&a?m(x):(a=i=void 0,n)}function G(){f!==void 0&&clearTimeout(f),s=0,a=l=i=f=void 0}function w(){return f===void 0?n:y(H())}function _(){var x=H(),I=b(x);if(a=arguments,i=this,l=x,I){if(f===void 0)return g(l);if(p)return clearTimeout(f),f=setTimeout(h,t),m(l)}return f===void 0&&(f=setTimeout(h,t)),n}return _.cancel=G,_.flush=w,_}var st=cn;var mn="Expected a function";function xn(e,t,r){var a=!0,i=!0;if(typeof e!="function")throw new TypeError(mn);return O(r)&&(a="leading"in r?!!r.leading:a,i="trailing"in r?!!r.trailing:i),st(e,t,{leading:a,maxWait:t,trailing:i})}var pe=xn;async function ut(e,t,r,a){switch(a.type){case"@imgly/background-removal":{let i=a.configuration??{},o={device:"gpu",...i,progress:pe((n,f,l)=>{let s=r.get(t);s.status!=="PROCESSING"||!r.isConsistent(t)||(i.progress?.(n,f,l),r.set(t,{...s,progress:{key:n,current:f,total:l}}))},100)};le(e,t,r,async n=>{let f=n[0].uri,l=await hn(f,i);return await Promise.all(n.map(async d=>{let p=await gn(d.uri,l,o),u=await lt(p,d.uri,e);return{...d,uri:u}}))},async n=>{let f=await vn(n,o);return await lt(f,n,e)});break}case"custom":{le(e,t,r,a.processSourceSet,a.processImageFileURI);break}default:throw new Error("Unknown background removal provider")}}async function lt(e,t,r){let i=new URL(t).pathname.split("/"),o=i[i.length-1],f=(await r.unstable_upload(new File([e],o,{type:e.type}),()=>{})).meta?.uri;if(f==null)throw new Error("Could not upload processed fill");return f}var Q="@imgly/plugin-background-removal-web",pt=(e={})=>({initialize(){},update(){},initializeUserInterface({cesdk:t}){Xe(t,{pluginId:Q,process:(a,i)=>{ut(t,a,i,e.provider??{type:"@imgly/background-removal"})}});let{translationsKeys:r}=Ye(t,{pluginId:Q,icon:"@imgly/icons/BGRemove",locations:e.ui?.locations});t.setTranslations({en:{[r.canvasMenuLabel]:"BG Removal"}})}});var bn=e=>({name:Q,version:"0.3.0-rc.2",...pt(e)}),cf=bn;export{cf as default};
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
lodash-es/lodash.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imgly/plugin-background-removal-web",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.2",
|
|
4
4
|
"description": "Background Removal plugin for the CE.SDK editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CE.SDK",
|
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
"concurrently": "^8.2.2",
|
|
64
64
|
"esbuild": "^0.19.11",
|
|
65
65
|
"eslint": "^8.51.0",
|
|
66
|
-
"typescript": "^5.3.3"
|
|
66
|
+
"typescript": "^5.3.3",
|
|
67
|
+
"@imgly/plugin-utils": "*"
|
|
67
68
|
},
|
|
68
69
|
"peerDependencies": {
|
|
69
70
|
"@cesdk/cesdk-js": "~1.21.0"
|
|
70
71
|
},
|
|
71
72
|
"dependencies": {
|
|
72
73
|
"@imgly/background-removal": "1.5.1",
|
|
73
|
-
"@imgly/plugin-utils": "*",
|
|
74
74
|
"lodash-es": "^4.17.21"
|
|
75
75
|
}
|
|
76
76
|
}
|