import { f as fallback } from './async-D55cHugf.js';
import { f as attr_class, a as attr, d as bind_props, g as attr_style } from './index-u8mz_F03.js';
import { o as onDestroy } from './index-server-CQz6EZl_.js';
import { b as bs } from './2-BLdXJizP.js';
import { o } from './StreamingBar-BGU65w2M.js';
import { h } from './Webcam-CvKMKUzA.js';

/* empty css                                           */function U(p,e){p.component(l=>{l.push(`<button class="svelte-1dqolfz"${attr_style("",{height:"100%"})}><div class="wrap svelte-1dqolfz"><span class="icon-wrap svelte-1dqolfz">`),h(l),l.push("<!----></span> Click to Access Webcam</div></button>");});}function Z(p,e){p.component(l=>{let o$1,_=fallback(e.stream_state,"closed"),d,r=fallback(e.streaming,false),M=fallback(e.pending,false),h=fallback(e.root,""),w=fallback(e.stream_every,1),u=fallback(e.mode,"image"),b=e.mirror_webcam,E=e.include_audio,L=fallback(e.webcam_constraints,null),T=e.i18n,k=e.upload,y=fallback(e.value,null),W=fallback(e.time_limit,null);function B(){if((!r||r&&s)&&o$1.videoWidth&&o$1.videoHeight){var i=d.getContext("2d");if(d.width=o$1.videoWidth,d.height=o$1.videoHeight,i.drawImage(o$1,0,0,o$1.videoWidth,o$1.videoHeight),b&&(i.scale(-1,1),i.drawImage(o$1,-o$1.videoWidth,0)),r&&(!s||_==="waiting"))return;if(r){d.toDataURL("image/jpeg");return}d.toBlob(a=>{},`image/${r?"jpeg":"png"}`,.8);}}let s=false,g=[],D,c,f;function j(){if(s){f.stop();let i=new Blob(g,{type:c}),a=new FileReader;a.onload=async function(v){if(v.target){let m=new File([i],"sample."+c.substring(6));const H=await bs([m]);(await k(H,h))?.filter(Boolean)[0];}},a.readAsDataURL(i);}else if(typeof MediaRecorder<"u"){g=[];let i=["video/webm","video/mp4"];for(let a of i)if(MediaRecorder.isTypeSupported(a)){c=a;break}if(c===null){console.error("No supported MediaRecorder mimeType");return}f=new MediaRecorder(D,{mimeType:c}),f.addEventListener("dataavailable",function(a){g.push(a.data);}),f.start(200);}s=!s;}function q({destroy:i}={}){u==="image"&&r&&(s=!s),i||(u==="image"?B():j());}function z(i,a){const v=m=>{i&&!i.contains(m.target)&&!m.defaultPrevented&&a(m);};return document.addEventListener("click",v,true),{destroy(){document.removeEventListener("click",v,true);}}}onDestroy(()=>{typeof window>"u"||q({destroy:true});}),l.push('<div class="wrap svelte-1tktvmr">'),o(l,{time_limit:W}),l.push(`<!---->  <video${attr_class("svelte-1tktvmr",void 0,{flip:b,hide:true})}></video> <img${attr("src",y?.url)}${attr_class("svelte-1tktvmr",void 0,{hide:true})}/> `),l.push("<!--[-->"),l.push('<div title="grant webcam access" style="height: 100%">'),U(l),l.push("<!----></div>"),l.push("<!--]--></div>"),bind_props(e,{stream_state:_,streaming:r,pending:M,root:h,stream_every:w,mode:u,mirror_webcam:b,include_audio:E,webcam_constraints:L,i18n:T,upload:k,value:y,time_limit:W,click_outside:z});});}

export { Z };
//# sourceMappingURL=Webcam2-CNM_PDwT.js.map
