@expofp/wayfinding 0.0.0-experimental.2632d13

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 (110) hide show
  1. package/README.md +85 -0
  2. package/dist/core/createWayfindingEngine.d.ts +16 -0
  3. package/dist/core/createWayfindingEngine.js +87 -0
  4. package/dist/core/geometry/pointInPolygon.d.ts +17 -0
  5. package/dist/core/geometry/pointInPolygon.js +50 -0
  6. package/dist/core/geometry/projectPointOnSegment.d.ts +27 -0
  7. package/dist/core/geometry/projectPointOnSegment.js +21 -0
  8. package/dist/core/graph/buildGraph.d.ts +3 -0
  9. package/dist/core/graph/buildGraph.js +7 -0
  10. package/dist/core/graph/buildNGraph.d.ts +13 -0
  11. package/dist/core/graph/buildNGraph.js +24 -0
  12. package/dist/core/graph/constants.d.ts +20 -0
  13. package/dist/core/graph/constants.js +19 -0
  14. package/dist/core/graph/findShortestPath.d.ts +23 -0
  15. package/dist/core/graph/findShortestPath.js +65 -0
  16. package/dist/core/graph/graphCache.d.ts +7 -0
  17. package/dist/core/graph/graphCache.js +23 -0
  18. package/dist/core/graph/graphHelpers.d.ts +8 -0
  19. package/dist/core/graph/graphHelpers.js +63 -0
  20. package/dist/core/graph/linkCost.d.ts +13 -0
  21. package/dist/core/graph/linkCost.js +24 -0
  22. package/dist/core/graph/pathfinder/aStarPathFinder.d.ts +3 -0
  23. package/dist/core/graph/pathfinder/aStarPathFinder.js +64 -0
  24. package/dist/core/graph/pathfinder/parseNodeId.d.ts +10 -0
  25. package/dist/core/graph/pathfinder/parseNodeId.js +20 -0
  26. package/dist/core/index.d.ts +17 -0
  27. package/dist/core/index.js +12 -0
  28. package/dist/core/position/distanceToRoute.d.ts +3 -0
  29. package/dist/core/position/distanceToRoute.js +29 -0
  30. package/dist/core/position/gpsThreshold.d.ts +32 -0
  31. package/dist/core/position/gpsThreshold.js +48 -0
  32. package/dist/core/position/rerouteController.d.ts +13 -0
  33. package/dist/core/position/rerouteController.js +22 -0
  34. package/dist/core/position/snapToRoute.d.ts +9 -0
  35. package/dist/core/position/snapToRoute.js +50 -0
  36. package/dist/core/position/splitRouteByPoint.d.ts +6 -0
  37. package/dist/core/position/splitRouteByPoint.js +56 -0
  38. package/dist/core/rendering/computeTrailPoints.d.ts +12 -0
  39. package/dist/core/rendering/computeTrailPoints.js +35 -0
  40. package/dist/core/rendering/computeTransitionPoints.d.ts +35 -0
  41. package/dist/core/rendering/computeTransitionPoints.js +112 -0
  42. package/dist/core/rendering/getVisibleRouteLines.d.ts +10 -0
  43. package/dist/core/rendering/getVisibleRouteLines.js +18 -0
  44. package/dist/core/rendering/routeGeometry.d.ts +9 -0
  45. package/dist/core/rendering/routeGeometry.js +10 -0
  46. package/dist/core/routing/buildMultiPointRoute.d.ts +13 -0
  47. package/dist/core/routing/buildMultiPointRoute.js +36 -0
  48. package/dist/core/routing/buildRoute.d.ts +12 -0
  49. package/dist/core/routing/buildRoute.js +19 -0
  50. package/dist/core/routing/getRouteLength.d.ts +3 -0
  51. package/dist/core/routing/getRouteLength.js +4 -0
  52. package/dist/core/routing/graphPointResolvers.d.ts +9 -0
  53. package/dist/core/routing/graphPointResolvers.js +13 -0
  54. package/dist/core/routing/optimizeWaypointOrder.d.ts +14 -0
  55. package/dist/core/routing/optimizeWaypointOrder.js +88 -0
  56. package/dist/core/routing/resolveWaypointCandidates.d.ts +23 -0
  57. package/dist/core/routing/resolveWaypointCandidates.js +49 -0
  58. package/dist/core/routing/routeResult.d.ts +4 -0
  59. package/dist/core/routing/routeResult.js +2 -0
  60. package/dist/core/types.d.ts +102 -0
  61. package/dist/core/types.js +1 -0
  62. package/dist/createWayfinding.d.ts +81 -0
  63. package/dist/createWayfinding.js +46 -0
  64. package/dist/index.d.ts +18 -0
  65. package/dist/index.js +16 -0
  66. package/dist/renderer/createWayfindingRenderer.d.ts +8 -0
  67. package/dist/renderer/createWayfindingRenderer.js +45 -0
  68. package/dist/renderer/iconManager.d.ts +58 -0
  69. package/dist/renderer/iconManager.js +222 -0
  70. package/dist/renderer/index.d.ts +5 -0
  71. package/dist/renderer/index.js +2 -0
  72. package/dist/renderer/layerManager.d.ts +36 -0
  73. package/dist/renderer/layerManager.js +31 -0
  74. package/dist/renderer/layers.d.ts +54 -0
  75. package/dist/renderer/layers.js +66 -0
  76. package/dist/renderer/lineAnimation.d.ts +25 -0
  77. package/dist/renderer/lineAnimation.js +196 -0
  78. package/dist/renderer/routeLineManager.d.ts +45 -0
  79. package/dist/renderer/routeLineManager.js +153 -0
  80. package/dist/renderer/trailManager.d.ts +29 -0
  81. package/dist/renderer/trailManager.js +183 -0
  82. package/dist/renderer/types.d.ts +163 -0
  83. package/dist/renderer/types.js +1 -0
  84. package/dist/runtime/createWayfindingRuntime.d.ts +3 -0
  85. package/dist/runtime/createWayfindingRuntime.js +237 -0
  86. package/dist/runtime/endpointView.d.ts +19 -0
  87. package/dist/runtime/endpointView.js +44 -0
  88. package/dist/runtime/getRouteLines.d.ts +19 -0
  89. package/dist/runtime/getRouteLines.js +16 -0
  90. package/dist/runtime/index.d.ts +4 -0
  91. package/dist/runtime/index.js +2 -0
  92. package/dist/runtime/positionTrailView.d.ts +51 -0
  93. package/dist/runtime/positionTrailView.js +35 -0
  94. package/dist/runtime/positionView.d.ts +22 -0
  95. package/dist/runtime/positionView.js +34 -0
  96. package/dist/runtime/routeLinesView.d.ts +16 -0
  97. package/dist/runtime/routeLinesView.js +10 -0
  98. package/dist/runtime/routeRenderData.d.ts +31 -0
  99. package/dist/runtime/routeRenderData.js +44 -0
  100. package/dist/runtime/routeUpdate.d.ts +17 -0
  101. package/dist/runtime/routeUpdate.js +17 -0
  102. package/dist/runtime/snapPositionToRoute.d.ts +10 -0
  103. package/dist/runtime/snapPositionToRoute.js +36 -0
  104. package/dist/runtime/trailView.d.ts +19 -0
  105. package/dist/runtime/trailView.js +43 -0
  106. package/dist/runtime/transitionView.d.ts +16 -0
  107. package/dist/runtime/transitionView.js +51 -0
  108. package/dist/runtime/types.d.ts +81 -0
  109. package/dist/runtime/types.js +1 -0
  110. package/package.json +45 -0
