vidply 1.0.5 → 1.0.7

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.
@@ -1,257 +1,257 @@
1
- /**
2
- * Vimeo Renderer
3
- */
4
-
5
- export class VimeoRenderer {
6
- constructor(player) {
7
- this.player = player;
8
- this.vimeo = null;
9
- this.videoId = null;
10
- this.isReady = false;
11
- this.iframe = null;
12
- }
13
-
14
- async init() {
15
- // Extract video ID from URL
16
- this.videoId = this.extractVideoId(this.player.element.src);
17
-
18
- if (!this.videoId) {
19
- throw new Error('Invalid Vimeo URL');
20
- }
21
-
22
- // Load Vimeo Player API
23
- await this.loadVimeoAPI();
24
-
25
- // Create iframe
26
- this.createIframe();
27
-
28
- // Initialize player
29
- await this.initializePlayer();
30
- }
31
-
32
- extractVideoId(url) {
33
- const patterns = [
34
- /vimeo\.com\/(\d+)/,
35
- /vimeo\.com\/video\/(\d+)/,
36
- /player\.vimeo\.com\/video\/(\d+)/
37
- ];
38
-
39
- for (const pattern of patterns) {
40
- const match = url.match(pattern);
41
- if (match && match[1]) {
42
- return match[1];
43
- }
44
- }
45
-
46
- return null;
47
- }
48
-
49
- async loadVimeoAPI() {
50
- // Check if API is already loaded
51
- if (window.Vimeo && window.Vimeo.Player) {
52
- return Promise.resolve();
53
- }
54
-
55
- return new Promise((resolve, reject) => {
56
- const script = document.createElement('script');
57
- script.src = 'https://player.vimeo.com/api/player.js';
58
- script.onload = () => resolve();
59
- script.onerror = () => reject(new Error('Failed to load Vimeo API'));
60
- document.head.appendChild(script);
61
- });
62
- }
63
-
64
- createIframe() {
65
- // Hide original element
66
- this.player.element.style.display = 'none';
67
-
68
- // Create container for iframe
69
- this.iframe = document.createElement('div');
70
- this.iframe.id = `vimeo-player-${Math.random().toString(36).substr(2, 9)}`;
71
- this.iframe.style.width = '100%';
72
- this.iframe.style.height = '100%';
73
-
74
- this.player.element.parentNode.insertBefore(this.iframe, this.player.element);
75
- }
76
-
77
- async initializePlayer() {
78
- const options = {
79
- id: this.videoId,
80
- width: '100%',
81
- height: '100%',
82
- controls: false,
83
- autoplay: this.player.options.autoplay,
84
- muted: this.player.options.muted,
85
- loop: this.player.options.loop,
86
- keyboard: false
87
- };
88
-
89
- if (this.player.options.startTime > 0) {
90
- options.startTime = this.player.options.startTime;
91
- }
92
-
93
- this.vimeo = new window.Vimeo.Player(this.iframe.id, options);
94
-
95
- // Wait for player to be ready
96
- await this.vimeo.ready();
97
- this.isReady = true;
98
-
99
- this.attachEvents();
100
-
101
- // Get initial duration
102
- try {
103
- const duration = await this.vimeo.getDuration();
104
- this.player.state.duration = duration;
105
- this.player.emit('loadedmetadata');
106
- } catch (error) {
107
- this.player.log('Error getting duration:', error, 'warn');
108
- }
109
- }
110
-
111
- attachEvents() {
112
- this.vimeo.on('play', () => {
113
- this.player.state.playing = true;
114
- this.player.state.paused = false;
115
- this.player.state.ended = false;
116
- this.player.emit('play');
117
-
118
- if (this.player.options.onPlay) {
119
- this.player.options.onPlay.call(this.player);
120
- }
121
- });
122
-
123
- this.vimeo.on('pause', () => {
124
- this.player.state.playing = false;
125
- this.player.state.paused = true;
126
- this.player.emit('pause');
127
-
128
- if (this.player.options.onPause) {
129
- this.player.options.onPause.call(this.player);
130
- }
131
- });
132
-
133
- this.vimeo.on('ended', () => {
134
- this.player.state.playing = false;
135
- this.player.state.paused = true;
136
- this.player.state.ended = true;
137
- this.player.emit('ended');
138
-
139
- if (this.player.options.onEnded) {
140
- this.player.options.onEnded.call(this.player);
141
- }
142
- });
143
-
144
- this.vimeo.on('timeupdate', (data) => {
145
- this.player.state.currentTime = data.seconds;
146
- this.player.state.duration = data.duration;
147
- this.player.emit('timeupdate', data.seconds);
148
-
149
- if (this.player.options.onTimeUpdate) {
150
- this.player.options.onTimeUpdate.call(this.player, data.seconds);
151
- }
152
- });
153
-
154
- this.vimeo.on('volumechange', (data) => {
155
- this.player.state.volume = data.volume;
156
- this.player.emit('volumechange', data.volume);
157
- });
158
-
159
- this.vimeo.on('bufferstart', () => {
160
- this.player.state.buffering = true;
161
- this.player.emit('waiting');
162
- });
163
-
164
- this.vimeo.on('bufferend', () => {
165
- this.player.state.buffering = false;
166
- this.player.emit('canplay');
167
- });
168
-
169
- this.vimeo.on('seeking', () => {
170
- this.player.state.seeking = true;
171
- this.player.emit('seeking');
172
- });
173
-
174
- this.vimeo.on('seeked', () => {
175
- this.player.state.seeking = false;
176
- this.player.emit('seeked');
177
- });
178
-
179
- this.vimeo.on('playbackratechange', (data) => {
180
- this.player.state.playbackSpeed = data.playbackRate;
181
- this.player.emit('ratechange', data.playbackRate);
182
- });
183
-
184
- this.vimeo.on('error', (error) => {
185
- this.player.handleError(new Error(`Vimeo error: ${error.message}`));
186
- });
187
- }
188
-
189
- play() {
190
- if (this.isReady && this.vimeo) {
191
- this.vimeo.play().catch(error => {
192
- this.player.log('Play error:', error, 'warn');
193
- });
194
- }
195
- }
196
-
197
- pause() {
198
- if (this.isReady && this.vimeo) {
199
- this.vimeo.pause().catch(error => {
200
- this.player.log('Pause error:', error, 'warn');
201
- });
202
- }
203
- }
204
-
205
- seek(time) {
206
- if (this.isReady && this.vimeo) {
207
- this.vimeo.setCurrentTime(time).catch(error => {
208
- this.player.log('Seek error:', error, 'warn');
209
- });
210
- }
211
- }
212
-
213
- setVolume(volume) {
214
- if (this.isReady && this.vimeo) {
215
- this.vimeo.setVolume(volume).catch(error => {
216
- this.player.log('Volume error:', error, 'warn');
217
- });
218
- this.player.state.volume = volume;
219
- }
220
- }
221
-
222
- setMuted(muted) {
223
- if (this.isReady && this.vimeo) {
224
- if (muted) {
225
- this.vimeo.setVolume(0);
226
- } else {
227
- this.vimeo.setVolume(this.player.state.volume);
228
- }
229
- this.player.state.muted = muted;
230
- }
231
- }
232
-
233
- setPlaybackSpeed(speed) {
234
- if (this.isReady && this.vimeo) {
235
- this.vimeo.setPlaybackRate(speed).catch(error => {
236
- this.player.log('Playback rate error:', error, 'warn');
237
- });
238
- this.player.state.playbackSpeed = speed;
239
- }
240
- }
241
-
242
- destroy() {
243
- if (this.vimeo && this.vimeo.destroy) {
244
- this.vimeo.destroy();
245
- }
246
-
247
- if (this.iframe && this.iframe.parentNode) {
248
- this.iframe.parentNode.removeChild(this.iframe);
249
- }
250
-
251
- // Show original element
252
- if (this.player.element) {
253
- this.player.element.style.display = '';
254
- }
255
- }
256
- }
257
-
1
+ /**
2
+ * Vimeo Renderer
3
+ */
4
+
5
+ export class VimeoRenderer {
6
+ constructor(player) {
7
+ this.player = player;
8
+ this.vimeo = null;
9
+ this.videoId = null;
10
+ this.isReady = false;
11
+ this.iframe = null;
12
+ }
13
+
14
+ async init() {
15
+ // Extract video ID from URL
16
+ this.videoId = this.extractVideoId(this.player.element.src);
17
+
18
+ if (!this.videoId) {
19
+ throw new Error('Invalid Vimeo URL');
20
+ }
21
+
22
+ // Load Vimeo Player API
23
+ await this.loadVimeoAPI();
24
+
25
+ // Create iframe
26
+ this.createIframe();
27
+
28
+ // Initialize player
29
+ await this.initializePlayer();
30
+ }
31
+
32
+ extractVideoId(url) {
33
+ const patterns = [
34
+ /vimeo\.com\/(\d+)/,
35
+ /vimeo\.com\/video\/(\d+)/,
36
+ /player\.vimeo\.com\/video\/(\d+)/
37
+ ];
38
+
39
+ for (const pattern of patterns) {
40
+ const match = url.match(pattern);
41
+ if (match && match[1]) {
42
+ return match[1];
43
+ }
44
+ }
45
+
46
+ return null;
47
+ }
48
+
49
+ async loadVimeoAPI() {
50
+ // Check if API is already loaded
51
+ if (window.Vimeo && window.Vimeo.Player) {
52
+ return Promise.resolve();
53
+ }
54
+
55
+ return new Promise((resolve, reject) => {
56
+ const script = document.createElement('script');
57
+ script.src = 'https://player.vimeo.com/api/player.js';
58
+ script.onload = () => resolve();
59
+ script.onerror = () => reject(new Error('Failed to load Vimeo API'));
60
+ document.head.appendChild(script);
61
+ });
62
+ }
63
+
64
+ createIframe() {
65
+ // Hide original element
66
+ this.player.element.style.display = 'none';
67
+
68
+ // Create container for iframe
69
+ this.iframe = document.createElement('div');
70
+ this.iframe.id = `vimeo-player-${Math.random().toString(36).substr(2, 9)}`;
71
+ this.iframe.style.width = '100%';
72
+ this.iframe.style.height = '100%';
73
+
74
+ this.player.element.parentNode.insertBefore(this.iframe, this.player.element);
75
+ }
76
+
77
+ async initializePlayer() {
78
+ const options = {
79
+ id: this.videoId,
80
+ width: '100%',
81
+ height: '100%',
82
+ controls: false,
83
+ autoplay: this.player.options.autoplay,
84
+ muted: this.player.options.muted,
85
+ loop: this.player.options.loop,
86
+ keyboard: false
87
+ };
88
+
89
+ if (this.player.options.startTime > 0) {
90
+ options.startTime = this.player.options.startTime;
91
+ }
92
+
93
+ this.vimeo = new window.Vimeo.Player(this.iframe.id, options);
94
+
95
+ // Wait for player to be ready
96
+ await this.vimeo.ready();
97
+ this.isReady = true;
98
+
99
+ this.attachEvents();
100
+
101
+ // Get initial duration
102
+ try {
103
+ const duration = await this.vimeo.getDuration();
104
+ this.player.state.duration = duration;
105
+ this.player.emit('loadedmetadata');
106
+ } catch (error) {
107
+ this.player.log('Error getting duration:', error, 'warn');
108
+ }
109
+ }
110
+
111
+ attachEvents() {
112
+ this.vimeo.on('play', () => {
113
+ this.player.state.playing = true;
114
+ this.player.state.paused = false;
115
+ this.player.state.ended = false;
116
+ this.player.emit('play');
117
+
118
+ if (this.player.options.onPlay) {
119
+ this.player.options.onPlay.call(this.player);
120
+ }
121
+ });
122
+
123
+ this.vimeo.on('pause', () => {
124
+ this.player.state.playing = false;
125
+ this.player.state.paused = true;
126
+ this.player.emit('pause');
127
+
128
+ if (this.player.options.onPause) {
129
+ this.player.options.onPause.call(this.player);
130
+ }
131
+ });
132
+
133
+ this.vimeo.on('ended', () => {
134
+ this.player.state.playing = false;
135
+ this.player.state.paused = true;
136
+ this.player.state.ended = true;
137
+ this.player.emit('ended');
138
+
139
+ if (this.player.options.onEnded) {
140
+ this.player.options.onEnded.call(this.player);
141
+ }
142
+ });
143
+
144
+ this.vimeo.on('timeupdate', (data) => {
145
+ this.player.state.currentTime = data.seconds;
146
+ this.player.state.duration = data.duration;
147
+ this.player.emit('timeupdate', data.seconds);
148
+
149
+ if (this.player.options.onTimeUpdate) {
150
+ this.player.options.onTimeUpdate.call(this.player, data.seconds);
151
+ }
152
+ });
153
+
154
+ this.vimeo.on('volumechange', (data) => {
155
+ this.player.state.volume = data.volume;
156
+ this.player.emit('volumechange', data.volume);
157
+ });
158
+
159
+ this.vimeo.on('bufferstart', () => {
160
+ this.player.state.buffering = true;
161
+ this.player.emit('waiting');
162
+ });
163
+
164
+ this.vimeo.on('bufferend', () => {
165
+ this.player.state.buffering = false;
166
+ this.player.emit('canplay');
167
+ });
168
+
169
+ this.vimeo.on('seeking', () => {
170
+ this.player.state.seeking = true;
171
+ this.player.emit('seeking');
172
+ });
173
+
174
+ this.vimeo.on('seeked', () => {
175
+ this.player.state.seeking = false;
176
+ this.player.emit('seeked');
177
+ });
178
+
179
+ this.vimeo.on('playbackratechange', (data) => {
180
+ this.player.state.playbackSpeed = data.playbackRate;
181
+ this.player.emit('ratechange', data.playbackRate);
182
+ });
183
+
184
+ this.vimeo.on('error', (error) => {
185
+ this.player.handleError(new Error(`Vimeo error: ${error.message}`));
186
+ });
187
+ }
188
+
189
+ play() {
190
+ if (this.isReady && this.vimeo) {
191
+ this.vimeo.play().catch(error => {
192
+ this.player.log('Play error:', error, 'warn');
193
+ });
194
+ }
195
+ }
196
+
197
+ pause() {
198
+ if (this.isReady && this.vimeo) {
199
+ this.vimeo.pause().catch(error => {
200
+ this.player.log('Pause error:', error, 'warn');
201
+ });
202
+ }
203
+ }
204
+
205
+ seek(time) {
206
+ if (this.isReady && this.vimeo) {
207
+ this.vimeo.setCurrentTime(time).catch(error => {
208
+ this.player.log('Seek error:', error, 'warn');
209
+ });
210
+ }
211
+ }
212
+
213
+ setVolume(volume) {
214
+ if (this.isReady && this.vimeo) {
215
+ this.vimeo.setVolume(volume).catch(error => {
216
+ this.player.log('Volume error:', error, 'warn');
217
+ });
218
+ this.player.state.volume = volume;
219
+ }
220
+ }
221
+
222
+ setMuted(muted) {
223
+ if (this.isReady && this.vimeo) {
224
+ if (muted) {
225
+ this.vimeo.setVolume(0);
226
+ } else {
227
+ this.vimeo.setVolume(this.player.state.volume);
228
+ }
229
+ this.player.state.muted = muted;
230
+ }
231
+ }
232
+
233
+ setPlaybackSpeed(speed) {
234
+ if (this.isReady && this.vimeo) {
235
+ this.vimeo.setPlaybackRate(speed).catch(error => {
236
+ this.player.log('Playback rate error:', error, 'warn');
237
+ });
238
+ this.player.state.playbackSpeed = speed;
239
+ }
240
+ }
241
+
242
+ destroy() {
243
+ if (this.vimeo && this.vimeo.destroy) {
244
+ this.vimeo.destroy();
245
+ }
246
+
247
+ if (this.iframe && this.iframe.parentNode) {
248
+ this.iframe.parentNode.removeChild(this.iframe);
249
+ }
250
+
251
+ // Show original element
252
+ if (this.player.element) {
253
+ this.player.element.style.display = '';
254
+ }
255
+ }
256
+ }
257
+