2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:59:27 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-01-18 08:06:16 -06:00
|
|
|
export const unicodeEmojiCategories = ['face', 'people', 'animals_and_nature', 'food_and_drink', 'activity', 'travel_and_places', 'objects', 'symbols', 'flags'] as const;
|
|
|
|
|
|
|
|
export type UnicodeEmojiDef = {
|
2019-09-21 07:31:38 -05:00
|
|
|
name: string;
|
|
|
|
char: string;
|
2022-01-18 08:06:16 -06:00
|
|
|
category: typeof unicodeEmojiCategories[number];
|
|
|
|
}
|
|
|
|
|
|
|
|
// initial converted from https://github.com/muan/emojilib/commit/242fe68be86ed6536843b83f7e32f376468b38fb
|
2022-07-13 07:17:19 -05:00
|
|
|
import _emojilist from '../emojilist.json';
|
|
|
|
|
2023-05-29 21:18:40 -05:00
|
|
|
export const emojilist: UnicodeEmojiDef[] = _emojilist.map(x => ({
|
|
|
|
name: x[1] as string,
|
|
|
|
char: x[0] as string,
|
|
|
|
category: unicodeEmojiCategories[x[2]],
|
|
|
|
}));
|
2022-12-25 00:52:52 -06:00
|
|
|
|
2024-02-23 19:22:23 -06:00
|
|
|
export const unicodeEmojisMap = new Map<string, UnicodeEmojiDef>(
|
2024-02-29 05:47:24 -06:00
|
|
|
emojilist.map(x => [x.char, x]),
|
2024-02-23 19:22:23 -06:00
|
|
|
);
|
|
|
|
|
2023-01-31 20:25:13 -06:00
|
|
|
const _indexByChar = new Map<string, number>();
|
|
|
|
const _charGroupByCategory = new Map<string, string[]>();
|
2023-05-29 21:18:40 -05:00
|
|
|
for (let i = 0; i < emojilist.length; i++) {
|
|
|
|
const emo = emojilist[i];
|
2023-01-31 20:25:13 -06:00
|
|
|
_indexByChar.set(emo.char, i);
|
|
|
|
|
|
|
|
if (_charGroupByCategory.has(emo.category)) {
|
|
|
|
_charGroupByCategory.get(emo.category)?.push(emo.char);
|
|
|
|
} else {
|
|
|
|
_charGroupByCategory.set(emo.category, [emo.char]);
|
|
|
|
}
|
2023-05-29 21:18:40 -05:00
|
|
|
}
|
2023-01-31 20:25:13 -06:00
|
|
|
|
|
|
|
export const emojiCharByCategory = _charGroupByCategory;
|
|
|
|
|
2024-02-29 05:47:24 -06:00
|
|
|
export function getUnicodeEmoji(char: string): UnicodeEmojiDef | null {
|
|
|
|
// Colorize it because emojilist.json assumes that
|
|
|
|
return unicodeEmojisMap.get(colorizeEmoji(char)) ?? null;
|
|
|
|
}
|
|
|
|
|
2023-06-01 02:28:24 -05:00
|
|
|
export function getEmojiName(char: string): string | null {
|
2024-01-07 01:02:53 -06:00
|
|
|
// Colorize it because emojilist.json assumes that
|
|
|
|
const idx = _indexByChar.get(colorizeEmoji(char));
|
2023-06-01 02:28:24 -05:00
|
|
|
if (idx == null) {
|
|
|
|
return null;
|
2023-01-31 20:25:13 -06:00
|
|
|
} else {
|
|
|
|
return emojilist[idx].name;
|
|
|
|
}
|
2022-12-25 00:52:52 -06:00
|
|
|
}
|
2023-12-02 00:26:46 -06:00
|
|
|
|
2024-01-07 01:02:53 -06:00
|
|
|
export function colorizeEmoji(char: string) {
|
|
|
|
return char.length === 1 ? `${char}\uFE0F` : char;
|
|
|
|
}
|
|
|
|
|
2023-12-02 00:26:46 -06:00
|
|
|
export interface CustomEmojiFolderTree {
|
|
|
|
value: string;
|
|
|
|
category: string;
|
|
|
|
children: CustomEmojiFolderTree[];
|
|
|
|
}
|