Skip to content

Commit c9f2baf

Browse files
committed
update fps meter plugin
1 parent bdf79fb commit c9f2baf

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

public/litecanvas.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,77 +1997,79 @@
19971997
})();
19981998
(() => {
19991999
function _() {
2000-
let u = 0, a = true, i = document.createElement("div"), r = [], p = () => (performance || Date).now();
2000+
let u = 0, a = true, i = document.createElement("div"), n = [], p = () => (performance || Date).now();
20012001
i.style.cssText = "position:absolute;top:0;right:0;cursor:pointer;opacity:0.8;z-index:10000", i.addEventListener("click", function(e) {
20022002
e.preventDefault(), o(++u % i.children.length);
20032003
}, false);
2004-
function l(e, n, v, t) {
2005-
let w = new P(e, n, v, i, t);
2006-
return r.push(w), w;
2004+
function l(e, r, x, t) {
2005+
let g = new T(e, r, x, i, t);
2006+
return n.push(g), g;
20072007
}
20082008
function o(e) {
2009-
for (let n = 0; n < i.children.length; n++) i.children[n].style.display = n === e ? "block" : "none";
2009+
for (let r = 0; r < i.children.length; r++) i.children[r].style.display = r === e ? "block" : "none";
20102010
u = e;
20112011
}
20122012
function f() {
20132013
u++, u >= i.children.length && (u = 0), o(u);
20142014
}
20152015
function s(e = "all") {
2016-
if (e === "all") for (let n = 0; n < r.length; n++) r[n].reset();
2017-
else r[e] && r[e].reset();
2016+
if (e === "all") for (let r = 0; r < n.length; r++) n[r].reset();
2017+
else n[e] && n[e].reset();
20182018
h = p(), y = 0;
20192019
}
2020-
function g(e = true) {
2020+
function w(e = true) {
20212021
a = !!e, i.style.display = a ? "" : "none";
20222022
}
20232023
let b = p(), h = b, y = 0, c = l("FPS", "#0ff", "#002"), d = l("MS", "#0f0", "#020"), m;
2024-
return self.performance && self.performance.memory && (m = l("MB", "#f08", "#201")), o(0), { dom: i, addPanel: l, showPanel: o, nextPanel: f, resetPanel: s, display: g, get hidden() {
2024+
return self.performance && self.performance.memory && (m = l("MB", "#f08", "#201")), o(0), { dom: i, addPanel: l, showPanel: o, nextPanel: f, resetPanel: s, display: w, get hidden() {
20252025
return !a;
20262026
}, begin: function() {
20272027
b = p();
20282028
}, end: function() {
20292029
y++;
20302030
let e = p();
20312031
if (d.update(e - b, 200), e >= h + 1e3 && (c.update(y * 1e3 / (e - h), 100), h = e, y = 0, m)) {
2032-
let n = performance.memory;
2033-
m.update(n.usedJSHeapSize / 1048576, n.jsHeapSizeLimit / 1048576);
2032+
let r = performance.memory;
2033+
m.update(r.usedJSHeapSize / 1048576, r.jsHeapSizeLimit / 1048576);
20342034
}
20352035
return e;
20362036
}, update: function() {
20372037
b = this.end();
20382038
} };
20392039
}
2040-
function P(u, a, i, r, p = {}) {
2041-
let l = Math.round, o = 1 / 0, f = 0, s = l(window.devicePixelRatio || 1), g = (p.width || 80) * s, b = 48 * s, h = 3 * s, y = 2 * s, c = 3 * s, d = 15 * s, m = (g - 6) * s, e = 30 * s, n = document.createElement("canvas");
2042-
n.width = g, n.height = b;
2043-
let v = r.children.length;
2044-
r.appendChild(n);
2045-
let t = n.getContext("2d");
2040+
function T(u, a, i, n, p = {}) {
2041+
let l = Math.round, o = 1 / 0, f = 0, s = l(window.devicePixelRatio || 1), w = (p.width || 80) * s, b = 48 * s, h = 3 * s, y = 2 * s, c = 3 * s, d = 15 * s, m = (w - 6) * s, e = 30 * s, r = document.createElement("canvas");
2042+
r.width = w, r.height = b;
2043+
let x = n.children.length;
2044+
n.appendChild(r);
2045+
let t = r.getContext("2d");
20462046
t.font = "bold " + 9 * s + "px Helvetica,Arial,sans-serif", t.textBaseline = "top";
2047-
function w() {
2048-
t.fillStyle = i, t.fillRect(0, 0, g, b), t.fillStyle = a, t.fillText(u, h, y), t.fillRect(c, d, m, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c, d, m, e);
2047+
function g() {
2048+
t.fillStyle = i, t.fillRect(0, 0, w, b), t.fillStyle = a, t.fillText(u, h, y), t.fillRect(c, d, m, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c, d, m, e);
20492049
}
2050-
return w(), { id: v, dom: n, reset: w, update: function(x, E) {
2051-
o = Math.min(o, x), f = Math.max(f, x), t.fillStyle = i, t.globalAlpha = 1, t.fillRect(0, 0, g, d), t.fillStyle = a;
2052-
let T = [l(x), u];
2053-
p.labelBefore && T.reverse(), t.fillText(T.join(" ") + " (" + l(o) + "-" + l(f) + ")", h, y), t.drawImage(n, c + s, d, m - s, e, c, d, m - s, e), t.fillRect(c + m - s, d, s, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c + m - s, d, s, l((1 - x / E) * e));
2050+
return g(), { id: x, dom: r, reset: g, update: function(v, P) {
2051+
o = Math.min(o, v), f = Math.max(f, v), t.fillStyle = i, t.globalAlpha = 1, t.fillRect(0, 0, w, d), t.fillStyle = a;
2052+
let E = [l(v), u];
2053+
p.labelBefore && E.reverse(), t.fillText(E.join(" ") + " (" + l(o) + "-" + l(f) + ")", h, y), t.drawImage(r, c + s, d, m - s, e, c, d, m - s, e), t.fillRect(c + m - s, d, s, e), t.fillStyle = i, t.globalAlpha = 0.9, t.fillRect(c + m - s, d, s, l((1 - v / P) * e));
20542054
} };
20552055
}
20562056
var k = { hotkeyShow: "F1", hotkeyNext: "F2", css: {}, hidden: false, id: "" };
20572057
function A(u, a = {}) {
20582058
a = Object.assign({}, k, a);
2059-
let i = u.stat(0), r = new _(), p = r.display, l = (o = true) => {
2060-
a.hidden = !o, p(o), r.resetPanel();
2059+
let i = u.stat(0), n = new _(), p = n.display, l = (o = true) => {
2060+
a.hidden = !o, p(o), n.resetPanel();
20612061
};
2062-
a.id && (r.dom.id = a.id);
2063-
for (let [o, f] of Object.entries(a.css || {})) r.dom.style[o] = f;
2064-
return u.canvas().parentElement.appendChild(r.dom), l(!a.hidden), i.keyboardEvents && listen("update", () => {
2065-
a.hotkeyShow && u.iskeypressed(a.hotkeyShow) && l(a.hidden), a.hotkeyNext && u.iskeypressed(a.hotkeyNext) && r.nextPanel();
2062+
a.id && (n.dom.id = a.id);
2063+
for (let [o, f] of Object.entries(a.css || {})) n.dom.style[o] = f;
2064+
return u.canvas().parentElement.appendChild(n.dom), l(!a.hidden), i.keyboardEvents && listen("update", () => {
2065+
a.hotkeyShow && u.iskeypressed(a.hotkeyShow) && l(a.hidden), a.hotkeyNext && u.iskeypressed(a.hotkeyNext) && n.nextPanel();
20662066
}), listen("before:update", (o, f = 1) => {
2067-
a.hidden || f === 1 && r.begin();
2067+
a.hidden || f === 1 && n.begin();
20682068
}), listen("after:draw", () => {
2069-
a.hidden || r.end();
2070-
}), r.display = l, { FPS_METER: r };
2069+
a.hidden || n.end();
2070+
}), listen("quit", () => {
2071+
n.dom.remove();
2072+
}), n.display = l, { FPS_METER: n };
20712073
}
20722074
window.pluginFrameRateMeter = A;
20732075
})();

public/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "2025.06.23.0";
2+
const version = "2025.06.25.0";
33

44
const precacheResources = [
55
"/",

0 commit comments

Comments
 (0)