stats-gl 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # stats-gl
2
+
3
+ stats-gl is a simple, yet powerful JavaScript library designed to help you monitor and visualize your web application's performance in real-time. The library provides panels that display Frames per Second (FPS), Central Processing Unit (CPU) usage, and if supported, Graphics Processing Unit (GPU) usage.
4
+
5
+ Note: GPU Monitoring will be available on Safari after the v17 release.
6
+
7
+ ## Table of Contents
8
+ - [Description](#description)
9
+ - [Installation](#installation)
10
+ - [Example Usage](#example-usage)
11
+ - [Parameters](#parameters)
12
+ - [Contributing](#contributing)
13
+ - [License](#license)
14
+
15
+ ## Description
16
+
17
+ The Stats class exposes methods to create performance panels, log performance metrics, and manage the display and layout of these panels. The performance metrics are logged for FPS CPU and GPU. The GPU logging is only available if the user's browser supports the WebGL 2.0 `EXT_disjoint_timer_query_webgl2` extension.
18
+
19
+ In addition to logging real-time performance data, the class also provides methods to calculate and display average performance metrics over a specified interval.
20
+
21
+ ## Installation
22
+
23
+ Stats.js is available as an npm package. You can install it using the following command:
24
+
25
+ ```bash
26
+ npm install stats-gl
27
+ ```
28
+
29
+ ## Example Usage
30
+
31
+ Below is an example of how you can use this class in your code:
32
+ ```js
33
+ import Stats from "stats-gl";
34
+
35
+ // create a new Stats object
36
+ const stats = new Stats({
37
+ logsPerSecond: 20,
38
+ samplesLog: 100,
39
+ samplesGraph: 10,
40
+ precision: 2,
41
+ minimal: false,
42
+ mode: 0
43
+ });
44
+
45
+ // append the stats container to the body of the document
46
+ document.body.appendChild( stats.container );
47
+
48
+ // begin the performance monitor
49
+ stats.begin();
50
+
51
+ // end the performance monitor
52
+ stats.end();
53
+ ```
54
+
55
+ ## Parameters
56
+ The constructor for the Stats class accepts an options object with the following properties:
57
+
58
+ - logsPerSecond: How often to log performance data, in logs per second.
59
+ - samplesLog: Number of recent log samples to keep for computing averages.
60
+ - samplesGraph: Number of recent graph samples to keep for computing averages.
61
+ - precision: Precision of the data, in number of decimal places.
62
+ - minimal: A boolean value to control the minimalistic mode of the panel display. If set to true, a simple click on the panel will switch between different metrics.
63
+ - mode: Sets the initial panel to display - 0 for FPS, 1 for CPU, and 2 for GPU (if supported).
64
+
65
+ All the parameters are optional and have default values. The class also provides other methods such as begin(), end(), init(canvas), etc. which can be used based on the requirement.
66
+
67
+ Note: The init(canvas) method is used to start the GPU monitoring and must be called with a canvas context before begin().
68
+
69
+ ## Contributing
70
+ We welcome contributions to Stats.js. Before contributing, please read our contributing guidelines and code of conduct.
71
+
72
+ Please report any issues or bugs you encounter.
73
+
74
+ ## License
75
+ This project is licensed under the MIT License.
@@ -0,0 +1,81 @@
1
+ declare class Panel {
2
+ canvas: HTMLCanvasElement;
3
+ context: CanvasRenderingContext2D | null;
4
+ name: string;
5
+ fg: string;
6
+ bg: string;
7
+ PR: number;
8
+ WIDTH: number;
9
+ HEIGHT: number;
10
+ TEXT_X: number;
11
+ TEXT_Y: number;
12
+ GRAPH_X: number;
13
+ GRAPH_Y: number;
14
+ GRAPH_WIDTH: number;
15
+ GRAPH_HEIGHT: number;
16
+ constructor(name: string, fg: string, bg: string);
17
+ update(value: number, valueGraph: number, maxValue: number, maxGraph: number, decimals?: number): void;
18
+ }
19
+
20
+ interface AverageArray {
21
+ logs: number[];
22
+ graph: number[];
23
+ }
24
+ declare class Stats {
25
+ mode: number;
26
+ container: HTMLDivElement;
27
+ minimal: boolean;
28
+ beginTime: number;
29
+ prevTime: number;
30
+ prevCpuTime: number;
31
+ frames: number;
32
+ averageCpu: AverageArray;
33
+ averageGpu: AverageArray;
34
+ queryCreated: boolean;
35
+ fpsPanel: Panel;
36
+ static Panel: any;
37
+ msPanel: Panel;
38
+ gpuPanel: Panel | null;
39
+ samplesLog: number;
40
+ samplesGraph: number;
41
+ logsPerSecond: number;
42
+ precision: number;
43
+ canvasGpu: HTMLCanvasElement | null;
44
+ gl: WebGL2RenderingContext | null;
45
+ ext: any;
46
+ query: WebGLQuery | null;
47
+ disjoint: any;
48
+ ns: any;
49
+ constructor({ logsPerSecond, samplesLog, samplesGraph, precision, minimal, mode }?: {
50
+ logsPerSecond?: number | undefined;
51
+ samplesLog?: number | undefined;
52
+ samplesGraph?: number | undefined;
53
+ precision?: number | undefined;
54
+ minimal?: boolean | undefined;
55
+ mode?: number | undefined;
56
+ });
57
+ resizePanel(panel: Panel, offset: number): void;
58
+ addPanel(panel: Panel, offset: number): Panel;
59
+ showPanel(id: number): void;
60
+ init(canvas: any): void;
61
+ begin(): void;
62
+ end(): void;
63
+ endInternal(): number;
64
+ addToAverage(value: number, averageArray: {
65
+ logs: any;
66
+ graph: any;
67
+ }): void;
68
+ beginProfiling(marker: string): void;
69
+ endProfiling(startMarker: string | PerformanceMeasureOptions | undefined, endMarker: string | undefined, measureName: string, averageArray: {
70
+ logs: number[];
71
+ graph: number[];
72
+ }): void;
73
+ updatePanel(panel: {
74
+ update: any;
75
+ } | null, averageArray: {
76
+ logs: number[];
77
+ graph: number[];
78
+ }): void;
79
+ }
80
+
81
+ export { AverageArray, Stats as default };
@@ -0,0 +1,135 @@
1
+ var P = Object.defineProperty;
2
+ var g = (o, t, i) => t in o ? P(o, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[t] = i;
3
+ var s = (o, t, i) => (g(o, typeof t != "symbol" ? t + "" : t, i), i);
4
+ class p {
5
+ constructor(t, i, h) {
6
+ s(this, "canvas");
7
+ s(this, "context");
8
+ s(this, "name");
9
+ s(this, "fg");
10
+ s(this, "bg");
11
+ s(this, "PR");
12
+ s(this, "WIDTH");
13
+ s(this, "HEIGHT");
14
+ s(this, "TEXT_X");
15
+ s(this, "TEXT_Y");
16
+ s(this, "GRAPH_X");
17
+ s(this, "GRAPH_Y");
18
+ s(this, "GRAPH_WIDTH");
19
+ s(this, "GRAPH_HEIGHT");
20
+ this.name = t, this.fg = i, this.bg = h, this.PR = Math.round(window.devicePixelRatio || 1), this.WIDTH = 90 * this.PR, this.HEIGHT = 48 * this.PR, this.TEXT_X = 3 * this.PR, this.TEXT_Y = 2 * this.PR, this.GRAPH_X = 3 * this.PR, this.GRAPH_Y = 15 * this.PR, this.GRAPH_WIDTH = 84 * this.PR, this.GRAPH_HEIGHT = 30 * this.PR, this.canvas = document.createElement("canvas"), this.canvas.width = 90 * this.PR, this.canvas.height = 48 * this.PR, this.canvas.style.width = "90px", this.canvas.style.height = "48px", this.canvas.style.cssText = "width:90px;height:48px", this.context = this.canvas.getContext("2d"), this.context && (this.context.font = "bold " + 9 * this.PR + "px Helvetica,Arial,sans-serif", this.context.textBaseline = "top", this.context.fillStyle = this.bg, this.context.fillRect(0, 0, this.WIDTH, this.HEIGHT), this.context.fillStyle = this.fg, this.context.fillText(this.name, this.TEXT_X, this.TEXT_Y), this.context.fillRect(this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH, this.GRAPH_HEIGHT), this.context.fillStyle = this.bg, this.context.globalAlpha = 0.9, this.context.fillRect(this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH, this.GRAPH_HEIGHT));
21
+ }
22
+ update(t, i, h, l, n = 0) {
23
+ let a = 1 / 0, e = 0;
24
+ this.context && (a = Math.min(a, t), e = Math.max(h, t), l = Math.max(l, i), this.context.fillStyle = this.bg, this.context.globalAlpha = 1, this.context.fillRect(0, 0, this.WIDTH, this.GRAPH_Y), this.context.fillStyle = this.fg, this.context.fillText(t.toFixed(n) + " " + this.name + " (" + a.toFixed(n) + "-" + parseFloat(e.toFixed(n)) + ")", this.TEXT_X, this.TEXT_Y), this.context.drawImage(this.canvas, this.GRAPH_X + this.PR, this.GRAPH_Y, this.GRAPH_WIDTH - this.PR, this.GRAPH_HEIGHT, this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH - this.PR, this.GRAPH_HEIGHT), this.context.fillRect(this.GRAPH_X + this.GRAPH_WIDTH - this.PR, this.GRAPH_Y, this.PR, this.GRAPH_HEIGHT), this.context.fillStyle = this.bg, this.context.globalAlpha = 0.9, this.context.fillRect(this.GRAPH_X + this.GRAPH_WIDTH - this.PR, this.GRAPH_Y, this.PR, parseFloat((1 - i / l).toFixed(n)) * this.GRAPH_HEIGHT));
25
+ }
26
+ }
27
+ const r = class r {
28
+ constructor({ logsPerSecond: t = 20, samplesLog: i = 100, samplesGraph: h = 10, precision: l = 2, minimal: n = !1, mode: a = 0 } = {}) {
29
+ s(this, "mode");
30
+ s(this, "container");
31
+ s(this, "minimal");
32
+ s(this, "beginTime");
33
+ s(this, "prevTime");
34
+ s(this, "prevCpuTime");
35
+ s(this, "frames");
36
+ s(this, "averageCpu");
37
+ s(this, "averageGpu");
38
+ s(this, "queryCreated");
39
+ s(this, "fpsPanel");
40
+ s(this, "msPanel");
41
+ s(this, "gpuPanel");
42
+ s(this, "samplesLog");
43
+ s(this, "samplesGraph");
44
+ s(this, "logsPerSecond");
45
+ s(this, "precision");
46
+ s(this, "canvasGpu");
47
+ s(this, "gl");
48
+ s(this, "ext");
49
+ s(this, "query");
50
+ s(this, "disjoint");
51
+ s(this, "ns");
52
+ this.mode = a, this.container = document.createElement("div"), this.container.style.cssText = "position:fixed;top:0;left:0;opacity:0.9;z-index:10000;", n && (this.container.style.cssText += "cursor:pointer"), this.canvasGpu = null, this.gl = null, this.query = null, this.minimal = n, this.beginTime = (performance || Date).now(), this.prevTime = this.beginTime, this.prevCpuTime = this.beginTime, this.frames = 0, this.averageCpu = {
53
+ logs: [],
54
+ graph: []
55
+ }, this.averageGpu = {
56
+ logs: [],
57
+ graph: []
58
+ }, this.queryCreated = !1, this.fpsPanel = this.addPanel(new r.Panel("FPS", "#0ff", "#002"), 0), this.msPanel = this.addPanel(new r.Panel("CPU", "#0f0", "#020"), 1), this.gpuPanel = null, this.samplesLog = i, this.samplesGraph = h, this.precision = l, this.logsPerSecond = t, this.minimal ? (this.container.addEventListener("click", (e) => {
59
+ e.preventDefault(), this.showPanel(++this.mode % this.container.children.length);
60
+ }, !1), this.mode = a, this.showPanel(this.mode)) : window.addEventListener("resize", () => {
61
+ this.resizePanel(this.fpsPanel, 0), this.resizePanel(this.msPanel, 1), this.gpuPanel && this.resizePanel(this.gpuPanel, 2);
62
+ });
63
+ }
64
+ resizePanel(t, i) {
65
+ this.minimal ? t.canvas.style.display = "none" : (t.canvas.style.display = "block", window.innerWidth < 700 ? (t.canvas.style.left = "0px", t.canvas.style.top = i * t.HEIGHT / t.PR + "px") : (t.canvas.style.top = "0px", t.canvas.style.left = i * t.WIDTH / t.PR + "px"));
66
+ }
67
+ addPanel(t, i) {
68
+ return t.canvas && (this.container.appendChild(t.canvas), this.resizePanel(t, i)), t;
69
+ }
70
+ showPanel(t) {
71
+ for (let i = 0; i < this.container.children.length; i++) {
72
+ const h = this.container.children[i];
73
+ h.style.display = i === t ? "block" : "none";
74
+ }
75
+ this.mode = t;
76
+ }
77
+ init(t) {
78
+ this.canvasGpu = t, this.canvasGpu && (this.gl = this.canvasGpu.getContext("webgl2"), this.ext = this.gl ? this.gl.getExtension("EXT_disjoint_timer_query_webgl2") : null, this.ext && (this.gpuPanel = this.addPanel(new r.Panel("GPU", "#ff0", "#220"), 2)));
79
+ }
80
+ begin() {
81
+ if (this.beginProfiling("cpu-started"), !(!this.gl || !this.ext)) {
82
+ if (this.query) {
83
+ const t = this.gl.getQueryParameter(this.query, this.gl.QUERY_RESULT_AVAILABLE);
84
+ if (this.disjoint = this.gl.getParameter(this.ext.GPU_DISJOINT_EXT), t && !this.disjoint) {
85
+ this.ns = this.gl.getQueryParameter(this.query, this.gl.QUERY_RESULT);
86
+ const i = this.ns * 1e-6;
87
+ (t || this.disjoint) && (this.gl.deleteQuery(this.query), this.query = null), t && this.addToAverage(i, this.averageGpu);
88
+ }
89
+ }
90
+ this.query || (this.queryCreated = !0, this.query = this.gl.createQuery(), this.query && this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT, this.query));
91
+ }
92
+ }
93
+ end() {
94
+ this.beginTime = this.endInternal(), this.endProfiling("cpu-started", "cpu-finished", "cpu-duration", this.averageCpu), !(!this.gl || !this.ext) && this.queryCreated && this.gl.getQuery(this.ext.TIME_ELAPSED_EXT, this.gl.CURRENT_QUERY) && this.gl.endQuery(this.ext.TIME_ELAPSED_EXT);
95
+ }
96
+ endInternal() {
97
+ this.frames++;
98
+ const t = (performance || Date).now();
99
+ if (t >= this.prevCpuTime + 1e3 / this.logsPerSecond && (this.updatePanel(this.msPanel, this.averageCpu), this.updatePanel(this.gpuPanel, this.averageGpu), this.prevCpuTime = t), t >= this.prevTime + 1e3) {
100
+ const i = this.frames * 1e3 / (t - this.prevTime);
101
+ this.fpsPanel.update(i, i, 100, 100, 0), this.prevTime = t, this.frames = 0;
102
+ }
103
+ return t;
104
+ }
105
+ addToAverage(t, i) {
106
+ i.logs.push(t), i.logs.length > this.samplesLog && i.logs.shift(), i.graph.push(t), i.graph.length > this.samplesGraph && i.graph.shift();
107
+ }
108
+ beginProfiling(t) {
109
+ window.performance && window.performance.mark(t);
110
+ }
111
+ endProfiling(t, i, h, l) {
112
+ if (window.performance && i) {
113
+ window.performance.mark(i);
114
+ const n = performance.measure(h, t, i);
115
+ this.addToAverage(n.duration, l);
116
+ }
117
+ }
118
+ updatePanel(t, i) {
119
+ if (i.logs.length > 0) {
120
+ let h = 0, l = 0.01;
121
+ for (let e = 0; e < i.logs.length; e++)
122
+ h += i.logs[e], i.logs[e] > l && (l = i.logs[e]);
123
+ let n = 0, a = 0.01;
124
+ for (let e = 0; e < i.graph.length; e++)
125
+ n += i.graph[e], i.graph[e] > a && (a = i.graph[e]);
126
+ t && t.update(h / Math.min(i.logs.length, this.samplesLog), n / Math.min(i.graph.length, this.samplesGraph), l, a, this.precision);
127
+ }
128
+ }
129
+ };
130
+ s(r, "Panel");
131
+ let c = r;
132
+ c.Panel = p;
133
+ export {
134
+ c as default
135
+ };
@@ -0,0 +1 @@
1
+ (function(o,e){typeof exports=="object"&&typeof module<"u"?module.exports=e():typeof define=="function"&&define.amd?define(e):(o=typeof globalThis<"u"?globalThis:o||self,o["Stats-Gl"]=e())})(this,function(){"use strict";var P=Object.defineProperty;var p=(o,e,n)=>e in o?P(o,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[e]=n;var s=(o,e,n)=>(p(o,typeof e!="symbol"?e+"":e,n),n);class o{constructor(t,i,l){s(this,"canvas");s(this,"context");s(this,"name");s(this,"fg");s(this,"bg");s(this,"PR");s(this,"WIDTH");s(this,"HEIGHT");s(this,"TEXT_X");s(this,"TEXT_Y");s(this,"GRAPH_X");s(this,"GRAPH_Y");s(this,"GRAPH_WIDTH");s(this,"GRAPH_HEIGHT");this.name=t,this.fg=i,this.bg=l,this.PR=Math.round(window.devicePixelRatio||1),this.WIDTH=90*this.PR,this.HEIGHT=48*this.PR,this.TEXT_X=3*this.PR,this.TEXT_Y=2*this.PR,this.GRAPH_X=3*this.PR,this.GRAPH_Y=15*this.PR,this.GRAPH_WIDTH=84*this.PR,this.GRAPH_HEIGHT=30*this.PR,this.canvas=document.createElement("canvas"),this.canvas.width=90*this.PR,this.canvas.height=48*this.PR,this.canvas.style.width="90px",this.canvas.style.height="48px",this.canvas.style.cssText="width:90px;height:48px",this.context=this.canvas.getContext("2d"),this.context&&(this.context.font="bold "+9*this.PR+"px Helvetica,Arial,sans-serif",this.context.textBaseline="top",this.context.fillStyle=this.bg,this.context.fillRect(0,0,this.WIDTH,this.HEIGHT),this.context.fillStyle=this.fg,this.context.fillText(this.name,this.TEXT_X,this.TEXT_Y),this.context.fillRect(this.GRAPH_X,this.GRAPH_Y,this.GRAPH_WIDTH,this.GRAPH_HEIGHT),this.context.fillStyle=this.bg,this.context.globalAlpha=.9,this.context.fillRect(this.GRAPH_X,this.GRAPH_Y,this.GRAPH_WIDTH,this.GRAPH_HEIGHT))}update(t,i,l,r,a=0){let c=1/0,h=0;this.context&&(c=Math.min(c,t),h=Math.max(l,t),r=Math.max(r,i),this.context.fillStyle=this.bg,this.context.globalAlpha=1,this.context.fillRect(0,0,this.WIDTH,this.GRAPH_Y),this.context.fillStyle=this.fg,this.context.fillText(t.toFixed(a)+" "+this.name+" ("+c.toFixed(a)+"-"+parseFloat(h.toFixed(a))+")",this.TEXT_X,this.TEXT_Y),this.context.drawImage(this.canvas,this.GRAPH_X+this.PR,this.GRAPH_Y,this.GRAPH_WIDTH-this.PR,this.GRAPH_HEIGHT,this.GRAPH_X,this.GRAPH_Y,this.GRAPH_WIDTH-this.PR,this.GRAPH_HEIGHT),this.context.fillRect(this.GRAPH_X+this.GRAPH_WIDTH-this.PR,this.GRAPH_Y,this.PR,this.GRAPH_HEIGHT),this.context.fillStyle=this.bg,this.context.globalAlpha=.9,this.context.fillRect(this.GRAPH_X+this.GRAPH_WIDTH-this.PR,this.GRAPH_Y,this.PR,parseFloat((1-i/r).toFixed(a))*this.GRAPH_HEIGHT))}}const n=class n{constructor({logsPerSecond:t=20,samplesLog:i=100,samplesGraph:l=10,precision:r=2,minimal:a=!1,mode:c=0}={}){s(this,"mode");s(this,"container");s(this,"minimal");s(this,"beginTime");s(this,"prevTime");s(this,"prevCpuTime");s(this,"frames");s(this,"averageCpu");s(this,"averageGpu");s(this,"queryCreated");s(this,"fpsPanel");s(this,"msPanel");s(this,"gpuPanel");s(this,"samplesLog");s(this,"samplesGraph");s(this,"logsPerSecond");s(this,"precision");s(this,"canvasGpu");s(this,"gl");s(this,"ext");s(this,"query");s(this,"disjoint");s(this,"ns");this.mode=c,this.container=document.createElement("div"),this.container.style.cssText="position:fixed;top:0;left:0;opacity:0.9;z-index:10000;",a&&(this.container.style.cssText+="cursor:pointer"),this.canvasGpu=null,this.gl=null,this.query=null,this.minimal=a,this.beginTime=(performance||Date).now(),this.prevTime=this.beginTime,this.prevCpuTime=this.beginTime,this.frames=0,this.averageCpu={logs:[],graph:[]},this.averageGpu={logs:[],graph:[]},this.queryCreated=!1,this.fpsPanel=this.addPanel(new n.Panel("FPS","#0ff","#002"),0),this.msPanel=this.addPanel(new n.Panel("CPU","#0f0","#020"),1),this.gpuPanel=null,this.samplesLog=i,this.samplesGraph=l,this.precision=r,this.logsPerSecond=t,this.minimal?(this.container.addEventListener("click",h=>{h.preventDefault(),this.showPanel(++this.mode%this.container.children.length)},!1),this.mode=c,this.showPanel(this.mode)):window.addEventListener("resize",()=>{this.resizePanel(this.fpsPanel,0),this.resizePanel(this.msPanel,1),this.gpuPanel&&this.resizePanel(this.gpuPanel,2)})}resizePanel(t,i){this.minimal?t.canvas.style.display="none":(t.canvas.style.display="block",window.innerWidth<700?(t.canvas.style.left="0px",t.canvas.style.top=i*t.HEIGHT/t.PR+"px"):(t.canvas.style.top="0px",t.canvas.style.left=i*t.WIDTH/t.PR+"px"))}addPanel(t,i){return t.canvas&&(this.container.appendChild(t.canvas),this.resizePanel(t,i)),t}showPanel(t){for(let i=0;i<this.container.children.length;i++){const l=this.container.children[i];l.style.display=i===t?"block":"none"}this.mode=t}init(t){this.canvasGpu=t,this.canvasGpu&&(this.gl=this.canvasGpu.getContext("webgl2"),this.ext=this.gl?this.gl.getExtension("EXT_disjoint_timer_query_webgl2"):null,this.ext&&(this.gpuPanel=this.addPanel(new n.Panel("GPU","#ff0","#220"),2)))}begin(){if(this.beginProfiling("cpu-started"),!(!this.gl||!this.ext)){if(this.query){const t=this.gl.getQueryParameter(this.query,this.gl.QUERY_RESULT_AVAILABLE);if(this.disjoint=this.gl.getParameter(this.ext.GPU_DISJOINT_EXT),t&&!this.disjoint){this.ns=this.gl.getQueryParameter(this.query,this.gl.QUERY_RESULT);const i=this.ns*1e-6;(t||this.disjoint)&&(this.gl.deleteQuery(this.query),this.query=null),t&&this.addToAverage(i,this.averageGpu)}}this.query||(this.queryCreated=!0,this.query=this.gl.createQuery(),this.query&&this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,this.query))}}end(){this.beginTime=this.endInternal(),this.endProfiling("cpu-started","cpu-finished","cpu-duration",this.averageCpu),!(!this.gl||!this.ext)&&this.queryCreated&&this.gl.getQuery(this.ext.TIME_ELAPSED_EXT,this.gl.CURRENT_QUERY)&&this.gl.endQuery(this.ext.TIME_ELAPSED_EXT)}endInternal(){this.frames++;const t=(performance||Date).now();if(t>=this.prevCpuTime+1e3/this.logsPerSecond&&(this.updatePanel(this.msPanel,this.averageCpu),this.updatePanel(this.gpuPanel,this.averageGpu),this.prevCpuTime=t),t>=this.prevTime+1e3){const i=this.frames*1e3/(t-this.prevTime);this.fpsPanel.update(i,i,100,100,0),this.prevTime=t,this.frames=0}return t}addToAverage(t,i){i.logs.push(t),i.logs.length>this.samplesLog&&i.logs.shift(),i.graph.push(t),i.graph.length>this.samplesGraph&&i.graph.shift()}beginProfiling(t){window.performance&&window.performance.mark(t)}endProfiling(t,i,l,r){if(window.performance&&i){window.performance.mark(i);const a=performance.measure(l,t,i);this.addToAverage(a.duration,r)}}updatePanel(t,i){if(i.logs.length>0){let l=0,r=.01;for(let h=0;h<i.logs.length;h++)l+=i.logs[h],i.logs[h]>r&&(r=i.logs[h]);let a=0,c=.01;for(let h=0;h<i.graph.length;h++)a+=i.graph[h],i.graph[h]>c&&(c=i.graph[h]);t&&t.update(l/Math.min(i.logs.length,this.samplesLog),a/Math.min(i.graph.length,this.samplesGraph),r,c,this.precision)}}};s(n,"Panel");let e=n;return e.Panel=o,e});
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "stats-gl",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/stats-gl.umd.cjs",
9
+ "module": "./dist/stats-gl.js",
10
+ "types": "./dist/stats-gl.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/stats-gl.js",
14
+ "require": "./dist/stats-gl.umd.cjs"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "dev": "vite demo",
19
+ "serve": "vite serve demo",
20
+ "build": "tsc && vite build && rollup -c && node ./scripts/copyBuild.js",
21
+ "preview": "vite preview"
22
+ },
23
+ "devDependencies": {
24
+ "fs-extra": "^11.1.1",
25
+ "path": "^0.12.7",
26
+ "rollup": "^3.26.3",
27
+ "rollup-plugin-dts": "^5.3.0",
28
+ "three": "^0.154.0",
29
+ "typescript": "^5.0.2",
30
+ "vite": "^4.4.0"
31
+ }
32
+ }