import {useWidth} from "./useWidth"; export const useOffset = <T extends HTMLElement, U extends HTMLElement>(parent: T | null, child: U | null, position: number) => { const parentWidth = useWidth(parent); const childWidth = useWidth(child); const offset = parentWidth * position - childWidth / 2; return Math.max(0, Math.min(offset, parentWidth - childWidth)); }