UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

84 lines 2.03 kB
/** * Track window size reactively * * @example * ```ts * const size = useWindowSize() * console.log(size.width, size.height) * * size.subscribe(({ width, height }) => { * console.log('Window resized:', width, height) * }) * ``` */ export declare function useWindowSize(): WindowSizeRef; /** * Track scroll position reactively * * @example * ```ts * const scroll = useScroll() * console.log(scroll.x, scroll.y) * * scroll.subscribe(({ y }) => { * if (y > 100) showBackToTop() * }) * * scroll.scrollToTop() * ``` */ export declare function useScroll(): ScrollRef; /** * Track document visibility * * @example * ```ts * const visibility = useVisibility() * * visibility.subscribe((visible) => { * if (!visible) pauseVideo() * else resumeVideo() * }) * ``` */ export declare function useVisibility(): VisibilityRef; /** * Reactive document title * * @example * ```ts * const title = useTitle('My App') * title.value = 'New Page - My App' * ``` */ export declare function useTitle(initialTitle?: string): { value: string; set: (title: string) => void }; /** * Reactive favicon */ export declare function useFavicon(href?: string): { value: string; set: (href: string) => void }; /** * useWindow - Reactive window properties composables * * Provides reactive tracking of window size, scroll position, visibility, etc. */ export declare interface WindowSize { width: number height: number } export declare interface ScrollPosition { x: number y: number } export declare interface WindowSizeRef extends WindowSize { subscribe: (callback: (size: WindowSize) => void) => () => void } export declare interface ScrollRef extends ScrollPosition { subscribe: (callback: (position: ScrollPosition) => void) => () => void scrollTo: (options: ScrollToOptions | number, y?: number) => void scrollToTop: () => void scrollToBottom: () => void } export declare interface VisibilityRef { isVisible: boolean subscribe: (callback: (visible: boolean) => void) => () => void }