import { f as fallback } from './async-Djx13DAD.js';
import { d as attr_class, a as attr, c as bind_props, g as attr_style } from './index-B7gr0Dsc.js';
import { o as onDestroy } from './index-server-lqjMX237.js';
import './MarkdownCode.svelte_svelte_type_style_lang-DJRtJayx.js';
import { S as Ss } from './2-CeYbpaU1.js';
import { o } from './StreamingBar-D7mIo11c.js';
import { h } from './Webcam-D2mdKJI9.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 $(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$1)&&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$1||_==="waiting"))return;if(r){d.toDataURL("image/jpeg");return}d.toBlob(a=>{},`image/${r?"jpeg":"png"}`,.8);}}let s$1=false,g=[],D,c,f;function j(){if(s$1){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 Ss([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$1=!s$1;}function q({destroy:i}={}){u==="image"&&r&&(s$1=!s$1),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 { $ };
//# sourceMappingURL=Webcam2-Co_MYLbs.js.map
