import {PlainScroll} from "../Scroll"; export function createAutoScrollManager(getScroll: () => PlainScroll | null | undefined) { const _state = { value: null as null | 'top' | 'bottom' | 'left' | 'right' }; const handler = { top: () => { getScroll()?.methods.autoScrollTop(); }, bottom: () => { getScroll()?.methods.autoScrollBottom(); }, left: () => { getScroll()?.methods.autoScrollLeft(); }, right: () => { getScroll()?.methods.autoScrollRight(); }, stop: () => { getScroll()?.methods.stopAutoScroll(); }, }; const set = (val: null | 'top' | 'bottom' | 'left' | 'right') => { const newVal = val; const oldVal = _state.value; if (newVal == oldVal) { return; } _state.value = val; if (!oldVal && !!newVal) { handler[newVal](); } else { handler.stop(); } }; const get = () => _state.value; const stop = () => getScroll()?.methods.stopAutoScroll(); return { get, set, stop }; }