/** @type {{ top: number, left: number } | null} */ let pendingScrollRestore = null /** * 뒤로가기 스크롤 복원 좌표를 저장한다. * @param {{ top?: number, left?: number }} position - 복원 좌표 * @returns {void} */ export const setPendingScrollRestore = (position) => { pendingScrollRestore = { top: Number(position?.top || 0), left: Number(position?.left || 0) } } /** * 저장된 스크롤 복원 좌표를 꺼낸다. * @returns {{ top: number, left: number } | null} */ export const consumePendingScrollRestore = () => { const position = pendingScrollRestore pendingScrollRestore = null return position } /** * 공개 사이트 경로에서 전환 베일을 사용할지 판별한다. * @param {string} path - 라우트 경로 * @returns {boolean} */ export const shouldUseSiteRouteVeil = (path) => { const clean = String(path || '').split('?')[0].split('#')[0] return !clean.startsWith('/admin') } /** * 문서 스크롤을 최상단으로 이동한다. * @returns {void} */ export const scrollDocumentToTop = () => { if (!import.meta.client) { return } window.scrollTo(0, 0) document.documentElement.scrollTop = 0 document.body.scrollTop = 0 } /** * 문서 스크롤을 지정 좌표로 이동한다. * @param {{ top?: number, left?: number }} position - 복원 좌표 * @returns {void} */ export const scrollDocumentTo = (position) => { if (!import.meta.client) { return } const top = Number(position?.top || 0) const left = Number(position?.left || 0) window.scrollTo(left, top) document.documentElement.scrollTop = top document.body.scrollTop = top }