@ingissa/navcore-react-native 1.0.8 → 1.0.10

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.
Files changed (125) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +135 -0
  3. package/dist/index.d.mts +131 -0
  4. package/dist/index.d.ts +131 -0
  5. package/dist/index.js +233 -0
  6. package/dist/index.mjs +223 -0
  7. package/package.json +46 -54
  8. package/dist/core/src/NavCore.d.ts +0 -142
  9. package/dist/core/src/NavCore.d.ts.map +0 -1
  10. package/dist/core/src/NavCore.js +0 -390
  11. package/dist/core/src/bearing/BearingEngine.d.ts +0 -24
  12. package/dist/core/src/bearing/BearingEngine.d.ts.map +0 -1
  13. package/dist/core/src/bearing/BearingEngine.js +0 -50
  14. package/dist/core/src/constants.d.ts +0 -34
  15. package/dist/core/src/constants.d.ts.map +0 -1
  16. package/dist/core/src/constants.js +0 -41
  17. package/dist/core/src/corridor/DeviationDetector.d.ts +0 -33
  18. package/dist/core/src/corridor/DeviationDetector.d.ts.map +0 -1
  19. package/dist/core/src/corridor/DeviationDetector.js +0 -83
  20. package/dist/core/src/corridor/DynamicCorridor.d.ts +0 -13
  21. package/dist/core/src/corridor/DynamicCorridor.d.ts.map +0 -1
  22. package/dist/core/src/corridor/DynamicCorridor.js +0 -26
  23. package/dist/core/src/dead-reckoning/DeadReckoning.d.ts +0 -35
  24. package/dist/core/src/dead-reckoning/DeadReckoning.d.ts.map +0 -1
  25. package/dist/core/src/dead-reckoning/DeadReckoning.js +0 -49
  26. package/dist/core/src/directions/DirectionsProvider.d.ts +0 -70
  27. package/dist/core/src/directions/DirectionsProvider.d.ts.map +0 -1
  28. package/dist/core/src/directions/DirectionsProvider.js +0 -7
  29. package/dist/core/src/directions/OSRMDirectionsProvider.d.ts +0 -26
  30. package/dist/core/src/directions/OSRMDirectionsProvider.d.ts.map +0 -1
  31. package/dist/core/src/directions/OSRMDirectionsProvider.js +0 -90
  32. package/dist/core/src/directions/OpenRouteServiceProvider.d.ts +0 -30
  33. package/dist/core/src/directions/OpenRouteServiceProvider.d.ts.map +0 -1
  34. package/dist/core/src/directions/OpenRouteServiceProvider.js +0 -111
  35. package/dist/core/src/directions/ValhallaDirectionsProvider.d.ts +0 -33
  36. package/dist/core/src/directions/ValhallaDirectionsProvider.d.ts.map +0 -1
  37. package/dist/core/src/directions/ValhallaDirectionsProvider.js +0 -155
  38. package/dist/core/src/eta/ETAEngine.d.ts +0 -61
  39. package/dist/core/src/eta/ETAEngine.d.ts.map +0 -1
  40. package/dist/core/src/eta/ETAEngine.js +0 -74
  41. package/dist/core/src/features.d.ts +0 -76
  42. package/dist/core/src/features.d.ts.map +0 -1
  43. package/dist/core/src/features.js +0 -76
  44. package/dist/core/src/geo/bearing.d.ts +0 -11
  45. package/dist/core/src/geo/bearing.d.ts.map +0 -1
  46. package/dist/core/src/geo/bearing.js +0 -25
  47. package/dist/core/src/geo/cumulative.d.ts +0 -9
  48. package/dist/core/src/geo/cumulative.d.ts.map +0 -1
  49. package/dist/core/src/geo/cumulative.js +0 -20
  50. package/dist/core/src/geo/haversine.d.ts +0 -13
  51. package/dist/core/src/geo/haversine.d.ts.map +0 -1
  52. package/dist/core/src/geo/haversine.js +0 -39
  53. package/dist/core/src/geo/projection.d.ts +0 -7
  54. package/dist/core/src/geo/projection.d.ts.map +0 -1
  55. package/dist/core/src/geo/projection.js +0 -17
  56. package/dist/core/src/geofencing/GeofencingEngine.d.ts +0 -93
  57. package/dist/core/src/geofencing/GeofencingEngine.d.ts.map +0 -1
  58. package/dist/core/src/geofencing/GeofencingEngine.js +0 -154
  59. package/dist/core/src/index.d.ts +0 -66
  60. package/dist/core/src/index.d.ts.map +0 -1
  61. package/dist/core/src/index.js +0 -62
  62. package/dist/core/src/kalman/KalmanFilter2D.d.ts +0 -46
  63. package/dist/core/src/kalman/KalmanFilter2D.d.ts.map +0 -1
  64. package/dist/core/src/kalman/KalmanFilter2D.js +0 -77
  65. package/dist/core/src/license/LicenseManager.d.ts +0 -40
  66. package/dist/core/src/license/LicenseManager.d.ts.map +0 -1
  67. package/dist/core/src/license/LicenseManager.js +0 -119
  68. package/dist/core/src/license/verifyP256Signature.d.ts +0 -2
  69. package/dist/core/src/license/verifyP256Signature.d.ts.map +0 -1
  70. package/dist/core/src/license/verifyP256Signature.js +0 -26
  71. package/dist/core/src/off-route/NavigationFSM.d.ts +0 -42
  72. package/dist/core/src/off-route/NavigationFSM.d.ts.map +0 -1
  73. package/dist/core/src/off-route/NavigationFSM.js +0 -56
  74. package/dist/core/src/off-route/OffRouteFSM.d.ts +0 -70
  75. package/dist/core/src/off-route/OffRouteFSM.d.ts.map +0 -1
  76. package/dist/core/src/off-route/OffRouteFSM.js +0 -151
  77. package/dist/core/src/predictor/RouteOffsetPredictor.d.ts +0 -24
  78. package/dist/core/src/predictor/RouteOffsetPredictor.d.ts.map +0 -1
  79. package/dist/core/src/predictor/RouteOffsetPredictor.js +0 -55
  80. package/dist/core/src/progress/InstructionEditor.d.ts +0 -77
  81. package/dist/core/src/progress/InstructionEditor.d.ts.map +0 -1
  82. package/dist/core/src/progress/InstructionEditor.js +0 -151
  83. package/dist/core/src/progress/InstructionResolver.d.ts +0 -25
  84. package/dist/core/src/progress/InstructionResolver.d.ts.map +0 -1
  85. package/dist/core/src/progress/InstructionResolver.js +0 -78
  86. package/dist/core/src/progress/ProgressTracker.d.ts +0 -12
  87. package/dist/core/src/progress/ProgressTracker.d.ts.map +0 -1
  88. package/dist/core/src/progress/ProgressTracker.js +0 -22
  89. package/dist/core/src/renderer/MapRendererAdapter.d.ts +0 -72
  90. package/dist/core/src/renderer/MapRendererAdapter.d.ts.map +0 -1
  91. package/dist/core/src/renderer/MapRendererAdapter.js +0 -19
  92. package/dist/core/src/route-builder/CustomRouteBuilder.d.ts +0 -83
  93. package/dist/core/src/route-builder/CustomRouteBuilder.d.ts.map +0 -1
  94. package/dist/core/src/route-builder/CustomRouteBuilder.js +0 -160
  95. package/dist/core/src/route-plan/RoutePlan.d.ts +0 -38
  96. package/dist/core/src/route-plan/RoutePlan.d.ts.map +0 -1
  97. package/dist/core/src/route-plan/RoutePlan.js +0 -102
  98. package/dist/core/src/session/NavigationSession.d.ts +0 -81
  99. package/dist/core/src/session/NavigationSession.d.ts.map +0 -1
  100. package/dist/core/src/session/NavigationSession.js +0 -115
  101. package/dist/core/src/snapper/ParallelRoadResolver.d.ts +0 -86
  102. package/dist/core/src/snapper/ParallelRoadResolver.d.ts.map +0 -1
  103. package/dist/core/src/snapper/ParallelRoadResolver.js +0 -83
  104. package/dist/core/src/snapper/RouteSnapper.d.ts +0 -38
  105. package/dist/core/src/snapper/RouteSnapper.d.ts.map +0 -1
  106. package/dist/core/src/snapper/RouteSnapper.js +0 -80
  107. package/dist/core/src/voice/VoiceTriggerEngine.d.ts +0 -80
  108. package/dist/core/src/voice/VoiceTriggerEngine.d.ts.map +0 -1
  109. package/dist/core/src/voice/VoiceTriggerEngine.js +0 -108
  110. package/dist/react-native/src/NavCoreProvider.d.ts +0 -33
  111. package/dist/react-native/src/NavCoreProvider.d.ts.map +0 -1
  112. package/dist/react-native/src/NavCoreProvider.js +0 -41
  113. package/dist/react-native/src/index.d.ts +0 -10
  114. package/dist/react-native/src/index.d.ts.map +0 -1
  115. package/dist/react-native/src/index.js +0 -8
  116. package/dist/react-native/src/useNavCore.d.ts +0 -60
  117. package/dist/react-native/src/useNavCore.d.ts.map +0 -1
  118. package/dist/react-native/src/useNavCore.js +0 -119
  119. package/dist/react-native/src/useNavSelectors.d.ts +0 -42
  120. package/dist/react-native/src/useNavSelectors.d.ts.map +0 -1
  121. package/dist/react-native/src/useNavSelectors.js +0 -103
  122. package/src/NavCoreProvider.tsx +0 -59
  123. package/src/index.ts +0 -18
  124. package/src/useNavCore.ts +0 -208
  125. package/src/useNavSelectors.ts +0 -143
