(function(){/* Copyright The Closure Library Authors. SPDX-License-Identifier: Apache-2.0 */ 'use strict';function q(a){var b=0;return function(){return b>>0)+"_",f=0;return b}); v("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;cc&&(c=Math.max(0,f+c));if(null==d||d>f)d=f;d=Number(d);0>d&&(d=Math.max(0,f+d));for(c=Number(c||0);cd;++d){var f=Math.min(100,Math.max(0,a.g[d]));c.fillRect(10*d+1,100-f+1,8,f)}c.setLineDash([2,2]);c.strokeStyle="#a0a0a0a0";c.lineWidth=2;c.beginPath();c.moveTo(0,30);c.lineTo(100,30);c.stroke();c.beginPath();c.moveTo(0,60);c.lineTo(100,60);c.stroke();a.h.textContent=b.toFixed(0)+" fps"};function S(a){this.config=a} S.prototype.create=function(a,b,c){var d=this;this.options=b;b=this.config;c=c.appendChild(document.createElement("div"));c.classList.add("control-panel-entry");c.classList.add("control-panel-slider");var f=c.appendChild(document.createElement("span"));f.classList.add("label");(this.g=c.appendChild(document.createElement("span"))).classList.add("callout");var g=this.h=c.appendChild(document.createElement("input"));g.classList.add("value");g.type="range";b.range?(g.min=""+b.range[0],g.max=""+b.range[1], g.step=void 0===b.step?"any":""+b.step):b.discrete&&(g.min="0",g.max=""+(Object.keys(b.discrete).length-1),g.step="1");g.oninput=function(){pa(d,Number(g.value))};g.onchange=function(){var e=Number(g.value);d.config.discrete&&(e=Object.keys(d.config.discrete)[e],Array.isArray(d.config.discrete)&&(e=Number(e)));d.options[d.config.field]=e;a()};f.textContent=b.title}; S.prototype.update=function(){var a=this.options[this.config.field];a=this.config.discrete&&!Array.isArray(this.config.discrete)?Object.keys(this.config.discrete).indexOf(a):a;this.h.value=""+a;pa(this,a)};function pa(a,b){b=a.config.discrete?Object.values(a.config.discrete)[b]:b;a.g.textContent=""+b};/* SPDX-License-Identifier: Apache-2.0 */ var qa={facingMode:"user",width:640,height:480},ra={allowVideo:!0,allowImage:!0,examples:{videos:[],images:[]}};function T(a){return"https://fonts.gstatic.com/s/i/googlematerialicons/"+a+"/v8/white-24dp/1x/gm_"+a+"_white_24dp.png"} function sa(a,b){var c=a.getVideoTracks()[0],d=c.getSettings().width,f=c.getSettings().height,g=d/f;if(1E-6>Math.abs(g-b))return a;if(g>b){var e=f;var h=2*Math.floor(f*b/2)}else h=d,e=2*Math.floor(d/b/2);a=new MediaStreamTrackProcessor({track:c});b=new MediaStreamTrackGenerator({kind:"video"});c=new TransformStream({transform:function(k,m){var l,r,n,p;return G(function(A){l=2*Math.floor((d-h)/4);r=2*Math.floor((f-e)/4);n={x:l,y:r,width:h,height:e};p=new VideoFrame(k,{visibleRect:n});k.close();m.enqueue(p); A.g=0})}});a.readable.pipeThrough(c).pipeTo(b.writable);return new MediaStream([b])}function U(a){this.j=[];this.u=0;this.l=!1;this.aspectRatio=0;this.config=Object.assign({},ra,a);this.config.cameraOptions=Object.assign({},qa,a.cameraOptions||{})} function ta(){var a,b,c,d,f,g;return G(function(e){switch(e.g){case 1:return D(e,navigator.mediaDevices.enumerateDevices(),2);case 2:a=e.i;b=a.filter(function(h){return"videoinput"===h.kind&&h.label});if(b.length){e.g=3;break}e.m=4;return D(e,navigator.mediaDevices.getUserMedia({video:!0}),6);case 6:c=e.i;d=w(c.getTracks());for(f=d.next();!f.done;f=d.next())g=f.value,g.stop();da(e);break;case 4:return ea(e),e.return(!1);case 3:return e.return(!0)}})} function ua(){var a,b,c,d,f,g;return G(function(e){switch(e.g){case 1:return a=[],D(e,ta(),2);case 2:b=e.i;if(!b){e.g=3;break}return D(e,navigator.mediaDevices.enumerateDevices(),4);case 4:for(c=e.i,d=w(c),f=d.next();!f.done;f=d.next())g=f.value,""!==g.label&&"videoinput"===g.kind&&a.push({label:g.label,deviceId:g.deviceId});case 3:return e.return(a)}})}function V(a){window.requestAnimationFrame(function(){a.tick()})} U.prototype.tick=function(){var a=this,b=null;this.l&&(this.video.paused||this.video.currentTime===this.u||(this.i||(va(this,this.video.currentTime/this.video.duration),this.h.time.textContent=wa(this.video.currentTime)),this.u=this.video.currentTime,b=this.config.onFrame?this.config.onFrame(this.video,{width:this.video.videoWidth,height:this.video.videoHeight}):null),b?b.then(function(){V(a)}):V(this))};U.prototype.setVideoCameraAspectRatio=function(a){this.aspectRatio=a;this.i&&xa(this,this.i)}; function xa(a,b){function c(){a.video.play();a.l=!0;V(a);a.video.removeEventListener("loadedmetadata",c)}b=0!==a.aspectRatio?sa(b,a.aspectRatio):b;a.i=b;a.video.srcObject=b;a.video.addEventListener("loadedmetadata",c)}function ya(a){var b,c,d,f;return G(function(g){a.h.parent.style.display="none";a.l=!1;if(a.i){b=a.i.getTracks();c=w(b);for(d=c.next();!d.done;d=c.next())f=d.value,f.stop();a.i=void 0}g.g=0})} function za(a){var b,c,d,f,g,e,h,k,m;return G(function(l){if(1==l.g)return D(l,ua(),2);b=l.i.map(function(r){return{label:r.label,type:"webcam",O:r,start:function(){return Aa(a,r)}}});f=null==(c=a.config.examples)?void 0:null==(d=c.videos)?void 0:d.map(function(r){return{label:r.name,type:"video",video:a.video,start:function(){Ba(a,r.src)}}});h=null==(g=a.config.examples)?void 0:null==(e=g.images)?void 0:e.map(function(r){return{label:r.name,type:"image",image:a.g,start:function(){Ca(a,r.src)}}}); return l.return([].concat(x(b),x(null!=(k=f)?k:[]),x(null!=(m=h)?m:[])))})}function Da(a,b){var c,d;return G(function(f){return 1==f.g?D(f,null==(d=(c=a.config).M)?void 0:d.call(c),2):3!=f.g?D(f,ya(a),3):D(f,b.start(),0)})}function Ea(a,b){var c,d,f,g,e;return G(function(h){return 1==h.g?D(h,null==(d=(c=a.config).onFrame)?void 0:d.call(c,b,{width:b.naturalWidth,height:b.naturalHeight}),2):h.return(null==(f=a.config)?void 0:null==(e=(g=f).onSourceChanged)?void 0:e.call(g,b.src,"image"))})} function Fa(a){var b,c,d;return G(function(f){if(1==f.g)return a.h.parent.style.display="flex",va(a,0),D(f,a.video.play(),2);a.C();a.l=!0;V(a);return f.return(null==(b=a.config)?void 0:null==(d=(c=b).onSourceChanged)?void 0:d.call(c,a.video.src,"video"))})} function Aa(a,b){var c,d,f,g,e;return G(function(h){return 1==h.g?(d={video:Object.assign({},{deviceId:b.deviceId},null!=(c=a.config.cameraOptions)?c:{})},D(h,null==(f=a.config)?void 0:null==(e=(g=f).M)?void 0:e.call(g),2)):3!=h.g?D(h,ya(a),3):h.return(navigator.mediaDevices.getUserMedia(d).then(function(k){xa(a,k);var m,l;return null==(m=a.config)?void 0:null==(l=m.onSourceChanged)?void 0:l.call(m,b.deviceId,"webcam")}).catch(function(k){console.error("Failed to acquire camera feed: "+k);alert("Failed to acquire camera feed: "+ k);throw k;}))})} function Ga(a,b){a.m=new na({options:a.j.map(function(c){var d=void 0;"image"===c.type?d=N("https://fonts.gstatic.com/s/i/googlematerialicons/image/v12/gm_grey-24dp/1x/gm_image_gm_grey_24dp.png"):"video"===c.type&&(d=N("https://fonts.gstatic.com/s/i/googlematerialicons/videocam/v12/gm_grey-24dp/1x/gm_videocam_gm_grey_24dp.png"));return{name:c.label,value:c.label,data:c,prefix:d}}),onclick:function(c){a.h.parent.style.display="none";c=c.data;c.start();window.localStorage.setItem("SOURCE_PICKER_LAST_SOURCE",c.label)}, B:function(){a.o.style.zIndex="2000"},A:function(){a.o.style.zIndex="100"}},b)} function Ha(a,b){var c=b.appendChild(document.createElement("input"));c.type="file";c.style.display="none";b.appendChild(M("file-selection",[b=L("",[N(T("file_upload"))])]));b.onclick=function(){c.click()};c.onchange=function(){var d,f,g,e,h,k;return G(function(m){d=c.files;if(null==(f=d)?0:f.length){g=d[0];e=g.type.toLowerCase();h=e.substring(0,e.indexOf("/"));var l;(l="undefined"!==typeof MediaSource&&g instanceof MediaSource)||(l=g.type.match(/^([^;]+)(?:;\w+=(?:\w+|"[\w;,= ]+"))*$/i),l=2===(null== l?void 0:l.length)&&(/^image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp|x-icon|heic|heif)$/i.test(l[1])||/^video\/(?:mpeg|mp4|ogg|webm|x-matroska|quicktime|x-ms-wmv)$/i.test(l[1])||/^audio\/(?:3gpp2|3gpp|aac|L16|midi|mp3|mp4|mpeg|oga|ogg|opus|x-m4a|x-matroska|x-wav|wav|webm)$/i.test(l[1])));if(!l)throw Error("");l=new J(URL.createObjectURL(g));k=l.toString();"image"===h?(P(a.m,g.name),Ca(a,k)):"video"===h&&(P(a.m,g.name),Ba(a,k))}m.g=0})}} function Ca(a,b){a.g.onload=function(){return G(function(c){a.config.onFrame?c=D(c,Da(a,{label:"file",type:"image",image:a.g,start:function(){return G(function(d){return D(d,Ea(a,a.g),0)})}}),0):(c.g=0,c=void 0);return c})};a.g.src=b} function Ba(a,b){function c(){return G(function(d){if(1==d.g)return a.video.loop=!0,a.config?d=D(d,Da(a,{label:"file",type:"video",video:a.video,start:function(){return Fa(a)}}),2):(d.g=2,d=void 0),d;a.video.removeEventListener("loadedmetadata",c);d.g=0})}a.video.addEventListener("loadedmetadata",c);a.video.srcObject=null;a.video.src=b}function Ia(a,b){O(a.m,b.label)||P(a.m)} function Ja(a){var b=window.localStorage.getItem("SOURCE_PICKER_LAST_SOURCE"),c=a.j.find(function(d){return d.label===b});c?Ia(a,c):0p+z.width&&(n=p+z.width);f.style.left=n+"px";a.video.currentTime=(n-p)/z.width*a.video.duration}k.preventDefault();var r=a.video.paused;a.video.pause();document.addEventListener("mousemove",l);document.addEventListener("mouseup",m)};h.onclick=function(){a.video.paused?(a.video.play(),h.src=c):(a.video.pause(),h.src=d)};a.C=function(){a.video.paused&&(h.src=d);h.src=c}} function va(a,b){var c=a.h.J,d=a.h.track.getBoundingClientRect();a=a.h.parent.getBoundingClientRect();c.style.left=d.left-a.left+d.width*b+"px"}function wa(a){var b=Math.floor(a%60).toString();b=1===b.length?"0"+b:b;a=Math.floor(a/60).toString();a=1===a.length?"0"+a:a;return a+":"+b}U.prototype.update=function(){if(this.g&&!this.l&&this.config.onFrame)this.config.onFrame(this.g,{width:this.g.naturalWidth,height:this.g.naturalHeight})};function W(a){this.config=a}W.prototype.create=function(a,b,c){a=c.appendChild(document.createElement("div"));a.classList.add("control-panel-entry");a.classList.add("control-panel-text");a.textContent=this.config.title};W.prototype.update=function(){};function X(a){this.config=a} X.prototype.create=function(a,b,c){var d=this;this.h=a;this.options=b;this.g=c.appendChild(document.createElement("div"));this.g.classList.add("control-panel-entry");this.g.classList.add("control-panel-toggle");this.g.onclick=function(){d.options[d.config.field]=!d.options[d.config.field];d.h()};a=this.g.appendChild(document.createElement("span"));a.classList.add("label");this.value=this.g.appendChild(document.createElement("span"));this.value.classList.add("value");a.textContent=this.config.title}; X.prototype.update=function(){this.options[this.config.field]?(this.value.textContent="Yes",this.g.classList.add("yes"),this.g.classList.remove("no")):(this.value.textContent="No",this.g.classList.add("no"),this.g.classList.remove("yes"))};function Y(a,b){var c=this;this.parent=a;this.options=b;this.i=[];this.h=!0;a=[L("hamburger-menu"),L("hamburger-menu"),L("hamburger-menu")];var d=L("control-panel-shell",[this.g=L("control-panel"),this.l=L("control-panel-expander",a)]);this.l.onclick=function(){c.h=!c.h;d.style.left=c.h?"0px":"-"+(d.offsetLeft+c.g.offsetLeft+c.g.offsetWidth-15)+"px";d.classList.toggle("control-panel-expanded")};this.parent.appendChild(d)} Y.prototype.add=function(a){var b=this;a=w(a);for(var c=a.next();!c.done;c=a.next())c=c.value,this.i.push(c),c.create(function(){Z(b)},this.options,this.g);Z(this);return this};Y.prototype.on=function(a){this.j=a;Z(this);return this};function Z(a){for(var b=w(a.i),c=b.next();!c.done;c=b.next())c.value.update();a.j&&a.j(a.options)}I("ControlPanel",Y);I("Slider",S);I("StaticText",W);I("Toggle",X);I("SourcePicker",U);I("FPS",R);I("DropDownControl",Q);}).call(this);