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