@nuxt/scripts 2.0.0-beta.5 → 2.0.0-beta.7

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 (86) hide show
  1. package/LICENSE.md +9 -0
  2. package/dist/devtools-client/200.html +1 -1
  3. package/dist/devtools-client/404.html +1 -1
  4. package/dist/devtools-client/_nuxt/BI6wdYky.js +1 -0
  5. package/dist/devtools-client/_nuxt/BQKaRBnk.js +179 -0
  6. package/dist/devtools-client/_nuxt/BckE5qrE.js +1 -0
  7. package/dist/devtools-client/_nuxt/CIwvJvFr.js +1 -0
  8. package/dist/devtools-client/_nuxt/Car86Ubo.js +3 -0
  9. package/dist/devtools-client/_nuxt/{Dat651Oh.js → ClT2ZYzs.js} +1 -1
  10. package/dist/devtools-client/_nuxt/Cs0md1ml.js +1 -0
  11. package/dist/devtools-client/_nuxt/D4iN56En.js +1 -0
  12. package/dist/devtools-client/_nuxt/DN3hUMR_.js +1 -0
  13. package/dist/devtools-client/_nuxt/DXEYGql4.js +1 -0
  14. package/dist/devtools-client/_nuxt/Divy0_cA.js +8 -0
  15. package/dist/devtools-client/_nuxt/QMsSHdby.js +6 -0
  16. package/dist/devtools-client/_nuxt/WbNXtEed.js +2 -0
  17. package/dist/devtools-client/_nuxt/builds/latest.json +1 -1
  18. package/dist/devtools-client/_nuxt/builds/meta/7f4505e1-4a64-4e0a-b3dd-aa394b0cd7f2.json +1 -0
  19. package/dist/devtools-client/_nuxt/entry.-RqqMwHr.css +2 -0
  20. package/dist/devtools-client/_nuxt/error-404.BJ1JSMYb.css +1 -0
  21. package/dist/devtools-client/_nuxt/error-500.BBf0uW5X.css +1 -0
  22. package/dist/devtools-client/_nuxt/{pages.aU4WirOM.css → pages.BTJrCFzE.css} +1 -1
  23. package/dist/devtools-client/docs/index.html +1 -1
  24. package/dist/devtools-client/first-party/index.html +1 -1
  25. package/dist/devtools-client/index.html +1 -1
  26. package/dist/devtools-client/registry/index.html +1 -1
  27. package/dist/module.d.mts +1 -0
  28. package/dist/module.d.ts +1 -0
  29. package/dist/module.json +1 -1
  30. package/dist/module.mjs +4 -1
  31. package/dist/registry.mjs +24 -1
  32. package/dist/runtime/components/Leaflet/ScriptLeafletMap.d.vue.ts +5 -5
  33. package/dist/runtime/components/Leaflet/ScriptLeafletMap.vue.d.ts +5 -5
  34. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.d.vue.ts +14 -35
  35. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.vue +194 -12
  36. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.vue.d.ts +14 -35
  37. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.d.vue.ts +22 -86
  38. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.vue +16 -4
  39. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.vue.d.ts +22 -86
  40. package/dist/runtime/components/MapLibre/ScriptMapLibreMarker.d.vue.ts +9 -18
  41. package/dist/runtime/components/MapLibre/ScriptMapLibreMarker.vue.d.ts +9 -18
  42. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.d.vue.ts +3 -8
  43. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.vue.d.ts +3 -8
  44. package/dist/runtime/components/MapLibre/ScriptMapLibrePopup.d.vue.ts +7 -14
  45. package/dist/runtime/components/MapLibre/ScriptMapLibrePopup.vue.d.ts +7 -14
  46. package/dist/runtime/components/MapLibre/types.d.ts +186 -0
  47. package/dist/runtime/components/MapLibre/types.js +0 -0
  48. package/dist/runtime/components/MapLibre/useMapLibreResource.d.ts +8 -1
  49. package/dist/runtime/components/MapLibre/useMapLibreResource.js +9 -2
  50. package/dist/runtime/components/ScriptCarbonAds.vue +3 -1
  51. package/dist/runtime/components/ScriptGoogleAdsense.d.vue.ts +1 -1
  52. package/dist/runtime/components/ScriptGoogleAdsense.vue.d.ts +1 -1
  53. package/dist/runtime/registry/pulse-analytics.d.ts +32 -0
  54. package/dist/runtime/registry/pulse-analytics.js +80 -0
  55. package/dist/runtime/registry/schemas.d.ts +42 -0
  56. package/dist/runtime/registry/schemas.js +42 -0
  57. package/dist/runtime/registry/tawk-to.d.ts +126 -0
  58. package/dist/runtime/registry/tawk-to.js +147 -0
  59. package/dist/runtime/server/proxy-handler.d.ts +0 -4
  60. package/dist/runtime/server/proxy-handler.js +109 -38
  61. package/dist/runtime/server/utils/network-dispatcher.platform.d.ts +2 -2
  62. package/dist/runtime/server/utils/network-dispatcher.platform.js +4 -1
  63. package/dist/runtime/types.d.ts +6 -1
  64. package/dist/stats.mjs +81 -0
  65. package/dist/types-source.mjs +159 -6
  66. package/dist/types.d.mts +2 -0
  67. package/package.json +23 -23
  68. package/dist/devtools-client/_nuxt/2p1_IuX2.js +0 -1
  69. package/dist/devtools-client/_nuxt/9elIQxwW.js +0 -1
  70. package/dist/devtools-client/_nuxt/B-kTnbRv.js +0 -1
  71. package/dist/devtools-client/_nuxt/BDNMzG2s.js +0 -1
  72. package/dist/devtools-client/_nuxt/BNPn63Jz.js +0 -1
  73. package/dist/devtools-client/_nuxt/BuTlAAeI.js +0 -152
  74. package/dist/devtools-client/_nuxt/C41E8Pp1.js +0 -8
  75. package/dist/devtools-client/_nuxt/CDDBpkXG.js +0 -3
  76. package/dist/devtools-client/_nuxt/Cbmw_5H5.js +0 -1
  77. package/dist/devtools-client/_nuxt/DAsiyhPm.js +0 -6
  78. package/dist/devtools-client/_nuxt/DabLKy7M.js +0 -1
  79. package/dist/devtools-client/_nuxt/DiZU_C4m.js +0 -1
  80. package/dist/devtools-client/_nuxt/KsX6Az5B.js +0 -1
  81. package/dist/devtools-client/_nuxt/LFNkKKtz.js +0 -28
  82. package/dist/devtools-client/_nuxt/UmWNrBO5.js +0 -2
  83. package/dist/devtools-client/_nuxt/builds/meta/778de0a6-ec82-430f-966c-9a96d75eb772.json +0 -1
  84. package/dist/devtools-client/_nuxt/entry.CYUdJFoE.css +0 -2
  85. package/dist/devtools-client/_nuxt/error-404.DnwL1N6v.css +0 -1
  86. package/dist/devtools-client/_nuxt/error-500.DEbXRLdm.css +0 -1
