forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite
emoji_unicode_mapping_light
to TS (mastodon#25444)
Co-authored-by: taichi.fukuda ひ <taichi.fukuda@systemi.co.jp>
- Loading branch information
1 parent
e93a75f
commit 9482810
Showing
7 changed files
with
76 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
app/javascript/mastodon/features/emoji/emoji_unicode_mapping_light.js
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
app/javascript/mastodon/features/emoji/emoji_unicode_mapping_light.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// A mapping of unicode strings to an object containing the filename | ||
// (i.e. the svg filename) and a shortCode intended to be shown | ||
// as a "title" attribute in an HTML element (aka tooltip). | ||
|
||
import type { | ||
FilenameData, | ||
ShortCodesToEmojiDataKey, | ||
} from './emoji_compressed'; | ||
import emojiCompressed from './emoji_compressed'; | ||
import { unicodeToFilename } from './unicode_to_filename'; | ||
|
||
type UnicodeMapping = { | ||
[key in FilenameData[number][0]]: { | ||
shortCode: ShortCodesToEmojiDataKey; | ||
filename: FilenameData[number][number]; | ||
}; | ||
}; | ||
|
||
const [ | ||
shortCodesToEmojiData, | ||
_skins, | ||
_categories, | ||
_short_names, | ||
emojisWithoutShortCodes, | ||
] = emojiCompressed; | ||
|
||
// decompress | ||
const unicodeMapping: UnicodeMapping = {}; | ||
|
||
function processEmojiMapData( | ||
emojiMapData: FilenameData[number], | ||
shortCode?: ShortCodesToEmojiDataKey, | ||
) { | ||
const [native, _filename] = emojiMapData; | ||
let filename = emojiMapData[1]; | ||
if (!filename) { | ||
// filename name can be derived from unicodeToFilename | ||
filename = unicodeToFilename(native); | ||
} | ||
unicodeMapping[native] = { | ||
shortCode, | ||
filename, | ||
}; | ||
} | ||
|
||
Object.keys(shortCodesToEmojiData).forEach( | ||
(shortCode: ShortCodesToEmojiDataKey) => { | ||
if (shortCode === undefined) return; | ||
const [filenameData, _searchData] = shortCodesToEmojiData[shortCode]; | ||
filenameData.forEach((emojiMapData) => { | ||
processEmojiMapData(emojiMapData, shortCode); | ||
}); | ||
}, | ||
); | ||
|
||
emojisWithoutShortCodes.forEach((emojiMapData) => { | ||
processEmojiMapData(emojiMapData); | ||
}); | ||
|
||
export { unicodeMapping }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters