1 line
1.7 KiB
JavaScript
1 line
1.7 KiB
JavaScript
var Stats=function(){var l=0,n=document.createElement("div");function e(e){return n.appendChild(e.dom),e}function t(e){for(var t=0;t<n.children.length;t++)n.children[t].style.display=t===e?"block":"none";l=e}n.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:90000",n.addEventListener("click",function(e){e.preventDefault(),t(++l%n.children.length)},!1);var a,i=(performance||Date).now(),o=i,r=0,f=e(new Stats.Panel("FPS","#0ff","#002")),c=e(new Stats.Panel("MS","#0f0","#020"));return self.performance&&self.performance.memory&&(a=e(new Stats.Panel("MB","#f08","#201"))),t(0),{REVISION:16,dom:n,addPanel:e,showPanel:t,begin:function(){i=(performance||Date).now()},end:function(){r++;var e,t=(performance||Date).now();return c.update(t-i,200),o+1e3<=t&&(f.update(1e3*r/(t-o),100),o=t,r=0,a&&(e=performance.memory,a.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576))),t},update:function(){i=this.end()},domElement:n,setMode:t}};Stats.Panel=function(l,n,a){var i=1/0,o=0,r=Math.round,f=r(window.devicePixelRatio||1),c=80*f,e=48*f,d=3*f,s=2*f,p=3*f,u=15*f,m=74*f,h=30*f,S=document.createElement("canvas"),x=(S.width=c,S.height=e,S.style.cssText="width:80px;height:48px",S.getContext("2d"));return x.font="bold "+9*f+"px Helvetica,Arial,sans-serif",x.textBaseline="top",x.fillStyle=a,x.fillRect(0,0,c,e),x.fillStyle=n,x.fillText(l,d,s),x.fillRect(p,u,m,h),x.fillStyle=a,x.globalAlpha=.9,x.fillRect(p,u,m,h),{dom:S,update:function(e,t){i=Math.min(i,e),o=Math.max(o,e),x.fillStyle=a,x.globalAlpha=1,x.fillRect(0,0,c,u),x.fillStyle=n,x.fillText(r(e)+" "+l+" ("+r(i)+"-"+r(o)+")",d,s),x.drawImage(S,p+f,u,m-f,h,p,u,m-f,h),x.fillRect(p+m-f,u,f,h),x.fillStyle=a,x.globalAlpha=.9,x.fillRect(p+m-f,u,f,r((1-e/t)*h))}}};export{Stats as default}; |