strataplayer 1.2.13 → 1.2.15
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/dist/core/StrataCore.d.ts +25 -13
- package/dist/strataplayer.cjs.js +6 -6
- package/dist/strataplayer.cjs.js.map +1 -1
- package/dist/strataplayer.es.js +890 -679
- package/dist/strataplayer.es.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/ui/Icons.d.ts +30 -0
- package/dist/ui/components/Menu.d.ts +10 -2
- package/dist/utils/playerUtils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -54,9 +54,30 @@ export interface ContextMenuItem {
|
|
|
54
54
|
onClick?: (close: () => void) => void;
|
|
55
55
|
click?: (close: () => void) => void;
|
|
56
56
|
checked?: boolean;
|
|
57
|
-
showBorder?: boolean;
|
|
58
57
|
separator?: boolean;
|
|
59
58
|
isLabel?: boolean;
|
|
59
|
+
showBorder?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface SettingItem {
|
|
62
|
+
id?: string;
|
|
63
|
+
html?: string | React.ReactNode;
|
|
64
|
+
icon?: string | React.ReactNode;
|
|
65
|
+
tooltip?: string;
|
|
66
|
+
separator?: boolean;
|
|
67
|
+
active?: boolean;
|
|
68
|
+
value?: any;
|
|
69
|
+
switch?: boolean;
|
|
70
|
+
onSwitch?: (item: SettingItem, checked: boolean) => void;
|
|
71
|
+
range?: boolean;
|
|
72
|
+
min?: number;
|
|
73
|
+
max?: number;
|
|
74
|
+
step?: number;
|
|
75
|
+
onRange?: (value: number) => void;
|
|
76
|
+
formatValue?: (value: number) => string;
|
|
77
|
+
onClick?: (item: SettingItem) => void;
|
|
78
|
+
click?: (item: SettingItem) => void;
|
|
79
|
+
children?: SettingItem[];
|
|
80
|
+
currentLabel?: React.ReactNode;
|
|
60
81
|
}
|
|
61
82
|
export interface ControlItem {
|
|
62
83
|
id?: string;
|
|
@@ -69,18 +90,7 @@ export interface ControlItem {
|
|
|
69
90
|
className?: string;
|
|
70
91
|
style?: React.CSSProperties;
|
|
71
92
|
isBuiltIn?: boolean;
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
export interface SettingItem {
|
|
75
|
-
id?: string;
|
|
76
|
-
html: string | React.ReactNode;
|
|
77
|
-
icon?: string | React.ReactNode;
|
|
78
|
-
tooltip?: string;
|
|
79
|
-
switch?: boolean;
|
|
80
|
-
onSwitch?: (item: SettingItem) => boolean | void;
|
|
81
|
-
onClick?: () => void;
|
|
82
|
-
click?: () => void;
|
|
83
|
-
isDefault?: boolean;
|
|
93
|
+
children?: SettingItem[];
|
|
84
94
|
}
|
|
85
95
|
export interface PlayerState {
|
|
86
96
|
isPlaying: boolean;
|
|
@@ -128,6 +138,7 @@ export interface PlayerState {
|
|
|
128
138
|
theme: PlayerTheme;
|
|
129
139
|
sources: PlayerSource[];
|
|
130
140
|
currentSourceIndex: number;
|
|
141
|
+
sourceStatuses: Record<number, 'success' | 'error' | undefined>;
|
|
131
142
|
isLocked: boolean;
|
|
132
143
|
flipState: {
|
|
133
144
|
horizontal: boolean;
|
|
@@ -223,6 +234,7 @@ export declare class StrataCore {
|
|
|
223
234
|
off(event: string, callback: EventCallback): void;
|
|
224
235
|
emit(event: string, data?: any): void;
|
|
225
236
|
private initVideoListeners;
|
|
237
|
+
private updateSourceStatus;
|
|
226
238
|
private initMediaSession;
|
|
227
239
|
private updateMediaSessionMetadata;
|
|
228
240
|
private updateMediaSessionPosition;
|
package/dist/strataplayer.cjs.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";var qt=Object.defineProperty;var Gt=(i,t,s)=>t in i?qt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s;var S=(i,t,s)=>Gt(i,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react"),_t=require("react-dom/client"),e=require("react/jsx-runtime"),Qt=require("react-dom");class Xt{constructor(){S(this,"events");this.events=new Map}on(t,s){var r;return this.events.has(t)||this.events.set(t,[]),(r=this.events.get(t))==null||r.push(s),()=>this.off(t,s)}off(t,s){const r=this.events.get(t);r&&this.events.set(t,r.filter(o=>o!==s))}emit(t,s){const r=this.events.get(t);r&&r.forEach(o=>o(s))}destroy(){this.events.clear()}}class Jt{constructor(t){S(this,"state");S(this,"listeners");this.state=t,this.listeners=new Set}get(){return this.state}setState(t){const s=this.state,r=typeof t=="function"?t(s):t;this.state={...s,...r},this.listeners.forEach(o=>o(this.state,s))}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}destroy(){this.listeners.clear()}}class Kt{constructor(t){S(this,"context",null);S(this,"source",null);S(this,"gainNode",null);S(this,"video");S(this,"isInitialized",!1);this.video=t}init(){if(!(this.isInitialized||!(window.AudioContext||window.webkitAudioContext))){this.context=new AudioContext,this.gainNode=this.context.createGain();try{this.source=this.context.createMediaElementSource(this.video),this.source.connect(this.gainNode),this.gainNode.connect(this.context.destination),this.isInitialized=!0}catch(s){console.warn("StrataPlayer: Failed to initialize AudioEngine",s)}}}setGain(t){this.isInitialized||this.init(),this.gainNode&&this.context&&(this.gainNode.gain.value=t,this.context.state==="suspended"&&this.context.resume())}destroy(){this.context&&this.context.close(),this.isInitialized=!1}}const Se={useNative:!1,fixCapitalization:!1,backgroundOpacity:50,backgroundBlur:!1,backgroundBlurAmount:4,textSize:100,textStyle:"shadow",isBold:!1,textColor:"#ffffff",verticalOffset:40},ft="strata-settings",$={isPlaying:!1,isBuffering:!1,isLive:!1,currentTime:0,duration:0,buffered:[],volume:1,isMuted:!1,audioGain:1,playbackRate:1,qualityLevels:[],currentQuality:-1,audioTracks:[],currentAudioTrack:-1,error:null,isFullscreen:!1,isWebFullscreen:!1,isPip:!1,subtitleTracks:[],currentSubtitle:-1,subtitleOffset:0,subtitleSettings:Se,activeCues:[],viewMode:"normal",notifications:[],iconSize:"medium",themeColor:"#6366f1",theme:"default",sources:[],currentSourceIndex:-1,isLocked:!1,flipState:{horizontal:!1,vertical:!1},aspectRatio:"default",isAutoSized:!1,isLooping:!1,controlsVisible:!0},pt=(i={})=>{let t={};if(!i.disablePersistence&&typeof window<"u")try{const r=localStorage.getItem(ft);r&&(t=JSON.parse(r))}catch{}const s={...Se,...t.subtitleSettings||{},...i.subtitleSettings||{}};return{...$,...t,volume:i.volume??t.volume??$.volume,isMuted:i.muted??t.isMuted??$.isMuted,playbackRate:i.playbackRate??t.playbackRate??$.playbackRate,audioGain:i.audioGain??t.audioGain??$.audioGain,theme:i.theme??t.theme??$.theme,themeColor:i.themeColor??t.themeColor??$.themeColor,iconSize:i.iconSize??t.iconSize??$.iconSize,subtitleSettings:s,isAutoSized:i.autoSize??$.isAutoSized,isLive:i.isLive??t.isLive??$.isLive,isLooping:i.loop??t.isLooping??$.isLooping}};class bt{constructor(t={},s){S(this,"video");S(this,"container",null);S(this,"events");S(this,"store");S(this,"plugins",new Map);S(this,"audioEngine");S(this,"config");S(this,"resizeObserver",null);S(this,"retryCount",0);S(this,"maxRetries",5);S(this,"retryTimer",null);S(this,"currentSource",null);S(this,"currentSrc","");S(this,"currentTracks",[]);S(this,"castInitialized",!1);S(this,"boundCueChange");S(this,"boundFullscreenChange");this.config=t,this.config.autoOrientation=this.config.autoOrientation??!0,this.config.fetchTimeout=this.config.fetchTimeout??3e4,this.config.centerControls=this.config.centerControls??!0,this.config.gestureSeek=this.config.gestureSeek??!1,this.video=s||document.createElement("video"),this.video.crossOrigin="anonymous",t.playsInline!==!1&&(this.video.playsInline=!0),this.events=new Xt;const r=pt(t);this.store=new Jt(r),this.audioEngine=new Kt(this.video),this.boundCueChange=this.handleCueChange.bind(this),this.boundFullscreenChange=()=>{const o=!!document.fullscreenElement;if(this.store.setState({isFullscreen:o}),this.emit("resize"),this.emit(o?"fullscreen":"fullscreen_exit"),o&&this.config.autoOrientation&&screen.orientation&&"lock"in screen.orientation){const h=this.video.videoWidth>this.video.videoHeight?"landscape":"portrait";try{screen.orientation.lock(h).catch(()=>{})}catch{}}else!o&&screen.orientation&&"unlock"in screen.orientation&&screen.orientation.unlock()},this.video.volume=r.volume,this.video.muted=r.isMuted,this.video.playbackRate=r.playbackRate,this.video.loop=r.isLooping,r.audioGain>1&&this.audioEngine.setGain(r.audioGain),r.isAutoSized&&(this.video.style.objectFit="cover"),this.initVideoListeners(),this.initMediaSession(),this.initCast(),t.disablePersistence||this.store.subscribe(o=>{const c={volume:o.volume,isMuted:o.isMuted,playbackRate:o.playbackRate,subtitleSettings:o.subtitleSettings,iconSize:o.iconSize,themeColor:o.themeColor,theme:o.theme,isLive:o.isLive,isLooping:o.isLooping};localStorage.setItem(ft,JSON.stringify(c))})}get playing(){return!this.video.paused&&!this.video.ended&&this.video.readyState>2}get currentTime(){return this.video.currentTime}set currentTime(t){this.seek(t)}get duration(){return this.video.duration||0}get paused(){return this.video.paused}get volume(){return this.video.volume}set volume(t){this.setVolume(t)}get muted(){return this.video.muted}set muted(t){this.video.muted=t,this.store.setState({isMuted:t})}get playbackRate(){return this.video.playbackRate}set playbackRate(t){this.video.playbackRate=t}get loop(){return this.video.loop}set loop(t){this.video.loop=t,this.store.setState({isLooping:t})}forward(t=10){this.skip(t)}backward(t=10){this.skip(-t)}on(t,s){return this.events.on(t,s)}off(t,s){return this.events.off(t,s)}emit(t,s){return this.events.emit(t,s)}initVideoListeners(){const t=r=>this.store.setState(r);["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"].forEach(r=>{this.video.addEventListener(r,o=>{switch(this.emit(`video:${r}`,o),r==="play"&&this.emit("play"),r==="pause"&&this.emit("pause"),r==="ended"&&this.emit("ended"),r==="error"&&this.emit("error",this.video.error),r==="seeked"&&this.emit("seek"),r){case"play":t({isPlaying:!0}),"mediaSession"in navigator&&(navigator.mediaSession.playbackState="playing"),this.updateMediaSessionPosition();break;case"pause":t({isPlaying:!1}),"mediaSession"in navigator&&(navigator.mediaSession.playbackState="paused");break;case"ended":t({isPlaying:!1}),"mediaSession"in navigator&&(navigator.mediaSession.playbackState="paused");break;case"waiting":t({isBuffering:!0}),this.emit("loading",!0);break;case"playing":t({isBuffering:!1}),this.emit("loading",!1);break;case"canplay":t({isBuffering:!1}),this.emit("loading",!1);break;case"loadeddata":t({isBuffering:!1}),this.retryCount=0,this.removeNotification("retry"),this.store.get().error&&t({error:null});break;case"loadedmetadata":this.updateMediaSessionMetadata(),this.updateMediaSessionPosition();break;case"timeupdate":this.video.seeking||t({currentTime:this.video.currentTime}),this.updateMediaSessionPosition();break;case"seeked":t({currentTime:this.video.currentTime}),this.updateMediaSessionPosition();break;case"durationchange":t({duration:this.video.duration}),this.updateMediaSessionPosition();break;case"volumechange":t({volume:this.video.volume,isMuted:this.video.muted});break;case"ratechange":t({playbackRate:this.video.playbackRate}),this.updateMediaSessionPosition();break;case"error":this.handleError();break;case"progress":this.updateBuffer();break;case"enterpictureinpicture":t({isPip:!0});break;case"leavepictureinpicture":t({isPip:!1});break}})}),this.video.addEventListener("enterpictureinpicture",()=>{t({isPip:!0}),this.emit("pip",!0)}),this.video.addEventListener("leavepictureinpicture",()=>{t({isPip:!1}),this.emit("pip",!1)}),document.addEventListener("fullscreenchange",this.boundFullscreenChange),this.video.textTracks.addEventListener("addtrack",this.updateSubtitles.bind(this)),this.video.textTracks.addEventListener("removetrack",this.updateSubtitles.bind(this))}initMediaSession(){if(!("mediaSession"in navigator))return;const t=navigator.mediaSession;t.setActionHandler("play",()=>this.play()),t.setActionHandler("pause",()=>this.pause()),t.setActionHandler("seekbackward",s=>this.skip(s.seekOffset?-s.seekOffset:-10)),t.setActionHandler("seekforward",s=>this.skip(s.seekOffset||10)),t.setActionHandler("seekto",s=>{s.seekTime!==void 0&&this.seek(s.seekTime)}),t.setActionHandler("stop",()=>{this.pause(),this.seek(0)}),t.setActionHandler("previoustrack",()=>{const s=this.store.get().currentSourceIndex;s>0&&this.switchSource(s-1)}),t.setActionHandler("nexttrack",()=>{const s=this.store.get().currentSourceIndex,r=this.store.get().sources.length;s<r-1&&this.switchSource(s+1)})}updateMediaSessionMetadata(){var r,o;if(!("mediaSession"in navigator))return;const t=((r=this.currentSource)==null?void 0:r.name)||((o=this.currentSource)==null?void 0:o.url.split("/").pop())||"Video",s=[];this.config.poster&&s.push({src:this.config.poster,sizes:"512x512",type:"image/jpeg"}),s.push({src:"logo.png",sizes:"512x512",type:"image/png"}),navigator.mediaSession.metadata=new MediaMetadata({title:t,artist:"StrataPlayer",artwork:s})}updateMediaSessionPosition(){if(!("mediaSession"in navigator))return;const t=this.video.duration,s=this.video.currentTime,r=this.video.playbackRate;if(!isNaN(t)&&isFinite(t)&&!isNaN(s))try{navigator.mediaSession.setPositionState({duration:Math.max(0,t),playbackRate:r,position:Math.max(0,Math.min(s,t))})}catch(o){console.warn("MediaSession Position Error:",o)}}triggerError(t,s=!1){s?this.handleError(t):this.notify({type:"warning",message:`Warning: ${t}`,duration:5e3})}handleError(t){const s=this.video.error,r=t||(s==null?void 0:s.message)||(s?`Code ${s.code}`:"Unknown Error");if(this.removeNotification("retry"),this.emit("video:error",s),this.retryCount<this.maxRetries){this.retryCount++;const o=Math.pow(2,this.retryCount-1)*1500;this.notify({id:"retry",type:"loading",message:`Error: ${r}. Retrying (${this.retryCount}/${this.maxRetries})...`}),console.warn(`[StrataPlayer] Error: ${r}. Retrying in ${o}ms...`),this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout(()=>{if(this.currentSource){this.load(this.currentSource,this.currentTracks,!0);const c=this.store.get().currentTime;if(c>0){const h=()=>{this.video.currentTime=c,this.video.removeEventListener("canplay",h)};this.video.addEventListener("canplay",h)}}},o)}else{this.removeNotification("retry");const o=`Failed to play after ${this.maxRetries} attempts: ${r}`;this.store.setState({error:o}),this.emit("error",o)}}updateBuffer(){const t=[];for(let s=0;s<this.video.buffered.length;s++)t.push({start:this.video.buffered.start(s),end:this.video.buffered.end(s)});this.store.setState({buffered:t})}updateSubtitles(){setTimeout(()=>{const t=Array.from(this.video.textTracks).filter(r=>r.kind==="subtitles"||r.kind==="captions").map((r,o)=>({label:r.label||r.language||`Track ${o+1}`,language:r.language,index:o}));this.store.setState({subtitleTracks:t});const s=this.store.get();s.currentSubtitle!==-1&&t.length>0&&s.currentSubtitle<t.length&&this.setSubtitle(s.currentSubtitle)},50)}async fetchWithRetry(t,s=3,r){const o=r??this.config.fetchTimeout??3e4;for(let c=0;c<s;c++){const h=new AbortController,b=setTimeout(()=>h.abort(),o);try{const g=await fetch(t,{signal:h.signal});if(clearTimeout(b),!g.ok)throw new Error(`HTTP ${g.status}`);return g}catch(g){if(clearTimeout(b),c===s-1)throw g;g.name==="AbortError"&&console.warn(`Fetch timeout (${o}ms) for ${t}`),await new Promise(p=>setTimeout(p,1e3*Math.pow(2,c)))}}throw new Error("Fetch failed")}attach(t){this.container=t,this.container.contains(this.video)||(this.video.style.width="100%",this.video.style.height="100%",this.video.style.objectFit=this.store.get().isAutoSized?"cover":"contain",this.video.style.backgroundColor="black",this.container.appendChild(this.video)),this.resizeObserver=new ResizeObserver(s=>{for(const r of s)this.emit("resize",{width:r.contentRect.width,height:r.contentRect.height})}),this.resizeObserver.observe(this.container),this.emit("ready")}use(t){this.plugins.has(t.name)||(t.init(this),this.plugins.set(t.name,t))}setSources(t,s=[]){this.store.setState({sources:t}),this.currentTracks=s,t.length>0&&this.load(t[0],s)}switchSource(t){const s=this.store.get().sources;if(t>=0&&t<s.length){const r=this.video.currentTime,o=!this.video.paused;this.load(s[t],this.currentTracks);const c=()=>{this.video.currentTime=r,o&&this.video.play(),this.video.removeEventListener("canplay",c)};this.video.addEventListener("canplay",c)}}load(t,s=[],r=!1){this.retryTimer&&clearTimeout(this.retryTimer);const o=typeof t=="string"?{url:t,type:"auto"}:t;r||(this.retryCount=0,this.store.setState({error:null}),this.removeNotification("retry")),this.currentSrc=o.url,this.currentSource=o,this.currentTracks=s;const h=this.store.get().sources.findIndex(p=>p.url===o.url);this.store.setState({isBuffering:!0,qualityLevels:[],currentQuality:-1,audioTracks:[],currentAudioTrack:-1,currentSourceIndex:h}),this.updateMediaSessionMetadata();let b=o.type||"auto";b==="auto"&&(o.url.includes(".m3u8")?b="hls":o.url.includes(".mpd")?b="dash":o.url.includes(".flv")||o.url.includes(".ts")?b="mpegts":o.url.startsWith("magnet:")||o.url.includes(".torrent")?b="webtorrent":b="mp4"),this.events.emit("load",{url:o.url,type:b});const g=this.video.getElementsByTagName("track");for(;g.length>0;)g[0].remove();s.length>0&&s.forEach(p=>{this.fetchWithRetry(p.src).then(()=>{this.addTextTrackInternal(p.src,p.label,p.srcLang,p.default)}).catch(u=>{this.notify({type:"warning",message:`Failed to load subtitle: ${p.label}`,duration:4e3})})}),(b==="mp4"||b==="webm"||b==="ogg")&&(this.video.src=o.url)}loadSubtitle(t,s="Subtitle"){this.addTextTrackInternal(t,s,void 0,!0)}addTextTrack(t,s){const r=new FileReader;r.onload=o=>{var g;if(!((g=o.target)!=null&&g.result))return;let c=o.target.result;(t.name.toLowerCase().endsWith(".srt")||!c.trim().startsWith("WEBVTT"))&&(c=c.replace(/(\d{2}:\d{2}:\d{2}),(\d{3})/g,"$1.$2"),c.trim().startsWith("WEBVTT")||(c=`WEBVTT
|
|
1
|
+
"use strict";var ts=Object.defineProperty;var ss=(s,t,i)=>t in s?ts(s,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[t]=i;var S=(s,t,i)=>ss(s,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react"),is=require("react-dom/client"),e=require("react/jsx-runtime"),ns=require("react-dom");class rs{constructor(){S(this,"events");this.events=new Map}on(t,i){var r;return this.events.has(t)||this.events.set(t,[]),(r=this.events.get(t))==null||r.push(i),()=>this.off(t,i)}off(t,i){const r=this.events.get(t);r&&this.events.set(t,r.filter(o=>o!==i))}emit(t,i){const r=this.events.get(t);r&&r.forEach(o=>o(i))}destroy(){this.events.clear()}}class as{constructor(t){S(this,"state");S(this,"listeners");this.state=t,this.listeners=new Set}get(){return this.state}setState(t){const i=this.state,r=typeof t=="function"?t(i):t;this.state={...i,...r},this.listeners.forEach(o=>o(this.state,i))}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}destroy(){this.listeners.clear()}}class os{constructor(t){S(this,"context",null);S(this,"source",null);S(this,"gainNode",null);S(this,"video");S(this,"isInitialized",!1);this.video=t}init(){if(!(this.isInitialized||!(window.AudioContext||window.webkitAudioContext))){this.context=new AudioContext,this.gainNode=this.context.createGain();try{this.source=this.context.createMediaElementSource(this.video),this.source.connect(this.gainNode),this.gainNode.connect(this.context.destination),this.isInitialized=!0}catch(i){console.warn("StrataPlayer: Failed to initialize AudioEngine",i)}}}setGain(t){this.isInitialized||this.init(),this.gainNode&&this.context&&(this.gainNode.gain.value=t,this.context.state==="suspended"&&this.context.resume())}destroy(){this.context&&this.context.close(),this.isInitialized=!1}}const ze=s=>{if(isNaN(s))return"00:00";const t=Math.floor(s/3600),i=Math.floor(s%3600/60),r=Math.floor(s%60);return t>0?`${t}:${i.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${i}:${r.toString().padStart(2,"0")}`},ls=async(s,t=3,i=2e4)=>{for(let r=0;r<t;r++){const o=new AbortController,c=setTimeout(()=>o.abort(),i);try{const h=await fetch(s,{signal:o.signal});if(clearTimeout(c),!h.ok)throw new Error(`HTTP ${h.status}`);return await h.text()}catch(h){if(clearTimeout(c),r===t-1)throw h;await new Promise(b=>setTimeout(b,1e3))}}throw new Error("Failed")},cs=async(s,t,i=2e4)=>{try{const o=(await ls(s,3,i)).split(`
|
|
2
|
+
`),c=[];let h=null,b=null;const j=s.substring(0,s.lastIndexOf("/")+1),g=u=>{const w=u.split(":");let x=0;return w.length===3?(x+=parseFloat(w[0])*3600,x+=parseFloat(w[1])*60,x+=parseFloat(w[2])):(x+=parseFloat(w[0])*60,x+=parseFloat(w[1])),x};for(let u of o)if(u=u.trim(),u.includes("-->")){const w=u.split("-->");h=g(w[0].trim()),b=g(w[1].trim())}else if(h!==null&&b!==null&&u.length>0){let[w,x]=u.split("#");!w.match(/^https?:\/\//)&&!w.startsWith("data:")&&(w=j+w);let C=0,R=0,p=0,D=0;if(x&&x.startsWith("xywh=")){const q=x.replace("xywh=","").split(",");q.length===4&&(C=parseInt(q[0]),R=parseInt(q[1]),p=parseInt(q[2]),D=parseInt(q[3]))}p>0&&D>0&&c.push({start:h,end:b,url:w,x:C,y:R,w:p,h:D}),h=null,b=null}return c}catch{return t({type:"warning",message:"Failed to load thumbnails",duration:4e3}),[]}},ds=()=>{if(!(typeof document>"u")){if(!document.getElementById("strata-fonts")){const s=document.createElement("link");s.rel="preconnect",s.href="https://fonts.googleapis.com",document.head.appendChild(s);const t=document.createElement("link");t.rel="preconnect",t.href="https://fonts.gstatic.com",t.crossOrigin="anonymous",document.head.appendChild(t);const i=document.createElement("link");i.id="strata-fonts",i.rel="stylesheet",i.href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Press+Start+2P&family=Cinzel:wght@400;600;700&display=swap",document.head.appendChild(i)}if(!document.querySelector('script[src*="cast_sender.js"]')&&!window.cast){const s=document.createElement("script");s.src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",document.head.appendChild(s)}}},Ee={useNative:!1,fixCapitalization:!1,backgroundOpacity:50,backgroundBlur:!1,backgroundBlurAmount:4,textSize:100,textStyle:"shadow",isBold:!1,textColor:"#ffffff",verticalOffset:40},St="strata-settings",B={isPlaying:!1,isBuffering:!1,isLive:!1,currentTime:0,duration:0,buffered:[],volume:1,isMuted:!1,audioGain:1,playbackRate:1,qualityLevels:[],currentQuality:-1,audioTracks:[],currentAudioTrack:-1,error:null,isFullscreen:!1,isWebFullscreen:!1,isPip:!1,subtitleTracks:[],currentSubtitle:-1,subtitleOffset:0,subtitleSettings:Ee,activeCues:[],viewMode:"normal",notifications:[],iconSize:"medium",themeColor:"#6366f1",theme:"default",sources:[],currentSourceIndex:-1,sourceStatuses:{},isLocked:!1,flipState:{horizontal:!1,vertical:!1},aspectRatio:"default",isAutoSized:!1,isLooping:!1,controlsVisible:!0},Ct=(s={})=>{let t={};if(!s.disablePersistence&&typeof window<"u")try{const r=localStorage.getItem(St);r&&(t=JSON.parse(r))}catch{}const i={...Ee,...t.subtitleSettings||{},...s.subtitleSettings||{}};return{...B,...t,volume:s.volume??t.volume??B.volume,isMuted:s.muted??t.isMuted??B.isMuted,playbackRate:s.playbackRate??t.playbackRate??B.playbackRate,audioGain:s.audioGain??t.audioGain??B.audioGain,theme:s.theme??t.theme??B.theme,themeColor:s.themeColor??t.themeColor??B.themeColor,iconSize:s.iconSize??t.iconSize??B.iconSize,subtitleSettings:i,isAutoSized:s.autoSize??B.isAutoSized,isLive:s.isLive??t.isLive??B.isLive,isLooping:s.loop??t.isLooping??B.isLooping,sourceStatuses:{}}};class Nt{constructor(t={},i){S(this,"video");S(this,"container",null);S(this,"events");S(this,"store");S(this,"plugins",new Map);S(this,"audioEngine");S(this,"config");S(this,"resizeObserver",null);S(this,"retryCount",0);S(this,"maxRetries",5);S(this,"retryTimer",null);S(this,"currentSource",null);S(this,"currentSrc","");S(this,"currentTracks",[]);S(this,"castInitialized",!1);S(this,"boundCueChange");S(this,"boundFullscreenChange");ds(),this.config=t,this.config.autoOrientation=this.config.autoOrientation??!0,this.config.fetchTimeout=this.config.fetchTimeout??3e4,this.config.centerControls=this.config.centerControls??!0,this.config.gestureSeek=this.config.gestureSeek??!1,this.video=i||document.createElement("video"),this.video.crossOrigin="anonymous",t.playsInline!==!1&&(this.video.playsInline=!0),this.events=new rs;const r=Ct(t);this.store=new as(r),this.audioEngine=new os(this.video),this.boundCueChange=this.handleCueChange.bind(this),this.boundFullscreenChange=()=>{const o=!!document.fullscreenElement;if(this.store.setState({isFullscreen:o}),this.emit("resize"),this.emit(o?"fullscreen":"fullscreen_exit"),o&&this.config.autoOrientation&&screen.orientation&&"lock"in screen.orientation){const h=this.video.videoWidth>this.video.videoHeight?"landscape":"portrait";try{screen.orientation.lock(h).catch(()=>{})}catch{}}else!o&&screen.orientation&&"unlock"in screen.orientation&&screen.orientation.unlock()},this.video.volume=r.volume,this.video.muted=r.isMuted,this.video.playbackRate=r.playbackRate,this.video.loop=r.isLooping,r.audioGain>1&&this.audioEngine.setGain(r.audioGain),r.isAutoSized&&(this.video.style.objectFit="cover"),this.initVideoListeners(),this.initMediaSession(),this.initCast(),t.disablePersistence||this.store.subscribe(o=>{const c={volume:o.volume,isMuted:o.isMuted,playbackRate:o.playbackRate,subtitleSettings:o.subtitleSettings,iconSize:o.iconSize,themeColor:o.themeColor,theme:o.theme,isLive:o.isLive,isLooping:o.isLooping};localStorage.setItem(St,JSON.stringify(c))})}get playing(){return!this.video.paused&&!this.video.ended&&this.video.readyState>2}get currentTime(){return this.video.currentTime}set currentTime(t){this.seek(t)}get duration(){return this.video.duration||0}get paused(){return this.video.paused}get volume(){return this.video.volume}set volume(t){this.setVolume(t)}get muted(){return this.video.muted}set muted(t){this.video.muted=t,this.store.setState({isMuted:t})}get playbackRate(){return this.video.playbackRate}set playbackRate(t){this.video.playbackRate=t}get loop(){return this.video.loop}set loop(t){this.video.loop=t,this.store.setState({isLooping:t})}forward(t=10){this.skip(t)}backward(t=10){this.skip(-t)}on(t,i){return this.events.on(t,i)}off(t,i){return this.events.off(t,i)}emit(t,i){return this.events.emit(t,i)}initVideoListeners(){const t=r=>this.store.setState(r);["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"].forEach(r=>{this.video.addEventListener(r,o=>{switch(this.emit(`video:${r}`,o),r==="play"&&this.emit("play"),r==="pause"&&this.emit("pause"),r==="ended"&&this.emit("ended"),r==="error"&&this.emit("error",this.video.error),r==="seeked"&&this.emit("seek"),r){case"play":t({isPlaying:!0}),"mediaSession"in navigator&&(navigator.mediaSession.playbackState="playing"),this.updateMediaSessionPosition();break;case"pause":t({isPlaying:!1}),"mediaSession"in navigator&&(navigator.mediaSession.playbackState="paused");break;case"ended":t({isPlaying:!1}),"mediaSession"in navigator&&(navigator.mediaSession.playbackState="paused");break;case"waiting":t({isBuffering:!0}),this.emit("loading",!0);break;case"playing":t({isBuffering:!1}),this.emit("loading",!1);break;case"canplay":t({isBuffering:!1}),this.emit("loading",!1),this.updateSourceStatus("success");break;case"loadeddata":t({isBuffering:!1}),this.retryCount=0,this.removeNotification("retry"),this.store.get().error&&t({error:null}),this.updateSourceStatus("success");break;case"loadedmetadata":this.updateMediaSessionMetadata(),this.updateMediaSessionPosition();break;case"timeupdate":this.video.seeking||t({currentTime:this.video.currentTime}),this.updateMediaSessionPosition();break;case"seeked":t({currentTime:this.video.currentTime}),this.updateMediaSessionPosition();break;case"durationchange":t({duration:this.video.duration}),this.updateMediaSessionPosition();break;case"volumechange":t({volume:this.video.volume,isMuted:this.video.muted});break;case"ratechange":t({playbackRate:this.video.playbackRate}),this.updateMediaSessionPosition();break;case"error":this.handleError();break;case"progress":this.updateBuffer();break;case"enterpictureinpicture":t({isPip:!0});break;case"leavepictureinpicture":t({isPip:!1});break}})}),this.video.addEventListener("enterpictureinpicture",()=>{t({isPip:!0}),this.emit("pip",!0)}),this.video.addEventListener("leavepictureinpicture",()=>{t({isPip:!1}),this.emit("pip",!1)}),document.addEventListener("fullscreenchange",this.boundFullscreenChange),this.video.textTracks.addEventListener("addtrack",this.updateSubtitles.bind(this)),this.video.textTracks.addEventListener("removetrack",this.updateSubtitles.bind(this))}updateSourceStatus(t){const i=this.store.get().currentSourceIndex;i!==-1&&this.store.setState(r=>({sourceStatuses:{...r.sourceStatuses,[i]:t}}))}initMediaSession(){if(!("mediaSession"in navigator))return;const t=navigator.mediaSession;t.setActionHandler("play",()=>this.play()),t.setActionHandler("pause",()=>this.pause()),t.setActionHandler("seekbackward",i=>this.skip(i.seekOffset?-i.seekOffset:-10)),t.setActionHandler("seekforward",i=>this.skip(i.seekOffset||10)),t.setActionHandler("seekto",i=>{i.seekTime!==void 0&&this.seek(i.seekTime)}),t.setActionHandler("stop",()=>{this.pause(),this.seek(0)}),t.setActionHandler("previoustrack",()=>{const i=this.store.get().currentSourceIndex;i>0&&this.switchSource(i-1)}),t.setActionHandler("nexttrack",()=>{const i=this.store.get().currentSourceIndex,r=this.store.get().sources.length;i<r-1&&this.switchSource(i+1)})}updateMediaSessionMetadata(){var r,o;if(!("mediaSession"in navigator))return;const t=((r=this.currentSource)==null?void 0:r.name)||((o=this.currentSource)==null?void 0:o.url.split("/").pop())||"Video",i=[];this.config.poster&&i.push({src:this.config.poster,sizes:"512x512",type:"image/jpeg"}),i.push({src:"logo.png",sizes:"512x512",type:"image/png"}),navigator.mediaSession.metadata=new MediaMetadata({title:t,artist:"StrataPlayer",artwork:i})}updateMediaSessionPosition(){if(!("mediaSession"in navigator))return;const t=this.video.duration,i=this.video.currentTime,r=this.video.playbackRate;if(!isNaN(t)&&isFinite(t)&&!isNaN(i))try{navigator.mediaSession.setPositionState({duration:Math.max(0,t),playbackRate:r,position:Math.max(0,Math.min(i,t))})}catch(o){console.warn("MediaSession Position Error:",o)}}triggerError(t,i=!1){i?this.handleError(t):this.notify({type:"warning",message:`Warning: ${t}`,duration:5e3})}handleError(t){const i=this.video.error,r=t||(i==null?void 0:i.message)||(i?`Code ${i.code}`:"Unknown Error");if(this.removeNotification("retry"),this.emit("video:error",i),this.retryCount<this.maxRetries){this.retryCount++;const o=Math.pow(2,this.retryCount-1)*1500;this.notify({id:"retry",type:"loading",message:`Error: ${r}. Retrying (${this.retryCount}/${this.maxRetries})...`}),console.warn(`[StrataPlayer] Error: ${r}. Retrying in ${o}ms...`),this.retryTimer&&clearTimeout(this.retryTimer),this.retryTimer=setTimeout(()=>{if(this.currentSource){this.load(this.currentSource,this.currentTracks,!0);const c=this.store.get().currentTime;if(c>0){const h=()=>{this.video.currentTime=c,this.video.removeEventListener("canplay",h)};this.video.addEventListener("canplay",h)}}},o)}else{this.removeNotification("retry");const o=`Failed to play after ${this.maxRetries} attempts: ${r}`;this.store.setState({error:o}),this.emit("error",o),this.updateSourceStatus("error")}}updateBuffer(){const t=[];for(let i=0;i<this.video.buffered.length;i++)t.push({start:this.video.buffered.start(i),end:this.video.buffered.end(i)});this.store.setState({buffered:t})}updateSubtitles(){setTimeout(()=>{const t=Array.from(this.video.textTracks).filter(r=>r.kind==="subtitles"||r.kind==="captions").map((r,o)=>({label:r.label||r.language||`Track ${o+1}`,language:r.language,index:o}));this.store.setState({subtitleTracks:t});const i=this.store.get();i.currentSubtitle!==-1&&t.length>0&&i.currentSubtitle<t.length&&this.setSubtitle(i.currentSubtitle)},50)}async fetchWithRetry(t,i=3,r){const o=r??this.config.fetchTimeout??3e4;for(let c=0;c<i;c++){const h=new AbortController,b=setTimeout(()=>h.abort(),o);try{const j=await fetch(t,{signal:h.signal});if(clearTimeout(b),!j.ok)throw new Error(`HTTP ${j.status}`);return j}catch(j){if(clearTimeout(b),c===i-1)throw j;j.name==="AbortError"&&console.warn(`Fetch timeout (${o}ms) for ${t}`),await new Promise(g=>setTimeout(g,1e3*Math.pow(2,c)))}}throw new Error("Fetch failed")}attach(t){this.container=t,this.container.contains(this.video)||(this.video.style.width="100%",this.video.style.height="100%",this.video.style.objectFit=this.store.get().isAutoSized?"cover":"contain",this.video.style.backgroundColor="black",this.container.appendChild(this.video)),this.resizeObserver=new ResizeObserver(i=>{for(const r of i)this.emit("resize",{width:r.contentRect.width,height:r.contentRect.height})}),this.resizeObserver.observe(this.container),this.emit("ready")}use(t){this.plugins.has(t.name)||(t.init(this),this.plugins.set(t.name,t))}setSources(t,i=[]){this.store.setState({sources:t}),this.currentTracks=i,t.length>0&&this.load(t[0],i)}switchSource(t){const i=this.store.get().sources;if(t>=0&&t<i.length){const r=this.video.currentTime,o=!this.video.paused;this.load(i[t],this.currentTracks);const c=()=>{this.video.currentTime=r,o&&this.video.play(),this.video.removeEventListener("canplay",c)};this.video.addEventListener("canplay",c)}}load(t,i=[],r=!1){this.retryTimer&&clearTimeout(this.retryTimer);const o=typeof t=="string"?{url:t,type:"auto"}:t;r||(this.retryCount=0,this.store.setState({error:null}),this.removeNotification("retry")),this.currentSrc=o.url,this.currentSource=o,this.currentTracks=i;const h=this.store.get().sources.findIndex(g=>g.url===o.url);this.store.setState({isBuffering:!0,qualityLevels:[],currentQuality:-1,audioTracks:[],currentAudioTrack:-1,currentSourceIndex:h}),this.updateMediaSessionMetadata();let b=o.type||"auto";b==="auto"&&(o.url.includes(".m3u8")?b="hls":o.url.includes(".mpd")?b="dash":o.url.includes(".flv")||o.url.includes(".ts")?b="mpegts":o.url.startsWith("magnet:")||o.url.includes(".torrent")?b="webtorrent":b="mp4"),this.events.emit("load",{url:o.url,type:b});const j=this.video.getElementsByTagName("track");for(;j.length>0;)j[0].remove();i.length>0&&i.forEach(g=>{this.fetchWithRetry(g.src).then(()=>{this.addTextTrackInternal(g.src,g.label,g.srcLang,g.default)}).catch(u=>{this.notify({type:"warning",message:`Failed to load subtitle: ${g.label}`,duration:4e3})})}),(b==="mp4"||b==="webm"||b==="ogg")&&(this.video.src=o.url)}loadSubtitle(t,i="Subtitle"){this.addTextTrackInternal(t,i,void 0,!0)}addTextTrack(t,i){const r=new FileReader;r.onload=o=>{var j;if(!((j=o.target)!=null&&j.result))return;let c=o.target.result;(t.name.toLowerCase().endsWith(".srt")||!c.trim().startsWith("WEBVTT"))&&(c=c.replace(/(\d{2}:\d{2}:\d{2}),(\d{3})/g,"$1.$2"),c.trim().startsWith("WEBVTT")||(c=`WEBVTT
|
|
2
3
|
|
|
3
|
-
`+c));const h=new Blob([c],{type:"text/vtt"}),b=URL.createObjectURL(h);this.addTextTrackInternal(b,s,"user",!0),setTimeout(()=>{const u=this.store.get().subtitleTracks.findIndex(j=>j.label===s);u!==-1&&(this.setSubtitle(u),this.notify({type:"success",message:"Subtitle uploaded",duration:3e3}))},200)},r.onerror=()=>{this.notify({type:"error",message:"Failed to read file",duration:3e3})},r.readAsText(t)}addTextTrackInternal(t,s,r="",o=!1){const c=document.createElement("track");c.kind="subtitles",c.label=s,c.src=t,c.srclang=r,o&&(c.default=!0),this.video.appendChild(c),this.updateSubtitles()}play(){return this.video.play()}pause(){return this.video.pause()}togglePlay(){this.video.paused?this.play():this.pause()}seek(t){if(isNaN(t))return;const s=Math.max(0,Math.min(t,this.video.duration));this.store.setState({currentTime:s}),this.video.currentTime=s}skip(t){this.seek(this.video.currentTime+t)}setVolume(t){const s=Math.max(0,Math.min(t,1));this.video.volume=s,s>0&&this.video.muted&&(this.video.muted=!1),s===0&&(this.video.muted=!0)}toggleMute(){this.video.muted=!this.video.muted}setAudioGain(t){this.store.setState({audioGain:t}),this.audioEngine.setGain(t)}setQuality(t){this.store.setState({currentQuality:t}),this.events.emit("quality-request",t)}setAudioTrack(t){this.store.setState({currentAudioTrack:t}),this.events.emit("audio-track-request",t)}setControlsVisible(t){this.store.get().controlsVisible!==t&&(this.store.setState({controlsVisible:t}),this.emit("control",t))}async toggleFullscreen(){if(this.container)try{document.fullscreenElement?await document.exitFullscreen():await this.container.requestFullscreen()}catch(t){console.error("Fullscreen toggle failed",t)}}toggleWebFullscreen(){const t=this.store.get().isWebFullscreen;document.fullscreenElement&&document.exitFullscreen().catch(()=>{});const s=!t;this.store.setState({isWebFullscreen:s}),typeof document<"u"&&(document.body.style.overflow=s?"hidden":""),this.emit("webfullscreen",s)}togglePip(){document.pictureInPictureElement?document.exitPictureInPicture():this.video!==document.pictureInPictureElement&&this.video.requestPictureInPicture&&this.video.requestPictureInPicture()}screenshot(){const t=document.createElement("canvas");t.width=this.video.videoWidth,t.height=this.video.videoHeight;const s=t.getContext("2d");if(s){s.drawImage(this.video,0,0,t.width,t.height);try{const r=t.toDataURL("image/png"),o=document.createElement("a");o.download=`screenshot-${new Date().toISOString()}.png`,o.href=r,o.click(),this.notify({type:"success",message:"Screenshot saved",duration:2e3})}catch{this.notify({type:"error",message:"Failed to take screenshot",duration:3e3})}}}toggleLock(){this.store.setState(t=>({isLocked:!t.isLocked}))}toggleLoop(){this.video.loop=!this.video.loop,this.store.setState({isLooping:this.video.loop}),this.notify({type:"info",message:`Loop: ${this.video.loop?"On":"Off"}`,duration:1500})}setFlip(t){const s=this.store.get().flipState,r={...s,[t]:!s[t]};this.store.setState({flipState:r});const o=r.horizontal?-1:1,c=r.vertical?-1:1;this.video.style.transform=`scale(${o}, ${c})`}setAspectRatio(t){if(this.store.setState({aspectRatio:t}),t==="default"){this.video.style.objectFit=this.store.get().isAutoSized?"cover":"contain",this.video.style.width="100%",this.video.style.height="100%";return}this.video.style.objectFit="contain",this.notify({type:"info",message:`Aspect Ratio: ${t} (CSS support limited)`,duration:2e3})}initCast(){const t=window,s=()=>{if(!this.castInitialized)try{t.cast&&t.cast.framework&&t.chrome&&t.chrome.cast&&(t.cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:t.chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:t.chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),this.castInitialized=!0)}catch(r){console.warn("Cast Init Error or already initialized",r)}};t.cast&&t.cast.framework?s():t.__onGCastApiAvailable=r=>{r&&s()}}requestCast(){const t=window;if(t.cast&&t.cast.framework)try{this.castInitialized||this.initCast(),t.cast.framework.CastContext.getInstance().requestSession().then(()=>{this.loadMediaToCast()}).catch(s=>{s!=="cancel"&&this.notify({type:"error",message:"Cast failed: "+s,duration:3e3})})}catch{this.notify({type:"warning",message:"Cast not available yet",duration:3e3})}else this.notify({type:"warning",message:"Cast API not loaded",duration:3e3})}loadMediaToCast(){const t=window;try{const s=t.cast.framework.CastContext.getInstance().getCurrentSession();if(!s)return;const r=new t.chrome.cast.media.MediaInfo(this.currentSrc,this.currentSrc.includes(".m3u8")?"application/x-mpegurl":"video/mp4"),o=new t.chrome.cast.media.LoadRequest(r);s.loadMedia(o).then(()=>{this.notify({type:"success",message:"Casting...",duration:3e3})}).catch(c=>console.error("Cast load error",c))}catch(s){console.error("Failed to load media into Cast session",s)}}handleCueChange(){const t=this.store.get();if(t.currentSubtitle===-1){this.store.setState({activeCues:[]});return}const r=Array.from(this.video.textTracks).filter(o=>o.kind==="subtitles"||o.kind==="captions")[t.currentSubtitle];if(r&&r.activeCues){const o=Array.from(r.activeCues).map(c=>c.text);this.store.setState({activeCues:o})}else this.store.setState({activeCues:[]})}setSubtitle(t){if(Array.from(this.video.textTracks).forEach(s=>{s.removeEventListener("cuechange",this.boundCueChange),s.mode="hidden"}),this.store.setState({currentSubtitle:t,subtitleOffset:0,activeCues:[]}),t!==-1){const r=Array.from(this.video.textTracks).filter(o=>o.kind==="subtitles"||o.kind==="captions")[t];if(r){const o=this.store.get().subtitleSettings;r.mode=o.useNative?"showing":"hidden",r.addEventListener("cuechange",this.boundCueChange),this.handleCueChange()}}}updateSubtitleSettings(t){const r={...this.store.get().subtitleSettings,...t};this.store.setState({subtitleSettings:r}),t.useNative!==void 0&&this.setSubtitle(this.store.get().currentSubtitle)}resetSubtitleSettings(){this.store.setState({subtitleSettings:Se}),this.setSubtitle(this.store.get().currentSubtitle)}setSubtitleOffset(t){const s=this.store.get().subtitleOffset,r=t-s;Math.abs(r)<.001||(Array.from(this.video.textTracks).forEach(o=>{(o.mode==="showing"||o.mode==="hidden")&&o.cues&&Array.from(o.cues).forEach(c=>{c.startTime+=r,c.endTime+=r})}),this.store.setState({subtitleOffset:t}),this.notify({type:"info",message:`Subtitle Offset: ${t>0?"+":""}${t.toFixed(1)}s`,duration:1500}))}async download(){var r;if(!this.video.src)return;const t=this.video.src;if(t.includes("blob:")||t.includes(".m3u8")){this.notify({type:"warning",message:"Stream download not supported in browser.",duration:4e3});return}const s=this.notify({type:"loading",message:"Preparing download...",progress:0});try{const o=await this.fetchWithRetry(t);if(!o.body)throw new Error("No body");const c=o.body.getReader(),h=o.headers.get("Content-Length"),b=h?parseInt(h,10):0;let g=0;const p=[];for(;;){const{done:M,value:T}=await c.read();if(M)break;if(p.push(T),g+=T.length,b){const f=Math.round(g/b*100);this.notify({id:s,type:"loading",message:`Downloading... ${f}%`,progress:f})}}const u=new Blob(p),j=window.URL.createObjectURL(u),y=document.createElement("a");y.style.display="none",y.href=j,y.download=((r=t.split("/").pop())==null?void 0:r.split("?")[0])||"video.mp4",document.body.appendChild(y),y.click(),window.URL.revokeObjectURL(j),document.body.removeChild(y),this.notify({id:s,type:"success",message:"Saved!",duration:3e3})}catch{this.notify({id:s,type:"error",message:"Download failed.",duration:4e3}),window.open(t,"_blank")}}notify(t){const s=t.id||Math.random().toString(36).substr(2,9),r={...t,id:s};return this.store.setState({notifications:[r]}),t.duration&&setTimeout(()=>this.removeNotification(s),t.duration),s}removeNotification(t){const s=this.store.get().notifications;this.store.setState({notifications:s.filter(r=>r.id!==t)})}setAppearance(t){this.store.setState(s=>({...s,...t}))}destroy(){this.retryTimer&&clearTimeout(this.retryTimer),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.store.get().isWebFullscreen&&typeof document<"u"&&(document.body.style.overflow=""),document.removeEventListener("fullscreenchange",this.boundFullscreenChange),this.video.pause(),this.video.src="";const t=this.video.getElementsByTagName("track");for(;t.length>0;)t[0].remove();this.emit("destroy"),this.events.destroy(),this.store.destroy(),this.plugins.forEach(s=>s.destroy&&s.destroy()),this.plugins.clear(),this.video.remove(),this.audioEngine.destroy()}}const we=i=>{if(isNaN(i))return"00:00";const t=Math.floor(i/3600),s=Math.floor(i%3600/60),r=Math.floor(i%60);return t>0?`${t}:${s.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${s}:${r.toString().padStart(2,"0")}`},Yt=async(i,t=3,s=2e4)=>{for(let r=0;r<t;r++){const o=new AbortController,c=setTimeout(()=>o.abort(),s);try{const h=await fetch(i,{signal:o.signal});if(clearTimeout(c),!h.ok)throw new Error(`HTTP ${h.status}`);return await h.text()}catch(h){if(clearTimeout(c),r===t-1)throw h;await new Promise(b=>setTimeout(b,1e3))}}throw new Error("Failed")},Zt=async(i,t,s=2e4)=>{try{const o=(await Yt(i,3,s)).split(`
|
|
4
|
-
`),c=[];let h=null,b=null;const g=i.substring(0,i.lastIndexOf("/")+1),p=u=>{const j=u.split(":");let y=0;return j.length===3?(y+=parseFloat(j[0])*3600,y+=parseFloat(j[1])*60,y+=parseFloat(j[2])):(y+=parseFloat(j[0])*60,y+=parseFloat(j[1])),y};for(let u of o)if(u=u.trim(),u.includes("-->")){const j=u.split("-->");h=p(j[0].trim()),b=p(j[1].trim())}else if(h!==null&&b!==null&&u.length>0){let[j,y]=u.split("#");!j.match(/^https?:\/\//)&&!j.startsWith("data:")&&(j=g+j);let M=0,T=0,f=0,B=0;if(y&&y.startsWith("xywh=")){const V=y.replace("xywh=","").split(",");V.length===4&&(M=parseInt(V[0]),T=parseInt(V[1]),f=parseInt(V[2]),B=parseInt(V[3]))}f>0&&B>0&&c.push({start:h,end:b,url:j,x:M,y:T,w:f,h:B}),h=null,b=null}return c}catch{return t({type:"warning",message:"Failed to load thumbnails",duration:4e3}),[]}},ot=(i,t=200)=>{const[s,r]=x.useState(i),[o,c]=x.useState(!1);return x.useEffect(()=>{if(i)r(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{c(!0)})});else{c(!1);const h=setTimeout(()=>{r(!1)},t);return()=>clearTimeout(h)}},[i,t]),{isMounted:s,isVisible:o}},v=({className:i,children:t,fill:s="none",strokeWidth:r=2,viewBox:o="0 0 24 24"})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:o,fill:s,stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",className:i,children:t}),lt=({className:i})=>e.jsx(v,{className:i,children:e.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),ct=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("rect",{width:"4",height:"16",x:"6",y:"4",rx:"1"}),e.jsx("rect",{width:"4",height:"16",x:"14",y:"4",rx:"1"})]}),es=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]}),ts=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]}),ss=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("line",{x1:"23",x2:"17",y1:"9",y2:"15"}),e.jsx("line",{x1:"17",x2:"23",y1:"9",y2:"15"})]}),is=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),e.jsx("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),e.jsx("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),e.jsx("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]}),ns=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),e.jsx("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),e.jsx("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),e.jsx("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]}),rs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.47a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),Ce=({className:i})=>e.jsx(v,{className:i,children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),as=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4"}),e.jsx("rect",{x:"12",y:"13",width:"10",height:"7",rx:"2"})]}),os=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 15h4"}),e.jsx("path",{d:"M15 15h2"}),e.jsx("path",{d:"M7 11h2"}),e.jsx("path",{d:"M13 11h4"})]}),ls=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]}),cs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"17 8 12 3 7 8"}),e.jsx("line",{x1:"12",x2:"12",y1:"3",y2:"15"})]}),ds=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"m12 19-7-7 7-7"}),e.jsx("path",{d:"M19 12H5"})]}),ye=({className:i})=>e.jsx(v,{className:i,children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),us=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M2 16.1A5 5 0 0 1 5.9 20"}),e.jsx("path",{d:"M2 12.05A9 9 0 0 1 9.95 20"}),e.jsx("path",{d:"M2 8V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-6"}),e.jsx("line",{x1:"2",x2:"2.01",y1:"20",y2:"20"})]}),hs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),ms=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),xs=({className:i})=>e.jsx(v,{className:i,children:e.jsx("path",{d:"M5 12h14"})}),fs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"M12 5v14"})]}),ps=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M4 21v-7"}),e.jsx("path",{d:"M4 10V3"}),e.jsx("path",{d:"M12 21v-9"}),e.jsx("path",{d:"M12 8V3"}),e.jsx("path",{d:"M20 21v-5"}),e.jsx("path",{d:"M20 12V3"}),e.jsx("path",{d:"M1 14h6"}),e.jsx("path",{d:"M9 8h6"}),e.jsx("path",{d:"M17 16h6"})]}),bs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("polyline",{points:"4 7 4 4 20 4 20 7"}),e.jsx("line",{x1:"9",x2:"15",y1:"20",y2:"20"}),e.jsx("line",{x1:"12",x2:"12",y1:"4",y2:"20"})]}),vt=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),e.jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"})]}),vs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),gs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("polyline",{points:"8 18 12 22 16 18"}),e.jsx("polyline",{points:"8 6 12 2 16 6"}),e.jsx("line",{x1:"12",x2:"12",y1:"2",y2:"22"})]}),ws=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"})]}),js=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"}),e.jsx("path",{d:"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"})]}),ys=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"m3 17 4-10 4 10"}),e.jsx("path",{d:"M4 13h6"}),e.jsx("path",{d:"M15 12h4.5a2.5 2.5 0 0 1 0 5H15V7h4a2.5 2.5 0 0 1 0 5h-4"})]}),ks=({className:i})=>e.jsx(v,{className:i,children:e.jsx("path",{d:"M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z"})}),Ss=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"}),e.jsx("circle",{cx:"12",cy:"13",r:"3"})]}),Cs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),Ns=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]}),Ms=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"21",y2:"21"}),e.jsx("line",{x1:"12",x2:"12",y1:"17",y2:"21"})]}),Ts=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("polygon",{points:"13 19 22 12 13 5 13 19"}),e.jsx("polygon",{points:"2 19 11 12 2 5 2 19"})]}),zs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),Rs=({className:i})=>e.jsxs(v,{className:i,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]}),dt=({className:i})=>e.jsxs("div",{className:`relative flex items-center justify-center ${i}`,children:[e.jsxs(v,{className:"w-full h-full",children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"})]}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[32%] font-bold select-none mt-[1px]",children:"10"})]}),ut=({className:i})=>e.jsxs("div",{className:`relative flex items-center justify-center ${i}`,children:[e.jsxs(v,{className:"w-full h-full",children:[e.jsx("path",{d:"M21 12a9 9 0 1 1-9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"})]}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[32%] font-bold select-none mt-[1px]",children:"10"})]}),Is=({notifications:i})=>e.jsx("div",{className:"absolute top-4 left-4 z-25 flex flex-col gap-2 pointer-events-none font-sans max-w-[85%] md:max-w-[320px]",children:i.map(t=>e.jsxs("div",{className:`
|
|
4
|
+
`+c));const h=new Blob([c],{type:"text/vtt"}),b=URL.createObjectURL(h);this.addTextTrackInternal(b,i,"user",!0),setTimeout(()=>{const u=this.store.get().subtitleTracks.findIndex(w=>w.label===i);u!==-1&&(this.setSubtitle(u),this.notify({type:"success",message:"Subtitle uploaded",duration:3e3}))},200)},r.onerror=()=>{this.notify({type:"error",message:"Failed to read file",duration:3e3})},r.readAsText(t)}addTextTrackInternal(t,i,r="",o=!1){const c=document.createElement("track");c.kind="subtitles",c.label=i,c.src=t,c.srclang=r,o&&(c.default=!0),this.video.appendChild(c),this.updateSubtitles()}play(){return this.video.play()}pause(){return this.video.pause()}togglePlay(){this.video.paused?this.play():this.pause()}seek(t){if(isNaN(t))return;const i=Math.max(0,Math.min(t,this.video.duration));this.store.setState({currentTime:i}),this.video.currentTime=i}skip(t){this.seek(this.video.currentTime+t)}setVolume(t){const i=Math.max(0,Math.min(t,1));this.video.volume=i,i>0&&this.video.muted&&(this.video.muted=!1),i===0&&(this.video.muted=!0)}toggleMute(){this.video.muted=!this.video.muted}setAudioGain(t){this.store.setState({audioGain:t}),this.audioEngine.setGain(t)}setQuality(t){this.store.setState({currentQuality:t}),this.events.emit("quality-request",t)}setAudioTrack(t){this.store.setState({currentAudioTrack:t}),this.events.emit("audio-track-request",t)}setControlsVisible(t){this.store.get().controlsVisible!==t&&(this.store.setState({controlsVisible:t}),this.emit("control",t))}async toggleFullscreen(){if(this.container)try{document.fullscreenElement?await document.exitFullscreen():await this.container.requestFullscreen()}catch(t){console.error("Fullscreen toggle failed",t)}}toggleWebFullscreen(){const t=this.store.get().isWebFullscreen;document.fullscreenElement&&document.exitFullscreen().catch(()=>{});const i=!t;this.store.setState({isWebFullscreen:i}),typeof document<"u"&&(document.body.style.overflow=i?"hidden":""),this.emit("webfullscreen",i)}togglePip(){document.pictureInPictureElement?document.exitPictureInPicture():this.video!==document.pictureInPictureElement&&this.video.requestPictureInPicture&&this.video.requestPictureInPicture()}screenshot(){const t=document.createElement("canvas");t.width=this.video.videoWidth,t.height=this.video.videoHeight;const i=t.getContext("2d");if(i){i.drawImage(this.video,0,0,t.width,t.height);try{const r=t.toDataURL("image/png"),o=document.createElement("a");o.download=`screenshot-${new Date().toISOString()}.png`,o.href=r,o.click(),this.notify({type:"success",message:"Screenshot saved",duration:2e3})}catch{this.notify({type:"error",message:"Failed to take screenshot",duration:3e3})}}}toggleLock(){this.store.setState(t=>({isLocked:!t.isLocked}))}toggleLoop(){this.video.loop=!this.video.loop,this.store.setState({isLooping:this.video.loop}),this.notify({type:"info",message:`Loop: ${this.video.loop?"On":"Off"}`,duration:1500})}setFlip(t){const i=this.store.get().flipState,r={...i,[t]:!i[t]};this.store.setState({flipState:r});const o=r.horizontal?-1:1,c=r.vertical?-1:1;this.video.style.transform=`scale(${o}, ${c})`}setAspectRatio(t){if(this.store.setState({aspectRatio:t}),t==="default"){this.video.style.objectFit=this.store.get().isAutoSized?"cover":"contain",this.video.style.width="100%",this.video.style.height="100%";return}this.video.style.objectFit="contain",this.notify({type:"info",message:`Aspect Ratio: ${t} (CSS support limited)`,duration:2e3})}initCast(){const t=window,i=()=>{if(!this.castInitialized)try{t.cast&&t.cast.framework&&t.chrome&&t.chrome.cast&&(t.cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:t.chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:t.chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),this.castInitialized=!0)}catch(r){console.warn("Cast Init Error or already initialized",r)}};t.cast&&t.cast.framework?i():t.__onGCastApiAvailable=r=>{r&&i()}}requestCast(){const t=window;if(t.cast&&t.cast.framework)try{this.castInitialized||this.initCast(),t.cast.framework.CastContext.getInstance().requestSession().then(()=>{this.loadMediaToCast()}).catch(i=>{i!=="cancel"&&this.notify({type:"error",message:"Cast failed: "+i,duration:3e3})})}catch{this.notify({type:"warning",message:"Cast not available yet",duration:3e3})}else this.notify({type:"warning",message:"Cast API not loaded",duration:3e3})}loadMediaToCast(){const t=window;try{const i=t.cast.framework.CastContext.getInstance().getCurrentSession();if(!i)return;const r=new t.chrome.cast.media.MediaInfo(this.currentSrc,this.currentSrc.includes(".m3u8")?"application/x-mpegurl":"video/mp4"),o=new t.chrome.cast.media.LoadRequest(r);i.loadMedia(o).then(()=>{this.notify({type:"success",message:"Casting...",duration:3e3})}).catch(c=>console.error("Cast load error",c))}catch(i){console.error("Failed to load media into Cast session",i)}}handleCueChange(){const t=this.store.get();if(t.currentSubtitle===-1){this.store.setState({activeCues:[]});return}const r=Array.from(this.video.textTracks).filter(o=>o.kind==="subtitles"||o.kind==="captions")[t.currentSubtitle];if(r&&r.activeCues){const o=Array.from(r.activeCues).map(c=>c.text);this.store.setState({activeCues:o})}else this.store.setState({activeCues:[]})}setSubtitle(t){if(Array.from(this.video.textTracks).forEach(i=>{i.removeEventListener("cuechange",this.boundCueChange),i.mode="hidden"}),this.store.setState({currentSubtitle:t,subtitleOffset:0,activeCues:[]}),t!==-1){const r=Array.from(this.video.textTracks).filter(o=>o.kind==="subtitles"||o.kind==="captions")[t];if(r){const o=this.store.get().subtitleSettings;r.mode=o.useNative?"showing":"hidden",r.addEventListener("cuechange",this.boundCueChange),this.handleCueChange()}}}updateSubtitleSettings(t){const r={...this.store.get().subtitleSettings,...t};this.store.setState({subtitleSettings:r}),t.useNative!==void 0&&this.setSubtitle(this.store.get().currentSubtitle)}resetSubtitleSettings(){this.store.setState({subtitleSettings:Ee}),this.setSubtitle(this.store.get().currentSubtitle)}setSubtitleOffset(t){const i=this.store.get().subtitleOffset,r=t-i;Math.abs(r)<.001||(Array.from(this.video.textTracks).forEach(o=>{(o.mode==="showing"||o.mode==="hidden")&&o.cues&&Array.from(o.cues).forEach(c=>{c.startTime+=r,c.endTime+=r})}),this.store.setState({subtitleOffset:t}),this.notify({type:"info",message:`Subtitle Offset: ${t>0?"+":""}${t.toFixed(1)}s`,duration:1500}))}async download(){var r;if(!this.video.src)return;const t=this.video.src;if(t.includes("blob:")||t.includes(".m3u8")){this.notify({type:"warning",message:"Stream download not supported in browser.",duration:4e3});return}const i=this.notify({type:"loading",message:"Preparing download...",progress:0});try{const o=await this.fetchWithRetry(t);if(!o.body)throw new Error("No body");const c=o.body.getReader(),h=o.headers.get("Content-Length"),b=h?parseInt(h,10):0;let j=0;const g=[];for(;;){const{done:C,value:R}=await c.read();if(C)break;if(g.push(R),j+=R.length,b){const p=Math.round(j/b*100);this.notify({id:i,type:"loading",message:`Downloading... ${p}%`,progress:p})}}const u=new Blob(g),w=window.URL.createObjectURL(u),x=document.createElement("a");x.style.display="none",x.href=w,x.download=((r=t.split("/").pop())==null?void 0:r.split("?")[0])||"video.mp4",document.body.appendChild(x),x.click(),window.URL.revokeObjectURL(w),document.body.removeChild(x),this.notify({id:i,type:"success",message:"Saved!",duration:3e3})}catch{this.notify({id:i,type:"error",message:"Download failed.",duration:4e3}),window.open(t,"_blank")}}notify(t){const i=t.id||Math.random().toString(36).substr(2,9),r={...t,id:i};return this.store.setState({notifications:[r]}),t.duration&&setTimeout(()=>this.removeNotification(i),t.duration),i}removeNotification(t){const i=this.store.get().notifications;this.store.setState({notifications:i.filter(r=>r.id!==t)})}setAppearance(t){this.store.setState(i=>({...i,...t}))}destroy(){this.retryTimer&&clearTimeout(this.retryTimer),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.store.get().isWebFullscreen&&typeof document<"u"&&(document.body.style.overflow=""),document.removeEventListener("fullscreenchange",this.boundFullscreenChange),this.video.pause(),this.video.src="";const t=this.video.getElementsByTagName("track");for(;t.length>0;)t[0].remove();this.emit("destroy"),this.events.destroy(),this.store.destroy(),this.plugins.forEach(i=>i.destroy&&i.destroy()),this.plugins.clear(),this.video.remove(),this.audioEngine.destroy()}}const Ie=(s,t=200)=>{const[i,r]=m.useState(s),[o,c]=m.useState(!1);return m.useEffect(()=>{if(s)r(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{c(!0)})});else{c(!1);const h=setTimeout(()=>{r(!1)},t);return()=>clearTimeout(h)}},[s,t]),{isMounted:i,isVisible:o}},v=({className:s,children:t,fill:i="none",strokeWidth:r=2,viewBox:o="0 0 24 24"})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:o,fill:i,stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",className:s,children:t}),vt=({className:s})=>e.jsx(v,{className:s,children:e.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),jt=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("rect",{width:"4",height:"16",x:"6",y:"4",rx:"1"}),e.jsx("rect",{width:"4",height:"16",x:"14",y:"4",rx:"1"})]}),us=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"}),e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]}),hs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"})]}),xs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("line",{x1:"23",x2:"17",y1:"9",y2:"15"}),e.jsx("line",{x1:"17",x2:"23",y1:"9",y2:"15"})]}),ms=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),e.jsx("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),e.jsx("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),e.jsx("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]}),fs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),e.jsx("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),e.jsx("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),e.jsx("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]}),ps=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.47a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),Pe=({className:s})=>e.jsx(v,{className:s,children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),bs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M21 9V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h4"}),e.jsx("rect",{x:"12",y:"13",width:"10",height:"7",rx:"2"})]}),gs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("rect",{width:"18",height:"14",x:"3",y:"5",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 15h4"}),e.jsx("path",{d:"M15 15h2"}),e.jsx("path",{d:"M7 11h2"}),e.jsx("path",{d:"M13 11h4"})]}),vs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]}),js=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"17 8 12 3 7 8"}),e.jsx("line",{x1:"12",x2:"12",y1:"3",y2:"15"})]}),ws=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"m12 19-7-7 7-7"}),e.jsx("path",{d:"M19 12H5"})]}),Le=({className:s})=>e.jsx(v,{className:s,children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),ys=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M2 16.1A5 5 0 0 1 5.9 20"}),e.jsx("path",{d:"M2 12.05A9 9 0 0 1 9.95 20"}),e.jsx("path",{d:"M2 8V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-6"}),e.jsx("line",{x1:"2",x2:"2.01",y1:"20",y2:"20"})]}),ks=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),Ss=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]}),Cs=({className:s})=>e.jsx(v,{className:s,children:e.jsx("path",{d:"M5 12h14"})}),Ns=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"M12 5v14"})]}),Ms=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M4 21v-7"}),e.jsx("path",{d:"M4 10V3"}),e.jsx("path",{d:"M12 21v-9"}),e.jsx("path",{d:"M12 8V3"}),e.jsx("path",{d:"M20 21v-5"}),e.jsx("path",{d:"M20 12V3"}),e.jsx("path",{d:"M1 14h6"}),e.jsx("path",{d:"M9 8h6"}),e.jsx("path",{d:"M17 16h6"})]}),Ts=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polyline",{points:"4 7 4 4 20 4 20 7"}),e.jsx("line",{x1:"9",x2:"15",y1:"20",y2:"20"}),e.jsx("line",{x1:"12",x2:"12",y1:"4",y2:"20"})]}),Mt=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),e.jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),e.jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"})]}),zs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),Is=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polyline",{points:"8 18 12 22 16 18"}),e.jsx("polyline",{points:"8 6 12 2 16 6"}),e.jsx("line",{x1:"12",x2:"12",y1:"2",y2:"22"})]}),Rs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"})]}),Ls=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"}),e.jsx("path",{d:"M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z"})]}),$s=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"m3 17 4-10 4 10"}),e.jsx("path",{d:"M4 13h6"}),e.jsx("path",{d:"M15 12h4.5a2.5 2.5 0 0 1 0 5H15V7h4a2.5 2.5 0 0 1 0 5h-4"})]}),Es=({className:s})=>e.jsx(v,{className:s,children:e.jsx("path",{d:"M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5C6 11.1 5 13 5 15a7 7 0 0 0 7 7z"})}),Ps=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"}),e.jsx("circle",{cx:"12",cy:"13",r:"3"})]}),Fs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),As=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 9.9-1"})]}),Bs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"21",y2:"21"}),e.jsx("line",{x1:"12",x2:"12",y1:"17",y2:"21"})]}),Vs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polygon",{points:"13 19 22 12 13 5 13 19"}),e.jsx("polygon",{points:"2 19 11 12 2 5 2 19"})]}),Os=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),Hs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]}),Ws=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),Ds=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polygon",{points:"12 2 2 7 12 12 22 7 12 2"}),e.jsx("polyline",{points:"2 17 12 22 22 17"}),e.jsx("polyline",{points:"2 12 12 17 22 12"})]}),qs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M6 2v14a2 2 0 0 0 2 2h14"}),e.jsx("path",{d:"M18 22V8a2 2 0 0 0-2-2H2"})]}),_s=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("rect",{width:"16",height:"20",x:"4",y:"2",rx:"2"}),e.jsx("circle",{cx:"12",cy:"14",r:"4"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"6",y2:"6"})]}),Gs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"m12 14 4-4"}),e.jsx("path",{d:"M3.34 19a10 10 0 1 1 17.32 0"})]}),Us=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M9 18V5l12-2v13"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("circle",{cx:"18",cy:"16",r:"3"})]}),Qs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("polyline",{points:"16 16 12 20 8 16"}),e.jsx("line",{x1:"12",x2:"12",y1:"20",y2:"10"}),e.jsx("path",{d:"M12 4a8 8 0 0 1 8 8"}),e.jsx("path",{d:"M20 4v8"}),e.jsx("path",{d:"M4 4v8"}),e.jsx("path",{d:"M4 12a8 8 0 0 1 8-8"})]}),Xs=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("path",{d:"M5 12.55a11 11 0 0 1 14.08 0"}),e.jsx("path",{d:"M1.42 9a16 16 0 0 1 21.16 0"}),e.jsx("path",{d:"M8.53 16.11a6 6 0 0 1 6.95 0"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"20",y2:"20"})]}),Js=({className:s})=>e.jsxs(v,{className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}),wt=({className:s})=>e.jsxs("div",{className:`relative flex items-center justify-center ${s}`,children:[e.jsxs(v,{className:"w-full h-full",children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"})]}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[32%] font-bold select-none mt-[1px]",children:"10"})]}),yt=({className:s})=>e.jsxs("div",{className:`relative flex items-center justify-center ${s}`,children:[e.jsxs(v,{className:"w-full h-full",children:[e.jsx("path",{d:"M21 12a9 9 0 1 1-9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"})]}),e.jsx("span",{className:"absolute inset-0 flex items-center justify-center text-[32%] font-bold select-none mt-[1px]",children:"10"})]}),Ks=({notifications:s})=>e.jsx("div",{className:"absolute top-4 left-4 z-25 flex flex-col gap-2 pointer-events-none font-sans max-w-[85%] md:max-w-[320px]",children:s.map(t=>e.jsxs("div",{className:`
|
|
5
5
|
bg-zinc-950/90 backdrop-blur-md border border-white/10 text-white px-3 py-2 rounded-lg shadow-xl text-xs font-medium flex items-start gap-2.5 animate-in slide-in-from-left-2 fade-in duration-300 pointer-events-auto
|
|
6
6
|
w-fit max-w-full
|
|
7
7
|
${t.type==="error"?"border-red-500/50 text-red-100":""}
|
|
8
8
|
${t.type==="warning"?"border-amber-500/50 text-amber-100":""}
|
|
9
|
-
`,children:[t.type==="loading"&&e.jsx(
|
|
9
|
+
`,children:[t.type==="loading"&&e.jsx(Le,{className:"w-3.5 h-3.5 animate-spin text-[var(--accent)] shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[e.jsx("span",{className:"break-words line-clamp-4 leading-relaxed whitespace-pre-wrap",children:t.message}),typeof t.progress=="number"&&e.jsx("div",{className:"h-0.5 w-full bg-white/10 rounded-full overflow-hidden mt-1.5",children:e.jsx("div",{className:"h-full bg-[var(--accent)] transition-all duration-300",style:{width:`${t.progress}%`}})})]})]},t.id))}),Ys=({cues:s,settings:t})=>{if(t.useNative||s.length===0)return null;const i=()=>{switch(t.textStyle){case"outline":return"0px 0px 4px black, 0px 0px 4px black";case"raised":return"0 -1px 1px black, 0 -2px 2px black";case"depressed":return"0 1px 1px white, 0 2px 2px black";case"shadow":return"2px 2px 2px rgba(0,0,0,0.8)";default:return"none"}};return e.jsx("div",{className:"absolute inset-x-0 flex flex-col items-center justify-end text-center z-10 pointer-events-none transition-all duration-200",style:{bottom:`${t.verticalOffset}px`},children:s.map((r,o)=>e.jsx("div",{className:"mb-1 inline-block max-w-[80%]",style:{fontSize:`${t.textSize}%`,color:t.textColor,fontWeight:t.isBold?"bold":"normal",textTransform:t.fixCapitalization?"capitalize":"none",textShadow:i(),lineHeight:1.4},children:e.jsx("span",{className:"px-2 py-0.5 rounded",style:{backgroundColor:`rgba(0, 0, 0, ${t.backgroundOpacity/100})`,backdropFilter:t.backgroundBlur?`blur(${t.backgroundBlurAmount}px)`:"none"},dangerouslySetInnerHTML:{__html:r}})},o))})},ue=({content:s})=>typeof s=="string"?s.trim().startsWith("<")?e.jsx("span",{dangerouslySetInnerHTML:{__html:s}}):e.jsx("span",{children:s}):e.jsx(e.Fragment,{children:s}),W=({label:s,checked:t,onChange:i,icon:r,tooltip:o})=>e.jsxs("div",{className:"flex items-center justify-between py-2.5 px-3 hover:bg-white/5 group transition-colors",style:{borderRadius:"var(--radius)"},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[r&&e.jsx("span",{className:"text-zinc-500 group-hover:text-zinc-400 transition-colors flex items-center justify-center w-4 h-4",children:e.jsx(ue,{content:r})}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm text-zinc-300 font-medium group-hover:text-white transition-colors flex items-center",children:e.jsx(ue,{content:s})}),o&&e.jsx("span",{className:"text-[10px] text-zinc-500",children:o})]})]}),e.jsx("button",{onClick:()=>i(!t),className:`w-11 h-6 shrink-0 transition-colors relative focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-zinc-900 ${t?"bg-[var(--accent)]":"bg-zinc-700"}`,style:{"--tw-ring-color":"var(--accent)",borderRadius:"var(--radius-full)",borderWidth:"var(--border-width)",borderColor:"rgba(255,255,255,0.1)"},children:e.jsx("div",{className:`absolute top-1/2 -translate-y-1/2 left-1 w-4 h-4 transition-transform shadow-sm ${t?"translate-x-5":"translate-x-0"}`,style:{borderRadius:"var(--radius-full)",backgroundColor:t?"var(--accent-contrast)":"#ffffff"}})})]}),ne=({label:s,value:t,min:i,max:r,step:o,onChange:c,formatValue:h,icon:b})=>e.jsxs("div",{className:"py-2.5 px-3 hover:bg-white/5 group transition-colors",style:{borderRadius:"var(--radius)"},children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[b&&e.jsx("span",{className:"text-zinc-500 group-hover:text-zinc-400 transition-colors flex items-center justify-center w-4 h-4",children:e.jsx(ue,{content:b})}),e.jsx("span",{className:"text-xs font-bold text-zinc-400 uppercase tracking-wider group-hover:text-zinc-300 transition-colors",children:s})]}),e.jsx("span",{className:"text-[10px] font-mono font-medium text-zinc-300 bg-white/10 px-1.5 py-0.5 tabular-nums",style:{borderRadius:"var(--radius-sm)"},children:h?h(t):t})]}),e.jsxs("div",{className:"relative h-4 flex items-center px-1",children:[e.jsx("input",{type:"range",min:i,max:r,step:o,value:t,onChange:j=>c(parseFloat(j.target.value)),className:"w-full h-1.5 appearance-none cursor-pointer focus:outline-none focus:ring-2 strata-range-input",style:{borderRadius:"var(--radius-full)",background:`linear-gradient(to right, var(--accent) 0%, var(--accent) ${(t-i)/(r-i)*100}%, #3f3f46 ${(t-i)/(r-i)*100}%, #3f3f46 100%)`,"--tw-ring-color":"var(--accent)"}}),e.jsx("style",{children:`
|
|
10
10
|
.strata-range-input::-webkit-slider-thumb {
|
|
11
11
|
-webkit-appearance: none;
|
|
12
12
|
height: 14px;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
transform: scale(1.1);
|
|
23
23
|
}
|
|
24
24
|
/* Pixel theme specific overrides are handled by global css */
|
|
25
|
-
`})]})]}),$s=({label:i,value:t,options:s,onChange:r,icon:o})=>e.jsxs("div",{className:"py-2.5 px-3 hover:bg-white/5 group transition-colors",style:{borderRadius:"var(--radius)"},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[o&&e.jsx("span",{className:"text-zinc-500 group-hover:text-zinc-400 transition-colors flex items-center justify-center w-4 h-4",children:e.jsx(ae,{content:o})}),e.jsx("span",{className:"text-xs font-bold text-zinc-400 uppercase tracking-wider group-hover:text-zinc-300 transition-colors",children:i})]}),e.jsxs("div",{className:"relative",children:[e.jsx("select",{value:t,onChange:c=>r(c.target.value),className:"w-full bg-zinc-800 border-[length:var(--border-width)] border-white/10 px-3 py-2 text-sm text-zinc-200 focus:outline-none focus:ring-2 appearance-none hover:bg-zinc-700 transition-colors cursor-pointer",style:{"--tw-ring-color":"var(--accent)",borderRadius:"var(--radius)"},children:s.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))}),e.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-zinc-400",children:e.jsx("svg",{width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M1 1L5 5L9 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),Q=({title:i,children:t})=>e.jsxs("div",{className:"py-2",children:[i&&e.jsx("h4",{className:"px-3 text-[10px] font-bold text-[var(--accent)] uppercase tracking-wider mb-1 mt-2",children:i}),e.jsx("div",{className:"space-y-0.5",children:t})]}),Es=({tracks:i,current:t,onSelect:s,onUpload:r,onClose:o,settings:c,onSettingsChange:h,onReset:b,offset:g,onOffsetChange:p,maxHeight:u,animationClass:j})=>{const[y,M]=x.useState("main"),T=x.useRef(null);return e.jsxs(gt,{onClose:o,align:"right",maxHeight:u,className:j,children:[y==="main"&&e.jsxs("div",{className:"animate-in slide-in-from-left-4 fade-in duration-200",children:[e.jsx("div",{className:"px-3 py-2 mb-1 border-b border-white/5 font-bold text-zinc-400 uppercase text-[11px] tracking-wider flex justify-between items-center bg-white/5 sticky top-0 z-10 backdrop-blur-md",style:{borderRadius:"var(--radius)"},children:e.jsx("span",{children:"Subtitles"})}),e.jsxs("div",{children:[e.jsx(C,{label:"Upload Subtitle",icon:e.jsx(cs,{className:"w-4 h-4"}),onClick:()=>{var f;return(f=T.current)==null?void 0:f.click()}}),e.jsx("input",{type:"file",accept:".vtt,.srt",ref:T,className:"hidden",onChange:f=>{var B;(B=f.target.files)!=null&&B[0]&&r(f.target.files[0])}}),e.jsx(C,{label:"Customize",icon:e.jsx(ps,{className:"w-4 h-4"}),onClick:()=>M("customize"),hasSubmenu:!0}),e.jsx("div",{className:"h-px bg-white/5 mx-2 my-1"}),e.jsx(C,{label:"Off",active:t===-1,onClick:()=>{s(-1),o()}}),i.map(f=>e.jsx(C,{label:f.label,value:f.language,active:t===f.index,onClick:()=>{s(f.index),o()}},f.index))]})]}),y==="customize"&&e.jsxs("div",{className:"animate-in slide-in-from-right-4 fade-in duration-200",children:[e.jsx(A,{label:"Customize",onBack:()=>M("main"),rightAction:e.jsx("button",{onClick:b,className:"p-1.5 text-zinc-400 hover:text-white transition-colors rounded-md hover:bg-white/10",title:"Reset All",children:e.jsx(ws,{className:"w-4 h-4"})})}),e.jsxs("div",{className:"pb-1",children:[e.jsx(Q,{children:e.jsx(_,{label:"Native Video Subtitle",checked:c.useNative,onChange:f=>h({useNative:f})})}),!c.useNative&&e.jsxs(e.Fragment,{children:[e.jsxs(Q,{title:"Sync & Position",children:[e.jsxs("div",{className:"py-2.5 px-3 rounded-lg hover:bg-white/5 group transition-colors",children:[e.jsx("div",{className:"flex justify-between items-center mb-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ms,{className:"w-4 h-4 text-zinc-500 group-hover:text-zinc-400 transition-colors"}),e.jsx("span",{className:"text-xs font-bold text-zinc-400 uppercase tracking-wider group-hover:text-zinc-300 transition-colors",children:"Sync Offset"})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>p(Math.round((g-.1)*10)/10),className:"w-8 h-8 flex items-center justify-center bg-zinc-800 rounded-lg hover:bg-zinc-700 text-zinc-300 transition-colors active:scale-95",children:e.jsx(xs,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 bg-zinc-900 border border-white/5 rounded-lg h-8 flex items-center justify-center text-xs font-mono font-medium text-[var(--accent)]",children:[g>0?"+":"",(g==null?void 0:g.toFixed(1))||"0.0","s"]}),e.jsx("button",{onClick:()=>p(Math.round((g+.1)*10)/10),className:"w-8 h-8 flex items-center justify-center bg-zinc-800 rounded-lg hover:bg-zinc-700 text-zinc-300 transition-colors active:scale-95",children:e.jsx(fs,{className:"w-4 h-4"})})]})]}),e.jsx(re,{label:"Vertical Position",icon:e.jsx(gs,{className:"w-4 h-4"}),value:c.verticalOffset,min:0,max:200,step:5,onChange:f=>h({verticalOffset:f}),formatValue:f=>`${f}px`})]}),e.jsxs(Q,{title:"Appearance",children:[e.jsx(re,{label:"Text Size",icon:e.jsx(bs,{className:"w-4 h-4"}),value:c.textSize,min:50,max:200,step:10,onChange:f=>h({textSize:f}),formatValue:f=>`${f}%`}),e.jsxs("div",{className:"py-2.5 px-3 rounded-lg hover:bg-white/5 group transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(vt,{className:"w-4 h-4 text-zinc-500 group-hover:text-zinc-400 transition-colors"}),e.jsx("span",{className:"text-xs font-bold text-zinc-400 uppercase tracking-wider group-hover:text-zinc-300 transition-colors",children:"Text Color"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 p-1 bg-zinc-800/50 rounded-lg",children:[["#ffffff","#ffff00","#00ffff","#ff00ff","#ff0000","#00ff00"].map(f=>e.jsx("button",{onClick:()=>h({textColor:f}),className:`w-6 h-6 rounded-full border border-white/10 transition-transform hover:scale-110 ${c.textColor===f?"ring-2 scale-110":""}`,style:{backgroundColor:f,"--tw-ring-color":"var(--accent)"}},f)),e.jsx("div",{className:"w-px h-6 bg-white/10 mx-1"}),e.jsx("div",{className:"relative w-6 h-6 rounded-full overflow-hidden ring-1 ring-white/20 cursor-pointer",children:e.jsx("input",{type:"color",value:c.textColor,onChange:f=>h({textColor:f.target.value}),className:"absolute inset-[-4px] w-[150%] h-[150%] cursor-pointer p-0 border-0"})})]})]}),e.jsx($s,{label:"Text Style",value:c.textStyle,options:[{label:"None",value:"none"},{label:"Outline",value:"outline"},{label:"Raised",value:"raised"},{label:"Depressed",value:"depressed"},{label:"Drop Shadow",value:"shadow"}],onChange:f=>h({textStyle:f})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-1 px-1",children:[e.jsx(_,{label:"Bold",icon:e.jsx(js,{className:"w-4 h-4"}),checked:c.isBold,onChange:f=>h({isBold:f})}),e.jsx(_,{label:"Fix Caps",icon:e.jsx(ys,{className:"w-4 h-4"}),checked:c.fixCapitalization,onChange:f=>h({fixCapitalization:f})})]})]}),e.jsxs(Q,{title:"Background",children:[e.jsx(re,{label:"Opacity",icon:e.jsx(vs,{className:"w-4 h-4"}),value:c.backgroundOpacity,min:0,max:100,step:5,onChange:f=>h({backgroundOpacity:f}),formatValue:f=>`${f}%`}),e.jsx(_,{label:"Blur Background",icon:e.jsx(ks,{className:"w-4 h-4"}),checked:c.backgroundBlur,onChange:f=>h({backgroundBlur:f})}),c.backgroundBlur&&e.jsx(re,{label:"Blur Intensity",value:c.backgroundBlurAmount,min:0,max:20,step:1,onChange:f=>h({backgroundBlurAmount:f}),formatValue:f=>`${f}px`})]})]})]})]})]})},je=({content:i})=>typeof i=="string"?i.trim().startsWith("<")?e.jsx("span",{dangerouslySetInnerHTML:{__html:i}}):e.jsx("span",{children:i}):e.jsx(e.Fragment,{children:i}),Ps=({x:i,y:t,items:s,onClose:r,containerWidth:o,containerHeight:c})=>{const h=x.useRef(null),[b,g]=x.useState({top:t,left:i,opacity:0});return x.useLayoutEffect(()=>{if(!h.current)return;const p=h.current.getBoundingClientRect(),u=p.width,j=p.height;let y=i,M=t;i+u>o-10&&(y=i-u),y<10&&(y=10),y+u>o&&(y=Math.max(10,o-u-10)),t+j>c-10&&(M=t-j);let T=c-20;M<10&&(M=10),M+j>c-10&&(M=Math.max(10,c-j-10)),g({top:M,left:y,maxHeight:T,opacity:1})},[i,t,s,o,c]),x.useEffect(()=>{const p=u=>{h.current&&!h.current.contains(u.target)&&r()};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[r]),e.jsx("div",{ref:h,className:"absolute z-50 min-w-[200px] bg-[var(--bg-panel)] backdrop-blur-xl border-[length:var(--border-width)] border-white/10 shadow-2xl p-1.5 font-[family-name:var(--font-main)] overflow-y-auto hide-scrollbar flex flex-col",style:{top:b.top,left:b.left,maxHeight:b.maxHeight,opacity:b.opacity,borderRadius:"var(--radius-lg)"},onClick:p=>p.stopPropagation(),children:s.map((p,u)=>p.separator?e.jsx("div",{className:"h-0 border-t border-white/10 mx-2 my-1.5"},u):p.isLabel?e.jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold text-zinc-500 uppercase tracking-wider select-none",children:e.jsx(je,{content:p.html||""})},u):e.jsxs(x.Fragment,{children:[e.jsxs("button",{onClick:()=>{p.disabled||(p.click?p.click(r):p.onClick&&p.onClick(r))},disabled:p.disabled,className:"w-full text-left px-3 py-2.5 flex items-center justify-between hover:bg-white/10 focus:bg-white/10 focus:outline-none transition-colors text-sm text-zinc-200 disabled:opacity-50 disabled:cursor-not-allowed group my-0.5",style:{borderRadius:"var(--radius)"},children:[e.jsxs("div",{className:"flex items-center gap-3 overflow-hidden",children:[p.icon&&e.jsx("span",{className:"text-zinc-400 w-4 h-4 flex items-center justify-center shrink-0 group-hover:text-zinc-300 transition-colors",children:e.jsx(je,{content:p.icon})}),e.jsx("span",{className:`flex items-center font-medium truncate ${p.checked?"text-[var(--accent)]":""}`,children:e.jsx(je,{content:p.html||""})})]}),p.checked&&e.jsx(Ce,{className:"w-4 h-4 text-[var(--accent)] shrink-0 ml-2"})]}),p.showBorder&&e.jsx("div",{className:"h-0 border-t border-white/10 mx-2 my-1"})]},u))})},Fs=({player:i,onClose:t})=>{const[s,r]=x.useState({});return x.useEffect(()=>{const o=()=>{var g;if(!i.video)return;const h=i.video,b=h.getVideoPlaybackQuality?h.getVideoPlaybackQuality():null;r({"Player Size":`${h.offsetWidth} x ${h.offsetHeight}`,"Video Resolution":`${h.videoWidth} x ${h.videoHeight}`,"Current Time":`${h.currentTime.toFixed(3)}s`,Duration:`${h.duration.toFixed(3)}s`,Volume:`${Math.round(h.volume*100)}%`,"Dropped Frames":b?b.droppedVideoFrames:"N/A",Buffer:h.buffered.length>0?`${(h.buffered.end(h.buffered.length-1)-h.currentTime).toFixed(2)}s`:"0s",Engine:((g=i.store.get().sources[i.store.get().currentSourceIndex])==null?void 0:g.type)||"native",URL:h.currentSrc})};o();const c=setInterval(o,1e3);return()=>clearInterval(c)},[i]),e.jsx("div",{className:"absolute inset-0 z-[60] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-[var(--bg-panel)] border border-white/10 rounded-xl w-full max-w-md shadow-2xl relative font-mono text-xs text-zinc-300 flex flex-col",style:{borderRadius:"var(--radius)",maxHeight:"90%"},children:[e.jsxs("div",{className:"p-5 pb-0 flex-shrink-0 relative",children:[e.jsx("button",{onClick:o=>{o.stopPropagation(),t()},className:"absolute top-3 right-3 p-1.5 text-zinc-400 hover:text-white hover:bg-white/10 rounded-full transition-colors",children:e.jsx(zs,{className:"w-4 h-4"})}),e.jsx("h3",{className:"text-sm font-bold text-white mb-4 uppercase tracking-wider border-b border-white/10 pb-2",children:"Video Statistics"})]}),e.jsx("div",{className:"overflow-y-auto hide-scrollbar p-5 pt-0 space-y-2.5 flex-1 min-h-0",children:Object.entries(s).map(([o,c])=>e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-center gap-1",children:[e.jsx("span",{className:"text-zinc-500 font-bold shrink-0",children:o}),e.jsx("span",{className:"text-zinc-200 truncate select-all font-medium bg-white/5 px-1.5 py-0.5 rounded break-all text-right",title:String(c),children:String(c)})]},o))})]})})},As=[{label:"Strata",value:"#6366f1"},{label:"Emerald",value:"#10b981"},{label:"Rose",value:"#f43f5e"},{label:"Amber",value:"#f59e0b"},{label:"Sky",value:"#0ea5e9"},{label:"Violet",value:"#8b5cf6"}],Bs=[{label:"Default",value:"default",color:"#6366f1"},{label:"Pixel",value:"pixel",color:"#ef4444"},{label:"Game",value:"game",color:"#eab308"},{label:"Hacker",value:"hacker",color:"#22c55e"}],xt=({content:i,className:t,style:s})=>typeof i=="string"?i.trim().startsWith("<")?e.jsx("div",{className:t,style:s,dangerouslySetInnerHTML:{__html:i}}):e.jsx("div",{className:t,style:s,children:i}):e.jsx("div",{className:t,style:s,children:i}),ke=i=>{var nt,rt;const{src:t,type:s,sources:r,poster:o,autoPlay:c,thumbnails:h,textTracks:b,plugins:g,onGetInstance:p,...u}=i,j=u.screenshot??!1,y=u.pip??!0,M=u.setting??!0,T=u.fullscreen??!0,f=u.fullscreenWeb??!1,B=u.lock??!1,V=u.fastForward??!0,wt=u.flip??!0,jt=u.aspectRatio??!0,Ne=u.hotKey??!0,yt=u.backdrop??!0,oe=u.gestureSeek??!1,kt=u.centerControls??!0,Me=u.fetchTimeout??3e4;u.autoOrientation;const D=x.useRef(null),[n,Te]=x.useState(null),[le,ce]=x.useState(!1),[ze,St]=x.useState(0),[Ct,Nt]=x.useState(0),[Re,Mt]=x.useState(!1),Ie=x.useMemo(()=>pt(u),[]),a=x.useSyncExternalStore(x.useCallback(l=>n?n.store.subscribe(l):()=>{},[n]),()=>n?n.store.get():Ie,()=>Ie),[z,E]=x.useState(!1),[R,O]=x.useState(!1),[I,N]=x.useState("main"),[X,de]=x.useState({x:0,y:0,visible:!1}),[Tt,Le]=x.useState(!1),$e=ot(z,200),Ee=ot(R,200),[ue,ee]=x.useState(!1),[te,he]=x.useState(0),[zt,Pe]=x.useState(!1),[Rt,Fe]=x.useState(!1),[me,se]=x.useState(!1),[Ae,Be]=x.useState([]),[Ve,Oe]=x.useState(null),[It,Lt]=x.useState(0),[H,He]=x.useState(null),[U,ie]=x.useState(null),[Os,We]=x.useState(null),[xe,De]=x.useState(!1),fe=x.useRef(null),Ue=x.useRef(1),K=x.useRef(null),qe=x.useRef(0),J=x.useRef(!1),Y=x.useRef(null),W=x.useRef(null),pe=x.useRef(null),be=x.useRef(null),Z=x.useRef(null);x.useEffect(()=>{if(Mt("ontouchstart"in window||navigator.maxTouchPoints>0),!D.current)return;const l=new bt({...u,poster:o});g&&g.length>0&&g.forEach(w=>l.use(w)),l.attach(D.current),Te(l),p&&p(l);const m=new ResizeObserver(w=>{for(const k of w)St(k.contentRect.height),Nt(k.contentRect.width)});return m.observe(D.current),()=>{m.disconnect(),l.destroy(),Te(null)}},[]),x.useEffect(()=>{if(!n)return;const l={};u.theme!==void 0&&u.theme!==a.theme&&(l.theme=u.theme),u.themeColor!==void 0&&u.themeColor!==a.themeColor&&(l.themeColor=u.themeColor),u.iconSize!==void 0&&u.iconSize!==a.iconSize&&(l.iconSize=u.iconSize),Object.keys(l).length>0&&n.setAppearance(l),u.volume!==void 0&&Math.abs(u.volume-a.volume)>.01&&n.setVolume(u.volume),u.muted!==void 0&&u.muted!==a.isMuted&&(u.muted?n.video.muted=!0:n.video.muted=!1)},[n,u.theme,u.themeColor,u.iconSize,u.volume,u.muted]),x.useEffect(()=>{if(!n)return;const l=b||[];r&&r.length>0?(ce(!1),n.setSources(r,l)):t&&(ce(!1),n.setSources([{url:t,type:s||"auto"}],l))},[t,s,r,b,n]),x.useEffect(()=>{n&&c&&n.play().catch(()=>{console.warn("Autoplay failed (likely needs user interaction)")})},[n,c]),x.useEffect(()=>{a.isPlaying&&!le&&ce(!0)},[a.isPlaying,le]),x.useEffect(()=>{h&&n?Zt(h,n.notify.bind(n),Me).then(l=>Be(l)):Be([])},[h,n,Me]),x.useEffect(()=>(U&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ie(null)},600)),()=>{Z.current&&clearTimeout(Z.current)}),[U]),x.useEffect(()=>{const l=m=>{var k;if(!n||!Ne||((k=document.activeElement)==null?void 0:k.tagName)==="INPUT")return;switch(m.key.toLowerCase()){case" ":case"k":m.preventDefault(),n.togglePlay();break;case"arrowright":m.preventDefault(),n.skip(5);break;case"arrowleft":m.preventDefault(),n.skip(-5);break;case"arrowup":m.preventDefault(),n.setVolume(n.video.volume+.1);break;case"arrowdown":m.preventDefault(),n.setVolume(n.video.volume-.1);break;case"f":m.preventDefault(),n.toggleFullscreen();break;case"m":m.preventDefault(),n.toggleMute();break;case"escape":n.store.get().isWebFullscreen&&(m.preventDefault(),n.toggleWebFullscreen());break}};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[n,Ne]);const Ge=()=>{n&&(n.setControlsVisible(!0),W.current&&clearTimeout(W.current),!(z||R)&&(W.current=setTimeout(()=>{!a.isPlaying||z||R||n.setControlsVisible(!1)},2500)))};x.useEffect(()=>{n&&(!z&&!R&&a.isPlaying?Ge():(z||R)&&(n.setControlsVisible(!0),W.current&&clearTimeout(W.current)))},[z,R,a.isPlaying,n]);const _e=x.useCallback(()=>{!V||!n||!a.isPlaying||a.isLocked||(Ue.current=n.video.playbackRate,fe.current=setTimeout(()=>{n.video.playbackRate=2,De(!0)},500))},[V,n,a.isPlaying,a.isLocked]),ve=x.useCallback(()=>{fe.current&&clearTimeout(fe.current),xe&&n&&(n.video.playbackRate=Ue.current,De(!1))},[xe,n]),$t=l=>{_e(),oe&&!a.isLocked&&(K.current=l.touches[0].clientX,qe.current=a.currentTime,J.current=!1)},Et=l=>{if(!a.isLocked&&oe&&K.current!==null){const m=l.touches[0].clientX-K.current;if(Math.abs(m)>10&&(ve(),J.current=!0,ee(!0),D.current&&a.duration)){const w=D.current.getBoundingClientRect(),k=m/w.width,F=Math.max(0,Math.min(a.duration,qe.current+k*a.duration));he(F)}}},Pt=l=>{if(ve(),oe&&J.current){n==null||n.seek(te),ee(!1),J.current=!1,K.current=null;return}K.current=null},ge=l=>{if(!pe.current||!a.duration)return 0;const m=pe.current.getBoundingClientRect(),w="touches"in l?l.touches[0].clientX:l.clientX;return Math.max(0,Math.min(1,(w-m.left)/m.width))*a.duration},Qe=l=>{if(a.isLocked)return;ee(!0),he(ge(l));const m=k=>he(ge(k)),w=k=>{n==null||n.seek(ge(k)),ee(!1),document.removeEventListener("mousemove",m),document.removeEventListener("touchmove",m),document.removeEventListener("mouseup",w),document.removeEventListener("touchend",w)};document.addEventListener("mousemove",m),document.addEventListener("touchmove",m),document.addEventListener("mouseup",w),document.addEventListener("touchend",w)},Xe=l=>{if(!be.current)return 0;const m=be.current.getBoundingClientRect(),w="touches"in l?l.touches[0].clientX:l.clientX;return Math.max(0,Math.min(1,(w-m.left)/m.width))},Je=l=>{if(!n||a.isLocked)return;Pe(!0),n.setVolume(Xe(l));const m=k=>n.setVolume(Xe(k)),w=()=>{Pe(!1),document.removeEventListener("mousemove",m),document.removeEventListener("touchmove",m),document.removeEventListener("mouseup",w),document.removeEventListener("touchend",w)};document.addEventListener("mousemove",m),document.addEventListener("touchmove",m),document.addEventListener("mouseup",w),document.addEventListener("touchend",w)},Ft=l=>{if(!a.duration||a.isLive)return;const m=l.currentTarget.getBoundingClientRect(),w=(l.clientX-m.left)/m.width,k=w*a.duration;Lt(w*100),Oe(k),Ae.length>0&&He(Ae.find(F=>k>=F.start&&k<F.end)||null)},ne=l=>{!n||a.isLocked||(n.skip(l==="forward"?10:-10),We(l),setTimeout(()=>We(null),300))},At=l=>{if(!n)return;if(J.current){J.current=!1;return}if(z&&E(!1),R&&O(!1),me&&se(!1),X.visible&&de({...X,visible:!1}),n.setControlsVisible(!0),W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{!a.isPlaying||z||R||n.setControlsVisible(!1)},2500),a.isLocked)return;const m=l.currentTarget.getBoundingClientRect(),w=l.clientX-m.left,k=m.width,F=Date.now();Y.current?(clearTimeout(Y.current),Y.current=null,w<k*.35?(ne("rewind"),ie({type:"rewind",id:F})):w>k*.65?(ne("forward"),ie({type:"forward",id:F})):n.toggleFullscreen()):Y.current=setTimeout(()=>{n.togglePlay(),Y.current=null},250)},Bt=l=>{var w;if(l.preventDefault(),a.isLocked)return;const m=(w=D.current)==null?void 0:w.getBoundingClientRect();m&&de({visible:!0,x:l.clientX-m.left,y:l.clientY-m.top})},Vt=l=>{if(l.stopPropagation(),me){se(!1);return}Re?se(!0):n==null||n.toggleMute()},Ot=a.isMuted||a.volume===0?ss:a.volume<.5?ts:es,Ke=Math.max(100,ze-120),Ht=()=>{switch(a.iconSize){case"small":return"w-4 h-4";case"large":return"w-6 h-6";default:return"w-5 h-5"}},Wt=()=>{switch(a.iconSize){case"small":return"p-2 min-w-[32px] min-h-[32px]";case"large":return"p-3 min-w-[44px] min-h-[44px]";default:return"p-2.5 min-w-[36px] min-h-[36px]"}},L=Ht(),P=Wt(),q=(()=>{switch(a.iconSize){case"small":return{playBtn:"w-14 h-14",playIcon:"w-6 h-6",skipBtn:"w-10 h-10",skipIcon:"w-5 h-5"};case"large":return{playBtn:"w-24 h-24",playIcon:"w-12 h-12",skipBtn:"w-16 h-16",skipIcon:"w-8 h-8"};default:return{playBtn:"w-20 h-20",playIcon:"w-9 h-9",skipBtn:"w-12 h-12",skipIcon:"w-6 h-6"}}})(),Dt=!a.isLocked&&(a.controlsVisible||!a.isPlaying||z||R),Ye=Rt||zt||me,Ze=yt?"backdrop-blur-xl bg-black/80":"bg-black/95",et=x.useMemo(()=>{const l=[{id:"play",position:"left",index:10,isBuiltIn:!0},{id:"volume",position:"left",index:20,isBuiltIn:!0},{id:"time",position:"left",index:30,isBuiltIn:!0},{id:"subtitle",position:"right",index:80,isBuiltIn:!0},{id:"screenshot",position:"right",index:85,isBuiltIn:!0},{id:"pip",position:"right",index:90,isBuiltIn:!0},{id:"download",position:"right",index:95,isBuiltIn:!0},{id:"settings",position:"right",index:100,isBuiltIn:!0},{id:"fullscreenWeb",position:"right",index:110,isBuiltIn:!0},{id:"fullscreen",position:"right",index:120,isBuiltIn:!0}];return u.controls&&u.controls.forEach(m=>{const w=l.find(k=>k.id===m.id);w?Object.assign(w,m):l.push(m)}),l.filter(m=>!(m.id==="screenshot"&&!j||m.id==="pip"&&!y||m.id==="settings"&&!M||m.id==="fullscreen"&&!T||m.id==="fullscreenWeb"&&!f)).sort((m,w)=>m.index-w.index)},[u.controls,j,y,M,T,f]),tt=l=>{var m,w,k,F,at;if(!l.isBuiltIn)return e.jsx("button",{onClick:()=>{l.click?l.click(n):l.onClick&&l.onClick(n)},className:`strata-control-btn text-zinc-300 hover:text-white transition-colors hover:bg-white/10 focus:outline-none flex items-center justify-center ${P} ${l.className||""}`,style:{borderRadius:"var(--radius)",...l.style},title:l.tooltip,children:e.jsx(xt,{content:l.html||""})},l.index);switch(l.id){case"play":return e.jsx("button",{onClick:()=>n==null?void 0:n.togglePlay(),className:`strata-control-btn text-zinc-300 hover:text-white transition-colors hover:bg-white/10 focus:outline-none ${P}`,style:{borderRadius:"var(--radius)"},children:a.isPlaying?e.jsx(ct,{className:`${L} fill-current`}):e.jsx(lt,{className:`${L} fill-current`})},"play");case"volume":return e.jsxs("div",{className:"flex items-center gap-2 group/vol relative",onMouseEnter:()=>{window.matchMedia("(hover: hover)").matches&&Fe(!0)},onMouseLeave:()=>{window.matchMedia("(hover: hover)").matches&&Fe(!1)},children:[e.jsx("button",{onClick:Vt,className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 focus:outline-none ${P}`,style:{borderRadius:"var(--radius)"},children:e.jsx(Ot,{className:L})}),e.jsx("div",{className:`relative h-8 flex items-center transition-all duration-300 ease-out overflow-hidden ${Ye?"w-28 opacity-100 ml-1":"w-0 opacity-0"}`,children:e.jsxs("div",{ref:be,className:"relative w-full h-full flex items-center cursor-pointer px-2",onMouseDown:Je,onTouchStart:Je,children:[e.jsx("div",{className:"w-full h-1 bg-white/20 overflow-hidden",style:{borderRadius:"var(--radius-full)"},children:e.jsx("div",{className:"h-full bg-white",style:{width:`${(a.isMuted?0:a.volume)*100}%`,borderRadius:"var(--radius-full)"}})}),e.jsx("div",{className:"absolute h-3 w-3 bg-white shadow-md top-1/2 -translate-y-1/2 pointer-events-none",style:{left:`calc(${(a.isMuted?0:a.volume)*100}% * 0.85 + 4px)`,borderRadius:"var(--radius-full)"}})]})}),Ye&&e.jsx("div",{className:"strata-tooltip absolute bottom-full mb-2 px-1.5 py-0.5 rounded text-[10px] font-bold font-mono shadow-lg pointer-events-none whitespace-nowrap z-50 transform -translate-x-1/2",style:{left:`calc(52px + ${(a.isMuted?0:a.volume)*80}px)`},children:a.isMuted?"0%":`${Math.round(a.volume*100)}%`})]},"volume");case"time":return u.isLive?e.jsxs("div",{className:"flex items-center gap-2 px-2 py-0.5 rounded-md border border-white/10",style:{backgroundColor:`${a.themeColor}1a`,borderColor:`${a.themeColor}33`},children:[e.jsx("div",{className:"w-2 h-2 rounded-full animate-pulse",style:{backgroundColor:a.themeColor}}),e.jsx("span",{className:"text-[10px] font-bold tracking-wider",style:{color:a.themeColor},children:"LIVE"})]},"live"):e.jsxs("div",{className:"text-xs font-medium text-zinc-400 font-mono select-none hidden sm:block tabular-nums",children:[we(ue?te:a.currentTime)," ",e.jsx("span",{className:"text-zinc-600",children:"/"})," ",we(a.duration)]},"time");case"subtitle":return e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:d=>{d.stopPropagation(),O(!R),E(!1)},className:`strata-control-btn transition-colors focus:outline-none ${P} ${R?"text-[var(--accent)] bg-white/10":"text-zinc-300 hover:text-white hover:bg-white/10"}`,style:{borderRadius:"var(--radius)"},children:e.jsx(os,{className:L})}),Ee.isMounted&&e.jsx(Es,{tracks:a.subtitleTracks,current:a.currentSubtitle,onSelect:d=>n==null?void 0:n.setSubtitle(d),onUpload:d=>n==null?void 0:n.addTextTrack(d,d.name),onClose:()=>O(!1),settings:a.subtitleSettings,onSettingsChange:d=>n==null?void 0:n.updateSubtitleSettings(d),onReset:()=>n==null?void 0:n.resetSubtitleSettings(),offset:a.subtitleOffset,onOffsetChange:d=>n==null?void 0:n.setSubtitleOffset(d),maxHeight:Ke,animationClass:`strata-backdrop ${Ze} ${Ee.isVisible?"opacity-100 translate-y-0 scale-100":"opacity-0 translate-y-2 scale-95"}`})]},"subtitle");case"screenshot":return e.jsx("button",{onClick:()=>n==null?void 0:n.screenshot(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 transition-colors hidden sm:block focus:outline-none ${P}`,style:{borderRadius:"var(--radius)"},title:"Screenshot",children:e.jsx(Ss,{className:L})},"ss");case"pip":return e.jsx("button",{onClick:()=>n==null?void 0:n.togglePip(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 transition-colors hidden sm:block focus:outline-none ${P}`,style:{borderRadius:"var(--radius)"},children:e.jsx(as,{className:L})},"pip");case"download":return e.jsx("button",{onClick:()=>n==null?void 0:n.download(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 transition-colors hidden sm:block focus:outline-none ${P}`,style:{borderRadius:"var(--radius)"},children:e.jsx(ls,{className:L})},"dl");case"fullscreen":return e.jsx("button",{onClick:()=>n==null?void 0:n.toggleFullscreen(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 rounded-lg transition-transform focus:outline-none ${P}`,style:{borderRadius:"var(--radius)"},children:a.isFullscreen?e.jsx(ns,{className:L}):e.jsx(is,{className:L})},"fs");case"fullscreenWeb":return e.jsx("button",{onClick:()=>n==null?void 0:n.toggleWebFullscreen(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 hidden sm:block focus:outline-none ${P} ${a.isWebFullscreen?"text-[var(--accent)]":""}`,style:{borderRadius:"var(--radius)"},title:"Web Fullscreen",children:e.jsx(Ms,{className:L})},"fsw");case"settings":return e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:d=>{d.stopPropagation(),E(!z),O(!1),N("main")},className:`strata-control-btn transition-all duration-300 focus:outline-none ${P} ${z?"rotate-90 text-[var(--accent)] bg-white/10":"text-zinc-300 hover:text-white hover:bg-white/10"}`,style:{borderRadius:"var(--radius)"},children:e.jsx(rs,{className:L})}),$e.isMounted&&e.jsx(gt,{onClose:()=>E(!1),align:"right",maxHeight:Ke,className:`strata-backdrop ${Ze} ${$e.isVisible?"opacity-100 translate-y-0 scale-100":"opacity-0 translate-y-2 scale-95"}`,children:e.jsxs("div",{className:"w-full",children:[I==="main"&&e.jsxs("div",{className:"animate-in slide-in-from-left-4 fade-in duration-200",children:[e.jsx("div",{className:"px-3 py-2 mb-1 border-b border-white/5 font-bold text-zinc-400 uppercase text-[11px] tracking-wider flex justify-between items-center bg-white/5 sticky top-0 z-10 backdrop-blur-md",style:{borderRadius:"var(--radius)"},children:e.jsx("span",{children:"Settings"})}),a.sources.length>1&&e.jsx(C,{label:"Source",value:((m=a.sources[a.currentSourceIndex])==null?void 0:m.name)||`Source ${a.currentSourceIndex+1}`,onClick:()=>N("sources"),hasSubmenu:!0}),e.jsx(C,{label:"Speed",value:`${a.playbackRate}x`,onClick:()=>N("speed"),hasSubmenu:!0}),e.jsx(C,{label:"Quality",value:a.currentQuality===-1?"Auto":`${(w=a.qualityLevels[a.currentQuality])==null?void 0:w.height}p`,onClick:()=>N("quality"),hasSubmenu:!0}),e.jsx(C,{label:"Audio",value:((k=a.audioTracks[a.currentAudioTrack])==null?void 0:k.label)||"Default",onClick:()=>N("audio"),hasSubmenu:!0}),wt&&e.jsx(C,{label:"Flip",value:a.flipState.horizontal?"H":a.flipState.vertical?"V":"Normal",onClick:()=>N("flip"),hasSubmenu:!0}),jt&&e.jsx(C,{label:"Aspect Ratio",value:a.aspectRatio,onClick:()=>N("ratio"),hasSubmenu:!0}),e.jsx(mt,{}),e.jsx(C,{label:"Audio Boost",value:a.audioGain>1?`${a.audioGain}x`:"Off",onClick:()=>N("boost"),hasSubmenu:!0}),e.jsx(C,{label:"Watch Party",icon:e.jsx(hs,{className:"w-4 h-4"}),onClick:()=>N("party"),hasSubmenu:!0}),e.jsx(C,{label:"Cast to Device",icon:e.jsx(us,{className:"w-4 h-4"}),onClick:()=>{n==null||n.requestCast(),E(!1)}}),(F=u.settings)==null?void 0:F.map((d,G)=>d.switch!==void 0?e.jsx("div",{className:"px-1",children:e.jsx(_,{label:d.html,icon:d.icon,checked:d.switch,tooltip:d.tooltip,onChange:Ws=>{d.onSwitch&&d.onSwitch(d)}})},`cust-${G}`):e.jsx(C,{label:d.html,icon:d.icon,onClick:()=>{d.click?d.click():d.onClick&&d.onClick(),E(!1)}},`cust-${G}`)),e.jsx(mt,{}),e.jsx(C,{label:"Appearance",icon:e.jsx(vt,{className:"w-4 h-4"}),onClick:()=>N("appearance"),hasSubmenu:!0})]}),["speed","quality","audio","boost","party","appearance","sources","flip","ratio"].includes(I)&&e.jsxs("div",{className:"animate-in slide-in-from-right-4 fade-in duration-200",children:[I==="sources"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Select Source",onBack:()=>N("main")}),a.sources.map((d,G)=>e.jsx(C,{label:d.name||`Source ${G+1}`,value:d.type,active:a.currentSourceIndex===G,onClick:()=>n==null?void 0:n.switchSource(G)},G))]}),I==="speed"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Speed",onBack:()=>N("main")}),[.5,1,1.5,2].map(d=>e.jsx(C,{label:`${d}x`,active:a.playbackRate===d,onClick:()=>n.video.playbackRate=d},d))]}),I==="quality"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Quality",onBack:()=>N("main")}),e.jsx(C,{label:"Auto",active:a.currentQuality===-1,onClick:()=>n==null?void 0:n.setQuality(-1)}),a.qualityLevels.map(d=>e.jsx(C,{label:`${d.height}p`,value:`${Math.round(d.bitrate/1e3)}k`,active:a.currentQuality===d.index,onClick:()=>n==null?void 0:n.setQuality(d.index)},d.index))]}),I==="audio"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Audio Track",onBack:()=>N("main")}),a.audioTracks.length===0&&e.jsx("div",{className:"px-4 py-3 text-zinc-500 text-xs text-center",children:"No tracks available"}),a.audioTracks.map(d=>e.jsx(C,{label:d.label,value:d.language,active:a.currentAudioTrack===d.index,onClick:()=>n==null?void 0:n.setAudioTrack(d.index)},d.index))]}),I==="boost"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Audio Boost",onBack:()=>N("main")}),[1,1.5,2,3].map(d=>e.jsx(C,{label:d===1?"Off":`${d}x`,active:a.audioGain===d,onClick:()=>n==null?void 0:n.setAudioGain(d)},d))]}),I==="flip"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Video Flip",onBack:()=>N("main")}),e.jsxs("div",{className:"p-2 space-y-1",children:[e.jsx(_,{label:"Horizontal Flip",checked:a.flipState.horizontal,onChange:()=>n==null?void 0:n.setFlip("horizontal")}),e.jsx(_,{label:"Vertical Flip",checked:a.flipState.vertical,onChange:()=>n==null?void 0:n.setFlip("vertical")})]})]}),I==="ratio"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Aspect Ratio",onBack:()=>N("main")}),["default","16:9","4:3"].map(d=>e.jsx(C,{label:d==="default"?"Default":d,active:a.aspectRatio===d,onClick:()=>n==null?void 0:n.setAspectRatio(d)},d))]}),I==="party"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Watch Party",onBack:()=>N("main")}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx("p",{className:"text-xs text-zinc-400 leading-relaxed",children:"Create a synchronized room on WatchParty.me to watch together."}),e.jsx("a",{href:`https://www.watchparty.me/create?video=${encodeURIComponent(((at=a.sources[a.currentSourceIndex])==null?void 0:at.url)||t||"")}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center w-full py-2.5 bg-[var(--accent)] hover:opacity-90 text-white font-medium transition-opacity text-xs",style:{borderRadius:"var(--radius)"},children:"Create Room"})]})]}),I==="appearance"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{label:"Appearance",onBack:()=>N("main")}),e.jsxs("div",{className:"pb-1",children:[e.jsx(Q,{title:"Theme",children:e.jsx("div",{className:"grid grid-cols-2 gap-2 px-3",children:Bs.map(d=>e.jsx("button",{onClick:()=>n==null?void 0:n.setAppearance({theme:d.value,themeColor:d.color}),className:`py-2 text-xs font-bold uppercase tracking-wide transition-colors border-[length:var(--border-width)] border-white/10 ${a.theme===d.value?"bg-[var(--accent)] text-white":"bg-white/5 text-zinc-400 hover:text-white"}`,style:{borderRadius:"var(--radius)"},children:d.label},d.value))})}),e.jsx(Q,{title:"Icon Size",children:e.jsx("div",{className:"grid grid-cols-3 gap-1 px-3",children:["small","medium","large"].map(d=>e.jsx("button",{onClick:()=>n==null?void 0:n.setAppearance({iconSize:d}),className:`py-1.5 text-xs font-medium transition-colors ${a.iconSize===d?"bg-white text-black":"bg-white/5 text-zinc-400 hover:text-zinc-200"}`,style:{borderRadius:"var(--radius)"},children:d.charAt(0).toUpperCase()+d.slice(1)},d))})}),e.jsxs(Q,{title:"Theme Color",children:[e.jsx("div",{className:"grid grid-cols-6 gap-2 px-3",children:As.map(d=>e.jsx("button",{title:d.label,onClick:()=>n==null?void 0:n.setAppearance({themeColor:d.value}),className:`w-6 h-6 transition-transform hover:scale-110 ${a.themeColor===d.value?"ring-2 ring-white scale-110":"ring-1 ring-white/10"}`,style:{backgroundColor:d.value,borderRadius:"var(--radius-full)"},children:a.themeColor===d.value&&e.jsx(Ce,{className:"w-3 h-3 text-white mx-auto stroke-[3]"})},d.value))}),e.jsx("div",{className:"px-3 pt-4",children:e.jsxs("div",{className:"flex items-center gap-3 bg-white/5 p-2 hover:bg-white/10 transition-colors group",style:{borderRadius:"var(--radius)"},children:[e.jsx("div",{className:"relative w-6 h-6 overflow-hidden ring-1 ring-white/20",style:{borderRadius:"var(--radius-full)"},children:e.jsx("input",{type:"color",value:a.themeColor,onChange:d=>n==null?void 0:n.setAppearance({themeColor:d.target.value}),className:"absolute inset-[-4px] w-[150%] h-[150%] cursor-pointer p-0 border-0"})}),e.jsx("span",{className:"text-xs text-zinc-400 font-medium group-hover:text-zinc-200",children:"Custom Color"}),e.jsx("span",{className:"text-[10px] font-mono text-zinc-500 ml-auto uppercase",children:a.themeColor})]})})]})]})]})]})]})})]},"settings");default:return null}},Ut=x.useMemo(()=>{const l=[{html:"Playback",isLabel:!0},{html:"Loop",checked:a.isLooping,onClick:()=>n==null?void 0:n.toggleLoop()},{separator:!0},{html:"Transform",isLabel:!0},{html:"Flip Horizontal",onClick:()=>n==null?void 0:n.setFlip("horizontal")},{html:"Flip Vertical",onClick:()=>n==null?void 0:n.setFlip("vertical")},{separator:!0},{html:"Aspect Ratio",isLabel:!0},{html:"Default",checked:a.aspectRatio==="default",onClick:()=>n==null?void 0:n.setAspectRatio("default")},{html:"16:9",checked:a.aspectRatio==="16:9",onClick:()=>n==null?void 0:n.setAspectRatio("16:9")},{html:"4:3",checked:a.aspectRatio==="4:3",onClick:()=>n==null?void 0:n.setAspectRatio("4:3")},{separator:!0},{html:"Video Info",icon:e.jsx(Rs,{className:"w-3.5 h-3.5"}),onClick:()=>Le(!0)},{separator:!0}];return u.contextmenu&&l.push(...u.contextmenu),l.push({html:e.jsx("span",{className:"text-zinc-500 text-xs font-semibold tracking-wide",children:"StrataPlayer"}),disabled:!0}),l.push({html:"Close",onClick:m=>m(),icon:e.jsx("div",{className:"text-red-400",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})}),l},[u.contextmenu,a.aspectRatio,a.isLooping,n]),st=a.isWebFullscreen,it=e.jsxs("div",{id:u.id,ref:D,className:`group bg-black overflow-hidden select-none font-[family-name:var(--font-main)] outline-none text-zinc-100 strata-player-reset ${st?"fixed inset-0 z-[2147483647] w-screen h-screen rounded-none":"relative w-full h-full rounded-[var(--radius)]"} ${u.container||""}`,style:{touchAction:"manipulation","--accent":a.themeColor},onMouseMove:Ge,onMouseLeave:()=>{a.isPlaying&&!z&&!R&&n&&n.setControlsVisible(!1)},onMouseDown:_e,onMouseUp:ve,onTouchStart:$t,onTouchMove:Et,onTouchEnd:Pt,onContextMenu:Bt,tabIndex:0,role:"region","aria-label":"Video Player","data-theme":a.theme,children:[e.jsx("style",{children:`
|
|
25
|
+
`})]})]}),Zs=({label:s,value:t,options:i,onChange:r,icon:o})=>e.jsxs("div",{className:"py-2.5 px-3 hover:bg-white/5 group transition-colors",style:{borderRadius:"var(--radius)"},children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[o&&e.jsx("span",{className:"text-zinc-500 group-hover:text-zinc-400 transition-colors flex items-center justify-center w-4 h-4",children:e.jsx(ue,{content:o})}),e.jsx("span",{className:"text-xs font-bold text-zinc-400 uppercase tracking-wider group-hover:text-zinc-300 transition-colors",children:s})]}),e.jsxs("div",{className:"relative",children:[e.jsx("select",{value:t,onChange:c=>r(c.target.value),className:"w-full bg-zinc-800 border-[length:var(--border-width)] border-white/10 px-3 py-2 text-sm text-zinc-200 focus:outline-none focus:ring-2 appearance-none hover:bg-zinc-700 transition-colors cursor-pointer",style:{"--tw-ring-color":"var(--accent)",borderRadius:"var(--radius)"},children:i.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))}),e.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-zinc-400",children:e.jsx("svg",{width:"10",height:"6",viewBox:"0 0 10 6",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M1 1L5 5L9 1",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]}),K=({title:s,children:t})=>e.jsxs("div",{className:"py-2",children:[s&&e.jsx("h4",{className:"px-3 text-[10px] font-bold text-[var(--accent)] uppercase tracking-wider mb-1 mt-2",children:s}),e.jsx("div",{className:"space-y-0.5",children:t})]}),Fe=({children:s,onClose:t,align:i="right",maxHeight:r,className:o})=>{const c=m.useRef(null),h=m.useRef(null),[b,j]=m.useState("auto"),g=i==="center"?"left-1/2 -translate-x-1/2 origin-bottom":"right-0 origin-bottom-right";m.useLayoutEffect(()=>{if(!h.current)return;const w=()=>{h.current&&j(h.current.offsetHeight)},x=new ResizeObserver(w);return x.observe(h.current),w(),()=>x.disconnect()},[]);const u={height:b==="auto"?"auto":`${b+14}px`,maxHeight:r?`${r}px`:void 0};return e.jsx("div",{ref:c,className:`absolute bottom-full mb-4 ${g} bg-[var(--bg-panel)] backdrop-blur-xl border-[length:var(--border-width)] border-white/10 shadow-2xl overflow-hidden w-[300px] max-w-[calc(100vw-32px)] text-sm z-50 ring-1 ring-white/5 font-[family-name:var(--font-main)] flex flex-col p-1.5 transition-[height,opacity,transform] duration-300 ease-out ${o}`,style:{...u,borderRadius:"var(--radius-lg)"},onClick:w=>w.stopPropagation(),children:e.jsx("div",{className:"overflow-y-auto hide-scrollbar flex-1",style:{borderRadius:"var(--radius)"},children:e.jsx("div",{ref:h,children:s})})})},de=({content:s,className:t})=>typeof s=="string"?s.trim().startsWith("<")?e.jsx("span",{className:t,dangerouslySetInnerHTML:{__html:s}}):e.jsx("span",{className:t,children:s}):e.jsx("span",{className:t,children:s}),N=({label:s,value:t,active:i,onClick:r,hasSubmenu:o,icon:c,rightIcon:h})=>e.jsxs("button",{onClick:r,className:"w-full flex items-center justify-between px-3 py-2.5 hover:bg-white/10 transition-colors text-left text-zinc-200 active:bg-white/5 focus:outline-none focus:bg-white/10 group overflow-hidden my-0.5",style:{borderRadius:"var(--radius)"},children:[e.jsxs("div",{className:"flex items-center gap-3 overflow-hidden",children:[c&&e.jsx("span",{className:"text-zinc-400 shrink-0 group-hover:text-zinc-300 transition-colors flex items-center justify-center w-4 h-4",children:e.jsx(de,{content:c})}),e.jsx("span",{className:`font-medium truncate text-sm flex items-center ${i?"text-[var(--accent)]":""}`,title:typeof s=="string"?s:void 0,children:e.jsx(de,{content:s})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-zinc-400 shrink-0",children:[t&&e.jsx("span",{className:"text-xs font-medium truncate max-w-[60px]",title:t,children:e.jsx(de,{content:t})}),h,i&&e.jsx(Pe,{className:"w-4 h-4 text-[var(--accent)] shrink-0"}),o&&e.jsx("span",{className:"text-xs group-hover:translate-x-0.5 transition-transform text-zinc-500 shrink-0",children:"›"})]})]}),F=({label:s,onBack:t,rightAction:i})=>e.jsxs("div",{className:"px-3 py-2 mb-1 border-b border-white/5 font-bold text-zinc-400 uppercase text-[11px] tracking-wider flex justify-between items-center bg-white/5 sticky top-0 z-10 backdrop-blur-md",style:{borderRadius:"var(--radius)"},children:[e.jsxs("button",{className:"flex items-center gap-2 hover:text-white transition-colors focus:outline-none",onClick:t,children:[e.jsx(ws,{className:"w-3 h-3"}),e.jsx("span",{children:e.jsx(de,{content:s})})]}),i]}),J=()=>e.jsx("div",{className:"h-px bg-white/5 mx-2 my-1"}),ei=({items:s,onClose:t,title:i,maxHeight:r,className:o})=>{const[c,h]=m.useState([]),b=c.length>0?c[c.length-1]:null,j=b?b.children||[]:s,g=b?b.html:i||"Menu",u=()=>{h(x=>x.slice(0,-1))},w=x=>{x.children&&h(C=>[...C,x])};return e.jsx(Fe,{onClose:t,maxHeight:r,className:o,children:e.jsxs("div",{className:"animate-in fade-in slide-in-from-right-4 duration-200",children:[c.length>0?e.jsx(F,{label:g||"Menu",onBack:u}):i&&e.jsx("div",{className:"px-3 py-2 mb-1 border-b border-white/5 font-bold text-zinc-400 uppercase text-[11px] tracking-wider flex justify-between items-center bg-white/5 sticky top-0 z-10 backdrop-blur-md",style:{borderRadius:"var(--radius)"},children:e.jsx("span",{children:i})}),e.jsx("div",{className:"pb-1",children:j.map((x,C)=>x.separator?e.jsx(J,{},C):x.range?e.jsx("div",{className:"px-1",children:e.jsx(ne,{label:x.html,icon:x.icon,value:x.value??x.min??0,min:x.min??0,max:x.max??100,step:x.step??1,onChange:R=>x.onRange&&x.onRange(R),formatValue:x.formatValue})},C):x.switch!==void 0?e.jsx("div",{className:"px-1",children:e.jsx(W,{label:x.html,icon:x.icon,checked:x.switch,tooltip:x.tooltip,onChange:R=>x.onSwitch&&x.onSwitch(x,R)})},C):e.jsx(m.Fragment,{children:e.jsx(N,{label:x.html,icon:x.icon,value:x.currentLabel||x.value,active:x.active,hasSubmenu:!!x.children,onClick:()=>{x.children?w(x):x.onClick?(x.onClick(x),!x.switch&&!x.range&&t()):x.click&&(x.click(x),t())}})},C))})]})})},ti=({tracks:s,current:t,onSelect:i,onUpload:r,onClose:o,settings:c,onSettingsChange:h,onReset:b,offset:j,onOffsetChange:g,maxHeight:u,animationClass:w})=>{const[x,C]=m.useState("main"),R=m.useRef(null);return e.jsxs(Fe,{onClose:o,align:"right",maxHeight:u,className:w,children:[x==="main"&&e.jsxs("div",{className:"animate-in slide-in-from-left-4 fade-in duration-200",children:[e.jsx("div",{className:"px-3 py-2 mb-1 border-b border-white/5 font-bold text-zinc-400 uppercase text-[11px] tracking-wider flex justify-between items-center bg-white/5 sticky top-0 z-10 backdrop-blur-md",style:{borderRadius:"var(--radius)"},children:e.jsx("span",{children:"Subtitles"})}),e.jsxs("div",{children:[e.jsx(N,{label:"Upload Subtitle",icon:e.jsx(js,{className:"w-4 h-4"}),onClick:()=>{var p;return(p=R.current)==null?void 0:p.click()}}),e.jsx("input",{type:"file",accept:".vtt,.srt",ref:R,className:"hidden",onChange:p=>{var D;(D=p.target.files)!=null&&D[0]&&r(p.target.files[0])}}),e.jsx(N,{label:"Customize",icon:e.jsx(Ms,{className:"w-4 h-4"}),onClick:()=>C("customize"),hasSubmenu:!0}),e.jsx("div",{className:"h-px bg-white/5 mx-2 my-1"}),e.jsx(N,{label:"Off",active:t===-1,onClick:()=>{i(-1),o()}}),s.map(p=>e.jsx(N,{label:p.label,value:p.language,active:t===p.index,onClick:()=>{i(p.index),o()}},p.index))]})]}),x==="customize"&&e.jsxs("div",{className:"animate-in slide-in-from-right-4 fade-in duration-200",children:[e.jsx(F,{label:"Customize",onBack:()=>C("main"),rightAction:e.jsx("button",{onClick:b,className:"p-1.5 text-zinc-400 hover:text-white transition-colors rounded-md hover:bg-white/10",title:"Reset All",children:e.jsx(Rs,{className:"w-4 h-4"})})}),e.jsxs("div",{className:"pb-1",children:[e.jsx(K,{children:e.jsx(W,{label:"Native Video Subtitle",checked:c.useNative,onChange:p=>h({useNative:p})})}),!c.useNative&&e.jsxs(e.Fragment,{children:[e.jsxs(K,{title:"Sync & Position",children:[e.jsxs("div",{className:"py-2.5 px-3 rounded-lg hover:bg-white/5 group transition-colors",children:[e.jsx("div",{className:"flex justify-between items-center mb-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ss,{className:"w-4 h-4 text-zinc-500 group-hover:text-zinc-400 transition-colors"}),e.jsx("span",{className:"text-xs font-bold text-zinc-400 uppercase tracking-wider group-hover:text-zinc-300 transition-colors",children:"Sync Offset"})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>g(Math.round((j-.1)*10)/10),className:"w-8 h-8 flex items-center justify-center bg-zinc-800 rounded-lg hover:bg-zinc-700 text-zinc-300 transition-colors active:scale-95",children:e.jsx(Cs,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 bg-zinc-900 border border-white/5 rounded-lg h-8 flex items-center justify-center text-xs font-mono font-medium text-[var(--accent)]",children:[j>0?"+":"",(j==null?void 0:j.toFixed(1))||"0.0","s"]}),e.jsx("button",{onClick:()=>g(Math.round((j+.1)*10)/10),className:"w-8 h-8 flex items-center justify-center bg-zinc-800 rounded-lg hover:bg-zinc-700 text-zinc-300 transition-colors active:scale-95",children:e.jsx(Ns,{className:"w-4 h-4"})})]})]}),e.jsx(ne,{label:"Vertical Position",icon:e.jsx(Is,{className:"w-4 h-4"}),value:c.verticalOffset,min:0,max:200,step:5,onChange:p=>h({verticalOffset:p}),formatValue:p=>`${p}px`})]}),e.jsxs(K,{title:"Appearance",children:[e.jsx(ne,{label:"Text Size",icon:e.jsx(Ts,{className:"w-4 h-4"}),value:c.textSize,min:50,max:200,step:10,onChange:p=>h({textSize:p}),formatValue:p=>`${p}%`}),e.jsxs("div",{className:"py-2.5 px-3 rounded-lg hover:bg-white/5 group transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Mt,{className:"w-4 h-4 text-zinc-500 group-hover:text-zinc-400 transition-colors"}),e.jsx("span",{className:"text-xs font-bold text-zinc-400 uppercase tracking-wider group-hover:text-zinc-300 transition-colors",children:"Text Color"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 p-1 bg-zinc-800/50 rounded-lg",children:[["#ffffff","#ffff00","#00ffff","#ff00ff","#ff0000","#00ff00"].map(p=>e.jsx("button",{onClick:()=>h({textColor:p}),className:`w-6 h-6 rounded-full border border-white/10 transition-transform hover:scale-110 ${c.textColor===p?"ring-2 scale-110":""}`,style:{backgroundColor:p,"--tw-ring-color":"var(--accent)"}},p)),e.jsx("div",{className:"w-px h-6 bg-white/10 mx-1"}),e.jsx("div",{className:"relative w-6 h-6 rounded-full overflow-hidden ring-1 ring-white/20 cursor-pointer",children:e.jsx("input",{type:"color",value:c.textColor,onChange:p=>h({textColor:p.target.value}),className:"absolute inset-[-4px] w-[150%] h-[150%] cursor-pointer p-0 border-0"})})]})]}),e.jsx(Zs,{label:"Text Style",value:c.textStyle,options:[{label:"None",value:"none"},{label:"Outline",value:"outline"},{label:"Raised",value:"raised"},{label:"Depressed",value:"depressed"},{label:"Drop Shadow",value:"shadow"}],onChange:p=>h({textStyle:p})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-1 px-1",children:[e.jsx(W,{label:"Bold",icon:e.jsx(Ls,{className:"w-4 h-4"}),checked:c.isBold,onChange:p=>h({isBold:p})}),e.jsx(W,{label:"Fix Caps",icon:e.jsx($s,{className:"w-4 h-4"}),checked:c.fixCapitalization,onChange:p=>h({fixCapitalization:p})})]})]}),e.jsxs(K,{title:"Background",children:[e.jsx(ne,{label:"Opacity",icon:e.jsx(zs,{className:"w-4 h-4"}),value:c.backgroundOpacity,min:0,max:100,step:5,onChange:p=>h({backgroundOpacity:p}),formatValue:p=>`${p}%`}),e.jsx(W,{label:"Blur Background",icon:e.jsx(Es,{className:"w-4 h-4"}),checked:c.backgroundBlur,onChange:p=>h({backgroundBlur:p})}),c.backgroundBlur&&e.jsx(ne,{label:"Blur Intensity",value:c.backgroundBlurAmount,min:0,max:20,step:1,onChange:p=>h({backgroundBlurAmount:p}),formatValue:p=>`${p}px`})]})]})]})]})]})},Re=({content:s})=>typeof s=="string"?s.trim().startsWith("<")?e.jsx("span",{dangerouslySetInnerHTML:{__html:s}}):e.jsx("span",{children:s}):e.jsx(e.Fragment,{children:s}),si=({x:s,y:t,items:i,onClose:r,containerWidth:o,containerHeight:c})=>{const h=m.useRef(null),[b,j]=m.useState({top:t,left:s,opacity:0});return m.useLayoutEffect(()=>{if(!h.current)return;const g=h.current.getBoundingClientRect(),u=g.width,w=g.height;let x=s,C=t;s+u>o-10&&(x=s-u),x<10&&(x=10),x+u>o&&(x=Math.max(10,o-u-10)),t+w>c-10&&(C=t-w);let R=c-20;C<10&&(C=10),C+w>c-10&&(C=Math.max(10,c-w-10)),j({top:C,left:x,maxHeight:R,opacity:1})},[s,t,i,o,c]),m.useEffect(()=>{const g=u=>{h.current&&!h.current.contains(u.target)&&r()};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[r]),e.jsx("div",{ref:h,className:"absolute z-50 min-w-[200px] bg-[var(--bg-panel)] backdrop-blur-xl border-[length:var(--border-width)] border-white/10 shadow-2xl p-1.5 font-[family-name:var(--font-main)] overflow-y-auto hide-scrollbar flex flex-col",style:{top:b.top,left:b.left,maxHeight:b.maxHeight,opacity:b.opacity,borderRadius:"var(--radius-lg)"},onClick:g=>g.stopPropagation(),children:i.map((g,u)=>g.separator?e.jsx("div",{className:"h-0 border-t border-white/10 mx-2 my-1.5"},u):g.isLabel?e.jsx("div",{className:"px-3 py-1.5 text-[10px] font-bold text-zinc-500 uppercase tracking-wider select-none",children:e.jsx(Re,{content:g.html||""})},u):e.jsxs(m.Fragment,{children:[e.jsxs("button",{onClick:()=>{g.disabled||(g.click?g.click(r):g.onClick&&g.onClick(r))},disabled:g.disabled,className:"w-full text-left px-3 py-2.5 flex items-center justify-between hover:bg-white/10 focus:bg-white/10 focus:outline-none transition-colors text-sm text-zinc-200 disabled:opacity-50 disabled:cursor-not-allowed group my-0.5",style:{borderRadius:"var(--radius)"},children:[e.jsxs("div",{className:"flex items-center gap-3 overflow-hidden",children:[g.icon&&e.jsx("span",{className:"text-zinc-400 w-4 h-4 flex items-center justify-center shrink-0 group-hover:text-zinc-300 transition-colors",children:e.jsx(Re,{content:g.icon})}),e.jsx("span",{className:`flex items-center font-medium truncate ${g.checked?"text-[var(--accent)]":""}`,children:e.jsx(Re,{content:g.html||""})})]}),g.checked&&e.jsx(Pe,{className:"w-4 h-4 text-[var(--accent)] shrink-0 ml-2"})]}),g.showBorder&&e.jsx("div",{className:"h-0 border-t border-white/10 mx-2 my-1"})]},u))})},ii=({player:s,onClose:t})=>{const[i,r]=m.useState({});return m.useEffect(()=>{const o=()=>{var j;if(!s.video)return;const h=s.video,b=h.getVideoPlaybackQuality?h.getVideoPlaybackQuality():null;r({"Player Size":`${h.offsetWidth} x ${h.offsetHeight}`,"Video Resolution":`${h.videoWidth} x ${h.videoHeight}`,"Current Time":`${h.currentTime.toFixed(3)}s`,Duration:`${h.duration.toFixed(3)}s`,Volume:`${Math.round(h.volume*100)}%`,"Dropped Frames":b?b.droppedVideoFrames:"N/A",Buffer:h.buffered.length>0?`${(h.buffered.end(h.buffered.length-1)-h.currentTime).toFixed(2)}s`:"0s",Engine:((j=s.store.get().sources[s.store.get().currentSourceIndex])==null?void 0:j.type)||"native",URL:h.currentSrc})};o();const c=setInterval(o,1e3);return()=>clearInterval(c)},[s]),e.jsx("div",{className:"absolute inset-0 z-[60] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-[var(--bg-panel)] border border-white/10 rounded-xl w-full max-w-md shadow-2xl relative font-mono text-xs text-zinc-300 flex flex-col",style:{borderRadius:"var(--radius)",maxHeight:"90%"},children:[e.jsxs("div",{className:"p-5 pb-0 flex-shrink-0 relative",children:[e.jsx("button",{onClick:o=>{o.stopPropagation(),t()},className:"absolute top-3 right-3 p-1.5 text-zinc-400 hover:text-white hover:bg-white/10 rounded-full transition-colors",children:e.jsx(Os,{className:"w-4 h-4"})}),e.jsx("h3",{className:"text-sm font-bold text-white mb-4 uppercase tracking-wider border-b border-white/10 pb-2",children:"Video Statistics"})]}),e.jsx("div",{className:"overflow-y-auto hide-scrollbar p-5 pt-0 space-y-2.5 flex-1 min-h-0",children:Object.entries(i).map(([o,c])=>e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-center gap-1",children:[e.jsx("span",{className:"text-zinc-500 font-bold shrink-0",children:o}),e.jsx("span",{className:"text-zinc-200 truncate select-all font-medium bg-white/5 px-1.5 py-0.5 rounded break-all text-right",title:String(c),children:String(c)})]},o))})]})})};function ni(s){if(!s)return"#ffffff";s=s.replace("#",""),s.length===3&&(s=s.split("").map(c=>c+c).join(""));const t=parseInt(s.substring(0,2),16),i=parseInt(s.substring(2,4),16),r=parseInt(s.substring(4,6),16);return(t*299+i*587+r*114)/1e3>=128?"#000000":"#ffffff"}const ri=[{label:"Strata",value:"#6366f1"},{label:"Emerald",value:"#10b981"},{label:"Rose",value:"#f43f5e"},{label:"Amber",value:"#f59e0b"},{label:"Sky",value:"#0ea5e9"},{label:"Violet",value:"#8b5cf6"}],ai=[{label:"Default",value:"default",color:"#6366f1"},{label:"Pixel",value:"pixel",color:"#ef4444"},{label:"Game",value:"game",color:"#eab308"},{label:"Hacker",value:"hacker",color:"#22c55e"}],kt=({content:s,className:t,style:i})=>typeof s=="string"?s.trim().startsWith("<")?e.jsx("div",{className:t,style:i,dangerouslySetInnerHTML:{__html:s}}):e.jsx("div",{className:t,style:i,children:s}):e.jsx("div",{className:t,style:i,children:s}),$e=s=>{var pt,bt;const{src:t,type:i,sources:r,poster:o,autoPlay:c,thumbnails:h,textTracks:b,plugins:j,onGetInstance:g,...u}=s,w=u.screenshot??!1,x=u.pip??!0,C=u.setting??!0,R=u.fullscreen??!0,p=u.fullscreenWeb??!1,D=u.lock??!1,q=u.fastForward??!0,Tt=u.flip??!0,zt=u.aspectRatio??!0,Ae=u.hotKey??!0,It=u.backdrop??!0,he=u.gestureSeek??!1,Rt=u.centerControls??!0,Be=u.fetchTimeout??3e4;u.autoOrientation;const U=m.useRef(null),[n,Ve]=m.useState(null),[xe,me]=m.useState(!1),[Oe,Lt]=m.useState(0),[$t,Et]=m.useState(0),[He,Pt]=m.useState(!1),We=m.useMemo(()=>Ct(u),[]),a=m.useSyncExternalStore(m.useCallback(l=>n?n.store.subscribe(l):()=>{},[n]),()=>n?n.store.get():We,()=>We),Ft=m.useMemo(()=>ni(a.themeColor),[a.themeColor]),[L,Y]=m.useState(!1),[$,fe]=m.useState(!1),[E,z]=m.useState("main"),[I,De]=m.useState(null),qe=m.useRef(null);I&&(qe.current=I);const[Z,pe]=m.useState({x:0,y:0,visible:!1}),[At,_e]=m.useState(!1),Ge=Ie(L,300),Ue=Ie($,300),Qe=Ie(!!I,300),P=m.useCallback(()=>{Y(!1),fe(!1),De(null)},[]),[be,re]=m.useState(!1),[ae,ge]=m.useState(0),[Bt,Xe]=m.useState(!1),[Vt,Je]=m.useState(!1),[ve,oe]=m.useState(!1),[Ke,Ye]=m.useState([]),[Ze,et]=m.useState(null),[Ot,Ht]=m.useState(0),[_,tt]=m.useState(null),[Q,le]=m.useState(null),[li,st]=m.useState(null),[je,it]=m.useState(!1),we=m.useRef(null),nt=m.useRef(1),te=m.useRef(null),rt=m.useRef(0),ee=m.useRef(!1),se=m.useRef(null),G=m.useRef(null),ye=m.useRef(null),ke=m.useRef(null),ie=m.useRef(null);m.useEffect(()=>{if(Pt("ontouchstart"in window||navigator.maxTouchPoints>0),!U.current)return;const l=new Nt({...u,poster:o});j&&j.length>0&&j.forEach(y=>l.use(y)),l.attach(U.current),Ve(l),g&&g(l);const f=new ResizeObserver(y=>{for(const k of y)Lt(k.contentRect.height),Et(k.contentRect.width)});return f.observe(U.current),()=>{f.disconnect(),l.destroy(),Ve(null)}},[]),m.useEffect(()=>{if(!n)return;const l={};u.theme!==void 0&&u.theme!==a.theme&&(l.theme=u.theme),u.themeColor!==void 0&&u.themeColor!==a.themeColor&&(l.themeColor=u.themeColor),u.iconSize!==void 0&&u.iconSize!==a.iconSize&&(l.iconSize=u.iconSize),Object.keys(l).length>0&&n.setAppearance(l),u.volume!==void 0&&Math.abs(u.volume-a.volume)>.01&&n.setVolume(u.volume),u.muted!==void 0&&u.muted!==a.isMuted&&(u.muted?n.video.muted=!0:n.video.muted=!1)},[n,u.theme,u.themeColor,u.iconSize,u.volume,u.muted]),m.useEffect(()=>{if(!n)return;const l=b||[];r&&r.length>0?(me(!1),n.setSources(r,l)):t&&(me(!1),n.setSources([{url:t,type:i||"auto"}],l))},[t,i,r,b,n]),m.useEffect(()=>{n&&c&&n.play().catch(()=>{console.warn("Autoplay failed (likely needs user interaction)")})},[n,c]),m.useEffect(()=>{a.isPlaying&&!xe&&me(!0)},[a.isPlaying,xe]),m.useEffect(()=>{h&&n?cs(h,n.notify.bind(n),Be).then(l=>Ye(l)):Ye([])},[h,n,Be]),m.useEffect(()=>(Q&&(ie.current&&clearTimeout(ie.current),ie.current=setTimeout(()=>{le(null)},600)),()=>{ie.current&&clearTimeout(ie.current)}),[Q]),m.useEffect(()=>{const l=f=>{var k;if(!n||!Ae||((k=document.activeElement)==null?void 0:k.tagName)==="INPUT")return;switch(f.key.toLowerCase()){case" ":case"k":f.preventDefault(),n.togglePlay();break;case"arrowright":f.preventDefault(),n.skip(5);break;case"arrowleft":f.preventDefault(),n.skip(-5);break;case"arrowup":f.preventDefault(),n.setVolume(n.video.volume+.1);break;case"arrowdown":f.preventDefault(),n.setVolume(n.video.volume-.1);break;case"f":f.preventDefault(),n.toggleFullscreen();break;case"m":f.preventDefault(),n.toggleMute();break;case"escape":n.store.get().isWebFullscreen&&(f.preventDefault(),n.toggleWebFullscreen());break}};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[n,Ae]);const at=()=>{n&&(n.setControlsVisible(!0),G.current&&clearTimeout(G.current),!(L||$||I)&&(G.current=setTimeout(()=>{!a.isPlaying||L||$||I||n.setControlsVisible(!1)},2500)))};m.useEffect(()=>{n&&(!L&&!$&&!I&&a.isPlaying?at():(L||$||I)&&(n.setControlsVisible(!0),G.current&&clearTimeout(G.current)))},[L,$,I,a.isPlaying,n]);const ot=m.useCallback(()=>{if(!(!q||!n||!a.isPlaying||a.isLocked)){if(L||$||I){P();return}nt.current=n.video.playbackRate,we.current=setTimeout(()=>{n.video.playbackRate=2,it(!0)},500)}},[q,n,a.isPlaying,a.isLocked,L,$,I]),Se=m.useCallback(()=>{we.current&&clearTimeout(we.current),je&&n&&(n.video.playbackRate=nt.current,it(!1))},[je,n]),Wt=l=>{if(ot(),L||$||I){P();return}he&&!a.isLocked&&(te.current=l.touches[0].clientX,rt.current=a.currentTime,ee.current=!1)},Dt=l=>{if(!a.isLocked&&he&&te.current!==null){const f=l.touches[0].clientX-te.current;if(Math.abs(f)>10&&(Se(),ee.current=!0,re(!0),U.current&&a.duration)){const y=U.current.getBoundingClientRect(),k=f/y.width,O=Math.max(0,Math.min(a.duration,rt.current+k*a.duration));ge(O)}}},qt=l=>{if(Se(),he&&ee.current){n==null||n.seek(ae),re(!1),ee.current=!1,te.current=null;return}te.current=null},Ce=l=>{if(!ye.current||!a.duration)return 0;const f=ye.current.getBoundingClientRect(),y="touches"in l?l.touches[0].clientX:l.clientX;return Math.max(0,Math.min(1,(y-f.left)/f.width))*a.duration},lt=l=>{if(a.isLocked)return;(L||$||I)&&P(),re(!0),ge(Ce(l));const f=k=>ge(Ce(k)),y=k=>{n==null||n.seek(Ce(k)),re(!1),document.removeEventListener("mousemove",f),document.removeEventListener("touchmove",f),document.removeEventListener("mouseup",y),document.removeEventListener("touchend",y)};document.addEventListener("mousemove",f),document.addEventListener("touchmove",f),document.addEventListener("mouseup",y),document.addEventListener("touchend",y)},ct=l=>{if(!ke.current)return 0;const f=ke.current.getBoundingClientRect(),y="touches"in l?l.touches[0].clientX:l.clientX;return Math.max(0,Math.min(1,(y-f.left)/f.width))},dt=l=>{if(!n||a.isLocked)return;Xe(!0),n.setVolume(ct(l));const f=k=>n.setVolume(ct(k)),y=()=>{Xe(!1),document.removeEventListener("mousemove",f),document.removeEventListener("touchmove",f),document.removeEventListener("mouseup",y),document.removeEventListener("touchend",y)};document.addEventListener("mousemove",f),document.addEventListener("touchmove",f),document.addEventListener("mouseup",y),document.addEventListener("touchend",y)},_t=l=>{if(!a.duration||a.isLive)return;const f=l.currentTarget.getBoundingClientRect(),y=(l.clientX-f.left)/f.width,k=y*a.duration;Ht(y*100),et(k),Ke.length>0&&tt(Ke.find(O=>k>=O.start&&k<O.end)||null)},ce=l=>{!n||a.isLocked||(n.skip(l==="forward"?10:-10),st(l),setTimeout(()=>st(null),300))},Gt=l=>{if(!n)return;if(ee.current){ee.current=!1;return}if(L||$||I){P();return}if(ve&&oe(!1),Z.visible&&pe({...Z,visible:!1}),n.setControlsVisible(!0),G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{!a.isPlaying||L||$||I||n.setControlsVisible(!1)},2500),a.isLocked)return;const f=l.currentTarget.getBoundingClientRect(),y=l.clientX-f.left,k=f.width,O=Date.now();se.current?(clearTimeout(se.current),se.current=null,y<k*.35?(ce("rewind"),le({type:"rewind",id:O})):y>k*.65?(ce("forward"),le({type:"forward",id:O})):n.toggleFullscreen()):se.current=setTimeout(()=>{n.togglePlay(),se.current=null},250)},Ut=l=>{var y;if(l.preventDefault(),a.isLocked)return;const f=(y=U.current)==null?void 0:y.getBoundingClientRect();f&&pe({visible:!0,x:l.clientX-f.left,y:l.clientY-f.top})},Qt=l=>{if(l.stopPropagation(),ve){oe(!1);return}He?oe(!0):n==null||n.toggleMute()},Xt=a.isMuted||a.volume===0?xs:a.volume<.5?hs:us,Ne=Math.max(100,Oe-120),Jt=()=>{switch(a.iconSize){case"small":return"w-4 h-4";case"large":return"w-6 h-6";default:return"w-5 h-5"}},Kt=()=>{switch(a.iconSize){case"small":return"p-2 min-w-[32px] min-h-[32px]";case"large":return"p-3 min-w-[44px] min-h-[44px]";default:return"p-2.5 min-w-[36px] min-h-[36px]"}},A=Jt(),V=Kt(),X=(()=>{switch(a.iconSize){case"small":return{playBtn:"w-14 h-14",playIcon:"w-6 h-6",skipBtn:"w-10 h-10",skipIcon:"w-5 h-5"};case"large":return{playBtn:"w-24 h-24",playIcon:"w-12 h-12",skipBtn:"w-16 h-16",skipIcon:"w-8 h-8"};default:return{playBtn:"w-20 h-20",playIcon:"w-9 h-9",skipBtn:"w-12 h-12",skipIcon:"w-6 h-6"}}})(),Yt=!a.isLocked&&(a.controlsVisible||!a.isPlaying||L||$||I),ut=Vt||Bt||ve,Me=It?"backdrop-blur-xl bg-black/80":"bg-black/95",ht=m.useMemo(()=>{const l=[{id:"play",position:"left",index:10,isBuiltIn:!0},{id:"volume",position:"left",index:20,isBuiltIn:!0},{id:"time",position:"left",index:30,isBuiltIn:!0},{id:"subtitle",position:"right",index:80,isBuiltIn:!0},{id:"screenshot",position:"right",index:85,isBuiltIn:!0},{id:"pip",position:"right",index:90,isBuiltIn:!0},{id:"download",position:"right",index:95,isBuiltIn:!0},{id:"settings",position:"right",index:100,isBuiltIn:!0},{id:"fullscreenWeb",position:"right",index:110,isBuiltIn:!0},{id:"fullscreen",position:"right",index:120,isBuiltIn:!0}];return u.controls&&u.controls.forEach(f=>{const y=l.find(k=>k.id===f.id);y?Object.assign(y,f):l.push(f)}),l.filter(f=>!(f.id==="screenshot"&&!w||f.id==="pip"&&!x||f.id==="settings"&&!C||f.id==="fullscreen"&&!R||f.id==="fullscreenWeb"&&!p)).sort((f,y)=>f.index-y.index)},[u.controls,w,x,C,R,p]),xt=l=>{var f,y,k,O,gt;if(!l.isBuiltIn){const d=l.id||`ctrl-${l.index}`,T=I===d,H=T||Qe.isMounted&&qe.current===d;return e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:M=>{if(M.stopPropagation(),l.children){const Te=T;P(),Te||De(d)}else l.click?l.click(n):l.onClick&&l.onClick(n)},className:`strata-control-btn transition-colors focus:outline-none flex items-center justify-center ${V} ${T?"text-[var(--accent)] bg-white/10":"text-zinc-300 hover:text-white hover:bg-white/10"} ${l.className||""}`,style:{borderRadius:"var(--radius)",...l.style},title:l.tooltip,children:e.jsx(kt,{content:l.html||""})}),l.children&&H&&e.jsx(ei,{items:l.children,onClose:P,maxHeight:Ne,className:`strata-backdrop ${Me} ${Qe.isVisible?"opacity-100 translate-y-0 scale-100 animate-in fade-in zoom-in-95 duration-300":"opacity-0 translate-y-2 scale-95 duration-300"}`})]},l.index)}switch(l.id){case"play":return e.jsx("button",{onClick:()=>n==null?void 0:n.togglePlay(),className:`strata-control-btn text-zinc-300 hover:text-white transition-colors hover:bg-white/10 focus:outline-none ${V}`,style:{borderRadius:"var(--radius)"},children:a.isPlaying?e.jsx(jt,{className:`${A} fill-current`}):e.jsx(vt,{className:`${A} fill-current`})},"play");case"volume":return e.jsxs("div",{className:"flex items-center gap-2 group/vol relative",onMouseEnter:()=>{window.matchMedia("(hover: hover)").matches&&Je(!0)},onMouseLeave:()=>{window.matchMedia("(hover: hover)").matches&&Je(!1)},children:[e.jsx("button",{onClick:Qt,className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 focus:outline-none ${V}`,style:{borderRadius:"var(--radius)"},children:e.jsx(Xt,{className:A})}),e.jsx("div",{className:`relative h-8 flex items-center transition-all duration-300 ease-out overflow-hidden ${ut?"w-28 opacity-100 ml-1":"w-0 opacity-0"}`,children:e.jsxs("div",{ref:ke,className:"relative w-full h-full flex items-center cursor-pointer px-2",onMouseDown:dt,onTouchStart:dt,children:[e.jsx("div",{className:"w-full h-1 bg-white/20 overflow-hidden",style:{borderRadius:"var(--radius-full)"},children:e.jsx("div",{className:"h-full bg-white",style:{width:`${(a.isMuted?0:a.volume)*100}%`,borderRadius:"var(--radius-full)"}})}),e.jsx("div",{className:"absolute h-3 w-3 bg-white shadow-md top-1/2 -translate-y-1/2 pointer-events-none",style:{left:`calc(${(a.isMuted?0:a.volume)*100}% * 0.85 + 4px)`,borderRadius:"var(--radius-full)"}})]})}),ut&&e.jsx("div",{className:"strata-tooltip absolute bottom-full mb-2 px-1.5 py-0.5 rounded text-[10px] font-bold font-mono shadow-lg pointer-events-none whitespace-nowrap z-50 transform -translate-x-1/2",style:{left:`calc(52px + ${(a.isMuted?0:a.volume)*80}px)`},children:a.isMuted?"0%":`${Math.round(a.volume*100)}%`})]},"volume");case"time":return u.isLive?e.jsxs("div",{className:"flex items-center gap-2 px-2 py-0.5 rounded-md border border-white/10",style:{backgroundColor:`${a.themeColor}1a`,borderColor:`${a.themeColor}33`},children:[e.jsx("div",{className:"w-2 h-2 rounded-full animate-pulse",style:{backgroundColor:a.themeColor}}),e.jsx("span",{className:"text-[10px] font-bold tracking-wider",style:{color:a.themeColor},children:"LIVE"})]},"live"):e.jsxs("div",{className:"text-xs font-medium text-zinc-400 font-mono select-none hidden sm:block tabular-nums",children:[ze(be?ae:a.currentTime)," ",e.jsx("span",{className:"text-zinc-600",children:"/"})," ",ze(a.duration)]},"time");case"subtitle":return e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:d=>{d.stopPropagation();const T=$;P(),T||fe(!0)},className:`strata-control-btn transition-colors focus:outline-none ${V} ${$?"text-[var(--accent)] bg-white/10":"text-zinc-300 hover:text-white hover:bg-white/10"}`,style:{borderRadius:"var(--radius)"},children:e.jsx(gs,{className:A})}),Ue.isMounted&&e.jsx(ti,{tracks:a.subtitleTracks,current:a.currentSubtitle,onSelect:d=>n==null?void 0:n.setSubtitle(d),onUpload:d=>n==null?void 0:n.addTextTrack(d,d.name),onClose:()=>fe(!1),settings:a.subtitleSettings,onSettingsChange:d=>n==null?void 0:n.updateSubtitleSettings(d),onReset:()=>n==null?void 0:n.resetSubtitleSettings(),offset:a.subtitleOffset,onOffsetChange:d=>n==null?void 0:n.setSubtitleOffset(d),maxHeight:Ne,animationClass:`strata-backdrop ${Me} ${Ue.isVisible?"opacity-100 translate-y-0 scale-100 animate-in fade-in zoom-in-95 duration-300":"opacity-0 translate-y-2 scale-95 duration-300"}`})]},"subtitle");case"screenshot":return e.jsx("button",{onClick:()=>n==null?void 0:n.screenshot(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 transition-colors hidden sm:block focus:outline-none ${V}`,style:{borderRadius:"var(--radius)"},title:"Screenshot",children:e.jsx(Ps,{className:A})},"ss");case"pip":return e.jsx("button",{onClick:()=>n==null?void 0:n.togglePip(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 transition-colors hidden sm:block focus:outline-none ${V}`,style:{borderRadius:"var(--radius)"},children:e.jsx(bs,{className:A})},"pip");case"download":return e.jsx("button",{onClick:()=>n==null?void 0:n.download(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 transition-colors hidden sm:block focus:outline-none ${V}`,style:{borderRadius:"var(--radius)"},children:e.jsx(vs,{className:A})},"dl");case"fullscreen":return e.jsx("button",{onClick:()=>n==null?void 0:n.toggleFullscreen(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 rounded-lg transition-transform focus:outline-none ${V}`,style:{borderRadius:"var(--radius)"},children:a.isFullscreen?e.jsx(fs,{className:A}):e.jsx(ms,{className:A})},"fs");case"fullscreenWeb":return e.jsx("button",{onClick:()=>n==null?void 0:n.toggleWebFullscreen(),className:`strata-control-btn text-zinc-300 hover:text-white hover:bg-white/10 hidden sm:block focus:outline-none ${V} ${a.isWebFullscreen?"text-[var(--accent)]":""}`,style:{borderRadius:"var(--radius)"},title:"Web Fullscreen",children:e.jsx(Bs,{className:A})},"fsw");case"settings":return e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:d=>{d.stopPropagation();const T=L;P(),T||(Y(!0),z("main"))},className:`strata-control-btn transition-all duration-300 focus:outline-none ${V} ${L?"rotate-90 text-[var(--accent)] bg-white/10":"text-zinc-300 hover:text-white hover:bg-white/10"}`,style:{borderRadius:"var(--radius)"},children:e.jsx(ps,{className:A})}),Ge.isMounted&&e.jsx(Fe,{onClose:()=>Y(!1),align:"right",maxHeight:Ne,className:`strata-backdrop ${Me} ${Ge.isVisible?"opacity-100 translate-y-0 scale-100 animate-in fade-in zoom-in-95 duration-300":"opacity-0 translate-y-2 scale-95 duration-300"}`,children:e.jsxs("div",{className:"w-full",children:[E==="main"&&e.jsxs("div",{className:"animate-in slide-in-from-left-4 fade-in duration-200",children:[e.jsx("div",{className:"px-3 py-2 mb-1 border-b border-white/5 font-bold text-zinc-400 uppercase text-[11px] tracking-wider flex justify-between items-center bg-white/5 sticky top-0 z-10 backdrop-blur-md",style:{borderRadius:"var(--radius)"},children:e.jsx("span",{children:"Settings"})}),a.sources.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(N,{label:"Source",icon:e.jsx(Ws,{className:"w-4 h-4"}),value:((f=a.sources[a.currentSourceIndex])==null?void 0:f.name)||`Source ${a.currentSourceIndex+1}`,onClick:()=>z("sources"),hasSubmenu:!0}),e.jsx(J,{})]}),e.jsx(N,{label:"Quality",icon:e.jsx(Ds,{className:"w-4 h-4"}),value:a.currentQuality===-1?"Auto":`${(y=a.qualityLevels[a.currentQuality])==null?void 0:y.height}p`,onClick:()=>z("quality"),hasSubmenu:!0}),e.jsx(N,{label:"Speed",icon:e.jsx(Gs,{className:"w-4 h-4"}),value:`${a.playbackRate}x`,onClick:()=>z("speed"),hasSubmenu:!0}),e.jsx(N,{label:"Audio",icon:e.jsx(Us,{className:"w-4 h-4"}),value:((k=a.audioTracks[a.currentAudioTrack])==null?void 0:k.label)||"Default",onClick:()=>z("audio"),hasSubmenu:!0}),e.jsx(J,{}),Tt&&e.jsx(N,{label:"Flip",icon:e.jsx(Qs,{className:"w-4 h-4"}),value:a.flipState.horizontal?"H":a.flipState.vertical?"V":"Normal",onClick:()=>z("flip"),hasSubmenu:!0}),zt&&e.jsx(N,{label:"Aspect Ratio",icon:e.jsx(qs,{className:"w-4 h-4"}),value:a.aspectRatio,onClick:()=>z("ratio"),hasSubmenu:!0}),e.jsx(N,{label:"Audio Boost",icon:e.jsx(_s,{className:"w-4 h-4"}),value:a.audioGain>1?`${a.audioGain}x`:"Off",onClick:()=>z("boost"),hasSubmenu:!0}),e.jsx(J,{}),e.jsx(N,{label:"Watch Party",icon:e.jsx(ks,{className:"w-4 h-4"}),onClick:()=>z("party"),hasSubmenu:!0}),e.jsx(N,{label:"Cast to Device",icon:e.jsx(ys,{className:"w-4 h-4"}),onClick:()=>{n==null||n.requestCast(),Y(!1)}}),u.settings&&u.settings.length>0&&e.jsx(J,{}),(O=u.settings)==null?void 0:O.map((d,T)=>d.switch!==void 0?e.jsx("div",{className:"px-1",children:e.jsx(W,{label:d.html,icon:d.icon,checked:d.switch,tooltip:d.tooltip,onChange:H=>{d.onSwitch&&d.onSwitch(d,H)}})},`cust-${T}`):e.jsx(N,{label:d.html,icon:d.icon,value:d.currentLabel||d.value,hasSubmenu:!!d.children,onClick:()=>{d.children?z(`custom-${T}`):(d.click?d.click(d):d.onClick&&d.onClick(d),Y(!1))}},`cust-${T}`)),e.jsx(J,{}),e.jsx(N,{label:"Appearance",icon:e.jsx(Mt,{className:"w-4 h-4"}),onClick:()=>z("appearance"),hasSubmenu:!0})]}),E.startsWith("custom-")&&(()=>{var H;const d=parseInt(E.split("-")[1]),T=(H=u.settings)==null?void 0:H[d];return!T||!T.children?null:e.jsxs("div",{className:"animate-in slide-in-from-right-4 fade-in duration-200",children:[e.jsx(F,{label:T.html||"Menu",onBack:()=>z("main")}),T.children.map((M,Te)=>e.jsxs(m.Fragment,{children:[M.separator&&e.jsx(J,{}),M.switch!==void 0&&e.jsx("div",{className:"px-1",children:e.jsx(W,{label:M.html,checked:M.switch,onChange:es=>M.onSwitch&&M.onSwitch(M,es)})}),!M.separator&&M.switch===void 0&&e.jsx(N,{label:M.html,icon:M.icon,value:M.value,active:M.active,onClick:()=>{M.onClick?M.onClick(M):M.click&&M.click(M),Y(!1)}})]},Te))]})})(),["speed","quality","audio","boost","party","appearance","sources","flip","ratio"].includes(E)&&e.jsxs("div",{className:"animate-in slide-in-from-right-4 fade-in duration-200",children:[E==="sources"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Select Source",onBack:()=>z("main")}),a.sources.map((d,T)=>{const H=a.sourceStatuses[T],M=H==="success"?e.jsx(Xs,{className:"w-3.5 h-3.5 text-emerald-500"}):H==="error"?e.jsx(Js,{className:"w-3.5 h-3.5 text-red-500"}):null;return e.jsx(N,{label:d.name||`Source ${T+1}`,value:d.type,active:a.currentSourceIndex===T,rightIcon:M,onClick:()=>n==null?void 0:n.switchSource(T)},T)})]}),E==="speed"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Speed",onBack:()=>z("main")}),[.5,1,1.5,2].map(d=>e.jsx(N,{label:`${d}x`,active:a.playbackRate===d,onClick:()=>n.video.playbackRate=d},d))]}),E==="quality"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Quality",onBack:()=>z("main")}),e.jsx(N,{label:"Auto",active:a.currentQuality===-1,onClick:()=>n==null?void 0:n.setQuality(-1)}),a.qualityLevels.map(d=>e.jsx(N,{label:`${d.height}p`,value:`${Math.round(d.bitrate/1e3)}k`,active:a.currentQuality===d.index,onClick:()=>n==null?void 0:n.setQuality(d.index)},d.index))]}),E==="audio"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Audio Track",onBack:()=>z("main")}),a.audioTracks.length===0&&e.jsx("div",{className:"px-4 py-3 text-zinc-500 text-xs text-center",children:"No tracks available"}),a.audioTracks.map(d=>e.jsx(N,{label:d.label,value:d.language,active:a.currentAudioTrack===d.index,onClick:()=>n==null?void 0:n.setAudioTrack(d.index)},d.index))]}),E==="boost"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Audio Boost",onBack:()=>z("main")}),[1,1.5,2,3].map(d=>e.jsx(N,{label:d===1?"Off":`${d}x`,active:a.audioGain===d,onClick:()=>n==null?void 0:n.setAudioGain(d)},d))]}),E==="flip"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Video Flip",onBack:()=>z("main")}),e.jsxs("div",{className:"p-2 space-y-1",children:[e.jsx(W,{label:"Horizontal Flip",checked:a.flipState.horizontal,onChange:()=>n==null?void 0:n.setFlip("horizontal")}),e.jsx(W,{label:"Vertical Flip",checked:a.flipState.vertical,onChange:()=>n==null?void 0:n.setFlip("vertical")})]})]}),E==="ratio"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Aspect Ratio",onBack:()=>z("main")}),["default","16:9","4:3"].map(d=>e.jsx(N,{label:d==="default"?"Default":d,active:a.aspectRatio===d,onClick:()=>n==null?void 0:n.setAspectRatio(d)},d))]}),E==="party"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Watch Party",onBack:()=>z("main")}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx("p",{className:"text-xs text-zinc-400 leading-relaxed",children:"Create a synchronized room on WatchParty.me to watch together."}),e.jsx("a",{href:`https://www.watchparty.me/create?video=${encodeURIComponent(((gt=a.sources[a.currentSourceIndex])==null?void 0:gt.url)||t||"")}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center w-full py-2.5 bg-[var(--accent)] hover:opacity-90 text-white font-medium transition-opacity text-xs",style:{borderRadius:"var(--radius)"},children:"Create Room"})]})]}),E==="appearance"&&e.jsxs(e.Fragment,{children:[e.jsx(F,{label:"Appearance",onBack:()=>z("main")}),e.jsxs("div",{className:"pb-1",children:[e.jsx(K,{title:"Theme",children:e.jsx("div",{className:"grid grid-cols-2 gap-2 px-3",children:ai.map(d=>e.jsx("button",{onClick:()=>n==null?void 0:n.setAppearance({theme:d.value,themeColor:d.color}),className:`py-2 text-xs font-bold uppercase tracking-wide transition-colors border-[length:var(--border-width)] border-white/10 ${a.theme===d.value?"bg-[var(--accent)] text-white":"bg-white/5 text-zinc-400 hover:text-white"}`,style:{borderRadius:"var(--radius)"},children:d.label},d.value))})}),e.jsx(K,{title:"Icon Size",children:e.jsx("div",{className:"grid grid-cols-3 gap-1 px-3",children:["small","medium","large"].map(d=>e.jsx("button",{onClick:()=>n==null?void 0:n.setAppearance({iconSize:d}),className:`py-1.5 text-xs font-medium transition-colors ${a.iconSize===d?"bg-white text-black":"bg-white/5 text-zinc-400 hover:text-zinc-200"}`,style:{borderRadius:"var(--radius)"},children:d.charAt(0).toUpperCase()+d.slice(1)},d))})}),e.jsxs(K,{title:"Theme Color",children:[e.jsx("div",{className:"grid grid-cols-6 gap-2 px-3",children:ri.map(d=>e.jsx("button",{title:d.label,onClick:()=>n==null?void 0:n.setAppearance({themeColor:d.value}),className:`w-6 h-6 transition-transform hover:scale-110 ${a.themeColor===d.value?"ring-2 ring-white scale-110":"ring-1 ring-white/10"}`,style:{backgroundColor:d.value,borderRadius:"var(--radius-full)"},children:a.themeColor===d.value&&e.jsx(Pe,{className:"w-3 h-3 text-white mx-auto stroke-[3]"})},d.value))}),e.jsx("div",{className:"px-3 pt-4",children:e.jsxs("div",{className:"flex items-center gap-3 bg-white/5 p-2 hover:bg-white/10 transition-colors group",style:{borderRadius:"var(--radius)"},children:[e.jsx("div",{className:"relative w-6 h-6 overflow-hidden ring-1 ring-white/20",style:{borderRadius:"var(--radius-full)"},children:e.jsx("input",{type:"color",value:a.themeColor,onChange:d=>n==null?void 0:n.setAppearance({themeColor:d.target.value}),className:"absolute inset-[-4px] w-[150%] h-[150%] cursor-pointer p-0 border-0"})}),e.jsx("span",{className:"text-xs text-zinc-400 font-medium group-hover:text-zinc-200",children:"Custom Color"}),e.jsx("span",{className:"text-[10px] font-mono text-zinc-500 ml-auto uppercase",children:a.themeColor})]})})]})]})]})]})]})})]},"settings");default:return null}},Zt=m.useMemo(()=>{const l=[{html:"Playback",isLabel:!0},{html:"Loop",checked:a.isLooping,onClick:()=>n==null?void 0:n.toggleLoop()},{separator:!0},{html:"Transform",isLabel:!0},{html:"Flip Horizontal",onClick:()=>n==null?void 0:n.setFlip("horizontal")},{html:"Flip Vertical",onClick:()=>n==null?void 0:n.setFlip("vertical")},{separator:!0},{html:"Aspect Ratio",isLabel:!0},{html:"Default",checked:a.aspectRatio==="default",onClick:()=>n==null?void 0:n.setAspectRatio("default")},{html:"16:9",checked:a.aspectRatio==="16:9",onClick:()=>n==null?void 0:n.setAspectRatio("16:9")},{html:"4:3",checked:a.aspectRatio==="4:3",onClick:()=>n==null?void 0:n.setAspectRatio("4:3")},{separator:!0},{html:"Video Info",icon:e.jsx(Hs,{className:"w-3.5 h-3.5"}),onClick:()=>_e(!0)},{separator:!0}];return u.contextmenu&&l.push(...u.contextmenu),l.push({html:e.jsx("span",{className:"text-zinc-500 text-xs font-semibold tracking-wide",children:"StrataPlayer"}),disabled:!0}),l.push({html:"Close",onClick:f=>f(),icon:e.jsx("div",{className:"text-red-400",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})}),l},[u.contextmenu,a.aspectRatio,a.isLooping,n]),mt=a.isWebFullscreen,ft=e.jsxs("div",{id:u.id,ref:U,className:`group bg-black overflow-hidden select-none font-[family-name:var(--font-main)] outline-none text-zinc-100 strata-player-reset ${mt?"fixed inset-0 z-[2147483647] w-screen h-screen rounded-none":"relative w-full h-full rounded-[var(--radius)]"} ${u.container||""}`,style:{touchAction:"manipulation","--accent":a.themeColor,"--accent-contrast":Ft},onMouseMove:at,onMouseLeave:()=>{a.isPlaying&&!L&&!$&&!I&&n&&n.setControlsVisible(!1)},onMouseDown:ot,onMouseUp:Se,onTouchStart:Wt,onTouchMove:Dt,onTouchEnd:qt,onContextMenu:Ut,tabIndex:0,role:"region","aria-label":"Video Player","data-theme":a.theme,children:[e.jsx("style",{children:`
|
|
26
26
|
[data-theme="default"] {
|
|
27
27
|
--radius: 0.75rem;
|
|
28
28
|
--radius-lg: 0.75rem;
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
/* Override Backdrop for specific themes if needed */
|
|
116
116
|
[data-theme="pixel"] .strata-backdrop { backdrop-filter: none; background: #000; }
|
|
117
117
|
[data-theme="hacker"] .strata-backdrop { backdrop-filter: none; background: #000; }
|
|
118
|
-
`}),a.theme==="hacker"&&e.jsx("div",{className:"strata-scanlines"}),!n&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-zinc-950 z-50",children:e.jsx(
|
|
118
|
+
`}),a.theme==="hacker"&&e.jsx("div",{className:"strata-scanlines"}),!n&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-zinc-950 z-50",children:e.jsx(Le,{className:"w-10 h-10 text-[var(--accent)] animate-spin"})}),n&&e.jsxs(e.Fragment,{children:[(pt=u.layers)==null?void 0:pt.map((l,f)=>e.jsx("div",{className:`absolute inset-0 pointer-events-none z-10 ${l.className||""}`,style:l.style,children:e.jsx(kt,{content:l.html||"",className:"w-full h-full"})},f)),e.jsx(Ks,{notifications:a.notifications}),e.jsx(Ys,{cues:a.activeCues,settings:a.subtitleSettings}),e.jsx("div",{className:"absolute inset-0 z-0",onClick:Gt,"aria-hidden":"true"}),o&&!xe&&e.jsx("div",{className:"absolute inset-0 bg-cover bg-center z-[5] pointer-events-none",style:{backgroundImage:`url(${o})`}}),Z.visible&&e.jsx(si,{x:Z.x,y:Z.y,items:Zt,onClose:()=>pe({...Z,visible:!1}),containerWidth:$t,containerHeight:Oe}),At&&n&&e.jsx(ii,{player:n,onClose:()=>_e(!1)}),je&&e.jsxs("div",{className:"absolute top-8 left-1/2 -translate-x-1/2 bg-black/50 backdrop-blur-md px-4 py-2 rounded-full flex items-center gap-2 z-40 animate-in fade-in zoom-in duration-200",children:[e.jsx(Vs,{className:"w-4 h-4 text-[var(--accent)] fill-current"}),e.jsx("span",{className:"text-xs font-bold tracking-wider",children:"2x Speed"})]}),D&&He&&a.controlsVisible&&e.jsx("button",{onClick:l=>{l.stopPropagation(),n.toggleLock()},className:`absolute left-4 md:left-6 bottom-24 md:bottom-28 z-50 p-3 rounded-full bg-black/50 backdrop-blur-md border border-white/10 text-white transition-all active:scale-95 ${a.isLocked?"text-[var(--accent)] bg-white/10":"hover:bg-white/10"}`,children:a.isLocked?e.jsx(Fs,{className:"w-5 h-5"}):e.jsx(As,{className:"w-5 h-5"})}),Q&&e.jsx("div",{className:`absolute top-0 bottom-0 flex items-center justify-center w-[35%] z-20 bg-white/5 backdrop-blur-[1px] animate-out fade-out duration-500 fill-mode-forwards ${Q.type==="rewind"?"left-0 rounded-r-[4rem]":"right-0 rounded-l-[4rem]"}`,onAnimationEnd:()=>le(null),children:e.jsxs("div",{className:"flex flex-col items-center text-white drop-shadow-lg",children:[Q.type==="rewind"?e.jsx(wt,{className:"w-12 h-12 animate-pulse"}):e.jsx(yt,{className:"w-12 h-12 animate-pulse"}),e.jsx("span",{className:"font-bold text-sm mt-2 font-mono",children:Q.type==="rewind"?"-10s":"+10s"})]})},Q.id),a.isBuffering&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-20 pointer-events-none",children:e.jsx(Le,{className:"w-12 h-12 text-[var(--accent)] animate-spin drop-shadow-lg"})}),a.error&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-30 bg-black/90 backdrop-blur-md animate-in fade-in",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 text-red-500 p-8 max-w-md text-center",children:[e.jsx("span",{className:"text-5xl mb-2",children:"⚠️"}),e.jsx("h3",{className:"text-xl font-bold text-white",children:"Playback Error"}),e.jsx("p",{className:"text-zinc-400 text-sm",children:a.error}),e.jsx("button",{onClick:()=>n.load(n.store.get().sources[n.store.get().currentSourceIndex]||{url:t||"",type:i||"auto"},b),className:"px-6 py-2 bg-[var(--accent)] text-white font-medium rounded-full hover:opacity-90 transition-opacity mt-4 shadow-lg",children:"Try Again"})]})}),Rt&&!a.isLocked&&(!a.isPlaying&&!a.isBuffering&&!a.error||a.controlsVisible)&&!a.isBuffering?e.jsx("div",{className:`absolute inset-0 flex items-center justify-center z-10 transition-opacity duration-300 pointer-events-none ${a.controlsVisible||!a.isPlaying?"opacity-100":"opacity-0"}`,children:e.jsxs("div",{className:"flex items-center gap-8 md:gap-16 pointer-events-auto",children:[e.jsx("button",{onClick:l=>{l.stopPropagation(),P(),ce("rewind")},className:`group flex items-center justify-center rounded-full bg-black/40 hover:bg-black/60 border border-white/10 transition-all duration-300 active:scale-125 active:opacity-80 text-white/90 focus:outline-none backdrop-blur-sm ${X.skipBtn}`,children:e.jsx(wt,{className:X.skipIcon})}),e.jsx("button",{onClick:l=>{l.stopPropagation(),P(),n.togglePlay()},className:`group relative flex items-center justify-center rounded-full bg-white/10 hover:bg-[var(--accent)] border border-white/10 shadow-2xl transition-all duration-300 active:scale-90 active:opacity-80 focus:outline-none backdrop-blur-md ${X.playBtn}`,children:a.isPlaying?e.jsx(jt,{className:`${X.playIcon} text-white fill-current`}):e.jsx(vt,{className:`${X.playIcon} text-white ml-1 fill-current`})}),e.jsx("button",{onClick:l=>{l.stopPropagation(),P(),ce("forward")},className:`group flex items-center justify-center rounded-full bg-black/40 hover:bg-black/60 border border-white/10 transition-all duration-300 active:scale-125 active:opacity-80 text-white/90 focus:outline-none backdrop-blur-sm ${X.skipBtn}`,children:e.jsx(yt,{className:X.skipIcon})})]})}):null,e.jsxs("div",{className:`absolute inset-x-0 bottom-0 z-30 transition-all duration-300 px-4 md:px-6 py-4 bg-gradient-to-t from-black/90 via-black/50 to-transparent ${Yt?"opacity-100 translate-y-0":"opacity-0 translate-y-4 pointer-events-none"}`,onClick:l=>{(L||$||I)&&P(),l.target===l.currentTarget&&oe(!1),l.stopPropagation()},children:[!u.isLive&&e.jsxs("div",{ref:ye,className:"relative w-full h-3 group/slider mb-3 cursor-pointer touch-none flex items-center",onMouseMove:_t,onMouseLeave:()=>{et(null),tt(null)},onMouseDown:lt,onTouchStart:lt,children:[(bt=u.highlight)==null?void 0:bt.map((l,f)=>e.jsx("div",{className:"absolute top-1/2 -translate-y-1/2 w-1.5 h-1.5 bg-yellow-400 rounded-full z-10 pointer-events-none",style:{left:`${l.time/a.duration*100}%`},title:l.text},f)),Ze!==null&&e.jsxs("div",{className:"absolute bottom-full mb-1.5 flex flex-col items-center transform -translate-x-1/2 z-40 pointer-events-none transition-opacity duration-150",style:{left:`clamp(70px, ${Ot}%, calc(100% - 70px))`},children:[_&&e.jsx("div",{className:"bg-black/90 border border-white/10 shadow-2xl overflow-hidden backdrop-blur-sm",style:{width:`${_.w*.5}px`,height:`${_.h*.5}px`,borderRadius:"var(--radius)"},children:e.jsx("div",{style:{backgroundImage:`url("${_.url}")`,width:`${_.w}px`,height:`${_.h}px`,backgroundPosition:`-${_.x}px -${_.y}px`,backgroundRepeat:"no-repeat",transform:"scale(0.5)",transformOrigin:"top left"}})}),e.jsx("div",{className:"strata-tooltip px-2 py-0.5 text-[11px] font-bold font-mono shadow-lg tabular-nums mt-1",children:ze(Ze)})]}),e.jsxs("div",{className:"w-full h-1 bg-white/20 overflow-hidden relative backdrop-blur-sm border-[length:var(--border-width)] border-white/10",style:{borderRadius:"var(--radius-full)"},children:[a.duration>0&&a.buffered.map((l,f)=>e.jsx("div",{className:"absolute top-0 bottom-0 bg-white/20",style:{left:`${l.start/a.duration*100}%`,width:`${(l.end-l.start)/a.duration*100}%`}},f)),e.jsx("div",{className:"absolute left-0 top-0 bottom-0 bg-[var(--accent)]",style:{width:`${(be?ae:a.currentTime)/a.duration*100}%`}})]}),e.jsx("div",{className:"absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-3.5 h-3.5 bg-white shadow-md scale-0 group-hover/slider:scale-100 transition-transform duration-100 z-10",style:{left:`${(be?ae:a.currentTime)/a.duration*100}%`,borderRadius:"var(--radius-full)"}})]}),e.jsxs("div",{className:"flex items-center justify-between pointer-events-auto",children:[e.jsx("div",{className:"flex items-center gap-3",children:ht.filter(l=>l.position==="left"||l.position==="center").map(xt)}),e.jsx("div",{className:"flex items-center gap-1",children:ht.filter(l=>l.position==="right").map(xt)})]})]})]})]});return mt&&typeof document<"u"?ns.createPortal(ft,document.body):ft},oi=(s,t)=>{const i=is.createRoot(s);return i.render(m.createElement($e,t)),{unmount:()=>{i.unmount()},update:r=>{i.render(m.createElement($e,{...t,...r}))}}};exports.StrataCore=Nt;exports.StrataPlayer=$e;exports.mountStrataPlayer=oi;
|
|
119
119
|
//# sourceMappingURL=strataplayer.cjs.js.map
|