egirlskey/packages/frontend/src/components/MkMention.vue

73 lines
1.9 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
2018-12-12 04:06:05 +00:00
<template>
<MkA v-user-preview="canonical" :class="[$style.root, { [$style.isMe]: isMe }]" :to="url" :style="{ background: bgCss }">
<img :class="$style.icon" :src="avatarUrl" alt="">
2023-01-14 11:31:48 +00:00
<span>
<span>@{{ username }}</span>
2023-04-01 04:42:40 +00:00
<span v-if="(host != localHost) || defaultStore.state.showFullAcct" :class="$style.host">@{{ toUnicode(host) }}</span>
2018-12-12 04:06:05 +00:00
</span>
</MkA>
2018-12-12 04:06:05 +00:00
</template>
2022-06-24 01:34:36 +00:00
<script lang="ts" setup>
2021-10-31 11:19:49 +00:00
import { toUnicode } from 'punycode';
import { computed } from 'vue';
2022-06-24 01:34:36 +00:00
import tinycolor from 'tinycolor2';
2023-09-19 07:37:43 +00:00
import { host as localHost } from '@/config.js';
import { $i } from '@/account.js';
import { defaultStore } from '@/store.js';
import { getStaticImageUrl } from '@/scripts/media-proxy.js';
2018-12-12 04:06:05 +00:00
2022-06-24 01:34:36 +00:00
const props = defineProps<{
username: string;
host: string;
}>();
2021-10-31 11:19:49 +00:00
2022-06-24 01:34:36 +00:00
const canonical = props.host === localHost ? `@${props.username}` : `@${props.username}@${toUnicode(props.host)}`;
2021-10-31 11:19:49 +00:00
2022-06-24 01:34:36 +00:00
const url = `/${canonical}`;
2021-10-31 11:19:49 +00:00
2022-06-24 01:34:36 +00:00
const isMe = $i && (
`@${props.username}@${toUnicode(props.host)}` === `@${$i.username}@${toUnicode(localHost)}`.toLowerCase()
);
2021-10-31 11:19:49 +00:00
2022-06-24 01:34:36 +00:00
const bg = tinycolor(getComputedStyle(document.documentElement).getPropertyValue(isMe ? '--mentionMe' : '--mention'));
bg.setAlpha(0.1);
const bgCss = bg.toRgbString();
const avatarUrl = computed(() => defaultStore.state.disableShowingAnimatedImages
? getStaticImageUrl(`/avatar/@${props.username}@${props.host}`)
: `/avatar/@${props.username}@${props.host}`,
);
2018-12-12 04:06:05 +00:00
</script>
2023-01-14 11:31:48 +00:00
<style lang="scss" module>
.root {
2021-10-31 11:19:49 +00:00
display: inline-block;
padding: 4px 8px 4px 4px;
border-radius: var(--radius-ellipse);
color: var(--mention);
2020-06-04 13:19:08 +00:00
&.isMe {
color: var(--mentionMe);
}
2023-01-14 11:31:48 +00:00
}
2018-12-12 04:06:05 +00:00
2023-01-14 11:31:48 +00:00
.icon {
width: 1.5em;
height: 1.5em;
object-fit: cover;
margin: 0 0.2em 0 0;
vertical-align: bottom;
border-radius: var(--radius-full);
2023-01-14 11:31:48 +00:00
}
2023-01-14 11:31:48 +00:00
.host {
opacity: 0.5;
}
2018-12-12 04:06:05 +00:00
</style>