@studiometa/ui-mapbox 0.0.1 → 1.10.0-beta.0

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 (117) hide show
  1. package/AbstractMapboxControl.d.ts +53 -0
  2. package/AbstractMapboxControl.js +70 -0
  3. package/AbstractMapboxControl.js.map +1 -0
  4. package/AbstractMapboxMapChild.d.ts +229 -0
  5. package/AbstractMapboxMapChild.js +336 -0
  6. package/AbstractMapboxMapChild.js.map +1 -0
  7. package/LICENSE.md +110 -0
  8. package/MapboxCluster.d.ts +208 -0
  9. package/MapboxCluster.js +418 -0
  10. package/MapboxCluster.js.map +1 -0
  11. package/MapboxClusterItem.d.ts +130 -0
  12. package/MapboxClusterItem.js +182 -0
  13. package/MapboxClusterItem.js.map +1 -0
  14. package/MapboxFullscreenControl.d.ts +21 -0
  15. package/MapboxFullscreenControl.js +21 -0
  16. package/MapboxFullscreenControl.js.map +1 -0
  17. package/MapboxGeocoder.d.ts +64 -0
  18. package/MapboxGeocoder.js +80 -0
  19. package/MapboxGeocoder.js.map +1 -0
  20. package/MapboxGeolocateControl.d.ts +23 -0
  21. package/MapboxGeolocateControl.js +31 -0
  22. package/MapboxGeolocateControl.js.map +1 -0
  23. package/MapboxImage.d.ts +49 -0
  24. package/MapboxImage.js +83 -0
  25. package/MapboxImage.js.map +1 -0
  26. package/MapboxImages.d.ts +66 -0
  27. package/MapboxImages.js +95 -0
  28. package/MapboxImages.js.map +1 -0
  29. package/MapboxLayer.d.ts +99 -0
  30. package/MapboxLayer.js +148 -0
  31. package/MapboxLayer.js.map +1 -0
  32. package/MapboxMap.d.ts +64 -0
  33. package/MapboxMap.js +131 -0
  34. package/MapboxMap.js.map +1 -0
  35. package/MapboxMarker.d.ts +56 -0
  36. package/MapboxMarker.js +73 -0
  37. package/MapboxMarker.js.map +1 -0
  38. package/MapboxNavigationControl.d.ts +27 -0
  39. package/MapboxNavigationControl.js +28 -0
  40. package/MapboxNavigationControl.js.map +1 -0
  41. package/MapboxPopup.d.ts +51 -0
  42. package/MapboxPopup.js +76 -0
  43. package/MapboxPopup.js.map +1 -0
  44. package/MapboxSource.d.ts +68 -0
  45. package/MapboxSource.js +104 -0
  46. package/MapboxSource.js.map +1 -0
  47. package/README.md +85 -0
  48. package/StoreLocator.d.ts +323 -0
  49. package/StoreLocator.js +538 -0
  50. package/StoreLocator.js.map +1 -0
  51. package/catalog.d.ts +7 -0
  52. package/catalog.js +68 -0
  53. package/catalog.js.map +1 -0
  54. package/dependencies.d.ts +85 -0
  55. package/dependencies.js +84 -0
  56. package/dependencies.js.map +1 -0
  57. package/index.d.ts +18 -0
  58. package/index.js +19 -0
  59. package/index.js.map +1 -0
  60. package/manifest.d.ts +6 -0
  61. package/manifest.js +133 -0
  62. package/manifest.js.map +1 -0
  63. package/package.json +43 -3
  64. package/utils.d.ts +112 -0
  65. package/utils.js +143 -0
  66. package/utils.js.map +1 -0
  67. package/Claude-of-Duty/node_modules/@esbuild/darwin-arm64/bin/esbuild +0 -0
  68. package/alfred-projects-cache.tsv +0 -137
  69. package/claude-501/-Users-titouanmathis--dotfiles/298a49f7-c4b3-4a50-9707-a9c0d0733e95/scratchpad/pptest/config.json +0 -1
  70. package/claude-501/-Users-titouanmathis--dotfiles/298a49f7-c4b3-4a50-9707-a9c0d0733e95/scratchpad/pptest/stub/herdr +0 -8
  71. package/claude-501/-Users-titouanmathis--dotfiles/7d127a50-a71a-411a-bc1f-15b070f909f9/tasks/bg1cckto6.output +0 -4
  72. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/after.toml +0 -298
  73. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/before.toml +0 -298
  74. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/extracted.txt +0 -36
  75. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/final.log +0 -496
  76. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/guard.sh +0 -18
  77. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/lock.check +0 -917
  78. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/mise-registry.json +0 -3827
  79. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/mise.lock.before +0 -917
  80. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/.config/mise/conf.d/extra.toml +0 -2
  81. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/.config/mise/mise.lock +0 -47
  82. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/mise.lock +0 -47
  83. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/misetest/mise.toml +0 -2
  84. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/.github/workflows/mise-check.yml +0 -188
  85. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/.github/workflows/renovate.yml +0 -62
  86. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/mise.lock +0 -917
  87. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/mise.toml +0 -291
  88. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/probe.log +0 -4974
  89. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/probe2.log +0 -22
  90. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/probe3.log +0 -4916
  91. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/probe/renovate.json +0 -62
  92. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/renovate-local.log +0 -670
  93. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/symtest/link/mise.lock +0 -47
  94. package/claude-501/-Users-titouanmathis--dotfiles/dd4cd328-df52-4522-a502-48fa24b7b142/scratchpad/symtest/real/source.toml +0 -4
  95. package/claude-501/-Users-titouanmathis-Lab--studiometa-automations/d6c27f69-577a-468b-9bb3-a45c03a66143/scratchpad/cookie.txt +0 -1
  96. package/gitlab-docs-read.md +0 -8
  97. package/gitlab-instance-limits.txt +0 -8
  98. package/piab-501/piab-devops-019fcbcc991d-59c77b27-fresh-47da8bd318.config +0 -1
  99. package/pins-new.txt +0 -36
  100. package/pins-old.txt +0 -36
  101. package/reply +0 -0
  102. package/zsh0IBbcP +0 -0
  103. package/zsh2LqT39 +0 -0
  104. package/zsh6KJGTP +0 -0
  105. package/zshN1hNdy +0 -0
  106. package/zshNjWSYH +0 -11
  107. package/zshNvB745 +0 -0
  108. package/zshOXC0uH +0 -0
  109. package/zshPG9CFU +0 -0
  110. package/zshVOeZsK +0 -0
  111. package/zshVqIgQS +0 -0
  112. package/zshXTrFg8 +0 -0
  113. package/zshaUGubs +0 -11
  114. package/zshbzOT6d +0 -1
  115. package/zshnbtbGK +0 -0
  116. package/zshpQi1EI +0 -2
  117. package/zshwhMjOD +0 -1
