@studiometa/ui-mapbox 1.10.0-beta.4 → 1.10.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/{AbstractMapboxControl.d.ts → dist/AbstractMapboxControl.d.ts} +1 -1
  2. package/{AbstractMapboxControl.js → dist/AbstractMapboxControl.js} +1 -1
  3. package/dist/AbstractMapboxControl.js.map +1 -0
  4. package/{AbstractMapboxMapChild.d.ts → dist/AbstractMapboxMapChild.d.ts} +3 -2
  5. package/{AbstractMapboxMapChild.js → dist/AbstractMapboxMapChild.js} +2 -2
  6. package/dist/AbstractMapboxMapChild.js.map +1 -0
  7. package/{MapboxCluster.d.ts → dist/MapboxCluster.d.ts} +1 -1
  8. package/{MapboxCluster.js → dist/MapboxCluster.js} +2 -2
  9. package/dist/MapboxCluster.js.map +1 -0
  10. package/{MapboxClusterItem.d.ts → dist/MapboxClusterItem.d.ts} +3 -2
  11. package/{MapboxClusterItem.js → dist/MapboxClusterItem.js} +2 -2
  12. package/dist/MapboxClusterItem.js.map +1 -0
  13. package/{MapboxFullscreenControl.d.ts → dist/MapboxFullscreenControl.d.ts} +1 -1
  14. package/{MapboxFullscreenControl.js → dist/MapboxFullscreenControl.js} +2 -2
  15. package/dist/MapboxFullscreenControl.js.map +1 -0
  16. package/{MapboxGeocoder.d.ts → dist/MapboxGeocoder.d.ts} +1 -1
  17. package/{MapboxGeocoder.js → dist/MapboxGeocoder.js} +1 -1
  18. package/dist/MapboxGeocoder.js.map +1 -0
  19. package/{MapboxGeolocateControl.d.ts → dist/MapboxGeolocateControl.d.ts} +1 -1
  20. package/{MapboxGeolocateControl.js → dist/MapboxGeolocateControl.js} +2 -2
  21. package/dist/MapboxGeolocateControl.js.map +1 -0
  22. package/{MapboxImage.d.ts → dist/MapboxImage.d.ts} +1 -1
  23. package/{MapboxImage.js → dist/MapboxImage.js} +1 -1
  24. package/dist/MapboxImage.js.map +1 -0
  25. package/{MapboxImages.d.ts → dist/MapboxImages.d.ts} +1 -1
  26. package/{MapboxImages.js → dist/MapboxImages.js} +1 -1
  27. package/dist/MapboxImages.js.map +1 -0
  28. package/{MapboxLayer.d.ts → dist/MapboxLayer.d.ts} +1 -1
  29. package/{MapboxLayer.js → dist/MapboxLayer.js} +1 -1
  30. package/dist/MapboxLayer.js.map +1 -0
  31. package/{MapboxMap.d.ts → dist/MapboxMap.d.ts} +3 -2
  32. package/{MapboxMap.js → dist/MapboxMap.js} +2 -2
  33. package/dist/MapboxMap.js.map +1 -0
  34. package/{MapboxMarker.d.ts → dist/MapboxMarker.d.ts} +1 -1
  35. package/{MapboxMarker.js → dist/MapboxMarker.js} +1 -1
  36. package/dist/MapboxMarker.js.map +1 -0
  37. package/{MapboxNavigationControl.d.ts → dist/MapboxNavigationControl.d.ts} +1 -1
  38. package/{MapboxNavigationControl.js → dist/MapboxNavigationControl.js} +2 -2
  39. package/dist/MapboxNavigationControl.js.map +1 -0
  40. package/{MapboxPopup.d.ts → dist/MapboxPopup.d.ts} +1 -1
  41. package/{MapboxPopup.js → dist/MapboxPopup.js} +1 -1
  42. package/dist/MapboxPopup.js.map +1 -0
  43. package/{MapboxSource.d.ts → dist/MapboxSource.d.ts} +1 -1
  44. package/{MapboxSource.js → dist/MapboxSource.js} +1 -1
  45. package/dist/MapboxSource.js.map +1 -0
  46. package/{StoreLocator.d.ts → dist/StoreLocator.d.ts} +3 -2
  47. package/{StoreLocator.js → dist/StoreLocator.js} +3 -3
  48. package/dist/StoreLocator.js.map +1 -0
  49. package/dist/autoload.d.ts +1 -0
  50. package/dist/autoload.js +7 -0
  51. package/dist/autoload.js.map +1 -0
  52. package/{catalog.d.ts → dist/catalog.d.ts} +2 -2
  53. package/dist/catalog.js.map +1 -0
  54. package/{dependencies.d.ts → dist/dependencies.d.ts} +1 -1
  55. package/{dependencies.js → dist/dependencies.js} +1 -1
  56. package/dist/dependencies.js.map +1 -0
  57. package/dist/manifest.d.ts +6 -0
  58. package/{manifest.js → dist/manifest.js} +1 -1
  59. package/dist/manifest.js.map +1 -0
  60. package/dist/scripts/manifest-types.d.ts +36 -0
  61. package/{utils.d.ts → dist/utils.d.ts} +1 -1
  62. package/{utils.js → dist/utils.js} +1 -1
  63. package/dist/utils.js.map +1 -0
  64. package/package.json +114 -19
  65. package/AbstractMapboxControl.js.map +0 -1
  66. package/AbstractMapboxMapChild.js.map +0 -1
  67. package/MapboxCluster.js.map +0 -1
  68. package/MapboxClusterItem.js.map +0 -1
  69. package/MapboxFullscreenControl.js.map +0 -1
  70. package/MapboxGeocoder.js.map +0 -1
  71. package/MapboxGeolocateControl.js.map +0 -1
  72. package/MapboxImage.js.map +0 -1
  73. package/MapboxImages.js.map +0 -1
  74. package/MapboxLayer.js.map +0 -1
  75. package/MapboxMap.js.map +0 -1
  76. package/MapboxMarker.js.map +0 -1
  77. package/MapboxNavigationControl.js.map +0 -1
  78. package/MapboxPopup.js.map +0 -1
  79. package/MapboxSource.js.map +0 -1
  80. package/StoreLocator.js.map +0 -1
  81. package/catalog.js.map +0 -1
  82. package/dependencies.js.map +0 -1
  83. package/manifest.d.ts +0 -6
  84. package/manifest.js.map +0 -1
  85. package/utils.js.map +0 -1
  86. /package/{catalog.js → dist/catalog.js} +0 -0
  87. /package/{index.d.ts → dist/index.d.ts} +0 -0
  88. /package/{index.js → dist/index.js} +0 -0
  89. /package/{index.js.map → dist/index.js.map} +0 -0
@@ -2,7 +2,7 @@ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractM
2
2
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import { ControlPosition, IControl } from "mapbox-gl";
4
4
 
