@nuxt/scripts 0.6.4 → 0.6.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.
- package/README.md +73 -73
- package/dist/client/200.html +9 -9
- package/dist/client/404.html +9 -9
- package/dist/client/_nuxt/{DX8FDaDx.js → BKIFFtfV.js} +1 -1
- package/dist/client/_nuxt/{DUCgB8kF.js → BKJqCZ0j.js} +1 -1
- package/dist/client/_nuxt/DcF05ETD.js +31 -0
- package/dist/client/_nuxt/aQeyjCqJ.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/3dcaf2bf-82f1-460f-80a6-1412196a7a77.json +1 -0
- package/dist/client/_nuxt/entry.FVeyw1Qn.css +1 -0
- package/dist/client/_nuxt/error-404.B7Lh29wY.css +1 -0
- package/dist/client/_nuxt/error-500.B_VIyt60.css +1 -0
- package/dist/client/index.html +9 -9
- package/dist/module.d.mts +2 -10
- package/dist/module.d.ts +2 -10
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -0
- package/dist/registry.mjs +2 -2
- package/dist/runtime/components/ScriptCarbonAds.vue +71 -71
- package/dist/runtime/components/ScriptCrisp.vue +84 -84
- package/dist/runtime/components/ScriptGoogleAdsense.vue +69 -69
- package/dist/runtime/components/ScriptGoogleMaps.vue +267 -265
- package/dist/runtime/components/ScriptIntercom.vue +93 -93
- package/dist/runtime/components/ScriptLemonSqueezy.vue +45 -45
- package/dist/runtime/components/ScriptLoadingIndicator.vue +22 -22
- package/dist/runtime/components/ScriptStripePricingTable.vue +68 -68
- package/dist/runtime/components/ScriptVimeoPlayer.vue +258 -256
- package/dist/runtime/components/ScriptYouTubePlayer.vue +171 -170
- package/dist/runtime/composables/useScript.js +2 -2
- package/dist/runtime/composables/useScriptEventPage.d.ts +4 -1
- package/dist/runtime/composables/useScriptEventPage.js +6 -5
- package/dist/runtime/registry/clarity.js +1 -1
- package/dist/runtime/registry/cloudflare-web-analytics.js +1 -1
- package/dist/runtime/registry/crisp.js +1 -1
- package/dist/runtime/registry/fathom-analytics.js +1 -1
- package/dist/runtime/registry/google-adsense.js +1 -1
- package/dist/runtime/registry/google-analytics.d.ts +13 -7
- package/dist/runtime/registry/google-analytics.js +25 -13
- package/dist/runtime/registry/google-maps.js +1 -1
- package/dist/runtime/registry/google-tag-manager.d.ts +16 -6
- package/dist/runtime/registry/google-tag-manager.js +16 -10
- package/dist/runtime/registry/hotjar.js +1 -1
- package/dist/runtime/registry/intercom.js +1 -1
- package/dist/runtime/registry/lemon-squeezy.js +1 -1
- package/dist/runtime/registry/matomo-analytics.js +7 -3
- package/dist/runtime/registry/meta-pixel.d.ts +1 -0
- package/dist/runtime/registry/meta-pixel.js +6 -2
- package/dist/runtime/registry/npm.js +1 -1
- package/dist/runtime/registry/plausible-analytics.js +1 -1
- package/dist/runtime/registry/segment.d.ts +1 -2
- package/dist/runtime/registry/segment.js +1 -1
- package/dist/runtime/registry/stripe.js +1 -1
- package/dist/runtime/registry/vimeo-player.js +1 -1
- package/dist/runtime/registry/x-pixel.js +7 -3
- package/dist/runtime/registry/youtube-player.js +1 -1
- package/dist/runtime/types.d.ts +20 -4
- package/dist/runtime/types.js +1 -1
- package/dist/runtime/utils.d.ts +1 -1
- package/dist/runtime/utils.js +16 -4
- package/package.json +30 -32
- package/dist/client/_nuxt/B8kiEHWd.js +0 -31
- package/dist/client/_nuxt/CE8XWCBP.js +0 -1
- package/dist/client/_nuxt/builds/meta/a56fe5f5-907d-4907-9967-836d6a0f3850.json +0 -1
- package/dist/client/_nuxt/entry.DvGwvmL9.css +0 -1
- package/dist/client/_nuxt/error-404.-RjlvToe.css +0 -1
- package/dist/client/_nuxt/error-500.Bz7LXgZy.css +0 -1
|
@@ -1,265 +1,267 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
/// <reference types="google.maps" />
|
|
3
|
-
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
4
|
-
import type { HTMLAttributes, ImgHTMLAttributes, Ref, ReservedProps } from 'vue'
|
|
5
|
-
import { withQuery } from 'ufo'
|
|
6
|
-
import type { QueryObject } from 'ufo'
|
|
7
|
-
import { defu } from 'defu'
|
|
8
|
-
import type { ElementScriptTrigger } from '../types'
|
|
9
|
-
import { scriptRuntimeConfig } from '../utils'
|
|
10
|
-
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
11
|
-
import { useScriptGoogleMaps } from '../registry/google-maps'
|
|
12
|
-
import { resolveComponent, useHead } from '#imports'
|
|
13
|
-
|
|
14
|
-
interface PlaceholderOptions {
|
|
15
|
-
width?: string | number
|
|
16
|
-
height?: string | number
|
|
17
|
-
center?: string
|
|
18
|
-
zoom?: number
|
|
19
|
-
size?: string
|
|
20
|
-
scale?: number
|
|
21
|
-
format?: 'png' | 'jpg' | 'gif' | 'png8' | 'png32' | 'jpg-baseline'
|
|
22
|
-
maptype?: 'roadmap' | 'satellite' | 'terrain' | 'hybrid'
|
|
23
|
-
language?: string
|
|
24
|
-
region?: string
|
|
25
|
-
markers?: string
|
|
26
|
-
path?: string
|
|
27
|
-
visible?: string
|
|
28
|
-
style?: string
|
|
29
|
-
map_id?: string
|
|
30
|
-
key?: string
|
|
31
|
-
signature?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const props = withDefaults(defineProps<{
|
|
35
|
-
/**
|
|
36
|
-
* Defines the trigger event to load the script.
|
|
37
|
-
*/
|
|
38
|
-
trigger?: ElementScriptTrigger
|
|
39
|
-
/**
|
|
40
|
-
* Is Google Maps being rendered above the fold?
|
|
41
|
-
* This will load the placeholder image with higher priority.
|
|
42
|
-
*/
|
|
43
|
-
aboveTheFold?: boolean
|
|
44
|
-
/**
|
|
45
|
-
* Defines the Google Maps API key. Must have access to the Static Maps API as well.
|
|
46
|
-
*/
|
|
47
|
-
apiKey: string
|
|
48
|
-
/**
|
|
49
|
-
* Defines map marker location.
|
|
50
|
-
*/
|
|
51
|
-
query?: string
|
|
52
|
-
/**
|
|
53
|
-
* Options for the map.
|
|
54
|
-
*/
|
|
55
|
-
options?: google.maps.MapOptions
|
|
56
|
-
/**
|
|
57
|
-
* Defines the width of the map.
|
|
58
|
-
*/
|
|
59
|
-
width?: number | string
|
|
60
|
-
/**
|
|
61
|
-
* Defines the height of the map
|
|
62
|
-
*/
|
|
63
|
-
height?: number | string
|
|
64
|
-
/**
|
|
65
|
-
* Customize the placeholder image attributes.
|
|
66
|
-
*
|
|
67
|
-
* @see https://developers.google.com/maps/documentation/maps-static/start.
|
|
68
|
-
*/
|
|
69
|
-
placeholderOptions?: PlaceholderOptions
|
|
70
|
-
/**
|
|
71
|
-
* Customize the placeholder image attributes.
|
|
72
|
-
*/
|
|
73
|
-
placeholderAttrs?: ImgHTMLAttributes & ReservedProps & Record<string, unknown>
|
|
74
|
-
/**
|
|
75
|
-
* Customize the root element attributes.
|
|
76
|
-
*/
|
|
77
|
-
rootAttrs?: HTMLAttributes & ReservedProps & Record<string, unknown>
|
|
78
|
-
}>(), {
|
|
79
|
-
// @ts-expect-error untyped
|
|
80
|
-
trigger: ['mouseenter', 'mouseover', 'mousedown'],
|
|
81
|
-
width: 600,
|
|
82
|
-
height: 400,
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
const emits = defineEmits<{
|
|
86
|
-
// our emit
|
|
87
|
-
ready: [e: Ref<google.maps.Map | undefined>]
|
|
88
|
-
error: []
|
|
89
|
-
}>()
|
|
90
|
-
|
|
91
|
-
const apiKey = props.apiKey || scriptRuntimeConfig('googleMaps')?.apiKey
|
|
92
|
-
|
|
93
|
-
if (!apiKey)
|
|
94
|
-
throw new Error('GoogleMaps requires an API key. Please provide `apiKey` on the <ScriptGoogleMaps> or globally via `runtimeConfig.public.scripts.googleMaps.apiKey`.')
|
|
95
|
-
if (!props.query && !props.options?.center)
|
|
96
|
-
throw new Error('GoogleMaps requires either a query or center prop to be set.')
|
|
97
|
-
|
|
98
|
-
const rootEl = ref<HTMLElement>()
|
|
99
|
-
const mapEl = ref<HTMLElement>()
|
|
100
|
-
|
|
101
|
-
const { $script } = useScriptGoogleMaps({
|
|
102
|
-
apiKey: props.apiKey,
|
|
103
|
-
scriptOptions: {
|
|
104
|
-
trigger: useScriptTriggerElement({ trigger: props.trigger, el: rootEl }),
|
|
105
|
-
},
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const options = computed(() => {
|
|
109
|
-
return defu(props.options, {
|
|
110
|
-
zoom: 15,
|
|
111
|
-
mapId: 'map',
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
const ready = ref(false)
|
|
115
|
-
|
|
116
|
-
function queryToLocation(service: google.maps.places.PlacesService, query: string) {
|
|
117
|
-
return new Promise<google.maps.LatLng>((resolve, reject) => {
|
|
118
|
-
service.findPlaceFromQuery({
|
|
119
|
-
query,
|
|
120
|
-
fields: ['name', 'geometry'],
|
|
121
|
-
}, (results, status) => {
|
|
122
|
-
if (status === 'OK' && results?.[0]?.geometry?.location)
|
|
123
|
-
return resolve(results[0].geometry.location)
|
|
124
|
-
return reject(new Error(`No location found for ${query}`))
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const map: Ref<google.maps.Map | undefined> = ref()
|
|
130
|
-
const markers: Ref<google.maps.marker.AdvancedMarkerElement[]> = ref([])
|
|
131
|
-
defineExpose({
|
|
132
|
-
map,
|
|
133
|
-
markers,
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
onMounted(() => {
|
|
137
|
-
watch(ready, (v) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
'
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
<slot />
|
|
264
|
-
|
|
265
|
-
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
/// <reference types="google.maps" />
|
|
3
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
4
|
+
import type { HTMLAttributes, ImgHTMLAttributes, Ref, ReservedProps } from 'vue'
|
|
5
|
+
import { withQuery } from 'ufo'
|
|
6
|
+
import type { QueryObject } from 'ufo'
|
|
7
|
+
import { defu } from 'defu'
|
|
8
|
+
import type { ElementScriptTrigger } from '../types'
|
|
9
|
+
import { scriptRuntimeConfig } from '../utils'
|
|
10
|
+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
|
|
11
|
+
import { useScriptGoogleMaps } from '../registry/google-maps'
|
|
12
|
+
import { resolveComponent, useHead } from '#imports'
|
|
13
|
+
|
|
14
|
+
interface PlaceholderOptions {
|
|
15
|
+
width?: string | number
|
|
16
|
+
height?: string | number
|
|
17
|
+
center?: string
|
|
18
|
+
zoom?: number
|
|
19
|
+
size?: string
|
|
20
|
+
scale?: number
|
|
21
|
+
format?: 'png' | 'jpg' | 'gif' | 'png8' | 'png32' | 'jpg-baseline'
|
|
22
|
+
maptype?: 'roadmap' | 'satellite' | 'terrain' | 'hybrid'
|
|
23
|
+
language?: string
|
|
24
|
+
region?: string
|
|
25
|
+
markers?: string
|
|
26
|
+
path?: string
|
|
27
|
+
visible?: string
|
|
28
|
+
style?: string
|
|
29
|
+
map_id?: string
|
|
30
|
+
key?: string
|
|
31
|
+
signature?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const props = withDefaults(defineProps<{
|
|
35
|
+
/**
|
|
36
|
+
* Defines the trigger event to load the script.
|
|
37
|
+
*/
|
|
38
|
+
trigger?: ElementScriptTrigger
|
|
39
|
+
/**
|
|
40
|
+
* Is Google Maps being rendered above the fold?
|
|
41
|
+
* This will load the placeholder image with higher priority.
|
|
42
|
+
*/
|
|
43
|
+
aboveTheFold?: boolean
|
|
44
|
+
/**
|
|
45
|
+
* Defines the Google Maps API key. Must have access to the Static Maps API as well.
|
|
46
|
+
*/
|
|
47
|
+
apiKey: string
|
|
48
|
+
/**
|
|
49
|
+
* Defines map marker location.
|
|
50
|
+
*/
|
|
51
|
+
query?: string
|
|
52
|
+
/**
|
|
53
|
+
* Options for the map.
|
|
54
|
+
*/
|
|
55
|
+
options?: google.maps.MapOptions
|
|
56
|
+
/**
|
|
57
|
+
* Defines the width of the map.
|
|
58
|
+
*/
|
|
59
|
+
width?: number | string
|
|
60
|
+
/**
|
|
61
|
+
* Defines the height of the map
|
|
62
|
+
*/
|
|
63
|
+
height?: number | string
|
|
64
|
+
/**
|
|
65
|
+
* Customize the placeholder image attributes.
|
|
66
|
+
*
|
|
67
|
+
* @see https://developers.google.com/maps/documentation/maps-static/start.
|
|
68
|
+
*/
|
|
69
|
+
placeholderOptions?: PlaceholderOptions
|
|
70
|
+
/**
|
|
71
|
+
* Customize the placeholder image attributes.
|
|
72
|
+
*/
|
|
73
|
+
placeholderAttrs?: ImgHTMLAttributes & ReservedProps & Record<string, unknown>
|
|
74
|
+
/**
|
|
75
|
+
* Customize the root element attributes.
|
|
76
|
+
*/
|
|
77
|
+
rootAttrs?: HTMLAttributes & ReservedProps & Record<string, unknown>
|
|
78
|
+
}>(), {
|
|
79
|
+
// @ts-expect-error untyped
|
|
80
|
+
trigger: ['mouseenter', 'mouseover', 'mousedown'],
|
|
81
|
+
width: 600,
|
|
82
|
+
height: 400,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const emits = defineEmits<{
|
|
86
|
+
// our emit
|
|
87
|
+
ready: [e: Ref<google.maps.Map | undefined>]
|
|
88
|
+
error: []
|
|
89
|
+
}>()
|
|
90
|
+
|
|
91
|
+
const apiKey = props.apiKey || scriptRuntimeConfig('googleMaps')?.apiKey
|
|
92
|
+
|
|
93
|
+
if (!apiKey)
|
|
94
|
+
throw new Error('GoogleMaps requires an API key. Please provide `apiKey` on the <ScriptGoogleMaps> or globally via `runtimeConfig.public.scripts.googleMaps.apiKey`.')
|
|
95
|
+
if (!props.query && !props.options?.center)
|
|
96
|
+
throw new Error('GoogleMaps requires either a query or center prop to be set.')
|
|
97
|
+
|
|
98
|
+
const rootEl = ref<HTMLElement>()
|
|
99
|
+
const mapEl = ref<HTMLElement>()
|
|
100
|
+
|
|
101
|
+
const { $script } = useScriptGoogleMaps({
|
|
102
|
+
apiKey: props.apiKey,
|
|
103
|
+
scriptOptions: {
|
|
104
|
+
trigger: useScriptTriggerElement({ trigger: props.trigger, el: rootEl }),
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const options = computed(() => {
|
|
109
|
+
return defu(props.options, {
|
|
110
|
+
zoom: 15,
|
|
111
|
+
mapId: 'map',
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
const ready = ref(false)
|
|
115
|
+
|
|
116
|
+
function queryToLocation(service: google.maps.places.PlacesService, query: string) {
|
|
117
|
+
return new Promise<google.maps.LatLng>((resolve, reject) => {
|
|
118
|
+
service.findPlaceFromQuery({
|
|
119
|
+
query,
|
|
120
|
+
fields: ['name', 'geometry'],
|
|
121
|
+
}, (results, status) => {
|
|
122
|
+
if (status === 'OK' && results?.[0]?.geometry?.location)
|
|
123
|
+
return resolve(results[0].geometry.location)
|
|
124
|
+
return reject(new Error(`No location found for ${query}`))
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const map: Ref<google.maps.Map | undefined> = ref()
|
|
130
|
+
const markers: Ref<google.maps.marker.AdvancedMarkerElement[]> = ref([])
|
|
131
|
+
defineExpose({
|
|
132
|
+
map,
|
|
133
|
+
markers,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
onMounted(() => {
|
|
137
|
+
watch(ready, (v) => {
|
|
138
|
+
if (v) {
|
|
139
|
+
emits('ready', map)
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
watch($script.status, () => {
|
|
143
|
+
if ($script.status.value === 'error') {
|
|
144
|
+
emits('error')
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
// create the map
|
|
148
|
+
$script.then(async (instance) => {
|
|
149
|
+
const maps = await instance.maps as any as typeof google.maps // some weird type issue here
|
|
150
|
+
const _map = new maps.Map(mapEl.value!, options.value)
|
|
151
|
+
const placesService = new maps.places.PlacesService(_map)
|
|
152
|
+
|
|
153
|
+
watch(options, () => _map.setOptions(options.value))
|
|
154
|
+
watch(() => props.query, async (query) => {
|
|
155
|
+
// always clear old markers
|
|
156
|
+
markers.value.forEach(marker => marker.remove())
|
|
157
|
+
markers.value = []
|
|
158
|
+
if (query) {
|
|
159
|
+
const marker = await maps.importLibrary('marker') as google.maps.MarkerLibrary
|
|
160
|
+
const location = await queryToLocation(placesService, query).catch((err) => {
|
|
161
|
+
console.warn(err)
|
|
162
|
+
return {
|
|
163
|
+
lat: 0,
|
|
164
|
+
lng: 0,
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
_map.setCenter(location)
|
|
168
|
+
markers.value.push(new marker.AdvancedMarkerElement({
|
|
169
|
+
map: _map,
|
|
170
|
+
position: location,
|
|
171
|
+
}))
|
|
172
|
+
ready.value = true
|
|
173
|
+
}
|
|
174
|
+
}, {
|
|
175
|
+
immediate: !!props.query,
|
|
176
|
+
})
|
|
177
|
+
if (!props.query)
|
|
178
|
+
ready.value = true
|
|
179
|
+
map.value = _map
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
if (import.meta.server) {
|
|
184
|
+
useHead({
|
|
185
|
+
link: [
|
|
186
|
+
{
|
|
187
|
+
rel: props.aboveTheFold ? 'preconnect' : 'dns-prefetch',
|
|
188
|
+
href: 'https://maps.googleapis.com',
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const placeholder = computed(() => {
|
|
195
|
+
const placeholderOptions: PlaceholderOptions = defu(props.placeholderOptions, {
|
|
196
|
+
// only map option values
|
|
197
|
+
zoom: options.value.zoom,
|
|
198
|
+
center: options.value.center?.toString() || '',
|
|
199
|
+
}, {
|
|
200
|
+
size: `${props.width}x${props.height}`,
|
|
201
|
+
key: apiKey,
|
|
202
|
+
scale: 2, // we assume a high DPI to avoid hydration issues
|
|
203
|
+
markers: `color:red|${props.query}`,
|
|
204
|
+
})
|
|
205
|
+
return withQuery('https://maps.googleapis.com/maps/api/staticmap', placeholderOptions as QueryObject)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
const placeholderAttrs = computed(() => {
|
|
209
|
+
return defu(props.placeholderAttrs, {
|
|
210
|
+
src: placeholder.value,
|
|
211
|
+
alt: props.query || '',
|
|
212
|
+
loading: props.aboveTheFold ? 'eager' : 'lazy',
|
|
213
|
+
style: {
|
|
214
|
+
cursor: 'pointer',
|
|
215
|
+
width: '100%',
|
|
216
|
+
objectFit: 'cover',
|
|
217
|
+
height: '100%',
|
|
218
|
+
},
|
|
219
|
+
} satisfies ImgHTMLAttributes)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
const rootAttrs = computed(() => {
|
|
223
|
+
return defu(props.rootAttrs, {
|
|
224
|
+
'aria-busy': $script.status.value === 'loading',
|
|
225
|
+
'aria-label': $script.status.value === 'awaitingLoad'
|
|
226
|
+
? 'Google Maps Static Map'
|
|
227
|
+
: $script.status.value === 'loading'
|
|
228
|
+
? 'Google Maps Map Embed Loading'
|
|
229
|
+
: 'Google Maps Embed',
|
|
230
|
+
'aria-live': 'polite',
|
|
231
|
+
'role': 'application',
|
|
232
|
+
'style': {
|
|
233
|
+
cursor: 'pointer',
|
|
234
|
+
position: 'relative',
|
|
235
|
+
maxWidth: '100%',
|
|
236
|
+
width: `${props.width}px`,
|
|
237
|
+
height: `'auto'`,
|
|
238
|
+
aspectRatio: `${props.width}/${props.height}`,
|
|
239
|
+
},
|
|
240
|
+
}) as HTMLAttributes
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
const ScriptLoadingIndicator = resolveComponent('ScriptLoadingIndicator')
|
|
244
|
+
|
|
245
|
+
onBeforeUnmount(() => {
|
|
246
|
+
markers.value.forEach(marker => marker.remove())
|
|
247
|
+
markers.value = []
|
|
248
|
+
map.value?.unbindAll()
|
|
249
|
+
map.value = undefined
|
|
250
|
+
mapEl.value?.firstChild?.remove()
|
|
251
|
+
})
|
|
252
|
+
</script>
|
|
253
|
+
|
|
254
|
+
<template>
|
|
255
|
+
<div ref="rootEl" v-bind="rootAttrs">
|
|
256
|
+
<div v-show="ready" ref="mapEl" class="script-google-maps__map" :style="{ width: '100%', height: '100%', maxWidth: '100%' }" />
|
|
257
|
+
<slot v-if="!ready" :placeholder="placeholder" name="placeholder">
|
|
258
|
+
<img v-bind="placeholderAttrs">
|
|
259
|
+
</slot>
|
|
260
|
+
<slot v-if="$script.status.value === 'loading'" name="loading">
|
|
261
|
+
<ScriptLoadingIndicator color="black" />
|
|
262
|
+
</slot>
|
|
263
|
+
<slot v-if="$script.status.value === 'awaitingLoad'" name="awaitingLoad" />
|
|
264
|
+
<slot v-else-if="$script.status.value === 'error'" name="error" />
|
|
265
|
+
<slot />
|
|
266
|
+
</div>
|
|
267
|
+
</template>
|