@imgly/plugin-background-removal-web 1.0.2 → 1.0.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/README.md CHANGED
@@ -6,11 +6,12 @@ This plugin introduces background removal for the CE.SDK editor, leveraging the
6
6
 
7
7
  ## Installation
8
8
 
9
- You can install the plugin via npm or yarn. Use the following commands to install the package:
9
+ You can install the plugin via npm or yarn.We are using the `onnxruntime-web` package as a peer dependency.
10
+ Use the following commands to install the package:
10
11
 
11
12
  ```
12
- yarn add @imgly/plugin-background-removal-web
13
- npm install @imgly/plugin-background-removal-web
13
+ yarn add @imgly/plugin-background-removal-web onnxruntime-web@1.21.0-dev.20250114-228dd16893
14
+ npm install @imgly/plugin-background-removal-web onnxruntime-web@1.21.0-dev.20250114-228dd16893
14
15
  ```
15
16
 
16
17
  ## Usage
@@ -23,20 +24,20 @@ import CreativeEditorSDK from '@cesdk/cesdk-js';
23
24
  import BackgroundRemovalPlugin from '@imgly/plugin-background-removal-web';
24
25
 
25
26
  const config = {
26
- license: '<your-license-here>',
27
- callbacks: {
28
- // Please note that the background removal plugin depends on an correctly
29
- // configured upload. 'local' will work for local testing, but in
30
- // production you will need something stable. Please take a look at:
31
- // https://img.ly/docs/cesdk/ui/guides/upload-images/
32
- onUpload: 'local'
33
- }
27
+ license: '<your-license-here>',
28
+ callbacks: {
29
+ // Please note that the background removal plugin depends on an correctly
30
+ // configured upload. 'local' will work for local testing, but in
31
+ // production you will need something stable. Please take a look at:
32
+ // https://img.ly/docs/cesdk/ui/guides/upload-images/
33
+ onUpload: 'local'
34
+ }
34
35
  };
35
36
 
36
37
  const cesdk = await CreativeEditorSDK.create(container, config);
37
38
  await cesdk.addDefaultAssetSources(),
38
- await cesdk.addDemoAssetSources({ sceneMode: 'Design' }),
39
- await cesdk.addPlugin(BackgroundRemovalPlugin());
39
+ await cesdk.addDemoAssetSources({ sceneMode: 'Design' }),
40
+ await cesdk.addPlugin(BackgroundRemovalPlugin());
40
41
 
41
42
  // Add the canvas menu component for background removal
42
43
  cesdk.ui.setCanvasMenuOrder([
@@ -61,7 +62,7 @@ using the following configuration:
61
62
  // 'inspectorBar', 'navigationBar'
62
63
  BackgroundRemovalPlugin({
63
64
  ui: { locations: 'canvasMenu' }
64
- })
65
+ });
65
66
  ```
66
67
 
67
68
  However, if you want to add the components manually, e.g. to be more flexible about the concrete position, you can use the following code snippet:
@@ -70,7 +71,7 @@ However, if you want to add the components manually, e.g. to be more flexible ab
70
71
  // Adding to the dock
71
72
  cesdk.ui.setDockOrder([
72
73
  ...cesdk.ui.getDockOrder(),
73
- '@imgly/plugin-background-removal-web.dock',
74
+ '@imgly/plugin-background-removal-web.dock'
74
75
  ]);
75
76
 
76
77
  // Adding to the inspector bar
@@ -87,6 +88,7 @@ cesdk.ui.setCanvasMenuOrder([
87
88
  ```
88
89
 
89
90
  ### Configuration of `@imgly/background-removal`
91
+
90
92
  By default, this plugin uses the `@imgly/background-removal-js` library to remove
91
93
  a background from the image fill. All configuration options from this underlying
92
94
  library can be used in this plugin.
@@ -126,52 +128,57 @@ It is possible to declare a different provider for the background removal proces
126
128
 
127
129
  ```typescript
128
130
  BackgroundRemovalPlugin({
129
- provider: {
130
- type: 'custom',
131
- // If the image has only one image file URI defined, this method will
132
- // be called. It must return a single new image file URI with the
133
- // removed background.
134
- processImageFileURI: async (imageFileURI: string) => {
135
- const blob = await removeBackground(imageFileURI);
136
- const upload = await uploadBlob(blob);
137
- return upload;
138
- },
139
- // Some images have a source set defined which provides multiple images
140
- // in different sizes.
141
- processSourceSet: async (
142
- // Source set for the current block sorted by the resolution.
143
- // URI with the highest URI is first
144
- sourceSet: {
145
- uri: string;
146
- width: number;
147
- height: number;
148
- }[],
149
- ) => {
150
- // You should call the remove background method on every URI in the
151
- // source set. Depending on your service or your algorithm, you
152
- // have the following options:
153
- // - Return a source set with a single image (will contradict the use-case of source sets and degrades the user experience)
154
- // - Create a segmented mask and apply it to every image (not always available)
155
- // - Create a new source set by resizing the resulting blob.
156
-
157
- // In this example we will do the last case.
158
- // First image has the highest resolution and might be the best
159
- // candidate to remove the background.
160
- const highestResolution = sourceSet[0];
161
- const highestResolutionBlob = await removeBackground(highestResolution.uri);
162
- const highestResolutionURI = await uploadBlob(highestResolutionBlob);
163
-
164
- const remainingSources = await Promise.all(
165
- sourceSet.slice(1).map((source) => {
166
- // ...
167
- const upload = uploadBlob(/* ... */)
168
- return { ...source, uri: upload };
169
- })
170
- );
171
-
172
- return [{ ...highestResolution, uri: highestResolutionURI }, remainingSources];
173
- }
131
+ provider: {
132
+ type: 'custom',
133
+ // If the image has only one image file URI defined, this method will
134
+ // be called. It must return a single new image file URI with the
135
+ // removed background.
136
+ processImageFileURI: async (imageFileURI: string) => {
137
+ const blob = await removeBackground(imageFileURI);
138
+ const upload = await uploadBlob(blob);
139
+ return upload;
140
+ },
141
+ // Some images have a source set defined which provides multiple images
142
+ // in different sizes.
143
+ processSourceSet: async (
144
+ // Source set for the current block sorted by the resolution.
145
+ // URI with the highest URI is first
146
+ sourceSet: {
147
+ uri: string;
148
+ width: number;
149
+ height: number;
150
+ }[]
151
+ ) => {
152
+ // You should call the remove background method on every URI in the
153
+ // source set. Depending on your service or your algorithm, you
154
+ // have the following options:
155
+ // - Return a source set with a single image (will contradict the use-case of source sets and degrades the user experience)
156
+ // - Create a segmented mask and apply it to every image (not always available)
157
+ // - Create a new source set by resizing the resulting blob.
158
+
159
+ // In this example we will do the last case.
160
+ // First image has the highest resolution and might be the best
161
+ // candidate to remove the background.
162
+ const highestResolution = sourceSet[0];
163
+ const highestResolutionBlob = await removeBackground(
164
+ highestResolution.uri
165
+ );
166
+ const highestResolutionURI = await uploadBlob(highestResolutionBlob);
167
+
168
+ const remainingSources = await Promise.all(
169
+ sourceSet.slice(1).map((source) => {
170
+ // ...
171
+ const upload = uploadBlob(/* ... */);
172
+ return { ...source, uri: upload };
173
+ })
174
+ );
175
+
176
+ return [
177
+ { ...highestResolution, uri: highestResolutionURI },
178
+ remainingSources
179
+ ];
174
180
  }
181
+ }
175
182
  });
176
183
  ```
