@nuxt/scripts 2.0.0-beta.6 → 2.0.0-beta.8

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 (67) hide show
  1. package/dist/devtools-client/200.html +1 -1
  2. package/dist/devtools-client/404.html +1 -1
  3. package/dist/devtools-client/_nuxt/{Bagqfgzu.js → BBRrg_AT.js} +3 -3
  4. package/dist/devtools-client/_nuxt/{CP6K2Qm6.js → BI6wdYky.js} +1 -1
  5. package/dist/devtools-client/_nuxt/{CWci3Eb_.js → BckE5qrE.js} +1 -1
  6. package/dist/devtools-client/_nuxt/{D_hceTm9.js → Cs0md1ml.js} +1 -1
  7. package/dist/devtools-client/_nuxt/{DZ6h2v9A.js → DN3hUMR_.js} +1 -1
  8. package/dist/devtools-client/_nuxt/{DXDqMNFL.js → DXEYGql4.js} +1 -1
  9. package/dist/devtools-client/_nuxt/{utTTwIIR.js → Divy0_cA.js} +3 -3
  10. package/dist/devtools-client/_nuxt/builds/latest.json +1 -1
  11. package/dist/devtools-client/_nuxt/builds/meta/afe20d38-a0b8-4d9f-be82-37b90ecac717.json +1 -0
  12. package/dist/devtools-client/_nuxt/error-404.BJ1JSMYb.css +1 -0
  13. package/dist/devtools-client/_nuxt/error-500.BBf0uW5X.css +1 -0
  14. package/dist/devtools-client/docs/index.html +1 -1
  15. package/dist/devtools-client/first-party/index.html +1 -1
  16. package/dist/devtools-client/index.html +1 -1
  17. package/dist/devtools-client/registry/index.html +1 -1
  18. package/dist/module.d.mts +1 -0
  19. package/dist/module.d.ts +1 -0
  20. package/dist/module.json +1 -1
  21. package/dist/module.mjs +4 -1
  22. package/dist/registry.mjs +24 -1
  23. package/dist/runtime/components/Leaflet/ScriptLeafletMap.d.vue.ts +5 -5
  24. package/dist/runtime/components/Leaflet/ScriptLeafletMap.vue.d.ts +5 -5
  25. package/dist/runtime/components/MapLibre/ScriptMapLibreAttributionControl.d.vue.ts +7 -0
  26. package/dist/runtime/components/MapLibre/ScriptMapLibreAttributionControl.vue +42 -0
  27. package/dist/runtime/components/MapLibre/ScriptMapLibreAttributionControl.vue.d.ts +7 -0
  28. package/dist/runtime/components/MapLibre/ScriptMapLibreFullscreenControl.d.vue.ts +13 -0
  29. package/dist/runtime/components/MapLibre/ScriptMapLibreFullscreenControl.vue +27 -0
  30. package/dist/runtime/components/MapLibre/ScriptMapLibreFullscreenControl.vue.d.ts +13 -0
  31. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.d.vue.ts +26 -35
  32. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.vue +233 -15
  33. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.vue.d.ts +26 -35
  34. package/dist/runtime/components/MapLibre/ScriptMapLibreGeolocateControl.d.vue.ts +25 -0
  35. package/dist/runtime/components/MapLibre/ScriptMapLibreGeolocateControl.vue +49 -0
  36. package/dist/runtime/components/MapLibre/ScriptMapLibreGeolocateControl.vue.d.ts +25 -0
  37. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.d.vue.ts +22 -86
  38. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.vue +23 -2
  39. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.vue.d.ts +22 -86
  40. package/dist/runtime/components/MapLibre/ScriptMapLibreMarker.d.vue.ts +3 -12
  41. package/dist/runtime/components/MapLibre/ScriptMapLibreMarker.vue.d.ts +3 -12
  42. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.d.vue.ts +3 -8
  43. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.vue +1 -4
  44. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.vue.d.ts +3 -8
  45. package/dist/runtime/components/MapLibre/ScriptMapLibrePopup.d.vue.ts +3 -10
  46. package/dist/runtime/components/MapLibre/ScriptMapLibrePopup.vue.d.ts +3 -10
  47. package/dist/runtime/components/MapLibre/ScriptMapLibreScaleControl.d.vue.ts +7 -0
  48. package/dist/runtime/components/MapLibre/ScriptMapLibreScaleControl.vue +25 -0
  49. package/dist/runtime/components/MapLibre/ScriptMapLibreScaleControl.vue.d.ts +7 -0
  50. package/dist/runtime/components/MapLibre/types.d.ts +275 -0
  51. package/dist/runtime/components/MapLibre/types.js +0 -0
  52. package/dist/runtime/components/MapLibre/useMapLibreResource.d.ts +8 -1
  53. package/dist/runtime/components/MapLibre/useMapLibreResource.js +9 -2
  54. package/dist/runtime/registry/pulse-analytics.d.ts +32 -0
  55. package/dist/runtime/registry/pulse-analytics.js +80 -0
  56. package/dist/runtime/registry/schemas.d.ts +42 -0
  57. package/dist/runtime/registry/schemas.js +42 -0
  58. package/dist/runtime/registry/tawk-to.d.ts +126 -0
  59. package/dist/runtime/registry/tawk-to.js +147 -0
  60. package/dist/runtime/types.d.ts +6 -1
  61. package/dist/stats.mjs +81 -0
  62. package/dist/types-source.mjs +312 -4
  63. package/dist/types.d.mts +2 -0
  64. package/package.json +10 -10
  65. package/dist/devtools-client/_nuxt/builds/meta/8bf6d5ed-9af4-4b18-be50-90e3f19066d5.json +0 -1
  66. package/dist/devtools-client/_nuxt/error-404.Bn3cR6N7.css +0 -1
  67. package/dist/devtools-client/_nuxt/error-500.ClHmgt9z.css +0 -1
