Files
estel_docs/app/components/content/ProseH1.vue
2025-08-15 01:13:08 +08:00

45 lines
1.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<h1
:id
:class="['scroll-m-20 font-extrabold tracking-tight', themeSizeClass]"
:style="themeTextShadowStyle"
>
<NuxtLink
v-if="generate"
:to="`#${id}`"
>
<slot />
</NuxtLink>
<slot v-else />
</h1>
</template>
<script setup lang="ts">
const { id } = defineProps<{ id?: string }>()
const { headings } = useRuntimeConfig().public.mdc
const generate = computed(() => id && ((typeof headings?.anchorLinks === 'boolean' && headings?.anchorLinks === true) || (typeof headings?.anchorLinks === 'object' && headings?.anchorLinks?.h1)))
// 读取主题,按主题做轻量风格差异:
// - classic: 无阴影,正常字号
// - elegant: 有文字阴影,正常字号
// - minimal: 无阴影,较小字号
const { selectedTheme } = useTheme()
// 这个计算属性 themeSizeClass 用于根据当前主题selectedTheme动态设置 h1 标题的字号样式:
// - 如果主题是 minimal则使用较小字号 'text-2xl lg:text-3xl'
// - 否则classic 或 elegant使用较大字号 'text-3xl lg:text-4xl'
const themeSizeClass = computed(() => {
return selectedTheme.value === 'classic'
? 'text-2xl lg:text-3xl underline decoration-3 decoration-primary dark:decoration-gray-700 underline-offset-8 mb-3'
: 'text-3xl lg:text-4xl'
})
const themeTextShadowStyle = computed(() => {
if (selectedTheme.value === 'elegant') {
return { textShadow: '0 2px 8px rgba(0,0,0,0.15)' }
}
return { textShadow: 'none' }
})
</script>