2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2023-01-26 07:48:12 +01:00
|
|
|
<template>
|
|
|
|
<span v-if="errored">:{{ customEmojiName }}:</span>
|
|
|
|
<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"/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed } from 'vue';
|
2023-04-12 03:58:56 +02:00
|
|
|
import { getProxiedImageUrl, getStaticImageUrl } from '@/scripts/media-proxy';
|
2023-01-26 07:48:12 +01:00
|
|
|
import { defaultStore } from '@/store';
|
2023-05-31 05:42:24 +02:00
|
|
|
import { customEmojisMap } from '@/custom-emojis';
|
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-01-26 07:48:12 +01:00
|
|
|
}>();
|
|
|
|
|
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(() => {
|
|
|
|
if (rawUrl.value == null) return null;
|
|
|
|
|
|
|
|
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}:`);
|
|
|
|
let errored = $ref(url.value == null);
|
|
|
|
</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>
|