@symbiote-native/sensors 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -21
- package/build/angular/index.d.ts +1 -1
- package/build/angular/index.js +1 -1
- package/build/angular/services/accelerometer.service/index.js +1 -1
- package/build/angular/services/barometer.service/index.js +1 -1
- package/build/angular/services/device-motion.service/index.js +1 -1
- package/build/angular/services/gyroscope.service/index.js +1 -1
- package/build/angular/services/light-sensor.service/index.js +1 -1
- package/build/angular/services/magnetometer-uncalibrated.service/index.js +2 -2
- package/build/angular/services/magnetometer.service/index.js +1 -1
- package/build/angular/services/pedometer.service/index.js +1 -1
- package/build/core/index.d.ts +5 -5
- package/build/core/index.js +5 -5
- package/build/react/hooks/use-magnetometer-uncalibrated/index.js +1 -1
- package/build/react/index.d.ts +1 -1
- package/build/react/index.js +1 -1
- package/build/solid/index.d.ts +10 -0
- package/build/solid/index.js +17 -0
- package/build/solid/primitives/create-accelerometer.d.ts +4 -0
- package/build/solid/primitives/create-accelerometer.js +5 -0
- package/build/solid/primitives/create-barometer.d.ts +4 -0
- package/build/solid/primitives/create-barometer.js +5 -0
- package/build/solid/primitives/create-device-motion.d.ts +4 -0
- package/build/solid/primitives/create-device-motion.js +5 -0
- package/build/solid/primitives/create-gyroscope.d.ts +4 -0
- package/build/solid/primitives/create-gyroscope.js +5 -0
- package/build/solid/primitives/create-light-sensor.d.ts +4 -0
- package/build/solid/primitives/create-light-sensor.js +5 -0
- package/build/solid/primitives/create-magnetometer-uncalibrated.d.ts +4 -0
- package/build/solid/primitives/create-magnetometer-uncalibrated.js +5 -0
- package/build/solid/primitives/create-magnetometer.d.ts +4 -0
- package/build/solid/primitives/create-magnetometer.js +5 -0
- package/build/solid/primitives/create-pedometer.d.ts +3 -0
- package/build/solid/primitives/create-pedometer.js +22 -0
- package/build/solid/primitives/device-sensor-accessor.d.ts +9 -0
- package/build/solid/primitives/device-sensor-accessor.js +66 -0
- package/build/svelte/index.d.ts +1 -1
- package/build/svelte/index.js +1 -1
- package/build/svelte/runes/use-accelerometer.svelte.js +1 -1
- package/build/svelte/runes/use-barometer.svelte.js +1 -1
- package/build/svelte/runes/use-device-motion.svelte.js +1 -1
- package/build/svelte/runes/use-gyroscope.svelte.js +1 -1
- package/build/svelte/runes/use-light-sensor.svelte.js +1 -1
- package/build/svelte/runes/use-magnetometer.svelte.js +1 -1
- package/build/svelte/runes/use-pedometer.svelte.js +1 -1
- package/build/vue/composables/use-barometer/index.js +1 -1
- package/build/vue/composables/use-device-motion/index.js +1 -1
- package/build/vue/composables/use-gyroscope/index.js +1 -1
- package/build/vue/composables/use-light-sensor/index.js +1 -1
- package/build/vue/composables/use-magnetometer/index.js +1 -1
- package/build/vue/composables/use-pedometer/index.js +1 -1
- package/build/vue/index.d.ts +1 -1
- package/build/vue/index.js +1 -1
- package/build-ngc/angular/index.d.ts +1 -1
- package/build-ngc/angular/index.js +1 -1
- package/build-ngc/angular/index.js.map +1 -1
- package/build-ngc/angular/services/accelerometer.service/index.js +1 -1
- package/build-ngc/angular/services/accelerometer.service/index.js.map +1 -1
- package/build-ngc/angular/services/barometer.service/index.js +1 -1
- package/build-ngc/angular/services/barometer.service/index.js.map +1 -1
- package/build-ngc/angular/services/device-motion.service/index.js +1 -1
- package/build-ngc/angular/services/device-motion.service/index.js.map +1 -1
- package/build-ngc/angular/services/gyroscope.service/index.js +1 -1
- package/build-ngc/angular/services/gyroscope.service/index.js.map +1 -1
- package/build-ngc/angular/services/light-sensor.service/index.js +1 -1
- package/build-ngc/angular/services/light-sensor.service/index.js.map +1 -1
- package/build-ngc/angular/services/magnetometer-uncalibrated.service/index.js +2 -2
- package/build-ngc/angular/services/magnetometer-uncalibrated.service/index.js.map +1 -1
- package/build-ngc/angular/services/magnetometer.service/index.js +1 -1
- package/build-ngc/angular/services/magnetometer.service/index.js.map +1 -1
- package/build-ngc/angular/services/pedometer.service/index.js +1 -1
- package/build-ngc/angular/services/pedometer.service/index.js.map +1 -1
- package/build-ngc/core/barometer.js.map +1 -1
- package/build-ngc/core/device-motion.js.map +1 -1
- package/build-ngc/core/device-sensor.js.map +1 -1
- package/build-ngc/core/gyroscope.js.map +1 -1
- package/build-ngc/core/index.d.ts +5 -5
- package/build-ngc/core/index.js +5 -5
- package/build-ngc/core/index.js.map +1 -1
- package/build-ngc/core/magnetometer-uncalibrated.js.map +1 -1
- package/build-ngc/core/native/exponent-barometer.js.map +1 -1
- package/build-ngc/core/native/exponent-device-motion.js.map +1 -1
- package/build-ngc/core/native/exponent-gyroscope.js.map +1 -1
- package/build-ngc/core/native/exponent-light-sensor/index.ios.js.map +1 -1
- package/build-ngc/core/native/exponent-magnetometer-uncalibrated.js.map +1 -1
- package/build-ngc/core/native/exponent-pedometer.js.map +1 -1
- package/build-ngc/core/pedometer.js.map +1 -1
- package/package.json +22 -8
- package/src/angular/index.ts +5 -1
- package/src/angular/services/accelerometer.service/index.ts +11 -2
- package/src/angular/services/barometer.service/index.ts +11 -2
- package/src/angular/services/device-motion.service/index.ts +11 -2
- package/src/angular/services/gyroscope.service/index.ts +11 -2
- package/src/angular/services/light-sensor.service/index.ts +11 -2
- package/src/angular/services/magnetometer-uncalibrated.service/index.ts +21 -5
- package/src/angular/services/magnetometer.service/index.ts +11 -2
- package/src/angular/services/pedometer.service/index.ts +8 -1
- package/src/core/barometer.ts +4 -1
- package/src/core/device-motion.ts +12 -2
- package/src/core/device-sensor.ts +8 -2
- package/src/core/gyroscope.ts +4 -1
- package/src/core/index.ts +25 -5
- package/src/core/magnetometer-uncalibrated.ts +2 -1
- package/src/core/native/exponent-barometer.ts +3 -3
- package/src/core/native/exponent-device-motion.ts +8 -6
- package/src/core/native/exponent-gyroscope.ts +3 -3
- package/src/core/native/exponent-light-sensor/index.ios.ts +7 -6
- package/src/core/native/exponent-magnetometer-uncalibrated.ts +2 -1
- package/src/core/native/exponent-pedometer.ts +4 -1
- package/src/core/pedometer.ts +7 -2
- package/src/react/hooks/use-accelerometer/index.ts +5 -2
- package/src/react/hooks/use-barometer/index.ts +6 -2
- package/src/react/hooks/use-device-motion/index.ts +5 -2
- package/src/react/hooks/use-gyroscope/index.ts +6 -2
- package/src/react/hooks/use-light-sensor/index.ts +5 -2
- package/src/react/hooks/use-magnetometer/index.ts +5 -2
- package/src/react/hooks/use-magnetometer-uncalibrated/index.ts +6 -2
- package/src/react/index.ts +5 -1
- package/src/solid/index.ts +19 -0
- package/src/solid/primitives/create-accelerometer.ts +16 -0
- package/src/solid/primitives/create-barometer.ts +16 -0
- package/src/solid/primitives/create-device-motion.ts +16 -0
- package/src/solid/primitives/create-gyroscope.ts +16 -0
- package/src/solid/primitives/create-light-sensor.ts +16 -0
- package/src/solid/primitives/create-magnetometer-uncalibrated.ts +19 -0
- package/src/solid/primitives/create-magnetometer.ts +16 -0
- package/src/solid/primitives/create-pedometer.ts +31 -0
- package/src/solid/primitives/device-sensor-accessor.ts +105 -0
- package/src/svelte/index.ts +5 -1
- package/src/svelte/runes/use-accelerometer.svelte.ts +5 -1
- package/src/svelte/runes/use-barometer.svelte.ts +5 -1
- package/src/svelte/runes/use-device-motion.svelte.ts +5 -1
- package/src/svelte/runes/use-gyroscope.svelte.ts +5 -1
- package/src/svelte/runes/use-light-sensor.svelte.ts +5 -1
- package/src/svelte/runes/use-magnetometer-uncalibrated.svelte.ts +4 -3
- package/src/svelte/runes/use-magnetometer.svelte.ts +5 -1
- package/src/svelte/runes/use-pedometer.svelte.ts +5 -1
- package/src/vue/composables/use-accelerometer/index.ts +3 -1
- package/src/vue/composables/use-barometer/index.ts +8 -2
- package/src/vue/composables/use-device-motion/index.ts +8 -2
- package/src/vue/composables/use-gyroscope/index.ts +8 -2
- package/src/vue/composables/use-light-sensor/index.ts +8 -2
- package/src/vue/composables/use-magnetometer/index.ts +8 -2
- package/src/vue/composables/use-pedometer/index.ts +5 -1
- package/src/vue/index.ts +5 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Solid lifecycle wiring over the framework-agnostic watchStepCount free function (core/) — the
|
|
2
|
+
// Solid twin of react/hooks/use-pedometer, vue/composables/use-pedometer and
|
|
3
|
+
// svelte/runes/use-pedometer.svelte.ts. Pedometer is the one sensor here that is not a
|
|
4
|
+
// DeviceSensor subclass (core/pedometer.ts's header), so it has no setUpdateInterval and takes no
|
|
5
|
+
// interval argument — hence its own body instead of ./device-sensor-accessor.
|
|
6
|
+
//
|
|
7
|
+
// `primitives/` and `create*`, and an ACCESSOR rather than a snapshot, for the reasons recorded in
|
|
8
|
+
// adapters/solid/src/primitives/create-color-scheme.ts.
|
|
9
|
+
|
|
10
|
+
import { createSignal, onCleanup, type Accessor } from 'solid-js';
|
|
11
|
+
import {
|
|
12
|
+
watchStepCount,
|
|
13
|
+
type EventSubscription,
|
|
14
|
+
type IPedometerResult,
|
|
15
|
+
} from '../../core';
|
|
16
|
+
|
|
17
|
+
export function createPedometer(): Accessor<IPedometerResult | null> {
|
|
18
|
+
const [result, setResult] = createSignal<IPedometerResult | null>(null);
|
|
19
|
+
|
|
20
|
+
// Subscribed from the primitive body, not from an effect: React/Vue/Svelte start listening a
|
|
21
|
+
// tick after their seed runs, so a step count landing in that window is lost.
|
|
22
|
+
const subscription: EventSubscription = watchStepCount(next => {
|
|
23
|
+
setResult(next);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
onCleanup(() => {
|
|
27
|
+
subscription.remove();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The one lifecycle body every DeviceSensor-shaped primitive in this folder delegates to
|
|
2
|
+
// (Accelerometer, Barometer, DeviceMotion, Gyroscope, LightSensor, Magnetometer,
|
|
3
|
+
// MagnetometerUncalibrated). Internal — not re-exported from ../index.ts, whose surface stays at
|
|
4
|
+
// parity with the react/vue/svelte entries.
|
|
5
|
+
//
|
|
6
|
+
// `primitives/` and `create*`, never `hooks/` + `use*`: Solid's ecosystem calls a composable
|
|
7
|
+
// reactive function a PRIMITIVE and reserves `use*` for consuming something that already exists.
|
|
8
|
+
// Full rationale in adapters/solid/src/primitives/create-color-scheme.ts.
|
|
9
|
+
//
|
|
10
|
+
// Returns an ACCESSOR, never a snapshot: a Solid component body runs ONCE, so a returned
|
|
11
|
+
// measurement would pin the caller to `null` forever.
|
|
12
|
+
//
|
|
13
|
+
// ## Why the interval is `number | Accessor<number | undefined>`
|
|
14
|
+
//
|
|
15
|
+
// React re-reads `updateIntervalMs` on every render and re-runs its effect when it changes; Vue
|
|
16
|
+
// and Svelte read it once at subscribe time. Neither shape ports: a Solid body runs once, so a
|
|
17
|
+
// plain parameter freezes the sample rate at whatever the caller passed at mount, and nothing
|
|
18
|
+
// reports it — the caller's `intervalMs` state moves and the native rate does not. So the
|
|
19
|
+
// parameter accepts EITHER form (solid-primitives' `MaybeAccessor` convention): a literal for the
|
|
20
|
+
// common static case, keeping the call site identical to the other adapters, or an accessor when
|
|
21
|
+
// the rate is derived from state. The accessor form is the reactive one and is the only one that
|
|
22
|
+
// creates an effect.
|
|
23
|
+
//
|
|
24
|
+
// Applying it splits in two on purpose. The mount-time value is applied SYNCHRONOUSLY, before
|
|
25
|
+
// `addListener`, so the very first native sample already arrives at the requested rate; the
|
|
26
|
+
// tracking effect is then `defer`red so it fires only on a LATER change. Without the defer the
|
|
27
|
+
// interval would be set twice at mount, and the second call would land a tick after the first
|
|
28
|
+
// samples.
|
|
29
|
+
//
|
|
30
|
+
// Outside a component or `createRoot` there is no owner for `onCleanup` — Solid warns and the
|
|
31
|
+
// native listener lives for the process. The accessor still tracks; only the teardown is lost.
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
createEffect,
|
|
35
|
+
createSignal,
|
|
36
|
+
on,
|
|
37
|
+
onCleanup,
|
|
38
|
+
untrack,
|
|
39
|
+
type Accessor,
|
|
40
|
+
} from 'solid-js';
|
|
41
|
+
import type { EventSubscription, IListener } from '../../core';
|
|
42
|
+
|
|
43
|
+
export type IUpdateIntervalMs =
|
|
44
|
+
number | Accessor<number | undefined> | undefined;
|
|
45
|
+
|
|
46
|
+
// Structural, not `DeviceSensor<Measurement>`: this needs exactly two methods, and every test in
|
|
47
|
+
// this folder passes a plain object in place of the singleton.
|
|
48
|
+
type ISensorHandle<Measurement> = {
|
|
49
|
+
addListener(listener: IListener<Measurement>): EventSubscription;
|
|
50
|
+
setUpdateInterval(intervalMs: number): void;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export function createDeviceSensorAccessor<Measurement>(
|
|
54
|
+
sensor: ISensorHandle<Measurement>,
|
|
55
|
+
updateIntervalMs?: IUpdateIntervalMs,
|
|
56
|
+
): Accessor<Measurement | null> {
|
|
57
|
+
const [measurement, setMeasurement] = createSignal<Measurement | null>(null);
|
|
58
|
+
|
|
59
|
+
function applyInterval(intervalMs: number | undefined): void {
|
|
60
|
+
// `!== undefined`, not truthiness: 0 is a legitimate "as fast as possible" rate, and an
|
|
61
|
+
// unconditional call would stomp the rate another consumer of this shared singleton set.
|
|
62
|
+
if (intervalMs !== undefined) {
|
|
63
|
+
sensor.setUpdateInterval(intervalMs);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// untracked: a primitive built inside a tracked scope must not re-run — and re-subscribe —
|
|
68
|
+
// just because it read the caller's interval accessor once.
|
|
69
|
+
applyInterval(
|
|
70
|
+
untrack(() =>
|
|
71
|
+
typeof updateIntervalMs === 'function'
|
|
72
|
+
? updateIntervalMs()
|
|
73
|
+
: updateIntervalMs,
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Subscribed from the primitive body, not from an effect: React/Vue/Svelte start listening a
|
|
78
|
+
// tick after their seed runs, so an event landing in that window is lost. Both statements here
|
|
79
|
+
// run in one synchronous tick and nothing can interleave.
|
|
80
|
+
const subscription: EventSubscription = sensor.addListener(next => {
|
|
81
|
+
// The updater form, because `Measurement` is unconstrained — a bare value would be read as a
|
|
82
|
+
// reducer for any measurement type that could itself be callable.
|
|
83
|
+
setMeasurement(() => next);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
onCleanup(() => {
|
|
87
|
+
subscription.remove();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (typeof updateIntervalMs === 'function') {
|
|
91
|
+
// Only the rate changes — the native listener is per-sensor and unaffected, so re-subscribing
|
|
92
|
+
// (as React's interval-keyed effect does) would drop events for nothing.
|
|
93
|
+
createEffect(
|
|
94
|
+
on(
|
|
95
|
+
updateIntervalMs,
|
|
96
|
+
intervalMs => {
|
|
97
|
+
applyInterval(intervalMs);
|
|
98
|
+
},
|
|
99
|
+
{ defer: true },
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return measurement;
|
|
105
|
+
}
|
package/src/svelte/index.ts
CHANGED
|
@@ -8,7 +8,11 @@ export type { IAccelerometerMeasurement } from '../core';
|
|
|
8
8
|
export { useBarometer } from './runes/use-barometer.svelte';
|
|
9
9
|
export type { IBarometerMeasurement } from '../core';
|
|
10
10
|
export { useDeviceMotion } from './runes/use-device-motion.svelte';
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
DeviceMotionOrientation,
|
|
13
|
+
gravity,
|
|
14
|
+
type IDeviceMotionMeasurement,
|
|
15
|
+
} from '../core';
|
|
12
16
|
export { useGyroscope } from './runes/use-gyroscope.svelte';
|
|
13
17
|
export type { IGyroscopeMeasurement } from '../core';
|
|
14
18
|
export { useLightSensor } from './runes/use-light-sensor.svelte';
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
//
|
|
10
10
|
// `updateIntervalMs` is a plain number, not a getter: it applies once at subscribe time and
|
|
11
11
|
// never reacts to a later change, matching the Vue/React twins.
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
Accelerometer,
|
|
14
|
+
type EventSubscription,
|
|
15
|
+
type IAccelerometerMeasurement,
|
|
16
|
+
} from '../../core';
|
|
13
17
|
|
|
14
18
|
export function useAccelerometer(updateIntervalMs?: number): {
|
|
15
19
|
readonly current: IAccelerometerMeasurement | null;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
3
|
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
4
|
// rather than a getter.
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Barometer,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IBarometerMeasurement,
|
|
9
|
+
} from '../../core';
|
|
6
10
|
|
|
7
11
|
export function useBarometer(updateIntervalMs?: number): {
|
|
8
12
|
readonly current: IBarometerMeasurement | null;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
3
|
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
4
|
// rather than a getter.
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
DeviceMotion,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IDeviceMotionMeasurement,
|
|
9
|
+
} from '../../core';
|
|
6
10
|
|
|
7
11
|
export function useDeviceMotion(updateIntervalMs?: number): {
|
|
8
12
|
readonly current: IDeviceMotionMeasurement | null;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
3
|
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
4
|
// rather than a getter.
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Gyroscope,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IGyroscopeMeasurement,
|
|
9
|
+
} from '../../core';
|
|
6
10
|
|
|
7
11
|
export function useGyroscope(updateIntervalMs?: number): {
|
|
8
12
|
readonly current: IGyroscopeMeasurement | null;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
3
|
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
4
|
// rather than a getter.
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
LightSensor,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type ILightSensorMeasurement,
|
|
9
|
+
} from '../../core';
|
|
6
10
|
|
|
7
11
|
export function useLightSensor(updateIntervalMs?: number): {
|
|
8
12
|
readonly current: ILightSensorMeasurement | null;
|
|
@@ -17,9 +17,10 @@ export function useMagnetometerUncalibrated(updateIntervalMs?: number): {
|
|
|
17
17
|
if (updateIntervalMs !== undefined) {
|
|
18
18
|
MagnetometerUncalibrated.setUpdateInterval(updateIntervalMs);
|
|
19
19
|
}
|
|
20
|
-
const subscription: EventSubscription =
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const subscription: EventSubscription =
|
|
21
|
+
MagnetometerUncalibrated.addListener(next => {
|
|
22
|
+
measurement = next;
|
|
23
|
+
});
|
|
23
24
|
return () => subscription.remove();
|
|
24
25
|
});
|
|
25
26
|
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
3
|
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
4
|
// rather than a getter.
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Magnetometer,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IMagnetometerMeasurement,
|
|
9
|
+
} from '../../core';
|
|
6
10
|
|
|
7
11
|
export function useMagnetometer(updateIntervalMs?: number): {
|
|
8
12
|
readonly current: IMagnetometerMeasurement | null;
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
// useAccelerometer there is no interval param to apply at subscribe time. See
|
|
4
4
|
// use-accelerometer.svelte.ts's header for why this lives in `runes/` with a `.svelte.ts`
|
|
5
5
|
// extension and returns a boxed getter object.
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
watchStepCount,
|
|
8
|
+
type EventSubscription,
|
|
9
|
+
type IPedometerResult,
|
|
10
|
+
} from '../../core';
|
|
7
11
|
|
|
8
12
|
export function usePedometer(): { readonly current: IPedometerResult | null } {
|
|
9
13
|
let result = $state<IPedometerResult | null>(null);
|
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
type IAccelerometerMeasurement,
|
|
13
13
|
} from '../../../core';
|
|
14
14
|
|
|
15
|
-
export function useAccelerometer(
|
|
15
|
+
export function useAccelerometer(
|
|
16
|
+
updateIntervalMs?: number,
|
|
17
|
+
): Ref<IAccelerometerMeasurement | null> {
|
|
16
18
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
17
19
|
const measurement = ref<IAccelerometerMeasurement | null>(null);
|
|
18
20
|
let subscription: EventSubscription | undefined;
|
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
|
|
8
8
|
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
Barometer,
|
|
11
|
+
type EventSubscription,
|
|
12
|
+
type IBarometerMeasurement,
|
|
13
|
+
} from '../../../core';
|
|
10
14
|
|
|
11
|
-
export function useBarometer(
|
|
15
|
+
export function useBarometer(
|
|
16
|
+
updateIntervalMs?: number,
|
|
17
|
+
): Ref<IBarometerMeasurement | null> {
|
|
12
18
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
13
19
|
const measurement = ref<IBarometerMeasurement | null>(null);
|
|
14
20
|
let subscription: EventSubscription | undefined;
|
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
|
|
8
8
|
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
DeviceMotion,
|
|
11
|
+
type EventSubscription,
|
|
12
|
+
type IDeviceMotionMeasurement,
|
|
13
|
+
} from '../../../core';
|
|
10
14
|
|
|
11
|
-
export function useDeviceMotion(
|
|
15
|
+
export function useDeviceMotion(
|
|
16
|
+
updateIntervalMs?: number,
|
|
17
|
+
): Ref<IDeviceMotionMeasurement | null> {
|
|
12
18
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
13
19
|
const measurement = ref<IDeviceMotionMeasurement | null>(null);
|
|
14
20
|
let subscription: EventSubscription | undefined;
|
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
|
|
8
8
|
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
Gyroscope,
|
|
11
|
+
type EventSubscription,
|
|
12
|
+
type IGyroscopeMeasurement,
|
|
13
|
+
} from '../../../core';
|
|
10
14
|
|
|
11
|
-
export function useGyroscope(
|
|
15
|
+
export function useGyroscope(
|
|
16
|
+
updateIntervalMs?: number,
|
|
17
|
+
): Ref<IGyroscopeMeasurement | null> {
|
|
12
18
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
13
19
|
const measurement = ref<IGyroscopeMeasurement | null>(null);
|
|
14
20
|
let subscription: EventSubscription | undefined;
|
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
|
|
8
8
|
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
LightSensor,
|
|
11
|
+
type EventSubscription,
|
|
12
|
+
type ILightSensorMeasurement,
|
|
13
|
+
} from '../../../core';
|
|
10
14
|
|
|
11
|
-
export function useLightSensor(
|
|
15
|
+
export function useLightSensor(
|
|
16
|
+
updateIntervalMs?: number,
|
|
17
|
+
): Ref<ILightSensorMeasurement | null> {
|
|
12
18
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
13
19
|
const measurement = ref<ILightSensorMeasurement | null>(null);
|
|
14
20
|
let subscription: EventSubscription | undefined;
|
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
|
|
8
8
|
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
Magnetometer,
|
|
11
|
+
type EventSubscription,
|
|
12
|
+
type IMagnetometerMeasurement,
|
|
13
|
+
} from '../../../core';
|
|
10
14
|
|
|
11
|
-
export function useMagnetometer(
|
|
15
|
+
export function useMagnetometer(
|
|
16
|
+
updateIntervalMs?: number,
|
|
17
|
+
): Ref<IMagnetometerMeasurement | null> {
|
|
12
18
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
13
19
|
const measurement = ref<IMagnetometerMeasurement | null>(null);
|
|
14
20
|
let subscription: EventSubscription | undefined;
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
// unlike useAccelerometer there is no interval param to apply at subscribe time.
|
|
5
5
|
|
|
6
6
|
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
watchStepCount,
|
|
9
|
+
type EventSubscription,
|
|
10
|
+
type IPedometerResult,
|
|
11
|
+
} from '../../../core';
|
|
8
12
|
|
|
9
13
|
export function usePedometer(): Ref<IPedometerResult | null> {
|
|
10
14
|
// A plain ref: the value is a POJO result, not an engine node, so no shallowRef needed.
|
package/src/vue/index.ts
CHANGED
|
@@ -8,7 +8,11 @@ export type { IAccelerometerMeasurement } from '../core';
|
|
|
8
8
|
export { useBarometer } from './composables/use-barometer';
|
|
9
9
|
export type { IBarometerMeasurement } from '../core';
|
|
10
10
|
export { useDeviceMotion } from './composables/use-device-motion';
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
DeviceMotionOrientation,
|
|
13
|
+
gravity,
|
|
14
|
+
type IDeviceMotionMeasurement,
|
|
15
|
+
} from '../core';
|
|
12
16
|
export { useGyroscope } from './composables/use-gyroscope';
|
|
13
17
|
export type { IGyroscopeMeasurement } from '../core';
|
|
14
18
|
export { useLightSensor } from './composables/use-light-sensor';
|