@mentra/miniapp 0.3.0-dev.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 +259 -0
- package/dist/background/index.d.ts +59 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +25 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/register.d.ts +38 -0
- package/dist/background/register.d.ts.map +1 -0
- package/dist/background/register.js +75 -0
- package/dist/background/register.js.map +1 -0
- package/dist/dev-reload.d.ts +21 -0
- package/dist/dev-reload.d.ts.map +1 -0
- package/dist/dev-reload.js +62 -0
- package/dist/dev-reload.js.map +1 -0
- package/dist/envelope.d.ts +23 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +47 -0
- package/dist/envelope.js.map +1 -0
- package/dist/globals.d.ts +54 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +12 -0
- package/dist/globals.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/actions.d.ts +54 -0
- package/dist/modules/actions.d.ts.map +1 -0
- package/dist/modules/actions.js +122 -0
- package/dist/modules/actions.js.map +1 -0
- package/dist/modules/auth.d.ts +25 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +52 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/base64.d.ts +16 -0
- package/dist/modules/base64.d.ts.map +1 -0
- package/dist/modules/base64.js +92 -0
- package/dist/modules/base64.js.map +1 -0
- package/dist/modules/blob.d.ts +161 -0
- package/dist/modules/blob.d.ts.map +1 -0
- package/dist/modules/blob.js +277 -0
- package/dist/modules/blob.js.map +1 -0
- package/dist/modules/camera.d.ts +137 -0
- package/dist/modules/camera.d.ts.map +1 -0
- package/dist/modules/camera.js +104 -0
- package/dist/modules/camera.js.map +1 -0
- package/dist/modules/cloud.d.ts +34 -0
- package/dist/modules/cloud.d.ts.map +1 -0
- package/dist/modules/cloud.js +70 -0
- package/dist/modules/cloud.js.map +1 -0
- package/dist/modules/dashboard.d.ts +16 -0
- package/dist/modules/dashboard.d.ts.map +1 -0
- package/dist/modules/dashboard.js +27 -0
- package/dist/modules/dashboard.js.map +1 -0
- package/dist/modules/display.d.ts +106 -0
- package/dist/modules/display.d.ts.map +1 -0
- package/dist/modules/display.js +57 -0
- package/dist/modules/display.js.map +1 -0
- package/dist/modules/events.d.ts +167 -0
- package/dist/modules/events.d.ts.map +1 -0
- package/dist/modules/events.js +123 -0
- package/dist/modules/events.js.map +1 -0
- package/dist/modules/glasses.d.ts +28 -0
- package/dist/modules/glasses.d.ts.map +1 -0
- package/dist/modules/glasses.js +39 -0
- package/dist/modules/glasses.js.map +1 -0
- package/dist/modules/heading.d.ts +16 -0
- package/dist/modules/heading.d.ts.map +1 -0
- package/dist/modules/heading.js +20 -0
- package/dist/modules/heading.js.map +1 -0
- package/dist/modules/imu.d.ts +31 -0
- package/dist/modules/imu.d.ts.map +1 -0
- package/dist/modules/imu.js +40 -0
- package/dist/modules/imu.js.map +1 -0
- package/dist/modules/input.d.ts +34 -0
- package/dist/modules/input.d.ts.map +1 -0
- package/dist/modules/input.js +50 -0
- package/dist/modules/input.js.map +1 -0
- package/dist/modules/led.d.ts +35 -0
- package/dist/modules/led.d.ts.map +1 -0
- package/dist/modules/led.js +39 -0
- package/dist/modules/led.js.map +1 -0
- package/dist/modules/location.d.ts +27 -0
- package/dist/modules/location.d.ts.map +1 -0
- package/dist/modules/location.js +35 -0
- package/dist/modules/location.js.map +1 -0
- package/dist/modules/mic.d.ts +44 -0
- package/dist/modules/mic.d.ts.map +1 -0
- package/dist/modules/mic.js +67 -0
- package/dist/modules/mic.js.map +1 -0
- package/dist/modules/miniapps.d.ts +72 -0
- package/dist/modules/miniapps.d.ts.map +1 -0
- package/dist/modules/miniapps.js +48 -0
- package/dist/modules/miniapps.js.map +1 -0
- package/dist/modules/navigation.d.ts +326 -0
- package/dist/modules/navigation.d.ts.map +1 -0
- package/dist/modules/navigation.js +386 -0
- package/dist/modules/navigation.js.map +1 -0
- package/dist/modules/permissions.d.ts +58 -0
- package/dist/modules/permissions.d.ts.map +1 -0
- package/dist/modules/permissions.js +66 -0
- package/dist/modules/permissions.js.map +1 -0
- package/dist/modules/phone.d.ts +61 -0
- package/dist/modules/phone.d.ts.map +1 -0
- package/dist/modules/phone.js +94 -0
- package/dist/modules/phone.js.map +1 -0
- package/dist/modules/pivots/engine.d.ts +169 -0
- package/dist/modules/pivots/engine.d.ts.map +1 -0
- package/dist/modules/pivots/engine.js +779 -0
- package/dist/modules/pivots/engine.js.map +1 -0
- package/dist/modules/pivots/geometry.d.ts +84 -0
- package/dist/modules/pivots/geometry.d.ts.map +1 -0
- package/dist/modules/pivots/geometry.js +371 -0
- package/dist/modules/pivots/geometry.js.map +1 -0
- package/dist/modules/pivots/instructions.d.ts +139 -0
- package/dist/modules/pivots/instructions.d.ts.map +1 -0
- package/dist/modules/pivots/instructions.js +280 -0
- package/dist/modules/pivots/instructions.js.map +1 -0
- package/dist/modules/speaker.d.ts +163 -0
- package/dist/modules/speaker.d.ts.map +1 -0
- package/dist/modules/speaker.js +250 -0
- package/dist/modules/speaker.js.map +1 -0
- package/dist/modules/storage.d.ts +50 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/dist/modules/storage.js +99 -0
- package/dist/modules/storage.js.map +1 -0
- package/dist/modules/stream.d.ts +129 -0
- package/dist/modules/stream.d.ts.map +1 -0
- package/dist/modules/stream.js +52 -0
- package/dist/modules/stream.js.map +1 -0
- package/dist/modules/system.d.ts +45 -0
- package/dist/modules/system.d.ts.map +1 -0
- package/dist/modules/system.js +42 -0
- package/dist/modules/system.js.map +1 -0
- package/dist/modules/transcription.d.ts +67 -0
- package/dist/modules/transcription.d.ts.map +1 -0
- package/dist/modules/transcription.js +106 -0
- package/dist/modules/transcription.js.map +1 -0
- package/dist/modules/translation.d.ts +59 -0
- package/dist/modules/translation.d.ts.map +1 -0
- package/dist/modules/translation.js +119 -0
- package/dist/modules/translation.js.map +1 -0
- package/dist/modules/ui.d.ts +186 -0
- package/dist/modules/ui.d.ts.map +1 -0
- package/dist/modules/ui.js +293 -0
- package/dist/modules/ui.js.map +1 -0
- package/dist/protocol.d.ts +294 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +320 -0
- package/dist/protocol.js.map +1 -0
- package/dist/react/MentraProvider.d.ts +33 -0
- package/dist/react/MentraProvider.d.ts.map +1 -0
- package/dist/react/MentraProvider.js +15 -0
- package/dist/react/MentraProvider.js.map +1 -0
- package/dist/react/MiniappHeader.d.ts +44 -0
- package/dist/react/MiniappHeader.d.ts.map +1 -0
- package/dist/react/MiniappHeader.js +32 -0
- package/dist/react/MiniappHeader.js.map +1 -0
- package/dist/react/index.d.ts +13 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useCapabilities.d.ts +26 -0
- package/dist/react/useCapabilities.d.ts.map +1 -0
- package/dist/react/useCapabilities.js +27 -0
- package/dist/react/useCapabilities.js.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts +27 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.js +36 -0
- package/dist/react/useCapsuleHeaderStyle.js.map +1 -0
- package/dist/react/useColorScheme.d.ts +18 -0
- package/dist/react/useColorScheme.d.ts.map +1 -0
- package/dist/react/useColorScheme.js +24 -0
- package/dist/react/useColorScheme.js.map +1 -0
- package/dist/react/useConnected.d.ts +17 -0
- package/dist/react/useConnected.d.ts.map +1 -0
- package/dist/react/useConnected.js +39 -0
- package/dist/react/useConnected.js.map +1 -0
- package/dist/react/useRpc.d.ts +29 -0
- package/dist/react/useRpc.d.ts.map +1 -0
- package/dist/react/useRpc.js +82 -0
- package/dist/react/useRpc.js.map +1 -0
- package/dist/react/useSafeArea.d.ts +21 -0
- package/dist/react/useSafeArea.d.ts.map +1 -0
- package/dist/react/useSafeArea.js +22 -0
- package/dist/react/useSafeArea.js.map +1 -0
- package/dist/session.d.ts +310 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +653 -0
- package/dist/session.js.map +1 -0
- package/dist/sub-path-types.test-d.d.ts +28 -0
- package/dist/sub-path-types.test-d.d.ts.map +1 -0
- package/dist/sub-path-types.test-d.js +37 -0
- package/dist/sub-path-types.test-d.js.map +1 -0
- package/dist/transport/auto.d.ts +35 -0
- package/dist/transport/auto.d.ts.map +1 -0
- package/dist/transport/auto.js +125 -0
- package/dist/transport/auto.js.map +1 -0
- package/dist/transport/dispatch.d.ts +43 -0
- package/dist/transport/dispatch.d.ts.map +1 -0
- package/dist/transport/dispatch.js +91 -0
- package/dist/transport/dispatch.js.map +1 -0
- package/dist/transport/local-socket.d.ts +28 -0
- package/dist/transport/local-socket.d.ts.map +1 -0
- package/dist/transport/local-socket.js +80 -0
- package/dist/transport/local-socket.js.map +1 -0
- package/dist/transport/mock.d.ts +54 -0
- package/dist/transport/mock.d.ts.map +1 -0
- package/dist/transport/mock.js +205 -0
- package/dist/transport/mock.js.map +1 -0
- package/dist/transport/postmessage.d.ts +36 -0
- package/dist/transport/postmessage.d.ts.map +1 -0
- package/dist/transport/postmessage.js +78 -0
- package/dist/transport/postmessage.js.map +1 -0
- package/dist/transport/types.d.ts +25 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +11 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/ui/index.d.ts +98 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +32 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +75 -0
- package/src/background/index.ts +152 -0
- package/src/background/register.ts +85 -0
- package/src/dev-reload.ts +60 -0
- package/src/envelope.ts +54 -0
- package/src/globals.ts +62 -0
- package/src/index.ts +171 -0
- package/src/modules/actions.ts +156 -0
- package/src/modules/auth.ts +68 -0
- package/src/modules/base64.ts +87 -0
- package/src/modules/blob.ts +341 -0
- package/src/modules/camera.ts +196 -0
- package/src/modules/cloud.ts +94 -0
- package/src/modules/dashboard.ts +31 -0
- package/src/modules/display.ts +122 -0
- package/src/modules/events.ts +264 -0
- package/src/modules/glasses.ts +44 -0
- package/src/modules/heading.ts +23 -0
- package/src/modules/imu.ts +44 -0
- package/src/modules/input.ts +71 -0
- package/src/modules/led.ts +61 -0
- package/src/modules/location.ts +39 -0
- package/src/modules/mic.ts +74 -0
- package/src/modules/miniapps.ts +90 -0
- package/src/modules/navigation.ts +670 -0
- package/src/modules/permissions.ts +84 -0
- package/src/modules/phone.ts +120 -0
- package/src/modules/pivots/engine.ts +863 -0
- package/src/modules/pivots/geometry.ts +409 -0
- package/src/modules/pivots/instructions.ts +343 -0
- package/src/modules/speaker.ts +328 -0
- package/src/modules/storage.ts +109 -0
- package/src/modules/stream.ts +163 -0
- package/src/modules/system.ts +76 -0
- package/src/modules/transcription.ts +128 -0
- package/src/modules/translation.ts +149 -0
- package/src/modules/ui.ts +498 -0
- package/src/protocol.ts +371 -0
- package/src/react/MentraProvider.tsx +50 -0
- package/src/react/MiniappHeader.tsx +122 -0
- package/src/react/index.ts +12 -0
- package/src/react/useCapabilities.ts +29 -0
- package/src/react/useCapsuleHeaderStyle.ts +54 -0
- package/src/react/useColorScheme.ts +26 -0
- package/src/react/useConnected.ts +47 -0
- package/src/react/useRpc.ts +106 -0
- package/src/react/useSafeArea.ts +40 -0
- package/src/session.ts +878 -0
- package/src/sub-path-types.test-d.ts +49 -0
- package/src/transport/auto.ts +143 -0
- package/src/transport/dispatch.ts +106 -0
- package/src/transport/local-socket.ts +93 -0
- package/src/transport/mock.ts +248 -0
- package/src/transport/postmessage.ts +95 -0
- package/src/transport/types.ts +26 -0
- package/src/ui/index.ts +122 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PhoneModule — phone device-state events.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors cloud SDK v3's PhoneManager structure. Sub-namespaced by concern:
|
|
5
|
+
*
|
|
6
|
+
* session.phone.notifications.{on, hasPermission, stop}
|
|
7
|
+
* session.phone.calendar.{on, hasPermission, stop}
|
|
8
|
+
* session.phone.onBattery(...) // stays flat
|
|
9
|
+
*
|
|
10
|
+
* Imperative phone-OS calls (share, openUrl, copyToClipboard, download) live
|
|
11
|
+
* on `session.system` — different shape (one-shot calls vs. event subs) so
|
|
12
|
+
* we don't conflate them.
|
|
13
|
+
*
|
|
14
|
+
* `phone.notifications.onDismissed` is Android-only. iOS doesn't expose
|
|
15
|
+
* notification-dismiss callbacks to apps (Apple privacy restriction);
|
|
16
|
+
* subscribing on iOS is a no-op even though the API is present.
|
|
17
|
+
*/
|
|
18
|
+
import { MiniappStreamType } from "../protocol";
|
|
19
|
+
class TrackedSubs {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.unsubs = new Set();
|
|
22
|
+
}
|
|
23
|
+
track(unsub) {
|
|
24
|
+
this.unsubs.add(unsub);
|
|
25
|
+
return () => {
|
|
26
|
+
this.unsubs.delete(unsub);
|
|
27
|
+
unsub();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
stop() {
|
|
31
|
+
for (const u of this.unsubs) {
|
|
32
|
+
try {
|
|
33
|
+
u();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* ignore */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
this.unsubs.clear();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class PhoneNotificationsModule extends TrackedSubs {
|
|
43
|
+
constructor(session) {
|
|
44
|
+
super();
|
|
45
|
+
this.session = session;
|
|
46
|
+
}
|
|
47
|
+
on(handler) {
|
|
48
|
+
return this.track(this.session._subscribe(MiniappStreamType.PHONE_NOTIFICATION, handler));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to dismiss events for phone notifications. Fires when the user
|
|
52
|
+
* dismisses (swipes away or clears) a notification.
|
|
53
|
+
*
|
|
54
|
+
* **Android only.** iOS does not expose dismiss callbacks to apps (Apple
|
|
55
|
+
* privacy restriction); subscribing on iOS succeeds but no events ever
|
|
56
|
+
* fire. The matching `notifications.on()` post-event still works on both
|
|
57
|
+
* platforms.
|
|
58
|
+
*/
|
|
59
|
+
onDismissed(handler) {
|
|
60
|
+
return this.track(this.session._subscribe(MiniappStreamType.PHONE_NOTIFICATION_DISMISSED, handler));
|
|
61
|
+
}
|
|
62
|
+
/** True iff `READ_NOTIFICATIONS` is declared in the miniapp's manifest. */
|
|
63
|
+
get hasPermission() {
|
|
64
|
+
return this.session._hasManifestPermission("READ_NOTIFICATIONS");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export class PhoneCalendarModule extends TrackedSubs {
|
|
68
|
+
constructor(session) {
|
|
69
|
+
super();
|
|
70
|
+
this.session = session;
|
|
71
|
+
}
|
|
72
|
+
on(handler) {
|
|
73
|
+
return this.track(this.session._subscribe(MiniappStreamType.CALENDAR_EVENT, handler));
|
|
74
|
+
}
|
|
75
|
+
/** True iff `CALENDAR` is declared in the miniapp's manifest. */
|
|
76
|
+
get hasPermission() {
|
|
77
|
+
return this.session._hasManifestPermission("CALENDAR");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export class PhoneModule {
|
|
81
|
+
constructor(session) {
|
|
82
|
+
this.session = session;
|
|
83
|
+
this.notifications = new PhoneNotificationsModule(session);
|
|
84
|
+
this.calendar = new PhoneCalendarModule(session);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Phone battery events. Stays flat (not sub-namespaced) — single event,
|
|
88
|
+
* no extra surface.
|
|
89
|
+
*/
|
|
90
|
+
onBattery(handler) {
|
|
91
|
+
return this.session._subscribe(MiniappStreamType.PHONE_BATTERY, handler);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=phone.js.map
|
|
@@ -0,0 +1 @@
|
|
|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AC,sBAAsB,CAAC,oBAAoB,CAAC,CAAA;IAClE,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,YAA6B,OAAuB;QAClD,KAAK,EAAE,CAAA;QADoB,YAAO,GAAP,OAAO,CAAgB;IAEpD,CAAC;IAED,EAAE,CAAC,OAA0C;QAC3C,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,cAAc,EAAE,OAAkC,CAAC,CAC9F,CAAA;IACH,CAAC;IAED,iEAAiE;IACjE,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC;CACF;AAED,MAAM,OAAO,WAAW;IAItB,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;QAClD,IAAI,CAAC,aAAa,GAAG,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAA;QAC1D,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAA;IAClD,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,OAAoC;QAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,aAAa,EAAE,OAAkC,CAAC,CAAA;IACrG,CAAC;CACF"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pivot engine — internal to NavigationModule.
|
|
3
|
+
*
|
|
4
|
+
* Owns the per-trip pivot list and the cursor that walks it as GPS
|
|
5
|
+
* ticks come in. Public consumers of the SDK never touch this class
|
|
6
|
+
* directly — they go through `navigation.onPivot()` / `getPivots()` /
|
|
7
|
+
* `getActivePivot()` / `getUpcomingPivot()`.
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle:
|
|
10
|
+
* - `reset()` on `navigation.start()`. Clears pivot list, cursor,
|
|
11
|
+
* all subscribers stay attached.
|
|
12
|
+
* - `setRoute(route)` on the first `onRoute` after start, and on
|
|
13
|
+
* every subsequent reroute. Rebuilds the pivot list from
|
|
14
|
+
* scratch.
|
|
15
|
+
* - `onLocationUpdate(coords)` on every GPS fix. Computes which
|
|
16
|
+
* events to fire and emits them to subscribers.
|
|
17
|
+
* - `reset()` on `stop()` / `arrived`.
|
|
18
|
+
*
|
|
19
|
+
* The engine doesn't subscribe to GPS itself — `NavigationModule`
|
|
20
|
+
* owns that, calling `onLocationUpdate(coords)` from its own GPS
|
|
21
|
+
* subscription. Keeps this class pure-state with no side effects.
|
|
22
|
+
*/
|
|
23
|
+
import type { LatLng, ManeuverKind, NavRoute, Pivot, PivotEvent, PivotOptions, TravelMode } from "../navigation";
|
|
24
|
+
import { bearingDeg, haversineMeters, signedAngleDiff } from "./geometry";
|
|
25
|
+
type Subscriber = (event: PivotEvent) => void;
|
|
26
|
+
export declare class PivotEngine {
|
|
27
|
+
private opts;
|
|
28
|
+
private pivots;
|
|
29
|
+
private states;
|
|
30
|
+
/** Index of the next pivot we expect the user to encounter. */
|
|
31
|
+
private cursor;
|
|
32
|
+
/** Pivot currently between `entered` and `exited`, or null. */
|
|
33
|
+
private activePivotIndex;
|
|
34
|
+
/**
|
|
35
|
+
* Latest route polyline + its cumulative-distance array. Retained
|
|
36
|
+
* after `setRoute()` so `onLocationUpdate` can project the user onto
|
|
37
|
+
* the path and compare along-path distance to each pivot's
|
|
38
|
+
* `distanceAlongRouteMeters`. This is what makes a pedestrian on the
|
|
39
|
+
* wrong sidewalk still trigger the upcoming turn — straight-line
|
|
40
|
+
* distance to the pivot point would miss it.
|
|
41
|
+
*/
|
|
42
|
+
private points;
|
|
43
|
+
private cumulative;
|
|
44
|
+
/**
|
|
45
|
+
* Async road-name resolver injected by NavigationModule. Backs the
|
|
46
|
+
* engine's last-resort fallback: when a pivot's `fromRoad` or
|
|
47
|
+
* `toRoad` is null after Routes-API instruction parsing, the
|
|
48
|
+
* engine samples a coordinate ~SAMPLE_OFFSET_M behind/ahead along
|
|
49
|
+
* the polyline and asks the host to reverse-geocode it. Patched
|
|
50
|
+
* onto the pivot in place when the response lands. Null when no
|
|
51
|
+
* resolver is wired — the engine simply leaves the field null.
|
|
52
|
+
*/
|
|
53
|
+
private roadNameResolver;
|
|
54
|
+
/**
|
|
55
|
+
* Generation counter bumped on every route rebuild. Geocode
|
|
56
|
+
* responses from a stale route are discarded by comparing the
|
|
57
|
+
* generation captured at request time against the current value.
|
|
58
|
+
* Without this, a slow geocode reply from a previous route can
|
|
59
|
+
* stamp a fresh route's pivot with the wrong road name.
|
|
60
|
+
*/
|
|
61
|
+
private routeGeneration;
|
|
62
|
+
private subscribers;
|
|
63
|
+
constructor(mode: TravelMode, opts: PivotOptions | undefined);
|
|
64
|
+
/** Replace the trip-level options. Used if `start()` is called
|
|
65
|
+
* with new options without a full reset. */
|
|
66
|
+
updateOptions(mode: TravelMode, opts: PivotOptions | undefined): void;
|
|
67
|
+
/**
|
|
68
|
+
* Install the host-backed reverse-geocode resolver. NavigationModule
|
|
69
|
+
* calls this once after constructing the engine, wiring through to
|
|
70
|
+
* the host's Geocoding REST adapter. When unset, the engine simply
|
|
71
|
+
* leaves null road names in place — geocoding is a best-effort
|
|
72
|
+
* enhancement, not a requirement.
|
|
73
|
+
*/
|
|
74
|
+
setRoadNameResolver(resolver: ((coord: LatLng) => Promise<string | null>) | null): void;
|
|
75
|
+
/**
|
|
76
|
+
* Clear all pivot state. Pivots = []. Cursor reset. Active pivot
|
|
77
|
+
* cleared. Subscribers stay attached so the next `setRoute` can
|
|
78
|
+
* fire events.
|
|
79
|
+
*/
|
|
80
|
+
reset(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Rebuild the pivot list from a Routes-API computed step list. This
|
|
83
|
+
* is the high-accuracy path used during live trips: `instruction`
|
|
84
|
+
* strings on each step name the road being entered unambiguously
|
|
85
|
+
* ("Turn left onto Octavia Blvd"), and the explicit `endLat/endLng`
|
|
86
|
+
* gives us the exact corner location without polyline-walking math.
|
|
87
|
+
*
|
|
88
|
+
* NavigationModule calls this once per route lifecycle — at trip
|
|
89
|
+
* start (after firing NAVIGATION_COMPUTE_ROUTE), and again on every
|
|
90
|
+
* reroute. The cursor + state machinery (approaching / entered /
|
|
91
|
+
* exited) is identical to `setRoute` — only the pivot construction
|
|
92
|
+
* differs.
|
|
93
|
+
*
|
|
94
|
+
* If the computed-step list is empty or no pivots survive the
|
|
95
|
+
* filters in `extractPivotsFromComputedSteps`, this falls back to
|
|
96
|
+
* `setRoute(route)` so the geometry-derived pivots are still
|
|
97
|
+
* available. That keeps the engine working on platforms that don't
|
|
98
|
+
* yet have Routes API plumbing.
|
|
99
|
+
*/
|
|
100
|
+
setRouteFromComputedSteps(route: NavRoute, computedSteps: Array<{
|
|
101
|
+
lat: number;
|
|
102
|
+
lng: number;
|
|
103
|
+
endLat: number;
|
|
104
|
+
endLng: number;
|
|
105
|
+
distanceMeters: number;
|
|
106
|
+
maneuver?: ManeuverKind;
|
|
107
|
+
instruction?: string;
|
|
108
|
+
/** Host-resolved road name (Phase 1). Optional for backward
|
|
109
|
+
* compat with callers that only supply `instruction`. */
|
|
110
|
+
road?: string | null;
|
|
111
|
+
}> | undefined): void;
|
|
112
|
+
/**
|
|
113
|
+
* Rebuild the pivot list from a fresh route. Called on every
|
|
114
|
+
* `onRoute` event. Any prior pivot list is discarded; cursor
|
|
115
|
+
* resets to 0.
|
|
116
|
+
*/
|
|
117
|
+
setRoute(route: NavRoute, _userPosition: LatLng | null): void;
|
|
118
|
+
/**
|
|
119
|
+
* For every pivot in the current list that has a missing road
|
|
120
|
+
* label, fill it in. Two-stage strategy:
|
|
121
|
+
*
|
|
122
|
+
* 1. **Inherit from neighbors.** Adjacent pivots on the route
|
|
123
|
+
* share roads by definition: between pivot N and pivot N+1
|
|
124
|
+
* there are no turns, so pivot N's toRoad == pivot N+1's
|
|
125
|
+
* fromRoad. If one side is known, copy it. This is free
|
|
126
|
+
* (no network) and avoids the geocode-mismatch class of bug
|
|
127
|
+
* where two different sample points return two different
|
|
128
|
+
* strings for what is conceptually the same road.
|
|
129
|
+
*
|
|
130
|
+
* 2. **Reverse-geocode the remainder.** For any field still
|
|
131
|
+
* null after inheritance, sample a coordinate ~18m behind
|
|
132
|
+
* (fromRoad) or ahead (toRoad) along the polyline and ask
|
|
133
|
+
* the host to reverse-geocode it. Best-effort — failures
|
|
134
|
+
* leave the field null.
|
|
135
|
+
*
|
|
136
|
+
* The `generation` guard rejects geocode replies arriving after
|
|
137
|
+
* a fresh route rebuild superseded them.
|
|
138
|
+
*/
|
|
139
|
+
private _resolveMissingRoadNames;
|
|
140
|
+
/**
|
|
141
|
+
* Drive the cursor with a new GPS fix. Fires `approaching` /
|
|
142
|
+
* `entered` / `exited` as thresholds are crossed.
|
|
143
|
+
*
|
|
144
|
+
* Two distance metrics are used:
|
|
145
|
+
*
|
|
146
|
+
* 1. **Along-path distance** — the user's projected position on the
|
|
147
|
+
* route polyline gives `userAlong`; each pivot's
|
|
148
|
+
* `distanceAlongRouteMeters` is its `pivotAlong`. The signed
|
|
149
|
+
* delta `pivotAlong - userAlong` says how far the user still has
|
|
150
|
+
* to walk to reach the pivot's perpendicular line (positive =
|
|
151
|
+
* ahead, negative = past). This is the primary metric for
|
|
152
|
+
* pedestrians, because it doesn't care which sidewalk they're on
|
|
153
|
+
* — only that they've crossed the pivot's latitude/longitude
|
|
154
|
+
* band.
|
|
155
|
+
*
|
|
156
|
+
* 2. **Straight-line distance** — fallback when the user is more
|
|
157
|
+
* than ON_ROUTE_PERP_TOLERANCE_M from the polyline (they've
|
|
158
|
+
* really wandered off, not just onto the wrong sidewalk). Keeps
|
|
159
|
+
* the legacy behavior for that case.
|
|
160
|
+
*/
|
|
161
|
+
onLocationUpdate(coords: LatLng): void;
|
|
162
|
+
subscribe(fn: Subscriber): () => void;
|
|
163
|
+
getPivots(): Pivot[];
|
|
164
|
+
getActivePivot(): Pivot | null;
|
|
165
|
+
getUpcomingPivot(): Pivot | null;
|
|
166
|
+
private emit;
|
|
167
|
+
}
|
|
168
|
+
export { bearingDeg, haversineMeters, signedAngleDiff };
|
|
169
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/modules/pivots/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAW,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAC,MAAM,eAAe,CAAA;AACvH,OAAO,EACL,UAAU,EAGV,eAAe,EACf,eAAe,EAEhB,MAAM,YAAY,CAAA;AAkDnB,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;AAY7C,qBAAa,WAAW;IACtB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAmB;IACjC,+DAA+D;IAC/D,OAAO,CAAC,MAAM,CAAI;IAClB,+DAA+D;IAC/D,OAAO,CAAC,gBAAgB,CAAsB;IAC9C;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAe;IACjC;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB,CAA2D;IACnF;;;;;;OAMG;IACH,OAAO,CAAC,eAAe,CAAI;IAE3B,OAAO,CAAC,WAAW,CAAwB;gBAE/B,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS;IAI5D;iDAC6C;IAC7C,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI;IAQrE;;;;;;OAMG;IACH,mBAAmB,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,G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