browser-device-orientation

Wraps DeviceOrientationEvent as global atoms, exposing the raw tilt snapshot plus alpha / beta / gamma and a compass-heading selector.

Permission
iOS requires a user gesture: call requestOrientationPermission() from a click handler before subscribing. Other browsers grant on subscribe.

Install

bun add @valdres/browser-device-orientation

Live example

Loading demo…

Usage

<script>
import { watch } from "valdres-svelte"
import { compassHeadingSelector } from "@valdres/browser-device-orientation"

const heading = watch(compassHeadingSelector)
</script>

{heading.value == null ? "—" : Math.round(heading.value) + "°"}

Exports

ExportKindType
orientationAtomatom (read-only)OrientationSnapshot | null
permissionAtomatom (settable)PermissionValue
orientationStatusAtomatom (read-only)OrientationStatus
alphaSelectorselectornumber | null
betaSelectorselectornumber | null
gammaSelectorselectornumber | null
absoluteSelectorselectorboolean | null
compassHeadingSelectorselectornumber | null
requestOrientationPermissionutil fn() => Promise<PermissionValue>
OrientationSnapshottype{ alpha, beta, gamma: number | null; absolute: boolean; webkitCompassHeading, webkitCompassAccuracy: number | null; timeStamp: number }
OrientationStatustype"unsupported" | "idle" | "active"
PermissionValuetype"granted" | "denied" | "prompt" | "unsupported"

Cross-framework

Global atoms/selectors — works in every framework, only the read primitive differs. The deviceorientation listener starts on the first subscriber and stops on the last.