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