2023-05-09 11:08:47 +10:00
|
|
|
/* eslint-disable import/no-commonjs --
|
|
|
|
We need to use CommonJS here due to preval */
|
2017-10-06 12:42:34 +11:00
|
|
|
// @preval
|
|
|
|
// http://www.unicode.org/Public/emoji/5.0/emoji-test.txt
|
|
|
|
// This file contains the compressed version of the emoji data from
|
|
|
|
// both emoji_map.json and from emoji-mart's emojiIndex and data objects.
|
|
|
|
// It's designed to be emitted in an array format to take up less space
|
|
|
|
// over the wire.
|
|
|
|
|
|
|
|
const { emojiIndex } = require('emoji-mart');
|
2023-05-24 01:15:17 +10:00
|
|
|
let data = require('emoji-mart/data/all.json');
|
2018-06-08 03:40:23 +10:00
|
|
|
const { uncompress: emojiMartUncompress } = require('emoji-mart/dist/utils/data');
|
2021-06-01 22:35:49 +10:00
|
|
|
|
2023-05-24 01:15:17 +10:00
|
|
|
const emojiMap = require('./emoji_map.json');
|
|
|
|
const { unicodeToFilename } = require('./unicode_to_filename');
|
|
|
|
const { unicodeToUnifiedName } = require('./unicode_to_unified_name');
|
|
|
|
|
2018-06-08 03:40:23 +10:00
|
|
|
|
|
|
|
if(data.compressed) {
|
|
|
|
data = emojiMartUncompress(data);
|
|
|
|
}
|
2021-06-01 22:35:49 +10:00
|
|
|
|
2018-06-08 03:40:23 +10:00
|
|
|
const emojiMartData = data;
|
2017-10-16 20:12:09 +11:00
|
|
|
|
2017-10-06 12:42:34 +11:00
|
|
|
const excluded = ['®', '©', '™'];
|
2021-06-01 22:35:49 +10:00
|
|
|
const skinTones = ['🏻', '🏼', '🏽', '🏾', '🏿'];
|
2017-10-06 12:42:34 +11:00
|
|
|
const shortcodeMap = {};
|
|
|
|
|
|
|
|
const shortCodesToEmojiData = {};
|
|
|
|
const emojisWithoutShortCodes = [];
|
|
|
|
|
|
|
|
Object.keys(emojiIndex.emojis).forEach(key => {
|
2021-06-01 22:35:49 +10:00
|
|
|
let emoji = emojiIndex.emojis[key];
|
|
|
|
|
|
|
|
// Emojis with skin tone modifiers are stored like this
|
|
|
|
if (Object.prototype.hasOwnProperty.call(emoji, '1')) {
|
|
|
|
emoji = emoji['1'];
|
|
|
|
}
|
|
|
|
|
|
|
|
shortcodeMap[emoji.native] = emoji.id;
|
2017-10-06 12:42:34 +11:00
|
|
|
});
|
|
|
|
|
|
|
|
const stripModifiers = unicode => {
|
2021-06-01 22:35:49 +10:00
|
|
|
skinTones.forEach(tone => {
|
2017-10-06 12:42:34 +11:00
|
|
|
unicode = unicode.replace(tone, '');
|
|
|
|
});
|
|
|
|
|
|
|
|
return unicode;
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(emojiMap).forEach(key => {
|
|
|
|
if (excluded.includes(key)) {
|
|
|
|
delete emojiMap[key];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const normalizedKey = stripModifiers(key);
|
|
|
|
let shortcode = shortcodeMap[normalizedKey];
|
|
|
|
|
|
|
|
if (!shortcode) {
|
|
|
|
shortcode = shortcodeMap[normalizedKey + '\uFE0F'];
|
|
|
|
}
|
|
|
|
|
|
|
|
const filename = emojiMap[key];
|
|
|
|
|
|
|
|
const filenameData = [key];
|
|
|
|
|
|
|
|
if (unicodeToFilename(key) !== filename) {
|
|
|
|
// filename can't be derived using unicodeToFilename
|
|
|
|
filenameData.push(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof shortcode === 'undefined') {
|
|
|
|
emojisWithoutShortCodes.push(filenameData);
|
|
|
|
} else {
|
2017-10-07 01:40:41 +11:00
|
|
|
if (!Array.isArray(shortCodesToEmojiData[shortcode])) {
|
|
|
|
shortCodesToEmojiData[shortcode] = [[]];
|
|
|
|
}
|
2021-06-01 22:35:49 +10:00
|
|
|
|
2017-10-06 12:42:34 +11:00
|
|
|
shortCodesToEmojiData[shortcode][0].push(filenameData);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(emojiIndex.emojis).forEach(key => {
|
2021-06-01 22:35:49 +10:00
|
|
|
let emoji = emojiIndex.emojis[key];
|
|
|
|
|
|
|
|
// Emojis with skin tone modifiers are stored like this
|
|
|
|
if (Object.prototype.hasOwnProperty.call(emoji, '1')) {
|
|
|
|
emoji = emoji['1'];
|
|
|
|
}
|
|
|
|
|
|
|
|
const { native } = emoji;
|
2017-10-30 02:23:38 +11:00
|
|
|
let { short_names, search, unified } = emojiMartData.emojis[key];
|
2021-06-01 22:35:49 +10:00
|
|
|
|
2017-10-06 12:42:34 +11:00
|
|
|
if (short_names[0] !== key) {
|
2022-02-23 06:14:17 +11:00
|
|
|
throw new Error('The compressor expects the first short_code to be the ' +
|
2017-10-06 12:42:34 +11:00
|
|
|
'key. It may need to be rewritten if the emoji change such that this ' +
|
|
|
|
'is no longer the case.');
|
|
|
|
}
|
|
|
|
|
2017-10-30 02:23:38 +11:00
|
|
|
short_names = short_names.slice(1); // first short name can be inferred from the key
|
2017-10-06 12:42:34 +11:00
|
|
|
|
|
|
|
const searchData = [native, short_names, search];
|
2021-06-01 22:35:49 +10:00
|
|
|
|
2017-10-06 12:42:34 +11:00
|
|
|
if (unicodeToUnifiedName(native) !== unified) {
|
|
|
|
// unified name can't be derived from unicodeToUnifiedName
|
|
|
|
searchData.push(unified);
|
|
|
|
}
|
|
|
|
|
2021-06-01 22:35:49 +10:00
|
|
|
if (!Array.isArray(shortCodesToEmojiData[key])) {
|
|
|
|
shortCodesToEmojiData[key] = [[]];
|
|
|
|
}
|
|
|
|
|
2017-10-06 12:42:34 +11:00
|
|
|
shortCodesToEmojiData[key].push(searchData);
|
|
|
|
});
|
|
|
|
|
|
|
|
// JSON.parse/stringify is to emulate what @preval is doing and avoid any
|
|
|
|
// inconsistent behavior in dev mode
|
|
|
|
module.exports = JSON.parse(JSON.stringify([
|
|
|
|
shortCodesToEmojiData,
|
2023-06-14 03:28:31 +10:00
|
|
|
/*
|
|
|
|
* The property `skins` is not found in the current context.
|
|
|
|
* This could potentially lead to issues when interacting with modules or data structures
|
|
|
|
* that expect the presence of `skins` property.
|
|
|
|
* Currently, no definitions or references to `skins` property can be found in:
|
|
|
|
* - {@link node_modules/emoji-mart/dist/utils/data.js}
|
|
|
|
* - {@link node_modules/emoji-mart/data/all.json}
|
|
|
|
* - {@link app/javascript/mastodon/features/emoji/emoji_compressed.d.ts#Skins}
|
|
|
|
* Future refactorings or updates should consider adding definitions or handling for `skins` property.
|
|
|
|
*/
|
2017-10-06 12:42:34 +11:00
|
|
|
emojiMartData.skins,
|
|
|
|
emojiMartData.categories,
|
2018-06-08 03:40:23 +10:00
|
|
|
emojiMartData.aliases,
|
2017-10-06 12:42:34 +11:00
|
|
|
emojisWithoutShortCodes,
|
|
|
|
]));
|