Spaces:
Sleeping
Sleeping
Update components/Emoji.tsx
Browse files- components/Emoji.tsx +6 -11
components/Emoji.tsx
CHANGED
|
@@ -7,13 +7,9 @@ interface EmojiProps {
|
|
| 7 |
size?: number | string;
|
| 8 |
}
|
| 9 |
|
| 10 |
-
//
|
| 11 |
-
//
|
| 12 |
-
|
| 13 |
-
// Windows NT 5.x = XP
|
| 14 |
-
// Windows 8 (6.2) 及以上系统原生支持彩色 Emoji,无需替换
|
| 15 |
-
const isLegacyWindows = typeof navigator !== 'undefined' &&
|
| 16 |
-
/Windows NT (5\.|6\.[0-1])/.test(navigator.userAgent);
|
| 17 |
|
| 18 |
// 将 Unicode 转换为 Twemoji 兼容的 Hex 文件名
|
| 19 |
const getEmojiHex = (emoji: string) => {
|
|
@@ -27,9 +23,8 @@ const getEmojiHex = (emoji: string) => {
|
|
| 27 |
};
|
| 28 |
|
| 29 |
export const Emoji: React.FC<EmojiProps> = memo(({ symbol, className = '', size }) => {
|
| 30 |
-
//
|
| 31 |
-
|
| 32 |
-
if (!isLegacyWindows) {
|
| 33 |
return (
|
| 34 |
<span
|
| 35 |
className={className}
|
|
@@ -49,7 +44,7 @@ export const Emoji: React.FC<EmojiProps> = memo(({ symbol, className = '', size
|
|
| 49 |
);
|
| 50 |
}
|
| 51 |
|
| 52 |
-
// ---
|
| 53 |
|
| 54 |
// 1. 简单正则判断是否包含 Emoji 字符 (避免对纯文本进行昂贵的 Hex 转换)
|
| 55 |
const isEmoji = /\p{Emoji}/u.test(symbol);
|
|
|
|
| 7 |
size?: number | string;
|
| 8 |
}
|
| 9 |
|
| 10 |
+
// 修改逻辑:所有 Windows 系统都使用 Twemoji 组件以保证显示一致性
|
| 11 |
+
// 其他系统(如 macOS, iOS, Android)通常有较好的原生 Emoji 支持,继续使用原生字体
|
| 12 |
+
const isWindows = typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
// 将 Unicode 转换为 Twemoji 兼容的 Hex 文件名
|
| 15 |
const getEmojiHex = (emoji: string) => {
|
|
|
|
| 23 |
};
|
| 24 |
|
| 25 |
export const Emoji: React.FC<EmojiProps> = memo(({ symbol, className = '', size }) => {
|
| 26 |
+
// 【性能优化】非 Windows 系统直接使用原生字体渲染
|
| 27 |
+
if (!isWindows) {
|
|
|
|
| 28 |
return (
|
| 29 |
<span
|
| 30 |
className={className}
|
|
|
|
| 44 |
);
|
| 45 |
}
|
| 46 |
|
| 47 |
+
// --- Windows 系统执行 Twemoji 图片替换 ---
|
| 48 |
|
| 49 |
// 1. 简单正则判断是否包含 Emoji 字符 (避免对纯文本进行昂贵的 Hex 转换)
|
| 50 |
const isEmoji = /\p{Emoji}/u.test(symbol);
|