@symbiote-native/sensors 0.2.1 → 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 +8 -13
- package/build/angular/services/barometer.service/index.js +8 -13
- package/build/angular/services/device-motion.service/index.js +8 -13
- package/build/angular/services/gyroscope.service/index.js +8 -13
- package/build/angular/services/light-sensor.service/index.js +8 -13
- package/build/angular/services/magnetometer-uncalibrated.service/index.js +10 -14
- package/build/angular/services/magnetometer.service/index.js +8 -13
- package/build/angular/services/pedometer.service/index.js +7 -11
- package/build/core/device-motion.js +3 -4
- 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 +16 -0
- package/build/svelte/index.js +14 -0
- package/build/svelte/runes/use-accelerometer.svelte.d.ts +4 -0
- package/build/svelte/runes/use-accelerometer.svelte.js +31 -0
- package/build/svelte/runes/use-barometer.svelte.d.ts +4 -0
- package/build/svelte/runes/use-barometer.svelte.js +22 -0
- package/build/svelte/runes/use-device-motion.svelte.d.ts +4 -0
- package/build/svelte/runes/use-device-motion.svelte.js +22 -0
- package/build/svelte/runes/use-gyroscope.svelte.d.ts +4 -0
- package/build/svelte/runes/use-gyroscope.svelte.js +22 -0
- package/build/svelte/runes/use-light-sensor.svelte.d.ts +4 -0
- package/build/svelte/runes/use-light-sensor.svelte.js +22 -0
- package/build/svelte/runes/use-magnetometer-uncalibrated.svelte.d.ts +4 -0
- package/build/svelte/runes/use-magnetometer-uncalibrated.svelte.js +22 -0
- package/build/svelte/runes/use-magnetometer.svelte.d.ts +4 -0
- package/build/svelte/runes/use-magnetometer.svelte.js +22 -0
- package/build/svelte/runes/use-pedometer.svelte.d.ts +4 -0
- package/build/svelte/runes/use-pedometer.svelte.js +20 -0
- 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 +11 -16
- package/build-ngc/angular/services/accelerometer.service/index.js.map +1 -1
- package/build-ngc/angular/services/barometer.service/index.js +11 -16
- package/build-ngc/angular/services/barometer.service/index.js.map +1 -1
- package/build-ngc/angular/services/device-motion.service/index.js +11 -16
- package/build-ngc/angular/services/device-motion.service/index.js.map +1 -1
- package/build-ngc/angular/services/gyroscope.service/index.js +11 -16
- package/build-ngc/angular/services/gyroscope.service/index.js.map +1 -1
- package/build-ngc/angular/services/light-sensor.service/index.js +11 -16
- package/build-ngc/angular/services/light-sensor.service/index.js.map +1 -1
- package/build-ngc/angular/services/magnetometer-uncalibrated.service/index.js +13 -17
- package/build-ngc/angular/services/magnetometer-uncalibrated.service/index.js.map +1 -1
- package/build-ngc/angular/services/magnetometer.service/index.js +11 -16
- package/build-ngc/angular/services/magnetometer.service/index.js.map +1 -1
- package/build-ngc/angular/services/pedometer.service/index.js +10 -14
- 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 +3 -4
- 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 +42 -14
- package/src/angular/index.ts +5 -1
- package/src/angular/services/accelerometer.service/index.ts +18 -14
- package/src/angular/services/barometer.service/index.ts +18 -14
- package/src/angular/services/device-motion.service/index.ts +18 -14
- package/src/angular/services/gyroscope.service/index.ts +18 -14
- package/src/angular/services/light-sensor.service/index.ts +18 -14
- package/src/angular/services/magnetometer-uncalibrated.service/index.ts +29 -17
- package/src/angular/services/magnetometer.service/index.ts +18 -14
- package/src/angular/services/pedometer.service/index.ts +14 -11
- package/src/core/barometer.ts +4 -1
- package/src/core/device-motion.ts +15 -6
- 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 +33 -0
- package/src/svelte/runes/use-accelerometer.svelte.ts +40 -0
- package/src/svelte/runes/use-barometer.svelte.ts +31 -0
- package/src/svelte/runes/use-device-motion.svelte.ts +31 -0
- package/src/svelte/runes/use-gyroscope.svelte.ts +31 -0
- package/src/svelte/runes/use-light-sensor.svelte.ts +31 -0
- package/src/svelte/runes/use-magnetometer-uncalibrated.svelte.ts +32 -0
- package/src/svelte/runes/use-magnetometer.svelte.ts +31 -0
- package/src/svelte/runes/use-pedometer.svelte.ts +27 -0
- package/src/svelte/svelte-ambient.d.ts +6 -0
- 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,33 @@
|
|
|
1
|
+
// @symbiote-native/sensors/svelte: the Svelte entry over the framework-agnostic core.
|
|
2
|
+
// useAccelerometer wires the Accelerometer singleton's addListener lifecycle onto Svelte's own
|
|
3
|
+
// `$effect` (runes/use-accelerometer.svelte.ts) — mirrors the lifecycle-bucket naming convention
|
|
4
|
+
// of adapters/svelte/src/runes (never `hooks/`/`composables/`, those are React's and Vue's terms).
|
|
5
|
+
|
|
6
|
+
export { useAccelerometer } from './runes/use-accelerometer.svelte';
|
|
7
|
+
export type { IAccelerometerMeasurement } from '../core';
|
|
8
|
+
export { useBarometer } from './runes/use-barometer.svelte';
|
|
9
|
+
export type { IBarometerMeasurement } from '../core';
|
|
10
|
+
export { useDeviceMotion } from './runes/use-device-motion.svelte';
|
|
11
|
+
export {
|
|
12
|
+
DeviceMotionOrientation,
|
|
13
|
+
gravity,
|
|
14
|
+
type IDeviceMotionMeasurement,
|
|
15
|
+
} from '../core';
|
|
16
|
+
export { useGyroscope } from './runes/use-gyroscope.svelte';
|
|
17
|
+
export type { IGyroscopeMeasurement } from '../core';
|
|
18
|
+
export { useLightSensor } from './runes/use-light-sensor.svelte';
|
|
19
|
+
export type { ILightSensorMeasurement } from '../core';
|
|
20
|
+
export { useMagnetometer } from './runes/use-magnetometer.svelte';
|
|
21
|
+
export type { IMagnetometerMeasurement } from '../core';
|
|
22
|
+
export { useMagnetometerUncalibrated } from './runes/use-magnetometer-uncalibrated.svelte';
|
|
23
|
+
export type { IMagnetometerUncalibratedMeasurement } from '../core';
|
|
24
|
+
export { usePedometer } from './runes/use-pedometer.svelte';
|
|
25
|
+
export {
|
|
26
|
+
watchStepCount,
|
|
27
|
+
getStepCountAsync,
|
|
28
|
+
isAvailableAsync,
|
|
29
|
+
getPermissionsAsync,
|
|
30
|
+
requestPermissionsAsync,
|
|
31
|
+
type IPedometerResult,
|
|
32
|
+
type IPedometerUpdateCallback,
|
|
33
|
+
} from '../core';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic Accelerometer singleton (core/).
|
|
2
|
+
// `.svelte.ts` (not `.ts`): runes ($state/$effect) only work in files with this extension
|
|
3
|
+
// outside an actual `.svelte` component; `runes/` is the framework's own lifecycle-bucket term
|
|
4
|
+
// (CLAUDE.md's <adapter_src_follows_framework_idioms>).
|
|
5
|
+
//
|
|
6
|
+
// Returns a boxed getter, not a bare `$state`: Svelte 5 reactivity is lexically scoped to the
|
|
7
|
+
// declaring module and doesn't survive being returned as a raw value, so callers read `.current`
|
|
8
|
+
// like unwrapping Vue's `Ref.value`.
|
|
9
|
+
//
|
|
10
|
+
// `updateIntervalMs` is a plain number, not a getter: it applies once at subscribe time and
|
|
11
|
+
// never reacts to a later change, matching the Vue/React twins.
|
|
12
|
+
import {
|
|
13
|
+
Accelerometer,
|
|
14
|
+
type EventSubscription,
|
|
15
|
+
type IAccelerometerMeasurement,
|
|
16
|
+
} from '../../core';
|
|
17
|
+
|
|
18
|
+
export function useAccelerometer(updateIntervalMs?: number): {
|
|
19
|
+
readonly current: IAccelerometerMeasurement | null;
|
|
20
|
+
} {
|
|
21
|
+
let measurement = $state<IAccelerometerMeasurement | null>(null);
|
|
22
|
+
|
|
23
|
+
$effect(() => {
|
|
24
|
+
if (updateIntervalMs !== undefined) {
|
|
25
|
+
Accelerometer.setUpdateInterval(updateIntervalMs);
|
|
26
|
+
}
|
|
27
|
+
// `measurement` is only ever written here, never read, so the effect has an empty dependency
|
|
28
|
+
// set and runs exactly once on mount, cleaning up exactly once on unmount.
|
|
29
|
+
const subscription: EventSubscription = Accelerometer.addListener(next => {
|
|
30
|
+
measurement = next;
|
|
31
|
+
});
|
|
32
|
+
return () => subscription.remove();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
get current(): IAccelerometerMeasurement | null {
|
|
37
|
+
return measurement;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic Barometer singleton (core/) — mirrors
|
|
2
|
+
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
|
+
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
|
+
// rather than a getter.
|
|
5
|
+
import {
|
|
6
|
+
Barometer,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IBarometerMeasurement,
|
|
9
|
+
} from '../../core';
|
|
10
|
+
|
|
11
|
+
export function useBarometer(updateIntervalMs?: number): {
|
|
12
|
+
readonly current: IBarometerMeasurement | null;
|
|
13
|
+
} {
|
|
14
|
+
let measurement = $state<IBarometerMeasurement | null>(null);
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (updateIntervalMs !== undefined) {
|
|
18
|
+
Barometer.setUpdateInterval(updateIntervalMs);
|
|
19
|
+
}
|
|
20
|
+
const subscription: EventSubscription = Barometer.addListener(next => {
|
|
21
|
+
measurement = next;
|
|
22
|
+
});
|
|
23
|
+
return () => subscription.remove();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
get current(): IBarometerMeasurement | null {
|
|
28
|
+
return measurement;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic DeviceMotion singleton (core/) — mirrors
|
|
2
|
+
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
|
+
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
|
+
// rather than a getter.
|
|
5
|
+
import {
|
|
6
|
+
DeviceMotion,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IDeviceMotionMeasurement,
|
|
9
|
+
} from '../../core';
|
|
10
|
+
|
|
11
|
+
export function useDeviceMotion(updateIntervalMs?: number): {
|
|
12
|
+
readonly current: IDeviceMotionMeasurement | null;
|
|
13
|
+
} {
|
|
14
|
+
let measurement = $state<IDeviceMotionMeasurement | null>(null);
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (updateIntervalMs !== undefined) {
|
|
18
|
+
DeviceMotion.setUpdateInterval(updateIntervalMs);
|
|
19
|
+
}
|
|
20
|
+
const subscription: EventSubscription = DeviceMotion.addListener(next => {
|
|
21
|
+
measurement = next;
|
|
22
|
+
});
|
|
23
|
+
return () => subscription.remove();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
get current(): IDeviceMotionMeasurement | null {
|
|
28
|
+
return measurement;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic Gyroscope singleton (core/) — mirrors
|
|
2
|
+
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
|
+
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
|
+
// rather than a getter.
|
|
5
|
+
import {
|
|
6
|
+
Gyroscope,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IGyroscopeMeasurement,
|
|
9
|
+
} from '../../core';
|
|
10
|
+
|
|
11
|
+
export function useGyroscope(updateIntervalMs?: number): {
|
|
12
|
+
readonly current: IGyroscopeMeasurement | null;
|
|
13
|
+
} {
|
|
14
|
+
let measurement = $state<IGyroscopeMeasurement | null>(null);
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (updateIntervalMs !== undefined) {
|
|
18
|
+
Gyroscope.setUpdateInterval(updateIntervalMs);
|
|
19
|
+
}
|
|
20
|
+
const subscription: EventSubscription = Gyroscope.addListener(next => {
|
|
21
|
+
measurement = next;
|
|
22
|
+
});
|
|
23
|
+
return () => subscription.remove();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
get current(): IGyroscopeMeasurement | null {
|
|
28
|
+
return measurement;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic LightSensor singleton (core/) — mirrors
|
|
2
|
+
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
|
+
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
|
+
// rather than a getter.
|
|
5
|
+
import {
|
|
6
|
+
LightSensor,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type ILightSensorMeasurement,
|
|
9
|
+
} from '../../core';
|
|
10
|
+
|
|
11
|
+
export function useLightSensor(updateIntervalMs?: number): {
|
|
12
|
+
readonly current: ILightSensorMeasurement | null;
|
|
13
|
+
} {
|
|
14
|
+
let measurement = $state<ILightSensorMeasurement | null>(null);
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (updateIntervalMs !== undefined) {
|
|
18
|
+
LightSensor.setUpdateInterval(updateIntervalMs);
|
|
19
|
+
}
|
|
20
|
+
const subscription: EventSubscription = LightSensor.addListener(next => {
|
|
21
|
+
measurement = next;
|
|
22
|
+
});
|
|
23
|
+
return () => subscription.remove();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
get current(): ILightSensorMeasurement | null {
|
|
28
|
+
return measurement;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic MagnetometerUncalibrated singleton (core/) —
|
|
2
|
+
// mirrors use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in
|
|
3
|
+
// `runes/` with a `.svelte.ts` extension, returns a boxed getter object, and takes a plain
|
|
4
|
+
// `updateIntervalMs` rather than a getter.
|
|
5
|
+
import {
|
|
6
|
+
MagnetometerUncalibrated,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IMagnetometerUncalibratedMeasurement,
|
|
9
|
+
} from '../../core';
|
|
10
|
+
|
|
11
|
+
export function useMagnetometerUncalibrated(updateIntervalMs?: number): {
|
|
12
|
+
readonly current: IMagnetometerUncalibratedMeasurement | null;
|
|
13
|
+
} {
|
|
14
|
+
let measurement = $state<IMagnetometerUncalibratedMeasurement | null>(null);
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (updateIntervalMs !== undefined) {
|
|
18
|
+
MagnetometerUncalibrated.setUpdateInterval(updateIntervalMs);
|
|
19
|
+
}
|
|
20
|
+
const subscription: EventSubscription =
|
|
21
|
+
MagnetometerUncalibrated.addListener(next => {
|
|
22
|
+
measurement = next;
|
|
23
|
+
});
|
|
24
|
+
return () => subscription.remove();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
get current(): IMagnetometerUncalibratedMeasurement | null {
|
|
29
|
+
return measurement;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic Magnetometer singleton (core/) — mirrors
|
|
2
|
+
// use-accelerometer.svelte.ts's shape exactly. See its header for why this lives in `runes/` with
|
|
3
|
+
// a `.svelte.ts` extension, returns a boxed getter object, and takes a plain `updateIntervalMs`
|
|
4
|
+
// rather than a getter.
|
|
5
|
+
import {
|
|
6
|
+
Magnetometer,
|
|
7
|
+
type EventSubscription,
|
|
8
|
+
type IMagnetometerMeasurement,
|
|
9
|
+
} from '../../core';
|
|
10
|
+
|
|
11
|
+
export function useMagnetometer(updateIntervalMs?: number): {
|
|
12
|
+
readonly current: IMagnetometerMeasurement | null;
|
|
13
|
+
} {
|
|
14
|
+
let measurement = $state<IMagnetometerMeasurement | null>(null);
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (updateIntervalMs !== undefined) {
|
|
18
|
+
Magnetometer.setUpdateInterval(updateIntervalMs);
|
|
19
|
+
}
|
|
20
|
+
const subscription: EventSubscription = Magnetometer.addListener(next => {
|
|
21
|
+
measurement = next;
|
|
22
|
+
});
|
|
23
|
+
return () => subscription.remove();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
get current(): IMagnetometerMeasurement | null {
|
|
28
|
+
return measurement;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Svelte lifecycle wiring over the framework-agnostic watchStepCount free function (core/) —
|
|
2
|
+
// mirrors use-accelerometer.svelte.ts's shape. Pedometer has no setUpdateInterval, so unlike
|
|
3
|
+
// useAccelerometer there is no interval param to apply at subscribe time. See
|
|
4
|
+
// use-accelerometer.svelte.ts's header for why this lives in `runes/` with a `.svelte.ts`
|
|
5
|
+
// extension and returns a boxed getter object.
|
|
6
|
+
import {
|
|
7
|
+
watchStepCount,
|
|
8
|
+
type EventSubscription,
|
|
9
|
+
type IPedometerResult,
|
|
10
|
+
} from '../../core';
|
|
11
|
+
|
|
12
|
+
export function usePedometer(): { readonly current: IPedometerResult | null } {
|
|
13
|
+
let result = $state<IPedometerResult | null>(null);
|
|
14
|
+
|
|
15
|
+
$effect(() => {
|
|
16
|
+
const subscription: EventSubscription = watchStepCount(next => {
|
|
17
|
+
result = next;
|
|
18
|
+
});
|
|
19
|
+
return () => subscription.remove();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
get current(): IPedometerResult | null {
|
|
24
|
+
return result;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Pulls in svelte's ambient global declarations ($state/$effect/...) for this package's tsc
|
|
2
|
+
// program. adapters/svelte gets these for free because render.ts does a real value import from
|
|
3
|
+
// 'svelte' (any file in a program importing a module loads its ambient globals for the whole
|
|
4
|
+
// program); this package has no such import, so a triple-slash reference does the same job
|
|
5
|
+
// explicitly rather than relying on an incidental side-effect.
|
|
6
|
+
/// <reference types="svelte" />
|
|
@@ -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';
|