var f=(c,e,t)=>new Promise((s,o)=>{var n=r=>{try{a(t.next(r))}catch(u){o(u)}},d=r=>{try{a(t.throw(r))}catch(u){o(u)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(n,d);a((t=t.apply(c,e)).next())});import{tsvb as m}from"effects-sdk";var i="https://assets.100ms.live/effectsdk/3.6.2/";var h=class{constructor(e,t){this.blurAmount=0;this.backgroundType="none";this.preset="balanced";this.TAG="[HMSEffectsPlugin]";this.operationQueue=Promise.resolve();this.effectRequestId=0;this.effects=new m(e),this.onInit=t,this.initPromise=new Promise(s=>{this.resolveInit=s}),this.effects.config({sdk_url:i,models:{colorcorrector:"",facedetector:"",lowlighter:""},test_inference:!0,wasmPaths:{"ort-wasm.wasm":`${i}ort-wasm.wasm`,"ort-wasm-simd.wasm":`${i}ort-wasm-simd.wasm`,"ort-wasm-simd.jsep.wasm":`${i}ort-wasm-simd.jsep.wasm`}}),this.effects.onError(s=>{s.type==="error"&&s.message&&console.error(this.TAG,"Effects SDK error:",s.message)}),this.effects.cache(),this.effects.onReady=()=>{var s;this.effects&&(this.resolveInit(),(s=this.onInit)==null||s.call(this),this.effects.setBackgroundFitMode("fill"),this.effects.setSegmentationPreset(this.preset))}}getName(){return"HMSEffects"}isSupported(){return this.effects.isSupported()}enqueueOperation(e){return this.operationQueue=this.operationQueue.then(()=>this.initPromise).then(()=>e()).catch(t=>{console.error(this.TAG,"Operation failed:",t)}),this.operationQueue}removeBlur(){this.blurAmount=0,this.backgroundType==="blur"&&(this.backgroundType="none");let e=++this.effectRequestId;this.enqueueOperation(()=>{e===this.effectRequestId&&this.effects.clearBlur()})}removeBackground(){this.background="",this.backgroundType==="image"&&(this.backgroundType="none");let e=++this.effectRequestId;this.enqueueOperation(()=>{e===this.effectRequestId&&this.effects.clearBackground()})}setBlur(e){if(e<0||e>1)throw new Error("Blur amount should be between 0 and 1");this.blurAmount=e,this.background="",this.backgroundType="blur";let t=++this.effectRequestId;this.enqueueOperation(()=>{t===this.effectRequestId&&(this.effects.clearBackground(),this.effects.setBlur(this.blurAmount),this.effects.run())})}setPreset(e){return f(this,null,function*(){return this.preset=e,new Promise((t,s)=>{this.enqueueOperation(()=>{this.effects.setSegmentationPreset(this.preset).then(t).catch(s)})})})}onResolutionChange(e){this.onResolutionChangeCallback=e}getPreset(){return this.preset}removeEffects(){this.backgroundType="none",this.background="",this.blurAmount=0;let e=++this.effectRequestId;this.enqueueOperation(()=>{e===this.effectRequestId&&(this.effects.clearBackground(),this.effects.clearBlur(),this.effects.stop())})}setBackground(e){if(!e)throw new Error("Background url cannot be empty");this.background=e,this.blurAmount=0,this.backgroundType="image";let t=++this.effectRequestId;this.enqueueOperation(()=>{t===this.effectRequestId&&(this.effects.clearBlur(),this.effects.setBackground(this.background),this.effects.run())})}getBlurAmount(){return this.blurAmount}getBackground(){return this.background||this.backgroundType}getMetrics(){var e,t;return(t=(e=this.effects).getMetrics)==null?void 0:t.call(e)}apply(e){return this.effects.clear(),this.applyEffect(),this.effects.onChangeInputResolution(()=>{var s;let t=this.effects.getStream();if(t){let{height:o,width:n}=t.getVideoTracks()[0].getSettings();(s=this.onResolutionChangeCallback)==null||s.call(this,n,o)}}),this.effects.useStream(e),this.effects.getStream()||e}stop(){this.removeEffects()}applyEffect(){this.blurAmount?this.setBlur(this.blurAmount):this.background&&this.setBackground(this.background)}};export{h as HMSEffectsPlugin};
//# sourceMappingURL=HMSEffectsPlugin.js.map
