yumechi-no-kuni/packages/frontend/src/components/MkMention.vue

61 lines
1.4 KiB
Vue
Raw Normal View History

2018-12-11 22:06:05 -06:00
<template>
2023-01-14 05:31:48 -06:00
<MkA v-user-preview="canonical" :class="[$style.root, { [$style.isMe]: isMe }]" :to="url" :style="{ background: bgCss }">
<img :class="$style.icon" :src="`/avatar/@${username}@${host}`" alt="">
<span>
<span :class="$style.username">@{{ username }}</span>
<span v-if="(host != localHost) || $store.state.showFullAcct" :class="$style.host">@{{ toUnicode(host) }}</span>
2018-12-11 22:06:05 -06:00
</span>
</MkA>
2018-12-11 22:06:05 -06:00
</template>
2022-06-23 20:34:36 -05:00
<script lang="ts" setup>
2021-10-31 06:19:49 -05:00
import { toUnicode } from 'punycode';
import { } from 'vue';
2022-06-23 20:34:36 -05:00
import tinycolor from 'tinycolor2';
2021-11-11 11:02:25 -06:00
import { host as localHost } from '@/config';
import { $i } from '@/account';
2018-12-11 22:06:05 -06:00
2022-06-23 20:34:36 -05:00
const props = defineProps<{
username: string;
host: string;
}>();
2021-10-31 06:19:49 -05:00
2022-06-23 20:34:36 -05:00
const canonical = props.host === localHost ? `@${props.username}` : `@${props.username}@${toUnicode(props.host)}`;
2021-10-31 06:19:49 -05:00
2022-06-23 20:34:36 -05:00
const url = `/${canonical}`;
2021-10-31 06:19:49 -05:00
2022-06-23 20:34:36 -05:00
const isMe = $i && (
`@${props.username}@${toUnicode(props.host)}` === `@${$i.username}@${toUnicode(localHost)}`.toLowerCase()
);
2021-10-31 06:19:49 -05:00
2022-06-23 20:34:36 -05:00
const bg = tinycolor(getComputedStyle(document.documentElement).getPropertyValue(isMe ? '--mentionMe' : '--mention'));
bg.setAlpha(0.1);
const bgCss = bg.toRgbString();
2018-12-11 22:06:05 -06:00
</script>
2023-01-14 05:31:48 -06:00
<style lang="scss" module>
.root {
2021-10-31 06:19:49 -05:00
display: inline-block;
padding: 4px 8px 4px 4px;
border-radius: 999px;
color: var(--mention);
2020-06-04 08:19:08 -05:00
&.isMe {
color: var(--mentionMe);
}
2023-01-14 05:31:48 -06:00
}
2018-12-11 22:06:05 -06:00
2023-01-14 05:31:48 -06:00
.icon {
width: 1.5em;
height: 1.5em;
object-fit: cover;
margin: 0 0.2em 0 0;
vertical-align: bottom;
border-radius: 100%;
}
2023-01-14 05:31:48 -06:00
.host {
opacity: 0.5;
}
2018-12-11 22:06:05 -06:00
</style>