import { SITE_BRAND_LOGO_TEXT_KEY, SITE_BRAND_LOGO_URL_KEY, SITE_THEME_STORAGE_KEY, resolveSiteTheme } from '../lib/site-theme-init.js' const siteSettingsFetchKey = 'site-settings-public' /** * 공개 사이트 설정에서 스플래시용 브랜드를 localStorage에 캐시한다. * @param {Object|null|undefined} settings - 사이트 설정 * @returns {void} */ const cacheSiteBrandForSplash = (settings) => { if (!settings?.logoUrl && !settings?.logoText) { return } if (settings.logoUrl) { localStorage.setItem(SITE_BRAND_LOGO_URL_KEY, settings.logoUrl) } if (settings.logoText) { localStorage.setItem(SITE_BRAND_LOGO_TEXT_KEY, settings.logoText) } } /** * 스플래시를 숨기고 본문을 표시한다. * @returns {void} */ const finishSiteSplash = () => { document.documentElement.classList.add('site-app-ready') } /** * 인증·관리자 경로는 스플래시 없이 즉시 본문을 연다. * @returns {boolean} */ const shouldSkipSiteSplash = () => /^\/(admin|signin|signup|forgot-password)(\/|$)/.test(window.location.pathname) export default defineNuxtPlugin((nuxtApp) => { const theme = useState('site-theme-mode', () => 'light') const savedTheme = localStorage.getItem(SITE_THEME_STORAGE_KEY) const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches theme.value = resolveSiteTheme(savedTheme, prefersDark) if (shouldSkipSiteSplash()) { finishSiteSplash() return } const { data: siteSettings } = useNuxtData(siteSettingsFetchKey) watch(siteSettings, (settings) => { cacheSiteBrandForSplash(settings) }, { immediate: true }) nuxtApp.hook('app:mounted', () => { requestAnimationFrame(() => { requestAnimationFrame(() => { finishSiteSplash() }) }) }) })