UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

109 lines 3.26 kB
/** * Query a single permission */ export declare function usePermission(name: PermissionName): PermissionRef; /** * Query multiple permissions at once */ export declare function usePermissions(names: PermissionName[]): MultiPermissionRef; /** * Check if a permission is granted */ export declare function isPermissionGranted(name: PermissionName): Promise<boolean>; /** * Check if camera permission is granted */ export declare function hasCameraPermission(): Promise<boolean>; /** * Check if microphone permission is granted */ export declare function hasMicrophonePermission(): Promise<boolean>; /** * Check if geolocation permission is granted */ export declare function hasGeolocationPermission(): Promise<boolean>; /** * Check if notifications permission is granted */ export declare function hasNotificationPermission(): Promise<boolean>; /** * Request camera and microphone permissions by accessing media */ export declare function requestMediaPermissions(options?: { video?: boolean; audio?: boolean }): Promise<{ granted: boolean; stream?: MediaStream; error?: Error }>; /** * Common permission groups */ export declare const permissionGroups: { media: readonly ['camera', unknown]; location: readonly [unknown]; notifications: readonly ['notifications', unknown]; sensors: readonly ['accelerometer', 'gyroscope', unknown]; clipboard: readonly ['clipboard-read', unknown] }; export declare interface PermissionStatus { state: PermissionState isGranted: boolean isDenied: boolean isPrompt: boolean } export declare interface PermissionRef { get: () => PermissionStatus subscribe: (fn: (status: PermissionStatus) => void) => () => void query: () => Promise<PermissionStatus> isSupported: () => boolean } export declare interface MultiPermissionRef { get: () => Record<string, PermissionStatus> subscribe: (fn: (states: Record<string, PermissionStatus>) => void) => () => void queryAll: () => Promise<Record<string, PermissionStatus>> isSupported: () => boolean } /** * usePermissions - Permissions API wrapper * * Query and monitor browser permission states for various APIs. * * @example * ```ts * // Check camera permission * const camera = usePermission('camera') * camera.subscribe(state => { * console.log('Camera permission:', state.state) // 'granted', 'denied', 'prompt' * }) * * // Check multiple permissions * const permissions = usePermissions(['camera', 'microphone', 'geolocation']) * permissions.subscribe(states => { * console.log('Camera:', states.camera) * console.log('Microphone:', states.microphone) * }) * ``` */ export type PermissionName = | 'accelerometer' | 'accessibility-events' | 'ambient-light-sensor' | 'background-fetch' | 'background-sync' | 'bluetooth' | 'camera' | 'clipboard-read' | 'clipboard-write' | 'device-info' | 'display-capture' | 'geolocation' | 'gyroscope' | 'magnetometer' | 'microphone' | 'midi' | 'nfc' | 'notifications' | 'payment-handler' | 'periodic-background-sync' | 'persistent-storage' | 'push' | 'screen-wake-lock' | 'speaker-selection' | 'storage-access' | 'window-management' | 'xr-spatial-tracking' export type PermissionState = 'granted' | 'denied' | 'prompt'