5
- //#region AbstractMapboxControl.d.ts
5
+ //#region src/AbstractMapboxControl.d.ts
6
6
  interface AbstractMapboxControlProps extends AbstractMapboxMapChildProps {
7
7
  $options: {
8
8
  position: ControlPosition;
@@ -1,5 +1,5 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
- //#region AbstractMapboxControl.ts
2
+ //#region src/AbstractMapboxControl.ts
3
3
  /**
4
4
  * Base class for the Mapbox controls added to the map via `map.addControl`.
5
5
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractMapboxControl.js","names":[],"sources":["../src/AbstractMapboxControl.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { ControlPosition, IControl } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\n\nexport interface AbstractMapboxControlProps extends AbstractMapboxMapChildProps {\n $options: {\n position: ControlPosition;\n };\n}\n\n/**\n * Base class for the Mapbox controls added to the map via `map.addControl`.\n *\n * It centralizes the shared `position` option, the lazy control instantiation\n * and the add/remove lifecycle. Concrete controls only need to implement the\n * `createControl` method to build their specific `mapboxgl.*Control` instance.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class AbstractMapboxControl<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & AbstractMapboxControlProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'AbstractMapboxControl',\n options: {\n position: {\n type: String,\n default: 'top-right',\n },\n },\n };\n\n /**\n * Control instance.\n * @private\n */\n __control: IControl;\n\n /**\n * The mapbox control instance.\n */\n get control() {\n if (!this.__control) {\n const {\n position: _position,\n name: _name,\n debug: _debug,\n log: _log,\n ...options\n } = this.$options;\n this.__control = this.createControl(options);\n }\n\n return this.__control;\n }\n\n /**\n * Create the concrete mapbox control instance.\n *\n * Subclasses must implement this method to return their specific\n * `mapboxgl.*Control` instance built from the given options.\n *\n * @protected\n */\n createControl(_options: Record<string, unknown>): IControl {\n throw new Error('The `createControl` method must be implemented.');\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n map.addControl(this.control, this.$options.position);\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n if (this.__control) {\n this.__readyMap?.removeControl(this.__control);\n this.__control = undefined;\n }\n }\n}\n\nexport default AbstractMapboxControl;\n"],"mappings":";;;;;;;;;;;AAsBA,IAAa,wBAAb,cAA4E,uBAE1E;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS,EACP,UAAU;GACR,MAAM;GACN,SAAS;GACV,EACF;EACF;;;;;CAMD;;;;CAKA,IAAI,UAAU;AACZ,MAAI,CAAC,KAAK,WAAW;GACnB,MAAM,EACJ,UAAU,WACV,MAAM,OACN,OAAO,QACP,KAAK,MACL,GAAG,YACD,KAAK;AACT,QAAK,YAAY,KAAK,cAAc,QAAQ;;AAG9C,SAAO,KAAK;;;;;;;;;;CAWd,cAAc,UAA6C;AACzD,QAAM,IAAI,MAAM,kDAAkD;;;;;CAMpE,UAAU;AACR,OAAK,cAAc,QAAQ;AACzB,OAAI,WAAW,KAAK,SAAS,KAAK,SAAS,SAAS;IACpD;;;;;CAMJ,gBAAgB;AACd,MAAI,KAAK,WAAW;AAClB,QAAK,YAAY,cAAc,KAAK,UAAU;AAC9C,QAAK,YAAY,KAAA"}
@@ -1,8 +1,9 @@
1
1
  import { MapboxMap } from "./MapboxMap.js";
2
- import { Base, BaseConfig, BaseProps } from "@studiometa/js-toolkit";
2
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import { Map } from "mapbox-gl";
4
+ import { Base } from "@studiometa/js-toolkit/Base";
4
5
 
5
- //#region AbstractMapboxMapChild.d.ts
6
+ //#region src/AbstractMapboxMapChild.d.ts
6
7
  interface AbstractMapboxMapChildProps extends BaseProps {}
7
8
  /**
8
9
  * Document-level event a `MapboxMap` dispatches when its instance mounts, so a
@@ -1,5 +1,5 @@
1
- import { Base } from "@studiometa/js-toolkit";
2
- //#region AbstractMapboxMapChild.ts
1
+ import { Base } from "@studiometa/js-toolkit/Base";
2
+ //#region src/AbstractMapboxMapChild.ts
3
3
  /**
4
4
  * Document-level event a `MapboxMap` dispatches when its instance mounts, so a
5
5
  * child that mounted *before* its map (e.g. an eagerly registered child under a
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractMapboxMapChild.js","names":[],"sources":["../src/AbstractMapboxMapChild.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map } from 'mapbox-gl';\nimport type { MapboxMap } from './MapboxMap.js';\n\nexport interface AbstractMapboxMapChildProps extends BaseProps {}\n\n/**\n * Document-level event a `MapboxMap` dispatches when its instance mounts, so a\n * child that mounted *before* its map (e.g. an eagerly registered child under a\n * lazily imported map) can retry resolving its parent and inject itself once the\n * map is connected. The dispatching `MapboxMap` instance travels in `detail`.\n */\nexport const MAPBOX_MAP_CONNECTED = 'mapbox-map:connected';\n\n/**\n * Base class for every component living inside a `MapboxMap`.\n *\n * Children are self-sufficient and dynamic-DOM-native: they resolve their\n * parent `MapboxMap` on their own via `$closest`, wait for the map to be ready\n * with `whenMapReady`, then inject their contribution. Each component is\n * registered independently (e.g. with `registerComponent`, optionally behind a\n * lazy `importWhen*` helper); registration order does not matter because a child\n * resolves its map through the connected-event retry. Once registered,\n * js-toolkit's document-wide `MutationObserver` mounts them whenever their\n * element enters the DOM —\n * statically, `Fetch`-injected or `appendChild`-ed — and terminates them when it\n * leaves, at which point they remove their contribution again.\n *\n * The base hardens three things every child inherits, rather than relying on\n * per-subclass discipline:\n *\n * 1. **Guarded injection & teardown** — mapbox-gl throws readily (a duplicate\n * source id, any style-touching call after `map.remove()`), and js-toolkit's\n * global queue runs lifecycle hooks with no try/catch: a single synchronous\n * throw wedges the queue and freezes every mount/destroy on the page. The\n * ready callback and the subclass teardown (`__onDestroyed`) are both run\n * inside a try/catch that routes to `$warn` + a `map-error` event and never\n * rethrows.\n * 2. **Dead-map safety** — once ready, the child subscribes to the map's own\n * `remove` event; when it fires the cached map reference is dropped so no\n * teardown ever calls a method on a removed map (which throws `TypeError`).\n * 3. **Retryable, standing resolution** — resolution is not one-shot: a child\n * with no map yet waits for `MAPBOX_MAP_CONNECTED`, and a map destroy →\n * remount re-injects the child on the new map's next load.\n * 4. **Style-reload re-injection** — a `map.setStyle()` wipes the whole style\n * (every source/layer/sprite) while the map instance and the still-mounted\n * children survive, so the declarative resources would silently vanish. Once\n * ready, the child subscribes to the map's `style.load` — fired once per\n * style load, the Mapbox-recommended hook for re-adding custom sources/layers\n * when switching base style — and re-runs its injection so it re-adds its\n * contribution onto the fresh style (H7, PR #567 review). The re-run reuses\n * the same containment as the first injection and is guarded on the resource\n * already being present, so it never double-injects.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class AbstractMapboxMapChild<T extends BaseProps = BaseProps> extends Base<\n T & AbstractMapboxMapChildProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'AbstractMapboxMapChild',\n emits: ['map-error'],\n };\n\n /**\n * The parent `MapboxMap` resolved at ready-time.\n *\n * `destroyed()` runs *after* the element has been detached from the DOM (e.g.\n * a `Fetch` list swap, or the parent map itself being removed), and a\n * `$closest` lookup on a disconnected node returns nothing — a real bug that\n * would leave the child's contribution stuck on the map. Caching the resolved\n * references at ready-time keeps every teardown path working through the\n * detach.\n * @private\n */\n __readyMapboxMap?: MapboxMap;\n\n /**\n * The Mapbox `Map` instance resolved at ready-time, cached for teardown. It is\n * dropped as soon as the map's `remove` event fires so teardown never touches\n * a removed map.\n * @private\n */\n __readyMap?: Map;\n\n /**\n * The injection callback registered through `whenMapReady`, kept so it can be\n * re-run against a new map when the current one is destroyed and remounted.\n *\n * The callback may be synchronous or `async`: a returned promise is awaited\n * inside the same containment as a synchronous body, so a rejection routes to\n * `$warn` + the `map-error` event instead of surfacing as an unhandled rejection.\n * @private\n */\n __readyCallback?: (map: Map) => void | Promise<void>;\n\n /**\n * Off handler for a still-pending `map-load` subscription, flushed on destroy\n * so a child removed before the map finished loading leaves no listener behind.\n * @private\n */\n __offMapReady?: () => void;\n\n /**\n * Off handler for the ready map's `remove` subscription.\n * @private\n */\n __offMapRemove?: () => void;\n\n /**\n * Off handler for the ready map's `style.load` re-injection subscription.\n * @private\n */\n __offStyleReload?: () => void;\n\n /**\n * Off handler for the document-level `MAPBOX_MAP_CONNECTED` retry subscription.\n * @private\n */\n __offConnected?: () => void;\n\n /**\n * The closest parent `MapboxMap` component instance.\n */\n get mapboxMap() {\n const mapboxMap = this.$closest<MapboxMap>('MapboxMap');\n\n if (!mapboxMap) {\n this.$warn(\n 'Can not find the parent map, does this component has a parent MapboxMap component?',\n );\n }\n\n return mapboxMap;\n }\n\n /**\n * The Mapbox `Map` instance of the closest parent `MapboxMap` component.\n */\n get map() {\n return this.mapboxMap?.map;\n }\n\n /**\n * Run a callback once the parent map is ready — now, on the next `map-load`,\n * or once a `MapboxMap` connects if none exists yet.\n *\n * The callback is stored so it can be re-run on a fresh map after a destroy →\n * remount. It is wrapped so a throw never propagates into the global queue, is\n * never fired after the child has been destroyed, and the resolved\n * map/`MapboxMap` are cached before it runs so teardown can reach them even\n * once the element is detached.\n *\n * The callback may be `async`: a subclass that awaits (image loading, cluster\n * expansion, ...) must additionally guard against the map changing under it by\n * checking `this.__readyMap === map` after every `await`, since the map it was\n * handed can be removed — or replaced by another — while the promise is in\n * flight. A rejected promise is contained here, never rethrown.\n *\n * @param {(map: Map) => void | Promise<void>} cb The work to run against the ready map.\n */\n whenMapReady(cb: (map: Map) => void | Promise<void>): void {\n this.__readyCallback = cb;\n this.__resolveMap();\n }\n\n /**\n * Resolve the parent `MapboxMap` and bind to it, or wait for one to connect.\n * @private\n */\n __resolveMap(): void {\n const mapboxMap = this.$closest<MapboxMap>('MapboxMap');\n\n if (!mapboxMap) {\n this.__waitForConnectedMap();\n return;\n }\n\n this.__bindToMap(mapboxMap);\n }\n\n /**\n * Subscribe once to `MAPBOX_MAP_CONNECTED` and retry resolution when a map\n * whose element is an ancestor of this child connects.\n * @private\n */\n __waitForConnectedMap(): void {\n if (this.__offConnected) {\n return;\n }\n\n const handler = (event: Event) => {\n const mapboxMap = (event as CustomEvent<MapboxMap>).detail;\n\n // Ignore maps that are not an ancestor of this child: several independent\n // maps can live on the same page.\n if (!mapboxMap?.$el?.contains(this.$el)) {\n return;\n }\n\n this.__offConnected?.();\n this.__offConnected = undefined;\n this.__resolveMap();\n };\n\n document.addEventListener(MAPBOX_MAP_CONNECTED, handler);\n this.__offConnected = () => document.removeEventListener(MAPBOX_MAP_CONNECTED, handler);\n }\n\n /**\n * Bind to a resolved `MapboxMap`: run the ready callback now if its map is\n * already loaded, otherwise once on `map-load`.\n * @private\n * @param {MapboxMap} mapboxMap\n */\n __bindToMap(mapboxMap: MapboxMap): void {\n // Resolve the concrete map now and subscribe to its `remove` immediately.\n // Binding the remove handler here rather than after load means a map removed\n // *while its load is still pending* re-resolves the child onto a replacement\n // instead of stranding it: the pending `map-load` subscription is flushed and\n // the child parks on `MAPBOX_MAP_CONNECTED` again.\n const map = mapboxMap.map;\n\n // The parent's `MapboxMap` instance may exist while its concrete map is not\n // built yet: it resolves `mapbox-gl` asynchronously in `mounted()` before\n // creating the map. Keep waiting on `MAPBOX_MAP_CONNECTED`, which the map\n // dispatches once its instance exists, and bind then.\n if (!map) {\n this.__waitForConnectedMap();\n return;\n }\n\n // Drop any stale pending subscription before (re)binding.\n this.__offMapReady?.();\n this.__offMapReady = undefined;\n\n this.__bindMapRemove(map);\n this.__bindStyleReload(map);\n\n const run = () => {\n // The child may have been destroyed while waiting for the map to load: do\n // not inject anything into a map the child no longer belongs to.\n if (!this.$isMounted) {\n return;\n }\n\n this.__readyMapboxMap = mapboxMap;\n this.__readyMap = map;\n this.__runReadyCallback(map);\n };\n\n if (mapboxMap.isLoaded) {\n run();\n } else {\n this.__offMapReady = mapboxMap.$on(\n 'map-load',\n () => {\n this.__offMapReady = undefined;\n run();\n },\n { once: true },\n );\n }\n }\n\n /**\n * Run the ready callback inside a uniform containment for both synchronous\n * throws and rejected promises: a synchronous body is wrapped in `try/catch`,\n * and an `async` body's returned promise is awaited so its rejection routes to\n * `$warn` + the `map-error` event instead of becoming an unhandled rejection.\n * Neither path ever rethrows into the global lifecycle queue.\n * @private\n * @param {Map} map\n */\n __runReadyCallback(map: Map): void {\n let result: void | Promise<void>;\n\n try {\n result = this.__readyCallback?.(map);\n } catch (err) {\n this.__handleError(err);\n return;\n }\n\n if (result && typeof (result as Promise<void>).then === 'function') {\n Promise.resolve(result).catch((err) => this.__handleError(err));\n }\n }\n\n /**\n * Subscribe once to the map's own `remove` event so teardown never runs\n * against a removed map, and so the child re-injects on a remounted map.\n * @private\n * @param {Map} map\n */\n __bindMapRemove(map: Map): void {\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n\n // Degrade gracefully for minimal map doubles without an event emitter: a\n // real mapbox map always exposes `on`/`off`.\n if (typeof map?.on !== 'function') {\n return;\n }\n\n const handler = () => {\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n\n // Let the subclass flush any map-scoped listener while the map is still\n // referenceable: once `__readyMap` is cleared its teardown can no longer\n // reach the map to `off` them.\n try {\n this.__onMapRemove(map);\n } catch (err) {\n this.__handleError(err);\n }\n\n // A map removed before it finished loading still has a pending `map-load`\n // subscription on the (now dead) `MapboxMap`: flush it so the child does\n // not try to bind on a load that will never come.\n this.__offMapReady?.();\n this.__offMapReady = undefined;\n // The style-reload watch was bound to the now-dead map: drop it too so no\n // `style.load` re-injection ever fires against a removed map.\n this.__offStyleReload?.();\n this.__offStyleReload = undefined;\n this.__readyMap = undefined;\n this.__readyMapboxMap = undefined;\n\n // The map went away, not the child: wait for a new one to connect and\n // re-run the injection against it.\n if (this.$isMounted && this.__readyCallback) {\n this.__waitForConnectedMap();\n }\n };\n\n map.on('remove', handler);\n this.__offMapRemove = () => map.off('remove', handler);\n }\n\n /**\n * Subscribe to the map's `style.load` so the child re-runs its injection after\n * a `setStyle` replaces the whole style, re-adding the source/layer/sprite it\n * would otherwise have silently lost.\n *\n * `style.load` fires once per style load — Mapbox's own recommended hook for\n * re-adding custom sources and layers when switching base style — so it does\n * not need the `styledata` de-duplication a broader `styledata` handler would.\n * The handler bails until the child has actually finished its first injection\n * on this map (`__readyMap === map`): at the *initial* style load `__readyMap`\n * is not set yet (the first injection runs on `map-load`), so this never\n * double-injects on mount and only re-injects on a genuine later `setStyle`.\n * @private\n * @param {Map} map\n */\n __bindStyleReload(map: Map): void {\n this.__offStyleReload?.();\n this.__offStyleReload = undefined;\n\n // Degrade gracefully for minimal map doubles without an event emitter.\n if (typeof map?.on !== 'function') {\n return;\n }\n\n const handler = () => {\n // Only re-inject once the first injection has run against this very map,\n // and only while still mounted with work to do. Re-runs against a map the\n // child no longer owns (removed/replaced) are the `remove` path's job.\n if (!this.$isMounted || !this.__readyCallback || this.__readyMap !== map) {\n return;\n }\n\n // Reuse the first-injection containment. Each subclass callback guards on\n // whether its resource is already present (`getSource`/`getLayer`/\n // `hasImage`), so re-running is safe and re-claims ownership with a fresh\n // liveness probe against the new style.\n this.__runReadyCallback(map);\n };\n\n map.on('style.load', handler);\n this.__offStyleReload = () => map.off('style.load', handler);\n }\n\n /**\n * Contain an error raised by a guarded injection or teardown: warn and emit an\n * `map-error` event, but never rethrow into the global queue.\n * @private\n * @param {unknown} err\n */\n __handleError(err: unknown): void {\n this.$warn(err);\n this.$emit('map-error', err);\n }\n\n /**\n * Hook run when the ready map fires its own `remove` event, while the map is\n * still referenceable (before `__readyMap` is cleared).\n *\n * Subclasses that attach map-scoped listeners (a layer waiting on\n * `sourcedata`, a cluster's per-layer click/hover handlers) override this to\n * `off` them against the map they were bound to — the removed map — since\n * their `__onDestroyed` runs later with `__readyMap` already `undefined` and\n * could not reach the map to unsubscribe.\n * @protected\n * @param {Map} _map The map being removed.\n */\n __onMapRemove(_map: Map) {}\n\n /**\n * Teardown hook implemented by subclasses instead of `destroyed()`.\n *\n * It runs inside the base's guard (see `destroyed`) so a throwing teardown — a\n * style-touching mapbox call, most often — can never wedge the global queue.\n * Implementations read the cached `__readyMap`, which is already `undefined`\n * when the map has been removed, and must not call `super`.\n * @protected\n */\n __onDestroyed() {}\n\n /**\n * Destroyed hook.\n *\n * Runs the guarded subclass teardown, then flushes every base subscription\n * (`map-load`, the map's `remove`, the connected retry). Subclasses override\n * `__onDestroyed` rather than this method.\n */\n destroyed() {\n try {\n this.__onDestroyed();\n } catch (err) {\n this.__handleError(err);\n }\n\n this.__offMapReady?.();\n this.__offMapReady = undefined;\n this.__offMapRemove?.();\n this.__offMapRemove = undefined;\n this.__offStyleReload?.();\n this.__offStyleReload = undefined;\n this.__offConnected?.();\n this.__offConnected = undefined;\n this.__readyCallback = undefined;\n }\n}\n\nexport default AbstractMapboxMapChild;\n"],"mappings":";;;;;;;;AAaA,MAAa,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CpC,IAAa,yBAAb,cAA6E,KAE3E;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,YAAY;EACrB;;;;;;;;;;;;CAaD;;;;;;;CAQA;;;;;;;;;;CAWA;;;;;;CAOA;;;;;CAMA;;;;;CAMA;;;;;CAMA;;;;CAKA,IAAI,YAAY;EACd,MAAM,YAAY,KAAK,SAAoB,YAAY;AAEvD,MAAI,CAAC,UACH,MAAK,MACH,qFACD;AAGH,SAAO;;;;;CAMT,IAAI,MAAM;AACR,SAAO,KAAK,WAAW;;;;;;;;;;;;;;;;;;;;CAqBzB,aAAa,IAA8C;AACzD,OAAK,kBAAkB;AACvB,OAAK,cAAc;;;;;;CAOrB,eAAqB;EACnB,MAAM,YAAY,KAAK,SAAoB,YAAY;AAEvD,MAAI,CAAC,WAAW;AACd,QAAK,uBAAuB;AAC5B;;AAGF,OAAK,YAAY,UAAU;;;;;;;CAQ7B,wBAA8B;AAC5B,MAAI,KAAK,eACP;EAGF,MAAM,WAAW,UAAiB;AAKhC,OAAI,CAJe,MAAiC,QAIpC,KAAK,SAAS,KAAK,IAAI,CACrC;AAGF,QAAK,kBAAkB;AACvB,QAAK,iBA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AAI,KAAK,cAAc,KAAK,gBAC1B,MAAK,uBAAuB;;AAIhC,MAAI,GAAG,UAAU,QAAQ;AACzB,OAAK,uBAAuB,IAAI,IAAI,UAAU,QAAQ;;;;;;;;;;;;;;;;;CAkBxD,kBAAkB,KAAgB;AAChC,OAAK,oBAAoB;AACzB,OAAK,mBAAmB,KAAA;AAGxB,MAAI,OAAO,KAAK,OAAO,WACrB;EAGF,MAAM,gBAAgB;AAIpB,OAAI,CAAC,KAAK,cAAc,CAAC,KAAK,mBAAmB,KAAK,eAAe,IACnE;AAOF,QAAK,mBAAmB,IAAI;;AAG9B,MAAI,GAAG,cAAc,QAAQ;AAC7B,OAAK,yBAAyB,IAAI,IAAI,cAAc,QAAQ;;;;;;;;CAS9D,cAAc,KAAoB;AAChC,OAAK,MAAM,IAAI;AACf,OAAK,MAAM,aAAa,IAAI;;;;;;;;;;;;;;CAe9B,cAAc,MAAW;;;;;;;;;;CAWzB,gBAAgB;;;;;;;;CAShB,YAAY;AACV,MAAI;AACF,QAAK,eAAe;WACb,KAAK;AACZ,QAAK,cAAc,IAAI;;AAGzB,OAAK,iBAAiB;AACtB,OAAK,gBAAgB,KAAA;AACrB,OAAK,kBAAkB;AACvB,OAAK,iBAAiB,KAAA;AACtB,OAAK,oBAAoB;AACzB,OAAK,mBAAmB,KAAA;AACxB,OAAK,kBAAkB;AACvB,OAAK,iBAAiB,KAAA;AACtB,OAAK,kBAAkB,KAAA"}
@@ -4,7 +4,7 @@ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
4
  import { CircleLayerSpecification, GeoJSONSourceSpecification, Map, MapMouseEvent, SymbolLayerSpecification } from "mapbox-gl";
5
5
  import { FeatureCollection, Point } from "geojson";
6
6
 
7
- //#region MapboxCluster.d.ts
7
+ //#region src/MapboxCluster.d.ts
8
8
  /**
9
9
  * Document-level event a `MapboxCluster` dispatches when its instance mounts, so
10
10
  * a `MapboxClusterItem` that mounted *before* its cluster can retry resolving it
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
- import { debounce } from "@studiometa/js-toolkit/utils";
3
- //#region MapboxCluster.ts
2
+ import { debounce } from "@studiometa/js-toolkit/utils/debounce";
3
+ //#region src/MapboxCluster.ts
4
4
  /**
5
5
  * Document-level event a `MapboxCluster` dispatches when its instance mounts, so
6
6
  * a `MapboxClusterItem` that mounted *before* its cluster can retry resolving it
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxCluster.js","names":[],"sources":["../src/MapboxCluster.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport { debounce } from '@studiometa/js-toolkit/utils/debounce';\nimport type {\n Map,\n CircleLayerSpecification,\n SymbolLayerSpecification,\n LayerSpecification,\n FilterSpecification,\n GeoJSONSourceSpecification,\n GeoJSONSource,\n MapMouseEvent,\n LngLatLike,\n} from 'mapbox-gl';\nimport type { FeatureCollection, Point } from 'geojson';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport type { MapboxClusterItem } from './MapboxClusterItem.js';\n\n/**\n * Document-level event a `MapboxCluster` dispatches when its instance mounts, so\n * a `MapboxClusterItem` that mounted *before* its cluster can retry resolving it\n * and register itself once the cluster is connected. The dispatching\n * `MapboxCluster` instance travels in `detail`.\n */\nexport const MAPBOX_CLUSTER_CONNECTED = 'mapbox-cluster:connected';\n\n/**\n * Module level counter used to generate a unique base id per instance.\n */\nlet clusterCount = 0;\n\n/**\n * Generate the next unique cluster base id.\n * @returns {string}\n */\nfunction nextClusterId(): string {\n const id = `mb-cluster-${clusterCount}`;\n clusterCount += 1;\n return id;\n}\n\nexport interface MapboxClusterProps extends AbstractMapboxMapChildProps {\n $options: {\n clusterMaxZoom: number;\n clusterRadius: number;\n clusterMinPoints: number;\n clusterProperties: Record<string, unknown>;\n clustersLayout: CircleLayerSpecification['layout'];\n clustersPaint: CircleLayerSpecification['paint'];\n clusterCountLayout: SymbolLayerSpecification['layout'];\n clusterCountPaint: SymbolLayerSpecification['paint'];\n unclusteredPointLayerType: string;\n unclusteredPointLayout: Record<string, unknown>;\n unclusteredPointPaint: Record<string, unknown>;\n };\n}\n\n/**\n * A clustered GeoJSON **source driver** whose features ARE its rendered items.\n *\n * `MapboxCluster` merges the map source and the sidebar list of a classic\n * \"store locator\" into a single declarative unit: `MapboxClusterItem`s (rendered\n * list entries living outside the map) push themselves into the cluster's\n * registry, and the cluster derives its clustered GeoJSON source from that\n * registry. Items self-register, the cluster rebuilds (debounced) on every\n * registry change, gated on `whenMapReady`, and nothing observes or `$query`s.\n *\n * The cluster is deliberately **thin**: it owns only the map data and the\n * clustering interaction (a clustered source, the three layers and the\n * click-to-zoom on clusters). It does **not** select, fly to, filter by viewport\n * or open popups — those search-UX concerns belong to the optional\n * [`StoreLocator`](./StoreLocator.js) orchestrator, which drives them on top of a\n * cluster. Used standalone, a `MapboxCluster` still renders a working clustered\n * map + list (points render, clusters zoom on click); it simply reports a click\n * on an unclustered point through the `map-item-click` event and lets the caller\n * decide what it means.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxCluster<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxClusterProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxCluster',\n emits: ['map-cluster-click', 'map-item-click', 'map-update'],\n options: {\n clusterMaxZoom: {\n type: Number,\n default: 14,\n },\n clusterRadius: {\n type: Number,\n default: 50,\n },\n clusterMinPoints: {\n type: Number,\n default: 2,\n },\n clusterProperties: {\n type: Object,\n default: () => ({}),\n },\n clustersLayout: {\n type: Object,\n default: () => ({}),\n },\n clustersPaint: {\n type: Object,\n default: () => ({\n 'circle-color': '#000',\n 'circle-radius': 40,\n }),\n },\n clusterCountLayout: {\n type: Object,\n default: () => ({\n 'text-field': ['get', 'point_count_abbreviated'],\n }),\n },\n clusterCountPaint: {\n type: Object,\n default: () => ({\n 'text-color': 'white',\n }),\n },\n unclusteredPointLayerType: {\n type: String,\n default: 'circle',\n },\n unclusteredPointLayout: {\n type: Object,\n default: () => ({}),\n },\n unclusteredPointPaint: {\n type: Object,\n default: () => ({\n 'circle-color': '#000',\n 'circle-radius': 4,\n }),\n },\n },\n };\n\n /**\n * Unique base id for this instance.\n * @private\n */\n __id = nextClusterId();\n\n /**\n * Live registry of the mounted `MapboxClusterItem`s, in registration order.\n * @private\n */\n __items: MapboxClusterItem[] = [];\n\n /**\n * The registered `MapboxClusterItem`s, in registration order.\n *\n * Read-only surface for an orchestrator (e.g. `StoreLocator`) that needs to\n * iterate the item set for viewport filtering, distance sorting or selection —\n * the cluster owns the registry, consumers only read it. A defensive copy is\n * returned so a consumer can not splice the live registry (which would corrupt\n * click resolution and source generation without scheduling a rebuild).\n */\n get items(): readonly MapboxClusterItem[] {\n return [...this.__items];\n }\n\n /**\n * Derive an id for the given suffix from the instance base id.\n * @private\n * @param {string} suffix\n * @returns {string}\n */\n __getId(suffix: string): string {\n return `${this.__id}-${suffix}`;\n }\n\n /**\n * The GeoJSON `FeatureCollection` derived from the whole registered item set.\n *\n * This is the single source of truth pushed to the map source and only changes\n * when the item set changes — panning must never rebuild it.\n */\n get featureCollection(): FeatureCollection<Point, Record<string, unknown>> {\n return {\n type: 'FeatureCollection',\n features: this.__items.map((item) => ({\n type: 'Feature',\n geometry: {\n type: 'Point',\n coordinates: item.lngLat,\n },\n properties: {\n ...item.properties,\n id: item.id,\n },\n })),\n };\n }\n\n /**\n * Register an item and schedule a coalesced rebuild so a batch of\n * registrations (e.g. a `Fetch` list swap) results in a single map update.\n * @param {MapboxClusterItem} item\n */\n register(item: MapboxClusterItem) {\n if (!this.__items.includes(item)) {\n this.__items.push(item);\n this.__scheduleRebuild();\n }\n }\n\n /**\n * Unregister an item and schedule a coalesced rebuild.\n * @param {MapboxClusterItem} item\n */\n unregister(item: MapboxClusterItem) {\n const index = this.__items.indexOf(item);\n\n if (index > -1) {\n this.__items.splice(index, 1);\n this.__scheduleRebuild();\n }\n }\n\n /**\n * Replace the live source data directly, bypassing the item registry.\n *\n * Kept for manual/imperative control; the common path is to let registered\n * items drive the data. Safe to call before mount or after teardown.\n *\n * NOTE: this bypasses the registry-is-source invariant, so anything pushed\n * here is transient — the next registry rebuild (any item mount/unmount, or a\n * debounced `__scheduleRebuild`) derives the source from `featureCollection`\n * again and silently overwrites it. Use it only for one-off imperative\n * overlays that do not need to survive an item-set change.\n *\n * @param {GeoJSONSourceSpecification['data']} data\n */\n setData(data: GeoJSONSourceSpecification['data']) {\n const source = this.__readyMap?.getSource<GeoJSONSource>(this.__getId('source'));\n\n if (source && typeof source.setData === 'function') {\n source.setData(data);\n }\n }\n\n /**\n * Coalesce rebuilds into a single trailing call, so a batch of registrations\n * spanning multiple ticks results in one map data update.\n * @private\n */\n __scheduleRebuild = debounce(() => {\n if (this.$isMounted) {\n this.__rebuild();\n }\n }, 100);\n\n /**\n * Push the derived feature collection to the source and announce the change.\n * No-op until the map is ready (the initial build happens in `whenMapReady`).\n * @private\n */\n __rebuild() {\n const map = this.__readyMap;\n\n if (!map) {\n return;\n }\n\n this.setData(this.featureCollection as GeoJSONSourceSpecification['data']);\n // Let an orchestrator react to the new item set (fit the map, refilter the\n // list). The cluster itself never fits or filters — it only reports.\n this.$emit('map-update', this.items);\n }\n\n /**\n * Click handler for the clusters layer, zooming on the clicked cluster.\n * @private\n */\n __handleClustersClick = (event: MapMouseEvent) => {\n const map = this.__readyMap;\n\n if (!map) {\n return;\n }\n\n const feature = map.queryRenderedFeatures(event.point, {\n layers: [this.__getId('clusters')],\n })[0];\n\n if (!feature) {\n return;\n }\n\n const clusterId = feature.properties?.cluster_id as number;\n\n this.$emit('map-cluster-click', clusterId, event);\n\n if (event.defaultPrevented) {\n return;\n }\n\n const source = map.getSource<GeoJSONSource>(this.__getId('source'));\n\n source?.getClusterExpansionZoom(clusterId, (error, zoom) => {\n // The expansion zoom resolves asynchronously: the map may have been\n // removed (or replaced) in the meantime, in which case the base cleared\n // `__readyMap`. Bail unless the captured map is still the current one so\n // `easeTo` never runs against a dead map.\n if (\n this.__readyMap !== map ||\n error ||\n zoom === null ||\n zoom === undefined ||\n feature.geometry.type !== 'Point'\n ) {\n return;\n }\n\n map.easeTo({\n center: feature.geometry.coordinates as LngLatLike,\n zoom,\n });\n });\n };\n\n /**\n * Set the map canvas cursor, guarding against a missing map.\n * @private\n * @param {string} cursor\n */\n __setCursor(cursor: string) {\n const canvas = this.__readyMap?.getCanvas();\n\n if (canvas) {\n canvas.style.cursor = cursor;\n }\n }\n\n /**\n * Set a pointer cursor when entering the clusters layer.\n * @private\n */\n __handleClustersMouseenter = () => {\n this.__setCursor('pointer');\n };\n\n /**\n * Reset the cursor when leaving the clusters layer.\n * @private\n */\n __handleClustersMouseleave = () => {\n this.__setCursor('');\n };\n\n /**\n * Report a click on an unclustered point: resolve the feature back to the\n * registered item behind it and emit `map-item-click`. The cluster makes no\n * decision about what a click means — an orchestrator (e.g. `StoreLocator`)\n * listens and selects, opens a popup, etc.\n * @private\n */\n __handleUnclusteredClick = (event: MapMouseEvent) => {\n const feature = event.features?.[0];\n const id = feature?.properties?.id;\n const item =\n id === undefined || id === null\n ? undefined\n : this.__items.find((candidate) => candidate.id === String(id));\n\n this.$emit('map-item-click', item, feature, event);\n };\n\n /**\n * Set a pointer cursor when entering an unclustered point.\n * @private\n */\n __handleUnclusteredMouseenter = () => {\n this.__setCursor('pointer');\n };\n\n /**\n * Reset the cursor when leaving an unclustered point.\n * @private\n */\n __handleUnclusteredMouseleave = () => {\n this.__setCursor('');\n };\n\n /**\n * Mounted hook: build the source and layers, wire the clustering interaction\n * and announce the initial item set — all once the map is ready.\n */\n mounted() {\n // Announce the cluster so any `MapboxClusterItem` that mounted before it —\n // and is waiting on `MAPBOX_CLUSTER_CONNECTED` — can register now. Items\n // register independently of map readiness, so this fires outside the\n // `whenMapReady` gate.\n document.dispatchEvent(new CustomEvent(MAPBOX_CLUSTER_CONNECTED, { detail: this }));\n\n this.whenMapReady((map) => this.__inject(map));\n }\n\n /**\n * Build the clustered source and its three layers and wire the clustering\n * interaction — idempotently, so it can run both on first readiness and on a\n * `style.load` re-injection after a `setStyle` wiped the style (H7, PR #567\n * review).\n *\n * A `setStyle` clears sources and layers but leaves layer-scoped map listeners\n * attached (they live on the map's event emitter, not the style), so this\n * guards `addSource`/`addLayer` against an already-present resource and\n * detaches every listener before re-attaching it — re-running never duplicates\n * a listener nor throws a duplicate-id error.\n * @private\n * @param {Map} map\n */\n __inject(map: Map) {\n const {\n clusterMaxZoom,\n clusterRadius,\n clusterMinPoints,\n clusterProperties,\n clustersLayout,\n clustersPaint,\n clusterCountLayout,\n clusterCountPaint,\n unclusteredPointLayerType,\n unclusteredPointLayout,\n unclusteredPointPaint,\n } = this.$options;\n\n const sourceId = this.__getId('source');\n const clustersId = this.__getId('clusters');\n const clusterCountId = this.__getId('cluster-count');\n const unclusteredPointId = this.__getId('unclustered-point');\n const clustersFilter = ['has', 'point_count'] as FilterSpecification;\n const unclusteredFilter = ['!', ['has', 'point_count']] as FilterSpecification;\n\n const source: GeoJSONSourceSpecification = {\n type: 'geojson',\n cluster: true,\n // Seed the source with the currently-registered items. Items registered\n // before the map was ready are already in `__items`, so the first render\n // is correct without waiting for a debounced rebuild.\n data: this.featureCollection,\n clusterMaxZoom,\n clusterRadius,\n clusterMinPoints,\n clusterProperties,\n };\n\n const clustersLayer: CircleLayerSpecification = {\n id: clustersId,\n type: 'circle',\n source: sourceId,\n filter: clustersFilter,\n layout: clustersLayout,\n paint: clustersPaint,\n };\n\n const clusterCountLayer: SymbolLayerSpecification = {\n id: clusterCountId,\n type: 'symbol',\n source: sourceId,\n filter: clustersFilter,\n layout: clusterCountLayout,\n paint: clusterCountPaint,\n };\n\n const unclusteredPointLayer = {\n id: unclusteredPointId,\n type: unclusteredPointLayerType,\n source: sourceId,\n filter: unclusteredFilter,\n layout: unclusteredPointLayout,\n paint: unclusteredPointPaint,\n } as unknown as LayerSpecification;\n\n if (!map.getSource(sourceId)) {\n map.addSource(sourceId, source);\n }\n for (const layer of [clustersLayer, clusterCountLayer, unclusteredPointLayer]) {\n if (!map.getLayer(layer.id)) {\n map.addLayer(layer);\n }\n }\n\n // Detach before attaching so a re-injection never doubles a listener.\n this.__offClusterListeners(map);\n map.on('click', clustersId, this.__handleClustersClick);\n map.on('mouseenter', clustersId, this.__handleClustersMouseenter);\n map.on('mouseleave', clustersId, this.__handleClustersMouseleave);\n map.on('click', unclusteredPointId, this.__handleUnclusteredClick);\n map.on('mouseenter', unclusteredPointId, this.__handleUnclusteredMouseenter);\n map.on('mouseleave', unclusteredPointId, this.__handleUnclusteredMouseleave);\n\n // Announce the seeded item set so an orchestrator can run its first fit +\n // viewport filter against a cluster that was already populated at load.\n this.$emit('map-update', this.items);\n }\n\n /**\n * Detach every map-scoped listener wired in `mounted`.\n * @private\n * @param {Map} map\n */\n __offClusterListeners(map: Map) {\n const clustersId = this.__getId('clusters');\n const unclusteredPointId = this.__getId('unclustered-point');\n\n map.off('click', clustersId, this.__handleClustersClick);\n map.off('mouseenter', clustersId, this.__handleClustersMouseenter);\n map.off('mouseleave', clustersId, this.__handleClustersMouseleave);\n map.off('click', unclusteredPointId, this.__handleUnclusteredClick);\n map.off('mouseenter', unclusteredPointId, this.__handleUnclusteredMouseenter);\n map.off('mouseleave', unclusteredPointId, this.__handleUnclusteredMouseleave);\n }\n\n /**\n * Flush the per-layer listeners against the map being removed, while it is\n * still referenceable — `__onDestroyed` runs later with `__readyMap` already\n * cleared and could not reach the map to unsubscribe.\n * @protected\n * @param {Map} map\n */\n __onMapRemove(map: Map) {\n this.__offClusterListeners(map);\n }\n\n /**\n * Teardown hook: tear down listeners, layers and source.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n\n if (map) {\n const clustersId = this.__getId('clusters');\n const clusterCountId = this.__getId('cluster-count');\n const unclusteredPointId = this.__getId('unclustered-point');\n const sourceId = this.__getId('source');\n\n this.__offClusterListeners(map);\n\n for (const id of [clustersId, clusterCountId, unclusteredPointId]) {\n if (map.getLayer(id)) {\n map.removeLayer(id);\n }\n }\n\n if (map.getSource(sourceId)) {\n map.removeSource(sourceId);\n }\n }\n\n this.__items = [];\n }\n}\n\nexport default MapboxCluster;\n"],"mappings":";;;;;;;;;AA0BA,MAAa,2BAA2B;;;;AAKxC,IAAI,eAAe;;;;;AAMnB,SAAS,gBAAwB;CAC/B,MAAM,KAAK,cAAc;AACzB,iBAAgB;AAChB,QAAO;;;;;;;;;;;;;;;;;;;;;;;;AAyCT,IAAa,gBAAb,cAAoE,uBAElE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO;GAAC;GAAqB;GAAkB;GAAa;EAC5D,SAAS;GACP,gBAAgB;IACd,MAAM;IACN,SAAS;IACV;GACD,eAAe;IACb,MAAM;IACN,SAAS;IACV;GACD,kBAAkB;IAChB,MAAM;IACN,SAAS;IACV;GACD,mBAAmB;IACjB,MAAM;IACN,gBAAgB,EAAE;IACnB;GACD,gBAAgB;IACd,MAAM;IACN,gBAAgB,EAAE;IACnB;GACD,eAAe;IACb,MAAM;IACN,gBAAgB;KACd,gBAAgB;KAChB,iBAAiB;KAClB;IACF;GACD,oBAAoB;IAClB,MAAM;IACN,gBAAgB,EACd,cAAc,CAAC,OAAO,0BAA0B,EACjD;IACF;GACD,mBAAmB;IACjB,MAAM;IACN,gBAAgB,EACd,cAAc,SACf;IACF;GACD,2BAA2B;IACzB,MAAM;IACN,SAAS;IACV;GACD,wBAAwB;IACtB,MAAM;IACN,gBAAgB,EAAE;IACnB;GACD,uBAAuB;IACrB,MAAM;IACN,gBAAgB;KACd,gBAAgB;KAChB,iBAAiB;KAClB;IACF;GACF;EACF;;;;;CAMD,OAAO,eAAe;;;;;CAMtB,UAA+B,EAAE;;;;;;;;;;CAWjC,IAAI,QAAsC;AACxC,SAAO,CAAC,GAAG,KAAK,QAAQ;;;;;;;;CAS1B,QAAQ,QAAwB;AAC9B,SAAO,GAAG,K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KAAK,8BAA8B;AAC7E,MAAI,IAAI,cAAc,oBAAoB,KAAK,8BAA8B;;;;;;;;;CAU/E,cAAc,KAAU;AACtB,OAAK,sBAAsB,IAAI;;;;;CAMjC,gBAAgB;EACd,MAAM,MAAM,KAAK;AAEjB,MAAI,KAAK;GACP,MAAM,aAAa,KAAK,QAAQ,WAAW;GAC3C,MAAM,iBAAiB,KAAK,QAAQ,gBAAgB;GACpD,MAAM,qBAAqB,KAAK,QAAQ,oBAAoB;GAC5D,MAAM,WAAW,KAAK,QAAQ,SAAS;AAEvC,QAAK,sBAAsB,IAAI;AAE/B,QAAK,MAAM,MAAM;IAAC;IAAY;IAAgB;IAAmB,CAC/D,KAAI,IAAI,SAAS,GAAG,CAClB,KAAI,YAAY,GAAG;AAIvB,OAAI,IAAI,UAAU,SAAS,CACzB,KAAI,aAAa,SAAS;;AAI9B,OAAK,UAAU,EAAE"}
@@ -1,7 +1,8 @@
1
1
  import { MapboxCluster } from "./MapboxCluster.js";
2
- import { Base, BaseConfig, BaseProps } from "@studiometa/js-toolkit";
2
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
+ import { Base } from "@studiometa/js-toolkit/Base";
3
4
 
4
- //#region MapboxClusterItem.d.ts
5
+ //#region src/MapboxClusterItem.d.ts
5
6
  interface MapboxClusterItemProps extends BaseProps {
6
7
  $options: {
7
8
  id: string;
@@ -1,6 +1,6 @@
1
1
  import { MAPBOX_CLUSTER_CONNECTED } from "./MapboxCluster.js";
2
- import { Base } from "@studiometa/js-toolkit";
3
- //#region MapboxClusterItem.ts
2
+ import { Base } from "@studiometa/js-toolkit/Base";
3
+ //#region src/MapboxClusterItem.ts
4
4
  /**
5
5
  * A single entry of a `MapboxCluster`.
6
6
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxClusterItem.js","names":[],"sources":["../src/MapboxClusterItem.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { MAPBOX_CLUSTER_CONNECTED, type MapboxCluster } from './MapboxCluster.js';\n\nexport interface MapboxClusterItemProps extends BaseProps {\n $options: {\n id: string;\n lngLat: [number, number];\n properties: Record<string, unknown>;\n };\n}\n\n/**\n * A single entry of a `MapboxCluster`.\n *\n * Unlike the other `@studiometa/ui-mapbox` components, this one is a **rendered**\n * element (e.g. a list `<li>` in a sidebar) and does not extend\n * `AbstractMapboxMapChild`: its DOM lives outside the `MapboxMap` element, so its\n * context is the parent `MapboxCluster` — resolved via `$closest('MapboxCluster')`\n * — rather than a map.\n *\n * It is at once the list item AND the map feature: the cluster derives its\n * GeoJSON source from the set of registered items, so the same markup drives\n * both the sidebar and the clustered points on the map. The child PUSHES itself\n * to the cluster on mount (`register`) and PULLS itself out on destroy\n * (`unregister`), so the cluster never has to query for its children.\n *\n * The component is headless and passive: it never selects itself. The state\n * setters below reflect state as data-attributes on `$el` so the integrator can\n * style the item with plain CSS, and they are driven by whoever coordinates the\n * experience — a [`StoreLocator`](./StoreLocator.js) orchestrator on `moveend`\n * and on selection, if one wraps the cluster:\n *\n * - `data-in-bounds` — present when the item's `lngLat` is inside the current\n * map viewport (list-visibility signal).\n * - `data-active` + `aria-current=\"true\"` — present when the item is selected.\n *\n * Used under a bare `MapboxCluster` (no orchestrator) the item still registers\n * and renders as a clustered point; it just carries no selection affordance of\n * its own — a click is reported by the cluster's `map-item-click` event for a\n * caller to act on.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxClusterItem<T extends BaseProps = BaseProps> extends Base<\n T & MapboxClusterItemProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxClusterItem',\n emits: ['map-error'],\n options: {\n id: String,\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n properties: {\n type: Object,\n default: () => ({}),\n },\n },\n };\n\n /**\n * The parent `MapboxCluster` resolved at mount, cached so the item can still\n * reach it on destroy.\n *\n * `destroyed()` runs *after* the element has been detached from the DOM (e.g.\n * a `Fetch` list swap), and a `$closest` lookup on a disconnected node returns\n * nothing — which would leave the removed item registered and its feature\n * stuck on the map. Caching the reference keeps the unregister path working.\n * @private\n */\n __cluster?: MapboxCluster;\n\n /**\n * Off handler for the document-level `MAPBOX_CLUSTER_CONNECTED` retry\n * subscription, used when the item mounts before its cluster.\n * @private\n */\n __offClusterConnected?: () => void;\n\n /**\n * The item's stable identifier, used to match map features back to the item.\n *\n * Expected to be non-empty and unique within a cluster. Duplicate ids are not\n * rejected, but their behavior is defined rather than undefined: a click on\n * any duplicate resolves to the FIRST registered item carrying that id (see\n * `MapboxCluster.__handleUnclusteredClick`). Integrators wanting a distinct\n * selection per element must give each item a unique id.\n */\n get id(): string {\n return this.$options.id;\n }\n\n /**\n * The item's coordinates as a `[lng, lat]` tuple.\n */\n get lngLat(): [number, number] {\n return this.$options.lngLat;\n }\n\n /**\n * Extra feature properties merged into the item's GeoJSON feature.\n */\n get properties(): Record<string, unknown> {\n return this.$options.properties;\n }\n\n /**\n * The HTML used as the map popup content when this item is selected.\n *\n * Uses the inner HTML of an optional `[data-ref=\"popup\"]` element when present\n * so the sidebar card and the map popup can differ, otherwise falls back to\n * the item's whole inner HTML.\n */\n get popupContent(): string {\n const ref = this.$el.querySelector('[data-ref=\"popup\"]');\n return (ref ?? this.$el).innerHTML.trim();\n }\n\n /**\n * Mounted hook: resolve the parent cluster and register with it.\n */\n mounted() {\n this.__resolveCluster();\n }\n\n /**\n * Resolve the parent `MapboxCluster` and register, or wait for one to connect.\n *\n * Resolution is retryable: an item eagerly registered under a lazily imported\n * cluster mounts first and finds nothing, so it waits for\n * `MAPBOX_CLUSTER_CONNECTED` and registers once its cluster is up.\n * @private\n */\n __resolveCluster() {\n const cluster = this.$closest<MapboxCluster>('MapboxCluster');\n\n if (!cluster) {\n this.__waitForConnectedCluster();\n return;\n }\n\n this.__cluster = cluster;\n cluster.register(this);\n }\n\n /**\n * Subscribe once to `MAPBOX_CLUSTER_CONNECTED` and retry resolution when a\n * cluster whose element is an ancestor of this item connects.\n * @private\n */\n __waitForConnectedCluster() {\n if (this.__offClusterConnected) {\n return;\n }\n\n const handler = (event: Event) => {\n const cluster = (event as CustomEvent<MapboxCluster>).detail;\n\n if (!cluster?.$el?.contains(this.$el)) {\n return;\n }\n\n this.__offClusterConnected?.();\n this.__offClusterConnected = undefined;\n this.__resolveCluster();\n };\n\n document.addEventListener(MAPBOX_CLUSTER_CONNECTED, handler);\n this.__offClusterConnected = () =>\n document.removeEventListener(MAPBOX_CLUSTER_CONNECTED, handler);\n }\n\n /**\n * Destroyed hook: unregister from the cached cluster, even if the element has\n * already been detached from the DOM, and drop any pending retry subscription.\n */\n destroyed() {\n try {\n this.__cluster?.unregister(this);\n } catch (err) {\n this.$warn(err);\n this.$emit('map-error', err);\n }\n\n this.__cluster = undefined;\n this.__offClusterConnected?.();\n this.__offClusterConnected = undefined;\n }\n\n /**\n * Reflect the \"in the current map viewport\" state as a `data-in-bounds`\n * attribute. Called by a `StoreLocator` orchestrator on every map `moveend`.\n * @param {boolean} value\n */\n setInBounds(value: boolean) {\n this.$el.toggleAttribute('data-in-bounds', value);\n }\n\n /**\n * Reflect the \"selected/active\" state as a `data-active` attribute and the\n * `aria-current` state. Called by a `StoreLocator` orchestrator on selection.\n * @param {boolean} value\n */\n setActive(value: boolean) {\n this.$el.toggleAttribute('data-active', value);\n\n if (value) {\n this.$el.setAttribute('aria-current', 'true');\n } else {\n this.$el.removeAttribute('aria-current');\n }\n }\n}\n\nexport default MapboxClusterItem;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,oBAAb,cAAwE,KAEtE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,YAAY;EACpB,SAAS;GACP,IAAI;GACJ,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF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js_toolkit0 from "@studiometa/js-toolkit";
3
3
  import * as mapbox_gl0 from "mapbox-gl";
4
4
  import { FullscreenControlOptions } from "mapbox-gl";
5
5
 
6
- //#region MapboxFullscreenControl.d.ts
6
+ //#region src/MapboxFullscreenControl.d.ts
7
7
  interface MapboxFullscreenControlProps extends AbstractMapboxControlProps {}
8
8
  declare const MapboxFullscreenControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
9
9
  /**
@@ -1,7 +1,7 @@
1
1
  import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- import { withExtraConfig } from "@studiometa/js-toolkit";
4
- //#region MapboxFullscreenControl.ts
3
+ import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
4
+ //#region src/MapboxFullscreenControl.ts
5
5
  /**
6
6
  * Add a fullscreen control to the map.
7
7
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxFullscreenControl.js","names":[],"sources":["../src/MapboxFullscreenControl.ts"],"sourcesContent":["import { withExtraConfig } from '@studiometa/js-toolkit/withExtraConfig';\nimport type { FullscreenControlOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxControl,\n type AbstractMapboxControlProps,\n} from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxFullscreenControlProps extends AbstractMapboxControlProps {}\n\n/**\n * Add a fullscreen control to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxFullscreenControl extends withExtraConfig(AbstractMapboxControl, {\n name: 'MapboxFullscreenControl',\n}) {\n /**\n * Create the mapbox FullscreenControl instance.\n * @protected\n */\n createControl(options: FullscreenControlOptions) {\n return new (getMapboxGl().FullscreenControl)(options);\n }\n}\n\nexport default MapboxFullscreenControl;\n"],"mappings":";;;;;;;;AAcA,IAAa,0BAAb,cAA6C,gBAAgB,uBAAuB,EAClF,MAAM,2BACP,CAAC,CAAC;;;;;CAKD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
@@ -3,7 +3,7 @@ import { MapboxGeocoderControl } from "./dependencies.js";
3
3
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
4
  import { Map } from "mapbox-gl";
5
5
 
6
- //#region MapboxGeocoder.d.ts
6
+ //#region src/MapboxGeocoder.d.ts
7
7
  interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {
8
8
  $options: {
9
9
  /**
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { getMapboxGl, resolveMapboxGeocoder } from "./dependencies.js";
3
- //#region MapboxGeocoder.ts
3
+ //#region src/MapboxGeocoder.ts
4
4
  /**
5
5
  * Add a geocoder control to the map.
6
6
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxGeocoder.js","names":[],"sources":["../src/MapboxGeocoder.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { Map, IControl } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport {\n getMapboxGl,\n resolveMapboxGeocoder,\n type MapboxGeocoderControl,\n} from './dependencies.js';\n\nexport interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * Wether to add the geocoder to the map or to the component's root element.\n */\n addToMap: boolean;\n /**\n * All MapboxGeocoder options, except the non serializable ones.\n *\n * Typed structurally (rather than with the optional geocoder peer types) to\n * keep the peer out of the public type surface. Refer to the Mapbox geocoder\n * package documentation (API.md#parameters) for the accepted options.\n */\n options: Record<string, unknown>;\n };\n}\n\n/**\n * Add a geocoder control to the map.\n *\n * The Mapbox geocoder module is an optional peer dependency and is loaded on\n * demand with a dynamic `import()` when the component mounts, so the rest of the\n * package keeps working without it installed.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxGeocoder<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxGeocoderProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxGeocoder',\n emits: ['map-result'],\n options: {\n addToMap: Boolean,\n options: Object,\n },\n };\n\n /**\n * Control instance, created once the lazily imported module resolves.\n * @private\n */\n __control?: MapboxGeocoderControl;\n\n /**\n * The Mapbox geocoder control instance, if it has been created yet.\n */\n get control(): MapboxGeocoderControl | undefined {\n return this.__control;\n }\n\n /**\n * Target element the geocoder is added to: the map when `addToMap` is set,\n * otherwise the component's own root element.\n */\n get target(): Map | HTMLElement | string {\n return this.$options.addToMap ? this.map : this.$el;\n }\n\n /**\n * Mounted hook.\n *\n * Lazily loads the optional Mapbox geocoder module, then builds and adds the\n * control once the parent map is ready.\n */\n async mounted() {\n const GeocoderControlClass = await resolveMapboxGeocoder();\n\n // The component may have been destroyed while the dynamic import was still\n // resolving. Bail out before creating and adding the control, otherwise it\n // would be attached after `destroyed()` already ran (and saw `__control`\n // undefined), leaking an orphan control.\n if (!this.$isMounted) {\n return;\n }\n\n this.whenMapReady(() => {\n // The ready callback is standing: it re-runs on every map replacement. An\n // element-targeted control (`addToMap` false) lives on `$el`, which\n // survives the map swap, so a previous control must be removed first or\n // each replacement would stack another geocoder onto the element. A\n // map-targeted control went away with its (removed) map, so only its\n // reference needs dropping.\n if (this.__control) {\n if (!this.$options.addToMap) {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n\n const options = {\n ...this.$options.options,\n mapboxgl: getMapboxGl(),\n accessToken:\n this.$options.options.accessToken ?? this.__readyMapboxMap?.$options.accessToken,\n };\n this.__control = new GeocoderControlClass(\n options as ConstructorParameters<typeof GeocoderControlClass>[0],\n );\n // Re-emit the control's `result` event as a prefixed component event so\n // consumers (e.g. a `StoreLocator`) can react to a geocoded address.\n this.__control.on?.('result', (event) => this.$emit('map-result', event.result));\n this.__control.addTo(this.target);\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n // The control may not exist yet: the dynamic import in `mounted()` might not\n // have resolved, or the geocoder module was never loaded.\n if (this.__control) {\n if (this.$options.addToMap) {\n this.__readyMap?.removeControl(this.__control as unknown as IControl);\n } else {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n }\n}\n\nexport default MapboxGeocoder;\n"],"mappings":";;;;;;;;;;;;AAsCA,IAAa,iBAAb,cAAqE,uBAEnE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,aAAa;EACrB,SAAS;GACP,UAAU;GACV,SAAS;GACV;EACF;;;;;CAMD;;;;CAKA,IAAI,UAA6C;AAC/C,SAAO,KAAK;;;;;;CAOd,IAAI,SAAqC;AACvC,SAAO,KAAK,SAAS,WAAW,KAAK,MAAM,KAAK;;;;;;;;CASlD,MAAM,UAAU;EACd,MAAM,uBAAuB,MAAM,uBAAuB;AAM1D,MAAI,CAAC,KAAK,WACR;AAGF,OAAK,mBAAmB;AAOtB,OAAI,KAAK,WAAW;AAClB,QAAI,CAAC,KAAK,SAAS,SACjB,MAAK,UAAU,UAAU;AAE3B,SAAK,YAAY,KAAA;;AASnB,QAAK,YAAY,IAAI,qBANL;IACd,GAAG,KAAK,SAAS;IACjB,UAAU,aAAa;IACvB,aACE,KAAK,SAAS,QAAQ,eAAe,KAAK,kBAAkB,SAAS;IACxE,CAGA;AAGD,QAAK,UAAU,KAAK,WAAW,UAAU,KAAK,MAAM,cAAc,MAAM,OAAO,CAAC;AAChF,QAAK,UAAU,MAAM,KAAK,OAAO;IACjC;;;;;CAMJ,gBAAgB;AAGd,MAAI,KAAK,WAAW;AAClB,OAAI,KAAK,SAAS,SAChB,MAAK,YAAY,cAAc,KAAK,UAAiC;OAErE,MAAK,UAAU,UAAU;AAE3B,QAAK,YAAY,KAAA"}
@@ -3,7 +3,7 @@ import * as _studiometa_js_toolkit0 from "@studiometa/js-toolkit";
3
3
  import * as mapbox_gl0 from "mapbox-gl";
4
4
  import { GeolocateControlOptions } from "mapbox-gl";
5
5
 
6
- //#region MapboxGeolocateControl.d.ts
6
+ //#region src/MapboxGeolocateControl.d.ts
7
7
  interface MapboxGeolocateControlProps extends AbstractMapboxControlProps {
8
8
  $options: AbstractMapboxControlProps['$options'] & Omit<GeolocateControlOptions, 'geolocation'>;
9
9
  }
@@ -1,7 +1,7 @@
1
1
  import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- import { withExtraConfig } from "@studiometa/js-toolkit";
4
- //#region MapboxGeolocateControl.ts
3
+ import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
4
+ //#region src/MapboxGeolocateControl.ts
5
5
  /**
6
6
  * Add a geolocate control to the map.
7
7
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxGeolocateControl.js","names":[],"sources":["../src/MapboxGeolocateControl.ts"],"sourcesContent":["import { withExtraConfig } from '@studiometa/js-toolkit/withExtraConfig';\nimport type { GeolocateControlOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxControl,\n type AbstractMapboxControlProps,\n} from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxGeolocateControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & Omit<GeolocateControlOptions, 'geolocation'>;\n}\n\n/**\n * Add a geolocate control to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxGeolocateControl extends withExtraConfig(AbstractMapboxControl, {\n name: 'MapboxGeolocateControl',\n options: {\n positionOptions: Object,\n fitBoundsOptions: Object,\n trackUserLocation: Boolean,\n showAccuracyCircle: Boolean,\n showUserLocation: Boolean,\n showUserHeading: Boolean,\n },\n}) {\n /**\n * Create the mapbox GeolocateControl instance.\n * @protected\n */\n createControl(options: GeolocateControlOptions) {\n return new (getMapboxGl().GeolocateControl)(options);\n }\n}\n\nexport default MapboxGeolocateControl;\n"],"mappings":";;;;;;;;AAgBA,IAAa,yBAAb,cAA4C,gBAAgB,uBAAuB;CACjF,MAAM;CACN,SAAS;EACP,iBAAiB;EACjB,kBAAkB;EAClB,mBAAmB;EACnB,oBAAoB;EACpB,kBAAkB;EAClB,iBAAiB;EAClB;CACF,CAAC,CAAC;;;;;CAKD,cAAc,SAAkC;AAC9C,SAAO,KAAK,aAAa,EAAC,iBAAkB,QAAQ"}
@@ -2,7 +2,7 @@ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractM
2
2
  import { MapboxImageOptions } from "./utils.js";
3
3
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
4
 
5
- //#region MapboxImage.d.ts
5
+ //#region src/MapboxImage.d.ts
6
6
  interface MapboxImageProps extends AbstractMapboxMapChildProps {
7
7
  $options: {
8
8
  name: string;
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { addMapboxImage, claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from "./utils.js";
3
- //#region MapboxImage.ts
3
+ //#region src/MapboxImage.ts
4
4
  /**
5
5
  * Load and register a single image against the map sprite.
6
6
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxImage.js","names":[],"sources":["../src/MapboxImage.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport {\n addMapboxImage,\n claimMapboxOwnership,\n getMapboxOwner,\n releaseMapboxOwnership,\n type MapboxImageOptions,\n} from './utils.js';\n\nexport interface MapboxImageProps extends AbstractMapboxMapChildProps {\n $options: {\n name: string;\n url: string;\n /**\n * The image options forwarded to `map.addImage`.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addimage\n */\n options: MapboxImageOptions;\n };\n}\n\n/**\n * Load and register a single image against the map sprite.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxImage<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxImageProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxImage',\n emits: ['map-ready'],\n options: {\n name: String,\n url: String,\n options: {\n type: Object,\n default: () => ({ pixelRatio: 1, sdf: false }),\n },\n },\n };\n\n /**\n * Whether this instance owns the sprite under its name. Only a sprite this\n * instance owns may be removed on teardown; a pre-existing sprite declared\n * outside the family is left untouched, and a sprite a newer sibling has since\n * adopted (a same-name `Fetch` swap) is left to that sibling.\n * @private\n */\n __owned = false;\n\n /**\n * The `kind:name` ownership key for this sprite.\n * @private\n */\n get __ownershipKey(): string {\n return `image:${this.$options.name}`;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady(async (map) => {\n const { name, url, options } = this.$options;\n const { image, added } = await addMapboxImage(map, { name, url, options });\n\n // The component may have been destroyed — or the map removed/replaced —\n // while the image was loading. Undo the add (only when THIS call added it,\n // and only while the map is still current & alive; a removed map took its\n // sprites with it) and bail before emitting so no orphan sprite survives.\n if (!this.$isMounted || this.__readyMap !== map) {\n if (added && this.__readyMap === map && map.hasImage(name)) {\n map.removeImage(name);\n }\n return;\n }\n\n // Own the sprite when we added it, or adopt it from a family sibling — a\n // same-name `Fetch` swap that added the sprite before this instance\n // mounted — so the outgoing instance's teardown does not remove the sprite\n // this mounted replacement now depends on. An unowned external sprite is\n // left untouched (and unclaimed).\n if (added || getMapboxOwner(map, this.__ownershipKey)) {\n // Sprites expose no object identity, so liveness can only probe\n // `hasImage`: enough to drop the entry after a `setStyle` wipe or an\n // external `removeImage`, and to re-own on a `style.load` re-injection.\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.hasImage(name));\n this.__owned = true;\n }\n\n this.$emit('map-ready', { name, image, options });\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const { name } = this.$options;\n const map = this.__readyMap;\n\n // Only remove a sprite this instance still owns: a newer sibling may have\n // adopted the name, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__owned &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.hasImage(name)\n ) {\n map.removeImage(name);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxImage;\n"],"mappings":";;;;;;;AA6BA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,YAAY;EACpB,SAAS;GACP,MAAM;GACN,KAAK;GACL,SAAS;IACP,MAAM;IACN,gBAAgB;KAAE,YAAY;KAAG,KAAK;KAAO;IAC9C;GACF;EACF;;;;;;;;CASD,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,SAAS,KAAK,SAAS;;;;;CAMhC,UAAU;AACR,OAAK,aAAa,OAAO,QAAQ;GAC/B,MAAM,EAAE,MAAM,KAAK,YAAY,KAAK;GACpC,MAAM,EAAE,OAAO,UAAU,MAAM,eAAe,KAAK;IAAE;IAAM;IAAK;IAAS,CAAC;AAM1E,OAAI,CAAC,KAAK,cAAc,KAAK,eAAe,KAAK;AAC/C,QAAI,SAAS,KAAK,eAAe,OAAO,IAAI,SAAS,KAAK,CACxD,KAAI,YAAY,KAAK;AAEvB;;AAQF,OAAI,SAAS,eAAe,KAAK,KAAK,eAAe,EAAE;AAIrD,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,KAAK,CAAC;AAC9E,SAAK,UAAU;;AAGjB,QAAK,MAAM,aAAa;IAAE;IAAM;IAAO;IAAS,CAAC;IACjD;;;;;CAMJ,gBAAgB;EACd,MAAM,EAAE,SAAS,KAAK;EACtB,MAAM,MAAM,KAAK;AAIjB,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,SAAS,KAAK,EACnB;AACA,OAAI,YAAY,KAAK;AACrB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
@@ -3,7 +3,7 @@ import { MapboxImageDefinition } from "./utils.js";
3
3
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
4
  import { Map } from "mapbox-gl";
5
5
 
6
- //#region MapboxImages.d.ts
6
+ //#region src/MapboxImages.d.ts
7
7
  interface MapboxImagesProps extends AbstractMapboxMapChildProps {
8
8
  $options: {
9
9
  /**
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { addMapboxImage, claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from "./utils.js";
3
- //#region MapboxImages.ts
3
+ //#region src/MapboxImages.ts
4
4
  /**
5
5
  * Load and register a list of images against the map sprite.
6
6
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxImages.js","names":[],"sources":["../src/MapboxImages.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport type { Map } from 'mapbox-gl';\nimport {\n addMapboxImage,\n claimMapboxOwnership,\n getMapboxOwner,\n releaseMapboxOwnership,\n type MapboxImageDefinition,\n} from './utils.js';\n\nexport interface MapboxImagesProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * A list of images to register against the map sprite.\n * @see ./MapboxImage.ts\n */\n sources: MapboxImageDefinition[];\n };\n}\n\n/**\n * Load and register a list of images against the map sprite.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxImages<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxImagesProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxImages',\n emits: ['map-ready'],\n options: {\n sources: {\n type: Array,\n default: () => [],\n },\n },\n };\n\n /**\n * The names of the sprites this instance owns. Only these may be removed on\n * teardown; pre-existing sprites (registered by someone else) are left\n * untouched, and a sprite a newer sibling has since adopted is left to it.\n * @private\n */\n __ownedNames: string[] = [];\n\n /**\n * The `kind:name` ownership key for the given sprite.\n * @private\n * @param {string} name\n * @returns {string}\n */\n __ownershipKey(name: string): string {\n return `image:${name}`;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady(async (map) => {\n const { sources } = this.$options;\n const images = await Promise.all(\n sources.map(async (source) => {\n const { image, added } = await addMapboxImage(map, source);\n // Take ownership incrementally, as each image settles, rather than\n // after the whole batch: if a later entry rejects, `Promise.all`\n // rejects, but the sprites already added stay owned and removable on\n // teardown instead of orphaned.\n this.__adopt(map, source.name, added);\n return image;\n }),\n );\n\n // The component may have been destroyed — or the map removed/replaced —\n // while the images were loading. Remove the ones we own (only while the\n // map is still current & alive) and bail before emitting to avoid orphans.\n if (!this.$isMounted || this.__readyMap !== map) {\n if (this.__readyMap === map) {\n this.__removeOwned(map);\n }\n return;\n }\n\n this.$emit('map-ready', images);\n });\n }\n\n /**\n * Own a sprite this instance added, or adopt one from a family sibling (a\n * same-name `Fetch` swap), so the outgoing instance's teardown does not remove\n * a sprite this replacement now depends on.\n * @private\n * @param {Map} map\n * @param {string} name\n * @param {boolean} added\n */\n __adopt(map: Map, name: string, added: boolean) {\n if (added || getMapboxOwner(map, this.__ownershipKey(name))) {\n // Sprites expose no object identity, so liveness can only probe\n // `hasImage`: enough to drop the entry after a `setStyle` wipe or an\n // external `removeImage`, and to re-own on a `style.load` re-injection.\n claimMapboxOwnership(map, this.__ownershipKey(name), this, () => map.hasImage(name));\n if (!this.__ownedNames.includes(name)) {\n this.__ownedNames.push(name);\n }\n }\n }\n\n /**\n * Remove every sprite this instance still owns from the given map, releasing\n * ownership as it goes.\n * @private\n * @param {Map | undefined} map\n */\n __removeOwned(map?: Map) {\n for (const name of this.__ownedNames) {\n const key = this.__ownershipKey(name);\n if (getMapboxOwner(map as object, key) === this && map?.hasImage(name)) {\n map.removeImage(name);\n releaseMapboxOwnership(map, key, this);\n }\n }\n this.__ownedNames = [];\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__removeOwned(this.__readyMap);\n }\n}\n\nexport default MapboxImages;\n"],"mappings":";;;;;;;AA4BA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,YAAY;EACpB,SAAS,EACP,SAAS;GACP,MAAM;GACN,eAAe,EAAE;GAClB,EACF;EACF;;;;;;;CAQD,eAAyB,EAAE;;;;;;;CAQ3B,eAAe,MAAsB;AACnC,SAAO,SAAS;;;;;CAMlB,UAAU;AACR,OAAK,aAAa,OAAO,QAAQ;GAC/B,MAAM,EAAE,YAAY,KAAK;GACzB,MAAM,SAAS,MAAM,QAAQ,IAC3B,QAAQ,IAAI,OAAO,WAAW;IAC5B,MAAM,EAAE,OAAO,UAAU,MAAM,eAAe,KAAK,OAAO;AAK1D,SAAK,QAAQ,KAAK,OAAO,MAAM,MAAM;AACrC,WAAO;KACP,CACH;AAKD,OAAI,CAAC,KAAK,cAAc,KAAK,eAAe,KAAK;AAC/C,QAAI,KAAK,eAAe,IACtB,MAAK,cAAc,IAAI;AAEzB;;AAGF,QAAK,MAAM,aAAa,OAAO;IAC/B;;;;;;;;;;;CAYJ,QAAQ,KAAU,MAAc,OAAgB;AAC9C,MAAI,SAAS,eAAe,KAAK,KAAK,eAAe,KAAK,CAAC,EAAE;AAI3D,wBAAqB,KAAK,KAAK,eAAe,KAAK,EAAE,YAAY,IAAI,SAAS,KAAK,CAAC;AACpF,OAAI,CAAC,KAAK,aAAa,SAAS,KAAK,CACnC,MAAK,aAAa,KAAK,KAAK;;;;;;;;;CAWlC,cAAc,KAAW;AACvB,OAAK,MAAM,QAAQ,KAAK,cAAc;GACpC,MAAM,MAAM,KAAK,eAAe,KAAK;AACrC,OAAI,eAAe,KAAe,IAAI,KAAK,QAAQ,KAAK,SAAS,KAAK,EAAE;AACtE,QAAI,YAAY,KAAK;AACrB,2BAAuB,KAAK,KAAK,KAAK;;;AAG1C,OAAK,eAAe,EAAE;;;;;CAMxB,gBAAgB;AACd,OAAK,cAAc,KAAK,WAAW"}
@@ -2,7 +2,7 @@ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractM
2
2
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import { LayerSpecification, Map, MapSourceDataEvent } from "mapbox-gl";
4
4
 
5
- //#region MapboxLayer.d.ts
5
+ //#region src/MapboxLayer.d.ts
6
6
  interface MapboxLayerProps extends AbstractMapboxMapChildProps {
7
7
  $options: {
8
8
  id: string;
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from "./utils.js";
3
- //#region MapboxLayer.ts
3
+ //#region src/MapboxLayer.ts
4
4
  /**
5
5
  * Add a layer to the map.
6
6
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxLayer.js","names":[],"sources":["../src/MapboxLayer.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { LayerSpecification, Map, MapSourceDataEvent } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxLayerProps extends AbstractMapboxMapChildProps {\n $options: {\n id: string;\n layer: LayerSpecification;\n beforeId: string;\n };\n}\n\n/**\n * Add a layer to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxLayer<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxLayerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxLayer',\n options: {\n id: String,\n layer: Object,\n beforeId: String,\n },\n };\n\n /**\n * Whether this instance owns the layer under its id. Only a layer this\n * instance owns may be removed on teardown; a layer declared outside the\n * family, or one a newer sibling has since adopted, is left untouched.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this layer.\n * @private\n */\n get __ownershipKey(): string {\n return `layer:${this.$options.id}`;\n }\n\n /**\n * The source id this layer references, when it references one by string.\n * @private\n */\n get __sourceId(): string | undefined {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source === 'string' ? source : undefined;\n }\n\n /**\n * Add (or re-add) the layer whenever its referenced source becomes available\n * and the layer is not currently on the map.\n *\n * This is a *standing* recovery watch, not a one-shot: it stays subscribed for\n * the layer's whole life so the layer re-commits itself if its source\n * disappears and comes back — e.g. a sibling `MapboxSource` teardown removes\n * this still-mounted layer to drop its source, then the source is re-added\n * later (H7, PR #567 review). Committing once and unsubscribing (the previous\n * behaviour) left such a layer gone for good.\n *\n * It is kept cheap: `sourcedata` fires often, so the handler early-returns\n * unless this layer is actually missing, and — when the event identifies a\n * source — ignores events for any source other than this layer's. The commit\n * itself is deferred to a microtask because mutating the style from within\n * mapbox-gl's render loop can leave a layer half-initialized and crash the\n * symbol placement pass.\n * @private\n * @param {MapSourceDataEvent} [event]\n */\n __handleSourceData = (event?: MapSourceDataEvent) => {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Ignore events for an unrelated source when the event tells us which one it\n // is: this gates the standing watch to this layer's source id.\n if (event?.sourceId && this.__sourceId && event.sourceId !== this.__sourceId) {\n return;\n }\n\n if (!map || map.getLayer(id) || !this.__sourceIsAvailable(map)) {\n return;\n }\n\n queueMicrotask(() => {\n // Re-check under the microtask: the map may have been removed/replaced, the\n // component destroyed, or the layer committed by another path in between.\n if (this.$isMounted && this.__readyMap === map && !map.getLayer(id)) {\n this.__commitLayer(map);\n }\n });\n };\n\n /**\n * Add the layer to the map, or adopt an existing one.\n *\n * When the id is free the layer is added and ownership claimed. When a layer\n * with this id already exists, re-adding it would throw a duplicate-id error,\n * so it is left in place; ownership is only taken over from a sibling\n * `MapboxLayer` (e.g. a `Fetch` swap), never from an externally declared layer.\n * @private\n * @param {Map} map\n */\n __commitLayer(map: Map): void {\n const { beforeId, id, layer } = this.$options;\n // `$options.layer` returns a freshly parsed object, so re-apply the id.\n layer.id = id;\n\n if (map.getLayer(id)) {\n // The id is taken. Only adopt it from another family instance (e.g. a\n // `Fetch` swap that mounted the replacement before the original tore\n // down); an externally declared layer stays untouched. Adopt AND refresh:\n // the incoming definition may differ in source/type/paint/layout/filter/\n // zoom range/beforeId, so re-add it (we own it) rather than leaving Mapbox\n // rendering the outgoing definition — matching how `MapboxSource` refreshes\n // its data on adopt.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n map.removeLayer(id);\n map.addLayer(layer, beforeId);\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n return;\n }\n\n map.addLayer(layer, beforeId);\n // Own the id, keyed to the very layer object just added: the liveness probe\n // reports the entry stale the moment this layer is removed (a `setStyle`\n // wipe, a sibling source teardown, an external `removeLayer`) or replaced\n // under the same id, so it can never misclassify a stranger's later layer.\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n\n /**\n * Whether the source referenced by the layer is available on the map.\n *\n * Layers referencing an inline source object — or no source at all, like a\n * `background` layer — are always considered available.\n * @private\n * @param {Map} map\n * @returns {boolean}\n */\n __sourceIsAvailable(map: Map): boolean {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source !== 'string' || Boolean(map.getSource(source));\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n // Install (or re-install, on a `style.load` re-injection) the standing\n // recovery watch exactly once. `off` before `on` keeps a single\n // subscription when `whenMapReady`'s callback re-runs after a `setStyle`.\n map.off('sourcedata', this.__handleSourceData);\n map.on('sourcedata', this.__handleSourceData);\n\n // The referenced source may be declared by a sibling `MapboxSource` that\n // has not mounted yet — sibling mount order is not guaranteed. Adding a\n // layer before its source silently fails, so commit now when the source is\n // available and otherwise let the standing watch commit once it arrives.\n if (this.__sourceIsAvailable(map)) {\n this.__commitLayer(map);\n }\n });\n }\n\n /**\n * Flush the standing `sourcedata` recovery watch against the map being\n * removed, while it is still referenceable — `__onDestroyed` runs later with\n * `__readyMap` already cleared and could not reach the map to unsubscribe.\n * @protected\n * @param {Map} map\n */\n __onMapRemove(map: Map) {\n map.off('sourcedata', this.__handleSourceData);\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n map?.off('sourcedata', this.__handleSourceData);\n\n // Only remove a layer this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getLayer(id)\n ) {\n map.removeLayer(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxLayer;\n"],"mappings":";;;;;;;AAoBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,IAAI;GACJ,OAAO;GACP,UAAU;GACX;EACF;;;;;;;CAQD,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,SAAS,KAAK,SAAS;;;;;;CAOhC,IAAI,aAAiC;EACnC,MAAM,EAAE,WAAW,KAAK,SAAS;AACjC,SAAO,OAAO,WAAW,WAAW,SAAS,KAAA;;;;;;;;;;;;;;;;;;;;;;CAuB/C,sBAAsB,UAA+B;EACnD,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MAAI,OAAO,YAAY,KAAK,cAAc,MAAM,aAAa,KAAK,WAChE;AAGF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AK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,SAAS,GAAG,EACjB;AACA,OAAI,YAAY,GAAG;AACnB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
@@ -1,7 +1,8 @@
1
- import { Base, BaseConfig, BaseProps } from "@studiometa/js-toolkit";
1
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
2
2
  import { Map, MapOptions } from "mapbox-gl";
3
+ import { Base } from "@studiometa/js-toolkit/Base";
3
4
 
4
- //#region MapboxMap.d.ts
5
+ //#region src/MapboxMap.d.ts
5
6
  interface MapboxMapProps extends BaseProps {
6
7
  $refs: {
7
8
  container: HTMLElement;
@@ -1,7 +1,7 @@
1
1
  import { MAPBOX_MAP_CONNECTED } from "./AbstractMapboxMapChild.js";
2
2
  import { resolveMapboxGl } from "./dependencies.js";
3
- import { Base } from "@studiometa/js-toolkit";
4
- //#region MapboxMap.ts
3
+ import { Base } from "@studiometa/js-toolkit/Base";
4
+ //#region src/MapboxMap.ts
5
5
  const FORWARDED_MAP_EVENTS = [
6
6
  "click",
7
7
  "dblclick",
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxMap.js","names":[],"sources":["../src/MapboxMap.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map, MapOptions } from 'mapbox-gl';\nimport { resolveMapboxGl } from './dependencies.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\n\nconst FORWARDED_MAP_EVENTS = [\n 'click',\n 'dblclick',\n 'mouseenter',\n 'mouseleave',\n 'mousemove',\n 'movestart',\n 'move',\n 'moveend',\n 'zoomstart',\n 'zoom',\n 'zoomend',\n 'rotatestart',\n 'rotate',\n 'rotateend',\n 'pitchstart',\n 'pitch',\n 'pitchend',\n 'dragstart',\n 'drag',\n 'dragend',\n 'idle',\n 'render',\n 'resize',\n 'remove',\n 'error',\n] as const;\n\nexport interface MapboxMapProps extends BaseProps {\n $refs: {\n container: HTMLElement;\n };\n $options: {\n accessToken: string;\n zoom: number;\n center: [number, number];\n mapOptions: Partial<Omit<MapOptions, 'container'>>;\n };\n}\n\n/**\n * Display a Mapbox GL map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMap',\n emits: ['map-load', ...FORWARDED_MAP_EVENTS.map((event) => `map-${event}`)],\n refs: ['container'],\n options: {\n accessToken: String,\n zoom: Number,\n center: {\n type: Array,\n default: () => [0, 0],\n },\n // Any other `mapbox-gl` `Map` option — including `style`, `pitch`,\n // `bearing`, `bounds`, ... — spread as-is into the `Map` constructor. The\n // convenience options above act as overridable defaults, while `container`\n // is always resolved from the component and can not be overridden.\n mapOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n // `MapboxMap` no longer declares its children. Each child component\n // (markers, popups, controls, sources, layers, clusters, ...) is registered\n // globally and resolves this map on its own via `$closest('MapboxMap')`,\n // then waits for readiness through `AbstractMapboxMapChild.whenMapReady`.\n // This makes the whole family dynamic-DOM-native: a child appended under a\n // map at any time mounts and injects itself, and cleans up when removed.\n };\n\n /**\n * Is the map loaded?\n */\n isLoaded = false;\n\n /**\n * Map instance, or `undefined` until it is built in `mounted()` and once it is\n * cleared on teardown.\n * @private\n */\n __map: Map | undefined;\n\n /**\n * Off handles for every forwarding listener attached to the map, flushed on\n * teardown so a retained reference to a removed `Map` does not keep this\n * component (and its `$emit` closures) alive.\n * @private\n */\n __offMapListeners: Array<() => void> = [];\n\n /**\n * The mapbox Map instance, or `undefined` until it has been built.\n *\n * The map is built in `mounted()` after `mapbox-gl` resolves (it may be\n * injected or lazily imported), so this getter returns `undefined` while that\n * resolution is still pending. Children read it after the map announces itself\n * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.\n */\n get map(): Map | undefined {\n return this.__map;\n }\n\n /**\n * Mounted hook.\n *\n * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then\n * announces it so children can inject themselves.\n */\n async mounted() {\n const mapboxgl = await resolveMapboxGl();\n\n // The component may have been destroyed while `mapbox-gl` was resolving: bail\n // out before building a map that nothing would ever tear down.\n if (!this.$isMounted) {\n return;\n }\n\n const map = new mapboxgl.Map({\n accessToken: this.$options.accessToken,\n zoom: this.$options.zoom,\n center: this.$options.center,\n ...this.$options.mapOptions,\n container: this.$refs.container ?? this.$el,\n });\n this.__map = map;\n\n const onLoad = () => {\n this.isLoaded = true;\n this.$emit('map-load', map);\n };\n map.on('load', onLoad);\n this.__offMapListeners.push(() => this.__map?.off('load', onLoad));\n\n for (const event of FORWARDED_MAP_EVENTS) {\n const handler = (e: unknown) => {\n this.$emit(`map-${event}`, e);\n };\n map.on(event, handler);\n this.__offMapListeners.push(() => this.__map?.off(event, handler));\n }\n\n // Announce this map so any child that mounted before it — and is waiting on\n // `MAPBOX_MAP_CONNECTED` — can resolve and inject itself now. This also fires\n // on a remount, letting still-mounted children re-inject on the new map.\n document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // Flush the forwarding listeners before removing the map so neither the map\n // nor this component leaks through a retained `Map` reference.\n for (const off of this.__offMapListeners) {\n off();\n }\n this.__offMapListeners = [];\n\n this.__map?.remove();\n this.__map = undefined;\n this.isLoaded = false;\n }\n}\n\nexport default MapboxMap;\n"],"mappings":";;;;AAMA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AAkBD,IAAa,YAAb,cAAgE,KAAyB;;;;CAIvF,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,YAAY,GAAG,qBAAqB,KAAK,UAAU,OAAO,Q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aseProps } from "@studiometa/js-toolkit";
4
4
  import { Marker, MarkerOptions } from "mapbox-gl";
5
5
 
6
- //#region MapboxMarker.d.ts
6
+ //#region src/MapboxMarker.d.ts
7
7
  interface MapboxMarkerProps extends AbstractMapboxMapChildProps {
8
8
  $options: {
9
9
  lngLat: [number, number];
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- //#region MapboxMarker.ts
3
+ //#region src/MapboxMarker.ts
4
4
  /**
5
5
  * Add a marker to Mapbox map.
6
6
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxMarker.js","names":[],"sources":["../src/MapboxMarker.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { Marker, MarkerOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport { MapboxPopup } from './MapboxPopup.js';\n\nexport interface MapboxMarkerProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n markerOptions: MarkerOptions;\n };\n}\n\n/**\n * Add a marker to Mapbox map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMarker<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxMarkerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMarker',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n // Marker options. (https://docs.mapbox.com/mapbox-gl-js/api/markers#marker)\n markerOptions: Object,\n },\n };\n\n /**\n * Marker instance.\n * @private\n */\n __marker: Marker;\n\n /**\n * The mapbox Marker instance.\n */\n get marker() {\n if (!this.__marker) {\n this.__marker = new (getMapboxGl().Marker)(this.$options.markerOptions);\n }\n\n return this.__marker;\n }\n\n /**\n * The optional child popup component instance.\n */\n get popup() {\n return this.$query<MapboxPopup>('MapboxPopup')[0];\n }\n\n /**\n * Attach a child `MapboxPopup`'s popup to this marker.\n *\n * Called from either side of the wiring, whichever mounts last: the marker\n * pulls its child popup on ready, and the popup pushes itself here when it\n * mounts after the marker (a dynamic append to an already-loaded map, where\n * the marker mounted first and found no popup to query yet). Setting the same\n * popup twice is idempotent.\n * @param {MapboxPopup} popupComponent\n */\n setChildPopup(popupComponent: MapboxPopup) {\n this.marker.setPopup(popupComponent.popup);\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n this.marker.setLngLat(this.$options.lngLat).addTo(map);\n\n // Pull the optional child popup if it has already mounted. When it mounts\n // *after* the marker instead (dynamic append), the popup pushes itself via\n // `setChildPopup`, so either mount order wires the pair.\n if (this.popup) {\n this.setChildPopup(this.popup);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__marker?.remove();\n this.__marker = undefined;\n }\n}\n\nexport default MapboxMarker;\n"],"mappings":";;;;;;;AAoBA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAED,eAAe;GAChB;EACF;;;;;CAMD;;;;CAKA,IAAI,SAAS;AACX,MAAI,CAAC,KAAK,SACR,MAAK,WAAW,KAAK,aAAa,EAAC,OAAQ,KAAK,SAAS,cAAc;AAGzE,SAAO,KAAK;;;;;CAMd,IAAI,QAAQ;AACV,SAAO,KAAK,OAAoB,cAAc,CAAC;;;;;;;;;;;;CAajD,cAAc,gBAA6B;AACzC,OAAK,OAAO,SAAS,eAAe,MAAM;;;;;CAM5C,UAAU;AACR,OAAK,cAAc,QAAQ;AACzB,QAAK,OAAO,UAAU,KAAK,SAAS,OAAO,CAAC,MAAM,IAAI;AAKtD,OAAI,KAAK,MACP,MAAK,cAAc,KAAK,MAAM;IAEhC;;;;;CAMJ,gBAAgB;AACd,OAAK,UAAU,QAAQ;AACvB,OAAK,WAAW,KAAA"}
@@ -3,7 +3,7 @@ import * as _studiometa_js_toolkit0 from "@studiometa/js-toolkit";
3
3
  import * as mapbox_gl0 from "mapbox-gl";
4
4
  import { NavigationControlOptions } from "mapbox-gl";
5
5
 
6
- //#region MapboxNavigationControl.d.ts
6
+ //#region src/MapboxNavigationControl.d.ts
7
7
  interface MapboxNavigationControlProps extends AbstractMapboxControlProps {
8
8
  $options: AbstractMapboxControlProps['$options'] & {
9
9
  showCompass: boolean;
@@ -1,7 +1,7 @@
1
1
  import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- import { withExtraConfig } from "@studiometa/js-toolkit";
4
- //#region MapboxNavigationControl.ts
3
+ import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
4
+ //#region src/MapboxNavigationControl.ts
5
5
  /**
6
6
  * Add a navigation control to the map.
7
7
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxNavigationControl.js","names":[],"sources":["../src/MapboxNavigationControl.ts"],"sourcesContent":["import { withExtraConfig } from '@studiometa/js-toolkit/withExtraConfig';\nimport type { NavigationControlOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxControl,\n type AbstractMapboxControlProps,\n} from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxNavigationControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & {\n showCompass: boolean;\n showZoom: boolean;\n visualizePitch: boolean;\n };\n}\n\n/**\n * Add a navigation control to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxNavigationControl extends withExtraConfig(AbstractMapboxControl, {\n name: 'MapboxNavigationControl',\n options: {\n showCompass: Boolean,\n showZoom: Boolean,\n visualizePitch: Boolean,\n },\n}) {\n /**\n * Create the mapbox NavigationControl instance.\n * @protected\n */\n createControl(options: NavigationControlOptions) {\n return new (getMapboxGl().NavigationControl)(options);\n }\n}\n\nexport default MapboxNavigationControl;\n"],"mappings":";;;;;;;;AAoBA,IAAa,0BAAb,cAA6C,gBAAgB,uBAAuB;CAClF,MAAM;CACN,SAAS;EACP,aAAa;EACb,UAAU;EACV,gBAAgB;EACjB;CACF,CAAC,CAAC;;;;;CAKD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
@@ -2,7 +2,7 @@ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractM
2
2
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import { Popup, PopupOptions } from "mapbox-gl";
4
4
 
5
- //#region MapboxPopup.d.ts
5
+ //#region src/MapboxPopup.d.ts
6
6
  interface MapboxPopupProps extends AbstractMapboxMapChildProps {
7
7
  $options: {
8
8
  lngLat: [number, number];
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- //#region MapboxPopup.ts
3
+ //#region src/MapboxPopup.ts
4
4
  /**
5
5
  * Display a popup on a MapboxMap map.
6
6
  * @see https://ui.studiometa.dev/reference/items/MapboxMap
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxPopup.js","names":[],"sources":["../src/MapboxPopup.ts"],"sourcesContent":["import { type BaseConfig, type BaseProps } from '@studiometa/js-toolkit';\nimport type { Popup, PopupOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport type { MapboxMarker } from './MapboxMarker.js';\n\nexport interface MapboxPopupProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n /**\n * Popup options.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/markers#popup\n */\n popupOptions: PopupOptions;\n };\n}\n\n/**\n * Display a popup on a MapboxMap map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap\n */\nexport class MapboxPopup<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxPopupProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxPopup',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n popupOptions: Object,\n },\n };\n\n /**\n * Popup instance.\n * @private\n */\n __popup: Popup;\n\n /**\n * Whether this component hid its own source element (to avoid rendering the\n * content twice). Tracked so teardown restores the original visibility only\n * when it was the one to change it.\n * @private\n */\n __didHide = false;\n\n /**\n * The mapbox Popup instance.\n */\n get popup() {\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n return this.__popup;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { popup, $el, $options } = this;\n\n popup.setLngLat($options.lngLat);\n\n const content = $el.innerHTML.trim();\n if (content) {\n popup.setHTML(content);\n // Hide the source markup so the content is not rendered twice: once in\n // the popup and once in the document. Remember we did so — only when it\n // was visible — to restore it on teardown.\n if (!$el.hidden) {\n $el.hidden = true;\n this.__didHide = true;\n }\n }\n\n // When inside a marker, hand the popup to it rather than adding it to the\n // map directly (the marker owns its popup via `setPopup`). Pushing to the\n // marker — instead of letting the marker pull us — also covers the dynamic\n // append case where the marker mounted first and found no popup to query.\n const marker = this.$closest<MapboxMarker>('MapboxMarker');\n if (marker) {\n marker.setChildPopup(this);\n } else {\n popup.addTo(map);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__popup?.remove();\n this.__popup = undefined;\n\n // Restore the source element's visibility only if this component hid it, so\n // a reused or remounted element keeps its original state.\n if (this.__didHide) {\n this.$el.hidden = false;\n this.__didHide = false;\n }\n }\n}\n\nexport default MapboxPopup;\n"],"mappings":";;;;;;;AAwBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,cAAc;GACf;EACF;;;;;CAMD;;;;;;;CAQA,YAAY;;;;CAKZ,IAAI,QAAQ;AACV,MAAI,CAAC,KAAK,QACR,MAAK,UAAU,KAAK,aAAa,EAAC,MAAO,KAAK,SAAS,aAAa;AAGtE,SAAO,KAAK;;;;;CAMd,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK,aAAa;AAEjC,SAAM,UAAU,SAAS,OAAO;GAEhC,MAAM,UAAU,IAAI,UAAU,MAAM;AACpC,OAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AAItB,QAAI,CAAC,IAAI,QAAQ;AACf,SAAI,SAAS;AACb,UAAK,YAAY;;;GAQrB,MAAM,SAAS,KAAK,SAAuB,eAAe;AAC1D,OAAI,OACF,QAAO,cAAc,KAAK;OAE1B,OAAM,MAAM,IAAI;IAElB;;;;;CAMJ,gBAAgB;AACd,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AAIf,MAAI,KAAK,WAAW;AAClB,QAAK,IAAI,SAAS;AAClB,QAAK,YAAY"}
@@ -2,7 +2,7 @@ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractM
2
2
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import { SourceSpecification } from "mapbox-gl";
4
4
 
5
- //#region MapboxSource.d.ts
5
+ //#region src/MapboxSource.d.ts
6
6
  interface MapboxSourceProps extends AbstractMapboxMapChildProps {
7
7
  $refs: {
8
8
  geojson?: HTMLScriptElement;
@@ -1,6 +1,6 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from "./utils.js";
3
- //#region MapboxSource.ts
3
+ //#region src/MapboxSource.ts
4
4
  /**
5
5
  * Add a source to the map.
6
6
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/