@mixd-id/web-scaffold 0.1.230406214 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mixd-id/web-scaffold",
3
3
  "private": false,
4
- "version": "0.1.230406214",
4
+ "version": "0.1.230406215",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
@@ -1,12 +1,17 @@
1
1
  <template>
2
2
  <div :class="$style.comp" :style="computedStyle">
3
- <div id="player" :class="videoClass" class="relative" @click="loadVideo">
4
- <Image :src="thumbnailUrl" :class="videoClass" />
5
- <div class="absolute top-0 left-0 right-0 bottom-0 flex items-center justify-center">
6
- <div class="bg-primary-500 cursor-pointer hover:bg-primary-600 p-3 px-4 rounded-lg">
7
- <svg class="w-[16px] h-[16px] fill-white" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"/></svg>
8
- </div>
9
- </div>
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>
10
15
  </div>
11
16
  </div>
12
17
  </template>
@@ -15,34 +20,38 @@
15
20
 
16
21
  import { componentMixin } from '../mixin/component'
17
22
 
18
-
19
23
  export default{
20
24
 
21
- inject: [ 'alert' ],
22
-
23
25
  mixins: [ componentMixin ],
24
26
 
25
27
  props: {
26
28
 
27
- videoId: String
29
+ videoId: String,
30
+
31
+ delay: {
32
+ type: Number,
33
+ default: 1000
34
+ },
28
35
 
29
36
  },
30
37
 
31
38
  computed: {
32
39
 
33
40
  videoUrl(){
34
- return `https://www.youtube.com/embed/${this.videoId}?autoplay=1`
41
+ return `https://www.youtube.com/embed/${this.videoId}`
35
42
  },
36
43
 
37
- thumbnailUrl(){
38
- return `https://img.youtube.com/vi/${this.videoId}/0.jpg`
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
+ }
39
50
  },
40
51
 
41
52
  videoClass(){
42
53
  return [
43
54
  this.$style.video,
44
- /*this.width[0] ? `w-${this.width[0]}` : undefined,
45
- this.width[1] ? `md:w-${this.width[1]}` : undefined,*/
46
55
  ]
47
56
  .filter(_ => _)
48
57
  .join(' ')
@@ -50,6 +59,46 @@ export default{
50
59
 
51
60
  },
52
61
 
62
+ data(){
63
+ return {
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)
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
+
53
102
  methods: {
54
103
 
55
104
  loadVideo(){
@@ -60,43 +109,29 @@ export default{
60
109
  document.head.appendChild(script)
61
110
  }
62
111
  else{
63
-
64
112
  if(!this.player){
65
113
  this.player = new YT.Player('player', {
114
+ height: '100%',
115
+ width: '100%',
66
116
  videoId: this.videoId,
67
117
  playerVars: {
68
118
  autoplay: 1,
69
- controls: 0,
70
- rel: 0,
119
+ controls: 1,
71
120
  },
72
121
  events: {
73
- onReady: () => console.log('onReady'),
74
- onStateChange: () => console.log('onStateChange'),
75
- onAutoplayBlocked: () => this.alert('onAutoplayBlocked'),
122
+ onReady: () => {
123
+ window.setTimeout(() => this.ready = true, 500)
124
+ }
76
125
  }
77
- });
126
+ })
78
127
  }
79
128
  else{
80
129
  this.player.loadVideoById(this.videoId)
81
130
  }
82
131
  }
83
- }
84
132
 
85
- },
86
-
87
- mounted() {
88
- this.id = this.uniqid()
89
- window.onYouTubeIframeAPIReady = () => {
90
- this.loadVideo()
91
133
  }
92
- },
93
134
 
94
- data(){
95
- return {
96
- id: null,
97
- player: null,
98
- start: false
99
- }
100
135
  }
101
136
 
102
137
  }
@@ -106,7 +141,8 @@ export default{
106
141
  <style module>
107
142
 
108
143
  .comp{
109
- @apply flex flex-col;
144
+ @apply relative;
145
+ aspect-ratio: 16 / 9;
110
146
  }
111
147
 
112
148
  .video{