@nuxt/scripts 0.11.4 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/client/200.html +9 -9
  2. package/dist/client/404.html +9 -9
  3. package/dist/client/_nuxt/{Bo1SWr6k.js → C347yIJI.js} +1 -1
  4. package/dist/client/_nuxt/DhL_UpCd.js +1 -0
  5. package/dist/client/_nuxt/Di440A2l.js +1 -0
  6. package/dist/client/_nuxt/V79VpDdr.js +21 -0
  7. package/dist/client/_nuxt/builds/latest.json +1 -1
  8. package/dist/client/_nuxt/builds/meta/3e09fd1b-e587-4ed5-a851-8fd373eda48a.json +1 -0
  9. package/dist/client/_nuxt/{entry.CJckMUzn.css → entry.B4DN0kwM.css} +1 -1
  10. package/dist/client/_nuxt/error-404.BtCtaqmq.css +1 -0
  11. package/dist/client/_nuxt/error-500.D9fi60uT.css +1 -0
  12. package/dist/client/index.html +9 -9
  13. package/dist/module.json +3 -3
  14. package/dist/registry.mjs +18 -0
  15. package/dist/runtime/components/ScriptAriaLoadingIndicator.vue.d.ts +2 -0
  16. package/dist/runtime/components/ScriptCarbonAds.vue +41 -57
  17. package/dist/runtime/components/ScriptCarbonAds.vue.d.ts +49 -0
  18. package/dist/runtime/components/ScriptCrisp.vue +43 -63
  19. package/dist/runtime/components/ScriptCrisp.vue.d.ts +65 -0
  20. package/dist/runtime/components/ScriptGoogleAdsense.vue +37 -60
  21. package/dist/runtime/components/ScriptGoogleAdsense.vue.d.ts +59 -0
  22. package/dist/runtime/components/ScriptGoogleMaps.vue +220 -365
  23. package/dist/runtime/components/ScriptGoogleMaps.vue.d.ts +215 -0
  24. package/dist/runtime/components/ScriptIntercom.vue +48 -67
  25. package/dist/runtime/components/ScriptIntercom.vue.d.ts +70 -0
  26. package/dist/runtime/components/ScriptLemonSqueezy.vue +26 -37
  27. package/dist/runtime/components/ScriptLemonSqueezy.vue.d.ts +41 -0
  28. package/dist/runtime/components/ScriptLoadingIndicator.vue +8 -13
  29. package/dist/runtime/components/ScriptLoadingIndicator.vue.d.ts +9 -0
  30. package/dist/runtime/components/ScriptStripePricingTable.vue +41 -53
  31. package/dist/runtime/components/ScriptStripePricingTable.vue.d.ts +56 -0
  32. package/dist/runtime/components/ScriptVimeoPlayer.vue +121 -218
  33. package/dist/runtime/components/ScriptVimeoPlayer.vue.d.ts +233 -0
  34. package/dist/runtime/components/ScriptYouTubePlayer.vue +105 -163
  35. package/dist/runtime/components/ScriptYouTubePlayer.vue.d.ts +133 -0
  36. package/dist/runtime/registry/clarity.d.ts +1 -1
  37. package/dist/runtime/registry/clarity.js +7 -1
  38. package/dist/runtime/registry/snapchat-pixel.js +1 -1
  39. package/dist/types.d.mts +2 -2
  40. package/package.json +39 -34
  41. package/dist/client/_nuxt/BojlM8av.js +0 -21
  42. package/dist/client/_nuxt/BwFnCI0m.js +0 -1
  43. package/dist/client/_nuxt/builds/meta/d0cfdf7f-f013-4561-b983-7ab31692811a.json +0 -1
  44. package/dist/client/_nuxt/error-404.BiTeRF3j.css +0 -1
  45. package/dist/client/_nuxt/error-500.Be1AE5oK.css +0 -1
  46. package/dist/client/_nuxt/yRslIvSb.js +0 -1
  47. package/dist/module.cjs +0 -5
  48. package/dist/module.d.ts +0 -60
  49. package/dist/registry.d.ts +0 -6
  50. package/dist/types.d.ts +0 -7