@@ -0,0 +1,13 @@
1
+ import { type GraphInstance, type RoutePoint, type RouteResult } from '../types.js';
2
+ /**
3
+ * Builds a route through an ordered sequence of pre-resolved candidate groups.
4
+ * Each group is a `RoutePoint[]` — the candidate graph points for one waypoint.
5
+ *
6
+ * Intermediate groups with no candidates (empty arrays) are silently skipped —
7
+ * adjacent groups are connected directly. This matches the legacy behavior
8
+ * where unreachable waypoints were omitted.
9
+ * @param graph
10
+ * @param candidateGroups
11
+ */
12
+ export declare function buildMultiPointRoute(graph: GraphInstance, candidateGroups: RoutePoint[][]): RouteResult;
13
+ //# sourceMappingURL=buildMultiPointRoute.d.ts.map
@@ -0,0 +1,36 @@
1
+ import { buildRoute } from './buildRoute.js';
2
+ import { emptyResult } from './routeResult.js';
3
+ /**
4
+ * Builds a route through an ordered sequence of pre-resolved candidate groups.
5
+ * Each group is a `RoutePoint[]` — the candidate graph points for one waypoint.
6
+ *
7
+ * Intermediate groups with no candidates (empty arrays) are silently skipped —
8
+ * adjacent groups are connected directly. This matches the legacy behavior
9
+ * where unreachable waypoints were omitted.
10
+ * @param graph
11
+ * @param candidateGroups
12
+ */
13
+ export function buildMultiPointRoute(graph, candidateGroups) {
14
+ if (candidateGroups.length < 2)
15
+ return emptyResult();
16
+ // Skip intermediate waypoints with no graph candidates (legacy behavior:
17
+ // the old code omitted such waypoints from pointsArr, connecting adjacent ones)
18
+ const reachable = candidateGroups.filter((candidates, index) => {
19
+ if (index === 0 || index === candidateGroups.length - 1)
20
+ return true;
21
+ return candidates.length > 0;
22
+ });
23
+ if (reachable.length < 2)
24
+ return emptyResult();
25
+ if (reachable.length === 2)
26
+ return buildRoute(graph, reachable[0], reachable[1]);
27
+ const segmentResults = [];
28
+ for (let i = 0; i < reachable.length - 1; i++) {
29
+ segmentResults.push(buildRoute(graph, reachable[i], reachable[i + 1]));
30
+ }
31
+ // Legs concatenate directly: for [A, B, C], buildRoute(A, B) → [A→…→B] and
32
+ // buildRoute(B, C) → [B→…→C] share endpoint B, forming one continuous polyline.
33
+ const allLines = segmentResults.flatMap((result) => result.lines);
34
+ const totalDistance = segmentResults.reduce((sum, result) => sum + result.totalDistance, 0);
35
+ return { lines: allLines, totalDistance };
36
+ }
@@ -0,0 +1,12 @@
1
+ import { type GraphInstance, type RoutePoint, type RouteResult } from '../types.js';
2
+ /**
3
+ * Builds a route between two sets of candidate graph points.
4
+ *
5
+ * This is pure pathfinding — it does not resolve waypoints to graph points.
6
+ * Resolution is the caller's responsibility (see `getGraphLines`).
7
+ * @param graph
8
+ * @param fromCandidates
9
+ * @param toCandidates
10
+ */
11
+ export declare function buildRoute(graph: GraphInstance, fromCandidates: RoutePoint[], toCandidates: RoutePoint[]): RouteResult;
12
+ //# sourceMappingURL=buildRoute.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { findShortestPath } from '../graph/findShortestPath.js';
2
+ import { emptyResult } from './routeResult.js';
3
+ /**
4
+ * Builds a route between two sets of candidate graph points.
5
+ *
6
+ * This is pure pathfinding — it does not resolve waypoints to graph points.
7
+ * Resolution is the caller's responsibility (see `getGraphLines`).
8
+ * @param graph
9
+ * @param fromCandidates
10
+ * @param toCandidates
11
+ */
12
+ export function buildRoute(graph, fromCandidates, toCandidates) {
13
+ if (!fromCandidates.length || !toCandidates.length)
14
+ return emptyResult();
15
+ const result = findShortestPath(graph, fromCandidates, toCandidates);
16
+ if (!result)
17
+ return emptyResult();
18
+ return { lines: result.lines, totalDistance: result.distance };
19
+ }
@@ -0,0 +1,3 @@
1
+ import { type RouteLine } from '../types.js';
2
+ export declare function getRouteLength(routeLines: readonly RouteLine[]): number;
3
+ //# sourceMappingURL=getRouteLength.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { pointDistance } from '@expofp/geometry';
2
+ export function getRouteLength(routeLines) {
3
+ return routeLines.reduce((distance, line) => distance + pointDistance(line.p0, line.p1), 0);
4
+ }
@@ -0,0 +1,9 @@
1
+ import { type GraphDataSource, type PolygonVertex, type RoutePoint } from '../types.js';
2
+ /**
3
+ * Graph endpoints inside a convex polygon (e.g. booth rect), filtered by layer.
4
+ * @param dataSource
5
+ * @param polygon
6
+ * @param layer
7
+ */
8
+ export declare function findGraphPointsInPolygon(dataSource: GraphDataSource, polygon: readonly PolygonVertex[], layer?: string): RoutePoint[];
9
+ //# sourceMappingURL=graphPointResolvers.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { computePolygonArea, pointInPolygon } from '../geometry/pointInPolygon.js';
2
+ /**
3
+ * Graph endpoints inside a convex polygon (e.g. booth rect), filtered by layer.
4
+ * @param dataSource
5
+ * @param polygon
6
+ * @param layer
7
+ */
8
+ export function findGraphPointsInPolygon(dataSource, polygon, layer) {
9
+ const polygonArea = computePolygonArea(polygon);
10
+ return dataSource
11
+ .getLineEnds()
12
+ .filter((lineEnd) => (!layer || lineEnd.layer === layer) && pointInPolygon(lineEnd, polygon, polygonArea));
13
+ }
@@ -0,0 +1,14 @@
1
+ import type { Point2Like } from '@expofp/geometry';
2
+ /**
3
+ * Optimizes waypoint ordering to minimize total travel distance.
4
+ * Nearest neighbor O(n²) + 2-opt refinement O(k·n²), k ≤ 100.
5
+ * @param data
6
+ */
7
+ export declare function optimizeWaypointOrder(data: readonly [string, Point2Like][]): string[];
8
+ /**
9
+ * Reorders waypoints for fastest traversal.
10
+ * First and last stay fixed (from/to), only middle waypoints are reordered.
11
+ * @param waypoints
12
+ */
13
+ export declare function reorderWaypoints<T extends Point2Like>(waypoints: T[]): T[];
14
+ //# sourceMappingURL=optimizeWaypointOrder.d.ts.map
@@ -0,0 +1,88 @@
1
+ const MAX_ITERATIONS = 100;
2
+ const MIN_IMPROVEMENT = -0.01;
3
+ /**
4
+ * Optimizes waypoint ordering to minimize total travel distance.
5
+ * Nearest neighbor O(n²) + 2-opt refinement O(k·n²), k ≤ 100.
6
+ * @param data
7
+ */
8
+ export function optimizeWaypointOrder(data) {
9
+ const points = new Map(data);
10
+ const waypoints = Array.from(points.keys());
11
+ if (waypoints.length <= 2)
12
+ return waypoints;
13
+ const route = nearestNeighbor(waypoints, points);
14
+ return route.length < 4 ? route : twoOpt(route, points);
15
+ }
16
+ /**
17
+ * Reorders waypoints for fastest traversal.
18
+ * First and last stay fixed (from/to), only middle waypoints are reordered.
19
+ * @param waypoints
20
+ */
21
+ export function reorderWaypoints(waypoints) {
22
+ if (waypoints.length <= 3)
23
+ return waypoints;
24
+ const first = waypoints[0];
25
+ const last = waypoints[waypoints.length - 1];
26
+ const middle = waypoints.slice(1, -1);
27
+ const indexed = middle.map((wp, index) => [
28
+ String(index),
29
+ { x: wp.x, y: wp.y },
30
+ ]);
31
+ const optimizedOrder = optimizeWaypointOrder(indexed);
32
+ const reordered = optimizedOrder.map((index) => middle[Number(index)]);
33
+ return [first, ...reordered, last];
34
+ }
35
+ function nearestNeighbor(waypoints, points) {
36
+ const sorted = [waypoints[0]];
37
+ const remaining = new Set(waypoints);
38
+ let current = waypoints[0];
39
+ remaining.delete(waypoints[0]);
40
+ while (remaining.size > 0) {
41
+ const cur = points.get(current);
42
+ let nearest = '';
43
+ let minDist = Infinity;
44
+ for (const id of remaining) {
45
+ const pt = points.get(id);
46
+ const distance = Math.abs(cur.x - pt.x) + Math.abs(cur.y - pt.y);
47
+ if (distance < minDist) {
48
+ minDist = distance;
49
+ nearest = id;
50
+ }
51
+ }
52
+ if (!nearest)
53
+ break;
54
+ sorted.push(nearest);
55
+ remaining.delete(nearest);
56
+ current = nearest;
57
+ }
58
+ return sorted;
59
+ }
60
+ function twoOpt(route, points) {
61
+ const result = [...route];
62
+ let improved = true;
63
+ for (let iter = 0; improved && iter < MAX_ITERATIONS; iter++) {
64
+ improved = false;
65
+ scan: for (let index = 1; index < result.length - 2; index++) {
66
+ for (let swapEnd = index + 1; swapEnd < result.length - 1; swapEnd++) {
67
+ const before = points.get(result[index - 1]);
68
+ const start = points.get(result[index]);
69
+ const end = points.get(result[swapEnd]);
70
+ const after = points.get(result[swapEnd + 1]);
71
+ const delta = Math.abs(before.x - end.x) +
72
+ Math.abs(before.y - end.y) +
73
+ Math.abs(start.x - after.x) +
74
+ Math.abs(start.y - after.y) -
75
+ (Math.abs(before.x - start.x) + Math.abs(before.y - start.y)) -
76
+ (Math.abs(end.x - after.x) + Math.abs(end.y - after.y));
77
+ if (delta < MIN_IMPROVEMENT) {
78
+ for (let left = index, right = swapEnd; left < right; left++, right--) {
79
+ [result[left], result[right]] = [result[right], result[left]];
80
+ }
81
+ improved = true;
82
+ break scan;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ return result;
88
+ }
@@ -0,0 +1,23 @@
1
+ import type { GraphInstance, RouteEndpoint, RouteLine, RoutePoint } from '../types.js';
2
+ export interface OffGraphEntry {
3
+ readonly segment: RouteLine;
4
+ readonly projection: RoutePoint;
5
+ }
6
+ /**
7
+ * A* candidates plus an optional `offGraphEntry` — set when the route's entry needs perpendicular
8
+ * trim to land on a point inside a segment instead of at a graph node.
9
+ */
10
+ export interface ResolvedCandidates {
11
+ readonly candidates: RoutePoint[];
12
+ readonly offGraphEntry: OffGraphEntry | null;
13
+ }
14
+ /**
15
+ * Turns a route endpoint into A* candidates.
16
+ * - Booth (has `bounds`) → graph nodes inside the polygon.
17
+ * - Off-graph point → nearest segment on its layer; both ends are candidates and `offGraphEntry`
18
+ * holds the perpendicular foot to trim to. If the foot falls off the segment, attach at its node.
19
+ * @param graph
20
+ * @param endpoint
21
+ */
22
+ export declare function resolveWaypointCandidates(graph: GraphInstance, endpoint: RouteEndpoint): ResolvedCandidates;
23
+ //# sourceMappingURL=resolveWaypointCandidates.d.ts.map
@@ -0,0 +1,49 @@
1
+ import { projectPointOnSegment, } from '../geometry/projectPointOnSegment.js';
2
+ import { findGraphPointsInPolygon } from './graphPointResolvers.js';
3
+ /**
4
+ * Turns a route endpoint into A* candidates.
5
+ * - Booth (has `bounds`) → graph nodes inside the polygon.
6
+ * - Off-graph point → nearest segment on its layer; both ends are candidates and `offGraphEntry`
7
+ * holds the perpendicular foot to trim to. If the foot falls off the segment, attach at its node.
8
+ * @param graph
9
+ * @param endpoint
10
+ */
11
+ export function resolveWaypointCandidates(graph, endpoint) {
12
+ if (endpoint.bounds?.length) {
13
+ return {
14
+ candidates: findGraphPointsInPolygon(graph.dataSource, endpoint.bounds, endpoint.layer),
15
+ offGraphEntry: null,
16
+ };
17
+ }
18
+ let nearest = null;
19
+ let nearestDistance = Infinity;
20
+ for (const line of graph.dataSource.getLines()) {
21
+ if (line.virtual)
22
+ continue;
23
+ if (endpoint.layer && line.p0.layer !== endpoint.layer)
24
+ continue;
25
+ if (line.p0.x === line.p1.x && line.p0.y === line.p1.y)
26
+ continue;
27
+ const proj = projectPointOnSegment(endpoint, line.p0, line.p1);
28
+ if (proj.distance < nearestDistance) {
29
+ nearestDistance = proj.distance;
30
+ nearest = { segment: line, proj };
31
+ }
32
+ }
33
+ if (!nearest)
34
+ return { candidates: [], offGraphEntry: null };
35
+ const { segment, proj } = nearest;
36
+ // Foot outside the segment → closest point is a graph node; attach there directly, no trim.
37
+ if (proj.t === 0)
38
+ return { candidates: [segment.p0], offGraphEntry: null };
39
+ if (proj.t === 1)
40
+ return { candidates: [segment.p1], offGraphEntry: null };
41
+ // Foot inside the segment → both ends are A* candidates (shorter path wins); trim to the foot.
42
+ return {
43
+ candidates: [segment.p0, segment.p1],
44
+ offGraphEntry: {
45
+ segment,
46
+ projection: { layer: segment.p0.layer, x: proj.projected.x, y: proj.projected.y },
47
+ },
48
+ };
49
+ }
@@ -0,0 +1,4 @@
1
+ import { type RouteResult } from '../types.js';
2
+ /** Returns a fresh empty result each call to avoid shared-mutable-object bugs at runtime. */
3
+ export declare const emptyResult: () => RouteResult;
4
+ //# sourceMappingURL=routeResult.d.ts.map
@@ -0,0 +1,2 @@
1
+ /** Returns a fresh empty result each call to avoid shared-mutable-object bugs at runtime. */
2
+ export const emptyResult = () => ({ lines: [], totalDistance: 0 });
@@ -0,0 +1,102 @@
1
+ export interface PolygonVertex {
2
+ readonly x: number;
3
+ readonly y: number;
4
+ }
5
+ export interface RoutePoint {
6
+ readonly x: number;
7
+ readonly y: number;
8
+ readonly layer: string;
9
+ }
10
+ /**
11
+ * A computed route segment — the public output of routing, consumed by the
12
+ * runtime and rendering. Carries only what consumers read; graph-build
13
+ * properties (direction, cost) live on {@link GraphLine}, not here.
14
+ */
15
+ export interface RouteLine {
16
+ readonly p0: RoutePoint;
17
+ readonly p1: RoutePoint;
18
+ /** Virtual link rather than a physical path segment. May or may not change layers. */
19
+ readonly virtual: boolean;
20
+ }
21
+ /**
22
+ * A source graph line from external wayfinding data (wf.data.js) — the input to
23
+ * graph building. Extends {@link RouteLine} with build-only properties
24
+ * (accessibility, direction, cost) that never reach a computed route.
25
+ */
26
+ export interface GraphLine extends RouteLine {
27
+ /** Flagged inaccessible in source data: graph-build filter + the venue accessible toggle. */
28
+ readonly unaccessible: boolean;
29
+ /** One-way link: in oriented mode no reverse edge is added. */
30
+ readonly unidirection: boolean;
31
+ /** Link weight for cost (`0` = unset → `DEFAULT_LINE_WEIGHT`). */
32
+ readonly weight: number;
33
+ /**
34
+ * Per-line virtual cost from the designer ("Virtual length"). When set it
35
+ * replaces the default policy (`0` = free/preferred, large = avoided);
36
+ * otherwise a layer-changing link costs `FLOOR_TRANSITION_PENALTY`, a
37
+ * same-layer one is free.
38
+ */
39
+ readonly virtualLength?: number;
40
+ }
41
+ export interface PathNode {
42
+ readonly id: string;
43
+ readonly layer: string;
44
+ readonly x: number;
45
+ readonly y: number;
46
+ }
47
+ export interface PathFinderOptions {
48
+ readonly oriented: boolean;
49
+ readonly onlyAccessible: boolean;
50
+ }
51
+ export interface PathFinder {
52
+ build(lines: GraphLine[], options: PathFinderOptions): void;
53
+ find(fromId: string, toId: string): PathNode[];
54
+ hasNode(id: string): boolean;
55
+ }
56
+ export interface GraphDataSource {
57
+ getLines(): GraphLine[];
58
+ getLineEnds(): RoutePoint[];
59
+ }
60
+ export interface GraphInstance {
61
+ readonly finder: PathFinder;
62
+ readonly dataSource: GraphDataSource;
63
+ readonly options: GraphBuildOptions;
64
+ }
65
+ export interface GraphBuildOptions {
66
+ readonly oriented?: boolean;
67
+ readonly onlyAccessible?: boolean;
68
+ }
69
+ export interface ShortestPathResult {
70
+ readonly lines: RouteLine[];
71
+ readonly distance: number;
72
+ }
73
+ export interface RouteResult {
74
+ readonly lines: RouteLine[];
75
+ readonly totalDistance: number;
76
+ }
77
+ export type RouteSnapResult = {
78
+ snapped: false;
79
+ } | {
80
+ readonly snapped: true;
81
+ readonly snappedPoint: RoutePoint;
82
+ readonly snappedLine: RouteLine;
83
+ /** Arc-length from `snappedPoint` to the destination, along the route. */
84
+ readonly distance: number;
85
+ };
86
+ /**
87
+ * Route endpoint: anchor on a layer, with optional perimeter polygon (booth bounds).
88
+ * With `bounds` → engine picks the optimal graph node inside the polygon.
89
+ * Without `bounds` → off-graph point (e.g. kiosk); engine snaps to nearest graph anchor.
90
+ *
91
+ * `id` is an opaque runtime discriminator the engine ignores — used by the
92
+ * adapter layer to mark off-graph endpoints (e.g. CP-derived vs kiosk anchor)
93
+ * so the renderer can branch on endpoint origin without re-checking UI types.
94
+ */
95
+ export interface RouteEndpoint extends RoutePoint {
96
+ readonly bounds?: readonly PolygonVertex[];
97
+ readonly id?: string;
98
+ }
99
+ export interface SnapToRouteConfig {
100
+ readonly snapThreshold: number;
101
+ }
102
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import type { Box } from '@expofp/geometry';
2
+ import type { RenderableDef } from '@expofp/renderer';
3
+ import { type GpsProjectionConfig, type GraphDataSource, type Route, type RouteEndpoint, type RouteLine, type RoutePoint, type TransitionPointDef } from './core/index.js';
4
+ import { type IconConfig, type RendererPort, type WayfindingLayers, type WayfindingRendererConfig } from './renderer/index.js';
5
+ import { type FloorContext, type IconProvider, type PositionInput, type SetRouteInput } from './runtime/index.js';
6
+ /** Plan GPS calibration plus optional snap / reroute distance overrides (meters). */
7
+ export type GpsConfig = GpsProjectionConfig & {
8
+ snapThreshold?: number;
9
+ rerouteThreshold?: number;
10
+ };
11
+ /**
12
+ * Everything `createWayfinding` needs. The host implements the four ports
13
+ * (`dataSource`/`renderer`/`iconProvider`/`floorContext`) so the package stays
14
+ * free of any concrete renderer, DOM, or app state.
15
+ */
16
+ export interface WayfindingConfig {
17
+ readonly dataSource: GraphDataSource;
18
+ readonly renderer: RendererPort;
19
+ readonly iconProvider: IconProvider;
20
+ readonly floorContext: FloorContext;
21
+ /** The layers from `initWayfindingLayers()` — the block the host mounted, which this fills. */
22
+ readonly layers: WayfindingLayers;
23
+ /** Route line colors; defaults apply for anything omitted. */
24
+ readonly rendererConfig?: WayfindingRendererConfig;
25
+ /** Plan GPS calibration; the snap and reroute thresholds are derived from it. */
26
+ readonly gpsConfig?: GpsConfig;
27
+ /**
28
+ * Draws every icon facing the camera, through `ImageDef.screenSpace`. Set it when the plan
29
+ * renders in 3D, together with the `overlay` option of `initWayfindingLayers`.
30
+ *
31
+ * An icon then keeps its plan anchor and the on-screen size `onScale` gives it, and stands up to
32
+ * face the viewer. Two costs come with that. It takes {@link IconConfig.cardinalSnap} out of
33
+ * use, because the renderer owns a screen-space def's orientation and ignores a roll rule on
34
+ * one. It also changes what {@link IconConfig.rotation} turns about, from the plan's normal to
35
+ * the screen's, so an icon whose rotation carries a plan heading points at a screen direction
36
+ * instead.
37
+ */
38
+ readonly screenSpaceIcons?: boolean;
39
+ readonly onTransitionClick?: (point: TransitionPointDef) => void;
40
+ /** Fired when the route changes. `bounds.isEmpty()` detects an empty/cleared route. */
41
+ readonly onRouteUpdate?: (lines: readonly RouteLine[], bounds: Box) => void;
42
+ /** Fired when the remaining distance changes (route change + position snaps). */
43
+ readonly onRouteDistance?: (distance: number) => void;
44
+ }
45
+ /**
46
+ * The single wayfinding instance. Owns the routing engine, the scene renderer, and the runtime; the
47
+ * host drives it with route/position/floor updates and forwards its pointer events to the
48
+ * `handle*` methods. Camera moves need nothing from here — the defs carry their own layout rules.
49
+ */
50
+ export interface Wayfinding {
51
+ /** Build (or update) the active route; `false` when no path exists. */
52
+ setRoute(input: SetRouteInput): boolean;
53
+ /** Build a one-off route without touching the active scene (diagnostics). */
54
+ buildRoute(from: RouteEndpoint, to: RouteEndpoint, options?: {
55
+ accessible?: boolean;
56
+ }): Route;
57
+ clearRoute(): void;
58
+ /** Update the user position; `null` hides the position icon and off-route trail. */
59
+ setPosition(position: PositionInput | null): void;
60
+ /** Re-render route content after the active floor changed. */
61
+ notifyFloorChanged(): void;
62
+ /** Whether the position has drifted off the active route far enough to reroute. */
63
+ shouldReroute(position: RoutePoint): boolean;
64
+ /**
65
+ * Forward a pointer click (already picked scene defs); fires icon `onClick`, and reports whether
66
+ * one claimed it.
67
+ */
68
+ handleClick(defs: readonly RenderableDef[]): boolean;
69
+ /** Forward a pointer move (already picked scene defs); `true` over a clickable icon. */
70
+ handleHover(defs: readonly RenderableDef[]): boolean;
71
+ /**
72
+ * Place, update, or hide (`config: null`) a host annotation icon — kiosk, you-are-here — on the
73
+ * wayfinding icon layer, laid out like the route's own. Buffered — call `flush()` to commit.
74
+ */
75
+ setIcon(name: string, config: IconConfig | null, key?: string | number): void;
76
+ /** Commit buffered scene mutations. */
77
+ flush(): void;
78
+ destroy(): void;
79
+ }
80
+ export declare function createWayfinding(config: WayfindingConfig): Wayfinding;
81
+ //# sourceMappingURL=createWayfinding.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { createWayfindingEngine, getThresholdFromMetersToSvg, getThresholdOrDefault, resolveRerouteThresholdSvg, SNAP_THRESHOLD_METERS, } from './core/index.js';
2
+ import { createWayfindingRenderer, } from './renderer/index.js';
3
+ import { createWayfindingRuntime, } from './runtime/index.js';
4
+ export function createWayfinding(config) {
5
+ const { dataSource, renderer: rendererPort, iconProvider, floorContext, layers, gpsConfig, } = config;
6
+ const engine = createWayfindingEngine(dataSource);
7
+ const renderer = createWayfindingRenderer(rendererPort, layers, {
8
+ ...config.rendererConfig,
9
+ screenSpaceIcons: config.screenSpaceIcons,
10
+ });
11
+ const snapThresholdMeters = getThresholdOrDefault(gpsConfig?.snapThreshold, SNAP_THRESHOLD_METERS);
12
+ const snapThreshold = getThresholdFromMetersToSvg({
13
+ thresholdInMeters: snapThresholdMeters,
14
+ gpsConfig,
15
+ });
16
+ const runtime = createWayfindingRuntime({
17
+ engine,
18
+ renderer,
19
+ iconProvider,
20
+ floorContext,
21
+ snapThreshold,
22
+ rerouteThreshold: resolveRerouteThresholdSvg(gpsConfig),
23
+ onTransitionClick: (point) => config.onTransitionClick?.(point),
24
+ onRouteUpdate: (lines, bounds) => config.onRouteUpdate?.(lines, bounds),
25
+ onRouteDistance: (distance) => config.onRouteDistance?.(distance),
26
+ });
27
+ return {
28
+ setRoute: (input) => runtime.setRoute(input),
29
+ buildRoute: (from, to, options) => engine.buildRoute(from, to, options),
30
+ clearRoute: () => runtime.clearRoute(),
31
+ setPosition: (position) => runtime.onPositionChanged(position),
32
+ notifyFloorChanged: () => runtime.onFloorChanged(),
33
+ shouldReroute: (position) => runtime.shouldReroute(position),
34
+ handleClick: (defs) => {
35
+ for (const def of defs) {
36
+ if (renderer.handleClick(def))
37
+ return true;
38
+ }
39
+ return false;
40
+ },
41
+ handleHover: (defs) => defs.some((def) => renderer.handleHover(def)),
42
+ setIcon: (name, config, key) => renderer.setIcon(name, config, key),
43
+ flush: () => renderer.flush(),
44
+ destroy: () => runtime.destroy(),
45
+ };
46
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `@expofp/wayfinding` — framework-neutral wayfinding: routing/snapping engine,
3
+ * an imperative runtime, and a scene renderer behind two entry points:
4
+ * `initWayfindingLayers` builds the layers for the host to mount,
5
+ * `createWayfinding` fills them.
6
+ */
7
+ export type { GpsConfig, Wayfinding, WayfindingConfig } from './createWayfinding.js';
8
+ export { createWayfinding } from './createWayfinding.js';
9
+ export type { WayfindingLayerOptions, WayfindingLayers } from './renderer/index.js';
10
+ export { initWayfindingLayers, resolveWayfindingLayers } from './renderer/index.js';
11
+ export type { GraphDataSource } from './core/index.js';
12
+ export type { IconConfig, RendererPort, RouteColors, TrailOptions, WayfindingRendererConfig, } from './renderer/index.js';
13
+ export type { FloorContext, IconAsset, IconName, IconProvider } from './runtime/index.js';
14
+ export type { GraphLine, Route, RouteEndpoint, RouteLine, RoutePoint, TransitionPointDef, } from './core/index.js';
15
+ export type { PositionInput, SetRouteInput } from './runtime/index.js';
16
+ export { CURRENT_POSITION_POINT_ID } from './runtime/index.js';
17
+ export { optimizeWaypointOrder } from './core/routing/optimizeWaypointOrder.js';
18
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@expofp/wayfinding` — framework-neutral wayfinding: routing/snapping engine,
3
+ * an imperative runtime, and a scene renderer behind two entry points:
4
+ * `initWayfindingLayers` builds the layers for the host to mount,
5
+ * `createWayfinding` fills them.
6
+ */
7
+ export { createWayfinding } from './createWayfinding.js';
8
+ export { initWayfindingLayers, resolveWayfindingLayers } from './renderer/index.js';
9
+ // Protocol sentinel: the host must stamp it as the `id` of a "current position"
10
+ // route endpoint so the runtime renders that point as the live position.
11
+ export { CURRENT_POSITION_POINT_ID } from './runtime/index.js';
12
+ // Pure routing helper: orders waypoints for the shortest visiting sequence
13
+ // (nearest-neighbor + 2-opt). Stateless and instance-free, so callers can plan
14
+ // multi-stop routes before a wayfinding instance exists (e.g. the SDK
15
+ // `getOptimizedRoutes`).
16
+ export { optimizeWaypointOrder } from './core/routing/optimizeWaypointOrder.js';
@@ -0,0 +1,8 @@
1
+ import type { WayfindingLayers } from './layers.js';
2
+ import type { RendererPort, WayfindingRenderer, WayfindingRendererConfig } from './types.js';
3
+ /**
4
+ * Create a {@link WayfindingRenderer} — the composition root over {@link LayerManager},
5
+ * {@link IconManager}, {@link TrailManager} and {@link RouteLineManager}.
6
+ */
7
+ export declare function createWayfindingRenderer(port: RendererPort, layers: WayfindingLayers, config?: WayfindingRendererConfig): WayfindingRenderer;
8
+ //# sourceMappingURL=createWayfindingRenderer.d.ts.map
@@ -0,0 +1,45 @@
1
+ import { createIconManager } from './iconManager.js';
2
+ import { createLayerManager } from './layerManager.js';
3
+ import { createRouteLineManager } from './routeLineManager.js';
4
+ import { createTrailManager } from './trailManager.js';
5
+ const DEFAULT_COLORS = {
6
+ passed: '#B5B7BC',
7
+ remaining: '#A4CCE2',
8
+ active: '#0794EA',
9
+ };
10
+ /**
11
+ * Create a {@link WayfindingRenderer} — the composition root over {@link LayerManager},
12
+ * {@link IconManager}, {@link TrailManager} and {@link RouteLineManager}.
13
+ */
14
+ export function createWayfindingRenderer(port, layers, config = {}) {
15
+ const colors = { ...DEFAULT_COLORS, ...config.colors };
16
+ const layerManager = createLayerManager(port);
17
+ const iconManager = createIconManager(layerManager, port, layers, config.screenSpaceIcons);
18
+ const trailManager = createTrailManager(layerManager, layers.trail);
19
+ const routeLineManager = createRouteLineManager(layerManager, colors, port, layers);
20
+ const wfRenderer = {
21
+ setIcon: (...args) => iconManager.setIcon(...args),
22
+ clearIcons: (...args) => iconManager.clearIcons(...args),
23
+ setTrail: (...args) => trailManager.setTrail(...args),
24
+ setRouteLines: (...args) => routeLineManager.setRouteLines(...args),
25
+ handleClick: (def) => iconManager.handleClick(def),
26
+ handleHover: (def) => iconManager.handleHover(def),
27
+ clearRoute() {
28
+ routeLineManager.clearLines();
29
+ trailManager.destroy();
30
+ iconManager.hideAll();
31
+ },
32
+ flush: () => layerManager.flush(),
33
+ destroy() {
34
+ wfRenderer.clearRoute();
35
+ iconManager.destroy();
36
+ trailManager.destroy();
37
+ routeLineManager.destroy();
38
+ // The layers belong to the host and outlive this instance, so emptying them has to reach the
39
+ // renderer before the dirty sets go — nothing is left to flush this afterwards.
40
+ layerManager.flush();
41
+ layerManager.destroy();
42
+ },
43
+ };
44
+ return wfRenderer;
45
+ }