Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mediapipe/control_utils

Package Overview
Dependencies
Maintainers
4
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mediapipe/control_utils - npm Package Compare versions

Comparing version 0.5.1625171504 to 0.5.1625178644

32

control_utils.js

@@ -27,11 +27,11 @@ (function(){/*

g.s.value),h.onclick=function(k){return function(){T(c,k.s.value)}}(g);window.addEventListener("click",function(k){d.contains(k.target)||d.classList.remove("open")});b.appendChild(f)}function T(a,b){for(var c=v(a.g.options),d=c.next();!d.done;d=c.next()){d=d.value;var f=a.i[d.value];if(d.value===b&&!f.classList.contains("selected"))return(b=a.options.querySelector(".selected"))&&b.classList.remove("selected"),f.classList.add("selected"),a.h.textContent=f.textContent,a.g.onclick(d),!0}return!1}
function U(a){var b=a.options.querySelector(".selected");b&&(b.classList.remove("selected"),a.h.textContent="")};function V(a){this.g=a}
V.prototype.create=function(a,b,c){var d=this,f=c.appendChild(document.createElement("div"));f.classList.add("control-panel-entry");f.classList.add("control-panel-slider");c=f.appendChild(document.createElement("span"));c.classList.add("label");c.textContent=this.g.title;c=new pa({options:this.g.options.map(function(g){return Object.assign(Object.assign({},g),{data:null})}),C:function(){f.style.zIndex="1000"},onclick:function(g){b[d.g.field]=g.value;a();if(d.g.onselectionchanged)d.g.onselectionchanged(g)},B:function(){f.style.zIndex=
"100"}},f);0<this.g.options.length&&T(c,this.g.options[0].value)};V.prototype.update=function(){};function W(){this.i=this.counter=0;this.g=Array.from({length:10}).fill(0)}
W.prototype.create=function(a,b,c){b=c.appendChild(document.createElement("div"));b.classList.add("control-panel-entry");b.classList.add("control-panel-fps");a=b.appendChild(document.createElement("canvas"));this.h=b.appendChild(document.createElement("div"));this.h.classList.add("fps-text");c=b.appendChild(document.createElement("div"));c.classList.add("fps-30");c.textContent="30";b=b.appendChild(document.createElement("div"));b.classList.add("fps-60");b.textContent="60";a.width=100;a.height=100;
this.j=a.getContext("2d");qa(this,0)};W.prototype.update=function(){};W.prototype.tick=function(){var a=Math.floor(performance.now()/1E3);1<=a-this.i&&(qa(this,this.counter),this.i=a,this.counter=0);++this.counter};
function qa(a,b){a.g.shift();a.g.push(b);var c=a.j;c.fillStyle="green";c.clearRect(0,0,c.canvas.width,c.canvas.height);for(var d=0;10>d;++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 X(a){this.g=a}
X.prototype.create=function(a,b,c){var d=this;this.options=b;b=this.g;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.h=c.appendChild(document.createElement("span"))).classList.add("callout");var g=this.i=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(){ra(d,Number(g.value))};g.onchange=function(){var e=Number(g.value);d.g.discrete&&(e=Object.keys(d.g.discrete)[e],Array.isArray(d.g.discrete)&&(e=Number(e)));d.options[d.g.field]=e;a()};f.textContent=b.title};
X.prototype.update=function(){var a=this.options[this.g.field];a=this.g.discrete&&!Array.isArray(this.g.discrete)?Object.keys(this.g.discrete).indexOf(a):a;this.i.value=""+a;ra(this,a)};function ra(a,b){b=a.g.discrete?Object.values(a.g.discrete)[b]:b;a.h.textContent=""+b};var sa={facingMode:"user",width:640,height:480},ta={allowVideo:!0,allowImage:!0,examples:{videos:[],images:[]}};function ua(a){return"https://fonts.gstatic.com/s/i/googlematerialicons/"+a+"/v8/white-24dp/1x/gm_"+a+"_white_24dp.png"}function Y(a){this.l=[];this.A=0;this.j=!1;this.g=Object.assign(Object.assign({},ta),a);this.g.cameraOptions=Object.assign(Object.assign({},this.g.cameraOptions||{}),sa)}
function qa(a,b){var c=a.options.querySelector(".selected");c&&(c.classList.remove("selected"),a.h.textContent=void 0===b?"":b)};function U(a){this.g=a}
U.prototype.create=function(a,b,c){var d=this,f=c.appendChild(document.createElement("div"));f.classList.add("control-panel-entry");f.classList.add("control-panel-slider");c=f.appendChild(document.createElement("span"));c.classList.add("label");c.textContent=this.g.title;c=new pa({options:this.g.options.map(function(g){return Object.assign(Object.assign({},g),{data:null})}),C:function(){f.style.zIndex="1000"},onclick:function(g){b[d.g.field]=g.value;a();if(d.g.onselectionchanged)d.g.onselectionchanged(g)},B:function(){f.style.zIndex=
"100"}},f);0<this.g.options.length&&T(c,this.g.options[0].value)};U.prototype.update=function(){};function V(){this.i=this.counter=0;this.g=Array.from({length:10}).fill(0)}
V.prototype.create=function(a,b,c){b=c.appendChild(document.createElement("div"));b.classList.add("control-panel-entry");b.classList.add("control-panel-fps");a=b.appendChild(document.createElement("canvas"));this.h=b.appendChild(document.createElement("div"));this.h.classList.add("fps-text");c=b.appendChild(document.createElement("div"));c.classList.add("fps-30");c.textContent="30";b=b.appendChild(document.createElement("div"));b.classList.add("fps-60");b.textContent="60";a.width=100;a.height=100;
this.j=a.getContext("2d");ra(this,0)};V.prototype.update=function(){};V.prototype.tick=function(){var a=Math.floor(performance.now()/1E3);1<=a-this.i&&(ra(this,this.counter),this.i=a,this.counter=0);++this.counter};
function ra(a,b){a.g.shift();a.g.push(b);var c=a.j;c.fillStyle="green";c.clearRect(0,0,c.canvas.width,c.canvas.height);for(var d=0;10>d;++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 W(a){this.g=a}
W.prototype.create=function(a,b,c){var d=this;this.options=b;b=this.g;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.h=c.appendChild(document.createElement("span"))).classList.add("callout");var g=this.i=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(){sa(d,Number(g.value))};g.onchange=function(){var e=Number(g.value);d.g.discrete&&(e=Object.keys(d.g.discrete)[e],Array.isArray(d.g.discrete)&&(e=Number(e)));d.options[d.g.field]=e;a()};f.textContent=b.title};
W.prototype.update=function(){var a=this.options[this.g.field];a=this.g.discrete&&!Array.isArray(this.g.discrete)?Object.keys(this.g.discrete).indexOf(a):a;this.i.value=""+a;sa(this,a)};function sa(a,b){b=a.g.discrete?Object.values(a.g.discrete)[b]:b;a.h.textContent=""+b};var ta={facingMode:"user",width:640,height:480},ua={allowVideo:!0,allowImage:!0,examples:{videos:[],images:[]}};function X(a){return"https://fonts.gstatic.com/s/i/googlematerialicons/"+a+"/v8/white-24dp/1x/gm_"+a+"_white_24dp.png"}function Y(a){this.l=[];this.A=0;this.j=!1;this.g=Object.assign(Object.assign({},ua),a);this.g.cameraOptions=Object.assign(Object.assign({},this.g.cameraOptions||{}),ta)}
function va(a){return L(a,function c(){var d,f,g,e,h;return I(c,function(k){if(1==k.g)return F(k,navigator.mediaDevices.getUserMedia({video:!0}),2);if(3!=k.g)return F(k,navigator.mediaDevices.enumerateDevices(),3);d=k.l;f=[];g=v(d);for(e=g.next();!e.done;e=g.next())h=e.value,""!==h.label&&f.push({label:h.label,deviceId:h.deviceId});return k.return(f)})})}function Z(a){window.requestAnimationFrame(function(){a.tick()})}

@@ -41,17 +41,17 @@ Y.prototype.tick=function(){var a=this,b=null;this.j&&(this.video.paused||this.video.currentTime===this.A||(this.m||(wa(this,this.video.currentTime/this.video.duration),this.i.time.textContent=xa(this.video.currentTime)),this.A=this.video.currentTime,b=this.g.onFrame?this.g.onFrame(this.video,{width:this.video.videoWidth,height:this.video.videoHeight}):null),b?b.then(function(){Z(a)}):Z(this))};function ya(a,b){a.video.srcObject=b;a.video.onloadedmetadata=function(){a.video.play();a.j=!0;Z(a)}}

function Aa(a){return L(a,function c(){var d=this,f,g,e,h;return I(c,function(k){if(1==k.g)return f=d,F(k,va(d),2);g=k.l.map(function(l){return{label:l.label,type:"webcam",N:l,start:function(){return Ba(f,l)}}});e=d.g.examples.videos.map(function(l){return{label:l.name,type:"video",video:f.video,start:function(){Ca(f,l.src)}}});h=d.g.examples.images.map(function(l){return{label:l.name,type:"image",image:f.h,start:function(){Da(f,l.src)}}});return k.return([].concat(w(g),w(e),w(h)))})})}
function Ea(a,b){return L(a,function d(){var f=this;return I(d,function(g){1==g.g?g=F(g,za(f),2):3!=g.g?g=F(g,b.start(),3):f.g.onSourceChanged?g=F(g,f.g.onSourceChanged(),0):(g.g=0,g=void 0);return g})})}function Fa(a,b){return L(a,function d(){var f=this;return I(d,function(g){U(f.o);f.g&&f.g.onFrame?g=F(g,f.g.onFrame(b,{width:b.naturalWidth,height:b.naturalHeight}),0):(g.g=0,g=void 0);return g})})}
function Ga(a){return L(a,function c(){var d=this;return I(c,function(f){if(1==f.g){U(d.o);if(!d.g||!d.g.onFrame){f.g=0;return}d.i.parent.style.display="flex";wa(d,0);return F(f,d.video.play(),3)}d.D();d.j=!0;Z(d);f.g=0})})}
function Ea(a,b){return L(a,function d(){var f=this;return I(d,function(g){1==g.g?g=F(g,za(f),2):3!=g.g?g=F(g,b.start(),3):f.g.onSourceChanged?g=F(g,f.g.onSourceChanged(),0):(g.g=0,g=void 0);return g})})}function Fa(a,b){return L(a,function d(){var f=this;return I(d,function(g){f.g&&f.g.onFrame?g=F(g,f.g.onFrame(b,{width:b.naturalWidth,height:b.naturalHeight}),0):(g.g=0,g=void 0);return g})})}
function Ga(a){return L(a,function c(){var d=this;return I(c,function(f){if(1==f.g){if(!d.g||!d.g.onFrame){f.g=0;return}d.i.parent.style.display="flex";wa(d,0);return F(f,d.video.play(),3)}d.D();d.j=!0;Z(d);f.g=0})})}
function Ba(a,b){return L(a,function d(){var f=this,g;return I(d,function(e){g=f;return e.return(navigator.mediaDevices.getUserMedia({video:{deviceId:{exact:b.deviceId}},audio:!1}).then(function(h){g.m=h;ya(g,h)}).catch(function(h){console.error("Failed to acquire camera feed: "+h);alert("Failed to acquire camera feed: "+h);throw h;}))})})}
function Ha(a,b){a.o=new pa({options:a.l.map(function(c){var d=void 0;"image"===c.type?d=S("https://fonts.gstatic.com/s/i/googlematerialicons/image/v12/gm_grey-24dp/1x/gm_image_gm_grey_24dp.png"):"video"===c.type&&(d=S("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.i.parent.style.display="none";c.data.start()},C:function(){a.u.style.zIndex="2000"},B:function(){a.u.style.zIndex=
"100"}},b)}
function Ia(a,b){var c=b.appendChild(document.createElement("input"));c.type="file";c.style.display="none";b.appendChild(R("file-selection",[b=Q("",[S(ua("file_upload"))])]));b.onclick=function(){c.click()};c.onchange=function(){return L(a,function f(){var g,e,h,k,l=this;return I(f,function(n){if((g=c.files)&&0<g.length){e=g[0].type.toLowerCase();h=e.substring(0,e.indexOf("/"));var u=g[0];var m=u.type.match(/^([^;]+)(?:;\w+=(?:\w+|"[\w;,= ]+"))*$/i);if(2!==(null===m||void 0===m?void 0:m.length)||
!(/^image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp|x-icon)$/i.test(m[1])||/^video\/(?:mpeg|mp4|ogg|webm|x-matroska|quicktime|x-ms-wmv)$/i.test(m[1])||/^audio\/(?:3gpp2|3gpp|aac|L16|midi|mp3|mp4|mpeg|oga|ogg|opus|x-m4a|x-matroska|x-wav|wav|webm)$/i.test(m[1])))throw Error("unsafe blob MIME type: "+u.type);if(URL&&URL.createObjectURL)u=new M(URL.createObjectURL(u),na);else throw Error("cannot find createObjectURL");k=u.toString();"image"===h?Da(l,k):"video"===h&&Ca(l,k)}n.g=0})})}}
function Ia(a,b){var c=b.appendChild(document.createElement("input"));c.type="file";c.style.display="none";b.appendChild(R("file-selection",[b=Q("",[S(X("file_upload"))])]));b.onclick=function(){c.click()};c.onchange=function(){return L(a,function f(){var g,e,h,k,l=this;return I(f,function(n){if((g=c.files)&&0<g.length){e=g[0].type.toLowerCase();h=e.substring(0,e.indexOf("/"));var u=g[0];var m=u.type.match(/^([^;]+)(?:;\w+=(?:\w+|"[\w;,= ]+"))*$/i);if(2!==(null===m||void 0===m?void 0:m.length)||!(/^image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp|x-icon)$/i.test(m[1])||
/^video\/(?:mpeg|mp4|ogg|webm|x-matroska|quicktime|x-ms-wmv)$/i.test(m[1])||/^audio\/(?:3gpp2|3gpp|aac|L16|midi|mp3|mp4|mpeg|oga|ogg|opus|x-m4a|x-matroska|x-wav|wav|webm)$/i.test(m[1])))throw Error("unsafe blob MIME type: "+u.type);if(URL&&URL.createObjectURL)u=new M(URL.createObjectURL(u),na);else throw Error("cannot find createObjectURL");k=u.toString();"image"===h?(qa(l.o,g[0].name),Da(l,k)):"video"===h&&Ca(l,k)}n.g=0})})}}
function Da(a,b){a.h.onload=function(){return L(a,function d(){var f=this,g;return I(d,function(e){g=f;f.g.onFrame?e=F(e,Ea(f,{label:"file",type:"image",image:f.h,start:function(){return L(g,function k(){var l=this;return I(k,function(n){return F(n,Fa(l,l.h),0)})})}}),0):(e.g=0,e=void 0);return e})})};a.h.src=b}
function Ca(a,b){a.video.onloadedmetadata=function(){return L(a,function d(){var f=this,g;return I(d,function(e){g=f;f.video.loop=!0;f.g.onFrame?e=F(e,Ea(f,{label:"file",type:"video",video:f.video,start:function(){return Ga(g)}}),0):(e.g=0,e=void 0);return e})})};a.video.srcObject=null;a.video.src=b}
Y.prototype.create=function(a,b,c){var d=this,f=this.u=c.appendChild(document.createElement("div"));f.classList.add("control-panel-entry");f.classList.add("control-panel-source-picker");var g=Q("source-selection");f.append(g);Aa(this).then(function(e){d.l=e;Ha(d,g);Ia(d,g);e=g.appendChild(document.createElement("div"));e.classList.add("inputs");d.video=e.appendChild(document.createElement("video"));d.video.setAttribute("crossorigin","anonymous");d.h=e.appendChild(document.createElement("img"));d.h.setAttribute("crossorigin",
"anonymous");Ja(d,f);0<d.l.length&&(e=d.l[0],T(d.o,e.label)||U(d.o),e.start())})};
function Ja(a,b){var c=ua("pause"),d=ua("play_arrow"),f,g,e,h;b.append(e=Q("video-controls",[h=S(c),g=Q("video-track"),f=Q("video-slider-ball"),b=R("video-time")]));a.i={parent:e,K:f,track:g,time:b};b.textContent="00:00";f.style.display="inline-block";f.onmousedown=function(k){function l(){k.preventDefault();document.removeEventListener("mousemove",n);u||a.video.play();document.removeEventListener("mouseup",l)}function n(m){k.preventDefault();var q=e.getBoundingClientRect(),E=f.getBoundingClientRect(),
"anonymous");Ja(d,f);0<d.l.length&&(e=d.l[0],T(d.o,e.label)||qa(d.o),e.start())})};
function Ja(a,b){var c=X("pause"),d=X("play_arrow"),f,g,e,h;b.append(e=Q("video-controls",[h=S(c),g=Q("video-track"),f=Q("video-slider-ball"),b=R("video-time")]));a.i={parent:e,K:f,track:g,time:b};b.textContent="00:00";f.style.display="inline-block";f.onmousedown=function(k){function l(){k.preventDefault();document.removeEventListener("mousemove",n);u||a.video.play();document.removeEventListener("mouseup",l)}function n(m){k.preventDefault();var q=e.getBoundingClientRect(),E=f.getBoundingClientRect(),
A=g.getBoundingClientRect();m=m.clientX-q.left-E.width/2;q=A.left-q.left;m<q?m=q:m>q+A.width&&(m=q+A.width);f.style.left=m+"px";a.video.currentTime=(m-q)/A.width*a.video.duration}k.preventDefault();var u=a.video.paused;a.video.pause();document.addEventListener("mousemove",n);document.addEventListener("mouseup",l)};h.onclick=function(){a.video.paused?(a.video.play(),h.src=c):(a.video.pause(),h.src=d)};a.D=function(){a.video.paused&&(h.src=d);h.src=c}}
function wa(a,b){var c=a.i.K,d=a.i.track.getBoundingClientRect();a=a.i.parent.getBoundingClientRect();c.style.left=d.left-a.left+d.width*b+"px"}function xa(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}Y.prototype.update=function(){if(this.h&&!this.j&&this.g.onFrame)this.g.onFrame(this.h,{width:this.h.naturalWidth,height:this.h.naturalHeight})};function Ka(a){this.g=a}Ka.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.g.title};Ka.prototype.update=function(){};function La(a){this.h=a}La.prototype.create=function(a,b,c){var d=this;this.i=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.h.field]=!d.options[d.h.field];d.i()};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.h.title};
La.prototype.update=function(){this.options[this.h.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 Ma(a,b){this.parent=a;this.options=b;this.g=[];this.h=this.parent.appendChild(document.createElement("div"));this.h.classList.add("control-panel")}Ma.prototype.add=function(a){var b=this;a=v(a);for(var c=a.next();!c.done;c=a.next())c=c.value,this.g.push(c),c.create(function(){Na(b)},this.options,this.h);Na(this);return this};Ma.prototype.on=function(a){this.i=a;Na(this);return this};function Na(a){for(var b=v(a.g),c=b.next();!c.done;c=b.next())c.value.update();a.i&&a.i(a.options)}
K("ControlPanel",Ma);K("Slider",X);K("StaticText",Ka);K("Toggle",La);K("SourcePicker",Y);K("FPS",W);K("DropDownControl",V);}).call(this);
K("ControlPanel",Ma);K("Slider",W);K("StaticText",Ka);K("Toggle",La);K("SourcePicker",Y);K("FPS",V);K("DropDownControl",U);}).call(this);
{
"name": "@mediapipe/control_utils",
"version": "0.5.1625171504",
"version": "0.5.1625178644",
"description": "Mediapipe Simple Control Panel",

@@ -5,0 +5,0 @@ "main": "control_utils.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc