~cytrogen/masto-fe

ref: 1a4a23b5c8a8e0beacded9bc44354e3f8778ae26 masto-fe/app/javascript/mastodon/features/emoji/emoji_mart_data_light.ts -rw-r--r-- 1.4 KiB
1a4a23b5 — Claire Merge pull request #2439 from ClearlyClaire/glitch-soc/merge-upstream 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// The output of this module is designed to mimic emoji-mart's
// "data" object, such that we can use it for a light version of emoji-mart's
// emojiIndex.search functionality.
import type { BaseEmoji } from 'emoji-mart';
import type { Emoji } from 'emoji-mart/dist-es/utils/data';

import type { Search, ShortCodesToEmojiData } from './emoji_compressed';
import emojiCompressed from './emoji_compressed';
import { unicodeToUnifiedName } from './unicode_to_unified_name';

type Emojis = {
  [key in NonNullable<keyof ShortCodesToEmojiData>]: {
    native: BaseEmoji['native'];
    search: Search;
    short_names: Emoji['short_names'];
    unified: Emoji['unified'];
  };
};

const [
  shortCodesToEmojiData,
  skins,
  categories,
  short_names,
  _emojisWithoutShortCodes,
] = emojiCompressed;

const emojis: Emojis = {};

// decompress
Object.keys(shortCodesToEmojiData).forEach((shortCode) => {
  const [_filenameData, searchData] = shortCodesToEmojiData[shortCode];
  const native = searchData[0];
  let short_names = searchData[1];
  const search = searchData[2];
  let unified = searchData[3];

  if (!unified) {
    // unified name can be derived from unicodeToUnifiedName
    unified = unicodeToUnifiedName(native);
  }

  if (short_names) short_names = [shortCode].concat(short_names);
  emojis[shortCode] = {
    native,
    search,
    short_names,
    unified,
  };
});

export { emojis, skins, categories, short_names };