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' /** * 공개 사이트 설정에서 스플래시용 로고 이미지 URL만 localStorage에 캐시한다. * logoText(井 등)는 헤더 이미지 없을 때 짧은 기호용이며 스플래시·브랜드명과 무관하다. * @param {Object|null|undefined} settings - 사이트 설정 * @returns {void} */ const cacheSiteBrandForSplash = (settings) => { try { localStorage.removeItem(SITE_BRAND_LOGO_TEXT_KEY) } catch { // ignore } if (!settings?.logoUrl) { return } localStorage.setItem(SITE_BRAND_LOGO_URL_KEY, settings.logoUrl) } /** * 스플래시를 숨기고 본문을 표시한다. * @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() }) }) }) })