@expofp/floorplan
Version:
Interactive floor plan library for expos and events
290 lines (289 loc) • 16.5 kB
JavaScript
//#region ../../node_modules/.pnpm/stats-gl@3.8.0_three@0.184.0/node_modules/stats-gl/dist/panel.js
(function() {
try {
var e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {};
e.SENTRY_RELEASE = { id: "3.7.8" };
var t = new e.Error().stack;
t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "533bf5ba-d354-4779-8c53-27d3e917165a", e._sentryDebugIdIdentifier = "sentry-dbid-533bf5ba-d354-4779-8c53-27d3e917165a");
} catch {}
})();
var e = class {
constructor(e, t, n) {
this.id = 0, this.name = e, this.fg = t, this.bg = n, this.gradient = null, 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 = this.WIDTH, this.canvas.height = this.HEIGHT, this.canvas.style.width = "90px", this.canvas.style.height = "48px", this.canvas.style.position = "absolute", this.canvas.style.cssText = "width:90px;height:48px;background-color: transparent !important;", this.context = this.canvas.getContext("2d"), this.initializeCanvas();
}
createGradient() {
if (!this.context) throw Error("No context");
let e = this.context.createLinearGradient(0, this.GRAPH_Y, 0, this.GRAPH_Y + this.GRAPH_HEIGHT), t, n = this.fg;
switch (this.fg.toLowerCase()) {
case "#0ff":
t = "#006666";
break;
case "#0f0":
t = "#006600";
break;
case "#ff0":
t = "#666600";
break;
case "#e1e1e1":
t = "#666666";
break;
default:
t = this.bg;
break;
}
return e.addColorStop(0, t), e.addColorStop(1, n), e;
}
initializeCanvas() {
this.context && (this.context.imageSmoothingEnabled = !1, this.context.font = "bold " + 9 * this.PR + "px Helvetica,Arial,sans-serif", this.context.textBaseline = "top", this.gradient = this.createGradient(), 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.fillStyle = this.bg, this.context.globalAlpha = .9, this.context.fillRect(this.GRAPH_X, this.GRAPH_Y, this.GRAPH_WIDTH, this.GRAPH_HEIGHT));
}
update(e, t, n = 0) {
if (!this.context || !this.gradient) return;
let r = Math.min(Infinity, e), i = Math.max(t, e);
this.context.globalAlpha = 1, this.context.fillStyle = this.bg, this.context.fillRect(0, 0, this.WIDTH, this.GRAPH_Y), this.context.fillStyle = this.fg, this.context.fillText(`${e.toFixed(n)} ${this.name} (${r.toFixed(n)}-${parseFloat(i.toFixed(n))})`, this.TEXT_X, this.TEXT_Y);
}
updateGraph(e, t) {
if (!this.context || !this.gradient) return;
e === 0 && t === 0 && (t = 1), t = Math.max(t, e, .1), e = Math.max(e, 0);
let n = Math.round(this.GRAPH_X), r = Math.round(this.GRAPH_Y), i = Math.round(this.GRAPH_WIDTH), a = Math.round(this.GRAPH_HEIGHT), o = Math.round(this.PR);
this.context.drawImage(this.canvas, n + o, r, i - o, a, n, r, i - o, a), this.context.fillStyle = this.bg, this.context.fillRect(n + i - o, r, o, a);
let s = Math.min(a, Math.round(e / t * a));
s > 0 && (this.context.globalAlpha = .9, this.context.fillStyle = this.gradient, this.context.fillRect(n + i - o, r + (a - s), o, s)), this.context.globalAlpha = 1;
}
}, t = class extends e {
constructor(e, t, n) {
super(e, t, n), this.vsyncValue = 0, this.SMALL_HEIGHT = 9 * this.PR, this.HEIGHT = this.SMALL_HEIGHT, this.WIDTH = 35 * this.PR, this.TEXT_Y = 0 * this.PR, this.canvas.height = this.HEIGHT, this.canvas.width = this.WIDTH, this.canvas.style.height = "9px", this.canvas.style.width = "35px", this.canvas.style.cssText = "\n width: 35px;\n height: 9px;\n position: absolute;\n top: 0;\n left: 0;\n background-color: transparent !important;\n pointer-events: none;\n ", this.initializeCanvas();
}
initializeCanvas() {
this.context && (this.context.imageSmoothingEnabled = !1, this.context.font = "bold " + 9 * this.PR + "px Helvetica,Arial,sans-serif", this.context.textBaseline = "top", this.context.globalAlpha = 1);
}
update(e, t, n = 0) {
this.context && (this.vsyncValue = e, this.context.clearRect(0, 0, this.WIDTH, this.HEIGHT), this.context.globalAlpha = 1, this.context.fillStyle = this.bg, this.context.fillText(`${e.toFixed(0)}Hz`, this.TEXT_X, this.TEXT_Y));
}
updateGraph(e, t) {}
setOffset(e, t) {
this.canvas.style.transform = `translate(${e}px, ${t}px)`;
}
}, n = class e {
constructor({ trackGPU: n = !1, trackCPT: r = !1, trackHz: i = !1, trackFPS: a = !0, logsPerSecond: o = 4, graphsPerSecond: s = 30, samplesLog: c = 40, samplesGraph: l = 10, precision: u = 2, minimal: d = !1, horizontal: f = !0, mode: p = 0 } = {}) {
this.gl = null, this.ext = null, this.activeQuery = null, this.gpuQueries = [], this.threeRendererPatched = !1, this.frameTimes = [], this.renderCount = 0, this.totalCpuDuration = 0, this.totalGpuDuration = 0, this.totalGpuDurationCompute = 0, this.fpsPanel = null, this.msPanel = null, this.gpuPanel = null, this.gpuPanelCompute = null, this.vsyncPanel = null, this.averageFps = {
logs: [],
graph: []
}, this.averageCpu = {
logs: [],
graph: []
}, this.averageGpu = {
logs: [],
graph: []
}, this.averageGpuCompute = {
logs: [],
graph: []
}, this.updateCounter = 0, this.lastMin = {}, this.lastMax = {}, this.lastValue = {}, this.VSYNC_RATES = [
{
refreshRate: 60,
frameTime: 16.67
},
{
refreshRate: 75,
frameTime: 13.33
},
{
refreshRate: 90,
frameTime: 11.11
},
{
refreshRate: 120,
frameTime: 8.33
},
{
refreshRate: 144,
frameTime: 6.94
},
{
refreshRate: 165,
frameTime: 6.06
},
{
refreshRate: 240,
frameTime: 4.17
}
], this.detectedVSync = null, this.frameTimeHistory = [], this.HISTORY_SIZE = 120, this.VSYNC_THRESHOLD = .05, this.lastFrameTime = 0, this.handleClick = (e) => {
e.preventDefault(), this.showPanel(++this.mode % this.dom.children.length);
}, this.handleResize = () => {
this.fpsPanel && this.resizePanel(this.fpsPanel), this.msPanel && this.resizePanel(this.msPanel), this.gpuPanel && this.resizePanel(this.gpuPanel), this.gpuPanelCompute && this.resizePanel(this.gpuPanelCompute);
}, this.mode = p, this.horizontal = f, this.minimal = d, this.trackGPU = n, this.trackCPT = r, this.trackHz = i, this.trackFPS = a, this.samplesLog = c, this.samplesGraph = l, this.precision = u, this.logsPerSecond = o, this.graphsPerSecond = s;
let m = performance.now();
this.prevGraphTime = m, this.dom = document.createElement("div"), this.initializeDOM(), this.beginTime = performance.now(), this.prevTextTime = this.beginTime, this.prevCpuTime = this.beginTime, this._panelId = 0, this.trackFPS && (this.fpsPanel = this.addPanel(new e.Panel("FPS", "#0ff", "#002")), this.msPanel = this.addPanel(new e.Panel("CPU", "#0f0", "#020"))), this.trackHz === !0 && (this.vsyncPanel = new t("", "#f0f", "#202"), this.dom.appendChild(this.vsyncPanel.canvas), this.vsyncPanel.setOffset(56, 35)), this.setupEventListeners();
}
initializeDOM() {
this.dom.style.cssText = `
position: fixed;
top: 0;
left: 0;
opacity: 0.9;
z-index: 10000;
${this.minimal ? "cursor: pointer;" : ""}
`;
}
setupEventListeners() {
this.minimal ? (this.dom.addEventListener("click", this.handleClick), this.showPanel(this.mode)) : window.addEventListener("resize", this.handleResize);
}
async init(e) {
if (!e) {
console.error("Stats: The \"canvas\" parameter is undefined.");
return;
}
if (!this.handleThreeRenderer(e) && !await this.handleWebGPURenderer(e)) if (this.initializeWebGL(e)) {
this.trackGPU && this.initializeGPUTracking();
return;
} else console.error("Stats-gl: Failed to initialize WebGL context");
}
handleThreeRenderer(e) {
return e.isWebGLRenderer && !this.threeRendererPatched ? (this.patchThreeRenderer(e), this.gl = e.getContext(), this.trackGPU && this.initializeGPUTracking(), !0) : !1;
}
async handleWebGPURenderer(e) {
return e.isWebGPURenderer ? ((this.trackGPU || this.trackCPT) && (e.backend.trackTimestamp = !0, e._initialized || await e.init(), e.hasFeature("timestamp-query") && this.initializeWebGPUPanels()), this.info = e.info, this.patchThreeWebGPU(e), !0) : !1;
}
initializeWebGPUPanels() {
this.trackGPU && (this.gpuPanel = this.addPanel(new e.Panel("GPU", "#ff0", "#220"))), this.trackCPT && (this.gpuPanelCompute = this.addPanel(new e.Panel("CPT", "#e1e1e1", "#212121")));
}
initializeWebGL(e) {
if (e instanceof WebGL2RenderingContext) this.gl = e;
else if (e instanceof HTMLCanvasElement || e instanceof OffscreenCanvas) {
if (this.gl = e.getContext("webgl2"), !this.gl) return console.error("Stats: Unable to obtain WebGL2 context."), !1;
} else return console.error("Stats: Invalid input type. Expected WebGL2RenderingContext, HTMLCanvasElement, or OffscreenCanvas."), !1;
return !0;
}
initializeGPUTracking() {
this.gl && (this.ext = this.gl.getExtension("EXT_disjoint_timer_query_webgl2"), this.ext && (this.gpuPanel = this.addPanel(new e.Panel("GPU", "#ff0", "#220"))));
}
begin() {
this.beginProfiling("cpu-started"), !(!this.gl || !this.ext) && (this.activeQuery && this.gl.endQuery(this.ext.TIME_ELAPSED_EXT), this.activeQuery = this.gl.createQuery(), this.activeQuery && this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT, this.activeQuery));
}
end() {
this.renderCount++, this.gl && this.ext && this.activeQuery && (this.gl.endQuery(this.ext.TIME_ELAPSED_EXT), this.gpuQueries.push({ query: this.activeQuery }), this.activeQuery = null), this.endProfiling("cpu-started", "cpu-finished", "cpu-duration");
}
update() {
this.endProfiling("cpu-started", "cpu-finished", "cpu-duration"), this.info ? this.processWebGPUTimestamps() : this.processGpuQueries(), this.updateAverages(), this.resetCounters();
}
processWebGPUTimestamps() {
this.totalGpuDuration = this.info.render.timestamp, this.totalGpuDurationCompute = this.info.compute.timestamp;
}
resetCounters() {
this.renderCount = 0, this.totalCpuDuration = 0, this.beginTime = this.endInternal();
}
resizePanel(e) {
e.canvas.style.position = "absolute", this.minimal ? e.canvas.style.display = "none" : (e.canvas.style.display = "block", this.horizontal ? (e.canvas.style.top = "0px", e.canvas.style.left = e.id * e.WIDTH / e.PR + "px") : (e.canvas.style.left = "0px", e.canvas.style.top = e.id * e.HEIGHT / e.PR + "px"));
}
addPanel(e) {
return e.canvas && (this.dom.appendChild(e.canvas), e.id = this._panelId, this.resizePanel(e), this._panelId++), e;
}
showPanel(e) {
for (let t = 0; t < this.dom.children.length; t++) {
let n = this.dom.children[t];
n.style.display = t === e ? "block" : "none";
}
this.mode = e;
}
processGpuQueries() {
!this.gl || !this.ext || (this.totalGpuDuration = 0, this.gpuQueries.forEach((e, t) => {
if (this.gl) {
let n = this.gl.getQueryParameter(e.query, this.gl.QUERY_RESULT_AVAILABLE), r = this.gl.getParameter(this.ext.GPU_DISJOINT_EXT);
if (n && !r) {
let n = this.gl.getQueryParameter(e.query, this.gl.QUERY_RESULT) * 1e-6;
this.totalGpuDuration += n, this.gl.deleteQuery(e.query), this.gpuQueries.splice(t, 1);
}
}
}));
}
detectVSync(e) {
if (this.lastFrameTime === 0) {
this.lastFrameTime = e;
return;
}
let t = e - this.lastFrameTime;
if (this.lastFrameTime = e, this.frameTimeHistory.push(t), this.frameTimeHistory.length > this.HISTORY_SIZE && this.frameTimeHistory.shift(), this.frameTimeHistory.length < 60) return;
let n = this.frameTimeHistory.reduce((e, t) => e + t) / this.frameTimeHistory.length, r = this.frameTimeHistory.reduce((e, t) => e + (t - n) ** 2, 0) / this.frameTimeHistory.length;
if (Math.sqrt(r) > 2) {
this.detectedVSync = null;
return;
}
let i = null, a = Infinity;
for (let e of this.VSYNC_RATES) {
let t = Math.abs(n - e.frameTime);
t < a && (a = t, i = e);
}
i && a / i.frameTime <= this.VSYNC_THRESHOLD ? this.detectedVSync = i : this.detectedVSync = null;
}
endInternal() {
var e;
let t = performance.now();
for (this.frameTimes.push(t); this.frameTimes.length > 0 && this.frameTimes[0] <= t - 1e3;) this.frameTimes.shift();
let n = Math.round(this.frameTimes.length);
this.addToAverage(n, this.averageFps);
let r = t >= this.prevTextTime + 1e3 / this.logsPerSecond, i = t >= this.prevGraphTime + 1e3 / this.graphsPerSecond;
if (this.updatePanelComponents(this.fpsPanel, this.averageFps, 0, r, i), this.updatePanelComponents(this.msPanel, this.averageCpu, this.precision, r, i), this.gpuPanel && this.updatePanelComponents(this.gpuPanel, this.averageGpu, this.precision, r, i), this.trackCPT && this.gpuPanelCompute && this.updatePanelComponents(this.gpuPanelCompute, this.averageGpuCompute, this.precision, r, i), r && (this.prevTextTime = t), i && (this.prevGraphTime = t), this.vsyncPanel !== null) {
this.detectVSync(t);
let n = ((e = this.detectedVSync) == null ? void 0 : e.refreshRate) || 0;
r && n > 0 && this.vsyncPanel.update(n, n);
}
return t;
}
updatePanelComponents(e, t, n, r, i) {
if (!e || t.logs.length === 0) return;
e.name in this.lastMin || (this.lastMin[e.name] = Infinity, this.lastMax[e.name] = 0, this.lastValue[e.name] = 0);
let a = t.logs[t.logs.length - 1];
this.lastMax[e.name] = Math.max(...t.logs), this.lastMin[e.name] = Math.min(this.lastMin[e.name], a), this.lastValue[e.name] = this.lastValue[e.name] * .7 + a * .3;
let o = Math.max(Math.max(...t.logs), ...t.graph.slice(-this.samplesGraph));
this.updateCounter++, r && e.update(this.lastValue[e.name], this.lastMax[e.name], n), i && e.updateGraph(a, o);
}
beginProfiling(e) {
if (window.performance) try {
window.performance.clearMarks(e), window.performance.mark(e);
} catch (e) {
console.debug("Stats: Performance marking failed:", e);
}
}
endProfiling(e, t, n) {
if (!(!window.performance || !t || !e)) try {
window.performance.getEntriesByName(e, "mark").length === 0 && this.beginProfiling(e), window.performance.clearMarks(t), window.performance.mark(t), window.performance.clearMeasures(n);
let r = performance.measure(n, e, t);
this.totalCpuDuration += r.duration, window.performance.clearMarks(e), window.performance.clearMarks(t), window.performance.clearMeasures(n);
} catch (e) {
console.debug("Stats: Performance measurement failed:", e);
}
}
updatePanel(e, t, n = 2) {
if (!e || t.logs.length === 0) return;
let r = performance.now();
e.name in this.lastMin || (this.lastMin[e.name] = Infinity, this.lastMax[e.name] = 0, this.lastValue[e.name] = 0);
let i = t.logs[t.logs.length - 1], a = Math.max(...t.logs.slice(-30));
this.lastMin[e.name] = Math.min(this.lastMin[e.name], i), this.lastMax[e.name] = Math.max(this.lastMax[e.name], i), this.lastValue[e.name] = this.lastValue[e.name] * .7 + i * .3;
let o = Math.max(a, ...t.graph.slice(-this.samplesGraph));
this.updateCounter++, this.updateCounter % (this.logsPerSecond * 2) == 0 && (this.lastMax[e.name] = a, this.lastMin[e.name] = i), e.update && (r >= this.prevCpuTime + 1e3 / this.logsPerSecond && e.update(this.lastValue[e.name], i, this.lastMax[e.name], o, n), r >= this.prevGraphTime + 1e3 / this.graphsPerSecond && (e.updateGraph(i, o), this.prevGraphTime = r));
}
updateAverages() {
this.addToAverage(this.totalCpuDuration, this.averageCpu), this.addToAverage(this.totalGpuDuration, this.averageGpu), this.info && this.totalGpuDurationCompute !== void 0 && this.addToAverage(this.totalGpuDurationCompute, this.averageGpuCompute);
}
addToAverage(e, t) {
t.logs.push(e), t.logs.length > this.samplesLog && (t.logs = t.logs.slice(-this.samplesLog)), t.graph.push(e), t.graph.length > this.samplesGraph && (t.graph = t.graph.slice(-this.samplesGraph));
}
get domElement() {
return this.dom;
}
patchThreeWebGPU(e) {
let t = e.info.reset, n = this;
e.info.reset = function() {
n.beginProfiling("cpu-started"), t.call(this);
};
}
patchThreeRenderer(e) {
let t = e.render, n = this;
e.render = function(e, r) {
n.begin(), t.call(this, e, r), n.end();
}, this.threeRendererPatched = !0;
}
};
n.Panel = e;
var r = n;
//#endregion
export { r as default };