73 lines
1.4 KiB
JavaScript
73 lines
1.4 KiB
JavaScript
/**
|
|
* {}
|
|
* @author yutent<yutent.io@gmail.com>
|
|
* @date 2023/07/18 19:11:01
|
|
*/
|
|
|
|
import { IS_SAFARI } from './env.js'
|
|
|
|
// 用canvas检测图形/图象的支持
|
|
export function checkCanvas(type) {
|
|
// macos下的safari, 调用webgpu,会崩溃
|
|
// 所以, webgpu不能用canvas调用来判断
|
|
if (type == 'webgpu') {
|
|
return !!navigator.gpu ^ 0
|
|
}
|
|
try {
|
|
var canvas = document.createElement('canvas')
|
|
var ctx = canvas.getContext(type)
|
|
return ctx ? 1 : 0
|
|
} catch (err) {
|
|
console.log(err)
|
|
return 0
|
|
}
|
|
}
|
|
|
|
export function checkMedia(type, isAudio = 1) {
|
|
let ctx = isAudio ? new Audio() : document.createElement('video')
|
|
let res = ctx.canPlayType(type)
|
|
if (res === 'maybe' || res === 'probably') {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
export function checkAsyncAwait() {
|
|
try {
|
|
eval('async function foo(){return await 123}')
|
|
return 1.25
|
|
} catch (e) {
|
|
return 0
|
|
}
|
|
}
|
|
|
|
export function checkPrivateFeatures() {
|
|
try {
|
|
eval('class Foo { #bar = 3}')
|
|
return 1.25
|
|
} catch (e) {
|
|
return 0
|
|
}
|
|
}
|
|
|
|
export function checkObjectSpread() {
|
|
try {
|
|
eval(`let a = [11, 22]
|
|
let b = [...a]
|
|
;[a[1], a[0]] = [a[0], a[1]]`)
|
|
return 1
|
|
} catch (e) {
|
|
return 0
|
|
}
|
|
}
|
|
|
|
export function checkOptionalChaining() {
|
|
try {
|
|
// ?。 和 ?? 同时期出现的, 检测一个即可
|
|
window.a?.b?.c()
|
|
return 1
|
|
} catch (e) {
|
|
return 0
|
|
}
|
|
}
|