@@ -0,0 +1,66 @@
1
+ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
2
+ import { MapboxImageDefinition } from "./utils.js";
3
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
+ import { Map } from "mapbox-gl";
5
+
6
+ //#region MapboxImages.d.ts
7
+ interface MapboxImagesProps extends AbstractMapboxMapChildProps {
8
+ $options: {
9
+ /**
10
+ * A list of images to register against the map sprite.
11
+ * @see ./MapboxImage.ts
12
+ */
13
+ sources: MapboxImageDefinition[];
14
+ };
15
+ }
16
+ /**
17
+ * Load and register a list of images against the map sprite.
18
+ * @see https://ui.studiometa.dev/reference/items/MapboxMap/
19
+ */
20
+ declare class MapboxImages<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<T & MapboxImagesProps> {
21
+ /**
22
+ * Config.
23
+ */
24
+ static config: BaseConfig;
25
+ /**
26
+ * The names of the sprites this instance owns. Only these may be removed on
27
+ * teardown; pre-existing sprites (registered by someone else) are left
28
+ * untouched, and a sprite a newer sibling has since adopted is left to it.
29
+ * @private
30
+ */
31
+ __ownedNames: string[];
32
+ /**
33
+ * The `kind:name` ownership key for the given sprite.
34
+ * @private
35
+ * @param {string} name
36
+ * @returns {string}
37
+ */
38
+ __ownershipKey(name: string): string;
39
+ /**
40
+ * Mounted hook.
41
+ */
42
+ mounted(): void;
43
+ /**
44
+ * Own a sprite this instance added, or adopt one from a family sibling (a
45
+ * same-name `Fetch` swap), so the outgoing instance's teardown does not remove
46
+ * a sprite this replacement now depends on.
47
+ * @private
48
+ * @param {Map} map
49
+ * @param {string} name
50
+ * @param {boolean} added
51
+ */
52
+ __adopt(map: Map, name: string, added: boolean): void;
53
+ /**
54
+ * Remove every sprite this instance still owns from the given map, releasing
55
+ * ownership as it goes.
56
+ * @private
57
+ * @param {Map | undefined} map
58
+ */
59
+ __removeOwned(map?: Map): void;
60
+ /**
61
+ * Teardown hook.
62
+ */
63
+ __onDestroyed(): void;
64
+ }
65
+ //#endregion
66
+ export { MapboxImages, MapboxImages as default, MapboxImagesProps };
@@ -0,0 +1,95 @@
1
+ import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
+ import { addMapboxImage, claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from "./utils.js";
3
+ //#region MapboxImages.ts
4
+ /**
5
+ * Load and register a list of images against the map sprite.
6
+ * @see https://ui.studiometa.dev/reference/items/MapboxMap/
7
+ */
8
+ var MapboxImages = class extends AbstractMapboxMapChild {
9
+ /**
10
+ * Config.
11
+ */
12
+ static config = {
13
+ name: "MapboxImages",
14
+ emits: ["map-ready"],
15
+ options: { sources: {
16
+ type: Array,
17
+ default: () => []
18
+ } }
19
+ };
20
+ /**
21
+ * The names of the sprites this instance owns. Only these may be removed on
22
+ * teardown; pre-existing sprites (registered by someone else) are left
23
+ * untouched, and a sprite a newer sibling has since adopted is left to it.
24
+ * @private
25
+ */
26
+ __ownedNames = [];
27
+ /**
28
+ * The `kind:name` ownership key for the given sprite.
29
+ * @private
30
+ * @param {string} name
31
+ * @returns {string}
32
+ */
33
+ __ownershipKey(name) {
34
+ return `image:${name}`;
35
+ }
36
+ /**
37
+ * Mounted hook.
38
+ */
39
+ mounted() {
40
+ this.whenMapReady(async (map) => {
41
+ const { sources } = this.$options;
42
+ const images = await Promise.all(sources.map(async (source) => {
43
+ const { image, added } = await addMapboxImage(map, source);
44
+ this.__adopt(map, source.name, added);
45
+ return image;
46
+ }));
47
+ if (!this.$isMounted || this.__readyMap !== map) {
48
+ if (this.__readyMap === map) this.__removeOwned(map);
49
+ return;
50
+ }
51
+ this.$emit("map-ready", images);
52
+ });
53
+ }
54
+ /**
55
+ * Own a sprite this instance added, or adopt one from a family sibling (a
56
+ * same-name `Fetch` swap), so the outgoing instance's teardown does not remove
57
+ * a sprite this replacement now depends on.
58
+ * @private
59
+ * @param {Map} map
60
+ * @param {string} name
61
+ * @param {boolean} added
62
+ */
63
+ __adopt(map, name, added) {
64
+ if (added || getMapboxOwner(map, this.__ownershipKey(name))) {
65
+ claimMapboxOwnership(map, this.__ownershipKey(name), this, () => map.hasImage(name));
66
+ if (!this.__ownedNames.includes(name)) this.__ownedNames.push(name);
67
+ }
68
+ }
69
+ /**
70
+ * Remove every sprite this instance still owns from the given map, releasing
71
+ * ownership as it goes.
72
+ * @private
73
+ * @param {Map | undefined} map
74
+ */
75
+ __removeOwned(map) {
76
+ for (const name of this.__ownedNames) {
77
+ const key = this.__ownershipKey(name);
78
+ if (getMapboxOwner(map, key) === this && map?.hasImage(name)) {
79
+ map.removeImage(name);
80
+ releaseMapboxOwnership(map, key, this);
81
+ }
82
+ }
83
+ this.__ownedNames = [];
84
+ }
85
+ /**
86
+ * Teardown hook.
87
+ */
88
+ __onDestroyed() {
89
+ this.__removeOwned(this.__readyMap);
90
+ }
91
+ };
92
+ //#endregion
93
+ export { MapboxImages, MapboxImages as default };
94
+
95
+ //# sourceMappingURL=MapboxImages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxImages.js","names":[],"sources":["../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"}
@@ -0,0 +1,99 @@
1
+ import { AbstractMapboxMapChild, AbstractMapboxMapChildProps } from "./AbstractMapboxMapChild.js";
2
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
3
+ import { LayerSpecification, Map, MapSourceDataEvent } from "mapbox-gl";
4
+
5
+ //#region MapboxLayer.d.ts
6
+ interface MapboxLayerProps extends AbstractMapboxMapChildProps {
7
+ $options: {
8
+ id: string;
9
+ layer: LayerSpecification;
10
+ beforeId: string;
11
+ };
12
+ }
13
+ /**
14
+ * Add a layer to the map.
15
+ * @see https://ui.studiometa.dev/reference/items/MapboxMap/
16
+ */
17
+ declare class MapboxLayer<T extends BaseProps = BaseProps> extends AbstractMapboxMapChild<T & MapboxLayerProps> {
18
+ /**
19
+ * Config.
20
+ */
21
+ static config: BaseConfig;
22
+ /**
23
+ * Whether this instance owns the layer under its id. Only a layer this
24
+ * instance owns may be removed on teardown; a layer declared outside the
25
+ * family, or one a newer sibling has since adopted, is left untouched.
26
+ * @private
27
+ */
28
+ __added: boolean;
29
+ /**
30
+ * The `kind:id` ownership key for this layer.
31
+ * @private
32
+ */
33
+ get __ownershipKey(): string;
34
+ /**
35
+ * The source id this layer references, when it references one by string.
36
+ * @private
37
+ */
38
+ get __sourceId(): string | undefined;
39
+ /**
40
+ * Add (or re-add) the layer whenever its referenced source becomes available
41
+ * and the layer is not currently on the map.
42
+ *
43
+ * This is a *standing* recovery watch, not a one-shot: it stays subscribed for
44
+ * the layer's whole life so the layer re-commits itself if its source
45
+ * disappears and comes back — e.g. a sibling `MapboxSource` teardown removes
46
+ * this still-mounted layer to drop its source, then the source is re-added
47
+ * later (H7, PR #567 review). Committing once and unsubscribing (the previous
48
+ * behaviour) left such a layer gone for good.
49
+ *
50
+ * It is kept cheap: `sourcedata` fires often, so the handler early-returns
51
+ * unless this layer is actually missing, and — when the event identifies a
52
+ * source — ignores events for any source other than this layer's. The commit
53
+ * itself is deferred to a microtask because mutating the style from within
54
+ * mapbox-gl's render loop can leave a layer half-initialized and crash the
55
+ * symbol placement pass.
56
+ * @private
57
+ * @param {MapSourceDataEvent} [event]
58
+ */
59
+ __handleSourceData: (event?: MapSourceDataEvent) => void;
60
+ /**
61
+ * Add the layer to the map, or adopt an existing one.
62
+ *
63
+ * When the id is free the layer is added and ownership claimed. When a layer
64
+ * with this id already exists, re-adding it would throw a duplicate-id error,
65
+ * so it is left in place; ownership is only taken over from a sibling
66
+ * `MapboxLayer` (e.g. a `Fetch` swap), never from an externally declared layer.
67
+ * @private
68
+ * @param {Map} map
69
+ */
70
+ __commitLayer(map: Map): void;
71
+ /**
72
+ * Whether the source referenced by the layer is available on the map.
73
+ *
74
+ * Layers referencing an inline source object — or no source at all, like a
75
+ * `background` layer — are always considered available.
76
+ * @private
77
+ * @param {Map} map
78
+ * @returns {boolean}
79
+ */
80
+ __sourceIsAvailable(map: Map): boolean;
81
+ /**
82
+ * Mounted hook.
83
+ */
84
+ mounted(): void;
85
+ /**
86
+ * Flush the standing `sourcedata` recovery watch against the map being
87
+ * removed, while it is still referenceable — `__onDestroyed` runs later with
88
+ * `__readyMap` already cleared and could not reach the map to unsubscribe.
89
+ * @protected
90
+ * @param {Map} map
91
+ */
92
+ __onMapRemove(map: Map): void;
93
+ /**
94
+ * Teardown hook.
95
+ */
96
+ __onDestroyed(): void;
97
+ }
98
+ //#endregion
99
+ export { MapboxLayer, MapboxLayer as default, MapboxLayerProps };
package/MapboxLayer.js ADDED
@@ -0,0 +1,148 @@
1
+ import { AbstractMapboxMapChild } from "./AbstractMapboxMapChild.js";
2
+ import { claimMapboxOwnership, getMapboxOwner, releaseMapboxOwnership } from "./utils.js";
3
+ //#region MapboxLayer.ts
4
+ /**
5
+ * Add a layer to the map.
6
+ * @see https://ui.studiometa.dev/reference/items/MapboxMap/
7
+ */
8
+ var MapboxLayer = class extends AbstractMapboxMapChild {
9
+ /**
10
+ * Config.
11
+ */
12
+ static config = {
13
+ name: "MapboxLayer",
14
+ options: {
15
+ id: String,
16
+ layer: Object,
17
+ beforeId: String
18
+ }
19
+ };
20
+ /**
21
+ * Whether this instance owns the layer under its id. Only a layer this
22
+ * instance owns may be removed on teardown; a layer declared outside the
23
+ * family, or one a newer sibling has since adopted, is left untouched.
24
+ * @private
25
+ */
26
+ __added = false;
27
+ /**
28
+ * The `kind:id` ownership key for this layer.
29
+ * @private
30
+ */
31
+ get __ownershipKey() {
32
+ return `layer:${this.$options.id}`;
33
+ }
34
+ /**
35
+ * The source id this layer references, when it references one by string.
36
+ * @private
37
+ */
38
+ get __sourceId() {
39
+ const { source } = this.$options.layer;
40
+ return typeof source === "string" ? source : void 0;
41
+ }
42
+ /**
43
+ * Add (or re-add) the layer whenever its referenced source becomes available
44
+ * and the layer is not currently on the map.
45
+ *
46
+ * This is a *standing* recovery watch, not a one-shot: it stays subscribed for
47
+ * the layer's whole life so the layer re-commits itself if its source
48
+ * disappears and comes back — e.g. a sibling `MapboxSource` teardown removes
49
+ * this still-mounted layer to drop its source, then the source is re-added
50
+ * later (H7, PR #567 review). Committing once and unsubscribing (the previous
51
+ * behaviour) left such a layer gone for good.
52
+ *
53
+ * It is kept cheap: `sourcedata` fires often, so the handler early-returns
54
+ * unless this layer is actually missing, and — when the event identifies a
55
+ * source — ignores events for any source other than this layer's. The commit
56
+ * itself is deferred to a microtask because mutating the style from within
57
+ * mapbox-gl's render loop can leave a layer half-initialized and crash the
58
+ * symbol placement pass.
59
+ * @private
60
+ * @param {MapSourceDataEvent} [event]
61
+ */
62
+ __handleSourceData = (event) => {
63
+ const map = this.__readyMap;
64
+ const { id } = this.$options;
65
+ if (event?.sourceId && this.__sourceId && event.sourceId !== this.__sourceId) return;
66
+ if (!map || map.getLayer(id) || !this.__sourceIsAvailable(map)) return;
67
+ queueMicrotask(() => {
68
+ if (this.$isMounted && this.__readyMap === map && !map.getLayer(id)) this.__commitLayer(map);
69
+ });
70
+ };
71
+ /**
72
+ * Add the layer to the map, or adopt an existing one.
73
+ *
74
+ * When the id is free the layer is added and ownership claimed. When a layer
75
+ * with this id already exists, re-adding it would throw a duplicate-id error,
76
+ * so it is left in place; ownership is only taken over from a sibling
77
+ * `MapboxLayer` (e.g. a `Fetch` swap), never from an externally declared layer.
78
+ * @private
79
+ * @param {Map} map
80
+ */
81
+ __commitLayer(map) {
82
+ const { beforeId, id, layer } = this.$options;
83
+ layer.id = id;
84
+ if (map.getLayer(id)) {
85
+ if (getMapboxOwner(map, this.__ownershipKey)) {
86
+ map.removeLayer(id);
87
+ map.addLayer(layer, beforeId);
88
+ const added = map.getLayer(id);
89
+ claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);
90
+ this.__added = true;
91
+ }
92
+ return;
93
+ }
94
+ map.addLayer(layer, beforeId);
95
+ const added = map.getLayer(id);
96
+ claimMapboxOwnership(map, this.__ownershipKey, this, () => map.getLayer(id) === added);
97
+ this.__added = true;
98
+ }
99
+ /**
100
+ * Whether the source referenced by the layer is available on the map.
101
+ *
102
+ * Layers referencing an inline source object — or no source at all, like a
103
+ * `background` layer — are always considered available.
104
+ * @private
105
+ * @param {Map} map
106
+ * @returns {boolean}
107
+ */
108
+ __sourceIsAvailable(map) {
109
+ const { source } = this.$options.layer;
110
+ return typeof source !== "string" || Boolean(map.getSource(source));
111
+ }
112
+ /**
113
+ * Mounted hook.
114
+ */
115
+ mounted() {
116
+ this.whenMapReady((map) => {
117
+ map.off("sourcedata", this.__handleSourceData);
118
+ map.on("sourcedata", this.__handleSourceData);
119
+ if (this.__sourceIsAvailable(map)) this.__commitLayer(map);
120
+ });
121
+ }
122
+ /**
123
+ * Flush the standing `sourcedata` recovery watch against the map being
124
+ * removed, while it is still referenceable — `__onDestroyed` runs later with
125
+ * `__readyMap` already cleared and could not reach the map to unsubscribe.
126
+ * @protected
127
+ * @param {Map} map
128
+ */
129
+ __onMapRemove(map) {
130
+ map.off("sourcedata", this.__handleSourceData);
131
+ }
132
+ /**
133
+ * Teardown hook.
134
+ */
135
+ __onDestroyed() {
136
+ const map = this.__readyMap;
137
+ const { id } = this.$options;
138
+ map?.off("sourcedata", this.__handleSourceData);
139
+ if (this.__added && getMapboxOwner(map, this.__ownershipKey) === this && map?.getLayer(id)) {
140
+ map.removeLayer(id);
141
+ releaseMapboxOwnership(map, this.__ownershipKey, this);
142
+ }
143
+ }
144
+ };
145
+ //#endregion
146
+ export { MapboxLayer, MapboxLayer as default };
147
+
148
+ //# sourceMappingURL=MapboxLayer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxLayer.js","names":[],"sources":["../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"}
package/MapboxMap.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ import { Base, BaseConfig, BaseProps } from "@studiometa/js-toolkit";
2
+ import { Map, MapOptions } from "mapbox-gl";
3
+
4
+ //#region MapboxMap.d.ts
5
+ interface MapboxMapProps extends BaseProps {
6
+ $refs: {
7
+ container: HTMLElement;
8
+ };
9
+ $options: {
10
+ accessToken: string;
11
+ zoom: number;
12
+ center: [number, number];
13
+ mapOptions: Partial<Omit<MapOptions, 'container'>>;
14
+ };
15
+ }
16
+ /**
17
+ * Display a Mapbox GL map.
18
+ * @see https://ui.studiometa.dev/reference/items/MapboxMap/
19
+ */
20
+ declare class MapboxMap<T extends BaseProps = BaseProps> extends Base<T & MapboxMapProps> {
21
+ /**
22
+ * Config.
23
+ */
24
+ static config: BaseConfig;
25
+ /**
26
+ * Is the map loaded?
27
+ */
28
+ isLoaded: boolean;
29
+ /**
30
+ * Map instance, or `undefined` until it is built in `mounted()` and once it is
31
+ * cleared on teardown.
32
+ * @private
33
+ */
34
+ __map: Map | undefined;
35
+ /**
36
+ * Off handles for every forwarding listener attached to the map, flushed on
37
+ * teardown so a retained reference to a removed `Map` does not keep this
38
+ * component (and its `$emit` closures) alive.
39
+ * @private
40
+ */
41
+ __offMapListeners: Array<() => void>;
42
+ /**
43
+ * The mapbox Map instance, or `undefined` until it has been built.
44
+ *
45
+ * The map is built in `mounted()` after `mapbox-gl` resolves (it may be
46
+ * injected or lazily imported), so this getter returns `undefined` while that
47
+ * resolution is still pending. Children read it after the map announces itself
48
+ * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.
49
+ */
50
+ get map(): Map | undefined;
51
+ /**
52
+ * Mounted hook.
53
+ *
54
+ * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then
55
+ * announces it so children can inject themselves.
56
+ */
57
+ mounted(): Promise<void>;
58
+ /**
59
+ * Destroyed hook.
60
+ */
61
+ destroyed(): void;
62
+ }
63
+ //#endregion
64
+ export { MapboxMap, MapboxMap as default, MapboxMapProps };
package/MapboxMap.js ADDED
@@ -0,0 +1,131 @@
1
+ import { MAPBOX_MAP_CONNECTED } from "./AbstractMapboxMapChild.js";
2
+ import { resolveMapboxGl } from "./dependencies.js";
3
+ import { Base } from "@studiometa/js-toolkit";
4
+ //#region MapboxMap.ts
5
+ const FORWARDED_MAP_EVENTS = [
6
+ "click",
7
+ "dblclick",
8
+ "mouseenter",
9
+ "mouseleave",
10
+ "mousemove",
11
+ "movestart",
12
+ "move",
13
+ "moveend",
14
+ "zoomstart",
15
+ "zoom",
16
+ "zoomend",
17
+ "rotatestart",
18
+ "rotate",
19
+ "rotateend",
20
+ "pitchstart",
21
+ "pitch",
22
+ "pitchend",
23
+ "dragstart",
24
+ "drag",
25
+ "dragend",
26
+ "idle",
27
+ "render",
28
+ "resize",
29
+ "remove",
30
+ "error"
31
+ ];
32
+ /**
33
+ * Display a Mapbox GL map.
34
+ * @see https://ui.studiometa.dev/reference/items/MapboxMap/
35
+ */
36
+ var MapboxMap = class extends Base {
37
+ /**
38
+ * Config.
39
+ */
40
+ static config = {
41
+ name: "MapboxMap",
42
+ emits: ["map-load", ...FORWARDED_MAP_EVENTS.map((event) => `map-${event}`)],
43
+ refs: ["container"],
44
+ options: {
45
+ accessToken: String,
46
+ zoom: Number,
47
+ center: {
48
+ type: Array,
49
+ default: () => [0, 0]
50
+ },
51
+ mapOptions: {
52
+ type: Object,
53
+ default: () => ({})
54
+ }
55
+ }
56
+ };
57
+ /**
58
+ * Is the map loaded?
59
+ */
60
+ isLoaded = false;
61
+ /**
62
+ * Map instance, or `undefined` until it is built in `mounted()` and once it is
63
+ * cleared on teardown.
64
+ * @private
65
+ */
66
+ __map;
67
+ /**
68
+ * Off handles for every forwarding listener attached to the map, flushed on
69
+ * teardown so a retained reference to a removed `Map` does not keep this
70
+ * component (and its `$emit` closures) alive.
71
+ * @private
72
+ */
73
+ __offMapListeners = [];
74
+ /**
75
+ * The mapbox Map instance, or `undefined` until it has been built.
76
+ *
77
+ * The map is built in `mounted()` after `mapbox-gl` resolves (it may be
78
+ * injected or lazily imported), so this getter returns `undefined` while that
79
+ * resolution is still pending. Children read it after the map announces itself
80
+ * through `MAPBOX_MAP_CONNECTED`, which only fires once the instance exists.
81
+ */
82
+ get map() {
83
+ return this.__map;
84
+ }
85
+ /**
86
+ * Mounted hook.
87
+ *
88
+ * Resolves `mapbox-gl` (injected or lazily imported), builds the map, then
89
+ * announces it so children can inject themselves.
90
+ */
91
+ async mounted() {
92
+ const mapboxgl = await resolveMapboxGl();
93
+ if (!this.$isMounted) return;
94
+ const map = new mapboxgl.Map({
95
+ accessToken: this.$options.accessToken,
96
+ zoom: this.$options.zoom,
97
+ center: this.$options.center,
98
+ ...this.$options.mapOptions,
99
+ container: this.$refs.container ?? this.$el
100
+ });
101
+ this.__map = map;
102
+ const onLoad = () => {
103
+ this.isLoaded = true;
104
+ this.$emit("map-load", map);
105
+ };
106
+ map.on("load", onLoad);
107
+ this.__offMapListeners.push(() => this.__map?.off("load", onLoad));
108
+ for (const event of FORWARDED_MAP_EVENTS) {
109
+ const handler = (e) => {
110
+ this.$emit(`map-${event}`, e);
111
+ };
112
+ map.on(event, handler);
113
+ this.__offMapListeners.push(() => this.__map?.off(event, handler));
114
+ }
115
+ document.dispatchEvent(new CustomEvent(MAPBOX_MAP_CONNECTED, { detail: this }));
116
+ }
117
+ /**
118
+ * Destroyed hook.
119
+ */
120
+ destroyed() {
121
+ for (const off of this.__offMapListeners) off();
122
+ this.__offMapListeners = [];
123
+ this.__map?.remove();
124
+ this.__map = void 0;
125
+ this.isLoaded = false;
126
+ }
127
+ };
128
+ //#endregion
129
+ export { MapboxMap, MapboxMap as default };
130
+
131
+ //# sourceMappingURL=MapboxMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxMap.js","names":[],"sources":["../MapboxMap.ts"],"sourcesContent":["import { Base, type BaseConfig, type 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":";;;;AAKA,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"}