@nuxt/scripts 0.7.1 → 0.8.0

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 (36) 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/{C1IUq70_.js → B7a7KwY0.js} +1 -1
  5. package/dist/client/_nuxt/{DOi3Eb0n.js → BYm2jJpo.js} +11 -11
  6. package/dist/client/_nuxt/{iQqcKxZm.js → CEoS15Fi.js} +1 -1
  7. package/dist/client/_nuxt/{CnUvXFHd.js → Nd9uLa0s.js} +1 -1
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/ec7cd9b1-e776-4993-98a3-da039c5325b9.json +1 -0
  10. package/dist/client/_nuxt/{entry.FVeyw1Qn.css → entry.BAZUAl3s.css} +1 -1
  11. package/dist/client/_nuxt/error-404.ChzstOPh.css +1 -0
  12. package/dist/client/_nuxt/error-500.BaOmLlKq.css +1 -0
  13. package/dist/client/index.html +9 -9
  14. package/dist/module.d.mts +2 -2
  15. package/dist/module.d.ts +2 -2
  16. package/dist/module.json +1 -1
  17. package/dist/module.mjs +2 -0
  18. package/dist/runtime/components/ScriptCarbonAds.vue +78 -71
  19. package/dist/runtime/components/ScriptCrisp.vue +94 -87
  20. package/dist/runtime/components/ScriptGoogleAdsense.vue +75 -69
  21. package/dist/runtime/components/ScriptGoogleMaps.vue +457 -435
  22. package/dist/runtime/components/ScriptIntercom.vue +103 -96
  23. package/dist/runtime/components/ScriptLemonSqueezy.vue +52 -45
  24. package/dist/runtime/components/ScriptLoadingIndicator.vue +22 -22
  25. package/dist/runtime/components/ScriptStripePricingTable.vue +75 -68
  26. package/dist/runtime/components/ScriptVimeoPlayer.vue +281 -280
  27. package/dist/runtime/components/ScriptYouTubePlayer.vue +174 -171
  28. package/dist/runtime/composables/useScript.js +25 -7
  29. package/dist/runtime/composables/useScriptTriggerElement.d.ts +3 -1
  30. package/dist/runtime/composables/useScriptTriggerElement.js +46 -19
  31. package/dist/runtime/registry/google-adsense.js +11 -14
  32. package/dist/runtime/types.js +1 -1
  33. package/package.json +29 -28
  34. package/dist/client/_nuxt/builds/meta/e4092e18-9a58-41ab-947e-35e1f2082b75.json +0 -1
  35. package/dist/client/_nuxt/error-404.CHrXIISA.css +0 -1
  36. package/dist/client/_nuxt/error-500.CrsjMPPf.css +0 -1
