@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.
- package/README.md +85 -0
- package/dist/core/createWayfindingEngine.d.ts +16 -0
- package/dist/core/createWayfindingEngine.js +87 -0
- package/dist/core/geometry/pointInPolygon.d.ts +17 -0
- package/dist/core/geometry/pointInPolygon.js +50 -0
- package/dist/core/geometry/projectPointOnSegment.d.ts +27 -0
- package/dist/core/geometry/projectPointOnSegment.js +21 -0
- package/dist/core/graph/buildGraph.d.ts +3 -0
- package/dist/core/graph/buildGraph.js +7 -0
- package/dist/core/graph/buildNGraph.d.ts +13 -0
- package/dist/core/graph/buildNGraph.js +24 -0
- package/dist/core/graph/constants.d.ts +20 -0
- package/dist/core/graph/constants.js +19 -0
- package/dist/core/graph/findShortestPath.d.ts +23 -0
- package/dist/core/graph/findShortestPath.js +65 -0
- package/dist/core/graph/graphCache.d.ts +7 -0
- package/dist/core/graph/graphCache.js +23 -0
- package/dist/core/graph/graphHelpers.d.ts +8 -0
- package/dist/core/graph/graphHelpers.js +63 -0
- package/dist/core/graph/linkCost.d.ts +13 -0
- package/dist/core/graph/linkCost.js +24 -0
- package/dist/core/graph/pathfinder/aStarPathFinder.d.ts +3 -0
- package/dist/core/graph/pathfinder/aStarPathFinder.js +64 -0
- package/dist/core/graph/pathfinder/parseNodeId.d.ts +10 -0
- package/dist/core/graph/pathfinder/parseNodeId.js +20 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.js +12 -0
- package/dist/core/position/distanceToRoute.d.ts +3 -0
- package/dist/core/position/distanceToRoute.js +29 -0
- package/dist/core/position/gpsThreshold.d.ts +32 -0
- package/dist/core/position/gpsThreshold.js +48 -0
- package/dist/core/position/rerouteController.d.ts +13 -0
- package/dist/core/position/rerouteController.js +22 -0
- package/dist/core/position/snapToRoute.d.ts +9 -0
- package/dist/core/position/snapToRoute.js +50 -0
- package/dist/core/position/splitRouteByPoint.d.ts +6 -0
- package/dist/core/position/splitRouteByPoint.js +56 -0
- package/dist/core/rendering/computeTrailPoints.d.ts +12 -0
- package/dist/core/rendering/computeTrailPoints.js +35 -0
- package/dist/core/rendering/computeTransitionPoints.d.ts +35 -0
- package/dist/core/rendering/computeTransitionPoints.js +112 -0
- package/dist/core/rendering/getVisibleRouteLines.d.ts +10 -0
- package/dist/core/rendering/getVisibleRouteLines.js +18 -0
- package/dist/core/rendering/routeGeometry.d.ts +9 -0
- package/dist/core/rendering/routeGeometry.js +10 -0
- package/dist/core/routing/buildMultiPointRoute.d.ts +13 -0
- package/dist/core/routing/buildMultiPointRoute.js +36 -0
- package/dist/core/routing/buildRoute.d.ts +12 -0
- package/dist/core/routing/buildRoute.js +19 -0
- package/dist/core/routing/getRouteLength.d.ts +3 -0
- package/dist/core/routing/getRouteLength.js +4 -0
- package/dist/core/routing/graphPointResolvers.d.ts +9 -0
- package/dist/core/routing/graphPointResolvers.js +13 -0
- package/dist/core/routing/optimizeWaypointOrder.d.ts +14 -0
- package/dist/core/routing/optimizeWaypointOrder.js +88 -0
- package/dist/core/routing/resolveWaypointCandidates.d.ts +23 -0
- package/dist/core/routing/resolveWaypointCandidates.js +49 -0
- package/dist/core/routing/routeResult.d.ts +4 -0
- package/dist/core/routing/routeResult.js +2 -0
- package/dist/core/types.d.ts +102 -0
- package/dist/core/types.js +1 -0
- package/dist/createWayfinding.d.ts +81 -0
- package/dist/createWayfinding.js +46 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +16 -0
- package/dist/renderer/createWayfindingRenderer.d.ts +8 -0
- package/dist/renderer/createWayfindingRenderer.js +45 -0
- package/dist/renderer/iconManager.d.ts +58 -0
- package/dist/renderer/iconManager.js +222 -0
- package/dist/renderer/index.d.ts +5 -0
- package/dist/renderer/index.js +2 -0
- package/dist/renderer/layerManager.d.ts +36 -0
- package/dist/renderer/layerManager.js +31 -0
- package/dist/renderer/layers.d.ts +54 -0
- package/dist/renderer/layers.js +66 -0
- package/dist/renderer/lineAnimation.d.ts +25 -0
- package/dist/renderer/lineAnimation.js +196 -0
- package/dist/renderer/routeLineManager.d.ts +45 -0
- package/dist/renderer/routeLineManager.js +153 -0
- package/dist/renderer/trailManager.d.ts +29 -0
- package/dist/renderer/trailManager.js +183 -0
- package/dist/renderer/types.d.ts +163 -0
- package/dist/renderer/types.js +1 -0
- package/dist/runtime/createWayfindingRuntime.d.ts +3 -0
- package/dist/runtime/createWayfindingRuntime.js +237 -0
- package/dist/runtime/endpointView.d.ts +19 -0
- package/dist/runtime/endpointView.js +44 -0
- package/dist/runtime/getRouteLines.d.ts +19 -0
- package/dist/runtime/getRouteLines.js +16 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/positionTrailView.d.ts +51 -0
- package/dist/runtime/positionTrailView.js +35 -0
- package/dist/runtime/positionView.d.ts +22 -0
- package/dist/runtime/positionView.js +34 -0
- package/dist/runtime/routeLinesView.d.ts +16 -0
- package/dist/runtime/routeLinesView.js +10 -0
- package/dist/runtime/routeRenderData.d.ts +31 -0
- package/dist/runtime/routeRenderData.js +44 -0
- package/dist/runtime/routeUpdate.d.ts +17 -0
- package/dist/runtime/routeUpdate.js +17 -0
- package/dist/runtime/snapPositionToRoute.d.ts +10 -0
- package/dist/runtime/snapPositionToRoute.js +36 -0
- package/dist/runtime/trailView.d.ts +19 -0
- package/dist/runtime/trailView.js +43 -0
- package/dist/runtime/transitionView.d.ts +16 -0
- package/dist/runtime/transitionView.js +51 -0
- package/dist/runtime/types.d.ts +81 -0
- package/dist/runtime/types.js +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ImageDef, RenderableDef } from '@expofp/renderer';
|
|
2
|
+
import type { LayerManager } from './layerManager.js';
|
|
3
|
+
import type { WayfindingLayers } from './layers.js';
|
|
4
|
+
import type { IconConfig, RendererPort } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The size an icon canvas is drawn at, in CSS pixels.
|
|
7
|
+
* @param canvas - The icon's canvas.
|
|
8
|
+
* @param width - The width the caller stated, if any.
|
|
9
|
+
* @param height - The height the caller stated, if any.
|
|
10
|
+
* @returns The stated size, with whatever is missing read from the canvas's `style`.
|
|
11
|
+
* @throws When neither the caller nor the canvas says how big the icon is.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveCssSize(canvas: HTMLCanvasElement, width?: number, height?: number): {
|
|
14
|
+
readonly width: number;
|
|
15
|
+
readonly height: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Lays one wayfinding icon out for a new pixel size: an icon holds its on-screen size, so its
|
|
19
|
+
* bounds are its size in CSS pixels times the pixel size, about its own center.
|
|
20
|
+
*
|
|
21
|
+
* The **only** writer of an icon's bounds size, which is what lets everything else here write
|
|
22
|
+
* logical fields alone and never track a scale. Returns nothing when the size was already right, so
|
|
23
|
+
* a settled camera costs no slot writes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function rescaleIcon(def: ImageDef, size: {
|
|
26
|
+
readonly width: number;
|
|
27
|
+
readonly height: number;
|
|
28
|
+
}, pixelSize: number): readonly RenderableDef[] | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Manages `ImageDef` icons in the scene graph.
|
|
31
|
+
*
|
|
32
|
+
* Icons are keyed by `(name, key?)`. First `setIcon` creates the `ImageDef`; later calls mutate in
|
|
33
|
+
* place. Pass `config: null` to hide an icon without destroying it.
|
|
34
|
+
*/
|
|
35
|
+
export interface IconManager {
|
|
36
|
+
/** Place, update, or hide an icon. See {@link WayfindingRenderer.setIcon}. */
|
|
37
|
+
setIcon(name: string, config: IconConfig | null, key?: string | number): void;
|
|
38
|
+
/** Hide all icons matching the given name(s). */
|
|
39
|
+
clearIcons(names: string | readonly string[]): void;
|
|
40
|
+
/** Hide every managed icon (used by `clearRoute`). */
|
|
41
|
+
hideAll(): void;
|
|
42
|
+
/** Clear internal state. */
|
|
43
|
+
destroy(): void;
|
|
44
|
+
/** Fire a clicked icon's `onClick`; returns whether the def was one. */
|
|
45
|
+
handleClick(def: RenderableDef): boolean;
|
|
46
|
+
/** Whether a def is a clickable icon. */
|
|
47
|
+
handleHover(def: RenderableDef): boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create an {@link IconManager} that places icons into the two icon layers of the block.
|
|
51
|
+
* @param layerManager - Tracks what changed.
|
|
52
|
+
* @param port - The host's roll rule and commit.
|
|
53
|
+
* @param layers - The icon layers to place into.
|
|
54
|
+
* @param screenSpace - Whether every icon faces the camera rather than lying on the plan.
|
|
55
|
+
* @returns The manager.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createIconManager(layerManager: LayerManager, port: RendererPort, layers: Pick<WayfindingLayers, 'icons' | 'currentPosition'>, screenSpace?: boolean): IconManager;
|
|
58
|
+
//# sourceMappingURL=iconManager.d.ts.map
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Rect } from '@expofp/geometry';
|
|
2
|
+
/**
|
|
3
|
+
* The size an icon canvas is drawn at, in CSS pixels.
|
|
4
|
+
* @param canvas - The icon's canvas.
|
|
5
|
+
* @param width - The width the caller stated, if any.
|
|
6
|
+
* @param height - The height the caller stated, if any.
|
|
7
|
+
* @returns The stated size, with whatever is missing read from the canvas's `style`.
|
|
8
|
+
* @throws When neither the caller nor the canvas says how big the icon is.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveCssSize(canvas, width, height) {
|
|
11
|
+
const resolvedWidth = width ?? parseFloat(canvas.style?.width ?? '');
|
|
12
|
+
const resolvedHeight = height ?? parseFloat(canvas.style?.height ?? '');
|
|
13
|
+
if (!(resolvedWidth > 0) || !(resolvedHeight > 0)) {
|
|
14
|
+
throw new Error(`renderer: canvas "${canvas.id}" has no CSS size: pass width and height, or draw it on a canvas whose style records one`);
|
|
15
|
+
}
|
|
16
|
+
return { width: resolvedWidth, height: resolvedHeight };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Lays one wayfinding icon out for a new pixel size: an icon holds its on-screen size, so its
|
|
20
|
+
* bounds are its size in CSS pixels times the pixel size, about its own center.
|
|
21
|
+
*
|
|
22
|
+
* The **only** writer of an icon's bounds size, which is what lets everything else here write
|
|
23
|
+
* logical fields alone and never track a scale. Returns nothing when the size was already right, so
|
|
24
|
+
* a settled camera costs no slot writes.
|
|
25
|
+
*/
|
|
26
|
+
export function rescaleIcon(def, size, pixelSize) {
|
|
27
|
+
const bounds = def.bounds;
|
|
28
|
+
const width = size.width * pixelSize;
|
|
29
|
+
const height = size.height * pixelSize;
|
|
30
|
+
if (bounds.size.x === width && bounds.size.y === height)
|
|
31
|
+
return undefined;
|
|
32
|
+
bounds.set(bounds.center.x, bounds.center.y, width, height, bounds.rotation, bounds.elevation);
|
|
33
|
+
return [def];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create an {@link IconManager} that places icons into the two icon layers of the block.
|
|
37
|
+
* @param layerManager - Tracks what changed.
|
|
38
|
+
* @param port - The host's roll rule and commit.
|
|
39
|
+
* @param layers - The icon layers to place into.
|
|
40
|
+
* @param screenSpace - Whether every icon faces the camera rather than lying on the plan.
|
|
41
|
+
* @returns The manager.
|
|
42
|
+
*/
|
|
43
|
+
export function createIconManager(layerManager, port, layers, screenSpace = false) {
|
|
44
|
+
const icons = new Map();
|
|
45
|
+
const iconKeysByName = new Map();
|
|
46
|
+
const keyToName = new Map();
|
|
47
|
+
/** The reverse of {@link icons}: a pointer hit names a def, so it is a lookup, not a scan. */
|
|
48
|
+
const iconsByDef = new Map();
|
|
49
|
+
/**
|
|
50
|
+
* Which of the two icon layers an icon belongs in — the only structural choice left to a caller,
|
|
51
|
+
* and not a layer name: `onTop` says the icon must not be covered by the others.
|
|
52
|
+
* @param cfg - The icon's config.
|
|
53
|
+
* @returns The layer to place it in.
|
|
54
|
+
*/
|
|
55
|
+
function layerFor(cfg) {
|
|
56
|
+
return cfg.onTop ? layers.currentPosition : layers.icons;
|
|
57
|
+
}
|
|
58
|
+
function composeKey(name, key) {
|
|
59
|
+
return key === undefined ? name : `${name}#${key}`;
|
|
60
|
+
}
|
|
61
|
+
function trackKey(name, iconKey) {
|
|
62
|
+
let nameKeys = iconKeysByName.get(name);
|
|
63
|
+
if (!nameKeys) {
|
|
64
|
+
nameKeys = new Set();
|
|
65
|
+
iconKeysByName.set(name, nameKeys);
|
|
66
|
+
}
|
|
67
|
+
nameKeys.add(iconKey);
|
|
68
|
+
keyToName.set(iconKey, name);
|
|
69
|
+
}
|
|
70
|
+
function untrackKey(iconKey) {
|
|
71
|
+
const name = keyToName.get(iconKey);
|
|
72
|
+
if (!name)
|
|
73
|
+
return;
|
|
74
|
+
const nameKeys = iconKeysByName.get(name);
|
|
75
|
+
if (nameKeys)
|
|
76
|
+
nameKeys.delete(iconKey);
|
|
77
|
+
keyToName.delete(iconKey);
|
|
78
|
+
}
|
|
79
|
+
function createIcon(iconKey, name, cfg, rotation = cfg.rotation) {
|
|
80
|
+
const layer = layerFor(cfg);
|
|
81
|
+
const size = resolveCssSize(cfg.canvas, cfg.width, cfg.height);
|
|
82
|
+
// The caller's own answer wins where it gave one. An icon whose rotation carries a plan bearing
|
|
83
|
+
// opts out, because a screen-space def spins about the screen's normal and would point at a
|
|
84
|
+
// fixed screen direction instead.
|
|
85
|
+
const facesCamera = cfg.screenSpace ?? screenSpace;
|
|
86
|
+
layerManager.touchLayer(layer);
|
|
87
|
+
// Size zero on purpose: an icon's size is only expressible in terms of the current pixel size, and
|
|
88
|
+
// `rescaleIcon` is its one writer. The renderer lays a def out as it registers, hidden or not, so
|
|
89
|
+
// it is never drawn at this placeholder.
|
|
90
|
+
const def = {
|
|
91
|
+
source: cfg.canvas,
|
|
92
|
+
bounds: new Rect({ x: cfg.x, y: cfg.y }, ZERO, rotation),
|
|
93
|
+
hidden: cfg.hidden ?? false,
|
|
94
|
+
dim: cfg.dimmed ? 1 : 0,
|
|
95
|
+
origin: cfg.origin,
|
|
96
|
+
screenSpace: facesCamera,
|
|
97
|
+
};
|
|
98
|
+
// A screen-space icon already stands up to face the viewer, so it has no readability to keep
|
|
99
|
+
// through a quarter turn. Its own billboarding is what a cardinal snap would be for.
|
|
100
|
+
if (cfg.cardinalSnap && !facesCamera)
|
|
101
|
+
port.attachCardinalSnap(def);
|
|
102
|
+
def.onScale = ({ pixelSize }) => rescaleIcon(def, size, pixelSize);
|
|
103
|
+
layer.children.push(def);
|
|
104
|
+
const record = {
|
|
105
|
+
imageDef: def,
|
|
106
|
+
layer,
|
|
107
|
+
callback: cfg.onClick ?? null,
|
|
108
|
+
};
|
|
109
|
+
icons.set(iconKey, record);
|
|
110
|
+
iconsByDef.set(def, record);
|
|
111
|
+
trackKey(name, iconKey);
|
|
112
|
+
return record;
|
|
113
|
+
}
|
|
114
|
+
function recreateIcon(iconKey, name, record, cfg) {
|
|
115
|
+
const oldChildren = record.layer.children;
|
|
116
|
+
const idx = oldChildren.indexOf(record.imageDef);
|
|
117
|
+
// The heading the icon holds, which the replacement inherits when the caller names none: a
|
|
118
|
+
// cardinal-snap icon carries whole quarters the camera gave it, and a new canvas is no reason
|
|
119
|
+
// to lose them.
|
|
120
|
+
const rotation = cfg.rotation ?? record.imageDef.bounds.rotation;
|
|
121
|
+
// Hidden as well as removed. The renderer commits a def write synchronously and defers the
|
|
122
|
+
// membership sweep, so a def only spliced out stays drawn — the old canvas, at the old place —
|
|
123
|
+
// until that sweep lands.
|
|
124
|
+
record.imageDef.hidden = true;
|
|
125
|
+
layerManager.touchDef(record.imageDef);
|
|
126
|
+
if (idx >= 0)
|
|
127
|
+
oldChildren.splice(idx, 1);
|
|
128
|
+
layerManager.touchLayer(record.layer);
|
|
129
|
+
icons.delete(iconKey);
|
|
130
|
+
iconsByDef.delete(record.imageDef);
|
|
131
|
+
untrackKey(iconKey);
|
|
132
|
+
createIcon(iconKey, name, cfg, rotation);
|
|
133
|
+
}
|
|
134
|
+
function updateIcon(iconKey, name, record, cfg) {
|
|
135
|
+
if (record.layer !== layerFor(cfg)) {
|
|
136
|
+
throw new Error(`renderer: icon "${iconKey}" cannot move between layers (was onTop=${!!(record.layer === layers.currentPosition)}, got onTop=${!!cfg.onTop})`);
|
|
137
|
+
}
|
|
138
|
+
if (record.imageDef.source !== cfg.canvas) {
|
|
139
|
+
recreateIcon(iconKey, name, record, cfg);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Logical fields only — where the icon is, which way it faces. The size it already carries is
|
|
143
|
+
// correct for the camera it was laid out at, and moving an icon does not change that.
|
|
144
|
+
const bounds = record.imageDef.bounds;
|
|
145
|
+
const rotation = cfg.rotation ?? bounds.rotation;
|
|
146
|
+
bounds.set(cfg.x, cfg.y, bounds.size.x, bounds.size.y, rotation, bounds.elevation);
|
|
147
|
+
record.imageDef.hidden = cfg.hidden ?? false;
|
|
148
|
+
record.imageDef.dim = cfg.dimmed ? 1 : 0;
|
|
149
|
+
record.callback = cfg.onClick ?? null;
|
|
150
|
+
layerManager.touchDef(record.imageDef);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Hides one icon and records that its **def** changed, not the layer holding it: the layer's
|
|
154
|
+
* children are unchanged, so a renderer reconciling the layer would never reach this instance.
|
|
155
|
+
*/
|
|
156
|
+
function hideIcon(record) {
|
|
157
|
+
record.imageDef.hidden = true;
|
|
158
|
+
record.callback = null;
|
|
159
|
+
layerManager.touchDef(record.imageDef);
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
setIcon(name, cfg, key) {
|
|
163
|
+
const iconKey = composeKey(name, key);
|
|
164
|
+
if (cfg === null) {
|
|
165
|
+
const record = icons.get(iconKey);
|
|
166
|
+
if (record)
|
|
167
|
+
hideIcon(record);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const existing = icons.get(iconKey);
|
|
171
|
+
if (existing)
|
|
172
|
+
updateIcon(iconKey, name, existing, cfg);
|
|
173
|
+
else
|
|
174
|
+
createIcon(iconKey, name, cfg);
|
|
175
|
+
},
|
|
176
|
+
clearIcons(names) {
|
|
177
|
+
const list = typeof names === 'string' ? [names] : names;
|
|
178
|
+
for (const name of list) {
|
|
179
|
+
const nameKeys = iconKeysByName.get(name);
|
|
180
|
+
if (!nameKeys)
|
|
181
|
+
continue;
|
|
182
|
+
for (const iconKey of nameKeys) {
|
|
183
|
+
const record = icons.get(iconKey);
|
|
184
|
+
if (record)
|
|
185
|
+
hideIcon(record);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
hideAll() {
|
|
190
|
+
for (const record of icons.values())
|
|
191
|
+
hideIcon(record);
|
|
192
|
+
},
|
|
193
|
+
destroy() {
|
|
194
|
+
// The layers belong to the host and outlive this manager, so what was put in them comes back
|
|
195
|
+
// out: a handle that keeps a torn-down instance's icons is not reusable.
|
|
196
|
+
for (const record of icons.values()) {
|
|
197
|
+
const children = record.layer.children;
|
|
198
|
+
const idx = children.indexOf(record.imageDef);
|
|
199
|
+
if (idx >= 0)
|
|
200
|
+
children.splice(idx, 1);
|
|
201
|
+
layerManager.touchLayer(record.layer);
|
|
202
|
+
}
|
|
203
|
+
icons.clear();
|
|
204
|
+
iconsByDef.clear();
|
|
205
|
+
iconKeysByName.clear();
|
|
206
|
+
keyToName.clear();
|
|
207
|
+
},
|
|
208
|
+
handleClick(def) {
|
|
209
|
+
const record = iconsByDef.get(def);
|
|
210
|
+
if (!record?.callback || record.imageDef.hidden)
|
|
211
|
+
return false;
|
|
212
|
+
record.callback();
|
|
213
|
+
return true;
|
|
214
|
+
},
|
|
215
|
+
handleHover(def) {
|
|
216
|
+
const record = iconsByDef.get(def);
|
|
217
|
+
return Boolean(record?.callback) && !record?.imageDef.hidden;
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/** The size a new icon is created at, before its handler gives it a real one. */
|
|
222
|
+
const ZERO = { x: 0, y: 0 };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createWayfindingRenderer } from './createWayfindingRenderer.js';
|
|
2
|
+
export type { WayfindingLayerOptions, WayfindingLayers } from './layers.js';
|
|
3
|
+
export { initWayfindingLayers, resolveWayfindingLayers } from './layers.js';
|
|
4
|
+
export type { IconConfig, RendererPort, RouteColors, TrailOptions, WayfindingRenderer, WayfindingRendererConfig, } from './types.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LayerDef, RenderableDef } from '@expofp/renderer';
|
|
2
|
+
import type { RendererPort } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Tracks what changed in the wayfinding layers and commits it.
|
|
5
|
+
*
|
|
6
|
+
* `touchLayer` marks a layer's **membership** as dirty and `touchDef` marks one def's **fields**;
|
|
7
|
+
* `flush` commits both through the injected `update` in a single call.
|
|
8
|
+
*
|
|
9
|
+
* The distinction is not cosmetic. A renderer reconciles a layer's children but writes a def's slot,
|
|
10
|
+
* so a def whose `hidden` or `bounds` moved is only drawn correctly if the def itself is committed —
|
|
11
|
+
* updating the layer that holds it reconciles a membership that did not change and reaches the def's
|
|
12
|
+
* instance not at all.
|
|
13
|
+
*/
|
|
14
|
+
export interface LayerManager {
|
|
15
|
+
/**
|
|
16
|
+
* Mark a layer's membership as dirty for the next {@link flush}.
|
|
17
|
+
* @param layer - The layer whose children changed.
|
|
18
|
+
*/
|
|
19
|
+
touchLayer(layer: LayerDef): void;
|
|
20
|
+
/**
|
|
21
|
+
* Mark one def's fields as dirty for the next {@link flush}.
|
|
22
|
+
* @param def - The def whose fields were mutated.
|
|
23
|
+
*/
|
|
24
|
+
touchDef(def: RenderableDef): void;
|
|
25
|
+
/** Commit everything dirty and clear the dirty sets. */
|
|
26
|
+
flush(): void;
|
|
27
|
+
/** Clear the dirty sets. */
|
|
28
|
+
destroy(): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a {@link LayerManager}.
|
|
32
|
+
* @param port - The commit function; see {@link RendererPort}.
|
|
33
|
+
* @returns The manager.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createLayerManager(port: RendererPort): LayerManager;
|
|
36
|
+
//# sourceMappingURL=layerManager.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a {@link LayerManager}.
|
|
3
|
+
* @param port - The commit function; see {@link RendererPort}.
|
|
4
|
+
* @returns The manager.
|
|
5
|
+
*/
|
|
6
|
+
export function createLayerManager(port) {
|
|
7
|
+
const touchedLayers = new Set();
|
|
8
|
+
const touchedDefs = new Set();
|
|
9
|
+
return {
|
|
10
|
+
touchLayer(layer) {
|
|
11
|
+
touchedLayers.add(layer);
|
|
12
|
+
},
|
|
13
|
+
touchDef(def) {
|
|
14
|
+
touchedDefs.add(def);
|
|
15
|
+
},
|
|
16
|
+
flush() {
|
|
17
|
+
if (touchedLayers.size === 0 && touchedDefs.size === 0)
|
|
18
|
+
return;
|
|
19
|
+
for (const layer of touchedLayers) {
|
|
20
|
+
layer.children = [...layer.children];
|
|
21
|
+
}
|
|
22
|
+
port.update(...touchedLayers, ...touchedDefs);
|
|
23
|
+
touchedLayers.clear();
|
|
24
|
+
touchedDefs.clear();
|
|
25
|
+
},
|
|
26
|
+
destroy() {
|
|
27
|
+
touchedLayers.clear();
|
|
28
|
+
touchedDefs.clear();
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ImageDef, LayerDef, LineDef } from '@expofp/renderer';
|
|
2
|
+
/**
|
|
3
|
+
* The layers wayfinding fills, resolved out of the block the host mounted.
|
|
4
|
+
*
|
|
5
|
+
* One layer per def kind is not a choice: `RenderableDefCollection` admits no mixed children, so
|
|
6
|
+
* images and lines cannot share one. Which layers exist and how they stack among themselves is this
|
|
7
|
+
* package's business; where the block sits in a scene is the host's.
|
|
8
|
+
*/
|
|
9
|
+
/** How the host wants the block built. */
|
|
10
|
+
export interface WayfindingLayerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Draws the whole block above 3D content, through `LayerDef.overlay`.
|
|
13
|
+
*
|
|
14
|
+
* Set it when the plan renders in 3D. A route runs along the floor, so a booth volume standing
|
|
15
|
+
* between it and a tilted camera hides it. The overlay tier turns depth testing off for the
|
|
16
|
+
* block and draws it after every plan-tier layer, which is the case the tier exists for.
|
|
17
|
+
*
|
|
18
|
+
* Set on the block alone, because `overlay` accumulates down the layer tree. Every layer inside
|
|
19
|
+
* inherits it, and none of them can opt back out.
|
|
20
|
+
*/
|
|
21
|
+
readonly overlay?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface WayfindingLayers {
|
|
24
|
+
/** Dot trail between an off-graph anchor and the route. */
|
|
25
|
+
readonly trail: LayerDef<ImageDef>;
|
|
26
|
+
/** Static route lines — passed and remaining. */
|
|
27
|
+
readonly lines: LayerDef<LineDef>;
|
|
28
|
+
/** The chase animation over the remaining route. */
|
|
29
|
+
readonly linesAnimated: LayerDef<LineDef>;
|
|
30
|
+
/** Endpoint, transition and host icons. The one layer worth making pickable. */
|
|
31
|
+
readonly icons: LayerDef<ImageDef>;
|
|
32
|
+
/** The live position, above the icons so an endpoint pin never covers it. */
|
|
33
|
+
readonly currentPosition: LayerDef<ImageDef>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates the wayfinding block, empty.
|
|
37
|
+
*
|
|
38
|
+
* Mount it wherever wayfinding belongs in the scene — the route has to draw over the pathway layers
|
|
39
|
+
* (efp #1206). `createWayfinding` finds it there and fills it.
|
|
40
|
+
* @param options - How to build the block. See {@link WayfindingLayerOptions}.
|
|
41
|
+
* @returns The block to mount.
|
|
42
|
+
*/
|
|
43
|
+
export declare function initWayfindingLayers(options?: WayfindingLayerOptions): LayerDef<LayerDef>;
|
|
44
|
+
/**
|
|
45
|
+
* Finds the mounted block in a scene and hands back the layers inside it, so a host that mounted
|
|
46
|
+
* the block needs to carry nothing but its scene.
|
|
47
|
+
*
|
|
48
|
+
* The block sits directly under the scene's root layer, which is where the host mounted it.
|
|
49
|
+
* @param sceneRoot - The scene's root layer.
|
|
50
|
+
* @returns The layers to fill.
|
|
51
|
+
* @throws If the scene holds no wayfinding block — it was never mounted, or this is another scene.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveWayfindingLayers(sceneRoot: LayerDef): WayfindingLayers;
|
|
54
|
+
//# sourceMappingURL=layers.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The block's own layer names. Private: after this module nothing addresses a wayfinding layer by
|
|
2
|
+
// name — the host mounts the block, and the renderer holds the references.
|
|
3
|
+
const BLOCK_LAYER_NAME = 'wayfinding';
|
|
4
|
+
const TRAIL_LAYER_NAME = 'wf-trail-points';
|
|
5
|
+
const LINES_LAYER_NAME = 'wf-lines';
|
|
6
|
+
const LINES_ANIMATED_LAYER_NAME = 'wf-lines-animated';
|
|
7
|
+
const ICONS_LAYER_NAME = 'wf-points';
|
|
8
|
+
const CURRENT_POSITION_LAYER_NAME = 'wf-current-position';
|
|
9
|
+
/**
|
|
10
|
+
* Creates the wayfinding block, empty.
|
|
11
|
+
*
|
|
12
|
+
* Mount it wherever wayfinding belongs in the scene — the route has to draw over the pathway layers
|
|
13
|
+
* (efp #1206). `createWayfinding` finds it there and fills it.
|
|
14
|
+
* @param options - How to build the block. See {@link WayfindingLayerOptions}.
|
|
15
|
+
* @returns The block to mount.
|
|
16
|
+
*/
|
|
17
|
+
export function initWayfindingLayers(options = {}) {
|
|
18
|
+
const trail = { name: TRAIL_LAYER_NAME, children: [] };
|
|
19
|
+
const lines = { name: LINES_LAYER_NAME, children: [] };
|
|
20
|
+
const linesAnimated = { name: LINES_ANIMATED_LAYER_NAME, children: [] };
|
|
21
|
+
const icons = { name: ICONS_LAYER_NAME, children: [] };
|
|
22
|
+
const currentPosition = {
|
|
23
|
+
name: CURRENT_POSITION_LAYER_NAME,
|
|
24
|
+
children: [],
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
name: BLOCK_LAYER_NAME,
|
|
28
|
+
// Bottom → top, and the only place the block's order is stated.
|
|
29
|
+
children: [trail, lines, linesAnimated, icons, currentPosition],
|
|
30
|
+
// Once for the block, which the children inherit: a search dims the venue behind the route,
|
|
31
|
+
// never the route.
|
|
32
|
+
dim: 0,
|
|
33
|
+
// Once for the block as well, and for the same reason. `overlay` accumulates down the tree, so
|
|
34
|
+
// the five layers above inherit it and none of them can drop back to the plan tier.
|
|
35
|
+
overlay: options.overlay,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Finds the mounted block in a scene and hands back the layers inside it, so a host that mounted
|
|
40
|
+
* the block needs to carry nothing but its scene.
|
|
41
|
+
*
|
|
42
|
+
* The block sits directly under the scene's root layer, which is where the host mounted it.
|
|
43
|
+
* @param sceneRoot - The scene's root layer.
|
|
44
|
+
* @returns The layers to fill.
|
|
45
|
+
* @throws If the scene holds no wayfinding block — it was never mounted, or this is another scene.
|
|
46
|
+
*/
|
|
47
|
+
export function resolveWayfindingLayers(sceneRoot) {
|
|
48
|
+
const children = sceneRoot.children;
|
|
49
|
+
const root = children.find((child) => 'name' in child && child.name === BLOCK_LAYER_NAME && 'children' in child);
|
|
50
|
+
if (!root)
|
|
51
|
+
throw new Error('The scene holds no wayfinding block — mount `root` first.');
|
|
52
|
+
const byName = new Map(root.children.map((layer) => [layer.name, layer]));
|
|
53
|
+
function layerOf(name) {
|
|
54
|
+
const layer = byName.get(name);
|
|
55
|
+
if (!layer)
|
|
56
|
+
throw new Error(`The wayfinding block is missing its \`${name}\` layer.`);
|
|
57
|
+
return layer;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
trail: layerOf(TRAIL_LAYER_NAME),
|
|
61
|
+
lines: layerOf(LINES_LAYER_NAME),
|
|
62
|
+
linesAnimated: layerOf(LINES_ANIMATED_LAYER_NAME),
|
|
63
|
+
icons: layerOf(ICONS_LAYER_NAME),
|
|
64
|
+
currentPosition: layerOf(CURRENT_POSITION_LAYER_NAME),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LineDef } from '@expofp/renderer';
|
|
2
|
+
export interface AnimationHandle {
|
|
3
|
+
stop: () => void;
|
|
4
|
+
getProgress: () => number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Runs the chase animation over route segments that are already in the scene, **moving them in
|
|
8
|
+
* place**: the segments behind the head are drawn whole, the one under it is drawn part-way, and the
|
|
9
|
+
* ones ahead are hidden.
|
|
10
|
+
*
|
|
11
|
+
* The membership never changes, which is the point. Rebuilding the layer's children every frame —
|
|
12
|
+
* with a fresh def for the partial segment — remounted an instance and churned a batch slot sixty
|
|
13
|
+
* times a second, and the overlay lost everything but the newest chunk. `LineDef.points` is re-read
|
|
14
|
+
* on every update precisely so an animation can move a line instead of replacing it.
|
|
15
|
+
*
|
|
16
|
+
* Only what actually changed is reported: normally the single segment under the head, and every
|
|
17
|
+
* segment once per lap, when the chase wraps.
|
|
18
|
+
* @param segments - The defs to animate, in route order. Their `points` are moved in place.
|
|
19
|
+
* @param onChange - Called with the defs that changed, for the caller to commit.
|
|
20
|
+
* @param getPixelSize - Plan units per CSS pixel, which the speed is modulated by.
|
|
21
|
+
* @param startProgress - Where in the lap to resume, in `[0, 1)`.
|
|
22
|
+
* @returns A handle, or nothing when there is no route to animate.
|
|
23
|
+
*/
|
|
24
|
+
export declare function animateLineSegments(segments: LineDef[], onChange: (changed: readonly LineDef[]) => void, getPixelSize: () => number, startProgress?: number): AnimationHandle | undefined;
|
|
25
|
+
//# sourceMappingURL=lineAnimation.d.ts.map
|