'use client' /** * Reading direction, for the components that have to know it. * * A menu opens toward the end of the line, a slider fills toward it, a carousel * advances toward it. None of that can be read off CSS, so it travels as * context — and `dir` on an ancestor element is what the DOM already uses, so a * provider with nothing above it answers from there rather than guessing. */ import { createContext, useContext, type ReactNode } from 'react' export type Direction = 'ltr' | 'rtl' const DirectionContext = createContext(undefined) export function DirectionProvider({ dir, children, }: { dir: Direction children?: ReactNode }) { return {children} } /** * The direction in force. Falls back to the document's own `dir`, so a page that * sets it on `` — which is where it belongs — needs no provider at all. */ export function useDirection(local?: Direction): Direction { const inherited = useContext(DirectionContext) if (local) return local if (inherited) return inherited if (typeof document !== 'undefined') { const d = document.documentElement.dir if (d === 'rtl' || d === 'ltr') return d } return 'ltr' }