@@ -4,17 +4,142 @@
4
4
 
5
5
  <script setup>
6
6
  import { toRaw, watch } from "vue";
7
- import { useMapLibreResource } from "./useMapLibreResource";
7
+ import { reportMapLibreResourceError, useMapLibreResource } from "./useMapLibreResource";
8
8
  const props = defineProps({
9
9
  sourceId: { type: String, required: true },
10
10
  data: { type: null, required: true },
11
11
  sourceOptions: { type: Object, required: false },
12
12
  layers: { type: Array, required: true },
13
- beforeId: { type: String, required: false }
13
+ beforeId: { type: String, required: false },
14
+ cursor: { type: String, required: false }
14
15
  });
16
+ const emit = defineEmits(["error", "click", "dblclick", "mouseenter", "mousemove", "mouseleave", "sourceready"]);
15
17
  let ownedLayerIds = [];
16
18
  let ownedSourceId;
19
+ let appliedStructure;
20
+ let appliedStyleSignature;
21
+ let appliedStyles = [];
22
+ let layerSubscriptions = [];
23
+ let restoreCursor;
24
+ let isPointerOverLayer = false;
25
+ let hoveredLayerKey = "";
26
+ let pendingHoverKey = "";
27
+ let isStyleMutable = false;
28
+ let hasPendingSync = false;
29
+ let capturedErrors;
30
+ function toError(event) {
31
+ return event.error instanceof Error ? event.error : new Error(event.error.message, { cause: event.error });
32
+ }
33
+ function applyStyleChange(change) {
34
+ const errors = [];
35
+ capturedErrors = errors;
36
+ try {
37
+ change();
38
+ } finally {
39
+ capturedErrors = void 0;
40
+ }
41
+ if (errors.length === 1)
42
+ throw errors[0];
43
+ if (errors.length > 1)
44
+ throw new AggregateError(errors, errors.map((error) => error.message).join("\n"));
45
+ }
46
+ function onMapError(event) {
47
+ if (capturedErrors) {
48
+ capturedErrors.push(toError(event));
49
+ return;
50
+ }
51
+ const isOwnSource = ownedSourceId !== void 0 && event.sourceId === ownedSourceId;
52
+ const isOwnLayer = event.layer?.id !== void 0 && ownedLayerIds.includes(event.layer.id);
53
+ if (isOwnSource || isOwnLayer)
54
+ reportMapLibreResourceError(toError(event), (failure) => emit("error", failure));
55
+ }
56
+ function layerStructure(layer) {
57
+ const structure = { ...layer };
58
+ delete structure.paint;
59
+ delete structure.layout;
60
+ delete structure.filter;
61
+ return structure;
62
+ }
63
+ function structureSignature() {
64
+ return JSON.stringify([
65
+ props.sourceId,
66
+ props.sourceOptions ?? null,
67
+ props.beforeId ?? null,
68
+ props.layers.map(layerStructure)
69
+ ]);
70
+ }
71
+ function readLayerStyles() {
72
+ return props.layers.map((layer) => {
73
+ const source = layer;
74
+ return {
75
+ paint: source.paint ?? {},
76
+ layout: source.layout ?? {},
77
+ filter: source.filter
78
+ };
79
+ });
80
+ }
81
+ function styleSignature() {
82
+ return JSON.stringify(readLayerStyles());
83
+ }
84
+ function detachLayerStyles(signature) {
85
+ return JSON.parse(signature);
86
+ }
87
+ function applyCursor(map, cursor) {
88
+ const canvas = map.getCanvas();
89
+ if (!canvas)
90
+ return;
91
+ if (cursor === void 0) {
92
+ if (restoreCursor !== void 0)
93
+ canvas.style.cursor = restoreCursor;
94
+ restoreCursor = void 0;
95
+ return;
96
+ }
97
+ restoreCursor ??= canvas.style.cursor;
98
+ canvas.style.cursor = cursor;
99
+ }
100
+ function unbindLayerEvents(map) {
101
+ for (const subscription of layerSubscriptions)
102
+ subscription.unsubscribe();
103
+ layerSubscriptions = [];
104
+ if (isPointerOverLayer)
105
+ pendingHoverKey = hoveredLayerKey;
106
+ isPointerOverLayer = false;
107
+ if (restoreCursor !== void 0)
108
+ applyCursor(map, void 0);
109
+ }
110
+ function bindLayerEvents(map, carryHover) {
111
+ unbindLayerEvents(map);
112
+ const carriedHoverKey = pendingHoverKey;
113
+ pendingHoverKey = "";
114
+ if (!ownedLayerIds.length)
115
+ return;
116
+ const layerIds = [...ownedLayerIds];
117
+ const layerKey = layerIds.join("\n");
118
+ layerSubscriptions = [
119
+ map.on("click", layerIds, (event) => emit("click", event)),
120
+ // The emit must stay synchronous, so `event.preventDefault()` still stops
121
+ // MapLibre's double-click zoom.
122
+ map.on("dblclick", layerIds, (event) => emit("dblclick", event)),
123
+ map.on("mousemove", layerIds, (event) => emit("mousemove", event)),
124
+ map.on("mouseenter", layerIds, (event) => {
125
+ isPointerOverLayer = true;
126
+ hoveredLayerKey = layerKey;
127
+ applyCursor(map, props.cursor || void 0);
128
+ emit("mouseenter", event);
129
+ }),
130
+ map.on("mouseleave", layerIds, (event) => {
131
+ isPointerOverLayer = false;
132
+ applyCursor(map, void 0);
133
+ emit("mouseleave", event);
134
+ })
135
+ ];
136
+ if (carryHover && carriedHoverKey === layerKey) {
137
+ isPointerOverLayer = true;
138
+ applyCursor(map, props.cursor || void 0);
139
+ }
140
+ }
17
141
  function removeOwnedResources(map) {
142
+ unbindLayerEvents(map);
18
143
  for (const layerId of [...ownedLayerIds].reverse()) {
19
144
  if (map.getLayer(layerId))
20
145
  map.removeLayer(layerId);
@@ -23,47 +148,127 @@ function removeOwnedResources(map) {
23
148
  if (ownedSourceId && map.getSource(ownedSourceId))
24
149
  map.removeSource(ownedSourceId);
25
150
  ownedSourceId = void 0;
151
+ appliedStructure = void 0;
152
+ appliedStyleSignature = void 0;
153
+ appliedStyles = [];
26
154
  }
27
- function syncResources(map) {
28
- if (!map.isStyleLoaded())
155
+ function syncResources(map, carryHover = false) {
156
+ if (!isStyleMutable && map.isStyleLoaded() !== true) {
157
+ appliedStructure = void 0;
158
+ appliedStyleSignature = void 0;
159
+ hasPendingSync = true;
29
160
  return;
161
+ }
162
+ hasPendingSync = false;
30
163
  removeOwnedResources(map);
31
164
  const sourceId = props.sourceId;
32
165
  try {
33
- map.addSource(sourceId, {
166
+ applyStyleChange(() => map.addSource(sourceId, {
34
167
  ...toRaw(props.sourceOptions),
35
168
  type: "geojson",
36
169
  data: toRaw(props.data)
37
- });
170
+ }));
38
171
  ownedSourceId = sourceId;
39
172
  for (const layer of props.layers) {
40
173
  const nextLayer = {
41
174
  ...toRaw(layer),
42
175
  source: layer.source || sourceId
43
176
  };
44
- map.addLayer(nextLayer, props.beforeId);
177
+ applyStyleChange(() => map.addLayer(nextLayer, props.beforeId));
178
+ if (!map.getLayer(nextLayer.id))
179
+ throw new Error(`MapLibre did not add the layer "${nextLayer.id}".`);
45
180
  ownedLayerIds.push(nextLayer.id);
46
181
  }
182
+ appliedStructure = structureSignature();
183
+ appliedStyleSignature = styleSignature();
184
+ appliedStyles = detachLayerStyles(appliedStyleSignature);
185
+ bindLayerEvents(map, carryHover);
47
186
  } catch (error) {
48
187
  removeOwnedResources(map);
49
188
  throw error;
50
189
  }
190
+ emit("sourceready", { map, sourceId });
191
+ }
192
+ function applyStyleBlock(before, after, set) {
193
+ for (const name of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
194
+ if (JSON.stringify(before[name]) !== JSON.stringify(after[name]))
195
+ set(name, after[name]);
196
+ }
197
+ }
198
+ function updateLayerStyles(map) {
199
+ const signature = styleSignature();
200
+ const nextStyles = detachLayerStyles(signature);
201
+ nextStyles.forEach((next, index) => {
202
+ const before = appliedStyles[index];
203
+ const layerId = ownedLayerIds[index];
204
+ if (!before || !layerId || !map.getLayer(layerId))
205
+ return;
206
+ applyStyleBlock(before.paint, next.paint, (name, value) => {
207
+ applyStyleChange(() => map.setPaintProperty(layerId, name, value));
208
+ });
209
+ applyStyleBlock(before.layout, next.layout, (name, value) => {
210
+ applyStyleChange(() => map.setLayoutProperty(layerId, name, value));
211
+ });
212
+ if (JSON.stringify(before.filter) !== JSON.stringify(next.filter))
213
+ applyStyleChange(() => map.setFilter(layerId, next.filter));
214
+ });
215
+ if (isPointerOverLayer) {
216
+ isPointerOverLayer = false;
217
+ applyCursor(map, void 0);
218
+ }
219
+ appliedStyles = nextStyles;
220
+ appliedStyleSignature = signature;
221
+ }
222
+ function trySyncResources(map, carryHover = false) {
223
+ try {
224
+ syncResources(map, carryHover);
225
+ } catch (error) {
226
+ reportMapLibreResourceError(error, (failure) => emit("error", failure));
227
+ }
228
+ }
229
+ function tryUpdateLayerStyles(map) {
230
+ try {
231
+ updateLayerStyles(map);
232
+ } catch (error) {
233
+ reportMapLibreResourceError(error, (failure) => emit("error", failure));
234
+ }
51
235
  }
52
236
  const geoJson = useMapLibreResource({
53
237
  create({ map }) {
54
- const onStyleLoad = () => syncResources(map);
238
+ isStyleMutable = map.isStyleLoaded() === true;
239
+ const onStyleLoad = () => {
240
+ isStyleMutable = true;
241
+ trySyncResources(map, true);
242
+ };
55
243
  const onLoad = () => {
244
+ isStyleMutable = true;
56
245
  if (!ownedSourceId)
57
- syncResources(map);
246
+ trySyncResources(map);
247
+ };
248
+ const onStyleDataLoading = () => {
249
+ isStyleMutable = false;
250
+ hasPendingSync = true;
251
+ };
252
+ const onIdle = () => {
253
+ isStyleMutable = true;
254
+ if (hasPendingSync)
255
+ trySyncResources(map);
58
256
  };
59
257
  map.on("style.load", onStyleLoad);
60
258
  map.on("load", onLoad);
61
- syncResources(map);
62
- return { map, onLoad, onStyleLoad };
259
+ map.on("styledataloading", onStyleDataLoading);
260
+ map.on("idle", onIdle);
261
+ map.on("error", onMapError);
262
+ trySyncResources(map);
263
+ return { map, onLoad, onStyleLoad, onStyleDataLoading, onIdle, onError: onMapError };
63
264
  },
265
+ onError: (error) => emit("error", error),
64
266
  cleanup(resource) {
65
267
  resource.map.off("load", resource.onLoad);
66
268
  resource.map.off("style.load", resource.onStyleLoad);
269
+ resource.map.off("styledataloading", resource.onStyleDataLoading);
270
+ resource.map.off("idle", resource.onIdle);
271
+ resource.map.off("error", resource.onError);
67
272
  removeOwnedResources(resource.map);
68
273
  }
69
274
  });
@@ -72,10 +277,23 @@ watch(() => props.data, (data) => {
72
277
  if (source?.type === "geojson")
73
278
  source.setData(toRaw(data));
74
279
  }, { deep: 2 });
75
- watch(() => [props.sourceId, props.layers, props.sourceOptions, props.beforeId], () => {
76
- if (geoJson.value)
77
- syncResources(geoJson.value.map);
78
- }, { deep: 3 });
280
+ watch(() => props.cursor, (cursor) => {
281
+ if (isPointerOverLayer && geoJson.value)
282
+ applyCursor(geoJson.value.map, cursor || void 0);
283
+ });
284
+ watch(structureSignature, (structure) => {
285
+ if (geoJson.value && structure !== appliedStructure)
286
+ trySyncResources(geoJson.value.map);
287
+ });
288
+ watch(styleSignature, (signature) => {
289
+ const map = geoJson.value?.map;
290
+ if (!map || signature === appliedStyleSignature)
291
+ return;
292
+ if (structureSignature() === appliedStructure)
293
+ tryUpdateLayerStyles(map);
294
+ else
295
+ trySyncResources(map);
296
+ });
79
297
  defineExpose({ geoJson });
80
298
  </script>
81
299
 
@@ -1,39 +1,30 @@
1
- import type { GeoJSON } from 'geojson';
2
1
  import type * as MapLibreGl from 'maplibre-gl';
3
- import type * as MapLibre from 'maplibre-gl';
4
- export type ScriptMapLibreGeoJsonLayer = Omit<MapLibre.LayerSpecification, 'source'> & {
5
- /** Override the component's source ID for this layer. */
6
- source?: string;
7
- };
8
- export interface ScriptMapLibreGeoJsonResource {
9
- map: MapLibre.Map;
10
- onLoad: () => void;
11
- onStyleLoad: () => void;
12
- }
2
+ import type { ScriptMapLibreGeoJsonProps, ScriptMapLibreGeoJsonResource } from './types.js';
3
+ export type { ScriptMapLibreGeoJsonEmits, ScriptMapLibreGeoJsonLayer, ScriptMapLibreGeoJsonProps, ScriptMapLibreGeoJsonResource, } from './types.js';
13
4
  declare const _default: typeof __VLS_export;
14
5
  export default _default;
15
- declare const __VLS_export: import("vue").DefineComponent<{
16
- /** MapLibre source ID. Changing it rebuilds the owned source and layers. */
17
- sourceId: string;
18
- /** Inline GeoJSON data or a URL returning GeoJSON. */
19
- data: GeoJSON | string;
20
- /** GeoJSON source options. `type` and `data` are supplied by the component. */
21
- sourceOptions?: Omit<MapLibreGl.GeoJSONSourceSpecification, "type" | "data">;
22
- /** Style layers backed by this source. */
23
- layers: ScriptMapLibreGeoJsonLayer[];
24
- /** Existing layer ID before which the layers are inserted. */
25
- beforeId?: string;
26
- }, {
6
+ declare const __VLS_export: import("vue").DefineComponent<ScriptMapLibreGeoJsonProps, {
27
7
  geoJson: import("vue").ShallowRef<ScriptMapLibreGeoJsonResource | undefined>;
28
- }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
29
- /** MapLibre source ID. Changing it rebuilds the owned source and layers. */
30
- sourceId: string;
31
- /** Inline GeoJSON data or a URL returning GeoJSON. */
32
- data: GeoJSON | string;
33
- /** GeoJSON source options. `type` and `data` are supplied by the component. */
34
- sourceOptions?: Omit<MapLibreGl.GeoJSONSourceSpecification, "type" | "data">;
35
- /** Style layers backed by this source. */
36
- layers: ScriptMapLibreGeoJsonLayer[];
37
- /** Existing layer ID before which the layers are inserted. */
38
- beforeId?: string;
39
- }> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
9
+ error: (error: Error) => any;
10
+ click: (event: MapLibreGl.MapLayerMouseEvent) => any;
11
+ dblclick: (event: MapLibreGl.MapLayerMouseEvent) => any;
12
+ mouseenter: (event: MapLibreGl.MapLayerMouseEvent) => any;
13
+ mouseleave: (event: MapLibreGl.MapLayerMouseEvent) => any;
14
+ mousemove: (event: MapLibreGl.MapLayerMouseEvent) => any;
15
+ sourceready: (payload: {
16
+ map: MapLibreGl.Map;
17
+ sourceId: string;
18
+ }) => any;
19
+ }, string, import("vue").PublicProps, Readonly<ScriptMapLibreGeoJsonProps> & Readonly<{
20
+ onError?: ((error: Error) => any) | undefined;
21
+ onClick?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
22
+ onDblclick?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
23
+ onMouseenter?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
24
+ onMouseleave?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
25
+ onMousemove?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
26
+ onSourceready?: ((payload: {
27
+ map: MapLibreGl.Map;
28
+ sourceId: string;
29
+ }) => any) | undefined;
30
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -0,0 +1,25 @@
1
+ import type * as MapLibre from 'maplibre-gl';
2
+ import type { ScriptMapLibreGeolocateControlProps } from './types.js';
3
+ declare const __VLS_export: import("vue").DefineComponent<ScriptMapLibreGeolocateControlProps, {
4
+ control: import("vue").ShallowRef<MapLibre.GeolocateControl | undefined>;
5
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ error: (event: MapLibre.GeolocateErrorEvent) => any;
7
+ geolocate: (event: MapLibre.GeolocatePositionEvent) => any;
8
+ outofmaxbounds: (event: MapLibre.GeolocatePositionEvent) => any;
9
+ trackuserlocationstart: (event: MapLibre.GeolocateEvent) => any;
10
+ trackuserlocationend: (event: MapLibre.GeolocateEvent) => any;
11
+ userlocationfocus: (event: MapLibre.GeolocateEvent) => any;
12
+ userlocationlostfocus: (event: MapLibre.GeolocateEvent) => any;
13
+ unavailable: (reason: "unsupported" | "permission-denied") => any;
14
+ }, string, import("vue").PublicProps, Readonly<ScriptMapLibreGeolocateControlProps> & Readonly<{
15
+ onError?: ((event: MapLibre.GeolocateErrorEvent) => any) | undefined;
16
+ onGeolocate?: ((event: MapLibre.GeolocatePositionEvent) => any) | undefined;
17
+ onOutofmaxbounds?: ((event: MapLibre.GeolocatePositionEvent) => any) | undefined;
18
+ onTrackuserlocationstart?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
19
+ onTrackuserlocationend?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
20
+ onUserlocationfocus?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
21
+ onUserlocationlostfocus?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
22
+ onUnavailable?: ((reason: "unsupported" | "permission-denied") => any) | undefined;
23
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
24
+ declare const _default: typeof __VLS_export;
25
+ export default _default;
@@ -0,0 +1,49 @@
1
+ <script setup>
2
+ import { useMapLibreResource } from "./useMapLibreResource";
3
+ defineOptions({ render: () => null });
4
+ const props = defineProps({
5
+ position: { type: null, required: false },
6
+ options: { type: null, required: false }
7
+ });
8
+ const emit = defineEmits(["geolocate", "error", "outofmaxbounds", "trackuserlocationstart", "trackuserlocationend", "userlocationfocus", "userlocationlostfocus", "unavailable"]);
9
+ const listeners = {
10
+ geolocate: (event) => emit("geolocate", event),
11
+ error: (event) => emit("error", event),
12
+ outofmaxbounds: (event) => emit("outofmaxbounds", event),
13
+ trackuserlocationstart: (event) => emit("trackuserlocationstart", event),
14
+ trackuserlocationend: (event) => emit("trackuserlocationend", event),
15
+ userlocationfocus: (event) => emit("userlocationfocus", event),
16
+ userlocationlostfocus: (event) => emit("userlocationlostfocus", event)
17
+ };
18
+ const eventNames = Object.keys(listeners);
19
+ async function readAvailability() {
20
+ if (!("geolocation" in navigator))
21
+ return "unsupported";
22
+ if (!navigator.permissions)
23
+ return "available";
24
+ const status = await navigator.permissions.query({ name: "geolocation" }).catch(() => {
25
+ return void 0;
26
+ });
27
+ return status?.state === "denied" ? "permission-denied" : "available";
28
+ }
29
+ const control = useMapLibreResource({
30
+ create({ maplibre, map }) {
31
+ const instance = new maplibre.GeolocateControl(props.options ?? {});
32
+ for (const name of eventNames)
33
+ instance.on(name, listeners[name]);
34
+ map.addControl(instance, props.position);
35
+ readAvailability().then((availability) => {
36
+ if (availability !== "available" && control.value === instance)
37
+ emit("unavailable", availability);
38
+ });
39
+ return instance;
40
+ },
41
+ cleanup(instance, { map }) {
42
+ for (const name of eventNames)
43
+ instance.off(name, listeners[name]);
44
+ if (map.hasControl(instance))
45
+ map.removeControl(instance);
46
+ }
47
+ });
48
+ defineExpose({ control });
49
+ </script>
@@ -0,0 +1,25 @@
1
+ import type * as MapLibre from 'maplibre-gl';
2
+ import type { ScriptMapLibreGeolocateControlProps } from './types.js';
3
+ declare const __VLS_export: import("vue").DefineComponent<ScriptMapLibreGeolocateControlProps, {
4
+ control: import("vue").ShallowRef<MapLibre.GeolocateControl | undefined>;
5
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ error: (event: MapLibre.GeolocateErrorEvent) => any;
7
+ geolocate: (event: MapLibre.GeolocatePositionEvent) => any;
8
+ outofmaxbounds: (event: MapLibre.GeolocatePositionEvent) => any;
9
+ trackuserlocationstart: (event: MapLibre.GeolocateEvent) => any;
10
+ trackuserlocationend: (event: MapLibre.GeolocateEvent) => any;
11
+ userlocationfocus: (event: MapLibre.GeolocateEvent) => any;
12
+ userlocationlostfocus: (event: MapLibre.GeolocateEvent) => any;
13
+ unavailable: (reason: "unsupported" | "permission-denied") => any;
14
+ }, string, import("vue").PublicProps, Readonly<ScriptMapLibreGeolocateControlProps> & Readonly<{
15
+ onError?: ((event: MapLibre.GeolocateErrorEvent) => any) | undefined;
16
+ onGeolocate?: ((event: MapLibre.GeolocatePositionEvent) => any) | undefined;
17
+ onOutofmaxbounds?: ((event: MapLibre.GeolocatePositionEvent) => any) | undefined;
18
+ onTrackuserlocationstart?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
19
+ onTrackuserlocationend?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
20
+ onUserlocationfocus?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
21
+ onUserlocationlostfocus?: ((event: MapLibre.GeolocateEvent) => any) | undefined;
22
+ onUnavailable?: ((reason: "unsupported" | "permission-denied") => any) | undefined;
23
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
24
+ declare const _default: typeof __VLS_export;
25
+ export default _default;
@@ -1,119 +1,55 @@
1
1
  import type * as MapLibre from 'maplibre-gl';
2
- import type { HTMLAttributes, ReservedProps, ShallowRef } from 'vue';
3
- import type { ElementScriptTrigger } from '#nuxt-scripts/types';
2
+ import type { ScriptMapLibreMapExpose, ScriptMapLibreMapProps, ScriptMapLibreMapSlots } from './types.js';
3
+ export type { ScriptMapLibreMapEmits, ScriptMapLibreMapExpose, ScriptMapLibreMapProps, ScriptMapLibreMapSlots, } from './types.js';
4
4
  export { MAPLIBRE_MAP_INJECTION_KEY } from './useMapLibreResource.js';
5
- export interface ScriptMapLibreMapProps {
6
- /**
7
- * Defines when the MapLibre script loads.
8
- * @default 'visible'
9
- */
10
- trigger?: ElementScriptTrigger;
11
- /** MapLibre style URL or inline style specification. */
12
- mapStyle: string | MapLibre.StyleSpecification;
13
- /** Initial and reactively controlled map center. */
14
- center: MapLibre.LngLatLike;
15
- /** Initial and reactively controlled zoom level. @default 12 */
16
- zoom?: number;
17
- /** Initial and reactively controlled bearing in degrees. @default 0 */
18
- bearing?: number;
19
- /** Initial and reactively controlled pitch in degrees. @default 0 */
20
- pitch?: number;
21
- /** Options passed to `new maplibregl.Map()`. Dedicated props take precedence. */
22
- options?: Omit<MapLibre.MapOptions, 'container'>;
23
- /** Inject MapLibre's stylesheet when the script begins loading. @default true */
24
- injectStyles?: boolean;
25
- /** Custom MapLibre stylesheet URL. */
26
- stylesheetUrl?: string;
27
- /** Worker URL passed to `maplibregl.setWorkerUrl()`. */
28
- workerUrl?: string;
29
- /** Width reserved before the map loads. @default 640 */
30
- width?: number | string;
31
- /** Height reserved before the map loads. @default 400 */
32
- height?: number | string;
33
- /** Accessible name for an interactive map. @default 'Interactive map' */
34
- ariaLabel?: string;
35
- /** Disable map input and remove it from the accessibility tree when decorative. @default true */
36
- interactive?: boolean;
37
- /** Attributes applied to the outer layout container. */
38
- rootAttrs?: HTMLAttributes & ReservedProps & Record<string, unknown>;
39
- }
40
- export interface ScriptMapLibreMapExpose {
41
- maplibre: ShallowRef<typeof MapLibre | undefined>;
42
- map: ShallowRef<MapLibre.Map | undefined>;
43
- load: () => Promise<unknown> | unknown;
44
- }
45
- export interface ScriptMapLibreMapEmits {
46
- 'ready': [payload: ScriptMapLibreMapExpose];
47
- 'error': [error: Error];
48
- 'click': [event: MapLibre.MapEventType['click']];
49
- 'move': [event: MapLibre.MapEventType['move']];
50
- 'moveend': [event: MapLibre.MapEventType['moveend']];
51
- 'zoom': [event: MapLibre.MapEventType['zoom']];
52
- 'zoomend': [event: MapLibre.MapEventType['zoomend']];
53
- 'rotate': [event: MapLibre.MapEventType['rotate']];
54
- 'rotateend': [event: MapLibre.MapEventType['rotateend']];
55
- 'pitch': [event: MapLibre.MapEventType['pitch']];
56
- 'pitchend': [event: MapLibre.MapEventType['pitchend']];
57
- 'update:center': [center: MapLibre.LngLat];
58
- 'update:zoom': [zoom: number];
59
- 'update:bearing': [bearing: number];
60
- 'update:pitch': [pitch: number];
61
- }
62
- export interface ScriptMapLibreMapSlots {
63
- default?: () => any;
64
- loading?: () => any;
65
- awaitingLoad?: () => any;
66
- error?: (props: {
67
- error: Error;
68
- }) => any;
69
- placeholder?: () => any;
70
- /** Text or links that expose the canvas map's essential information to assistive technology. */
71
- description?: () => any;
72
- }
73
5
  declare const _default: typeof __VLS_export;
74
6
  export default _default;
75
7
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<ScriptMapLibreMapProps, ScriptMapLibreMapExpose, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
76
8
  error: (error: Error) => any;
77
9
  ready: (payload: ScriptMapLibreMapExpose) => any;
10
+ load: (event: MapLibre.MapLibreEvent<unknown>) => any;
78
11
  click: (event: MapLibre.MapMouseEvent) => any;
79
- move: (event: MapLibre.MapMovementEvent) => any;
80
12
  zoom: (event: MapLibre.MapMovementEvent) => any;
81
- rotate: (event: MapLibre.MapMovementEvent) => any;
82
- zoomend: (event: MapLibre.MapMovementEvent) => any;
13
+ pitch: (event: MapLibre.MapMovementEvent) => any;
14
+ move: (event: MapLibre.MapMovementEvent) => any;
83
15
  moveend: (event: MapLibre.MapMovementEvent) => any;
84
- "update:center": (center: MapLibre.LngLat) => any;
85
- "update:zoom": (zoom: number) => any;
16
+ zoomend: (event: MapLibre.MapMovementEvent) => any;
17
+ rotate: (event: MapLibre.MapMovementEvent) => any;
86
18
  rotateend: (event: MapLibre.MapMovementEvent) => any;
87
- pitch: (event: MapLibre.MapMovementEvent) => any;
88
19
  pitchend: (event: MapLibre.MapMovementEvent) => any;
20
+ "update:center": (center: MapLibre.LngLat) => any;
21
+ "update:zoom": (zoom: number) => any;
22
+ styleload: (event: MapLibre.MapStyleLoadEvent) => any;
89
23
  "update:bearing": (bearing: number) => any;
90
24
  "update:pitch": (pitch: number) => any;
91
25
  }, string, import("vue").PublicProps, Readonly<ScriptMapLibreMapProps> & Readonly<{
92
26
  onError?: ((error: Error) => any) | undefined;
93
27
  onReady?: ((payload: ScriptMapLibreMapExpose) => any) | undefined;
28
+ onLoad?: ((event: MapLibre.MapLibreEvent<unknown>) => any) | undefined;
94
29
  onClick?: ((event: MapLibre.MapMouseEvent) => any) | undefined;
95
- onMove?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
96
30
  onZoom?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
97
- onRotate?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
98
- onZoomend?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
31
+ onPitch?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
32
+ onMove?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
99
33
  onMoveend?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
100
- "onUpdate:center"?: ((center: MapLibre.LngLat) => any) | undefined;
101
- "onUpdate:zoom"?: ((zoom: number) => any) | undefined;
34
+ onZoomend?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
35
+ onRotate?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
102
36
  onRotateend?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
103
- onPitch?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
104
37
  onPitchend?: ((event: MapLibre.MapMovementEvent) => any) | undefined;
38
+ "onUpdate:center"?: ((center: MapLibre.LngLat) => any) | undefined;
39
+ "onUpdate:zoom"?: ((zoom: number) => any) | undefined;
40
+ onStyleload?: ((event: MapLibre.MapStyleLoadEvent) => any) | undefined;
105
41
  "onUpdate:bearing"?: ((bearing: number) => any) | undefined;
106
42
  "onUpdate:pitch"?: ((pitch: number) => any) | undefined;
107
43
  }>, {
108
- trigger: ElementScriptTrigger;
44
+ trigger: import("../../types.js").ElementScriptTrigger;
109
45
  injectStyles: boolean;
110
46
  width: number | string;
111
47
  height: number | string;
112
- zoom: number;
113
- ariaLabel: string;
114
48
  interactive: boolean;
115
- pitch: number;
49
+ zoom: number;
116
50
  bearing: number;
51
+ pitch: number;
52
+ ariaLabel: string;
117
53
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, ScriptMapLibreMapSlots>;
118
54
  type __VLS_WithSlots<T, S> = T & {
119
55
  new (): {