(function(h,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(h=typeof globalThis<"u"?globalThis:h||self,v(h["image-filter"]={}))})(this,function(h){"use strict";var z=Object.defineProperty;var J=(h,v,I)=>v in h?z(h,v,{enumerable:!0,configurable:!0,writable:!0,value:I}):h[v]=I;var S=(h,v,I)=>(J(h,typeof v!="symbol"?v+"":v,I),I);class v{constructor(r){S(this,"cvs");this.cvs=r}process(r){let e,t;r instanceof HTMLImageElement?(e=r.naturalWidth,t=r.naturalHeight):r instanceof HTMLCanvasElement?(e=r.width,t=r.height):(e=r.videoWidth,t=r.videoHeight);const s=this.cvs.getContext("2d");if(this.cvs.width=e,this.cvs.height=t,s){s.drawImage(r,0,0);const f=s.getImageData(0,0,this.cvs.width,this.cvs.height),o=f.data;for(var n=0;n>15}setThreshold(e){this.threshold=e}setOTSUEnabled(e){this.otsuEnabled=e}}class B extends v{convert(r,e,t,s){const n=r*6966+e*23436+t*2366>>15;return{r:n,g:n,b:n,a:s}}}class P extends v{convert(r,e,t,s){const n=r*.393+e*.769+t*.189,f=r*.349+e*.686+t*.168,o=r*.272+e*.534+t*.131;return{r:n,g:f,b:o,a:s}}}let j;const E=document.createElement("canvas");window.Dynamsoft&&(j=window.Dynamsoft.DDV);const N=async()=>new Promise((u,r)=>{E.toBlob(e=>{e?u(e):r()},"image/jpeg",100)}),k=async u=>new Promise((r,e)=>{let t=document.createElement("img");t.onload=function(){r(t)};let s=URL.createObjectURL(u);t.src=s});if(!j){class u{}j={ImageFilter:u}}class V extends j.ImageFilter{async applyFilter(r,e){if(e==="original")return new Promise((t,s)=>{t(r.data)});{let t=await k(r.data);e==="BW"?new M(E,127,!0).process(t):e==="sepia"?new P(E).process(t):e==="grayscale"?new B(E).process(t):e==="invert"&&new W(E).process(t);let s=await N();return new Promise((n,f)=>{n(s)})}}get defaultFilterType(){return"original"}querySupported(){return[{type:"original",label:"Original"},{type:"grayscale",label:"Gray"},{type:"BW",label:"B&W"},{type:"invert",label:"Invert"},{type:"sepia",label:"Retro"}]}destroy(){super.destroy()}}class W extends v{convert(r,e,t,s){return r=255-r,e=255-e,t=255-t,{r,g:e,b:t,a:s}}}h.BlackwhiteFilter=M,h.GenericImageFilter=v,h.GrayscaleFilter=B,h.ImageFilterHandler=V,h.InvertFilter=W,h.SepiaFilter=P,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});