@mixd-id/web-scaffold 0.1.230406213 → 0.1.230406215
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/package.json +1 -1
- package/src/components/YoutubeVideo.vue +97 -20
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div :class="$style.comp" :style="computedStyle">
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<
|
|
13
|
-
</
|
|
14
|
-
</
|
|
3
|
+
<div :class="videoClass" class="absolute top-0 left-0 right-0 bottom-0 z-10"
|
|
4
|
+
:style="{ opacity:ready ? 1 : 0 }">
|
|
5
|
+
<div id="player"></div>
|
|
6
|
+
</div>
|
|
7
|
+
<div :class="videoClass" class="relative flex items-center justify-center"
|
|
8
|
+
:style="thumbnailStyle">
|
|
9
|
+
<button class="w-[68px] h-[48px]" aria-label="Play" title="Play">
|
|
10
|
+
<svg height="100%" version="1.1" viewBox="0 0 68 48" width="100%">
|
|
11
|
+
<path class="ytp-large-play-button-bg" d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z" fill="#333"></path>
|
|
12
|
+
<path d="M 45,24 27,14 27,34" fill="#fff"></path>
|
|
13
|
+
</svg>
|
|
14
|
+
</button>
|
|
15
15
|
</div>
|
|
16
16
|
</div>
|
|
17
17
|
</template>
|
|
@@ -26,25 +26,32 @@ export default{
|
|
|
26
26
|
|
|
27
27
|
props: {
|
|
28
28
|
|
|
29
|
-
videoId: String
|
|
29
|
+
videoId: String,
|
|
30
|
+
|
|
31
|
+
delay: {
|
|
32
|
+
type: Number,
|
|
33
|
+
default: 1000
|
|
34
|
+
},
|
|
30
35
|
|
|
31
36
|
},
|
|
32
37
|
|
|
33
38
|
computed: {
|
|
34
39
|
|
|
35
40
|
videoUrl(){
|
|
36
|
-
return `https://www.youtube.com/embed/${this.videoId}
|
|
41
|
+
return `https://www.youtube.com/embed/${this.videoId}`
|
|
37
42
|
},
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
return
|
|
44
|
+
thumbnailStyle(){
|
|
45
|
+
return {
|
|
46
|
+
'background-image': `url('https://img.youtube.com/vi/${this.videoId}/0.jpg')`,
|
|
47
|
+
'background-size': 'cover',
|
|
48
|
+
'background-position': 'center center',
|
|
49
|
+
}
|
|
41
50
|
},
|
|
42
51
|
|
|
43
52
|
videoClass(){
|
|
44
53
|
return [
|
|
45
54
|
this.$style.video,
|
|
46
|
-
/*this.width[0] ? `w-${this.width[0]}` : undefined,
|
|
47
|
-
this.width[1] ? `md:w-${this.width[1]}` : undefined,*/
|
|
48
55
|
]
|
|
49
56
|
.filter(_ => _)
|
|
50
57
|
.join(' ')
|
|
@@ -54,8 +61,77 @@ export default{
|
|
|
54
61
|
|
|
55
62
|
data(){
|
|
56
63
|
return {
|
|
57
|
-
start: false
|
|
64
|
+
start: false,
|
|
65
|
+
ready: false,
|
|
66
|
+
mountedAt: null,
|
|
67
|
+
player: null
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
mounted() {
|
|
72
|
+
this.mountedAt = new Date().getTime()
|
|
73
|
+
|
|
74
|
+
if(this.delay){
|
|
75
|
+
window.setTimeout(() => {
|
|
76
|
+
if(!this.ready){
|
|
77
|
+
this.loadVideo()
|
|
78
|
+
}
|
|
79
|
+
}, this.delay)
|
|
58
80
|
}
|
|
81
|
+
|
|
82
|
+
this.$observe.once(this.$el, () => {
|
|
83
|
+
if(new Date().getTime() - this.mountedAt < this.delay){
|
|
84
|
+
window.setTimeout(() => {
|
|
85
|
+
if(!this.ready){
|
|
86
|
+
this.loadVideo()
|
|
87
|
+
}
|
|
88
|
+
}, this.delay - (new Date().getTime() - this.mountedAt))
|
|
89
|
+
}
|
|
90
|
+
else{
|
|
91
|
+
if(!this.ready){
|
|
92
|
+
this.loadVideo()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
window.onYouTubeIframeAPIReady = () => {
|
|
98
|
+
this.loadVideo()
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
methods: {
|
|
103
|
+
|
|
104
|
+
loadVideo(){
|
|
105
|
+
|
|
106
|
+
if(!('YT' in window)){
|
|
107
|
+
const script = document.createElement('script')
|
|
108
|
+
script.src = 'https://www.youtube.com/iframe_api'
|
|
109
|
+
document.head.appendChild(script)
|
|
110
|
+
}
|
|
111
|
+
else{
|
|
112
|
+
if(!this.player){
|
|
113
|
+
this.player = new YT.Player('player', {
|
|
114
|
+
height: '100%',
|
|
115
|
+
width: '100%',
|
|
116
|
+
videoId: this.videoId,
|
|
117
|
+
playerVars: {
|
|
118
|
+
autoplay: 1,
|
|
119
|
+
controls: 1,
|
|
120
|
+
},
|
|
121
|
+
events: {
|
|
122
|
+
onReady: () => {
|
|
123
|
+
window.setTimeout(() => this.ready = true, 500)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
else{
|
|
129
|
+
this.player.loadVideoById(this.videoId)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
59
135
|
}
|
|
60
136
|
|
|
61
137
|
}
|
|
@@ -65,7 +141,8 @@ export default{
|
|
|
65
141
|
<style module>
|
|
66
142
|
|
|
67
143
|
.comp{
|
|
68
|
-
@apply
|
|
144
|
+
@apply relative;
|
|
145
|
+
aspect-ratio: 16 / 9;
|
|
69
146
|
}
|
|
70
147
|
|
|
71
148
|
.video{
|