@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
package/README.md CHANGED
@@ -21,20 +21,23 @@ npm install @mapbox/mapbox-gl-geocoder
21
21
 
22
22
  ## Usage
23
23
 
24
- Register each component your page uses: each one registers independently and resolves its parent map on its own. `mapbox-gl` is heavy (~230 kB gzipped), so the recommended default is to lazy-register each component with js-toolkit's `importWhen*` helpers and the per-component subpaths (each subpath's default export is the component class), keeping the dependency out of your main bundle until a map is actually on the page:
24
+ Register each component your page uses: each one registers independently and resolves its parent map on its own.
25
25
 
26
26
  ```js
27
- import { registerComponents, importWhenVisible } from '@studiometa/js-toolkit';
27
+ import { registerComponents } from '@studiometa/js-toolkit';
28
+ import { MapboxMap, MapboxMarker, MapboxPopup } from '@studiometa/ui-mapbox';
28
29
 
29
30
  // Register only the components your page uses; order doesn't matter.
30
- registerComponents(
31
- importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxMap'), 'MapboxMap'),
32
- importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxMarker'), 'MapboxMarker'),
33
- importWhenVisible(() => import('@studiometa/ui-mapbox/MapboxPopup'), 'MapboxPopup'),
34
- );
31
+ registerComponents(MapboxMap, MapboxMarker, MapboxPopup);
35
32
  ```
36
33
 