@@ -1,282 +1,283 @@
1
- <script setup lang="ts">
2
- /// <reference types="vimeo__player" />
3
- import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
4
- import type { HTMLAttributes, ImgHTMLAttributes } from 'vue'
5
- import { defu } from 'defu'
6
- import type { ElementScriptTrigger } from '../types'
7
- import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
8
- import { useScriptVimeoPlayer } from '../registry/vimeo-player'
9
- import { useAsyncData, useHead } from '#imports'
10
-
11
- interface VimeoOptions {
12
- // copied from @types/vimeo__player
13
- id?: number | undefined
14
- url?: string | undefined
15
- autopause?: boolean | undefined
16
- autoplay?: boolean | undefined
17
- background?: boolean | undefined
18
- byline?: boolean | undefined
19
- color?: string | undefined
20
- controls?: boolean | undefined
21
- dnt?: boolean | undefined
22
- height?: number | undefined
23
-
24
- interactive_params?: string | undefined
25
- keyboard?: boolean | undefined
26
- loop?: boolean | undefined
27
- maxheight?: number | undefined
28
- maxwidth?: number | undefined
29
- muted?: boolean | undefined
30
- pip?: boolean | undefined
31
- playsinline?: boolean | undefined
32
- portrait?: boolean | undefined
33
- responsive?: boolean | undefined
34
- speed?: boolean | undefined
35
- quality?: Vimeo.VimeoVideoQuality | undefined
36
- texttrack?: string | undefined
37
- title?: boolean | undefined
38
- transparent?: boolean | undefined
39
- width?: number | undefined
40
- }
41
-
42
- const props = withDefaults(defineProps<{
43
- // custom
44
- trigger?: ElementScriptTrigger
45
- placeholderAttrs?: ImgHTMLAttributes
46
- rootAttrs?: HTMLAttributes
47
- aboveTheFold?: boolean
48
- vimeoOptions?: VimeoOptions
49
- id?: number | undefined
50
- url?: string | undefined
51
- }>(), {
52
- trigger: 'mousedown',
53
- })
54
-
55
- const emits = defineEmits<TEmits>()
56
-
57
- type EventMap<E extends keyof Vimeo.EventMap> = [event: Vimeo.EventMap[E], player: Vimeo]
58
-
59
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
60
- type TEmits = {
61
- play: EventMap<'play'>
62
- playing: EventMap<'playing'>
63
- pause: EventMap<'pause'>
64
- ended: EventMap<'ended'>
65
- timeupdate: EventMap<'timeupdate'>
66
- progress: EventMap<'progress'>
67
- seeking: EventMap<'seeking'>
68
- seeked: EventMap<'seeked'>
69
- texttrackchange: EventMap<'texttrackchange'>
70
- chapterchange: EventMap<'chapterchange'>
71
- cuechange: EventMap<'cuechange'>
72
- cuepoint: EventMap<'cuepoint'>
73
- volumechange: EventMap<'volumechange'>
74
- playbackratechange: EventMap<'playbackratechange'>
75
- bufferstart: EventMap<'bufferstart'>
76
- bufferend: EventMap<'bufferend'>
77
- error: EventMap<'error'>
78
- loaded: EventMap<'loaded'>
79
- durationchange: EventMap<'durationchange'>
80
- fullscreenchange: EventMap<'fullscreenchange'>
81
- qualitychange: EventMap<'qualitychange'>
82
- camerachange: EventMap<'camerachange'>
83
- resize: EventMap<'resize'>
84
- enterpictureinpicture: EventMap<'enterpictureinpicture'>
85
- leavepictureinpicture: EventMap<'leavepictureinpicture'>
86
- }
87
-
88
- const events: (keyof TEmits)[] = [
89
- 'play',
90
- 'playing',
91
- 'pause',
92
- 'ended',
93
- 'timeupdate',
94
- 'progress',
95
- 'seeking',
96
- 'seeked',
97
- 'texttrackchange',
98
- 'chapterchange',
99
- 'cuechange',
100
- 'cuepoint',
101
- 'volumechange',
102
- 'playbackratechange',
103
- 'bufferstart',
104
- 'bufferend',
105
- 'error',
106
- 'loaded',
107
- 'durationchange',
108
- 'fullscreenchange',
109
- 'qualitychange',
110
- 'camerachange',
111
- 'resize',
112
- 'enterpictureinpicture',
113
- 'leavepictureinpicture',
114
- ]
115
-
116
- const elVimeo = ref()
117
- const rootEl = ref()
118
-
119
- const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
120
- let clickTriggered = false
121
- if (props.trigger === 'mousedown') {
122
- trigger.then(() => {
123
- clickTriggered = true
124
- })
125
- }
126
- const ready = ref(false)
127
- const { onLoaded, status } = useScriptVimeoPlayer({
128
- scriptOptions: {
129
- trigger,
130
- },
131
- })
132
-
133
- if (import.meta.server) {
134
- // dns-prefetch https://i.vimeocdn.com
135
- useHead({
136
- link: [
137
- {
138
- rel: props.aboveTheFold ? 'preconnect' : 'dns-prefetch',
139
- href: 'https://i.vimeocdn.com',
140
- },
141
- ],
142
- })
143
- }
144
-
145
- const id = computed(() => {
146
- return props.vimeoOptions?.id || props.id
147
- })
148
-
149
- const { data: payload } = useAsyncData(
150
- `vimeo-embed:${id.value}`,
151
- // TODO ideally we cache this
152
- () => $fetch(`https://vimeo.com/api/v2/video/${id.value}.json`).then(res => (res as any)[0]),
153
- {
154
- watch: [id],
155
- },
156
- )
157
-
158
- const placeholder = computed(() => payload.value?.thumbnail_large)
159
-
160
- let player: Vimeo | undefined
161
- // we can't directly expose the player as vue will break the proxy
162
- defineExpose({
163
- play: () => player?.play(),
164
- pause: () => player?.pause(),
165
- getDuration: () => player?.getDuration(),
166
- getCurrentTime: () => player?.getCurrentTime(),
167
- setCurrentTime: (time: number) => player?.setCurrentTime(time),
168
- getVolume: () => player?.getVolume(),
169
- setVolume: (volume: number) => player?.setVolume(volume),
170
- getPaused: () => player?.getPaused(),
171
- getEnded: () => player?.getEnded(),
172
- getLoop: () => player?.getLoop(),
173
- setLoop: (loop: boolean) => player?.setLoop(loop),
174
- getPlaybackRate: () => player?.getPlaybackRate(),
175
- setPlaybackRate: (rate: number) => player?.setPlaybackRate(rate),
176
- })
177
-
178
- const width = computed(() => {
179
- return props.vimeoOptions?.width || elVimeo.value?.parentNode?.offsetWidth || 640
180
- })
181
-
182
- const height = computed(() => {
183
- return props.vimeoOptions?.height || elVimeo.value?.parentNode?.offsetHeight || 480
184
- })
185
-
186
- onMounted(() => {
187
- onLoaded(async ({ Vimeo }) => {
188
- const vimeoOptions = props.vimeoOptions || {}
189
- if (!vimeoOptions.id && props.id) {
190
- vimeoOptions.id = props.id
191
- }
192
- if (!vimeoOptions.url && props.url) {
193
- vimeoOptions.url = props.url
194
- }
195
- vimeoOptions.width = width.value
196
- vimeoOptions.height = height.value
197
- player = new Vimeo.Player(elVimeo.value, vimeoOptions)
198
- if (clickTriggered) {
199
- player!.play()
200
- clickTriggered = false
201
- }
202
- for (const event of events) {
203
- player!.on(event, (e: EventMap<typeof event>) => {
204
- // @ts-expect-error ts isn't able to infer the correct event type
205
- emits(event, e, player)
206
- if (event === 'loaded')
207
- ready.value = true
208
- })
209
- }
210
- })
211
- })
212
-
213
- watch(() => props.id, (v) => {
214
- if (v) {
215
- player?.loadVideo(Number(v))
216
- }
217
- })
218
- watch(status, (status) => {
219
- if (status === 'error') {
220
- // @ts-expect-error untyped
221
- emits('error')
222
- }
223
- })
224
-
225
- const rootAttrs = computed(() => {
226
- return defu(props.rootAttrs, {
227
- 'aria-busy': status.value === 'loading',
228
- 'aria-label': status.value === 'awaitingLoad'
229
- ? 'Vimeo Player - Placeholder'
230
- : status.value === 'loading'
231
- ? 'Vimeo Player - Loading'
232
- : 'Vimeo Player - Loaded',
233
- 'aria-live': 'polite',
234
- 'role': 'application',
235
- 'style': {
236
- maxWidth: '100%',
237
- width: `${width.value}px`,
238
- height: 'auto',
239
- aspectRatio: `16/9`,
240
- position: 'relative',
241
- backgroundColor: 'black',
242
- },
243
- }) as HTMLAttributes
244
- })
245
-
246
- const placeholderAttrs = computed(() => {
247
- return defu(props.placeholderAttrs, {
248
- src: placeholder.value,
249
- alt: '',
250
- loading: props.aboveTheFold ? 'eager' : 'lazy',
251
- // @ts-expect-error untyped
252
- fetchpriority: props.aboveTheFold ? 'high' : undefined,
253
- style: {
254
- cursor: 'pointer',
255
- width: '100%',
256
- objectFit: 'contain',
257
- height: '100%',
258
- },
259
- } satisfies ImgHTMLAttributes)
260
- })
261
-
262
- onBeforeUnmount(() => player?.unload())
263
- </script>
264
-
265
- <template>
266
- <div ref="rootEl" v-bind="rootAttrs">
267
- <div v-show="ready" ref="elVimeo" class="vimeo-player" />
268
- <slot v-if="!ready" v-bind="payload" :placeholder="placeholder" name="placeholder">
269
- <img v-if="placeholder" v-bind="placeholderAttrs">
270
- </slot>
271
- <slot v-if="status === 'loading'" name="loading">
272
- <ScriptLoadingIndicator color="white" />
273
- </slot>
274
- <slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
275
- <slot v-else-if="status === 'error'" name="error" />
276
- <slot />
277
- </div>
278
- </template>
279
-
1
+ <script setup lang="ts">
2
+ /// <reference types="vimeo__player" />
3
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
4
+ import type { HTMLAttributes, ImgHTMLAttributes } from 'vue'
5
+ import { defu } from 'defu'
6
+ import type { ElementScriptTrigger } from '../types'
7
+ import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
8
+ import { useScriptVimeoPlayer } from '../registry/vimeo-player'
9
+ import { useAsyncData, useHead } from '#imports'
10
+
11
+ interface VimeoOptions {
12
+ // copied from @types/vimeo__player
13
+ id?: number | undefined
14
+ url?: string | undefined
15
+ autopause?: boolean | undefined
16
+ autoplay?: boolean | undefined
17
+ background?: boolean | undefined
18
+ byline?: boolean | undefined
19
+ color?: string | undefined
20
+ controls?: boolean | undefined
21
+ dnt?: boolean | undefined
22
+ height?: number | undefined
23
+
24
+ interactive_params?: string | undefined
25
+ keyboard?: boolean | undefined
26
+ loop?: boolean | undefined
27
+ maxheight?: number | undefined
28
+ maxwidth?: number | undefined
29
+ muted?: boolean | undefined
30
+ pip?: boolean | undefined
31
+ playsinline?: boolean | undefined
32
+ portrait?: boolean | undefined
33
+ responsive?: boolean | undefined
34
+ speed?: boolean | undefined
35
+ quality?: Vimeo.VimeoVideoQuality | undefined
36
+ texttrack?: string | undefined
37
+ title?: boolean | undefined
38
+ transparent?: boolean | undefined
39
+ width?: number | undefined
40
+ }
41
+
42
+ const props = withDefaults(defineProps<{
43
+ // custom
44
+ trigger?: ElementScriptTrigger
45
+ placeholderAttrs?: ImgHTMLAttributes
46
+ rootAttrs?: HTMLAttributes
47
+ aboveTheFold?: boolean
48
+ vimeoOptions?: VimeoOptions
49
+ id?: number | undefined
50
+ url?: string | undefined
51
+ }>(), {
52
+ trigger: 'mousedown',
53
+ })
54
+
55
+ const emits = defineEmits<TEmits>()
56
+
57
+ type EventMap<E extends keyof Vimeo.EventMap> = [event: Vimeo.EventMap[E], player: Vimeo]
58
+
59
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
60
+ type TEmits = {
61
+ play: EventMap<'play'>
62
+ playing: EventMap<'playing'>
63
+ pause: EventMap<'pause'>
64
+ ended: EventMap<'ended'>
65
+ timeupdate: EventMap<'timeupdate'>
66
+ progress: EventMap<'progress'>
67
+ seeking: EventMap<'seeking'>
68
+ seeked: EventMap<'seeked'>
69
+ texttrackchange: EventMap<'texttrackchange'>
70
+ chapterchange: EventMap<'chapterchange'>
71
+ cuechange: EventMap<'cuechange'>
72
+ cuepoint: EventMap<'cuepoint'>
73
+ volumechange: EventMap<'volumechange'>
74
+ playbackratechange: EventMap<'playbackratechange'>
75
+ bufferstart: EventMap<'bufferstart'>
76
+ bufferend: EventMap<'bufferend'>
77
+ error: EventMap<'error'>
78
+ loaded: EventMap<'loaded'>
79
+ durationchange: EventMap<'durationchange'>
80
+ fullscreenchange: EventMap<'fullscreenchange'>
81
+ qualitychange: EventMap<'qualitychange'>
82
+ camerachange: EventMap<'camerachange'>
83
+ resize: EventMap<'resize'>
84
+ enterpictureinpicture: EventMap<'enterpictureinpicture'>
85
+ leavepictureinpicture: EventMap<'leavepictureinpicture'>
86
+ }
87
+
88
+ const events: (keyof TEmits)[] = [
89
+ 'play',
90
+ 'playing',
91
+ 'pause',
92
+ 'ended',
93
+ 'timeupdate',
94
+ 'progress',
95
+ 'seeking',
96
+ 'seeked',
97
+ 'texttrackchange',
98
+ 'chapterchange',
99
+ 'cuechange',
100
+ 'cuepoint',
101
+ 'volumechange',
102
+ 'playbackratechange',
103
+ 'bufferstart',
104
+ 'bufferend',
105
+ 'error',
106
+ 'loaded',
107
+ 'durationchange',
108
+ 'fullscreenchange',
109
+ 'qualitychange',
110
+ 'camerachange',
111
+ 'resize',
112
+ 'enterpictureinpicture',
113
+ 'leavepictureinpicture',
114
+ ]
115
+
116
+ const elVimeo = ref()
117
+ const rootEl = ref()
118
+
119
+ const trigger = useScriptTriggerElement({ trigger: props.trigger, el: rootEl })
120
+ let clickTriggered = false
121
+ if (props.trigger === 'mousedown' && trigger instanceof Promise) {
122
+ trigger.then(() => {
123
+ clickTriggered = true
124
+ })
125
+ }
126
+ const ready = ref(false)
127
+ const { onLoaded, status } = useScriptVimeoPlayer({
128
+ scriptOptions: {
129
+ trigger,
130
+ },
131
+ })
132
+
133
+ if (import.meta.server) {
134
+ // dns-prefetch https://i.vimeocdn.com
135
+ useHead({
136
+ link: [
137
+ {
138
+ rel: props.aboveTheFold ? 'preconnect' : 'dns-prefetch',
139
+ href: 'https://i.vimeocdn.com',
140
+ },
141
+ ],
142
+ })
143
+ }
144
+
145
+ const id = computed(() => {
146
+ return props.vimeoOptions?.id || props.id
147
+ })
148
+
149
+ const { data: payload } = useAsyncData(
150
+ `vimeo-embed:${id.value}`,
151
+ // TODO ideally we cache this
152
+ () => $fetch(`https://vimeo.com/api/v2/video/${id.value}.json`).then(res => (res as any)[0]),
153
+ {
154
+ watch: [id],
155
+ },
156
+ )
157
+
158
+ const placeholder = computed(() => payload.value?.thumbnail_large)
159
+
160
+ let player: Vimeo | undefined
161
+ // we can't directly expose the player as vue will break the proxy
162
+ defineExpose({
163
+ play: () => player?.play(),
164
+ pause: () => player?.pause(),
165
+ getDuration: () => player?.getDuration(),
166
+ getCurrentTime: () => player?.getCurrentTime(),
167
+ setCurrentTime: (time: number) => player?.setCurrentTime(time),
168
+ getVolume: () => player?.getVolume(),
169
+ setVolume: (volume: number) => player?.setVolume(volume),
170
+ getPaused: () => player?.getPaused(),
171
+ getEnded: () => player?.getEnded(),
172
+ getLoop: () => player?.getLoop(),
173
+ setLoop: (loop: boolean) => player?.setLoop(loop),
174
+ getPlaybackRate: () => player?.getPlaybackRate(),
175
+ setPlaybackRate: (rate: number) => player?.setPlaybackRate(rate),
176
+ })
177
+
178
+ const width = computed(() => {
179
+ return props.vimeoOptions?.width || elVimeo.value?.parentNode?.offsetWidth || 640
180
+ })
181
+
182
+ const height = computed(() => {
183
+ return props.vimeoOptions?.height || elVimeo.value?.parentNode?.offsetHeight || 480
184
+ })
185
+
186
+ onMounted(() => {
187
+ onLoaded(async ({ Vimeo }) => {
188
+ const vimeoOptions = props.vimeoOptions || {}
189
+ if (!vimeoOptions.id && props.id) {
190
+ vimeoOptions.id = props.id
191
+ }
192
+ if (!vimeoOptions.url && props.url) {
193
+ vimeoOptions.url = props.url
194
+ }
195
+ vimeoOptions.width = width.value
196
+ vimeoOptions.height = height.value
197
+ player = new Vimeo.Player(elVimeo.value, vimeoOptions)
198
+ if (clickTriggered) {
199
+ player!.play()
200
+ clickTriggered = false
201
+ }
202
+ for (const event of events) {
203
+ player!.on(event, (e: EventMap<typeof event>) => {
204
+ // @ts-expect-error ts isn't able to infer the correct event type
205
+ emits(event, e, player)
206
+ if (event === 'loaded')
207
+ ready.value = true
208
+ })
209
+ }
210
+ })
211
+ })
212
+
213
+ watch(() => props.id, (v) => {
214
+ if (v) {
215
+ player?.loadVideo(Number(v))
216
+ }
217
+ })
218
+ watch(status, (status) => {
219
+ if (status === 'error') {
220
+ // @ts-expect-error untyped
221
+ emits('error')
222
+ }
223
+ })
224
+
225
+ const rootAttrs = computed(() => {
226
+ return defu(props.rootAttrs, {
227
+ 'aria-busy': status.value === 'loading',
228
+ 'aria-label': status.value === 'awaitingLoad'
229
+ ? 'Vimeo Player - Placeholder'
230
+ : status.value === 'loading'
231
+ ? 'Vimeo Player - Loading'
232
+ : 'Vimeo Player - Loaded',
233
+ 'aria-live': 'polite',
234
+ 'role': 'application',
235
+ 'style': {
236
+ maxWidth: '100%',
237
+ width: `${width.value}px`,
238
+ height: 'auto',
239
+ aspectRatio: `16/9`,
240
+ position: 'relative',
241
+ backgroundColor: 'black',
242
+ },
243
+ ...(trigger instanceof Promise ? trigger.ssrAttrs || {} : {}),
244
+ }) as HTMLAttributes
245
+ })
246
+
247
+ const placeholderAttrs = computed(() => {
248
+ return defu(props.placeholderAttrs, {
249
+ src: placeholder.value,
250
+ alt: '',
251
+ loading: props.aboveTheFold ? 'eager' : 'lazy',
252
+ // @ts-expect-error untyped
253
+ fetchpriority: props.aboveTheFold ? 'high' : undefined,
254
+ style: {
255
+ cursor: 'pointer',
256
+ width: '100%',
257
+ objectFit: 'contain',
258
+ height: '100%',
259
+ },
260
+ } satisfies ImgHTMLAttributes)
261
+ })
262
+
263
+ onBeforeUnmount(() => player?.unload())
264
+ </script>
265
+
266
+ <template>
267
+ <div ref="rootEl" v-bind="rootAttrs">
268
+ <div v-show="ready" ref="elVimeo" class="vimeo-player" />
269
+ <slot v-if="!ready" v-bind="payload" :placeholder="placeholder" name="placeholder">
270
+ <img v-if="placeholder" v-bind="placeholderAttrs">
271
+ </slot>
272
+ <slot v-if="status === 'loading'" name="loading">
273
+ <ScriptLoadingIndicator color="white" />
274
+ </slot>
275
+ <slot v-if="status === 'awaitingLoad'" name="awaitingLoad" />
276
+ <slot v-else-if="status === 'error'" name="error" />
277
+ <slot />
278
+ </div>
279
+ </template>
280
+
280
281
  <style>
281
282
  .vimeo-player iframe{aspect-ratio:16/9;height:auto;max-width:100%!important;width:100%}
282
- </style>
283
+ </style>