Files
sori.studio/lib/site-route-transition.js
zenn 4c8f6e44f6 페이지 전환 깜빡임 완화 및 레이아웃 통합 (v1.10.50)
- 게시물 상세를 default 레이아웃으로 통합해 홈↔게시물 레이아웃 교체 제거
- CSS 전환 베일·스크롤 정리 플러그인으로 이동 중 깜빡임 완화

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 14:28:24 +09:00

66 lines
1.6 KiB
JavaScript

/** @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
}