feat(canvas-v3): P3 插件 fallback + canvas 绘制统计

This commit is contained in:
qiqi committed 2026-12-01 00:44:34 +08:00
1 parent b0ceb3353d
commit ec304b49d7
6 files changed
+19 -4

No files matched your search

+5 -1
View File
@@ -12,6 +12,7 @@
const useEffect = React.useEffect
const useState = React.useState
const imgCache = new Map()
const perf = { lastMs: 0, frames: 0 }
function css (name, fallback) {
try {
@@ -47,6 +48,7 @@
function draw (canvas, o) {
if (!canvas || !o || typeof canvas.getContext !== 'function') return
const t0 = (typeof performance !== 'undefined' && performance.now) ? performance.now() : 0
const rect = canvas.getBoundingClientRect ? canvas.getBoundingClientRect() : null
const w = Math.max(1, Math.round((rect && rect.width) || canvas.clientWidth || 1))
const h = Math.max(1, Math.round((rect && rect.height) || canvas.clientHeight || 1))
@@ -172,6 +174,7 @@
}
void accent
}
if (t0) { perf.lastMs = (typeof performance !== 'undefined' && performance.now ? performance.now() : t0) - t0; perf.frames++ }
}
function CanvasNodeLayer (props) {
@@ -196,5 +199,6 @@
return el('canvas', { className: 'iwb-node-canvas', 'aria-hidden': 'true', ref: ref })
}
global.IWBCanvasV3NodeLayer = { CanvasNodeLayer, draw }
function stats () { return { drawMs: perf.lastMs, frames: perf.frames, images: imgCache.size } }
global.IWBCanvasV3NodeLayer = { CanvasNodeLayer, draw, stats }
})(typeof window !== 'undefined' ? window : globalThis)