UNPKG

awv3

Version:
1 lines 2.51 kB
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}exports.__esModule=!0;var _classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),Stats=function(){function e(){var t=this;(0,_classCallCheck3["default"])(this,e),this.mode=0,this.beginTime=(performance||Date).now(),this.prevTime=this.beginTime,this.frames=0,this.dom=document.createElement("div"),this.dom.style.cssText="position:absolute;top:10px;left:10px;cursor:pointer;opacity:0.9;z-index:10000;transform: translate3d(0,0,0);",this.callback=function(e){e.preventDefault(),l(++t.mode%t.dom.children.length)},this.dom.addEventListener("click",this.callback,!1);var i=function(e){return t.dom.appendChild(e.dom),e},l=function(e){for(var i=0;i<t.dom.children.length;i++)t.dom.children[i].style.display=i===e?"block":"none";t.mode=e};this.fpsPanel=i(new e.Panel("FPS","#28b4d7","#002")),this.msPanel=i(new e.Panel("MS","#28d79f","#020")),self.performance&&self.performance.memory&&(this.memPanel=i(new e.Panel("MB","#c23369","#201"))),l(0)}return e.prototype.begin=function(){this.beginTime=(performance||Date).now()},e.prototype.end=function(){this.frames++;var e=(performance||Date).now();if(this.msPanel.update(e-this.beginTime,200),e>this.prevTime+1e3&&(this.fpsPanel.update(1e3*this.frames/(e-this.prevTime),100),this.prevTime=e,this.frames=0,this.memPanel)){var t=performance.memory;this.memPanel.update(t.usedJSHeapSize/1048576,t.jsHeapSizeLimit/1048576)}return e},e.prototype.update=function(){this.beginTime=this.end()},e.prototype.remove=function(){this.dom.removeEventListener("click",this.callback),this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom)},e.Panel=function(e,t,i){var l=1/0,n=0,a=Math.round,s=a(window.devicePixelRatio||1),o=80*s,r=48*s,c=3*s,m=2*s,h=3*s,d=15*s,f=74*s,p=30*s,u=document.createElement("canvas");u.width=o,u.height=r,u.style.cssText="width:80px;height:48px";var v=u.getContext("2d");return v.font=10*s+"px monospace",v.textBaseline="top",v.fillStyle=i,v.fillRect(0,0,o,r),v.fillStyle=t,v.fillText(e,c,m),v.fillRect(h,d,f,p),v.fillStyle=i,v.globalAlpha=.9,v.fillRect(h,d,f,p),{dom:u,update:function(r,b){l=Math.min(l,r),n=Math.max(n,r),v.fillStyle=i,v.globalAlpha=1,v.fillRect(0,0,o,d),v.fillStyle=t,v.fillText(a(r)+" "+e+" ("+a(l)+"-"+a(n)+")",c,m),v.drawImage(u,h+s,d,f-s,p,h,d,f-s,p),v.fillRect(h+f-s,d,s,p),v.fillStyle=i,v.globalAlpha=.9,v.fillRect(h+f-s,d,s,a((1-r/b)*p))}}},e}();exports["default"]=Stats;