@mappedin/blue-dot 6.0.1-beta.55 → 6.0.1-beta.56

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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../../packages/common/pubsub.ts", "../src/blue-dot.ts"],
4
+ "sourcesContent": ["export { BlueDot } from './blue-dot';\nexport type {\n\tBlueDotEvents,\n\tBlueDotEventPayloads,\n\tBlueDotPositionUpdate,\n\tBlueDotState,\n\tBlueDotAction,\n\tFollowMode,\n\tFollowCameraOptions,\n\tBlueDotOptions,\n} from './types';\n", "/**\n * Generic PubSub class implementing the Publish-Subscribe pattern for event handling.\n *\n * @template EVENT_PAYLOAD - The type of the event payload.\n * @template EVENT - The type of the event.\n */\nexport class PubSub<EVENT_PAYLOAD, EVENT extends keyof EVENT_PAYLOAD = keyof EVENT_PAYLOAD> {\n\t/**\n\t * @private\n\t * @internal\n\t */\n\tprivate _subscribers: any = {};\n\t/**\n\t * @private\n\t * @internal\n\t */\n\tprivate _destroyed = false;\n\n\t/**\n\t * @private\n\t * @internal\n\t */\n\tpublish<EVENT_NAME extends EVENT>(eventName: EVENT_NAME, data?: EVENT_PAYLOAD[EVENT_NAME]) {\n\t\tif (!this._subscribers || !this._subscribers[eventName] || this._destroyed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._subscribers[eventName]!.forEach(function (fn) {\n\t\t\tif (typeof fn !== 'function') {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfn(data);\n\t\t});\n\t}\n\n\t/**\n\t * Subscribe a function to an event.\n\t *\n\t * @param eventName An event name which, when fired, will call the provided\n\t * function.\n\t * @param fn A callback that gets called when the corresponding event is fired. The\n\t * callback will get passed an argument with a type that's one of event payloads.\n\t * @example\n\t * // Subscribe to the 'click' event\n\t * const handler = (event) => {\n\t * const { coordinate } = event;\n\t * const { latitude, longitude } = coordinate;\n\t * \tconsole.log(`Map was clicked at ${latitude}, ${longitude}`);\n\t * };\n\t * map.on('click', handler);\n\t */\n\ton<EVENT_NAME extends EVENT>(\n\t\teventName: EVENT_NAME,\n\t\tfn: (\n\t\t\tpayload: EVENT_PAYLOAD[EVENT_NAME] extends {\n\t\t\t\tdata: null;\n\t\t\t}\n\t\t\t\t? EVENT_PAYLOAD[EVENT_NAME]['data']\n\t\t\t\t: EVENT_PAYLOAD[EVENT_NAME],\n\t\t) => void,\n\t) {\n\t\tif (!this._subscribers || this._destroyed) {\n\t\t\tthis._subscribers = {};\n\t\t}\n\t\tthis._subscribers[eventName] = this._subscribers[eventName] || [];\n\t\tthis._subscribers[eventName]!.push(fn);\n\t}\n\n\t/**\n\t * Unsubscribe a function previously subscribed with {@link on}\n\t *\n\t * @param eventName An event name to which the provided function was previously\n\t * subscribed.\n\t * @param fn A function that was previously passed to {@link on}. The function must\n\t * have the same reference as the function that was subscribed.\n\t * @example\n\t * // Unsubscribe from the 'click' event\n\t * const handler = (event) => {\n\t * \tconsole.log('Map was clicked', event);\n\t * };\n\t * map.off('click', handler);\n\t */\n\toff<EVENT_NAME extends EVENT>(\n\t\teventName: EVENT_NAME,\n\t\tfn: (\n\t\t\tpayload: EVENT_PAYLOAD[EVENT_NAME] extends {\n\t\t\t\tdata: null;\n\t\t\t}\n\t\t\t\t? EVENT_PAYLOAD[EVENT_NAME]['data']\n\t\t\t\t: EVENT_PAYLOAD[EVENT_NAME],\n\t\t) => void,\n\t) {\n\t\tif (!this._subscribers || this._subscribers[eventName] == null || this._destroyed) {\n\t\t\treturn;\n\t\t}\n\t\tconst itemIdx = this._subscribers[eventName]!.indexOf(fn);\n\n\t\tif (itemIdx !== -1) {\n\t\t\tthis._subscribers[eventName]!.splice(itemIdx, 1);\n\t\t}\n\t}\n\t/**\n\t * @private\n\t * @internal\n\t */\n\tdestroy() {\n\t\tthis._destroyed = true;\n\t\tthis._subscribers = {};\n\t}\n}\n", "import { PubSub } from '@packages/internal/common/pubsub';\nimport type { MapView } from '@mappedin/mappedin-js';\nimport type {\n\tBlueDotEventPayloads,\n\tBlueDotOptions,\n\tBlueDotPositionUpdate,\n\tBlueDotState,\n\tFollowCameraOptions,\n\tFollowMode,\n} from './types';\n\n/**\n * Show a Blue Dot indicating the device's position on the map.\n *\n * @example\n * ```ts\n * import { show3dMap } from '@mappedin/mappedin-js';\n * import { BlueDot } from '@mappedin/blue-dot';\n *\n * const mapView = await show3dMap(...);\n *\n * // Enable BlueDot\n * new BlueDot(mapView).enable();\n *\n * // Option 1: Listen for position updates from the device\n * mapView.BlueDot.on('position-update', (position) => {\n * console.log('User position:', position);\n * });\n *\n * // Option 2: Update position manually\n * new BlueDot(mapView).update({ latitude, longitude, accuracy, floorOrFloorId });\n *\n * ```\n */\nexport class BlueDot {\n\t#pubsub = new PubSub<BlueDotEventPayloads>();\n\t#mapView: MapView;\n\n\t/**\n\t * Create a new {@link BlueDot} instance.\n\t */\n\tconstructor(mapView: MapView) {\n\t\tthis.#mapView = mapView;\n\t\tthis.#mapView.__BlueDot.on('blue-dot-position-error', e => {\n\t\t\tthis.#pubsub.publish('error', e);\n\t\t});\n\t\tthis.#mapView.__BlueDot.on('blue-dot-position-update', e => {\n\t\t\tthis.#pubsub.publish('position-update', e);\n\t\t});\n\t\tthis.#mapView.__BlueDot.on('blue-dot-state-change', e => {\n\t\t\tthis.#pubsub.publish('state-change', e);\n\t\t});\n\t\tthis.#mapView.__BlueDot.on('blue-dot-follow-change', e => {\n\t\t\tthis.#pubsub.publish('follow-change', e);\n\t\t});\n\t\tthis.#mapView.__BlueDot.on('click', e => {\n\t\t\tthis.#pubsub.publish('click', e);\n\t\t});\n\t\tthis.#mapView.__BlueDot.on('hover', () => {\n\t\t\tthis.#pubsub.publish('hover');\n\t\t});\n\t}\n\n\t/**\n\t * The current state of the BlueDot. Can be 'hidden', 'active', 'inactive', or 'disabled'.\n\t * Listen for state changes using the 'state-change' event.\n\t *\n\t * @example\n\t * mapView.BlueDot.on('state-change', ({ state }) => {\n\t * if (state === 'active') {\n\t * // BlueDot is visible and tracking\n\t * }\n\t * });\n\t */\n\tget state(): BlueDotState {\n\t\treturn this.#mapView.__BlueDot.state;\n\t}\n\n\t/**\n\t * Whether the BlueDot is currently following the user (camera follow mode).\n\t */\n\tget following() {\n\t\treturn this.#mapView.__BlueDot.following;\n\t}\n\n\t/**\n\t * The direction the user is facing in degrees from north clockwise.\n\t * @see https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates/heading\n\t */\n\tget heading() {\n\t\treturn this.#mapView.__BlueDot.heading;\n\t}\n\n\t/**\n\t * The accuracy of the current position in metres.\n\t */\n\tget accuracy() {\n\t\treturn this.#mapView.__BlueDot.accuracy;\n\t}\n\n\t/**\n\t * The coordinate of the current position.\n\t */\n\tget coordinate() {\n\t\treturn this.#mapView.__BlueDot.coordinate;\n\t}\n\n\t/**\n\t * The floor the Blue Dot is currently on. If undefined, the Blue Dot will appear on every floor.\n\t */\n\tget floor() {\n\t\treturn this.#mapView.__BlueDot.floor;\n\t}\n\n\t/**\n\t * Enable the Blue Dot. It will be hidden until a position is received either from the browser or by calling {@link BlueDot.update}.\n\t * @param options - The options to setup the Blue Dot (see {@link BlueDotOptions}).\n\t *\n\t * @example Enable with default options\n\t * mapView.BlueDot.enable();\n\t *\n\t * @example Enable with custom color and accuracy ring\n\t * mapView.BlueDot.enable({ color: '#00ff00', accuracyRing: { color: '#00ff00', opacity: 0.2 } });\n\t *\n\t * @see See the [BlueDot Guide](https://developer.mappedin.com/web-sdk/blue-dot) for more information.\n\t */\n\tenable = (options?: BlueDotOptions) => {\n\t\tthis.#mapView.__BlueDot.enable(options);\n\t};\n\n\t/**\n\t * Disable the Blue Dot. It will be hidden and no longer update.\n\t */\n\tdisable = () => {\n\t\tthis.#mapView.__BlueDot.disable();\n\t};\n\n\ton: PubSub<BlueDotEventPayloads>['on'] = (eventName, fn) => {\n\t\tthis.#pubsub.on(eventName, fn);\n\t};\n\n\toff: PubSub<BlueDotEventPayloads>['off'] = (eventName, fn) => {\n\t\tthis.#pubsub.off(eventName, fn);\n\t};\n\n\t/**\n\t * Enable or disable the devices's geolocation listener to automatically position the Blue Dot.\n\t * If enabled, the device will request permission to access the user's precise location.\n\t * @param watch - Whether to enable or disable the listener.\n\t */\n\twatchDevicePosition = (watch = true) => {\n\t\tthis.#mapView.__BlueDot.watchDevicePosition(watch);\n\t};\n\n\t/**\n\t * Manually override some position properties of the Blue Dot.\n\t * Accepts a full GeolocationPosition object or a partial {@link BlueDotPositionUpdate} object.\n\t * @example Manually set the accuracy and heading\n\t * ```ts\n\t * api.BlueDot.update({ accuracy: 10, heading: 90 });\n\t * ```\n\t * @example Reset accuracy and heading to device values\n\t * ```ts\n\t * api.BlueDot.update({ accuracy: 'device', heading: 'device' });\n\t * ```\n\t */\n\tupdate = (position: BlueDotPositionUpdate) => {\n\t\tthis.#mapView.__BlueDot.update(position);\n\t};\n\n\t/**\n\t * Set the camera to follow the BlueDot in various modes. User interaction will cancel following automatically.\n\t * @param mode The follow mode ('position-only', 'position-and-heading', 'position-and-path-direction', or false to disable).\n\t * @param cameraOptions Optional camera options (zoom, pitch, etc.).\n\t *\n\t * @example\n\t * mapView.BlueDot.follow('position-and-heading', { zoomLevel: 21, pitch: 45 });\n\t */\n\tfollow = (mode: FollowMode, cameraOptions?: FollowCameraOptions) => {\n\t\tthis.#mapView.__BlueDot.follow(mode, cameraOptions);\n\t};\n\n\tdestroy = () => {\n\t\tthis.#pubsub.destroy();\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;67BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,ICMO,IAAMC,EAAN,MAAMA,CAA+E,CAArF,cAKNC,EAAA,KAAQ,eAAoB,CAAC,GAK7BA,EAAA,KAAQ,aAAa,IAMrB,QAAkCC,EAAuBC,EAAkC,CACtF,CAAC,KAAK,cAAgB,CAAC,KAAK,aAAaD,CAAS,GAAK,KAAK,YAIhE,KAAK,aAAaA,CAAS,EAAG,QAAQ,S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S,UAAU,QAChC,CAKA,IAAI,YAAa,CAChB,OAAOQ,EAAA,KAAKR,GAAS,UAAU,UAChC,CAKA,IAAI,OAAQ,CACX,OAAOQ,EAAA,KAAKR,GAAS,UAAU,KAChC,CAyED,EAtJCD,EAAA,YACAC,EAAA,YAFoBM,EAAAL,EAAA,WAAd,IAAMe,EAANf",
6
+ "names": ["index_exports", "__export", "BlueDot", "_PubSub", "__publicField", "eventName", "data", "fn", "itemIdx", "__name", "PubSub", "_pubsub", "_mapView", "_BlueDot", "mapView", "__privateAdd", "PubSub", "__publicField", "__name", "options", "__privateGet", "eventName", "fn", "watch", "position", "mode", "cameraOptions", "__privateSet", "BlueDot"]
7
+ }
@@ -1,6 +1,6 @@
1
1
  // Generated by dts-bundle v0.7.3
