@obipascal/player 1.0.3 → 1.0.5

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 CHANGED
@@ -215,6 +215,75 @@ function ControlPanel() {
215
215
  }
216
216
  ```
217
217
 
218
+ ### Using with Apollo Client / GraphQL
219
+
220
+ If you're using Apollo Client or other GraphQL clients for URL signing, use `useQuery` instead of `useLazyQuery` to avoid abort errors:
221
+
222
+ ```tsx
223
+ import React from "react"
224
+ import { S3Config, WontumPlayerReact } from "@obipascal/player"
225
+ import { useQuery } from "@apollo/client"
226
+ import { GET_MEDIA_SIGNED_URL } from "@/graphql/queries/media.queries"
227
+
228
+ interface VideoPlayerProps {
229
+ videoUrl: string
230
+ }
231
+
232
+ function VideoPlayer({ videoUrl }: VideoPlayerProps) {
233
+ // ✅ Use useQuery with skip option instead of useLazyQuery
234
+ const { refetch } = useQuery(GET_MEDIA_SIGNED_URL, {
235
+ skip: true, // Don't run on mount
236
+ fetchPolicy: "no-cache", // Always fetch fresh signed URLs
237
+ })
238
+
239
+ const url = new URL(videoUrl)
240
+
241
+ const s3config: S3Config = {
242
+ cloudFrontDomains: [url.hostname],
243
+ signUrl: async (resourceUrl: string) => {
244
+ try {
245
+ const { data } = await refetch({
246
+ signingMediaInput: {
247
+ resourceUrl,
248
+ isPublic: false,
249
+ type: "COOKIES",
250
+ },
251
+ })
252
+
253
+ console.log("Signed URL result:", data)
254
+ // For cookie-based signing, return the original URL
255
+ // The server sets cookies in the response
256
+ return resourceUrl
257
+ } catch (error) {
258
+ console.error("Failed to sign URL:", error)
259
+ throw error
260
+ }
261
+ },
262
+ }
263
+
264
+ return (
265
+ <WontumPlayerReact
266
+ src={videoUrl}
267
+ width="100%"
268
+ height="500px"
269
+ autoplay={false}
270
+ controls
271
+ s3Config={s3config}
272
+ theme={{
273
+ primaryColor: "#3b82f6",
274
+ accentColor: "#60a5fa",
275
+ }}
276
+ />
277
+ )
278
+ }
279
+ ```
280
+
281
+ **Why `useQuery` with `skip` instead of `useLazyQuery`?**
282
+
283
+ - `useLazyQuery` creates a new AbortController on each call, which can be aborted during React lifecycle
284
+ - `useQuery` with `skip: true` and `refetch` persists across renders, avoiding abort issues
285
+ - The SDK includes retry logic for AbortErrors, but using `useQuery` prevents them entirely
286
+
218
287
  ## 🔒 CloudFront & S3 Integration
219
288
 
220
289
  This player supports **three video hosting scenarios**. Choose the one that fits your needs:
@@ -1,4 +1,4 @@
1
- import { WontumPlayerConfig, PlayerState, PlayerEvent, PlayerEventType } from './types';
1
+ import { WontumPlayerConfig, PlayerState, PlayerEvent, PlayerEventType, QualityLevel } from './types';
2
2
  import { Analytics } from './analytics';
3
3
 
4
4
  /**
@@ -13,6 +13,7 @@ export declare class WontumPlayer {
13
13
  analytics: Analytics;
14
14
  private s3Handler;
15
15
  private uiController;
16
+ private qualities;
16
17
  private state;
17
18
  constructor(config: WontumPlayerConfig);
18
19
  private addSubtitleTracks;
@@ -32,6 +33,7 @@ export declare class WontumPlayer {
32
33
  unmute(): void;
33
34
  setPlaybackRate(rate: number): void;
34
35
  setQuality(qualityIndex: number): void;
36
+ getQualities(): QualityLevel[];
35
37
  enterFullscreen(): void;
36
38
  exitFullscreen(): void;
37
39
  getState(): PlayerState;
@@ -14,9 +14,6 @@ export declare class UIController {
14
14
  private skipForwardButton;
15
15
  private volumeButton;
16
16
  private fullscreenButton;
17
- private qualityButton;
18
- private subtitleButton;
19
- private speedButton;
20
17
  private settingsButton;
21
18
  private volumeSlider;
22
19
  private progressInput;
@@ -41,11 +38,8 @@ export declare class UIController {
41
38
  private getVolumeIcon;
42
39
  private getMutedIcon;
43
40
  private getFullscreenIcon;
44
- private getQualityIcon;
45
41
  private getSkipBackwardIcon;
46
42
  private getSkipForwardIcon;
47
- private getSubtitleIcon;
48
- private getSpeedIcon;
49
43
  private getSettingsIcon;
50
44
  destroy(): void;
51
45
  }
@@ -1,15 +1,15 @@
1
- "use strict";var lt=Object.defineProperty;var ct=(l,t,e)=>t in l?lt(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var o=(l,t,e)=>ct(l,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("hls.js"),v=require("react");function ut(l){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const e in l)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(l,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>l[e]})}}return t.default=l,Object.freeze(t)}const et=ut(v);class nt{constructor(t){o(this,"config");o(this,"sessionId");o(this,"events",[]);o(this,"sessionStartTime");o(this,"playbackStartTime",null);o(this,"totalPlayTime",0);o(this,"totalBufferTime",0);o(this,"bufferStartTime",null);o(this,"rebufferCount",0);o(this,"seekCount",0);var e;this.config=t,this.sessionId=(t==null?void 0:t.sessionId)||this.generateSessionId(),this.sessionStartTime=Date.now(),(e=this.config)!=null&&e.enabled&&this.trackEvent("session_start",this.getSessionData())}trackEvent(t,e={}){var r;if(!((r=this.config)!=null&&r.enabled))return;const s={eventType:t,timestamp:Date.now(),sessionId:this.sessionId,videoId:this.config.videoId,userId:this.config.userId,data:{...e,...this.getQoEMetrics()}};this.events.push(s),this.updateMetrics(t,e),this.config.endpoint&&this.sendEvent(s),process.env.NODE_ENV==="development"&&console.log("[Analytics]",t,s.data)}updateMetrics(t,e){switch(t){case"play":this.playbackStartTime=Date.now();break;case"pause":case"ended":this.playbackStartTime&&(this.totalPlayTime+=Date.now()-this.playbackStartTime,this.playbackStartTime=null);break;case"buffering_start":this.bufferStartTime=Date.now(),this.rebufferCount++;break;case"buffering_end":this.bufferStartTime&&(this.totalBufferTime+=Date.now()-this.bufferStartTime,this.bufferStartTime=null);break;case"seeked":this.seekCount++;break}}getQoEMetrics(){const t=Date.now()-this.sessionStartTime,e=this.totalPlayTime>0?this.totalBufferTime/this.totalPlayTime:0;return{sessionDuration:t,totalPlayTime:this.totalPlayTime,totalBufferTime:this.totalBufferTime,bufferingRatio:Math.round(e*1e3)/1e3,rebufferCount:this.rebufferCount,seekCount:this.seekCount}}getSessionData(){return{userAgent:navigator.userAgent,platform:navigator.platform,language:navigator.language,screenResolution:`${screen.width}x${screen.height}`,viewport:`${window.innerWidth}x${window.innerHeight}`,connection:this.getConnectionInfo()}}getConnectionInfo(){const t=navigator,e=t.connection||t.mozConnection||t.webkitConnection;return e?{effectiveType:e.effectiveType,downlink:e.downlink,rtt:e.rtt,saveData:e.saveData}:null}async sendEvent(t){var e;if((e=this.config)!=null&&e.endpoint)try{await fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(s){console.error("Failed to send analytics event:",s)}}generateSessionId(){return`session_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}getEvents(){return[...this.events]}getMetrics(){return{sessionId:this.sessionId,...this.getQoEMetrics(),eventCount:this.events.length}}destroy(){var t;(t=this.config)!=null&&t.enabled&&this.trackEvent("session_end",this.getSessionData()),this.events=[]}}class st{constructor(t,e){o(this,"container");o(this,"player");o(this,"controlsContainer");o(this,"progressContainer");o(this,"progressBar");o(this,"playButton");o(this,"skipBackwardButton");o(this,"skipForwardButton");o(this,"volumeButton");o(this,"fullscreenButton");o(this,"qualityButton");o(this,"subtitleButton");o(this,"speedButton");o(this,"settingsButton");o(this,"volumeSlider");o(this,"progressInput");o(this,"hideControlsTimeout",null);o(this,"stickyControls",!1);this.container=t,this.player=e,this.injectStyles(),this.createProgressBar(),this.controlsContainer=this.createControls(),this.container.appendChild(this.controlsContainer),this.playButton=this.controlsContainer.querySelector(".wontum-play-btn"),this.skipBackwardButton=this.controlsContainer.querySelector(".wontum-skip-backward-btn"),this.skipForwardButton=this.controlsContainer.querySelector(".wontum-skip-forward-btn"),this.volumeButton=this.controlsContainer.querySelector(".wontum-volume-btn"),this.fullscreenButton=this.controlsContainer.querySelector(".wontum-fullscreen-btn"),this.qualityButton=this.controlsContainer.querySelector(".wontum-quality-btn"),this.subtitleButton=this.controlsContainer.querySelector(".wontum-subtitle-btn"),this.speedButton=this.controlsContainer.querySelector(".wontum-speed-btn"),this.settingsButton=this.controlsContainer.querySelector(".wontum-settings-btn"),this.volumeSlider=this.controlsContainer.querySelector(".wontum-volume-slider"),this.progressInput=this.container.querySelector(".wontum-progress-input"),this.progressBar=this.container.querySelector(".wontum-progress-filled"),this.stickyControls=this.player.config.stickyControls||!1,this.stickyControls&&this.controlsContainer.classList.add("sticky"),this.setupEventListeners(),this.setupPlayerEventListeners()}injectStyles(){const t="wontum-player-styles";if(document.getElementById(t))return;const e=this.player.config.theme||{},s=e.primaryColor||"#3b82f6",r=e.accentColor||"#2563eb",i=e.fontFamily||"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",c=e.controlsBackground||"linear-gradient(to top, rgba(0,0,0,0.8), transparent)",u=e.buttonHoverBg||"rgba(255, 255, 255, 0.1)",f=e.progressHeight||"6px",b=e.borderRadius||"4px",y=document.createElement("style");y.id=t,y.textContent=`
1
+ "use strict";var V=Object.defineProperty;var W=(l,t,e)=>t in l?V(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var o=(l,t,e)=>W(l,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("hls.js"),I=require("react/jsx-runtime"),h=require("react");function _(l){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const e in l)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(l,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>l[e]})}}return t.default=l,Object.freeze(t)}const B=_(h);class P{constructor(t){o(this,"config");o(this,"sessionId");o(this,"events",[]);o(this,"sessionStartTime");o(this,"playbackStartTime",null);o(this,"totalPlayTime",0);o(this,"totalBufferTime",0);o(this,"bufferStartTime",null);o(this,"rebufferCount",0);o(this,"seekCount",0);var e;this.config=t,this.sessionId=(t==null?void 0:t.sessionId)||this.generateSessionId(),this.sessionStartTime=Date.now(),(e=this.config)!=null&&e.enabled&&this.trackEvent("session_start",this.getSessionData())}trackEvent(t,e={}){var i;if(!((i=this.config)!=null&&i.enabled))return;const n={eventType:t,timestamp:Date.now(),sessionId:this.sessionId,videoId:this.config.videoId,userId:this.config.userId,data:{...e,...this.getQoEMetrics()}};this.events.push(n),this.updateMetrics(t,e),this.config.endpoint&&this.sendEvent(n),process.env.NODE_ENV==="development"&&console.log("[Analytics]",t,n.data)}updateMetrics(t,e){switch(t){case"play":this.playbackStartTime=Date.now();break;case"pause":case"ended":this.playbackStartTime&&(this.totalPlayTime+=Date.now()-this.playbackStartTime,this.playbackStartTime=null);break;case"buffering_start":this.bufferStartTime=Date.now(),this.rebufferCount++;break;case"buffering_end":this.bufferStartTime&&(this.totalBufferTime+=Date.now()-this.bufferStartTime,this.bufferStartTime=null);break;case"seeked":this.seekCount++;break}}getQoEMetrics(){const t=Date.now()-this.sessionStartTime,e=this.totalPlayTime>0?this.totalBufferTime/this.totalPlayTime:0;return{sessionDuration:t,totalPlayTime:this.totalPlayTime,totalBufferTime:this.totalBufferTime,bufferingRatio:Math.round(e*1e3)/1e3,rebufferCount:this.rebufferCount,seekCount:this.seekCount}}getSessionData(){return{userAgent:navigator.userAgent,platform:navigator.platform,language:navigator.language,screenResolution:`${screen.width}x${screen.height}`,viewport:`${window.innerWidth}x${window.innerHeight}`,connection:this.getConnectionInfo()}}getConnectionInfo(){const t=navigator,e=t.connection||t.mozConnection||t.webkitConnection;return e?{effectiveType:e.effectiveType,downlink:e.downlink,rtt:e.rtt,saveData:e.saveData}:null}async sendEvent(t){var e;if((e=this.config)!=null&&e.endpoint)try{await fetch(this.config.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(n){console.error("Failed to send analytics event:",n)}}generateSessionId(){return`session_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}getEvents(){return[...this.events]}getMetrics(){return{sessionId:this.sessionId,...this.getQoEMetrics(),eventCount:this.events.length}}destroy(){var t;(t=this.config)!=null&&t.enabled&&this.trackEvent("session_end",this.getSessionData()),this.events=[]}}class ${constructor(t,e){o(this,"container");o(this,"player");o(this,"controlsContainer");o(this,"progressContainer");o(this,"progressBar");o(this,"playButton");o(this,"skipBackwardButton");o(this,"skipForwardButton");o(this,"volumeButton");o(this,"fullscreenButton");o(this,"settingsButton");o(this,"volumeSlider");o(this,"progressInput");o(this,"hideControlsTimeout",null);o(this,"stickyControls",!1);this.container=t,this.player=e,this.injectStyles(),this.createProgressBar(),this.controlsContainer=this.createControls(),this.container.appendChild(this.controlsContainer),this.playButton=this.controlsContainer.querySelector(".wontum-play-btn"),this.skipBackwardButton=this.controlsContainer.querySelector(".wontum-skip-backward-btn"),this.skipForwardButton=this.controlsContainer.querySelector(".wontum-skip-forward-btn"),this.volumeButton=this.controlsContainer.querySelector(".wontum-volume-btn"),this.fullscreenButton=this.controlsContainer.querySelector(".wontum-fullscreen-btn"),this.settingsButton=this.controlsContainer.querySelector(".wontum-settings-btn"),this.volumeSlider=this.controlsContainer.querySelector(".wontum-volume-slider"),this.progressInput=this.container.querySelector(".wontum-progress-input"),this.progressBar=this.container.querySelector(".wontum-progress-filled"),this.stickyControls=this.player.config.stickyControls||!1,this.stickyControls&&this.controlsContainer.classList.add("sticky"),this.setupEventListeners(),this.setupPlayerEventListeners()}injectStyles(){const t="wontum-player-styles";if(document.getElementById(t))return;const e=this.player.config.theme||{},n=e.primaryColor||"#3b82f6",i=e.accentColor||"#2563eb",s=e.fontFamily||"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",a=e.controlsBackground||"linear-gradient(to top, rgba(0,0,0,0.8), transparent)",r=e.buttonHoverBg||"rgba(255, 255, 255, 0.1)",c=e.progressHeight||"6px",u=e.borderRadius||"4px",g=document.createElement("style");g.id=t,g.textContent=`
2
2
  .wontum-player-container {
3
3
  position: relative;
4
4
  background: #000;
5
- font-family: ${i};
5
+ font-family: ${s};
6
6
  overflow: hidden;
7
- --primary-color: ${s};
8
- --accent-color: ${r};
9
- --controls-bg: ${c};
10
- --button-hover: ${u};
11
- --progress-height: ${f};
12
- --border-radius: ${b};
7
+ --primary-color: ${n};
8
+ --accent-color: ${i};
9
+ --controls-bg: ${a};
10
+ --button-hover: ${r};
11
+ --progress-height: ${c};
12
+ --border-radius: ${u};
13
13
  }
14
14
 
15
15
  .wontum-player-video {
@@ -278,21 +278,7 @@
278
278
  }
279
279
 
280
280
  .wontum-quality-menu {
281
- position: absolute;
282
- bottom: 100%;
283
- right: 0;
284
- background: rgba(20, 20, 20, 0.95);
285
- backdrop-filter: blur(10px);
286
- border-radius: 6px;
287
281
  padding: 6px 0;
288
- margin-bottom: 8px;
289
- display: none;
290
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
291
- min-width: 120px;
292
- }
293
-
294
- .wontum-quality-menu.active {
295
- display: block;
296
282
  }
297
283
 
298
284
  .wontum-quality-option {
@@ -315,21 +301,7 @@
315
301
  }
316
302
 
317
303
  .wontum-speed-menu {
318
- position: absolute;
319
- bottom: 100%;
320
- right: 0;
321
- background: rgba(20, 20, 20, 0.95);
322
- backdrop-filter: blur(10px);
323
- border-radius: 6px;
324
304
  padding: 6px 0;
325
- margin-bottom: 8px;
326
- display: none;
327
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
328
- min-width: 120px;
329
- }
330
-
331
- .wontum-speed-menu.active {
332
- display: block;
333
305
  }
334
306
 
335
307
  .wontum-speed-option {
@@ -351,24 +323,73 @@
351
323
  background: rgba(255, 255, 255, 0.05);
352
324
  }
353
325
 
354
- .wontum-settings-menu {
326
+ .wontum-settings-panel {
355
327
  position: absolute;
356
328
  bottom: 100%;
357
329
  right: 0;
358
330
  background: rgba(20, 20, 20, 0.95);
359
331
  backdrop-filter: blur(10px);
360
- border-radius: 6px;
361
- padding: 6px 0;
332
+ border-radius: 8px;
362
333
  margin-bottom: 8px;
363
- min-width: 200px;
334
+ min-width: 320px;
364
335
  display: none;
365
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
336
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
337
+ overflow: hidden;
338
+ }
339
+
340
+ .wontum-settings-panel.active {
341
+ display: flex;
342
+ flex-direction: column;
343
+ }
344
+
345
+ .wontum-settings-tabs {
346
+ display: flex;
347
+ background: rgba(0, 0, 0, 0.3);
348
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
349
+ }
350
+
351
+ .wontum-tab {
352
+ flex: 1;
353
+ padding: 10px 12px;
354
+ background: none;
355
+ border: none;
356
+ color: rgba(255, 255, 255, 0.7);
357
+ font-size: 12px;
358
+ cursor: pointer;
359
+ transition: all 0.2s ease;
360
+ border-bottom: 2px solid transparent;
361
+ font-family: inherit;
362
+ }
363
+
364
+ .wontum-tab:hover {
365
+ background: rgba(255, 255, 255, 0.05);
366
+ color: rgba(255, 255, 255, 0.9);
367
+ }
368
+
369
+ .wontum-tab.active {
370
+ color: var(--primary-color);
371
+ border-bottom-color: var(--primary-color);
372
+ background: rgba(59, 130, 246, 0.1);
373
+ }
374
+
375
+ .wontum-settings-content {
376
+ min-height: 120px;
377
+ max-height: 300px;
378
+ overflow-y: auto;
366
379
  }
367
380
 
368
- .wontum-settings-menu.active {
381
+ .wontum-tab-panel {
382
+ display: none;
383
+ }
384
+
385
+ .wontum-tab-panel.active {
369
386
  display: block;
370
387
  }
371
388
 
389
+ .wontum-settings-menu {
390
+ padding: 6px 0;
391
+ }
392
+
372
393
  .wontum-settings-option {
373
394
  padding: 12px 16px;
374
395
  cursor: pointer;
@@ -416,21 +437,7 @@
416
437
  }
417
438
 
418
439
  .wontum-subtitle-menu {
419
- position: absolute;
420
- bottom: 100%;
421
- right: 0;
422
- background: rgba(20, 20, 20, 0.95);
423
- backdrop-filter: blur(10px);
424
- border-radius: 6px;
425
440
  padding: 6px 0;
426
- margin-bottom: 8px;
427
- display: none;
428
- min-width: 150px;
429
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
430
- }
431
-
432
- .wontum-subtitle-menu.active {
433
- display: block;
434
441
  }
435
442
 
436
443
  .wontum-subtitle-option {
@@ -463,7 +470,7 @@
463
470
  transform: translateY(0) !important;
464
471
  pointer-events: all !important;
465
472
  }
466
- `,document.head.appendChild(y),this.container.classList.add("wontum-player-container")}createProgressBar(){const t=document.createElement("div");t.className="wontum-progress-container",t.innerHTML=`
473
+ `,document.head.appendChild(g),this.container.classList.add("wontum-player-container")}createProgressBar(){const t=document.createElement("div");t.className="wontum-progress-container",t.innerHTML=`
467
474
  <div class="wontum-progress-track"></div>
468
475
  <div class="wontum-progress-filled"></div>
469
476
  <input type="range" class="wontum-progress-input" min="0" max="100" value="0" step="0.1">
@@ -499,32 +506,32 @@
499
506
 
500
507
  <div class="wontum-spacer"></div>
501
508
 
502
- <div class="wontum-subtitle-container" style="position: relative;">
503
- <button class="wontum-btn wontum-subtitle-btn" aria-label="Subtitles">
504
- ${this.getSubtitleIcon()}
505
- </button>
506
- <div class="wontum-subtitle-menu"></div>
507
- </div>
508
-
509
- <div class="wontum-speed-container" style="position: relative;">
510
- <button class="wontum-btn wontum-speed-btn" aria-label="Playback Speed">
511
- ${this.getSpeedIcon()}
512
- </button>
513
- <div class="wontum-speed-menu"></div>
514
- </div>
515
-
516
- <div class="wontum-quality-container" style="position: relative;">
517
- <button class="wontum-btn wontum-quality-btn" aria-label="Quality">
518
- ${this.getQualityIcon()}
519
- </button>
520
- <div class="wontum-quality-menu"></div>
521
- </div>
522
-
523
509
  <div class="wontum-settings-container" style="position: relative;">
524
510
  <button class="wontum-btn wontum-settings-btn" aria-label="Settings">
525
511
  ${this.getSettingsIcon()}
526
512
  </button>
527
- <div class="wontum-settings-menu"></div>
513
+ <div class="wontum-settings-panel">
514
+ <div class="wontum-settings-tabs">
515
+ <button class="wontum-tab active" data-tab="general">General</button>
516
+ <button class="wontum-tab" data-tab="quality">Quality</button>
517
+ <button class="wontum-tab" data-tab="speed">Speed</button>
518
+ <button class="wontum-tab" data-tab="subtitles">Subtitles</button>
519
+ </div>
520
+ <div class="wontum-settings-content">
521
+ <div class="wontum-tab-panel active" data-panel="general">
522
+ <div class="wontum-settings-menu"></div>
523
+ </div>
524
+ <div class="wontum-tab-panel" data-panel="quality">
525
+ <div class="wontum-quality-menu"></div>
526
+ </div>
527
+ <div class="wontum-tab-panel" data-panel="speed">
528
+ <div class="wontum-speed-menu"></div>
529
+ </div>
530
+ <div class="wontum-tab-panel" data-panel="subtitles">
531
+ <div class="wontum-subtitle-menu"></div>
532
+ </div>
533
+ </div>
534
+ </div>
528
535
  </div>
529
536
 
530
537
  <button class="wontum-btn wontum-fullscreen-btn" aria-label="Fullscreen">
@@ -535,28 +542,28 @@
535
542
  <div class="wontum-loading" style="display: none;">
536
543
  <div class="wontum-spinner"></div>
537
544
  </div>
538
- `,t}setupEventListeners(){this.playButton.addEventListener("click",()=>{this.player.getState().playing?this.player.pause():this.player.play()}),this.skipBackwardButton.addEventListener("click",()=>{this.player.skipBackward(10)}),this.skipForwardButton.addEventListener("click",()=>{this.player.skipForward(10)}),this.progressInput.addEventListener("input",e=>{const s=e.target,r=parseFloat(s.value),i=this.player.getState(),c=r/100*i.duration;this.player.seek(c)}),this.volumeSlider.addEventListener("input",e=>{const s=e.target,r=parseFloat(s.value)/100;this.player.setVolume(r)}),this.volumeButton.addEventListener("click",()=>{this.player.getState().muted?this.player.unmute():this.player.mute()}),this.fullscreenButton.addEventListener("click",()=>{this.player.getState().fullscreen?this.player.exitFullscreen():this.player.enterFullscreen()}),this.qualityButton.addEventListener("click",()=>{var s,r,i;this.controlsContainer.querySelector(".wontum-quality-menu").classList.toggle("active"),(s=this.controlsContainer.querySelector(".wontum-settings-menu"))==null||s.classList.remove("active"),(r=this.controlsContainer.querySelector(".wontum-subtitle-menu"))==null||r.classList.remove("active"),(i=this.controlsContainer.querySelector(".wontum-speed-menu"))==null||i.classList.remove("active")}),this.subtitleButton.addEventListener("click",()=>{var s,r,i;this.controlsContainer.querySelector(".wontum-subtitle-menu").classList.toggle("active"),(s=this.controlsContainer.querySelector(".wontum-settings-menu"))==null||s.classList.remove("active"),(r=this.controlsContainer.querySelector(".wontum-quality-menu"))==null||r.classList.remove("active"),(i=this.controlsContainer.querySelector(".wontum-speed-menu"))==null||i.classList.remove("active"),this.updateSubtitleMenu()}),this.speedButton.addEventListener("click",()=>{var s,r,i;this.controlsContainer.querySelector(".wontum-speed-menu").classList.toggle("active"),(s=this.controlsContainer.querySelector(".wontum-settings-menu"))==null||s.classList.remove("active"),(r=this.controlsContainer.querySelector(".wontum-quality-menu"))==null||r.classList.remove("active"),(i=this.controlsContainer.querySelector(".wontum-subtitle-menu"))==null||i.classList.remove("active"),this.updateSpeedMenu()}),this.settingsButton.addEventListener("click",()=>{var s,r,i;this.controlsContainer.querySelector(".wontum-settings-menu").classList.toggle("active"),(s=this.controlsContainer.querySelector(".wontum-quality-menu"))==null||s.classList.remove("active"),(r=this.controlsContainer.querySelector(".wontum-subtitle-menu"))==null||r.classList.remove("active"),(i=this.controlsContainer.querySelector(".wontum-speed-menu"))==null||i.classList.remove("active"),this.updateSettingsMenu()}),this.player.getVideoElement().addEventListener("click",()=>{this.player.getState().playing?this.player.pause():this.player.play()}),this.container.addEventListener("mousemove",()=>{this.showControls(),this.resetHideControlsTimeout()}),this.container.addEventListener("mouseleave",()=>{this.hideControls()})}setupPlayerEventListeners(){this.player.on("play",()=>{this.playButton.innerHTML=this.getPauseIcon()}),this.player.on("pause",()=>{this.playButton.innerHTML=this.getPlayIcon()}),this.player.on("timeupdate",t=>{const{currentTime:e}=t.data,s=this.player.getState();if(s.duration>0){const i=e/s.duration*100;this.progressBar.style.width=`${i}%`,this.progressInput.value=i.toString()}const r=this.controlsContainer.querySelector(".wontum-current-time");r.textContent=this.formatTime(e)}),this.player.on("loadedmetadata",t=>{const{duration:e}=t.data,s=this.controlsContainer.querySelector(".wontum-duration");s.textContent=this.formatTime(e),t.data.qualities&&this.updateQualityMenu(t.data.qualities)}),this.player.on("volumechange",t=>{const{volume:e,muted:s}=t.data;this.volumeSlider.value=(e*100).toString(),this.volumeButton.innerHTML=s?this.getMutedIcon():this.getVolumeIcon()}),this.player.on("waiting",()=>{const t=this.controlsContainer.querySelector(".wontum-loading");t.style.display="block"}),this.player.on("canplay",()=>{const t=this.controlsContainer.querySelector(".wontum-loading");t.style.display="none"})}updateSubtitleMenu(){const t=this.controlsContainer.querySelector(".wontum-subtitle-menu"),e=this.player.getSubtitleTracks();if(e.length===0){t.innerHTML='<div class="wontum-subtitle-option">No subtitles available</div>';return}const s=e.findIndex(r=>r.mode==="showing");t.innerHTML=`
539
- <div class="wontum-subtitle-option ${s===-1?"active":""}" data-track="-1">Off</div>
540
- ${e.map((r,i)=>`
541
- <div class="wontum-subtitle-option ${i===s?"active":""}" data-track="${i}">
542
- ${r.label||r.language||`Track ${i+1}`}
545
+ `,t}setupEventListeners(){this.playButton.addEventListener("click",()=>{this.player.getState().playing?this.player.pause():this.player.play()}),this.skipBackwardButton.addEventListener("click",()=>{this.player.skipBackward(10)}),this.skipForwardButton.addEventListener("click",()=>{this.player.skipForward(10)}),this.progressInput.addEventListener("input",n=>{const i=n.target,s=parseFloat(i.value),a=this.player.getState(),r=s/100*a.duration;this.player.seek(r)}),this.volumeSlider.addEventListener("input",n=>{const i=n.target,s=parseFloat(i.value)/100;this.player.setVolume(s)}),this.volumeButton.addEventListener("click",()=>{this.player.getState().muted?this.player.unmute():this.player.mute()}),this.fullscreenButton.addEventListener("click",()=>{this.player.getState().fullscreen?this.player.exitFullscreen():this.player.enterFullscreen()}),this.settingsButton.addEventListener("click",()=>{const n=this.controlsContainer.querySelector(".wontum-settings-panel");n.classList.toggle("active"),n.classList.contains("active")&&(this.updateSettingsMenu(),this.updateQualityMenu(),this.updateSpeedMenu(),this.updateSubtitleMenu())});const t=this.controlsContainer.querySelectorAll(".wontum-tab");t.forEach(n=>{n.addEventListener("click",i=>{const s=i.currentTarget,a=s.getAttribute("data-tab");t.forEach(u=>u.classList.remove("active")),s.classList.add("active"),this.controlsContainer.querySelectorAll(".wontum-tab-panel").forEach(u=>u.classList.remove("active"));const c=this.controlsContainer.querySelector(`[data-panel="${a}"]`);c==null||c.classList.add("active")})}),this.player.getVideoElement().addEventListener("click",()=>{this.player.getState().playing?this.player.pause():this.player.play()}),this.container.addEventListener("mousemove",()=>{this.showControls(),this.resetHideControlsTimeout()}),this.container.addEventListener("mouseleave",()=>{this.hideControls()})}setupPlayerEventListeners(){this.player.on("play",()=>{this.playButton.innerHTML=this.getPauseIcon()}),this.player.on("pause",()=>{this.playButton.innerHTML=this.getPlayIcon()}),this.player.on("timeupdate",t=>{const{currentTime:e}=t.data,n=this.player.getState();if(n.duration>0){const s=e/n.duration*100;this.progressBar.style.width=`${s}%`,this.progressInput.value=s.toString()}const i=this.controlsContainer.querySelector(".wontum-current-time");i.textContent=this.formatTime(e)}),this.player.on("loadedmetadata",t=>{const{duration:e}=t.data,n=this.controlsContainer.querySelector(".wontum-duration");n.textContent=this.formatTime(e),t.data.qualities&&this.updateQualityMenu(t.data.qualities)}),this.player.on("volumechange",t=>{const{volume:e,muted:n}=t.data;this.volumeSlider.value=(e*100).toString(),this.volumeButton.innerHTML=n?this.getMutedIcon():this.getVolumeIcon()}),this.player.on("waiting",()=>{const t=this.controlsContainer.querySelector(".wontum-loading");t.style.display="block"}),this.player.on("canplay",()=>{const t=this.controlsContainer.querySelector(".wontum-loading");t.style.display="none"})}updateSubtitleMenu(){const t=this.controlsContainer.querySelector(".wontum-subtitle-menu"),e=this.player.getSubtitleTracks();if(e.length===0){t.innerHTML='<div class="wontum-subtitle-option">No subtitles available</div>';return}const n=e.findIndex(i=>i.mode==="showing");t.innerHTML=`
546
+ <div class="wontum-subtitle-option ${n===-1?"active":""}" data-track="-1">Off</div>
547
+ ${e.map((i,s)=>`
548
+ <div class="wontum-subtitle-option ${s===n?"active":""}" data-track="${s}">
549
+ ${i.label||i.language||`Track ${s+1}`}
543
550
  </div>
544
551
  `).join("")}
545
- `,t.querySelectorAll(".wontum-subtitle-option").forEach(r=>{r.addEventListener("click",i=>{const c=i.target,u=parseInt(c.dataset.track||"-1");u===-1?this.player.disableSubtitles():this.player.enableSubtitles(u),t.querySelectorAll(".wontum-subtitle-option").forEach(f=>f.classList.remove("active")),c.classList.add("active"),t.classList.remove("active")})})}updateSpeedMenu(){const t=this.controlsContainer.querySelector(".wontum-speed-menu"),s=this.player.getState().playbackRate||1,r=[.25,.5,.75,1,1.25,1.5,1.75,2];t.innerHTML=r.map(i=>`
546
- <div class="wontum-speed-option ${s===i?"active":""}" data-speed="${i}">
547
- ${i===1?"Normal":i+"x"}
552
+ `,t.querySelectorAll(".wontum-subtitle-option").forEach(i=>{i.addEventListener("click",s=>{const a=s.target,r=parseInt(a.dataset.track||"-1");r===-1?this.player.disableSubtitles():this.player.enableSubtitles(r),t.querySelectorAll(".wontum-subtitle-option").forEach(c=>c.classList.remove("active")),a.classList.add("active")})})}updateSpeedMenu(){const t=this.controlsContainer.querySelector(".wontum-speed-menu"),n=this.player.getState().playbackRate||1,i=[.25,.5,.75,1,1.25,1.5,1.75,2];t.innerHTML=i.map(s=>`
553
+ <div class="wontum-speed-option ${n===s?"active":""}" data-speed="${s}">
554
+ ${s===1?"Normal":s+"x"}
548
555
  </div>
549
- `).join(""),t.querySelectorAll(".wontum-speed-option").forEach(i=>{i.addEventListener("click",c=>{const u=c.target,f=parseFloat(u.dataset.speed||"1");this.player.setPlaybackRate(f),t.querySelectorAll(".wontum-speed-option").forEach(b=>b.classList.remove("active")),u.classList.add("active"),t.classList.remove("active")})})}updateSettingsMenu(){const t=this.controlsContainer.querySelector(".wontum-settings-menu");t.innerHTML=`
556
+ `).join(""),t.querySelectorAll(".wontum-speed-option").forEach(s=>{s.addEventListener("click",a=>{const r=a.target,c=parseFloat(r.dataset.speed||"1");this.player.setPlaybackRate(c),t.querySelectorAll(".wontum-speed-option").forEach(u=>u.classList.remove("active")),r.classList.add("active")})})}updateSettingsMenu(){const t=this.controlsContainer.querySelector(".wontum-settings-menu");t.innerHTML=`
550
557
  <div class="wontum-settings-option" data-setting="sticky-controls">
551
558
  <span>Sticky Controls</span>
552
559
  <div class="wontum-toggle-switch ${this.stickyControls?"active":""}"></div>
553
560
  </div>
554
- `;const e=t.querySelector('[data-setting="sticky-controls"]');e.addEventListener("click",()=>{this.stickyControls=!this.stickyControls,e.querySelector(".wontum-toggle-switch").classList.toggle("active"),this.stickyControls?(this.controlsContainer.classList.add("sticky"),this.progressContainer.classList.add("sticky")):(this.controlsContainer.classList.remove("sticky"),this.progressContainer.classList.remove("sticky"))})}updateQualityMenu(t){const e=this.controlsContainer.querySelector(".wontum-quality-menu");e.innerHTML=`
561
+ `;const e=t.querySelector('[data-setting="sticky-controls"]');e.addEventListener("click",()=>{this.stickyControls=!this.stickyControls,e.querySelector(".wontum-toggle-switch").classList.toggle("active"),this.stickyControls?(this.controlsContainer.classList.add("sticky"),this.progressContainer.classList.add("sticky")):(this.controlsContainer.classList.remove("sticky"),this.progressContainer.classList.remove("sticky"))})}updateQualityMenu(t){const e=this.controlsContainer.querySelector(".wontum-quality-menu"),n=t||this.player.getQualities();if(!n||n.length===0){e.innerHTML='<div class="wontum-quality-option">No qualities available</div>';return}e.innerHTML=`
555
562
  <div class="wontum-quality-option active" data-quality="-1">Auto</div>
556
- ${t.map((s,r)=>`
557
- <div class="wontum-quality-option" data-quality="${r}">${s.name}</div>
563
+ ${n.map((i,s)=>`
564
+ <div class="wontum-quality-option" data-quality="${s}">${i.name}</div>
558
565
  `).join("")}
559
- `,e.querySelectorAll(".wontum-quality-option").forEach(s=>{s.addEventListener("click",r=>{const i=r.target,c=parseInt(i.dataset.quality||"-1");this.player.setQuality(c),e.querySelectorAll(".wontum-quality-option").forEach(u=>u.classList.remove("active")),i.classList.add("active"),e.classList.remove("active")})})}showControls(){this.controlsContainer.classList.remove("hidden"),this.progressContainer.classList.remove("hidden")}hideControls(){if(this.stickyControls)return;this.player.getState().playing&&(this.controlsContainer.classList.add("hidden"),this.progressContainer.classList.add("hidden"))}resetHideControlsTimeout(){this.stickyControls||(this.hideControlsTimeout&&clearTimeout(this.hideControlsTimeout),this.hideControlsTimeout=window.setTimeout(()=>{this.hideControls()},1e4))}formatTime(t){if(isNaN(t))return"0:00";const e=Math.floor(t/60),s=Math.floor(t%60);return`${e}:${s.toString().padStart(2,"0")}`}getPlayIcon(){return'<svg viewBox="0 0 24 24"><path fill="white" d="M8 5v14l11-7z"/></svg>'}getPauseIcon(){return'<svg viewBox="0 0 24 24"><path fill="white" d="M6 4h4v16H6V4zm8 0h4v16h-4V4z"/></svg>'}getVolumeIcon(){return'<svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>'}getMutedIcon(){return'<svg viewBox="0 0 24 24"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>'}getFullscreenIcon(){return'<svg viewBox="0 0 24 24"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>'}getQualityIcon(){return'<svg viewBox="0 0 24 24"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-8 12H9.5v-2h-2v2H6V9h1.5v2.5h2V9H11v6zm7-1c0 .55-.45 1-1 1h-.75v1.5h-1.5V15H14c-.55 0-1-.45-1-1v-4c0-.55.45-1 1-1h3c.55 0 1 .45 1 1v4zm-3.5-.5h2v-3h-2v3z"/></svg>'}getSkipBackwardIcon(){return`<svg viewBox="0 0 60 60" fill="none" xmlns="http://www.w3.org/2000/svg">
566
+ `,e.querySelectorAll(".wontum-quality-option").forEach(i=>{i.addEventListener("click",s=>{const a=s.target,r=parseInt(a.dataset.quality||"-1");this.player.setQuality(r),e.querySelectorAll(".wontum-quality-option").forEach(c=>c.classList.remove("active")),a.classList.add("active")})})}showControls(){this.controlsContainer.classList.remove("hidden"),this.progressContainer.classList.remove("hidden")}hideControls(){if(this.stickyControls)return;this.player.getState().playing&&(this.controlsContainer.classList.add("hidden"),this.progressContainer.classList.add("hidden"))}resetHideControlsTimeout(){this.stickyControls||(this.hideControlsTimeout&&clearTimeout(this.hideControlsTimeout),this.hideControlsTimeout=window.setTimeout(()=>{this.hideControls()},1e4))}formatTime(t){if(isNaN(t))return"0:00";const e=Math.floor(t/60),n=Math.floor(t%60);return`${e}:${n.toString().padStart(2,"0")}`}getPlayIcon(){return'<svg viewBox="0 0 24 24"><path fill="white" d="M8 5v14l11-7z"/></svg>'}getPauseIcon(){return'<svg viewBox="0 0 24 24"><path fill="white" d="M6 4h4v16H6V4zm8 0h4v16h-4V4z"/></svg>'}getVolumeIcon(){return'<svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02z"/></svg>'}getMutedIcon(){return'<svg viewBox="0 0 24 24"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>'}getFullscreenIcon(){return'<svg viewBox="0 0 24 24"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>'}getSkipBackwardIcon(){return`<svg viewBox="0 0 60 60" fill="none" xmlns="http://www.w3.org/2000/svg">
560
567
  <circle cx="30" cy="30" r="28" stroke="white" stroke-width="2"/>
561
568
  <!-- Circular arrow backward -->
562
569
  <path d="M30 12 A18 18 0 1 0 30 48" stroke="white" stroke-width="2.5" stroke-linecap="round" fill="none"/>
@@ -568,25 +575,4 @@
568
575
  <path d="M30 12 A18 18 0 1 1 30 48" stroke="white" stroke-width="2.5" stroke-linecap="round" fill="none"/>
569
576
  <path d="M35 12 L30 12 L30 17" stroke="white" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
570
577
  <text x="30" y="35" font-family="Arial, sans-serif" font-size="14" font-weight="bold" fill="white" text-anchor="middle">10</text>
571
- </svg>`}getSubtitleIcon(){return'<svg viewBox="0 0 24 24"><path d="M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM4 12h4v2H4v-2zm10 6H4v-2h10v2zm6 0h-4v-2h4v2zm0-4H10v-2h10v2z"/></svg>'}getSpeedIcon(){return'<svg viewBox="0 0 24 24"><path d="M20.38 8.57l-1.23 1.85a8 8 0 0 1-.22 7.58H5.07A8 8 0 0 1 15.58 6.85l1.85-1.23A10 10 0 0 0 3.35 19a2 2 0 0 0 1.72 1h13.85a2 2 0 0 0 1.74-1 10 10 0 0 0-.27-10.44zm-9.79 6.84a2 2 0 0 0 2.83 0l5.66-8.49-8.49 5.66a2 2 0 0 0 0 2.83z"/></svg>'}getSettingsIcon(){return'<svg viewBox="0 0 24 24"><path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg>'}destroy(){this.hideControlsTimeout&&clearTimeout(this.hideControlsTimeout),this.controlsContainer.remove()}}class rt{constructor(t){o(this,"config");o(this,"urlCache",new Map);o(this,"signedUrls",new Set);this.config=t}async processUrl(t){return this.isCloudFrontUrl(t)?this.signCloudFrontUrl(t):this.isS3Url(t)?this.getPresignedUrl(t):t}isCloudFrontUrl(t){var e;if(!((e=this.config)!=null&&e.cloudFrontDomains)||this.config.cloudFrontDomains.length===0)return!1;try{const s=new URL(t);return this.config.cloudFrontDomains.some(r=>s.hostname.includes(r))}catch{return!1}}isS3Url(t){return t.includes(".s3.")||t.includes("s3.amazonaws.com")||t.startsWith("s3://")}async signCloudFrontUrl(t){var e;if(this.signedUrls.has(t))return t;if((e=this.config)!=null&&e.signUrl)try{const s=await this.config.signUrl(t);return this.signedUrls.add(t),s}catch(s){throw console.error("Failed to sign CloudFront URL:",s),new Error("Failed to sign CloudFront URL")}return console.warn("No signUrl function provided. CloudFront cookies may not be set."),t}extractS3Key(t){if(t.startsWith("s3://"))return t.replace("s3://","").split("/").slice(1).join("/");const e=t.match(/s3[.-]([^.]+)\.amazonaws\.com\/(.+)/);if(e)return e[2];const s=t.match(/([^.]+)\.s3\.amazonaws\.com\/(.+)/);return s?s[2]:t}async getPresignedUrl(t){var r;const e=this.extractS3Key(t),s=this.urlCache.get(e);if(s&&s.expiresAt>Date.now())return s.url;if((r=this.config)!=null&&r.getPresignedUrl)try{const i=await this.config.getPresignedUrl(e);return this.urlCache.set(e,{url:i,expiresAt:Date.now()+50*60*1e3}),i}catch(i){throw console.error("Failed to generate presigned URL:",i),new Error("Failed to generate presigned URL for S3 object")}return console.warn("No getPresignedUrl function provided. Using direct S3 URL (requires public bucket)"),t}static constructS3Url(t,e,s="us-east-1"){return`https://${t}.s3.${s}.amazonaws.com/${e}`}static parseS3Uri(t){if(!t.startsWith("s3://"))return null;const e=t.replace("s3://","").split("/"),s=e[0],r=e.slice(1).join("/");return{bucket:s,key:r}}clearCache(){this.urlCache.clear(),this.signedUrls.clear()}}class Y{constructor(t){o(this,"container");o(this,"videoElement");o(this,"hls",null);o(this,"config");o(this,"eventListeners",new Map);o(this,"analytics");o(this,"s3Handler");o(this,"uiController");o(this,"state",{playing:!1,paused:!0,ended:!1,buffering:!1,currentTime:0,duration:0,volume:1,muted:!1,playbackRate:1,quality:"auto",availableQualities:[],fullscreen:!1});if(this.config=t,this.container=typeof t.container=="string"?document.querySelector(t.container):t.container,!this.container)throw new Error("Container element not found");this.analytics=new nt(t.analytics),this.s3Handler=new rt(t.s3Config),this.videoElement=this.createVideoElement(),this.container.appendChild(this.videoElement),this.uiController=new st(this.container,this),this.setupVideoListeners(),this.loadSource(t.src),t.autoplay&&(this.videoElement.autoplay=!0),t.muted&&this.mute(),t.poster&&(this.videoElement.poster=t.poster),t.preload&&(this.videoElement.preload=t.preload),t.subtitles&&this.addSubtitleTracks(t.subtitles)}addSubtitleTracks(t){t.forEach(e=>{const s=document.createElement("track");s.kind="subtitles",s.label=e.label,s.src=e.src,s.srclang=e.srclang,e.default&&(s.default=!0),this.videoElement.appendChild(s)})}createVideoElement(){const t=document.createElement("video");return t.className="wontum-player-video",t.style.width="100%",t.style.height="100%",t.playsInline=!0,t}setupVideoListeners(){this.videoElement.addEventListener("play",()=>{this.state.playing=!0,this.state.paused=!1,this.emit("play"),this.analytics.trackEvent("play",this.getAnalyticsData())}),this.videoElement.addEventListener("pause",()=>{this.state.playing=!1,this.state.paused=!0,this.emit("pause"),this.analytics.trackEvent("pause",this.getAnalyticsData())}),this.videoElement.addEventListener("ended",()=>{this.state.ended=!0,this.state.playing=!1,this.emit("ended"),this.analytics.trackEvent("ended",this.getAnalyticsData())}),this.videoElement.addEventListener("timeupdate",()=>{this.state.currentTime=this.videoElement.currentTime,this.emit("timeupdate",{currentTime:this.state.currentTime})}),this.videoElement.addEventListener("loadedmetadata",()=>{this.state.duration=this.videoElement.duration,this.emit("loadedmetadata",{duration:this.state.duration}),this.analytics.trackEvent("loadedmetadata",this.getAnalyticsData())}),this.videoElement.addEventListener("volumechange",()=>{this.state.volume=this.videoElement.volume,this.state.muted=this.videoElement.muted,this.emit("volumechange",{volume:this.state.volume,muted:this.state.muted})}),this.videoElement.addEventListener("ratechange",()=>{this.state.playbackRate=this.videoElement.playbackRate,this.emit("ratechange",{playbackRate:this.state.playbackRate})}),this.videoElement.addEventListener("waiting",()=>{this.state.buffering=!0,this.emit("waiting"),this.analytics.trackEvent("buffering_start",this.getAnalyticsData())}),this.videoElement.addEventListener("canplay",()=>{this.state.buffering=!1,this.emit("canplay"),this.analytics.trackEvent("buffering_end",this.getAnalyticsData())}),this.videoElement.addEventListener("seeking",()=>{this.emit("seeking")}),this.videoElement.addEventListener("seeked",()=>{this.emit("seeked",{currentTime:this.state.currentTime}),this.analytics.trackEvent("seeked",this.getAnalyticsData())}),this.videoElement.addEventListener("error",t=>{const e=this.videoElement.error;this.emit("error",{error:e}),this.analytics.trackEvent("error",{...this.getAnalyticsData(),error:e==null?void 0:e.message})}),this.videoElement.addEventListener("loadstart",()=>{this.emit("loadstart")}),this.videoElement.addEventListener("loadeddata",()=>{this.emit("loadeddata")}),this.videoElement.addEventListener("canplaythrough",()=>{this.emit("canplaythrough")}),this.videoElement.addEventListener("playing",()=>{this.state.playing=!0,this.state.buffering=!1,this.emit("playing")}),this.videoElement.addEventListener("durationchange",()=>{this.state.duration=this.videoElement.duration,this.emit("durationchange",{duration:this.state.duration})}),this.videoElement.addEventListener("progress",()=>{this.emit("progress",{buffered:this.videoElement.buffered})}),this.videoElement.addEventListener("stalled",()=>{this.emit("stalled")}),this.videoElement.addEventListener("suspend",()=>{this.emit("suspend")}),this.videoElement.addEventListener("abort",()=>{this.emit("abort")}),this.videoElement.addEventListener("emptied",()=>{this.emit("emptied")}),this.videoElement.addEventListener("resize",()=>{this.emit("resize",{videoWidth:this.videoElement.videoWidth,videoHeight:this.videoElement.videoHeight})})}async loadSource(t){try{const e=await this.s3Handler.processUrl(t);if(E.isSupported())this.hls=new E(this.config.hlsConfig),this.hls.loadSource(e),this.hls.attachMedia(this.videoElement),this.hls.on(E.Events.MANIFEST_PARSED,(s,r)=>{const i=this.extractQualities(r.levels);this.state.availableQualities=i.map(c=>c.name),this.emit("loadedmetadata",{qualities:i})}),this.hls.on(E.Events.LEVEL_SWITCHED,(s,r)=>{var c;const i=(c=this.hls)==null?void 0:c.levels[r.level];i&&(this.state.quality=`${i.height}p`,this.emit("qualitychange",{quality:this.state.quality}))}),this.hls.on(E.Events.ERROR,(s,r)=>{r.fatal&&this.handleHlsError(r)});else if(this.videoElement.canPlayType("application/vnd.apple.mpegurl"))this.videoElement.src=e;else throw new Error("HLS is not supported in this browser")}catch(e){console.error("Failed to load video source:",e),this.emit("error",{error:e})}}extractQualities(t){return t.map(e=>({height:e.height,width:e.width,bitrate:e.bitrate,name:`${e.height}p`}))}handleHlsError(t){var e,s;switch(t.type){case E.ErrorTypes.NETWORK_ERROR:console.error("Network error occurred"),(e=this.hls)==null||e.startLoad();break;case E.ErrorTypes.MEDIA_ERROR:console.error("Media error occurred"),(s=this.hls)==null||s.recoverMediaError();break;default:console.error("Fatal error occurred:",t),this.destroy();break}}getAnalyticsData(){return{currentTime:this.state.currentTime,duration:this.state.duration,quality:this.state.quality,playbackRate:this.state.playbackRate,volume:this.state.volume,muted:this.state.muted}}play(){return this.videoElement.play()}pause(){this.videoElement.pause()}seek(t){this.videoElement.currentTime=t}skipForward(t=10){const e=Math.min(this.state.currentTime+t,this.state.duration);this.seek(e)}skipBackward(t=10){const e=Math.max(this.state.currentTime-t,0);this.seek(e)}setVolume(t){this.videoElement.volume=Math.max(0,Math.min(1,t))}mute(){this.videoElement.muted=!0}unmute(){this.videoElement.muted=!1}setPlaybackRate(t){this.videoElement.playbackRate=t}setQuality(t){this.hls&&(this.hls.currentLevel=t)}enterFullscreen(){this.container.requestFullscreen&&(this.container.requestFullscreen(),this.state.fullscreen=!0,this.emit("fullscreenchange",{fullscreen:!0}))}exitFullscreen(){document.exitFullscreen&&(document.exitFullscreen(),this.state.fullscreen=!1,this.emit("fullscreenchange",{fullscreen:!1}))}getState(){return{...this.state}}getVideoElement(){return this.videoElement}enableSubtitles(t){const e=this.videoElement.textTracks;for(let s=0;s<e.length;s++)e[s].mode=s===t?"showing":"hidden"}disableSubtitles(){const t=this.videoElement.textTracks;for(let e=0;e<t.length;e++)t[e].mode="hidden"}toggleSubtitles(){const t=this.videoElement.textTracks;return Array.from(t).some(s=>s.mode==="showing")?(this.disableSubtitles(),!1):t.length>0?(this.enableSubtitles(0),!0):!1}getSubtitleTracks(){return Array.from(this.videoElement.textTracks)}areSubtitlesEnabled(){const t=this.videoElement.textTracks;return Array.from(t).some(e=>e.mode==="showing")}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,new Set),this.eventListeners.get(t).add(e)}off(t,e){var s;(s=this.eventListeners.get(t))==null||s.delete(e)}emit(t,e){var r;const s={type:t,data:e,timestamp:Date.now()};(r=this.eventListeners.get(t))==null||r.forEach(i=>{i(s)})}destroy(){this.hls&&(this.hls.destroy(),this.hls=null),this.uiController.destroy(),this.videoElement.remove(),this.eventListeners.clear(),this.analytics.destroy()}}var W={exports:{}},q={};/**
572
- * @license React
573
- * react-jsx-runtime.production.js
574
- *
575
- * Copyright (c) Meta Platforms, Inc. and affiliates.
576
- *
577
- * This source code is licensed under the MIT license found in the
578
- * LICENSE file in the root directory of this source tree.
579
- */var K;function dt(){if(K)return q;K=1;var l=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function e(s,r,i){var c=null;if(i!==void 0&&(c=""+i),r.key!==void 0&&(c=""+r.key),"key"in r){i={};for(var u in r)u!=="key"&&(i[u]=r[u])}else i=r;return r=i.ref,{$$typeof:l,type:s,key:c,ref:r!==void 0?r:null,props:i}}return q.Fragment=t,q.jsx=e,q.jsxs=e,q}var P={};/**
580
- * @license React
581
- * react-jsx-runtime.development.js
582
- *
583
- * Copyright (c) Meta Platforms, Inc. and affiliates.
584
- *
585
- * This source code is licensed under the MIT license found in the
586
- * LICENSE file in the root directory of this source tree.
587
- */var tt;function ht(){return tt||(tt=1,process.env.NODE_ENV!=="production"&&function(){function l(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===z?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case x:return"Fragment";case $:return"Profiler";case B:return"StrictMode";case H:return"Suspense";case N:return"SuspenseList";case R:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case I:return"Portal";case j:return n.displayName||"Context";case O:return(n._context.displayName||"Context")+".Consumer";case F:var a=n.render;return n=n.displayName,n||(n=a.displayName||a.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case L:return a=n.displayName||null,a!==null?a:l(n.type)||"Memo";case k:a=n._payload,n=n._init;try{return l(n(a))}catch{}}return null}function t(n){return""+n}function e(n){try{t(n);var a=!1}catch{a=!0}if(a){a=console;var d=a.error,h=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return d.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",h),t(n)}}function s(n){if(n===x)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===k)return"<...>";try{var a=l(n);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function r(){var n=_.A;return n===null?null:n.getOwner()}function i(){return Error("react-stack-top-frame")}function c(n){if(p.call(n,"key")){var a=Object.getOwnPropertyDescriptor(n,"key").get;if(a&&a.isReactWarning)return!1}return n.key!==void 0}function u(n,a){function d(){Q||(Q=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",a))}d.isReactWarning=!0,Object.defineProperty(n,"key",{get:d,configurable:!0})}function f(){var n=l(this.type);return J[n]||(J[n]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),n=this.props.ref,n!==void 0?n:null}function b(n,a,d,h,D,U){var m=d.ref;return n={$$typeof:T,type:n,key:a,props:d,_owner:h},(m!==void 0?m:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:f}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function y(n,a,d,h,D,U){var m=a.children;if(m!==void 0)if(h)if(g(m)){for(h=0;h<m.length;h++)A(m[h]);Object.freeze&&Object.freeze(m)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else A(m);if(p.call(a,"key")){m=l(n);var C=Object.keys(a).filter(function(at){return at!=="key"});h=0<C.length?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}",Z[m+h]||(C=0<C.length?"{"+C.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
588
- let props = %s;
589
- <%s {...props} />
590
- React keys must be passed directly to JSX without using spread:
591
- let props = %s;
592
- <%s key={someKey} {...props} />`,h,m,C,m),Z[m+h]=!0)}if(m=null,d!==void 0&&(e(d),m=""+d),c(a)&&(e(a.key),m=""+a.key),"key"in a){d={};for(var V in a)V!=="key"&&(d[V]=a[V])}else d=a;return m&&u(d,typeof n=="function"?n.displayName||n.name||"Unknown":n),b(n,m,d,r(),D,U)}function A(n){M(n)?n._store&&(n._store.validated=1):typeof n=="object"&&n!==null&&n.$$typeof===k&&(n._payload.status==="fulfilled"?M(n._payload.value)&&n._payload.value._store&&(n._payload.value._store.validated=1):n._store&&(n._store.validated=1))}function M(n){return typeof n=="object"&&n!==null&&n.$$typeof===T}var w=v,T=Symbol.for("react.transitional.element"),I=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),B=Symbol.for("react.strict_mode"),$=Symbol.for("react.profiler"),O=Symbol.for("react.consumer"),j=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),H=Symbol.for("react.suspense"),N=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),R=Symbol.for("react.activity"),z=Symbol.for("react.client.reference"),_=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,p=Object.prototype.hasOwnProperty,g=Array.isArray,S=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(n){return n()}};var Q,J={},X=w.react_stack_bottom_frame.bind(w,i)(),G=S(s(i)),Z={};P.Fragment=x,P.jsx=function(n,a,d){var h=1e4>_.recentlyCreatedOwnerStacks++;return y(n,a,d,!1,h?Error("react-stack-top-frame"):X,h?S(s(n)):G)},P.jsxs=function(n,a,d){var h=1e4>_.recentlyCreatedOwnerStacks++;return y(n,a,d,!0,h?Error("react-stack-top-frame"):X,h?S(s(n)):G)}}()),P}process.env.NODE_ENV==="production"?W.exports=dt():W.exports=ht();var it=W.exports;const mt=l=>{const{src:t,autoplay:e,muted:s,controls:r=!0,poster:i,preload:c,theme:u,s3Config:f,analytics:b,hlsConfig:y,subtitles:A,stickyControls:M,onReady:w,onPlay:T,onPause:I,onEnded:x,onTimeUpdate:B,onVolumeChange:$,onError:O,onLoadedMetadata:j,onQualityChange:F,style:H,className:N,width:L="100%",height:k="500px"}=l,R=v.useRef(null),z=v.useRef(null);return v.useEffect(()=>{if(!R.current)return;const _={src:t,container:R.current,autoplay:e,muted:s,controls:r,poster:i,preload:c,theme:u,s3Config:f,analytics:b,hlsConfig:y,subtitles:A,stickyControls:M},p=new Y(_);return z.current=p,T&&p.on("play",T),I&&p.on("pause",I),x&&p.on("ended",x),O&&p.on("error",g=>{var S;return O((S=g.data)==null?void 0:S.error)}),j&&p.on("loadedmetadata",j),F&&p.on("qualitychange",g=>F(g.data.level)),B&&p.on("timeupdate",g=>B(g.data.currentTime)),$&&p.on("volumechange",g=>$(g.data.volume,g.data.muted)),w&&w(p),()=>{p.destroy(),z.current=null}},[t]),it.jsx("div",{ref:R,className:N,style:{width:typeof L=="number"?`${L}px`:L,height:typeof k=="number"?`${k}px`:k,...H}})},pt=l=>{const[t,e]=v.useState(null),[s,r]=v.useState(null),i=v.useRef(null);return v.useEffect(()=>{if(!i.current)return;const c=new Y({...l,container:i.current});e(c);const u=()=>{r(c.getState())};return c.on("play",u),c.on("pause",u),c.on("timeupdate",u),c.on("volumechange",u),c.on("loadedmetadata",u),()=>{c.destroy()}},[l.src]),{containerRef:i,player:t,state:s}},ot=et.createContext({player:null,state:null}),vt=l=>{const{player:t,children:e}=l,[s,r]=v.useState(t.getState());return v.useEffect(()=>{const i=()=>{r(t.getState())};return t.on("play",i),t.on("pause",i),t.on("timeupdate",i),t.on("volumechange",i),t.on("loadedmetadata",i),()=>{}},[t]),it.jsx(ot.Provider,{value:{player:t,state:s},children:e})},gt=()=>{const l=et.useContext(ot);if(!l.player)throw new Error("useWontumPlayerContext must be used within WontumPlayerProvider");return l};exports.Analytics=nt;exports.S3Handler=rt;exports.UIController=st;exports.WontumPlayer=Y;exports.WontumPlayerProvider=vt;exports.WontumPlayerReact=mt;exports.useWontumPlayer=pt;exports.useWontumPlayerContext=gt;
578
+ </svg>`}getSettingsIcon(){return'<svg viewBox="0 0 24 24"><path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/></svg>'}destroy(){this.hideControlsTimeout&&clearTimeout(this.hideControlsTimeout),this.controlsContainer.remove()}}class F{constructor(t){o(this,"config");o(this,"urlCache",new Map);o(this,"signedUrls",new Set);this.config=t}async processUrl(t){return this.isCloudFrontUrl(t)?this.signCloudFrontUrl(t):this.isS3Url(t)?this.getPresignedUrl(t):t}isCloudFrontUrl(t){var e;if(!((e=this.config)!=null&&e.cloudFrontDomains)||this.config.cloudFrontDomains.length===0)return!1;try{const n=new URL(t);return this.config.cloudFrontDomains.some(i=>n.hostname.includes(i))}catch{return!1}}isS3Url(t){return t.includes(".s3.")||t.includes("s3.amazonaws.com")||t.startsWith("s3://")}async signCloudFrontUrl(t,e=0){var s,a;if(this.signedUrls.has(t))return t;if((s=this.config)!=null&&s.signUrl)try{const r=await this.config.signUrl(t);return this.signedUrls.add(t),r}catch(r){const c=(r==null?void 0:r.name)==="AbortError"||((a=r==null?void 0:r.message)==null?void 0:a.includes("aborted"));if(c&&e<2)return console.warn(`Sign URL aborted, retrying (${e+1}/2)...`),await new Promise(u=>setTimeout(u,300)),this.signCloudFrontUrl(t,e+1);throw console.error("Failed to sign CloudFront URL:",r),c?new Error("Failed to sign CloudFront URL: Request was aborted. If using Apollo Client or other GraphQL clients, consider moving the query outside component lifecycle or using useQuery with skip option."):new Error(`Failed to sign CloudFront URL: ${(r==null?void 0:r.message)||"Unknown error"}`)}return console.warn("No signUrl function provided. CloudFront cookies may not be set."),t}extractS3Key(t){if(t.startsWith("s3://"))return t.replace("s3://","").split("/").slice(1).join("/");const e=t.match(/s3[.-]([^.]+)\.amazonaws\.com\/(.+)/);if(e)return e[2];const n=t.match(/([^.]+)\.s3\.amazonaws\.com\/(.+)/);return n?n[2]:t}async getPresignedUrl(t){var i;const e=this.extractS3Key(t),n=this.urlCache.get(e);if(n&&n.expiresAt>Date.now())return n.url;if((i=this.config)!=null&&i.getPresignedUrl)try{const s=await this.config.getPresignedUrl(e);return this.urlCache.set(e,{url:s,expiresAt:Date.now()+50*60*1e3}),s}catch(s){throw console.error("Failed to generate presigned URL:",s),new Error("Failed to generate presigned URL for S3 object")}return console.warn("No getPresignedUrl function provided. Using direct S3 URL (requires public bucket)"),t}static constructS3Url(t,e,n="us-east-1"){return`https://${t}.s3.${n}.amazonaws.com/${e}`}static parseS3Uri(t){if(!t.startsWith("s3://"))return null;const e=t.replace("s3://","").split("/"),n=e[0],i=e.slice(1).join("/");return{bucket:n,key:i}}clearCache(){this.urlCache.clear(),this.signedUrls.clear()}}class b{constructor(t){o(this,"container");o(this,"videoElement");o(this,"hls",null);o(this,"config");o(this,"eventListeners",new Map);o(this,"analytics");o(this,"s3Handler");o(this,"uiController");o(this,"qualities",[]);o(this,"state",{playing:!1,paused:!0,ended:!1,buffering:!1,currentTime:0,duration:0,volume:1,muted:!1,playbackRate:1,quality:"auto",availableQualities:[],fullscreen:!1});if(this.config=t,this.container=typeof t.container=="string"?document.querySelector(t.container):t.container,!this.container)throw new Error("Container element not found");this.analytics=new P(t.analytics),this.s3Handler=new F(t.s3Config),this.videoElement=this.createVideoElement(),this.container.appendChild(this.videoElement),this.uiController=new $(this.container,this),this.setupVideoListeners(),this.loadSource(t.src),t.autoplay&&(this.videoElement.autoplay=!0),t.muted&&this.mute(),t.poster&&(this.videoElement.poster=t.poster),t.preload&&(this.videoElement.preload=t.preload),t.subtitles&&this.addSubtitleTracks(t.subtitles)}addSubtitleTracks(t){t.forEach(e=>{const n=document.createElement("track");n.kind="subtitles",n.label=e.label,n.src=e.src,n.srclang=e.srclang,e.default&&(n.default=!0),this.videoElement.appendChild(n)})}createVideoElement(){const t=document.createElement("video");return t.className="wontum-player-video",t.style.width="100%",t.style.height="100%",t.playsInline=!0,t}setupVideoListeners(){this.videoElement.addEventListener("play",()=>{this.state.playing=!0,this.state.paused=!1,this.emit("play"),this.analytics.trackEvent("play",this.getAnalyticsData())}),this.videoElement.addEventListener("pause",()=>{this.state.playing=!1,this.state.paused=!0,this.emit("pause"),this.analytics.trackEvent("pause",this.getAnalyticsData())}),this.videoElement.addEventListener("ended",()=>{this.state.ended=!0,this.state.playing=!1,this.emit("ended"),this.analytics.trackEvent("ended",this.getAnalyticsData())}),this.videoElement.addEventListener("timeupdate",()=>{this.state.currentTime=this.videoElement.currentTime,this.emit("timeupdate",{currentTime:this.state.currentTime})}),this.videoElement.addEventListener("loadedmetadata",()=>{this.state.duration=this.videoElement.duration,this.emit("loadedmetadata",{duration:this.state.duration}),this.analytics.trackEvent("loadedmetadata",this.getAnalyticsData())}),this.videoElement.addEventListener("volumechange",()=>{this.state.volume=this.videoElement.volume,this.state.muted=this.videoElement.muted,this.emit("volumechange",{volume:this.state.volume,muted:this.state.muted})}),this.videoElement.addEventListener("ratechange",()=>{this.state.playbackRate=this.videoElement.playbackRate,this.emit("ratechange",{playbackRate:this.state.playbackRate})}),this.videoElement.addEventListener("waiting",()=>{this.state.buffering=!0,this.emit("waiting"),this.analytics.trackEvent("buffering_start",this.getAnalyticsData())}),this.videoElement.addEventListener("canplay",()=>{this.state.buffering=!1,this.emit("canplay"),this.analytics.trackEvent("buffering_end",this.getAnalyticsData())}),this.videoElement.addEventListener("seeking",()=>{this.emit("seeking")}),this.videoElement.addEventListener("seeked",()=>{this.emit("seeked",{currentTime:this.state.currentTime}),this.analytics.trackEvent("seeked",this.getAnalyticsData())}),this.videoElement.addEventListener("error",t=>{const e=this.videoElement.error;this.emit("error",{error:e}),this.analytics.trackEvent("error",{...this.getAnalyticsData(),error:e==null?void 0:e.message})}),this.videoElement.addEventListener("loadstart",()=>{this.emit("loadstart")}),this.videoElement.addEventListener("loadeddata",()=>{this.emit("loadeddata")}),this.videoElement.addEventListener("canplaythrough",()=>{this.emit("canplaythrough")}),this.videoElement.addEventListener("playing",()=>{this.state.playing=!0,this.state.buffering=!1,this.emit("playing")}),this.videoElement.addEventListener("durationchange",()=>{this.state.duration=this.videoElement.duration,this.emit("durationchange",{duration:this.state.duration})}),this.videoElement.addEventListener("progress",()=>{this.emit("progress",{buffered:this.videoElement.buffered})}),this.videoElement.addEventListener("stalled",()=>{this.emit("stalled")}),this.videoElement.addEventListener("suspend",()=>{this.emit("suspend")}),this.videoElement.addEventListener("abort",()=>{this.emit("abort")}),this.videoElement.addEventListener("emptied",()=>{this.emit("emptied")}),this.videoElement.addEventListener("resize",()=>{this.emit("resize",{videoWidth:this.videoElement.videoWidth,videoHeight:this.videoElement.videoHeight})})}async loadSource(t){try{const e=await this.s3Handler.processUrl(t);if(m.isSupported())this.hls=new m(this.config.hlsConfig),this.hls.loadSource(e),this.hls.attachMedia(this.videoElement),this.hls.on(m.Events.MANIFEST_PARSED,(n,i)=>{const s=this.extractQualities(i.levels);this.qualities=s}),this.hls.on(m.Events.LEVEL_SWITCHED,(n,i)=>{var a;const s=(a=this.hls)==null?void 0:a.levels[i.level];s&&(this.state.quality=`${s.height}p`,this.emit("qualitychange",{quality:this.state.quality}))}),this.hls.on(m.Events.ERROR,(n,i)=>{i.fatal&&this.handleHlsError(i)});else if(this.videoElement.canPlayType("application/vnd.apple.mpegurl"))this.videoElement.src=e;else throw new Error("HLS is not supported in this browser")}catch(e){console.error("Failed to load video source:",e),this.emit("error",{error:e})}}extractQualities(t){return t.map(e=>({height:e.height,width:e.width,bitrate:e.bitrate,name:`${e.height}p`}))}handleHlsError(t){var e,n;switch(t.type){case m.ErrorTypes.NETWORK_ERROR:console.error("Network error occurred"),(e=this.hls)==null||e.startLoad();break;case m.ErrorTypes.MEDIA_ERROR:console.error("Media error occurred"),(n=this.hls)==null||n.recoverMediaError();break;default:console.error("Fatal error occurred:",t),this.destroy();break}}getAnalyticsData(){return{currentTime:this.state.currentTime,duration:this.state.duration,quality:this.state.quality,playbackRate:this.state.playbackRate,volume:this.state.volume,muted:this.state.muted}}play(){return this.videoElement.play()}pause(){this.videoElement.pause()}seek(t){this.videoElement.currentTime=t}skipForward(t=10){const e=Math.min(this.state.currentTime+t,this.state.duration);this.seek(e)}skipBackward(t=10){const e=Math.max(this.state.currentTime-t,0);this.seek(e)}setVolume(t){this.videoElement.volume=Math.max(0,Math.min(1,t))}mute(){this.videoElement.muted=!0}unmute(){this.videoElement.muted=!1}setPlaybackRate(t){this.videoElement.playbackRate=t}setQuality(t){this.hls&&(this.hls.currentLevel=t)}getQualities(){return this.qualities}enterFullscreen(){this.container.requestFullscreen&&(this.container.requestFullscreen(),this.state.fullscreen=!0,this.emit("fullscreenchange",{fullscreen:!0}))}exitFullscreen(){document.exitFullscreen&&(document.exitFullscreen(),this.state.fullscreen=!1,this.emit("fullscreenchange",{fullscreen:!1}))}getState(){return{...this.state}}getVideoElement(){return this.videoElement}enableSubtitles(t){const e=this.videoElement.textTracks;for(let n=0;n<e.length;n++)e[n].mode=n===t?"showing":"hidden"}disableSubtitles(){const t=this.videoElement.textTracks;for(let e=0;e<t.length;e++)t[e].mode="hidden"}toggleSubtitles(){const t=this.videoElement.textTracks;return Array.from(t).some(n=>n.mode==="showing")?(this.disableSubtitles(),!1):t.length>0?(this.enableSubtitles(0),!0):!1}getSubtitleTracks(){return Array.from(this.videoElement.textTracks)}areSubtitlesEnabled(){const t=this.videoElement.textTracks;return Array.from(t).some(e=>e.mode==="showing")}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,new Set),this.eventListeners.get(t).add(e)}off(t,e){var n;(n=this.eventListeners.get(t))==null||n.delete(e)}emit(t,e){var i;const n={type:t,data:e,timestamp:Date.now()};(i=this.eventListeners.get(t))==null||i.forEach(s=>{s(n)})}destroy(){this.hls&&(this.hls.destroy(),this.hls=null),this.uiController.destroy(),this.videoElement.remove(),this.eventListeners.clear(),this.analytics.destroy()}}const N=l=>{const{src:t,autoplay:e,muted:n,controls:i=!0,poster:s,preload:a,theme:r,s3Config:c,analytics:u,hlsConfig:g,subtitles:U,stickyControls:D,onReady:f,onPlay:k,onPause:E,onEnded:x,onTimeUpdate:S,onVolumeChange:C,onError:L,onLoadedMetadata:T,onQualityChange:q,style:z,className:H,width:v="100%",height:y="500px"}=l,w=h.useRef(null),M=h.useRef(null);return h.useEffect(()=>{if(!w.current)return;const j={src:t,container:w.current,autoplay:e,muted:n,controls:i,poster:s,preload:a,theme:r,s3Config:c,analytics:u,hlsConfig:g,subtitles:U,stickyControls:D},d=new b(j);return M.current=d,k&&d.on("play",k),E&&d.on("pause",E),x&&d.on("ended",x),L&&d.on("error",p=>{var R;return L((R=p.data)==null?void 0:R.error)}),T&&d.on("loadedmetadata",T),q&&d.on("qualitychange",p=>q(p.data.level)),S&&d.on("timeupdate",p=>S(p.data.currentTime)),C&&d.on("volumechange",p=>C(p.data.volume,p.data.muted)),f&&f(d),()=>{d.destroy(),M.current=null}},[t]),I.jsx("div",{ref:w,className:H,style:{width:typeof v=="number"?`${v}px`:v,height:typeof y=="number"?`${y}px`:y,...z}})},Q=l=>{const[t,e]=h.useState(null),[n,i]=h.useState(null),s=h.useRef(null);return h.useEffect(()=>{if(!s.current)return;const a=new b({...l,container:s.current});e(a);const r=()=>{i(a.getState())};return a.on("play",r),a.on("pause",r),a.on("timeupdate",r),a.on("volumechange",r),a.on("loadedmetadata",r),()=>{a.destroy()}},[l.src]),{containerRef:s,player:t,state:n}},A=B.createContext({player:null,state:null}),O=l=>{const{player:t,children:e}=l,[n,i]=h.useState(t.getState());return h.useEffect(()=>{const s=()=>{i(t.getState())};return t.on("play",s),t.on("pause",s),t.on("timeupdate",s),t.on("volumechange",s),t.on("loadedmetadata",s),()=>{}},[t]),I.jsx(A.Provider,{value:{player:t,state:n},children:e})},Y=()=>{const l=B.useContext(A);if(!l.player)throw new Error("useWontumPlayerContext must be used within WontumPlayerProvider");return l};exports.Analytics=P;exports.S3Handler=F;exports.UIController=$;exports.WontumPlayer=b;exports.WontumPlayerProvider=O;exports.WontumPlayerReact=N;exports.useWontumPlayer=Q;exports.useWontumPlayerContext=Y;