diff --git a/web/image_conveyor_drag_math.mjs b/web/image_conveyor_drag_math.mjs index 7c5055d..03b2e73 100644 --- a/web/image_conveyor_drag_math.mjs +++ b/web/image_conveyor_drag_math.mjs @@ -49,3 +49,21 @@ export function cardIntentInsertionIndex(items, draggedId, targetId) { export function materializationNeedsLibraryRefresh(payload) { return Array.isArray(payload?.moved) && payload.moved.length > 0 } + +export function libraryRefreshScrollRestore( + view, + savedScrollTop, + liveScrollTop, + clientWidth, + clientHeight +) { + const normalizedView = String(view ?? '') + if (!normalizedView) return null + const visible = Number(clientWidth) > 0 && Number(clientHeight) > 0 + const live = Number(liveScrollTop) + const saved = Number(savedScrollTop) + const scrollTop = visible && Number.isFinite(live) + ? live + : (Number.isFinite(saved) ? saved : 0) + return { view: normalizedView, scrollTop: Math.max(0, scrollTop) } +}