@mappedin/blue-dot 6.0.1-beta.54
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/LICENSE.txt +104 -0
- package/README.md +117 -0
- package/lib/esm/index.d.ts +706 -0
- package/lib/esm/index.js +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
// Generated by dts-bundle v0.7.3
|
|
2
|
+
// Dependencies for this module:
|
|
3
|
+
// ../blue-dot/@packages/internal/common
|
|
4
|
+
// ../blue-dot/@mappedin/mappedin-js
|
|
5
|
+
// ../blue-dot/three
|
|
6
|
+
// ../blue-dot/zod
|
|
7
|
+
// ../blue-dot/type-fest
|
|
8
|
+
|
|
9
|
+
declare module '@mappedin/blue-dot' {
|
|
10
|
+
export { BlueDot } from '@mappedin/blue-dot/blue-dot/src/blue-dot';
|
|
11
|
+
export type { BlueDotEvents, BlueDotEventPayloads, BlueDotPositionUpdate, BlueDotState, BlueDotAction, FollowMode, FollowCameraOptions, BlueDotOptions, } from '@mappedin/blue-dot/blue-dot/src/types';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '@mappedin/blue-dot/blue-dot/src/blue-dot' {
|
|
15
|
+
import { PubSub } from '@packages/internal/common';
|
|
16
|
+
import type { MapView } from '@mappedin/mappedin-js';
|
|
17
|
+
import type { BlueDotEventPayloads, BlueDotOptions, BlueDotPositionUpdate, BlueDotState, FollowCameraOptions, FollowMode } from '@mappedin/blue-dot/blue-dot/src/types';
|
|
18
|
+
/**
|
|
19
|
+
* Show a Blue Dot indicating the device's position on the map.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { show3dMap } from '@mappedin/mappedin-js';
|
|
24
|
+
* import { BlueDot } from '@mappedin/blue-dot';
|
|
25
|
+
*
|
|
26
|
+
* const mapView = await show3dMap(...);
|
|
27
|
+
*
|
|
28
|
+
* // Enable BlueDot
|
|
29
|
+
* new BlueDot(mapView).enable();
|
|
30
|
+
*
|
|
31
|
+
* // Option 1: Listen for position updates from the device
|
|
32
|
+
* mapView.BlueDot.on('position-update', (position) => {
|
|
33
|
+
* console.log('User position:', position);
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Option 2: Update position manually
|
|
37
|
+
* new BlueDot(mapView).update({ latitude, longitude, accuracy, floorOrFloorId });
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class BlueDot {
|
|
42
|
+
#private;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new {@link BlueDot} instance.
|
|
45
|
+
*/
|
|
46
|
+
constructor(mapView: MapView);
|
|
47
|
+
/**
|
|
48
|
+
* The current state of the BlueDot. Can be 'hidden', 'active', 'inactive', or 'disabled'.
|
|
49
|
+
* Listen for state changes using the 'state-change' event.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* mapView.BlueDot.on('state-change', ({ state }) => {
|
|
53
|
+
* if (state === 'active') {
|
|
54
|
+
* // BlueDot is visible and tracking
|
|
55
|
+
* }
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
58
|
+
get state(): BlueDotState;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the BlueDot is currently following the user (camera follow mode).
|
|
61
|
+
*/
|
|
62
|
+
get following(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The direction the user is facing in degrees from north clockwise.
|
|
65
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading
|
|
66
|
+
*/
|
|
67
|
+
get heading(): number | null | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* The accuracy of the current position in metres.
|
|
70
|
+
*/
|
|
71
|
+
get accuracy(): number | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* The coordinate of the current position.
|
|
74
|
+
*/
|
|
75
|
+
get coordinate(): import("@mappedin/mappedin-js").Coordinate | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* The floor the Blue Dot is currently on. If undefined, the Blue Dot will appear on every floor.
|
|
78
|
+
*/
|
|
79
|
+
get floor(): import("@mappedin/mappedin-js").Floor | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Enable the Blue Dot. It will be hidden until a position is received either from the browser or by calling {@link BlueDot.update}.
|
|
82
|
+
* @param options - The options to setup the Blue Dot (see {@link BlueDotOptions}).
|
|
83
|
+
*
|
|
84
|
+
* @example Enable with default options
|
|
85
|
+
* mapView.BlueDot.enable();
|
|
86
|
+
*
|
|
87
|
+
* @example Enable with custom color and accuracy ring
|
|
88
|
+
* mapView.BlueDot.enable({ color: '#00ff00', accuracyRing: { color: '#00ff00', opacity: 0.2 } });
|
|
89
|
+
*
|
|
90
|
+
* @see See the [BlueDot Guide](https://developer.mappedin.com/web-sdk/blue-dot) for more information.
|
|
91
|
+
*/
|
|
92
|
+
enable: (options?: BlueDotOptions) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Disable the Blue Dot. It will be hidden and no longer update.
|
|
95
|
+
*/
|
|
96
|
+
disable: () => void;
|
|
97
|
+
on: PubSub<BlueDotEventPayloads>['on'];
|
|
98
|
+
off: PubSub<BlueDotEventPayloads>['off'];
|
|
99
|
+
/**
|
|
100
|
+
* Enable or disable the devices's geolocation listener to automatically position the Blue Dot.
|
|
101
|
+
* If enabled, the device will request permission to access the user's precise location.
|
|
102
|
+
* @param watch - Whether to enable or disable the listener.
|
|
103
|
+
*/
|
|
104
|
+
watchDevicePosition: (watch?: boolean) => void;
|
|
105
|
+
/**
|
|
106
|
+
* Manually override some position properties of the Blue Dot.
|
|
107
|
+
* Accepts a full GeolocationPosition object or a partial {@link BlueDotPositionUpdate} object.
|
|
108
|
+
* @example Manually set the accuracy and heading
|
|
109
|
+
* ```ts
|
|
110
|
+
* api.BlueDot.update({ accuracy: 10, heading: 90 });
|
|
111
|
+
* ```
|
|
112
|
+
* @example Reset accuracy and heading to device values
|
|
113
|
+
* ```ts
|
|
114
|
+
* api.BlueDot.update({ accuracy: 'device', heading: 'device' });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
update: (position: BlueDotPositionUpdate) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Set the camera to follow the BlueDot in various modes. User interaction will cancel following automatically.
|
|
120
|
+
* @param mode The follow mode ('position-only', 'position-and-heading', 'position-and-path-direction', or false to disable).
|
|
121
|
+
* @param cameraOptions Optional camera options (zoom, pitch, etc.).
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* mapView.BlueDot.follow('position-and-heading', { zoomLevel: 21, pitch: 45 });
|
|
125
|
+
*/
|
|
126
|
+
follow: (mode: FollowMode, cameraOptions?: FollowCameraOptions) => void;
|
|
127
|
+
destroy: () => void;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare module '@mappedin/blue-dot/blue-dot/src/types' {
|
|
132
|
+
import type { Coordinate, Floor } from '@mappedin/mappedin-js';
|
|
133
|
+
import type { EasingCurve } from '@mappedin/blue-dot/packages/common';
|
|
134
|
+
export type FollowMode =
|
|
135
|
+
/** Camera position follows the Blue Dot's position. */
|
|
136
|
+
'position-only'
|
|
137
|
+
/** Camera position follows the Blue Dot's position. Camera bearing matches the Blue Dot's heading. */
|
|
138
|
+
| 'position-and-heading'
|
|
139
|
+
/** Camera position follows the Blue Dot's position. Camera bearing is calculated based on the Navigation path. */
|
|
140
|
+
| 'position-and-path-direction'
|
|
141
|
+
/** Disables follow mode */
|
|
142
|
+
| false;
|
|
143
|
+
export type FollowCameraOptions = {
|
|
144
|
+
/**
|
|
145
|
+
* @default 21
|
|
146
|
+
*/
|
|
147
|
+
zoomLevel?: number;
|
|
148
|
+
/**
|
|
149
|
+
* @default 45
|
|
150
|
+
*/
|
|
151
|
+
pitch?: number;
|
|
152
|
+
/**
|
|
153
|
+
* Camera bearing in degrees clockwise from North. 0 is North, 90 is East, 180 is South, 270 is West.
|
|
154
|
+
* This option is only available in 'position-only' mode. In all other modes, the bearing will be calculated automatically.
|
|
155
|
+
* @default undefined
|
|
156
|
+
*/
|
|
157
|
+
bearing?: number;
|
|
158
|
+
/**
|
|
159
|
+
* @default undefined
|
|
160
|
+
*/
|
|
161
|
+
elevation?: number;
|
|
162
|
+
/**
|
|
163
|
+
* @default 1000
|
|
164
|
+
*/
|
|
165
|
+
duration?: number;
|
|
166
|
+
/**
|
|
167
|
+
* @default 'ease-in-out'
|
|
168
|
+
*/
|
|
169
|
+
easing?: EasingCurve;
|
|
170
|
+
};
|
|
171
|
+
export type BlueDotEventPayloads = {
|
|
172
|
+
/**
|
|
173
|
+
* Emitted when the Blue Dot's position is updated.
|
|
174
|
+
*/
|
|
175
|
+
'position-update': {
|
|
176
|
+
floor: Floor | undefined;
|
|
177
|
+
heading: GeolocationPosition['coords']['heading'] | undefined;
|
|
178
|
+
accuracy: GeolocationPosition['coords']['accuracy'] | undefined;
|
|
179
|
+
coordinate: Coordinate;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Emitted when the Blue Dot's state changes.
|
|
183
|
+
*/
|
|
184
|
+
'state-change': {
|
|
185
|
+
/**
|
|
186
|
+
* The new state of the Blue Dot.
|
|
187
|
+
*/
|
|
188
|
+
state: BlueDotState;
|
|
189
|
+
/**
|
|
190
|
+
* The action that caused the state change.
|
|
191
|
+
*/
|
|
192
|
+
action: BlueDotAction;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Emitted when the Blue Dot encounters an error.
|
|
196
|
+
*/
|
|
197
|
+
error: GeolocationPositionError;
|
|
198
|
+
/**
|
|
199
|
+
* Emitted when the Blue Dot's following state changes.
|
|
200
|
+
*/
|
|
201
|
+
'follow-change': {
|
|
202
|
+
/**
|
|
203
|
+
* Whether the Blue Dot is following the user.
|
|
204
|
+
*/
|
|
205
|
+
following: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* The mode the Blue Dot is following the user in.
|
|
208
|
+
*/
|
|
209
|
+
mode?: FollowMode;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Emitted when the user clicks on the Blue Dot.
|
|
213
|
+
*/
|
|
214
|
+
click: {
|
|
215
|
+
coordinate: Coordinate;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Emitted when the user hovers over the Blue Dot.
|
|
219
|
+
*/
|
|
220
|
+
hover: undefined;
|
|
221
|
+
};
|
|
222
|
+
export type BlueDotEvents = keyof BlueDotEventPayloads;
|
|
223
|
+
export type BlueDotState = 'hidden' | 'active' | 'inactive' | 'disabled';
|
|
224
|
+
export type BlueDotAction = 'timeout' | 'error' | 'position-update' | 'enable' | 'disable';
|
|
225
|
+
export type BlueDotOptions = {
|
|
226
|
+
/**
|
|
227
|
+
* The radius of the BlueDot in pixels. The BlueDot will maintain this size clamped to a minimum of 0.35 metres.
|
|
228
|
+
* @default 10
|
|
229
|
+
*/
|
|
230
|
+
radius?: number;
|
|
231
|
+
/**
|
|
232
|
+
* The color of the BlueDot core element.
|
|
233
|
+
* @default #2266ff
|
|
234
|
+
*/
|
|
235
|
+
color?: string;
|
|
236
|
+
/**
|
|
237
|
+
* The color of the BlueDot when it has timed out and gone inactive.
|
|
238
|
+
* @default #808080
|
|
239
|
+
*/
|
|
240
|
+
inactiveColor?: string;
|
|
241
|
+
/**
|
|
242
|
+
* Options for the accuracy ring around the BlueDot.
|
|
243
|
+
*/
|
|
244
|
+
accuracyRing?: {
|
|
245
|
+
/**
|
|
246
|
+
* The color of the accuracy ring.
|
|
247
|
+
* @default #2266ff
|
|
248
|
+
*/
|
|
249
|
+
color?: string;
|
|
250
|
+
/**
|
|
251
|
+
* The opacity of the accuracy ring.
|
|
252
|
+
* @default 0.3
|
|
253
|
+
*/
|
|
254
|
+
opacity?: number;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Options for the heading directional indicator.
|
|
258
|
+
*/
|
|
259
|
+
heading?: {
|
|
260
|
+
/**
|
|
261
|
+
* The color of the heading cone.
|
|
262
|
+
* @default #2266ff
|
|
263
|
+
*/
|
|
264
|
+
color?: string;
|
|
265
|
+
/**
|
|
266
|
+
* The opacity of the heading cone.
|
|
267
|
+
* @default 0.7
|
|
268
|
+
*/
|
|
269
|
+
opacity?: number;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* The duration of the timeout in milliseconds.
|
|
273
|
+
* If the BlueDot does not receive a position update within this time, it will grey out until a position is received.
|
|
274
|
+
* @default 30000
|
|
275
|
+
*/
|
|
276
|
+
timeout?: number;
|
|
277
|
+
/**
|
|
278
|
+
* Whether to watch the device's position.
|
|
279
|
+
* @default true
|
|
280
|
+
*/
|
|
281
|
+
watchDevicePosition?: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Whether to log debug messages.
|
|
284
|
+
* @default false
|
|
285
|
+
*/
|
|
286
|
+
debug?: boolean;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Position update options for the {@link BlueDot.update} method.
|
|
290
|
+
*/
|
|
291
|
+
export type BlueDotPositionUpdate = {
|
|
292
|
+
/**
|
|
293
|
+
* Latitude to override.
|
|
294
|
+
* Set to `'device'` to reset to the device's latitude.
|
|
295
|
+
*/
|
|
296
|
+
latitude?: GeolocationPosition['coords']['latitude'] | 'device' | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* Longitude to override.
|
|
299
|
+
* Set to `'device'` to reset to the device's longitude.
|
|
300
|
+
*/
|
|
301
|
+
longitude?: GeolocationPosition['coords']['longitude'] | 'device' | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* Accuracy to override.
|
|
304
|
+
* Set to `'device'` to reset to the device's accuracy.
|
|
305
|
+
* Set to `undefined` to disable the accuracy ring.
|
|
306
|
+
*/
|
|
307
|
+
accuracy?: GeolocationPosition['coords']['accuracy'] | 'device' | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Heading to override.
|
|
310
|
+
* Set to `'device'` to reset to the device's heading.
|
|
311
|
+
* Set to `undefined` to disable the heading indicator.
|
|
312
|
+
*/
|
|
313
|
+
heading?: GeolocationPosition['coords']['heading'] | 'device' | undefined;
|
|
314
|
+
/**
|
|
315
|
+
* Floor or floorId to override.
|
|
316
|
+
* Set to `'device'` to reset to the device's floor level.
|
|
317
|
+
* Set to `undefined` to disable floor level and show the BlueDot on all floors.
|
|
318
|
+
*/
|
|
319
|
+
floorOrFloorId?: Floor | string | 'device' | undefined;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
declare module '@mappedin/blue-dot/packages/common' {
|
|
324
|
+
import Logger from '@mappedin/blue-dot/packages/common/Mappedin.Logger';
|
|
325
|
+
export * from '@mappedin/blue-dot/packages/common/errors';
|
|
326
|
+
export * from '@mappedin/blue-dot/packages/common/utils';
|
|
327
|
+
export * from '@mappedin/blue-dot/packages/common/async';
|
|
328
|
+
export * from '@mappedin/blue-dot/packages/common/assert';
|
|
329
|
+
export * from '@mappedin/blue-dot/packages/common/random-id';
|
|
330
|
+
export { PubSub } from '@mappedin/blue-dot/packages/common/pubsub';
|
|
331
|
+
export { SafeStorage, SESSION_ID_KEY, DEVICE_ID_KEY } from '@mappedin/blue-dot/packages/common/storage';
|
|
332
|
+
export { Logger };
|
|
333
|
+
export * from '@mappedin/blue-dot/packages/common/color';
|
|
334
|
+
export * from '@mappedin/blue-dot/packages/common/interpolate';
|
|
335
|
+
export * from '@mappedin/blue-dot/packages/common/type-utils';
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
declare module '@mappedin/blue-dot/packages/common/Mappedin.Logger' {
|
|
339
|
+
export const MI_DEBUG_KEY = "mi-debug";
|
|
340
|
+
export const MI_ERROR_LABEL = "[MappedinJS]";
|
|
341
|
+
export enum E_SDK_LOG_LEVEL {
|
|
342
|
+
LOG = 0,
|
|
343
|
+
WARN = 1,
|
|
344
|
+
ERROR = 2,
|
|
345
|
+
SILENT = 3
|
|
346
|
+
}
|
|
347
|
+
export function createLogger(name?: string, { prefix }?: {
|
|
348
|
+
prefix?: string | undefined;
|
|
349
|
+
}): {
|
|
350
|
+
logState: E_SDK_LOG_LEVEL;
|
|
351
|
+
log(...args: any[]): void;
|
|
352
|
+
warn(...args: any[]): void;
|
|
353
|
+
error(...args: any[]): void;
|
|
354
|
+
assert(...args: any[]): void;
|
|
355
|
+
time(label: string): void;
|
|
356
|
+
timeEnd(label: string): void;
|
|
357
|
+
setLevel(level: E_SDK_LOG_LEVEL): void;
|
|
358
|
+
};
|
|
359
|
+
const Logger: {
|
|
360
|
+
logState: E_SDK_LOG_LEVEL;
|
|
361
|
+
log(...args: any[]): void;
|
|
362
|
+
warn(...args: any[]): void;
|
|
363
|
+
error(...args: any[]): void;
|
|
364
|
+
assert(...args: any[]): void;
|
|
365
|
+
time(label: string): void;
|
|
366
|
+
timeEnd(label: string): void;
|
|
367
|
+
setLevel(level: E_SDK_LOG_LEVEL): void;
|
|
368
|
+
};
|
|
369
|
+
export function setLoggerLevel(level: E_SDK_LOG_LEVEL): void;
|
|
370
|
+
export default Logger;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
declare module '@mappedin/blue-dot/packages/common/errors' {
|
|
374
|
+
/**
|
|
375
|
+
* @internal
|
|
376
|
+
*/
|
|
377
|
+
export class MappedinError extends Error {
|
|
378
|
+
constructor(message: string, label?: string);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @internal
|
|
382
|
+
*/
|
|
383
|
+
export class MappedinRenderError extends MappedinError {
|
|
384
|
+
constructor(message: string, label?: string);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
declare module '@mappedin/blue-dot/packages/common/utils' {
|
|
389
|
+
import { Box2 } from 'three';
|
|
390
|
+
import type { Box3 } from 'three';
|
|
391
|
+
export function findMapWithElevationClosestToZero<T extends {
|
|
392
|
+
elevation?: number;
|
|
393
|
+
}>(maps: T[]): T | undefined;
|
|
394
|
+
/**
|
|
395
|
+
* Omit properites from object
|
|
396
|
+
*/
|
|
397
|
+
export function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keysToOmit: K[]): Omit<T, K>;
|
|
398
|
+
export function decodeAccessToken(accessToken: string): {
|
|
399
|
+
sub: string;
|
|
400
|
+
aud: string[];
|
|
401
|
+
capabilities: Record<string, any>;
|
|
402
|
+
};
|
|
403
|
+
export function toRadians(degrees: number): number;
|
|
404
|
+
export function toDegrees(radians: number): number;
|
|
405
|
+
export function round(value: number, decimals: number): number;
|
|
406
|
+
export function euclideanModulo(value: number, modulus: number): number;
|
|
407
|
+
/**
|
|
408
|
+
* Position from our SDKs may be tuple of longitude and latitude optionally followed by altitude.
|
|
409
|
+
*/
|
|
410
|
+
type Position = [number, number] | [number, number, number?] | number[];
|
|
411
|
+
/**
|
|
412
|
+
* Calculates the approximate distance between two geographic coordinates on Earth's surface.
|
|
413
|
+
*
|
|
414
|
+
* This function uses the equirectangular approximation method to compute the distance, which simplifies
|
|
415
|
+
* the math and speeds up calculations, but is less accurate over long distances compared to other methods
|
|
416
|
+
* like the haversine formula.
|
|
417
|
+
*
|
|
418
|
+
* @param point1 - The first point's longitude and latitude as [longitude, latitude].
|
|
419
|
+
* @param point1 - The second point's longitude and latitude as [longitude, latitude].
|
|
420
|
+
* @return The approximate distance between the two points in meters.
|
|
421
|
+
*/
|
|
422
|
+
export function haversineDistance([lon1, lat1]: Position, [lon2, lat2]: Position): number;
|
|
423
|
+
/**
|
|
424
|
+
* Calculates the bearing clockwise from North between two geographic coordinates on Earth's surface.
|
|
425
|
+
* 0 is North, 90 is East, 180 is South, 270 is West.
|
|
426
|
+
*
|
|
427
|
+
* @param point1 - The first point's longitude and latitude as [longitude, latitude].
|
|
428
|
+
* @param point2 - The second point's longitude and latitude as [longitude, latitude].
|
|
429
|
+
* @returns The forward bearing in degrees from point1 to point2, measured clockwise from true North.
|
|
430
|
+
*/
|
|
431
|
+
export function getForwardBearing([lon1, lat1]: Position, [lon2, lat2]: Position): number;
|
|
432
|
+
/**
|
|
433
|
+
*
|
|
434
|
+
* Normalizes the start and end rotations to the range 0 to 2 PI and ensures the shortest path for rotation.
|
|
435
|
+
*
|
|
436
|
+
* @param startRotation - The start rotation in radians
|
|
437
|
+
* @param targetRotation - The target rotation in radians
|
|
438
|
+
* @returns Start and end rotations for the tween.
|
|
439
|
+
*/
|
|
440
|
+
export function shortestTweenRotation(startRotation: number, targetRotation: number): {
|
|
441
|
+
start: number;
|
|
442
|
+
end: number;
|
|
443
|
+
};
|
|
444
|
+
export function isFiniteBox(box: Box2 | Box3): boolean;
|
|
445
|
+
export function clampWithWarning(x: number, lower: number, upper: number, warning: string): number;
|
|
446
|
+
export function arraysEqual(arr1: any[] | null | undefined, arr2: any[] | null | undefined): boolean;
|
|
447
|
+
export function isBrowser(): boolean;
|
|
448
|
+
export {};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
declare module '@mappedin/blue-dot/packages/common/async' {
|
|
452
|
+
export function debounce<T extends (...args: any[]) => void>(func: T, wait: number, immediate?: boolean): (...args: Parameters<T>) => void;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
declare module '@mappedin/blue-dot/packages/common/assert' {
|
|
456
|
+
/**
|
|
457
|
+
* Options for assertExists function
|
|
458
|
+
*/
|
|
459
|
+
export interface AssertExistsOptions {
|
|
460
|
+
/** Name of the value being checked (for better error messages) */
|
|
461
|
+
valueName?: string;
|
|
462
|
+
/** Custom error message to use instead of the default */
|
|
463
|
+
customMessage?: string;
|
|
464
|
+
/** Error class to use (defaults to AssertionError) */
|
|
465
|
+
errorClass?: new (message: string) => Error;
|
|
466
|
+
/** Whether to capture and format the stack trace (defaults to true) */
|
|
467
|
+
captureStackTrace?: boolean;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Custom error class for assertions to make stack traces more identifiable
|
|
471
|
+
*/
|
|
472
|
+
export class AssertionError extends Error {
|
|
473
|
+
name: string;
|
|
474
|
+
constructor(message: string);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Asserts that a value is not null or undefined.
|
|
478
|
+
* @param value The value to check
|
|
479
|
+
* @param options Optional configuration for the assertion
|
|
480
|
+
*/
|
|
481
|
+
export function assertExists<T>(value: T, options?: AssertExistsOptions): asserts value is NonNullable<T>;
|
|
482
|
+
/**
|
|
483
|
+
* Asserts that an object is an instance of a specific class.
|
|
484
|
+
* @param obj The object to check
|
|
485
|
+
* @param className The class constructor to check against
|
|
486
|
+
* @param errorMessage Optional custom error message
|
|
487
|
+
*/
|
|
488
|
+
export function assertInstanceOf<T>(obj: unknown, className: new (...args: any[]) => T, errorMessage?: string): asserts obj is T;
|
|
489
|
+
/**
|
|
490
|
+
* Asserts that an object has a specific 'type' property value.
|
|
491
|
+
* @param obj The object to check
|
|
492
|
+
* @param expectedType The expected value of the 'type' property
|
|
493
|
+
* @param errorMessage Optional custom error message
|
|
494
|
+
*/
|
|
495
|
+
export function assertType<T extends {
|
|
496
|
+
type: string;
|
|
497
|
+
}, P extends T['type']>(obj: T | undefined, expectedType: P, errorMessage?: string): asserts obj is Extract<T, {
|
|
498
|
+
type: P;
|
|
499
|
+
}>;
|
|
500
|
+
/**
|
|
501
|
+
* Retrieves an entity from a map and asserts it is of a specific type.
|
|
502
|
+
* @param map The map containing entities
|
|
503
|
+
* @param entityId The ID of the entity to retrieve
|
|
504
|
+
* @param expectedType The class constructor the entity should be an instance of
|
|
505
|
+
* @returns The entity cast to the expected type
|
|
506
|
+
*/
|
|
507
|
+
export function getEntityAsType<T>(map: Map<string | number, unknown>, entityId: string | number, expectedType: new (...args: any[]) => T): T;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
declare module '@mappedin/blue-dot/packages/common/random-id' {
|
|
511
|
+
/**
|
|
512
|
+
* Returns a UUIDv4-like ID without relying on a CSPRNG as we don't need it for these purposes.
|
|
513
|
+
* @hidden
|
|
514
|
+
*/
|
|
515
|
+
export const randomId: () => string;
|
|
516
|
+
export function cyrb53(str: string, seed?: number): number;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
declare module '@mappedin/blue-dot/packages/common/pubsub' {
|
|
520
|
+
/**
|
|
521
|
+
* Generic PubSub class implementing the Publish-Subscribe pattern for event handling.
|
|
522
|
+
*
|
|
523
|
+
* @template EVENT_PAYLOAD - The type of the event payload.
|
|
524
|
+
* @template EVENT - The type of the event.
|
|
525
|
+
*/
|
|
526
|
+
export class PubSub<EVENT_PAYLOAD, EVENT extends keyof EVENT_PAYLOAD = keyof EVENT_PAYLOAD> {
|
|
527
|
+
/**
|
|
528
|
+
* @private
|
|
529
|
+
* @internal
|
|
530
|
+
*/
|
|
531
|
+
_subscribers: any;
|
|
532
|
+
/**
|
|
533
|
+
* @private
|
|
534
|
+
* @internal
|
|
535
|
+
*/
|
|
536
|
+
publish<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, data?: EVENT_PAYLOAD[EVENT_NAME]): void;
|
|
537
|
+
/**
|
|
538
|
+
* Subscribe a function to an event.
|
|
539
|
+
*
|
|
540
|
+
* @param eventName An event name which, when fired, will call the provided
|
|
541
|
+
* function.
|
|
542
|
+
* @param fn A callback that gets called when the corresponding event is fired. The
|
|
543
|
+
* callback will get passed an argument with a type that's one of event payloads.
|
|
544
|
+
* @example
|
|
545
|
+
* // Subscribe to the 'click' event
|
|
546
|
+
* const handler = (event) => {
|
|
547
|
+
* const { coordinate } = event;
|
|
548
|
+
* const { latitude, longitude } = coordinate;
|
|
549
|
+
* console.log(`Map was clicked at ${latitude}, ${longitude}`);
|
|
550
|
+
* };
|
|
551
|
+
* map.on('click', handler);
|
|
552
|
+
*/
|
|
553
|
+
on<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, fn: (payload: EVENT_PAYLOAD[EVENT_NAME] extends {
|
|
554
|
+
data: null;
|
|
555
|
+
} ? EVENT_PAYLOAD[EVENT_NAME]['data'] : EVENT_PAYLOAD[EVENT_NAME]) => void): void;
|
|
556
|
+
/**
|
|
557
|
+
* Unsubscribe a function previously subscribed with {@link on}
|
|
558
|
+
*
|
|
559
|
+
* @param eventName An event name to which the provided function was previously
|
|
560
|
+
* subscribed.
|
|
561
|
+
* @param fn A function that was previously passed to {@link on}. The function must
|
|
562
|
+
* have the same reference as the function that was subscribed.
|
|
563
|
+
* @example
|
|
564
|
+
* // Unsubscribe from the 'click' event
|
|
565
|
+
* const handler = (event) => {
|
|
566
|
+
* console.log('Map was clicked', event);
|
|
567
|
+
* };
|
|
568
|
+
* map.off('click', handler);
|
|
569
|
+
*/
|
|
570
|
+
off<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, fn: (payload: EVENT_PAYLOAD[EVENT_NAME] extends {
|
|
571
|
+
data: null;
|
|
572
|
+
} ? EVENT_PAYLOAD[EVENT_NAME]['data'] : EVENT_PAYLOAD[EVENT_NAME]) => void): void;
|
|
573
|
+
/**
|
|
574
|
+
* @private
|
|
575
|
+
* @internal
|
|
576
|
+
*/
|
|
577
|
+
destroy(): void;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
declare module '@mappedin/blue-dot/packages/common/storage' {
|
|
582
|
+
export const SESSION_DATA_KEY: "mi-session-data";
|
|
583
|
+
export const LOCAL_DATA_KEY: "mi-local-data";
|
|
584
|
+
export const SESSION_ID_KEY: "id";
|
|
585
|
+
export const DEVICE_ID_KEY: "deviceId";
|
|
586
|
+
export type SessionData = {
|
|
587
|
+
[SESSION_ID_KEY]: string;
|
|
588
|
+
[prop: string]: unknown;
|
|
589
|
+
};
|
|
590
|
+
export type LocalData = {
|
|
591
|
+
[DEVICE_ID_KEY]: string;
|
|
592
|
+
[prop: string]: unknown;
|
|
593
|
+
};
|
|
594
|
+
export class SafeStorage {
|
|
595
|
+
#private;
|
|
596
|
+
static getInstance(): SafeStorage;
|
|
597
|
+
static ___clearInstance(): void;
|
|
598
|
+
saveSessionData<T extends keyof SessionData>(key: T, data: SessionData[T]): boolean;
|
|
599
|
+
loadSessionData<T extends keyof SessionData>(key: T): SessionData[T] extends undefined ? SessionData[T] | undefined : SessionData[T];
|
|
600
|
+
saveLocalData<T extends keyof LocalData>(key: T, data: LocalData[T]): boolean;
|
|
601
|
+
loadLocalData<T extends keyof LocalData>(key: T): LocalData[T] extends undefined ? LocalData[T] | undefined : LocalData[T];
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
declare module '@mappedin/blue-dot/packages/common/color' {
|
|
606
|
+
export const X11_COLOR_NAMES_SET: Set<string>;
|
|
607
|
+
/**
|
|
608
|
+
* Check if a string is a valid X11 color name, as defined in ThreeJS Color.NAMES
|
|
609
|
+
* @param color - The color string to check.
|
|
610
|
+
* @returns True if the color is a valid X11 color name, false otherwise.
|
|
611
|
+
*/
|
|
612
|
+
export const isX11Color: (color: string) => boolean;
|
|
613
|
+
/**
|
|
614
|
+
* Check if a string is a valid hex color.
|
|
615
|
+
* @param color - The color string to check.
|
|
616
|
+
* @returns True if the color is a valid hex color, false otherwise.
|
|
617
|
+
*/
|
|
618
|
+
export const isHexColor: (color: string) => boolean;
|
|
619
|
+
/**
|
|
620
|
+
* Check if a string is a valid RGB/RGBA color.
|
|
621
|
+
* @param color - The color string to check.
|
|
622
|
+
* @returns True if the color is a valid RGB/RGBA color, false otherwise.
|
|
623
|
+
*/
|
|
624
|
+
export const isRgbColor: (color: string) => boolean;
|
|
625
|
+
/**
|
|
626
|
+
* Check if a string is a valid HSL/HSLA color.
|
|
627
|
+
* @param color - The color string to check.
|
|
628
|
+
* @returns True if the color is a valid HSL/HSLA color, false otherwise.
|
|
629
|
+
*/
|
|
630
|
+
export const isHslColor: (color: string) => boolean;
|
|
631
|
+
/**
|
|
632
|
+
* Check if a string is a valid ThreeJS color. Can be hex, rgb, rgba, hsl, hsla, or X11 color name.
|
|
633
|
+
* @param color - The color string to check.
|
|
634
|
+
* @returns True if the color is a valid ThreeJS color, false otherwise.
|
|
635
|
+
*/
|
|
636
|
+
export const isColor: (color: string) => boolean;
|
|
637
|
+
/**
|
|
638
|
+
* Convert a color string to an array of RGB values.
|
|
639
|
+
* @param color - The color string to convert.
|
|
640
|
+
* @returns The array of RGB values.
|
|
641
|
+
*/
|
|
642
|
+
export const stringToRgbArray: (color: string) => [number, number, number];
|
|
643
|
+
/**
|
|
644
|
+
* Convert an array of RGB values to a hex string.
|
|
645
|
+
* @param rgb - The array of RGB values to convert.
|
|
646
|
+
* @returns The hex string representation of the RGB values.
|
|
647
|
+
*/
|
|
648
|
+
export const rgbArrayToString: (rgb: [number, number, number]) => string;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
declare module '@mappedin/blue-dot/packages/common/interpolate' {
|
|
652
|
+
import { z } from 'zod';
|
|
653
|
+
export const easingCurveSchema: z.ZodEnum<["ease-in", "ease-out", "ease-in-out", "linear"]>;
|
|
654
|
+
export type EasingCurve = z.infer<typeof easingCurveSchema>;
|
|
655
|
+
export const linearEase: (t: number) => number;
|
|
656
|
+
export const quadEaseIn: (t: number) => number;
|
|
657
|
+
export const easeIn: (x: number) => number;
|
|
658
|
+
export const quadEaseOut: (t: number) => number;
|
|
659
|
+
export function interpolate(value: number, inputMin: number, inputMax: number, outputMin: number, outputMax: number, easeFunc?: EasingCurve | ((t: number) => number)): number;
|
|
660
|
+
/**
|
|
661
|
+
* Return the closest range within an ordered set of values that a given value falls within. If the given value is
|
|
662
|
+
* exactly within a range, returns the index of the range. If the given value is less than the first value in the range,
|
|
663
|
+
* returns 0. If the given value is greater than the last value in the range, returns the last range (lastIndex - 1).
|
|
664
|
+
*/
|
|
665
|
+
export function getInterpolationBreakpoint(value: number, range: number[]): number;
|
|
666
|
+
export function interpolateMulti(value: number, inputRange: number[], outputRange: number[], easeFunc?: EasingCurve | ((t: number) => number)): number;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
declare module '@mappedin/blue-dot/packages/common/type-utils' {
|
|
670
|
+
import type { SetOptional } from 'type-fest';
|
|
671
|
+
type Primitive = string | number | boolean | null | undefined;
|
|
672
|
+
export type PartialExcept<T, K extends string> = {
|
|
673
|
+
[P in keyof T as P extends K ? P : never]: T[P];
|
|
674
|
+
} & {
|
|
675
|
+
[P in keyof T as P extends K ? never : P]?: T[P] extends Primitive ? T[P] : T[P] extends (infer U)[] ? PartialExcept<U, K>[] : PartialExcept<T[P], K>;
|
|
676
|
+
};
|
|
677
|
+
/**
|
|
678
|
+
* Utility type that extracts nested values matching a specific type with recursion depth limit
|
|
679
|
+
* @example
|
|
680
|
+
* type A = ExtractDeep<{ a: { b: string; c: number; }; d: string; e: number; }, number>;
|
|
681
|
+
* // { a: { c: number; } e: number; }
|
|
682
|
+
*/
|
|
683
|
+
export type ExtractDeep<T, U, Depth extends readonly number[] = []> = Depth['length'] extends 3 ? any : {
|
|
684
|
+
[K in keyof T as T[K] extends U ? K : T[K] extends object | undefined ? ExtractDeep<NonNullable<T[K]>, U, [...Depth, 0]> extends never ? never : K : never]: T[K] extends object | undefined ? undefined extends T[K] ? ExtractDeep<NonNullable<T[K]>, U, [...Depth, 0]> | undefined : ExtractDeep<NonNullable<T[K]>, U, [...Depth, 0]> : T[K] extends U ? T[K] : never;
|
|
685
|
+
};
|
|
686
|
+
/**
|
|
687
|
+
* Utility type that makes all properties of a type required, but allows undefined values
|
|
688
|
+
* to satisfy the required type.
|
|
689
|
+
* https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585
|
|
690
|
+
* @example
|
|
691
|
+
* type A = Complete<{ a: string; b: number; c: undefined; }>;
|
|
692
|
+
* // { a: string; b: number; c: undefined; }
|
|
693
|
+
*/
|
|
694
|
+
export type Complete<T> = {
|
|
695
|
+
[P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? T[P] : T[P] | undefined;
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* Utility type that makes all properties required except for the ones specified in the second argument.
|
|
699
|
+
* @example
|
|
700
|
+
* type A = RequiredExcept<{ a: string; b: number; c: undefined; }, 'c'>;
|
|
701
|
+
* // { a: string; b: number; c?: undefined; }
|
|
702
|
+
*/
|
|
703
|
+
export type RequiredExcept<T, K extends keyof T> = SetOptional<Required<T>, K>;
|
|
704
|
+
export {};
|
|
705
|
+
}
|
|
706
|
+
|