@@ -1,482 +1,337 @@
1
- <script lang="ts" setup>
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-nocheck
4
-
5
- /// <reference types="google.maps" />
6
- import { computed, onBeforeUnmount, onMounted, ref, watch, toRaw } from 'vue'
7
- import type { HTMLAttributes, ImgHTMLAttributes, Ref, ReservedProps } from 'vue'
8
- import { withQuery } from 'ufo'
9
- import type { QueryObject } from 'ufo'
10
- import { defu } from 'defu'
11
- import { hash } from 'ohash'
12
- import { useHead } from 'nuxt/app'
13
- import type { ElementScriptTrigger } from '../types'
14
- import { scriptRuntimeConfig } from '../utils'
15
- import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
16
- import { useScriptGoogleMaps } from '../registry/google-maps'
17
- import ScriptAriaLoadingIndicator from './ScriptAriaLoadingIndicator.vue'
18
-
19
- interface PlaceholderOptions {
20
- width?: string | number
21
- height?: string | number
22
- center?: string
23
- zoom?: number
24
- size?: string
25
- scale?: number
26
- format?: 'png' | 'jpg' | 'gif' | 'png8' | 'png32' | 'jpg-baseline'
27
- maptype?: 'roadmap' | 'satellite' | 'terrain' | 'hybrid'
28
- language?: string
29
- region?: string
30
- markers?: string
31
- path?: string
32
- visible?: string
33
- style?: string
34
- map_id?: string
35
- key?: string
36
- signature?: string
37
- }
38
-
39
- const props = withDefaults(defineProps<{
40
- /**
41
- * Defines the trigger event to load the script.
42
- */
43
- trigger?: ElementScriptTrigger
44
- /**
45
- * Is Google Maps being rendered above the fold?
46
- * This will load the placeholder image with higher priority.
47
- */
48
- aboveTheFold?: boolean
49
- /**
50
- * Defines the Google Maps API key. Must have access to the Static Maps API as well.
51
- */
52
- apiKey?: string
53
- /**
54
- * A latitude / longitude of where to focus the map.
55
- */
56
- center?: google.maps.LatLng | google.maps.LatLngLiteral | `${string},${string}`
57
- /**
58
- * Should a marker be displayed on the map where the centre is.
59
- */
60
- centerMarker?: boolean
61
- /**
62
- * Options for the map.
63
- */
64
- mapOptions?: google.maps.MapOptions
65
- /**
66
- * Defines the region of the map.
67
- */
68
- region?: string
69
- /**
70
- * Defines the language of the map
71
- */
72
- language?: string
73
- /**
74
- * Defines the version of google maps js API
75
- */
76
- version?: string
77
- /**
78
- * Defines the width of the map.
79
- */
80
- width?: number | string
81
- /**
82
- * Defines the height of the map
83
- */
84
- height?: number | string
85
- /**
86
- * Customize the placeholder image attributes.
87
- *
88
- * @see https://developers.google.com/maps/documentation/maps-static/start.
89
- */
90
- placeholderOptions?: PlaceholderOptions
91
- /**
92
- * Customize the placeholder image attributes.
93
- */
94
- placeholderAttrs?: ImgHTMLAttributes & ReservedProps & Record<string, unknown>
95
- /**
96
- * Customize the root element attributes.
97
- */
98
- rootAttrs?: HTMLAttributes & ReservedProps & Record<string, unknown>
99
- /**
100
- * Extra Markers to add to the map.
101
- */
102
- markers?: (`${string},${string}` | google.maps.marker.AdvancedMarkerElementOptions)[]
103
- }>(), {
104
- // @ts-expect-error untyped
105
- trigger: ['mouseenter', 'mouseover', 'mousedown'],
106
- width: 640,
107
- height: 400,
108
- })
109
-
110
- const emits = defineEmits<{
111
- // our emit
112
- ready: [e: typeof googleMaps]
113
- error: []
114
- }>()
115
-
116
- const apiKey = props.apiKey || scriptRuntimeConfig('googleMaps')?.apiKey
117
-
118
- const mapsApi = ref<typeof google.maps | undefined>()
119
-
1
+ <script setup>
2
+ import { computed, onBeforeUnmount, onMounted, ref, watch, toRaw } from "vue";
3
+ import { withQuery } from "ufo";
4
+ import { defu } from "defu";
5
+ import { hash } from "ohash";
6
+ import { useHead } from "nuxt/app";
7
+ import { scriptRuntimeConfig } from "../utils";
8
+ import { useScriptTriggerElement } from "../composables/useScriptTriggerElement";
9
+ import { useScriptGoogleMaps } from "../registry/google-maps";
10
+ import ScriptAriaLoadingIndicator from "./ScriptAriaLoadingIndicator.vue";
11
+ const props = defineProps({
12
+ trigger: { type: [String, Array, Boolean], required: false, default: ["mouseenter", "mouseover", "mousedown"] },
13
+ aboveTheFold: { type: Boolean, required: false },
14
+ apiKey: { type: String, required: false },
15
+ center: { type: null, required: false },
16
+ centerMarker: { type: Boolean, required: false },
17
+ mapOptions: { type: null, required: false },
18
+ region: { type: String, required: false },
19
+ language: { type: String, required: false },
20
+ version: { type: String, required: false },
21
+ width: { type: [Number, String], required: false, default: 640 },
22
+ height: { type: [Number, String], required: false, default: 400 },
23
+ placeholderOptions: { type: Object, required: false },
24
+ placeholderAttrs: { type: Object, required: false },
25
+ rootAttrs: { type: Object, required: false },
26
+ markers: { type: Array, required: false }
27
+ });
28
+ const emits = defineEmits(["ready", "error"]);
29
+ const apiKey = props.apiKey || scriptRuntimeConfig("googleMaps")?.apiKey;
30
+ const mapsApi = ref();
120
31
  if (import.meta.dev && !apiKey)
