calckey/src/client/app/common/views/components/emoji.vue

122 lines
2.6 KiB
Vue
Raw Normal View History

2018-11-05 02:19:40 +00:00
<template>
<img v-if="customEmoji" class="fvgwvorwhxigeolkkrcderjzcawqrscl custom" :class="{ normal: normal }" :src="url" :alt="alt" :title="alt"/>
<img v-else-if="char && !useOsDefaultEmojis" class="fvgwvorwhxigeolkkrcderjzcawqrscl" :src="url" :alt="alt" :title="alt"/>
<span v-else-if="char && useOsDefaultEmojis">{{ char }}</span>
<span v-else>:{{ name }}:</span>
2018-11-05 02:19:40 +00:00
</template>
<script lang="ts">
import Vue from 'vue';
// スクリプトサイズがデカい
//import { lib } from 'emojilib';
import { getStaticImageUrl } from '../../../common/scripts/get-static-image-url';
2019-03-18 13:02:45 +00:00
import { twemojiBase } from '../../../../../misc/twemoji-base';
2018-11-05 02:19:40 +00:00
export default Vue.extend({
props: {
name: {
type: String,
required: false
},
emoji: {
type: String,
required: false
},
normal: {
type: Boolean,
required: false,
default: false
},
customEmojis: {
required: false,
2018-11-12 15:12:55 +00:00
default: () => []
},
isReaction: {
type: Boolean,
default: false
},
},
2018-11-05 02:19:40 +00:00
data() {
return {
url: null,
char: null,
customEmoji: null
2018-11-05 02:19:40 +00:00
}
},
computed: {
alt(): string {
2018-11-05 10:33:28 +00:00
return this.customEmoji ? `:${this.customEmoji.name}:` : this.char;
},
useOsDefaultEmojis(): boolean {
return this.$store.state.device.useOsDefaultEmojis && !this.isReaction;
}
2018-11-05 02:19:40 +00:00
},
watch: {
customEmojis() {
if (this.name) {
const customEmoji = this.customEmojis.find(x => x.name == this.name);
if (customEmoji) {
this.customEmoji = customEmoji;
this.url = this.$store.state.device.disableShowingAnimatedImages
? getStaticImageUrl(customEmoji.url)
: customEmoji.url;
}
}
},
},
created() {
if (this.name) {
const customEmoji = this.customEmojis.find(x => x.name == this.name);
if (customEmoji) {
this.customEmoji = customEmoji;
2019-02-04 19:09:44 +00:00
this.url = this.$store.state.device.disableShowingAnimatedImages
? getStaticImageUrl(customEmoji.url)
: customEmoji.url;
} else {
//const emoji = lib[this.name];
//if (emoji) {
// this.char = emoji.char;
//}
2018-11-05 02:19:40 +00:00
}
} else {
this.char = this.emoji;
}
if (this.char) {
let codes = Array.from(this.char).map(x => x.codePointAt(0).toString(16));
if (!codes.includes('200d')) codes = codes.filter(x => x != 'fe0f');
codes = codes.filter(x => x && x.length);
2019-03-18 13:02:45 +00:00
this.url = `${twemojiBase}/2/svg/${codes.join('-')}.svg`;
2018-11-05 02:19:40 +00:00
}
},
2018-11-05 02:19:40 +00:00
});
</script>
<style lang="stylus" scoped>
.fvgwvorwhxigeolkkrcderjzcawqrscl
2018-11-05 16:48:33 +00:00
height 1.25em
vertical-align -0.25em
&.custom
height 2.5em
vertical-align middle
transition transform 0.2s ease
&:hover
transform scale(1.2)
&.normal
height 1.25em
vertical-align -0.25em
&:hover
transform none
2018-11-05 02:19:40 +00:00
</style>