mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
feat: forceUseSvgFlag
This commit is contained in:
parent
edd2404538
commit
704818d084
@ -5,7 +5,16 @@ import { useEffect, useState } from "react"
|
|||||||
export default function ServerFlag({ country_code, className }: { country_code: string; className?: string }) {
|
export default function ServerFlag({ country_code, className }: { country_code: string; className?: string }) {
|
||||||
const [supportsEmojiFlags, setSupportsEmojiFlags] = useState(false)
|
const [supportsEmojiFlags, setSupportsEmojiFlags] = useState(false)
|
||||||
|
|
||||||
|
// @ts-expect-error ForceUseSvgFlag is a global variable
|
||||||
|
const forceUseSvgFlag = window.ForceUseSvgFlag as boolean
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (forceUseSvgFlag) {
|
||||||
|
// 如果环境变量要求直接使用 SVG,则无需检查 Emoji 支持
|
||||||
|
setSupportsEmojiFlags(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const checkEmojiSupport = () => {
|
const checkEmojiSupport = () => {
|
||||||
const canvas = document.createElement("canvas")
|
const canvas = document.createElement("canvas")
|
||||||
const ctx = canvas.getContext("2d")
|
const ctx = canvas.getContext("2d")
|
||||||
@ -27,7 +36,7 @@ export default function ServerFlag({ country_code, className }: { country_code:
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={cn("text-[12px] text-muted-foreground", className)}>
|
<span className={cn("text-[12px] text-muted-foreground", className)}>
|
||||||
{!supportsEmojiFlags ? <span className={`fi fi-${country_code}`} /> : getUnicodeFlagIcon(country_code)}
|
{forceUseSvgFlag || !supportsEmojiFlags ? <span className={`fi fi-${country_code}`} /> : getUnicodeFlagIcon(country_code)}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user