@studiometa/ui-mapbox 1.11.1 → 2.0.0-alpha.1

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 (50) hide show
  1. package/README.md +12 -16
  2. package/dist/AbstractMapboxControl.js +1 -1
  3. package/dist/AbstractMapboxControl.js.map +1 -1
  4. package/dist/AbstractMapboxMapChild.d.ts +32 -12
  5. package/dist/AbstractMapboxMapChild.js +24 -17
  6. package/dist/AbstractMapboxMapChild.js.map +1 -1
  7. package/dist/MapboxCluster.d.ts +19 -2
  8. package/dist/MapboxCluster.js +11 -9
  9. package/dist/MapboxCluster.js.map +1 -1
  10. package/dist/MapboxClusterItem.d.ts +11 -3
  11. package/dist/MapboxClusterItem.js +5 -6
  12. package/dist/MapboxClusterItem.js.map +1 -1
  13. package/dist/MapboxFullscreenControl.d.ts +8 -4
  14. package/dist/MapboxFullscreenControl.js +6 -2
  15. package/dist/MapboxFullscreenControl.js.map +1 -1
  16. package/dist/MapboxGeocoder.d.ts +57 -5
  17. package/dist/MapboxGeocoder.js +73 -16
  18. package/dist/MapboxGeocoder.js.map +1 -1
  19. package/dist/MapboxGeolocateControl.d.ts +8 -4
  20. package/dist/MapboxGeolocateControl.js +16 -12
  21. package/dist/MapboxGeolocateControl.js.map +1 -1
  22. package/dist/MapboxImage.d.ts +11 -1
  23. package/dist/MapboxImage.js +0 -1
  24. package/dist/MapboxImage.js.map +1 -1
  25. package/dist/MapboxImages.d.ts +9 -1
  26. package/dist/MapboxImages.js +1 -2
  27. package/dist/MapboxImages.js.map +1 -1
  28. package/dist/MapboxLayer.js.map +1 -1
  29. package/dist/MapboxMap.d.ts +17 -2
  30. package/dist/MapboxMap.js +5 -5
  31. package/dist/MapboxMap.js.map +1 -1
  32. package/dist/MapboxMarker.js.map +1 -1
  33. package/dist/MapboxNavigationControl.d.ts +8 -4
  34. package/dist/MapboxNavigationControl.js +13 -9
  35. package/dist/MapboxNavigationControl.js.map +1 -1
  36. package/dist/MapboxPopup.js.map +1 -1
  37. package/dist/MapboxSource.js +1 -1
  38. package/dist/MapboxSource.js.map +1 -1
  39. package/dist/StoreLocator.d.ts +76 -51
  40. package/dist/StoreLocator.js +112 -105
  41. package/dist/StoreLocator.js.map +1 -1
  42. package/dist/catalog.js +22 -11
  43. package/dist/catalog.js.map +1 -1
  44. package/dist/dependencies.d.ts +6 -4
  45. package/dist/dependencies.js +6 -4
  46. package/dist/dependencies.js.map +1 -1
  47. package/dist/manifest.js +14 -84
  48. package/dist/manifest.js.map +1 -1
  49. package/dist/scripts/manifest-types.d.ts +8 -5
  50. package/package.json +3 -3
@@ -9,6 +9,14 @@ interface MapboxClusterItemProps extends BaseProps {
9
9
  lngLat: [number, number];
10
10
  properties: Record<string, unknown>;
11
11
  };
12
+ /**
13
+ * The item shares the map family's error channel.
14
+ */
15
+ $emits: {
16
+ 'map-error': {
17
+ error: unknown;
18
+ };
19
+ };
12
20
  }
13
21
  /**
14
22
  * A single entry of a `MapboxCluster`.
@@ -51,7 +59,7 @@ declare class MapboxClusterItem<T extends BaseProps = BaseProps> extends Base<T
51
59
  * The parent `MapboxCluster` resolved at mount, cached so the item can still
52
60
  * reach it on destroy.
53
61
  *
54
- * `destroyed()` runs *after* the element has been detached from the DOM (e.g.
62
+ * `unmounted()` runs *after* the element has been detached from the DOM (e.g.
55
63
  * a `Fetch` list swap), and a `$closest` lookup on a disconnected node returns
56
64
  * nothing — which would leave the removed item registered and its feature
57
65
  * stuck on the map. Caching the reference keeps the unregister path working.
@@ -110,10 +118,10 @@ declare class MapboxClusterItem<T extends BaseProps = BaseProps> extends Base<T
110
118
  */
111
119
  __waitForConnectedCluster(): void;
112
120
  /**
113
- * Destroyed hook: unregister from the cached cluster, even if the element has
121
+ * Unmounted hook: unregister from the cached cluster, even if the element has
114
122
  * already been detached from the DOM, and drop any pending retry subscription.
115
123
  */