37
- Other triggers are available too — `importWhenIdle`, `importOnInteraction` and `importOnMediaQuery` — see the [`importWhen*` helper docs](https://js-toolkit.studiometa.dev/api/helpers/importWhenVisible.html). Then author the map declaratively in your markup:
34
+ `mapbox-gl` is heavy (~230 kB gzipped), but it is never in your main bundle: `MapboxMap` loads it with a dynamic `import()` when it mounts, and `MapboxMap` mounts only when the map nears the viewport. The autoload entry also defers the component modules. It registers a lazy entry for every component of the package, and imports a component module only when an element on the page declares its token:
35
+
36
+ ```js
37
+ import '@studiometa/ui-mapbox/autoload';
38
+ ```
39
+
40
+ Then author the map declaratively in your markup:
38
41
 
39
42
  ```html
40
43
  <div
@@ -48,14 +51,7 @@ Other triggers are available too — `importWhenIdle`, `importOnInteraction` and
48
51
  </div>
49
52
  ```
50
53
 
51
- If you do not need code-splitting, register eagerly instead — each component is exported by name from the package:
52
-
53
- ```js
54
- import { registerComponent } from '@studiometa/js-toolkit';
55
- import { MapboxMap } from '@studiometa/ui-mapbox';
56
-
57
- registerComponent(MapboxMap);
58
- ```
54
+ `MapboxMarker` renders nothing of its own, because it configures the map from its attributes, so its element carries `hidden`. The autoload manifest gives the map children the `eager` mount strategy, so they load because their element exists, `hidden` or not. `MapboxMap`, `StoreLocator` and `MapboxGeocoder` keep `visible`, which holds `mapbox-gl` and `@mapbox/mapbox-gl-geocoder` back until they near the viewport. Do not put `hidden` on a `MapboxGeocoder`: it holds the search input, or nothing when it is added to the map, and a hidden element never loads. Override any strategy per element with `data-mount`.
59
55
 
60
56
  Do not forget to include the `mapbox-gl` stylesheet so the map renders correctly.
61
57
 
@@ -30,7 +30,7 @@ var AbstractMapboxControl = class extends AbstractMapboxMapChild {
30
30
  */
31
31
  get control() {
32
32
  if (!this.__control) {
33
- const { position: _position, name: _name, debug: _debug, log: _log, ...options } = this.$options;
33
+ const { position: _position, ...options } = this.$options;
34
34
  this.__control = this.createControl(options);
35
35
  }
36
36
  return this.__control;
@@ -1 +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
+ {"version":3,"file":"AbstractMapboxControl.js","names":[],"sources":["../src/AbstractMapboxControl.ts"],"sourcesContent":["import type { BaseProps, 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 // `position` is consumed by `map.addControl()`; every other option\n // belongs to the concrete control.\n const { position: _position, ...options } = 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;GAGnB,MAAM,EAAE,UAAU,WAAW,GAAG,YAAY,KAAK;AACjD,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"}
@@ -4,7 +4,17 @@ import { Map } from "mapbox-gl";
4
4
  import { Base } from "@studiometa/js-toolkit/Base";
5
5
 
6
6
  //#region src/AbstractMapboxMapChild.d.ts
7
- interface AbstractMapboxMapChildProps extends BaseProps {}
7
+ interface AbstractMapboxMapChildProps extends BaseProps {
8
+ /**
9
+ * The one event every map child can emit, dispatched whenever its injection
10
+ * or its teardown throws.
11
+ */
12
+ $emits: {
13
+ 'map-error': {
14
+ error: unknown;
15
+ };
16
+ };
17
+ }
8
18
  /**
9
19
  * Document-level event a `MapboxMap` dispatches when its instance mounts, so a
10
20
  * child that mounted *before* its map (e.g. an eagerly registered child under a
@@ -34,7 +44,7 @@ declare const MAPBOX_MAP_CONNECTED = "mapbox-map:connected";
34
44
  * global queue runs lifecycle hooks with no try/catch: a single synchronous
35
45
  * throw wedges the queue and freezes every mount/destroy on the page. The
36
46
  * ready callback and the subclass teardown (`__onDestroyed`) are both run
37
- * inside a try/catch that routes to `$warn` + a `map-error` event and never
47
+ * inside a try/catch that routes to `$error` + a `map-error` event and never
38
48
  * rethrows.
39
49
  * 2. **Dead-map safety** — once ready, the child subscribes to the map's own
40
50
  * `remove` event; when it fires the cached map reference is dropped so no
@@ -62,7 +72,7 @@ declare class AbstractMapboxMapChild<T extends BaseProps = BaseProps> extends Ba
62
72
  /**
63
73
  * The parent `MapboxMap` resolved at ready-time.
64
74
  *
65
- * `destroyed()` runs *after* the element has been detached from the DOM (e.g.
75
+ * `unmounted()` runs *after* the element has been detached from the DOM (e.g.
66
76
  * a `Fetch` list swap, or the parent map itself being removed), and a
67
77
  * `$closest` lookup on a disconnected node returns nothing — a real bug that
68
78
  * would leave the child's contribution stuck on the map. Caching the resolved
@@ -84,7 +94,7 @@ declare class AbstractMapboxMapChild<T extends BaseProps = BaseProps> extends Ba
84
94
  *
85
95
  * The callback may be synchronous or `async`: a returned promise is awaited
86
96
  * inside the same containment as a synchronous body, so a rejection routes to
87
- * `$warn` + the `map-error` event instead of surfacing as an unhandled rejection.
97
+ * `$error` + the `map-error` event instead of surfacing as an unhandled rejection.
88
98
  * @private
89
99
  */
90
100
  __readyCallback?: (map: Map) => void | Promise<void>;
@@ -158,7 +168,7 @@ declare class AbstractMapboxMapChild<T extends BaseProps = BaseProps> extends Ba
158
168
  * Run the ready callback inside a uniform containment for both synchronous
159
169
  * throws and rejected promises: a synchronous body is wrapped in `try/catch`,
160
170
  * and an `async` body's returned promise is awaited so its rejection routes to
161
- * `$warn` + the `map-error` event instead of becoming an unhandled rejection.
171
+ * `$error` + the `map-error` event instead of becoming an unhandled rejection.
162
172
  * Neither path ever rethrows into the global lifecycle queue.
163
173
  * @private
164
174
  * @param {Map} map
@@ -188,8 +198,10 @@ declare class AbstractMapboxMapChild<T extends BaseProps = BaseProps> extends Ba
188
198
  */
189
199
  __bindStyleReload(map: Map): void;
190
200
  /**
191
- * Contain an error raised by a guarded injection or teardown: warn and emit an
192
- * `map-error` event, but never rethrow into the global queue.
201
+ * Contain an error raised by a guarded injection or teardown: report it on the
202
+ * diagnostic channel — `$error()`, which carries the cause a warning has
203
+ * nowhere to put — and emit a `map-error` event, but never rethrow into the
204
+ * global queue.
193
205
  * @private
194
206
  * @param {unknown} err
195
207
  */
@@ -208,9 +220,9 @@ declare class AbstractMapboxMapChild<T extends BaseProps = BaseProps> extends Ba
208
220
  */
209
221
  __onMapRemove(_map: Map): void;
210
222
  /**
211
- * Teardown hook implemented by subclasses instead of `destroyed()`.
223
+ * Teardown hook implemented by subclasses instead of `unmounted()`.
212
224
  *
213
- * It runs inside the base's guard (see `destroyed`) so a throwing teardown — a
225
+ * It runs inside the base's guard (see `unmounted`) so a throwing teardown — a
214
226
  * style-touching mapbox call, most often — can never wedge the global queue.
215
227
  * Implementations read the cached `__readyMap`, which is already `undefined`
216
228
  * when the map has been removed, and must not call `super`.
@@ -218,13 +230,21 @@ declare class AbstractMapboxMapChild<T extends BaseProps = BaseProps> extends Ba
218
230
  */
219
231
  __onDestroyed(): void;
220
232
  /**
221
- * Destroyed hook.
233
+ * Unmounted hook.
222
234
  *
223
235
  * Runs the guarded subclass teardown, then flushes every base subscription
224
236
  * (`map-load`, the map's `remove`, the connected retry). Subclasses override
225
237
  * `__onDestroyed` rather than this method.
226
- */
227
- destroyed(): void;
238
+ *
239
+ * **`__readyMap` and `__readyMapboxMap` are deliberately kept.** An
240
+ * asynchronous injection still in flight — `MapboxImage` awaiting
241
+ * `loadImage`, `MapboxImages` awaiting its batch — resolves after this runs
242
+ * and undoes itself by checking `this.__readyMap === map`. Clearing them here
243
+ * would read like an obvious cleanup and would strand every sprite those
244
+ * paths add after teardown. The map reference is dropped by the map's own
245
+ * `remove` handler instead, which is the event that actually invalidates it.
246
+ */
247
+ unmounted(): void;
228
248
  }
229
249
  //#endregion
230
250
  export { AbstractMapboxMapChild, AbstractMapboxMapChild as default, AbstractMapboxMapChildProps, MAPBOX_MAP_CONNECTED };
@@ -29,7 +29,7 @@ const MAPBOX_MAP_CONNECTED = "mapbox-map:connected";
29
29
  * global queue runs lifecycle hooks with no try/catch: a single synchronous
30
30
  * throw wedges the queue and freezes every mount/destroy on the page. The
31
31
  * ready callback and the subclass teardown (`__onDestroyed`) are both run
32
- * inside a try/catch that routes to `$warn` + a `map-error` event and never
32
+ * inside a try/catch that routes to `$error` + a `map-error` event and never
33
33
  * rethrows.
34
34
  * 2. **Dead-map safety** — once ready, the child subscribes to the map's own
35
35
  * `remove` event; when it fires the cached map reference is dropped so no
@@ -53,14 +53,11 @@ var AbstractMapboxMapChild = class extends Base {
53
53
  /**
54
54
  * Config.
55
55
  */
56
- static config = {
57
- name: "AbstractMapboxMapChild",
58
- emits: ["map-error"]
59
- };
56
+ static config = { name: "AbstractMapboxMapChild" };
60
57
  /**
61
58
  * The parent `MapboxMap` resolved at ready-time.
62
59
  *
63
- * `destroyed()` runs *after* the element has been detached from the DOM (e.g.
60
+ * `unmounted()` runs *after* the element has been detached from the DOM (e.g.
64
61
  * a `Fetch` list swap, or the parent map itself being removed), and a
65
62
  * `$closest` lookup on a disconnected node returns nothing — a real bug that
66
63
  * would leave the child's contribution stuck on the map. Caching the resolved
@@ -82,7 +79,7 @@ var AbstractMapboxMapChild = class extends Base {
82
79
  *
83
80
  * The callback may be synchronous or `async`: a returned promise is awaited
84
81
  * inside the same containment as a synchronous body, so a rejection routes to
85
- * `$warn` + the `map-error` event instead of surfacing as an unhandled rejection.
82
+ * `$error` + the `map-error` event instead of surfacing as an unhandled rejection.
86
83
  * @private
87
84
  */
88
85
  __readyCallback;
@@ -112,7 +109,7 @@ var AbstractMapboxMapChild = class extends Base {
112
109
  */
113
110
  get mapboxMap() {
114
111
  const mapboxMap = this.$closest("MapboxMap");
115
- if (!mapboxMap) this.$warn("Can not find the parent map, does this component has a parent MapboxMap component?");
112
+ if (!mapboxMap) this.$warn("mapbox-map-child.orphan", "Can not find the parent map, does this component has a parent MapboxMap component?");
116
113
  return mapboxMap;
117
114
  }
118
115
  /**
@@ -203,7 +200,7 @@ var AbstractMapboxMapChild = class extends Base {
203
200
  * Run the ready callback inside a uniform containment for both synchronous
204
201
  * throws and rejected promises: a synchronous body is wrapped in `try/catch`,
205
202
  * and an `async` body's returned promise is awaited so its rejection routes to
206
- * `$warn` + the `map-error` event instead of becoming an unhandled rejection.
203
+ * `$error` + the `map-error` event instead of becoming an unhandled rejection.
207
204
  * Neither path ever rethrows into the global lifecycle queue.
208
205
  * @private
209
206
  * @param {Map} map
@@ -274,14 +271,16 @@ var AbstractMapboxMapChild = class extends Base {
274
271
  this.__offStyleReload = () => map.off("style.load", handler);
275
272
  }
276
273
  /**
277
- * Contain an error raised by a guarded injection or teardown: warn and emit an
278
- * `map-error` event, but never rethrow into the global queue.
274
+ * Contain an error raised by a guarded injection or teardown: report it on the
275
+ * diagnostic channel — `$error()`, which carries the cause a warning has
276
+ * nowhere to put — and emit a `map-error` event, but never rethrow into the
277
+ * global queue.
279
278
  * @private
280
279
  * @param {unknown} err
281
280
  */
282
281
  __handleError(err) {
283
- this.$warn(err);
284
- this.$emit("map-error", err);
282
+ this.$error("mapbox-map-child.failed", "A guarded map injection or teardown threw.", err);
283
+ this.$emit("map-error", { error: err });
285
284
  }
286
285
  /**
287
286
  * Hook run when the ready map fires its own `remove` event, while the map is
@@ -297,9 +296,9 @@ var AbstractMapboxMapChild = class extends Base {
297
296
  */
298
297
  __onMapRemove(_map) {}
299
298
  /**
300
- * Teardown hook implemented by subclasses instead of `destroyed()`.
299
+ * Teardown hook implemented by subclasses instead of `unmounted()`.
301
300
  *
302
- * It runs inside the base's guard (see `destroyed`) so a throwing teardown — a
301
+ * It runs inside the base's guard (see `unmounted`) so a throwing teardown — a
303
302
  * style-touching mapbox call, most often — can never wedge the global queue.
304
303
  * Implementations read the cached `__readyMap`, which is already `undefined`
305
304
  * when the map has been removed, and must not call `super`.
@@ -307,13 +306,21 @@ var AbstractMapboxMapChild = class extends Base {
307
306
  */
308
307
  __onDestroyed() {}
309
308
  /**
310
- * Destroyed hook.
309
+ * Unmounted hook.
311
310
  *
312
311
  * Runs the guarded subclass teardown, then flushes every base subscription
313
312
  * (`map-load`, the map's `remove`, the connected retry). Subclasses override
314
313
  * `__onDestroyed` rather than this method.
314
+ *
315
+ * **`__readyMap` and `__readyMapboxMap` are deliberately kept.** An
316
+ * asynchronous injection still in flight — `MapboxImage` awaiting
317
+ * `loadImage`, `MapboxImages` awaiting its batch — resolves after this runs
318
+ * and undoes itself by checking `this.__readyMap === map`. Clearing them here
319
+ * would read like an obvious cleanup and would strand every sprite those
320
+ * paths add after teardown. The map reference is dropped by the map's own
321
+ * `remove` handler instead, which is the event that actually invalidates it.
315
322
  */
316
- destroyed() {
323
+ unmounted() {
317
324
  try {
318
325
  this.__onDestroyed();
319
326
  } catch (err) {
@@ -1 +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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAK,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"}
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 * The one event every map child can emit, dispatched whenever its injection\n * or its teardown throws.\n */\n $emits: {\n 'map-error': { error: unknown };\n };\n}\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 `$error` + 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 };\n\n /**\n * The parent `MapboxMap` resolved at ready-time.\n *\n * `unmounted()` 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 * `$error` + 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 'mapbox-map-child.orphan',\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 * `$error` + 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: report it on the\n * diagnostic channel — `$error()`, which carries the cause a warning has\n * nowhere to put — and emit a `map-error` event, but never rethrow into the\n * global queue.\n * @private\n * @param {unknown} err\n */\n __handleError(err: unknown): void {\n this.$error('mapbox-map-child.failed', 'A guarded map injection or teardown threw.', err);\n this.$emit('map-error', { 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 `unmounted()`.\n *\n * It runs inside the base's guard (see `unmounted`) 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 * Unmounted 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 * **`__readyMap` and `__readyMapboxMap` are deliberately kept.** An\n * asynchronous injection still in flight — `MapboxImage` awaiting\n * `loadImage`, `MapboxImages` awaiting its batch — resolves after this runs\n * and undoes itself by checking `this.__readyMap === map`. Clearing them here\n * would read like an obvious cleanup and would strand every sprite those\n * paths add after teardown. The map reference is dropped by the map's own\n * `remove` handler instead, which is the event that actually invalidates it.\n */\n unmounted() {\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":";;;;;;;;AAqBA,MAAa,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,OAAO,2BAA2B,8CAA8C,IAAI;AACzF,OAAK,MAAM,aAAa,EAAE,OAAO,KAAK,CAAC;;;;;;;;;;;;;;CAezC,cAAc,MAAW;;;;;;;;;;CAWzB,gBAAgB;;;;;;;;;;;;;;;;CAiBhB,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"}
@@ -2,7 +2,7 @@ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractM
2
2
  import { MapboxClusterItem } from "./MapboxClusterItem.js";
3
3
  import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
4
  import { CircleLayerSpecification, GeoJSONSourceSpecification, Map, MapMouseEvent, SymbolLayerSpecification } from "mapbox-gl";
5
- import { FeatureCollection, Point } from "geojson";
5
+ import { Feature, FeatureCollection, Point } from "geojson";
6
6
 
7
7
  //#region src/MapboxCluster.d.ts
8
8
  /**
@@ -26,6 +26,23 @@ interface MapboxClusterProps extends AbstractMapboxMapChildProps {
26
26
  unclusteredPointLayout: Record<string, unknown>;
27
27
  unclusteredPointPaint: Record<string, unknown>;
28
28
  };
29
+ /**
30
+ * The cluster's own events, on top of the inherited `map-error`.
31
+ */
32
+ $emits: AbstractMapboxMapChildProps['$emits'] & {
33
+ 'map-cluster-click': {
34
+ clusterId: number;
35
+ event: MapMouseEvent;
36
+ };
37
+ 'map-item-click': {
38
+ item: MapboxClusterItem | undefined;
39
+ feature: Feature | undefined;
40
+ event: MapMouseEvent;
41
+ };
42
+ 'map-update': {
43
+ items: readonly MapboxClusterItem[];
44
+ };
45
+ };
29
46
  }
30
47
  /**
31
48
  * A clustered GeoJSON **source driver** whose features ARE its rendered items.
@@ -119,7 +136,7 @@ declare class MapboxCluster<T extends BaseProps = BaseProps> extends AbstractMap
119
136
  * spanning multiple ticks results in one map data update.
120
137
  * @private
121
138
  */
122
- __scheduleRebuild: (...args: unknown[]) => void;
139
+ __scheduleRebuild: () => void;
123
140
  /**
124
141
  * Push the derived feature collection to the source and announce the change.
125
142
  * No-op until the map is ready (the initial build happens in `whenMapReady`).
@@ -49,11 +49,6 @@ var MapboxCluster = class extends AbstractMapboxMapChild {
49
49
  */
50
50
  static config = {
51
51
  name: "MapboxCluster",
52
- emits: [
53
- "map-cluster-click",
54
- "map-item-click",
55
- "map-update"
56
- ],
57
52
  options: {
58
53
  clusterMaxZoom: {
59
54
  type: Number,
@@ -216,7 +211,7 @@ var MapboxCluster = class extends AbstractMapboxMapChild {
216
211
  __rebuild() {
217
212
  if (!this.__readyMap) return;
218
213
  this.setData(this.featureCollection);
219
- this.$emit("map-update", this.items);
214
+ this.$emit("map-update", { items: this.items });
220
215
  }
221
216
  /**
222
217
  * Click handler for the clusters layer, zooming on the clicked cluster.
@@ -228,7 +223,10 @@ var MapboxCluster = class extends AbstractMapboxMapChild {
228
223
  const feature = map.queryRenderedFeatures(event.point, { layers: [this.__getId("clusters")] })[0];
229
224
  if (!feature) return;
230
225
  const clusterId = feature.properties?.cluster_id;
231
- this.$emit("map-cluster-click", clusterId, event);
226
+ this.$emit("map-cluster-click", {
227
+ clusterId,
228
+ event
229
+ });
232
230
  if (event.defaultPrevented) return;
233
231
  map.getSource(this.__getId("source"))?.getClusterExpansionZoom(clusterId, (error, zoom) => {
234
232
  if (this.__readyMap !== map || error || zoom === null || zoom === void 0 || feature.geometry.type !== "Point") return;
@@ -272,7 +270,11 @@ var MapboxCluster = class extends AbstractMapboxMapChild {
272
270
  const feature = event.features?.[0];
273
271
  const id = feature?.properties?.id;
274
272
  const item = id === void 0 || id === null ? void 0 : this.__items.find((candidate) => candidate.id === String(id));
275
- this.$emit("map-item-click", item, feature, event);
273
+ this.$emit("map-item-click", {
274
+ item,
275
+ feature,
276
+ event
277
+ });
276
278
  };
277
279
  /**
278
280
  * Set a pointer cursor when entering an unclustered point.
@@ -364,7 +366,7 @@ var MapboxCluster = class extends AbstractMapboxMapChild {
364
366
  map.on("click", unclusteredPointId, this.__handleUnclusteredClick);
365
367
  map.on("mouseenter", unclusteredPointId, this.__handleUnclusteredMouseenter);
366
368
  map.on("mouseleave", unclusteredPointId, this.__handleUnclusteredMouseleave);
367
- this.$emit("map-update", this.items);
369
+ this.$emit("map-update", { items: this.items });
368
370
  }
369
371
  /**
370
372
  * Detach every map-scoped listener wired in `mounted`.
@@ -1 +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;;;;;C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KAAK,2BAA2B;AAClE,MAAI,IAAI,cAAc,YAAY,KAAK,2BAA2B;AAClE,MAAI,IAAI,SAAS,oBAAoB,KAAK,yBAAyB;AACnE,MAAI,IAAI,cAAc,oBAAoB,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
+ {"version":3,"file":"MapboxCluster.js","names":[],"sources":["../src/MapboxCluster.ts"],"sourcesContent":["import type { BaseProps, 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 { Feature, 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 * The cluster's own events, on top of the inherited `map-error`.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-cluster-click': { clusterId: number; event: MapMouseEvent };\n 'map-item-click': {\n item: MapboxClusterItem | undefined;\n feature: Feature | undefined;\n event: MapMouseEvent;\n };\n 'map-update': { items: readonly MapboxClusterItem[] };\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 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', { items: 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', { items: 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;;;;;;;;;;;;;;;;;;;;;;;;AAqDT,IAAa,gBAAb,cAAoE,uBAElE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,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,EA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