2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-12-26 08:04:56 +01:00
|
|
|
const twemojiSvgBase = '/twemoji';
|
|
|
|
const fluentEmojiPngBase = '/fluent-emoji';
|
2024-01-04 20:42:25 +01:00
|
|
|
const tossfaceSvgBase = '/tossface';
|
2022-12-26 08:04:56 +01:00
|
|
|
|
|
|
|
export function char2twemojiFilePath(char: string): string {
|
2023-07-25 12:46:52 +02:00
|
|
|
let codes = Array.from(char, x => x.codePointAt(0)?.toString(16));
|
2022-12-26 08:04:56 +01:00
|
|
|
if (!codes.includes('200d')) codes = codes.filter(x => x !== 'fe0f');
|
|
|
|
codes = codes.filter(x => x && x.length);
|
|
|
|
const fileName = codes.join('-');
|
|
|
|
return `${twemojiSvgBase}/${fileName}.svg`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function char2fluentEmojiFilePath(char: string): string {
|
2023-07-25 12:46:52 +02:00
|
|
|
let codes = Array.from(char, x => x.codePointAt(0)?.toString(16));
|
2022-12-26 08:04:56 +01:00
|
|
|
// Fluent Emojiは国旗非対応 https://github.com/microsoft/fluentui-emoji/issues/25
|
|
|
|
if (codes[0]?.startsWith('1f1')) return char2twemojiFilePath(char);
|
|
|
|
if (!codes.includes('200d')) codes = codes.filter(x => x !== 'fe0f');
|
2024-09-10 11:39:53 +02:00
|
|
|
codes = codes.filter(x => x != null && x.length > 0);
|
|
|
|
const fileName = (codes as string[]).map(x => x.padStart(4, '0')).join('-');
|
2022-12-26 08:04:56 +01:00
|
|
|
return `${fluentEmojiPngBase}/${fileName}.png`;
|
|
|
|
}
|
2024-01-04 20:42:25 +01:00
|
|
|
|
|
|
|
export function char2tossfaceFilePath(char: string): string {
|
|
|
|
let codes = Array.from(char, x => x.codePointAt(0)?.toString(16));
|
|
|
|
// Twemoji is the only emoji font which still supports the shibuya 50 emoji to this day
|
|
|
|
if (codes[0]?.startsWith('e50a')) return char2twemojiFilePath(char);
|
|
|
|
// Tossface does not use the fe0f modifier
|
|
|
|
codes = codes.filter(x => x !== 'fe0f');
|
|
|
|
codes = codes.filter(x => x && x.length);
|
|
|
|
const fileName = codes.join('-');
|
|
|
|
return `${tossfaceSvgBase}/${fileName}.svg`;
|
|
|
|
}
|