2
2
  // Dependencies for this module:
3
- // ../blue-dot/@packages/internal/common
3
+ // ../blue-dot/@packages/internal/common/pubsub
4
4
  // ../blue-dot/@mappedin/mappedin-js
5
5
  // ../blue-dot/three
6
6
  // ../blue-dot/type-fest
@@ -11,7 +11,7 @@ declare module '@mappedin/blue-dot' {
11
11
  }
12
12
 
13
13
  declare module '@mappedin/blue-dot/blue-dot/src/blue-dot' {
14
- import { PubSub } from '@packages/internal/common';
14
+ import { PubSub } from '@packages/internal/common/pubsub';
15
15
  import type { MapView } from '@mappedin/mappedin-js';
16
16
  import type { BlueDotEventPayloads, BlueDotOptions, BlueDotPositionUpdate, BlueDotState, FollowCameraOptions, FollowMode } from '@mappedin/blue-dot/blue-dot/src/types';
17
17
  /**
@@ -220,7 +220,7 @@ declare module '@mappedin/blue-dot/blue-dot/src/types' {
220
220
  };
221
221
  export type BlueDotEvents = keyof BlueDotEventPayloads;
222
222
  export type BlueDotState = 'hidden' | 'active' | 'inactive' | 'disabled';
223
- export type BlueDotAction = 'timeout' | 'error' | 'position-update' | 'enable' | 'disable';
223
+ export type BlueDotAction = 'timeout' | 'error' | 'position-update' | 'enable' | 'disable' | 'initialize';
224
224
  export type BlueDotOptions = {
225
225
  /**
226
226
  * The radius of the BlueDot in pixels. The BlueDot will maintain this size clamped to a minimum of 0.35 metres.
@@ -517,6 +517,7 @@ declare module '@mappedin/blue-dot/packages/common/random-id' {
517
517
  */
518
518
  export const randomId: () => string;
519
519
  export function cyrb53(str: string, seed?: number): number;
520
+ export function shortId(): string;
520
521
  }
521
522
 
522
523
  declare module '@mappedin/blue-dot/packages/common/pubsub' {