@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
62 lines • 1.81 kB
TypeScript
/**
* Get current position as a Promise
*/
export declare function getCurrentPosition(options?: PositionOptions): Promise<GeolocationPosition>;
/**
* Calculate distance between two coordinates (Haversine formula)
* @returns Distance in meters
*/
export declare function calculateDistance(lat1: number, lon1: number, lat2: number, lon2: number): number;
/**
* Reactive geolocation composable with watch support
*/
export declare function useGeolocation(options?: GeolocationOptions): GeolocationRef;
/**
* Watch position changes (alias for useGeolocation with watch)
*/
export declare function useGeolocationWatch(options?: GeolocationOptions): GeolocationRef;
/**
* useGeolocation - Reactive Geolocation API wrapper
*
* Provides easy access to the browser's Geolocation API with reactive state.
*
* @example
* ```ts
* const geo = useGeolocation()
* geo.subscribe(state => {
* console.log(state.coords?.latitude, state.coords?.longitude)
* })
*
* // Or get current position once
* const position = await getCurrentPosition()
* ```
*/
export declare interface GeolocationCoords {
latitude: number
longitude: number
altitude: number | null
accuracy: number
altitudeAccuracy: number | null
heading: number | null
speed: number | null
}
export declare interface GeolocationState {
coords: GeolocationCoords | null
timestamp: number | null
error: GeolocationPositionError | null
loading: boolean
supported: boolean
}
export declare interface GeolocationOptions {
enableHighAccuracy?: boolean
timeout?: number
maximumAge?: number
immediate?: boolean
}
export declare interface GeolocationRef {
get: () => GeolocationState
subscribe: (fn: (state: GeolocationState) => void) => () => void
refresh: () => void
pause: () => void
resume: () => void
}