dvc890 commited on
Commit
23e52fb
·
verified ·
1 Parent(s): 355c0ae

Update components/Emoji.tsx

Browse files
Files changed (1) hide show
  1. components/Emoji.tsx +6 -11
components/Emoji.tsx CHANGED
@@ -7,13 +7,9 @@ interface EmojiProps {
7
  size?: number | string;
8
  }
9
 
10
- // 智能检测:是否为旧版 Windows 系统 (Windows 7, Vista, XP)
11
- // Windows NT 6.1 = Windows 7
12
- // Windows NT 6.0 = Vista
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
- // --- 以下逻辑仅在 Windows 7 等旧系统执行 ---
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);