121
- throw new Error('GoogleMaps requires an API key. Please provide `apiKey` on the <ScriptGoogleMaps> or globally via `runtimeConfig.public.scripts.googleMaps.apiKey`.')
122
-
123
- // TODO allow a null center may need to be resolved via an API function
124
-
125
- const rootEl = ref<HTMLElement>()
126
- const mapEl = ref<HTMLElement>()
127
-
128
- const centerOverride = ref()
129
-
130
- const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
32
+ throw new Error("GoogleMaps requires an API key. Please provide `apiKey` on the <ScriptGoogleMaps> or globally via `runtimeConfig.public.scripts.googleMaps.apiKey`.");
33
+ const rootEl = ref();
34
+ const mapEl = ref();
35
+ const centerOverride = ref();
36
+ const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl });
131
37
  const { load, status, onLoaded } = useScriptGoogleMaps({
132
38
  apiKey: props.apiKey,
133
39
  scriptOptions: {
134
- trigger,
40
+ trigger
135
41
  },
136
42
  region: props.region,
137
43
  language: props.language,
138
- v: props.version,
139
- })
140
-
44
+ v: props.version
45
+ });
141
46
  const options = computed(() => {
142
47
  return defu({ center: centerOverride.value }, props.mapOptions, {
143
48
  center: props.center,
144
49
  zoom: 15,
145
- mapId: props.mapOptions?.styles ? undefined : 'map',
146
- })
147
- })
148
- const ready = ref(false)
149
-
150
- const map: Ref<google.maps.Map | undefined> = ref()
151
- const mapMarkers: Ref<Map<string, Promise<google.maps.marker.AdvancedMarkerElement>>> = ref(new Map())
152
-
153
- function isLocationQuery(s: string | any) {
154
- return typeof s === 'string' && (s.split(',').length > 2 || s.includes('+'))
50
+ mapId: props.mapOptions?.styles ? void 0 : "map"
51
+ });
52
+ });
53
+ const ready = ref(false);
54
+ const map = ref();
55
+ const mapMarkers = ref(/* @__PURE__ */ new Map());
56
+ function isLocationQuery(s) {
57
+ return typeof s === "string" && (s.split(",").length > 2 || s.includes("+"));
155
58
  }
