mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-30 20:21:20 -08:00
refactor(mediabunny): [PKG-MB-08] checkpoint typed entry and compatible media declarations
This commit is contained in:
1 parent
8a2b56e829
commit
5e28dfee95
39 files changed
+3007
-287
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import type VideoShim from './VideoShim'
|
||||
|
||||
export function bridgeCanvas(canvas: HTMLCanvasElement, shim: VideoShim): void {
|
||||
const methods = new Map<string, (...args: unknown[]) => unknown>()
|
||||
// Dynamic forwarding is intentional: own and direct-prototype members are historical API.
|
||||
const native = canvas as unknown as Record<string, unknown>
|
||||
const members = shim as unknown as Record<string, unknown>
|
||||
for (const name in canvas) {
|
||||
if (typeof native[name] === 'function') {
|
||||
// Preserve the historical second read, including accessor side effects and binding errors.
|
||||
const method = native[name] as (...args: unknown[]) => unknown
|
||||
methods.set(name, method.bind(canvas))
|
||||
}
|
||||
}
|
||||
const names = new Set([
|
||||
...Object.getOwnPropertyNames(shim),
|
||||
...Object.getOwnPropertyNames(Object.getPrototypeOf(shim)),
|
||||
])
|
||||
for (const name of names) {
|
||||
if (name === 'constructor' || name in canvas)
|
||||
continue
|
||||
Object.defineProperty(canvas, name, {
|
||||
get() {
|
||||
const value = members[name]
|
||||
return typeof value === 'function' ? value.bind(shim) : value
|
||||
},
|
||||
set(value: unknown) {
|
||||
members[name] = value
|
||||
},
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
})
|
||||
}
|
||||
for (const [name, method] of methods)
|
||||
native[name] = (...args: unknown[]) => method(...args)
|
||||
}
|
||||
Reference in new issue
Block a user