@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,17 @@
|
|
|
1
|
+
// @symbiote-native/sensors/solid: the Solid entry over the framework-agnostic core.
|
|
2
|
+
// createAccelerometer wires the Accelerometer singleton's addListener lifecycle onto Solid's own
|
|
3
|
+
// signal + onCleanup (primitives/create-accelerometer) — `primitives/` and `create*` are Solid's
|
|
4
|
+
// terms for a composable reactive function, never `hooks/`/`composables/`/`runes/`, which are
|
|
5
|
+
// React's, Vue's and Svelte's. Same convention as adapters/solid/src/primitives.
|
|
6
|
+
//
|
|
7
|
+
// Every primitive returns an `Accessor`, and each DeviceSensor-shaped one takes its update
|
|
8
|
+
// interval as a number OR an accessor — see primitives/device-sensor-accessor for why.
|
|
9
|
+
export { createAccelerometer } from './primitives/create-accelerometer.js';
|
|
10
|
+
export { createBarometer } from './primitives/create-barometer.js';
|
|
11
|
+
export { createDeviceMotion } from './primitives/create-device-motion.js';
|
|
12
|
+
export { createGyroscope } from './primitives/create-gyroscope.js';
|
|
13
|
+
export { createLightSensor } from './primitives/create-light-sensor.js';
|
|
14
|
+
export { createMagnetometer } from './primitives/create-magnetometer.js';
|
|
15
|
+
export { createMagnetometerUncalibrated } from './primitives/create-magnetometer-uncalibrated.js';
|
|
16
|
+
export { createPedometer } from './primitives/create-pedometer.js';
|
|
17
|
+
export * from '../core/index.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { type IAccelerometerMeasurement } from '../../core';
|
|
3
|
+
import { type IUpdateIntervalMs } from './device-sensor-accessor';
|
|
4
|
+
export declare function createAccelerometer(updateIntervalMs?: IUpdateIntervalMs): Accessor<IAccelerometerMeasurement | null>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { type IBarometerMeasurement } from '../../core';
|
|
3
|
+
import { type IUpdateIntervalMs } from './device-sensor-accessor';
|
|
4
|
+
export declare function createBarometer(updateIntervalMs?: IUpdateIntervalMs): Accessor<IBarometerMeasurement | null>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { type IDeviceMotionMeasurement } from '../../core';
|
|
3
|
+
import { type IUpdateIntervalMs } from './device-sensor-accessor';
|
|
4
|
+
export declare function createDeviceMotion(updateIntervalMs?: IUpdateIntervalMs): Accessor<IDeviceMotionMeasurement | null>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { type IGyroscopeMeasurement } from '../../core';
|
|
3
|
+
import { type IUpdateIntervalMs } from './device-sensor-accessor';
|
|
4
|
+
export declare function createGyroscope(updateIntervalMs?: IUpdateIntervalMs): Accessor<IGyroscopeMeasurement | null>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { type ILightSensorMeasurement } from '../../core';
|
|
3
|
+
import { type IUpdateIntervalMs } from './device-sensor-accessor';
|
|
4
|
+
export declare function createLightSensor(updateIntervalMs?: IUpdateIntervalMs): Accessor<ILightSensorMeasurement | null>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { type IMagnetometerUncalibratedMeasurement } from '../../core';
|
|
3
|
+
import { type IUpdateIntervalMs } from './device-sensor-accessor';
|
|
4
|
+
export declare function createMagnetometerUncalibrated(updateIntervalMs?: IUpdateIntervalMs): Accessor<IMagnetometerUncalibratedMeasurement | null>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MagnetometerUncalibrated, } from '../../core/index.js';
|
|
2
|
+
import { createDeviceSensorAccessor, } from './device-sensor-accessor.js';
|
|
3
|
+
export function createMagnetometerUncalibrated(updateIntervalMs) {
|
|
4
|
+
return createDeviceSensorAccessor(MagnetometerUncalibrated, updateIntervalMs);
|
|
5
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { type IMagnetometerMeasurement } from '../../core';
|
|
3
|
+
import { type IUpdateIntervalMs } from './device-sensor-accessor';
|
|
4
|
+
export declare function createMagnetometer(updateIntervalMs?: IUpdateIntervalMs): Accessor<IMagnetometerMeasurement | null>;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
import { createSignal, onCleanup } from 'solid-js';
|
|
10
|
+
import { watchStepCount, } from '../../core/index.js';
|
|
11
|
+
export function createPedometer() {
|
|
12
|
+
const [result, setResult] = createSignal(null);
|
|
13
|
+
// Subscribed from the primitive body, not from an effect: React/Vue/Svelte start listening a
|
|
14
|
+
// tick after their seed runs, so a step count landing in that window is lost.
|
|
15
|
+
const subscription = watchStepCount(next => {
|
|
16
|
+
setResult(next);
|
|
17
|
+
});
|
|
18
|
+
onCleanup(() => {
|
|
19
|
+
subscription.remove();
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import type { EventSubscription, IListener } from '../../core';
|
|
3
|
+
export type IUpdateIntervalMs = number | Accessor<number | undefined> | undefined;
|
|
4
|
+
type ISensorHandle<Measurement> = {
|
|
5
|
+
addListener(listener: IListener<Measurement>): EventSubscription;
|
|
6
|
+
setUpdateInterval(intervalMs: number): void;
|
|
7
|
+
};
|
|
8
|
+
export declare function createDeviceSensorAccessor<Measurement>(sensor: ISensorHandle<Measurement>, updateIntervalMs?: IUpdateIntervalMs): Accessor<Measurement | null>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
import { createEffect, createSignal, on, onCleanup, untrack, } from 'solid-js';
|
|
33
|
+
export function createDeviceSensorAccessor(sensor, updateIntervalMs) {
|
|
34
|
+
const [measurement, setMeasurement] = createSignal(null);
|
|
35
|
+
function applyInterval(intervalMs) {
|
|
36
|
+
// `!== undefined`, not truthiness: 0 is a legitimate "as fast as possible" rate, and an
|
|
37
|
+
// unconditional call would stomp the rate another consumer of this shared singleton set.
|
|
38
|
+
if (intervalMs !== undefined) {
|
|
39
|
+
sensor.setUpdateInterval(intervalMs);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// untracked: a primitive built inside a tracked scope must not re-run — and re-subscribe —
|
|
43
|
+
// just because it read the caller's interval accessor once.
|
|
44
|
+
applyInterval(untrack(() => typeof updateIntervalMs === 'function'
|
|
45
|
+
? updateIntervalMs()
|
|
46
|
+
: updateIntervalMs));
|
|
47
|
+
// Subscribed from the primitive body, not from an effect: React/Vue/Svelte start listening a
|
|
48
|
+
// tick after their seed runs, so an event landing in that window is lost. Both statements here
|
|
49
|
+
// run in one synchronous tick and nothing can interleave.
|
|
50
|
+
const subscription = sensor.addListener(next => {
|
|
51
|
+
// The updater form, because `Measurement` is unconstrained — a bare value would be read as a
|
|
52
|
+
// reducer for any measurement type that could itself be callable.
|
|
53
|
+
setMeasurement(() => next);
|
|
54
|
+
});
|
|
55
|
+
onCleanup(() => {
|
|
56
|
+
subscription.remove();
|
|
57
|
+
});
|
|
58
|
+
if (typeof updateIntervalMs === 'function') {
|
|
59
|
+
// Only the rate changes — the native listener is per-sensor and unaffected, so re-subscribing
|
|
60
|
+
// (as React's interval-keyed effect does) would drop events for nothing.
|
|
61
|
+
createEffect(on(updateIntervalMs, intervalMs => {
|
|
62
|
+
applyInterval(intervalMs);
|
|
63
|
+
}, { defer: true }));
|
|
64
|
+
}
|
|
65
|
+
return measurement;
|
|
66
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { useAccelerometer } from './runes/use-accelerometer.svelte';
|
|
2
|
+
export type { IAccelerometerMeasurement } from '../core';
|
|
3
|
+
export { useBarometer } from './runes/use-barometer.svelte';
|
|
4
|
+
export type { IBarometerMeasurement } from '../core';
|
|
5
|
+
export { useDeviceMotion } from './runes/use-device-motion.svelte';
|
|
6
|
+
export { DeviceMotionOrientation, gravity, type IDeviceMotionMeasurement, } from '../core';
|
|
7
|
+
export { useGyroscope } from './runes/use-gyroscope.svelte';
|
|
8
|
+
export type { IGyroscopeMeasurement } from '../core';
|
|
9
|
+
export { useLightSensor } from './runes/use-light-sensor.svelte';
|
|
10
|
+
export type { ILightSensorMeasurement } from '../core';
|
|
11
|
+
export { useMagnetometer } from './runes/use-magnetometer.svelte';
|
|
12
|
+
export type { IMagnetometerMeasurement } from '../core';
|
|
13
|
+
export { useMagnetometerUncalibrated } from './runes/use-magnetometer-uncalibrated.svelte';
|
|
14
|
+
export type { IMagnetometerUncalibratedMeasurement } from '../core';
|
|
15
|
+
export { usePedometer } from './runes/use-pedometer.svelte';
|
|
16
|
+
export { watchStepCount, getStepCountAsync, isAvailableAsync, getPermissionsAsync, requestPermissionsAsync, type IPedometerResult, type IPedometerUpdateCallback, } from '../core';
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export { useAccelerometer } from './runes/use-accelerometer.svelte';
|
|
6
|
+
export { useBarometer } from './runes/use-barometer.svelte';
|
|
7
|
+
export { useDeviceMotion } from './runes/use-device-motion.svelte';
|
|
8
|
+
export { DeviceMotionOrientation, gravity, } from '../core/index.js';
|
|
9
|
+
export { useGyroscope } from './runes/use-gyroscope.svelte';
|
|
10
|
+
export { useLightSensor } from './runes/use-light-sensor.svelte';
|
|
11
|
+
export { useMagnetometer } from './runes/use-magnetometer.svelte';
|
|
12
|
+
export { useMagnetometerUncalibrated } from './runes/use-magnetometer-uncalibrated.svelte';
|
|
13
|
+
export { usePedometer } from './runes/use-pedometer.svelte';
|
|
14
|
+
export { watchStepCount, getStepCountAsync, isAvailableAsync, getPermissionsAsync, requestPermissionsAsync, } from '../core/index.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { Accelerometer, } from '../../core/index.js';
|
|
13
|
+
export function useAccelerometer(updateIntervalMs) {
|
|
14
|
+
let measurement = $state(null);
|
|
15
|
+
$effect(() => {
|
|
16
|
+
if (updateIntervalMs !== undefined) {
|
|
17
|
+
Accelerometer.setUpdateInterval(updateIntervalMs);
|
|
18
|
+
}
|
|
19
|
+
// `measurement` is only ever written here, never read, so the effect has an empty dependency
|
|
20
|
+
// set and runs exactly once on mount, cleaning up exactly once on unmount.
|
|
21
|
+
const subscription = Accelerometer.addListener(next => {
|
|
22
|
+
measurement = next;
|
|
23
|
+
});
|
|
24
|
+
return () => subscription.remove();
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
get current() {
|
|
28
|
+
return measurement;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { Barometer, } from '../../core/index.js';
|
|
6
|
+
export function useBarometer(updateIntervalMs) {
|
|
7
|
+
let measurement = $state(null);
|
|
8
|
+
$effect(() => {
|
|
9
|
+
if (updateIntervalMs !== undefined) {
|
|
10
|
+
Barometer.setUpdateInterval(updateIntervalMs);
|
|
11
|
+
}
|
|
12
|
+
const subscription = Barometer.addListener(next => {
|
|
13
|
+
measurement = next;
|
|
14
|
+
});
|
|
15
|
+
return () => subscription.remove();
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get current() {
|
|
19
|
+
return measurement;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { DeviceMotion, } from '../../core/index.js';
|
|
6
|
+
export function useDeviceMotion(updateIntervalMs) {
|
|
7
|
+
let measurement = $state(null);
|
|
8
|
+
$effect(() => {
|
|
9
|
+
if (updateIntervalMs !== undefined) {
|
|
10
|
+
DeviceMotion.setUpdateInterval(updateIntervalMs);
|
|
11
|
+
}
|
|
12
|
+
const subscription = DeviceMotion.addListener(next => {
|
|
13
|
+
measurement = next;
|
|
14
|
+
});
|
|
15
|
+
return () => subscription.remove();
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get current() {
|
|
19
|
+
return measurement;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { Gyroscope, } from '../../core/index.js';
|
|
6
|
+
export function useGyroscope(updateIntervalMs) {
|
|
7
|
+
let measurement = $state(null);
|
|
8
|
+
$effect(() => {
|
|
9
|
+
if (updateIntervalMs !== undefined) {
|
|
10
|
+
Gyroscope.setUpdateInterval(updateIntervalMs);
|
|
11
|
+
}
|
|
12
|
+
const subscription = Gyroscope.addListener(next => {
|
|
13
|
+
measurement = next;
|
|
14
|
+
});
|
|
15
|
+
return () => subscription.remove();
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get current() {
|
|
19
|
+
return measurement;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { LightSensor, } from '../../core/index.js';
|
|
6
|
+
export function useLightSensor(updateIntervalMs) {
|
|
7
|
+
let measurement = $state(null);
|
|
8
|
+
$effect(() => {
|
|
9
|
+
if (updateIntervalMs !== undefined) {
|
|
10
|
+
LightSensor.setUpdateInterval(updateIntervalMs);
|
|
11
|
+
}
|
|
12
|
+
const subscription = LightSensor.addListener(next => {
|
|
13
|
+
measurement = next;
|
|
14
|
+
});
|
|
15
|
+
return () => subscription.remove();
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get current() {
|
|
19
|
+
return measurement;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { MagnetometerUncalibrated, } from '../../core/index.js';
|
|
6
|
+
export function useMagnetometerUncalibrated(updateIntervalMs) {
|
|
7
|
+
let measurement = $state(null);
|
|
8
|
+
$effect(() => {
|
|
9
|
+
if (updateIntervalMs !== undefined) {
|
|
10
|
+
MagnetometerUncalibrated.setUpdateInterval(updateIntervalMs);
|
|
11
|
+
}
|
|
12
|
+
const subscription = MagnetometerUncalibrated.addListener(next => {
|
|
13
|
+
measurement = next;
|
|
14
|
+
});
|
|
15
|
+
return () => subscription.remove();
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get current() {
|
|
19
|
+
return measurement;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { Magnetometer, } from '../../core/index.js';
|
|
6
|
+
export function useMagnetometer(updateIntervalMs) {
|
|
7
|
+
let measurement = $state(null);
|
|
8
|
+
$effect(() => {
|
|
9
|
+
if (updateIntervalMs !== undefined) {
|
|
10
|
+
Magnetometer.setUpdateInterval(updateIntervalMs);
|
|
11
|
+
}
|
|
12
|
+
const subscription = Magnetometer.addListener(next => {
|
|
13
|
+
measurement = next;
|
|
14
|
+
});
|
|
15
|
+
return () => subscription.remove();
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
get current() {
|
|
19
|
+
return measurement;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { watchStepCount, } from '../../core/index.js';
|
|
7
|
+
export function usePedometer() {
|
|
8
|
+
let result = $state(null);
|
|
9
|
+
$effect(() => {
|
|
10
|
+
const subscription = watchStepCount(next => {
|
|
11
|
+
result = next;
|
|
12
|
+
});
|
|
13
|
+
return () => subscription.remove();
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
get current() {
|
|
17
|
+
return result;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// across reactive updates), this subscribes exactly once at mount and never needs to react to
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
|
|
8
|
-
import { Barometer } from '../../../core/index.js';
|
|
8
|
+
import { Barometer, } from '../../../core/index.js';
|
|
9
9
|
export function useBarometer(updateIntervalMs) {
|
|
10
10
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
11
11
|
const measurement = ref(null);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// across reactive updates), this subscribes exactly once at mount and never needs to react to
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
|
|
8
|
-
import { DeviceMotion } from '../../../core/index.js';
|
|
8
|
+
import { DeviceMotion, } from '../../../core/index.js';
|
|
9
9
|
export function useDeviceMotion(updateIntervalMs) {
|
|
10
10
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
11
11
|
const measurement = ref(null);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// across reactive updates), this subscribes exactly once at mount and never needs to react to
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
|
|
8
|
-
import { Gyroscope } from '../../../core/index.js';
|
|
8
|
+
import { Gyroscope, } from '../../../core/index.js';
|
|
9
9
|
export function useGyroscope(updateIntervalMs) {
|
|
10
10
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
11
11
|
const measurement = ref(null);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// across reactive updates), this subscribes exactly once at mount and never needs to react to
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
|
|
8
|
-
import { LightSensor } from '../../../core/index.js';
|
|
8
|
+
import { LightSensor, } from '../../../core/index.js';
|
|
9
9
|
export function useLightSensor(updateIntervalMs) {
|
|
10
10
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
11
11
|
const measurement = ref(null);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// across reactive updates), this subscribes exactly once at mount and never needs to react to
|
|
6
6
|
// a later change of updateIntervalMs, so a plain numeric param is enough.
|
|
7
7
|
import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
|
|
8
|
-
import { Magnetometer } from '../../../core/index.js';
|
|
8
|
+
import { Magnetometer, } from '../../../core/index.js';
|
|
9
9
|
export function useMagnetometer(updateIntervalMs) {
|
|
10
10
|
// A plain ref: the value is a POJO measurement, not an engine node, so no shallowRef needed.
|
|
11
11
|
const measurement = ref(null);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// onMounted/onUnmounted shape of useAccelerometer. Pedometer has no setUpdateInterval, so
|
|
4
4
|
// unlike useAccelerometer there is no interval param to apply at subscribe time.
|
|
5
5
|
import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
|
|
6
|
-
import { watchStepCount } from '../../../core/index.js';
|
|
6
|
+
import { watchStepCount, } from '../../../core/index.js';
|
|
7
7
|
export function usePedometer() {
|
|
8
8
|
// A plain ref: the value is a POJO result, not an engine node, so no shallowRef needed.
|
|
9
9
|
const result = ref(null);
|
package/build/vue/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type { IAccelerometerMeasurement } from '../core';
|
|
|
3
3
|
export { useBarometer } from './composables/use-barometer';
|
|
4
4
|
export type { IBarometerMeasurement } from '../core';
|
|
5
5
|
export { useDeviceMotion } from './composables/use-device-motion';
|
|
6
|
-
export { DeviceMotionOrientation, gravity, type IDeviceMotionMeasurement } from '../core';
|
|
6
|
+
export { DeviceMotionOrientation, gravity, type IDeviceMotionMeasurement, } from '../core';
|
|
7
7
|
export { useGyroscope } from './composables/use-gyroscope';
|
|
8
8
|
export type { IGyroscopeMeasurement } from '../core';
|
|
9
9
|
export { useLightSensor } from './composables/use-light-sensor';
|
package/build/vue/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export { useAccelerometer } from './composables/use-accelerometer/index.js';
|
|
6
6
|
export { useBarometer } from './composables/use-barometer/index.js';
|
|
7
7
|
export { useDeviceMotion } from './composables/use-device-motion/index.js';
|
|
8
|
-
export { DeviceMotionOrientation, gravity } from '../core/index.js';
|
|
8
|
+
export { DeviceMotionOrientation, gravity, } from '../core/index.js';
|
|
9
9
|
export { useGyroscope } from './composables/use-gyroscope/index.js';
|
|
10
10
|
export { useLightSensor } from './composables/use-light-sensor/index.js';
|
|
11
11
|
export { useMagnetometer } from './composables/use-magnetometer/index.js';
|
|
@@ -3,7 +3,7 @@ export type { IAccelerometerMeasurement } from '../core';
|
|
|
3
3
|
export { BarometerService } from './services/barometer.service';
|
|
4
4
|
export type { IBarometerMeasurement } from '../core';
|
|
5
5
|
export { DeviceMotionService } from './services/device-motion.service';
|
|
6
|
-
export { DeviceMotionOrientation, gravity, type IDeviceMotionMeasurement } from '../core';
|
|
6
|
+
export { DeviceMotionOrientation, gravity, type IDeviceMotionMeasurement, } from '../core';
|
|
7
7
|
export { GyroscopeService } from './services/gyroscope.service';
|
|
8
8
|
export type { IGyroscopeMeasurement } from '../core';
|
|
9
9
|
export { LightSensorService } from './services/light-sensor.service';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export { AccelerometerService } from './services/accelerometer.service';
|
|
4
4
|
export { BarometerService } from './services/barometer.service';
|
|
5
5
|
export { DeviceMotionService } from './services/device-motion.service';
|
|
6
|
-
export { DeviceMotionOrientation, gravity } from '../core';
|
|
6
|
+
export { DeviceMotionOrientation, gravity, } from '../core';
|
|
7
7
|
export { GyroscopeService } from './services/gyroscope.service';
|
|
8
8
|
export { LightSensorService } from './services/light-sensor.service';
|
|
9
9
|
export { MagnetometerService } from './services/magnetometer.service';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/angular/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,iEAAiE;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/angular/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,iEAAiE;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EACL,uBAAuB,EACvB,OAAO,GAER,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAE/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,GAGxB,MAAM,SAAS,CAAC"}
|