156
-
157
- function resetMapMarkerMap(_marker: google.maps.marker.AdvancedMarkerElement | Promise<google.maps.marker.AdvancedMarkerElement>) {
158
- // eslint-disable-next-line no-async-promise-executor
159
- return new Promise<void>(async (resolve) => {
160
- const marker = _marker instanceof Promise ? await _marker : _marker
59
+ function resetMapMarkerMap(_marker) {
60
+ return new Promise(async (resolve) => {
61
+ const marker = _marker instanceof Promise ? await _marker : _marker;
161
62
  if (marker) {
162
- // @ts-expect-error broken type
163
- marker.setMap(null)
63
+ marker.setMap(null);
164
64
  }
165
- resolve()
166
- })
65
+ resolve();
66
+ });
167
67
  }
168
-
169
- function normalizeAdvancedMapMarkerOptions(_options?: google.maps.marker.AdvancedMarkerElementOptions | `${string},${string}`) {
170
- const opts = typeof _options === 'string'
171
- ? {
172
- position: {
173
- lat: Number.parseFloat(_options.split(',')[0] || '0'),
174
- lng: Number.parseFloat(_options.split(',')[1] || '0'),
175
- },
176
- }
177
- : _options
68
+ function normalizeAdvancedMapMarkerOptions(_options) {
69
+ const opts = typeof _options === "string" ? {
70
+ position: {
71
+ lat: Number.parseFloat(_options.split(",")[0] || "0"),
72
+ lng: Number.parseFloat(_options.split(",")[1] || "0")
73
+ }
74
+ } : _options;
178
75
  if (!opts.position) {
179
- // set default
180
76
  opts.position = {
181
77
  lat: 0,
182
- lng: 0,
183
- }
78
+ lng: 0
79
+ };
184
80
  }
81
+ return opts;
185
82
  }
186
-
187
- async function createAdvancedMapMarker(_options?: google.maps.marker.AdvancedMarkerElementOptions | `${string},${string}`) {
83
+ async function createAdvancedMapMarker(_options) {
188
84
  if (!_options)
189
- return
190
- const normalizedOptions = normalizeAdvancedMapMarkerOptions(_options)
191
- const key = hash({ position: normalizedOptions.position })
85
+ return;
86
+ const normalizedOptions = normalizeAdvancedMapMarkerOptions(_options);
87
+ const key = hash({ position: normalizedOptions.position });
192
88
  if (mapMarkers.value.has(key))
193
- return mapMarkers.value.get(key)
194
- // eslint-disable-next-line no-async-promise-executor
195
- const p = new Promise<google.maps.marker.AdvancedMarkerElement>(async (resolve) => {
196
- const lib = await importLibrary('marker')
89
+ return mapMarkers.value.get(key);
90
+ const p = new Promise(async (resolve) => {
91
+ const lib = await importLibrary("marker");
197
92
  const mapMarkerOptions = defu(toRaw(normalizedOptions), {
198
- map: toRaw(map.value!),
93
+ map: toRaw(map.value),
199
94
  // @ts-expect-error unified API for maps and markers
200
- position: normalizedOptions.location,
201
- })
202
- resolve(new lib.AdvancedMarkerElement(mapMarkerOptions))
203
- })
204
- mapMarkers.value.set(key, p)
205
- return p
95
+ position: normalizedOptions.location
96
+ });
97
+ resolve(new lib.AdvancedMarkerElement(mapMarkerOptions));
98
+ });
99
+ mapMarkers.value.set(key, p);
100
+ return p;
206
101
  }