@@ -4,17 +4,111 @@
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", "mouseenter", "mouseleave"]);
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
+ function layerStructure(layer) {
30
+ const structure = { ...layer };
31
+ delete structure.paint;
32
+ delete structure.layout;
33
+ delete structure.filter;
34
+ return structure;
35
+ }
36
+ function structureSignature() {
37
+ return JSON.stringify([
38
+ props.sourceId,
39
+ props.sourceOptions ?? null,
40
+ props.beforeId ?? null,
41
+ props.layers.map(layerStructure)
42
+ ]);
43
+ }
44
+ function readLayerStyles() {
45
+ return props.layers.map((layer) => {
46
+ const source = layer;
47
+ return {
48
+ paint: source.paint ?? {},
49
+ layout: source.layout ?? {},
50
+ filter: source.filter
51
+ };
52
+ });
53
+ }
54
+ function styleSignature() {
55
+ return JSON.stringify(readLayerStyles());
56
+ }
57
+ function detachLayerStyles(signature) {
58
+ return JSON.parse(signature);
59
+ }
60
+ function applyCursor(map, cursor) {
61
+ const canvas = map.getCanvas();
62
+ if (!canvas)
63
+ return;
64
+ if (cursor === void 0) {
65
+ if (restoreCursor !== void 0)
66
+ canvas.style.cursor = restoreCursor;
67
+ restoreCursor = void 0;
68
+ return;
69
+ }
70
+ restoreCursor ??= canvas.style.cursor;
71
+ canvas.style.cursor = cursor;
72
+ }
73
+ function unbindLayerEvents(map) {
74
+ for (const subscription of layerSubscriptions)
75
+ subscription.unsubscribe();
76
+ layerSubscriptions = [];
77
+ if (isPointerOverLayer)
78
+ pendingHoverKey = hoveredLayerKey;
79
+ isPointerOverLayer = false;
80
+ if (restoreCursor !== void 0)
81
+ applyCursor(map, void 0);
82
+ }
83
+ function bindLayerEvents(map, carryHover) {
84
+ unbindLayerEvents(map);
85
+ const carriedHoverKey = pendingHoverKey;
86
+ pendingHoverKey = "";
87
+ if (!ownedLayerIds.length)
88
+ return;
89
+ const layerIds = [...ownedLayerIds];
90
+ const layerKey = layerIds.join("\n");
91
+ layerSubscriptions = [
92
+ map.on("click", layerIds, (event) => emit("click", event)),
93
+ map.on("mouseenter", layerIds, (event) => {
94
+ isPointerOverLayer = true;
95
+ hoveredLayerKey = layerKey;
96
+ applyCursor(map, props.cursor || void 0);
97
+ emit("mouseenter", event);
98
+ }),
99
+ map.on("mouseleave", layerIds, (event) => {
100
+ isPointerOverLayer = false;
101
+ applyCursor(map, void 0);
102
+ emit("mouseleave", event);
103
+ })
104
+ ];
105
+ if (carryHover && carriedHoverKey === layerKey) {
106
+ isPointerOverLayer = true;
107
+ applyCursor(map, props.cursor || void 0);
108
+ }
109
+ }
17
110
  function removeOwnedResources(map) {
111
+ unbindLayerEvents(map);
18
112
  for (const layerId of [...ownedLayerIds].reverse()) {
19
113
  if (map.getLayer(layerId))
20
114
  map.removeLayer(layerId);
@@ -23,10 +117,18 @@ function removeOwnedResources(map) {
23
117
  if (ownedSourceId && map.getSource(ownedSourceId))
24
118
  map.removeSource(ownedSourceId);
25
119
  ownedSourceId = void 0;
120
+ appliedStructure = void 0;
121
+ appliedStyleSignature = void 0;
122
+ appliedStyles = [];
26
123
  }
27
- function syncResources(map) {
28
- if (!map.isStyleLoaded())
124
+ function syncResources(map, carryHover = false) {
125
+ if (!isStyleMutable && map.isStyleLoaded() !== true) {
126
+ appliedStructure = void 0;
127
+ appliedStyleSignature = void 0;
128
+ hasPendingSync = true;
29
129
  return;
130
+ }
131
+ hasPendingSync = false;
30
132
  removeOwnedResources(map);
31
133
  const sourceId = props.sourceId;
32
134
  try {
@@ -44,26 +146,93 @@ function syncResources(map) {
44
146
  map.addLayer(nextLayer, props.beforeId);
45
147
  ownedLayerIds.push(nextLayer.id);
46
148
  }
149
+ appliedStructure = structureSignature();
150
+ appliedStyleSignature = styleSignature();
151
+ appliedStyles = detachLayerStyles(appliedStyleSignature);
152
+ bindLayerEvents(map, carryHover);
47
153
  } catch (error) {
48
154
  removeOwnedResources(map);
49
155
  throw error;
50
156
  }
51
157
  }
158
+ function applyStyleBlock(before, after, set) {
159
+ for (const name of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
160
+ if (JSON.stringify(before[name]) !== JSON.stringify(after[name]))
161
+ set(name, after[name]);
162
+ }
163
+ }
164
+ function updateLayerStyles(map) {
165
+ const signature = styleSignature();
166
+ const nextStyles = detachLayerStyles(signature);
167
+ nextStyles.forEach((next, index) => {
168
+ const before = appliedStyles[index];
169
+ const layerId = ownedLayerIds[index];
170
+ if (!before || !layerId || !map.getLayer(layerId))
171
+ return;
172
+ applyStyleBlock(before.paint, next.paint, (name, value) => {
173
+ map.setPaintProperty(layerId, name, value);
174
+ });
175
+ applyStyleBlock(before.layout, next.layout, (name, value) => {
176
+ map.setLayoutProperty(layerId, name, value);
177
+ });
178
+ if (JSON.stringify(before.filter) !== JSON.stringify(next.filter))
179
+ map.setFilter(layerId, next.filter);
180
+ });
181
+ if (isPointerOverLayer) {
182
+ isPointerOverLayer = false;
183
+ applyCursor(map, void 0);
184
+ }
185
+ appliedStyles = nextStyles;
186
+ appliedStyleSignature = signature;
187
+ }
188
+ function trySyncResources(map, carryHover = false) {
189
+ try {
190
+ syncResources(map, carryHover);
191
+ } catch (error) {
192
+ reportMapLibreResourceError(error, (failure) => emit("error", failure));
193
+ }
194
+ }
195
+ function tryUpdateLayerStyles(map) {
196
+ try {
197
+ updateLayerStyles(map);
198
+ } catch (error) {
199
+ reportMapLibreResourceError(error, (failure) => emit("error", failure));
200
+ }
201
+ }
52
202
  const geoJson = useMapLibreResource({
53
203
  create({ map }) {
54
- const onStyleLoad = () => syncResources(map);
204
+ isStyleMutable = map.isStyleLoaded() === true;
205
+ const onStyleLoad = () => {
206
+ isStyleMutable = true;
207
+ trySyncResources(map, true);
208
+ };
55
209
  const onLoad = () => {
210
+ isStyleMutable = true;
56
211
  if (!ownedSourceId)
57
- syncResources(map);
212
+ trySyncResources(map);
213
+ };
214
+ const onStyleDataLoading = () => {
215
+ isStyleMutable = false;
216
+ hasPendingSync = true;
217
+ };
218
+ const onIdle = () => {
219
+ isStyleMutable = true;
220
+ if (hasPendingSync)
221
+ trySyncResources(map);
58
222
  };
59
223
  map.on("style.load", onStyleLoad);
60
224
  map.on("load", onLoad);
61
- syncResources(map);
62
- return { map, onLoad, onStyleLoad };
225
+ map.on("styledataloading", onStyleDataLoading);
226
+ map.on("idle", onIdle);
227
+ trySyncResources(map);
228
+ return { map, onLoad, onStyleLoad, onStyleDataLoading, onIdle };
63
229
  },
230
+ onError: (error) => emit("error", error),
64
231
  cleanup(resource) {
65
232
  resource.map.off("load", resource.onLoad);
66
233
  resource.map.off("style.load", resource.onStyleLoad);
234
+ resource.map.off("styledataloading", resource.onStyleDataLoading);
235
+ resource.map.off("idle", resource.onIdle);
67
236
  removeOwnedResources(resource.map);
68
237
  }
69
238
  });
@@ -72,10 +241,23 @@ watch(() => props.data, (data) => {
72
241
  if (source?.type === "geojson")
73
242
  source.setData(toRaw(data));
74
243
  }, { deep: 2 });
75
- watch(() => [props.sourceId, props.layers, props.sourceOptions, props.beforeId], () => {
76
- if (geoJson.value)
77
- syncResources(geoJson.value.map);
78
- }, { deep: 3 });
244
+ watch(() => props.cursor, (cursor) => {
245
+ if (isPointerOverLayer && geoJson.value)
246
+ applyCursor(geoJson.value.map, cursor || void 0);
247
+ });
248
+ watch(structureSignature, (structure) => {
249
+ if (geoJson.value && structure !== appliedStructure)
250
+ trySyncResources(geoJson.value.map);
251
+ });
252
+ watch(styleSignature, (signature) => {
253
+ const map = geoJson.value?.map;
254
+ if (!map || signature === appliedStyleSignature)
255
+ return;
256
+ if (structureSignature() === appliedStructure)
257
+ tryUpdateLayerStyles(map);
258
+ else
259
+ trySyncResources(map);
260
+ });
79
261
  defineExpose({ geoJson });
80
262
  </script>
81
263
 
@@ -1,39 +1,18 @@
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
+ mouseenter: (event: MapLibreGl.MapLayerMouseEvent) => any;
12
+ mouseleave: (event: MapLibreGl.MapLayerMouseEvent) => any;
13
+ }, string, import("vue").PublicProps, Readonly<ScriptMapLibreGeoJsonProps> & Readonly<{
14
+ onError?: ((error: Error) => any) | undefined;
15
+ onClick?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
16
+ onMouseenter?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
17
+ onMouseleave?: ((event: MapLibreGl.MapLayerMouseEvent) => any) | undefined;
18
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -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 (): {
@@ -25,7 +25,7 @@ const props = defineProps({
25
25
  interactive: { type: Boolean, required: false, default: true },
26
26
  rootAttrs: { type: Object, required: false }
27
27
  });
28
- const emit = defineEmits(["ready", "error", "click", "move", "moveend", "zoom", "zoomend", "rotate", "rotateend", "pitch", "pitchend", "update:center", "update:zoom", "update:bearing", "update:pitch"]);
28
+ const emit = defineEmits(["ready", "error", "load", "styleload", "click", "move", "moveend", "zoom", "zoomend", "rotate", "rotateend", "pitch", "pitchend", "update:center", "update:zoom", "update:bearing", "update:pitch"]);
29
29
  const slots = defineSlots();
30
30
  const rootEl = useTemplateRef("rootEl");
31
31
  const mapEl = useTemplateRef("mapEl");
@@ -48,13 +48,24 @@ onError((error) => {
48
48
  loadError.value = error ?? new Error("MapLibre failed to load");
49
49
  emit("error", loadError.value);
50
50
  });
51
- const exposed = { maplibre, map, load };
51
+ function fitBounds(bounds, options) {
52
+ map.value?.fitBounds(bounds, options);
53
+ }
54
+ function easeTo(options) {
55
+ map.value?.easeTo(options);
56
+ }
57
+ function flyTo(options) {
58
+ map.value?.flyTo(options);
59
+ }
60
+ const exposed = { maplibre, map, load, fitBounds, easeTo, flyTo };
52
61
  defineExpose(exposed);
53
62
  provide(MAPLIBRE_MAP_INJECTION_KEY, {
54
63
  maplibre,
55
64
  map
56
65
  });
57
66
  function bindMapEvents(instance) {
67
+ instance.on("load", (event) => emit("load", event));
68
+ instance.on("style.load", (event) => emit("styleload", event));
58
69
  instance.on("click", (event) => emit("click", event));
59
70
  instance.on("move", (event) => emit("move", event));
60
71
  instance.on("moveend", (event) => {
@@ -77,8 +88,9 @@ function bindMapEvents(instance) {
77
88
  emit("update:pitch", instance.getPitch());
78
89
  });
79
90
  instance.on("error", (event) => {
80
- loadError.value = event.error;
81
- emit("error", event.error);
91
+ const error = event.error instanceof Error ? event.error : new Error(event.error.message, { cause: event.error });
92
+ loadError.value = error;
93
+ emit("error", error);
82
94
  });
83
95
  }
84
96
  onMounted(() => {
@@ -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 (): {