@mappedin/blue-dot 6.0.1-beta.61 → 6.5.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/chunk-O7W66ETT.js +1 -0
- package/lib/esm/index.d.ts +1222 -833
- package/lib/esm/index.js +1 -11
- package/lib/esm/react/index.d.ts +1226 -841
- package/lib/esm/react/index.js +1 -75
- package/lib/rn/blue-dot.d.ts +47 -9
- package/lib/rn/constants.d.ts +1 -0
- package/lib/rn/index-rn.js +5 -316
- package/lib/rn/types.d.ts +13 -1
- package/lib/rn/utils.d.ts +9 -0
- package/package.json +5 -5
- package/lib/blue-dot.iife.js.map +0 -7
- package/lib/esm/chunk-R4BVXYKM.js +0 -1574
- package/lib/esm/chunk-R4BVXYKM.js.map +0 -7
- package/lib/esm/index.js.map +0 -7
- package/lib/esm/react/index.js.map +0 -7
- package/lib/rn/index-rn.js.map +0 -7
package/lib/esm/react/index.d.ts
CHANGED
|
@@ -1,877 +1,1262 @@
|
|
|
1
|
-
|
|
2
|
-
// Dependencies for this module:
|
|
3
|
-
// ../blue-dot/@mappedin/mappedin-js
|
|
4
|
-
// ../blue-dot/@packages/internal/common/extensions
|
|
5
|
-
// ../blue-dot/@packages/internal/common/pubsub
|
|
6
|
-
// ../blue-dot/type-fest
|
|
7
|
-
// ../blue-dot/zod
|
|
8
|
-
// ../blue-dot/three
|
|
9
|
-
|
|
10
|
-
declare module '@mappedin/blue-dot/react' {
|
|
11
|
-
export { useBlueDot } from '@mappedin/blue-dot/react/blue-dot/src/react/use-blue-dot';
|
|
12
|
-
export { useBlueDotEvent } from '@mappedin/blue-dot/react/blue-dot/src/react/use-blue-dot-event';
|
|
13
|
-
}
|
|
1
|
+
import { Coordinate, Floor, MapView, Model } from "@mappedin/mappedin-js";
|
|
14
2
|
|
|
15
|
-
|
|
16
|
-
import { BlueDot } from '@mappedin/blue-dot/react/blue-dot/src/blue-dot';
|
|
17
|
-
export function useBlueDot(): BlueDot;
|
|
18
|
-
}
|
|
3
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/primitive.d.ts
|
|
19
4
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export function useBlueDotEvent<T extends BlueDotEvents>(eventName: T, callback: (payload: BlueDotEventPayloads[T]) => void): void;
|
|
23
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
24
7
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { show3dMap } from '@mappedin/mappedin-js';
|
|
38
|
-
* import { BlueDot } from '@mappedin/blue-dot';
|
|
39
|
-
*
|
|
40
|
-
* const mapView = await show3dMap(...);
|
|
41
|
-
*
|
|
42
|
-
* // Enable BlueDot
|
|
43
|
-
* new BlueDot(mapView).enable();
|
|
44
|
-
*
|
|
45
|
-
* // Option 1: Listen for position updates from the device
|
|
46
|
-
* mapView.BlueDot.on('position-update', (position) => {
|
|
47
|
-
* console.log('User position:', position);
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* // Option 2: Update position manually
|
|
51
|
-
* new BlueDot(mapView).update({ latitude, longitude, accuracy, floorOrFloorId });
|
|
52
|
-
*
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export class BlueDot implements MapViewExtension<BlueDotState> {
|
|
56
|
-
#private;
|
|
57
|
-
/**
|
|
58
|
-
* Create a new {@link BlueDot} instance.
|
|
59
|
-
*/
|
|
60
|
-
constructor(mapView: MapView);
|
|
61
|
-
/**
|
|
62
|
-
* Get the Model for the BlueDot core element.
|
|
63
|
-
*/
|
|
64
|
-
get dotModel(): Model | undefined;
|
|
65
|
-
/**
|
|
66
|
-
* Get the Model for the accuracy ring.
|
|
67
|
-
*/
|
|
68
|
-
get accuracyRingModel(): Model | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* Get the Model for the heading cone.
|
|
71
|
-
*/
|
|
72
|
-
get headingConeModel(): Model | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Whether the BlueDot is currently enabled.
|
|
75
|
-
*/
|
|
76
|
-
get isEnabled(): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* The current state of the BlueDot. Can be 'hidden', 'active', 'inactive', or 'disabled'.
|
|
79
|
-
* Listen for state changes using the 'status-change' event.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* mapView.BlueDot.on('status-change', ({ status }) => {
|
|
83
|
-
* if (status === 'active') {
|
|
84
|
-
* // BlueDot is visible and tracking
|
|
85
|
-
* }
|
|
86
|
-
* });
|
|
87
|
-
*/
|
|
88
|
-
get status(): BlueDotStatus;
|
|
89
|
-
/**
|
|
90
|
-
* Whether the BlueDot is currently following the user (camera follow mode).
|
|
91
|
-
*/
|
|
92
|
-
get isFollowing(): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* The direction the user is facing in degrees from north clockwise.
|
|
95
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading
|
|
96
|
-
*/
|
|
97
|
-
get heading(): GeolocationPosition['coords']['heading'] | undefined;
|
|
98
|
-
/**
|
|
99
|
-
* The accuracy of the current position in metres.
|
|
100
|
-
*/
|
|
101
|
-
get accuracy(): GeolocationPosition['coords']['accuracy'] | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* The coordinate of the current position.
|
|
104
|
-
*/
|
|
105
|
-
get coordinate(): Coordinate | undefined;
|
|
106
|
-
getState: () => ReadonlyDeep<BlueDotState>;
|
|
107
|
-
/**
|
|
108
|
-
* The floor the Blue Dot is currently on. If undefined, the Blue Dot will appear on every floor.
|
|
109
|
-
*/
|
|
110
|
-
get floor(): Floor | undefined;
|
|
111
|
-
/**
|
|
112
|
-
* Enable the Blue Dot. It will be hidden until a position is received either from the browser or by calling {@link BlueDot.update}.
|
|
113
|
-
* @param options - The options to setup the Blue Dot (see {@link BlueDotOptions}).
|
|
114
|
-
*
|
|
115
|
-
* @example Enable with default options
|
|
116
|
-
* mapView.BlueDot.enable();
|
|
117
|
-
*
|
|
118
|
-
* @example Enable with custom color and accuracy ring
|
|
119
|
-
* mapView.BlueDot.enable({ color: '#00ff00', accuracyRing: { color: '#00ff00', opacity: 0.2 } });
|
|
120
|
-
*
|
|
121
|
-
* @see See the [BlueDot Guide](https://developer.mappedin.com/web-sdk/blue-dot) for more information.
|
|
122
|
-
*/
|
|
123
|
-
enable: (options?: BlueDotUpdateState) => void;
|
|
124
|
-
/**
|
|
125
|
-
* Disable the Blue Dot. It will be hidden and no longer update.
|
|
126
|
-
*/
|
|
127
|
-
disable: () => void;
|
|
128
|
-
/**
|
|
129
|
-
* Subscribe to a BlueDot event.
|
|
130
|
-
* @param eventName The name of the event to listen for.
|
|
131
|
-
* @param fn The function to call when the event is emitted.
|
|
132
|
-
*/
|
|
133
|
-
on: PubSub<BlueDotEventPayloads>['on'];
|
|
134
|
-
/**
|
|
135
|
-
* Unsubscribe from a BlueDot event.
|
|
136
|
-
* @param eventName The name of the event to unsubscribe from.
|
|
137
|
-
* @param fn The function to unsubscribe from the event.
|
|
138
|
-
*/
|
|
139
|
-
off: PubSub<BlueDotEventPayloads>['off'];
|
|
140
|
-
/**
|
|
141
|
-
* Update the BlueDot state after it has been enabled.
|
|
142
|
-
* This allows overriding previously set values like colors, and other options.
|
|
143
|
-
* @param options - The options to update
|
|
144
|
-
*
|
|
145
|
-
* @example Update color and accuracy ring
|
|
146
|
-
* mapView.BlueDot.updateState({
|
|
147
|
-
* color: '#ff0000',
|
|
148
|
-
* accuracyRing: { color: '#ff0000', opacity: 0.5 }
|
|
149
|
-
* });
|
|
150
|
-
*/
|
|
151
|
-
updateState: (options: BlueDotUpdateState) => void;
|
|
152
|
-
/**
|
|
153
|
-
* Enable or disable the devices's geolocation listener to automatically position the Blue Dot.
|
|
154
|
-
* If enabled, the device will request permission to access the user's precise location.
|
|
155
|
-
* @param watch - Whether to enable or disable the listener.
|
|
156
|
-
*/
|
|
157
|
-
watchDevicePosition: (watch: boolean) => void;
|
|
158
|
-
/**
|
|
159
|
-
* Manually override some position properties of the Blue Dot.
|
|
160
|
-
* Accepts a full GeolocationPosition object or a partial {@link BlueDotPositionUpdate} object.
|
|
161
|
-
* @example Manually set the accuracy and heading
|
|
162
|
-
* ```ts
|
|
163
|
-
* api.BlueDot.update({ accuracy: 10, heading: 90 });
|
|
164
|
-
* ```
|
|
165
|
-
* @example Reset accuracy and heading to device values
|
|
166
|
-
* ```ts
|
|
167
|
-
* api.BlueDot.update({ accuracy: 'device', heading: 'device' });
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
update: (position: GeolocationPositionExtended | BlueDotPositionUpdate | undefined, options?: BlueDotUpdateOptions) => void;
|
|
171
|
-
/**
|
|
172
|
-
* Set the camera to follow the BlueDot in various modes. User interaction will cancel following automatically.
|
|
173
|
-
* @param mode The follow mode ('position-only', 'position-and-heading', 'position-and-path-direction', or false to disable).
|
|
174
|
-
* @param cameraOptions Optional camera options (zoom, pitch, etc.).
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* mapView.BlueDot.follow('position-and-heading', { zoomLevel: 21, pitch: 45 });
|
|
178
|
-
*/
|
|
179
|
-
follow: (mode: FollowMode, cameraOptions?: FollowCameraOptions) => void;
|
|
180
|
-
/**
|
|
181
|
-
* Set a position processor callback that allows intercepting and modifying device/geolocation position updates before they are applied.
|
|
182
|
-
*
|
|
183
|
-
* **Note**: This processor only applies to automatic position updates from device geolocation.
|
|
184
|
-
* Manual position updates via `update()` method bypass the processor and are applied directly.
|
|
185
|
-
*
|
|
186
|
-
* @param processor - A callback function that receives current state and incoming update. Return undefined to discard the update, or return a modified update object.
|
|
187
|
-
*
|
|
188
|
-
* @example Discard inaccurate positions
|
|
189
|
-
* ```ts
|
|
190
|
-
* blueDot.setPositionProcessor((current, incoming) => {
|
|
191
|
-
* if (incoming.accuracy && incoming.accuracy > 50) {
|
|
192
|
-
* return undefined; // Discard update
|
|
193
|
-
* }
|
|
194
|
-
* return incoming; // Accept update
|
|
195
|
-
* });
|
|
196
|
-
* ```
|
|
197
|
-
*
|
|
198
|
-
* @example Modify incoming positions
|
|
199
|
-
* ```ts
|
|
200
|
-
* blueDot.setPositionProcessor((current, incoming) => {
|
|
201
|
-
* // Apply custom smoothing or validation logic
|
|
202
|
-
* return {
|
|
203
|
-
* ...incoming,
|
|
204
|
-
* accuracy: Math.min(incoming.accuracy || 100, 10) // Cap accuracy
|
|
205
|
-
* };
|
|
206
|
-
* });
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
setPositionProcessor(processor?: BlueDotPositionProcessor): void;
|
|
210
|
-
destroy: () => void;
|
|
211
|
-
}
|
|
8
|
+
@category Type
|
|
9
|
+
*/
|
|
10
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/observable-like.d.ts
|
|
13
|
+
declare global {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
15
|
+
interface SymbolConstructor {
|
|
16
|
+
readonly observable: symbol;
|
|
17
|
+
}
|
|
212
18
|
}
|
|
213
19
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
* @default 45
|
|
236
|
-
*/
|
|
237
|
-
pitch?: number;
|
|
238
|
-
/**
|
|
239
|
-
* Camera bearing in degrees clockwise from North. 0 is North, 90 is East, 180 is South, 270 is West.
|
|
240
|
-
* This option is only available in 'position-only' mode. In all other modes, the bearing will be calculated automatically.
|
|
241
|
-
* @default undefined
|
|
242
|
-
*/
|
|
243
|
-
bearing?: number;
|
|
244
|
-
/**
|
|
245
|
-
* @default undefined
|
|
246
|
-
*/
|
|
247
|
-
elevation?: number;
|
|
248
|
-
/**
|
|
249
|
-
* @default 1000
|
|
250
|
-
*/
|
|
251
|
-
duration?: number;
|
|
252
|
-
/**
|
|
253
|
-
* @default 'ease-in-out'
|
|
254
|
-
*/
|
|
255
|
-
easing?: EasingCurve;
|
|
256
|
-
};
|
|
257
|
-
export type BlueDotEventPayloads = {
|
|
258
|
-
/**
|
|
259
|
-
* Emitted when the Blue Dot's position is updated.
|
|
260
|
-
*/
|
|
261
|
-
'position-update': {
|
|
262
|
-
floor: Floor | undefined;
|
|
263
|
-
heading: GeolocationPosition['coords']['heading'] | undefined;
|
|
264
|
-
accuracy: GeolocationPosition['coords']['accuracy'] | undefined;
|
|
265
|
-
coordinate: Coordinate;
|
|
266
|
-
};
|
|
267
|
-
/**
|
|
268
|
-
* Emitted when the Blue Dot's status changes.
|
|
269
|
-
*/
|
|
270
|
-
'status-change': {
|
|
271
|
-
/**
|
|
272
|
-
* The new status of the Blue Dot.
|
|
273
|
-
*/
|
|
274
|
-
status: BlueDotStatus;
|
|
275
|
-
/**
|
|
276
|
-
* The action that caused the status change.
|
|
277
|
-
*/
|
|
278
|
-
action: BlueDotAction;
|
|
279
|
-
};
|
|
280
|
-
/**
|
|
281
|
-
* Emitted when the Blue Dot encounters an error.
|
|
282
|
-
*/
|
|
283
|
-
error: GeolocationPositionError;
|
|
284
|
-
/**
|
|
285
|
-
* Emitted when the Blue Dot's following state changes.
|
|
286
|
-
*/
|
|
287
|
-
'follow-change': {
|
|
288
|
-
/**
|
|
289
|
-
* Whether the Blue Dot is following the user.
|
|
290
|
-
*/
|
|
291
|
-
following: boolean;
|
|
292
|
-
/**
|
|
293
|
-
* The mode the Blue Dot is following the user in.
|
|
294
|
-
*/
|
|
295
|
-
mode?: FollowMode;
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Emitted when the user clicks on the Blue Dot.
|
|
299
|
-
*/
|
|
300
|
-
click: {
|
|
301
|
-
coordinate: Coordinate;
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* Emitted when the user hovers over the Blue Dot.
|
|
305
|
-
*/
|
|
306
|
-
hover: {
|
|
307
|
-
coordinate: Coordinate;
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
export type BlueDotEvents = keyof BlueDotEventPayloads;
|
|
311
|
-
export type BlueDotStatus = 'hidden' | 'active' | 'inactive' | 'disabled';
|
|
312
|
-
export type BlueDotAction = 'timeout' | 'error' | 'position-update' | 'enable' | 'disable' | 'initialize';
|
|
313
|
-
export type BlueDotState = {
|
|
314
|
-
/**
|
|
315
|
-
* The radius of the BlueDot in pixels. The BlueDot will maintain this size clamped to a minimum of 0.35 metres.
|
|
316
|
-
* @default 10
|
|
317
|
-
*/
|
|
318
|
-
radius: number;
|
|
319
|
-
/**
|
|
320
|
-
* The color of the BlueDot core element.
|
|
321
|
-
* @default #2266ff
|
|
322
|
-
*/
|
|
323
|
-
color: string;
|
|
324
|
-
/**
|
|
325
|
-
* The color of the BlueDot when it has timed out and gone inactive.
|
|
326
|
-
* @default #808080
|
|
327
|
-
*/
|
|
328
|
-
inactiveColor: string;
|
|
329
|
-
/**
|
|
330
|
-
* Options for the accuracy ring around the BlueDot.
|
|
331
|
-
*/
|
|
332
|
-
accuracyRing: {
|
|
333
|
-
/**
|
|
334
|
-
* The color of the accuracy ring.
|
|
335
|
-
* @default #2266ff
|
|
336
|
-
*/
|
|
337
|
-
color: string;
|
|
338
|
-
/**
|
|
339
|
-
* The opacity of the accuracy ring.
|
|
340
|
-
* @default 0.3
|
|
341
|
-
*/
|
|
342
|
-
opacity: number;
|
|
343
|
-
};
|
|
344
|
-
/**
|
|
345
|
-
* Options for the heading directional indicator.
|
|
346
|
-
*/
|
|
347
|
-
heading: {
|
|
348
|
-
/**
|
|
349
|
-
* The color of the heading cone.
|
|
350
|
-
* @default #2266ff
|
|
351
|
-
*/
|
|
352
|
-
color: string;
|
|
353
|
-
/**
|
|
354
|
-
* The opacity of the heading cone.
|
|
355
|
-
* @default 0.7
|
|
356
|
-
*/
|
|
357
|
-
opacity: number;
|
|
358
|
-
/**
|
|
359
|
-
* Whether to display the heading cone when the BlueDot is inactive (timed out).
|
|
360
|
-
* @default false
|
|
361
|
-
*/
|
|
362
|
-
displayWhenInactive: boolean;
|
|
363
|
-
};
|
|
364
|
-
/**
|
|
365
|
-
* The duration of the timeout in milliseconds.
|
|
366
|
-
* If the BlueDot does not receive a position update within this time, it will grey out until a position is received.
|
|
367
|
-
* @default 30000
|
|
368
|
-
*/
|
|
369
|
-
timeout: number;
|
|
370
|
-
/**
|
|
371
|
-
* Whether to watch the device's position.
|
|
372
|
-
* @default true
|
|
373
|
-
*/
|
|
374
|
-
watchDevicePosition: boolean;
|
|
375
|
-
/**
|
|
376
|
-
* Whether to log debug messages.
|
|
377
|
-
* @default false
|
|
378
|
-
*/
|
|
379
|
-
debug: boolean;
|
|
380
|
-
/**
|
|
381
|
-
* The maximum acceptable accuracy in meters. Position updates with accuracy exceeding this value will be dropped.
|
|
382
|
-
* @default 50
|
|
383
|
-
*/
|
|
384
|
-
accuracyThreshold: number;
|
|
385
|
-
/**
|
|
386
|
-
* The initial state of the BlueDot when enabled.
|
|
387
|
-
* @default 'hidden'
|
|
388
|
-
*/
|
|
389
|
-
initialState: 'hidden' | 'inactive';
|
|
390
|
-
/**
|
|
391
|
-
* @hidden
|
|
392
|
-
* Whether the BlueDot must remain within the map bounds. Disabling this will disable analytics as well.
|
|
393
|
-
* @default true
|
|
394
|
-
*/
|
|
395
|
-
preventOutOfBounds: boolean;
|
|
396
|
-
};
|
|
397
|
-
export type BlueDotUpdateState = PartialDeep<BlueDotState>;
|
|
398
|
-
/**
|
|
399
|
-
* Position update options for the {@link BlueDot.update} method.
|
|
400
|
-
*/
|
|
401
|
-
export type BlueDotPositionUpdate = {
|
|
402
|
-
/**
|
|
403
|
-
* Latitude to override.
|
|
404
|
-
* Set to `'device'` to reset to the device's latitude.
|
|
405
|
-
*/
|
|
406
|
-
latitude?: GeolocationPosition['coords']['latitude'] | 'device' | undefined;
|
|
407
|
-
/**
|
|
408
|
-
* Longitude to override.
|
|
409
|
-
* Set to `'device'` to reset to the device's longitude.
|
|
410
|
-
*/
|
|
411
|
-
longitude?: GeolocationPosition['coords']['longitude'] | 'device' | undefined;
|
|
412
|
-
/**
|
|
413
|
-
* Accuracy to override.
|
|
414
|
-
* Set to `'device'` to reset to the device's accuracy.
|
|
415
|
-
* Set to `undefined` to disable the accuracy ring.
|
|
416
|
-
*/
|
|
417
|
-
accuracy?: GeolocationPosition['coords']['accuracy'] | 'device' | undefined;
|
|
418
|
-
/**
|
|
419
|
-
* Heading to override.
|
|
420
|
-
* Set to `'device'` to reset to the device's heading.
|
|
421
|
-
* Set to `undefined` to disable the heading indicator.
|
|
422
|
-
*/
|
|
423
|
-
heading?: GeolocationPosition['coords']['heading'] | 'device' | undefined;
|
|
424
|
-
/**
|
|
425
|
-
* Floor or floorId to override.
|
|
426
|
-
* Set to `'device'` to reset to the device's floor level.
|
|
427
|
-
* Set to `undefined` to disable floor level and show the BlueDot on all floors.
|
|
428
|
-
*/
|
|
429
|
-
floorOrFloorId?: Floor | string | 'device' | undefined;
|
|
430
|
-
/**
|
|
431
|
-
* Timestamp of the position update in milliseconds.
|
|
432
|
-
*/
|
|
433
|
-
timestamp?: number;
|
|
434
|
-
};
|
|
435
|
-
export type BlueDotPositionUpdateWithFloor = Omit<BlueDotPositionUpdate, 'floorOrFloorId'> & {
|
|
436
|
-
floor?: Floor | 'device' | undefined;
|
|
437
|
-
};
|
|
438
|
-
export type ParsedBlueDotPosition = z.infer<typeof positionSchema>;
|
|
439
|
-
export type BlueDotPositionProcessor = (current: BlueDotPositionUpdateWithFloor, incoming: BlueDotPositionUpdateWithFloor) => BlueDotPositionUpdateWithFloor | undefined;
|
|
440
|
-
export type StateTransitions = {
|
|
441
|
-
[Action in BlueDotAction]?: BlueDotStatus;
|
|
442
|
-
};
|
|
443
|
-
export type StateMachine = {
|
|
444
|
-
[State in BlueDotStatus]: {
|
|
445
|
-
actions: StateTransitions;
|
|
446
|
-
};
|
|
447
|
-
};
|
|
448
|
-
/**
|
|
449
|
-
* Options for the BlueDot update method.
|
|
450
|
-
*/
|
|
451
|
-
export type BlueDotUpdateOptions = {
|
|
452
|
-
/**
|
|
453
|
-
* If true, maintains the current state and skips timers and analytics for this update.
|
|
454
|
-
* @default false
|
|
455
|
-
*/
|
|
456
|
-
silent?: boolean;
|
|
457
|
-
/**
|
|
458
|
-
* If true, animates the position change. If false, updates immediately.
|
|
459
|
-
* @default true
|
|
460
|
-
*/
|
|
461
|
-
animate?: boolean;
|
|
462
|
-
};
|
|
463
|
-
export type GeolocationPositionExtended = GeolocationPosition & {
|
|
464
|
-
coords: GeolocationPosition['coords'] & {
|
|
465
|
-
readonly floorLevel?: number;
|
|
466
|
-
};
|
|
467
|
-
};
|
|
468
|
-
}
|
|
20
|
+
/**
|
|
21
|
+
@remarks
|
|
22
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
23
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
24
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
25
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
26
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
27
|
+
|
|
28
|
+
@category Observable
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
33
|
+
/**
|
|
34
|
+
Extract all optional keys from the given type.
|
|
35
|
+
|
|
36
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
37
|
+
|
|
38
|
+
@example
|
|
39
|
+
```
|
|
40
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
469
41
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
export * from '@mappedin/blue-dot/react/packages/common/assert';
|
|
476
|
-
export * from '@mappedin/blue-dot/react/packages/common/random-id';
|
|
477
|
-
export { PubSub } from '@mappedin/blue-dot/react/packages/common/pubsub';
|
|
478
|
-
export { SafeStorage, SESSION_ID_KEY, DEVICE_ID_KEY } from '@mappedin/blue-dot/react/packages/common/storage';
|
|
479
|
-
export { Logger };
|
|
480
|
-
export * from '@mappedin/blue-dot/react/packages/common/color';
|
|
481
|
-
export * from '@mappedin/blue-dot/react/packages/common/interpolate';
|
|
42
|
+
interface User {
|
|
43
|
+
name: string;
|
|
44
|
+
surname: string;
|
|
45
|
+
|
|
46
|
+
luckyNumber?: number;
|
|
482
47
|
}
|
|
483
48
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
49
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
50
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
51
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const update1: UpdateOperation<User> = {
|
|
55
|
+
name: 'Alice'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const update2: UpdateOperation<User> = {
|
|
59
|
+
name: 'Bob',
|
|
60
|
+
luckyNumber: REMOVE_FIELD
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
@category Utilities
|
|
65
|
+
*/
|
|
66
|
+
type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
67
|
+
? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
68
|
+
: never;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
71
|
+
/**
|
|
72
|
+
Extract all required keys from the given type.
|
|
73
|
+
|
|
74
|
+
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
75
|
+
|
|
76
|
+
@example
|
|
77
|
+
```
|
|
78
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
79
|
+
|
|
80
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
81
|
+
|
|
82
|
+
interface User {
|
|
83
|
+
name: string;
|
|
84
|
+
surname: string;
|
|
85
|
+
|
|
86
|
+
luckyNumber?: number;
|
|
507
87
|
}
|
|
508
88
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
89
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
90
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
@category Utilities
|
|
94
|
+
*/
|
|
95
|
+
type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
96
|
+
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-never.d.ts
|
|
99
|
+
/**
|
|
100
|
+
Returns a boolean for whether the given type is `never`.
|
|
101
|
+
|
|
102
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
103
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
104
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
105
|
+
|
|
106
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
107
|
+
|
|
108
|
+
@example
|
|
109
|
+
```
|
|
110
|
+
import type {IsNever, And} from 'type-fest';
|
|
111
|
+
|
|
112
|
+
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
113
|
+
type AreStringsEqual<A extends string, B extends string> =
|
|
114
|
+
And<
|
|
115
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
116
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
117
|
+
>;
|
|
118
|
+
|
|
119
|
+
type EndIfEqual<I extends string, O extends string> =
|
|
120
|
+
AreStringsEqual<I, O> extends true
|
|
121
|
+
? never
|
|
122
|
+
: void;
|
|
123
|
+
|
|
124
|
+
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
125
|
+
if (input === output) {
|
|
126
|
+
process.exit(0);
|
|
127
|
+
}
|
|
542
128
|
}
|
|
543
129
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
130
|
+
endIfEqual('abc', 'abc');
|
|
131
|
+
//=> never
|
|
132
|
+
|
|
133
|
+
endIfEqual('abc', '123');
|
|
134
|
+
//=> void
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
@category Type Guard
|
|
138
|
+
@category Utilities
|
|
139
|
+
*/
|
|
140
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/if-never.d.ts
|
|
143
|
+
/**
|
|
144
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
145
|
+
|
|
146
|
+
@see {@link IsNever}
|
|
147
|
+
|
|
148
|
+
@example
|
|
149
|
+
```
|
|
150
|
+
import type {IfNever} from 'type-fest';
|
|
151
|
+
|
|
152
|
+
type ShouldBeTrue = IfNever<never>;
|
|
153
|
+
//=> true
|
|
154
|
+
|
|
155
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
156
|
+
//=> 'bar'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
@category Type Guard
|
|
160
|
+
@category Utilities
|
|
161
|
+
*/
|
|
162
|
+
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-any.d.ts
|
|
165
|
+
// Can eventually be replaced with the built-in once this library supports
|
|
166
|
+
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
167
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
Returns a boolean for whether the given type is `any`.
|
|
171
|
+
|
|
172
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
173
|
+
|
|
174
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
175
|
+
|
|
176
|
+
@example
|
|
177
|
+
```
|
|
178
|
+
import type {IsAny} from 'type-fest';
|
|
179
|
+
|
|
180
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
181
|
+
const anyObject: any = {a: 1, b: 2};
|
|
182
|
+
|
|
183
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
184
|
+
return obj[key];
|
|
557
185
|
}
|
|
558
186
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
* Normalizes the start and end rotations to the range 0 to 2 PI and ensures the shortest path for rotation.
|
|
606
|
-
*
|
|
607
|
-
* @param startRotation - The start rotation in radians
|
|
608
|
-
* @param targetRotation - The target rotation in radians
|
|
609
|
-
* @returns Start and end rotations for the tween.
|
|
610
|
-
*/
|
|
611
|
-
export function shortestTweenRotation(startRotation: number, targetRotation: number): {
|
|
612
|
-
start: number;
|
|
613
|
-
end: number;
|
|
614
|
-
};
|
|
615
|
-
export function isFiniteBox(box: Box2 | Box3): boolean;
|
|
616
|
-
export { clampWithWarning } from '@mappedin/blue-dot/react/packages/common/math-utils';
|
|
617
|
-
export { arraysEqual } from '@mappedin/blue-dot/react/packages/common/array-utils';
|
|
618
|
-
export function isBrowser(): boolean;
|
|
619
|
-
/**
|
|
620
|
-
* Calculates the simple Euclidean distance between two geographic coordinates.
|
|
621
|
-
*
|
|
622
|
-
* This treats longitude and latitude as Cartesian coordinates on a flat plane.
|
|
623
|
-
* It's the fastest distance calculation but least accurate for geographic data.
|
|
624
|
-
* Best used for relative distance comparisons rather than actual measurements.
|
|
625
|
-
*
|
|
626
|
-
* @param point1 - The first point's longitude and latitude as [longitude, latitude].
|
|
627
|
-
* @param point2 - The second point's longitude and latitude as [longitude, latitude].
|
|
628
|
-
* @returns The Euclidean distance between the two points in meters.
|
|
629
|
-
*/
|
|
630
|
-
export function euclideanDistance(point1: Position, point2: Position): number;
|
|
631
|
-
/**
|
|
632
|
-
* Calculates the approximate distance between two geographic coordinates on Earth's surface.
|
|
633
|
-
*
|
|
634
|
-
* This function uses the equirectangular approximation method to compute the distance, which simplifies
|
|
635
|
-
* the math and speeds up calculations, but is less accurate over long distances compared to other methods
|
|
636
|
-
* like the haversine formula.
|
|
637
|
-
*
|
|
638
|
-
* @param point1 - The first point's longitude and latitude as [longitude, latitude].
|
|
639
|
-
* @param point2 - The second point's longitude and latitude as [longitude, latitude].
|
|
640
|
-
* @returns The approximate distance between the two points in meters.
|
|
641
|
-
*/
|
|
642
|
-
export function equirectangularDistance(point1: Position, point2: Position): number;
|
|
187
|
+
const typedA = get(typedObject, 'a');
|
|
188
|
+
//=> 1
|
|
189
|
+
|
|
190
|
+
const anyA = get(anyObject, 'a');
|
|
191
|
+
//=> any
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
@category Type Guard
|
|
195
|
+
@category Utilities
|
|
196
|
+
*/
|
|
197
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/simplify.d.ts
|
|
200
|
+
/**
|
|
201
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
202
|
+
|
|
203
|
+
@example
|
|
204
|
+
```
|
|
205
|
+
import type {Simplify} from 'type-fest';
|
|
206
|
+
|
|
207
|
+
type PositionProps = {
|
|
208
|
+
top: number;
|
|
209
|
+
left: number;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
type SizeProps = {
|
|
213
|
+
width: number;
|
|
214
|
+
height: number;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
218
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
222
|
+
|
|
223
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
224
|
+
|
|
225
|
+
@example
|
|
226
|
+
```
|
|
227
|
+
import type {Simplify} from 'type-fest';
|
|
228
|
+
|
|
229
|
+
interface SomeInterface {
|
|
230
|
+
foo: number;
|
|
231
|
+
bar?: string;
|
|
232
|
+
baz: number | undefined;
|
|
643
233
|
}
|
|
644
234
|
|
|
645
|
-
|
|
646
|
-
|
|
235
|
+
type SomeType = {
|
|
236
|
+
foo: number;
|
|
237
|
+
bar?: string;
|
|
238
|
+
baz: number | undefined;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
242
|
+
const someType: SomeType = literal;
|
|
243
|
+
const someInterface: SomeInterface = literal;
|
|
244
|
+
|
|
245
|
+
function fn(object: Record<string, unknown>): void {}
|
|
246
|
+
|
|
247
|
+
fn(literal); // Good: literal object type is sealed
|
|
248
|
+
fn(someType); // Good: type is sealed
|
|
249
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
250
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
254
|
+
@see SimplifyDeep
|
|
255
|
+
@category Object
|
|
256
|
+
*/
|
|
257
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
260
|
+
/**
|
|
261
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
262
|
+
|
|
263
|
+
This is the counterpart of `PickIndexSignature`.
|
|
264
|
+
|
|
265
|
+
Use-cases:
|
|
266
|
+
- Remove overly permissive signatures from third-party types.
|
|
267
|
+
|
|
268
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
269
|
+
|
|
270
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
271
|
+
|
|
272
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
276
|
+
|
|
277
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
278
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
type Indexed = {} extends Record<string, unknown>
|
|
285
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
286
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
287
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
288
|
+
|
|
289
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
290
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
291
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
292
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
299
|
+
|
|
300
|
+
type OmitIndexSignature<ObjectType> = {
|
|
301
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
302
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
303
|
+
};
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
310
|
+
|
|
311
|
+
type OmitIndexSignature<ObjectType> = {
|
|
312
|
+
[KeyType in keyof ObjectType
|
|
313
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
314
|
+
as {} extends Record<KeyType, unknown>
|
|
315
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
316
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
317
|
+
]: ObjectType[KeyType];
|
|
318
|
+
};
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
322
|
+
|
|
323
|
+
@example
|
|
324
|
+
```
|
|
325
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
326
|
+
|
|
327
|
+
interface Example {
|
|
328
|
+
// These index signatures will be removed.
|
|
329
|
+
[x: string]: any
|
|
330
|
+
[x: number]: any
|
|
331
|
+
[x: symbol]: any
|
|
332
|
+
[x: `head-${string}`]: string
|
|
333
|
+
[x: `${string}-tail`]: string
|
|
334
|
+
[x: `head-${string}-tail`]: string
|
|
335
|
+
[x: `${bigint}`]: string
|
|
336
|
+
[x: `embedded-${number}`]: string
|
|
337
|
+
|
|
338
|
+
// These explicitly defined keys will remain.
|
|
339
|
+
foo: 'bar';
|
|
340
|
+
qux?: 'baz';
|
|
647
341
|
}
|
|
648
342
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
343
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
344
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
@see PickIndexSignature
|
|
348
|
+
@category Object
|
|
349
|
+
*/
|
|
350
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
353
|
+
/**
|
|
354
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
355
|
+
|
|
356
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
357
|
+
|
|
358
|
+
@example
|
|
359
|
+
```
|
|
360
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
361
|
+
|
|
362
|
+
declare const symbolKey: unique symbol;
|
|
363
|
+
|
|
364
|
+
type Example = {
|
|
365
|
+
// These index signatures will remain.
|
|
366
|
+
[x: string]: unknown;
|
|
367
|
+
[x: number]: unknown;
|
|
368
|
+
[x: symbol]: unknown;
|
|
369
|
+
[x: `head-${string}`]: string;
|
|
370
|
+
[x: `${string}-tail`]: string;
|
|
371
|
+
[x: `head-${string}-tail`]: string;
|
|
372
|
+
[x: `${bigint}`]: string;
|
|
373
|
+
[x: `embedded-${number}`]: string;
|
|
374
|
+
|
|
375
|
+
// These explicitly defined keys will be removed.
|
|
376
|
+
['kebab-case-key']: string;
|
|
377
|
+
[symbolKey]: string;
|
|
378
|
+
foo: 'bar';
|
|
379
|
+
qux?: 'baz';
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
383
|
+
// {
|
|
384
|
+
// [x: string]: unknown;
|
|
385
|
+
// [x: number]: unknown;
|
|
386
|
+
// [x: symbol]: unknown;
|
|
387
|
+
// [x: `head-${string}`]: string;
|
|
388
|
+
// [x: `${string}-tail`]: string;
|
|
389
|
+
// [x: `head-${string}-tail`]: string;
|
|
390
|
+
// [x: `${bigint}`]: string;
|
|
391
|
+
// [x: `embedded-${number}`]: string;
|
|
392
|
+
// }
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
@see OmitIndexSignature
|
|
396
|
+
@category Object
|
|
397
|
+
*/
|
|
398
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/merge.d.ts
|
|
401
|
+
// Merges two objects without worrying about index signatures.
|
|
402
|
+
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
406
|
+
|
|
407
|
+
@example
|
|
408
|
+
```
|
|
409
|
+
import type {Merge} from 'type-fest';
|
|
410
|
+
|
|
411
|
+
interface Foo {
|
|
412
|
+
[x: string]: unknown;
|
|
413
|
+
[x: number]: unknown;
|
|
414
|
+
foo: string;
|
|
415
|
+
bar: symbol;
|
|
702
416
|
}
|
|
703
417
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
418
|
+
type Bar = {
|
|
419
|
+
[x: number]: number;
|
|
420
|
+
[x: symbol]: unknown;
|
|
421
|
+
bar: Date;
|
|
422
|
+
baz: boolean;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
426
|
+
// => {
|
|
427
|
+
// [x: string]: unknown;
|
|
428
|
+
// [x: number]: number;
|
|
429
|
+
// [x: symbol]: unknown;
|
|
430
|
+
// foo: string;
|
|
431
|
+
// bar: Date;
|
|
432
|
+
// baz: boolean;
|
|
433
|
+
// }
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
@category Object
|
|
437
|
+
*/
|
|
438
|
+
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/if-any.d.ts
|
|
441
|
+
/**
|
|
442
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
443
|
+
|
|
444
|
+
@see {@link IsAny}
|
|
445
|
+
|
|
446
|
+
@example
|
|
447
|
+
```
|
|
448
|
+
import type {IfAny} from 'type-fest';
|
|
449
|
+
|
|
450
|
+
type ShouldBeTrue = IfAny<any>;
|
|
451
|
+
//=> true
|
|
452
|
+
|
|
453
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
454
|
+
//=> 'bar'
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
@category Type Guard
|
|
458
|
+
@category Utilities
|
|
459
|
+
*/
|
|
460
|
+
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/type.d.ts
|
|
463
|
+
/**
|
|
464
|
+
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
465
|
+
*/
|
|
466
|
+
type BuiltIns = Primitive | void | Date | RegExp;
|
|
467
|
+
/**
|
|
468
|
+
Test if the given function has multiple call signatures.
|
|
469
|
+
|
|
470
|
+
Needed to handle the case of a single call signature with properties.
|
|
471
|
+
|
|
472
|
+
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
473
|
+
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
474
|
+
*/
|
|
475
|
+
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
476
|
+
(...arguments_: infer A): unknown;
|
|
477
|
+
(...arguments_: infer B): unknown;
|
|
478
|
+
} ? B extends A ? A extends B ? false : true : true : false;
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/object.d.ts
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
Merges user specified options with default options.
|
|
484
|
+
|
|
485
|
+
@example
|
|
486
|
+
```
|
|
487
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
488
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
489
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
490
|
+
|
|
491
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
492
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
@example
|
|
496
|
+
```
|
|
497
|
+
// Complains if default values are not provided for optional options
|
|
498
|
+
|
|
499
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
500
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
501
|
+
type SpecifiedOptions = {};
|
|
502
|
+
|
|
503
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
504
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
505
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
@example
|
|
509
|
+
```
|
|
510
|
+
// Complains if an option's default type does not conform to the expected type
|
|
511
|
+
|
|
512
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
513
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
514
|
+
type SpecifiedOptions = {};
|
|
515
|
+
|
|
516
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
517
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
518
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
@example
|
|
522
|
+
```
|
|
523
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
524
|
+
|
|
525
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
526
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
527
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
528
|
+
|
|
529
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
530
|
+
// ~~~~~~~~~~~~~~~~
|
|
531
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
532
|
+
```
|
|
533
|
+
*/
|
|
534
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny<SpecifiedOptions, Defaults, IfNever<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
535
|
+
>>;
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/partial-deep.d.ts
|
|
538
|
+
/**
|
|
539
|
+
@see {@link PartialDeep}
|
|
540
|
+
*/
|
|
541
|
+
type PartialDeepOptions = {
|
|
542
|
+
/**
|
|
543
|
+
Whether to affect the individual elements of arrays and tuples.
|
|
544
|
+
@default false
|
|
545
|
+
*/
|
|
546
|
+
readonly recurseIntoArrays?: boolean;
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
Allows `undefined` values in non-tuple arrays.
|
|
550
|
+
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
551
|
+
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
552
|
+
@default true
|
|
553
|
+
@example
|
|
554
|
+
You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
|
|
555
|
+
```
|
|
556
|
+
import type {PartialDeep} from 'type-fest';
|
|
557
|
+
type Settings = {
|
|
558
|
+
languages: string[];
|
|
559
|
+
};
|
|
560
|
+
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
|
|
561
|
+
partialSettings.languages = [undefined]; // Error
|
|
562
|
+
partialSettings.languages = []; // Ok
|
|
563
|
+
```
|
|
564
|
+
*/
|
|
565
|
+
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
566
|
+
};
|
|
567
|
+
type DefaultPartialDeepOptions = {
|
|
568
|
+
recurseIntoArrays: false;
|
|
569
|
+
allowUndefinedInNonTupleArrays: true;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
Create a type from another type with all keys and nested keys set to optional.
|
|
574
|
+
|
|
575
|
+
Use-cases:
|
|
576
|
+
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
577
|
+
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
578
|
+
|
|
579
|
+
@example
|
|
580
|
+
```
|
|
581
|
+
import type {PartialDeep} from 'type-fest';
|
|
582
|
+
|
|
583
|
+
const settings: Settings = {
|
|
584
|
+
textEditor: {
|
|
585
|
+
fontSize: 14,
|
|
586
|
+
fontColor: '#000000',
|
|
587
|
+
fontWeight: 400
|
|
588
|
+
},
|
|
589
|
+
autocomplete: false,
|
|
590
|
+
autosave: true
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
|
|
594
|
+
return {...settings, ...savedSettings};
|
|
712
595
|
}
|
|
713
596
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
* @internal
|
|
725
|
-
*/
|
|
726
|
-
publish<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, data?: EVENT_PAYLOAD[EVENT_NAME]): void;
|
|
727
|
-
/**
|
|
728
|
-
* Subscribe a function to an event.
|
|
729
|
-
*
|
|
730
|
-
* @param eventName An event name which, when fired, will call the provided
|
|
731
|
-
* function.
|
|
732
|
-
* @param fn A callback that gets called when the corresponding event is fired. The
|
|
733
|
-
* callback will get passed an argument with a type that's one of event payloads.
|
|
734
|
-
* @example
|
|
735
|
-
* // Subscribe to the 'click' event
|
|
736
|
-
* const handler = (event) => {
|
|
737
|
-
* const { coordinate } = event;
|
|
738
|
-
* const { latitude, longitude } = coordinate;
|
|
739
|
-
* console.log(`Map was clicked at ${latitude}, ${longitude}`);
|
|
740
|
-
* };
|
|
741
|
-
* map.on('click', handler);
|
|
742
|
-
*/
|
|
743
|
-
on<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, fn: (payload: EVENT_PAYLOAD[EVENT_NAME] extends {
|
|
744
|
-
data: null;
|
|
745
|
-
} ? EVENT_PAYLOAD[EVENT_NAME]['data'] : EVENT_PAYLOAD[EVENT_NAME]) => void): void;
|
|
746
|
-
/**
|
|
747
|
-
* Unsubscribe a function previously subscribed with {@link on}
|
|
748
|
-
*
|
|
749
|
-
* @param eventName An event name to which the provided function was previously
|
|
750
|
-
* subscribed.
|
|
751
|
-
* @param fn A function that was previously passed to {@link on}. The function must
|
|
752
|
-
* have the same reference as the function that was subscribed.
|
|
753
|
-
* @example
|
|
754
|
-
* // Unsubscribe from the 'click' event
|
|
755
|
-
* const handler = (event) => {
|
|
756
|
-
* console.log('Map was clicked', event);
|
|
757
|
-
* };
|
|
758
|
-
* map.off('click', handler);
|
|
759
|
-
*/
|
|
760
|
-
off<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, fn: (payload: EVENT_PAYLOAD[EVENT_NAME] extends {
|
|
761
|
-
data: null;
|
|
762
|
-
} ? EVENT_PAYLOAD[EVENT_NAME]['data'] : EVENT_PAYLOAD[EVENT_NAME]) => void): void;
|
|
763
|
-
/**
|
|
764
|
-
* @private
|
|
765
|
-
* @internal
|
|
766
|
-
*/
|
|
767
|
-
destroy(): void;
|
|
768
|
-
}
|
|
597
|
+
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
|
|
601
|
+
|
|
602
|
+
```
|
|
603
|
+
import type {PartialDeep} from 'type-fest';
|
|
604
|
+
|
|
605
|
+
type Settings = {
|
|
606
|
+
languages: string[];
|
|
769
607
|
}
|
|
770
608
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
609
|
+
const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
610
|
+
languages: [undefined]
|
|
611
|
+
};
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
@see {@link PartialDeepOptions}
|
|
615
|
+
|
|
616
|
+
@category Object
|
|
617
|
+
@category Array
|
|
618
|
+
@category Set
|
|
619
|
+
@category Map
|
|
620
|
+
*/
|
|
621
|
+
type PartialDeep<T, Options extends PartialDeepOptions = {}> = _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
622
|
+
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown)) ? T : IsNever<keyof T> extends true // For functions with no properties
|
|
623
|
+
? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
624
|
+
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
625
|
+
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
626
|
+
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : PartialObjectDeep<T, Options> // Tuples behave properly
|
|
627
|
+
: T // If they don't opt into array testing, just use the original type
|
|
628
|
+
: PartialObjectDeep<T, Options> : unknown;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
632
|
+
*/
|
|
633
|
+
type PartialMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
637
|
+
*/
|
|
638
|
+
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
642
|
+
*/
|
|
643
|
+
type PartialReadonlyMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
647
|
+
*/
|
|
648
|
+
type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
652
|
+
*/
|
|
653
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = (ObjectType extends ((...arguments_: any) => unknown) ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType> : {}) & ({ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options> });
|
|
654
|
+
//#endregion
|
|
655
|
+
//#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/readonly-deep.d.ts
|
|
656
|
+
/**
|
|
657
|
+
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
658
|
+
|
|
659
|
+
This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.
|
|
660
|
+
|
|
661
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/13923) if you want to have this type as a built-in in TypeScript.
|
|
662
|
+
|
|
663
|
+
@example
|
|
664
|
+
```
|
|
665
|
+
// data.json
|
|
666
|
+
{
|
|
667
|
+
"foo": ["bar"]
|
|
793
668
|
}
|
|
794
669
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
670
|
+
// main.ts
|
|
671
|
+
import type {ReadonlyDeep} from 'type-fest';
|
|
672
|
+
import dataJson = require('./data.json');
|
|
673
|
+
|
|
674
|
+
const data: ReadonlyDeep<typeof dataJson> = dataJson;
|
|
675
|
+
|
|
676
|
+
export default data;
|
|
677
|
+
|
|
678
|
+
// test.ts
|
|
679
|
+
import data from './main';
|
|
680
|
+
|
|
681
|
+
data.foo.push('bar');
|
|
682
|
+
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
Note that types containing overloaded functions are not made deeply readonly due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
686
|
+
|
|
687
|
+
@category Object
|
|
688
|
+
@category Array
|
|
689
|
+
@category Set
|
|
690
|
+
@category Map
|
|
691
|
+
*/
|
|
692
|
+
type ReadonlyDeep<T> = T extends BuiltIns ? T : T extends (new (...arguments_: any[]) => unknown) ? T // Skip class constructors
|
|
693
|
+
: T extends ((...arguments_: any[]) => unknown) ? {} extends ReadonlyObjectDeep<T> ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T> : T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>> ? ReadonlyMapDeep<KeyType, ValueType> : T extends Readonly<ReadonlySet<infer ItemType>> ? ReadonlySetDeep<ItemType> :
|
|
694
|
+
// Identify tuples to avoid converting them to arrays inadvertently; special case `readonly [...never[]]`, as it emerges undesirably from recursive invocations of ReadonlyDeep below.
|
|
695
|
+
T extends readonly [] | readonly [...never[]] ? readonly [] : T extends readonly [infer U, ...infer V] ? readonly [ReadonlyDeep<U>, ...ReadonlyDeep<V>] : T extends readonly [...infer U, infer V] ? readonly [...ReadonlyDeep<U>, ReadonlyDeep<V>] : T extends ReadonlyArray<infer ItemType> ? ReadonlyArray<ReadonlyDeep<ItemType>> : T extends object ? ReadonlyObjectDeep<T> : unknown;
|
|
696
|
+
/**
|
|
697
|
+
Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
698
|
+
*/
|
|
699
|
+
type ReadonlyMapDeep<KeyType$1, ValueType$1> = {} & Readonly<ReadonlyMap<ReadonlyDeep<KeyType$1>, ReadonlyDeep<ValueType$1>>>;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
Same as `ReadonlyDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
703
|
+
*/
|
|
704
|
+
type ReadonlySetDeep<ItemType$1> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType$1>>>;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
|
|
708
|
+
*/
|
|
709
|
+
type ReadonlyObjectDeep<ObjectType extends object> = { readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]> };
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region ../packages/common/extensions.d.ts
|
|
712
|
+
interface MapViewExtension<T> {
|
|
713
|
+
enable(options?: PartialDeep<T>): void;
|
|
714
|
+
disable(): void;
|
|
715
|
+
get isEnabled(): boolean;
|
|
716
|
+
destroy(): void;
|
|
717
|
+
}
|
|
718
|
+
//#endregion
|
|
719
|
+
//#region ../packages/common/pubsub.d.ts
|
|
720
|
+
/**
|
|
721
|
+
* Generic PubSub class implementing the Publish-Subscribe pattern for event handling.
|
|
722
|
+
*
|
|
723
|
+
* @template EVENT_PAYLOAD - The type of the event payload.
|
|
724
|
+
* @template EVENT - The type of the event.
|
|
725
|
+
*/
|
|
726
|
+
declare class PubSub<EVENT_PAYLOAD, EVENT extends keyof EVENT_PAYLOAD = keyof EVENT_PAYLOAD> {
|
|
727
|
+
/**
|
|
728
|
+
* @private
|
|
729
|
+
* @internal
|
|
730
|
+
*/
|
|
731
|
+
private _subscribers;
|
|
732
|
+
/**
|
|
733
|
+
* @private
|
|
734
|
+
* @internal
|
|
735
|
+
*/
|
|
736
|
+
private _destroyed;
|
|
737
|
+
/**
|
|
738
|
+
* @private
|
|
739
|
+
* @internal
|
|
740
|
+
*/
|
|
741
|
+
publish<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, data?: EVENT_PAYLOAD[EVENT_NAME]): void;
|
|
742
|
+
/**
|
|
743
|
+
* Subscribe a function to an event.
|
|
744
|
+
*
|
|
745
|
+
* @param eventName An event name which, when fired, will call the provided
|
|
746
|
+
* function.
|
|
747
|
+
* @param fn A callback that gets called when the corresponding event is fired. The
|
|
748
|
+
* callback will get passed an argument with a type that's one of event payloads.
|
|
749
|
+
* @example
|
|
750
|
+
* // Subscribe to the 'click' event
|
|
751
|
+
* const handler = (event) => {
|
|
752
|
+
* const { coordinate } = event;
|
|
753
|
+
* const { latitude, longitude } = coordinate;
|
|
754
|
+
* console.log(`Map was clicked at ${latitude}, ${longitude}`);
|
|
755
|
+
* };
|
|
756
|
+
* map.on('click', handler);
|
|
757
|
+
*/
|
|
758
|
+
on<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, fn: (payload: EVENT_PAYLOAD[EVENT_NAME] extends {
|
|
759
|
+
data: null;
|
|
760
|
+
} ? EVENT_PAYLOAD[EVENT_NAME]['data'] : EVENT_PAYLOAD[EVENT_NAME]) => void): void;
|
|
761
|
+
/**
|
|
762
|
+
* Unsubscribe a function previously subscribed with {@link on}
|
|
763
|
+
*
|
|
764
|
+
* @param eventName An event name to which the provided function was previously
|
|
765
|
+
* subscribed.
|
|
766
|
+
* @param fn A function that was previously passed to {@link on}. The function must
|
|
767
|
+
* have the same reference as the function that was subscribed.
|
|
768
|
+
* @example
|
|
769
|
+
* // Unsubscribe from the 'click' event
|
|
770
|
+
* const handler = (event) => {
|
|
771
|
+
* console.log('Map was clicked', event);
|
|
772
|
+
* };
|
|
773
|
+
* map.off('click', handler);
|
|
774
|
+
*/
|
|
775
|
+
off<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, fn: (payload: EVENT_PAYLOAD[EVENT_NAME] extends {
|
|
776
|
+
data: null;
|
|
777
|
+
} ? EVENT_PAYLOAD[EVENT_NAME]['data'] : EVENT_PAYLOAD[EVENT_NAME]) => void): void;
|
|
778
|
+
/**
|
|
779
|
+
* @private
|
|
780
|
+
* @internal
|
|
781
|
+
*/
|
|
782
|
+
destroy(): void;
|
|
783
|
+
}
|
|
784
|
+
//#endregion
|
|
785
|
+
//#region ../packages/common/interpolate.d.ts
|
|
786
|
+
declare const EASING_CURVES: readonly ["ease-in", "ease-out", "ease-in-out", "linear"];
|
|
787
|
+
type EasingCurve = (typeof EASING_CURVES)[number];
|
|
788
|
+
//#endregion
|
|
789
|
+
//#region src/types.d.ts
|
|
790
|
+
type FollowMode = /** Camera position follows the Blue Dot's position. */
|
|
791
|
+
'position-only'
|
|
792
|
+
/** Camera position follows the Blue Dot's position. Camera bearing matches the Blue Dot's heading. */ | 'position-and-heading'
|
|
793
|
+
/** Camera position follows the Blue Dot's position. Camera bearing is calculated based on the Navigation path. */ | 'position-and-path-direction'
|
|
794
|
+
/** Disables follow mode */ | false;
|
|
795
|
+
type FollowCameraOptions = {
|
|
796
|
+
/**
|
|
797
|
+
* @default 21
|
|
798
|
+
*/
|
|
799
|
+
zoomLevel?: number;
|
|
800
|
+
/**
|
|
801
|
+
* @default 45
|
|
802
|
+
*/
|
|
803
|
+
pitch?: number;
|
|
804
|
+
/**
|
|
805
|
+
* Camera bearing in degrees clockwise from North. 0 is North, 90 is East, 180 is South, 270 is West.
|
|
806
|
+
* This option is only available in 'position-only' mode. In all other modes, the bearing will be calculated automatically.
|
|
807
|
+
* @default undefined
|
|
808
|
+
*/
|
|
809
|
+
bearing?: number;
|
|
810
|
+
/**
|
|
811
|
+
* @default undefined
|
|
812
|
+
*/
|
|
813
|
+
elevation?: number;
|
|
814
|
+
/**
|
|
815
|
+
* @default 1000
|
|
816
|
+
*/
|
|
817
|
+
duration?: number;
|
|
818
|
+
/**
|
|
819
|
+
* @default 'ease-in-out'
|
|
820
|
+
*/
|
|
821
|
+
easing?: EasingCurve;
|
|
822
|
+
};
|
|
823
|
+
type BlueDotEventPayloads = {
|
|
824
|
+
/**
|
|
825
|
+
* Emitted when the Blue Dot's position is updated either from the device's geolocation API or by calling {@link BlueDot.update}.
|
|
826
|
+
* see {@link BlueDot.watchDevicePosition} for more details.
|
|
827
|
+
*/
|
|
828
|
+
'position-update': {
|
|
829
|
+
floor: Floor | undefined;
|
|
830
|
+
heading: GeolocationPosition['coords']['heading'] | undefined;
|
|
831
|
+
accuracy: GeolocationPosition['coords']['accuracy'] | undefined;
|
|
832
|
+
coordinate: Coordinate;
|
|
833
|
+
};
|
|
834
|
+
/**
|
|
835
|
+
* Emitted when the device's orientation changes and the Blue Dot's heading is updated.
|
|
836
|
+
* see {@link BlueDot.watchDeviceOrientation} for more details.
|
|
837
|
+
*/
|
|
838
|
+
'device-orientation-update': {
|
|
839
|
+
heading: GeolocationPosition['coords']['heading'] | undefined;
|
|
840
|
+
};
|
|
841
|
+
/**
|
|
842
|
+
* Emitted when the Blue Dot's status changes.
|
|
843
|
+
*/
|
|
844
|
+
'status-change': {
|
|
809
845
|
/**
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
*/
|
|
814
|
-
export const isRgbColor: (color: string) => boolean;
|
|
846
|
+
* The new status of the Blue Dot.
|
|
847
|
+
*/
|
|
848
|
+
status: BlueDotStatus;
|
|
815
849
|
/**
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
850
|
+
* The action that caused the status change.
|
|
851
|
+
*/
|
|
852
|
+
action: BlueDotAction;
|
|
853
|
+
};
|
|
854
|
+
/**
|
|
855
|
+
* Emitted when the Blue Dot encounters an error.
|
|
856
|
+
*/
|
|
857
|
+
error: GeolocationPositionError;
|
|
858
|
+
/**
|
|
859
|
+
* Emitted when the Blue Dot's following state changes.
|
|
860
|
+
*/
|
|
861
|
+
'follow-change': {
|
|
821
862
|
/**
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
*/
|
|
826
|
-
export const isColor: (color: string) => boolean;
|
|
863
|
+
* Whether the Blue Dot is following the user.
|
|
864
|
+
*/
|
|
865
|
+
following: boolean;
|
|
827
866
|
/**
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
867
|
+
* The mode the Blue Dot is following the user in.
|
|
868
|
+
*/
|
|
869
|
+
mode?: FollowMode;
|
|
870
|
+
};
|
|
871
|
+
/**
|
|
872
|
+
* Emitted when the user clicks on the Blue Dot.
|
|
873
|
+
*/
|
|
874
|
+
click: {
|
|
875
|
+
coordinate: Coordinate;
|
|
876
|
+
};
|
|
877
|
+
/**
|
|
878
|
+
* Emitted when the user hovers over the Blue Dot.
|
|
879
|
+
*/
|
|
880
|
+
hover: {
|
|
881
|
+
coordinate: Coordinate;
|
|
882
|
+
};
|
|
883
|
+
};
|
|
884
|
+
type BlueDotEvents = keyof BlueDotEventPayloads;
|
|
885
|
+
type BlueDotStatus = 'hidden' | 'active' | 'inactive' | 'disabled';
|
|
886
|
+
type BlueDotAction = 'timeout' | 'error' | 'position-update' | 'enable' | 'disable' | 'initialize';
|
|
887
|
+
type BlueDotState = {
|
|
888
|
+
/**
|
|
889
|
+
* The radius of the BlueDot in pixels. The BlueDot will maintain this size clamped to a minimum of 0.35 metres.
|
|
890
|
+
* @default 10
|
|
891
|
+
*/
|
|
892
|
+
radius: number;
|
|
893
|
+
/**
|
|
894
|
+
* The color of the BlueDot core element.
|
|
895
|
+
* @default #2266ff
|
|
896
|
+
*/
|
|
897
|
+
color: string;
|
|
898
|
+
/**
|
|
899
|
+
* The color of the BlueDot when it has timed out and gone inactive.
|
|
900
|
+
* @default #808080
|
|
901
|
+
*/
|
|
902
|
+
inactiveColor: string;
|
|
903
|
+
/**
|
|
904
|
+
* Options for the accuracy ring around the BlueDot.
|
|
905
|
+
*/
|
|
906
|
+
accuracyRing: {
|
|
833
907
|
/**
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
export const rgbArrayToString: (rgb: [number, number, number]) => string;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
declare module '@mappedin/blue-dot/react/packages/common/interpolate' {
|
|
842
|
-
export const EASING_CURVES: readonly ["ease-in", "ease-out", "ease-in-out", "linear"];
|
|
843
|
-
export type EasingCurve = (typeof EASING_CURVES)[number];
|
|
908
|
+
* The color of the accuracy ring.
|
|
909
|
+
* @default #2266ff
|
|
910
|
+
*/
|
|
911
|
+
color: string;
|
|
844
912
|
/**
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
export function interpolate(value: number, inputMin: number, inputMax: number, outputMin: number, outputMax: number, easeFunc?: EasingCurve | ((t: number) => number)): number;
|
|
913
|
+
* The opacity of the accuracy ring.
|
|
914
|
+
* @default 0.3
|
|
915
|
+
*/
|
|
916
|
+
opacity: number;
|
|
917
|
+
};
|
|
918
|
+
/**
|
|
919
|
+
* Options for the heading directional indicator.
|
|
920
|
+
*/
|
|
921
|
+
heading: {
|
|
855
922
|
/**
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
export function getInterpolationBreakpoint(value: number, range: number[]): number;
|
|
861
|
-
export function interpolateMulti(value: number, inputRange: number[], outputRange: number[], easeFunc?: EasingCurve | ((t: number) => number)): number;
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
declare module '@mappedin/blue-dot/react/packages/common/math-utils' {
|
|
923
|
+
* The color of the heading cone.
|
|
924
|
+
* @default #2266ff
|
|
925
|
+
*/
|
|
926
|
+
color: string;
|
|
865
927
|
/**
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
declare module '@mappedin/blue-dot/react/packages/common/array-utils' {
|
|
928
|
+
* The opacity of the heading cone.
|
|
929
|
+
* @default 0.7
|
|
930
|
+
*/
|
|
931
|
+
opacity: number;
|
|
872
932
|
/**
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
933
|
+
* Whether to display the heading cone when the BlueDot is inactive (timed out).
|
|
934
|
+
* @default false
|
|
935
|
+
*/
|
|
936
|
+
displayWhenInactive: boolean;
|
|
937
|
+
};
|
|
938
|
+
/**
|
|
939
|
+
* The duration of the timeout in milliseconds.
|
|
940
|
+
* If the BlueDot does not receive a position update within this time, it will grey out until a position is received.
|
|
941
|
+
* @default 30000
|
|
942
|
+
*/
|
|
943
|
+
timeout: number;
|
|
944
|
+
/**
|
|
945
|
+
* Whether to watch the device's position.
|
|
946
|
+
* @default true
|
|
947
|
+
*/
|
|
948
|
+
watchDevicePosition: boolean;
|
|
949
|
+
/**
|
|
950
|
+
* Whether to log debug messages.
|
|
951
|
+
* @default false
|
|
952
|
+
*/
|
|
953
|
+
debug: boolean;
|
|
954
|
+
/**
|
|
955
|
+
* The maximum acceptable accuracy in meters. Position updates with accuracy exceeding this value will be dropped.
|
|
956
|
+
* @default 50
|
|
957
|
+
*/
|
|
958
|
+
accuracyThreshold: number;
|
|
959
|
+
/**
|
|
960
|
+
* The initial state of the BlueDot when enabled.
|
|
961
|
+
* @default 'hidden'
|
|
962
|
+
*/
|
|
963
|
+
initialState: 'hidden' | 'inactive';
|
|
964
|
+
/**
|
|
965
|
+
* @hidden
|
|
966
|
+
* Whether the BlueDot must remain within the map bounds. Disabling this will disable analytics as well.
|
|
967
|
+
* @default true
|
|
968
|
+
*/
|
|
969
|
+
preventOutOfBounds: boolean;
|
|
970
|
+
};
|
|
971
|
+
type BlueDotUpdateState = PartialDeep<BlueDotState>;
|
|
972
|
+
/**
|
|
973
|
+
* Position update options for the {@link BlueDot.update} method.
|
|
974
|
+
*/
|
|
975
|
+
type BlueDotPositionUpdate = {
|
|
976
|
+
/**
|
|
977
|
+
* Latitude to override.
|
|
978
|
+
* Set to `'device'` to reset to the device's latitude.
|
|
979
|
+
*/
|
|
980
|
+
latitude?: GeolocationPosition['coords']['latitude'] | 'device' | undefined;
|
|
981
|
+
/**
|
|
982
|
+
* Longitude to override.
|
|
983
|
+
* Set to `'device'` to reset to the device's longitude.
|
|
984
|
+
*/
|
|
985
|
+
longitude?: GeolocationPosition['coords']['longitude'] | 'device' | undefined;
|
|
986
|
+
/**
|
|
987
|
+
* Accuracy to override.
|
|
988
|
+
* Set to `'device'` to reset to the device's accuracy.
|
|
989
|
+
* Set to `undefined` to disable the accuracy ring.
|
|
990
|
+
*/
|
|
991
|
+
accuracy?: GeolocationPosition['coords']['accuracy'] | 'device' | undefined;
|
|
992
|
+
/**
|
|
993
|
+
* Heading to override.
|
|
994
|
+
* Set to `'device'` to reset to the device's heading.
|
|
995
|
+
* Set to `undefined` to disable the heading indicator.
|
|
996
|
+
*/
|
|
997
|
+
heading?: GeolocationPosition['coords']['heading'] | 'device' | undefined;
|
|
998
|
+
/**
|
|
999
|
+
* Floor or floorId to override.
|
|
1000
|
+
* Set to `'device'` to reset to the device's floor level.
|
|
1001
|
+
* Set to `undefined` to disable floor level and show the BlueDot on all floors.
|
|
1002
|
+
*/
|
|
1003
|
+
floorOrFloorId?: Floor | string | 'device' | undefined;
|
|
1004
|
+
/**
|
|
1005
|
+
* Timestamp of the position update in milliseconds.
|
|
1006
|
+
*/
|
|
1007
|
+
timestamp?: number;
|
|
1008
|
+
};
|
|
1009
|
+
type BlueDotPositionUpdateWithFloor = Omit<BlueDotPositionUpdate, 'floorOrFloorId'> & {
|
|
1010
|
+
floor?: Floor | 'device' | undefined;
|
|
1011
|
+
};
|
|
1012
|
+
type BlueDotPositionProcessor = (current: BlueDotPositionUpdateWithFloor, incoming: BlueDotPositionUpdateWithFloor) => BlueDotPositionUpdateWithFloor | undefined;
|
|
1013
|
+
/**
|
|
1014
|
+
* Options for the BlueDot update method.
|
|
1015
|
+
*/
|
|
1016
|
+
type BlueDotUpdateOptions = {
|
|
1017
|
+
/**
|
|
1018
|
+
* If true, maintains the current state and skips timers and analytics for this update.
|
|
1019
|
+
* @default false
|
|
1020
|
+
*/
|
|
1021
|
+
silent?: boolean;
|
|
1022
|
+
/**
|
|
1023
|
+
* If true, animates the position change. If false, updates immediately.
|
|
1024
|
+
* @default true
|
|
1025
|
+
*/
|
|
1026
|
+
animate?: boolean;
|
|
1027
|
+
};
|
|
1028
|
+
type GeolocationPositionExtended = GeolocationPosition & {
|
|
1029
|
+
coords: GeolocationPosition['coords'] & {
|
|
1030
|
+
readonly floorLevel?: number;
|
|
1031
|
+
};
|
|
1032
|
+
};
|
|
1033
|
+
//#endregion
|
|
1034
|
+
//#region src/blue-dot.d.ts
|
|
1035
|
+
/**
|
|
1036
|
+
* Show a Blue Dot indicating the device's position on the map.
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```ts
|
|
1040
|
+
* import { show3dMap } from '@mappedin/mappedin-js';
|
|
1041
|
+
* import { BlueDot } from '@mappedin/blue-dot';
|
|
1042
|
+
*
|
|
1043
|
+
* const mapView = await show3dMap(...);
|
|
1044
|
+
*
|
|
1045
|
+
* // Enable BlueDot
|
|
1046
|
+
* const blueDot = new BlueDot(mapView).enable();
|
|
1047
|
+
*
|
|
1048
|
+
* // Option 1: Listen for position updates from the device
|
|
1049
|
+
* blueDot.on('position-update', (position) => {
|
|
1050
|
+
* console.log('User position:', position);
|
|
1051
|
+
* });
|
|
1052
|
+
*
|
|
1053
|
+
* // Option 2: Update position manually
|
|
1054
|
+
* blueDot.update({ latitude, longitude, accuracy, floorOrFloorId });
|
|
1055
|
+
*
|
|
1056
|
+
* ```
|
|
1057
|
+
*/
|
|
1058
|
+
declare class BlueDot implements MapViewExtension<BlueDotState> {
|
|
1059
|
+
#private;
|
|
1060
|
+
/**
|
|
1061
|
+
* Create a new {@link BlueDot} instance.
|
|
1062
|
+
*/
|
|
1063
|
+
constructor(mapView: MapView);
|
|
1064
|
+
/**
|
|
1065
|
+
* Get the Model for the BlueDot core element.
|
|
1066
|
+
*/
|
|
1067
|
+
get dotModel(): Model | undefined;
|
|
1068
|
+
/**
|
|
1069
|
+
* Get the Model for the accuracy ring.
|
|
1070
|
+
*/
|
|
1071
|
+
get accuracyRingModel(): Model | undefined;
|
|
1072
|
+
/**
|
|
1073
|
+
* Get the Model for the heading cone.
|
|
1074
|
+
*/
|
|
1075
|
+
get headingConeModel(): Model | undefined;
|
|
1076
|
+
/**
|
|
1077
|
+
* Whether the BlueDot is currently enabled.
|
|
1078
|
+
*/
|
|
1079
|
+
get isEnabled(): boolean;
|
|
1080
|
+
/**
|
|
1081
|
+
* The current state of the BlueDot. Can be 'hidden', 'active', 'inactive', or 'disabled'.
|
|
1082
|
+
* Listen for state changes using the 'status-change' event.
|
|
1083
|
+
*
|
|
1084
|
+
* @example
|
|
1085
|
+
* mapView.BlueDot.on('status-change', ({ status }) => {
|
|
1086
|
+
* if (status === 'active') {
|
|
1087
|
+
* // BlueDot is visible and tracking
|
|
1088
|
+
* }
|
|
1089
|
+
* });
|
|
1090
|
+
*/
|
|
1091
|
+
get status(): BlueDotStatus;
|
|
1092
|
+
/**
|
|
1093
|
+
* Whether the BlueDot is currently following the user (camera follow mode).
|
|
1094
|
+
*/
|
|
1095
|
+
get isFollowing(): boolean;
|
|
1096
|
+
/**
|
|
1097
|
+
* The direction the user is facing in degrees from north clockwise.
|
|
1098
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading
|
|
1099
|
+
*/
|
|
1100
|
+
get heading(): GeolocationPosition['coords']['heading'] | undefined;
|
|
1101
|
+
/**
|
|
1102
|
+
* The accuracy of the current position in metres.
|
|
1103
|
+
*/
|
|
1104
|
+
get accuracy(): GeolocationPosition['coords']['accuracy'] | undefined;
|
|
1105
|
+
/**
|
|
1106
|
+
* The coordinate of the current position.
|
|
1107
|
+
*/
|
|
1108
|
+
get coordinate(): Coordinate | undefined;
|
|
1109
|
+
/**
|
|
1110
|
+
* Returns the current Blue Dot state.
|
|
1111
|
+
*/
|
|
1112
|
+
getState(): ReadonlyDeep<BlueDotState>;
|
|
1113
|
+
/**
|
|
1114
|
+
* The floor the Blue Dot is currently on. If undefined, the Blue Dot will appear on every floor.
|
|
1115
|
+
*/
|
|
1116
|
+
get floor(): Floor | undefined;
|
|
1117
|
+
/**
|
|
1118
|
+
* Enable the Blue Dot. It will be hidden until a position is received either from the browser or by calling {@link BlueDot.update}.
|
|
1119
|
+
* @param options - The options to setup the Blue Dot (see {@link BlueDotUpdateState}).
|
|
1120
|
+
*
|
|
1121
|
+
* @example Enable with default options
|
|
1122
|
+
* ```ts
|
|
1123
|
+
* const blueDot = new BlueDot(mapView);
|
|
1124
|
+
* blueDot.enable();
|
|
1125
|
+
* ```
|
|
1126
|
+
* @example Enable with custom color and accuracy ring
|
|
1127
|
+
* ```ts
|
|
1128
|
+
* const blueDot = new BlueDot(mapView);
|
|
1129
|
+
* blueDot.enable({ color: '#00ff00', accuracyRing: { color: '#00ff00', opacity: 0.2 } });
|
|
1130
|
+
* ```
|
|
1131
|
+
*
|
|
1132
|
+
* @see See the [BlueDot Guide](https://developer.mappedin.com/web-sdk/blue-dot) for more information.
|
|
1133
|
+
*/
|
|
1134
|
+
enable: (options?: BlueDotUpdateState) => void;
|
|
1135
|
+
/**
|
|
1136
|
+
* Disable the Blue Dot. It will be hidden and no longer update.
|
|
1137
|
+
*/
|
|
1138
|
+
disable: () => void;
|
|
1139
|
+
/**
|
|
1140
|
+
* Subscribe to a BlueDot event.
|
|
1141
|
+
* @param eventName The name of the event to listen for.
|
|
1142
|
+
* @param fn The function to call when the event is emitted.
|
|
1143
|
+
*/
|
|
1144
|
+
on: PubSub<BlueDotEventPayloads>['on'];
|
|
1145
|
+
/**
|
|
1146
|
+
* Unsubscribe from a BlueDot event.
|
|
1147
|
+
* @param eventName The name of the event to unsubscribe from.
|
|
1148
|
+
* @param fn The function to unsubscribe from the event.
|
|
1149
|
+
*/
|
|
1150
|
+
off: PubSub<BlueDotEventPayloads>['off'];
|
|
1151
|
+
/**
|
|
1152
|
+
* Update the BlueDot state after it has been enabled.
|
|
1153
|
+
* This allows overriding previously set values like colors, and other options.
|
|
1154
|
+
* @param options - The options to update
|
|
1155
|
+
*
|
|
1156
|
+
* @example Update color and accuracy ring
|
|
1157
|
+
* ```ts
|
|
1158
|
+
* const blueDot = new BlueDot(mapView);
|
|
1159
|
+
* blueDot.updateState({
|
|
1160
|
+
* color: '#ff0000',
|
|
1161
|
+
* accuracyRing: { color: '#ff0000', opacity: 0.5 }
|
|
1162
|
+
* });
|
|
1163
|
+
* ```
|
|
1164
|
+
*/
|
|
1165
|
+
updateState: (options: BlueDotUpdateState) => void;
|
|
1166
|
+
/**
|
|
1167
|
+
* Enable or disable the devices's geolocation listener to automatically position the Blue Dot.
|
|
1168
|
+
* If enabled, the device will request permission to access the user's precise location.
|
|
1169
|
+
*
|
|
1170
|
+
* @remarks This will emit a 'position-update' event every time a new position is received.
|
|
1171
|
+
*
|
|
1172
|
+
* @param watch - Whether to enable or disable the listener.
|
|
1173
|
+
*/
|
|
1174
|
+
watchDevicePosition: (watch: boolean) => void;
|
|
1175
|
+
/**
|
|
1176
|
+
* Enable or disable the device orientation listener to automatically update the Blue Dot's heading.
|
|
1177
|
+
* This must be enabled in response to a user action such as a tap or click and cannot be enabled automatically.
|
|
1178
|
+
*
|
|
1179
|
+
* @remarks This will emit a 'device-orientation-update' event every time the device's orientation changes.
|
|
1180
|
+
* Device orientation changes will not emit a 'position-update' event.
|
|
1181
|
+
*
|
|
1182
|
+
* @see https://www.w3.org/TR/orientation-event/#dom-deviceorientationevent-requestpermission
|
|
1183
|
+
*
|
|
1184
|
+
* @param watch - Whether to enable or disable the listener.
|
|
1185
|
+
*
|
|
1186
|
+
* @example Enable device orientation listener
|
|
1187
|
+
* ```ts
|
|
1188
|
+
* const blueDot = new BlueDot(mapView);
|
|
1189
|
+
* // Enable device orientation on button click
|
|
1190
|
+
* button.addEventListener('click', () => {
|
|
1191
|
+
* blueDot.watchDeviceOrientation(true);
|
|
1192
|
+
* });
|
|
1193
|
+
* ```
|
|
1194
|
+
*/
|
|
1195
|
+
watchDeviceOrientation: (watch: boolean) => Promise<void>;
|
|
1196
|
+
/**
|
|
1197
|
+
* Manually override some position properties of the Blue Dot.
|
|
1198
|
+
* Accepts a full GeolocationPosition object or a partial {@link BlueDotPositionUpdate} object.
|
|
1199
|
+
*
|
|
1200
|
+
* @remarks This will emit a 'position-update' event.
|
|
1201
|
+
*
|
|
1202
|
+
* @example Manually set the accuracy and heading
|
|
1203
|
+
* ```ts
|
|
1204
|
+
* api.BlueDot.update({ accuracy: 10, heading: 90 });
|
|
1205
|
+
* ```
|
|
1206
|
+
* @example Reset accuracy and heading to device values
|
|
1207
|
+
* ```ts
|
|
1208
|
+
* api.BlueDot.update({ accuracy: 'device', heading: 'device' });
|
|
1209
|
+
* ```
|
|
1210
|
+
*/
|
|
1211
|
+
update: (position: GeolocationPositionExtended | BlueDotPositionUpdate | undefined, options?: BlueDotUpdateOptions) => void;
|
|
1212
|
+
/**
|
|
1213
|
+
* Set the camera to follow the BlueDot in various modes. User interaction will cancel following automatically.
|
|
1214
|
+
* @param mode The follow mode ('position-only', 'position-and-heading', 'position-and-path-direction', or false to disable).
|
|
1215
|
+
* @param cameraOptions Optional camera options (zoom, pitch, etc.).
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1218
|
+
* mapView.BlueDot.follow('position-and-heading', { zoomLevel: 21, pitch: 45 });
|
|
1219
|
+
*/
|
|
1220
|
+
follow: (mode: FollowMode, cameraOptions?: FollowCameraOptions) => void;
|
|
1221
|
+
/**
|
|
1222
|
+
* Set a position processor callback that allows intercepting and modifying device/geolocation position updates before they are applied.
|
|
1223
|
+
*
|
|
1224
|
+
* **Note**: This processor only applies to automatic position updates from device geolocation.
|
|
1225
|
+
* Manual position updates via `update()` method bypass the processor and are applied directly.
|
|
1226
|
+
*
|
|
1227
|
+
* @param processor - A callback function that receives current state and incoming update. Return undefined to discard the update, or return a modified update object.
|
|
1228
|
+
*
|
|
1229
|
+
* @example Discard inaccurate positions
|
|
1230
|
+
* ```ts
|
|
1231
|
+
* blueDot.setPositionProcessor((current, incoming) => {
|
|
1232
|
+
* if (incoming.accuracy && incoming.accuracy > 50) {
|
|
1233
|
+
* return undefined; // Discard update
|
|
1234
|
+
* }
|
|
1235
|
+
* return incoming; // Accept update
|
|
1236
|
+
* });
|
|
1237
|
+
* ```
|
|
1238
|
+
*
|
|
1239
|
+
* @example Modify incoming positions
|
|
1240
|
+
* ```ts
|
|
1241
|
+
* blueDot.setPositionProcessor((current, incoming) => {
|
|
1242
|
+
* // Apply custom smoothing or validation logic
|
|
1243
|
+
* return {
|
|
1244
|
+
* ...incoming,
|
|
1245
|
+
* accuracy: Math.min(incoming.accuracy || 100, 10) // Cap accuracy
|
|
1246
|
+
* };
|
|
1247
|
+
* });
|
|
1248
|
+
* ```
|
|
1249
|
+
*/
|
|
1250
|
+
setPositionProcessor(processor?: BlueDotPositionProcessor): void;
|
|
1251
|
+
destroy: () => void;
|
|
1252
|
+
private onPositionUpdate;
|
|
1253
|
+
private onPositionError;
|
|
876
1254
|
}
|
|
877
|
-
|
|
1255
|
+
//#endregion
|
|
1256
|
+
//#region src/react/use-blue-dot.d.ts
|
|
1257
|
+
declare function useBlueDot(): BlueDot;
|
|
1258
|
+
//#endregion
|
|
1259
|
+
//#region src/react/use-blue-dot-event.d.ts
|
|
1260
|
+
declare function useBlueDotEvent<T extends BlueDotEvents>(eventName: T, callback: (payload: BlueDotEventPayloads[T]) => void): void;
|
|
1261
|
+
//#endregion
|
|
1262
|
+
export { useBlueDot, useBlueDotEvent };
|