@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
85 lines • 2.15 kB
TypeScript
/**
* Check if Wake Lock API is supported
*/
export declare function isWakeLockSupported(): boolean;
/**
* Create a reactive wake lock controller
*
* The Screen Wake Lock API prevents the screen from dimming or locking
* while your application is active. Useful for video players, presentation
* apps, or any application where the user needs to see the screen without
* interacting with it.
*
* @example
* ```ts
* const wakeLock = useWakeLock()
*
* // Request wake lock
* await wakeLock.request()
*
* // Subscribe to state changes
* wakeLock.subscribe((state) => {
* console.log('Wake lock active:', state.isActive)
* })
*
* // Release when done
* await wakeLock.release()
*
* // Or toggle
* await wakeLock.toggle()
* ```
*/
export declare function useWakeLock(): WakeLockRef;
/**
* Auto-acquire wake lock while component is mounted
*
* @example
* ```ts
* // In a video player component
* const wakeLock = useAutoWakeLock()
*
* wakeLock.subscribe((isActive) => {
* console.log('Screen wake lock:', isActive ? 'on' : 'off')
* })
* ```
*/
export declare function useAutoWakeLock(): void;
/**
* Wake lock that only activates while a condition is true
*
* @example
* ```ts
* const isPlaying = { value: false }
*
* const wakeLock = useConditionalWakeLock(() => isPlaying.value)
*
* // When video starts playing
* isPlaying.value = true
* wakeLock.check() // Acquires wake lock
*
* // When video pauses
* isPlaying.value = false
* wakeLock.check() // Releases wake lock
* ```
*/
export declare function useConditionalWakeLock(condition: () => boolean): void;
/**
* Wake Lock Composables
*
* Reactive utilities for the Screen Wake Lock API to prevent devices from sleeping.
*/
export declare interface WakeLockState {
isSupported: boolean
isActive: boolean
type: 'screen' | null
error: Error | null
}
export declare interface WakeLockRef {
get: () => WakeLockState
subscribe: (fn: (state: WakeLockState) => void) => () => void
request: () => Promise<boolean>
release: () => Promise<void>
toggle: () => Promise<boolean>
isSupported: () => boolean
isActive: () => boolean
}