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
|
|
|
|
-->
|
|
|
|
|
2023-01-26 07:48:12 +01:00
|
|
|
<template>
|
|
|
|
<span v-if="errored">:{{ customEmojiName }}:</span>
|
2023-11-04 10:27:22 +01:00
|
|
|
<img
|
|
|
|
v-else
|
|
|
|
:class="[$style.root, { [$style.normal]: normal, [$style.noStyle]: noStyle }]"
|
|
|
|
:src="url"
|
|
|
|
:alt="alt"
|
|
|
|
:title="alt"
|
|
|
|
decoding="async"
|
|
|
|
@error="errored = true"
|
|
|
|
@load="errored = false"
|
|
|
|
@click="onClick"
|
|
|
|
/>
|
2023-01-26 07:48:12 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { computed, inject, ref } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { customEmojisMap } from '@/custom-emojis.js';
|
2023-11-04 10:27:22 +01:00
|
|
|
import * as os from '@/os.js';
|
2024-01-13 07:25:11 +01:00
|
|
|
import { misskeyApiGet } from '@/scripts/misskey-api.js';
|
2023-11-04 10:27:22 +01:00
|
|
|
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-04 10:27:22 +01:00
|
|
|
import { i18n } from '@/i18n.js';
|
2024-01-13 07:25:11 +01:00
|
|
|
import MkCustomEmojiDetailedDialog from '@/components/MkCustomEmojiDetailedDialog.vue';
|
2023-01-26 07:48:12 +01:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
name: string;
|
|
|
|
normal?: boolean;
|
|
|
|
noStyle?: boolean;
|
|
|
|
host?: string | null;
|
|
|
|
url?: string;
|
2023-04-12 03:58:56 +02:00
|
|
|
useOriginalSize?: boolean;
|
2023-11-04 10:27:22 +01:00
|
|
|
menu?: boolean;
|
|
|
|
menuReaction?: boolean;
|
2023-01-26 07:48:12 +01:00
|
|
|
}>();
|
|
|
|
|
2023-11-04 10:27:22 +01:00
|
|
|
const react = inject<((name: string) => void) | null>('react', null);
|
|
|
|
|
2023-07-14 00:59:54 +02:00
|
|
|
const customEmojiName = computed(() => (props.name[0] === ':' ? props.name.substring(1, props.name.length - 1) : props.name).replace('@.', ''));
|
2023-04-12 03:58:56 +02:00
|
|
|
const isLocal = computed(() => !props.host && (customEmojiName.value.endsWith('@.') || !customEmojiName.value.includes('@')));
|
2023-02-03 21:37:15 +01:00
|
|
|
|
|
|
|
const rawUrl = computed(() => {
|
2023-01-26 07:48:12 +01:00
|
|
|
if (props.url) {
|
|
|
|
return props.url;
|
|
|
|
}
|
2023-04-12 03:58:56 +02:00
|
|
|
if (isLocal.value) {
|
2023-05-31 05:42:24 +02:00
|
|
|
return customEmojisMap.get(customEmojiName.value)?.url ?? null;
|
2023-02-03 21:37:15 +01:00
|
|
|
}
|
|
|
|
return props.host ? `/emoji/${customEmojiName.value}@${props.host}.webp` : `/emoji/${customEmojiName.value}.webp`;
|
2023-01-26 07:48:12 +01:00
|
|
|
});
|
2023-02-03 21:37:15 +01:00
|
|
|
|
2023-04-12 03:58:56 +02:00
|
|
|
const url = computed(() => {
|
2024-01-30 11:53:53 +01:00
|
|
|
if (rawUrl.value == null) return undefined;
|
2023-04-12 03:58:56 +02:00
|
|
|
|
|
|
|
const proxied =
|
|
|
|
(rawUrl.value.startsWith('/emoji/') || (props.useOriginalSize && isLocal.value))
|
|
|
|
? rawUrl.value
|
|
|
|
: getProxiedImageUrl(
|
|
|
|
rawUrl.value,
|
|
|
|
props.useOriginalSize ? undefined : 'emoji',
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
return defaultStore.reactiveState.disableShowingAnimatedImages.value
|
|
|
|
? getStaticImageUrl(proxied)
|
|
|
|
: proxied;
|
|
|
|
});
|
2023-02-03 21:37:15 +01:00
|
|
|
|
2023-01-26 07:48:12 +01:00
|
|
|
const alt = computed(() => `:${customEmojiName.value}:`);
|
2023-12-07 06:42:09 +01:00
|
|
|
const errored = ref(url.value == null);
|
2023-11-04 10:27:22 +01:00
|
|
|
|
|
|
|
function onClick(ev: MouseEvent) {
|
|
|
|
if (props.menu) {
|
|
|
|
os.popupMenu([{
|
|
|
|
type: 'label',
|
|
|
|
text: `:${props.name}:`,
|
|
|
|
}, {
|
|
|
|
text: i18n.ts.copy,
|
|
|
|
icon: 'ti ti-copy',
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`:${props.name}:`);
|
|
|
|
os.success();
|
|
|
|
},
|
|
|
|
}, ...(props.menuReaction && react ? [{
|
|
|
|
text: i18n.ts.doReaction,
|
|
|
|
icon: 'ti ti-plus',
|
|
|
|
action: () => {
|
|
|
|
react(`:${props.name}:`);
|
2024-01-09 05:25:33 +01:00
|
|
|
sound.playMisskeySfx('reaction');
|
2023-11-04 10:27:22 +01:00
|
|
|
},
|
2024-01-13 07:25:11 +01:00
|
|
|
}] : []), {
|
|
|
|
text: i18n.ts.info,
|
|
|
|
icon: 'ti ti-info-circle',
|
|
|
|
action: async () => {
|
|
|
|
os.popup(MkCustomEmojiDetailedDialog, {
|
|
|
|
emoji: await misskeyApiGet('emoji', {
|
|
|
|
name: customEmojiName.value,
|
|
|
|
}),
|
|
|
|
}, {
|
|
|
|
anchor: ev.target,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
2023-11-04 10:27:22 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-26 07:48:12 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2023-02-23 07:42:57 +01:00
|
|
|
height: 2em;
|
2023-01-26 07:48:12 +01:00
|
|
|
vertical-align: middle;
|
|
|
|
transition: transform 0.2s ease;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
transform: scale(1.2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.normal {
|
|
|
|
height: 1.25em;
|
|
|
|
vertical-align: -0.25em;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
transform: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.noStyle {
|
|
|
|
height: auto !important;
|
|
|
|
}
|
|
|
|
</style>
|