@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
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxImages.js","names":[],"sources":["../src/MapboxImages.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport type { Map } from 'mapbox-gl';\nimport {\n addMapboxImage,\n claimMapboxOwnership,\n getMapboxOwner,\n releaseMapboxOwnership,\n type MapboxImageDefinition,\n} from './utils.js';\n\nexport interface MapboxImagesProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * A list of images to register against the map sprite.\n * @see ./MapboxImage.ts\n */\n sources: MapboxImageDefinition[];\n };\n}\n\n/**\n * Load and register a list of images against the map sprite.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxImages<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxImagesProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxImages',\n emits: ['map-ready'],\n options: {\n sources: {\n type: Array,\n default: () => [],\n },\n },\n };\n\n /**\n * The names of the sprites this instance owns. Only these may be removed on\n * teardown; pre-existing sprites (registered by someone else) are left\n * untouched, and a sprite a newer sibling has since adopted is left to it.\n * @private\n */\n __ownedNames: string[] = [];\n\n /**\n * The `kind:name` ownership key for the given sprite.\n * @private\n * @param {string} name\n * @returns {string}\n */\n __ownershipKey(name: string): string {\n return `image:${name}`;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady(async (map) => {\n const { sources } = this.$options;\n const images = await Promise.all(\n sources.map(async (source) => {\n const { image, added } = await addMapboxImage(map, source);\n // Take ownership incrementally, as each image settles, rather than\n // after the whole batch: if a later entry rejects, `Promise.all`\n // rejects, but the sprites already added stay owned and removable on\n // teardown instead of orphaned.\n this.__adopt(map, source.name, added);\n return image;\n }),\n );\n\n // The component may have been destroyed — or the map removed/replaced —\n // while the images were loading. Remove the ones we own (only while the\n // map is still current & alive) and bail before emitting to avoid orphans.\n if (!this.$isMounted || this.__readyMap !== map) {\n if (this.__readyMap === map) {\n this.__removeOwned(map);\n }\n return;\n }\n\n this.$emit('map-ready', images);\n });\n }\n\n /**\n * Own a sprite this instance added, or adopt one from a family sibling (a\n * same-name `Fetch` swap), so the outgoing instance's teardown does not remove\n * a sprite this replacement now depends on.\n * @private\n * @param {Map} map\n * @param {string} name\n * @param {boolean} added\n */\n __adopt(map: Map, name: string, added: boolean) {\n if (added || getMapboxOwner(map, this.__ownershipKey(name))) {\n // Sprites expose no object identity, so liveness can only probe\n // `hasImage`: enough to drop the entry after a `setStyle` wipe or an\n // external `removeImage`, and to re-own on a `style.load` re-injection.\n claimMapboxOwnership(map, this.__ownershipKey(name), this, () => map.hasImage(name));\n if (!this.__ownedNames.includes(name)) {\n this.__ownedNames.push(name);\n }\n }\n }\n\n /**\n * Remove every sprite this instance still owns from the given map, releasing\n * ownership as it goes.\n * @private\n * @param {Map | undefined} map\n */\n __removeOwned(map?: Map) {\n for (const name of this.__ownedNames) {\n const key = this.__ownershipKey(name);\n if (getMapboxOwner(map as object, key) === this && map?.hasImage(name)) {\n map.removeImage(name);\n releaseMapboxOwnership(map, key, this);\n }\n }\n this.__ownedNames = [];\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__removeOwned(this.__readyMap);\n }\n}\n\nexport default MapboxImages;\n"],"mappings":";;;;;;;AA4BA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,YAAY;EACpB,SAAS,EACP,SAAS;GACP,MAAM;GACN,eAAe,EAAE;GAClB,EACF;EACF;;;;;;;CAQD,eAAyB,EAAE;;;;;;;CAQ3B,eAAe,MAAsB;AACnC,SAAO,SAAS;;;;;CAMlB,UAAU;AACR,OAAK,aAAa,OAAO,QAAQ;GAC/B,MAAM,EAAE,YAAY,KAAK;GACzB,MAAM,SAAS,MAAM,QAAQ,IAC3B,QAAQ,IAAI,OAAO,WAAW;IAC5B,MAAM,EAAE,OAAO,UAAU,MAAM,eAAe,KAAK,OAAO;AAK1D,SAAK,QAAQ,KAAK,OAAO,MAAM,MAAM;AACrC,WAAO;KACP,CACH;AAKD,OAAI,CAAC,KAAK,cAAc,KAAK,eAAe,KAAK;AAC/C,QAAI,KAAK,eAAe,IACtB,MAAK,cAAc,IAAI;AAEzB;;AAGF,QAAK,MAAM,aAAa,OAAO;IAC/B;;;;;;;;;;;CAYJ,QAAQ,KAAU,MAAc,OAAgB;AAC9C,MAAI,SAAS,eAAe,KAAK,KAAK,eAAe,KAAK,CAAC,EAAE;AAI3D,wBAAqB,KAAK,KAAK,eAAe,KAAK,EAAE,YAAY,IAAI,SAAS,KAAK,CAAC;AACpF,OAAI,CAAC,KAAK,aAAa,SAAS,KAAK,CACnC,MAAK,aAAa,KAAK,KAAK;;;;;;;;;CAWlC,cAAc,KAAW;AACvB,OAAK,MAAM,QAAQ,KAAK,cAAc;GACpC,MAAM,MAAM,KAAK,eAAe,KAAK;AACrC,OAAI,eAAe,KAAe,IAAI,KAAK,QAAQ,KAAK,SAAS,KAAK,EAAE;AACtE,QAAI,YAAY,KAAK;AACrB,2BAAuB,KAAK,KAAK,KAAK;;;AAG1C,OAAK,eAAe,EAAE;;;;;CAMxB,gBAAgB;AACd,OAAK,cAAc,KAAK,WAAW"}
1
+ {"version":3,"file":"MapboxImages.js","names":[],"sources":["../src/MapboxImages.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport type { Map } from 'mapbox-gl';\nimport {\n addMapboxImage,\n claimMapboxOwnership,\n getMapboxOwner,\n releaseMapboxOwnership,\n type MapboxImage,\n type MapboxImageDefinition,\n} from './utils.js';\n\nexport interface MapboxImagesProps extends AbstractMapboxMapChildProps {\n $options: {\n /**\n * A list of images to register against the map sprite.\n * @see ./MapboxImage.ts\n */\n sources: MapboxImageDefinition[];\n };\n /**\n * Announced once every sprite in the list is registered against the map.\n */\n $emits: AbstractMapboxMapChildProps['$emits'] & {\n 'map-ready': { images: MapboxImage[] };\n };\n}\n\n/**\n * Load and register a list of images against the map sprite.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxImages<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxImagesProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxImages',\n options: {\n sources: {\n type: Array,\n default: () => [],\n },\n },\n };\n\n /**\n * The names of the sprites this instance owns. Only these may be removed on\n * teardown; pre-existing sprites (registered by someone else) are left\n * untouched, and a sprite a newer sibling has since adopted is left to it.\n * @private\n */\n __ownedNames: string[] = [];\n\n /**\n * The `kind:name` ownership key for the given sprite.\n * @private\n * @param {string} name\n * @returns {string}\n */\n __ownershipKey(name: string): string {\n return `image:${name}`;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady(async (map) => {\n const { sources } = this.$options;\n const images = await Promise.all(\n sources.map(async (source) => {\n const { image, added } = await addMapboxImage(map, source);\n // Take ownership incrementally, as each image settles, rather than\n // after the whole batch: if a later entry rejects, `Promise.all`\n // rejects, but the sprites already added stay owned and removable on\n // teardown instead of orphaned.\n this.__adopt(map, source.name, added);\n return image;\n }),\n );\n\n // The component may have been destroyed — or the map removed/replaced —\n // while the images were loading. Remove the ones we own (only while the\n // map is still current & alive) and bail before emitting to avoid orphans.\n if (!this.$isMounted || this.__readyMap !== map) {\n if (this.__readyMap === map) {\n this.__removeOwned(map);\n }\n return;\n }\n\n this.$emit('map-ready', { images });\n });\n }\n\n /**\n * Own a sprite this instance added, or adopt one from a family sibling (a\n * same-name `Fetch` swap), so the outgoing instance's teardown does not remove\n * a sprite this replacement now depends on.\n * @private\n * @param {Map} map\n * @param {string} name\n * @param {boolean} added\n */\n __adopt(map: Map, name: string, added: boolean) {\n if (added || getMapboxOwner(map, this.__ownershipKey(name))) {\n // Sprites expose no object identity, so liveness can only probe\n // `hasImage`: enough to drop the entry after a `setStyle` wipe or an\n // external `removeImage`, and to re-own on a `style.load` re-injection.\n claimMapboxOwnership(map, this.__ownershipKey(name), this, () => map.hasImage(name));\n if (!this.__ownedNames.includes(name)) {\n this.__ownedNames.push(name);\n }\n }\n }\n\n /**\n * Remove every sprite this instance still owns from the given map, releasing\n * ownership as it goes.\n * @private\n * @param {Map | undefined} map\n */\n __removeOwned(map?: Map) {\n for (const name of this.__ownedNames) {\n const key = this.__ownershipKey(name);\n if (getMapboxOwner(map as object, key) === this && map?.hasImage(name)) {\n map.removeImage(name);\n releaseMapboxOwnership(map, key, this);\n }\n }\n this.__ownedNames = [];\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__removeOwned(this.__readyMap);\n }\n}\n\nexport default MapboxImages;\n"],"mappings":";;;;;;;AAmCA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS,EACP,SAAS;GACP,MAAM;GACN,eAAe,EAAE;GAClB,EACF;EACF;;;;;;;CAQD,eAAyB,EAAE;;;;;;;CAQ3B,eAAe,MAAsB;AACnC,SAAO,SAAS;;;;;CAMlB,UAAU;AACR,OAAK,aAAa,OAAO,QAAQ;GAC/B,MAAM,EAAE,YAAY,KAAK;GACzB,MAAM,SAAS,MAAM,QAAQ,IAC3B,QAAQ,IAAI,OAAO,WAAW;IAC5B,MAAM,EAAE,OAAO,UAAU,MAAM,eAAe,KAAK,OAAO;AAK1D,SAAK,QAAQ,KAAK,OAAO,MAAM,MAAM;AACrC,WAAO;KACP,CACH;AAKD,OAAI,CAAC,KAAK,cAAc,KAAK,eAAe,KAAK;AAC/C,QAAI,KAAK,eAAe,IACtB,MAAK,cAAc,IAAI;AAEzB;;AAGF,QAAK,MAAM,aAAa,EAAE,QAAQ,CAAC;IACnC;;;;;;;;;;;CAYJ,QAAQ,KAAU,MAAc,OAAgB;AAC9C,MAAI,SAAS,eAAe,KAAK,KAAK,eAAe,KAAK,CAAC,EAAE;AAI3D,wBAAqB,KAAK,KAAK,eAAe,KAAK,EAAE,YAAY,IAAI,SAAS,KAAK,CAAC;AACpF,OAAI,CAAC,KAAK,aAAa,SAAS,KAAK,CACnC,MAAK,aAAa,KAAK,KAAK;;;;;;;;;CAWlC,cAAc,KAAW;AACvB,OAAK,MAAM,QAAQ,KAAK,cAAc;GACpC,MAAM,MAAM,KAAK,eAAe,KAAK;AACrC,OAAI,eAAe,KAAe,IAAI,KAAK,QAAQ,KAAK,SAAS,KAAK,EAAE;AACtE,QAAI,YAAY,KAAK;AACrB,2BAAuB,KAAK,KAAK,KAAK;;;AAG1C,OAAK,eAAe,EAAE;;;;;CAMxB,gBAAgB;AACd,OAAK,cAAc,KAAK,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxLayer.js","names":[],"sources":["../src/MapboxLayer.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { LayerSpecification, Map, MapSourceDataEvent } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxLayerProps extends AbstractMapboxMapChildProps {\n $options: {\n id: string;\n layer: LayerSpecification;\n beforeId: string;\n };\n}\n\n/**\n * Add a layer to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxLayer<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxLayerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxLayer',\n options: {\n id: String,\n layer: Object,\n beforeId: String,\n },\n };\n\n /**\n * Whether this instance owns the layer under its id. Only a layer this\n * instance owns may be removed on teardown; a layer declared outside the\n * family, or one a newer sibling has since adopted, is left untouched.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this layer.\n * @private\n */\n get __ownershipKey(): string {\n return `layer:${this.$options.id}`;\n }\n\n /**\n * The source id this layer references, when it references one by string.\n * @private\n */\n get __sourceId(): string | undefined {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source === 'string' ? source : undefined;\n }\n\n /**\n * Add (or re-add) the layer whenever its referenced source becomes available\n * and the layer is not currently on the map.\n *\n * This is a *standing* recovery watch, not a one-shot: it stays subscribed for\n * the layer's whole life so the layer re-commits itself if its source\n * disappears and comes back — e.g. a sibling `MapboxSource` teardown removes\n * this still-mounted layer to drop its source, then the source is re-added\n * later (H7, PR #567 review). Committing once and unsubscribing (the previous\n * behaviour) left such a layer gone for good.\n *\n * It is kept cheap: `sourcedata` fires often, so the handler early-returns\n * unless this layer is actually missing, and — when the event identifies a\n * source — ignores events for any source other than this layer's. The commit\n * itself is deferred to a microtask because mutating the style from within\n * mapbox-gl's render loop can leave a layer half-initialized and crash the\n * symbol placement pass.\n * @private\n * @param {MapSourceDataEvent} [event]\n */\n __handleSourceData = (event?: MapSourceDataEvent) => {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Ignore events for an unrelated source when the event tells us which one it\n // is: this gates the standing watch to this layer's source id.\n if (event?.sourceId && this.__sourceId && event.sourceId !== this.__sourceId) {\n return;\n }\n\n if (!map || map.getLayer(id) || !this.__sourceIsAvailable(map)) {\n return;\n }\n\n queueMicrotask(() => {\n // Re-check under the microtask: the map may have been removed/replaced, the\n // component destroyed, or the layer committed by another path in between.\n if (this.$isMounted && this.__readyMap === map && !map.getLayer(id)) {\n this.__commitLayer(map);\n }\n });\n };\n\n /**\n * Add the layer to the map, or adopt an existing one.\n *\n * When the id is free the layer is added and ownership claimed. When a layer\n * with this id already exists, re-adding it would throw a duplicate-id error,\n * so it is left in place; ownership is only taken over from a sibling\n * `MapboxLayer` (e.g. a `Fetch` swap), never from an externally declared layer.\n * @private\n * @param {Map} map\n */\n __commitLayer(map: Map): void {\n const { beforeId, id, layer } = this.$options;\n // `$options.layer` returns a freshly parsed object, so re-apply the id.\n layer.id = id;\n\n if (map.getLayer(id)) {\n // The id is taken. Only adopt it from another family instance (e.g. a\n // `Fetch` swap that mounted the replacement before the original tore\n // down); an externally declared layer stays untouched. Adopt AND refresh:\n // the incoming definition may differ in source/type/paint/layout/filter/\n // zoom range/beforeId, so re-add it (we own it) rather than leaving Mapbox\n // rendering the outgoing definition — matching how `MapboxSource` refreshes\n // its data on adopt.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n map.removeLayer(id);\n map.addLayer(layer, beforeId);\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n return;\n }\n\n map.addLayer(layer, beforeId);\n // Own the id, keyed to the very layer object just added: the liveness probe\n // reports the entry stale the moment this layer is removed (a `setStyle`\n // wipe, a sibling source teardown, an external `removeLayer`) or replaced\n // under the same id, so it can never misclassify a stranger's later layer.\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n\n /**\n * Whether the source referenced by the layer is available on the map.\n *\n * Layers referencing an inline source object — or no source at all, like a\n * `background` layer — are always considered available.\n * @private\n * @param {Map} map\n * @returns {boolean}\n */\n __sourceIsAvailable(map: Map): boolean {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source !== 'string' || Boolean(map.getSource(source));\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n // Install (or re-install, on a `style.load` re-injection) the standing\n // recovery watch exactly once. `off` before `on` keeps a single\n // subscription when `whenMapReady`'s callback re-runs after a `setStyle`.\n map.off('sourcedata', this.__handleSourceData);\n map.on('sourcedata', this.__handleSourceData);\n\n // The referenced source may be declared by a sibling `MapboxSource` that\n // has not mounted yet — sibling mount order is not guaranteed. Adding a\n // layer before its source silently fails, so commit now when the source is\n // available and otherwise let the standing watch commit once it arrives.\n if (this.__sourceIsAvailable(map)) {\n this.__commitLayer(map);\n }\n });\n }\n\n /**\n * Flush the standing `sourcedata` recovery watch against the map being\n * removed, while it is still referenceable — `__onDestroyed` runs later with\n * `__readyMap` already cleared and could not reach the map to unsubscribe.\n * @protected\n * @param {Map} map\n */\n __onMapRemove(map: Map) {\n map.off('sourcedata', this.__handleSourceData);\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n map?.off('sourcedata', this.__handleSourceData);\n\n // Only remove a layer this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getLayer(id)\n ) {\n map.removeLayer(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxLayer;\n"],"mappings":";;;;;;;AAoBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,IAAI;GACJ,OAAO;GACP,UAAU;GACX;EACF;;;;;;;CAQD,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,SAAS,KAAK,SAAS;;;;;;CAOhC,IAAI,aAAiC;EACnC,MAAM,EAAE,WAAW,KAAK,SAAS;AACjC,SAAO,OAAO,WAAW,WAAW,SAAS,KAAA;;;;;;;;;;;;;;;;;;;;;;CAuB/C,sBAAsB,UAA+B;EACnD,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MAAI,OAAO,YAAY,KAAK,cAAc,MAAM,aAAa,KAAK,WAChE;AAGF,MAAI,CAAC,OAAO,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,oBAAoB,IAAI,CAC5D;AAGF,uBAAqB;AAGnB,OAAI,KAAK,cAAc,KAAK,eAAe,OAAO,CAAC,IAAI,SAAS,GAAG,CACjE,MAAK,cAAc,IAAI;IAEzB;;;;;;;;;;;;CAaJ,cAAc,KAAgB;EAC5B,MAAM,EAAE,UAAU,IAAI,UAAU,KAAK;AAErC,QAAM,KAAK;AAEX,MAAI,IAAI,SAAS,GAAG,EAAE;AAQpB,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,YAAY,GAAG;AACnB,QAAI,SAAS,OAAO,SAAS;IAC7B,MAAM,QAAQ,IAAI,SAAS,GAAG;AAC9B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,GAAG,KAAK,MAAM;AACtF,SAAK,UAAU;;AAEjB;;AAGF,MAAI,SAAS,OAAO,SAAS;EAK7B,MAAM,QAAQ,IAAI,SAAS,GAAG;AAC9B,uBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,GAAG,KAAK,MAAM;AACtF,OAAK,UAAU;;;;;;;;;;;CAYjB,oBAAoB,KAAmB;EACrC,MAAM,EAAE,WAAW,KAAK,SAAS;AACjC,SAAO,OAAO,WAAW,YAAY,QAAQ,IAAI,UAAU,OAAO,CAAC;;;;;CAMrE,UAAU;AACR,OAAK,cAAc,QAAQ;AAIzB,OAAI,IAAI,cAAc,KAAK,mBAAmB;AAC9C,OAAI,GAAG,cAAc,KAAK,mBAAmB;AAM7C,OAAI,KAAK,oBAAoB,IAAI,CAC/B,MAAK,cAAc,IAAI;IAEzB;;;;;;;;;CAUJ,cAAc,KAAU;AACtB,MAAI,IAAI,cAAc,KAAK,mBAAmB;;;;;CAMhD,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAEpB,OAAK,IAAI,cAAc,KAAK,mBAAmB;AAI/C,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,SAAS,GAAG,EACjB;AACA,OAAI,YAAY,GAAG;AACnB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
1
+ {"version":3,"file":"MapboxLayer.js","names":[],"sources":["../src/MapboxLayer.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { LayerSpecification, Map, MapSourceDataEvent } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxLayerProps extends AbstractMapboxMapChildProps {\n $options: {\n id: string;\n layer: LayerSpecification;\n beforeId: string;\n };\n}\n\n/**\n * Add a layer to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxLayer<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxLayerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxLayer',\n options: {\n id: String,\n layer: Object,\n beforeId: String,\n },\n };\n\n /**\n * Whether this instance owns the layer under its id. Only a layer this\n * instance owns may be removed on teardown; a layer declared outside the\n * family, or one a newer sibling has since adopted, is left untouched.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this layer.\n * @private\n */\n get __ownershipKey(): string {\n return `layer:${this.$options.id}`;\n }\n\n /**\n * The source id this layer references, when it references one by string.\n * @private\n */\n get __sourceId(): string | undefined {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source === 'string' ? source : undefined;\n }\n\n /**\n * Add (or re-add) the layer whenever its referenced source becomes available\n * and the layer is not currently on the map.\n *\n * This is a *standing* recovery watch, not a one-shot: it stays subscribed for\n * the layer's whole life so the layer re-commits itself if its source\n * disappears and comes back — e.g. a sibling `MapboxSource` teardown removes\n * this still-mounted layer to drop its source, then the source is re-added\n * later (H7, PR #567 review). Committing once and unsubscribing (the previous\n * behaviour) left such a layer gone for good.\n *\n * It is kept cheap: `sourcedata` fires often, so the handler early-returns\n * unless this layer is actually missing, and — when the event identifies a\n * source — ignores events for any source other than this layer's. The commit\n * itself is deferred to a microtask because mutating the style from within\n * mapbox-gl's render loop can leave a layer half-initialized and crash the\n * symbol placement pass.\n * @private\n * @param {MapSourceDataEvent} [event]\n */\n __handleSourceData = (event?: MapSourceDataEvent) => {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Ignore events for an unrelated source when the event tells us which one it\n // is: this gates the standing watch to this layer's source id.\n if (event?.sourceId && this.__sourceId && event.sourceId !== this.__sourceId) {\n return;\n }\n\n if (!map || map.getLayer(id) || !this.__sourceIsAvailable(map)) {\n return;\n }\n\n queueMicrotask(() => {\n // Re-check under the microtask: the map may have been removed/replaced, the\n // component destroyed, or the layer committed by another path in between.\n if (this.$isMounted && this.__readyMap === map && !map.getLayer(id)) {\n this.__commitLayer(map);\n }\n });\n };\n\n /**\n * Add the layer to the map, or adopt an existing one.\n *\n * When the id is free the layer is added and ownership claimed. When a layer\n * with this id already exists, re-adding it would throw a duplicate-id error,\n * so it is left in place; ownership is only taken over from a sibling\n * `MapboxLayer` (e.g. a `Fetch` swap), never from an externally declared layer.\n * @private\n * @param {Map} map\n */\n __commitLayer(map: Map): void {\n const { beforeId, id, layer } = this.$options;\n // `$options.layer` returns a freshly parsed object, so re-apply the id.\n layer.id = id;\n\n if (map.getLayer(id)) {\n // The id is taken. Only adopt it from another family instance (e.g. a\n // `Fetch` swap that mounted the replacement before the original tore\n // down); an externally declared layer stays untouched. Adopt AND refresh:\n // the incoming definition may differ in source/type/paint/layout/filter/\n // zoom range/beforeId, so re-add it (we own it) rather than leaving Mapbox\n // rendering the outgoing definition — matching how `MapboxSource` refreshes\n // its data on adopt.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n map.removeLayer(id);\n map.addLayer(layer, beforeId);\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n return;\n }\n\n map.addLayer(layer, beforeId);\n // Own the id, keyed to the very layer object just added: the liveness probe\n // reports the entry stale the moment this layer is removed (a `setStyle`\n // wipe, a sibling source teardown, an external `removeLayer`) or replaced\n // under the same id, so it can never misclassify a stranger's later layer.\n const added = map.getLayer(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);\n this.__added = true;\n }\n\n /**\n * Whether the source referenced by the layer is available on the map.\n *\n * Layers referencing an inline source object — or no source at all, like a\n * `background` layer — are always considered available.\n * @private\n * @param {Map} map\n * @returns {boolean}\n */\n __sourceIsAvailable(map: Map): boolean {\n const { source } = this.$options.layer as { source?: unknown };\n return typeof source !== 'string' || Boolean(map.getSource(source));\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n // Install (or re-install, on a `style.load` re-injection) the standing\n // recovery watch exactly once. `off` before `on` keeps a single\n // subscription when `whenMapReady`'s callback re-runs after a `setStyle`.\n map.off('sourcedata', this.__handleSourceData);\n map.on('sourcedata', this.__handleSourceData);\n\n // The referenced source may be declared by a sibling `MapboxSource` that\n // has not mounted yet — sibling mount order is not guaranteed. Adding a\n // layer before its source silently fails, so commit now when the source is\n // available and otherwise let the standing watch commit once it arrives.\n if (this.__sourceIsAvailable(map)) {\n this.__commitLayer(map);\n }\n });\n }\n\n /**\n * Flush the standing `sourcedata` recovery watch against the map being\n * removed, while it is still referenceable — `__onDestroyed` runs later with\n * `__readyMap` already cleared and could not reach the map to unsubscribe.\n * @protected\n * @param {Map} map\n */\n __onMapRemove(map: Map) {\n map.off('sourcedata', this.__handleSourceData);\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n map?.off('sourcedata', this.__handleSourceData);\n\n // Only remove a layer this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getLayer(id)\n ) {\n map.removeLayer(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxLayer;\n"],"mappings":";;;;;;;AAoBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,IAAI;GACJ,OAAO;GACP,UAAU;GACX;EACF;;;;;;;CAQD,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,SAAS,KAAK,SAAS;;;;;;CAOhC,IAAI,aAAiC;EACnC,MAAM,EAAE,WAAW,KAAK,SAAS;AACjC,SAAO,OAAO,WAAW,WAAW,SAAS,KAAA;;;;;;;;;;;;;;;;;;;;;;CAuB/C,sBAAsB,UAA+B;EACnD,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MAAI,OAAO,YAAY,KAAK,cAAc,MAAM,aAAa,KAAK,WAChE;AAGF,MAAI,CAAC,OAAO,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,oBAAoB,IAAI,CAC5D;AAGF,uBAAqB;AAGnB,OAAI,KAAK,cAAc,KAAK,eAAe,OAAO,CAAC,IAAI,SAAS,GAAG,CACjE,MAAK,cAAc,IAAI;IAEzB;;;;;;;;;;;;CAaJ,cAAc,KAAgB;EAC5B,MAAM,EAAE,UAAU,IAAI,UAAU,KAAK;AAErC,QAAM,KAAK;AAEX,MAAI,IAAI,SAAS,GAAG,EAAE;AAQpB,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,YAAY,GAAG;AACnB,QAAI,SAAS,OAAO,SAAS;IAC7B,MAAM,QAAQ,IAAI,SAAS,GAAG;AAC9B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,GAAG,KAAK,MAAM;AACtF,SAAK,UAAU;;AAEjB;;AAGF,MAAI,SAAS,OAAO,SAAS;EAK7B,MAAM,QAAQ,IAAI,SAAS,GAAG;AAC9B,uBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,SAAS,GAAG,KAAK,MAAM;AACtF,OAAK,UAAU;;;;;;;;;;;CAYjB,oBAAoB,KAAmB;EACrC,MAAM,EAAE,WAAW,KAAK,SAAS;AACjC,SAAO,OAAO,WAAW,YAAY,QAAQ,IAAI,UAAU,OAAO,CAAC;;;;;CAMrE,UAAU;AACR,OAAK,cAAc,QAAQ;AAIzB,OAAI,IAAI,cAAc,KAAK,mBAAmB;AAC9C,OAAI,GAAG,cAAc,KAAK,mBAAmB;AAM7C,OAAI,KAAK,oBAAoB,IAAI,CAC/B,MAAK,cAAc,IAAI;IAEzB;;;;;;;;;CAUJ,cAAc,KAAU;AACtB,MAAI,IAAI,cAAc,KAAK,mBAAmB;;;;;CAMhD,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAEpB,OAAK,IAAI,cAAc,KAAK,mBAAmB;AAI/C,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,SAAS,GAAG,EACjB;AACA,OAAI,YAAY,GAAG;AACnB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
@@ -3,6 +3,9 @@ import { Map, MapOptions } from "mapbox-gl";
3
3
  import { Base } from "@studiometa/js-toolkit/Base";
4
4
 
5
5
  //#region src/MapboxMap.d.ts
6
+ declare const FORWARDED_MAP_EVENTS: readonly ["click", "dblclick", "mouseenter", "mouseleave", "mousemove", "movestart", "move", "moveend", "zoomstart", "zoom", "zoomend", "rotatestart", "rotate", "rotateend", "pitchstart", "pitch", "pitchend", "dragstart", "drag", "dragend", "idle", "render", "resize", "remove", "error"];
7
+ /** One forwarded mapbox event name, prefixed the way the component re-emits it. */
8
+ type ForwardedMapEvent = `map-${(typeof FORWARDED_MAP_EVENTS)[number]}`;
6
9
  interface MapboxMapProps extends BaseProps {
7
10
  $refs: {
8
11
  container: HTMLElement;
@@ -13,6 +16,18 @@ interface MapboxMapProps extends BaseProps {
13
16
  center: [number, number];
14
17
  mapOptions: Partial<Omit<MapOptions, 'container'>>;
15
18
  };
19
+ /**
20
+ * The map lifecycle: `map-load` once the Mapbox instance is ready, plus one
21
+ * `map-*` event per entry of `FORWARDED_MAP_EVENTS` carrying the original
22
+ * mapbox event.
23
+ */
24
+ $emits: {
25
+ 'map-load': {
26
+ map: Map;
27
+ };
28
+ } & Record<ForwardedMapEvent, {
29
+ event: unknown;
30
+ }>;
16
31
  }
17
32
  /**
18
33
  * Display a Mapbox GL map.
@@ -57,9 +72,9 @@ declare class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & Mapbox
57
72
  */
58
73
  mounted(): Promise<void>;
59
74
  /**
60
- * Destroyed hook.
75
+ * Unmounted hook.
61
76
  */
62
- destroyed(): void;
77
+ unmounted(): void;
63
78
  }
64
79
  //#endregion
65
80
  export { MapboxMap, MapboxMap as default, MapboxMapProps };
package/dist/MapboxMap.js CHANGED
@@ -39,7 +39,7 @@ var MapboxMap = class extends Base {
39
39
  */
40
40
  static config = {
41
41
  name: "MapboxMap",
42
- emits: ["map-load", ...FORWARDED_MAP_EVENTS.map((event) => `map-${event}`)],
42
+ mountStrategy: "visible",
43
43
  refs: ["container"],
44
44
  options: {
45
45
  accessToken: String,
@@ -101,13 +101,13 @@ var MapboxMap = class extends Base {
101
101
  this.__map = map;
102
102
  const onLoad = () => {
103
103
  this.isLoaded = true;
104
- this.$emit("map-load", map);
104
+ this.$emit("map-load", { map });
105
105
  };
106
106
  map.on("load", onLoad);
107
107
  this.__offMapListeners.push(() => this.__map?.off("load", onLoad));
108
108
  for (const event of FORWARDED_MAP_EVENTS) {
109
109
  const handler = (e) => {
110
- this.$emit(`map-${event}`, e);
110
+ this.$emit(`map-${event}`, { event: e });
111
111
  };
112
112
  map.on(event, handler);
113
113
  this.__offMapListeners.push(() => this.__map?.off(event, handler));
@@ -115,9 +115,9 @@ var MapboxMap = class extends Base {
115
115
  document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));
116
116
  }
117
117
  /**
118
- * Destroyed hook.
118
+ * Unmounted hook.
119
119
  */
120
- destroyed() {
120
+ unmounted() {
121
121
  for (const off of this.__offMapListeners) off();
122
122
  this.__offMapListeners = [];
123
123
  this.__map?.remove();
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxMap.js","names":[],"sources":["../src/MapboxMap.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map, MapOptions } from 'mapbox-gl';\nimport { resolveMapboxGl } from './dependencies.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\n\nconst FORWARDED_MAP_EVENTS = [\n 'click',\n 'dblclick',\n 'mouseenter',\n 'mouseleave',\n 'mousemove',\n 'movestart',\n 'move',\n 'moveend',\n 'zoomstart',\n 'zoom',\n 'zoomend',\n 'rotatestart',\n 'rotate',\n 'rotateend',\n 'pitchstart',\n 'pitch',\n 'pitchend',\n 'dragstart',\n 'drag',\n 'dragend',\n 'idle',\n 'render',\n 'resize',\n 'remove',\n 'error',\n] as const;\n\nexport interface MapboxMapProps extends BaseProps {\n $refs: {\n container: HTMLElement;\n };\n $options: {\n accessToken: string;\n zoom: number;\n center: [number, number];\n mapOptions: Partial<Omit<MapOptions, 'container'>>;\n };\n}\n\n/**\n * Display a Mapbox GL map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMap',\n emits: ['map-load', ...FORWARDED_MAP_EVENTS.map((event) => `map-${event}`)],\n refs: ['container'],\n options: {\n accessToken: String,\n zoom: Number,\n center: {\n type: Array,\n default: () => [0, 0],\n },\n // Any other `mapbox-gl` `Map` option — including `style`, `pitch`,\n // `bearing`, `bounds`, ... — spread as-is into the `Map` constructor. The\n // convenience options above act as overridable defaults, while `container`\n // is always resolved from the component and can not be overridden.\n mapOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n // `MapboxMap` no longer declares its children. Each child component\n // (markers, popups, controls, sources, layers, clusters, ...) is registered\n // globally and resolves this map on its own via `$closest('MapboxMap')`,\n // then waits for readiness through `AbstractMapboxMapChild.whenMapReady`.\n // This makes the whole family dynamic-DOM-native: a child appended under a\n // map at any time mounts and injects itself, and cleans up when removed.\n };\n\n /**\n * Is the map loaded?\n */\n isLoaded = false;\n\n /**\n * Map instance, or `undefined` until it is built in `mounted()` and once it is\n * cleared on teardown.\n * @private\n */\n __map: Map | undefined;\n\n /**\n * Off handles for every forwarding listener attached to the map, flushed on\n * teardown so a retained reference to a removed `Map` does not keep this\n * component (and its `$emit` closures) alive.\n * @private\n */\n __offMapListeners: Array<() => void> = [];\n\n /**\n * The mapbox Map instance, or `undefined` until it has been built.\n *\n * The map is built in `mounted()` after `mapbox-gl` resolves (it may be\n * injected or lazily imported), so this getter returns `undefined` while that\n * resolution is still pending. Children read it after the map announces itself\n * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.\n */\n get map(): Map | undefined {\n return this.__map;\n }\n\n /**\n * Mounted hook.\n *\n * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then\n * announces it so children can inject themselves.\n */\n async mounted() {\n const mapboxgl = await resolveMapboxGl();\n\n // The component may have been destroyed while `mapbox-gl` was resolving: bail\n // out before building a map that nothing would ever tear down.\n if (!this.$isMounted) {\n return;\n }\n\n const map = new mapboxgl.Map({\n accessToken: this.$options.accessToken,\n zoom: this.$options.zoom,\n center: this.$options.center,\n ...this.$options.mapOptions,\n container: this.$refs.container ?? this.$el,\n });\n this.__map = map;\n\n const onLoad = () => {\n this.isLoaded = true;\n this.$emit('map-load', map);\n };\n map.on('load', onLoad);\n this.__offMapListeners.push(() => this.__map?.off('load', onLoad));\n\n for (const event of FORWARDED_MAP_EVENTS) {\n const handler = (e: unknown) => {\n this.$emit(`map-${event}`, e);\n };\n map.on(event, handler);\n this.__offMapListeners.push(() => this.__map?.off(event, handler));\n }\n\n // Announce this map so any child that mounted before it — and is waiting on\n // `MAPBOX_MAP_CONNECTED` — can resolve and inject itself now. This also fires\n // on a remount, letting still-mounted children re-inject on the new map.\n document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // Flush the forwarding listeners before removing the map so neither the map\n // nor this component leaks through a retained `Map` reference.\n for (const off of this.__offMapListeners) {\n off();\n }\n this.__offMapListeners = [];\n\n this.__map?.remove();\n this.__map = undefined;\n this.isLoaded = false;\n }\n}\n\nexport default MapboxMap;\n"],"mappings":";;;;AAMA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AAkBD,IAAa,YAAb,cAAgE,KAAyB;;;;CAIvF,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO,CAAC,YAAY,GAAG,qBAAqB,KAAK,UAAU,OAAO,QAAQ,CAAC;EAC3E,MAAM,CAAC,YAAY;EACnB,SAAS;GACP,aAAa;GACb,MAAM;GACN,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAKD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EAOF;;;;CAKD,WAAW;;;;;;CAOX;;;;;;;CAQA,oBAAuC,EAAE;;;;;;;;;CAUzC,IAAI,MAAuB;AACzB,SAAO,KAAK;;;;;;;;CASd,MAAM,UAAU;EACd,MAAM,WAAW,MAAM,iBAAiB;AAIxC,MAAI,CAAC,KAAK,WACR;EAGF,MAAM,MAAM,IAAI,SAAS,IAAI;GAC3B,aAAa,KAAK,SAAS;GAC3B,MAAM,KAAK,SAAS;GACpB,QAAQ,KAAK,SAAS;GACtB,GAAG,KAAK,SAAS;GACjB,WAAW,KAAK,MAAM,aAAa,KAAK;GACzC,CAAC;AACF,OAAK,QAAQ;EAEb,MAAM,eAAe;AACnB,QAAK,WAAW;AAChB,QAAK,MAAM,YAAY,IAAI;;AAE7B,MAAI,GAAG,QAAQ,OAAO;AACtB,OAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,QAAQ,OAAO,CAAC;AAElE,OAAK,MAAM,SAAS,sBAAsB;GACxC,MAAM,WAAW,MAAe;AAC9B,SAAK,MAAM,OAAO,SAAS,EAAE;;AAE/B,OAAI,GAAG,OAAO,QAAQ;AACtB,QAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,OAAO,QAAQ,CAAC;;AAMpE,WAAS,cAAc,IAAI,YAAY,sBAAsB,EAAE,QAAQ,MAAM,CAAC,CAAC;;;;;CAMjF,YAAY;AAGV,OAAK,MAAM,OAAO,KAAK,kBACrB,MAAK;AAEP,OAAK,oBAAoB,EAAE;AAE3B,OAAK,OAAO,QAAQ;AACpB,OAAK,QAAQ,KAAA;AACb,OAAK,WAAW"}
1
+ {"version":3,"file":"MapboxMap.js","names":[],"sources":["../src/MapboxMap.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Map, MapOptions } from 'mapbox-gl';\nimport { resolveMapboxGl } from './dependencies.js';\nimport { MAPBOX_MAP_CONNECTED } from './AbstractMapboxMapChild.js';\n\nconst FORWARDED_MAP_EVENTS = [\n 'click',\n 'dblclick',\n 'mouseenter',\n 'mouseleave',\n 'mousemove',\n 'movestart',\n 'move',\n 'moveend',\n 'zoomstart',\n 'zoom',\n 'zoomend',\n 'rotatestart',\n 'rotate',\n 'rotateend',\n 'pitchstart',\n 'pitch',\n 'pitchend',\n 'dragstart',\n 'drag',\n 'dragend',\n 'idle',\n 'render',\n 'resize',\n 'remove',\n 'error',\n] as const;\n\n/** One forwarded mapbox event name, prefixed the way the component re-emits it. */\ntype ForwardedMapEvent = `map-${(typeof FORWARDED_MAP_EVENTS)[number]}`;\n\nexport interface MapboxMapProps extends BaseProps {\n $refs: {\n container: HTMLElement;\n };\n $options: {\n accessToken: string;\n zoom: number;\n center: [number, number];\n mapOptions: Partial<Omit<MapOptions, 'container'>>;\n };\n /**\n * The map lifecycle: `map-load` once the Mapbox instance is ready, plus one\n * `map-*` event per entry of `FORWARDED_MAP_EVENTS` carrying the original\n * mapbox event.\n */\n $emits: { 'map-load': { map: Map } } & Record<ForwardedMapEvent, { event: unknown }>;\n}\n\n/**\n * Display a Mapbox GL map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMap',\n mountStrategy: 'visible',\n refs: ['container'],\n options: {\n accessToken: String,\n zoom: Number,\n center: {\n type: Array,\n default: () => [0, 0],\n },\n // Any other `mapbox-gl` `Map` option — including `style`, `pitch`,\n // `bearing`, `bounds`, ... — spread as-is into the `Map` constructor. The\n // convenience options above act as overridable defaults, while `container`\n // is always resolved from the component and can not be overridden.\n mapOptions: {\n type: Object,\n default: () => ({}),\n },\n },\n // `MapboxMap` declares no child components. Each child component\n // (markers, popups, controls, sources, layers, clusters, ...) is registered\n // globally and resolves this map on its own via `$closest('MapboxMap')`,\n // then waits for readiness through `AbstractMapboxMapChild.whenMapReady`.\n // This makes the whole family dynamic-DOM-native: a child appended under a\n // map at any time mounts and injects itself, and cleans up when removed.\n };\n\n /**\n * Is the map loaded?\n */\n isLoaded = false;\n\n /**\n * Map instance, or `undefined` until it is built in `mounted()` and once it is\n * cleared on teardown.\n * @private\n */\n __map: Map | undefined;\n\n /**\n * Off handles for every forwarding listener attached to the map, flushed on\n * teardown so a retained reference to a removed `Map` does not keep this\n * component (and its `$emit` closures) alive.\n * @private\n */\n __offMapListeners: Array<() => void> = [];\n\n /**\n * The mapbox Map instance, or `undefined` until it has been built.\n *\n * The map is built in `mounted()` after `mapbox-gl` resolves (it may be\n * injected or lazily imported), so this getter returns `undefined` while that\n * resolution is still pending. Children read it after the map announces itself\n * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.\n */\n get map(): Map | undefined {\n return this.__map;\n }\n\n /**\n * Mounted hook.\n *\n * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then\n * announces it so children can inject themselves.\n */\n async mounted() {\n const mapboxgl = await resolveMapboxGl();\n\n // The component may have been destroyed while `mapbox-gl` was resolving: bail\n // out before building a map that nothing would ever tear down.\n if (!this.$isMounted) {\n return;\n }\n\n const map = new mapboxgl.Map({\n accessToken: this.$options.accessToken,\n zoom: this.$options.zoom,\n center: this.$options.center,\n ...this.$options.mapOptions,\n container: this.$refs.container ?? this.$el,\n });\n this.__map = map;\n\n const onLoad = () => {\n this.isLoaded = true;\n this.$emit('map-load', { map });\n };\n map.on('load', onLoad);\n this.__offMapListeners.push(() => this.__map?.off('load', onLoad));\n\n for (const event of FORWARDED_MAP_EVENTS) {\n const handler = (e: unknown) => {\n this.$emit(`map-${event}`, { event: e });\n };\n map.on(event, handler);\n this.__offMapListeners.push(() => this.__map?.off(event, handler));\n }\n\n // Announce this map so any child that mounted before it — and is waiting on\n // `MAPBOX_MAP_CONNECTED` — can resolve and inject itself now. This also fires\n // on a remount, letting still-mounted children re-inject on the new map.\n document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));\n }\n\n /**\n * Unmounted hook.\n */\n unmounted() {\n // Flush the forwarding listeners before removing the map so neither the map\n // nor this component leaks through a retained `Map` reference.\n for (const off of this.__offMapListeners) {\n off();\n }\n this.__offMapListeners = [];\n\n this.__map?.remove();\n this.__map = undefined;\n this.isLoaded = false;\n }\n}\n\nexport default MapboxMap;\n"],"mappings":";;;;AAMA,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AA2BD,IAAa,YAAb,cAAgE,KAAyB;;;;CAIvF,OAAO,SAAqB;EAC1B,MAAM;EACN,eAAe;EACf,MAAM,CAAC,YAAY;EACnB,SAAS;GACP,aAAa;GACb,MAAM;GACN,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAKD,YAAY;IACV,MAAM;IACN,gBAAgB,EAAE;IACnB;GACF;EAOF;;;;CAKD,WAAW;;;;;;CAOX;;;;;;;CAQA,oBAAuC,EAAE;;;;;;;;;CAUzC,IAAI,MAAuB;AACzB,SAAO,KAAK;;;;;;;;CASd,MAAM,UAAU;EACd,MAAM,WAAW,MAAM,iBAAiB;AAIxC,MAAI,CAAC,KAAK,WACR;EAGF,MAAM,MAAM,IAAI,SAAS,IAAI;GAC3B,aAAa,KAAK,SAAS;GAC3B,MAAM,KAAK,SAAS;GACpB,QAAQ,KAAK,SAAS;GACtB,GAAG,KAAK,SAAS;GACjB,WAAW,KAAK,MAAM,aAAa,KAAK;GACzC,CAAC;AACF,OAAK,QAAQ;EAEb,MAAM,eAAe;AACnB,QAAK,WAAW;AAChB,QAAK,MAAM,YAAY,EAAE,KAAK,CAAC;;AAEjC,MAAI,GAAG,QAAQ,OAAO;AACtB,OAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,QAAQ,OAAO,CAAC;AAElE,OAAK,MAAM,SAAS,sBAAsB;GACxC,MAAM,WAAW,MAAe;AAC9B,SAAK,MAAM,OAAO,SAAS,EAAE,OAAO,GAAG,CAAC;;AAE1C,OAAI,GAAG,OAAO,QAAQ;AACtB,QAAK,kBAAkB,WAAW,KAAK,OAAO,IAAI,OAAO,QAAQ,CAAC;;AAMpE,WAAS,cAAc,IAAI,YAAY,sBAAsB,EAAE,QAAQ,MAAM,CAAC,CAAC;;;;;CAMjF,YAAY;AAGV,OAAK,MAAM,OAAO,KAAK,kBACrB,MAAK;AAEP,OAAK,oBAAoB,EAAE;AAE3B,OAAK,OAAO,QAAQ;AACpB,OAAK,QAAQ,KAAA;AACb,OAAK,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxMarker.js","names":[],"sources":["../src/MapboxMarker.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { Marker, MarkerOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport { MapboxPopup } from './MapboxPopup.js';\n\nexport interface MapboxMarkerProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n markerOptions: MarkerOptions;\n };\n}\n\n/**\n * Add a marker to Mapbox map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMarker<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxMarkerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMarker',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n // Marker options. (https://docs.mapbox.com/mapbox-gl-js/api/markers#marker)\n markerOptions: Object,\n },\n };\n\n /**\n * Marker instance.\n * @private\n */\n __marker: Marker;\n\n /**\n * The mapbox Marker instance.\n */\n get marker() {\n if (!this.__marker) {\n this.__marker = new (getMapboxGl().Marker)(this.$options.markerOptions);\n }\n\n return this.__marker;\n }\n\n /**\n * The optional child popup component instance.\n */\n get popup() {\n return this.$query<MapboxPopup>('MapboxPopup')[0];\n }\n\n /**\n * Attach a child `MapboxPopup`'s popup to this marker.\n *\n * Called from either side of the wiring, whichever mounts last: the marker\n * pulls its child popup on ready, and the popup pushes itself here when it\n * mounts after the marker (a dynamic append to an already-loaded map, where\n * the marker mounted first and found no popup to query yet). Setting the same\n * popup twice is idempotent.\n * @param {MapboxPopup} popupComponent\n */\n setChildPopup(popupComponent: MapboxPopup) {\n this.marker.setPopup(popupComponent.popup);\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n this.marker.setLngLat(this.$options.lngLat).addTo(map);\n\n // Pull the optional child popup if it has already mounted. When it mounts\n // *after* the marker instead (dynamic append), the popup pushes itself via\n // `setChildPopup`, so either mount order wires the pair.\n if (this.popup) {\n this.setChildPopup(this.popup);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__marker?.remove();\n this.__marker = undefined;\n }\n}\n\nexport default MapboxMarker;\n"],"mappings":";;;;;;;AAoBA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAED,eAAe;GAChB;EACF;;;;;CAMD;;;;CAKA,IAAI,SAAS;AACX,MAAI,CAAC,KAAK,SACR,MAAK,WAAW,KAAK,aAAa,EAAC,OAAQ,KAAK,SAAS,cAAc;AAGzE,SAAO,KAAK;;;;;CAMd,IAAI,QAAQ;AACV,SAAO,KAAK,OAAoB,cAAc,CAAC;;;;;;;;;;;;CAajD,cAAc,gBAA6B;AACzC,OAAK,OAAO,SAAS,eAAe,MAAM;;;;;CAM5C,UAAU;AACR,OAAK,cAAc,QAAQ;AACzB,QAAK,OAAO,UAAU,KAAK,SAAS,OAAO,CAAC,MAAM,IAAI;AAKtD,OAAI,KAAK,MACP,MAAK,cAAc,KAAK,MAAM;IAEhC;;;;;CAMJ,gBAAgB;AACd,OAAK,UAAU,QAAQ;AACvB,OAAK,WAAW,KAAA"}
1
+ {"version":3,"file":"MapboxMarker.js","names":[],"sources":["../src/MapboxMarker.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { Marker, MarkerOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport { MapboxPopup } from './MapboxPopup.js';\n\nexport interface MapboxMarkerProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n markerOptions: MarkerOptions;\n };\n}\n\n/**\n * Add a marker to Mapbox map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxMarker<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxMarkerProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxMarker',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n // Marker options. (https://docs.mapbox.com/mapbox-gl-js/api/markers#marker)\n markerOptions: Object,\n },\n };\n\n /**\n * Marker instance.\n * @private\n */\n __marker: Marker;\n\n /**\n * The mapbox Marker instance.\n */\n get marker() {\n if (!this.__marker) {\n this.__marker = new (getMapboxGl().Marker)(this.$options.markerOptions);\n }\n\n return this.__marker;\n }\n\n /**\n * The optional child popup component instance.\n */\n get popup() {\n return this.$query<MapboxPopup>('MapboxPopup')[0];\n }\n\n /**\n * Attach a child `MapboxPopup`'s popup to this marker.\n *\n * Called from either side of the wiring, whichever mounts last: the marker\n * pulls its child popup on ready, and the popup pushes itself here when it\n * mounts after the marker (a dynamic append to an already-loaded map, where\n * the marker mounted first and found no popup to query yet). Setting the same\n * popup twice is idempotent.\n * @param {MapboxPopup} popupComponent\n */\n setChildPopup(popupComponent: MapboxPopup) {\n this.marker.setPopup(popupComponent.popup);\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n this.marker.setLngLat(this.$options.lngLat).addTo(map);\n\n // Pull the optional child popup if it has already mounted. When it mounts\n // *after* the marker instead (dynamic append), the popup pushes itself via\n // `setChildPopup`, so either mount order wires the pair.\n if (this.popup) {\n this.setChildPopup(this.popup);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__marker?.remove();\n this.__marker = undefined;\n }\n}\n\nexport default MapboxMarker;\n"],"mappings":";;;;;;;AAoBA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GAED,eAAe;GAChB;EACF;;;;;CAMD;;;;CAKA,IAAI,SAAS;AACX,MAAI,CAAC,KAAK,SACR,MAAK,WAAW,KAAK,aAAa,EAAC,OAAQ,KAAK,SAAS,cAAc;AAGzE,SAAO,KAAK;;;;;CAMd,IAAI,QAAQ;AACV,SAAO,KAAK,OAAoB,cAAc,CAAC;;;;;;;;;;;;CAajD,cAAc,gBAA6B;AACzC,OAAK,OAAO,SAAS,eAAe,MAAM;;;;;CAM5C,UAAU;AACR,OAAK,cAAc,QAAQ;AACzB,QAAK,OAAO,UAAU,KAAK,SAAS,OAAO,CAAC,MAAM,IAAI;AAKtD,OAAI,KAAK,MACP,MAAK,cAAc,KAAK,MAAM;IAEhC;;;;;CAMJ,gBAAgB;AACd,OAAK,UAAU,QAAQ;AACvB,OAAK,WAAW,KAAA"}
@@ -1,5 +1,5 @@
1
- import { AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
2
- import * as _studiometa_js_toolkit0 from "@studiometa/js-toolkit";
1
+ import { AbstractMapboxControl, AbstractMapboxControlProps } from "./AbstractMapboxControl.js";
2
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
3
  import * as mapbox_gl0 from "mapbox-gl";
4
4
  import { NavigationControlOptions } from "mapbox-gl";
5
5
 
@@ -11,12 +11,16 @@ interface MapboxNavigationControlProps extends AbstractMapboxControlProps {
11
11
  visualizePitch: boolean;
12
12
  };
13
13
  }
14
- declare const MapboxNavigationControl_base: _studiometa_js_toolkit0.BaseDecorator<_studiometa_js_toolkit0.BaseInterface, _studiometa_js_toolkit0.Base<_studiometa_js_toolkit0.BaseProps>>;
15
14
  /**
16
15
  * Add a navigation control to the map.
16
+ *
17
17
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
18
18
  */
19
- declare class MapboxNavigationControl extends MapboxNavigationControl_base {
19
+ declare class MapboxNavigationControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<T & MapboxNavigationControlProps> {
20
+ /**
21
+ * Config.
22
+ */
23
+ static config: BaseConfig;
20
24
  /**
21
25
  * Create the mapbox NavigationControl instance.
22
26
  * @protected
@@ -1,19 +1,23 @@
1
1
  import { AbstractMapboxControl } from "./AbstractMapboxControl.js";
2
2
  import { getMapboxGl } from "./dependencies.js";
3
- import { withExtraConfig } from "@studiometa/js-toolkit/withExtraConfig";
4
3
  //#region src/MapboxNavigationControl.ts
5
4
  /**
6
5
  * Add a navigation control to the map.
6
+ *
7
7
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
8
8
  */
9
- var MapboxNavigationControl = class extends withExtraConfig(AbstractMapboxControl, {
10
- name: "MapboxNavigationControl",
11
- options: {
12
- showCompass: Boolean,
13
- showZoom: Boolean,
14
- visualizePitch: Boolean
15
- }
16
- }) {
9
+ var MapboxNavigationControl = class extends AbstractMapboxControl {
10
+ /**
11
+ * Config.
12
+ */
13
+ static config = {
14
+ name: "MapboxNavigationControl",
15
+ options: {
16
+ showCompass: Boolean,
17
+ showZoom: Boolean,
18
+ visualizePitch: Boolean
19
+ }
20
+ };
17
21
  /**
18
22
  * Create the mapbox NavigationControl instance.
19
23
  * @protected
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxNavigationControl.js","names":[],"sources":["../src/MapboxNavigationControl.ts"],"sourcesContent":["import { withExtraConfig } from '@studiometa/js-toolkit/withExtraConfig';\nimport type { NavigationControlOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxControl,\n type AbstractMapboxControlProps,\n} from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxNavigationControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & {\n showCompass: boolean;\n showZoom: boolean;\n visualizePitch: boolean;\n };\n}\n\n/**\n * Add a navigation control to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxNavigationControl extends withExtraConfig(AbstractMapboxControl, {\n name: 'MapboxNavigationControl',\n options: {\n showCompass: Boolean,\n showZoom: Boolean,\n visualizePitch: Boolean,\n },\n}) {\n /**\n * Create the mapbox NavigationControl instance.\n * @protected\n */\n createControl(options: NavigationControlOptions) {\n return new (getMapboxGl().NavigationControl)(options);\n }\n}\n\nexport default MapboxNavigationControl;\n"],"mappings":";;;;;;;;AAoBA,IAAa,0BAAb,cAA6C,gBAAgB,uBAAuB;CAClF,MAAM;CACN,SAAS;EACP,aAAa;EACb,UAAU;EACV,gBAAgB;EACjB;CACF,CAAC,CAAC;;;;;CAKD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
1
+ {"version":3,"file":"MapboxNavigationControl.js","names":[],"sources":["../src/MapboxNavigationControl.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { NavigationControlOptions } from 'mapbox-gl';\nimport { AbstractMapboxControl, type AbstractMapboxControlProps } from './AbstractMapboxControl.js';\nimport { getMapboxGl } from './dependencies.js';\n\nexport interface MapboxNavigationControlProps extends AbstractMapboxControlProps {\n $options: AbstractMapboxControlProps['$options'] & {\n showCompass: boolean;\n showZoom: boolean;\n visualizePitch: boolean;\n };\n}\n\n/**\n * Add a navigation control to the map.\n *\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxNavigationControl<T extends BaseProps = BaseProps> extends AbstractMapboxControl<\n T & MapboxNavigationControlProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxNavigationControl',\n options: {\n showCompass: Boolean,\n showZoom: Boolean,\n visualizePitch: Boolean,\n },\n };\n\n /**\n * Create the mapbox NavigationControl instance.\n * @protected\n */\n createControl(options: NavigationControlOptions) {\n return new (getMapboxGl().NavigationControl)(options);\n }\n}\n\nexport default MapboxNavigationControl;\n"],"mappings":";;;;;;;;AAkBA,IAAa,0BAAb,cAA8E,sBAE5E;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,aAAa;GACb,UAAU;GACV,gBAAgB;GACjB;EACF;;;;;CAMD,cAAc,SAAmC;AAC/C,SAAO,KAAK,aAAa,EAAC,kBAAmB,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxPopup.js","names":[],"sources":["../src/MapboxPopup.ts"],"sourcesContent":["import { type BaseConfig, type BaseProps } from '@studiometa/js-toolkit';\nimport type { Popup, PopupOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport type { MapboxMarker } from './MapboxMarker.js';\n\nexport interface MapboxPopupProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n /**\n * Popup options.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/markers#popup\n */\n popupOptions: PopupOptions;\n };\n}\n\n/**\n * Display a popup on a MapboxMap map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap\n */\nexport class MapboxPopup<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxPopupProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxPopup',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n popupOptions: Object,\n },\n };\n\n /**\n * Popup instance.\n * @private\n */\n __popup: Popup;\n\n /**\n * Whether this component hid its own source element (to avoid rendering the\n * content twice). Tracked so teardown restores the original visibility only\n * when it was the one to change it.\n * @private\n */\n __didHide = false;\n\n /**\n * The mapbox Popup instance.\n */\n get popup() {\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n return this.__popup;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { popup, $el, $options } = this;\n\n popup.setLngLat($options.lngLat);\n\n const content = $el.innerHTML.trim();\n if (content) {\n popup.setHTML(content);\n // Hide the source markup so the content is not rendered twice: once in\n // the popup and once in the document. Remember we did so — only when it\n // was visible — to restore it on teardown.\n if (!$el.hidden) {\n $el.hidden = true;\n this.__didHide = true;\n }\n }\n\n // When inside a marker, hand the popup to it rather than adding it to the\n // map directly (the marker owns its popup via `setPopup`). Pushing to the\n // marker — instead of letting the marker pull us — also covers the dynamic\n // append case where the marker mounted first and found no popup to query.\n const marker = this.$closest<MapboxMarker>('MapboxMarker');\n if (marker) {\n marker.setChildPopup(this);\n } else {\n popup.addTo(map);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__popup?.remove();\n this.__popup = undefined;\n\n // Restore the source element's visibility only if this component hid it, so\n // a reused or remounted element keeps its original state.\n if (this.__didHide) {\n this.$el.hidden = false;\n this.__didHide = false;\n }\n }\n}\n\nexport default MapboxPopup;\n"],"mappings":";;;;;;;AAwBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,cAAc;GACf;EACF;;;;;CAMD;;;;;;;CAQA,YAAY;;;;CAKZ,IAAI,QAAQ;AACV,MAAI,CAAC,KAAK,QACR,MAAK,UAAU,KAAK,aAAa,EAAC,MAAO,KAAK,SAAS,aAAa;AAGtE,SAAO,KAAK;;;;;CAMd,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK,aAAa;AAEjC,SAAM,UAAU,SAAS,OAAO;GAEhC,MAAM,UAAU,IAAI,UAAU,MAAM;AACpC,OAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AAItB,QAAI,CAAC,IAAI,QAAQ;AACf,SAAI,SAAS;AACb,UAAK,YAAY;;;GAQrB,MAAM,SAAS,KAAK,SAAuB,eAAe;AAC1D,OAAI,OACF,QAAO,cAAc,KAAK;OAE1B,OAAM,MAAM,IAAI;IAElB;;;;;CAMJ,gBAAgB;AACd,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AAIf,MAAI,KAAK,WAAW;AAClB,QAAK,IAAI,SAAS;AAClB,QAAK,YAAY"}
1
+ {"version":3,"file":"MapboxPopup.js","names":[],"sources":["../src/MapboxPopup.ts"],"sourcesContent":["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport type { Popup, PopupOptions } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { getMapboxGl } from './dependencies.js';\nimport type { MapboxMarker } from './MapboxMarker.js';\n\nexport interface MapboxPopupProps extends AbstractMapboxMapChildProps {\n $options: {\n lngLat: [number, number];\n /**\n * Popup options.\n * @see https://docs.mapbox.com/mapbox-gl-js/api/markers#popup\n */\n popupOptions: PopupOptions;\n };\n}\n\n/**\n * Display a popup on a MapboxMap map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap\n */\nexport class MapboxPopup<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxPopupProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxPopup',\n options: {\n lngLat: {\n type: Array,\n default: () => [0, 0],\n },\n popupOptions: Object,\n },\n };\n\n /**\n * Popup instance.\n * @private\n */\n __popup: Popup;\n\n /**\n * Whether this component hid its own source element (to avoid rendering the\n * content twice). Tracked so teardown restores the original visibility only\n * when it was the one to change it.\n * @private\n */\n __didHide = false;\n\n /**\n * The mapbox Popup instance.\n */\n get popup() {\n if (!this.__popup) {\n this.__popup = new (getMapboxGl().Popup)(this.$options.popupOptions);\n }\n\n return this.__popup;\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { popup, $el, $options } = this;\n\n popup.setLngLat($options.lngLat);\n\n const content = $el.innerHTML.trim();\n if (content) {\n popup.setHTML(content);\n // Hide the source markup so the content is not rendered twice: once in\n // the popup and once in the document. Remember we did so — only when it\n // was visible — to restore it on teardown.\n if (!$el.hidden) {\n $el.hidden = true;\n this.__didHide = true;\n }\n }\n\n // When inside a marker, hand the popup to it rather than adding it to the\n // map directly (the marker owns its popup via `setPopup`). Pushing to the\n // marker — instead of letting the marker pull us — also covers the dynamic\n // append case where the marker mounted first and found no popup to query.\n const marker = this.$closest<MapboxMarker>('MapboxMarker');\n if (marker) {\n marker.setChildPopup(this);\n } else {\n popup.addTo(map);\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n this.__popup?.remove();\n this.__popup = undefined;\n\n // Restore the source element's visibility only if this component hid it, so\n // a reused or remounted element keeps its original state.\n if (this.__didHide) {\n this.$el.hidden = false;\n this.__didHide = false;\n }\n }\n}\n\nexport default MapboxPopup;\n"],"mappings":";;;;;;;AAwBA,IAAa,cAAb,cAAkE,uBAEhE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,SAAS;GACP,QAAQ;IACN,MAAM;IACN,eAAe,CAAC,GAAG,EAAE;IACtB;GACD,cAAc;GACf;EACF;;;;;CAMD;;;;;;;CAQA,YAAY;;;;CAKZ,IAAI,QAAQ;AACV,MAAI,CAAC,KAAK,QACR,MAAK,UAAU,KAAK,aAAa,EAAC,MAAO,KAAK,SAAS,aAAa;AAGtE,SAAO,KAAK;;;;;CAMd,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK,aAAa;AAEjC,SAAM,UAAU,SAAS,OAAO;GAEhC,MAAM,UAAU,IAAI,UAAU,MAAM;AACpC,OAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AAItB,QAAI,CAAC,IAAI,QAAQ;AACf,SAAI,SAAS;AACb,UAAK,YAAY;;;GAQrB,MAAM,SAAS,KAAK,SAAuB,eAAe;AAC1D,OAAI,OACF,QAAO,cAAc,KAAK;OAE1B,OAAM,MAAM,IAAI;IAElB;;;;;CAMJ,gBAAgB;AACd,OAAK,SAAS,QAAQ;AACtB,OAAK,UAAU,KAAA;AAIf,MAAI,KAAK,WAAW;AAClB,QAAK,IAAI,SAAS;AAClB,QAAK,YAAY"}
@@ -35,7 +35,7 @@ var MapboxSource = class extends AbstractMapboxMapChild {
35
35
  data
36
36
  };
37
37
  } catch (err) {
38
- this.$warn("Invalid JSON in the `geojson` ref:", err);
38
+ this.$error("mapbox-source.invalid-geojson", "Invalid JSON in the `geojson` ref.", err);
39
39
  return source;
40
40
  }
41
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxSource.js","names":[],"sources":["../src/MapboxSource.ts"],"sourcesContent":["import { type BaseProps, type BaseConfig } from '@studiometa/js-toolkit';\nimport type { SourceSpecification, GeoJSONSourceSpecification, GeoJSONSource } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxSourceProps extends AbstractMapboxMapChildProps {\n $refs: {\n geojson?: HTMLScriptElement;\n };\n $options: {\n id: string;\n /**\n * The source specification, e.g. `{ type: 'geojson', data }`.\n * @see https://docs.mapbox.com/style-spec/reference/sources/\n */\n source: SourceSpecification;\n };\n}\n\n/**\n * Add a source to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxSource<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxSourceProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxSource',\n refs: ['geojson'],\n options: {\n id: String,\n source: Object,\n },\n };\n\n /**\n * Resolve the source specification.\n *\n * When a `geojson` ref — a `<script data-ref=\"geojson\" type=\"application/json\">`\n * element — is present, its content is parsed as inline GeoJSON and injected\n * as the source spec's `data`. Otherwise the `source` option is used as is.\n */\n get source(): SourceSpecification {\n const { source } = this.$options;\n const script = this.$refs.geojson;\n const content = script?.textContent?.trim();\n\n // Only inject inline data when the script ref holds actual content. A\n // missing, empty or whitespace-only ref is treated as \"no inline data\" and\n // the `source` option is used as is instead of injecting `data: null`.\n if (!content) {\n return source;\n }\n\n try {\n const data = JSON.parse(content) as GeoJSONSourceSpecification['data'];\n return { ...source, data } as SourceSpecification;\n } catch (err) {\n this.$warn('Invalid JSON in the `geojson` ref:', err);\n return source;\n }\n }\n\n /**\n * Whether this instance owns the source under its id. Only a source this\n * instance owns — along with the layers tied to it — may be removed on\n * teardown; a source declared by someone else outside the family is left\n * untouched, and a source a newer sibling has since adopted is left to that\n * sibling.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this source.\n * @private\n */\n get __ownershipKey(): string {\n return `source:${this.$options.id}`;\n }\n\n /**\n * Mounted hook.\n *\n * Adopt-or-add: when the id is free, add the source and claim ownership. When\n * a source with this id already exists, adding it again would throw a\n * duplicate-id error, so instead update its data (for GeoJSON) and — when the\n * existing source belongs to a sibling `MapboxSource` (e.g. a `Fetch` swap\n * mounted the replacement before the original tore down) — take over\n * ownership. A source declared outside the family is left untouched and not\n * owned.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { id } = this.$options;\n const { source } = this;\n\n if (!map.getSource(id)) {\n map.addSource(id, source);\n // Own the id, keyed to the very source object just added: the liveness\n // probe reports the entry stale the moment this source is removed (a\n // `setStyle` wipe, an external `removeSource`) or replaced under the same\n // id, so it can never misclassify a stranger's later source (H6).\n const added = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === added);\n this.__added = true;\n return;\n }\n\n // The id is taken. Only adopt it from another family instance; an\n // externally declared source stays untouched. `getMapboxOwner` validates\n // the existing owner's liveness, so a stale entry left by a wiped/removed\n // source does not read as owned and is not adopted here.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n if (source.type === 'geojson' && 'data' in source) {\n const existing = map.getSource<GeoJSONSource>(id);\n existing?.setData(source.data as GeoJSONSourceSpecification['data']);\n }\n\n const existing = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === existing);\n this.__added = true;\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Only remove a source this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getSource(id)\n ) {\n // Remove every layer tied to the source before removing the source itself,\n // otherwise Mapbox throws because layers still reference a missing source.\n //\n // H7 (PR #567 review): this also removes layers owned by still-mounted\n // `MapboxLayer` instances. Those layers now keep a standing `sourcedata`\n // recovery watch (see `MapboxLayer.__handleSourceData`), so when a source\n // with the same id is later re-added they re-commit themselves rather than\n // vanishing permanently. The removal here is unavoidable (Mapbox rejects\n // removing a source still referenced by a layer); recovery is the layer's\n // job. The common `Fetch` swap (source AND layers replaced together) is\n // likewise fine: the replacement layers re-commit on their own.\n for (const layer of map.getStyle().layers) {\n if ('source' in layer && layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n\n map.removeSource(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxSource;\n"],"mappings":";;;;;;;AA0BA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,MAAM,CAAC,UAAU;EACjB,SAAS;GACP,IAAI;GACJ,QAAQ;GACT;EACF;;;;;;;;CASD,IAAI,SAA8B;EAChC,MAAM,EAAE,WAAW,KAAK;EAExB,MAAM,UADS,KAAK,MAAM,SACF,aAAa,MAAM;AAK3C,MAAI,CAAC,QACH,QAAO;AAGT,MAAI;GACF,MAAM,OAAO,KAAK,MAAM,QAAQ;AAChC,UAAO;IAAE,GAAG;IAAQ;IAAM;WACnB,KAAK;AACZ,QAAK,MAAM,sCAAsC,IAAI;AACrD,UAAO;;;;;;;;;;;CAYX,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,UAAU,KAAK,SAAS;;;;;;;;;;;;;CAcjC,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK;GACpB,MAAM,EAAE,WAAW;AAEnB,OAAI,CAAC,IAAI,UAAU,GAAG,EAAE;AACtB,QAAI,UAAU,IAAI,OAAO;IAKzB,MAAM,QAAQ,IAAI,UAAU,GAAG;AAC/B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,MAAM;AACvF,SAAK,UAAU;AACf;;AAOF,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,OAAO,SAAS,aAAa,UAAU,OACxB,KAAI,UAAyB,GAAG,EACvC,QAAQ,OAAO,KAA2C;IAGtE,MAAM,WAAW,IAAI,UAAU,GAAG;AAClC,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,SAAS;AAC1F,SAAK,UAAU;;IAEjB;;;;;CAMJ,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,UAAU,GAAG,EAClB;AAYA,QAAK,MAAM,SAAS,IAAI,UAAU,CAAC,OACjC,KAAI,YAAY,SAAS,MAAM,WAAW,GACxC,KAAI,YAAY,MAAM,GAAG;AAI7B,OAAI,aAAa,GAAG;AACpB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
1
+ {"version":3,"file":"MapboxSource.js","names":[],"sources":["../src/MapboxSource.ts"],"sourcesContent":["import type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { SourceSpecification, GeoJSONSourceSpecification, GeoJSONSource } from 'mapbox-gl';\nimport {\n AbstractMapboxMapChild,\n type AbstractMapboxMapChildProps,\n} from './AbstractMapboxMapChild.js';\nimport { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from './utils.js';\n\nexport interface MapboxSourceProps extends AbstractMapboxMapChildProps {\n $refs: {\n geojson?: HTMLScriptElement;\n };\n $options: {\n id: string;\n /**\n * The source specification, e.g. `{ type: 'geojson', data }`.\n * @see https://docs.mapbox.com/style-spec/reference/sources/\n */\n source: SourceSpecification;\n };\n}\n\n/**\n * Add a source to the map.\n * @see https://ui.studiometa.dev/reference/items/MapboxMap/\n */\nexport class MapboxSource<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<\n T & MapboxSourceProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MapboxSource',\n refs: ['geojson'],\n options: {\n id: String,\n source: Object,\n },\n };\n\n /**\n * Resolve the source specification.\n *\n * When a `geojson` ref — a `<script data-ref=\"geojson\" type=\"application/json\">`\n * element — is present, its content is parsed as inline GeoJSON and injected\n * as the source spec's `data`. Otherwise the `source` option is used as is.\n */\n get source(): SourceSpecification {\n const { source } = this.$options;\n const script = this.$refs.geojson;\n const content = script?.textContent?.trim();\n\n // Only inject inline data when the script ref holds actual content. A\n // missing, empty or whitespace-only ref is treated as \"no inline data\" and\n // the `source` option is used as is instead of injecting `data: null`.\n if (!content) {\n return source;\n }\n\n try {\n const data = JSON.parse(content) as GeoJSONSourceSpecification['data'];\n return { ...source, data } as SourceSpecification;\n } catch (err) {\n this.$error('mapbox-source.invalid-geojson', 'Invalid JSON in the `geojson` ref.', err);\n return source;\n }\n }\n\n /**\n * Whether this instance owns the source under its id. Only a source this\n * instance owns — along with the layers tied to it — may be removed on\n * teardown; a source declared by someone else outside the family is left\n * untouched, and a source a newer sibling has since adopted is left to that\n * sibling.\n * @private\n */\n __added = false;\n\n /**\n * The `kind:id` ownership key for this source.\n * @private\n */\n get __ownershipKey(): string {\n return `source:${this.$options.id}`;\n }\n\n /**\n * Mounted hook.\n *\n * Adopt-or-add: when the id is free, add the source and claim ownership. When\n * a source with this id already exists, adding it again would throw a\n * duplicate-id error, so instead update its data (for GeoJSON) and — when the\n * existing source belongs to a sibling `MapboxSource` (e.g. a `Fetch` swap\n * mounted the replacement before the original tore down) — take over\n * ownership. A source declared outside the family is left untouched and not\n * owned.\n */\n mounted() {\n this.whenMapReady((map) => {\n const { id } = this.$options;\n const { source } = this;\n\n if (!map.getSource(id)) {\n map.addSource(id, source);\n // Own the id, keyed to the very source object just added: the liveness\n // probe reports the entry stale the moment this source is removed (a\n // `setStyle` wipe, an external `removeSource`) or replaced under the same\n // id, so it can never misclassify a stranger's later source (H6).\n const added = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === added);\n this.__added = true;\n return;\n }\n\n // The id is taken. Only adopt it from another family instance; an\n // externally declared source stays untouched. `getMapboxOwner` validates\n // the existing owner's liveness, so a stale entry left by a wiped/removed\n // source does not read as owned and is not adopted here.\n if (getMapboxOwner(map, this.__ownershipKey)) {\n if (source.type === 'geojson' && 'data' in source) {\n const existing = map.getSource<GeoJSONSource>(id);\n existing?.setData(source.data as GeoJSONSourceSpecification['data']);\n }\n\n const existing = map.getSource(id);\n claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getSource(id) === existing);\n this.__added = true;\n }\n });\n }\n\n /**\n * Teardown hook.\n */\n __onDestroyed() {\n const map = this.__readyMap;\n const { id } = this.$options;\n\n // Only remove a source this instance still owns: a newer sibling may have\n // adopted the id, and a removed map is already gone (`__readyMap` is unset).\n if (\n this.__added &&\n getMapboxOwner(map as object, this.__ownershipKey) === this &&\n map?.getSource(id)\n ) {\n // Remove every layer tied to the source before removing the source itself,\n // otherwise Mapbox throws because layers still reference a missing source.\n //\n // H7 (PR #567 review): this also removes layers owned by still-mounted\n // `MapboxLayer` instances. Those layers now keep a standing `sourcedata`\n // recovery watch (see `MapboxLayer.__handleSourceData`), so when a source\n // with the same id is later re-added they re-commit themselves rather than\n // vanishing permanently. The removal here is unavoidable (Mapbox rejects\n // removing a source still referenced by a layer); recovery is the layer's\n // job. The common `Fetch` swap (source AND layers replaced together) is\n // likewise fine: the replacement layers re-commit on their own.\n for (const layer of map.getStyle().layers) {\n if ('source' in layer && layer.source === id) {\n map.removeLayer(layer.id);\n }\n }\n\n map.removeSource(id);\n releaseMapboxOwnership(map, this.__ownershipKey, this);\n }\n }\n}\n\nexport default MapboxSource;\n"],"mappings":";;;;;;;AA0BA,IAAa,eAAb,cAAmE,uBAEjE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,MAAM,CAAC,UAAU;EACjB,SAAS;GACP,IAAI;GACJ,QAAQ;GACT;EACF;;;;;;;;CASD,IAAI,SAA8B;EAChC,MAAM,EAAE,WAAW,KAAK;EAExB,MAAM,UADS,KAAK,MAAM,SACF,aAAa,MAAM;AAK3C,MAAI,CAAC,QACH,QAAO;AAGT,MAAI;GACF,MAAM,OAAO,KAAK,MAAM,QAAQ;AAChC,UAAO;IAAE,GAAG;IAAQ;IAAM;WACnB,KAAK;AACZ,QAAK,OAAO,iCAAiC,sCAAsC,IAAI;AACvF,UAAO;;;;;;;;;;;CAYX,UAAU;;;;;CAMV,IAAI,iBAAyB;AAC3B,SAAO,UAAU,KAAK,SAAS;;;;;;;;;;;;;CAcjC,UAAU;AACR,OAAK,cAAc,QAAQ;GACzB,MAAM,EAAE,OAAO,KAAK;GACpB,MAAM,EAAE,WAAW;AAEnB,OAAI,CAAC,IAAI,UAAU,GAAG,EAAE;AACtB,QAAI,UAAU,IAAI,OAAO;IAKzB,MAAM,QAAQ,IAAI,UAAU,GAAG;AAC/B,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,MAAM;AACvF,SAAK,UAAU;AACf;;AAOF,OAAI,eAAe,KAAK,KAAK,eAAe,EAAE;AAC5C,QAAI,OAAO,SAAS,aAAa,UAAU,OACxB,KAAI,UAAyB,GAAG,EACvC,QAAQ,OAAO,KAA2C;IAGtE,MAAM,WAAW,IAAI,UAAU,GAAG;AAClC,yBAAqB,KAAK,KAAK,gBAAgB,YAAY,IAAI,UAAU,GAAG,KAAK,SAAS;AAC1F,SAAK,UAAU;;IAEjB;;;;;CAMJ,gBAAgB;EACd,MAAM,MAAM,KAAK;EACjB,MAAM,EAAE,OAAO,KAAK;AAIpB,MACE,KAAK,WACL,eAAe,KAAe,KAAK,eAAe,KAAK,QACvD,KAAK,UAAU,GAAG,EAClB;AAYA,QAAK,MAAM,SAAS,IAAI,UAAU,CAAC,OACjC,KAAI,YAAY,SAAS,MAAM,WAAW,GACxC,KAAI,YAAY,MAAM,GAAG;AAI7B,OAAI,aAAa,GAAG;AACpB,0BAAuB,KAAK,KAAK,gBAAgB,KAAK"}
@@ -2,7 +2,7 @@ import { MapboxMap } from "./MapboxMap.js";
2
2
  import { MapboxClusterItem } from "./MapboxClusterItem.js";
3
3
  import { MapboxCluster } from "./MapboxCluster.js";
4
4
  import { MapboxGeocoder } from "./MapboxGeocoder.js";
5
- import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
5
+ import { BaseConfig, BaseProps, ChildrenCollection } from "@studiometa/js-toolkit";
6
6
  import { LngLatBoundsLike, Map, Popup } from "mapbox-gl";
7
7
  import { Base } from "@studiometa/js-toolkit/Base";
8
8
 
@@ -14,6 +14,15 @@ interface StoreLocatorProps extends BaseProps {
14
14
  fitOnUpdate: boolean;
15
15
  popupOptions: Record<string, unknown>;
16
16
  };
17
+ $emits: {
18
+ 'map-select': {
19
+ item: MapboxClusterItem;
20
+ };
21
+ 'map-deselect': void;
22
+ 'map-filter': {
23
+ items: MapboxClusterItem[];
24
+ };
25
+ };
17
26
  }
18
27
  /**
19
28
  * Coordinate a "find a store near you" experience on top of a `MapboxMap`.
@@ -41,17 +50,15 @@ interface StoreLocatorProps extends BaseProps {
41
50
  * and the `map-select` event.
42
51
  *
43
52
  * The orchestrator requires its `MapboxCluster` (and `MapboxMap`) to live within
44
- * its own subtree; it resolves them with `$query`, retries a few ticks for
45
- * asynchronously-mounted children, and — like the map children — subscribes to
46
- * the `MAPBOX_MAP_CONNECTED` / `MAPBOX_CLUSTER_CONNECTED` events so a late or
47
- * replaced map/cluster (re)binds instead of stranding the orchestrator on a
48
- * destroyed instance, and to the map's own `remove` event so a removed map is
49
- * never called into. Register each component independently (e.g. with
50
- * `registerComponent`, optionally behind a lazy `importWhen*` helper):
51
- * `StoreLocator`, `MapboxMap`, `MapboxCluster` and `MapboxClusterItem`.
52
- * Registration order does not matter because children resolve their map through
53
- * the connected-event retry, and the orchestrator declares no child components
54
- * so nothing is ever double-mounted.
53
+ * its own subtree. It watches both with `$watchChildren()`, so a cluster or
54
+ * geocoder that mounts late — or one that replaces the wired instance — is
55
+ * picked up without polling; it subscribes to `MAPBOX_MAP_CONNECTED` because a
56
+ * map announces its Mapbox instance *after* mounting, which a children
57
+ * collection cannot report; and it subscribes to the map's own `remove` event
58
+ * so a removed map is never called into. Register each component independently
59
+ * with `registerComponent`: `StoreLocator`, `MapboxMap`, `MapboxCluster` and
60
+ * `MapboxClusterItem`. Registration and mount order do not matter, and the
61
+ * orchestrator declares no child components so nothing is ever double-mounted.
55
62
  *
56
63
  * @see https://ui.studiometa.dev/reference/items/MapboxMap/
57
64
  */
@@ -61,9 +68,9 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
61
68
  *
62
69
  * No child components are declared: `MapboxMap`, `MapboxCluster`,
63
70
  * `MapboxClusterItem` and `MapboxGeocoder` are each registered independently
64
- * (e.g. with `registerComponent`, optionally behind a lazy `importWhen*`
65
- * helper) and mount on their own. The orchestrator discovers them through
66
- * `$query` once available — declaring them here would double-mount them.
71
+ * with `registerComponent` and mount on their own. The orchestrator discovers
72
+ * them through `$watchChildren()`; declaring them here would double-mount
73
+ * them, since the registry already mounts a declared element.
67
74
  */
68
75
  static config: BaseConfig;
69
76
  /**
@@ -99,13 +106,13 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
99
106
  __popup?: Popup;
100
107
  /**
101
108
  * Unsubscribe callbacks for the `MapboxCluster` listeners, flushed both on
102
- * destroy and when the cluster is replaced (so the orchestrator re-wires onto
103
- * the new instance rather than staying subscribed to the destroyed one).
109
+ * unmount and when the cluster is replaced (so the orchestrator re-wires onto
110
+ * the new instance rather than staying subscribed to the unmounted one).
104
111
  * @private
105
112
  */
106
113
  __offCluster: Array<() => void>;
107
114
  /**
108
- * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on destroy.
115
+ * Unsubscribe callbacks for the `MapboxGeocoder` listeners, flushed on unmount.
109
116
  * @private
110
117
  */
111
118
  __offGeocoder: Array<() => void>;
@@ -129,26 +136,33 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
129
136
  */
130
137
  __offMapConnected?: () => void;
131
138
  /**
132
- * Off handle for the standing document-level `MAPBOX_CLUSTER_CONNECTED` retry
133
- * subscription, so a cluster that mounts late — or replaces the wired one — is
134
- * (re)wired instead of stranding the orchestrator on a destroyed instance.
135
- * @private
136
- */
137
- __offClusterConnected?: () => void;
138
- /**
139
- * Whether the `MapboxCluster` listeners are already attached.
139
+ * The mounted `MapboxCluster` descendants, live and in DOM order.
140
+ *
141
+ * The collection answers "has the cluster mounted yet?" on its own: a cluster
142
+ * that mounts late, or one that replaces the wired one, reaches the
143
+ * `added`/`removed` callbacks with nothing to poll. The cluster still
144
+ * dispatches `MAPBOX_CLUSTER_CONNECTED` for `MapboxClusterItem`, which looks
145
+ * *up* for its cluster and has no watching counterpart to `$closest()`.
140
146
  * @private
141
147
  */
142
- __clusterWired: boolean;
148
+ __clusters: ChildrenCollection<MapboxCluster>;
143
149
  /**
144
- * Whether the `MapboxGeocoder` `map-result` listener is already attached.
150
+ * The mounted `MapboxGeocoder` descendants, live and in DOM order. The
151
+ * geocoder is optional, so nothing waits for it: it wires itself whenever it
152
+ * turns up.
145
153
  * @private
146
154
  */
147
- __geocoderWired: boolean;
155
+ __geocoders: ChildrenCollection<MapboxGeocoder>;
148
156
  /**
149
- * The closest child `MapboxMap` component.
157
+ * The child `MapboxMap` component, once it has mounted.
158
+ *
159
+ * The getter does not warn when there is none: a wrapper mounts before the
160
+ * elements inside it and mount order is not guaranteed, so "no map yet" is
161
+ * the normal state on every healthy locator. A locator with genuinely no map
162
+ * in its markup is reported once instead, from
163
+ * {@link __warnWhenMapIsMissing}.
150
164
  */
151
- get mapboxMap(): MapboxMap<BaseProps>;
165
+ get mapboxMap(): MapboxMap | undefined;
152
166
  /**
153
167
  * The child `MapboxCluster`, discovered in the subtree.
154
168
  */
@@ -284,41 +298,52 @@ declare class StoreLocator<T extends BaseProps = BaseProps> extends Base<T & Sto
284
298
  */
285
299
  __waitForConnectedMap(): void;
286
300
  /**
287
- * Subscribe once to `MAPBOX_CLUSTER_CONNECTED` and (re)wire when a
288
- * `MapboxCluster` inside this orchestrator connects. A cluster that replaces
289
- * the wired one drops the stale wiring and re-wires onto the new instance, so
290
- * list clicks, viewport filtering and selection keep working after a swap.
301
+ * Report a locator with no `MapboxMap` in its markup, once.
302
+ *
303
+ * The check reads the **element**, not the mounted instance: DOM ancestry is
304
+ * a fact that exists before anything mounts, so it is immune both to mount
305
+ * ordering and to the map's mount strategy — a `data-mount` that has not
306
+ * fired yet is not a missing map. `whenDOMSettled()` waits for
307
+ * the mutation batch that brought the locator in, which is the earliest
308
+ * moment the markup can be judged complete.
291
309
  * @private
292
310
  */
293
- __waitForConnectedCluster(): void;
311
+ __warnWhenMapIsMissing(): Promise<void>;
294
312
  /**
295
- * Detach the current cluster listeners and reset the wiring flag so
296
- * `__wireChildren` binds afresh onto a replacement cluster.
313
+ * Detach the current cluster listeners so a replacement can be wired afresh.
297
314
  * @private
298
315
  */
299
316
  __unwireCluster(): void;
300
317
  /**
301
- * Attach the `MapboxCluster`/`MapboxGeocoder` listeners once those children
302
- * are available. Both mount asynchronously (the geocoder even lazy-imports its
303
- * module), so we poll a bounded number of ticks until *each* is wired — the
304
- * cluster is required, the geocoder optional. A locator missing the geocoder
305
- * simply polls to the attempt cap (bounded and harmless). The standing
306
- * connected-event subscriptions cover anything that mounts after the cap.
318
+ * Detach the current geocoder listener.
319
+ * @private
320
+ */
321
+ __unwireGeocoder(): void;
322
+ /**
323
+ * Attach the `MapboxCluster` listeners, once, to the first cluster in the
324
+ * subtree. A no-op while the orchestrator itself is unmounted: the collection
325
+ * outlives a mount cycle, so `mounted()` wires whatever it already holds.
326
+ * @private
327
+ */
328
+ __wireCluster(cluster?: MapboxCluster): void;
329
+ /**
330
+ * Attach the optional `MapboxGeocoder` listener, once, to the first geocoder
331
+ * in the subtree.
307
332
  * @private
308
- * @param {number} attempt
309
333
  */
310
- __wireChildren(attempt?: number): void;
334
+ __wireGeocoder(geocoder?: MapboxGeocoder): void;
311
335
  /**
312
- * Mounted hook: bind the delegated sidebar click, resolve and bind the map,
313
- * and install the standing connected-event subscriptions so a late or replaced
314
- * map/cluster (re)binds instead of stranding the orchestrator.
336
+ * Mounted hook: wire whatever the children collections already hold, bind the
337
+ * delegated sidebar click, resolve and bind the map, and install the standing
338
+ * `MAPBOX_MAP_CONNECTED` subscription so a late or replaced map rebinds
339
+ * instead of stranding the orchestrator.
315
340
  */
316
341
  mounted(): void;
317
342
  /**
318
- * Destroyed hook: detach every listener, close the popup and clear the cached
343
+ * Unmounted hook: detach every listener, close the popup and clear the cached
319
344
  * references — even when the element has already been detached from the DOM.
320
345
  */
321
- destroyed(): void;
346
+ unmounted(): void;
322
347
  }
323
348
  //#endregion
324
349
  export { StoreLocator, StoreLocator as default, StoreLocatorProps };