UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

109 lines 2.87 kB
/** * Check if DeviceOrientation is supported */ export declare function isDeviceOrientationSupported(): boolean; /** * Check if DeviceMotion is supported */ export declare function isDeviceMotionSupported(): boolean; /** * Request permission for device orientation (required on iOS 13+) */ export declare function requestOrientationPermission(): Promise<boolean>; /** * Request permission for device motion (required on iOS 13+) */ export declare function requestMotionPermission(): Promise<boolean>; /** * Create a reactive device orientation tracker * * @example * ```ts * const orientation = useDeviceOrientation() * * // Request permission first (required on iOS) * await orientation.requestPermission() * * // Subscribe to orientation changes * orientation.subscribe((state) => { * console.log('Alpha (compass):', state.alpha) * console.log('Beta (front/back):', state.beta) * console.log('Gamma (left/right):', state.gamma) * }) * ``` */ export declare function useDeviceOrientation(): DeviceOrientationRef; /** * Create a reactive device motion tracker * * @example * ```ts * const motion = useDeviceMotion() * * // Request permission first (required on iOS) * await motion.requestPermission() * * // Subscribe to motion changes * motion.subscribe((state) => { * console.log('Acceleration:', state.acceleration) * console.log('Rotation rate:', state.rotationRate) * }) * ``` */ export declare function useDeviceMotion(): DeviceMotionRef; /** * Simple tilt detection for parallax effects * * @example * ```ts * const tilt = useParallax() * * tilt.subscribe(({ x, y }) => { * element.style.transform = `translate(${x * 10}px, ${y * 10}px)` * }) * ``` */ export declare function useParallax(): void; /** * Device Orientation & Motion Composables * * Reactive utilities for device orientation and motion sensors. */ export declare interface DeviceOrientationState { isSupported: boolean isAbsolute: boolean alpha: number | null beta: number | null gamma: number | null } export declare interface DeviceMotionState { isSupported: boolean acceleration: { x: number | null y: number | null z: number | null } accelerationIncludingGravity: { x: number | null y: number | null z: number | null } rotationRate: { alpha: number | null beta: number | null gamma: number | null } interval: number } export declare interface DeviceOrientationRef { get: () => DeviceOrientationState subscribe: (fn: (state: DeviceOrientationState) => void) => () => void isSupported: () => boolean requestPermission: () => Promise<boolean> } export declare interface DeviceMotionRef { get: () => DeviceMotionState subscribe: (fn: (state: DeviceMotionState) => void) => () => void isSupported: () => boolean requestPermission: () => Promise<boolean> }