177
184
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var Pt=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},jt=Pt,Ot=typeof global=="object"&&global&&global.Object===Object&&global,ze=Ot,wt=typeof self=="object"&&self&&self.Object===Object&&self,Rt=ze||wt||Function("return this")(),O=Rt,kt=O.Symbol,L=kt,$e=Object.prototype,Ct=$e.hasOwnProperty,Et=$e.toString,G=L?L.toStringTag:void 0;function Ft(e){var t=Ct.call(e,G),r=e[G];try{e[G]=void 0;var a=!0}catch{}var n=Et.call(e);return a&&(t?e[G]=r:delete e[G]),n}var Bt=Ft,Lt=Object.prototype,Dt=Lt.toString;function At(e){return Dt.call(e)}var Nt=At,Mt="[object Null]",Tt="[object Undefined]",Ie=L?L.toStringTag:void 0;function Ut(e){return e==null?e===void 0?Tt:Mt:Ie&&Ie in Object(e)?Bt(e):Nt(e)}var H=Ut;function Gt(e){return e!=null&&typeof e=="object"}var z=Gt,Wt=Array.isArray,J=Wt;function zt(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Ve=zt,$t="[object AsyncFunction]",Vt="[object Function]",Ht="[object GeneratorFunction]",Kt="[object Proxy]";function qt(e){if(!Ve(e))return!1;var t=H(e);return t==Vt||t==Ht||t==$t||t==Kt}var He=qt,Zt=O["__core-js_shared__"],ne=Zt,_e=function(){var e=/[^.]+$/.exec(ne&&ne.keys&&ne.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Jt(e){return!!_e&&_e in e}var Yt=Jt,Qt=Function.prototype,Xt=Qt.toString;function er(e){if(e!=null){try{return Xt.call(e)}catch{}try{return e+""}catch{}}return""}var C=er,tr=/[\\^$.*+?()[\]{}|]/g,rr=/^\[object .+?Constructor\]$/,ar=Function.prototype,or=Object.prototype,nr=ar.toString,ir=or.hasOwnProperty,sr=RegExp("^"+nr.call(ir).replace(tr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function lr(e){if(!Ve(e)||Yt(e))return!1;var t=He(e)?sr:rr;return t.test(C(e))}var fr=lr;function ur(e,t){return e?.[t]}var pr=ur;function dr(e,t){var r=pr(e,t);return fr(r)?r:void 0}var D=dr,cr=D(O,"WeakMap"),fe=cr,mr=9007199254740991,gr=/^(?:0|[1-9]\d*)$/;function xr(e,t){var r=typeof e;return t=t??mr,!!t&&(r=="number"||r!="symbol"&&gr.test(e))&&e>-1&&e%1==0&&e<t}var vr=xr;function hr(e,t){return e===t||e!==e&&t!==t}var Ke=hr,br=9007199254740991;function yr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=br}var qe=yr;function Sr(e){return e!=null&&qe(e.length)&&!He(e)}var Ir=Sr,_r=Object.prototype;function Pr(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||_r;return e===r}var jr=Pr;function Or(e,t){for(var r=-1,a=Array(e);++r<e;)a[r]=t(r);return a}var wr=Or,Rr="[object Arguments]";function kr(e){return z(e)&&H(e)==Rr}var Pe=kr,Ze=Object.prototype,Cr=Ze.hasOwnProperty,Er=Ze.propertyIsEnumerable,Fr=Pe(function(){return arguments}())?Pe:function(e){return z(e)&&Cr.call(e,"callee")&&!Er.call(e,"callee")},Br=Fr;function Lr(){return!1}var Dr=Lr,Je=typeof exports=="object"&&exports&&!exports.nodeType&&exports,je=Je&&typeof module=="object"&&module&&!module.nodeType&&module,Ar=je&&je.exports===Je,Oe=Ar?O.Buffer:void 0,Nr=Oe?Oe.isBuffer:void 0,Mr=Nr||Dr,ue=Mr,Tr="[object Arguments]",Ur="[object Array]",Gr="[object Boolean]",Wr="[object Date]",zr="[object Error]",$r="[object Function]",Vr="[object Map]",Hr="[object Number]",Kr="[object Object]",qr="[object RegExp]",Zr="[object Set]",Jr="[object String]",Yr="[object WeakMap]",Qr="[object ArrayBuffer]",Xr="[object DataView]",ea="[object Float32Array]",ta="[object Float64Array]",ra="[object Int8Array]",aa="[object Int16Array]",oa="[object Int32Array]",na="[object Uint8Array]",ia="[object Uint8ClampedArray]",sa="[object Uint16Array]",la="[object Uint32Array]",m={};m[ea]=m[ta]=m[ra]=m[aa]=m[oa]=m[na]=m[ia]=m[sa]=m[la]=!0;m[Tr]=m[Ur]=m[Qr]=m[Gr]=m[Xr]=m[Wr]=m[zr]=m[$r]=m[Vr]=m[Hr]=m[Kr]=m[qr]=m[Zr]=m[Jr]=m[Yr]=!1;function fa(e){return z(e)&&qe(e.length)&&!!m[H(e)]}var ua=fa;function pa(e){return function(t){return e(t)}}var da=pa,Ye=typeof exports=="object"&&exports&&!exports.nodeType&&exports,W=Ye&&typeof module=="object"&&module&&!module.nodeType&&module,ca=W&&W.exports===Ye,ie=ca&&ze.process,ma=function(){try{var e=W&&W.require&&W.require("util").types;return e||ie&&ie.binding&&ie.binding("util")}catch{}}(),we=ma,Re=we&&we.isTypedArray,ga=Re?da(Re):ua,Qe=ga,xa=Object.prototype,va=xa.hasOwnProperty;function ha(e,t){var r=J(e),a=!r&&Br(e),n=!r&&!a&&ue(e),o=!r&&!a&&!n&&Qe(e),s=r||a||n||o,i=s?wr(e.length,String):[],f=i.length;for(var l in e)(t||va.call(e,l))&&!(s&&(l=="length"||n&&(l=="offset"||l=="parent")||o&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||vr(l,f)))&&i.push(l);return i}var ba=ha;function ya(e,t){return function(r){return e(t(r))}}var Sa=ya,Ia=Sa(Object.keys,Object),_a=Ia,Pa=Object.prototype,ja=Pa.hasOwnProperty;function Oa(e){if(!jr(e))return _a(e);var t=[];for(var r in Object(e))ja.call(e,r)&&r!="constructor"&&t.push(r);return t}var wa=Oa;function Ra(e){return Ir(e)?ba(e):wa(e)}var ka=Ra,Ca=D(Object,"create"),$=Ca;function Ea(){this.__data__=$?$(null):{},this.size=0}var Fa=Ea;function Ba(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var La=Ba,Da="__lodash_hash_undefined__",Aa=Object.prototype,Na=Aa.hasOwnProperty;function Ma(e){var t=this.__data__;if($){var r=t[e];return r===Da?void 0:r}return Na.call(t,e)?t[e]:void 0}var Ta=Ma,Ua=Object.prototype,Ga=Ua.hasOwnProperty;function Wa(e){var t=this.__data__;return $?t[e]!==void 0:Ga.call(t,e)}var za=Wa,$a="__lodash_hash_undefined__";function Va(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=$&&t===void 0?$a:t,this}var Ha=Va;function A(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])}}A.prototype.clear=Fa;A.prototype.delete=La;A.prototype.get=Ta;A.prototype.has=za;A.prototype.set=Ha;var ke=A;function Ka(){this.__data__=[],this.size=0}var qa=Ka;function Za(e,t){for(var r=e.length;r--;)if(Ke(e[r][0],t))return r;return-1}var Q=Za,Ja=Array.prototype,Ya=Ja.splice;function Qa(e){var t=this.__data__,r=Q(t,e);if(r<0)return!1;var a=t.length-1;return r==a?t.pop():Ya.call(t,r,1),--this.size,!0}var Xa=Qa;function eo(e){var t=this.__data__,r=Q(t,e);return r<0?void 0:t[r][1]}var to=eo;function ro(e){return Q(this.__data__,e)>-1}var ao=ro;function oo(e,t){var r=this.__data__,a=Q(r,e);return a<0?(++this.size,r.push([e,t])):r[a][1]=t,this}var no=oo;function N(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])}}N.prototype.clear=qa;N.prototype.delete=Xa;N.prototype.get=to;N.prototype.has=ao;N.prototype.set=no;var X=N,io=D(O,"Map"),V=io;function so(){this.size=0,this.__data__={hash:new ke,map:new(V||X),string:new ke}}var lo=so;function fo(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var uo=fo;function po(e,t){var r=e.__data__;return uo(t)?r[typeof t=="string"?"string":"hash"]:r.map}var ee=po;function co(e){var t=ee(this,e).delete(e);return this.size-=t?1:0,t}var mo=co;function go(e){return ee(this,e).get(e)}var xo=go;function vo(e){return ee(this,e).has(e)}var ho=vo;function bo(e,t){var r=ee(this,e),a=r.size;return r.set(e,t),this.size+=r.size==a?0:1,this}var yo=bo;function M(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])}}M.prototype.clear=lo;M.prototype.delete=mo;M.prototype.get=xo;M.prototype.has=ho;M.prototype.set=yo;var Xe=M;function So(e,t){for(var r=-1,a=t.length,n=e.length;++r<a;)e[n+r]=t[r];return e}var Io=So;function _o(){this.__data__=new X,this.size=0}var Po=_o;function jo(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var Oo=jo;function wo(e){return this.__data__.get(e)}var Ro=wo;function ko(e){return this.__data__.has(e)}var Co=ko,Eo=200;function Fo(e,t){var r=this.__data__;if(r instanceof X){var a=r.__data__;if(!V||a.length<Eo-1)return a.push([e,t]),this.size=++r.size,this;r=this.__data__=new Xe(a)}return r.set(e,t),this.size=r.size,this}var Bo=Fo;function T(e){var t=this.__data__=new X(e);this.size=t.size}T.prototype.clear=Po;T.prototype.delete=Oo;T.prototype.get=Ro;T.prototype.has=Co;T.prototype.set=Bo;var se=T;function Lo(e,t){for(var r=-1,a=e==null?0:e.length,n=0,o=[];++r<a;){var s=e[r];t(s,r,e)&&(o[n++]=s)}return o}var Do=Lo;function Ao(){return[]}var No=Ao,Mo=Object.prototype,To=Mo.propertyIsEnumerable,Ce=Object.getOwnPropertySymbols,Uo=Ce?function(e){return e==null?[]:(e=Object(e),Do(Ce(e),function(t){return To.call(e,t)}))}:No,Go=Uo;function Wo(e,t,r){var a=t(e);return J(e)?a:Io(a,r(e))}var zo=Wo;function $o(e){return zo(e,ka,Go)}var Ee=$o,Vo=D(O,"DataView"),pe=Vo,Ho=D(O,"Promise"),de=Ho,Ko=D(O,"Set"),ce=Ko,Fe="[object Map]",qo="[object Object]",Be="[object Promise]",Le="[object Set]",De="[object WeakMap]",Ae="[object DataView]",Zo=C(pe),Jo=C(V),Yo=C(de),Qo=C(ce),Xo=C(fe),k=H;(pe&&k(new pe(new ArrayBuffer(1)))!=Ae||V&&k(new V)!=Fe||de&&k(de.resolve())!=Be||ce&&k(new ce)!=Le||fe&&k(new fe)!=De)&&(k=function(e){var t=H(e),r=t==qo?e.constructor:void 0,a=r?C(r):"";if(a)switch(a){case Zo:return Ae;case Jo:return Fe;case Yo:return Be;case Qo:return Le;case Xo:return De}return t});var Ne=k,en=O.Uint8Array,Me=en,tn="__lodash_hash_undefined__";function rn(e){return this.__data__.set(e,tn),this}var an=rn;function on(e){return this.__data__.has(e)}var nn=on;function Y(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Xe;++t<r;)this.add(e[t])}Y.prototype.add=Y.prototype.push=an;Y.prototype.has=nn;var sn=Y;function ln(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 fn=ln;function un(e,t){return e.has(t)}var pn=un,dn=1,cn=2;function mn(e,t,r,a,n,o){var s=r&dn,i=e.length,f=t.length;if(i!=f&&!(s&&f>i))return!1;var l=o.get(e),d=o.get(t);if(l&&d)return l==t&&d==e;var p=-1,u=!0,g=r&cn?new sn:void 0;for(o.set(e,t),o.set(t,e);++p<i;){var h=e[p],y=t[p];if(a)var I=s?a(y,h,p,t,e,o):a(h,y,p,e,t,o);if(I!==void 0){if(I)continue;u=!1;break}if(g){if(!fn(t,function(S,_){if(!pn(g,_)&&(h===S||n(h,S,r,a,o)))return g.push(_)})){u=!1;break}}else if(!(h===y||n(h,y,r,a,o))){u=!1;break}}return o.delete(e),o.delete(t),u}var et=mn;function gn(e){var t=-1,r=Array(e.size);return e.forEach(function(a,n){r[++t]=[n,a]}),r}var xn=gn;function vn(e){var t=-1,r=Array(e.size);return e.forEach(function(a){r[++t]=a}),r}var hn=vn,bn=1,yn=2,Sn="[object Boolean]",In="[object Date]",_n="[object Error]",Pn="[object Map]",jn="[object Number]",On="[object RegExp]",wn="[object Set]",Rn="[object String]",kn="[object Symbol]",Cn="[object ArrayBuffer]",En="[object DataView]",Te=L?L.prototype:void 0,le=Te?Te.valueOf:void 0;function Fn(e,t,r,a,n,o,s){switch(r){case En:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Cn:return!(e.byteLength!=t.byteLength||!o(new Me(e),new Me(t)));case Sn:case In:case jn:return Ke(+e,+t);case _n:return e.name==t.name&&e.message==t.message;case On:case Rn:return e==t+"";case Pn:var i=xn;case wn:var f=a&bn;if(i||(i=hn),e.size!=t.size&&!f)return!1;var l=s.get(e);if(l)return l==t;a|=yn,s.set(e,t);var d=et(i(e),i(t),a,n,o,s);return s.delete(e),d;case kn:if(le)return le.call(e)==le.call(t)}return!1}var Bn=Fn,Ln=1,Dn=Object.prototype,An=Dn.hasOwnProperty;function Nn(e,t,r,a,n,o){var s=r&Ln,i=Ee(e),f=i.length,l=Ee(t),d=l.length;if(f!=d&&!s)return!1;for(var p=f;p--;){var u=i[p];if(!(s?u in t:An.call(t,u)))return!1}var g=o.get(e),h=o.get(t);if(g&&h)return g==t&&h==e;var y=!0;o.set(e,t),o.set(t,e);for(var I=s;++p<f;){u=i[p];var S=e[u],_=t[u];if(a)var w=s?a(_,S,u,t,e,o):a(S,_,u,e,t,o);if(!(w===void 0?S===_||n(S,_,r,a,o):w)){y=!1;break}I||(I=u=="constructor")}if(y&&!I){var j=e.constructor,P=t.constructor;j!=P&&"constructor"in e&&"constructor"in t&&!(typeof j=="function"&&j instanceof j&&typeof P=="function"&&P instanceof P)&&(y=!1)}return o.delete(e),o.delete(t),y}var Mn=Nn,Tn=1,Ue="[object Arguments]",Ge="[object Array]",Z="[object Object]",Un=Object.prototype,We=Un.hasOwnProperty;function Gn(e,t,r,a,n,o){var s=J(e),i=J(t),f=s?Ge:Ne(e),l=i?Ge:Ne(t);f=f==Ue?Z:f,l=l==Ue?Z:l;var d=f==Z,p=l==Z,u=f==l;if(u&&ue(e)){if(!ue(t))return!1;s=!0,d=!1}if(u&&!d)return o||(o=new se),s||Qe(e)?et(e,t,r,a,n,o):Bn(e,t,f,r,a,n,o);if(!(r&Tn)){var g=d&&We.call(e,"__wrapped__"),h=p&&We.call(t,"__wrapped__");if(g||h){var y=g?e.value():e,I=h?t.value():t;return o||(o=new se),n(y,I,r,a,o)}}return u?(o||(o=new se),Mn(e,t,r,a,n,o)):!1}var Wn=Gn;function tt(e,t,r,a,n){return e===t?!0:e==null||t==null||!z(e)&&!z(t)?e!==e&&t!==t:Wn(e,t,r,a,tt,n)}var zn=tt;function $n(e,t){return zn(e,t)}var Vn=$n,Hn=class extends jt{get(e){return super.get(e)??{status:"IDLE"}}isDuplicate(e){if(!this.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING"||t.status==="ERROR"||!this.engine.block.hasFill(e))return!1;let r=this.engine.block.getFill(e);return!(t.blockId===e||t.fillId===r)}fixDuplicate(e){let t=this.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.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING")return!0;if(!this.engine.block.hasFill(e))return!1;let r=this.engine.block.getFill(e);if(r==null||e!==t.blockId||r!==t.fillId)return!1;let a=this.engine.block.getSourceSet(r,"fill/image/sourceSet"),n=this.engine.block.getString(r,"fill/image/imageFileURI");if(a.length===0&&!n&&t.status==="PROCESSING")return!0;if(a?.length>0){let o=t.initialSourceSet;if(t.status!=="PROCESSED"&&!Vn(a,o))return!1}else if(t.status!=="PROCESSED"&&n!==t.initialImageFileURI)return!1;return!0}recoverInitialImageData(e){if(!this.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,n=t.initialPreviewFileURI,o=this.getValidFill(e,t);o!=null&&(a&&this.engine.block.setString(o,"fill/image/imageFileURI",a),n&&this.engine.block.setString(o,"fill/image/previewFileURI",n),r.length>0&&this.engine.block.setSourceSet(o,"fill/image/sourceSet",r))}getValidFill(e,t){if(!this.engine.block.isValid(e)||!this.engine.block.hasFill(e)||e!==t.blockId)return;let r=this.engine.block.getFill(e);if(r===t.fillId)return r}},rt=Hn;async function Kn(e,t,r,a){let n=t.engine.block;if(!n.hasFill(e))throw new Error("Block does not support fill");let o=n.getFill(e),s=n.getSourceSet(o,"fill/image/sourceSet"),i=n.getString(o,"fill/image/imageFileURI"),f=n.getString(o,"fill/image/previewFileURI");try{t.engine.block.setState(o,{type:"Pending",progress:0});let l={...r.get(e),version:"0.0.0",initialSourceSet:s,initialImageFileURI:i,initialPreviewFileURI:f,blockId:e,fillId:o,status:"PROCESSING"};r.set(e,l);let d=await a.processFill(l);if(r.get(e).status!=="PROCESSING"||!r.isConsistent(e)||r.get(e).status!=="PROCESSING"||!r.isConsistent(e)||d==null)return;let p={version:"0.0.0",initialSourceSet:s,initialImageFileURI:i,initialPreviewFileURI:f,blockId:e,fillId:o,status:"PROCESSED"},u=a.commitProcessing(d,p);(u==null||u===e)&&r.set(e,p),t.engine.editor.addUndoStep()}catch(l){if(t.engine.block.isValid(e)&&(r.set(e,{version:"0.0.0",initialSourceSet:s,initialImageFileURI:i,initialPreviewFileURI:f,blockId:e,fillId:o,status:"ERROR"}),r.recoverInitialImageData(e)),l!=null&&typeof l=="object"&&"message"in l&&typeof l.message=="string"){let d=l.message==="signal timed out"?"Processing canceled due to timeout":l.message;t.ui.showNotification({type:"error",message:d})}console.log(l)}finally{t.engine.block.isValid(o)&&t.engine.block.setState(o,{type:"Ready"})}}var me=Kn;function at(e){return`${e}.fillProcessing.feature`}function qn(e){return[`${e}.canvasMenu`,`${e}.fillProcessing.canvasMenu`]}function Zn(e){return[`${e}.dock`,`${e}.fillProcessing.dock`]}function Jn(e){return[`${e}.inspectorBar`,`${e}.fillProcessing.inspectorBar`]}function Yn(e){return[`${e}.navigationBar`,`${e}.fillProcessing.navigationBar`]}function Qn(e){return[`${e}.canvasBar`,`${e}.fillProcessing.canvasBar`]}function Xn(e){return`plugin.${e}.fillProcessing.canvasMenu.button.label`}function ei(e){return`plugin.${e}.fillProcessing.dock.button.label`}function ti(e){return`plugin.${e}.fillProcessing.inspectorBar.button.label`}function ri(e){return`plugin.${e}.fillProcessing.navigationBar.button.label`}function ai(e){return`plugin.${e}.fillProcessing.canvasBar.button.label`}function ot(e,{pluginId:t,process:r}){let a=at(t),n=new rt(e.engine,t);return oi(e,n,a),e.engine.event.subscribe([],async o=>{o.forEach(s=>{let i=s.block;if(!(!e.engine.block.isValid(i)||!n.hasData(i))){if(s.type==="Created")n.isDuplicate(i)&&n.fixDuplicate(i);else if(s.type==="Updated")switch(n.get(i).status){case"PENDING":{e.feature.isEnabled(a,{engine:e.engine})&&e.engine.block.isAllowedByScope(i,"fill/change")&&e.engine.block.getState(i).type!=="Pending"&&r(i,n);break}case"PROCESSING":case"PROCESSED":{n.isConsistent(i)||n.clear(i);break}default:}}})}),{featureId:a}}function oi(e,t,r){e.feature.enable(r,({engine:a})=>{let n=a.block.findAllSelected();if(n.length!==1)return!1;let[o]=n;if(!e.engine.block.isVisible(o))return!1;if(e.engine.block.hasFill(o)){if(e.engine.block.getKind(o)==="sticker")return!1;let s=e.engine.block.getFill(o);if(e.engine.block.getType(s)!=="//ly.img.ubq/fill/image")return!1;let i=a.block.getString(s,"fill/image/imageFileURI");return a.block.getSourceSet(s,"fill/image/sourceSet").length>0||i!==""?!0:t.get(o).status==="PROCESSING"}return!1})}function nt(e,t){let{pluginId:r,locations:a}=t,n=new rt(e.engine,r),o=Xn(r),s=qn(r),i=s[0],f=ei(r),l=Zn(r),d=l[0],p=ti(r),u=Jn(r),g=u[0],h=ri(r),y=Yn(r),I=y[0],S=ai(r),_=Qn(r),w=_[0],j=at(r);return a?.includes("inspectorBar")&&e.ui.setInspectorBarOrder([g,...e.ui.getInspectorBarOrder()]),a?.includes("navigationBar")&&e.ui.setNavigationBarOrder([I,...e.ui.getNavigationBarOrder()]),a?.includes("canvasBarTop")&&e.ui.setCanvasBarOrder([w,...e.ui.getCanvasBarOrder("top")],"top"),a?.includes("canvasBarBottom")&&e.ui.setCanvasBarOrder([w,...e.ui.getCanvasBarOrder("bottom")],"bottom"),a?.includes("canvasMenu")&&e.ui.setCanvasMenuOrder([i,...e.ui.getCanvasMenuOrder()]),a?.includes("dock")&&e.ui.setDockOrder([...e.ui.getDockOrder(),d]),e.ui.registerComponent(l,({builder:{Button:P},engine:c})=>{let[b]=c.block.findAllSelected(),v=!1,R=!1,F;if(b==null&&(v=!0),!v&&!e.feature.isEnabled(j,{engine:c})&&(v=!0),!v&&!e.engine.block.isAllowedByScope(b,"fill/change")&&(v=!0),!v&&c.block.getState(b)?.type==="Pending"&&(v=!0),!v){let x=n.get(b);if(R=x.status==="PROCESSING",v=x.status==="PENDING"||x.status==="PROCESSING",x.status==="PROCESSING"&&x.progress){let{current:q,total:oe}=x.progress;F=q/oe*100}}let B=`${d}.button`;P(B,{label:f,icon:t.icon,isLoading:R,isDisabled:v,loadingProgress:F,onClick:()=>{let x=n.get(b);(x.status==="IDLE"||x.status==="ERROR"||x.status==="PROCESSED")&&n.set(b,{status:"PENDING"})}})}),[{componentIds:u,variant:"plain",label:p},{componentIds:y,variant:"regular",label:h},{componentIds:_,variant:"regular",label:S},{componentIds:s,variant:"plain",label:o}].forEach(({componentIds:P,label:c,variant:b})=>{let v=P[0];e.ui.registerComponent(P,({builder:{Button:R},engine:F})=>{if(!e.feature.isEnabled(j,{engine:F}))return;let[B]=F.block.findAllSelected();if(!e.engine.block.isAllowedByScope(B,"fill/change"))return;let x=n.get(B),q=x.status==="PROCESSING",oe=x.status==="PENDING"||x.status==="PROCESSING"||F.block.getState(B)?.type==="Pending",Se;if(q&&x.progress){let{current:It,total:_t}=x.progress;Se=It/_t*100}let St=`${v}.button`;R(St,{icon:t.icon,label:c,variant:b,isLoading:q,isDisabled:oe,loadingProgress:Se,onClick:()=>{(x.status==="IDLE"||x.status==="ERROR"||x.status==="PROCESSED")&&n.set(B,{status:"PENDING"})}})})}),{canvasMenuComponentId:i,dockComponentId:d,translationsKeys:{inspectorBarLabel:p,navigationBarLabel:h,canvasBarLabel:S,canvasMenuLabel:o,dockLabel:f}}}var Vi=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Hi=new RegExp(/[A-Fa-f0-9]{1}/,"g"),Ki=new RegExp(/[A-Fa-f0-9]{2}/,"g");var ni=typeof global=="object"&&global&&global.Object===Object&&global,it=ni;var ii=typeof self=="object"&&self&&self.Object===Object&&self,si=it||ii||Function("return this")(),te=si;var li=te.Symbol,U=li;var st=Object.prototype,fi=st.hasOwnProperty,ui=st.toString,K=U?U.toStringTag:void 0;function pi(e){var t=fi.call(e,K),r=e[K];try{e[K]=void 0;var a=!0}catch{}var n=ui.call(e);return a&&(t?e[K]=r:delete e[K]),n}var lt=pi;var di=Object.prototype,ci=di.toString;function mi(e){return ci.call(e)}var ft=mi;var gi="[object Null]",xi="[object Undefined]",ut=U?U.toStringTag:void 0;function vi(e){return e==null?e===void 0?xi:gi:ut&&ut in Object(e)?lt(e):ft(e)}var pt=vi;function hi(e){return e!=null&&typeof e=="object"}var dt=hi;var bi="[object Symbol]";function yi(e){return typeof e=="symbol"||dt(e)&&pt(e)==bi}var ct=yi;var Si=/\s/;function Ii(e){for(var t=e.length;t--&&Si.test(e.charAt(t)););return t}var mt=Ii;var _i=/^\s+/;function Pi(e){return e&&e.slice(0,mt(e)+1).replace(_i,"")}var gt=Pi;function ji(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var E=ji;var xt=NaN,Oi=/^[-+]0x[0-9a-f]+$/i,wi=/^0b[01]+$/i,Ri=/^0o[0-7]+$/i,ki=parseInt;function Ci(e){if(typeof e=="number")return e;if(ct(e))return xt;if(E(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=E(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=gt(e);var r=wi.test(e);return r||Ri.test(e)?ki(e.slice(2),r?2:8):Oi.test(e)?xt:+e}var ge=Ci;var Ei=function(){return te.Date.now()},re=Ei;var Fi="Expected a function",Bi=Math.max,Li=Math.min;function Di(e,t,r){var a,n,o,s,i,f,l=0,d=!1,p=!1,u=!0;if(typeof e!="function")throw new TypeError(Fi);t=ge(t)||0,E(r)&&(d=!!r.leading,p="maxWait"in r,o=p?Bi(ge(r.maxWait)||0,t):o,u="trailing"in r?!!r.trailing:u);function g(c){var b=a,v=n;return a=n=void 0,l=c,s=e.apply(v,b),s}function h(c){return l=c,i=setTimeout(S,t),d?g(c):s}function y(c){var b=c-f,v=c-l,R=t-b;return p?Li(R,o-v):R}function I(c){var b=c-f,v=c-l;return f===void 0||b>=t||b<0||p&&v>=o}function S(){var c=re();if(I(c))return _(c);i=setTimeout(S,y(c))}function _(c){return i=void 0,u&&a?g(c):(a=n=void 0,s)}function w(){i!==void 0&&clearTimeout(i),l=0,a=f=n=i=void 0}function j(){return i===void 0?s:_(re())}function P(){var c=re(),b=I(c);if(a=arguments,n=this,f=c,b){if(i===void 0)return h(f);if(p)return clearTimeout(i),i=setTimeout(S,t),g(f)}return i===void 0&&(i=setTimeout(S,t)),s}return P.cancel=w,P.flush=j,P}var vt=Di;var Ai="Expected a function";function Ni(e,t,r){var a=!0,n=!0;if(typeof e!="function")throw new TypeError(Ai);return E(r)&&(a="leading"in r?!!r.leading:a,n="trailing"in r?!!r.trailing:n),vt(e,t,{leading:a,maxWait:t,trailing:n})}var xe=Ni;import{applySegmentationMask as Ui,removeBackground as Gi,segmentForeground as Wi}from"@imgly/background-removal";function Mi(e,t=1024){if(e.length===0)return;let[r,a]=e.reduce((n,o)=>(o.width>=t&&o.height>=t?n[0].push(o):n[1].push(o),n),[[],[]]);return r.length>0?r.sort((n,o)=>n.width*n.height-o.width*o.height)[0]:a.sort((n,o)=>o.width*o.height-n.width*n.height)[0]}var ht=Mi;async function Ti(e,t,r){let n=new URL(t).pathname.split("/"),o=n[n.length-1],i=(await r.unstable_upload(new File([e],o,{type:e.type}),()=>{})).meta?.uri;if(i==null)throw new Error("Could not upload processed fill");return i}var ve=Ti;async function be(e,t,r,a,n){return me(e,t,r,{processFill:n??(async o=>{let s=o.initialSourceSet,i=ht(s);if(i==null)throw new Error("No source found");let f=await he(i.uri,t),l=await Wi(f,a);return await Promise.all(s.map(async p=>{let u=await Ui(await he(p.uri,t),l,a),g=await ve(u,p.uri,t);return{...p,uri:g}}))}),commitProcessing:(o,s)=>{let i=s.fillId;t.engine.block.setSourceSet(i,"fill/image/sourceSet",o);let f=[...o].sort((l,d)=>l.width*l.height-d.width*d.height)[0];f!=null&&t.engine.block.setString(i,"fill/image/previewFileURI",f.uri)}})}async function ye(e,t,r,a,n){return me(e,t,r,{processFill:n??(async o=>{let s=o.initialImageFileURI,i=await Gi(await he(s,t),a);return await ve(i,s,t)}),commitProcessing:(o,s)=>{let i=s.fillId;t.engine.block.setString(i,"fill/image/imageFileURI",o),t.engine.block.setString(i,"fill/image/previewFileURI","")}})}async function he(e,t){if(e.startsWith("buffer:")){let r=await t.engine.editor.getMimeType(e),a=t.engine.editor.getBufferLength(e),n=t.engine.editor.getBufferData(e,0,a);return new Blob([n],{type:r})}else return e}async function bt(e,t,r,a){let n=e.engine.block;if(!n.hasFill(t))throw new Error("Block does not support fill");let o=n.getFill(t),s=n.getSourceSet(o,"fill/image/sourceSet"),i=n.getString(o,"fill/image/imageFileURI");if(s.length===0&&i==="")throw new Error("No source or image file URI found");switch(a.type){case"@imgly/background-removal":{let f=a.configuration??{},l={device:"gpu",...f,progress:xe((d,p,u)=>{let g=r.get(t);g.status!=="PROCESSING"||!r.isConsistent(t)||(f.progress?.(d,p,u),r.set(t,{...g,progress:{key:d,current:p,total:u}}))},100)};s.length>0?be(t,e,r,l):ye(t,e,r,l);break}case"custom":{s.length>0?be(t,e,r,void 0,f=>a.processSourceSet(f.initialSourceSet)):ye(t,e,r,void 0,f=>a.processImageFileURI(f.initialImageFileURI));break}default:throw new Error("Unknown background removal provider")}}var ae="@imgly/plugin-background-removal-web",yt=(e={})=>({initialize({cesdk:t}){if(t==null)return;zi(t),ot(t,{pluginId:ae,process:(a,n)=>{bt(t,a,n,e.provider??{type:"@imgly/background-removal"})}});let{translationsKeys:r}=nt(t,{pluginId:ae,icon:"@imgly/icons/BGRemove",locations:e.ui?.locations});t.setTranslations({en:{[r.inspectorBarLabel]:"BG Removal",[r.navigationBarLabel]:"BG Removal",[r.canvasBarLabel]:"BG Removal",[r.canvasMenuLabel]:"BG Removal",[r.dockLabel]:"BG Removal"}})}});function zi(e){e.ui.addIconSet("@imgly/plugin/background-removal",`
1
+ var gt=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.engine.block.isValid(e)&&this.engine.block.hasMetadata(e,this.key)}get(e){if(this.hasData(e))return JSON.parse(this.engine.block.getMetadata(e,this.key))}set(e,t){this.engine.block.setMetadata(e,this.key,JSON.stringify(t))}clear(e){this.engine.block.hasMetadata(e,this.key)&&this.engine.block.removeMetadata(e,this.key)}},xt=gt,ht=typeof global=="object"&&global&&global.Object===Object&&global,Me=ht,vt=typeof self=="object"&&self&&self.Object===Object&&self,bt=Me||vt||Function("return this")(),S=bt,yt=S.Symbol,O=yt,Te=Object.prototype,St=Te.hasOwnProperty,It=Te.toString,D=O?O.toStringTag:void 0;function _t(e){var t=St.call(e,D),r=e[D];try{e[D]=void 0;var o=!0}catch{}var i=It.call(e);return o&&(t?e[D]=r:delete e[D]),i}var jt=_t,wt=Object.prototype,Pt=wt.toString;function Rt(e){return Pt.call(e)}var Ot=Rt,Ft="[object Null]",kt="[object Undefined]",xe=O?O.toStringTag:void 0;function Ct(e){return e==null?e===void 0?kt:Ft:xe&&xe in Object(e)?jt(e):Ot(e)}var z=Ct;function Et(e){return e!=null&&typeof e=="object"}var T=Et,Bt=Array.isArray,$=Bt;function Lt(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Ne=Lt,At="[object AsyncFunction]",Dt="[object Function]",Mt="[object GeneratorFunction]",Tt="[object Proxy]";function Nt(e){if(!Ne(e))return!1;var t=z(e);return t==Dt||t==Mt||t==At||t==Tt}var Ue=Nt,Ut=S["__core-js_shared__"],Q=Ut,he=function(){var e=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function zt(e){return!!he&&he in e}var Gt=zt,Wt=Function.prototype,Vt=Wt.toString;function $t(e){if(e!=null){try{return Vt.call(e)}catch{}try{return e+""}catch{}}return""}var w=$t,Kt=/[\\^$.*+?()[\]{}|]/g,qt=/^\[object .+?Constructor\]$/,Ht=Function.prototype,Zt=Object.prototype,Jt=Ht.toString,Xt=Zt.hasOwnProperty,Yt=RegExp("^"+Jt.call(Xt).replace(Kt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Qt(e){if(!Ne(e)||Gt(e))return!1;var t=Ue(e)?Yt:qt;return t.test(w(e))}var er=Qt;function tr(e,t){return e?.[t]}var rr=tr;function or(e,t){var r=rr(e,t);return er(r)?r:void 0}var F=or,ar=F(S,"WeakMap"),oe=ar,ir=9007199254740991,nr=/^(?:0|[1-9]\d*)$/;function fr(e,t){var r=typeof e;return t=t??ir,!!t&&(r=="number"||r!="symbol"&&nr.test(e))&&e>-1&&e%1==0&&e<t}var sr=fr;function lr(e,t){return e===t||e!==e&&t!==t}var ze=lr,ur=9007199254740991;function pr(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ur}var Ge=pr;function dr(e){return e!=null&&Ge(e.length)&&!Ue(e)}var cr=dr,mr=Object.prototype;function gr(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||mr;return e===r}var xr=gr;function hr(e,t){for(var r=-1,o=Array(e);++r<e;)o[r]=t(r);return o}var vr=hr,br="[object Arguments]";function yr(e){return T(e)&&z(e)==br}var ve=yr,We=Object.prototype,Sr=We.hasOwnProperty,Ir=We.propertyIsEnumerable,_r=ve(function(){return arguments}())?ve:function(e){return T(e)&&Sr.call(e,"callee")&&!Ir.call(e,"callee")},jr=_r;function wr(){return!1}var Pr=wr,Ve=typeof exports=="object"&&exports&&!exports.nodeType&&exports,be=Ve&&typeof module=="object"&&module&&!module.nodeType&&module,Rr=be&&be.exports===Ve,ye=Rr?S.Buffer:void 0,Or=ye?ye.isBuffer:void 0,Fr=Or||Pr,ae=Fr,kr="[object Arguments]",Cr="[object Array]",Er="[object Boolean]",Br="[object Date]",Lr="[object Error]",Ar="[object Function]",Dr="[object Map]",Mr="[object Number]",Tr="[object Object]",Nr="[object RegExp]",Ur="[object Set]",zr="[object String]",Gr="[object WeakMap]",Wr="[object ArrayBuffer]",Vr="[object DataView]",$r="[object Float32Array]",Kr="[object Float64Array]",qr="[object Int8Array]",Hr="[object Int16Array]",Zr="[object Int32Array]",Jr="[object Uint8Array]",Xr="[object Uint8ClampedArray]",Yr="[object Uint16Array]",Qr="[object Uint32Array]",c={};c[$r]=c[Kr]=c[qr]=c[Hr]=c[Zr]=c[Jr]=c[Xr]=c[Yr]=c[Qr]=!0;c[kr]=c[Cr]=c[Wr]=c[Er]=c[Vr]=c[Br]=c[Lr]=c[Ar]=c[Dr]=c[Mr]=c[Tr]=c[Nr]=c[Ur]=c[zr]=c[Gr]=!1;function eo(e){return T(e)&&Ge(e.length)&&!!c[z(e)]}var to=eo;function ro(e){return function(t){return e(t)}}var oo=ro,$e=typeof exports=="object"&&exports&&!exports.nodeType&&exports,M=$e&&typeof module=="object"&&module&&!module.nodeType&&module,ao=M&&M.exports===$e,ee=ao&&Me.process,io=function(){try{var e=M&&M.require&&M.require("util").types;return e||ee&&ee.binding&&ee.binding("util")}catch{}}(),Se=io,Ie=Se&&Se.isTypedArray,no=Ie?oo(Ie):to,Ke=no,fo=Object.prototype,so=fo.hasOwnProperty;function lo(e,t){var r=$(e),o=!r&&jr(e),i=!r&&!o&&ae(e),a=!r&&!o&&!i&&Ke(e),f=r||o||i||a,n=f?vr(e.length,String):[],l=n.length;for(var s in e)(t||so.call(e,s))&&!(f&&(s=="length"||i&&(s=="offset"||s=="parent")||a&&(s=="buffer"||s=="byteLength"||s=="byteOffset")||sr(s,l)))&&n.push(s);return n}var uo=lo;function po(e,t){return function(r){return e(t(r))}}var co=po,mo=co(Object.keys,Object),go=mo,xo=Object.prototype,ho=xo.hasOwnProperty;function vo(e){if(!xr(e))return go(e);var t=[];for(var r in Object(e))ho.call(e,r)&&r!="constructor"&&t.push(r);return t}var bo=vo;function yo(e){return cr(e)?uo(e):bo(e)}var So=yo,Io=F(Object,"create"),N=Io;function _o(){this.__data__=N?N(null):{},this.size=0}var jo=_o;function wo(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Po=wo,Ro="__lodash_hash_undefined__",Oo=Object.prototype,Fo=Oo.hasOwnProperty;function ko(e){var t=this.__data__;if(N){var r=t[e];return r===Ro?void 0:r}return Fo.call(t,e)?t[e]:void 0}var Co=ko,Eo=Object.prototype,Bo=Eo.hasOwnProperty;function Lo(e){var t=this.__data__;return N?t[e]!==void 0:Bo.call(t,e)}var Ao=Lo,Do="__lodash_hash_undefined__";function Mo(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=N&&t===void 0?Do:t,this}var To=Mo;function k(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1])}}k.prototype.clear=jo;k.prototype.delete=Po;k.prototype.get=Co;k.prototype.has=Ao;k.prototype.set=To;var _e=k;function No(){this.__data__=[],this.size=0}var Uo=No;function zo(e,t){for(var r=e.length;r--;)if(ze(e[r][0],t))return r;return-1}var q=zo,Go=Array.prototype,Wo=Go.splice;function Vo(e){var t=this.__data__,r=q(t,e);if(r<0)return!1;var o=t.length-1;return r==o?t.pop():Wo.call(t,r,1),--this.size,!0}var $o=Vo;function Ko(e){var t=this.__data__,r=q(t,e);return r<0?void 0:t[r][1]}var qo=Ko;function Ho(e){return q(this.__data__,e)>-1}var Zo=Ho;function Jo(e,t){var r=this.__data__,o=q(r,e);return o<0?(++this.size,r.push([e,t])):r[o][1]=t,this}var Xo=Jo;function C(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1])}}C.prototype.clear=Uo;C.prototype.delete=$o;C.prototype.get=qo;C.prototype.has=Zo;C.prototype.set=Xo;var H=C,Yo=F(S,"Map"),U=Yo;function Qo(){this.size=0,this.__data__={hash:new _e,map:new(U||H),string:new _e}}var ea=Qo;function ta(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var ra=ta;function oa(e,t){var r=e.__data__;return ra(t)?r[typeof t=="string"?"string":"hash"]:r.map}var Z=oa;function aa(e){var t=Z(this,e).delete(e);return this.size-=t?1:0,t}var ia=aa;function na(e){return Z(this,e).get(e)}var fa=na;function sa(e){return Z(this,e).has(e)}var la=sa;function ua(e,t){var r=Z(this,e),o=r.size;return r.set(e,t),this.size+=r.size==o?0:1,this}var pa=ua;function E(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1])}}E.prototype.clear=ea;E.prototype.delete=ia;E.prototype.get=fa;E.prototype.has=la;E.prototype.set=pa;var qe=E;function da(e,t){for(var r=-1,o=t.length,i=e.length;++r<o;)e[i+r]=t[r];return e}var ca=da;function ma(){this.__data__=new H,this.size=0}var ga=ma;function xa(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var ha=xa;function va(e){return this.__data__.get(e)}var ba=va;function ya(e){return this.__data__.has(e)}var Sa=ya,Ia=200;function _a(e,t){var r=this.__data__;if(r instanceof H){var o=r.__data__;if(!U||o.length<Ia-1)return o.push([e,t]),this.size=++r.size,this;r=this.__data__=new qe(o)}return r.set(e,t),this.size=r.size,this}var ja=_a;function B(e){var t=this.__data__=new H(e);this.size=t.size}B.prototype.clear=ga;B.prototype.delete=ha;B.prototype.get=ba;B.prototype.has=Sa;B.prototype.set=ja;var te=B;function wa(e,t){for(var r=-1,o=e==null?0:e.length,i=0,a=[];++r<o;){var f=e[r];t(f,r,e)&&(a[i++]=f)}return a}var Pa=wa;function Ra(){return[]}var Oa=Ra,Fa=Object.prototype,ka=Fa.propertyIsEnumerable,je=Object.getOwnPropertySymbols,Ca=je?function(e){return e==null?[]:(e=Object(e),Pa(je(e),function(t){return ka.call(e,t)}))}:Oa,Ea=Ca;function Ba(e,t,r){var o=t(e);return $(e)?o:ca(o,r(e))}var La=Ba;function Aa(e){return La(e,So,Ea)}var we=Aa,Da=F(S,"DataView"),ie=Da,Ma=F(S,"Promise"),ne=Ma,Ta=F(S,"Set"),fe=Ta,Pe="[object Map]",Na="[object Object]",Re="[object Promise]",Oe="[object Set]",Fe="[object WeakMap]",ke="[object DataView]",Ua=w(ie),za=w(U),Ga=w(ne),Wa=w(fe),Va=w(oe),j=z;(ie&&j(new ie(new ArrayBuffer(1)))!=ke||U&&j(new U)!=Pe||ne&&j(ne.resolve())!=Re||fe&&j(new fe)!=Oe||oe&&j(new oe)!=Fe)&&(j=function(e){var t=z(e),r=t==Na?e.constructor:void 0,o=r?w(r):"";if(o)switch(o){case Ua:return ke;case za:return Pe;case Ga:return Re;case Wa:return Oe;case Va:return Fe}return t});var Ce=j,$a=S.Uint8Array,Ee=$a,Ka="__lodash_hash_undefined__";function qa(e){return this.__data__.set(e,Ka),this}var Ha=qa;function Za(e){return this.__data__.has(e)}var Ja=Za;function K(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new qe;++t<r;)this.add(e[t])}K.prototype.add=K.prototype.push=Ha;K.prototype.has=Ja;var Xa=K;function Ya(e,t){for(var r=-1,o=e==null?0:e.length;++r<o;)if(t(e[r],r,e))return!0;return!1}var Qa=Ya;function ei(e,t){return e.has(t)}var ti=ei,ri=1,oi=2;function ai(e,t,r,o,i,a){var f=r&ri,n=e.length,l=t.length;if(n!=l&&!(f&&l>n))return!1;var s=a.get(e),d=a.get(t);if(s&&d)return s==t&&d==e;var u=-1,p=!0,m=r&oi?new Xa:void 0;for(a.set(e,t),a.set(t,e);++u<n;){var x=e[u],h=t[u];if(o)var b=f?o(h,x,u,t,e,a):o(x,h,u,e,t,a);if(b!==void 0){if(b)continue;p=!1;break}if(m){if(!Qa(t,function(v,y){if(!ti(m,y)&&(x===v||i(x,v,r,o,a)))return m.push(y)})){p=!1;break}}else if(!(x===h||i(x,h,r,o,a))){p=!1;break}}return a.delete(e),a.delete(t),p}var He=ai;function ii(e){var t=-1,r=Array(e.size);return e.forEach(function(o,i){r[++t]=[i,o]}),r}var ni=ii;function fi(e){var t=-1,r=Array(e.size);return e.forEach(function(o){r[++t]=o}),r}var si=fi,li=1,ui=2,pi="[object Boolean]",di="[object Date]",ci="[object Error]",mi="[object Map]",gi="[object Number]",xi="[object RegExp]",hi="[object Set]",vi="[object String]",bi="[object Symbol]",yi="[object ArrayBuffer]",Si="[object DataView]",Be=O?O.prototype:void 0,re=Be?Be.valueOf:void 0;function Ii(e,t,r,o,i,a,f){switch(r){case Si:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case yi:return!(e.byteLength!=t.byteLength||!a(new Ee(e),new Ee(t)));case pi:case di:case gi:return ze(+e,+t);case ci:return e.name==t.name&&e.message==t.message;case xi:case vi:return e==t+"";case mi:var n=ni;case hi:var l=o&li;if(n||(n=si),e.size!=t.size&&!l)return!1;var s=f.get(e);if(s)return s==t;o|=ui,f.set(e,t);var d=He(n(e),n(t),o,i,a,f);return f.delete(e),d;case bi:if(re)return re.call(e)==re.call(t)}return!1}var _i=Ii,ji=1,wi=Object.prototype,Pi=wi.hasOwnProperty;function Ri(e,t,r,o,i,a){var f=r&ji,n=we(e),l=n.length,s=we(t),d=s.length;if(l!=d&&!f)return!1;for(var u=l;u--;){var p=n[u];if(!(f?p in t:Pi.call(t,p)))return!1}var m=a.get(e),x=a.get(t);if(m&&x)return m==t&&x==e;var h=!0;a.set(e,t),a.set(t,e);for(var b=f;++u<l;){p=n[u];var v=e[p],y=t[p];if(o)var W=f?o(y,v,p,t,e,a):o(v,y,p,e,t,a);if(!(W===void 0?v===y||i(v,y,r,o,a):W)){h=!1;break}b||(b=p=="constructor")}if(h&&!b){var R=e.constructor,I=t.constructor;R!=I&&"constructor"in e&&"constructor"in t&&!(typeof R=="function"&&R instanceof R&&typeof I=="function"&&I instanceof I)&&(h=!1)}return a.delete(e),a.delete(t),h}var Oi=Ri,Fi=1,Le="[object Arguments]",Ae="[object Array]",V="[object Object]",ki=Object.prototype,De=ki.hasOwnProperty;function Ci(e,t,r,o,i,a){var f=$(e),n=$(t),l=f?Ae:Ce(e),s=n?Ae:Ce(t);l=l==Le?V:l,s=s==Le?V:s;var d=l==V,u=s==V,p=l==s;if(p&&ae(e)){if(!ae(t))return!1;f=!0,d=!1}if(p&&!d)return a||(a=new te),f||Ke(e)?He(e,t,r,o,i,a):_i(e,t,l,r,o,i,a);if(!(r&Fi)){var m=d&&De.call(e,"__wrapped__"),x=u&&De.call(t,"__wrapped__");if(m||x){var h=m?e.value():e,b=x?t.value():t;return a||(a=new te),i(h,b,r,o,a)}}return p?(a||(a=new te),Oi(e,t,r,o,i,a)):!1}var Ei=Ci;function Ze(e,t,r,o,i){return e===t?!0:e==null||t==null||!T(e)&&!T(t)?e!==e&&t!==t:Ei(e,t,r,o,Ze,i)}var Bi=Ze;function Li(e,t){return Bi(e,t)}var Ai=Li,Di=class extends xt{get(e){return super.get(e)??{status:"IDLE"}}isDuplicate(e){if(!this.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING"||t.status==="ERROR"||!this.engine.block.hasFill(e))return!1;let r=this.engine.block.getFill(e);return!(t.blockId===e||t.fillId===r)}fixDuplicate(e){let t=this.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.engine.block.isValid(e))return!1;let t=this.get(e);if(t.status==="IDLE"||t.status==="PENDING")return!0;if(!this.engine.block.hasFill(e))return!1;let r=this.engine.block.getFill(e);if(r==null||e!==t.blockId||r!==t.fillId)return!1;let o=this.engine.block.getSourceSet(r,"fill/image/sourceSet"),i=this.engine.block.getString(r,"fill/image/imageFileURI");if(o.length===0&&!i&&t.status==="PROCESSING")return!0;if(o?.length>0){let a=t.initialSourceSet;if(t.status!=="PROCESSED"&&!Ai(o,a))return!1}else if(t.status!=="PROCESSED"&&i!==t.initialImageFileURI)return!1;return!0}recoverInitialImageData(e){if(!this.engine.block.hasFill(e))return;let t=this.get(e);if(t.status==="PENDING"||t.status==="IDLE")return;let r=t.initialSourceSet,o=t.initialImageFileURI,i=t.initialPreviewFileURI,a=this.getValidFill(e,t);a!=null&&(o&&this.engine.block.setString(a,"fill/image/imageFileURI",o),i&&this.engine.block.setString(a,"fill/image/previewFileURI",i),r.length>0&&this.engine.block.setSourceSet(a,"fill/image/sourceSet",r))}getValidFill(e,t){if(!this.engine.block.isValid(e)||!this.engine.block.hasFill(e)||e!==t.blockId)return;let r=this.engine.block.getFill(e);if(r===t.fillId)return r}},Je=Di;async function Mi(e,t,r,o){let i=t.engine.block;if(!i.hasFill(e))throw new Error("Block does not support fill");let a=i.getFill(e),f=i.getSourceSet(a,"fill/image/sourceSet"),n=i.getString(a,"fill/image/imageFileURI"),l=i.getString(a,"fill/image/previewFileURI");try{t.engine.block.setState(a,{type:"Pending",progress:0});let s={...r.get(e),version:"0.0.0",initialSourceSet:f,initialImageFileURI:n,initialPreviewFileURI:l,blockId:e,fillId:a,status:"PROCESSING"};r.set(e,s);let d=await o.processFill(s);if(r.get(e).status!=="PROCESSING"||!r.isConsistent(e)||r.get(e).status!=="PROCESSING"||!r.isConsistent(e)||d==null)return;let u={version:"0.0.0",initialSourceSet:f,initialImageFileURI:n,initialPreviewFileURI:l,blockId:e,fillId:a,status:"PROCESSED"},p=o.commitProcessing(d,u);(p==null||p===e)&&r.set(e,u),t.engine.editor.addUndoStep()}catch(s){if(t.engine.block.isValid(e)&&(r.set(e,{version:"0.0.0",initialSourceSet:f,initialImageFileURI:n,initialPreviewFileURI:l,blockId:e,fillId:a,status:"ERROR"}),r.recoverInitialImageData(e)),s!=null&&typeof s=="object"&&"message"in s&&typeof s.message=="string"){let d=s.message==="signal timed out"?"Processing canceled due to timeout":s.message;t.ui.showNotification({type:"error",message:d})}console.log(s)}finally{t.engine.block.isValid(a)&&t.engine.block.setState(a,{type:"Ready"})}}var se=Mi;function Xe(e){return`${e}.fillProcessing.feature`}function Ti(e){return`${e}.fillProcessing.canvasMenu`}function Ni(e){return`plugin.${e}.fillProcessing.canvasMenu.button.label`}function Ye(e,{pluginId:t,process:r}){let o=Xe(t),i=new Je(e.engine,t);return Ui(e,i,o),e.engine.event.subscribe([],async a=>{a.forEach(f=>{let n=f.block;if(!(!e.engine.block.isValid(n)||!i.hasData(n))){if(f.type==="Created")i.isDuplicate(n)&&i.fixDuplicate(n);else if(f.type==="Updated")switch(i.get(n).status){case"PENDING":{e.feature.isEnabled(o,{engine:e.engine})&&e.engine.block.isAllowedByScope(n,"fill/change")&&e.engine.block.getState(n).type!=="Pending"&&r(n,i);break}case"PROCESSING":case"PROCESSED":{i.isConsistent(n)||i.clear(n);break}default:}}})}),{featureId:o}}function Ui(e,t,r){e.feature.enable(r,({engine:o})=>{let i=o.block.findAllSelected();if(i.length!==1)return!1;let[a]=i;if(!e.engine.block.isVisible(a))return!1;if(e.engine.block.hasFill(a)){if(e.engine.block.getKind(a)==="sticker")return!1;let f=e.engine.block.getFill(a);if(e.engine.block.getType(f)!=="//ly.img.ubq/fill/image")return!1;let n=o.block.getString(f,"fill/image/imageFileURI");return o.block.getSourceSet(f,"fill/image/sourceSet").length>0||n!==""?!0:t.get(a).status==="PROCESSING"}return!1})}function Qe(e,t){let{pluginId:r,locations:o}=t,i=new Je(e.engine,r),a=Ti(r),f=Ni(r),n=Xe(r);return o?.includes("canvasMenu")&&e.ui.setCanvasMenuOrder([a,...e.ui.getCanvasMenuOrder()]),e.ui.registerComponent(a,({builder:{Button:l},engine:s})=>{if(!e.feature.isEnabled(n,{engine:s}))return;let[d]=s.block.findAllSelected();if(!e.engine.block.isAllowedByScope(d,"fill/change"))return;let u=i.get(d),p=u.status==="PROCESSING",m=u.status==="PENDING"||u.status==="PROCESSING"||s.block.getState(d)?.type==="Pending",x;if(p&&u.progress){let{current:b,total:v}=u.progress;x=b/v*100}let h=`${a}.button`;l(h,{label:f,icon:t.icon,isLoading:p,isDisabled:m,loadingProgress:x,onClick:()=>{(u.status==="IDLE"||u.status==="ERROR"||u.status==="PROCESSED")&&i.set(d,{status:"PENDING"})}})}),{canvasMenuComponentId:a,translationsKeys:{canvasMenuLabel:f}}}var On=new RegExp(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,"i"),Fn=new RegExp(/[A-Fa-f0-9]{1}/,"g"),kn=new RegExp(/[A-Fa-f0-9]{2}/,"g");var zi=typeof global=="object"&&global&&global.Object===Object&&global,et=zi;var Gi=typeof self=="object"&&self&&self.Object===Object&&self,Wi=et||Gi||Function("return this")(),J=Wi;var Vi=J.Symbol,L=Vi;var tt=Object.prototype,$i=tt.hasOwnProperty,Ki=tt.toString,G=L?L.toStringTag:void 0;function qi(e){var t=$i.call(e,G),r=e[G];try{e[G]=void 0;var o=!0}catch{}var i=Ki.call(e);return o&&(t?e[G]=r:delete e[G]),i}var rt=qi;var Hi=Object.prototype,Zi=Hi.toString;function Ji(e){return Zi.call(e)}var ot=Ji;var Xi="[object Null]",Yi="[object Undefined]",at=L?L.toStringTag:void 0;function Qi(e){return e==null?e===void 0?Yi:Xi:at&&at in Object(e)?rt(e):ot(e)}var it=Qi;function en(e){return e!=null&&typeof e=="object"}var nt=en;var tn="[object Symbol]";function rn(e){return typeof e=="symbol"||nt(e)&&it(e)==tn}var ft=rn;var on=/\s/;function an(e){for(var t=e.length;t--&&on.test(e.charAt(t)););return t}var st=an;var nn=/^\s+/;function fn(e){return e&&e.slice(0,st(e)+1).replace(nn,"")}var lt=fn;function sn(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var P=sn;var ut=NaN,ln=/^[-+]0x[0-9a-f]+$/i,un=/^0b[01]+$/i,pn=/^0o[0-7]+$/i,dn=parseInt;function cn(e){if(typeof e=="number")return e;if(ft(e))return ut;if(P(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=P(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=lt(e);var r=un.test(e);return r||pn.test(e)?dn(e.slice(2),r?2:8):ln.test(e)?ut:+e}var le=cn;var mn=function(){return J.Date.now()},X=mn;var gn="Expected a function",xn=Math.max,hn=Math.min;function vn(e,t,r){var o,i,a,f,n,l,s=0,d=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(gn);t=le(t)||0,P(r)&&(d=!!r.leading,u="maxWait"in r,a=u?xn(le(r.maxWait)||0,t):a,p="trailing"in r?!!r.trailing:p);function m(g){var _=o,A=i;return o=i=void 0,s=g,f=e.apply(A,_),f}function x(g){return s=g,n=setTimeout(v,t),d?m(g):f}function h(g){var _=g-l,A=g-s,ge=t-_;return u?hn(ge,a-A):ge}function b(g){var _=g-l,A=g-s;return l===void 0||_>=t||_<0||u&&A>=a}function v(){var g=X();if(b(g))return y(g);n=setTimeout(v,h(g))}function y(g){return n=void 0,p&&o?m(g):(o=i=void 0,f)}function W(){n!==void 0&&clearTimeout(n),s=0,o=l=i=n=void 0}function R(){return n===void 0?f:y(X())}function I(){var g=X(),_=b(g);if(o=arguments,i=this,l=g,_){if(n===void 0)return x(l);if(u)return clearTimeout(n),n=setTimeout(v,t),m(l)}return n===void 0&&(n=setTimeout(v,t)),f}return I.cancel=W,I.flush=R,I}var pt=vn;var bn="Expected a function";function yn(e,t,r){var o=!0,i=!0;if(typeof e!="function")throw new TypeError(bn);return P(r)&&(o="leading"in r?!!r.leading:o,i="trailing"in r?!!r.trailing:i),pt(e,t,{leading:o,maxWait:t,trailing:i})}var ue=yn;import{applySegmentationMask as _n,removeBackground as jn,segmentForeground as wn}from"@imgly/background-removal";function Sn(e,t=1024){if(e.length===0)return;let[r,o]=e.reduce((i,a)=>(a.width>=t&&a.height>=t?i[0].push(a):i[1].push(a),i),[[],[]]);return r.length>0?r.sort((i,a)=>i.width*i.height-a.width*a.height)[0]:o.sort((i,a)=>a.width*a.height-i.width*i.height)[0]}var dt=Sn;async function In(e,t,r){let i=new URL(t).pathname.split("/"),a=i[i.length-1],n=(await r.unstable_upload(new File([e],a,{type:e.type}),()=>{})).meta?.uri;if(n==null)throw new Error("Could not upload processed fill");return n}var pe=In;async function ce(e,t,r,o,i){return se(e,t,r,{processFill:i??(async a=>{let f=a.initialSourceSet,n=dt(f);if(n==null)throw new Error("No source found");let l=await de(n.uri,t),s=await wn(l,o);return await Promise.all(f.map(async u=>{let p=await _n(await de(u.uri,t),s,o),m=await pe(p,u.uri,t);return{...u,uri:m}}))}),commitProcessing:(a,f)=>{let n=f.fillId;t.engine.block.setSourceSet(n,"fill/image/sourceSet",a);let l=[...a].sort((s,d)=>s.width*s.height-d.width*d.height)[0];l!=null&&t.engine.block.setString(n,"fill/image/previewFileURI",l.uri)}})}async function me(e,t,r,o,i){return se(e,t,r,{processFill:i??(async a=>{let f=a.initialImageFileURI,n=await jn(await de(f,t),o);return await pe(n,f,t)}),commitProcessing:(a,f)=>{let n=f.fillId;t.engine.block.setString(n,"fill/image/imageFileURI",a),t.engine.block.setString(n,"fill/image/previewFileURI","")}})}async function de(e,t){if(e.startsWith("buffer:")){let r=await t.engine.editor.getMimeType(e),o=t.engine.editor.getBufferLength(e),i=t.engine.editor.getBufferData(e,0,o);return new Blob([i],{type:r})}else return e}async function ct(e,t,r,o){let i=e.engine.block;if(!i.hasFill(t))throw new Error("Block does not support fill");let a=i.getFill(t),f=i.getSourceSet(a,"fill/image/sourceSet"),n=i.getString(a,"fill/image/imageFileURI");if(f.length===0&&n==="")throw new Error("No source or image file URI found");switch(o.type){case"@imgly/background-removal":{let l=o.configuration??{},s={device:"gpu",...l,progress:ue((d,u,p)=>{let m=r.get(t);m.status!=="PROCESSING"||!r.isConsistent(t)||(l.progress?.(d,u,p),r.set(t,{...m,progress:{key:d,current:u,total:p}}))},100)};f.length>0?ce(t,e,r,s):me(t,e,r,s);break}case"custom":{f.length>0?ce(t,e,r,void 0,l=>o.processSourceSet(l.initialSourceSet)):me(t,e,r,void 0,l=>o.processImageFileURI(l.initialImageFileURI));break}default:throw new Error("Unknown background removal provider")}}var Y="@imgly/plugin-background-removal-web",mt=(e={})=>({initialize({cesdk:t}){if(t==null)return;Pn(t),Ye(t,{pluginId:Y,process:(o,i)=>{ct(t,o,i,e.provider??{type:"@imgly/background-removal"})}});let{translationsKeys:r}=Qe(t,{pluginId:Y,icon:"@imgly/icons/BGRemove",locations:e.ui?.locations});t.setTranslations({en:{[r.inspectorBarLabel]:"BG Removal",[r.navigationBarLabel]:"BG Removal",[r.canvasBarLabel]:"BG Removal",[r.canvasMenuLabel]:"BG Removal",[r.dockLabel]:"BG Removal"}})}});function Pn(e){e.ui.addIconSet("@imgly/plugin/background-removal",`
2
2
  <svg>
3
3
  <symbol
4
4
  fill="none"
@@ -17,7 +17,7 @@ var Pt=class{constructor(e,t){this.engine=e,this.key=t}hasData(e){return this.en
17
17
  <path d="M13.4317 13.1374C14.3663 12.6292 15.0007 11.6387 15.0007 10.5C15.0007 8.84315 13.6576 7.5 12.0007 7.5C10.3439 7.5 9.00074 8.84315 9.00074 10.5C9.00074 11.6387 9.63515 12.6292 10.5698 13.1374C9.94563 13.2733 9.38367 13.4801 8.9164 13.6917C7.98874 14.112 7.54792 15.1133 7.62602 16.1287L8.00074 21.0005H16.0007L16.3755 16.1287C16.4536 15.1133 16.0128 14.112 15.0851 13.6917C14.6178 13.4801 14.0559 13.2733 13.4317 13.1374Z" fill="currentColor"/>
18
18
  </symbol>
19
19
  </svg>
20
- `)}var $i=e=>({name:ae,version:"1.0.2",...yt(e)}),Ks=$i;export{Ks as default};
20
+ `)}var Rn=e=>({name:Y,version:"1.0.3",...mt(e)}),Cf=Rn;export{Cf as default};
21
21
  /*! Bundled license information:
22
22
 
23
23
  lodash-es/lodash.js: