@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.
Files changed (66) hide show
  1. package/README.md +73 -73
  2. package/dist/client/200.html +9 -9
  3. package/dist/client/404.html +9 -9
  4. package/dist/client/_nuxt/{DX8FDaDx.js → BKIFFtfV.js} +1 -1
  5. package/dist/client/_nuxt/{DUCgB8kF.js → BKJqCZ0j.js} +1 -1
  6. package/dist/client/_nuxt/DcF05ETD.js +31 -0
  7. package/dist/client/_nuxt/aQeyjCqJ.js +1 -0
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/3dcaf2bf-82f1-460f-80a6-1412196a7a77.json +1 -0
  10. package/dist/client/_nuxt/entry.FVeyw1Qn.css +1 -0
  11. package/dist/client/_nuxt/error-404.B7Lh29wY.css +1 -0
  12. package/dist/client/_nuxt/error-500.B_VIyt60.css +1 -0
  13. package/dist/client/index.html +9 -9
  14. package/dist/module.d.mts +2 -10
  15. package/dist/module.d.ts +2 -10
  16. package/dist/module.json +1 -1
  17. package/dist/module.mjs +3 -0
  18. package/dist/registry.mjs +2 -2
  19. package/dist/runtime/components/ScriptCarbonAds.vue +71 -71
  20. package/dist/runtime/components/ScriptCrisp.vue +84 -84
  21. package/dist/runtime/components/ScriptGoogleAdsense.vue +69 -69
  22. package/dist/runtime/components/ScriptGoogleMaps.vue +267 -265
  23. package/dist/runtime/components/ScriptIntercom.vue +93 -93
  24. package/dist/runtime/components/ScriptLemonSqueezy.vue +45 -45
  25. package/dist/runtime/components/ScriptLoadingIndicator.vue +22 -22
  26. package/dist/runtime/components/ScriptStripePricingTable.vue +68 -68
  27. package/dist/runtime/components/ScriptVimeoPlayer.vue +258 -256
  28. package/dist/runtime/components/ScriptYouTubePlayer.vue +171 -170
  29. package/dist/runtime/composables/useScript.js +2 -2
  30. package/dist/runtime/composables/useScriptEventPage.d.ts +4 -1
  31. package/dist/runtime/composables/useScriptEventPage.js +6 -5
  32. package/dist/runtime/registry/clarity.js +1 -1
  33. package/dist/runtime/registry/cloudflare-web-analytics.js +1 -1
  34. package/dist/runtime/registry/crisp.js +1 -1
  35. package/dist/runtime/registry/fathom-analytics.js +1 -1
  36. package/dist/runtime/registry/google-adsense.js +1 -1
  37. package/dist/runtime/registry/google-analytics.d.ts +13 -7
  38. package/dist/runtime/registry/google-analytics.js +25 -13
  39. package/dist/runtime/registry/google-maps.js +1 -1
  40. package/dist/runtime/registry/google-tag-manager.d.ts +16 -6
  41. package/dist/runtime/registry/google-tag-manager.js +16 -10
  42. package/dist/runtime/registry/hotjar.js +1 -1
  43. package/dist/runtime/registry/intercom.js +1 -1
  44. package/dist/runtime/registry/lemon-squeezy.js +1 -1
  45. package/dist/runtime/registry/matomo-analytics.js +7 -3
  46. package/dist/runtime/registry/meta-pixel.d.ts +1 -0
  47. package/dist/runtime/registry/meta-pixel.js +6 -2
  48. package/dist/runtime/registry/npm.js +1 -1
  49. package/dist/runtime/registry/plausible-analytics.js +1 -1
  50. package/dist/runtime/registry/segment.d.ts +1 -2
  51. package/dist/runtime/registry/segment.js +1 -1
  52. package/dist/runtime/registry/stripe.js +1 -1
  53. package/dist/runtime/registry/vimeo-player.js +1 -1
  54. package/dist/runtime/registry/x-pixel.js +7 -3
  55. package/dist/runtime/registry/youtube-player.js +1 -1
  56. package/dist/runtime/types.d.ts +20 -4
  57. package/dist/runtime/types.js +1 -1
  58. package/dist/runtime/utils.d.ts +1 -1
  59. package/dist/runtime/utils.js +16 -4
  60. package/package.json +30 -32
  61. package/dist/client/_nuxt/B8kiEHWd.js +0 -31
  62. package/dist/client/_nuxt/CE8XWCBP.js +0 -1
  63. package/dist/client/_nuxt/builds/meta/a56fe5f5-907d-4907-9967-836d6a0f3850.json +0 -1
  64. package/dist/client/_nuxt/entry.DvGwvmL9.css +0 -1
  65. package/dist/client/_nuxt/error-404.-RjlvToe.css +0 -1
  66. 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
