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-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-06-24 01:51:13 +02:00
|
|
|
export type UnicodeEmojiDef = {
|
|
|
|
emoji: string;
|
|
|
|
category: typeof unicodeEmojiCategories[number];
|
|
|
|
skin_tone_support: boolean;
|
|
|
|
slug: string;
|
|
|
|
keywords?: string[];
|
|
|
|
};
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
export const unicodeEmojiCategories = [
|
2023-06-23 04:34:52 +02:00
|
|
|
"emotion",
|
2023-01-13 05:40:33 +01:00
|
|
|
"people",
|
|
|
|
"animals_and_nature",
|
|
|
|
"food_and_drink",
|
|
|
|
"activity",
|
|
|
|
"travel_and_places",
|
|
|
|
"objects",
|
|
|
|
"symbols",
|
|
|
|
"flags",
|
|
|
|
] as const;
|
2022-01-18 15:06:16 +01:00
|
|
|
|
2023-06-23 04:34:52 +02:00
|
|
|
export const categoryMapping = {
|
|
|
|
"Smileys & Emotion": "emotion",
|
|
|
|
"People & Body": "people",
|
|
|
|
"Animals & Nature": "animals_and_nature",
|
|
|
|
"Food & Drink": "food_and_drink",
|
|
|
|
"Activities": "activity",
|
|
|
|
"Travel & Places": "travel_and_places",
|
|
|
|
"Objects": "objects",
|
|
|
|
"Symbols": "symbols",
|
|
|
|
"Flags": "flags",
|
|
|
|
} as const;
|
|
|
|
|
2023-06-24 01:51:13 +02:00
|
|
|
export function addSkinTone(emoji: string, skinTone?: number) {
|
|
|
|
const chosenSkinTone = skinTone || defaultStore.state.reactionPickerSkinTone;
|
|
|
|
const skinToneModifiers = [
|
|
|
|
"",
|
|
|
|
emojiComponents.light_skin_tone,
|
|
|
|
emojiComponents.medium_light_skin_tone,
|
|
|
|
emojiComponents.medium_skin_tone,
|
|
|
|
emojiComponents.medium_dark_skin_tone,
|
|
|
|
emojiComponents.dark_skin_tone
|
|
|
|
];
|
|
|
|
return emoji + (skinToneModifiers[chosenSkinTone - 1] || "");
|
2023-06-23 05:58:44 +02:00
|
|
|
}
|
2023-06-23 04:34:52 +02:00
|
|
|
|
2023-06-23 07:39:52 +02:00
|
|
|
const unicodeFifteenEmojis = [
|
|
|
|
'🫨', '🩷', '🩵', '🩶',
|
|
|
|
'🫷', '🫸', '🫎', '🫏',
|
|
|
|
'🪽', '🐦⬛', '🪿', '🪼',
|
|
|
|
'🪻', '🫚', '🫛', '🪭',
|
|
|
|
'🪮', '🪇', '🪈', '🪯',
|
|
|
|
'🛜'
|
|
|
|
]
|
|
|
|
|
2023-06-23 04:34:52 +02:00
|
|
|
const newData = {};
|
|
|
|
|
|
|
|
Object.keys(data).forEach((originalCategory) => {
|
|
|
|
const newCategory = categoryMapping[originalCategory];
|
|
|
|
if (newCategory) {
|
|
|
|
newData[newCategory] = newData[newCategory] || [];
|
|
|
|
Object.keys(data[originalCategory]).forEach((emojiIndex) => {
|
|
|
|
const emojiObj = { ...data[originalCategory][emojiIndex] };
|
2023-06-23 07:39:52 +02:00
|
|
|
if (unicodeFifteenEmojis.includes(emojiObj.emoji)) {
|
|
|
|
return;
|
|
|
|
}
|
2023-06-23 05:58:44 +02:00
|
|
|
emojiObj.category = newCategory;
|
|
|
|
emojiObj.keywords = keywordSet[emojiObj.emoji];
|
|
|
|
newData[newCategory].push(emojiObj);
|
2023-06-23 04:34:52 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-23 05:58:44 +02:00
|
|
|
export const emojilist: UnicodeEmojiDef[] = Object.keys(newData).reduce((acc, category) => {
|
|
|
|
const categoryItems = newData[category].map((item) => {
|
2023-06-23 07:39:52 +02:00
|
|
|
return {
|
|
|
|
emoji: item.emoji,
|
|
|
|
slug: item.slug,
|
|
|
|
category: item.category,
|
2023-06-24 01:51:13 +02:00
|
|
|
skin_tone_support: item.skin_tone_support || false,
|
2023-06-23 07:39:52 +02:00
|
|
|
keywords: item.keywords || [],
|
|
|
|
};
|
2023-06-23 04:34:52 +02:00
|
|
|
});
|
2023-06-23 05:58:44 +02:00
|
|
|
return acc.concat(categoryItems);
|
|
|
|
}, []);
|
2023-06-23 04:34:52 +02:00
|
|
|
|
2022-07-13 14:17:19 +02:00
|
|
|
|
2023-06-23 04:34:52 +02:00
|
|
|
export function getNicelyLabeledCategory(internalName) {
|
|
|
|
return Object.keys(categoryMapping).find(
|
|
|
|
(key) => categoryMapping[key] === internalName
|
|
|
|
) || internalName;
|
|
|
|
}
|