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-07-16 06:14:16 +02:00
|
|
|
<template>
|
2023-11-05 10:01:51 +01:00
|
|
|
<img v-if="!useOsNativeEmojis" :class="$style.root" :src="url" :alt="props.emoji" decoding="async" @pointerenter="computeTitle" @click="onClick"/>
|
2024-01-07 08:02:53 +01:00
|
|
|
<span v-else :alt="props.emoji" @pointerenter="computeTitle" @click="onClick">{{ colorizedNativeEmoji }}</span>
|
2018-11-05 03:19:40 +01:00
|
|
|
</template>
|
|
|
|
|
2022-07-16 06:14:16 +02:00
|
|
|
<script lang="ts" setup>
|
2023-11-05 10:01:51 +01:00
|
|
|
import { computed, inject } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { char2twemojiFilePath, char2fluentEmojiFilePath } from '@/scripts/emoji-base.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2024-01-07 08:02:53 +01:00
|
|
|
import { colorizeEmoji, getEmojiName } from '@/scripts/emojilist.js';
|
2023-11-05 10:01:51 +01:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
2023-12-13 00:15:25 +01:00
|
|
|
import * as sound from '@/scripts/sound.js';
|
2023-11-05 10:01:51 +01:00
|
|
|
import { i18n } from '@/i18n.js';
|
2018-11-05 08:19:10 +01:00
|
|
|
|
2022-07-16 06:14:16 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
emoji: string;
|
2023-11-05 10:01:51 +01:00
|
|
|
menu?: boolean;
|
|
|
|
menuReaction?: boolean;
|
2022-07-16 06:14:16 +02:00
|
|
|
}>();
|
2018-11-05 11:20:35 +01:00
|
|
|
|
2023-11-05 10:01:51 +01:00
|
|
|
const react = inject<((name: string) => void) | null>('react', null);
|
|
|
|
|
2022-12-26 08:04:56 +01:00
|
|
|
const char2path = defaultStore.state.emojiStyle === 'twemoji' ? char2twemojiFilePath : char2fluentEmojiFilePath;
|
|
|
|
|
2023-01-26 07:48:12 +01:00
|
|
|
const useOsNativeEmojis = computed(() => defaultStore.state.emojiStyle === 'native');
|
2024-01-07 08:02:53 +01:00
|
|
|
const url = computed(() => char2path(props.emoji));
|
|
|
|
const colorizedNativeEmoji = computed(() => colorizeEmoji(props.emoji));
|
2022-12-25 07:52:52 +01:00
|
|
|
|
2022-12-25 08:03:21 +01:00
|
|
|
// Searching from an array with 2000 items for every emoji felt like too energy-consuming, so I decided to do it lazily on pointerenter
|
2022-12-25 07:52:52 +01:00
|
|
|
function computeTitle(event: PointerEvent): void {
|
2023-01-26 07:48:12 +01:00
|
|
|
const title = getEmojiName(props.emoji as string) ?? props.emoji as string;
|
2022-12-25 07:52:52 +01:00
|
|
|
(event.target as HTMLElement).title = title;
|
|
|
|
}
|
2023-11-05 10:01:51 +01:00
|
|
|
|
|
|
|
function onClick(ev: MouseEvent) {
|
|
|
|
if (props.menu) {
|
|
|
|
os.popupMenu([{
|
|
|
|
type: 'label',
|
|
|
|
text: props.emoji,
|
|
|
|
}, {
|
|
|
|
text: i18n.ts.copy,
|
|
|
|
icon: 'ti ti-copy',
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(props.emoji);
|
|
|
|
os.success();
|
|
|
|
},
|
|
|
|
}, ...(props.menuReaction && react ? [{
|
|
|
|
text: i18n.ts.doReaction,
|
|
|
|
icon: 'ti ti-plus',
|
|
|
|
action: () => {
|
|
|
|
react(props.emoji);
|
2024-01-09 05:25:33 +01:00
|
|
|
sound.playMisskeySfx('reaction');
|
2023-11-05 10:01:51 +01:00
|
|
|
},
|
|
|
|
}] : [])], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
}
|
2018-11-05 03:19:40 +01:00
|
|
|
</script>
|
|
|
|
|
2023-01-09 21:17:54 +01:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-01-29 20:37:25 +01:00
|
|
|
height: 1.25em;
|
|
|
|
vertical-align: -0.25em;
|
2023-01-09 21:17:54 +01:00
|
|
|
}
|
2018-11-05 03:19:40 +01:00
|
|
|
</style>
|