207
-
208
- const queryToLatLngCache = new Map<string, google.maps.LatLng>()
209
-
210
- async function resolveQueryToLatLang(query: string) {
211
- if (query && typeof query === 'object')
212
- return Promise.resolve(query)
102
+ const queryToLatLngCache = /* @__PURE__ */ new Map();
103
+ async function resolveQueryToLatLang(query) {
104
+ if (query && typeof query === "object")
105
+ return Promise.resolve(query);
213
106
  if (queryToLatLngCache.has(query)) {
214
- return Promise.resolve(queryToLatLngCache.get(query))
107
+ return Promise.resolve(queryToLatLngCache.get(query));
215
108
  }
216
- // only if the query is a string we need to do a lookup
217
- // eslint-disable-next-line no-async-promise-executor
218
- return new Promise<google.maps.LatLng>(async (resolve, reject) => {
109
+ return new Promise(async (resolve, reject) => {
219
110
  if (!mapsApi.value) {
220
- await load()
221
- // await new promise, watch until mapsApi is set
222
- await new Promise<void>((resolve) => {
111
+ await load();
112
+ await new Promise((resolve2) => {
223
113
  const _ = watch(mapsApi, () => {
224
- _()
225
- resolve()
226
- })
227
- })
114
+ _();
115
+ resolve2();
116
+ });
117
+ });
228
118
  }
229
- const placesService = new mapsApi.value!.places.PlacesService(map.value!)
119
+ const placesService = new mapsApi.value.places.PlacesService(map.value);
230
120
  placesService.findPlaceFromQuery({
231
121
  query,
232
- fields: ['name', 'geometry'],
233
- }, (results, status) => {
234
- if (status === 'OK' && results?.[0]?.geometry?.location)
235
- return resolve(results[0].geometry.location)
236
- return reject(new Error(`No location found for ${query}`))
237
- })
122
+ fields: ["name", "geometry"]
123
+ }, (results, status2) => {
124
+ if (status2 === "OK" && results?.[0]?.geometry?.location)
125
+ return resolve(results[0].geometry.location);
126
+ return reject(new Error(`No location found for ${query}`));
127
+ });
238
128
  }).then((res) => {
239
- queryToLatLngCache.set(query, res)
240
- return res
241
- })
129
+ queryToLatLngCache.set(query, res);
130
+ return res;
131
+ });
242
132
  }
243
-
244
- const libraries = new Map<string, any>()
245
-
246
- function importLibrary(key: 'marker'): Promise<google.maps.MarkerLibrary>
247
- function importLibrary(key: 'places'): Promise<google.maps.PlacesLibrary>
248
- function importLibrary(key: 'geometry'): Promise<google.maps.GeometryLibrary>
249
- function importLibrary(key: 'drawing'): Promise<google.maps.DrawingLibrary>
250
- function importLibrary(key: 'visualization'): Promise<google.maps.VisualizationLibrary>
251
- function importLibrary(key: string): Promise<any>
252
- function importLibrary<T>(key: string): Promise<T> {
133
+ const libraries = /* @__PURE__ */ new Map();
134
+ function importLibrary(key) {
253
135
  if (libraries.has(key))
254
- return libraries.get(key)
136
+ return libraries.get(key);
255
137
  const p = mapsApi.value?.importLibrary(key) || new Promise((resolve) => {
256
138
  const stop = watch(mapsApi, (api) => {
257
139
  if (api) {
258
- const p = api.importLibrary(key)
259
- resolve(p)
260
- stop()
140
+ const p2 = api.importLibrary(key);
141
+ resolve(p2);
142
+ stop();
261
143
  }
262
- }, { immediate: true })
263
- })
264
- libraries.set(key, p)
265
- return p as any as Promise<T>
144
+ }, { immediate: true });
145
+ });
146
+ libraries.set(key, p);
147
+ return p;
266
148
  }
