2018-11-04 18:19:40 -08:00
|
|
|
<template>
|
|
|
|
<img class="mk-emoji" :src="url" :alt="alt || name" :title="name">
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import { lib } from 'emojilib';
|
2018-11-04 23:19:10 -08:00
|
|
|
|
|
|
|
const findCustomEmoji = (x, emoji) =>
|
|
|
|
x.name === emoji ||
|
|
|
|
x.aliases && x.aliases.includes(emoji);
|
|
|
|
|
2018-11-04 18:19:40 -08:00
|
|
|
export default Vue.extend({
|
2018-11-04 20:23:26 -08:00
|
|
|
props: {
|
|
|
|
emoji: {
|
|
|
|
type: String,
|
2018-11-04 22:15:30 -08:00
|
|
|
required: false
|
|
|
|
},
|
|
|
|
raw: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
2018-11-04 20:23:26 -08:00
|
|
|
},
|
|
|
|
customEmojis: {
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
},
|
2018-11-04 18:19:40 -08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
url: null,
|
|
|
|
alt: null,
|
|
|
|
name: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$nextTick(() => this.exec());
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
exec() {
|
2018-11-04 22:15:30 -08:00
|
|
|
const { emoji, raw, customEmojis } = this;
|
2018-11-05 00:04:17 -08:00
|
|
|
this.name = emoji ? `:${emoji}:` : raw;
|
|
|
|
if (!raw && customEmojis && customEmojis.length) {
|
2018-11-04 23:19:10 -08:00
|
|
|
this.url = customEmojis.find(x => findCustomEmoji(x, emoji)).url;
|
2018-11-05 00:04:17 -08:00
|
|
|
} else { // *MEM: `customEmojis` always has a emoji named `emoji`
|
2018-11-04 22:15:30 -08:00
|
|
|
const char = raw || lib[emoji] && lib[emoji].char;
|
2018-11-04 18:19:40 -08:00
|
|
|
if (char) {
|
|
|
|
this.url = `https://twemoji.maxcdn.com/2/svg/${char.codePointAt(0).toString(16)}.svg`;
|
|
|
|
this.alt = char;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.mk-emoji
|
|
|
|
height 2.5em
|
|
|
|
vertical-align middle
|
|
|
|
</style>
|