- v && emits('ready', map)
139
- })
140
- watch($script.status, () => {
141
- if ($script.status.value === 'error') {
142
- emits('error')
143
- }
144
- })
145
- // create the map
146
- $script.then(async (instance) => {
147
- const maps = await instance.maps as any as typeof google.maps // some weird type issue here
148
- const _map = new maps.Map(mapEl.value!, options.value)
149
- const placesService = new maps.places.PlacesService(_map)
150
-
151
- watch(options, () => _map.setOptions(options.value))
152
- watch(() => props.query, async (query) => {
153
- // always clear old markers
154
- markers.value.forEach(marker => marker.remove())
155
- markers.value = []
156
- if (query) {
157
- const marker = await maps.importLibrary('marker') as google.maps.MarkerLibrary
158
- const location = await queryToLocation(placesService, query).catch((err) => {
159
- console.warn(err)
160
- return {
161
- lat: 0,
162
- lng: 0,
163
- }
164
- })
165
- _map.setCenter(location)
166
- markers.value.push(new marker.AdvancedMarkerElement({
167
- map: _map,
168
- position: location,
169
- }))
170
- ready.value = true
171
- }
172
- }, {
173
- immediate: !!props.query,
174
- })
175
- if (!props.query)
176
- ready.value = true
177
- map.value = _map
178
- })
179
- })
180
-
181
- if (import.meta.server) {
182
- useHead({
183
- link: [
184
- {
185
- rel: props.aboveTheFold ? 'preconnect' : 'dns-prefetch',
186
- href: 'https://maps.googleapis.com',
187
- },
188
- ],
189
- })
190
- }
191
-
192
- const placeholder = computed(() => {
193
- const placeholderOptions: PlaceholderOptions = defu(props.placeholderOptions, {
194
- // only map option values
195
- zoom: options.value.zoom,
196
- center: options.value.center?.toString() || '',
197
- }, {
198
- size: `${props.width}x${props.height}`,
199
- key: apiKey,
200
- scale: 2, // we assume a high DPI to avoid hydration issues
201
- markers: `color:red|${props.query}`,
202
- })
203
- return withQuery('https://maps.googleapis.com/maps/api/staticmap', placeholderOptions as QueryObject)
204
- })
205
-
206
- const placeholderAttrs = computed(() => {
207
- return defu(props.placeholderAttrs, {
208
- src: placeholder.value,
209
- alt: props.query || '',
210
- loading: props.aboveTheFold ? 'eager' : 'lazy',
211
- style: {
212
- cursor: 'pointer',
213
- width: '100%',
214
- objectFit: 'cover',
215
- height: '100%',
216
- },
217
- } satisfies ImgHTMLAttributes)
218
- })
219
-
220
- const rootAttrs = computed(() => {
221
- return defu(props.rootAttrs, {
222
- 'aria-busy': $script.status.value === 'loading',
223
- 'aria-label': $script.status.value === 'awaitingLoad'
224
- ? 'Google Maps Static Map'
225
- : $script.status.value === 'loading'
226
- ? 'Google Maps Map Embed Loading'
227
- : 'Google Maps Embed',
228
- 'aria-live': 'polite',
229
- 'role': 'application',
230
- 'style': {
231
- cursor: 'pointer',
232
- position: 'relative',
233
- maxWidth: '100%',
234
- width: `${props.width}px`,
235
- height: `'auto'`,
236
- aspectRatio: `${props.width}/${props.height}`,
237
- },
238
- }) as HTMLAttributes
239
- })
240
-
241
- const ScriptLoadingIndicator = resolveComponent('ScriptLoadingIndicator')
242
-
243
- onBeforeUnmount(() => {
244
- markers.value.forEach(marker => marker.remove())
245
- markers.value = []
246
- map.value?.unbindAll()
247
- map.value = undefined
248
- mapEl.value?.firstChild?.remove()
249
- })
250
- </script>
251
-
252
- <template>
253
- <div ref="rootEl" v-bind="rootAttrs">
254
- <div v-show="ready" ref="mapEl" class="script-google-maps__map" :style="{ width: '100%', height: '100%', maxWidth: '100%' }" />
255
- <slot v-if="!ready" :placeholder="placeholder" name="placeholder">
256
- <img v-bind="placeholderAttrs">
257
- </slot>
258
- <slot v-if="$script.status.value === 'loading'" name="loading">
259
- <ScriptLoadingIndicator color="black" />
260
- </slot>
261
- <slot v-if="$script.status.value === 'awaitingLoad'" name="awaitingLoad" />
262
- <slot v-else-if="$script.status.value === 'error'" name="error" />
263
- <slot />
264
- </div>
265
- </template>
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>