@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
46 lines • 1.19 kB
TypeScript
/**
* Monitor battery status
*/
export declare function useBattery(): BatteryRef;
/**
* Get battery level as percentage
*/
export declare function getBatteryLevel(): Promise<number | null>;
/**
* Check if device is charging
*/
export declare function isCharging(): Promise<boolean | null>;
/**
* Check if Battery API is available
*/
export declare function hasBattery(): boolean;
/**
* useBattery - Battery Status API wrapper
*
* Monitor device battery status reactively.
*
* @example
* ```ts
* const battery = useBattery()
* battery.subscribe(state => {
* console.log('Battery level:', state.level * 100 + '%')
* console.log('Charging:', state.charging)
* console.log('Time to full:', state.chargingTime)
* console.log('Time to empty:', state.dischargingTime)
* })
* ```
*/
export declare interface BatteryState {
charging: boolean
chargingTime: number
dischargingTime: number
level: number
}
export declare interface BatteryRef {
get: () => BatteryState
subscribe: (fn: (state: BatteryState) => void) => () => void
isSupported: () => boolean
getPercentage: () => number
isLow: (threshold?: number) => boolean
isCritical: () => boolean
}