267
-
268
149
  const googleMaps = {
269
150
  googleMaps: mapsApi,
270
151
  map,
271
152
  createAdvancedMapMarker,
272
153
  resolveQueryToLatLang,
273
- importLibrary,
274
- } as const
275
-
276
- defineExpose(googleMaps)
277
-
154
+ importLibrary
155
+ };
156
+ defineExpose(googleMaps);
278
157
  onMounted(() => {
279
158
  watch(ready, (v) => {
280
159
  if (v) {
281
- emits('ready', googleMaps)
160
+ emits("ready", googleMaps);
282
161
  }
283
- })
162
+ });
284
163
  watch(status, (v) => {
285
- if (v === 'error') {
286
- emits('error')
164
+ if (v === "error") {
165
+ emits("error");
287
166
  }
288
- })
167
+ });
289
168
  watch(options, () => {
290
- map.value?.setOptions(options.value)
291
- })
169
+ map.value?.setOptions(options.value);
170
+ });
292
171
  watch([() => props.markers, map], async () => {
293
172
  if (!map.value) {
294
- return
173
+ return;
295
174
  }
296
- // mapMarkers is a map where we hash the next array entry as the map key
297
- // we need to do a diff to see what we remove or add
298
- const nextMap = new Map((props.markers || []).map(m => [hash({ position: normalizeAdvancedMapMarkerOptions(m).position }), m]))
299
- // compare idsToMatch in nextMap, if we're missing an id, we need to remove it
175
+ const nextMap = new Map((props.markers || []).map((m) => [hash({ position: normalizeAdvancedMapMarkerOptions(m).position }), m]));
300
176
  const toRemove = new Set([
301
- ...mapMarkers.value.keys(),
302
- ].filter(k => !nextMap.has(k)))
303
- // compare to existing
304
- const toAdd = new Set([...nextMap.keys()].filter(k => !mapMarkers.value.has(k)))
305
- // do a diff of next and prev
306
- const centerHash = hash({ position: options.value.center })
177
+ ...mapMarkers.value.keys()
178
+ ].filter((k) => !nextMap.has(k)));
179
+ const toAdd = new Set([...nextMap.keys()].filter((k) => !mapMarkers.value.has(k)));
180
+ const centerHash = hash({ position: options.value.center });
307
181
  for (const key of toRemove) {
308
182
  if (key === centerHash) {
309
- continue
183
+ continue;
310
184
  }
311
- const marker = await mapMarkers.value.get(key)
185
+ const marker = await mapMarkers.value.get(key);
312
186
  if (marker) {
313
- resetMapMarkerMap(marker)
314
- .then(() => {
315
- mapMarkers.value.delete(key)
316
- })
187
+ resetMapMarkerMap(marker).then(() => {
188
+ mapMarkers.value.delete(key);
189
+ });
317
190
  }
318
191
  }
319
192
  for (const k of toAdd) {
320
- createAdvancedMapMarker(nextMap.get(k))
193
+ createAdvancedMapMarker(nextMap.get(k));
321
194
  }
322
195
  }, {
323
196
  immediate: true,
324
- deep: true,
325
- })
197
+ deep: true
198
+ });
326
199
  watch([() => options.value.center, ready, map], async (next, prev) => {
327
200
  if (!map.value) {
328
- return
201
+ return;
329
202
  }
330
- let center = toRaw(next[0])
203
+ let center = toRaw(next[0]);
331
204
  if (center) {
332
205
  if (isLocationQuery(center) && ready.value) {
333
- // need to resolve center from query
334
- center = await resolveQueryToLatLang(center as string)
206
+ center = await resolveQueryToLatLang(center);
335
207
  }
336
- map.value!.setCenter(center as google.maps.LatLng)
337
- if (typeof props.centerMarker === 'undefined' || props.centerMarker) {
208
+ map.value.setCenter(center);
209
+ if (typeof props.centerMarker === "undefined" || props.centerMarker) {
338
210
  if (options.value.mapId) {
339
- // not allowed to use advanced markers with styles
340
- return
211
+ return;
341
212
  }
342
213
  if (prev[0]) {
343
- const prevCenterHash = hash({ position: prev[0] })
214
+ const prevCenterHash = hash({ position: prev[0] });
344
215
  if (mapMarkers.value.has(prevCenterHash)) {
345
- resetMapMarkerMap(mapMarkers.value.get(prevCenterHash)!)
346
- .then(() => {
347
- mapMarkers.value.delete(prevCenterHash)
348
- })
216
+ resetMapMarkerMap(mapMarkers.value.get(prevCenterHash)).then(() => {
217
+ mapMarkers.value.delete(prevCenterHash);
218
+ });
349
219
  }
350
220
  }
351
- createAdvancedMapMarker({ position: center })
221
+ createAdvancedMapMarker({ position: center });
352
222
  }
353
223
  }
354
224
  }, {
355
- immediate: true,
356
- })
225
+ immediate: true
226
+ });
357
227
  onLoaded(async (instance) => {
358
- mapsApi.value = await instance.maps
359
- // may need to transform the center before we can init the map
360
- const center = options.value.center as string
361
- const _options: google.maps.MapOptions = {
228
+ mapsApi.value = await instance.maps;
229
+ const center = options.value.center;
230
+ const _options = {
362
231
  ...options.value,
363
232
  // @ts-expect-error broken
364
- center: !center || isLocationQuery(center) ? undefined : center,
365
- }
366
- map.value = new mapsApi.value!.Map(mapEl.value!, _options)
233
+ center: !center || isLocationQuery(center) ? void 0 : center
234
+ };
235
+ map.value = new mapsApi.value.Map(mapEl.value, _options);
367
236
  if (center && isLocationQuery(center)) {
368
- // need to resolve center
369
- centerOverride.value = await resolveQueryToLatLang(center)
370
- map.value?.setCenter(centerOverride.value)
237
+ centerOverride.value = await resolveQueryToLatLang(center);
238
+ map.value?.setCenter(centerOverride.value);
371
239
  }
372
- ready.value = true
373
- })
374
- })
375
-
240
+ ready.value = true;
241
+ });
242
+ });
376
243
  if (import.meta.server) {
377
244
  useHead({
378
245
  link: [
379
246
  {
380
- rel: props.aboveTheFold ? 'preconnect' : 'dns-prefetch',
381
- href: 'https://maps.googleapis.com',
382
- },
383
- ],
384
- })
247
+ rel: props.aboveTheFold ? "preconnect" : "dns-prefetch",
248
+ href: "https://maps.googleapis.com"
249
+ }
250
+ ]
251
+ });
385
252
  }
