From d2c9f39c0bb71acb927b4bb75f7a98d5df733697 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 1 Jun 2021 14:35:49 +0200 Subject: [Glitch] Add assets from Twemoji 13.1.0 Port abd7b4636a4bda2454f1d30e7f87843d0c06dcbe to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/util/emoji/emoji_compressed.js | 34 ++++++++++++++++++---- .../glitch/util/emoji/unicode_to_unified_name.js | 4 +++ 2 files changed, 32 insertions(+), 6 deletions(-) (limited to 'app/javascript/flavours/glitch/util') diff --git a/app/javascript/flavours/glitch/util/emoji/emoji_compressed.js b/app/javascript/flavours/glitch/util/emoji/emoji_compressed.js index 48d90201a..74b53ce5c 100644 --- a/app/javascript/flavours/glitch/util/emoji/emoji_compressed.js +++ b/app/javascript/flavours/glitch/util/emoji/emoji_compressed.js @@ -7,30 +7,38 @@ const { unicodeToFilename } = require('./unicode_to_filename'); const { unicodeToUnifiedName } = require('./unicode_to_unified_name'); -const emojiMap = require('./emoji_map.json'); +const emojiMap = require('./emoji_map.json'); const { emojiIndex } = require('emoji-mart'); const { uncompress: emojiMartUncompress } = require('emoji-mart/dist/utils/data'); + let data = require('emoji-mart/data/all.json'); if(data.compressed) { data = emojiMartUncompress(data); } -const emojiMartData = data; +const emojiMartData = data; const excluded = ['®', '©', '™']; -const skins = ['🏻', '🏼', '🏽', '🏾', '🏿']; +const skinTones = ['🏻', '🏼', '🏽', '🏾', '🏿']; const shortcodeMap = {}; const shortCodesToEmojiData = {}; const emojisWithoutShortCodes = []; Object.keys(emojiIndex.emojis).forEach(key => { - shortcodeMap[emojiIndex.emojis[key].native] = emojiIndex.emojis[key].id; + 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; }); const stripModifiers = unicode => { - skins.forEach(tone => { + skinTones.forEach(tone => { unicode = unicode.replace(tone, ''); }); @@ -65,13 +73,22 @@ Object.keys(emojiMap).forEach(key => { if (!Array.isArray(shortCodesToEmojiData[shortcode])) { shortCodesToEmojiData[shortcode] = [[]]; } + shortCodesToEmojiData[shortcode][0].push(filenameData); } }); Object.keys(emojiIndex.emojis).forEach(key => { - const { native } = emojiIndex.emojis[key]; + 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; let { short_names, search, unified } = emojiMartData.emojis[key]; + if (short_names[0] !== key) { throw new Error('The compresser expects the first short_code to be the ' + 'key. It may need to be rewritten if the emoji change such that this ' + @@ -81,11 +98,16 @@ Object.keys(emojiIndex.emojis).forEach(key => { short_names = short_names.slice(1); // first short name can be inferred from the key const searchData = [native, short_names, search]; + if (unicodeToUnifiedName(native) !== unified) { // unified name can't be derived from unicodeToUnifiedName searchData.push(unified); } + if (!Array.isArray(shortCodesToEmojiData[key])) { + shortCodesToEmojiData[key] = [[]]; + } + shortCodesToEmojiData[key].push(searchData); }); diff --git a/app/javascript/flavours/glitch/util/emoji/unicode_to_unified_name.js b/app/javascript/flavours/glitch/util/emoji/unicode_to_unified_name.js index 808ac197e..d29550f12 100644 --- a/app/javascript/flavours/glitch/util/emoji/unicode_to_unified_name.js +++ b/app/javascript/flavours/glitch/util/emoji/unicode_to_unified_name.js @@ -2,16 +2,20 @@ function padLeft(str, num) { while (str.length < num) { str = '0' + str; } + return str; } exports.unicodeToUnifiedName = (str) => { let output = ''; + for (let i = 0; i < str.length; i += 2) { if (i > 0) { output += '-'; } + output += padLeft(str.codePointAt(i).toString(16).toUpperCase(), 4); } + return output; }; -- cgit