2018-11-05 02:19:40 +00:00
|
|
|
<template>
|
2020-12-28 08:00:31 +00:00
|
|
|
<img v-if="customEmoji" class="mk-emoji custom" :class="{ normal, noStyle }" :src="url" :alt="alt" :title="alt" decoding="async"/>
|
|
|
|
<img v-else-if="char && !useOsNativeEmojis" class="mk-emoji" :src="url" :alt="alt" :title="alt" decoding="async"/>
|
2020-02-12 18:11:37 +00:00
|
|
|
<span v-else-if="char && useOsNativeEmojis">{{ char }}</span>
|
2020-11-08 03:08:07 +00:00
|
|
|
<span v-else>{{ emoji }}</span>
|
2018-11-05 02:19:40 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 11:12:00 +00:00
|
|
|
import { defineComponent } from 'vue';
|
2021-03-23 08:30:14 +00:00
|
|
|
import { getStaticImageUrl } from '@client/scripts/get-static-image-url';
|
|
|
|
import { twemojiSvgBase } from '@client/../misc/twemoji-base';
|
2018-11-05 07:19:10 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2018-11-05 04:23:26 +00:00
|
|
|
props: {
|
2018-11-05 10:20:35 +00:00
|
|
|
emoji: {
|
2018-11-05 06:15:30 +00:00
|
|
|
type: String,
|
2020-11-08 03:08:07 +00:00
|
|
|
required: true
|
2018-11-05 04:23:26 +00:00
|
|
|
},
|
2018-12-06 01:02:04 +00:00
|
|
|
normal: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
noStyle: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2018-11-05 04:23:26 +00:00
|
|
|
customEmojis: {
|
2018-11-05 10:20:35 +00:00
|
|
|
required: false,
|
2018-11-12 15:12:55 +00:00
|
|
|
default: () => []
|
2019-03-17 15:03:57 +00:00
|
|
|
},
|
|
|
|
isReaction: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2018-11-05 04:23:26 +00:00
|
|
|
},
|
2018-11-05 10:20:35 +00:00
|
|
|
|
2018-11-05 02:19:40 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
url: null,
|
2018-11-05 10:20:35 +00:00
|
|
|
char: null,
|
|
|
|
customEmoji: null
|
2018-11-05 02:19:40 +00:00
|
|
|
}
|
|
|
|
},
|
2018-11-05 10:20:35 +00:00
|
|
|
|
|
|
|
computed: {
|
2020-11-08 03:08:07 +00:00
|
|
|
isCustom(): boolean {
|
|
|
|
return this.emoji.startsWith(':');
|
|
|
|
},
|
|
|
|
|
2018-11-05 10:20:35 +00:00
|
|
|
alt(): string {
|
2018-11-05 10:33:28 +00:00
|
|
|
return this.customEmoji ? `:${this.customEmoji.name}:` : this.char;
|
2018-11-05 10:20:35 +00:00
|
|
|
},
|
|
|
|
|
2020-02-12 18:11:37 +00:00
|
|
|
useOsNativeEmojis(): boolean {
|
2020-12-19 01:55:52 +00:00
|
|
|
return this.$store.state.useOsNativeEmojis && !this.isReaction;
|
2020-02-10 14:17:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
ce() {
|
|
|
|
let ce = [];
|
|
|
|
if (this.customEmojis) ce = ce.concat(this.customEmojis);
|
2020-12-19 01:55:52 +00:00
|
|
|
if (this.$instance && this.$instance.emojis) ce = ce.concat(this.$instance.emojis);
|
2020-02-10 14:17:42 +00:00
|
|
|
return ce;
|
2018-11-05 10:20:35 +00:00
|
|
|
}
|
2018-11-05 02:19:40 +00:00
|
|
|
},
|
2018-11-05 10:20:35 +00:00
|
|
|
|
2019-07-05 08:58:54 +00:00
|
|
|
watch: {
|
2020-02-10 14:17:42 +00:00
|
|
|
ce: {
|
|
|
|
handler() {
|
2020-11-08 03:08:07 +00:00
|
|
|
if (this.isCustom) {
|
|
|
|
const customEmoji = this.ce.find(x => x.name === this.emoji.substr(1, this.emoji.length - 2));
|
2020-02-10 14:17:42 +00:00
|
|
|
if (customEmoji) {
|
|
|
|
this.customEmoji = customEmoji;
|
2020-12-19 01:55:52 +00:00
|
|
|
this.url = this.$store.state.disableShowingAnimatedImages
|
2020-02-10 14:17:42 +00:00
|
|
|
? getStaticImageUrl(customEmoji.url)
|
|
|
|
: customEmoji.url;
|
|
|
|
}
|
2019-07-05 08:58:54 +00:00
|
|
|
}
|
2020-02-10 14:17:42 +00:00
|
|
|
},
|
|
|
|
immediate: true
|
2019-07-05 08:58:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2018-11-05 10:20:35 +00:00
|
|
|
created() {
|
2020-11-08 03:08:07 +00:00
|
|
|
if (!this.isCustom) {
|
2018-11-05 10:20:35 +00:00
|
|
|
this.char = this.emoji;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.char) {
|
2018-12-07 08:21:34 +00:00
|
|
|
let codes = Array.from(this.char).map(x => x.codePointAt(0).toString(16));
|
2018-11-06 05:09:40 +00:00
|
|
|
if (!codes.includes('200d')) codes = codes.filter(x => x != 'fe0f');
|
2018-12-07 08:21:34 +00:00
|
|
|
codes = codes.filter(x => x && x.length);
|
2018-11-06 05:09:40 +00:00
|
|
|
|
2019-09-21 12:31:38 +00:00
|
|
|
this.url = `${twemojiSvgBase}/${codes.join('-')}.svg`;
|
2018-11-05 02:19:40 +00:00
|
|
|
}
|
2019-07-05 08:58:54 +00:00
|
|
|
},
|
2018-11-05 02:19:40 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-emoji {
|
|
|
|
height: 1.25em;
|
|
|
|
vertical-align: -0.25em;
|
2018-11-05 10:20:35 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&.custom {
|
|
|
|
height: 2.5em;
|
|
|
|
vertical-align: middle;
|
|
|
|
transition: transform 0.2s ease;
|
2018-11-05 12:04:19 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&:hover {
|
|
|
|
transform: scale(1.2);
|
|
|
|
}
|
2018-11-05 10:20:35 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&.normal {
|
|
|
|
height: 1.25em;
|
|
|
|
vertical-align: -0.25em;
|
2018-12-06 01:02:04 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&:hover {
|
|
|
|
transform: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-06 01:02:04 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&.noStyle {
|
|
|
|
height: auto !important;
|
|
|
|
}
|
|
|
|
}
|
2018-11-05 02:19:40 +00:00
|
|
|
</style>
|