386
-
387
- function transformMapStyles(styles: google.maps.MapTypeStyle[]) {
253
+ function transformMapStyles(styles) {
388
254
  return styles.map((style) => {
389
- const feature = style.featureType ? `feature:${style.featureType}` : ''
390
- const element = style.elementType ? `element:${style.elementType}` : ''
255
+ const feature = style.featureType ? `feature:${style.featureType}` : "";
256
+ const element = style.elementType ? `element:${style.elementType}` : "";
391
257
  const rules = (style.stylers || []).map((styler) => {
392
258
  return Object.entries(styler).map(([key, value]) => {
393
- if (key === 'color' && typeof value === 'string') {
394
- value = value.replace('#', '0x')
259
+ if (key === "color" && typeof value === "string") {
260
+ value = value.replace("#", "0x");
395
261
  }
396
- return `${key}:${value}`
397
- }).join('|')
398
- }).filter(Boolean).join('|')
399
- return [feature, element, rules].filter(Boolean).join('|')
400
- }).filter(Boolean)
262
+ return `${key}:${value}`;
263
+ }).join("|");
264
+ }).filter(Boolean).join("|");
265
+ return [feature, element, rules].filter(Boolean).join("|");
266
+ }).filter(Boolean);
401
267
  }
402
-
403
268
  const placeholder = computed(() => {
404
- let center = options.value.center
405
- if (center && typeof center === 'object') {
406
- center = `${center.lat},${center.lng}`
269
+ let center = options.value.center;
270
+ if (center && typeof center === "object") {
271
+ center = `${center.lat},${center.lng}`;
407
272
  }
408
- // @ts-expect-error lazy type
409
- const placeholderOptions: PlaceholderOptions = defu(props.placeholderOptions, {
273
+ const placeholderOptions = defu(props.placeholderOptions, {
410
274
  // only map option values
411
275
  zoom: options.value.zoom,
412
- center,
276
+ center
413
277
  }, {
414
278
  size: `${props.width}x${props.height}`,
415
279
  key: apiKey,
416
- scale: 2, // we assume a high DPI to avoid hydration issues
417
- style: props.mapOptions?.styles ? transformMapStyles(props.mapOptions.styles) : undefined,
280
+ scale: 2,
281
+ // we assume a high DPI to avoid hydration issues
282
+ style: props.mapOptions?.styles ? transformMapStyles(props.mapOptions.styles) : void 0,
418
283
  markers: [
419
- ...(props.markers || []),
420
- center,
421
- ]
422
- .filter(Boolean)
423
- .map((m) => {
424
- if (typeof m === 'object' && m.location) {
425
- m = m.location
426
- }
427
- if (typeof m === 'object' && m.lat) {
428
- return `${m.lat},${m.lng}`
429
- }
430
- return m
431
- })
432
- .join('|'),
433
- })
434
- return withQuery('https://maps.googleapis.com/maps/api/staticmap', placeholderOptions as QueryObject)
435
- })
436
-
284
+ ...props.markers || [],
285
+ center
286
+ ].filter(Boolean).map((m) => {
287
+ if (typeof m === "object" && m.location) {
288
+ m = m.location;
289
+ }
290
+ if (typeof m === "object" && m.lat) {
291
+ return `${m.lat},${m.lng}`;
292
+ }
293
+ return m;
294
+ }).join("|")
295
+ });
296
+ return withQuery("https://maps.googleapis.com/maps/api/staticmap", placeholderOptions);
297
+ });
437
298
  const placeholderAttrs = computed(() => {
438
299
  return defu(props.placeholderAttrs, {
439
300
  src: placeholder.value,
440
- alt: 'Google Maps Static Map',
441
- loading: props.aboveTheFold ? 'eager' : 'lazy',
301
+ alt: "Google Maps Static Map",
302
+ loading: props.aboveTheFold ? "eager" : "lazy",
442
303
  style: {
443
- cursor: 'pointer',
444
- width: '100%',
445
- objectFit: 'cover',
446
- height: '100%',
447
- },
448
- } satisfies ImgHTMLAttributes)
449
- })
450
-
304
+ cursor: "pointer",
305
+ width: "100%",
306
+ objectFit: "cover",
307
+ height: "100%"
308
+ }
309
+ });
310
+ });
451
311
  const rootAttrs = computed(() => {
452
312
  return defu(props.rootAttrs, {
453
- 'aria-busy': status.value === 'loading',
454
- 'aria-label': status.value === 'awaitingLoad'
455
- ? 'Google Maps Static Map'
456
- : status.value === 'loading'
457
- ? 'Google Maps Map Embed Loading'
458
- : 'Google Maps Embed',
459
- 'aria-live': 'polite',
460
- 'role': 'application',
461
- 'style': {
462
- cursor: 'pointer',
463
- position: 'relative',
464
- maxWidth: '100%',
313
+ "aria-busy": status.value === "loading",
314
+ "aria-label": status.value === "awaitingLoad" ? "Google Maps Static Map" : status.value === "loading" ? "Google Maps Map Embed Loading" : "Google Maps Embed",
315
+ "aria-live": "polite",
316
+ "role": "application",
317
+ "style": {
318
+ cursor: "pointer",
319
+ position: "relative",
320
+ maxWidth: "100%",
465
321
  width: `${props.width}px`,
466
322
  height: `'auto'`,
467
- aspectRatio: `${props.width}/${props.height}`,
323
+ aspectRatio: `${props.width}/${props.height}`
468
324
  },
469
- ...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
470
- }) as HTMLAttributes
471
- })
472
-
325
+ ...trigger instanceof Promise ? trigger.ssrAttrs || {} : {}
326
+ });
327
+ });
473
328
  onBeforeUnmount(async () => {
474
- await Promise.all([...mapMarkers.value.entries()].map(([,marker]) => resetMapMarkerMap(marker)))
475
- mapMarkers.value.clear()
476
- map.value?.unbindAll()
477
- map.value = undefined
478
- mapEl.value?.firstChild?.remove()
479
- })
329
+ await Promise.all([...mapMarkers.value.entries()].map(([, marker]) => resetMapMarkerMap(marker)));
330
+ mapMarkers.value.clear();
331
+ map.value?.unbindAll();
332
+ map.value = void 0;
333
+ mapEl.value?.firstChild?.remove();
334
+ });
480
335
  </script>
481
336
 
482
337
  <template>