2022-12-28 04:06:54 +03:00
|
|
|
import type { FontSize } from '~/types'
|
|
|
|
import { InjectionKeyFontSize } from '~/constants/symbols'
|
2022-12-28 04:28:17 +03:00
|
|
|
import { COOKIE_KEY_FONT_SIZE, COOKIE_MAX_AGE } from '~/constants'
|
2022-12-28 04:06:54 +03:00
|
|
|
import { fontSizeMap } from '~/constants/options'
|
|
|
|
|
|
|
|
export default defineNuxtPlugin((nuxt) => {
|
|
|
|
const DEFAULT = 'md'
|
2022-12-28 04:28:17 +03:00
|
|
|
const cookieFontSize = useCookie<FontSize>(COOKIE_KEY_FONT_SIZE, { default: () => DEFAULT, maxAge: COOKIE_MAX_AGE })
|
2022-12-28 04:06:54 +03:00
|
|
|
nuxt.vueApp.provide(InjectionKeyFontSize, cookieFontSize)
|
|
|
|
|
|
|
|
if (!process.server) {
|
|
|
|
watchEffect(() => {
|
|
|
|
document.documentElement.style.setProperty('--font-size', fontSizeMap[cookieFontSize.value || DEFAULT])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
useHead({
|
|
|
|
style: [
|
|
|
|
{
|
|
|
|
innerHTML: `:root { --font-size: ${fontSizeMap[cookieFontSize.value || DEFAULT]}; }`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|