/** * Reactive helpers tracking navigator/window-level browser state (1.14+): * preferred language(s), online status, page visibility, document/window focus, * idle, share/wake-lock/permission helpers, and broadcast channels. * * @module bquery/media */ import { type AbortableOptions } from './internal'; import type { MediaSignalHandle } from './types'; /** * Reactive signal tracking `navigator.language`. * * Updates when the browser fires the `languagechange` event. */ export declare const usePreferredLanguage: (options?: AbortableOptions) => MediaSignalHandle; /** * Reactive signal tracking `navigator.languages` as a readonly array. */ export declare const usePreferredLanguages: (options?: AbortableOptions) => MediaSignalHandle; /** * Reactive boolean tracking `navigator.onLine`. * * Slimmer alternative to {@link useNetworkStatus} for the common * "online vs offline" use case. */ export declare const useOnlineStatus: (options?: AbortableOptions) => MediaSignalHandle; /** * Reactive signal tracking `document.visibilityState`. */ export declare const usePageVisibility: (options?: AbortableOptions) => MediaSignalHandle<"visible" | "hidden">; /** * Reactive boolean tracking `document.hasFocus()`. */ export declare const useDocumentFocus: (options?: AbortableOptions) => MediaSignalHandle; /** * Reactive boolean tracking whether the top-level window currently has focus. * * Equivalent to {@link useDocumentFocus} but named for symmetry with * `useWindowFocus()`-style APIs found in other ecosystems. */ export declare const useWindowFocus: (options?: AbortableOptions) => MediaSignalHandle; /** * Options for {@link useIdle}. */ export interface UseIdleOptions extends AbortableOptions { /** * Events that reset the idle timer. * @default ['mousemove', 'mousedown', 'keydown', 'touchstart', 'scroll', 'wheel'] */ events?: readonly string[]; /** When `true`, treat `document.visibilityState === 'hidden'` as activity. @default true */ watchVisibility?: boolean; /** Initial value when DOM is unavailable. @default false */ initial?: boolean; } /** * Reactive boolean that becomes `true` when no user input has occurred * within `timeoutMs`. * * @example * ```ts * const idle = useIdle(60_000); * effect(() => idle.value && console.log('User is idle')); * ``` */ export declare const useIdle: (timeoutMs: number, options?: UseIdleOptions) => MediaSignalHandle; /** * Reactive signal tracking a `navigator.permissions.query()` result. * * Returns `'unsupported'` when the Permissions API is not available. */ export declare const usePermission: (name: PermissionName | string, options?: AbortableOptions) => MediaSignalHandle; /** * Handle returned by {@link useWakeLock}. */ export interface WakeLockHandle { /** Reactive signal — `true` while a wake lock is currently held. */ readonly isActive: MediaSignalHandle; /** Whether the Screen Wake Lock API is supported in this environment. */ readonly isSupported: boolean; /** Request a wake lock of the given type (default `'screen'`). */ request(type?: 'screen'): Promise; /** Release the currently held wake lock. */ release(): Promise; /** Release and tear down. Idempotent. */ destroy(): void; } /** * Reactive wrapper over the Screen Wake Lock API. */ export declare const useWakeLock: (options?: AbortableOptions) => WakeLockHandle; /** * Whether `navigator.share()` is available. */ export declare const useShareSupported: () => boolean; /** * Returned shape of {@link useShare}. */ export interface ShareHandle { readonly isSupported: boolean; share(data: ShareData): Promise; } /** * Wrapper around `navigator.share()` that swallows the well-known * `AbortError` so consumers can `.then(success => …)`. */ export declare const useShare: () => ShareHandle; /** * Reactive Broadcast Channel handle returned by {@link useBroadcastChannel}. */ export interface BroadcastChannelHandle { /** Reactive signal of the most recently received message, or `null`. */ readonly data: MediaSignalHandle; /** Whether the Broadcast Channel API is supported. */ readonly isSupported: boolean; /** Post a message to all other listeners on the same channel name. */ post(value: T): void; /** Close the channel and tear down. Idempotent. */ close(): void; } /** * Wraps `new BroadcastChannel(name)` as a reactive `data` signal plus a * `post()` helper. */ export declare const useBroadcastChannel: (name: string, options?: AbortableOptions) => BroadcastChannelHandle; /** * Options for {@link useEventListener}. */ export interface UseEventListenerOptions extends AddEventListenerOptions, AbortableOptions { } /** * Registers an event listener and returns a cleanup function. The listener * is automatically removed when `options.signal` aborts. * * @returns A cleanup function. Idempotent. * * @example * ```ts * const stop = useEventListener(window, 'resize', () => console.log('resize')); * stop(); * ``` */ export declare function useEventListener(target: Window, event: K, handler: (event: WindowEventMap[K]) => void, options?: UseEventListenerOptions): () => void; export declare function useEventListener(target: Document, event: K, handler: (event: DocumentEventMap[K]) => void, options?: UseEventListenerOptions): () => void; export declare function useEventListener(target: HTMLElement, event: K, handler: (event: HTMLElementEventMap[K]) => void, options?: UseEventListenerOptions): () => void; export declare function useEventListener(target: EventTarget, event: string, handler: EventListenerOrEventListenerObject, options?: UseEventListenerOptions): () => void; /** * Reactive list of `MediaDeviceInfo` entries. * * Updates when the browser fires `devicechange`. Returns an empty array * on platforms without `navigator.mediaDevices.enumerateDevices()`. */ export declare const useMediaDevices: (options?: AbortableOptions) => MediaSignalHandle; /** * Options for {@link useStorage}. */ export interface UseStorageOptions extends AbortableOptions { /** Which web storage to use. @default 'local' */ storage?: 'local' | 'session'; /** Custom serializer. @default JSON.stringify */ serialize?: (value: T) => string; /** Custom deserializer. @default JSON.parse */ deserialize?: (raw: string) => T; /** Sync across tabs via the `storage` event. @default true (local only) */ syncTabs?: boolean; } /** * Reactive storage handle. */ export interface StorageHandle { readonly value: MediaSignalHandle; set(value: T): void; remove(): void; destroy(): void; } /** * Reactive wrapper around `localStorage` / `sessionStorage` that * synchronises across browser tabs via the `storage` event. */ export declare const useStorage: (key: string, defaultValue: T, options?: UseStorageOptions) => StorageHandle; //# sourceMappingURL=browser-state.d.ts.map