39 lines
953 B
Vue
39 lines
953 B
Vue
<template>
|
|
<!-- Iconify Icons -->
|
|
<Icon v-if="isIconName(name)" :name="name" :size="size" />
|
|
<!-- Emojis -->
|
|
<span
|
|
v-else-if="isEmoji(name)"
|
|
:style="`font-size: ${size}px;`"
|
|
>{{ name }}</span>
|
|
<!-- Link -->
|
|
<NuxtImg
|
|
v-else
|
|
:src="name"
|
|
:style="`width: ${size}px; height: ${size}px;`"
|
|
class="inline"
|
|
/>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
const { size = 16 } = defineProps<{
|
|
name: string;
|
|
size?: number;
|
|
}>();
|
|
|
|
function isIconName(name: string): boolean {
|
|
if (name.includes('http'))
|
|
return false;
|
|
|
|
// 简单的图标名称检查,以 i- 开头或包含常见图标集
|
|
return name.startsWith('i-') ||
|
|
name.includes('lucide') ||
|
|
name.includes('heroicons') ||
|
|
name.includes('simple-icons');
|
|
}
|
|
|
|
function isEmoji(name: string): boolean {
|
|
return /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g.test(name);
|
|
}
|
|
</script>
|