116
- destroyed(): void;
124
+ unmounted(): void;
117
125
  /**
118
126
  * Reflect the "in the current map viewport" state as a `data-in-bounds`
119
127
  * attribute. Called by a `StoreLocator` orchestrator on every map `moveend`.
@@ -39,7 +39,6 @@ var MapboxClusterItem = class extends Base {
39
39
  */
40
40
  static config = {
41
41
  name: "MapboxClusterItem",
42
- emits: ["map-error"],
43
42
  options: {
44
43
  id: String,
45
44
  lngLat: {
@@ -56,7 +55,7 @@ var MapboxClusterItem = class extends Base {
56
55
  * The parent `MapboxCluster` resolved at mount, cached so the item can still
57
56
  * reach it on destroy.
58
57
  *
59
- * `destroyed()` runs *after* the element has been detached from the DOM (e.g.
58
+ * `unmounted()` runs *after* the element has been detached from the DOM (e.g.
60
59
  * a `Fetch` list swap), and a `$closest` lookup on a disconnected node returns
61
60
  * nothing — which would leave the removed item registered and its feature
62
61
  * stuck on the map. Caching the reference keeps the unregister path working.
@@ -143,15 +142,15 @@ var MapboxClusterItem = class extends Base {
143
142
  this.__offClusterConnected = () => document.removeEventListener(MAPBOX_CLUSTER_CONNECTED, handler);
144
143
  }
145
144
  /**
146
- * Destroyed hook: unregister from the cached cluster, even if the element has
145
+ * Unmounted hook: unregister from the cached cluster, even if the element has
147
146
  * already been detached from the DOM, and drop any pending retry subscription.
148
147
  */
149
- destroyed() {
148
+ unmounted() {
150
149
  try {
151
150
  this.__cluster?.unregister(this);
152
151
  } catch (err) {
153
- this.$warn(err);
154
- this.$emit("map-error", err);
152
+ this.$error("mapbox-cluster-item.unregister-failed", "Unregistering from the cluster threw.", err);
153
+ this.$emit("map-error", { error: err });
155
154
  }
156
155
  this.__cluster = void 0;
157
156
  this.__offClusterConnected?.();
@@ -1 +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;EACF;;;;;;;;;;;CAYD;;;;;;CAOA;;;;;;;;;;CAWA,IAAI,KAAa;AACf,SAAO,KAAK,SAAS;;;;;CAMvB,IAAI,SAA2B;AAC7B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAI,aAAsC;AACxC,SAAO,KAAK,SAAS;;;;;;;;;CAUvB,IAAI,eAAuB;AAEzB,UADY,KAAK,IAAI,cAAc,uBAAqB,IACzC,KAAK,KAAK,UAAU,MAAM;;;;;CAM3C,UAAU;AACR,OAAK,kBAAkB;;;;;;;;;;CAWzB,mBAAmB;EACjB,MAAM,UAAU,KAAK,SAAwB,gBAAgB;AAE7D,MAAI,CAAC,SAAS;AACZ,QAAK,2BAA2B;AAChC;;AAGF,OAAK,YAAY;AACjB,UAAQ,SAAS,KAAK;;;;;;;CAQxB,4BAA4B;AAC1B,MAAI,KAAK,sBACP;EAGF,MAAM,WAAW,UAAiB;AAGhC,OAAI,CAFa,MAAqC,QAExC,KAAK,SAAS,KAAK,IAAI,CACnC;AAGF,QAAK,yBAAyB;AAC9B,QAAK,wBAAwB,KAAA;AAC7B,QAAK,kBAAkB;;AAGzB,WAAS,iBAAiB,0BAA0B,QAAQ;AAC5D,OAAK,8BACH,SAAS,oBAAoB,0BAA0B,QAAQ;;;;;;CAOnE,YAAY;AACV,MAAI;AACF,QAAK,WAAW,WAAW,KAAK;WACzB,KAAK;AACZ,QAAK,MAAM,IAAI;AACf,QAAK,MAAM,aAAa,IAAI;;AAG9B,OAAK,YAAY,KAAA;AACjB,OAAK,yBAAyB;AAC9B,OAAK,wBAAwB,KAAA;;;;;;;CAQ/B,YAAY,OAAgB;AAC1B,OAAK,IAAI,gBAAgB,kBAAkB,MAAM;;;;;;;CAQnD,UAAU,OAAgB;AACxB,OAAK,IAAI,gBAAgB,eAAe,MAAM;AAE9C,MAAI,MACF,MAAK,IAAI,aAAa,gBAAgB,OAAO;MAE7C,MAAK,IAAI,gBAAgB,eAAe"}
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 * The item shares the map family's error channel.\n */\n $emits: {\n 'map-error': { error: 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 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 * `unmounted()` 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 * Unmounted 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 unmounted() {\n try {\n this.__cluster?.unregister(this);\n } catch (err) {\n this.$error(\n 'mapbox-cluster-item.unregister-failed',\n 'Unregistering from the cluster threw.',\n err,\n );\n this.$emit('map-error', { 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,IAAa,oBAAb,cAAwE,KAEtE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,IAAI;GACJ,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EACF;;;;;;;;;;;CAYD;;;;;;CAOA;;;;;;;;;;CAWA,IAAI,KAAa;AACf,SAAO,KAAK,SAAS;;;;;CAMvB,IAAI,SAA2B;AAC7B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAI,aAAsC;AACxC,SAAO,KAAK,SAAS;;;;;;;;;CAUvB,IAAI,eAAuB;AAEzB,UADY,KAAK,IAAI,cAAc,uBAAqB,IACzC,KAAK,KAAK,UAAU,MAAM;;;;;CAM3C,UAAU;AACR,OAAK,kBAAkB;;;;;;;;;;CAWzB,mBAAmB;EACjB,MAAM,UAAU,KAAK,SAAwB,gBAAgB;AAE7D,MAAI,CAAC,SAAS;AACZ,QAAK,2BAA2B;AAChC;;AAGF,OAAK,YAAY;AACjB,UAAQ,SAAS,KAAK;;;;;;;CAQxB,4BAA4B;AAC1B,MAAI,KAAK,sBACP;EAGF,MAAM,WAAW,UAAiB;AAGhC,OAAI,CAFa,MAAqC,QAExC,KAAK,SAAS,KAAK,IAAI,CACnC;AAGF,QAAK,yBAAyB;AAC9B,QAAK,wBAAwB,KAAA;AAC7B,QAAK,kBAAkB;;AAGzB,WAAS,iBAAiB,0BAA0B,QAAQ;AAC5D,OAAK,8BACH,SAAS,oBAAoB,0BAA0B,QAAQ;;;;;;CAOnE,YAAY;AACV,MAAI;AACF,QAAK,WAAW,WAAW,KAAK;WACzB,KAAK;AACZ,QAAK,OACH,yCACA,yCACA,IACD;AACD,QAAK,MAAM,aAAa,EAAE,OAAO,KAAK,CAAC;;AAGzC,OAAK,YAAY,KAAA;AACjB,OAAK,yBAAyB;AAC9B,OAAK,wBAAwB,KAAA;;;;;;;CAQ/B,YAAY,OAAgB;AAC1B,OAAK,IAAI,gBAAgB,kBAAkB,MAAM;;;;;;;CAQnD,UAAU,OAAgB;AACxB,OAAK,IAAI,gBAAgB,eAAe,MAAM;AAE9C,MAAI,MACF,MAAK,IAAI,aAAa,gBAAgB,OAAO;MAE7C,MAAK,IAAI,gBAAgB,eAAe"}
@@ -1,16 +1,20 @@
1
- import { AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
2
- import * as _studiometa_js_toolkit0 from "@studiometa/js-toolkit";
1
+ import { AbstractMapboxControl, AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
2
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import * as mapbox_gl0 from "mapbox-gl";
4
4
  import { FullscreenControlOptions } from "mapbox-gl";
5
5
 
6
6
  //#region src/MapboxFullscreenControl.d.ts
7
7
  interface MapboxFullscreenControlProps extends AbstractMapboxControlProps {}
8
- declare const MapboxFullscreenControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
9
8
  /**
10
9
  * Add a fullscreen control to the map.
10
+ *
11
11
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
12
12
  */
13
- declare class MapboxFullscreenControl extends MapboxFullscreenControl_base {
13
+ declare class MapboxFullscreenControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<T & MapboxFullscreenControlProps> {
14
+ /**
15
+ * Config.
16
+ */
17
+ static config: BaseConfig;
14
18
  /**
15
19
  * Create the mapbox FullscreenControl instance.
16
20
  * @protected
@@ -1,12 +1,16 @@
1
1
  import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
4
3
  //#region src/MapboxFullscreenControl.ts
5
4
  /**
6
5
  * Add a fullscreen control to the map.
6
+ *
7
7
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
8
8
  */
9
- var MapboxFullscreenControl = class extends withExtraConfig(AbstractMapboxControl, { name: "MapboxFullscreenControl" }) {
9
+ var MapboxFullscreenControl = class extends AbstractMapboxControl {
10
+ /**
11
+ * Config.
12
+ */
13
+ static config = { name: "MapboxFullscreenControl" };
10
14
  /**
11
15
  * Create the mapbox FullscreenControl instance.
12
16
  * @protected
@@ -1 +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"}
1
+ {"version":3,"file":"MapboxFullscreenControl.js","names":[],"sources":["../src/MapboxFullscreenControl.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { FullscreenControlOptions } from 'mapbox-gl';\nimport { AbstractMapboxControl, type AbstractMapboxControlProps } 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 *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxFullscreenControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<\n T & MapboxFullscreenControlProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxFullscreenControl',\n };\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":";;;;;;;;AAYA,IAAa,0BAAb,cAA8E,sBAE5E;;;;CAIA,OAAO,SAAqB,EAC1B,MAAM,2BACP;;;;;CAMD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
@@ -7,7 +7,14 @@ import { Map } from "mapbox-gl";
7
7
  interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {
8
8
  $options: {
9
9
  /**
10
- * Wether to add the geocoder to the map or to the component's root element.
10
+ * The Mapbox access token for the geocoding requests. Inside a `MapboxMap`,
11
+ * it falls back to the map's `accessToken`. An `accessToken` set in
12
+ * `options` wins over it, as one set in `mapOptions` does on `MapboxMap`.
13
+ */
14
+ accessToken: string;
15
+ /**
16
+ * Wether to add the geocoder to the parent map or to the component's root
17
+ * element. Requires a parent `MapboxMap`.
11
18
  */
12
19
  addToMap: boolean;
13
20
  /**
@@ -19,9 +26,26 @@ interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {
19
26
  */
20
27
  options: Record<string, unknown>;
21
28
  };
29
+ /**
30
+ * The geocoder's own event, declared in the props type. The geocoded result
31
+ * travels as `detail.result`.
32
+ */
33
+ $emits: AbstractMapboxMapChildProps['$emits'] & {
34
+ 'map-result': {
35
+ result: unknown;
36
+ };
37
+ };
22
38
  }
23
39
  /**
24
- * Add a geocoder control to the map.
40
+ * Add a geocoder control to the map, or to the component's root element.
41
+ *
42
+ * Inside a `MapboxMap`, the control waits for the map and falls back to the
43
+ * map's `accessToken`. Only a control added to the map (`addToMap`) shows a
44
+ * marker for the picked result: the geocoder library skips the marker when it is
45
+ * rendered in an element. Without a parent map (and without `addToMap`), it works
46
+ * on its own: it renders in the root element as soon as it mounts, needs its own
47
+ * access token (the `accessToken` option, or `options.accessToken`), and never
48
+ * loads `mapbox-gl`.
25
49
  *
26
50
  * The Mapbox geocoder module is an optional peer dependency and is loaded on
27
51
  * demand with a dynamic `import()` when the component mounts, so the rest of the
@@ -44,17 +68,45 @@ declare class MapboxGeocoder<T extends BaseProps = BaseProps> extends AbstractMa
44
68
  */
45
69
  get control(): MapboxGeocoderControl | undefined;
46
70
  /**
47
- * Target element the geocoder is added to: the map when `addToMap` is set,
48
- * otherwise the component's own root element.
71
+ * Target element the geocoder is added to: the parent map when `addToMap` is
72
+ * set, otherwise the component's own root element.
49
73
  */
50
74
  get target(): Map | HTMLElement | string;
51
75
  /**
52
76
  * Mounted hook.
53
77
  *
54
78
  * Lazily loads the optional Mapbox geocoder module, then builds and adds the
55
- * control once the parent map is ready.
79
+ * control: once the parent map is ready, or right away without a parent map.
56
80
  */
57
81
  mounted(): Promise<void>;
82
+ /**
83
+ * The options the control is built with.
84
+ *
85
+ * The token comes from the `accessToken` option, or else from the fallback (the
86
+ * parent map's token). The raw `options` are spread over it, so an
87
+ * `accessToken` set there wins, as one set in `mapOptions` does on
88
+ * `MapboxMap`. An empty `accessToken` option counts as absent: a `String`
89
+ * option reads as `''` when its attribute is missing.
90
+ * @private
91
+ * @param {string} [fallbackAccessToken] The parent map's access token.
92
+ */
93
+ __controlOptions(fallbackAccessToken?: string): Record<string, unknown>;
94
+ /**
95
+ * Add a control to the target, replacing the previous one, and re-emit its
96
+ * `result` event as a prefixed component event, so consumers (e.g. a
97
+ * `StoreLocator`) can react to a geocoded address.
98
+ *
99
+ * A previous control exists when the map is replaced (the ready callback
100
+ * re-runs) or when the instance is unmounted and mounted again while the
101
+ * geocoder import is pending (both `mounted()` calls resume). An
102
+ * element-targeted control (`addToMap` false) lives on `$el`, which survives
103
+ * both, so it must be removed first or the element would stack several
104
+ * geocoders. A map-targeted control went away with its (removed) map, so only
105
+ * its reference needs dropping.
106
+ * @private
107
+ * @param {MapboxGeocoderControl} control
108
+ */
109
+ __addControl(control: MapboxGeocoderControl): void;
58
110
  /**
59
111
  * Teardown hook.
60
112
  */
@@ -1,8 +1,17 @@
1
1
  import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
2
  import { getMapboxGl, resolveMapboxGeocoder } from "./dependencies.js";
3
+ import { selectorFor } from "@studiometa/js-toolkit/utils/selectorFor";
3
4
  //#region src/MapboxGeocoder.ts
4
5
  /**
5
- * Add a geocoder control to the map.
6
+ * Add a geocoder control to the map, or to the component's root element.
7
+ *
8
+ * Inside a `MapboxMap`, the control waits for the map and falls back to the
9
+ * map's `accessToken`. Only a control added to the map (`addToMap`) shows a
10
+ * marker for the picked result: the geocoder library skips the marker when it is
11
+ * rendered in an element. Without a parent map (and without `addToMap`), it works
12
+ * on its own: it renders in the root element as soon as it mounts, needs its own
13
+ * access token (the `accessToken` option, or `options.accessToken`), and never
14
+ * loads `mapbox-gl`.
6
15
  *
7
16
  * The Mapbox geocoder module is an optional peer dependency and is loaded on
8
17
  * demand with a dynamic `import()` when the component mounts, so the rest of the
@@ -16,8 +25,9 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
16
25
  */
17
26
  static config = {
18
27
  name: "MapboxGeocoder",
19
- emits: ["map-result"],
28
+ mountStrategy: "visible",
20
29
  options: {
30
+ accessToken: String,
21
31
  addToMap: Boolean,
22
32
  options: Object
23
33
  }
@@ -34,8 +44,8 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
34
44
  return this.__control;
35
45
  }
36
46
  /**
37
- * Target element the geocoder is added to: the map when `addToMap` is set,
38
- * otherwise the component's own root element.
47
+ * Target element the geocoder is added to: the parent map when `addToMap` is
48
+ * set, otherwise the component's own root element.
39
49
  */
40
50
  get target() {
41
51
  return this.$options.addToMap ? this.map : this.$el;
@@ -44,26 +54,73 @@ var MapboxGeocoder = class extends AbstractMapboxMapChild {
44
54
  * Mounted hook.
45
55
  *
46
56
  * Lazily loads the optional Mapbox geocoder module, then builds and adds the
47
- * control once the parent map is ready.
57
+ * control: once the parent map is ready, or right away without a parent map.
48
58
  */
49
59
  async mounted() {
60
+ const standalone = !this.$options.addToMap && !this.$el.parentElement?.closest(selectorFor("MapboxMap"));
61
+ if (standalone && !this.__controlOptions().accessToken) {
62
+ this.$warn("mapbox-geocoder.missing-access-token", "A MapboxGeocoder without a parent MapboxMap needs an access token: set its `data-option-access-token`.");
63
+ return;
64
+ }
50
65
  const GeocoderControlClass = await resolveMapboxGeocoder();
51
66
  if (!this.$isMounted) return;
52
- this.whenMapReady(() => {
53
- if (this.__control) {
54
- if (!this.$options.addToMap) this.__control.onRemove();
55
- this.__control = void 0;
67
+ if (standalone) {
68
+ try {
69
+ this.__addControl(new GeocoderControlClass(this.__controlOptions()));
70
+ } catch (err) {
71
+ this.__handleError(err);
56
72
  }
57
- this.__control = new GeocoderControlClass({
58
- ...this.$options.options,
59
- mapboxgl: getMapboxGl(),
60
- accessToken: this.$options.options.accessToken ?? this.__readyMapboxMap?.$options.accessToken
61
- });
62
- this.__control.on?.("result", (event) => this.$emit("map-result", event.result));
63
- this.__control.addTo(this.target);
73
+ return;
74
+ }
75
+ this.whenMapReady(() => {
76
+ this.__addControl(new GeocoderControlClass({
77
+ ...this.__controlOptions(this.__readyMapboxMap?.$options.accessToken),
78
+ mapboxgl: getMapboxGl()
79
+ }));
64
80
  });
65
81
  }
66
82
  /**
83
+ * The options the control is built with.
84
+ *
85
+ * The token comes from the `accessToken` option, or else from the fallback (the
86
+ * parent map's token). The raw `options` are spread over it, so an
87
+ * `accessToken` set there wins, as one set in `mapOptions` does on
88
+ * `MapboxMap`. An empty `accessToken` option counts as absent: a `String`
89
+ * option reads as `''` when its attribute is missing.
90
+ * @private
91
+ * @param {string} [fallbackAccessToken] The parent map's access token.
92
+ */
93
+ __controlOptions(fallbackAccessToken) {
94
+ return {
95
+ accessToken: this.$options.accessToken || fallbackAccessToken,
96
+ ...this.$options.options
97
+ };
98
+ }
99
+ /**
100
+ * Add a control to the target, replacing the previous one, and re-emit its
101
+ * `result` event as a prefixed component event, so consumers (e.g. a
102
+ * `StoreLocator`) can react to a geocoded address.
103
+ *
104
+ * A previous control exists when the map is replaced (the ready callback
105
+ * re-runs) or when the instance is unmounted and mounted again while the
106
+ * geocoder import is pending (both `mounted()` calls resume). An
107
+ * element-targeted control (`addToMap` false) lives on `$el`, which survives
108
+ * both, so it must be removed first or the element would stack several
109
+ * geocoders. A map-targeted control went away with its (removed) map, so only
110
+ * its reference needs dropping.
111
+ * @private
112
+ * @param {MapboxGeocoderControl} control
113
+ */
114
+ __addControl(control) {
115
+ if (this.__control) {
116
+ if (!this.$options.addToMap) this.__control.onRemove();
117
+ this.__control = void 0;
118
+ }
119
+ control.on?.("result", (event) => this.$emit("map-result", { result: event.result }));
120
+ control.addTo(this.target);
121
+ this.__control = control;
122
+ }
123
+ /**
67
124
  * Teardown hook.
68
125
  */
69
126
  __onDestroyed() {
@@ -1 +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"}
1
+ {"version":3,"file":"MapboxGeocoder.js","names":[],"sources":["../src/MapboxGeocoder.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport { selectorFor } from '@studiometa/js-toolkit/utils/selectorFor';\nimport type { Map, IControl } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl, resolveMapboxGeocoder, type MapboxGeocoderControl } from './dependencies.js';\n\nexport interface MapboxGeocoderProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * The Mapbox access token for the geocoding requests. Inside a `MapboxMap`,\n * it falls back to the map's `accessToken`. An `accessToken` set in\n * `options` wins over it, as one set in `mapOptions` does on `MapboxMap`.\n */\n accessToken: string;\n /**\n * Wether to add the geocoder to the parent map or to the component's root\n * element. Requires a parent `MapboxMap`.\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 * The geocoder's own event, declared in the props type. The geocoded result\n * travels as `detail.result`.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-result': { result: unknown };\n };\n}\n\n/**\n * Add a geocoder control to the map, or to the component's root element.\n *\n * Inside a `MapboxMap`, the control waits for the map and falls back to the\n * map's `accessToken`. Only a control added to the map (`addToMap`) shows a\n * marker for the picked result: the geocoder library skips the marker when it is\n * rendered in an element. Without a parent map (and without `addToMap`), it works\n * on its own: it renders in the root element as soon as it mounts, needs its own\n * access token (the `accessToken` option, or `options.accessToken`), and never\n * loads `mapbox-gl`.\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 mountStrategy: 'visible',\n options: {\n accessToken: String,\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 parent map when `addToMap` is\n * set, 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, or right away without a parent map.\n */\n async mounted() {\n // Look for the parent map element rather than a mounted `MapboxMap`\n // instance: a lazily mounted map has no instance yet, and the geocoder must\n // wait for it instead of going standalone.\n const standalone =\n !this.$options.addToMap && !this.$el.parentElement?.closest(selectorFor('MapboxMap'));\n\n if (standalone && !this.__controlOptions().accessToken) {\n this.$warn(\n 'mapbox-geocoder.missing-access-token',\n 'A MapboxGeocoder without a parent MapboxMap needs an access token: set its `data-option-access-token`.',\n );\n return;\n }\n\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 `__onDestroyed()` already ran (and saw `__control`\n // undefined), leaking an orphan control.\n if (!this.$isMounted) {\n return;\n }\n\n if (standalone) {\n // Contain a throw like the map path does: without it, it would surface as\n // an unhandled rejection of `mounted()` with no `map-error` event.\n try {\n this.__addControl(new GeocoderControlClass(this.__controlOptions()));\n } catch (err) {\n this.__handleError(err);\n }\n return;\n }\n\n // The ready callback is standing: it re-runs on every map replacement.\n this.whenMapReady(() => {\n this.__addControl(\n new GeocoderControlClass({\n ...this.__controlOptions(this.__readyMapboxMap?.$options.accessToken),\n mapboxgl: getMapboxGl(),\n }),\n );\n });\n }\n\n /**\n * The options the control is built with.\n *\n * The token comes from the `accessToken` option, or else from the fallback (the\n * parent map's token). The raw `options` are spread over it, so an\n * `accessToken` set there wins, as one set in `mapOptions` does on\n * `MapboxMap`. An empty `accessToken` option counts as absent: a `String`\n * option reads as `''` when its attribute is missing.\n * @private\n * @param {string} [fallbackAccessToken] The parent map's access token.\n */\n __controlOptions(fallbackAccessToken?: string): Record<string, unknown> {\n return {\n accessToken: this.$options.accessToken || fallbackAccessToken,\n ...this.$options.options,\n };\n }\n\n /**\n * Add a control to the target, replacing the previous one, and re-emit its\n * `result` event as a prefixed component event, so consumers (e.g. a\n * `StoreLocator`) can react to a geocoded address.\n *\n * A previous control exists when the map is replaced (the ready callback\n * re-runs) or when the instance is unmounted and mounted again while the\n * geocoder import is pending (both `mounted()` calls resume). An\n * element-targeted control (`addToMap` false) lives on `$el`, which survives\n * both, so it must be removed first or the element would stack several\n * geocoders. A map-targeted control went away with its (removed) map, so only\n * its reference needs dropping.\n * @private\n * @param {MapboxGeocoderControl} control\n */\n __addControl(control: MapboxGeocoderControl) {\n if (this.__control) {\n if (!this.$options.addToMap) {\n this.__control.onRemove();\n }\n this.__control = undefined;\n }\n\n control.on?.('result', (event) => this.$emit('map-result', { result: event.result }));\n control.addTo(this.target);\n // Keep the control only once it is added: teardown calls `onRemove()` on it,\n // which throws on a control that never rendered.\n this.__control = control;\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, the geocoder module was never loaded, or a geocoder without\n // a parent map had no access token.\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":";;;;;;;;;;;;;;;;;;;;;AAyDA,IAAa,iBAAb,cAAqE,uBAEnE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,eAAe;EACf,SAAS;GACP,aAAa;GACb,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;EAId,MAAM,aACJ,CAAC,KAAK,SAAS,YAAY,CAAC,KAAK,IAAI,eAAe,QAAQ,YAAY,YAAY,CAAC;AAEvF,MAAI,cAAc,CAAC,KAAK,kBAAkB,CAAC,aAAa;AACtD,QAAK,MACH,wCACA,yGACD;AACD;;EAGF,MAAM,uBAAuB,MAAM,uBAAuB;AAM1D,MAAI,CAAC,KAAK,WACR;AAGF,MAAI,YAAY;AAGd,OAAI;AACF,SAAK,aAAa,IAAI,qBAAqB,KAAK,kBAAkB,CAAC,CAAC;YAC7D,KAAK;AACZ,SAAK,cAAc,IAAI;;AAEzB;;AAIF,OAAK,mBAAmB;AACtB,QAAK,aACH,IAAI,qBAAqB;IACvB,GAAG,KAAK,iBAAiB,KAAK,kBAAkB,SAAS,YAAY;IACrE,UAAU,aAAa;IACxB,CAAC,CACH;IACD;;;;;;;;;;;;;CAcJ,iBAAiB,qBAAuD;AACtE,SAAO;GACL,aAAa,KAAK,SAAS,eAAe;GAC1C,GAAG,KAAK,SAAS;GAClB;;;;;;;;;;;;;;;;;CAkBH,aAAa,SAAgC;AAC3C,MAAI,KAAK,WAAW;AAClB,OAAI,CAAC,KAAK,SAAS,SACjB,MAAK,UAAU,UAAU;AAE3B,QAAK,YAAY,KAAA;;AAGnB,UAAQ,KAAK,WAAW,UAAU,KAAK,MAAM,cAAc,EAAE,QAAQ,MAAM,QAAQ,CAAC,CAAC;AACrF,UAAQ,MAAM,KAAK,OAAO;AAG1B,OAAK,YAAY;;;;;CAMnB,gBAAgB;AAId,MAAI,KAAK,WAAW;AAClB,OAAI,KAAK,SAAS,SAChB,MAAK,YAAY,cAAc,KAAK,UAAiC;OAErE,MAAK,UAAU,UAAU;AAE3B,QAAK,YAAY,KAAA"}
@@ -1,5 +1,5 @@
1
- import { AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
2
- import * as _studiometa_js_toolkit0 from "@studiometa/js-toolkit";
1
+ import { AbstractMapboxControl, AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
2
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import * as mapbox_gl0 from "mapbox-gl";
4
4
  import { GeolocateControlOptions } from "mapbox-gl";
5
5
 
@@ -7,12 +7,16 @@ import { GeolocateControlOptions } from "mapbox-gl";
7
7
  interface MapboxGeolocateControlProps extends AbstractMapboxControlProps {
8
8
  $options: AbstractMapboxControlProps['$options'] & Omit<GeolocateControlOptions, 'geolocation'>;
9
9
  }
10
- declare const MapboxGeolocateControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
11
10
  /**
12
11
  * Add a geolocate control to the map.
12
+ *
13
13
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
14
14
  */
15
- declare class MapboxGeolocateControl extends MapboxGeolocateControl_base {
15
+ declare class MapboxGeolocateControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<T & MapboxGeolocateControlProps> {
16
+ /**
17
+ * Config.
18
+ */
19
+ static config: BaseConfig;
16
20
  /**
17
21
  * Create the mapbox GeolocateControl instance.
18
22
  * @protected
@@ -1,22 +1,26 @@
1
1
  import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
4
3
  //#region src/MapboxGeolocateControl.ts
5
4
  /**
6
5
  * Add a geolocate control to the map.
6
+ *
7
7
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
8
8
  */
9
- var MapboxGeolocateControl = class extends withExtraConfig(AbstractMapboxControl, {
10
- name: "MapboxGeolocateControl",
11
- options: {
12
- positionOptions: Object,
13
- fitBoundsOptions: Object,
14
- trackUserLocation: Boolean,
15
- showAccuracyCircle: Boolean,
16
- showUserLocation: Boolean,
17
- showUserHeading: Boolean
18
- }
19
- }) {
9
+ var MapboxGeolocateControl = class extends AbstractMapboxControl {
10
+ /**
11
+ * Config.
12
+ */
13
+ static config = {
14
+ name: "MapboxGeolocateControl",
15
+ options: {
16
+ positionOptions: Object,
17
+ fitBoundsOptions: Object,
18
+ trackUserLocation: Boolean,
19
+ showAccuracyCircle: Boolean,
20
+ showUserLocation: Boolean,
21
+ showUserHeading: Boolean
22
+ }
23
+ };
20
24
  /**
21
25
  * Create the mapbox GeolocateControl instance.
22
26
  * @protected
@@ -1 +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"}
1
+ {"version":3,"file":"MapboxGeolocateControl.js","names":[],"sources":["../src/MapboxGeolocateControl.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { GeolocateControlOptions } from 'mapbox-gl';\nimport { AbstractMapboxControl, type AbstractMapboxControlProps } 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 *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxGeolocateControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<\n T & MapboxGeolocateControlProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\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 /**\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":";;;;;;;;AAcA,IAAa,yBAAb,cAA6E,sBAE3E;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,iBAAiB;GACjB,kBAAkB;GAClB,mBAAmB;GACnB,oBAAoB;GACpB,kBAAkB;GAClB,iBAAiB;GAClB;EACF;;;;;CAMD,cAAc,SAAkC;AAC9C,SAAO,KAAK,aAAa,EAAC,iBAAkB,QAAQ"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
2
- import { MapboxImageOptions } from "./utils.js";
2
+ import { MapboxImage as MapboxImage$1, MapboxImageOptions } from "./utils.js";
3
3
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
4
 
5
5
  //#region src/MapboxImage.d.ts
@@ -13,6 +13,16 @@ interface MapboxImageProps extends AbstractMapboxMapChildProps {
13
13
  */
14
14
  options: MapboxImageOptions;
15
15
  };
16
+ /**
17
+ * Announced once the sprite is registered against the map.
18
+ */
19
+ $emits: AbstractMapboxMapChildProps['$emits'] & {
20
+ 'map-ready': {
21
+ name: string;
22
+ image: MapboxImage$1;
23
+ options: MapboxImageOptions;
24
+ };
25
+ };
16
26
  }
17
27
  /**
18
28
  * Load and register a single image against the map sprite.
@@ -11,7 +11,6 @@ var MapboxImage = class extends AbstractMapboxMapChild {
11
11
  */
12
12
  static config = {
13
13
  name: "MapboxImage",
14
- emits: ["map-ready"],
15
14
  options: {
16
15
  name: String,
17
16
  url: String,
@@ -1 +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"}
1
+ {"version":3,"file":"MapboxImage.js","names":[],"sources":["../src/MapboxImage.ts"],"sourcesContent":["import type { BaseProps, 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 MapboxImage as MapboxImageBitmap,\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 * Announced once the sprite is registered against the map.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-ready': { name: string; image: MapboxImageBitmap; 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 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":";;;;;;;AAoCA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,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"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
2
- import { MapboxImageDefinition } from "./utils.js";
2
+ import { MapboxImage, MapboxImageDefinition } from "./utils.js";
3
3
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
4
  import { Map } from "mapbox-gl";
5
5
 
@@ -12,6 +12,14 @@ interface MapboxImagesProps extends AbstractMapboxMapChildProps {
12
12
  */
13
13
  sources: MapboxImageDefinition[];
14
14
  };
15
+ /**
16
+ * Announced once every sprite in the list is registered against the map.
17
+ */
18
+ $emits: AbstractMapboxMapChildProps['$emits'] & {
19
+ 'map-ready': {
20
+ images: MapboxImage[];
21
+ };
22
+ };
15
23
  }
16
24
  /**
17
25
  * Load and register a list of images against the map sprite.
@@ -11,7 +11,6 @@ var MapboxImages = class extends AbstractMapboxMapChild {
11
11
  */
12
12
  static config = {
13
13
  name: "MapboxImages",
14
- emits: ["map-ready"],
15
14
  options: { sources: {
16
15
  type: Array,
17
16
  default: () => []
@@ -48,7 +47,7 @@ var MapboxImages = class extends AbstractMapboxMapChild {
48
47
  if (this.__readyMap === map) this.__removeOwned(map);
49
48
  return;
50
49
  }
51
- this.$emit("map-ready", images);
50
+ this.$emit("map-ready", { images });
52
51
  });
53
52
  }
54
53
  /**