@@ -1,83 +0,0 @@
1
- /**
2
- * Module 4b: DeviationDetector
3
- * Compound deviation detection using distance, bearing, and movement signals.
4
- */
5
- import { haversineDistance } from '../geo/haversine';
6
- import { getBearingBetweenPoints, normalizeAngle } from '../geo/bearing';
7
- import { BEARING_MISMATCH_THRESHOLD } from '../constants';
8
- /**
9
- * Find the closest segment to a GPS point within a search window.
10
- */
11
- export function findClosestSegment(gps, route, startIdx, windowSize, routeFlowBearing = null) {
12
- let bestIdx = Math.max(0, startIdx);
13
- let bestDist = Infinity;
14
- let bestProj = route[bestIdx] ?? [0, 0];
15
- const end = Math.min(startIdx + windowSize, route.length - 1);
16
- for (let i = Math.max(0, startIdx); i < end; i++) {
17
- const a = route[i];
18
- const b = route[i + 1];
19
- // Simple flat projection for speed (deviation detection doesn't need
20
- // sub-metre accuracy — haversine is used for the final distance check)
21
- const [px, py] = gps;
22
- const [ax, ay] = a;
23
- const [bx, by] = b;
24
- const dx = bx - ax;
25
- const dy = by - ay;
26
- const lenSq = dx * dx + dy * dy;
27
- let proj;
28
- if (lenSq === 0) {
29
- proj = a;
30
- }
31
- else {
32
- let t = ((px - ax) * dx + (py - ay) * dy) / lenSq;
33
- t = Math.max(0, Math.min(1, t));
34
- proj = [ax + t * dx, ay + t * dy];
35
- }
36
- const d = haversineDistance(gps[1], gps[0], proj[1], proj[0]);
37
- // Anti-parallel penalty: if route flow bearing is known, penalize
38
- // segments going the opposite direction
39
- if (routeFlowBearing !== null && d < bestDist * 1.5) {
40
- const segBearing = getBearingBetweenPoints(a, b);
41
- const diff = Math.abs(normalizeAngle(routeFlowBearing - segBearing));
42
- if (diff > 120)
43
- continue; // Very anti-parallel, skip
44
- }
45
- if (d < bestDist) {
46
- bestDist = d;
47
- bestIdx = i;
48
- bestProj = proj;
49
- }
50
- }
51
- return { segmentIndex: bestIdx, distance: bestDist, projection: bestProj };
52
- }
53
- export class DeviationDetector {
54
- /**
55
- * Evaluate deviation signals for the current GPS position.
56
- */
57
- evaluate(gps, gpsBearing, speedMps, closest, route, corridor, prevDistToNextSegment) {
58
- const outsideCorridor = closest.distance > corridor;
59
- // Bearing mismatch
60
- let bearingMismatch = false;
61
- if (gpsBearing !== null && closest.segmentIndex < route.length - 1) {
62
- const segBearing = getBearingBetweenPoints(route[closest.segmentIndex], route[closest.segmentIndex + 1]);
63
- const diff = Math.abs(normalizeAngle(gpsBearing - segBearing));
64
- bearingMismatch = diff > BEARING_MISMATCH_THRESHOLD;
65
- }
66
- // Moving away detection
67
- let movingAway = false;
68
- if (prevDistToNextSegment !== null && speedMps > 1.5) {
69
- const nextEnd = route[Math.min(closest.segmentIndex + 2, route.length - 1)];
70
- const currentDistToNext = haversineDistance(gps[1], gps[0], nextEnd[1], nextEnd[0]);
71
- movingAway = currentDistToNext > prevDistToNextSegment + 5;
72
- }
73
- // Compound confirmation: outside corridor AND (bearing mismatch OR moving away)
74
- const confirmed = outsideCorridor && (bearingMismatch || movingAway);
75
- return {
76
- distanceToRoute: closest.distance,
77
- outsideCorridor,
78
- bearingMismatch,
79
- movingAway,
80
- confirmed,
81
- };
82
- }
83
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Module 4a: DynamicCorridor
3
- * Speed-adaptive corridor width calculation.
4
- */
5
- /**
6
- * Compute speed-adaptive corridor width in metres.
7
- *
8
- * Corridor widens with speed: BASE + speed * FACTOR, capped at MAX.
9
- * GPS accuracy optionally widens the corridor further.
10
- * Turn lookahead widens corridor when approaching upcoming maneuvers to prevent false off-route alerts.
11
- */
12
- export declare function calculateDynamicCorridor(speedMps: number, gpsAccuracy?: number | null, baseMeters?: number, maxMeters?: number, speedFactor?: number, accuracyFactor?: number, distanceToTurn?: number | null, turnMultiplier?: number, turnLookaheadDist?: number): number;
13
- //# sourceMappingURL=DynamicCorridor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DynamicCorridor.d.ts","sourceRoot":"","sources":["../../../../../core/src/corridor/DynamicCorridor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,WAAW,GAAE,MAAM,GAAG,IAAW,EACjC,UAAU,GAAE,MAA6B,EACzC,SAAS,GAAE,MAA4B,EACvC,WAAW,GAAE,MAA8B,EAC3C,cAAc,GAAE,MAA4B,EAC5C,cAAc,GAAE,MAAM,GAAG,IAAW,EACpC,cAAc,GAAE,MAAiC,EACjD,iBAAiB,GAAE,MAAuC,GACzD,MAAM,CAgBR"}
@@ -1,26 +0,0 @@
1
- /**
2
- * Module 4a: DynamicCorridor
3
- * Speed-adaptive corridor width calculation.
4
- */
5
- import { BASE_CORRIDOR_METERS, MAX_CORRIDOR_METERS, SPEED_CORRIDOR_FACTOR, GPS_ACCURACY_FACTOR, TURN_LOOKAHEAD_DISTANCE_METERS, TURN_CORRIDOR_MULTIPLIER, } from '../constants';
6
- /**
7
- * Compute speed-adaptive corridor width in metres.
8
- *
9
- * Corridor widens with speed: BASE + speed * FACTOR, capped at MAX.
10
- * GPS accuracy optionally widens the corridor further.
11
- * Turn lookahead widens corridor when approaching upcoming maneuvers to prevent false off-route alerts.
12
- */
13
- export function calculateDynamicCorridor(speedMps, gpsAccuracy = null, baseMeters = BASE_CORRIDOR_METERS, maxMeters = MAX_CORRIDOR_METERS, speedFactor = SPEED_CORRIDOR_FACTOR, accuracyFactor = GPS_ACCURACY_FACTOR, distanceToTurn = null, turnMultiplier = TURN_CORRIDOR_MULTIPLIER, turnLookaheadDist = TURN_LOOKAHEAD_DISTANCE_METERS) {
14
- let corridor = baseMeters + speedMps * speedFactor;
15
- if (gpsAccuracy !== null && gpsAccuracy > 0) {
16
- corridor += gpsAccuracy * accuracyFactor;
17
- }
18
- let effectiveMax = maxMeters;
19
- if (distanceToTurn !== null && distanceToTurn >= 0 && distanceToTurn <= turnLookaheadDist) {
20
- const proximity = 1 - Math.max(0, distanceToTurn / turnLookaheadDist);
21
- const scale = 1 + (turnMultiplier - 1) * proximity;
22
- corridor *= scale;
23
- effectiveMax = maxMeters * turnMultiplier;
24
- }
25
- return Math.min(corridor, effectiveMax);
26
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * Module 3: DeadReckoning
3
- * Predicts vehicle position during GPS outages or stale fixes.
4
- */
5
- import { type Coordinate } from '../geo/haversine';
6
- export interface DRAnchor {
7
- coord: Coordinate;
8
- idx: number;
9
- ts: number;
10
- }
11
- export interface DRPrediction {
12
- predictedCoord: Coordinate;
13
- isActive: boolean;
14
- ageMs: number;
15
- }
16
- /**
17
- * Given a snapped anchor on the route, extrapolate forward using speed and bearing.
18
- */
19
- export declare function computeDeadReckoningOnRoute(anchor: DRAnchor | null, speed: number, bearing: number, now: number, maxAgeMs?: number): DRPrediction;
20
- /**
21
- * Stateful dead reckoning engine.
22
- */
23
- export declare class DeadReckoningEngine {
24
- private anchor;
25
- private readonly maxAgeMs;
26
- constructor(maxAgeMs?: number);
27
- /** Set the anchor point (called when GPS is available and snapping succeeds) */
28
- setAnchor(coord: Coordinate, idx: number, timestamp: number): void;
29
- /** Predict position given current speed and bearing */
30
- predict(speed: number, bearing: number, now: number): DRPrediction;
31
- /** Clear the anchor (GPS restored) */
32
- clearAnchor(): void;
33
- getAnchor(): DRAnchor | null;
34
- }
35
- //# sourceMappingURL=DeadReckoning.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeadReckoning.d.ts","sourceRoot":"","sources":["../../../../../core/src/dead-reckoning/DeadReckoning.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAGrE,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,UAAU,CAAC;IAC3B,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,QAAQ,GAAG,IAAI,EACvB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAsB,GAC/B,YAAY,CAmBd;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,QAAQ,GAAE,MAAsB;IAI5C,gFAAgF;IAChF,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAIlE,uDAAuD;IACvD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY;IAIlE,sCAAsC;IACtC,WAAW,IAAI,IAAI;IAInB,SAAS,IAAI,QAAQ,GAAG,IAAI;CAG7B"}
@@ -1,49 +0,0 @@
1
- /**
2
- * Module 3: DeadReckoning
3
- * Predicts vehicle position during GPS outages or stale fixes.
4
- */
5
- import { destinationPoint } from '../geo/haversine';
6
- import { DR_MAX_AGE_MS } from '../constants';
7
- /**
8
- * Given a snapped anchor on the route, extrapolate forward using speed and bearing.
9
- */
10
- export function computeDeadReckoningOnRoute(anchor, speed, bearing, now, maxAgeMs = DR_MAX_AGE_MS) {
11
- if (!anchor || speed < 0.5) {
12
- return { predictedCoord: anchor?.coord ?? [0, 0], isActive: false, ageMs: 0 };
13
- }
14
- const ageMs = now - anchor.ts;
15
- if (ageMs > maxAgeMs || ageMs < 0) {
16
- return { predictedCoord: anchor.coord, isActive: false, ageMs };
17
- }
18
- const distM = speed * (ageMs / 1000);
19
- const predicted = destinationPoint(anchor.coord[1], anchor.coord[0], bearing, distM);
20
- return {
21
- predictedCoord: predicted,
22
- isActive: true,
23
- ageMs,
24
- };
25
- }
26
- /**
27
- * Stateful dead reckoning engine.
28
- */
29
- export class DeadReckoningEngine {
30
- constructor(maxAgeMs = DR_MAX_AGE_MS) {
31
- this.anchor = null;
32
- this.maxAgeMs = maxAgeMs;
33
- }
34
- /** Set the anchor point (called when GPS is available and snapping succeeds) */
35
- setAnchor(coord, idx, timestamp) {
36
- this.anchor = { coord, idx, ts: timestamp };
37
- }
38
- /** Predict position given current speed and bearing */
39
- predict(speed, bearing, now) {
40
- return computeDeadReckoningOnRoute(this.anchor, speed, bearing, now, this.maxAgeMs);
41
- }
42
- /** Clear the anchor (GPS restored) */
43
- clearAnchor() {
44
- this.anchor = null;
45
- }
46
- getAnchor() {
47
- return this.anchor;
48
- }
49
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * DirectionsProvider — Generic interface for route computation.
3
- *
4
- * All direction adapters (Mapbox, OSRM, Valhalla, ORS…) implement this contract.
5
- * NavCore itself only depends on this interface — swap providers with zero engine changes.
6
- */
7
- import type { Coordinate } from '../geo/haversine';
8
- export interface DirectionsOptions {
9
- /** Travel mode */
10
- profile?: 'driving' | 'cycling' | 'walking';
11
- /** Include step-by-step maneuver data */
12
- steps?: boolean;
13
- /** Language for instruction text */
14
- language?: string;
15
- /** Return alternative routes */
16
- alternatives?: boolean;
17
- }
18
- export interface DirectionsManeuver {
19
- type: string;
20
- modifier?: string;
21
- location: Coordinate;
22
- bearingBefore: number;
23
- bearingAfter: number;
24
- instruction?: string;
25
- }
26
- export interface DirectionsStep {
27
- distance: number;
28
- duration: number;
29
- geometry: Coordinate[];
30
- maneuver: DirectionsManeuver;
31
- name?: string;
32
- }
33
- export interface DirectionsLeg {
34
- distance: number;
35
- duration: number;
36
- steps?: DirectionsStep[];
37
- }
38
- export interface DirectionsResult {
39
- /** Full route geometry as [lng, lat] coordinates */
40
- geometry: Coordinate[];
41
- /** Total distance in metres */
42
- distance: number;
43
- /** Total duration in seconds */
44
- duration: number;
45
- /** Per-leg breakdown */
46
- legs: DirectionsLeg[];
47
- /** Raw API response for provider-specific access */
48
- raw?: unknown;
49
- }
50
- /**
51
- * Any directions source implements this single method.
52
- *
53
- * @example
54
- * ```typescript
55
- * const provider: DirectionsProvider = new OSRMDirectionsProvider({ baseUrl: '...' });
56
- * const result = await provider.getRoute([[lng1, lat1], [lng2, lat2]]);
57
- * engine.setRoute(result.geometry);
58
- * ```
59
- */
60
- export interface DirectionsProvider {
61
- /**
62
- * Compute a route through the given waypoints.
63
- * Implementations MUST handle the case where `waypoints.length > provider limit`
64
- * by chunking internally.
65
- *
66
- * @throws {Error} if fewer than 2 waypoints are given, or the API fails.
67
- */
68
- getRoute(waypoints: Coordinate[], options?: DirectionsOptions): Promise<DirectionsResult>;
69
- }
70
- //# sourceMappingURL=DirectionsProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DirectionsProvider.d.ts","sourceRoot":"","sources":["../../../../../core/src/directions/DirectionsProvider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,MAAM,WAAW,iBAAiB;IAChC,kBAAkB;IAClB,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAC5C,yCAAyC;IACzC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAID,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,UAAU,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,wBAAwB;IACxB,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,oDAAoD;IACpD,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAID;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC3F"}
@@ -1,7 +0,0 @@
1
- /**
2
- * DirectionsProvider — Generic interface for route computation.
3
- *
4
- * All direction adapters (Mapbox, OSRM, Valhalla, ORS…) implement this contract.
5
- * NavCore itself only depends on this interface — swap providers with zero engine changes.
6
- */
7
- export {};
@@ -1,26 +0,0 @@
1
- /**
2
- * OSRMDirectionsProvider
3
- *
4
- * Self-hosted OSRM (Open Source Routing Machine) adapter.
5
- * Zero API key required. Ideal for self-hosted deployments.
6
- *
7
- * @see https://project-osrm.org/docs/v5.24.0/api/
8
- */
9
- import type { Coordinate } from '../geo/haversine';
10
- import type { DirectionsProvider, DirectionsOptions, DirectionsResult } from './DirectionsProvider';
11
- export interface OSRMConfig {
12
- /** Base URL of your OSRM server, e.g. 'http://router.project-osrm.org' */
13
- baseUrl: string;
14
- /** Routing profile (default: 'driving') */
15
- profile?: 'driving' | 'cycling' | 'walking';
16
- /** Max waypoints per API request (OSRM supports unlimited, but chunking keeps requests fast) */
17
- maxWaypointsPerChunk?: number;
18
- }
19
- export declare class OSRMDirectionsProvider implements DirectionsProvider {
20
- private readonly config;
21
- constructor(config: OSRMConfig);
22
- getRoute(waypoints: Coordinate[], options?: DirectionsOptions): Promise<DirectionsResult>;
23
- private fetchRoute;
24
- private fetchChunked;
25
- }
26
- //# sourceMappingURL=OSRMDirectionsProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OSRMDirectionsProvider.d.ts","sourceRoot":"","sources":["../../../../../core/src/directions/OSRMDirectionsProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEpG,MAAM,WAAW,UAAU;IACzB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAC5C,gGAAgG;IAChG,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAID,qBAAa,sBAAuB,YAAW,kBAAkB;IAC/D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAElC,MAAM,EAAE,UAAU;IAQxB,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAYjF,UAAU;YA8CV,YAAY;CA+B3B"}
@@ -1,90 +0,0 @@
1
- /**
2
- * OSRMDirectionsProvider
3
- *
4
- * Self-hosted OSRM (Open Source Routing Machine) adapter.
5
- * Zero API key required. Ideal for self-hosted deployments.
6
- *
7
- * @see https://project-osrm.org/docs/v5.24.0/api/
8
- */
9
- const DEFAULT_MAX_CHUNK = 100;
10
- export class OSRMDirectionsProvider {
11
- constructor(config) {
12
- this.config = {
13
- baseUrl: config.baseUrl.replace(/\/$/, ''),
14
- profile: config.profile ?? 'driving',
15
- maxWaypointsPerChunk: config.maxWaypointsPerChunk ?? DEFAULT_MAX_CHUNK,
16
- };
17
- }
18
- async getRoute(waypoints, options) {
19
- if (waypoints.length < 2)
20
- throw new Error('[OSRM] At least 2 waypoints required');
21
- const profile = options?.profile ?? this.config.profile;
22
- if (waypoints.length <= this.config.maxWaypointsPerChunk) {
23
- return this.fetchRoute(waypoints, profile, options);
24
- }
25
- return this.fetchChunked(waypoints, profile, options);
26
- }
27
- async fetchRoute(waypoints, profile, options) {
28
- const coords = waypoints.map(w => `${w[0]},${w[1]}`).join(';');
29
- const steps = options?.steps !== false ? 'true' : 'false';
30
- const url = `${this.config.baseUrl}/route/v1/${profile}/${coords}` +
31
- `?overview=full&geometries=geojson&steps=${steps}&annotations=false`;
32
- const res = await fetch(url);
33
- if (!res.ok)
34
- throw new Error(`[OSRM] HTTP ${res.status}: ${res.statusText}`);
35
- const data = await res.json();
36
- if (data.code !== 'Ok' || !data.routes?.length) {
37
- throw new Error(`[OSRM] No route found: ${data.code}`);
38
- }
39
- const route = data.routes[0];
40
- return {
41
- geometry: route.geometry.coordinates,
42
- distance: route.distance,
43
- duration: route.duration,
44
- legs: (route.legs ?? []).map((leg) => ({
45
- distance: leg.distance,
46
- duration: leg.duration,
47
- steps: (leg.steps ?? []).map((step) => ({
48
- distance: step.distance,
49
- duration: step.duration,
50
- geometry: step.geometry?.coordinates ?? [],
51
- maneuver: {
52
- type: step.maneuver?.type ?? 'unknown',
53
- modifier: step.maneuver?.modifier,
54
- location: step.maneuver?.location ?? [0, 0],
55
- bearingBefore: step.maneuver?.bearing_before ?? 0,
56
- bearingAfter: step.maneuver?.bearing_after ?? 0,
57
- instruction: step.name ?? undefined,
58
- },
59
- name: step.name,
60
- })),
61
- })),
62
- raw: data,
63
- };
64
- }
65
- async fetchChunked(waypoints, profile, options) {
66
- const size = this.config.maxWaypointsPerChunk;
67
- const chunks = [];
68
- for (let i = 0; i < waypoints.length; i += size - 1) {
69
- const chunk = waypoints.slice(i, i + size);
70
- if (chunk.length < 2)
71
- break;
72
- chunks.push(chunk);
73
- if (i + size >= waypoints.length)
74
- break;
75
- }
76
- const results = await Promise.all(chunks.map(c => this.fetchRoute(c, profile, options)));
77
- const geometry = [];
78
- let distance = 0;
79
- let duration = 0;
80
- const legs = [];
81
- for (let i = 0; i < results.length; i++) {
82
- const r = results[i];
83
- geometry.push(...(i === 0 ? r.geometry : r.geometry.slice(1)));
84
- distance += r.distance;
85
- duration += r.duration;
86
- legs.push(...r.legs);
87
- }
88
- return { geometry, distance, duration, legs, raw: results.map(r => r.raw) };
89
- }
90
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * OpenRouteServiceProvider
3
- *
4
- * OpenRouteService (ORS) API adapter. Free tier: 2000 req/day.
5
- * Requires an API key from https://openrouteservice.org/
6
- *
7
- * @see https://openrouteservice.org/dev/#/api-docs/v2/directions
8
- */
9
- import type { Coordinate } from '../geo/haversine';
10
- import type { DirectionsProvider, DirectionsOptions, DirectionsResult } from './DirectionsProvider';
11
- export type ORSProfile = 'driving-car' | 'driving-hgv' | 'cycling-regular' | 'cycling-road' | 'cycling-mountain' | 'foot-walking' | 'foot-hiking' | 'wheelchair';
12
- export interface ORSConfig {
13
- /** ORS API key */
14
- apiKey: string;
15
- /** Routing profile (default: 'driving-car') */
16
- profile?: ORSProfile;
17
- /** API base URL (default: ORS public API) */
18
- baseUrl?: string;
19
- /** Max waypoints per request (ORS limit: 50) */
20
- maxWaypointsPerChunk?: number;
21
- }
22
- export declare class OpenRouteServiceProvider implements DirectionsProvider {
23
- private readonly config;
24
- constructor(config: ORSConfig);
25
- getRoute(waypoints: Coordinate[], options?: DirectionsOptions): Promise<DirectionsResult>;
26
- private profileFromOptions;
27
- private fetchRoute;
28
- private fetchChunked;
29
- }
30
- //# sourceMappingURL=OpenRouteServiceProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OpenRouteServiceProvider.d.ts","sourceRoot":"","sources":["../../../../../core/src/directions/OpenRouteServiceProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEpG,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,aAAa,GACb,iBAAiB,GACjB,cAAc,GACd,kBAAkB,GAClB,cAAc,GACd,aAAa,GACb,YAAY,CAAC;AAEjB,MAAM,WAAW,SAAS;IACxB,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAKD,qBAAa,wBAAyB,YAAW,kBAAkB;IACjE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;gBAEjC,MAAM,EAAE,SAAS;IASvB,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAY/F,OAAO,CAAC,kBAAkB;YAQZ,UAAU;YA4DV,YAAY;CA+B3B"}
@@ -1,111 +0,0 @@
1
- /**
2
- * OpenRouteServiceProvider
3
- *
4
- * OpenRouteService (ORS) API adapter. Free tier: 2000 req/day.
5
- * Requires an API key from https://openrouteservice.org/
6
- *
7
- * @see https://openrouteservice.org/dev/#/api-docs/v2/directions
8
- */
9
- const DEFAULT_BASE_URL = 'https://api.openrouteservice.org/v2/directions';
10
- const DEFAULT_MAX_CHUNK = 50;
11
- export class OpenRouteServiceProvider {
12
- constructor(config) {
13
- this.config = {
14
- apiKey: config.apiKey,
15
- profile: config.profile ?? 'driving-car',
16
- baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
17
- maxWaypointsPerChunk: config.maxWaypointsPerChunk ?? DEFAULT_MAX_CHUNK,
18
- };
19
- }
20
- async getRoute(waypoints, options) {
21
- if (waypoints.length < 2)
22
- throw new Error('[ORS] At least 2 waypoints required');
23
- const profile = this.profileFromOptions(options);
24
- if (waypoints.length <= this.config.maxWaypointsPerChunk) {
25
- return this.fetchRoute(waypoints, profile, options);
26
- }
27
- return this.fetchChunked(waypoints, profile, options);
28
- }
29
- profileFromOptions(options) {
30
- switch (options?.profile) {
31
- case 'cycling': return 'cycling-regular';
32
- case 'walking': return 'foot-walking';
33
- default: return this.config.profile;
34
- }
35
- }
36
- async fetchRoute(waypoints, profile, options) {
37
- const body = JSON.stringify({
38
- coordinates: waypoints, // ORS uses [lng, lat] natively
39
- instructions: options?.steps !== false,
40
- language: options?.language ?? 'en',
41
- });
42
- const res = await fetch(`${this.config.baseUrl}/${profile}/geojson`, {
43
- method: 'POST',
44
- headers: {
45
- 'Content-Type': 'application/json',
46
- 'Authorization': this.config.apiKey,
47
- },
48
- body,
49
- });
50
- if (!res.ok) {
51
- const errText = await res.text();
52
- throw new Error(`[ORS] HTTP ${res.status}: ${errText}`);
53
- }
54
- const data = await res.json();
55
- const feature = data.features?.[0];
56
- if (!feature)
57
- throw new Error('[ORS] No route returned');
58
- const summary = feature.properties?.summary ?? {};
59
- const segments = feature.properties?.segments ?? [];
60
- const legs = segments.map((seg) => ({
61
- distance: seg.distance ?? 0,
62
- duration: seg.duration ?? 0,
63
- steps: (seg.steps ?? []).map((step) => ({
64
- distance: step.distance ?? 0,
65
- duration: step.duration ?? 0,
66
- geometry: [],
67
- maneuver: {
68
- type: step.type?.toString() ?? 'unknown',
69
- modifier: undefined,
70
- location: waypoints[0],
71
- bearingBefore: 0,
72
- bearingAfter: 0,
73
- instruction: step.instruction,
74
- },
75
- name: step.name,
76
- })),
77
- }));
78
- return {
79
- geometry: (feature.geometry?.coordinates ?? []),
80
- distance: summary.distance ?? 0,
81
- duration: summary.duration ?? 0,
82
- legs,
83
- raw: data,
84
- };
85
- }
86
- async fetchChunked(waypoints, profile, options) {
87
- const size = this.config.maxWaypointsPerChunk;
88
- const chunks = [];
89
- for (let i = 0; i < waypoints.length; i += size - 1) {
90
- const chunk = waypoints.slice(i, i + size);
91
- if (chunk.length < 2)
92
- break;
93
- chunks.push(chunk);
94
- if (i + size >= waypoints.length)
95
- break;
96
- }
97
- const results = await Promise.all(chunks.map(c => this.fetchRoute(c, profile, options)));
98
- const geometry = [];
99
- let distance = 0;
100
- let duration = 0;
101
- const legs = [];
102
- for (let i = 0; i < results.length; i++) {
103
- const r = results[i];
104
- geometry.push(...(i === 0 ? r.geometry : r.geometry.slice(1)));
105
- distance += r.distance;
106
- duration += r.duration;
107
- legs.push(...r.legs);
108
- }
109
- return { geometry, distance, duration, legs, raw: results.map(r => r.raw) };
110
- }
111
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * ValhallaDirectionsProvider
3
- *
4
- * Self-hosted Valhalla routing engine adapter.
5
- * Supports the `/route` and `/optimized_route` endpoints.
6
- * Zero API key for self-hosted. Uses Mapbox-hosted Valhalla with a token.
7
- *
8
- * @see https://valhalla.github.io/valhalla/api/turn-by-turn/api-reference/
9
- */
10
- import type { Coordinate } from '../geo/haversine';
11
- import type { DirectionsProvider, DirectionsOptions, DirectionsResult } from './DirectionsProvider';
12
- export type ValhallaCostingModel = 'auto' | 'bicycle' | 'pedestrian' | 'bus' | 'motor_scooter';
13
- export interface ValhallaConfig {
14
- /** Base URL of your Valhalla server or hosted instance */
15
- baseUrl: string;
16
- /** Routing costing model (default: 'auto') */
17
- costing?: ValhallaCostingModel;
18
- /** Optional API key (required for hosted Valhalla services) */
19
- apiKey?: string;
20
- /** Max waypoints per chunk (default: 50) */
21
- maxWaypointsPerChunk?: number;
22
- }
23
- export declare class ValhallaDirectionsProvider implements DirectionsProvider {
24
- private readonly config;
25
- constructor(config: ValhallaConfig);
26
- getRoute(waypoints: Coordinate[], options?: DirectionsOptions): Promise<DirectionsResult>;
27
- private profileToCosting;
28
- private fetchRoute;
29
- /** Decode Valhalla's encoded polyline6 format */
30
- private decodePolyline;
31
- private fetchChunked;
32
- }
33
- //# sourceMappingURL=ValhallaDirectionsProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ValhallaDirectionsProvider.d.ts","sourceRoot":"","sources":["../../../../../core/src/directions/ValhallaDirectionsProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEpG,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,GAAG,eAAe,CAAC;AAE/F,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAID,qBAAa,0BAA2B,YAAW,kBAAkB;IACnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;gBAEtC,MAAM,EAAE,cAAc;IAS5B,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAY/F,OAAO,CAAC,gBAAgB;YAQV,UAAU;IA6ExB,iDAAiD;IACjD,OAAO,CAAC,cAAc;YAmCR,YAAY;CA+B3B"}