2023-06-23 04:34:52 +02:00
|
|
|
import data from "unicode-emoji-json/data-by-group.json";
|
2023-06-23 05:58:44 +02:00
|
|
|
import emojiComponents from "unicode-emoji-json/data-emoji-components.json";
|
2023-06-30 06:34:09 +02:00
|
|
|
import individualData from "unicode-emoji-json/data-by-emoji.json";
|
2023-06-23 04:34:52 +02:00
|
|
|
import keywordSet from "emojilib";
|
2023-06-23 05:58:44 +02:00
|
|
|
import { defaultStore } from "@/store";
|
2023-06-23 04:34:52 +02:00
|
|
|
|
2023-09-02 01:27:33 +02:00
|
|
|
export interface UnicodeEmojiDef {
|
2023-06-24 01:51:13 +02:00
|
|
|
emoji: string;
|
2024-03-30 16:30:03 +01:00
|
|
|
category: (typeof unicodeEmojiCategories)[number]["name"];
|
|
|
|
category_slug: (typeof unicodeEmojiCategories)[number]["slug"];
|
2023-06-24 01:51:13 +02:00
|
|
|
skin_tone_support: boolean;
|
|
|
|
slug: string;
|
|
|
|
keywords?: string[];
|
2023-09-02 01:27:33 +02:00
|
|
|
}
|
2023-06-24 01:51:13 +02:00
|
|
|
|
2024-03-30 16:30:03 +01:00
|
|
|
export const unicodeEmojiCategories = data.map((categories) => ({
|
|
|
|
slug: categories.slug,
|
|
|
|
name: categories.name,
|
|
|
|
}));
|
2023-06-23 04:34:52 +02:00
|
|
|
|
2023-06-24 01:51:13 +02:00
|
|
|
export function addSkinTone(emoji: string, skinTone?: number) {
|
|
|
|
const chosenSkinTone = skinTone || defaultStore.state.reactionPickerSkinTone;
|
|
|
|
const skinToneModifiers = [
|
2023-06-24 06:22:44 +02:00
|
|
|
"",
|
|
|
|
emojiComponents.light_skin_tone,
|
|
|
|
emojiComponents.medium_light_skin_tone,
|
|
|
|
emojiComponents.medium_skin_tone,
|
|
|
|
emojiComponents.medium_dark_skin_tone,
|
|
|
|
emojiComponents.dark_skin_tone,
|
2023-06-24 01:51:13 +02:00
|
|
|
];
|
2023-06-30 06:34:09 +02:00
|
|
|
const strippedEmoji = emoji.replace(
|
|
|
|
new RegExp(`(${skinToneModifiers.slice(1).join("|")})`, "gi"),
|
|
|
|
"",
|
|
|
|
);
|
|
|
|
if (individualData[strippedEmoji].skin_tone_support) {
|
|
|
|
return strippedEmoji + (skinToneModifiers[chosenSkinTone - 1] || "");
|
|
|
|
} else {
|
2023-06-25 04:38:55 +02:00
|
|
|
return emoji;
|
|
|
|
}
|
2023-06-23 05:58:44 +02:00
|
|
|
}
|
2023-06-23 04:34:52 +02:00
|
|
|
|
2024-03-30 16:30:03 +01:00
|
|
|
export const emojilist: UnicodeEmojiDef[] = data
|
|
|
|
.flatMap((category) =>
|
|
|
|
category.emojis.map((emoji) => ({
|
|
|
|
...emoji,
|
|
|
|
category: category.name,
|
|
|
|
category_slug: category.slug,
|
|
|
|
keywords: keywordSet[emoji.emoji],
|
|
|
|
})),
|
|
|
|
)
|
|
|
|
.map((item) => ({
|
|
|
|
emoji: item.emoji,
|
|
|
|
slug: item.slug,
|
|
|
|
category: item.category,
|
|
|
|
category_slug: item.category_slug,
|
|
|
|
skin_tone_support: item.skin_tone_support || false,
|
|
|
|
keywords: item.keywords || [],
|
|
|
|
}));
|