@xhub-reel/embed 0.2.2 → 0.2.3
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/index.js +7 -3
- package/dist/index.mjs +7 -3
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
'use strict';var dn=require('hls.js'),zustand=require('zustand'),middleware=require('zustand/middleware'),designTokens=require('@xhub-reel/design-tokens'),react=require('react'),react$1=require('motion/react'),jsxRuntime=require('react/jsx-runtime'),react$2=require('@use-gesture/react'),client=require('react-dom/client');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var dn__default=/*#__PURE__*/_interopDefault(dn);var kt={maxBufferLength:30,maxMaxBufferLength:60,maxBufferSize:3e7,maxBufferHole:.5,abrEwmaDefaultEstimate:5e5,abrBandWidthUpFactor:.7,abrBandWidthFactor:.9,startLevel:-1,autoStartLoad:true,startPosition:-1,fragLoadingMaxRetry:3,manifestLoadingMaxRetry:3,levelLoadingMaxRetry:3,fragLoadingTimeOut:2e4,manifestLoadingTimeOut:1e4,levelLoadingTimeOut:1e4,lowLatencyMode:false,liveSyncDuration:3};var et={ACTIVATION_THRESHOLD:.5,DEACTIVATION_THRESHOLD:.3},Re={MAX_VIDEOS_IN_DOM:5,MAX_DECODED_FRAMES:3,MAX_TOTAL_MEMORY:150*1024*1024},Ne={HEIGHT_DEFAULT:2,HEIGHT_ACTIVE:4};var Lt={PLAYER_PREFERENCES:"xhub-reel-player"};var jt={isMuted:true,volume:1,playbackSpeed:1,quality:"auto"},_e=zustand.create()(middleware.persist(e=>({...jt,toggleMute:()=>e(t=>({isMuted:!t.isMuted})),setMuted:t=>e({isMuted:t}),setVolume:t=>e({volume:Math.max(0,Math.min(1,t)),isMuted:t===0}),setPlaybackSpeed:t=>e({playbackSpeed:t}),setQuality:t=>e({quality:t}),resetPreferences:()=>e(jt)}),{name:Lt.PLAYER_PREFERENCES}));var Zt={videos:[],currentIndex:0,isLoading:false,hasMore:true,error:null},Tt=zustand.create(e=>({...Zt,setVideos:t=>e({videos:t,currentIndex:0}),appendVideos:t=>e(n=>({videos:[...n.videos,...t]})),setCurrentIndex:t=>e({currentIndex:t}),goToNext:()=>e(t=>({currentIndex:Math.min(t.currentIndex+1,t.videos.length-1)})),goToPrevious:()=>e(t=>({currentIndex:Math.max(t.currentIndex-1,0)})),removeVideo:t=>e(n=>{let r=n.videos.filter(s=>s.id!==t),o=Math.min(n.currentIndex,r.length-1);return {videos:r,currentIndex:Math.max(0,o)}}),setLoading:t=>e({isLoading:t}),setHasMore:t=>e({hasMore:t}),setError:t=>e({error:t}),reset:()=>e(Zt)}));function Y(...e){return Object.assign({},...e.filter(Boolean))}var Ue={flex:(e={})=>({display:"flex",flexDirection:e.direction,alignItems:e.align,justifyContent:e.justify,gap:typeof e.gap=="number"?e.gap:designTokens.spacing[e.gap||0],flexWrap:e.wrap}),flexCenter:{display:"flex",alignItems:"center",justifyContent:"center"},flexBetween:{display:"flex",alignItems:"center",justifyContent:"space-between"},flexColumn:{display:"flex",flexDirection:"column"},grid:(e={})=>({display:"grid",gridTemplateColumns:typeof e.columns=="number"?`repeat(${e.columns}, 1fr)`:e.columns,gridTemplateRows:typeof e.rows=="number"?`repeat(${e.rows}, 1fr)`:e.rows,gap:typeof e.gap=="number"?e.gap:designTokens.spacing[e.gap||0]}),absolute:(e={})=>({position:"absolute",...e.inset!==void 0&&{inset:e.inset},...e.top!==void 0&&{top:e.top},...e.right!==void 0&&{right:e.right},...e.bottom!==void 0&&{bottom:e.bottom},...e.left!==void 0&&{left:e.left}}),fixed:(e={})=>({position:"fixed",...e.inset!==void 0&&{inset:e.inset},...e.top!==void 0&&{top:e.top},...e.right!==void 0&&{right:e.right},...e.bottom!==void 0&&{bottom:e.bottom},...e.left!==void 0&&{left:e.left}}),fullScreen:{position:"fixed",inset:0,width:"100%",height:"100%"},fullSize:{width:"100%",height:"100%"},centerAbsolute:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"}};({heading:{fontSize:designTokens.fontSizes.xl,fontWeight:designTokens.fontWeights.bold,color:designTokens.colors.text},body:{fontSize:designTokens.fontSizes.md,fontWeight:designTokens.fontWeights.normal,color:designTokens.colors.text},caption:{fontSize:designTokens.fontSizes.xs,fontWeight:designTokens.fontWeights.normal,color:designTokens.colors.textSecondary},videoText:{color:designTokens.colors.text,textShadow:designTokens.shadows.text}});var Ie={bg:e=>({backgroundColor:e in designTokens.colors?designTokens.colors[e]:e}),rounded:(e="md")=>({borderRadius:designTokens.radii[e]}),border:(e={})=>({borderWidth:e.width||1,borderStyle:e.style||"solid",borderColor:e.color?e.color in designTokens.colors?designTokens.colors[e.color]:e.color:designTokens.colors.border}),shadow:(e="md")=>({boxShadow:designTokens.shadows[e]}),opacity:e=>({opacity:e}),glass:(e=20)=>({backgroundColor:designTokens.colors.overlay,backdropFilter:`blur(${e}px)`,WebkitBackdropFilter:`blur(${e}px)`}),glassLight:(e=10)=>({backgroundColor:designTokens.colors.overlayLight,backdropFilter:`blur(${e}px)`,WebkitBackdropFilter:`blur(${e}px)`})},tn={clickable:{cursor:"pointer",userSelect:"none"}},nn={transition:(e="all",t="normal",n="xhubReel")=>({transitionProperty:Array.isArray(e)?e.join(", "):e,transitionDuration:designTokens.durations[t],transitionTimingFunction:designTokens.easings[n]}),noTransition:{transition:"none"}},Qe={scrollY:{overflowY:"auto",overflowX:"hidden",WebkitOverflowScrolling:"touch"},hideScrollbar:{scrollbarWidth:"none",msOverflowStyle:"none"},snapY:{scrollSnapType:"y mandatory",overscrollBehaviorY:"contain"},snapStart:{scrollSnapAlign:"start",scrollSnapStop:"always"}};var rn={square:e=>({width:e,height:e}),width:e=>({width:e}),height:e=>({height:e}),minHeight:e=>({minHeight:e}),maxWidth:e=>({maxWidth:e})};({feedContainer:Y(Ue.fixed({inset:0}),Qe.scrollY,Qe.snapY,Qe.hideScrollbar,Ie.bg("background"),{touchAction:"pan-y"}),feedItem:Y(Ue.fullSize,Qe.snapStart,Ie.bg("background"),{position:"relative"}),actionButton:Y(Ue.flexCenter,rn.square(48),Ie.rounded("full"),tn.clickable,nn.transition(["transform","background-color"])),bottomSheet:Y(Ue.fixed({left:0,right:0,bottom:0}),Ie.glass(),Ie.rounded("xl"),{borderBottomLeftRadius:0,borderBottomRightRadius:0})});var on=class{callbacks={};currentInfo;constructor(){this.currentInfo=this.detectNetwork(),this.setupListeners();}detectNetwork(){let e=navigator.connection;return {online:navigator.onLine,effectiveType:e?.effectiveType??"unknown",downlink:e?.downlink??null,rtt:e?.rtt??null,saveData:e?.saveData??false,type:e?.type??"unknown"}}setupListeners(){window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.addEventListener("change",this.handleConnectionChange);}handleOnline=()=>{this.currentInfo={...this.currentInfo,online:true},this.callbacks.onOnline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleOffline=()=>{this.currentInfo={...this.currentInfo,online:false},this.callbacks.onOffline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleConnectionChange=()=>{this.currentInfo=this.detectNetwork(),this.callbacks.onNetworkChange?.(this.currentInfo);};subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isSlowNetwork(){let{effectiveType:e}=this.currentInfo;return e==="slow-2g"||e==="2g"}getRecommendedConfig(){let{effectiveType:e,saveData:t}=this.currentInfo;return t||e==="slow-2g"||e==="2g"?{maxBufferLength:10,maxMaxBufferLength:20,startLevel:0}:e==="3g"?{maxBufferLength:20,maxMaxBufferLength:40,startLevel:1}:{}}estimateDownloadTime(e){let{downlink:t}=this.currentInfo;if(!t||t===0)return 1/0;let n=t*1e6/8;return e/n}destroy(){window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.removeEventListener("change",this.handleConnectionChange);}};var sn=class{callbacks={};currentInfo={batteryLevel:null,isCharging:false,isLowPowerMode:false};battery=null;constructor(){this.initBattery();}async initBattery(){try{let e=navigator;e.getBattery&&(this.battery=await e.getBattery(),this.updateInfo(),this.setupListeners());}catch{}}updateInfo(){this.battery&&(this.currentInfo={batteryLevel:this.battery.level,isCharging:this.battery.charging,isLowPowerMode:this.battery.level<.2},this.callbacks.onPowerChange?.(this.currentInfo),this.currentInfo.batteryLevel!==null&&this.currentInfo.batteryLevel<.15&&this.callbacks.onLowBattery?.());}setupListeners(){this.battery&&(this.battery.addEventListener("levelchange",()=>this.updateInfo()),this.battery.addEventListener("chargingchange",()=>this.updateInfo()));}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isPowerSaving(){return this.currentInfo.isLowPowerMode&&!this.currentInfo.isCharging}getRecommendedConfig(){return this.isPowerSaving()?{maxBufferLength:15,capLevelToPlayerSize:true}:{}}destroy(){this.callbacks={};}};var an=class{queue=[];preloaded=new Set;loading=new Set;callbacks={};options;paused=false;velocityThreshold=2e3;constructor(e={}){this.options={maxConcurrent:e.maxConcurrent??2,maxQueue:e.maxQueue??5};}enqueue(e){let t=e.id??e.url;if(!(this.preloaded.has(e.url)||this.queue.some(n=>n.url===e.url))){if(this.queue.length>=this.options.maxQueue){let n=this.queue.shift();n&&this.callbacks.onPreloadCancel?.(n);}this.queue.push({...e,id:t,status:"pending"}),this.queue.sort((n,r)=>r.priority-n.priority),this.processQueue();}}enqueueMany(e){e.forEach(t=>this.enqueue(t));}cancel(e){let t=this.queue.find(n=>n.url===e);t&&(this.queue=this.queue.filter(n=>n.url!==e),this.loading.delete(t.id),this.callbacks.onPreloadCancel?.(t));}cancelAll(){this.queue.forEach(e=>{this.callbacks.onPreloadCancel?.(e);}),this.queue=[],this.loading.clear();}add(e,t,n=0){this.enqueue({id:e,url:t,priority:n});}remove(e){this.queue=this.queue.filter(t=>t.id!==e),this.loading.delete(e);}clear(){this.cancelAll(),this.preloaded.clear();}setPaused(e){this.paused=e,e||this.processQueue();}handleScrollVelocity(e){Math.abs(e)>this.velocityThreshold?this.setPaused(true):this.setPaused(false);}isPreloaded(e){return this.preloaded.has(e)}getStatus(e){let t=this.queue.find(n=>n.url===e);return t?t.status:this.preloaded.has(e)?"loaded":null}getAllStatuses(){return this.queue.map(e=>e.status)}getPreloadedUrls(){return Array.from(this.preloaded)}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}processQueue(){if(!this.paused)for(;this.loading.size<this.options.maxConcurrent&&this.queue.some(e=>e.status==="pending");){let e=this.queue.find(t=>t.status==="pending");e&&this.preloadItem(e);}}async preloadItem(e){e.status="loading",this.loading.add(e.id),this.callbacks.onPreloadStart?.(e);try{let t=document.createElement("link");t.rel="preload",t.as="fetch",t.href=e.url,t.crossOrigin="anonymous",document.head.appendChild(t),await new Promise((n,r)=>{t.onload=()=>n(),t.onerror=()=>r(new Error("Preload failed"));}),e.status="loaded",this.preloaded.add(e.url),this.callbacks.onPreloadComplete?.(e);}catch(t){e.status="error",this.callbacks.onPreloadError?.(e,t);}finally{this.loading.delete(e.id),this.processQueue();}}destroy(){this.clear(),this.callbacks={};}};var ln=class{metrics=this.createEmptyMetrics();callbacks={};bufferingStartTime=null;playStartTime=null;isPlaying=false;createEmptyMetrics(){return {videoId:null,sessionStartTime:null,playbackStartTime:null,totalPlayTime:0,totalBufferingTime:0,bufferingCount:0,qualitySwitches:[],errors:[],seeks:[],avgBitrate:0,startupTime:null}}startSession(e,t){this.metrics={...this.createEmptyMetrics(),videoId:e,sessionStartTime:Date.now()},this.notifyUpdate();}endSession(){this.isPlaying&&this.playStartTime&&(this.metrics.totalPlayTime+=Date.now()-this.playStartTime),this.isPlaying=false,this.playStartTime=null;let e={...this.metrics};return this.callbacks.onSessionEnd?.(e),e}trackFirstFrame(){this.metrics.sessionStartTime&&!this.metrics.playbackStartTime&&(this.metrics.playbackStartTime=Date.now(),this.metrics.startupTime=this.metrics.playbackStartTime-this.metrics.sessionStartTime,this.isPlaying=true,this.playStartTime=Date.now(),this.notifyUpdate());}trackBuffering(e){let t=Date.now();e&&!this.bufferingStartTime?(this.bufferingStartTime=t,this.metrics.bufferingCount++):!e&&this.bufferingStartTime&&(this.metrics.totalBufferingTime+=t-this.bufferingStartTime,this.bufferingStartTime=null),this.notifyUpdate();}trackQualitySwitch(e,t,n){this.metrics.qualitySwitches.push({timestamp:Date.now(),fromLevel:e,toLevel:t,automatic:n}),this.notifyUpdate();}trackError(e,t,n){let r=typeof e=="string"?e:e.message;this.metrics.errors.push({timestamp:Date.now(),message:r,recoverable:t}),this.notifyUpdate();}trackBitrate(e){this.metrics.avgBitrate=e,this.notifyUpdate();}trackReplay(){this.playStartTime=Date.now(),this.isPlaying=true,this.notifyUpdate();}trackSeek(e,t,n){this.metrics.seeks.push({timestamp:Date.now(),from:e,to:t,latency:n}),this.notifyUpdate();}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getMetrics(){return {...this.metrics}}notifyUpdate(){this.callbacks.onMetricsUpdate?.(this.getMetrics());}destroy(){this.endSession(),this.callbacks={};}};var It=class pn{hls=null;video=null;options;retryCount=0;maxRetries=3;constructor(t={}){this.options=t;}static isSupported(){return dn__default.default.isSupported()}attach(t,n){if(this.destroy(),this.video=t,this.retryCount=0,!pn.isSupported()){this.options.callbacks?.onError?.(new Error("HLS.js is not supported in this browser"),false);return}this.options.callbacks?.onStateChange?.("loading"),this.hls=new dn__default.default({...kt,...this.options.config}),this.setupHLSListeners(),this.setupVideoListeners(),this.hls.attachMedia(t),this.hls.loadSource(n);}loadSource(t){if(!this.hls||!this.video)throw new Error("HLS engine not attached to video element");this.retryCount=0,this.options.callbacks?.onStateChange?.("loading"),this.hls.loadSource(t);}destroy(){this.video&&(this.removeVideoListeners(),this.video=null),this.hls&&(this.hls.destroy(),this.hls=null);}getQualityLevels(){return this.hls?this.hls.levels.map(t=>({label:`${t.height}p`,height:t.height,bitrate:t.bitrate})):[]}setQuality(t){this.hls&&(this.hls.currentLevel=t);}getCurrentQuality(){return this.hls?.currentLevel??-1}getBandwidth(){return this.hls?.bandwidthEstimate??0}isAutoQuality(){return this.hls?.autoLevelEnabled??true}startLoad(t){this.hls?.startLoad(t);}stopLoad(){this.hls?.stopLoad();}setupHLSListeners(){this.hls&&(this.hls.on(dn.Events.MANIFEST_PARSED,(t,n)=>{let r=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(r),this.options.callbacks?.onStateChange?.("ready"),this.video?.autoplay&&this.video.play().catch(()=>{});}),this.hls.on(dn.Events.LEVEL_SWITCHED,(t,n)=>{this.options.callbacks?.onQualityChange?.(n.level,this.isAutoQuality());}),this.hls.on(dn.Events.FRAG_LOADED,()=>{this.options.callbacks?.onBandwidthUpdate?.(this.getBandwidth());}),this.hls.on(dn.Events.ERROR,(t,n)=>{this.handleError(n);}));}setupVideoListeners(){this.video&&(this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleVideoError));}removeVideoListeners(){this.video&&(this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleVideoError));}handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleVideoError=()=>{let t=this.video?.error;this.options.callbacks?.onError?.(new Error(t?.message??"Video playback error"),false),this.options.callbacks?.onStateChange?.("error");};handleError(t){if(t.fatal){let n=false;switch(t.type){case dn.ErrorTypes.NETWORK_ERROR:this.retryCount<this.maxRetries&&(this.retryCount++,console.warn(`[HLSEngine] Network error, retry ${this.retryCount}/${this.maxRetries}`),this.hls?.startLoad(),n=true);break;case dn.ErrorTypes.MEDIA_ERROR:console.warn("[HLSEngine] Media error, attempting recovery"),this.hls?.recoverMediaError(),n=true;break}n?this.options.callbacks?.onError?.(new Error(`HLS error (recovering): ${t.details}`),true):(this.options.callbacks?.onError?.(new Error(`HLS fatal error: ${t.details}`),false),this.options.callbacks?.onStateChange?.("error"),this.destroy());}else console.warn("[HLSEngine] Non-fatal error:",t.details);}};async function fn(e,t={}){try{return await e.play(),{success:!0}}catch(n){let r=n;if(r.name==="NotAllowedError"){e.muted=true;try{return await e.play(),{success:!0,mutedAutoplay:!0}}catch{return t.onNeedsUserGesture?.(),{success:false,reason:"user_gesture_required"}}}return {success:false,reason:"unknown",error:r}}}var hn=[.5,1,1.5,2],it=class Mt{video=null;options;lastQuality=null;bandwidthSamples=[];constructor(t={}){this.options=t;}static isSupported(){return typeof document>"u"?false:document.createElement("video").canPlayType("application/vnd.apple.mpegurl")!==""}static isIOS(){return typeof navigator>"u"?false:/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1}attach(t,n){this.destroy(),this.video=t,this.options.callbacks?.onStateChange?.("loading"),this.setupVideoListeners(),t.src=n,t.load();}loadSource(t){if(!this.video)throw new Error("Native HLS not attached to video element");this.options.callbacks?.onStateChange?.("loading"),this.video.src=t,this.video.load();}async play(){return this.video?fn(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}destroy(){this.video&&(this.removeVideoListeners(),this.video.removeAttribute("src"),this.video.load(),this.video=null),this.bandwidthSamples=[],this.lastQuality=null;}getQualityLevels(){let t=this.estimateCurrentQuality(),n=[{label:"Auto",height:0,bitrate:0}];return t&&n.push(t),n}setQuality(t){console.warn("[NativeHLS] Quality selection not supported, using auto");}getCurrentQuality(){return -1}estimateCurrentQuality(){if(!this.video||this.video.videoHeight===0)return null;let t=this.video.videoHeight,n=this.estimateBitrate();return {label:`${t}p`,height:t,bitrate:n}}estimateBitrate(){if(this.bandwidthSamples.length>0){let n=this.bandwidthSamples.reduce((r,o)=>r+o,0);return Math.round(n/this.bandwidthSamples.length)}if(!this.video)return 0;let t=this.video.videoHeight;return t>=1080?5e6:t>=720?25e5:t>=480?1e6:t>=360?5e5:25e4}getBandwidth(){return this.estimateBitrate()}isAutoQuality(){return true}startLoad(){this.video?.load();}stopLoad(){this.video&&(this.video.preload="none");}async enterFullscreen(){let t=this.video;if(t){if(t.requestFullscreen){await t.requestFullscreen();return}t.webkitEnterFullscreen&&await t.webkitEnterFullscreen();}}async exitFullscreen(){let t=this.video;if(t){if(document.exitFullscreen){await document.exitFullscreen();return}t.webkitExitFullscreen&&await t.webkitExitFullscreen();}}isFullscreen(){let t=this.video;return t?document.fullscreenElement?document.fullscreenElement===t:t.webkitDisplayingFullscreen??false:false}isFullscreenSupported(){let t=this.video;return t?!!(t.requestFullscreen||t.webkitSupportsFullscreen):false}isPlaybackRateSupported(t){return Mt.isIOS()?hn.includes(t):t>=.5&&t<=2}getSupportedPlaybackRates(){return Mt.isIOS()?[...hn]:[.5,.75,1,1.25,1.5,2]}setupVideoListeners(){this.video&&(this.video.addEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleError),this.video.addEventListener("resize",this.handleResize),this.video.addEventListener("progress",this.handleProgress));}removeVideoListeners(){this.video&&(this.video.removeEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleError),this.video.removeEventListener("resize",this.handleResize),this.video.removeEventListener("progress",this.handleProgress));}handleLoadedMetadata=()=>{let t=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(t),this.options.callbacks?.onStateChange?.("ready"),this.checkQualityChange();};handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleError=()=>{let t=this.video?.error,n=t?.message??"Video playback error",r=t?.code!==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED;this.options.callbacks?.onError?.(new Error(n),r),this.options.callbacks?.onStateChange?.("error");};handleResize=()=>{this.checkQualityChange();};handleProgress=()=>{this.updateBandwidthEstimate();};checkQualityChange(){let t=this.estimateCurrentQuality();t&&(!this.lastQuality||this.lastQuality.height!==t.height)&&(this.lastQuality=t,this.options.callbacks?.onQualityChange?.(t));}updateBandwidthEstimate(){if(this.video&&typeof performance<"u"&&performance.getEntriesByType){let n=performance.getEntriesByType("resource").filter(r=>r.initiatorType==="video"||r.name.includes(".ts")||r.name.includes(".m3u8"));if(n.length>0){let o=n.slice(-5).filter(s=>s.transferSize>0&&s.duration>0).map(s=>s.transferSize*8/(s.duration/1e3));if(o.length>0){let s=o.reduce((a,d)=>a+d,0)/o.length;this.bandwidthSamples.push(s),this.bandwidthSamples.length>10&&this.bandwidthSamples.shift(),this.options.callbacks?.onBandwidthUpdate?.(s);}}}}},mn=class{engine=null;video=null;options;isNative=false;animationFrameId=null;isTracking=false;networkDetector=null;powerManager=null;preloadManager=null;analytics=null;cleanupFunctions=[];wasPlayingBeforeOffline=false;wasPlayingBeforeLowBattery=false;constructor(e={}){this.options={enableNetworkAdaptation:true,enablePowerAdaptation:true,enableAnalytics:false,...e},this.isNative=this.shouldUseNative(),this.initializeServices();}static isSupported(){return It.isSupported()||it.isSupported()}attach(e,t,n){this.video=e,this.destroyEngine(),this.setupVideoListeners(),this.analytics&&n&&this.analytics.startSession(n,e);let r=this.getAdaptedConfig();this.isNative?this.engine=new it({callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture,onQualityChange:o=>{this.options.callbacks?.onQualityChange?.(-1,o);}}}):this.engine=new It({config:r,callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onQualityChange:(o,s)=>{let a=this.engine?.getQualityLevels()??[],d=o>=0&&o<a.length?a[o]:void 0;this.options.callbacks?.onQualityChange?.(s?-1:o,d);}}}),this.engine.attach(e,t);}loadSource(e,t){if(!this.engine||!this.video)throw new Error("Player not attached to video element");this.analytics&&(this.analytics.endSession(),t&&this.analytics.startSession(t,this.video)),this.engine.loadSource(e);}destroy(){this.destroyEngine(),this.destroyServices();}async play(){return this.video?this.isNative&&this.engine instanceof it?this.engine.play():fn(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}pause(){this.video?.pause();}async togglePlay(){return this.video?.paused?this.play():(this.pause(),{success:true})}seek(e){if(this.video){let t=this.video.currentTime;this.video.currentTime=Math.max(0,Math.min(e,this.video.duration||0)),this.analytics?.trackSeek(t,e,0);}}seekForward(e=10){this.video&&this.seek(this.video.currentTime+e);}seekBackward(e=10){this.video&&this.seek(this.video.currentTime-e);}getCurrentTime(){return this.video?.currentTime??0}getDuration(){return this.video?.duration??0}setVolume(e){this.video&&(this.video.volume=Math.max(0,Math.min(1,e)));}getVolume(){return this.video?.volume??1}setMuted(e){this.video&&(this.video.muted=e);}isMuted(){return this.video?.muted??true}toggleMute(){this.setMuted(!this.isMuted());}setPlaybackRate(e){this.video&&(this.video.playbackRate=e);}getPlaybackRate(){return this.video?.playbackRate??1}getQualityLevels(){return this.engine?.getQualityLevels()??[]}setQuality(e){let t=this.getCurrentQuality();this.engine?.setQuality(e),t!==e&&this.analytics?.trackQualitySwitch(t,e,e===-1);}getCurrentQuality(){return this.engine?.getCurrentQuality()??-1}isUsingNative(){return this.isNative}getVideoElement(){return this.video}getBuffered(){if(!this.video)return 0;let e=this.video.buffered,t=this.video.currentTime;for(let n=0;n<e.length;n++)if(t>=e.start(n)&&t<=e.end(n))return e.end(n)-t;return 0}getNetworkInfo(){return this.networkDetector?.getInfo()??null}getPowerInfo(){return this.powerManager?.getInfo()??null}getPreloadManager(){return this.preloadManager}getAnalytics(){return this.analytics?.getMetrics()??null}isSlowNetwork(){return this.networkDetector?.isSlowNetwork()??false}isPowerSaving(){return this.powerManager?.isPowerSaving()??false}shouldUseNative(){return this.options.preferNative!==false&&it.isSupported()?true:!It.isSupported()}initializeServices(){if(this.options.enableNetworkAdaptation){this.networkDetector=new on;let e=this.networkDetector.subscribe({onNetworkChange:this.handleNetworkChange,onOffline:()=>this.options.callbacks?.onError?.(new Error("Network offline"),true)});this.cleanupFunctions.push(e);}if(this.options.enablePowerAdaptation){this.powerManager=new sn;let e=this.powerManager.subscribe({onPowerChange:this.handlePowerChange});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.powerManager?.destroy());}if(this.options.preloadConfig&&(this.preloadManager=new an(this.options.preloadConfig),this.cleanupFunctions.push(()=>this.preloadManager?.destroy())),this.options.enableAnalytics){this.analytics=new ln;let e=this.analytics.subscribe({onMetricsUpdate:t=>this.options.callbacks?.onAnalyticsUpdate?.(t)});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.analytics?.destroy());}}destroyServices(){this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.networkDetector=null,this.powerManager=null,this.preloadManager=null,this.analytics=null;}destroyEngine(){this.stopProgressTracking(),this.removeVideoListeners(),this.engine&&(this.engine.destroy(),this.engine=null);}getAdaptedConfig(){let e={};return this.networkDetector&&(e={...e,...this.networkDetector.getRecommendedConfig()}),this.powerManager&&(e={...e,...this.powerManager.getRecommendedConfig()}),e}isNetworkBelowThreshold(e,t){let n=["slow-2g","2g","3g","4g","5g","unknown"],r=n.indexOf(e),o=n.indexOf(t);return e==="unknown"?false:r>=0&&r<=o}handleNetworkChange=e=>{this.options.callbacks?.onNetworkChange?.(e);let t=this.options.lowQualityThreshold??"2g",n=this.isNetworkBelowThreshold(e.effectiveType,t);this.options.autoQualityOnNetworkChange&&this.engine&&(n?this.setQuality(0):(e.effectiveType==="4g"||e.effectiveType==="5g")&&this.setQuality(-1)),this.options.autoPauseOnOffline&&!e.online&&(this.wasPlayingBeforeOffline=this.video?!this.video.paused:false,this.pause()),this.options.autoResumeOnOnline&&e.online&&this.wasPlayingBeforeOffline&&(this.play(),this.wasPlayingBeforeOffline=false),this.preloadManager&&this.preloadManager.setPaused(e.effectiveType==="2g"||!e.online);};handlePowerChange=e=>{this.options.callbacks?.onPowerChange?.(e);let t=this.options.lowBatteryThreshold??.15,n=e.batteryLevel!==null&&e.batteryLevel<t;this.options.autoPauseOnLowBattery&&n&&!e.isCharging&&(this.wasPlayingBeforeLowBattery=this.video?!this.video.paused:false,this.pause()),this.wasPlayingBeforeLowBattery&&(e.isCharging||e.batteryLevel!==null&&e.batteryLevel>=t+.05)&&(this.play(),this.wasPlayingBeforeLowBattery=false),this.preloadManager&&e.isLowPowerMode&&this.preloadManager.setPaused(true);};setupVideoListeners(){this.video&&(this.video.addEventListener("timeupdate",this.handleTimeUpdate),this.video.addEventListener("progress",this.handleProgress),this.video.addEventListener("volumechange",this.handleVolumeChange),this.video.addEventListener("ratechange",this.handleRateChange),this.video.addEventListener("play",this.handlePlay),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("playing",this.handlePlaying));}removeVideoListeners(){this.video&&(this.video.removeEventListener("timeupdate",this.handleTimeUpdate),this.video.removeEventListener("progress",this.handleProgress),this.video.removeEventListener("volumechange",this.handleVolumeChange),this.video.removeEventListener("ratechange",this.handleRateChange),this.video.removeEventListener("play",this.handlePlay),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("playing",this.handlePlaying));}handleTimeUpdate=()=>{this.video&&this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0);};handleProgress=()=>{this.options.callbacks?.onProgress?.(this.getBuffered());};handleVolumeChange=()=>{this.video&&this.options.callbacks?.onVolumeChange?.(this.video.volume,this.video.muted);};handleRateChange=()=>{this.video&&this.options.callbacks?.onRateChange?.(this.video.playbackRate);};handlePlay=()=>{this.options.enableSmoothTimeUpdates&&this.startProgressTracking();};handlePause=()=>{this.stopProgressTracking();};handleEnded=()=>{this.stopProgressTracking(),this.analytics&&this.analytics.endSession();};handleWaiting=()=>{this.analytics?.trackBuffering(true);};handlePlaying=()=>{this.analytics?.trackBuffering(false),this.analytics?.trackFirstFrame();};startProgressTracking(){if(this.isTracking||!this.video)return;this.isTracking=true;let e=()=>{if(!this.video||this.video.paused||this.video.ended){this.isTracking=false,this.animationFrameId=null;return}this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0),this.animationFrameId=requestAnimationFrame(e);};this.animationFrameId=requestAnimationFrame(e);}stopProgressTracking(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.isTracking=false;}},Cr=[{from:"idle",to:"loading"},{from:"loading",to:"ready"},{from:"loading",to:"error"},{from:"ready",to:"playing"},{from:"ready",to:"loading"},{from:"ready",to:"error"},{from:"playing",to:"paused"},{from:"playing",to:"buffering"},{from:"playing",to:"ended"},{from:"playing",to:"error"},{from:"playing",to:"loading"},{from:"paused",to:"playing"},{from:"paused",to:"buffering"},{from:"paused",to:"loading"},{from:"paused",to:"error"},{from:"buffering",to:"playing"},{from:"buffering",to:"paused"},{from:"buffering",to:"stalled"},{from:"buffering",to:"error"},{from:"stalled",to:"playing"},{from:"stalled",to:"buffering"},{from:"stalled",to:"error"},{from:"stalled",to:"loading"},{from:"ended",to:"playing"},{from:"ended",to:"loading"},{from:"ended",to:"idle"},{from:"error",to:"loading"},{from:"error",to:"idle"},{from:"*",to:"idle"}],kr=class{_state="idle";listeners=new Set;stalledTimeout=null;stalledThreshold=3e3;get state(){return this._state}transition(e){if(!this.canTransition(e))return console.warn(`[PlayerStateMachine] Invalid transition: ${this._state} -> ${e}`),false;let n=this._state;return this._state=e,e==="buffering"?this.startStalledTimer():this.clearStalledTimer(),this.listeners.forEach(r=>r(e,n)),true}canTransition(e){let t=Cr.find(n=>(n.from===this._state||n.from==="*")&&n.to===e);return !(!t||t.guard&&!t.guard())}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}reset(){this.clearStalledTimer(),this._state="idle";}isPlaying(){return this._state==="playing"}canPlay(){return ["ready","paused","ended"].includes(this._state)}isLoading(){return ["loading","buffering"].includes(this._state)}hasError(){return this._state==="error"}startStalledTimer(){this.clearStalledTimer(),this.stalledTimeout=setTimeout(()=>{this._state==="buffering"&&this.transition("stalled");},this.stalledThreshold);}clearStalledTimer(){this.stalledTimeout&&(clearTimeout(this.stalledTimeout),this.stalledTimeout=null);}};function Lr(){return new kr}function gn(){let e=react.useMemo(()=>Lr(),[]),[t,n]=react.useState(e.state);react.useEffect(()=>e.subscribe(a=>{n(a);}),[e]);let r=react.useCallback(s=>e.transition(s),[e]),o=react.useCallback(()=>{e.reset(),n("idle");},[e]);return {state:t,isPlaying:t==="playing",isPaused:t==="paused",isLoading:t==="loading",isBuffering:t==="buffering",isStalled:t==="stalled",isEnded:t==="ended",hasError:t==="error",canPlay:e.canPlay(),transition:r,reset:o}}function yn(e){let{volume:t,isMuted:n,setVolume:r,toggleMute:o,setMuted:s}=_e();react.useEffect(()=>{let i=e.current;i&&(i.volume=t,i.muted=n);},[e,t,n]),react.useEffect(()=>{let i=e.current;if(!i)return;let l=()=>{i.volume!==t&&r(i.volume),i.muted!==n&&s(i.muted);};return i.addEventListener("volumechange",l),()=>i.removeEventListener("volumechange",l)},[e,t,n,r,s]);let a=react.useCallback(i=>{let l=Math.max(0,Math.min(1,i));r(l),e.current&&(e.current.volume=l),l>0&&n&&(s(false),e.current&&(e.current.muted=false));},[e,n,r,s]),d=react.useCallback(()=>{o(),e.current&&(e.current.muted=!n);},[e,n,o]),u=react.useCallback(()=>{n||(s(true),e.current&&(e.current.muted=true));},[e,n,s]),h=react.useCallback(()=>{n&&(s(false),e.current&&(e.current.muted=false));},[e,n,s]);return {volume:t,isMuted:n,setVolume:a,toggleMute:d,mute:u,unmute:h}}function vn(e,t={}){let{enableSmoothTracking:n=false}=t,[r,o]=react.useState(0),[s,a]=react.useState(0),[d,u]=react.useState(0),[h,i]=react.useState([]),l=react.useRef(null),p=react.useRef(false),f=s>0?r/s*100:0,y=react.useCallback(c=>{let v=[],P=c.buffered;for(let R=0;R<P.length;R++)v.push({start:P.start(R),end:P.end(R)});i(v);let x=0;for(let R of v)if(c.currentTime>=R.start&&c.currentTime<=R.end){x=R.end-c.currentTime;break}u(x);},[]),m=react.useCallback(()=>{l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),p.current=false;},[]),b=react.useCallback(()=>{let c=e.current;if(!c||p.current)return;p.current=true;let v=()=>{if(!c||c.paused||c.ended){p.current=false,l.current=null;return}o(c.currentTime),l.current=requestAnimationFrame(v);};l.current=requestAnimationFrame(v);},[e]);react.useEffect(()=>{let c=e.current;if(!c)return;let v=()=>{o(c.currentTime);},P=()=>{a(c.duration||0);},x=()=>{a(c.duration||0);},R=()=>{y(c);},A=()=>{n&&b();},D=()=>{m();},z=()=>{m();},_=()=>{o(c.currentTime);},g=()=>{o(c.currentTime),y(c);};return c.addEventListener("timeupdate",v),c.addEventListener("loadedmetadata",P),c.addEventListener("durationchange",x),c.addEventListener("progress",R),c.addEventListener("play",A),c.addEventListener("pause",D),c.addEventListener("ended",z),c.addEventListener("seeking",_),c.addEventListener("seeked",g),c.readyState>=1&&(a(c.duration||0),o(c.currentTime)),c.readyState>=3&&y(c),!c.paused&&n&&b(),()=>{c.removeEventListener("timeupdate",v),c.removeEventListener("loadedmetadata",P),c.removeEventListener("durationchange",x),c.removeEventListener("progress",R),c.removeEventListener("play",A),c.removeEventListener("pause",D),c.removeEventListener("ended",z),c.removeEventListener("seeking",_),c.removeEventListener("seeked",g),m();}},[e,n,y,b,m]);let S=react.useCallback(c=>{let v=e.current;if(!v||!isFinite(v.duration))return;let P=Math.max(0,Math.min(c,v.duration));v.currentTime=P,o(P);},[e]),V=react.useCallback(c=>{let v=e.current;if(!v||!isFinite(v.duration))return;let x=Math.max(0,Math.min(100,c))/100*v.duration;v.currentTime=x,o(x);},[e]),H=s>0&&isFinite(s);return {currentTime:r,duration:s,buffered:d,progress:f,bufferedRanges:h,seek:S,seekToProgress:V,isSeekable:H,startSmoothTracking:b,stopSmoothTracking:m}}function bn(e){let{quality:t,setQuality:n}=_e(),[r,o]=react.useState(-1),[s,a]=react.useState([]);react.useEffect(()=>{if(!e)return;let i=e.getQualityLevels();a(i),o(e.getCurrentQuality());},[e]),react.useEffect(()=>{if(!(!e||s.length===0))if(t==="auto")e.setQuality(-1),o(-1);else {let i=parseInt(t.replace("p","")),l=s.findIndex(p=>p.height===i);l!==-1&&(e.setQuality(l),o(l));}},[e,t,s]);let d=r===-1,u=react.useCallback(i=>{if(e)if(typeof i=="number")if(e.setQuality(i),o(i),i===-1)n("auto");else {let l=s[i];l&&n(`${l.height}p`);}else n(i);},[e,s,n]),h=react.useCallback(()=>{u("auto");},[u]);return {quality:t,currentLevel:r,availableLevels:s,isAuto:d,setQuality:u,setAuto:h}}function Vt(e){return e<1e3?e.toString():e<1e4?`${(e/1e3).toFixed(1)}K`:e<1e6?`${Math.floor(e/1e3)}K`:`${(e/1e6).toFixed(1)}M`}var Vr={position:"absolute",right:designTokens.spacing[4],bottom:160,display:"flex",flexDirection:"column",alignItems:"center",gap:designTokens.components.actionBar.gap,zIndex:10},Ar={display:"flex",flexDirection:"column",alignItems:"center",gap:designTokens.components.actionBar.iconCountGap,background:"none",border:"none",padding:0,cursor:"pointer"},Fr={width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,display:"flex",alignItems:"center",justifyContent:"center"},Or={fontSize:designTokens.fontSizes.xs,fontWeight:designTokens.fontWeights.normal,color:designTokens.colors.text,textShadow:designTokens.shadows.text,lineHeight:designTokens.components.actionBar.counterLineHeight,textAlign:"center"},Hr={display:"flex",flexDirection:"column",alignItems:"center",position:"relative",width:designTokens.components.profileAction.avatarSize,height:55},Sn={width:designTokens.components.profileAction.avatarSize,height:designTokens.components.profileAction.avatarSize,borderRadius:"50%",objectFit:"cover",cursor:"pointer",background:designTokens.colors.surface},Dr={position:"absolute",bottom:0,left:"50%",transform:"translateX(-50%)",width:designTokens.components.profileAction.followButtonSize,height:designTokens.components.profileAction.followButtonSize,borderRadius:"50%",backgroundColor:designTokens.colors.like,border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},Br=({filled:e,color:t="white"})=>e?jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:t})}):jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("path",{d:"M15.21 5.5C14.7957 5.5 14.46 5.83579 14.46 6.25C14.46 6.66421 14.7957 7 15.21 7C16.819 7 17.996 8.3642 17.996 10.1346C17.996 10.5488 18.3317 10.8846 18.746 10.8846C19.1602 10.8846 19.496 10.5488 19.496 10.1346C19.496 7.7358 17.8342 5.5 15.21 5.5Z",fill:t}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.89327 2.25C3.85788 2.25 1.24994 5.6858 1.24994 9.47438C1.24994 13.301 3.5604 16.37 5.9378 18.4936C8.31629 20.6183 10.9036 21.9251 11.7628 22.2115L11.9999 22.2906L12.2371 22.2115C13.0963 21.9251 15.6836 20.6183 18.0621 18.4936C20.4395 16.37 22.7499 13.301 22.7499 9.47438C22.7499 5.6858 20.142 2.25 16.1066 2.25C14.2397 2.25 12.8941 3.06969 11.9999 3.91063C11.1058 3.06969 9.76018 2.25 7.89327 2.25ZM2.74994 9.47438C2.74994 6.3142 4.8731 3.75 7.89327 3.75C9.60588 3.75 10.7397 4.66987 11.4269 5.48383L11.9999 6.16259L12.573 5.48383C13.2602 4.66987 14.394 3.75 16.1066 3.75C19.1268 3.75 21.2499 6.3142 21.2499 9.47438C21.2499 12.6733 19.3104 15.3672 17.0628 17.375C15.0361 19.1854 12.8741 20.3336 11.9999 20.6978C11.1257 20.3336 8.96379 19.1854 6.93708 17.375C4.68948 15.3672 2.74994 12.6733 2.74994 9.47438Z",fill:t})]}),Nr=()=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsxRuntime.jsx("path",{d:"M14 1.45801C7.07347 1.45801 1.45837 7.0731 1.45837 13.9997C1.45837 16.3815 2.1232 18.6107 3.27778 20.5088L2.36541 23.0178C1.77294 24.6471 3.35258 26.2268 4.98188 25.6343L7.49089 24.7219C9.389 25.8765 11.6182 26.5413 14 26.5413C20.9266 26.5413 26.5417 20.9262 26.5417 13.9997C26.5417 7.0731 20.9266 1.45801 14 1.45801Z",fill:"white"})}),_r=({filled:e})=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsxRuntime.jsx("path",{d:"M16.6904 1.45801H11.2789C10.2487 1.458 9.4224 1.45799 8.75434 1.51253C8.06795 1.56857 7.47186 1.68652 6.92253 1.96632C6.90122 1.97718 6.88036 1.98891 6.86 2.00147C5.64436 2.75199 4.94533 3.52276 4.62739 4.64643C4.48015 5.1668 4.42512 5.72644 4.40084 6.3243C4.38332 6.75558 4.3811 7.24294 4.37866 7.77623C4.37775 7.97537 4.37678 8.18091 4.375 8.39232V24.8275C4.375 25.7739 5.14242 26.5413 6.08883 26.5413C6.51994 26.5413 6.93517 26.3792 7.25226 26.0859L13.3276 20.4783C13.3386 20.4682 13.3493 20.4578 13.3597 20.4471C13.5821 20.2197 13.743 20.0895 13.8601 20.0183C13.9156 19.9846 13.9524 19.9697 13.9731 19.9631C13.9833 19.9599 13.9898 19.9585 13.9933 19.958L13.9975 19.9575L13.9992 19.9574C13.9992 19.9574 14.0065 19.9571 14.0257 19.9632C14.0466 19.9698 14.0837 19.9849 14.1394 20.0187C14.2569 20.0901 14.4182 20.2206 14.641 20.4479C14.6512 20.4583 14.6616 20.4684 14.6724 20.4783L20.7477 26.0859C21.0648 26.3792 21.4801 26.5413 21.9112 26.5413C22.8576 26.5413 23.625 25.7739 23.625 24.8275V8.3619C23.625 7.33168 23.625 6.5054 23.5705 5.83735C23.5144 5.15096 23.3965 4.55487 23.1167 4.00554C23.1058 3.98416 23.094 3.96325 23.0814 3.94284C22.3309 2.72781 21.5599 2.0287 20.4364 1.71046C19.9159 1.56305 19.3562 1.50785 18.7583 1.48352C18.3245 1.46588 17.8344 1.46376 17.2978 1.46144C17.1014 1.46059 16.8988 1.45968 16.6904 1.45801Z",fill:e?designTokens.colors.warning:"white"})}),Ur=()=>jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:28,height:28,viewBox:"0 0 28 28",fill:"none",children:[jsxRuntime.jsx("path",{d:"M20.6583 8.99195C21.1139 8.53634 21.1139 7.79765 20.6583 7.34203L14.8249 1.5087C14.6061 1.28991 14.3094 1.16699 14 1.16699C13.6905 1.16699 13.3938 1.28991 13.175 1.5087L7.34167 7.34204C6.88606 7.79765 6.88606 8.53634 7.34167 8.99195C7.79728 9.44756 8.53597 9.44756 8.99158 8.99195L12.8333 5.15024L12.8333 17.5003C12.8333 18.1447 13.3556 18.667 14 18.667C14.6443 18.667 15.1666 18.1447 15.1666 17.5003L15.1666 5.15024L19.0083 8.99195C19.4639 9.44756 20.2026 9.44756 20.6583 8.99195Z",fill:"white"}),jsxRuntime.jsx("path",{d:"M24.4562 22.2708C24.4991 21.7457 24.5 21.0663 24.5 20.067V16.3337C24.5 15.6893 25.0223 15.167 25.6666 15.167C26.311 15.167 26.8333 15.6893 26.8333 16.3337L26.8333 20.1152C26.8333 21.0543 26.8333 21.8294 26.7817 22.4608C26.7282 23.1166 26.6132 23.7194 26.3247 24.2856C25.8772 25.1637 25.1633 25.8776 24.2852 26.325C23.719 26.6135 23.1162 26.7285 22.4604 26.7821C21.829 26.8337 21.054 26.8337 20.1149 26.8337H7.88508C6.94599 26.8337 6.17087 26.8337 5.5395 26.7821C4.88372 26.7285 4.28089 26.6135 3.71467 26.325C2.83658 25.8776 2.12267 25.1637 1.67526 24.2856C1.38676 23.7194 1.27176 23.1166 1.21819 22.4608C1.1666 21.8294 1.16661 21.0543 1.16663 20.1152V16.3337C1.16663 15.6893 1.68896 15.167 2.33329 15.167C2.97762 15.167 3.49996 15.6893 3.49996 16.3337L3.49996 20.067C3.49996 21.0663 3.50087 21.7457 3.54377 22.2708C3.58556 22.7823 3.66131 23.0438 3.75428 23.2263C3.97798 23.6653 4.33494 24.0223 4.77398 24.246C4.95645 24.339 5.21802 24.4147 5.7295 24.4565C6.25461 24.4994 6.93395 24.5003 7.93329 24.5003H20.0666C21.066 24.5003 21.7453 24.4994 22.2704 24.4565C22.7819 24.4147 23.0435 24.339 23.2259 24.246C23.665 24.0223 24.0219 23.6653 24.2456 23.2263C24.3386 23.0438 24.4144 22.7823 24.4562 22.2708Z",fill:"white"})]}),Qr=()=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 12 12",fill:"white",children:jsxRuntime.jsx("path",{d:"M6 1V11M1 6H11",stroke:"white",strokeWidth:2,strokeLinecap:"round"})}),zr=()=>jsxRuntime.jsx("svg",{width:12,height:12,viewBox:"0 0 12 12",fill:"none",children:jsxRuntime.jsx("path",{d:"M2 6L5 9L10 3",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})});function Wr({avatarUrl:e,isFollowed:t=false,onClick:n,onFollow:r}){return jsxRuntime.jsxs("div",{style:Hr,children:[jsxRuntime.jsx(react$1.motion.button,{style:{background:"none",border:"none",padding:0,cursor:"pointer"},onClick:n,whileTap:{scale:.95},"aria-label":"View profile",children:e?jsxRuntime.jsx("img",{src:e,alt:"Profile",style:Sn}):jsxRuntime.jsx("div",{style:Sn})}),!t&&r&&jsxRuntime.jsx(react$1.motion.button,{style:Dr,onClick:o=>{o.stopPropagation(),r();},whileTap:{scale:.9},animate:t?{scale:[1,1.2,1]}:{scale:1},transition:{type:"spring",...designTokens.springs.bouncy},"aria-label":t?"Following":"Follow",children:t?jsxRuntime.jsx(zr,{}):jsxRuntime.jsx(Qr,{})})]})}function ot({icon:e,count:t,isActive:n=false,onClick:r,label:o}){return jsxRuntime.jsxs(react$1.motion.button,{style:Ar,onClick:r,"aria-label":o,whileTap:{scale:.9},transition:{type:"spring",...designTokens.springs.bouncy},children:[jsxRuntime.jsx(react$1.motion.div,{style:Fr,animate:n?{scale:[1,1.2,1]}:{scale:1},transition:n?{duration:.3,ease:[.32,.72,0,1]}:{type:"spring",...designTokens.springs.default},children:e}),t!==void 0&&jsxRuntime.jsx("span",{style:Or,children:Vt(t)})]})}function at({likeCount:e,commentCount:t,shareCount:n,saveCount:r,isLiked:o=false,isSaved:s=false,onLike:a,onComment:d,onShare:u,onSave:h,avatarUrl:i,onProfileClick:l,onFollow:p,isFollowed:f=false,style:y,className:m=""}){return jsxRuntime.jsxs("div",{style:designTokens.mergeStyles(Vr,y),className:m,children:[i&&jsxRuntime.jsx(Wr,{avatarUrl:i,isFollowed:f,onClick:l,onFollow:p}),jsxRuntime.jsx(ot,{icon:jsxRuntime.jsx(Br,{filled:o,color:o?designTokens.colors.like:"white"}),count:e,isActive:o,onClick:a,label:o?"Unlike":"Like"}),jsxRuntime.jsx(ot,{icon:jsxRuntime.jsx(Nr,{}),count:t,onClick:d,label:"Comments"}),jsxRuntime.jsx(ot,{icon:jsxRuntime.jsx(_r,{filled:s}),count:r,isActive:s,onClick:h,label:s?"Unsave":"Save"}),jsxRuntime.jsx(ot,{icon:jsxRuntime.jsx(Ur,{}),count:n,onClick:u,label:"Share"})]})}var Kr={display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",cursor:"pointer",borderRadius:designTokens.radii.full,transitionProperty:"background-color, transform, opacity",transitionDuration:designTokens.durations.fast,transitionTimingFunction:designTokens.easings.xhubReel,userSelect:"none"},jr={sm:{width:32,height:32},md:{width:designTokens.components.tapArea,height:designTokens.components.tapArea},lg:{width:56,height:56}},Zr={default:{backgroundColor:designTokens.colors.surface,color:designTokens.colors.text},ghost:{backgroundColor:"transparent",color:designTokens.colors.text},glass:{backgroundColor:"rgba(0, 0, 0, 0.2)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",color:designTokens.colors.text}},Jr={opacity:.5,cursor:"not-allowed",pointerEvents:"none"},Ft=react.forwardRef(({icon:e,size:t="md",variant:n="ghost",disabled:r,style:o,className:s="",...a},d)=>jsxRuntime.jsx("button",{ref:d,type:"button",disabled:r,style:designTokens.mergeStyles(Kr,jr[t],Zr[n],r&&Jr,o),className:s,...a,children:e}));Ft.displayName="IconButton";var ai={position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:designTokens.zIndices.overlay},li={display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",borderRadius:"50%",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",cursor:"pointer"},di=({size:e})=>jsxRuntime.jsx("svg",{width:e*.4,height:e*.4,viewBox:"0 0 24 24",fill:designTokens.colors.text,children:jsxRuntime.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),ui=({size:e})=>jsxRuntime.jsxs("svg",{width:e*.35,height:e*.35,viewBox:"0 0 24 24",fill:designTokens.colors.text,children:[jsxRuntime.jsx("rect",{x:"6",y:"4",width:"4",height:"16"}),jsxRuntime.jsx("rect",{x:"14",y:"4",width:"4",height:"16"})]});function dt({isPlaying:e,show:t,onToggle:n,size:r=72,autoHideDelay:o=1e3,showOnStateChange:s=true,style:a,className:d=""}){let[u,h]=react.useState(false),[i,l]=react.useState(false),p=t!==void 0,f=p?t:u;react.useEffect(()=>{if(!(p||!s||!i)&&(h(true),o>0)){let S=setTimeout(()=>{h(false);},o);return ()=>clearTimeout(S)}},[e,p,s,o,i]);let y=react.useCallback(()=>{n&&(l(true),h(true),n());},[n]),m=!!n,b=m?"auto":"none";return jsxRuntime.jsx(react$1.AnimatePresence,{children:f&&jsxRuntime.jsx(react$1.motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},style:designTokens.mergeStyles(ai,{pointerEvents:b},a),className:d,onClick:y,children:jsxRuntime.jsx(react$1.motion.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.8,opacity:0},transition:{type:"spring",...designTokens.springs.default},whileTap:m?{scale:.9}:void 0,style:{...li,width:r,height:r,cursor:m?"pointer":"default"},children:e?jsxRuntime.jsx(ui,{size:r}):jsxRuntime.jsx(di,{size:r})})})})}var yi={position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.6)",zIndex:designTokens.zIndices.modal},vi={position:"fixed",left:0,right:0,bottom:0,backgroundColor:designTokens.colors.overlay,backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",borderTopLeftRadius:designTokens.radii.xl,borderTopRightRadius:designTokens.radii.xl,zIndex:designTokens.zIndices.modal+1,display:"flex",flexDirection:"column",maxHeight:"90vh"},bi={width:designTokens.components.bottomSheet.handleWidth,height:designTokens.components.bottomSheet.handleHeight,backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:2,margin:"12px auto 0",flexShrink:0},Si={display:"flex",alignItems:"center",justifyContent:"space-between",padding:`${designTokens.spacing[4]}px ${designTokens.spacing[4]}px ${designTokens.spacing[3]}px`,flexShrink:0},wi={fontSize:18,fontWeight:600,color:designTokens.colors.text},Pi={width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",cursor:"pointer",color:designTokens.colors.textSecondary,borderRadius:"50%"},Ei={flex:1,overflow:"auto",WebkitOverflowScrolling:"touch"},Ci=()=>jsxRuntime.jsxs("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]});function Rn({isOpen:e,onClose:t,title:n,children:r,height:o="60vh",maxHeight:s="90vh",showClose:a=true,showHandle:d=true,style:u,className:h=""}){let i=react.useCallback(l=>{l.key==="Escape"&&t();},[t]);return react.useEffect(()=>(e&&(document.addEventListener("keydown",i),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",i),document.body.style.overflow="";}),[e,i]),jsxRuntime.jsx(react$1.AnimatePresence,{children:e&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(react$1.motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:yi,onClick:t}),jsxRuntime.jsxs(react$1.motion.div,{initial:{y:"100%"},animate:{y:0},exit:{y:"100%"},transition:{type:"spring",...designTokens.springs.default},drag:"y",dragConstraints:{top:0,bottom:0},dragElastic:{top:0,bottom:.5},onDragEnd:(l,p)=>{(p.offset.y>100||p.velocity.y>500)&&t();},style:designTokens.mergeStyles(vi,{height:o,maxHeight:s,touchAction:"none"},u),className:h,children:[d&&jsxRuntime.jsx("div",{style:bi}),(n||a)&&jsxRuntime.jsxs("div",{style:Si,children:[jsxRuntime.jsx("span",{style:wi,children:n}),a&&jsxRuntime.jsx("button",{style:Pi,onClick:t,"aria-label":"Close",children:jsxRuntime.jsx(Ci,{})})]}),jsxRuntime.jsx("div",{style:Ei,children:r})]})]})})}function Mn({size:e=24,color:t=designTokens.colors.text,thickness:n=2,style:r,className:o=""}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("style",{children:`
|
|
1
|
+
'use strict';var br=require('hls.js'),zustand=require('zustand'),middleware=require('zustand/middleware'),designTokens=require('@xhub-reel/design-tokens'),react=require('react'),react$1=require('motion/react'),jsxRuntime=require('react/jsx-runtime'),react$2=require('@use-gesture/react'),client=require('react-dom/client');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var br__default=/*#__PURE__*/_interopDefault(br);var Bt={maxBufferLength:30,maxMaxBufferLength:60,maxBufferSize:3e7,maxBufferHole:.5,abrEwmaDefaultEstimate:5e5,abrBandWidthUpFactor:.7,abrBandWidthFactor:.9,startLevel:-1,autoStartLoad:true,startPosition:-1,fragLoadingMaxRetry:3,manifestLoadingMaxRetry:3,levelLoadingMaxRetry:3,fragLoadingTimeOut:2e4,manifestLoadingTimeOut:1e4,levelLoadingTimeOut:1e4,lowLatencyMode:false,liveSyncDuration:3};var lt={ACTIVATION_THRESHOLD:.5,DEACTIVATION_THRESHOLD:.3},De={MAX_VIDEOS_IN_DOM:5,MAX_DECODED_FRAMES:3,MAX_TOTAL_MEMORY:150*1024*1024},Xe={HEIGHT_DEFAULT:2,HEIGHT_ACTIVE:4};var Ut={PLAYER_PREFERENCES:"xhub-reel-player"};var pr={isMuted:true,volume:1,playbackSpeed:1,quality:"auto"},Ne=zustand.create()(middleware.persist(t=>({...pr,toggleMute:()=>t(e=>({isMuted:!e.isMuted})),setMuted:e=>t({isMuted:e}),setVolume:e=>t({volume:Math.max(0,Math.min(1,e)),isMuted:e===0}),setPlaybackSpeed:e=>t({playbackSpeed:e}),setQuality:e=>t({quality:e}),resetPreferences:()=>t(pr)}),{name:Ut.PLAYER_PREFERENCES}));var mr={videos:[],currentIndex:0,isLoading:false,hasMore:true,error:null},_t=zustand.create(t=>({...mr,setVideos:e=>t({videos:e,currentIndex:0}),appendVideos:e=>t(r=>({videos:[...r.videos,...e]})),setCurrentIndex:e=>t({currentIndex:e}),goToNext:()=>t(e=>({currentIndex:Math.min(e.currentIndex+1,e.videos.length-1)})),goToPrevious:()=>t(e=>({currentIndex:Math.max(e.currentIndex-1,0)})),removeVideo:e=>t(r=>{let o=r.videos.filter(i=>i.id!==e),n=Math.min(r.currentIndex,o.length-1);return {videos:o,currentIndex:Math.max(0,n)}}),setLoading:e=>t({isLoading:e}),setHasMore:e=>t({hasMore:e}),setError:e=>t({error:e}),reset:()=>t(mr)}));function J(...t){return Object.assign({},...t.filter(Boolean))}var Ye={flex:(t={})=>({display:"flex",flexDirection:t.direction,alignItems:t.align,justifyContent:t.justify,gap:typeof t.gap=="number"?t.gap:designTokens.spacing[t.gap||0],flexWrap:t.wrap}),flexCenter:{display:"flex",alignItems:"center",justifyContent:"center"},flexBetween:{display:"flex",alignItems:"center",justifyContent:"space-between"},flexColumn:{display:"flex",flexDirection:"column"},grid:(t={})=>({display:"grid",gridTemplateColumns:typeof t.columns=="number"?`repeat(${t.columns}, 1fr)`:t.columns,gridTemplateRows:typeof t.rows=="number"?`repeat(${t.rows}, 1fr)`:t.rows,gap:typeof t.gap=="number"?t.gap:designTokens.spacing[t.gap||0]}),absolute:(t={})=>({position:"absolute",...t.inset!==void 0&&{inset:t.inset},...t.top!==void 0&&{top:t.top},...t.right!==void 0&&{right:t.right},...t.bottom!==void 0&&{bottom:t.bottom},...t.left!==void 0&&{left:t.left}}),fixed:(t={})=>({position:"fixed",...t.inset!==void 0&&{inset:t.inset},...t.top!==void 0&&{top:t.top},...t.right!==void 0&&{right:t.right},...t.bottom!==void 0&&{bottom:t.bottom},...t.left!==void 0&&{left:t.left}}),fullScreen:{position:"fixed",inset:0,width:"100%",height:"100%"},fullSize:{width:"100%",height:"100%"},centerAbsolute:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"}};({heading:{fontSize:designTokens.fontSizes.xl,fontWeight:designTokens.fontWeights.bold,color:designTokens.colors.text},body:{fontSize:designTokens.fontSizes.md,fontWeight:designTokens.fontWeights.normal,color:designTokens.colors.text},caption:{fontSize:designTokens.fontSizes.xs,fontWeight:designTokens.fontWeights.normal,color:designTokens.colors.textSecondary},videoText:{color:designTokens.colors.text,textShadow:designTokens.shadows.text}});var Be={bg:t=>({backgroundColor:t in designTokens.colors?designTokens.colors[t]:t}),rounded:(t="md")=>({borderRadius:designTokens.radii[t]}),border:(t={})=>({borderWidth:t.width||1,borderStyle:t.style||"solid",borderColor:t.color?t.color in designTokens.colors?designTokens.colors[t.color]:t.color:designTokens.colors.border}),shadow:(t="md")=>({boxShadow:designTokens.shadows[t]}),opacity:t=>({opacity:t}),glass:(t=20)=>({backgroundColor:designTokens.colors.overlay,backdropFilter:`blur(${t}px)`,WebkitBackdropFilter:`blur(${t}px)`}),glassLight:(t=10)=>({backgroundColor:designTokens.colors.overlayLight,backdropFilter:`blur(${t}px)`,WebkitBackdropFilter:`blur(${t}px)`})},yr={clickable:{cursor:"pointer",userSelect:"none"}},gr={transition:(t="all",e="normal",r="xhubReel")=>({transitionProperty:Array.isArray(t)?t.join(", "):t,transitionDuration:designTokens.durations[e],transitionTimingFunction:designTokens.easings[r]}),noTransition:{transition:"none"}},Ke={scrollY:{overflowY:"auto",overflowX:"hidden",WebkitOverflowScrolling:"touch"},hideScrollbar:{scrollbarWidth:"none",msOverflowStyle:"none"},snapY:{scrollSnapType:"y mandatory",overscrollBehaviorY:"contain"},snapStart:{scrollSnapAlign:"start",scrollSnapStop:"always"}};var vr={square:t=>({width:t,height:t}),width:t=>({width:t}),height:t=>({height:t}),minHeight:t=>({minHeight:t}),maxWidth:t=>({maxWidth:t})};({feedContainer:J(Ye.fixed({inset:0}),Ke.scrollY,Ke.snapY,Ke.hideScrollbar,Be.bg("background"),{touchAction:"pan-y"}),feedItem:J(Ye.fullSize,Ke.snapStart,Be.bg("background"),{position:"relative"}),actionButton:J(Ye.flexCenter,vr.square(48),Be.rounded("full"),yr.clickable,gr.transition(["transform","background-color"])),bottomSheet:J(Ye.fixed({left:0,right:0,bottom:0}),Be.glass(),Be.rounded("xl"),{borderBottomLeftRadius:0,borderBottomRightRadius:0})});var Ue=class t{hls=null;video=null;options;retryCount=0;maxRetries=3;constructor(e={}){this.options=e;}static isSupported(){return br__default.default.isSupported()}attach(e,r){if(this.destroy(),this.video=e,this.retryCount=0,!t.isSupported()){this.options.callbacks?.onError?.(new Error("HLS.js is not supported in this browser"),false);return}this.options.callbacks?.onStateChange?.("loading"),this.hls=new br__default.default({...Bt,...this.options.config}),this.setupHLSListeners(),this.setupVideoListeners(),this.hls.attachMedia(e),this.hls.loadSource(r);}loadSource(e){if(!this.hls||!this.video)throw new Error("HLS engine not attached to video element");this.retryCount=0,this.options.callbacks?.onStateChange?.("loading"),this.hls.loadSource(e);}destroy(){this.video&&(this.removeVideoListeners(),this.video=null),this.hls&&(this.hls.destroy(),this.hls=null);}getQualityLevels(){return this.hls?this.hls.levels.map(e=>({label:`${e.height}p`,height:e.height,bitrate:e.bitrate})):[]}setQuality(e){this.hls&&(this.hls.currentLevel=e);}getCurrentQuality(){return this.hls?.currentLevel??-1}getBandwidth(){return this.hls?.bandwidthEstimate??0}isAutoQuality(){return this.hls?.autoLevelEnabled??true}startLoad(e){this.hls?.startLoad(e);}stopLoad(){this.hls?.stopLoad();}setupHLSListeners(){this.hls&&(this.hls.on(br.Events.MANIFEST_PARSED,(e,r)=>{let o=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(o),this.options.callbacks?.onStateChange?.("ready"),this.video?.autoplay&&this.video.play().catch(()=>{});}),this.hls.on(br.Events.LEVEL_SWITCHED,(e,r)=>{this.options.callbacks?.onQualityChange?.(r.level,this.isAutoQuality());}),this.hls.on(br.Events.FRAG_LOADED,()=>{this.options.callbacks?.onBandwidthUpdate?.(this.getBandwidth());}),this.hls.on(br.Events.ERROR,(e,r)=>{this.handleError(r);}));}setupVideoListeners(){this.video&&(this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleVideoError));}removeVideoListeners(){this.video&&(this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleVideoError));}handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleVideoError=()=>{let e=this.video?.error;this.options.callbacks?.onError?.(new Error(e?.message??"Video playback error"),false),this.options.callbacks?.onStateChange?.("error");};handleError(e){if(e.fatal){let r=false;switch(e.type){case br.ErrorTypes.NETWORK_ERROR:this.retryCount<this.maxRetries&&(this.retryCount++,console.warn(`[HLSEngine] Network error, retry ${this.retryCount}/${this.maxRetries}`),this.hls?.startLoad(),r=true);break;case br.ErrorTypes.MEDIA_ERROR:console.warn("[HLSEngine] Media error, attempting recovery"),this.hls?.recoverMediaError(),r=true;break;}r?this.options.callbacks?.onError?.(new Error(`HLS error (recovering): ${e.details}`),true):(this.options.callbacks?.onError?.(new Error(`HLS fatal error: ${e.details}`),false),this.options.callbacks?.onStateChange?.("error"),this.destroy());}else console.warn("[HLSEngine] Non-fatal error:",e.details);}};async function pt(t,e={}){try{return await t.play(),{success:!0}}catch(r){let o=r;if(o.name==="NotAllowedError"){t.muted=true;try{return await t.play(),{success:!0,mutedAutoplay:!0}}catch{return e.onNeedsUserGesture?.(),{success:false,reason:"user_gesture_required"}}}return {success:false,reason:"unknown",error:o}}}var Pr=[.5,1,1.5,2],Te=class t{video=null;options;lastQuality=null;bandwidthSamples=[];constructor(e={}){this.options=e;}static isSupported(){return typeof document>"u"?false:document.createElement("video").canPlayType("application/vnd.apple.mpegurl")!==""}static isIOS(){return typeof navigator>"u"?false:/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1}attach(e,r){this.destroy(),this.video=e,this.options.callbacks?.onStateChange?.("loading"),this.setupVideoListeners(),e.src=r,e.load();}loadSource(e){if(!this.video)throw new Error("Native HLS not attached to video element");this.options.callbacks?.onStateChange?.("loading"),this.video.src=e,this.video.load();}async play(){return this.video?pt(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}destroy(){this.video&&(this.removeVideoListeners(),this.video.removeAttribute("src"),this.video.load(),this.video=null),this.bandwidthSamples=[],this.lastQuality=null;}getQualityLevels(){let e=this.estimateCurrentQuality(),r=[{label:"Auto",height:0,bitrate:0}];return e&&r.push(e),r}setQuality(e){console.warn("[NativeHLS] Quality selection not supported, using auto");}getCurrentQuality(){return -1}estimateCurrentQuality(){if(!this.video||this.video.videoHeight===0)return null;let e=this.video.videoHeight,r=this.estimateBitrate();return {label:`${e}p`,height:e,bitrate:r}}estimateBitrate(){if(this.bandwidthSamples.length>0){let r=this.bandwidthSamples.reduce((o,n)=>o+n,0);return Math.round(r/this.bandwidthSamples.length)}if(!this.video)return 0;let e=this.video.videoHeight;return e>=1080?5e6:e>=720?25e5:e>=480?1e6:e>=360?5e5:25e4}getBandwidth(){return this.estimateBitrate()}isAutoQuality(){return true}startLoad(){this.video?.load();}stopLoad(){this.video&&(this.video.preload="none");}async enterFullscreen(){let e=this.video;if(e){if(e.requestFullscreen){await e.requestFullscreen();return}e.webkitEnterFullscreen&&await e.webkitEnterFullscreen();}}async exitFullscreen(){let e=this.video;if(e){if(document.exitFullscreen){await document.exitFullscreen();return}e.webkitExitFullscreen&&await e.webkitExitFullscreen();}}isFullscreen(){let e=this.video;return e?document.fullscreenElement?document.fullscreenElement===e:e.webkitDisplayingFullscreen??false:false}isFullscreenSupported(){let e=this.video;return e?!!(e.requestFullscreen||e.webkitSupportsFullscreen):false}isPlaybackRateSupported(e){return t.isIOS()?Pr.includes(e):e>=.5&&e<=2}getSupportedPlaybackRates(){return t.isIOS()?[...Pr]:[.5,.75,1,1.25,1.5,2]}setupVideoListeners(){this.video&&(this.video.addEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleError),this.video.addEventListener("resize",this.handleResize),this.video.addEventListener("progress",this.handleProgress));}removeVideoListeners(){this.video&&(this.video.removeEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleError),this.video.removeEventListener("resize",this.handleResize),this.video.removeEventListener("progress",this.handleProgress));}handleLoadedMetadata=()=>{let e=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(e),this.options.callbacks?.onStateChange?.("ready"),this.checkQualityChange();};handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleError=()=>{let e=this.video?.error,r=e?.message??"Video playback error",o=e?.code!==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED;this.options.callbacks?.onError?.(new Error(r),o),this.options.callbacks?.onStateChange?.("error");};handleResize=()=>{this.checkQualityChange();};handleProgress=()=>{this.updateBandwidthEstimate();};checkQualityChange(){let e=this.estimateCurrentQuality();e&&(!this.lastQuality||this.lastQuality.height!==e.height)&&(this.lastQuality=e,this.options.callbacks?.onQualityChange?.(e));}updateBandwidthEstimate(){if(this.video&&typeof performance<"u"&&performance.getEntriesByType){let r=performance.getEntriesByType("resource").filter(o=>o.initiatorType==="video"||o.name.includes(".ts")||o.name.includes(".m3u8"));if(r.length>0){let n=r.slice(-5).filter(i=>i.transferSize>0&&i.duration>0).map(i=>i.transferSize*8/(i.duration/1e3));if(n.length>0){let i=n.reduce((a,u)=>a+u,0)/n.length;this.bandwidthSamples.push(i),this.bandwidthSamples.length>10&&this.bandwidthSamples.shift(),this.options.callbacks?.onBandwidthUpdate?.(i);}}}}};var Le=class{callbacks={};currentInfo;constructor(){this.currentInfo=this.detectNetwork(),this.setupListeners();}detectNetwork(){let e=navigator.connection;return {online:navigator.onLine,effectiveType:e?.effectiveType??"unknown",downlink:e?.downlink??null,rtt:e?.rtt??null,saveData:e?.saveData??false,type:e?.type??"unknown"}}setupListeners(){window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.addEventListener("change",this.handleConnectionChange);}handleOnline=()=>{this.currentInfo={...this.currentInfo,online:true},this.callbacks.onOnline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleOffline=()=>{this.currentInfo={...this.currentInfo,online:false},this.callbacks.onOffline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleConnectionChange=()=>{this.currentInfo=this.detectNetwork(),this.callbacks.onNetworkChange?.(this.currentInfo);};subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isSlowNetwork(){let{effectiveType:e}=this.currentInfo;return e==="slow-2g"||e==="2g"}getRecommendedConfig(){let{effectiveType:e,saveData:r}=this.currentInfo;return r||e==="slow-2g"||e==="2g"?{maxBufferLength:10,maxMaxBufferLength:20,startLevel:0}:e==="3g"?{maxBufferLength:20,maxMaxBufferLength:40,startLevel:1}:{}}estimateDownloadTime(e){let{downlink:r}=this.currentInfo;if(!r||r===0)return 1/0;let o=r*1e6/8;return e/o}destroy(){window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.removeEventListener("change",this.handleConnectionChange);}};var Re=class{callbacks={};currentInfo={batteryLevel:null,isCharging:false,isLowPowerMode:false};battery=null;constructor(){this.initBattery();}async initBattery(){try{let e=navigator;e.getBattery&&(this.battery=await e.getBattery(),this.updateInfo(),this.setupListeners());}catch{}}updateInfo(){this.battery&&(this.currentInfo={batteryLevel:this.battery.level,isCharging:this.battery.charging,isLowPowerMode:this.battery.level<.2},this.callbacks.onPowerChange?.(this.currentInfo),this.currentInfo.batteryLevel!==null&&this.currentInfo.batteryLevel<.15&&this.callbacks.onLowBattery?.());}setupListeners(){this.battery&&(this.battery.addEventListener("levelchange",()=>this.updateInfo()),this.battery.addEventListener("chargingchange",()=>this.updateInfo()));}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isPowerSaving(){return this.currentInfo.isLowPowerMode&&!this.currentInfo.isCharging}getRecommendedConfig(){return this.isPowerSaving()?{maxBufferLength:15,capLevelToPlayerSize:true}:{}}destroy(){this.callbacks={};}};var Ie=class{queue=[];preloaded=new Set;loading=new Set;callbacks={};options;paused=false;velocityThreshold=2e3;constructor(e={}){this.options={maxConcurrent:e.maxConcurrent??2,maxQueue:e.maxQueue??5};}enqueue(e){let r=e.id??e.url;if(!(this.preloaded.has(e.url)||this.queue.some(o=>o.url===e.url))){if(this.queue.length>=this.options.maxQueue){let o=this.queue.shift();o&&this.callbacks.onPreloadCancel?.(o);}this.queue.push({...e,id:r,status:"pending"}),this.queue.sort((o,n)=>n.priority-o.priority),this.processQueue();}}enqueueMany(e){e.forEach(r=>this.enqueue(r));}cancel(e){let r=this.queue.find(o=>o.url===e);r&&(this.queue=this.queue.filter(o=>o.url!==e),this.loading.delete(r.id),this.callbacks.onPreloadCancel?.(r));}cancelAll(){this.queue.forEach(e=>{this.callbacks.onPreloadCancel?.(e);}),this.queue=[],this.loading.clear();}add(e,r,o=0){this.enqueue({id:e,url:r,priority:o});}remove(e){this.queue=this.queue.filter(r=>r.id!==e),this.loading.delete(e);}clear(){this.cancelAll(),this.preloaded.clear();}setPaused(e){this.paused=e,e||this.processQueue();}handleScrollVelocity(e){Math.abs(e)>this.velocityThreshold?this.setPaused(true):this.setPaused(false);}isPreloaded(e){return this.preloaded.has(e)}getStatus(e){let r=this.queue.find(o=>o.url===e);return r?r.status:this.preloaded.has(e)?"loaded":null}getAllStatuses(){return this.queue.map(e=>e.status)}getPreloadedUrls(){return Array.from(this.preloaded)}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}processQueue(){if(!this.paused)for(;this.loading.size<this.options.maxConcurrent&&this.queue.some(e=>e.status==="pending");){let e=this.queue.find(r=>r.status==="pending");e&&this.preloadItem(e);}}async preloadItem(e){e.status="loading",this.loading.add(e.id),this.callbacks.onPreloadStart?.(e);try{let r=document.createElement("link");r.rel="preload",r.as="fetch",r.href=e.url,r.crossOrigin="anonymous",document.head.appendChild(r),await new Promise((o,n)=>{r.onload=()=>o(),r.onerror=()=>n(new Error("Preload failed"));}),e.status="loaded",this.preloaded.add(e.url),this.callbacks.onPreloadComplete?.(e);}catch(r){e.status="error",this.callbacks.onPreloadError?.(e,r);}finally{this.loading.delete(e.id),this.processQueue();}}destroy(){this.clear(),this.callbacks={};}};var Me=class{metrics=this.createEmptyMetrics();callbacks={};bufferingStartTime=null;playStartTime=null;isPlaying=false;createEmptyMetrics(){return {videoId:null,sessionStartTime:null,playbackStartTime:null,totalPlayTime:0,totalBufferingTime:0,bufferingCount:0,qualitySwitches:[],errors:[],seeks:[],avgBitrate:0,startupTime:null}}startSession(e,r){this.metrics={...this.createEmptyMetrics(),videoId:e,sessionStartTime:Date.now()},this.notifyUpdate();}endSession(){this.isPlaying&&this.playStartTime&&(this.metrics.totalPlayTime+=Date.now()-this.playStartTime),this.isPlaying=false,this.playStartTime=null;let e={...this.metrics};return this.callbacks.onSessionEnd?.(e),e}trackFirstFrame(){this.metrics.sessionStartTime&&!this.metrics.playbackStartTime&&(this.metrics.playbackStartTime=Date.now(),this.metrics.startupTime=this.metrics.playbackStartTime-this.metrics.sessionStartTime,this.isPlaying=true,this.playStartTime=Date.now(),this.notifyUpdate());}trackBuffering(e){let r=Date.now();e&&!this.bufferingStartTime?(this.bufferingStartTime=r,this.metrics.bufferingCount++):!e&&this.bufferingStartTime&&(this.metrics.totalBufferingTime+=r-this.bufferingStartTime,this.bufferingStartTime=null),this.notifyUpdate();}trackQualitySwitch(e,r,o){this.metrics.qualitySwitches.push({timestamp:Date.now(),fromLevel:e,toLevel:r,automatic:o}),this.notifyUpdate();}trackError(e,r,o){let n=typeof e=="string"?e:e.message;this.metrics.errors.push({timestamp:Date.now(),message:n,recoverable:r}),this.notifyUpdate();}trackBitrate(e){this.metrics.avgBitrate=e,this.notifyUpdate();}trackReplay(){this.playStartTime=Date.now(),this.isPlaying=true,this.notifyUpdate();}trackSeek(e,r,o){this.metrics.seeks.push({timestamp:Date.now(),from:e,to:r,latency:o}),this.notifyUpdate();}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getMetrics(){return {...this.metrics}}notifyUpdate(){this.callbacks.onMetricsUpdate?.(this.getMetrics());}destroy(){this.endSession(),this.callbacks={};}};var je=class{engine=null;video=null;options;isNative=false;animationFrameId=null;isTracking=false;networkDetector=null;powerManager=null;preloadManager=null;analytics=null;cleanupFunctions=[];wasPlayingBeforeOffline=false;wasPlayingBeforeLowBattery=false;constructor(e={}){this.options={enableNetworkAdaptation:true,enablePowerAdaptation:true,enableAnalytics:false,...e},this.isNative=this.shouldUseNative(),this.initializeServices();}static isSupported(){return Ue.isSupported()||Te.isSupported()}attach(e,r,o){this.video=e,this.destroyEngine(),this.setupVideoListeners(),this.analytics&&o&&this.analytics.startSession(o,e);let n=this.getAdaptedConfig();this.isNative?this.engine=new Te({callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture,onQualityChange:i=>{this.options.callbacks?.onQualityChange?.(-1,i);}}}):this.engine=new Ue({config:n,callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onQualityChange:(i,a)=>{let u=this.engine?.getQualityLevels()??[],d=i>=0&&i<u.length?u[i]:void 0;this.options.callbacks?.onQualityChange?.(a?-1:i,d);}}}),this.engine.attach(e,r);}loadSource(e,r){if(!this.engine||!this.video)throw new Error("Player not attached to video element");this.analytics&&(this.analytics.endSession(),r&&this.analytics.startSession(r,this.video)),this.engine.loadSource(e);}destroy(){this.destroyEngine(),this.destroyServices();}async play(){return this.video?this.isNative&&this.engine instanceof Te?this.engine.play():pt(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}pause(){this.video?.pause();}async togglePlay(){return this.video?.paused?this.play():(this.pause(),{success:true})}seek(e){if(this.video){let r=this.video.currentTime;this.video.currentTime=Math.max(0,Math.min(e,this.video.duration||0)),this.analytics?.trackSeek(r,e,0);}}seekForward(e=10){this.video&&this.seek(this.video.currentTime+e);}seekBackward(e=10){this.video&&this.seek(this.video.currentTime-e);}getCurrentTime(){return this.video?.currentTime??0}getDuration(){return this.video?.duration??0}setVolume(e){this.video&&(this.video.volume=Math.max(0,Math.min(1,e)));}getVolume(){return this.video?.volume??1}setMuted(e){this.video&&(this.video.muted=e);}isMuted(){return this.video?.muted??true}toggleMute(){this.setMuted(!this.isMuted());}setPlaybackRate(e){this.video&&(this.video.playbackRate=e);}getPlaybackRate(){return this.video?.playbackRate??1}getQualityLevels(){return this.engine?.getQualityLevels()??[]}setQuality(e){let r=this.getCurrentQuality();this.engine?.setQuality(e),r!==e&&this.analytics?.trackQualitySwitch(r,e,e===-1);}getCurrentQuality(){return this.engine?.getCurrentQuality()??-1}isUsingNative(){return this.isNative}getVideoElement(){return this.video}getBuffered(){if(!this.video)return 0;let e=this.video.buffered,r=this.video.currentTime;for(let o=0;o<e.length;o++)if(r>=e.start(o)&&r<=e.end(o))return e.end(o)-r;return 0}getNetworkInfo(){return this.networkDetector?.getInfo()??null}getPowerInfo(){return this.powerManager?.getInfo()??null}getPreloadManager(){return this.preloadManager}getAnalytics(){return this.analytics?.getMetrics()??null}isSlowNetwork(){return this.networkDetector?.isSlowNetwork()??false}isPowerSaving(){return this.powerManager?.isPowerSaving()??false}shouldUseNative(){return this.options.preferNative!==false&&Te.isSupported()?true:!Ue.isSupported()}initializeServices(){if(this.options.enableNetworkAdaptation){this.networkDetector=new Le;let e=this.networkDetector.subscribe({onNetworkChange:this.handleNetworkChange,onOffline:()=>this.options.callbacks?.onError?.(new Error("Network offline"),true)});this.cleanupFunctions.push(e);}if(this.options.enablePowerAdaptation){this.powerManager=new Re;let e=this.powerManager.subscribe({onPowerChange:this.handlePowerChange});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.powerManager?.destroy());}if(this.options.preloadConfig&&(this.preloadManager=new Ie(this.options.preloadConfig),this.cleanupFunctions.push(()=>this.preloadManager?.destroy())),this.options.enableAnalytics){this.analytics=new Me;let e=this.analytics.subscribe({onMetricsUpdate:r=>this.options.callbacks?.onAnalyticsUpdate?.(r)});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.analytics?.destroy());}}destroyServices(){this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.networkDetector=null,this.powerManager=null,this.preloadManager=null,this.analytics=null;}destroyEngine(){this.stopProgressTracking(),this.removeVideoListeners(),this.engine&&(this.engine.destroy(),this.engine=null);}getAdaptedConfig(){let e={};return this.networkDetector&&(e={...e,...this.networkDetector.getRecommendedConfig()}),this.powerManager&&(e={...e,...this.powerManager.getRecommendedConfig()}),e}isNetworkBelowThreshold(e,r){let o=["slow-2g","2g","3g","4g","5g","unknown"],n=o.indexOf(e),i=o.indexOf(r);return e==="unknown"?false:n>=0&&n<=i}handleNetworkChange=e=>{this.options.callbacks?.onNetworkChange?.(e);let r=this.options.lowQualityThreshold??"2g",o=this.isNetworkBelowThreshold(e.effectiveType,r);this.options.autoQualityOnNetworkChange&&this.engine&&(o?this.setQuality(0):(e.effectiveType==="4g"||e.effectiveType==="5g")&&this.setQuality(-1)),this.options.autoPauseOnOffline&&!e.online&&(this.wasPlayingBeforeOffline=this.video?!this.video.paused:false,this.pause()),this.options.autoResumeOnOnline&&e.online&&this.wasPlayingBeforeOffline&&(this.play(),this.wasPlayingBeforeOffline=false),this.preloadManager&&this.preloadManager.setPaused(e.effectiveType==="2g"||!e.online);};handlePowerChange=e=>{this.options.callbacks?.onPowerChange?.(e);let r=this.options.lowBatteryThreshold??.15,o=e.batteryLevel!==null&&e.batteryLevel<r;this.options.autoPauseOnLowBattery&&o&&!e.isCharging&&(this.wasPlayingBeforeLowBattery=this.video?!this.video.paused:false,this.pause()),this.wasPlayingBeforeLowBattery&&(e.isCharging||e.batteryLevel!==null&&e.batteryLevel>=r+.05)&&(this.play(),this.wasPlayingBeforeLowBattery=false),this.preloadManager&&e.isLowPowerMode&&this.preloadManager.setPaused(true);};setupVideoListeners(){this.video&&(this.video.addEventListener("timeupdate",this.handleTimeUpdate),this.video.addEventListener("progress",this.handleProgress),this.video.addEventListener("volumechange",this.handleVolumeChange),this.video.addEventListener("ratechange",this.handleRateChange),this.video.addEventListener("play",this.handlePlay),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("playing",this.handlePlaying));}removeVideoListeners(){this.video&&(this.video.removeEventListener("timeupdate",this.handleTimeUpdate),this.video.removeEventListener("progress",this.handleProgress),this.video.removeEventListener("volumechange",this.handleVolumeChange),this.video.removeEventListener("ratechange",this.handleRateChange),this.video.removeEventListener("play",this.handlePlay),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("playing",this.handlePlaying));}handleTimeUpdate=()=>{this.video&&this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0);};handleProgress=()=>{this.options.callbacks?.onProgress?.(this.getBuffered());};handleVolumeChange=()=>{this.video&&this.options.callbacks?.onVolumeChange?.(this.video.volume,this.video.muted);};handleRateChange=()=>{this.video&&this.options.callbacks?.onRateChange?.(this.video.playbackRate);};handlePlay=()=>{this.options.enableSmoothTimeUpdates&&this.startProgressTracking();};handlePause=()=>{this.stopProgressTracking();};handleEnded=()=>{this.stopProgressTracking(),this.analytics&&this.analytics.endSession();};handleWaiting=()=>{this.analytics?.trackBuffering(true);};handlePlaying=()=>{this.analytics?.trackBuffering(false),this.analytics?.trackFirstFrame();};startProgressTracking(){if(this.isTracking||!this.video)return;this.isTracking=true;let e=()=>{if(!this.video||this.video.paused||this.video.ended){this.isTracking=false,this.animationFrameId=null;return}this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0),this.animationFrameId=requestAnimationFrame(e);};this.animationFrameId=requestAnimationFrame(e);}stopProgressTracking(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.isTracking=false;}};var No=[{from:"idle",to:"loading"},{from:"loading",to:"ready"},{from:"loading",to:"error"},{from:"ready",to:"playing"},{from:"ready",to:"loading"},{from:"ready",to:"error"},{from:"playing",to:"paused"},{from:"playing",to:"buffering"},{from:"playing",to:"ended"},{from:"playing",to:"error"},{from:"playing",to:"loading"},{from:"paused",to:"playing"},{from:"paused",to:"buffering"},{from:"paused",to:"loading"},{from:"paused",to:"error"},{from:"buffering",to:"playing"},{from:"buffering",to:"paused"},{from:"buffering",to:"stalled"},{from:"buffering",to:"error"},{from:"stalled",to:"playing"},{from:"stalled",to:"buffering"},{from:"stalled",to:"error"},{from:"stalled",to:"loading"},{from:"ended",to:"playing"},{from:"ended",to:"loading"},{from:"ended",to:"idle"},{from:"error",to:"loading"},{from:"error",to:"idle"},{from:"*",to:"idle"}],Wt=class{_state="idle";listeners=new Set;stalledTimeout=null;stalledThreshold=3e3;get state(){return this._state}transition(e){if(!this.canTransition(e))return console.warn(`[PlayerStateMachine] Invalid transition: ${this._state} -> ${e}`),false;let o=this._state;return this._state=e,e==="buffering"?this.startStalledTimer():this.clearStalledTimer(),this.listeners.forEach(n=>n(e,o)),true}canTransition(e){let r=No.find(o=>(o.from===this._state||o.from==="*")&&o.to===e);return !(!r||r.guard&&!r.guard())}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}reset(){this.clearStalledTimer(),this._state="idle";}isPlaying(){return this._state==="playing"}canPlay(){return ["ready","paused","ended"].includes(this._state)}isLoading(){return ["loading","buffering"].includes(this._state)}hasError(){return this._state==="error"}startStalledTimer(){this.clearStalledTimer(),this.stalledTimeout=setTimeout(()=>{this._state==="buffering"&&this.transition("stalled");},this.stalledThreshold);}clearStalledTimer(){this.stalledTimeout&&(clearTimeout(this.stalledTimeout),this.stalledTimeout=null);}};function kr(){return new Wt}function Gt(){let t=react.useMemo(()=>kr(),[]),[e,r]=react.useState(t.state);react.useEffect(()=>t.subscribe(a=>{r(a);}),[t]);let o=react.useCallback(i=>t.transition(i),[t]),n=react.useCallback(()=>{t.reset(),r("idle");},[t]);return {state:e,isPlaying:e==="playing",isPaused:e==="paused",isLoading:e==="loading",isBuffering:e==="buffering",isStalled:e==="stalled",isEnded:e==="ended",hasError:e==="error",canPlay:t.canPlay(),transition:o,reset:n}}function ft(t){let{volume:e,isMuted:r,setVolume:o,toggleMute:n,setMuted:i}=Ne();react.useEffect(()=>{let s=t.current;s&&(s.volume=e,s.muted=r);},[t,e,r]),react.useEffect(()=>{let s=t.current;if(!s)return;let l=()=>{s.volume!==e&&o(s.volume),s.muted!==r&&i(s.muted);};return s.addEventListener("volumechange",l),()=>s.removeEventListener("volumechange",l)},[t,e,r,o,i]);let a=react.useCallback(s=>{let l=Math.max(0,Math.min(1,s));o(l),t.current&&(t.current.volume=l),l>0&&r&&(i(false),t.current&&(t.current.muted=false));},[t,r,o,i]),u=react.useCallback(()=>{n(),t.current&&(t.current.muted=!r);},[t,r,n]),d=react.useCallback(()=>{r||(i(true),t.current&&(t.current.muted=true));},[t,r,i]),f=react.useCallback(()=>{r&&(i(false),t.current&&(t.current.muted=false));},[t,r,i]);return {volume:e,isMuted:r,setVolume:a,toggleMute:u,mute:d,unmute:f}}function yt(t,e={}){let{enableSmoothTracking:r=false}=e,[o,n]=react.useState(0),[i,a]=react.useState(0),[u,d]=react.useState(0),[f,s]=react.useState([]),l=react.useRef(null),c=react.useRef(false),y=i>0?o/i*100:0,h=react.useCallback(p=>{let b=[],v=p.buffered;for(let V=0;V<v.length;V++)b.push({start:v.start(V),end:v.end(V)});s(b);let M=0;for(let V of b)if(p.currentTime>=V.start&&p.currentTime<=V.end){M=V.end-p.currentTime;break}d(M);},[]),m=react.useCallback(()=>{l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),c.current=false;},[]),P=react.useCallback(()=>{let p=t.current;if(!p||c.current)return;c.current=true;let b=()=>{if(!p||p.paused||p.ended){c.current=false,l.current=null;return}n(p.currentTime),l.current=requestAnimationFrame(b);};l.current=requestAnimationFrame(b);},[t]);react.useEffect(()=>{let p=t.current;if(!p)return;let b=()=>{n(p.currentTime);},v=()=>{a(p.duration||0);},M=()=>{a(p.duration||0);},V=()=>{h(p);},D=()=>{r&&P();},A=()=>{m();},_=()=>{m();},U=()=>{n(p.currentTime);},g=()=>{n(p.currentTime),h(p);};return p.addEventListener("timeupdate",b),p.addEventListener("loadedmetadata",v),p.addEventListener("durationchange",M),p.addEventListener("progress",V),p.addEventListener("play",D),p.addEventListener("pause",A),p.addEventListener("ended",_),p.addEventListener("seeking",U),p.addEventListener("seeked",g),p.readyState>=1&&(a(p.duration||0),n(p.currentTime)),p.readyState>=3&&h(p),!p.paused&&r&&P(),()=>{p.removeEventListener("timeupdate",b),p.removeEventListener("loadedmetadata",v),p.removeEventListener("durationchange",M),p.removeEventListener("progress",V),p.removeEventListener("play",D),p.removeEventListener("pause",A),p.removeEventListener("ended",_),p.removeEventListener("seeking",U),p.removeEventListener("seeked",g),m();}},[t,r,h,P,m]);let S=react.useCallback(p=>{let b=t.current;if(!b||!isFinite(b.duration))return;let v=Math.max(0,Math.min(p,b.duration));b.currentTime=v,n(v);},[t]),L=react.useCallback(p=>{let b=t.current;if(!b||!isFinite(b.duration))return;let M=Math.max(0,Math.min(100,p))/100*b.duration;b.currentTime=M,n(M);},[t]),H=i>0&&isFinite(i);return {currentTime:o,duration:i,buffered:u,progress:y,bufferedRanges:f,seek:S,seekToProgress:L,isSeekable:H,startSmoothTracking:P,stopSmoothTracking:m}}function gt(t){let{quality:e,setQuality:r}=Ne(),[o,n]=react.useState(-1),[i,a]=react.useState([]);react.useEffect(()=>{if(!t)return;let s=t.getQualityLevels();a(s),n(t.getCurrentQuality());},[t]),react.useEffect(()=>{if(!(!t||i.length===0))if(e==="auto")t.setQuality(-1),n(-1);else {let s=parseInt(e.replace("p","")),l=i.findIndex(c=>c.height===s);l!==-1&&(t.setQuality(l),n(l));}},[t,e,i]);let u=o===-1,d=react.useCallback(s=>{if(t)if(typeof s=="number")if(t.setQuality(s),n(s),s===-1)r("auto");else {let l=i[s];l&&r(`${l.height}p`);}else r(s);},[t,i,r]),f=react.useCallback(()=>{d("auto");},[d]);return {quality:e,currentLevel:o,availableLevels:i,isAuto:u,setQuality:d,setAuto:f}}function $t(t){return t<1e3?t.toString():t<1e4?`${(t/1e3).toFixed(1)}K`:t<1e6?`${Math.floor(t/1e3)}K`:`${(t/1e6).toFixed(1)}M`}var Xo={position:"absolute",right:designTokens.spacing[4],bottom:160,display:"flex",flexDirection:"column",alignItems:"center",gap:designTokens.components.actionBar.gap,zIndex:10},Yo={display:"flex",flexDirection:"column",alignItems:"center",gap:designTokens.components.actionBar.iconCountGap,background:"none",border:"none",padding:0,cursor:"pointer"},Ko={width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,display:"flex",alignItems:"center",justifyContent:"center"},jo={fontSize:designTokens.fontSizes.xs,fontWeight:designTokens.fontWeights.normal,color:designTokens.colors.text,textShadow:designTokens.shadows.text,lineHeight:designTokens.components.actionBar.counterLineHeight,textAlign:"center"},Zo={display:"flex",flexDirection:"column",alignItems:"center",position:"relative",width:designTokens.components.profileAction.avatarSize,height:55},Or={width:designTokens.components.profileAction.avatarSize,height:designTokens.components.profileAction.avatarSize,borderRadius:"50%",objectFit:"cover",cursor:"pointer",background:designTokens.colors.surface},Jo={position:"absolute",bottom:0,left:"50%",transform:"translateX(-50%)",width:designTokens.components.profileAction.followButtonSize,height:designTokens.components.profileAction.followButtonSize,borderRadius:"50%",backgroundColor:designTokens.colors.like,border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},en=({filled:t,color:e="white"})=>t?jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:e})}):jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 24 24",fill:"none",children:[jsxRuntime.jsx("path",{d:"M15.21 5.5C14.7957 5.5 14.46 5.83579 14.46 6.25C14.46 6.66421 14.7957 7 15.21 7C16.819 7 17.996 8.3642 17.996 10.1346C17.996 10.5488 18.3317 10.8846 18.746 10.8846C19.1602 10.8846 19.496 10.5488 19.496 10.1346C19.496 7.7358 17.8342 5.5 15.21 5.5Z",fill:e}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.89327 2.25C3.85788 2.25 1.24994 5.6858 1.24994 9.47438C1.24994 13.301 3.5604 16.37 5.9378 18.4936C8.31629 20.6183 10.9036 21.9251 11.7628 22.2115L11.9999 22.2906L12.2371 22.2115C13.0963 21.9251 15.6836 20.6183 18.0621 18.4936C20.4395 16.37 22.7499 13.301 22.7499 9.47438C22.7499 5.6858 20.142 2.25 16.1066 2.25C14.2397 2.25 12.8941 3.06969 11.9999 3.91063C11.1058 3.06969 9.76018 2.25 7.89327 2.25ZM2.74994 9.47438C2.74994 6.3142 4.8731 3.75 7.89327 3.75C9.60588 3.75 10.7397 4.66987 11.4269 5.48383L11.9999 6.16259L12.573 5.48383C13.2602 4.66987 14.394 3.75 16.1066 3.75C19.1268 3.75 21.2499 6.3142 21.2499 9.47438C21.2499 12.6733 19.3104 15.3672 17.0628 17.375C15.0361 19.1854 12.8741 20.3336 11.9999 20.6978C11.1257 20.3336 8.96379 19.1854 6.93708 17.375C4.68948 15.3672 2.74994 12.6733 2.74994 9.47438Z",fill:e})]}),tn=()=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsxRuntime.jsx("path",{d:"M14 1.45801C7.07347 1.45801 1.45837 7.0731 1.45837 13.9997C1.45837 16.3815 2.1232 18.6107 3.27778 20.5088L2.36541 23.0178C1.77294 24.6471 3.35258 26.2268 4.98188 25.6343L7.49089 24.7219C9.389 25.8765 11.6182 26.5413 14 26.5413C20.9266 26.5413 26.5417 20.9262 26.5417 13.9997C26.5417 7.0731 20.9266 1.45801 14 1.45801Z",fill:"white"})}),rn=({filled:t})=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:designTokens.components.actionBar.iconSize,height:designTokens.components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsxRuntime.jsx("path",{d:"M16.6904 1.45801H11.2789C10.2487 1.458 9.4224 1.45799 8.75434 1.51253C8.06795 1.56857 7.47186 1.68652 6.92253 1.96632C6.90122 1.97718 6.88036 1.98891 6.86 2.00147C5.64436 2.75199 4.94533 3.52276 4.62739 4.64643C4.48015 5.1668 4.42512 5.72644 4.40084 6.3243C4.38332 6.75558 4.3811 7.24294 4.37866 7.77623C4.37775 7.97537 4.37678 8.18091 4.375 8.39232V24.8275C4.375 25.7739 5.14242 26.5413 6.08883 26.5413C6.51994 26.5413 6.93517 26.3792 7.25226 26.0859L13.3276 20.4783C13.3386 20.4682 13.3493 20.4578 13.3597 20.4471C13.5821 20.2197 13.743 20.0895 13.8601 20.0183C13.9156 19.9846 13.9524 19.9697 13.9731 19.9631C13.9833 19.9599 13.9898 19.9585 13.9933 19.958L13.9975 19.9575L13.9992 19.9574C13.9992 19.9574 14.0065 19.9571 14.0257 19.9632C14.0466 19.9698 14.0837 19.9849 14.1394 20.0187C14.2569 20.0901 14.4182 20.2206 14.641 20.4479C14.6512 20.4583 14.6616 20.4684 14.6724 20.4783L20.7477 26.0859C21.0648 26.3792 21.4801 26.5413 21.9112 26.5413C22.8576 26.5413 23.625 25.7739 23.625 24.8275V8.3619C23.625 7.33168 23.625 6.5054 23.5705 5.83735C23.5144 5.15096 23.3965 4.55487 23.1167 4.00554C23.1058 3.98416 23.094 3.96325 23.0814 3.94284C22.3309 2.72781 21.5599 2.0287 20.4364 1.71046C19.9159 1.56305 19.3562 1.50785 18.7583 1.48352C18.3245 1.46588 17.8344 1.46376 17.2978 1.46144C17.1014 1.46059 16.8988 1.45968 16.6904 1.45801Z",fill:t?designTokens.colors.warning:"white"})}),on=()=>jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:28,height:28,viewBox:"0 0 28 28",fill:"none",children:[jsxRuntime.jsx("path",{d:"M20.6583 8.99195C21.1139 8.53634 21.1139 7.79765 20.6583 7.34203L14.8249 1.5087C14.6061 1.28991 14.3094 1.16699 14 1.16699C13.6905 1.16699 13.3938 1.28991 13.175 1.5087L7.34167 7.34204C6.88606 7.79765 6.88606 8.53634 7.34167 8.99195C7.79728 9.44756 8.53597 9.44756 8.99158 8.99195L12.8333 5.15024L12.8333 17.5003C12.8333 18.1447 13.3556 18.667 14 18.667C14.6443 18.667 15.1666 18.1447 15.1666 17.5003L15.1666 5.15024L19.0083 8.99195C19.4639 9.44756 20.2026 9.44756 20.6583 8.99195Z",fill:"white"}),jsxRuntime.jsx("path",{d:"M24.4562 22.2708C24.4991 21.7457 24.5 21.0663 24.5 20.067V16.3337C24.5 15.6893 25.0223 15.167 25.6666 15.167C26.311 15.167 26.8333 15.6893 26.8333 16.3337L26.8333 20.1152C26.8333 21.0543 26.8333 21.8294 26.7817 22.4608C26.7282 23.1166 26.6132 23.7194 26.3247 24.2856C25.8772 25.1637 25.1633 25.8776 24.2852 26.325C23.719 26.6135 23.1162 26.7285 22.4604 26.7821C21.829 26.8337 21.054 26.8337 20.1149 26.8337H7.88508C6.94599 26.8337 6.17087 26.8337 5.5395 26.7821C4.88372 26.7285 4.28089 26.6135 3.71467 26.325C2.83658 25.8776 2.12267 25.1637 1.67526 24.2856C1.38676 23.7194 1.27176 23.1166 1.21819 22.4608C1.1666 21.8294 1.16661 21.0543 1.16663 20.1152V16.3337C1.16663 15.6893 1.68896 15.167 2.33329 15.167C2.97762 15.167 3.49996 15.6893 3.49996 16.3337L3.49996 20.067C3.49996 21.0663 3.50087 21.7457 3.54377 22.2708C3.58556 22.7823 3.66131 23.0438 3.75428 23.2263C3.97798 23.6653 4.33494 24.0223 4.77398 24.246C4.95645 24.339 5.21802 24.4147 5.7295 24.4565C6.25461 24.4994 6.93395 24.5003 7.93329 24.5003H20.0666C21.066 24.5003 21.7453 24.4994 22.2704 24.4565C22.7819 24.4147 23.0435 24.339 23.2259 24.246C23.665 24.0223 24.0219 23.6653 24.2456 23.2263C24.3386 23.0438 24.4144 22.7823 24.4562 22.2708Z",fill:"white"})]}),nn=()=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 12 12",fill:"white",children:jsxRuntime.jsx("path",{d:"M6 1V11M1 6H11",stroke:"white",strokeWidth:2,strokeLinecap:"round"})}),sn=()=>jsxRuntime.jsx("svg",{width:12,height:12,viewBox:"0 0 12 12",fill:"none",children:jsxRuntime.jsx("path",{d:"M2 6L5 9L10 3",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})});function an({avatarUrl:t,isFollowed:e=false,onClick:r,onFollow:o}){return jsxRuntime.jsxs("div",{style:Zo,children:[jsxRuntime.jsx(react$1.motion.button,{style:{background:"none",border:"none",padding:0,cursor:"pointer"},onClick:r,whileTap:{scale:.95},"aria-label":"View profile",children:t?jsxRuntime.jsx("img",{src:t,alt:"Profile",style:Or}):jsxRuntime.jsx("div",{style:Or})}),!e&&o&&jsxRuntime.jsx(react$1.motion.button,{style:Jo,onClick:n=>{n.stopPropagation(),o();},whileTap:{scale:.9},animate:e?{scale:[1,1.2,1]}:{scale:1},transition:{type:"spring",...designTokens.springs.bouncy},"aria-label":e?"Following":"Follow",children:e?jsxRuntime.jsx(sn,{}):jsxRuntime.jsx(nn,{})})]})}function vt({icon:t,count:e,isActive:r=false,onClick:o,label:n}){return jsxRuntime.jsxs(react$1.motion.button,{style:Yo,onClick:o,"aria-label":n,whileTap:{scale:.9},transition:{type:"spring",...designTokens.springs.bouncy},children:[jsxRuntime.jsx(react$1.motion.div,{style:Ko,animate:r?{scale:[1,1.2,1]}:{scale:1},transition:r?{duration:.3,ease:[.32,.72,0,1]}:{type:"spring",...designTokens.springs.default},children:t}),e!==void 0&&jsxRuntime.jsx("span",{style:jo,children:$t(e)})]})}function St({likeCount:t,commentCount:e,shareCount:r,saveCount:o,isLiked:n=false,isSaved:i=false,onLike:a,onComment:u,onShare:d,onSave:f,avatarUrl:s,onProfileClick:l,onFollow:c,isFollowed:y=false,style:h,className:m=""}){return jsxRuntime.jsxs("div",{style:designTokens.mergeStyles(Xo,h),className:m,children:[s&&jsxRuntime.jsx(an,{avatarUrl:s,isFollowed:y,onClick:l,onFollow:c}),jsxRuntime.jsx(vt,{icon:jsxRuntime.jsx(en,{filled:n,color:n?designTokens.colors.like:"white"}),count:t,isActive:n,onClick:a,label:n?"Unlike":"Like"}),jsxRuntime.jsx(vt,{icon:jsxRuntime.jsx(tn,{}),count:e,onClick:u,label:"Comments"}),jsxRuntime.jsx(vt,{icon:jsxRuntime.jsx(rn,{filled:i}),count:o,isActive:i,onClick:f,label:i?"Unsave":"Save"}),jsxRuntime.jsx(vt,{icon:jsxRuntime.jsx(on,{}),count:r,onClick:d,label:"Share"})]})}var mn={display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",cursor:"pointer",borderRadius:designTokens.radii.full,transitionProperty:"background-color, transform, opacity",transitionDuration:designTokens.durations.fast,transitionTimingFunction:designTokens.easings.xhubReel,userSelect:"none"},fn={sm:{width:32,height:32},md:{width:designTokens.components.tapArea,height:designTokens.components.tapArea},lg:{width:56,height:56}},hn={default:{backgroundColor:designTokens.colors.surface,color:designTokens.colors.text},ghost:{backgroundColor:"transparent",color:designTokens.colors.text},glass:{backgroundColor:"rgba(0, 0, 0, 0.2)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",color:designTokens.colors.text}},yn={opacity:.5,cursor:"not-allowed",pointerEvents:"none"},Xt=react.forwardRef(({icon:t,size:e="md",variant:r="ghost",disabled:o,style:n,className:i="",...a},u)=>jsxRuntime.jsx("button",{ref:u,type:"button",disabled:o,style:designTokens.mergeStyles(mn,fn[e],hn[r],o&&yn,n),className:i,...a,children:t}));Xt.displayName="IconButton";var Cn={position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:designTokens.zIndices.overlay},xn={display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",borderRadius:"50%",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",cursor:"pointer"},kn=({size:t})=>jsxRuntime.jsx("svg",{width:t*.4,height:t*.4,viewBox:"0 0 24 24",fill:designTokens.colors.text,children:jsxRuntime.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),Tn=({size:t})=>jsxRuntime.jsxs("svg",{width:t*.35,height:t*.35,viewBox:"0 0 24 24",fill:designTokens.colors.text,children:[jsxRuntime.jsx("rect",{x:"6",y:"4",width:"4",height:"16"}),jsxRuntime.jsx("rect",{x:"14",y:"4",width:"4",height:"16"})]});function wt({isPlaying:t,show:e,onToggle:r,size:o=72,autoHideDelay:n=1e3,showOnStateChange:i=true,style:a,className:u=""}){let[d,f]=react.useState(false),[s,l]=react.useState(false),c=e!==void 0,y=c?e:d;react.useEffect(()=>{if(!(c||!i||!s)&&(f(true),n>0)){let S=setTimeout(()=>{f(false);},n);return ()=>clearTimeout(S)}},[t,c,i,n,s]);let h=react.useCallback(()=>{r&&(l(true),f(true),r());},[r]),m=!!r,P=m?"auto":"none";return jsxRuntime.jsx(react$1.AnimatePresence,{children:y&&jsxRuntime.jsx(react$1.motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},style:designTokens.mergeStyles(Cn,{pointerEvents:P},a),className:u,onClick:h,children:jsxRuntime.jsx(react$1.motion.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.8,opacity:0},transition:{type:"spring",...designTokens.springs.default},whileTap:m?{scale:.9}:void 0,style:{...xn,width:o,height:o,cursor:m?"pointer":"default"},children:t?jsxRuntime.jsx(Tn,{size:o}):jsxRuntime.jsx(kn,{size:o})})})})}var Hn={position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.6)",zIndex:designTokens.zIndices.modal},An={position:"fixed",left:0,right:0,bottom:0,backgroundColor:designTokens.colors.overlay,backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",borderTopLeftRadius:designTokens.radii.xl,borderTopRightRadius:designTokens.radii.xl,zIndex:designTokens.zIndices.modal+1,display:"flex",flexDirection:"column",maxHeight:"90vh"},Fn={width:designTokens.components.bottomSheet.handleWidth,height:designTokens.components.bottomSheet.handleHeight,backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:2,margin:"12px auto 0",flexShrink:0},Dn={display:"flex",alignItems:"center",justifyContent:"space-between",padding:`${designTokens.spacing[4]}px ${designTokens.spacing[4]}px ${designTokens.spacing[3]}px`,flexShrink:0},Nn={fontSize:18,fontWeight:600,color:designTokens.colors.text},Bn={width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",cursor:"pointer",color:designTokens.colors.textSecondary,borderRadius:"50%"},Un={flex:1,overflow:"auto",WebkitOverflowScrolling:"touch"},_n=()=>jsxRuntime.jsxs("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]});function Qr({isOpen:t,onClose:e,title:r,children:o,height:n="60vh",maxHeight:i="90vh",showClose:a=true,showHandle:u=true,style:d,className:f=""}){let s=react.useCallback(l=>{l.key==="Escape"&&e();},[e]);return react.useEffect(()=>(t&&(document.addEventListener("keydown",s),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",s),document.body.style.overflow="";}),[t,s]),jsxRuntime.jsx(react$1.AnimatePresence,{children:t&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(react$1.motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:Hn,onClick:e}),jsxRuntime.jsxs(react$1.motion.div,{initial:{y:"100%"},animate:{y:0},exit:{y:"100%"},transition:{type:"spring",...designTokens.springs.default},drag:"y",dragConstraints:{top:0,bottom:0},dragElastic:{top:0,bottom:.5},onDragEnd:(l,c)=>{(c.offset.y>100||c.velocity.y>500)&&e();},style:designTokens.mergeStyles(An,{height:n,maxHeight:i,touchAction:"none"},d),className:f,children:[u&&jsxRuntime.jsx("div",{style:Fn}),(r||a)&&jsxRuntime.jsxs("div",{style:Dn,children:[jsxRuntime.jsx("span",{style:Nn,children:r}),a&&jsxRuntime.jsx("button",{style:Bn,onClick:e,"aria-label":"Close",children:jsxRuntime.jsx(_n,{})})]}),jsxRuntime.jsx("div",{style:Un,children:o})]})]})})}function Wr({size:t=24,color:e=designTokens.colors.text,thickness:r=2,style:o,className:n=""}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("style",{children:`
|
|
2
2
|
@keyframes xhub-reel-spin {
|
|
3
3
|
to { transform: rotate(360deg); }
|
|
4
4
|
}
|
|
5
|
-
`}),jsxRuntime.jsx("div",{role:"status","aria-label":"Loading",style:designTokens.mergeStyles({width:e,height:e,borderWidth:n,borderStyle:"solid",borderColor:`${t}30`,borderTopColor:t,borderRadius:"50%",animation:"xhub-reel-spin 1s linear infinite"},r),className:o})]})}var Hi={position:"fixed",left:designTokens.spacing[4],right:designTokens.spacing[4],zIndex:designTokens.zIndices.toast,display:"flex",justifyContent:"center",pointerEvents:"none"},Di={display:"flex",alignItems:"center",gap:designTokens.spacing[3],padding:`${designTokens.spacing[3]}px ${designTokens.spacing[4]}px`,backgroundColor:designTokens.colors.surface,borderRadius:designTokens.radii.lg,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.5)",pointerEvents:"auto",maxWidth:400},Bi={default:{},success:{borderLeft:`3px solid ${designTokens.colors.success}`},error:{borderLeft:`3px solid ${designTokens.colors.error}`},warning:{borderLeft:`3px solid ${designTokens.colors.warning}`}},Ni={flex:1,fontSize:designTokens.fontSizes.sm,color:designTokens.colors.text,lineHeight:1.4},_i={padding:`${designTokens.spacing[1]}px ${designTokens.spacing[3]}px`,backgroundColor:"transparent",border:"none",color:designTokens.colors.accent,fontSize:designTokens.fontSizes.sm,fontWeight:600,cursor:"pointer",borderRadius:designTokens.radii.sm};function Fn({message:e,isVisible:t,onClose:n,duration:r=3e3,variant:o="default",action:s,position:a="bottom",style:d,className:u=""}){react.useEffect(()=>{if(t&&r>0){let i=setTimeout(n,r);return ()=>clearTimeout(i)}},[t,r,n]);let h=a==="top"?{top:designTokens.spacing[4]}:{bottom:designTokens.spacing[4]+80};return jsxRuntime.jsx(react$1.AnimatePresence,{children:t&&jsxRuntime.jsx("div",{style:{...Hi,...h},children:jsxRuntime.jsxs(react$1.motion.div,{initial:{opacity:0,y:a==="top"?-20:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:a==="top"?-20:20,scale:.95},transition:{type:"spring",...designTokens.springs.default},style:designTokens.mergeStyles(Di,Bi[o],d),className:u,children:[jsxRuntime.jsx("span",{style:Ni,children:e}),s&&jsxRuntime.jsx("button",{style:_i,onClick:()=>{s.onClick(),n();},children:s.label})]})})})}var Gi={position:"absolute",pointerEvents:"none",zIndex:designTokens.zIndices.overlay},$i={filter:"drop-shadow(0 4px 8px rgba(255, 45, 85, 0.5))"};function ht(){let[e,t]=react.useState(false),[n,r]=react.useState({x:0,y:0}),o=react.useCallback((a,d)=>{let u=a??(typeof window<"u"?window.innerWidth/2:200),h=d??(typeof window<"u"?window.innerHeight/2:400);r({x:u,y:h}),t(true),setTimeout(()=>{t(false);},800);},[]),s=react.useCallback(()=>{t(false);},[]);return {isShowing:e,position:n,showHeart:o,hideHeart:s}}var qi=({size:e,color:t})=>jsxRuntime.jsx("svg",{style:$i,xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 28 28",fill:t,children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:t})});function pt({show:e,position:t={x:0,y:0},size:n=100,color:r=designTokens.colors.like,showParticles:o=true,particleCount:s=8,onComplete:a,style:d,className:u=""}){return jsxRuntime.jsx(react$1.AnimatePresence,{onExitComplete:a,children:e&&jsxRuntime.jsxs(react$1.motion.div,{initial:{opacity:0,scale:0},animate:{opacity:[0,1,1,0],scale:[0,1.3,1,.8],y:[0,-20,-20,-40]},exit:{scale:0,opacity:0},transition:{duration:.8,times:[0,.2,.6,1],ease:"easeOut"},style:{...Gi,left:t.x-n/2,top:t.y-n/2,width:n,height:n,...d},className:u,children:[jsxRuntime.jsx(qi,{size:n,color:r}),o&&[...Array(s)].map((h,i)=>jsxRuntime.jsx(react$1.motion.div,{style:{position:"absolute",width:12,height:12,borderRadius:"50%",backgroundColor:r,left:n/2-6,top:n/2-6},initial:{opacity:1,scale:1},animate:{opacity:0,scale:.5,x:Math.cos(i*Math.PI*2/s)*60,y:Math.sin(i*Math.PI*2/s)*60},transition:{duration:.5,delay:.1,ease:"easeOut"}},i))]})})}function Bn(e){let[t,n]=react.useState(false),r=typeof document<"u"&&!!(document.fullscreenEnabled||document.webkitFullscreenElement!==void 0||document.mozFullScreenElement!==void 0||document.msFullscreenElement!==void 0),o=()=>{let i=document;return i.fullscreenElement||i.webkitFullscreenElement||i.mozFullScreenElement||i.msFullscreenElement||null},s=async i=>{let l=i;l.requestFullscreen?await l.requestFullscreen():l.webkitRequestFullscreen?await l.webkitRequestFullscreen():l.mozRequestFullScreen?await l.mozRequestFullScreen():l.msRequestFullscreen&&await l.msRequestFullscreen();},a=async()=>{let i=document;i.exitFullscreen?await i.exitFullscreen():i.webkitExitFullscreen?await i.webkitExitFullscreen():i.mozCancelFullScreen?await i.mozCancelFullScreen():i.msExitFullscreen&&await i.msExitFullscreen();};react.useEffect(()=>{let i=()=>{let l=o();n(l===e.current);};return document.addEventListener("fullscreenchange",i),document.addEventListener("webkitfullscreenchange",i),document.addEventListener("mozfullscreenchange",i),document.addEventListener("MSFullscreenChange",i),()=>{document.removeEventListener("fullscreenchange",i),document.removeEventListener("webkitfullscreenchange",i),document.removeEventListener("mozfullscreenchange",i),document.removeEventListener("MSFullscreenChange",i);}},[e]);let d=react.useCallback(async()=>{let i=e.current;if(!(!i||!r))try{await s(i),n(!0);let l=screen.orientation;if(l?.lock)try{await l.lock("landscape");}catch{}}catch(l){console.error("[useFullscreen] Failed to enter fullscreen:",l);}},[e,r]),u=react.useCallback(async()=>{if(r)try{await a(),n(!1);let i=screen.orientation;i?.unlock&&i.unlock();}catch(i){console.error("[useFullscreen] Failed to exit fullscreen:",i);}},[r]),h=react.useCallback(async()=>{t?await u():await d();},[t,d,u]);return {isFullscreen:t,isSupported:r,toggleFullscreen:h,enterFullscreen:d,exitFullscreen:u}}var Ji={feed:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},watch:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},auto:{autoQualitySwitch:true,pauseOnOffline:true,resumeOnOnline:true,lowQualityOn:"2g"},manual:{autoQualitySwitch:false,pauseOnOffline:false,resumeOnOnline:false}},eo={aggressive:{autoPauseOnLowBattery:true,pauseThreshold:.2},moderate:{autoPauseOnLowBattery:true,pauseThreshold:.15},conservative:{autoPauseOnLowBattery:true,pauseThreshold:.1},manual:{autoPauseOnLowBattery:false}};function $e(e,t,n={}){let r=react.useRef(null),o=react.useRef(null),s=t??o,[a,d]=react.useState(false),u=gn(),h=yn(e),i=vn(e),l=bn(r.current),p=Bn(s),f=react.useRef(n);f.current=n;let{networkBehavior:y,powerBehavior:m}=n,b=react.useMemo(()=>{if(y)return typeof y=="string"?Ji[y]:y},[y]),S=react.useMemo(()=>{if(m)return typeof m=="string"?eo[m]:m},[m]),V=react.useMemo(()=>({onStateChange:g=>{u.transition(g),f.current.onStateChange?.(g),g==="ready"&&!a&&(d(true),f.current.onReady?.());},onError:(g,B)=>{f.current.onError?.(g,B);},onTimeUpdate:(g,B)=>{f.current.onTimeUpdate?.(g,B);},onQualityLevelsLoaded:g=>{f.current.onQualityLevelsLoaded?.(g);},onNetworkChange:g=>{b?.onNetworkChange?.(g),f.current.onNetworkChange?.(g);},onPowerChange:g=>{S?.onPowerChange?.(g),f.current.onPowerChange?.(g);},onAnalyticsUpdate:g=>{f.current.onAnalyticsUpdate?.(g);}}),[u,a,b,S]);react.useEffect(()=>{let g=e.current;if(!g)return;let B=()=>f.current.onPlay?.(),q=()=>f.current.onPause?.(),oe=()=>f.current.onEnded?.();return g.addEventListener("play",B),g.addEventListener("pause",q),g.addEventListener("ended",oe),()=>{g.removeEventListener("play",B),g.removeEventListener("pause",q),g.removeEventListener("ended",oe);}},[e]);let H=react.useCallback((g,B)=>{let q=e.current;if(!q){console.error("[usePlayer] No video element");return}d(false),r.current&&r.current.destroy(),r.current=new mn({preferNative:f.current.preferNative,enableSmoothTimeUpdates:f.current.enableSmoothTimeUpdates,enableNetworkAdaptation:f.current.enableNetworkAdaptation,enablePowerAdaptation:f.current.enablePowerAdaptation,enableAnalytics:f.current.enableAnalytics,preloadConfig:f.current.preloadConfig,callbacks:V,autoQualityOnNetworkChange:b?.autoQualitySwitch,autoPauseOnOffline:b?.pauseOnOffline,autoResumeOnOnline:b?.resumeOnOnline,lowQualityThreshold:b?.lowQualityOn,autoPauseOnLowBattery:S?.autoPauseOnLowBattery,lowBatteryThreshold:S?.pauseThreshold}),r.current.attach(q,g,B);},[e,V,b,S]),c=react.useCallback(()=>{r.current&&(r.current.destroy(),r.current=null),u.reset(),d(false);},[u]),v=react.useCallback(async()=>{await r.current?.play();},[]),P=react.useCallback(()=>{r.current?.pause();},[]),x=react.useCallback(async()=>{await r.current?.togglePlay();},[]),R=react.useCallback(g=>{r.current?.seek(g);},[]),A=react.useCallback((g=10)=>{r.current?.seekForward(g);},[]),D=react.useCallback((g=10)=>{r.current?.seekBackward(g);},[]),z=react.useCallback(g=>{r.current?.setPlaybackRate(g);},[]),_=react.useCallback(()=>{let g=e.current;g&&(g.currentTime=0,g.play().catch(()=>{}));},[e]);return {playerCore:r.current,videoRef:e,containerRef:s,state:u,isReady:a,play:v,pause:P,togglePlay:x,seek:R,seekForward:A,seekBackward:D,setPlaybackSpeed:z,restart:_,volume:h,progress:i,quality:l,fullscreen:p,attach:H,destroy:c}}var ro={position:"relative",width:"100%",height:"100%",backgroundColor:designTokens.colors.background},io={width:"100%",height:"100%",objectFit:"contain"},Ut=react.forwardRef(({video:e,autoPlay:t=true,muted:n=true,loop:r=true,poster:o,children:s,style:a,className:d="",onPlay:u,onPause:h,onEnded:i,onError:l,onStateChange:p,onTimeUpdate:f,onQualityLevelsLoaded:y,onReady:m},b)=>{let S=react.useRef(null),V=react.useRef(null),H=typeof e=="string"?e:e.url,c=o??(typeof e=="object"?e.thumbnail:void 0),v=$e(S,V,{onStateChange:p,onError:P=>l?.(P),onTimeUpdate:f,onQualityLevelsLoaded:y,onPlay:u,onPause:h,onEnded:i,onReady:m});return react.useEffect(()=>(H&&v.attach(H),()=>{v.destroy();}),[H]),react.useEffect(()=>{let P=S.current;P&&(P.muted=n,P.loop=r);},[n,r]),react.useEffect(()=>{let P=S.current;!P||!v.isReady||!t||P.play().catch(x=>{x.name==="NotAllowedError"&&(P.muted=true,P.play().catch(()=>{}));});},[t,v.isReady]),react.useImperativeHandle(b,()=>({play:v.play,pause:v.pause,togglePlay:v.togglePlay,seek:v.seek,seekForward:v.seekForward,seekBackward:v.seekBackward,restart:v.restart,setVolume:v.volume.setVolume,toggleMute:v.volume.toggleMute,setPlaybackSpeed:v.setPlaybackSpeed,setQuality:v.quality.setQuality,getQualityLevels:()=>v.quality.availableLevels,getVideoElement:()=>S.current,getCurrentTime:()=>v.progress.currentTime,getDuration:()=>v.progress.duration,isPaused:()=>S.current?.paused??true}),[v]),jsxRuntime.jsxs("div",{ref:V,style:Y(ro,a),className:d,children:[jsxRuntime.jsx("video",{ref:S,poster:c,playsInline:true,preload:"auto",style:io}),s]})});Ut.displayName="VideoPlayer";var co=30,ho=1e3/co,J={container:{position:"absolute",bottom:0,left:0,right:0,zIndex:designTokens.zIndices.sticky,touchAction:"none",userSelect:"none",WebkitUserSelect:"none",transition:"all 0.125s ease-in-out"},collapsed:{height:Ne.HEIGHT_DEFAULT,paddingInline:designTokens.spacing[3],cursor:"pointer"},expanded:{padding:`${designTokens.spacing[2]}px ${designTokens.spacing[3]}px`,paddingBottom:`calc(${designTokens.spacing[1]}px + env(safe-area-inset-bottom, 0px))`,background:"linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%)"},timeContainer:{display:"flex",justifyContent:"center",alignItems:"center",marginBottom:designTokens.spacing[2]},timeText:{fontSize:designTokens.fontSizes.sm,fontWeight:designTokens.fontWeights.semibold,color:designTokens.colors.text,textShadow:designTokens.shadows.text,fontVariantNumeric:"tabular-nums",backgroundColor:"rgba(0, 0, 0, 0.6)",padding:`${designTokens.spacing[1]}px ${designTokens.spacing[3]}px`,borderRadius:designTokens.radii.md},track:{position:"relative",width:"100%",backgroundColor:"rgba(255, 255, 255, 0.2)",borderRadius:designTokens.radii.full,overflow:"hidden"},trackCollapsed:{height:Ne.HEIGHT_DEFAULT},trackExpanded:{height:Ne.HEIGHT_ACTIVE},buffer:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:designTokens.radii.full},progress:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:designTokens.colors.text,borderRadius:designTokens.radii.full},scrubber:{position:"absolute",top:"50%",width:16,height:16,marginLeft:-8,marginTop:-8,backgroundColor:designTokens.colors.text,borderRadius:designTokens.radii.full,boxShadow:"0 2px 4px rgba(0,0,0,0.3)",transform:"scale(0)",transition:"transform 150ms ease"},scrubberVisible:{transform:"scale(1)"},touchArea:{position:"absolute",top:-12,left:0,right:0,bottom:-12,cursor:"pointer"}};function ge(e){if(!isFinite(e)||isNaN(e))return "0:00";let t=Math.floor(e/60),n=Math.floor(e%60);return `${t}:${n.toString().padStart(2,"0")}`}function po(e){if(e.buffered.length===0)return 0;for(let t=0;t<e.buffered.length;t++)if(e.buffered.start(t)<=e.currentTime&&e.buffered.end(t)>=e.currentTime)return e.buffered.end(t);return e.buffered.end(e.buffered.length-1)}var ft=react.forwardRef(({videoRef:e,expanded:t=false,onSeekStart:n,onSeek:r,onSeekEnd:o,onExpandedChange:s,style:a,className:d=""},u)=>{let h=react.useRef(null),i=react.useRef(null),l=react.useRef(null),p=react.useRef(null),f=react.useRef(null),y=react.useRef(0),[m,b]=react.useState({currentTime:0,duration:0}),S=react.useRef(null),V=react.useRef(0),H=react.useRef(0),c=react.useRef(false),v=react.useRef(t);react.useEffect(()=>{v.current=t;},[t]);let P=react.useCallback(C=>{let E=e.current;if(!E||c.current)return;let k=E.duration||0,L=E.currentTime||0,O=po(E),Se=k>0?L/k*100:0,w=k>0?O/k*100:0;i.current&&(i.current.style.width=`${Se}%`),l.current&&(l.current.style.width=`${w}%`),p.current&&v.current&&(p.current.style.left=`${Se}%`),y.current=k,f.current&&(f.current.textContent=`${ge(L)} / ${ge(k)}`);let N=C??performance.now();N-H.current>=500&&(H.current=N,b(j=>Math.abs(j.currentTime-L)>=.5||j.duration!==k?{currentTime:Math.floor(L),duration:Math.floor(k)}:j));},[e]),x=react.useCallback(C=>{C-V.current>=ho&&(V.current=C,P()),S.current=requestAnimationFrame(x);},[P]);react.useEffect(()=>(S.current=requestAnimationFrame(x),()=>{S.current&&cancelAnimationFrame(S.current);}),[x]);let R=react.useCallback(C=>{let E=h.current,k=e.current;if(!E||!k)return 0;let L=E.getBoundingClientRect(),O=C-L.left;return Math.max(0,Math.min(1,O/L.width))*(k.duration||0)},[e]),A=react.useCallback(C=>{c.current=true,n?.();let E=R(C);r?.(E);let k=e.current;if(k&&i.current){let L=k.duration||y.current||1,O=E/L*100;i.current.style.width=`${O}%`,p.current&&(p.current.style.left=`${O}%`),f.current&&(f.current.textContent=`${ge(E)} / ${ge(L)}`);}},[R,r,n,e]),D=react.useCallback(C=>{if(!c.current)return;let E=R(C);r?.(E);let k=e.current;if(k&&i.current){let L=k.duration||y.current||1,O=E/L*100;i.current.style.width=`${O}%`,p.current&&(p.current.style.left=`${O}%`),f.current&&(f.current.textContent=`${ge(E)} / ${ge(L)}`);}},[R,r,e]),z=react.useCallback(C=>{if(!c.current)return;c.current=false;let E=R(C);o?.(E);let k=e.current;k&&(k.currentTime=E);},[R,o,e]),_=react.useCallback(C=>{let E=C.touches[0];E&&A(E.clientX);},[A]),g=react.useCallback(C=>{let E=C.touches[0];E&&D(E.clientX);},[D]),B=react.useCallback(C=>{let E=C.changedTouches[0];E&&z(E.clientX);},[z]),q=react.useCallback(C=>{A(C.clientX);let E=L=>D(L.clientX),k=L=>{z(L.clientX),document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",k);};document.addEventListener("mousemove",E),document.addEventListener("mouseup",k);},[A,D,z]),oe=react.useCallback(()=>{t||s?.(true);},[t,s]),X=react.useCallback(C=>{let E=e.current;if(!E)return;let k=E.duration||0,L=E.currentTime||0,O=L;switch(C.key){case "ArrowLeft":O=Math.max(0,L-5);break;case "ArrowRight":O=Math.min(k,L+5);break;case "ArrowUp":O=Math.min(k,L+10);break;case "ArrowDown":O=Math.max(0,L-10);break;case "Home":O=0;break;case "End":O=k;break;default:return}C.preventDefault(),E.currentTime=O,r?.(O),P();},[e,r,P]);react.useImperativeHandle(u,()=>({update:P,setExpanded:C=>{s?.(C);}}));let $={...J.container,...t?J.expanded:J.collapsed,...a},K={...J.track,...t?J.trackExpanded:J.trackCollapsed},se={...J.scrubber,...t?J.scrubberVisible:{}};return jsxRuntime.jsxs("div",{ref:h,style:$,className:d,onClick:t?void 0:oe,onTouchStart:_,onTouchMove:g,onTouchEnd:B,onTouchCancel:B,onMouseDown:q,onKeyDown:X,role:"slider","aria-label":"Video progress","aria-valuemin":0,"aria-valuemax":m.duration,"aria-valuenow":m.currentTime,"aria-valuetext":`${ge(m.currentTime)} of ${ge(m.duration)}`,tabIndex:0,children:[t&&jsxRuntime.jsx("div",{style:J.timeContainer,children:jsxRuntime.jsx("span",{ref:f,style:J.timeText,children:"0:00 / 0:00"})}),jsxRuntime.jsxs("div",{style:K,"aria-hidden":"true",children:[jsxRuntime.jsx("div",{style:J.touchArea}),jsxRuntime.jsx("div",{ref:l,style:J.buffer}),jsxRuntime.jsx("div",{ref:i,style:J.progress}),t&&jsxRuntime.jsx("div",{ref:p,style:se})]})]})});ft.displayName="Timeline";var fo={DOUBLE_TAP_DELAY:200},mo={THRESHOLD:500},qe={VERTICAL_THRESHOLD:.3,HORIZONTAL_THRESHOLD:.4,MIN_VELOCITY:.5},mt={THRESHOLD:10};var ye={TAP_DELAY:fo.DOUBLE_TAP_DELAY,LONG_PRESS_THRESHOLD:mo.THRESHOLD,SWIPE_VERTICAL_THRESHOLD:qe.VERTICAL_THRESHOLD,SWIPE_HORIZONTAL_THRESHOLD:qe.HORIZONTAL_THRESHOLD,DRAG_THRESHOLD:mt.THRESHOLD};function Qn(){return typeof navigator<"u"&&"vibrate"in navigator}function gt(){Qn()&&navigator.vibrate(10);}function zn(){Qn()&&navigator.vibrate(20);}function Wn(e,t){let n=e.currentTarget||e.target;if(!n||typeof n.getBoundingClientRect!="function")return "center";let r=n.getBoundingClientRect(),o=e.clientX-r.left,s=r.width;if(s===0)return "center";let a=s*.33,d=s*.67;return o<a?"left":o>d?"right":"center"}function yt(e){let t=react.useRef(0),n=react.useRef("center"),r=react.useRef(null),o=react.useRef(null),s=react.useRef(false),a=react.useRef(false),d=react.useRef({x:0,y:0}),u=react.useCallback(i=>{if(a.current){a.current=false;return}let l=Wn(i),p=Date.now(),f=p-t.current,y={x:i.clientX,y:i.clientY};f<ye.TAP_DELAY&&n.current===l?(r.current&&(clearTimeout(r.current),r.current=null),gt(),e.onDoubleTap?.(l,y)):r.current=setTimeout(()=>{e.onSingleTap?.(l),r.current=null;},ye.TAP_DELAY),t.current=p,n.current=l;},[e]);return react$2.useGesture({onPointerDown:({event:i})=>{let l=i;d.current={x:l.clientX,y:l.clientY},a.current=false;let p=setTimeout(()=>{s.current=true,e.onHoldStart?.();},150);o.current=setTimeout(()=>{a.current=true,zn();let y=l.target.getBoundingClientRect();e.onLongPress?.({x:l.clientX-y.left,y:l.clientY-y.top});},ye.LONG_PRESS_THRESHOLD),i.target.dataset.holdTimeout=String(p);},onPointerUp:({event:i})=>{let l=i.target.dataset.holdTimeout;l&&clearTimeout(Number(l)),o.current&&(clearTimeout(o.current),o.current=null),s.current&&(s.current=false,e.onHoldEnd?.());},onPointerMove:({event:i})=>{let l=i,p=Math.abs(l.clientX-d.current.x),f=Math.abs(l.clientY-d.current.y);(p>10||f>10)&&o.current&&(clearTimeout(o.current),o.current=null);},onClick:({event:i})=>{u(i);},onDrag:({movement:[i,l],direction:[p,f],velocity:[y,m],last:b,event:S})=>{if(S.preventDefault(),!b)return;let V=window.innerWidth,H=window.innerHeight;if(Math.abs(l)>H*ye.SWIPE_VERTICAL_THRESHOLD){f>0?e.onSwipeDown?.():e.onSwipeUp?.();return}if(Math.abs(i)>V*ye.SWIPE_HORIZONTAL_THRESHOLD){p>0?e.onSwipeRight?.():e.onSwipeLeft?.();return}Math.abs(i)>ye.DRAG_THRESHOLD&&Math.abs(y)>Math.abs(m)&&e.onSeekDrag?.(i);}},{drag:{threshold:ye.DRAG_THRESHOLD,filterTaps:true},eventOptions:{passive:false}})}var wo=800,Po=.05,Eo=.95;function Qt({onSwipeUp:e,onSwipeDown:t,onSwipeProgress:n,onSwipeCancel:r,threshold:o=qe.VERTICAL_THRESHOLD,velocityThreshold:s=qe.MIN_VELOCITY,hapticEnabled:a=true,disabled:d=false,enableProgressState:u=false}={}){let h=Math.max(Po,Math.min(Eo,o)),[i,l]=react.useState({progress:0,direction:null,isSwiping:false}),p=react.useRef({onSwipeUp:e,onSwipeDown:t,onSwipeProgress:n,onSwipeCancel:r}),f=react.useRef(typeof window<"u"?window.innerHeight:wo);return p.current={onSwipeUp:e,onSwipeDown:t,onSwipeProgress:n,onSwipeCancel:r},react.useEffect(()=>{let m=()=>{f.current=window.innerHeight;},b=()=>{setTimeout(()=>{f.current=window.innerHeight;},100);};return window.addEventListener("resize",m,{passive:true}),window.addEventListener("orientationchange",b,{passive:true}),()=>{window.removeEventListener("resize",m),window.removeEventListener("orientationchange",b);}},[]),{bind:react$2.useDrag(({movement:[,m],velocity:[,b],active:S,cancel:V})=>{if(d){V?.();return}let c=f.current*h,v=Math.min(1,Math.abs(m)/c),P=m<0?"up":"down";if(S)p.current.onSwipeProgress?.(v,P,m),u&&l({progress:v,direction:P,isSwiping:true});else {let x=Math.abs(m)>=c,R=Math.abs(b)>=s;x||R?(a&>(),P==="up"?p.current.onSwipeUp?.():p.current.onSwipeDown?.()):p.current.onSwipeCancel?.(),l({progress:0,direction:null,isSwiping:false});}},{axis:"y",threshold:mt.THRESHOLD,filterTaps:true,pointer:{touch:true},eventOptions:{passive:true}}),...i}}var Oe={container:{position:"relative",width:"100%",height:"100%",backgroundColor:designTokens.colors.background},video:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"contain"},placeholder:{position:"absolute",inset:0,backgroundSize:"cover",backgroundPosition:"center"},tapArea:{zIndex:designTokens.zIndices.base},pauseOverlay:{zIndex:designTokens.zIndices.overlay},pauseIconWrapper:{borderRadius:designTokens.radii.full,transition:`opacity ${designTokens.durations.normal}ms ${designTokens.easings.xhubReel}, transform ${designTokens.durations.normal}ms ${designTokens.easings.xhubReel}`}};var zt=react.createContext(null);function pe(){let e=react.useContext(zt);if(!e)throw new Error("VideoFeedItem compound components must be used within a VideoFeedItem");return e}function $n({elementRef:e,activateThreshold:t=et.ACTIVATION_THRESHOLD,deactivateThreshold:n=et.DEACTIVATION_THRESHOLD,rootMargin:r="0px",onVisibilityChange:o}){let[s,a]=react.useState(false),[d,u]=react.useState(false),[h,i]=react.useState(0),l=react.useRef(null);return react.useEffect(()=>{let p=e.current;if(!p)return;l.current&&l.current.disconnect();let f=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1];return l.current=new IntersectionObserver(y=>{y.forEach(m=>{let b=m.intersectionRatio;i(b),a(b>0),b>=t?u(true):b<n&&u(false),o?.(b>0,b);});},{threshold:f,rootMargin:r}),l.current.observe(p),()=>{l.current?.disconnect();}},[e,t,n,r,o]),{isVisible:s,isActive:d,visibilityRatio:h}}function Yn({containerRef:e,videoRef:t,isCurrentVideo:n=false,onActivate:r,onDeactivate:o,autoActivate:s=true,trackVisibility:a=false,onVisibilityChange:d}){let u=react.useRef(false),{isVisible:h,isActive:i,visibilityRatio:l}=$n({elementRef:e??{current:null},onVisibilityChange:a?d:void 0}),p=a?i:n;react.useEffect(()=>{s&&(p&&!u.current?(u.current=true,r?.()):!p&&u.current&&(u.current=false,o?.()));},[p,r,o,s]);let f=react.useCallback(()=>{let m=t.current;m&&m.play().catch(()=>{m.muted=true,m.play().catch(()=>{});}),r?.();},[t,r]),y=react.useCallback(()=>{let m=t.current;m&&(m.pause(),m.currentTime=0),o?.();},[t,o]);return {isActive:p,isVisible:a?h:n,visibilityRatio:a?l:n?1:0,activate:f,deactivate:y}}var Gt=class{entries=new Map;listeners=new Set;memoryWarningThreshold;constructor(){this.memoryWarningThreshold=Re.MAX_TOTAL_MEMORY/(1024*1024),this.setupMemoryPressureListener();}register(t,n=10){this.entries.set(t,{videoId:t,inDom:false,hasDecodedFrames:false,estimatedSizeMB:n,lastAccessed:Date.now()}),this.notifyListeners();}unregister(t){this.entries.delete(t),this.notifyListeners();}setInDom(t,n){let r=this.entries.get(t);r&&(r.inDom=n,r.lastAccessed=Date.now(),this.notifyListeners());}setHasDecodedFrames(t,n){let r=this.entries.get(t);r&&(r.hasDecodedFrames=n,r.lastAccessed=Date.now(),this.notifyListeners());}getState(){let t=0,n=0,r=0;return this.entries.forEach(o=>{o.inDom&&t++,o.hasDecodedFrames&&n++,r+=o.estimatedSizeMB;}),{videosInDom:t,decodedVideos:n,estimatedMemoryMB:r,isLowMemory:r>this.memoryWarningThreshold}}getVideosToDispose(){let t=this.getState(),n=[],r=Re?.MAX_VIDEOS_IN_DOM,o=Re?.MAX_DECODED_FRAMES,s=Array.from(this.entries.values()).sort((a,d)=>a.lastAccessed-d.lastAccessed);if(t.videosInDom>r){let a=t.videosInDom-r,d=0;for(let u of s){if(d>=a)break;u.inDom&&(n.push(u.videoId),d++);}}if(t.decodedVideos>o){let a=t.decodedVideos-o,d=0;for(let u of s){if(d>=a)break;u.hasDecodedFrames&&!n.includes(u.videoId)&&(n.push(u.videoId),d++);}}return n}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}forceCleanup(){let t=this.getVideosToDispose();return t.forEach(n=>this.unregister(n)),t}notifyListeners(){let t=this.getState();this.listeners.forEach(n=>n(t));}setupMemoryPressureListener(){typeof window>"u"||"memory"in performance&&setInterval(()=>{this.getState().isLowMemory&&(console.warn("[MemoryManager] Low memory warning, forcing cleanup"),this.forceCleanup());},5e3);}},ve=new Gt;function Zn({videoId:e,estimatedSizeMB:t=10,onShouldDispose:n}){let[r,o]=react.useState(()=>ve.getState()),[s,a]=react.useState(false);react.useEffect(()=>(ve.register(e,t),()=>{ve.unregister(e);}),[e,t]),react.useEffect(()=>ve.subscribe(i=>{o(i);let p=ve.getVideosToDispose().includes(e);p&&!s?(a(true),n?.()):!p&&s&&a(false);}),[e,s,n]);let d=react.useCallback(h=>{ve.setInDom(e,h);},[e]),u=react.useCallback(h=>{ve.setHasDecodedFrames(e,h);},[e]);return {memoryState:r,setInDom:d,setHasDecodedFrames:u,shouldDispose:s}}function er({video:e,isActive:t,priority:n,initialMuted:r=true,onLike:o,onComment:s,onShare:a,onAuthorClick:d}){let u=react.useRef(null),h=react.useRef(null),i=react.useRef(false),[l,p]=react.useState(false),[f,y]=react.useState(false),[m,b]=react.useState(false),{isShowing:S,position:V,showHeart:H}=ht(),c=react.useMemo(()=>({maxConcurrent:2,maxBufferSize:10*1024*1024,priorityLevels:10}),[]),v=react.useCallback(w=>{},[]),P=react.useCallback(w=>{},[]),x=react.useCallback(w=>{w.startupTime&&w.startupTime>1e3&&console.warn("[VideoFeedItem] Slow startup:",w.startupTime,"ms",e.id);},[e.id]),{state:R}=$e(h,u,{preferNative:true,enableSmoothTimeUpdates:true,networkBehavior:"feed",powerBehavior:"moderate",preloadConfig:c,enableAnalytics:true,onPlay:()=>{p(false),y(false);},onPause:()=>{h.current?.seeking||(p(true),y(true));},onNetworkChange:v,onPowerChange:P,onAnalyticsUpdate:x}),A=react.useCallback(async()=>{let w=h.current;if(w){w.muted=r;try{await w.play();}catch(N){if(N.name==="NotAllowedError"&&!r){console.warn("[VideoFeedItem] Autoplay blocked, falling back to muted"),w.muted=true;try{await w.play();}catch(j){console.warn("[VideoFeedItem] Play failed even muted:",j.message);}}else console.warn("[VideoFeedItem] Play failed:",N.message);}}},[r]),D=react.useCallback(()=>{let w=h.current;w&&w.pause();},[]),z=react.useCallback(w=>{let N=h.current;N&&(N.currentTime=w);},[]),[_,g]=react.useState(false);react.useEffect(()=>{let w=h.current;if(!w)return;let N=()=>g(true),j=()=>g(false),Ze=()=>g(false);return w.addEventListener("play",N),w.addEventListener("pause",j),w.addEventListener("ended",Ze),g(!w.paused),()=>{w.removeEventListener("play",N),w.removeEventListener("pause",j),w.removeEventListener("ended",Ze);}},[e.id]);let B=_||R.state==="playing",{setInDom:q,setHasDecodedFrames:oe,shouldDispose:X}=Zn({videoId:e.id,onShouldDispose:()=>{D(),h.current&&(h.current.src="",h.current.load());}}),$=!X&&n!=="none",K=react.useRef(false);Yn({videoRef:h,isCurrentVideo:t,onActivate:()=>{console.log("[VideoFeedItem] onActivate called, videoRef:",h.current?.src),oe(true),h.current?A():(console.log("[VideoFeedItem] Video element not ready, marking pending play"),K.current=true);},onDeactivate:()=>{console.log("[VideoFeedItem] onDeactivate called"),K.current=false,oe(false),D(),z(0);},autoActivate:true}),react.useEffect(()=>{h.current&&K.current&&t&&(console.log("[VideoFeedItem] Video element now available, executing pending play"),K.current=false,A());}),react.useEffect(()=>(q(true),()=>q(false)),[q]),react.useEffect(()=>{let w=h.current;if(!w)return;b(false);let N=()=>{console.log("[VideoFeedItem] Video loadeddata:",e.id,{isActive:t,priority:n}),n==="high"&&!t?requestAnimationFrame(()=>{w.readyState>=2&&(w.currentTime=.01,b(true),console.log("[VideoFeedItem] First frame decoded (preloaded):",e.id));}):t&&b(true);},j=()=>{n==="high"&&!m&&b(true);};return w.addEventListener("loadeddata",N),w.addEventListener("canplay",j),w.readyState>=2&&N(),()=>{w.removeEventListener("loadeddata",N),w.removeEventListener("canplay",j);}},[e.id,t,n,m]),react.useEffect(()=>{console.log("[VideoFeedItem] State:",{videoId:e.id,isActive:t,priority:n,shouldRenderVideo:$,hasVideoElement:!!h.current,videoSrc:h.current?.src});},[e.id,t,n,$]);let se=react.useMemo(()=>{switch(n){case "high":return "auto";case "medium":return "metadata";case "low":case "metadata":return "none";default:return "none"}},[n]),C=react.useCallback(()=>{i.current=B,y(true),p(false),D();},[B,D]),E=react.useCallback(w=>{z(w),i.current?(A(),y(false)):p(true);},[z,A]),k=react.useCallback(()=>{B?D():A();},[B,A,D]),L=react.useCallback((w,N)=>{H(N.x,N.y),o?.();},[H,o]),O=react.useCallback(()=>{},[]),Se=yt({onSingleTap:k,onDoubleTap:L,onLongPress:O});return {video:e,isActive:t,shouldRenderVideo:$,preload:se,isPreloaded:m,initialMuted:r,containerRef:u,videoRef:h,isPlaying:B,showPauseOverlay:l,timelineExpanded:f,play:A,pause:D,seek:z,setShowPauseOverlay:p,setTimelineExpanded:y,gestureBindings:Se,showHeart:S,heartPosition:V,triggerHeart:H,onLike:o,onComment:s,onShare:a,onAuthorClick:d,handleSeekStart:C,handleSeekEnd:E}}var St=react.forwardRef(({placeholder:e,...t},n)=>{let{video:r,videoRef:o,shouldRenderVideo:s,preload:a,isPreloaded:d,initialMuted:u}=pe();if(!s)return e??jsxRuntime.jsx("div",{...t,style:{...Oe.placeholder,backgroundImage:`url(${r.thumbnail})`,...t.style}});let h=!d;return jsxRuntime.jsx("video",{ref:i=>{typeof n=="function"?n(i):n&&(n.current=i),o.current=i;},src:r.url,poster:h?r.thumbnail:void 0,preload:a,loop:true,playsInline:true,muted:u,style:Oe.video})});St.displayName="VideoFeedItemPlayer";var wt=react.forwardRef(({onLike:e,onComment:t,onShare:n,...r},o)=>{let{video:s,onLike:a,onComment:d,onShare:u}=pe();return jsxRuntime.jsx("div",{ref:o,...r,children:jsxRuntime.jsx(at,{avatarUrl:s.author.avatar,likeCount:s.stats.likes,commentCount:s.stats.comments,shareCount:s.stats.shares,isLiked:s.isLiked,onLike:e??a,onComment:t??d,onShare:n??u})})});wt.displayName="VideoFeedItemActions";var Pt=react.forwardRef(({expanded:e,...t},n)=>{let{videoRef:r,shouldRenderVideo:o,timelineExpanded:s,setTimelineExpanded:a,handleSeekStart:d,handleSeekEnd:u}=pe();return o?jsxRuntime.jsx("div",{ref:n,...t,children:jsxRuntime.jsx(ft,{videoRef:r,expanded:e??s,onSeekStart:d,onSeekEnd:u,onExpandedChange:a})}):null});Pt.displayName="VideoFeedItemTimeline";var He={container:{position:"absolute",bottom:0,left:0,right:64,padding:designTokens.spacing[4],paddingBottom:"env(safe-area-inset-bottom, 16px)",zIndex:designTokens.zIndices.base},containerWithTimeline:{paddingBottom:"calc(env(safe-area-inset-bottom, 16px) + 48px)"},authorButton:{gap:designTokens.spacing[2],marginBottom:designTokens.spacing[3]},avatar:{borderRadius:designTokens.radii.full,border:`2px solid ${designTokens.colors.text}`},username:{color:designTokens.colors.text,fontWeight:designTokens.fontWeights.semibold,fontSize:designTokens.fontSizes.sm,textShadow:designTokens.shadows.text},caption:{color:designTokens.colors.text,fontSize:designTokens.fontSizes.sm,lineHeight:1.4,textShadow:designTokens.shadows.text,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:designTokens.spacing[1]},author:{color:designTokens.colors.text,fontSize:designTokens.fontSizes.sm,fontWeight:designTokens.fontWeights.semibold,textShadow:designTokens.shadows.text,display:"-webkit-box",WebkitLineClamp:1,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:designTokens.spacing[1]},hashtags:{display:"flex",flexWrap:"wrap",gap:designTokens.spacing[1],marginTop:designTokens.spacing[2],paddingBottom:designTokens.spacing[1]},hashtag:{color:designTokens.colors.accent,fontSize:designTokens.fontSizes.sm,fontWeight:designTokens.fontWeights.medium,textShadow:designTokens.shadows.text}};function or({video:e,timelineExpanded:t=false,style:n,className:r=""}){let o=Y(He.container,t&&He.containerWithTimeline,n);return jsxRuntime.jsxs("div",{style:o,className:r,children:[e.author&&jsxRuntime.jsx("p",{style:He.author,children:e.author.displayName}),e.caption&&jsxRuntime.jsx("p",{style:He.caption,children:e.caption}),e.hashtags&&e.hashtags.length>0&&jsxRuntime.jsx("div",{style:He.hashtags,children:e.hashtags.slice(0,3).map((s,a)=>jsxRuntime.jsxs("span",{style:He.hashtag,children:["#",s]},a))})]})}var Et=react.forwardRef(({showPlayPause:e=true,showDoubleTapHeart:t=true,showVideoInfo:n=true,...r},o)=>{let{video:s,isPlaying:a,showPauseOverlay:d,timelineExpanded:u,showHeart:h,heartPosition:i,onAuthorClick:l}=pe();return jsxRuntime.jsxs("div",{ref:o,...r,children:[e&&jsxRuntime.jsx(dt,{isPlaying:a,show:d,size:64,autoHideDelay:800,showOnStateChange:false}),t&&jsxRuntime.jsx(pt,{show:h,position:i,size:100,showParticles:true,particleCount:8}),n&&jsxRuntime.jsx(or,{video:s,onAuthorClick:l,timelineExpanded:u})]})});Et.displayName="VideoFeedItemOverlay";var Be=react.forwardRef(({video:e,isActive:t=false,priority:n="none",initialMuted:r=true,showTimeline:o=true,onLike:s,onComment:a,onShare:d,onAuthorClick:u,style:h,className:i="",children:l},p)=>{let f=er({video:e,isActive:t,priority:n,initialMuted:r,onLike:s,onComment:a,onShare:d,onAuthorClick:u}),y=l??jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(St,{}),jsxRuntime.jsx(Et,{}),jsxRuntime.jsx(wt,{}),o&&jsxRuntime.jsx(Pt,{})]});return jsxRuntime.jsx(zt.Provider,{value:f,children:jsxRuntime.jsx("div",{ref:m=>{typeof p=="function"?p(m):p&&(p.current=m),f.containerRef.current=m;},style:Y(Oe.container,h),className:i,...f.gestureBindings(),children:y})})});Be.displayName="VideoFeedItem";function sr(e,t){let n=e-t;return n===0||n===-1||n===1?"high":n===2?"medium":n===3?"low":Math.abs(n)<=5?"metadata":"none"}var Bo="cubic-bezier(0.32, 0.72, 0, 1)",No=300,_o=800,Uo=50;function lr({trackRef:e,transitionDuration:t=No,easing:n=Bo,onTransitionEnd:r}){let o=react.useRef(typeof window<"u"?window.innerHeight:_o),s=react.useRef(0),a=react.useRef(null),d=react.useRef(false),u=react.useRef(true);react.useEffect(()=>{let f=()=>{o.current=window.innerHeight;},y=()=>{setTimeout(()=>{o.current=window.innerHeight;},100);};return window.addEventListener("resize",f,{passive:true}),window.addEventListener("orientationchange",y,{passive:true}),()=>{window.removeEventListener("resize",f),window.removeEventListener("orientationchange",y);}},[]);let h=react.useCallback(f=>{s.current=f,a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{let y=e.current;y&&(y.style.transition="none",y.style.transform=`translateY(${f}px)`),a.current=null;});},[e]),i=react.useCallback(f=>new Promise(y=>{let m=e.current;if(!m||!u.current){y();return}if(d.current){y();return}d.current=true,s.current=f;let b=null,S=null,V=H=>{H.propertyName==="transform"&&(b?.(),u.current&&(d.current=false,r?.()),y());};b=()=>{m.removeEventListener("transitionend",V),S&&(clearTimeout(S),S=null);},m.addEventListener("transitionend",V),S=setTimeout(()=>{b?.(),u.current&&d.current&&(d.current=false,r?.()),y();},t+Uo),m.offsetHeight,m.style.transition=`transform ${t}ms ${n}`,m.style.transform=`translateY(${f}px)`;}),[e,t,n,r]),l=react.useCallback(()=>i(0),[i]),p=react.useCallback(()=>s.current,[]);return react.useEffect(()=>(u.current=true,()=>{u.current=false,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null);}),[]),{setTranslateY:h,animateTo:i,snapBack:l,getCurrentY:p,viewportHeight:o.current,isAnimating:d.current}}var Wo=300,Go=50,$o=.3,qo="cubic-bezier(0.32, 0.72, 0, 1)",be={container:{position:"fixed",inset:0,overflow:"hidden",backgroundColor:designTokens.colors.background,touchAction:"none",userSelect:"none",WebkitUserSelect:"none"},track:{position:"relative",width:"100%",height:"100%",willChange:"transform"},slide:{position:"absolute",left:0,width:"100%",height:"100%",backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},loadingIndicator:{position:"absolute",bottom:80,left:0,right:0,display:"flex",justifyContent:"center",zIndex:designTokens.zIndices.base,pointerEvents:"none"},spinner:{width:24,height:24,borderWidth:2,borderStyle:"solid",borderColor:"rgba(255, 255, 255, 0.3)",borderTopColor:designTokens.colors.text,borderRadius:designTokens.radii.full,animation:"xhub-reel-spin 1s linear infinite"}},Ke=react.forwardRef(({videos:e,initialIndex:t=0,onLoadMore:n,onVideoChange:r,onLike:o,onComment:s,onShare:a,onAuthorClick:d,isLoading:u=false,hasMore:h=false,loadMoreThreshold:i=3,transitionDuration:l=Wo,swipeThreshold:p=Go,velocityThreshold:f=$o,gesturesDisabled:y=false,hapticEnabled:m=true,initialMuted:b=true,style:S,className:V=""},H)=>{let[c,v]=react.useState(()=>Math.min(Math.max(0,t),Math.max(0,e.length-1))),[P,x]=react.useState(false),[R,A]=react.useState(false),D=react.useRef(null),z=react.useRef(null),_=react.useRef(e),g=react.useRef(c),B=react.useRef(u),q=react.useRef(h),oe=react.useRef(P),{setCurrentIndex:X}=Tt(),{setTranslateY:$,animateTo:K,snapBack:se,viewportHeight:C}=lr({trackRef:z,transitionDuration:l,easing:qo});react.useEffect(()=>{_.current=e;},[e]),react.useEffect(()=>{g.current=c;},[c]),react.useEffect(()=>{B.current=u;},[u]),react.useEffect(()=>{q.current=h;},[h]),react.useEffect(()=>{oe.current=P;},[P]),react.useEffect(()=>{if(e.length===0){v(0);return}if(c>=e.length){let I=e.length-1,U=e[I];v(I),X(I),U&&r?.(U,I);}},[e.length,c,X,r,e]);let E=react.useCallback(I=>sr(I,c),[c]),k=react.useCallback(I=>{let U=_.current;q.current&&!B.current&&U.length-I<=i&&n?.();},[i,n]),L=react.useCallback(async(I,U=true)=>{if(oe.current)return;let F=_.current,M=Math.max(0,Math.min(I,F.length-1)),ae=g.current;if(M===ae){$(0);return}let xe=M>ae?-1:1;if(U){x(true),A(true),await K(xe*C),v(M),X(M),$(0);let we=F[M];we&&r?.(we,M),k(M),A(false),x(false);}else {v(M),X(M),$(0);let we=F[M];we&&(r?.(we,M),k(M));}},[C,K,$,X,r,k]),O=react.useCallback((I=true)=>{let U=_.current,F=g.current;F<U.length-1&&L(F+1,I);},[L]),Se=react.useCallback((I=true)=>{let U=g.current;U>0&&L(U-1,I);},[L]),w=react.useCallback((I,U,F)=>{let M=_.current,ae=g.current,xe=ae>0,we=ae<M.length-1,Kt=F;(U==="down"&&!xe||U==="up"&&!we)&&(Kt*=.3),$(Kt);},[$]),N=react.useCallback(async()=>{let I=_.current;if(!(g.current<I.length-1)){await se();return}x(true),A(true),await K(-C);let M=g.current+1,ae=_.current;if(M<ae.length){v(M),X(M);let xe=ae[M];xe&&r?.(xe,M),k(M);}$(0),A(false),x(false);},[C,K,se,$,X,r,k]),j=react.useCallback(async()=>{if(!(g.current>0)){await se();return}x(true),A(true),await K(C);let F=g.current-1;if(F>=0){v(F),X(F);let M=_.current[F];M&&r?.(M,F);}$(0),A(false),x(false);},[C,K,se,$,X,r]),Ze=react.useCallback(async()=>{await se();},[se]),{bind:cr}=Qt({onSwipeUp:N,onSwipeDown:j,onSwipeProgress:w,onSwipeCancel:Ze,threshold:p/C,velocityThreshold:f,hapticEnabled:m,disabled:y||P,enableProgressState:false});react.useImperativeHandle(H,()=>({slideTo:L,slideNext:O,slidePrev:Se,get activeIndex(){return g.current},get totalSlides(){return _.current.length},get isBeginning(){return g.current===0},get isEnd(){return g.current===_.current.length-1}})),react.useEffect(()=>{let I=e[c];I&&r?.(I,c);},[]);let Je=[];if(c>0&&Je.push({index:c-1,position:-1}),Je.push({index:c,position:0}),c<e.length-1&&Je.push({index:c+1,position:1}),e.length===0)return jsxRuntime.jsx("div",{ref:D,style:Y(be.container,S),className:V,"data-xhub-reel-feed":true,children:u&&jsxRuntime.jsx("div",{style:{...be.loadingIndicator,top:"50%",bottom:"auto"},children:jsxRuntime.jsx("div",{style:be.spinner})})});let hr={...be.track};return jsxRuntime.jsxs("div",{ref:D,...cr(),style:Y(be.container,S),className:V,"data-xhub-reel-feed":true,children:[jsxRuntime.jsx("style",{children:`
|
|
5
|
+
`}),jsxRuntime.jsx("div",{role:"status","aria-label":"Loading",style:designTokens.mergeStyles({width:t,height:t,borderWidth:r,borderStyle:"solid",borderColor:`${e}30`,borderTopColor:e,borderRadius:"50%",animation:"xhub-reel-spin 1s linear infinite"},o),className:n})]})}var Jn={position:"fixed",left:designTokens.spacing[4],right:designTokens.spacing[4],zIndex:designTokens.zIndices.toast,display:"flex",justifyContent:"center",pointerEvents:"none"},ei={display:"flex",alignItems:"center",gap:designTokens.spacing[3],padding:`${designTokens.spacing[3]}px ${designTokens.spacing[4]}px`,backgroundColor:designTokens.colors.surface,borderRadius:designTokens.radii.lg,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.5)",pointerEvents:"auto",maxWidth:400},ti={default:{},success:{borderLeft:`3px solid ${designTokens.colors.success}`},error:{borderLeft:`3px solid ${designTokens.colors.error}`},warning:{borderLeft:`3px solid ${designTokens.colors.warning}`}},ri={flex:1,fontSize:designTokens.fontSizes.sm,color:designTokens.colors.text,lineHeight:1.4},oi={padding:`${designTokens.spacing[1]}px ${designTokens.spacing[3]}px`,backgroundColor:"transparent",border:"none",color:designTokens.colors.accent,fontSize:designTokens.fontSizes.sm,fontWeight:600,cursor:"pointer",borderRadius:designTokens.radii.sm};function qr({message:t,isVisible:e,onClose:r,duration:o=3e3,variant:n="default",action:i,position:a="bottom",style:u,className:d=""}){react.useEffect(()=>{if(e&&o>0){let s=setTimeout(r,o);return ()=>clearTimeout(s)}},[e,o,r]);let f=a==="top"?{top:designTokens.spacing[4]}:{bottom:designTokens.spacing[4]+80};return jsxRuntime.jsx(react$1.AnimatePresence,{children:e&&jsxRuntime.jsx("div",{style:{...Jn,...f},children:jsxRuntime.jsxs(react$1.motion.div,{initial:{opacity:0,y:a==="top"?-20:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:a==="top"?-20:20,scale:.95},transition:{type:"spring",...designTokens.springs.default},style:designTokens.mergeStyles(ei,ti[n],u),className:d,children:[jsxRuntime.jsx("span",{style:ri,children:t}),i&&jsxRuntime.jsx("button",{style:oi,onClick:()=>{i.onClick(),r();},children:i.label})]})})})}var li={position:"absolute",pointerEvents:"none",zIndex:designTokens.zIndices.overlay},ui={filter:"drop-shadow(0 4px 8px rgba(255, 45, 85, 0.5))"};function xt(){let[t,e]=react.useState(false),[r,o]=react.useState({x:0,y:0}),n=react.useCallback((a,u)=>{let d=a??(typeof window<"u"?window.innerWidth/2:200),f=u??(typeof window<"u"?window.innerHeight/2:400);o({x:d,y:f}),e(true),setTimeout(()=>{e(false);},800);},[]),i=react.useCallback(()=>{e(false);},[]);return {isShowing:t,position:r,showHeart:n,hideHeart:i}}var di=({size:t,color:e})=>jsxRuntime.jsx("svg",{style:ui,xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 28 28",fill:e,children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:e})});function kt({show:t,position:e={x:0,y:0},size:r=100,color:o=designTokens.colors.like,showParticles:n=true,particleCount:i=8,onComplete:a,style:u,className:d=""}){return jsxRuntime.jsx(react$1.AnimatePresence,{onExitComplete:a,children:t&&jsxRuntime.jsxs(react$1.motion.div,{initial:{opacity:0,scale:0},animate:{opacity:[0,1,1,0],scale:[0,1.3,1,.8],y:[0,-20,-20,-40]},exit:{scale:0,opacity:0},transition:{duration:.8,times:[0,.2,.6,1],ease:"easeOut"},style:{...li,left:e.x-r/2,top:e.y-r/2,width:r,height:r,...u},className:d,children:[jsxRuntime.jsx(di,{size:r,color:o}),n&&[...Array(i)].map((f,s)=>jsxRuntime.jsx(react$1.motion.div,{style:{position:"absolute",width:12,height:12,borderRadius:"50%",backgroundColor:o,left:r/2-6,top:r/2-6},initial:{opacity:1,scale:1},animate:{opacity:0,scale:.5,x:Math.cos(s*Math.PI*2/i)*60,y:Math.sin(s*Math.PI*2/i)*60},transition:{duration:.5,delay:.1,ease:"easeOut"}},s))]})})}function jr(t){let[e,r]=react.useState(false),o=typeof document<"u"&&!!(document.fullscreenEnabled||document.webkitFullscreenElement!==void 0||document.mozFullScreenElement!==void 0||document.msFullscreenElement!==void 0),n=()=>{let s=document;return s.fullscreenElement||s.webkitFullscreenElement||s.mozFullScreenElement||s.msFullscreenElement||null},i=async s=>{let l=s;l.requestFullscreen?await l.requestFullscreen():l.webkitRequestFullscreen?await l.webkitRequestFullscreen():l.mozRequestFullScreen?await l.mozRequestFullScreen():l.msRequestFullscreen&&await l.msRequestFullscreen();},a=async()=>{let s=document;s.exitFullscreen?await s.exitFullscreen():s.webkitExitFullscreen?await s.webkitExitFullscreen():s.mozCancelFullScreen?await s.mozCancelFullScreen():s.msExitFullscreen&&await s.msExitFullscreen();};react.useEffect(()=>{let s=()=>{let l=n();r(l===t.current);};return document.addEventListener("fullscreenchange",s),document.addEventListener("webkitfullscreenchange",s),document.addEventListener("mozfullscreenchange",s),document.addEventListener("MSFullscreenChange",s),()=>{document.removeEventListener("fullscreenchange",s),document.removeEventListener("webkitfullscreenchange",s),document.removeEventListener("mozfullscreenchange",s),document.removeEventListener("MSFullscreenChange",s);}},[t]);let u=react.useCallback(async()=>{let s=t.current;if(!(!s||!o))try{await i(s),r(!0);let l=screen.orientation;if(l?.lock)try{await l.lock("landscape");}catch{}}catch(l){console.error("[useFullscreen] Failed to enter fullscreen:",l);}},[t,o]),d=react.useCallback(async()=>{if(o)try{await a(),r(!1);let s=screen.orientation;s?.unlock&&s.unlock();}catch(s){console.error("[useFullscreen] Failed to exit fullscreen:",s);}},[o]),f=react.useCallback(async()=>{e?await d():await u();},[e,u,d]);return {isFullscreen:e,isSupported:o,toggleFullscreen:f,enterFullscreen:u,exitFullscreen:d}}var yi={feed:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},watch:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},auto:{autoQualitySwitch:true,pauseOnOffline:true,resumeOnOnline:true,lowQualityOn:"2g"},manual:{autoQualitySwitch:false,pauseOnOffline:false,resumeOnOnline:false}},gi={aggressive:{autoPauseOnLowBattery:true,pauseThreshold:.2},moderate:{autoPauseOnLowBattery:true,pauseThreshold:.15},conservative:{autoPauseOnLowBattery:true,pauseThreshold:.1},manual:{autoPauseOnLowBattery:false}};function rt(t,e,r={}){let o=react.useRef(null),n=react.useRef(null),i=e??n,[a,u]=react.useState(false),d=Gt(),f=ft(t),s=yt(t),l=gt(o.current),c=jr(i),y=react.useRef(r);y.current=r;let{networkBehavior:h,powerBehavior:m}=r,P=react.useMemo(()=>{if(h)return typeof h=="string"?yi[h]:h},[h]),S=react.useMemo(()=>{if(m)return typeof m=="string"?gi[m]:m},[m]),L=react.useMemo(()=>({onStateChange:g=>{d.transition(g),y.current.onStateChange?.(g),g==="ready"&&!a&&(u(true),y.current.onReady?.());},onError:(g,B)=>{y.current.onError?.(g,B);},onTimeUpdate:(g,B)=>{y.current.onTimeUpdate?.(g,B);},onQualityLevelsLoaded:g=>{y.current.onQualityLevelsLoaded?.(g);},onNetworkChange:g=>{P?.onNetworkChange?.(g),y.current.onNetworkChange?.(g);},onPowerChange:g=>{S?.onPowerChange?.(g),y.current.onPowerChange?.(g);},onAnalyticsUpdate:g=>{y.current.onAnalyticsUpdate?.(g);}}),[d,a,P,S]);react.useEffect(()=>{let g=t.current;if(!g)return;let B=()=>y.current.onPlay?.(),Q=()=>y.current.onPause?.(),j=()=>y.current.onEnded?.();return g.addEventListener("play",B),g.addEventListener("pause",Q),g.addEventListener("ended",j),()=>{g.removeEventListener("play",B),g.removeEventListener("pause",Q),g.removeEventListener("ended",j);}},[t]);let H=react.useCallback((g,B)=>{let Q=t.current;if(!Q){console.error("[usePlayer] No video element");return}u(false),o.current&&o.current.destroy(),o.current=new je({preferNative:y.current.preferNative,enableSmoothTimeUpdates:y.current.enableSmoothTimeUpdates,enableNetworkAdaptation:y.current.enableNetworkAdaptation,enablePowerAdaptation:y.current.enablePowerAdaptation,enableAnalytics:y.current.enableAnalytics,preloadConfig:y.current.preloadConfig,callbacks:L,autoQualityOnNetworkChange:P?.autoQualitySwitch,autoPauseOnOffline:P?.pauseOnOffline,autoResumeOnOnline:P?.resumeOnOnline,lowQualityThreshold:P?.lowQualityOn,autoPauseOnLowBattery:S?.autoPauseOnLowBattery,lowBatteryThreshold:S?.pauseThreshold}),o.current.attach(Q,g,B);},[t,L,P,S]),p=react.useCallback(()=>{o.current&&(o.current.destroy(),o.current=null),d.reset(),u(false);},[d]),b=react.useCallback(async()=>{await o.current?.play();},[]),v=react.useCallback(()=>{o.current?.pause();},[]),M=react.useCallback(async()=>{await o.current?.togglePlay();},[]),V=react.useCallback(g=>{o.current?.seek(g);},[]),D=react.useCallback((g=10)=>{o.current?.seekForward(g);},[]),A=react.useCallback((g=10)=>{o.current?.seekBackward(g);},[]),_=react.useCallback(g=>{o.current?.setPlaybackRate(g);},[]),U=react.useCallback(()=>{let g=t.current;g&&(g.currentTime=0,g.play().catch(()=>{}));},[t]);return {playerCore:o.current,videoRef:t,containerRef:i,state:d,isReady:a,play:b,pause:v,togglePlay:M,seek:V,seekForward:D,seekBackward:A,setPlaybackSpeed:_,restart:U,volume:f,progress:s,quality:l,fullscreen:c,attach:H,destroy:p}}var Si={position:"relative",width:"100%",height:"100%",backgroundColor:designTokens.colors.background},Pi={width:"100%",height:"100%",objectFit:"contain"},tr=react.forwardRef(({video:t,autoPlay:e=true,muted:r=true,loop:o=true,poster:n,children:i,style:a,className:u="",onPlay:d,onPause:f,onEnded:s,onError:l,onStateChange:c,onTimeUpdate:y,onQualityLevelsLoaded:h,onReady:m},P)=>{let S=react.useRef(null),L=react.useRef(null),H=typeof t=="string"?t:t.url,p=n??(typeof t=="object"?t.thumbnail:void 0),b=rt(S,L,{onStateChange:c,onError:v=>l?.(v),onTimeUpdate:y,onQualityLevelsLoaded:h,onPlay:d,onPause:f,onEnded:s,onReady:m});return react.useEffect(()=>(H&&b.attach(H),()=>{b.destroy();}),[H]),react.useEffect(()=>{let v=S.current;v&&(v.muted=r,v.loop=o);},[r,o]),react.useEffect(()=>{let v=S.current;!v||!b.isReady||!e||v.play().catch(M=>{M.name==="NotAllowedError"&&(v.muted=true,v.play().catch(()=>{}));});},[e,b.isReady]),react.useImperativeHandle(P,()=>({play:b.play,pause:b.pause,togglePlay:b.togglePlay,seek:b.seek,seekForward:b.seekForward,seekBackward:b.seekBackward,restart:b.restart,setVolume:b.volume.setVolume,toggleMute:b.volume.toggleMute,setPlaybackSpeed:b.setPlaybackSpeed,setQuality:b.quality.setQuality,getQualityLevels:()=>b.quality.availableLevels,getVideoElement:()=>S.current,getCurrentTime:()=>b.progress.currentTime,getDuration:()=>b.progress.duration,isPaused:()=>S.current?.paused??true}),[b]),jsxRuntime.jsxs("div",{ref:L,style:J(Si,a),className:u,children:[jsxRuntime.jsx("video",{ref:S,poster:p,playsInline:true,preload:"auto",style:Pi}),i]})});tr.displayName="VideoPlayer";var Ti=30,Li=1e3/Ti,eo=150,$={container:{position:"absolute",bottom:0,left:0,right:0,zIndex:designTokens.zIndices.sticky,touchAction:"none",userSelect:"none",WebkitUserSelect:"none",transition:"all 0.125s ease-in-out"},collapsed:{height:Xe.HEIGHT_DEFAULT,paddingInline:designTokens.spacing[3],cursor:"pointer"},expanded:{padding:`${designTokens.spacing[2]}px ${designTokens.spacing[3]}px`,paddingBottom:`calc(${designTokens.spacing[1]}px + env(safe-area-inset-bottom, 0px))`,background:"linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%)"},timeContainer:{display:"flex",justifyContent:"center",alignItems:"center",marginBottom:designTokens.spacing[2]},timeText:{fontSize:designTokens.fontSizes.sm,fontWeight:designTokens.fontWeights.semibold,color:designTokens.colors.text,textShadow:designTokens.shadows.text,fontVariantNumeric:"tabular-nums",backgroundColor:"rgba(0, 0, 0, 0.6)",padding:`${designTokens.spacing[1]}px ${designTokens.spacing[3]}px`,borderRadius:designTokens.radii.md},trackWrapper:{position:"relative",width:"100%"},track:{position:"relative",width:"100%",backgroundColor:"rgba(255, 255, 255, 0.2)",borderRadius:designTokens.radii.full,overflow:"hidden"},trackCollapsed:{height:Xe.HEIGHT_DEFAULT},trackExpanded:{height:Xe.HEIGHT_ACTIVE},buffer:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:designTokens.radii.full},progress:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:designTokens.colors.text,borderRadius:designTokens.radii.full},scrubber:{position:"absolute",top:"50%",width:16,height:16,marginLeft:-8,marginTop:-8,backgroundColor:designTokens.colors.text,borderRadius:designTokens.radii.full,boxShadow:"0 2px 4px rgba(0,0,0,0.3)",transform:"scale(0)",transition:"transform 150ms ease"},scrubberVisible:{transform:"scale(1)"},touchArea:{position:"absolute",top:-12,left:0,right:0,bottom:-12,cursor:"pointer"},previewContainer:{position:"absolute",bottom:"100%",marginBottom:designTokens.spacing[3],transform:"translateX(-50%)",display:"flex",flexDirection:"column",alignItems:"center",gap:designTokens.spacing[1],pointerEvents:"none",zIndex:designTokens.zIndices.popover,opacity:0,transition:`opacity ${eo}ms ease, transform ${eo}ms ease`},previewThumbnail:{borderRadius:designTokens.radii.lg,overflow:"hidden",backgroundColor:"rgba(0, 0, 0, 0.8)",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.4)",border:"2px solid rgba(255, 255, 255, 0.2)"},previewImage:{width:"100%",height:"100%",objectFit:"cover"},previewTime:{fontSize:designTokens.fontSizes.xs,fontWeight:designTokens.fontWeights.semibold,color:designTokens.colors.text,textShadow:designTokens.shadows.text,fontVariantNumeric:"tabular-nums",backgroundColor:"rgba(0, 0, 0, 0.8)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",padding:`${designTokens.spacing[1]}px ${designTokens.spacing[2]}px`,borderRadius:designTokens.radii.full,whiteSpace:"nowrap"},previewLine:{position:"absolute",bottom:0,width:2,height:designTokens.spacing[2],backgroundColor:designTokens.colors.text,borderRadius:designTokens.radii.full,transform:"translateX(-50%)"}};function ue(t){if(!isFinite(t)||isNaN(t))return "0:00";let e=Math.floor(t/60),r=Math.floor(t%60);return `${e}:${r.toString().padStart(2,"0")}`}function Ri(t){if(t.buffered.length===0)return 0;for(let e=0;e<t.buffered.length;e++)if(t.buffered.start(e)<=t.currentTime&&t.buffered.end(e)>=t.currentTime)return t.buffered.end(e);return t.buffered.end(t.buffered.length-1)}function Ii(t){return Math.max(10,Math.min(90,t))}var Lt=react.forwardRef(({videoRef:t,expanded:e=false,onSeekStart:r,onSeek:o,onSeekEnd:n,onExpandedChange:i,showPreview:a=false,getThumbnailUrl:u,previewWidth:d=120,previewHeight:f=68,style:s,className:l=""},c)=>{let y=react.useRef(null),h=react.useRef(null),m=react.useRef(null),P=react.useRef(null),S=react.useRef(null),L=react.useRef(0),H=react.useRef(null),p=react.useRef(null),b=react.useRef(null),[v,M]=react.useState({currentTime:0,duration:0}),V=react.useRef(null),D=react.useRef(0),A=react.useRef(0),_=react.useRef(false),U=react.useRef(e);react.useEffect(()=>{U.current=e;},[e]);let g=react.useCallback(k=>{let C=t.current;if(!C||_.current)return;let x=C.duration||0,T=C.currentTime||0,w=Ri(C),F=x>0?T/x*100:0,O=x>0?w/x*100:0;h.current&&(h.current.style.width=`${F}%`),m.current&&(m.current.style.width=`${O}%`),P.current&&U.current&&(P.current.style.left=`${F}%`),L.current=x,S.current&&(S.current.textContent=`${ue(T)} / ${ue(x)}`);let R=k??performance.now();R-A.current>=500&&(A.current=R,M(X=>Math.abs(X.currentTime-T)>=.5||X.duration!==x?{currentTime:Math.floor(T),duration:Math.floor(x)}:X));},[t]),B=react.useCallback(k=>{k-D.current>=Li&&(D.current=k,g()),V.current=requestAnimationFrame(B);},[g]);react.useEffect(()=>(V.current=requestAnimationFrame(B),()=>{V.current&&cancelAnimationFrame(V.current);}),[B]);let Q=react.useCallback(k=>{let C=y.current,x=t.current;if(!C||!x)return {time:0,percent:0};let T=C.getBoundingClientRect(),w=k-T.left,F=Math.max(0,Math.min(1,w/T.width));return {time:F*(x.duration||0),percent:F*100}},[t]),j=react.useCallback((k,C,x)=>{if(!a)return;let T=H.current,w=p.current,F=b.current;if(T)if(x){let O=Ii(C);T.style.left=`${O}%`,T.style.opacity="1",T.style.transform="translateX(-50%) translateY(0)";let R=L.current;if(F&&(F.textContent=`${ue(k)} / ${ue(R)}`),w&&u){let X=u(k);X?(w.src=X,w.style.display="block"):w.style.display="none";}}else T.style.opacity="0",T.style.transform="translateX(-50%) translateY(8px)";},[a,u]),Y=react.useCallback(k=>{_.current=true,r?.();let{time:C,percent:x}=Q(k);o?.(C);let T=t.current;if(T&&h.current){let w=T.duration||L.current||1;h.current.style.width=`${x}%`,P.current&&(P.current.style.left=`${x}%`),S.current&&(S.current.textContent=`${ue(C)} / ${ue(w)}`);}j(C,x,true);},[Q,o,r,t,j]),z=react.useCallback(k=>{if(!_.current)return;let{time:C,percent:x}=Q(k);o?.(C);let T=t.current;if(T&&h.current){let w=T.duration||L.current||1;h.current.style.width=`${x}%`,P.current&&(P.current.style.left=`${x}%`),S.current&&(S.current.textContent=`${ue(C)} / ${ue(w)}`);}j(C,x,true);},[Q,o,t,j]),K=react.useCallback(k=>{if(!_.current)return;_.current=false;let{time:C}=Q(k);n?.(C);let x=t.current;x&&(x.currentTime=C),setTimeout(()=>{j(0,0,false);},100);},[Q,n,t,j]),se=react.useCallback(k=>{let C=k.touches[0];C&&Y(C.clientX);},[Y]),re=react.useCallback(k=>{let C=k.touches[0];C&&z(C.clientX);},[z]),Ae=react.useCallback(k=>{let C=k.changedTouches[0];C&&K(C.clientX);},[K]),ce=react.useCallback(k=>{Y(k.clientX);let C=T=>z(T.clientX),x=T=>{K(T.clientX),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",x);};document.addEventListener("mousemove",C),document.addEventListener("mouseup",x);},[Y,z,K]),pe=react.useCallback(()=>{e||i?.(true);},[e,i]),$e=react.useCallback(k=>{let C=t.current;if(!C)return;let x=C.duration||0,T=C.currentTime||0,w=T;switch(k.key){case "ArrowLeft":w=Math.max(0,T-5);break;case "ArrowRight":w=Math.min(x,T+5);break;case "ArrowUp":w=Math.min(x,T+10);break;case "ArrowDown":w=Math.max(0,T-10);break;case "Home":w=0;break;case "End":w=x;break;default:return}k.preventDefault(),C.currentTime=w,o?.(w),g();},[t,o,g]);react.useImperativeHandle(c,()=>({update:g,setExpanded:k=>{i?.(k);}}));let qe={...$.container,...e?$.expanded:$.collapsed,...s},E={...$.track,...e?$.trackExpanded:$.trackCollapsed},W={...$.scrubber,...e?$.scrubberVisible:{}},ne={...$.previewThumbnail,width:d,height:f};return jsxRuntime.jsxs("div",{ref:y,style:qe,className:l,onClick:e?void 0:pe,onTouchStart:se,onTouchMove:re,onTouchEnd:Ae,onTouchCancel:Ae,onMouseDown:ce,onKeyDown:$e,role:"slider","aria-label":"Video progress","aria-valuemin":0,"aria-valuemax":v.duration,"aria-valuenow":v.currentTime,"aria-valuetext":`${ue(v.currentTime)} of ${ue(v.duration)}`,tabIndex:0,children:[e&&jsxRuntime.jsx("div",{style:$.timeContainer,children:jsxRuntime.jsx("span",{ref:S,style:$.timeText,children:"0:00 / 0:00"})}),jsxRuntime.jsxs("div",{style:$.trackWrapper,children:[a&&jsxRuntime.jsxs("div",{ref:H,style:$.previewContainer,"aria-hidden":"true",children:[u&&jsxRuntime.jsx("div",{style:ne,children:jsxRuntime.jsx("img",{ref:p,style:$.previewImage,alt:"Seek preview"})}),jsxRuntime.jsx("span",{ref:b,style:$.previewTime,children:"0:00 / 0:00"}),jsxRuntime.jsx("div",{style:$.previewLine})]}),jsxRuntime.jsxs("div",{style:E,"aria-hidden":"true",children:[jsxRuntime.jsx("div",{style:$.touchArea}),jsxRuntime.jsx("div",{ref:m,style:$.buffer}),jsxRuntime.jsx("div",{ref:h,style:$.progress}),e&&jsxRuntime.jsx("div",{ref:P,style:W})]})]})]})});Lt.displayName="Timeline";var Mi={DOUBLE_TAP_DELAY:200},Vi={THRESHOLD:500},ot={VERTICAL_THRESHOLD:.3,HORIZONTAL_THRESHOLD:.4,MIN_VELOCITY:.5},Rt={THRESHOLD:10};var Pe={TAP_DELAY:Mi.DOUBLE_TAP_DELAY,LONG_PRESS_THRESHOLD:Vi.THRESHOLD,SWIPE_VERTICAL_THRESHOLD:ot.VERTICAL_THRESHOLD,SWIPE_HORIZONTAL_THRESHOLD:ot.HORIZONTAL_THRESHOLD,DRAG_THRESHOLD:Rt.THRESHOLD};function to(){return typeof navigator<"u"&&"vibrate"in navigator}function It(){to()&&navigator.vibrate(10);}function ro(){to()&&navigator.vibrate(20);}function oo(t,e){let r=t.currentTarget||t.target;if(!r||typeof r.getBoundingClientRect!="function")return "center";let o=r.getBoundingClientRect(),n=t.clientX-o.left,i=o.width;if(i===0)return "center";let a=i*.33,u=i*.67;return n<a?"left":n>u?"right":"center"}function Mt(t){let e=react.useRef(0),r=react.useRef("center"),o=react.useRef(null),n=react.useRef(null),i=react.useRef(false),a=react.useRef(false),u=react.useRef({x:0,y:0}),d=react.useCallback(s=>{if(a.current){a.current=false;return}let l=oo(s),c=Date.now(),y=c-e.current,h={x:s.clientX,y:s.clientY};y<Pe.TAP_DELAY&&r.current===l?(o.current&&(clearTimeout(o.current),o.current=null),It(),t.onDoubleTap?.(l,h)):o.current=setTimeout(()=>{t.onSingleTap?.(l),o.current=null;},Pe.TAP_DELAY),e.current=c,r.current=l;},[t]);return react$2.useGesture({onPointerDown:({event:s})=>{let l=s;u.current={x:l.clientX,y:l.clientY},a.current=false;let c=setTimeout(()=>{i.current=true,t.onHoldStart?.();},150);n.current=setTimeout(()=>{a.current=true,ro();let h=l.target.getBoundingClientRect();t.onLongPress?.({x:l.clientX-h.left,y:l.clientY-h.top});},Pe.LONG_PRESS_THRESHOLD),s.target.dataset.holdTimeout=String(c);},onPointerUp:({event:s})=>{let l=s.target.dataset.holdTimeout;l&&clearTimeout(Number(l)),n.current&&(clearTimeout(n.current),n.current=null),i.current&&(i.current=false,t.onHoldEnd?.());},onPointerMove:({event:s})=>{let l=s,c=Math.abs(l.clientX-u.current.x),y=Math.abs(l.clientY-u.current.y);(c>10||y>10)&&n.current&&(clearTimeout(n.current),n.current=null);},onClick:({event:s})=>{d(s);},onDrag:({movement:[s,l],direction:[c,y],velocity:[h,m],last:P,event:S})=>{if(S.preventDefault(),!P)return;let L=window.innerWidth,H=window.innerHeight;if(Math.abs(l)>H*Pe.SWIPE_VERTICAL_THRESHOLD){y>0?t.onSwipeDown?.():t.onSwipeUp?.();return}if(Math.abs(s)>L*Pe.SWIPE_HORIZONTAL_THRESHOLD){c>0?t.onSwipeRight?.():t.onSwipeLeft?.();return}Math.abs(s)>Pe.DRAG_THRESHOLD&&Math.abs(h)>Math.abs(m)&&t.onSeekDrag?.(s);}},{drag:{threshold:Pe.DRAG_THRESHOLD,filterTaps:true},eventOptions:{passive:false}})}var Ni=800,Bi=.05,Ui=.95;function rr({onSwipeUp:t,onSwipeDown:e,onSwipeProgress:r,onSwipeCancel:o,threshold:n=ot.VERTICAL_THRESHOLD,velocityThreshold:i=ot.MIN_VELOCITY,hapticEnabled:a=true,disabled:u=false,enableProgressState:d=false}={}){let f=Math.max(Bi,Math.min(Ui,n)),[s,l]=react.useState({progress:0,direction:null,isSwiping:false}),c=react.useRef({onSwipeUp:t,onSwipeDown:e,onSwipeProgress:r,onSwipeCancel:o}),y=react.useRef(typeof window<"u"?window.innerHeight:Ni);return c.current={onSwipeUp:t,onSwipeDown:e,onSwipeProgress:r,onSwipeCancel:o},react.useEffect(()=>{let m=()=>{y.current=window.innerHeight;},P=()=>{setTimeout(()=>{y.current=window.innerHeight;},100);};return window.addEventListener("resize",m,{passive:true}),window.addEventListener("orientationchange",P,{passive:true}),()=>{window.removeEventListener("resize",m),window.removeEventListener("orientationchange",P);}},[]),{bind:react$2.useDrag(({movement:[,m],velocity:[,P],active:S,cancel:L})=>{if(u){L?.();return}let p=y.current*f,b=Math.min(1,Math.abs(m)/p),v=m<0?"up":"down";if(S)c.current.onSwipeProgress?.(b,v,m),d&&l({progress:b,direction:v,isSwiping:true});else {let M=Math.abs(m)>=p,V=Math.abs(P)>=i;M||V?(a&&It(),v==="up"?c.current.onSwipeUp?.():c.current.onSwipeDown?.()):c.current.onSwipeCancel?.(),l({progress:0,direction:null,isSwiping:false});}},{axis:"y",threshold:Rt.THRESHOLD,filterTaps:true,pointer:{touch:true},eventOptions:{passive:true}}),...s}}var we={container:{position:"relative",width:"100%",height:"100%",backgroundColor:designTokens.colors.background},video:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"contain"},placeholder:{position:"absolute",inset:0,backgroundSize:"contain",backgroundPosition:"center",backgroundRepeat:"no-repeat"},tapArea:{zIndex:designTokens.zIndices.base},pauseOverlay:{zIndex:designTokens.zIndices.overlay},pauseIconWrapper:{borderRadius:designTokens.radii.full,transition:`opacity ${designTokens.durations.normal}ms ${designTokens.easings.xhubReel}, transform ${designTokens.durations.normal}ms ${designTokens.easings.xhubReel}`}};var or=react.createContext(null);function ye(){let t=react.useContext(or);if(!t)throw new Error("VideoFeedItem compound components must be used within a VideoFeedItem");return t}function io({elementRef:t,activateThreshold:e=lt.ACTIVATION_THRESHOLD,deactivateThreshold:r=lt.DEACTIVATION_THRESHOLD,rootMargin:o="0px",onVisibilityChange:n}){let[i,a]=react.useState(false),[u,d]=react.useState(false),[f,s]=react.useState(0),l=react.useRef(null);return react.useEffect(()=>{let c=t.current;if(!c)return;l.current&&l.current.disconnect();let y=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1];return l.current=new IntersectionObserver(h=>{h.forEach(m=>{let P=m.intersectionRatio;s(P),a(P>0),P>=e?d(true):P<r&&d(false),n?.(P>0,P);});},{threshold:y,rootMargin:o}),l.current.observe(c),()=>{l.current?.disconnect();}},[t,e,r,o,n]),{isVisible:i,isActive:u,visibilityRatio:f}}function ao({containerRef:t,videoRef:e,isCurrentVideo:r=false,onActivate:o,onDeactivate:n,autoActivate:i=true,trackVisibility:a=false,onVisibilityChange:u}){let d=react.useRef(false),{isVisible:f,isActive:s,visibilityRatio:l}=io({elementRef:t??{current:null},onVisibilityChange:a?u:void 0}),c=a?s:r;react.useEffect(()=>{i&&(c&&!d.current?(d.current=true,o?.()):!c&&d.current&&(d.current=false,n?.()));},[c,o,n,i]);let y=react.useCallback(()=>{let m=e.current;m&&m.play().catch(()=>{m.muted=true,m.play().catch(()=>{});}),o?.();},[e,o]),h=react.useCallback(()=>{let m=e.current;m&&(m.pause(),m.currentTime=0),n?.();},[e,n]);return {isActive:c,isVisible:a?f:r,visibilityRatio:a?l:r?1:0,activate:y,deactivate:h}}var ir=class{entries=new Map;listeners=new Set;memoryWarningThreshold;constructor(){this.memoryWarningThreshold=De.MAX_TOTAL_MEMORY/(1024*1024),this.setupMemoryPressureListener();}register(e,r=10){this.entries.set(e,{videoId:e,inDom:false,hasDecodedFrames:false,estimatedSizeMB:r,lastAccessed:Date.now()}),this.notifyListeners();}unregister(e){this.entries.delete(e),this.notifyListeners();}setInDom(e,r){let o=this.entries.get(e);o&&(o.inDom=r,o.lastAccessed=Date.now(),this.notifyListeners());}setHasDecodedFrames(e,r){let o=this.entries.get(e);o&&(o.hasDecodedFrames=r,o.lastAccessed=Date.now(),this.notifyListeners());}getState(){let e=0,r=0,o=0;return this.entries.forEach(n=>{n.inDom&&e++,n.hasDecodedFrames&&r++,o+=n.estimatedSizeMB;}),{videosInDom:e,decodedVideos:r,estimatedMemoryMB:o,isLowMemory:o>this.memoryWarningThreshold}}getVideosToDispose(){let e=this.getState(),r=[],o=De?.MAX_VIDEOS_IN_DOM,n=De?.MAX_DECODED_FRAMES,i=Array.from(this.entries.values()).sort((a,u)=>a.lastAccessed-u.lastAccessed);if(e.videosInDom>o){let a=e.videosInDom-o,u=0;for(let d of i){if(u>=a)break;d.inDom&&(r.push(d.videoId),u++);}}if(e.decodedVideos>n){let a=e.decodedVideos-n,u=0;for(let d of i){if(u>=a)break;d.hasDecodedFrames&&!r.includes(d.videoId)&&(r.push(d.videoId),u++);}}return r}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}forceCleanup(){let e=this.getVideosToDispose();return e.forEach(r=>this.unregister(r)),e}notifyListeners(){let e=this.getState();this.listeners.forEach(r=>r(e));}setupMemoryPressureListener(){typeof window>"u"||"memory"in performance&&setInterval(()=>{this.getState().isLowMemory&&(console.warn("[MemoryManager] Low memory warning, forcing cleanup"),this.forceCleanup());},5e3);}},Ee=new ir;function po({videoId:t,estimatedSizeMB:e=10,onShouldDispose:r}){let[o,n]=react.useState(()=>Ee.getState()),[i,a]=react.useState(false);react.useEffect(()=>(Ee.register(t,e),()=>{Ee.unregister(t);}),[t,e]),react.useEffect(()=>Ee.subscribe(s=>{n(s);let c=Ee.getVideosToDispose().includes(t);c&&!i?(a(true),r?.()):!c&&i&&a(false);}),[t,i,r]);let u=react.useCallback(f=>{Ee.setInDom(t,f);},[t]),d=react.useCallback(f=>{Ee.setHasDecodedFrames(t,f);},[t]);return {memoryState:o,setInDom:u,setHasDecodedFrames:d,shouldDispose:i}}function fo({video:t,isActive:e,priority:r,initialMuted:o=true,onLike:n,onComment:i,onShare:a,onAuthorClick:u}){let d=react.useRef(null),f=react.useRef(null),s=react.useRef(false),[l,c]=react.useState(false),[y,h]=react.useState(false),[m,P]=react.useState(false),{isShowing:S,position:L,showHeart:H}=xt(),p=react.useMemo(()=>({maxConcurrent:2,maxBufferSize:10*1024*1024,priorityLevels:10}),[]),b=react.useCallback(E=>{},[]),v=react.useCallback(E=>{},[]),M=react.useCallback(E=>{E.startupTime&&E.startupTime>1e3&&console.warn("[VideoFeedItem] Slow startup:",E.startupTime,"ms",t.id);},[t.id]),{state:V}=rt(f,d,{preferNative:true,enableSmoothTimeUpdates:true,networkBehavior:"feed",powerBehavior:"moderate",preloadConfig:p,enableAnalytics:true,onPlay:()=>{c(false),h(false);},onPause:()=>{f.current?.seeking||(c(true),h(true));},onNetworkChange:b,onPowerChange:v,onAnalyticsUpdate:M}),D=react.useCallback(async()=>{let E=f.current;if(E){E.muted=o;try{await E.play();}catch(W){if(W.name==="NotAllowedError"&&!o){console.warn("[VideoFeedItem] Autoplay blocked, falling back to muted"),E.muted=true;try{await E.play();}catch(ne){console.warn("[VideoFeedItem] Play failed even muted:",ne.message);}}else console.warn("[VideoFeedItem] Play failed:",W.message);}}},[o]),A=react.useCallback(()=>{let E=f.current;E&&E.pause();},[]),_=react.useCallback(E=>{let W=f.current;W&&(W.currentTime=E);},[]),[U,g]=react.useState(false);react.useEffect(()=>{let E=f.current;if(!E)return;let W=()=>g(true),ne=()=>g(false),k=()=>g(false);return E.addEventListener("play",W),E.addEventListener("pause",ne),E.addEventListener("ended",k),g(!E.paused),()=>{E.removeEventListener("play",W),E.removeEventListener("pause",ne),E.removeEventListener("ended",k);}},[t.id]);let B=U||V.state==="playing",{setInDom:Q,setHasDecodedFrames:j,shouldDispose:Y}=po({videoId:t.id,onShouldDispose:()=>{A(),f.current&&(f.current.src="",f.current.load());}}),z=!Y&&r!=="none",K=react.useRef(false);ao({videoRef:f,isCurrentVideo:e,onActivate:()=>{console.log("[VideoFeedItem] onActivate called, videoRef:",f.current?.src),j(true),f.current?D():(console.log("[VideoFeedItem] Video element not ready, marking pending play"),K.current=true);},onDeactivate:()=>{console.log("[VideoFeedItem] onDeactivate called"),K.current=false,j(false),A(),_(0);},autoActivate:true}),react.useEffect(()=>{f.current&&K.current&&e&&(console.log("[VideoFeedItem] Video element now available, executing pending play"),K.current=false,D());}),react.useEffect(()=>(Q(true),()=>Q(false)),[Q]),react.useEffect(()=>{let E=f.current;if(!E)return;P(false);let W=()=>{console.log("[VideoFeedItem] Video loadeddata:",t.id,{isActive:e,priority:r}),r==="high"&&!e?requestAnimationFrame(()=>{E.readyState>=2&&(E.currentTime=.01,P(true),console.log("[VideoFeedItem] First frame decoded (preloaded):",t.id));}):e&&P(true);},ne=()=>{r==="high"&&!m&&P(true);};return E.addEventListener("loadeddata",W),E.addEventListener("canplay",ne),E.readyState>=2&&W(),()=>{E.removeEventListener("loadeddata",W),E.removeEventListener("canplay",ne);}},[t.id,e,r,m]),react.useEffect(()=>{console.log("[VideoFeedItem] State:",{videoId:t.id,isActive:e,priority:r,shouldRenderVideo:z,hasVideoElement:!!f.current,videoSrc:f.current?.src});},[t.id,e,r,z]);let se=react.useMemo(()=>{switch(r){case "high":return "auto";case "medium":return "metadata";case "low":case "metadata":return "none";default:return "none"}},[r]),re=react.useCallback(()=>{s.current=B,h(true),c(false),A();},[B,A]),Ae=react.useCallback(E=>{_(E),s.current?(D(),h(false)):c(true);},[_,D]),ce=react.useCallback(()=>{B?A():D();},[B,D,A]),pe=react.useCallback((E,W)=>{H(W.x,W.y),n?.();},[H,n]),$e=react.useCallback(()=>{},[]),qe=Mt({onSingleTap:ce,onDoubleTap:pe,onLongPress:$e});return {video:t,isActive:e,priority:r,shouldRenderVideo:z,preload:se,isPreloaded:m,initialMuted:o,containerRef:d,videoRef:f,isPlaying:B,showPauseOverlay:l,timelineExpanded:y,play:D,pause:A,seek:_,setShowPauseOverlay:c,setTimelineExpanded:h,gestureBindings:qe,showHeart:S,heartPosition:L,triggerHeart:H,onLike:n,onComment:i,onShare:a,onAuthorClick:u,handleSeekStart:re,handleSeekEnd:Ae}}var yo=react.createContext(null);function go(){return react.useContext(yo)?.pool??null}function vo(){return react.useContext(yo)?.isReady??false}var Ht=react.forwardRef(({placeholder:t,forceNative:e=false,...r},o)=>{let{video:n,videoRef:i,shouldRenderVideo:a,preload:u,isPreloaded:d,initialMuted:f,isActive:s,priority:l}=ye(),c=go(),y=vo(),h=react.useRef(null),m=react.useRef(null),[P,S]=react.useState(false),L=react.useRef(false),H=c&&y&&!e,p=react.useCallback((v,M)=>{if(!h.current)return false;m.current&&m.current.parentNode&&m.current.parentNode.removeChild(m.current),Object.assign(v.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"contain",zIndex:"1",opacity:M?"1":"0",transition:"opacity 0.15s ease-out"});let V=()=>{v.style.opacity="1",S(false);};return v.readyState>=3?V():v.addEventListener("canplay",V,{once:true}),h.current.appendChild(v),m.current=v,typeof o=="function"?o(v):o&&(o.current=v),i.current=v,true},[o,i]);if(react.useEffect(()=>{if(!H||!c||!a){S(false),L.current=false;return}let v=n.id,M=n.url,V=c.getElement(v);if(V){let A=c.isReady(v);if(p(V,A)){A||(S(true),c.prepare(v,M,{priority:"high"}).catch(()=>{})),console.log("[VideoFeedItemPlayer] Attached existing element:",v,{isReady:A});return}}if(L.current)return;L.current=true,S(true);let D=s||l==="high"?"high":"medium";return c.prepare(v,M,{priority:D}).then(()=>{let A=c.getElement(v);A&&(p(A,true),console.log("[VideoFeedItemPlayer] Prepared and attached:",v));}).catch(A=>{console.warn("[VideoFeedItemPlayer] Prepare failed:",v,A),S(false);}),()=>{m.current&&m.current.parentNode===h.current&&h.current?.removeChild(m.current),m.current=null,L.current=false;}},[H,c,n.id,n.url,a,s,l,p]),react.useEffect(()=>{if(!H||!c)return;let v=n.id;s?c.activate(v):c.deactivate(v);},[H,c,n.id,s]),!a)return t??jsxRuntime.jsx("div",{...r,style:{...we.placeholder,backgroundImage:`url(${n.thumbnail})`,...r.style}});if(H)return jsxRuntime.jsxs("div",{ref:h,style:{...we.video,position:"relative"},...r,children:[jsxRuntime.jsx("style",{children:`
|
|
6
|
+
@keyframes xhub-reel-spin {
|
|
7
|
+
to { transform: rotate(360deg); }
|
|
8
|
+
}
|
|
9
|
+
`}),jsxRuntime.jsx("div",{style:{...we.placeholder,backgroundImage:`url(${n.thumbnail})`,position:"absolute",inset:0,zIndex:0}}),P&&jsxRuntime.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:2,pointerEvents:"none"},children:jsxRuntime.jsx("div",{style:{width:40,height:40,borderWidth:3,borderStyle:"solid",borderColor:"rgba(255, 255, 255, 0.2)",borderTopColor:"#8B5CF6",borderRadius:"50%",animation:"xhub-reel-spin 0.8s linear infinite"}})})]});let b=!d;return jsxRuntime.jsx("video",{ref:v=>{typeof o=="function"?o(v):o&&(o.current=v),i.current=v;},src:n.url,poster:b?n.thumbnail:void 0,preload:u,loop:true,playsInline:true,muted:f,style:we.video})});Ht.displayName="VideoFeedItemPlayer";var At=react.forwardRef(({onLike:t,onComment:e,onShare:r,...o},n)=>{let{video:i,onLike:a,onComment:u,onShare:d}=ye();return jsxRuntime.jsx("div",{ref:n,...o,children:jsxRuntime.jsx(St,{avatarUrl:i.author.avatar,likeCount:i.stats.likes,commentCount:i.stats.comments,shareCount:i.stats.shares,isLiked:i.isLiked,onLike:t??a,onComment:e??u,onShare:r??d})})});At.displayName="VideoFeedItemActions";var Ft=react.forwardRef(({expanded:t,showPreview:e=false,getThumbnailUrl:r,previewWidth:o,previewHeight:n,...i},a)=>{let{video:u,videoRef:d,shouldRenderVideo:f,timelineExpanded:s,setTimelineExpanded:l,handleSeekStart:c,handleSeekEnd:y}=ye(),h=react.useCallback(m=>u.thumbnail||void 0,[u.thumbnail]);return f?jsxRuntime.jsx("div",{ref:a,...i,children:jsxRuntime.jsx(Lt,{videoRef:d,expanded:t??s,onSeekStart:c,onSeekEnd:y,onExpandedChange:l,showPreview:e,getThumbnailUrl:r??(e?h:void 0),previewWidth:o,previewHeight:n})}):null});Ft.displayName="VideoFeedItemTimeline";var ze={container:{position:"absolute",bottom:0,left:0,right:64,padding:designTokens.spacing[4],paddingBottom:"env(safe-area-inset-bottom, 16px)",zIndex:designTokens.zIndices.base},containerWithTimeline:{paddingBottom:"calc(env(safe-area-inset-bottom, 16px) + 48px)"},authorButton:{gap:designTokens.spacing[2],marginBottom:designTokens.spacing[3]},avatar:{borderRadius:designTokens.radii.full,border:`2px solid ${designTokens.colors.text}`},username:{color:designTokens.colors.text,fontWeight:designTokens.fontWeights.semibold,fontSize:designTokens.fontSizes.sm,textShadow:designTokens.shadows.text},caption:{color:designTokens.colors.text,fontSize:designTokens.fontSizes.sm,lineHeight:1.4,textShadow:designTokens.shadows.text,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:designTokens.spacing[1]},author:{color:designTokens.colors.text,fontSize:designTokens.fontSizes.sm,fontWeight:designTokens.fontWeights.semibold,textShadow:designTokens.shadows.text,display:"-webkit-box",WebkitLineClamp:1,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:designTokens.spacing[1]},hashtags:{display:"flex",flexWrap:"wrap",gap:designTokens.spacing[1],marginTop:designTokens.spacing[2],paddingBottom:designTokens.spacing[1]},hashtag:{color:designTokens.colors.accent,fontSize:designTokens.fontSizes.sm,fontWeight:designTokens.fontWeights.medium,textShadow:designTokens.shadows.text}};function Eo({video:t,timelineExpanded:e=false,style:r,className:o=""}){let n=J(ze.container,e&&ze.containerWithTimeline,r);return jsxRuntime.jsxs("div",{style:n,className:o,children:[t.author&&jsxRuntime.jsx("p",{style:ze.author,children:t.author.displayName}),t.caption&&jsxRuntime.jsx("p",{style:ze.caption,children:t.caption}),t.hashtags&&t.hashtags.length>0&&jsxRuntime.jsx("div",{style:ze.hashtags,children:t.hashtags.slice(0,3).map((i,a)=>jsxRuntime.jsxs("span",{style:ze.hashtag,children:["#",i]},a))})]})}var Dt=react.forwardRef(({showPlayPause:t=true,showDoubleTapHeart:e=true,showVideoInfo:r=true,...o},n)=>{let{video:i,isPlaying:a,showPauseOverlay:u,timelineExpanded:d,showHeart:f,heartPosition:s,onAuthorClick:l}=ye();return jsxRuntime.jsxs("div",{ref:n,...o,children:[t&&jsxRuntime.jsx(wt,{isPlaying:a,show:u,size:64,autoHideDelay:800,showOnStateChange:false}),e&&jsxRuntime.jsx(kt,{show:f,position:s,size:100,showParticles:true,particleCount:8}),r&&jsxRuntime.jsx(Eo,{video:i,onAuthorClick:l,timelineExpanded:d})]})});Dt.displayName="VideoFeedItemOverlay";var Ge=react.forwardRef(({video:t,isActive:e=false,priority:r="none",initialMuted:o=true,showTimeline:n=true,onLike:i,onComment:a,onShare:u,onAuthorClick:d,style:f,className:s="",children:l},c)=>{let y=fo({video:t,isActive:e,priority:r,initialMuted:o,onLike:i,onComment:a,onShare:u,onAuthorClick:d}),h=l??jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Ht,{}),jsxRuntime.jsx(Dt,{}),jsxRuntime.jsx(At,{}),n&&jsxRuntime.jsx(Ft,{})]});return jsxRuntime.jsx(or.Provider,{value:y,children:jsxRuntime.jsx("div",{ref:m=>{typeof c=="function"?c(m):c&&(c.current=m),y.containerRef.current=m;},style:J(we.container,f),className:s,...y.gestureBindings(),children:h})})});Ge.displayName="VideoFeedItem";function Co(t,e){let r=t-e;return r===0||r===-1||r===1?"high":r===2?"medium":r===3?"low":Math.abs(r)<=5?"metadata":"none"}var ss="cubic-bezier(0.32, 0.72, 0, 1)",as=300,ls=800,us=50;function ko({trackRef:t,transitionDuration:e=as,easing:r=ss,onTransitionEnd:o}){let n=react.useRef(typeof window<"u"?window.innerHeight:ls),i=react.useRef(0),a=react.useRef(null),u=react.useRef(false),d=react.useRef(true);react.useEffect(()=>{let y=()=>{n.current=window.innerHeight;},h=()=>{setTimeout(()=>{n.current=window.innerHeight;},100);};return window.addEventListener("resize",y,{passive:true}),window.addEventListener("orientationchange",h,{passive:true}),()=>{window.removeEventListener("resize",y),window.removeEventListener("orientationchange",h);}},[]);let f=react.useCallback(y=>{i.current=y,a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{let h=t.current;h&&(h.style.transition="none",h.style.transform=`translateY(${y}px)`),a.current=null;});},[t]),s=react.useCallback(y=>new Promise(h=>{let m=t.current;if(!m||!d.current){h();return}if(u.current){h();return}u.current=true,i.current=y;let P=null,S=null,L=H=>{H.propertyName==="transform"&&(P?.(),d.current&&(u.current=false,o?.()),h());};P=()=>{m.removeEventListener("transitionend",L),S&&(clearTimeout(S),S=null);},m.addEventListener("transitionend",L),S=setTimeout(()=>{P?.(),d.current&&u.current&&(u.current=false,o?.()),h();},e+us),m.offsetHeight,m.style.transition=`transform ${e}ms ${r}`,m.style.transform=`translateY(${y}px)`;}),[t,e,r,o]),l=react.useCallback(()=>s(0),[s]),c=react.useCallback(()=>i.current,[]);return react.useEffect(()=>(d.current=true,()=>{d.current=false,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null);}),[]),{setTranslateY:f,animateTo:s,snapBack:l,getCurrentY:c,viewportHeight:n.current,isAnimating:u.current}}var ps=300,ms=50,fs=.3,hs="cubic-bezier(0.32, 0.72, 0, 1)",Ce={container:{position:"fixed",inset:0,overflow:"hidden",backgroundColor:designTokens.colors.background,touchAction:"none",userSelect:"none",WebkitUserSelect:"none"},track:{position:"relative",width:"100%",height:"100%",willChange:"transform"},slide:{position:"absolute",left:0,width:"100%",height:"100%",backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},loadingIndicator:{position:"absolute",bottom:80,left:0,right:0,display:"flex",justifyContent:"center",zIndex:designTokens.zIndices.base,pointerEvents:"none"},spinner:{width:24,height:24,borderWidth:2,borderStyle:"solid",borderColor:"rgba(255, 255, 255, 0.3)",borderTopColor:designTokens.colors.text,borderRadius:designTokens.radii.full,animation:"xhub-reel-spin 1s linear infinite"}},st=react.forwardRef(({videos:t,initialIndex:e=0,onLoadMore:r,onVideoChange:o,onLike:n,onComment:i,onShare:a,onAuthorClick:u,isLoading:d=false,hasMore:f=false,loadMoreThreshold:s=3,transitionDuration:l=ps,swipeThreshold:c=ms,velocityThreshold:y=fs,gesturesDisabled:h=false,hapticEnabled:m=true,initialMuted:P=true,style:S,className:L=""},H)=>{let[p,b]=react.useState(()=>Math.min(Math.max(0,e),Math.max(0,t.length-1))),[v,M]=react.useState(false),[V,D]=react.useState(false),A=react.useRef(null),_=react.useRef(null),U=react.useRef(t),g=react.useRef(p),B=react.useRef(d),Q=react.useRef(f),j=react.useRef(v),{setCurrentIndex:Y}=_t(),{setTranslateY:z,animateTo:K,snapBack:se,viewportHeight:re}=ko({trackRef:_,transitionDuration:l,easing:hs});react.useEffect(()=>{U.current=t;},[t]),react.useEffect(()=>{g.current=p;},[p]),react.useEffect(()=>{B.current=d;},[d]),react.useEffect(()=>{Q.current=f;},[f]),react.useEffect(()=>{j.current=v;},[v]),react.useEffect(()=>{if(t.length===0){b(0);return}if(p>=t.length){let w=t.length-1,F=t[w];b(w),Y(w),F&&o?.(F,w);}},[t.length,p,Y,o,t]);let Ae=react.useCallback(w=>Co(w,p),[p]),ce=react.useCallback(w=>{let F=U.current;Q.current&&!B.current&&F.length-w<=s&&r?.();},[s,r]),pe=react.useCallback(async(w,F=true)=>{if(j.current)return;let O=U.current,R=Math.max(0,Math.min(w,O.length-1)),X=g.current;if(R===X){z(0);return}let Fe=R>X?-1:1;if(F){M(true),D(true),await K(Fe*re),b(R),Y(R),z(0);let xe=O[R];xe&&o?.(xe,R),ce(R),D(false),M(false);}else {b(R),Y(R),z(0);let xe=O[R];xe&&(o?.(xe,R),ce(R));}},[re,K,z,Y,o,ce]),$e=react.useCallback((w=true)=>{let F=U.current,O=g.current;O<F.length-1&&pe(O+1,w);},[pe]),qe=react.useCallback((w=true)=>{let F=g.current;F>0&&pe(F-1,w);},[pe]),E=react.useCallback((w,F,O)=>{let R=U.current,X=g.current,Fe=X>0,xe=X<R.length-1,cr=O;(F==="down"&&!Fe||F==="up"&&!xe)&&(cr*=.3),z(cr);},[z]),W=react.useCallback(async()=>{let w=U.current;if(!(g.current<w.length-1)){await se();return}M(true),D(true),await K(-re);let R=g.current+1,X=U.current;if(R<X.length){b(R),Y(R);let Fe=X[R];Fe&&o?.(Fe,R),ce(R);}z(0),D(false),M(false);},[re,K,se,z,Y,o,ce]),ne=react.useCallback(async()=>{if(!(g.current>0)){await se();return}M(true),D(true),await K(re);let O=g.current-1;if(O>=0){b(O),Y(O);let R=U.current[O];R&&o?.(R,O);}z(0),D(false),M(false);},[re,K,se,z,Y,o]),k=react.useCallback(async()=>{await se();},[se]),{bind:C}=rr({onSwipeUp:W,onSwipeDown:ne,onSwipeProgress:E,onSwipeCancel:k,threshold:c/re,velocityThreshold:y,hapticEnabled:m,disabled:h||v,enableProgressState:false});react.useImperativeHandle(H,()=>({slideTo:pe,slideNext:$e,slidePrev:qe,get activeIndex(){return g.current},get totalSlides(){return U.current.length},get isBeginning(){return g.current===0},get isEnd(){return g.current===U.current.length-1}})),react.useEffect(()=>{let w=t[p];w&&o?.(w,p);},[]);let x=[];if(p>0&&x.push({index:p-1,position:-1}),x.push({index:p,position:0}),p<t.length-1&&x.push({index:p+1,position:1}),t.length===0)return jsxRuntime.jsx("div",{ref:A,style:J(Ce.container,S),className:L,"data-xhub-reel-feed":true,children:d&&jsxRuntime.jsx("div",{style:{...Ce.loadingIndicator,top:"50%",bottom:"auto"},children:jsxRuntime.jsx("div",{style:Ce.spinner})})});let T={...Ce.track};return jsxRuntime.jsxs("div",{ref:A,...C(),style:J(Ce.container,S),className:L,"data-xhub-reel-feed":true,children:[jsxRuntime.jsx("style",{children:`
|
|
6
10
|
@keyframes xhub-reel-spin {
|
|
7
11
|
to { transform: rotate(360deg); }
|
|
8
12
|
}
|
|
9
|
-
`}),jsxRuntime.jsx("div",{ref:
|
|
13
|
+
`}),jsxRuntime.jsx("div",{ref:_,style:T,children:x.map(({index:w,position:F})=>{let O=t[w];if(!O)return null;let R=Ae(w),X=w===p&&!V;return jsxRuntime.jsx("div",{"data-index":w,style:{...Ce.slide,top:F*re},children:jsxRuntime.jsx(Ge,{video:O,isActive:X,priority:R,initialMuted:P,onLike:()=>n?.(O),onComment:()=>i?.(O),onShare:()=>a?.(O),onAuthorClick:()=>u?.(O)})},O.id)})}),d&&jsxRuntime.jsx("div",{style:Ce.loadingIndicator,children:jsxRuntime.jsx("div",{style:Ce.spinner})})]})});st.displayName="VideoFeed";function dr({videos:t,initialIndex:e=0,onLoadMore:r,hasMore:o=true,isLoading:n=false,onLike:i,onComment:a,onShare:u,onAuthorClick:d,onVideoChange:f,className:s=""}){let l=react.useRef(null),c=react.useCallback((S,L)=>{f?.(S,L);},[f]),y=react.useCallback(S=>{i?.(S);},[i]),h=react.useCallback(S=>{a?.(S);},[a]),m=react.useCallback(S=>{u?.(S);},[u]),P=react.useCallback(S=>{d?.(S);},[d]);return jsxRuntime.jsx("div",{className:`h-screen w-full overflow-hidden bg-black ${s}`,children:jsxRuntime.jsx(st,{ref:l,videos:t,initialIndex:e,onLoadMore:r,hasMore:o,isLoading:n,onVideoChange:c,onLike:y,onComment:h,onShare:m,onAuthorClick:P})})}function Lo(t){let{container:e,...r}=t,o=typeof e=="string"?document.querySelector(e):e;if(!o||!(o instanceof HTMLElement))throw new Error("[XHubReelEmbed] Invalid container element");let n=client.createRoot(o),i=r,a=u=>{i=u,n.render(react.createElement(dr,u));};return a(r),{updateVideos:u=>{a({...i,videos:u});},destroy:()=>{n.unmount();}}}typeof window<"u"&&(window.XHubReel=Lo);exports.ActionBar=St;exports.BottomSheet=Qr;exports.IconButton=Xt;exports.PlayPauseOverlay=wt;exports.Spinner=Wr;exports.Toast=qr;exports.VideoFeed=st;exports.VideoFeedItem=Ge;exports.VideoPlayer=tr;exports.XHubReelEmbed=dr;exports.createXHubReelEmbed=Lo;exports.useVideoGestures=Mt;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import dn,{Events,ErrorTypes}from'hls.js';import {create}from'zustand';import {persist}from'zustand/middleware';import {shadows,colors,fontWeights,fontSizes,radii,spacing,easings,durations,components,mergeStyles,zIndices,springs}from'@xhub-reel/design-tokens';import {forwardRef,useRef,useEffect,useImperativeHandle,useState,useCallback,createContext,useMemo,useContext,createElement}from'react';import {AnimatePresence,motion}from'motion/react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useDrag,useGesture}from'@use-gesture/react';import {createRoot}from'react-dom/client';var kt={maxBufferLength:30,maxMaxBufferLength:60,maxBufferSize:3e7,maxBufferHole:.5,abrEwmaDefaultEstimate:5e5,abrBandWidthUpFactor:.7,abrBandWidthFactor:.9,startLevel:-1,autoStartLoad:true,startPosition:-1,fragLoadingMaxRetry:3,manifestLoadingMaxRetry:3,levelLoadingMaxRetry:3,fragLoadingTimeOut:2e4,manifestLoadingTimeOut:1e4,levelLoadingTimeOut:1e4,lowLatencyMode:false,liveSyncDuration:3};var et={ACTIVATION_THRESHOLD:.5,DEACTIVATION_THRESHOLD:.3},Re={MAX_VIDEOS_IN_DOM:5,MAX_DECODED_FRAMES:3,MAX_TOTAL_MEMORY:150*1024*1024},Ne={HEIGHT_DEFAULT:2,HEIGHT_ACTIVE:4};var Lt={PLAYER_PREFERENCES:"xhub-reel-player"};var jt={isMuted:true,volume:1,playbackSpeed:1,quality:"auto"},_e=create()(persist(e=>({...jt,toggleMute:()=>e(t=>({isMuted:!t.isMuted})),setMuted:t=>e({isMuted:t}),setVolume:t=>e({volume:Math.max(0,Math.min(1,t)),isMuted:t===0}),setPlaybackSpeed:t=>e({playbackSpeed:t}),setQuality:t=>e({quality:t}),resetPreferences:()=>e(jt)}),{name:Lt.PLAYER_PREFERENCES}));var Zt={videos:[],currentIndex:0,isLoading:false,hasMore:true,error:null},Tt=create(e=>({...Zt,setVideos:t=>e({videos:t,currentIndex:0}),appendVideos:t=>e(n=>({videos:[...n.videos,...t]})),setCurrentIndex:t=>e({currentIndex:t}),goToNext:()=>e(t=>({currentIndex:Math.min(t.currentIndex+1,t.videos.length-1)})),goToPrevious:()=>e(t=>({currentIndex:Math.max(t.currentIndex-1,0)})),removeVideo:t=>e(n=>{let r=n.videos.filter(s=>s.id!==t),o=Math.min(n.currentIndex,r.length-1);return {videos:r,currentIndex:Math.max(0,o)}}),setLoading:t=>e({isLoading:t}),setHasMore:t=>e({hasMore:t}),setError:t=>e({error:t}),reset:()=>e(Zt)}));function Y(...e){return Object.assign({},...e.filter(Boolean))}var Ue={flex:(e={})=>({display:"flex",flexDirection:e.direction,alignItems:e.align,justifyContent:e.justify,gap:typeof e.gap=="number"?e.gap:spacing[e.gap||0],flexWrap:e.wrap}),flexCenter:{display:"flex",alignItems:"center",justifyContent:"center"},flexBetween:{display:"flex",alignItems:"center",justifyContent:"space-between"},flexColumn:{display:"flex",flexDirection:"column"},grid:(e={})=>({display:"grid",gridTemplateColumns:typeof e.columns=="number"?`repeat(${e.columns}, 1fr)`:e.columns,gridTemplateRows:typeof e.rows=="number"?`repeat(${e.rows}, 1fr)`:e.rows,gap:typeof e.gap=="number"?e.gap:spacing[e.gap||0]}),absolute:(e={})=>({position:"absolute",...e.inset!==void 0&&{inset:e.inset},...e.top!==void 0&&{top:e.top},...e.right!==void 0&&{right:e.right},...e.bottom!==void 0&&{bottom:e.bottom},...e.left!==void 0&&{left:e.left}}),fixed:(e={})=>({position:"fixed",...e.inset!==void 0&&{inset:e.inset},...e.top!==void 0&&{top:e.top},...e.right!==void 0&&{right:e.right},...e.bottom!==void 0&&{bottom:e.bottom},...e.left!==void 0&&{left:e.left}}),fullScreen:{position:"fixed",inset:0,width:"100%",height:"100%"},fullSize:{width:"100%",height:"100%"},centerAbsolute:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"}};({heading:{fontSize:fontSizes.xl,fontWeight:fontWeights.bold,color:colors.text},body:{fontSize:fontSizes.md,fontWeight:fontWeights.normal,color:colors.text},caption:{fontSize:fontSizes.xs,fontWeight:fontWeights.normal,color:colors.textSecondary},videoText:{color:colors.text,textShadow:shadows.text}});var Ie={bg:e=>({backgroundColor:e in colors?colors[e]:e}),rounded:(e="md")=>({borderRadius:radii[e]}),border:(e={})=>({borderWidth:e.width||1,borderStyle:e.style||"solid",borderColor:e.color?e.color in colors?colors[e.color]:e.color:colors.border}),shadow:(e="md")=>({boxShadow:shadows[e]}),opacity:e=>({opacity:e}),glass:(e=20)=>({backgroundColor:colors.overlay,backdropFilter:`blur(${e}px)`,WebkitBackdropFilter:`blur(${e}px)`}),glassLight:(e=10)=>({backgroundColor:colors.overlayLight,backdropFilter:`blur(${e}px)`,WebkitBackdropFilter:`blur(${e}px)`})},tn={clickable:{cursor:"pointer",userSelect:"none"}},nn={transition:(e="all",t="normal",n="xhubReel")=>({transitionProperty:Array.isArray(e)?e.join(", "):e,transitionDuration:durations[t],transitionTimingFunction:easings[n]}),noTransition:{transition:"none"}},Qe={scrollY:{overflowY:"auto",overflowX:"hidden",WebkitOverflowScrolling:"touch"},hideScrollbar:{scrollbarWidth:"none",msOverflowStyle:"none"},snapY:{scrollSnapType:"y mandatory",overscrollBehaviorY:"contain"},snapStart:{scrollSnapAlign:"start",scrollSnapStop:"always"}};var rn={square:e=>({width:e,height:e}),width:e=>({width:e}),height:e=>({height:e}),minHeight:e=>({minHeight:e}),maxWidth:e=>({maxWidth:e})};({feedContainer:Y(Ue.fixed({inset:0}),Qe.scrollY,Qe.snapY,Qe.hideScrollbar,Ie.bg("background"),{touchAction:"pan-y"}),feedItem:Y(Ue.fullSize,Qe.snapStart,Ie.bg("background"),{position:"relative"}),actionButton:Y(Ue.flexCenter,rn.square(48),Ie.rounded("full"),tn.clickable,nn.transition(["transform","background-color"])),bottomSheet:Y(Ue.fixed({left:0,right:0,bottom:0}),Ie.glass(),Ie.rounded("xl"),{borderBottomLeftRadius:0,borderBottomRightRadius:0})});var on=class{callbacks={};currentInfo;constructor(){this.currentInfo=this.detectNetwork(),this.setupListeners();}detectNetwork(){let e=navigator.connection;return {online:navigator.onLine,effectiveType:e?.effectiveType??"unknown",downlink:e?.downlink??null,rtt:e?.rtt??null,saveData:e?.saveData??false,type:e?.type??"unknown"}}setupListeners(){window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.addEventListener("change",this.handleConnectionChange);}handleOnline=()=>{this.currentInfo={...this.currentInfo,online:true},this.callbacks.onOnline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleOffline=()=>{this.currentInfo={...this.currentInfo,online:false},this.callbacks.onOffline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleConnectionChange=()=>{this.currentInfo=this.detectNetwork(),this.callbacks.onNetworkChange?.(this.currentInfo);};subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isSlowNetwork(){let{effectiveType:e}=this.currentInfo;return e==="slow-2g"||e==="2g"}getRecommendedConfig(){let{effectiveType:e,saveData:t}=this.currentInfo;return t||e==="slow-2g"||e==="2g"?{maxBufferLength:10,maxMaxBufferLength:20,startLevel:0}:e==="3g"?{maxBufferLength:20,maxMaxBufferLength:40,startLevel:1}:{}}estimateDownloadTime(e){let{downlink:t}=this.currentInfo;if(!t||t===0)return 1/0;let n=t*1e6/8;return e/n}destroy(){window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.removeEventListener("change",this.handleConnectionChange);}};var sn=class{callbacks={};currentInfo={batteryLevel:null,isCharging:false,isLowPowerMode:false};battery=null;constructor(){this.initBattery();}async initBattery(){try{let e=navigator;e.getBattery&&(this.battery=await e.getBattery(),this.updateInfo(),this.setupListeners());}catch{}}updateInfo(){this.battery&&(this.currentInfo={batteryLevel:this.battery.level,isCharging:this.battery.charging,isLowPowerMode:this.battery.level<.2},this.callbacks.onPowerChange?.(this.currentInfo),this.currentInfo.batteryLevel!==null&&this.currentInfo.batteryLevel<.15&&this.callbacks.onLowBattery?.());}setupListeners(){this.battery&&(this.battery.addEventListener("levelchange",()=>this.updateInfo()),this.battery.addEventListener("chargingchange",()=>this.updateInfo()));}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isPowerSaving(){return this.currentInfo.isLowPowerMode&&!this.currentInfo.isCharging}getRecommendedConfig(){return this.isPowerSaving()?{maxBufferLength:15,capLevelToPlayerSize:true}:{}}destroy(){this.callbacks={};}};var an=class{queue=[];preloaded=new Set;loading=new Set;callbacks={};options;paused=false;velocityThreshold=2e3;constructor(e={}){this.options={maxConcurrent:e.maxConcurrent??2,maxQueue:e.maxQueue??5};}enqueue(e){let t=e.id??e.url;if(!(this.preloaded.has(e.url)||this.queue.some(n=>n.url===e.url))){if(this.queue.length>=this.options.maxQueue){let n=this.queue.shift();n&&this.callbacks.onPreloadCancel?.(n);}this.queue.push({...e,id:t,status:"pending"}),this.queue.sort((n,r)=>r.priority-n.priority),this.processQueue();}}enqueueMany(e){e.forEach(t=>this.enqueue(t));}cancel(e){let t=this.queue.find(n=>n.url===e);t&&(this.queue=this.queue.filter(n=>n.url!==e),this.loading.delete(t.id),this.callbacks.onPreloadCancel?.(t));}cancelAll(){this.queue.forEach(e=>{this.callbacks.onPreloadCancel?.(e);}),this.queue=[],this.loading.clear();}add(e,t,n=0){this.enqueue({id:e,url:t,priority:n});}remove(e){this.queue=this.queue.filter(t=>t.id!==e),this.loading.delete(e);}clear(){this.cancelAll(),this.preloaded.clear();}setPaused(e){this.paused=e,e||this.processQueue();}handleScrollVelocity(e){Math.abs(e)>this.velocityThreshold?this.setPaused(true):this.setPaused(false);}isPreloaded(e){return this.preloaded.has(e)}getStatus(e){let t=this.queue.find(n=>n.url===e);return t?t.status:this.preloaded.has(e)?"loaded":null}getAllStatuses(){return this.queue.map(e=>e.status)}getPreloadedUrls(){return Array.from(this.preloaded)}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}processQueue(){if(!this.paused)for(;this.loading.size<this.options.maxConcurrent&&this.queue.some(e=>e.status==="pending");){let e=this.queue.find(t=>t.status==="pending");e&&this.preloadItem(e);}}async preloadItem(e){e.status="loading",this.loading.add(e.id),this.callbacks.onPreloadStart?.(e);try{let t=document.createElement("link");t.rel="preload",t.as="fetch",t.href=e.url,t.crossOrigin="anonymous",document.head.appendChild(t),await new Promise((n,r)=>{t.onload=()=>n(),t.onerror=()=>r(new Error("Preload failed"));}),e.status="loaded",this.preloaded.add(e.url),this.callbacks.onPreloadComplete?.(e);}catch(t){e.status="error",this.callbacks.onPreloadError?.(e,t);}finally{this.loading.delete(e.id),this.processQueue();}}destroy(){this.clear(),this.callbacks={};}};var ln=class{metrics=this.createEmptyMetrics();callbacks={};bufferingStartTime=null;playStartTime=null;isPlaying=false;createEmptyMetrics(){return {videoId:null,sessionStartTime:null,playbackStartTime:null,totalPlayTime:0,totalBufferingTime:0,bufferingCount:0,qualitySwitches:[],errors:[],seeks:[],avgBitrate:0,startupTime:null}}startSession(e,t){this.metrics={...this.createEmptyMetrics(),videoId:e,sessionStartTime:Date.now()},this.notifyUpdate();}endSession(){this.isPlaying&&this.playStartTime&&(this.metrics.totalPlayTime+=Date.now()-this.playStartTime),this.isPlaying=false,this.playStartTime=null;let e={...this.metrics};return this.callbacks.onSessionEnd?.(e),e}trackFirstFrame(){this.metrics.sessionStartTime&&!this.metrics.playbackStartTime&&(this.metrics.playbackStartTime=Date.now(),this.metrics.startupTime=this.metrics.playbackStartTime-this.metrics.sessionStartTime,this.isPlaying=true,this.playStartTime=Date.now(),this.notifyUpdate());}trackBuffering(e){let t=Date.now();e&&!this.bufferingStartTime?(this.bufferingStartTime=t,this.metrics.bufferingCount++):!e&&this.bufferingStartTime&&(this.metrics.totalBufferingTime+=t-this.bufferingStartTime,this.bufferingStartTime=null),this.notifyUpdate();}trackQualitySwitch(e,t,n){this.metrics.qualitySwitches.push({timestamp:Date.now(),fromLevel:e,toLevel:t,automatic:n}),this.notifyUpdate();}trackError(e,t,n){let r=typeof e=="string"?e:e.message;this.metrics.errors.push({timestamp:Date.now(),message:r,recoverable:t}),this.notifyUpdate();}trackBitrate(e){this.metrics.avgBitrate=e,this.notifyUpdate();}trackReplay(){this.playStartTime=Date.now(),this.isPlaying=true,this.notifyUpdate();}trackSeek(e,t,n){this.metrics.seeks.push({timestamp:Date.now(),from:e,to:t,latency:n}),this.notifyUpdate();}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getMetrics(){return {...this.metrics}}notifyUpdate(){this.callbacks.onMetricsUpdate?.(this.getMetrics());}destroy(){this.endSession(),this.callbacks={};}};var It=class pn{hls=null;video=null;options;retryCount=0;maxRetries=3;constructor(t={}){this.options=t;}static isSupported(){return dn.isSupported()}attach(t,n){if(this.destroy(),this.video=t,this.retryCount=0,!pn.isSupported()){this.options.callbacks?.onError?.(new Error("HLS.js is not supported in this browser"),false);return}this.options.callbacks?.onStateChange?.("loading"),this.hls=new dn({...kt,...this.options.config}),this.setupHLSListeners(),this.setupVideoListeners(),this.hls.attachMedia(t),this.hls.loadSource(n);}loadSource(t){if(!this.hls||!this.video)throw new Error("HLS engine not attached to video element");this.retryCount=0,this.options.callbacks?.onStateChange?.("loading"),this.hls.loadSource(t);}destroy(){this.video&&(this.removeVideoListeners(),this.video=null),this.hls&&(this.hls.destroy(),this.hls=null);}getQualityLevels(){return this.hls?this.hls.levels.map(t=>({label:`${t.height}p`,height:t.height,bitrate:t.bitrate})):[]}setQuality(t){this.hls&&(this.hls.currentLevel=t);}getCurrentQuality(){return this.hls?.currentLevel??-1}getBandwidth(){return this.hls?.bandwidthEstimate??0}isAutoQuality(){return this.hls?.autoLevelEnabled??true}startLoad(t){this.hls?.startLoad(t);}stopLoad(){this.hls?.stopLoad();}setupHLSListeners(){this.hls&&(this.hls.on(Events.MANIFEST_PARSED,(t,n)=>{let r=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(r),this.options.callbacks?.onStateChange?.("ready"),this.video?.autoplay&&this.video.play().catch(()=>{});}),this.hls.on(Events.LEVEL_SWITCHED,(t,n)=>{this.options.callbacks?.onQualityChange?.(n.level,this.isAutoQuality());}),this.hls.on(Events.FRAG_LOADED,()=>{this.options.callbacks?.onBandwidthUpdate?.(this.getBandwidth());}),this.hls.on(Events.ERROR,(t,n)=>{this.handleError(n);}));}setupVideoListeners(){this.video&&(this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleVideoError));}removeVideoListeners(){this.video&&(this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleVideoError));}handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleVideoError=()=>{let t=this.video?.error;this.options.callbacks?.onError?.(new Error(t?.message??"Video playback error"),false),this.options.callbacks?.onStateChange?.("error");};handleError(t){if(t.fatal){let n=false;switch(t.type){case ErrorTypes.NETWORK_ERROR:this.retryCount<this.maxRetries&&(this.retryCount++,console.warn(`[HLSEngine] Network error, retry ${this.retryCount}/${this.maxRetries}`),this.hls?.startLoad(),n=true);break;case ErrorTypes.MEDIA_ERROR:console.warn("[HLSEngine] Media error, attempting recovery"),this.hls?.recoverMediaError(),n=true;break}n?this.options.callbacks?.onError?.(new Error(`HLS error (recovering): ${t.details}`),true):(this.options.callbacks?.onError?.(new Error(`HLS fatal error: ${t.details}`),false),this.options.callbacks?.onStateChange?.("error"),this.destroy());}else console.warn("[HLSEngine] Non-fatal error:",t.details);}};async function fn(e,t={}){try{return await e.play(),{success:!0}}catch(n){let r=n;if(r.name==="NotAllowedError"){e.muted=true;try{return await e.play(),{success:!0,mutedAutoplay:!0}}catch{return t.onNeedsUserGesture?.(),{success:false,reason:"user_gesture_required"}}}return {success:false,reason:"unknown",error:r}}}var hn=[.5,1,1.5,2],it=class Mt{video=null;options;lastQuality=null;bandwidthSamples=[];constructor(t={}){this.options=t;}static isSupported(){return typeof document>"u"?false:document.createElement("video").canPlayType("application/vnd.apple.mpegurl")!==""}static isIOS(){return typeof navigator>"u"?false:/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1}attach(t,n){this.destroy(),this.video=t,this.options.callbacks?.onStateChange?.("loading"),this.setupVideoListeners(),t.src=n,t.load();}loadSource(t){if(!this.video)throw new Error("Native HLS not attached to video element");this.options.callbacks?.onStateChange?.("loading"),this.video.src=t,this.video.load();}async play(){return this.video?fn(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}destroy(){this.video&&(this.removeVideoListeners(),this.video.removeAttribute("src"),this.video.load(),this.video=null),this.bandwidthSamples=[],this.lastQuality=null;}getQualityLevels(){let t=this.estimateCurrentQuality(),n=[{label:"Auto",height:0,bitrate:0}];return t&&n.push(t),n}setQuality(t){console.warn("[NativeHLS] Quality selection not supported, using auto");}getCurrentQuality(){return -1}estimateCurrentQuality(){if(!this.video||this.video.videoHeight===0)return null;let t=this.video.videoHeight,n=this.estimateBitrate();return {label:`${t}p`,height:t,bitrate:n}}estimateBitrate(){if(this.bandwidthSamples.length>0){let n=this.bandwidthSamples.reduce((r,o)=>r+o,0);return Math.round(n/this.bandwidthSamples.length)}if(!this.video)return 0;let t=this.video.videoHeight;return t>=1080?5e6:t>=720?25e5:t>=480?1e6:t>=360?5e5:25e4}getBandwidth(){return this.estimateBitrate()}isAutoQuality(){return true}startLoad(){this.video?.load();}stopLoad(){this.video&&(this.video.preload="none");}async enterFullscreen(){let t=this.video;if(t){if(t.requestFullscreen){await t.requestFullscreen();return}t.webkitEnterFullscreen&&await t.webkitEnterFullscreen();}}async exitFullscreen(){let t=this.video;if(t){if(document.exitFullscreen){await document.exitFullscreen();return}t.webkitExitFullscreen&&await t.webkitExitFullscreen();}}isFullscreen(){let t=this.video;return t?document.fullscreenElement?document.fullscreenElement===t:t.webkitDisplayingFullscreen??false:false}isFullscreenSupported(){let t=this.video;return t?!!(t.requestFullscreen||t.webkitSupportsFullscreen):false}isPlaybackRateSupported(t){return Mt.isIOS()?hn.includes(t):t>=.5&&t<=2}getSupportedPlaybackRates(){return Mt.isIOS()?[...hn]:[.5,.75,1,1.25,1.5,2]}setupVideoListeners(){this.video&&(this.video.addEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleError),this.video.addEventListener("resize",this.handleResize),this.video.addEventListener("progress",this.handleProgress));}removeVideoListeners(){this.video&&(this.video.removeEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleError),this.video.removeEventListener("resize",this.handleResize),this.video.removeEventListener("progress",this.handleProgress));}handleLoadedMetadata=()=>{let t=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(t),this.options.callbacks?.onStateChange?.("ready"),this.checkQualityChange();};handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleError=()=>{let t=this.video?.error,n=t?.message??"Video playback error",r=t?.code!==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED;this.options.callbacks?.onError?.(new Error(n),r),this.options.callbacks?.onStateChange?.("error");};handleResize=()=>{this.checkQualityChange();};handleProgress=()=>{this.updateBandwidthEstimate();};checkQualityChange(){let t=this.estimateCurrentQuality();t&&(!this.lastQuality||this.lastQuality.height!==t.height)&&(this.lastQuality=t,this.options.callbacks?.onQualityChange?.(t));}updateBandwidthEstimate(){if(this.video&&typeof performance<"u"&&performance.getEntriesByType){let n=performance.getEntriesByType("resource").filter(r=>r.initiatorType==="video"||r.name.includes(".ts")||r.name.includes(".m3u8"));if(n.length>0){let o=n.slice(-5).filter(s=>s.transferSize>0&&s.duration>0).map(s=>s.transferSize*8/(s.duration/1e3));if(o.length>0){let s=o.reduce((a,d)=>a+d,0)/o.length;this.bandwidthSamples.push(s),this.bandwidthSamples.length>10&&this.bandwidthSamples.shift(),this.options.callbacks?.onBandwidthUpdate?.(s);}}}}},mn=class{engine=null;video=null;options;isNative=false;animationFrameId=null;isTracking=false;networkDetector=null;powerManager=null;preloadManager=null;analytics=null;cleanupFunctions=[];wasPlayingBeforeOffline=false;wasPlayingBeforeLowBattery=false;constructor(e={}){this.options={enableNetworkAdaptation:true,enablePowerAdaptation:true,enableAnalytics:false,...e},this.isNative=this.shouldUseNative(),this.initializeServices();}static isSupported(){return It.isSupported()||it.isSupported()}attach(e,t,n){this.video=e,this.destroyEngine(),this.setupVideoListeners(),this.analytics&&n&&this.analytics.startSession(n,e);let r=this.getAdaptedConfig();this.isNative?this.engine=new it({callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture,onQualityChange:o=>{this.options.callbacks?.onQualityChange?.(-1,o);}}}):this.engine=new It({config:r,callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onQualityChange:(o,s)=>{let a=this.engine?.getQualityLevels()??[],d=o>=0&&o<a.length?a[o]:void 0;this.options.callbacks?.onQualityChange?.(s?-1:o,d);}}}),this.engine.attach(e,t);}loadSource(e,t){if(!this.engine||!this.video)throw new Error("Player not attached to video element");this.analytics&&(this.analytics.endSession(),t&&this.analytics.startSession(t,this.video)),this.engine.loadSource(e);}destroy(){this.destroyEngine(),this.destroyServices();}async play(){return this.video?this.isNative&&this.engine instanceof it?this.engine.play():fn(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}pause(){this.video?.pause();}async togglePlay(){return this.video?.paused?this.play():(this.pause(),{success:true})}seek(e){if(this.video){let t=this.video.currentTime;this.video.currentTime=Math.max(0,Math.min(e,this.video.duration||0)),this.analytics?.trackSeek(t,e,0);}}seekForward(e=10){this.video&&this.seek(this.video.currentTime+e);}seekBackward(e=10){this.video&&this.seek(this.video.currentTime-e);}getCurrentTime(){return this.video?.currentTime??0}getDuration(){return this.video?.duration??0}setVolume(e){this.video&&(this.video.volume=Math.max(0,Math.min(1,e)));}getVolume(){return this.video?.volume??1}setMuted(e){this.video&&(this.video.muted=e);}isMuted(){return this.video?.muted??true}toggleMute(){this.setMuted(!this.isMuted());}setPlaybackRate(e){this.video&&(this.video.playbackRate=e);}getPlaybackRate(){return this.video?.playbackRate??1}getQualityLevels(){return this.engine?.getQualityLevels()??[]}setQuality(e){let t=this.getCurrentQuality();this.engine?.setQuality(e),t!==e&&this.analytics?.trackQualitySwitch(t,e,e===-1);}getCurrentQuality(){return this.engine?.getCurrentQuality()??-1}isUsingNative(){return this.isNative}getVideoElement(){return this.video}getBuffered(){if(!this.video)return 0;let e=this.video.buffered,t=this.video.currentTime;for(let n=0;n<e.length;n++)if(t>=e.start(n)&&t<=e.end(n))return e.end(n)-t;return 0}getNetworkInfo(){return this.networkDetector?.getInfo()??null}getPowerInfo(){return this.powerManager?.getInfo()??null}getPreloadManager(){return this.preloadManager}getAnalytics(){return this.analytics?.getMetrics()??null}isSlowNetwork(){return this.networkDetector?.isSlowNetwork()??false}isPowerSaving(){return this.powerManager?.isPowerSaving()??false}shouldUseNative(){return this.options.preferNative!==false&&it.isSupported()?true:!It.isSupported()}initializeServices(){if(this.options.enableNetworkAdaptation){this.networkDetector=new on;let e=this.networkDetector.subscribe({onNetworkChange:this.handleNetworkChange,onOffline:()=>this.options.callbacks?.onError?.(new Error("Network offline"),true)});this.cleanupFunctions.push(e);}if(this.options.enablePowerAdaptation){this.powerManager=new sn;let e=this.powerManager.subscribe({onPowerChange:this.handlePowerChange});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.powerManager?.destroy());}if(this.options.preloadConfig&&(this.preloadManager=new an(this.options.preloadConfig),this.cleanupFunctions.push(()=>this.preloadManager?.destroy())),this.options.enableAnalytics){this.analytics=new ln;let e=this.analytics.subscribe({onMetricsUpdate:t=>this.options.callbacks?.onAnalyticsUpdate?.(t)});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.analytics?.destroy());}}destroyServices(){this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.networkDetector=null,this.powerManager=null,this.preloadManager=null,this.analytics=null;}destroyEngine(){this.stopProgressTracking(),this.removeVideoListeners(),this.engine&&(this.engine.destroy(),this.engine=null);}getAdaptedConfig(){let e={};return this.networkDetector&&(e={...e,...this.networkDetector.getRecommendedConfig()}),this.powerManager&&(e={...e,...this.powerManager.getRecommendedConfig()}),e}isNetworkBelowThreshold(e,t){let n=["slow-2g","2g","3g","4g","5g","unknown"],r=n.indexOf(e),o=n.indexOf(t);return e==="unknown"?false:r>=0&&r<=o}handleNetworkChange=e=>{this.options.callbacks?.onNetworkChange?.(e);let t=this.options.lowQualityThreshold??"2g",n=this.isNetworkBelowThreshold(e.effectiveType,t);this.options.autoQualityOnNetworkChange&&this.engine&&(n?this.setQuality(0):(e.effectiveType==="4g"||e.effectiveType==="5g")&&this.setQuality(-1)),this.options.autoPauseOnOffline&&!e.online&&(this.wasPlayingBeforeOffline=this.video?!this.video.paused:false,this.pause()),this.options.autoResumeOnOnline&&e.online&&this.wasPlayingBeforeOffline&&(this.play(),this.wasPlayingBeforeOffline=false),this.preloadManager&&this.preloadManager.setPaused(e.effectiveType==="2g"||!e.online);};handlePowerChange=e=>{this.options.callbacks?.onPowerChange?.(e);let t=this.options.lowBatteryThreshold??.15,n=e.batteryLevel!==null&&e.batteryLevel<t;this.options.autoPauseOnLowBattery&&n&&!e.isCharging&&(this.wasPlayingBeforeLowBattery=this.video?!this.video.paused:false,this.pause()),this.wasPlayingBeforeLowBattery&&(e.isCharging||e.batteryLevel!==null&&e.batteryLevel>=t+.05)&&(this.play(),this.wasPlayingBeforeLowBattery=false),this.preloadManager&&e.isLowPowerMode&&this.preloadManager.setPaused(true);};setupVideoListeners(){this.video&&(this.video.addEventListener("timeupdate",this.handleTimeUpdate),this.video.addEventListener("progress",this.handleProgress),this.video.addEventListener("volumechange",this.handleVolumeChange),this.video.addEventListener("ratechange",this.handleRateChange),this.video.addEventListener("play",this.handlePlay),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("playing",this.handlePlaying));}removeVideoListeners(){this.video&&(this.video.removeEventListener("timeupdate",this.handleTimeUpdate),this.video.removeEventListener("progress",this.handleProgress),this.video.removeEventListener("volumechange",this.handleVolumeChange),this.video.removeEventListener("ratechange",this.handleRateChange),this.video.removeEventListener("play",this.handlePlay),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("playing",this.handlePlaying));}handleTimeUpdate=()=>{this.video&&this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0);};handleProgress=()=>{this.options.callbacks?.onProgress?.(this.getBuffered());};handleVolumeChange=()=>{this.video&&this.options.callbacks?.onVolumeChange?.(this.video.volume,this.video.muted);};handleRateChange=()=>{this.video&&this.options.callbacks?.onRateChange?.(this.video.playbackRate);};handlePlay=()=>{this.options.enableSmoothTimeUpdates&&this.startProgressTracking();};handlePause=()=>{this.stopProgressTracking();};handleEnded=()=>{this.stopProgressTracking(),this.analytics&&this.analytics.endSession();};handleWaiting=()=>{this.analytics?.trackBuffering(true);};handlePlaying=()=>{this.analytics?.trackBuffering(false),this.analytics?.trackFirstFrame();};startProgressTracking(){if(this.isTracking||!this.video)return;this.isTracking=true;let e=()=>{if(!this.video||this.video.paused||this.video.ended){this.isTracking=false,this.animationFrameId=null;return}this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0),this.animationFrameId=requestAnimationFrame(e);};this.animationFrameId=requestAnimationFrame(e);}stopProgressTracking(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.isTracking=false;}},Cr=[{from:"idle",to:"loading"},{from:"loading",to:"ready"},{from:"loading",to:"error"},{from:"ready",to:"playing"},{from:"ready",to:"loading"},{from:"ready",to:"error"},{from:"playing",to:"paused"},{from:"playing",to:"buffering"},{from:"playing",to:"ended"},{from:"playing",to:"error"},{from:"playing",to:"loading"},{from:"paused",to:"playing"},{from:"paused",to:"buffering"},{from:"paused",to:"loading"},{from:"paused",to:"error"},{from:"buffering",to:"playing"},{from:"buffering",to:"paused"},{from:"buffering",to:"stalled"},{from:"buffering",to:"error"},{from:"stalled",to:"playing"},{from:"stalled",to:"buffering"},{from:"stalled",to:"error"},{from:"stalled",to:"loading"},{from:"ended",to:"playing"},{from:"ended",to:"loading"},{from:"ended",to:"idle"},{from:"error",to:"loading"},{from:"error",to:"idle"},{from:"*",to:"idle"}],kr=class{_state="idle";listeners=new Set;stalledTimeout=null;stalledThreshold=3e3;get state(){return this._state}transition(e){if(!this.canTransition(e))return console.warn(`[PlayerStateMachine] Invalid transition: ${this._state} -> ${e}`),false;let n=this._state;return this._state=e,e==="buffering"?this.startStalledTimer():this.clearStalledTimer(),this.listeners.forEach(r=>r(e,n)),true}canTransition(e){let t=Cr.find(n=>(n.from===this._state||n.from==="*")&&n.to===e);return !(!t||t.guard&&!t.guard())}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}reset(){this.clearStalledTimer(),this._state="idle";}isPlaying(){return this._state==="playing"}canPlay(){return ["ready","paused","ended"].includes(this._state)}isLoading(){return ["loading","buffering"].includes(this._state)}hasError(){return this._state==="error"}startStalledTimer(){this.clearStalledTimer(),this.stalledTimeout=setTimeout(()=>{this._state==="buffering"&&this.transition("stalled");},this.stalledThreshold);}clearStalledTimer(){this.stalledTimeout&&(clearTimeout(this.stalledTimeout),this.stalledTimeout=null);}};function Lr(){return new kr}function gn(){let e=useMemo(()=>Lr(),[]),[t,n]=useState(e.state);useEffect(()=>e.subscribe(a=>{n(a);}),[e]);let r=useCallback(s=>e.transition(s),[e]),o=useCallback(()=>{e.reset(),n("idle");},[e]);return {state:t,isPlaying:t==="playing",isPaused:t==="paused",isLoading:t==="loading",isBuffering:t==="buffering",isStalled:t==="stalled",isEnded:t==="ended",hasError:t==="error",canPlay:e.canPlay(),transition:r,reset:o}}function yn(e){let{volume:t,isMuted:n,setVolume:r,toggleMute:o,setMuted:s}=_e();useEffect(()=>{let i=e.current;i&&(i.volume=t,i.muted=n);},[e,t,n]),useEffect(()=>{let i=e.current;if(!i)return;let l=()=>{i.volume!==t&&r(i.volume),i.muted!==n&&s(i.muted);};return i.addEventListener("volumechange",l),()=>i.removeEventListener("volumechange",l)},[e,t,n,r,s]);let a=useCallback(i=>{let l=Math.max(0,Math.min(1,i));r(l),e.current&&(e.current.volume=l),l>0&&n&&(s(false),e.current&&(e.current.muted=false));},[e,n,r,s]),d=useCallback(()=>{o(),e.current&&(e.current.muted=!n);},[e,n,o]),u=useCallback(()=>{n||(s(true),e.current&&(e.current.muted=true));},[e,n,s]),h=useCallback(()=>{n&&(s(false),e.current&&(e.current.muted=false));},[e,n,s]);return {volume:t,isMuted:n,setVolume:a,toggleMute:d,mute:u,unmute:h}}function vn(e,t={}){let{enableSmoothTracking:n=false}=t,[r,o]=useState(0),[s,a]=useState(0),[d,u]=useState(0),[h,i]=useState([]),l=useRef(null),p=useRef(false),f=s>0?r/s*100:0,y=useCallback(c=>{let v=[],P=c.buffered;for(let R=0;R<P.length;R++)v.push({start:P.start(R),end:P.end(R)});i(v);let x=0;for(let R of v)if(c.currentTime>=R.start&&c.currentTime<=R.end){x=R.end-c.currentTime;break}u(x);},[]),m=useCallback(()=>{l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),p.current=false;},[]),b=useCallback(()=>{let c=e.current;if(!c||p.current)return;p.current=true;let v=()=>{if(!c||c.paused||c.ended){p.current=false,l.current=null;return}o(c.currentTime),l.current=requestAnimationFrame(v);};l.current=requestAnimationFrame(v);},[e]);useEffect(()=>{let c=e.current;if(!c)return;let v=()=>{o(c.currentTime);},P=()=>{a(c.duration||0);},x=()=>{a(c.duration||0);},R=()=>{y(c);},A=()=>{n&&b();},D=()=>{m();},z=()=>{m();},_=()=>{o(c.currentTime);},g=()=>{o(c.currentTime),y(c);};return c.addEventListener("timeupdate",v),c.addEventListener("loadedmetadata",P),c.addEventListener("durationchange",x),c.addEventListener("progress",R),c.addEventListener("play",A),c.addEventListener("pause",D),c.addEventListener("ended",z),c.addEventListener("seeking",_),c.addEventListener("seeked",g),c.readyState>=1&&(a(c.duration||0),o(c.currentTime)),c.readyState>=3&&y(c),!c.paused&&n&&b(),()=>{c.removeEventListener("timeupdate",v),c.removeEventListener("loadedmetadata",P),c.removeEventListener("durationchange",x),c.removeEventListener("progress",R),c.removeEventListener("play",A),c.removeEventListener("pause",D),c.removeEventListener("ended",z),c.removeEventListener("seeking",_),c.removeEventListener("seeked",g),m();}},[e,n,y,b,m]);let S=useCallback(c=>{let v=e.current;if(!v||!isFinite(v.duration))return;let P=Math.max(0,Math.min(c,v.duration));v.currentTime=P,o(P);},[e]),V=useCallback(c=>{let v=e.current;if(!v||!isFinite(v.duration))return;let x=Math.max(0,Math.min(100,c))/100*v.duration;v.currentTime=x,o(x);},[e]),H=s>0&&isFinite(s);return {currentTime:r,duration:s,buffered:d,progress:f,bufferedRanges:h,seek:S,seekToProgress:V,isSeekable:H,startSmoothTracking:b,stopSmoothTracking:m}}function bn(e){let{quality:t,setQuality:n}=_e(),[r,o]=useState(-1),[s,a]=useState([]);useEffect(()=>{if(!e)return;let i=e.getQualityLevels();a(i),o(e.getCurrentQuality());},[e]),useEffect(()=>{if(!(!e||s.length===0))if(t==="auto")e.setQuality(-1),o(-1);else {let i=parseInt(t.replace("p","")),l=s.findIndex(p=>p.height===i);l!==-1&&(e.setQuality(l),o(l));}},[e,t,s]);let d=r===-1,u=useCallback(i=>{if(e)if(typeof i=="number")if(e.setQuality(i),o(i),i===-1)n("auto");else {let l=s[i];l&&n(`${l.height}p`);}else n(i);},[e,s,n]),h=useCallback(()=>{u("auto");},[u]);return {quality:t,currentLevel:r,availableLevels:s,isAuto:d,setQuality:u,setAuto:h}}function Vt(e){return e<1e3?e.toString():e<1e4?`${(e/1e3).toFixed(1)}K`:e<1e6?`${Math.floor(e/1e3)}K`:`${(e/1e6).toFixed(1)}M`}var Vr={position:"absolute",right:spacing[4],bottom:160,display:"flex",flexDirection:"column",alignItems:"center",gap:components.actionBar.gap,zIndex:10},Ar={display:"flex",flexDirection:"column",alignItems:"center",gap:components.actionBar.iconCountGap,background:"none",border:"none",padding:0,cursor:"pointer"},Fr={width:components.actionBar.iconSize,height:components.actionBar.iconSize,display:"flex",alignItems:"center",justifyContent:"center"},Or={fontSize:fontSizes.xs,fontWeight:fontWeights.normal,color:colors.text,textShadow:shadows.text,lineHeight:components.actionBar.counterLineHeight,textAlign:"center"},Hr={display:"flex",flexDirection:"column",alignItems:"center",position:"relative",width:components.profileAction.avatarSize,height:55},Sn={width:components.profileAction.avatarSize,height:components.profileAction.avatarSize,borderRadius:"50%",objectFit:"cover",cursor:"pointer",background:colors.surface},Dr={position:"absolute",bottom:0,left:"50%",transform:"translateX(-50%)",width:components.profileAction.followButtonSize,height:components.profileAction.followButtonSize,borderRadius:"50%",backgroundColor:colors.like,border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},Br=({filled:e,color:t="white"})=>e?jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:t})}):jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 24 24",fill:"none",children:[jsx("path",{d:"M15.21 5.5C14.7957 5.5 14.46 5.83579 14.46 6.25C14.46 6.66421 14.7957 7 15.21 7C16.819 7 17.996 8.3642 17.996 10.1346C17.996 10.5488 18.3317 10.8846 18.746 10.8846C19.1602 10.8846 19.496 10.5488 19.496 10.1346C19.496 7.7358 17.8342 5.5 15.21 5.5Z",fill:t}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.89327 2.25C3.85788 2.25 1.24994 5.6858 1.24994 9.47438C1.24994 13.301 3.5604 16.37 5.9378 18.4936C8.31629 20.6183 10.9036 21.9251 11.7628 22.2115L11.9999 22.2906L12.2371 22.2115C13.0963 21.9251 15.6836 20.6183 18.0621 18.4936C20.4395 16.37 22.7499 13.301 22.7499 9.47438C22.7499 5.6858 20.142 2.25 16.1066 2.25C14.2397 2.25 12.8941 3.06969 11.9999 3.91063C11.1058 3.06969 9.76018 2.25 7.89327 2.25ZM2.74994 9.47438C2.74994 6.3142 4.8731 3.75 7.89327 3.75C9.60588 3.75 10.7397 4.66987 11.4269 5.48383L11.9999 6.16259L12.573 5.48383C13.2602 4.66987 14.394 3.75 16.1066 3.75C19.1268 3.75 21.2499 6.3142 21.2499 9.47438C21.2499 12.6733 19.3104 15.3672 17.0628 17.375C15.0361 19.1854 12.8741 20.3336 11.9999 20.6978C11.1257 20.3336 8.96379 19.1854 6.93708 17.375C4.68948 15.3672 2.74994 12.6733 2.74994 9.47438Z",fill:t})]}),Nr=()=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsx("path",{d:"M14 1.45801C7.07347 1.45801 1.45837 7.0731 1.45837 13.9997C1.45837 16.3815 2.1232 18.6107 3.27778 20.5088L2.36541 23.0178C1.77294 24.6471 3.35258 26.2268 4.98188 25.6343L7.49089 24.7219C9.389 25.8765 11.6182 26.5413 14 26.5413C20.9266 26.5413 26.5417 20.9262 26.5417 13.9997C26.5417 7.0731 20.9266 1.45801 14 1.45801Z",fill:"white"})}),_r=({filled:e})=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsx("path",{d:"M16.6904 1.45801H11.2789C10.2487 1.458 9.4224 1.45799 8.75434 1.51253C8.06795 1.56857 7.47186 1.68652 6.92253 1.96632C6.90122 1.97718 6.88036 1.98891 6.86 2.00147C5.64436 2.75199 4.94533 3.52276 4.62739 4.64643C4.48015 5.1668 4.42512 5.72644 4.40084 6.3243C4.38332 6.75558 4.3811 7.24294 4.37866 7.77623C4.37775 7.97537 4.37678 8.18091 4.375 8.39232V24.8275C4.375 25.7739 5.14242 26.5413 6.08883 26.5413C6.51994 26.5413 6.93517 26.3792 7.25226 26.0859L13.3276 20.4783C13.3386 20.4682 13.3493 20.4578 13.3597 20.4471C13.5821 20.2197 13.743 20.0895 13.8601 20.0183C13.9156 19.9846 13.9524 19.9697 13.9731 19.9631C13.9833 19.9599 13.9898 19.9585 13.9933 19.958L13.9975 19.9575L13.9992 19.9574C13.9992 19.9574 14.0065 19.9571 14.0257 19.9632C14.0466 19.9698 14.0837 19.9849 14.1394 20.0187C14.2569 20.0901 14.4182 20.2206 14.641 20.4479C14.6512 20.4583 14.6616 20.4684 14.6724 20.4783L20.7477 26.0859C21.0648 26.3792 21.4801 26.5413 21.9112 26.5413C22.8576 26.5413 23.625 25.7739 23.625 24.8275V8.3619C23.625 7.33168 23.625 6.5054 23.5705 5.83735C23.5144 5.15096 23.3965 4.55487 23.1167 4.00554C23.1058 3.98416 23.094 3.96325 23.0814 3.94284C22.3309 2.72781 21.5599 2.0287 20.4364 1.71046C19.9159 1.56305 19.3562 1.50785 18.7583 1.48352C18.3245 1.46588 17.8344 1.46376 17.2978 1.46144C17.1014 1.46059 16.8988 1.45968 16.6904 1.45801Z",fill:e?colors.warning:"white"})}),Ur=()=>jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:28,height:28,viewBox:"0 0 28 28",fill:"none",children:[jsx("path",{d:"M20.6583 8.99195C21.1139 8.53634 21.1139 7.79765 20.6583 7.34203L14.8249 1.5087C14.6061 1.28991 14.3094 1.16699 14 1.16699C13.6905 1.16699 13.3938 1.28991 13.175 1.5087L7.34167 7.34204C6.88606 7.79765 6.88606 8.53634 7.34167 8.99195C7.79728 9.44756 8.53597 9.44756 8.99158 8.99195L12.8333 5.15024L12.8333 17.5003C12.8333 18.1447 13.3556 18.667 14 18.667C14.6443 18.667 15.1666 18.1447 15.1666 17.5003L15.1666 5.15024L19.0083 8.99195C19.4639 9.44756 20.2026 9.44756 20.6583 8.99195Z",fill:"white"}),jsx("path",{d:"M24.4562 22.2708C24.4991 21.7457 24.5 21.0663 24.5 20.067V16.3337C24.5 15.6893 25.0223 15.167 25.6666 15.167C26.311 15.167 26.8333 15.6893 26.8333 16.3337L26.8333 20.1152C26.8333 21.0543 26.8333 21.8294 26.7817 22.4608C26.7282 23.1166 26.6132 23.7194 26.3247 24.2856C25.8772 25.1637 25.1633 25.8776 24.2852 26.325C23.719 26.6135 23.1162 26.7285 22.4604 26.7821C21.829 26.8337 21.054 26.8337 20.1149 26.8337H7.88508C6.94599 26.8337 6.17087 26.8337 5.5395 26.7821C4.88372 26.7285 4.28089 26.6135 3.71467 26.325C2.83658 25.8776 2.12267 25.1637 1.67526 24.2856C1.38676 23.7194 1.27176 23.1166 1.21819 22.4608C1.1666 21.8294 1.16661 21.0543 1.16663 20.1152V16.3337C1.16663 15.6893 1.68896 15.167 2.33329 15.167C2.97762 15.167 3.49996 15.6893 3.49996 16.3337L3.49996 20.067C3.49996 21.0663 3.50087 21.7457 3.54377 22.2708C3.58556 22.7823 3.66131 23.0438 3.75428 23.2263C3.97798 23.6653 4.33494 24.0223 4.77398 24.246C4.95645 24.339 5.21802 24.4147 5.7295 24.4565C6.25461 24.4994 6.93395 24.5003 7.93329 24.5003H20.0666C21.066 24.5003 21.7453 24.4994 22.2704 24.4565C22.7819 24.4147 23.0435 24.339 23.2259 24.246C23.665 24.0223 24.0219 23.6653 24.2456 23.2263C24.3386 23.0438 24.4144 22.7823 24.4562 22.2708Z",fill:"white"})]}),Qr=()=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 12 12",fill:"white",children:jsx("path",{d:"M6 1V11M1 6H11",stroke:"white",strokeWidth:2,strokeLinecap:"round"})}),zr=()=>jsx("svg",{width:12,height:12,viewBox:"0 0 12 12",fill:"none",children:jsx("path",{d:"M2 6L5 9L10 3",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})});function Wr({avatarUrl:e,isFollowed:t=false,onClick:n,onFollow:r}){return jsxs("div",{style:Hr,children:[jsx(motion.button,{style:{background:"none",border:"none",padding:0,cursor:"pointer"},onClick:n,whileTap:{scale:.95},"aria-label":"View profile",children:e?jsx("img",{src:e,alt:"Profile",style:Sn}):jsx("div",{style:Sn})}),!t&&r&&jsx(motion.button,{style:Dr,onClick:o=>{o.stopPropagation(),r();},whileTap:{scale:.9},animate:t?{scale:[1,1.2,1]}:{scale:1},transition:{type:"spring",...springs.bouncy},"aria-label":t?"Following":"Follow",children:t?jsx(zr,{}):jsx(Qr,{})})]})}function ot({icon:e,count:t,isActive:n=false,onClick:r,label:o}){return jsxs(motion.button,{style:Ar,onClick:r,"aria-label":o,whileTap:{scale:.9},transition:{type:"spring",...springs.bouncy},children:[jsx(motion.div,{style:Fr,animate:n?{scale:[1,1.2,1]}:{scale:1},transition:n?{duration:.3,ease:[.32,.72,0,1]}:{type:"spring",...springs.default},children:e}),t!==void 0&&jsx("span",{style:Or,children:Vt(t)})]})}function at({likeCount:e,commentCount:t,shareCount:n,saveCount:r,isLiked:o=false,isSaved:s=false,onLike:a,onComment:d,onShare:u,onSave:h,avatarUrl:i,onProfileClick:l,onFollow:p,isFollowed:f=false,style:y,className:m=""}){return jsxs("div",{style:mergeStyles(Vr,y),className:m,children:[i&&jsx(Wr,{avatarUrl:i,isFollowed:f,onClick:l,onFollow:p}),jsx(ot,{icon:jsx(Br,{filled:o,color:o?colors.like:"white"}),count:e,isActive:o,onClick:a,label:o?"Unlike":"Like"}),jsx(ot,{icon:jsx(Nr,{}),count:t,onClick:d,label:"Comments"}),jsx(ot,{icon:jsx(_r,{filled:s}),count:r,isActive:s,onClick:h,label:s?"Unsave":"Save"}),jsx(ot,{icon:jsx(Ur,{}),count:n,onClick:u,label:"Share"})]})}var Kr={display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",cursor:"pointer",borderRadius:radii.full,transitionProperty:"background-color, transform, opacity",transitionDuration:durations.fast,transitionTimingFunction:easings.xhubReel,userSelect:"none"},jr={sm:{width:32,height:32},md:{width:components.tapArea,height:components.tapArea},lg:{width:56,height:56}},Zr={default:{backgroundColor:colors.surface,color:colors.text},ghost:{backgroundColor:"transparent",color:colors.text},glass:{backgroundColor:"rgba(0, 0, 0, 0.2)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",color:colors.text}},Jr={opacity:.5,cursor:"not-allowed",pointerEvents:"none"},Ft=forwardRef(({icon:e,size:t="md",variant:n="ghost",disabled:r,style:o,className:s="",...a},d)=>jsx("button",{ref:d,type:"button",disabled:r,style:mergeStyles(Kr,jr[t],Zr[n],r&&Jr,o),className:s,...a,children:e}));Ft.displayName="IconButton";var ai={position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:zIndices.overlay},li={display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",borderRadius:"50%",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",cursor:"pointer"},di=({size:e})=>jsx("svg",{width:e*.4,height:e*.4,viewBox:"0 0 24 24",fill:colors.text,children:jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),ui=({size:e})=>jsxs("svg",{width:e*.35,height:e*.35,viewBox:"0 0 24 24",fill:colors.text,children:[jsx("rect",{x:"6",y:"4",width:"4",height:"16"}),jsx("rect",{x:"14",y:"4",width:"4",height:"16"})]});function dt({isPlaying:e,show:t,onToggle:n,size:r=72,autoHideDelay:o=1e3,showOnStateChange:s=true,style:a,className:d=""}){let[u,h]=useState(false),[i,l]=useState(false),p=t!==void 0,f=p?t:u;useEffect(()=>{if(!(p||!s||!i)&&(h(true),o>0)){let S=setTimeout(()=>{h(false);},o);return ()=>clearTimeout(S)}},[e,p,s,o,i]);let y=useCallback(()=>{n&&(l(true),h(true),n());},[n]),m=!!n,b=m?"auto":"none";return jsx(AnimatePresence,{children:f&&jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},style:mergeStyles(ai,{pointerEvents:b},a),className:d,onClick:y,children:jsx(motion.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.8,opacity:0},transition:{type:"spring",...springs.default},whileTap:m?{scale:.9}:void 0,style:{...li,width:r,height:r,cursor:m?"pointer":"default"},children:e?jsx(ui,{size:r}):jsx(di,{size:r})})})})}var yi={position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.6)",zIndex:zIndices.modal},vi={position:"fixed",left:0,right:0,bottom:0,backgroundColor:colors.overlay,backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",borderTopLeftRadius:radii.xl,borderTopRightRadius:radii.xl,zIndex:zIndices.modal+1,display:"flex",flexDirection:"column",maxHeight:"90vh"},bi={width:components.bottomSheet.handleWidth,height:components.bottomSheet.handleHeight,backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:2,margin:"12px auto 0",flexShrink:0},Si={display:"flex",alignItems:"center",justifyContent:"space-between",padding:`${spacing[4]}px ${spacing[4]}px ${spacing[3]}px`,flexShrink:0},wi={fontSize:18,fontWeight:600,color:colors.text},Pi={width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",cursor:"pointer",color:colors.textSecondary,borderRadius:"50%"},Ei={flex:1,overflow:"auto",WebkitOverflowScrolling:"touch"},Ci=()=>jsxs("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]});function Rn({isOpen:e,onClose:t,title:n,children:r,height:o="60vh",maxHeight:s="90vh",showClose:a=true,showHandle:d=true,style:u,className:h=""}){let i=useCallback(l=>{l.key==="Escape"&&t();},[t]);return useEffect(()=>(e&&(document.addEventListener("keydown",i),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",i),document.body.style.overflow="";}),[e,i]),jsx(AnimatePresence,{children:e&&jsxs(Fragment,{children:[jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:yi,onClick:t}),jsxs(motion.div,{initial:{y:"100%"},animate:{y:0},exit:{y:"100%"},transition:{type:"spring",...springs.default},drag:"y",dragConstraints:{top:0,bottom:0},dragElastic:{top:0,bottom:.5},onDragEnd:(l,p)=>{(p.offset.y>100||p.velocity.y>500)&&t();},style:mergeStyles(vi,{height:o,maxHeight:s,touchAction:"none"},u),className:h,children:[d&&jsx("div",{style:bi}),(n||a)&&jsxs("div",{style:Si,children:[jsx("span",{style:wi,children:n}),a&&jsx("button",{style:Pi,onClick:t,"aria-label":"Close",children:jsx(Ci,{})})]}),jsx("div",{style:Ei,children:r})]})]})})}function Mn({size:e=24,color:t=colors.text,thickness:n=2,style:r,className:o=""}){return jsxs(Fragment,{children:[jsx("style",{children:`
|
|
1
|
+
import br,{Events,ErrorTypes}from'hls.js';import {create}from'zustand';import {persist}from'zustand/middleware';import {shadows,colors,fontWeights,fontSizes,radii,spacing,easings,durations,components,mergeStyles,zIndices,springs}from'@xhub-reel/design-tokens';import {forwardRef,useRef,useEffect,useImperativeHandle,useState,useCallback,createContext,useMemo,useContext,createElement}from'react';import {AnimatePresence,motion}from'motion/react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useDrag,useGesture}from'@use-gesture/react';import {createRoot}from'react-dom/client';var Bt={maxBufferLength:30,maxMaxBufferLength:60,maxBufferSize:3e7,maxBufferHole:.5,abrEwmaDefaultEstimate:5e5,abrBandWidthUpFactor:.7,abrBandWidthFactor:.9,startLevel:-1,autoStartLoad:true,startPosition:-1,fragLoadingMaxRetry:3,manifestLoadingMaxRetry:3,levelLoadingMaxRetry:3,fragLoadingTimeOut:2e4,manifestLoadingTimeOut:1e4,levelLoadingTimeOut:1e4,lowLatencyMode:false,liveSyncDuration:3};var lt={ACTIVATION_THRESHOLD:.5,DEACTIVATION_THRESHOLD:.3},De={MAX_VIDEOS_IN_DOM:5,MAX_DECODED_FRAMES:3,MAX_TOTAL_MEMORY:150*1024*1024},Xe={HEIGHT_DEFAULT:2,HEIGHT_ACTIVE:4};var Ut={PLAYER_PREFERENCES:"xhub-reel-player"};var pr={isMuted:true,volume:1,playbackSpeed:1,quality:"auto"},Ne=create()(persist(t=>({...pr,toggleMute:()=>t(e=>({isMuted:!e.isMuted})),setMuted:e=>t({isMuted:e}),setVolume:e=>t({volume:Math.max(0,Math.min(1,e)),isMuted:e===0}),setPlaybackSpeed:e=>t({playbackSpeed:e}),setQuality:e=>t({quality:e}),resetPreferences:()=>t(pr)}),{name:Ut.PLAYER_PREFERENCES}));var mr={videos:[],currentIndex:0,isLoading:false,hasMore:true,error:null},_t=create(t=>({...mr,setVideos:e=>t({videos:e,currentIndex:0}),appendVideos:e=>t(r=>({videos:[...r.videos,...e]})),setCurrentIndex:e=>t({currentIndex:e}),goToNext:()=>t(e=>({currentIndex:Math.min(e.currentIndex+1,e.videos.length-1)})),goToPrevious:()=>t(e=>({currentIndex:Math.max(e.currentIndex-1,0)})),removeVideo:e=>t(r=>{let o=r.videos.filter(i=>i.id!==e),n=Math.min(r.currentIndex,o.length-1);return {videos:o,currentIndex:Math.max(0,n)}}),setLoading:e=>t({isLoading:e}),setHasMore:e=>t({hasMore:e}),setError:e=>t({error:e}),reset:()=>t(mr)}));function J(...t){return Object.assign({},...t.filter(Boolean))}var Ye={flex:(t={})=>({display:"flex",flexDirection:t.direction,alignItems:t.align,justifyContent:t.justify,gap:typeof t.gap=="number"?t.gap:spacing[t.gap||0],flexWrap:t.wrap}),flexCenter:{display:"flex",alignItems:"center",justifyContent:"center"},flexBetween:{display:"flex",alignItems:"center",justifyContent:"space-between"},flexColumn:{display:"flex",flexDirection:"column"},grid:(t={})=>({display:"grid",gridTemplateColumns:typeof t.columns=="number"?`repeat(${t.columns}, 1fr)`:t.columns,gridTemplateRows:typeof t.rows=="number"?`repeat(${t.rows}, 1fr)`:t.rows,gap:typeof t.gap=="number"?t.gap:spacing[t.gap||0]}),absolute:(t={})=>({position:"absolute",...t.inset!==void 0&&{inset:t.inset},...t.top!==void 0&&{top:t.top},...t.right!==void 0&&{right:t.right},...t.bottom!==void 0&&{bottom:t.bottom},...t.left!==void 0&&{left:t.left}}),fixed:(t={})=>({position:"fixed",...t.inset!==void 0&&{inset:t.inset},...t.top!==void 0&&{top:t.top},...t.right!==void 0&&{right:t.right},...t.bottom!==void 0&&{bottom:t.bottom},...t.left!==void 0&&{left:t.left}}),fullScreen:{position:"fixed",inset:0,width:"100%",height:"100%"},fullSize:{width:"100%",height:"100%"},centerAbsolute:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)"}};({heading:{fontSize:fontSizes.xl,fontWeight:fontWeights.bold,color:colors.text},body:{fontSize:fontSizes.md,fontWeight:fontWeights.normal,color:colors.text},caption:{fontSize:fontSizes.xs,fontWeight:fontWeights.normal,color:colors.textSecondary},videoText:{color:colors.text,textShadow:shadows.text}});var Be={bg:t=>({backgroundColor:t in colors?colors[t]:t}),rounded:(t="md")=>({borderRadius:radii[t]}),border:(t={})=>({borderWidth:t.width||1,borderStyle:t.style||"solid",borderColor:t.color?t.color in colors?colors[t.color]:t.color:colors.border}),shadow:(t="md")=>({boxShadow:shadows[t]}),opacity:t=>({opacity:t}),glass:(t=20)=>({backgroundColor:colors.overlay,backdropFilter:`blur(${t}px)`,WebkitBackdropFilter:`blur(${t}px)`}),glassLight:(t=10)=>({backgroundColor:colors.overlayLight,backdropFilter:`blur(${t}px)`,WebkitBackdropFilter:`blur(${t}px)`})},yr={clickable:{cursor:"pointer",userSelect:"none"}},gr={transition:(t="all",e="normal",r="xhubReel")=>({transitionProperty:Array.isArray(t)?t.join(", "):t,transitionDuration:durations[e],transitionTimingFunction:easings[r]}),noTransition:{transition:"none"}},Ke={scrollY:{overflowY:"auto",overflowX:"hidden",WebkitOverflowScrolling:"touch"},hideScrollbar:{scrollbarWidth:"none",msOverflowStyle:"none"},snapY:{scrollSnapType:"y mandatory",overscrollBehaviorY:"contain"},snapStart:{scrollSnapAlign:"start",scrollSnapStop:"always"}};var vr={square:t=>({width:t,height:t}),width:t=>({width:t}),height:t=>({height:t}),minHeight:t=>({minHeight:t}),maxWidth:t=>({maxWidth:t})};({feedContainer:J(Ye.fixed({inset:0}),Ke.scrollY,Ke.snapY,Ke.hideScrollbar,Be.bg("background"),{touchAction:"pan-y"}),feedItem:J(Ye.fullSize,Ke.snapStart,Be.bg("background"),{position:"relative"}),actionButton:J(Ye.flexCenter,vr.square(48),Be.rounded("full"),yr.clickable,gr.transition(["transform","background-color"])),bottomSheet:J(Ye.fixed({left:0,right:0,bottom:0}),Be.glass(),Be.rounded("xl"),{borderBottomLeftRadius:0,borderBottomRightRadius:0})});var Ue=class t{hls=null;video=null;options;retryCount=0;maxRetries=3;constructor(e={}){this.options=e;}static isSupported(){return br.isSupported()}attach(e,r){if(this.destroy(),this.video=e,this.retryCount=0,!t.isSupported()){this.options.callbacks?.onError?.(new Error("HLS.js is not supported in this browser"),false);return}this.options.callbacks?.onStateChange?.("loading"),this.hls=new br({...Bt,...this.options.config}),this.setupHLSListeners(),this.setupVideoListeners(),this.hls.attachMedia(e),this.hls.loadSource(r);}loadSource(e){if(!this.hls||!this.video)throw new Error("HLS engine not attached to video element");this.retryCount=0,this.options.callbacks?.onStateChange?.("loading"),this.hls.loadSource(e);}destroy(){this.video&&(this.removeVideoListeners(),this.video=null),this.hls&&(this.hls.destroy(),this.hls=null);}getQualityLevels(){return this.hls?this.hls.levels.map(e=>({label:`${e.height}p`,height:e.height,bitrate:e.bitrate})):[]}setQuality(e){this.hls&&(this.hls.currentLevel=e);}getCurrentQuality(){return this.hls?.currentLevel??-1}getBandwidth(){return this.hls?.bandwidthEstimate??0}isAutoQuality(){return this.hls?.autoLevelEnabled??true}startLoad(e){this.hls?.startLoad(e);}stopLoad(){this.hls?.stopLoad();}setupHLSListeners(){this.hls&&(this.hls.on(Events.MANIFEST_PARSED,(e,r)=>{let o=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(o),this.options.callbacks?.onStateChange?.("ready"),this.video?.autoplay&&this.video.play().catch(()=>{});}),this.hls.on(Events.LEVEL_SWITCHED,(e,r)=>{this.options.callbacks?.onQualityChange?.(r.level,this.isAutoQuality());}),this.hls.on(Events.FRAG_LOADED,()=>{this.options.callbacks?.onBandwidthUpdate?.(this.getBandwidth());}),this.hls.on(Events.ERROR,(e,r)=>{this.handleError(r);}));}setupVideoListeners(){this.video&&(this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleVideoError));}removeVideoListeners(){this.video&&(this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleVideoError));}handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleVideoError=()=>{let e=this.video?.error;this.options.callbacks?.onError?.(new Error(e?.message??"Video playback error"),false),this.options.callbacks?.onStateChange?.("error");};handleError(e){if(e.fatal){let r=false;switch(e.type){case ErrorTypes.NETWORK_ERROR:this.retryCount<this.maxRetries&&(this.retryCount++,console.warn(`[HLSEngine] Network error, retry ${this.retryCount}/${this.maxRetries}`),this.hls?.startLoad(),r=true);break;case ErrorTypes.MEDIA_ERROR:console.warn("[HLSEngine] Media error, attempting recovery"),this.hls?.recoverMediaError(),r=true;break;}r?this.options.callbacks?.onError?.(new Error(`HLS error (recovering): ${e.details}`),true):(this.options.callbacks?.onError?.(new Error(`HLS fatal error: ${e.details}`),false),this.options.callbacks?.onStateChange?.("error"),this.destroy());}else console.warn("[HLSEngine] Non-fatal error:",e.details);}};async function pt(t,e={}){try{return await t.play(),{success:!0}}catch(r){let o=r;if(o.name==="NotAllowedError"){t.muted=true;try{return await t.play(),{success:!0,mutedAutoplay:!0}}catch{return e.onNeedsUserGesture?.(),{success:false,reason:"user_gesture_required"}}}return {success:false,reason:"unknown",error:o}}}var Pr=[.5,1,1.5,2],Te=class t{video=null;options;lastQuality=null;bandwidthSamples=[];constructor(e={}){this.options=e;}static isSupported(){return typeof document>"u"?false:document.createElement("video").canPlayType("application/vnd.apple.mpegurl")!==""}static isIOS(){return typeof navigator>"u"?false:/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1}attach(e,r){this.destroy(),this.video=e,this.options.callbacks?.onStateChange?.("loading"),this.setupVideoListeners(),e.src=r,e.load();}loadSource(e){if(!this.video)throw new Error("Native HLS not attached to video element");this.options.callbacks?.onStateChange?.("loading"),this.video.src=e,this.video.load();}async play(){return this.video?pt(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}destroy(){this.video&&(this.removeVideoListeners(),this.video.removeAttribute("src"),this.video.load(),this.video=null),this.bandwidthSamples=[],this.lastQuality=null;}getQualityLevels(){let e=this.estimateCurrentQuality(),r=[{label:"Auto",height:0,bitrate:0}];return e&&r.push(e),r}setQuality(e){console.warn("[NativeHLS] Quality selection not supported, using auto");}getCurrentQuality(){return -1}estimateCurrentQuality(){if(!this.video||this.video.videoHeight===0)return null;let e=this.video.videoHeight,r=this.estimateBitrate();return {label:`${e}p`,height:e,bitrate:r}}estimateBitrate(){if(this.bandwidthSamples.length>0){let r=this.bandwidthSamples.reduce((o,n)=>o+n,0);return Math.round(r/this.bandwidthSamples.length)}if(!this.video)return 0;let e=this.video.videoHeight;return e>=1080?5e6:e>=720?25e5:e>=480?1e6:e>=360?5e5:25e4}getBandwidth(){return this.estimateBitrate()}isAutoQuality(){return true}startLoad(){this.video?.load();}stopLoad(){this.video&&(this.video.preload="none");}async enterFullscreen(){let e=this.video;if(e){if(e.requestFullscreen){await e.requestFullscreen();return}e.webkitEnterFullscreen&&await e.webkitEnterFullscreen();}}async exitFullscreen(){let e=this.video;if(e){if(document.exitFullscreen){await document.exitFullscreen();return}e.webkitExitFullscreen&&await e.webkitExitFullscreen();}}isFullscreen(){let e=this.video;return e?document.fullscreenElement?document.fullscreenElement===e:e.webkitDisplayingFullscreen??false:false}isFullscreenSupported(){let e=this.video;return e?!!(e.requestFullscreen||e.webkitSupportsFullscreen):false}isPlaybackRateSupported(e){return t.isIOS()?Pr.includes(e):e>=.5&&e<=2}getSupportedPlaybackRates(){return t.isIOS()?[...Pr]:[.5,.75,1,1.25,1.5,2]}setupVideoListeners(){this.video&&(this.video.addEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.addEventListener("playing",this.handlePlaying),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("canplay",this.handleCanPlay),this.video.addEventListener("error",this.handleError),this.video.addEventListener("resize",this.handleResize),this.video.addEventListener("progress",this.handleProgress));}removeVideoListeners(){this.video&&(this.video.removeEventListener("loadedmetadata",this.handleLoadedMetadata),this.video.removeEventListener("playing",this.handlePlaying),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("canplay",this.handleCanPlay),this.video.removeEventListener("error",this.handleError),this.video.removeEventListener("resize",this.handleResize),this.video.removeEventListener("progress",this.handleProgress));}handleLoadedMetadata=()=>{let e=this.getQualityLevels();this.options.callbacks?.onQualityLevelsLoaded?.(e),this.options.callbacks?.onStateChange?.("ready"),this.checkQualityChange();};handlePlaying=()=>{this.options.callbacks?.onStateChange?.("playing");};handlePause=()=>{this.options.callbacks?.onStateChange?.("paused");};handleWaiting=()=>{this.options.callbacks?.onStateChange?.("buffering");};handleEnded=()=>{this.options.callbacks?.onStateChange?.("ended");};handleCanPlay=()=>{this.video?.paused&&this.options.callbacks?.onStateChange?.("ready");};handleError=()=>{let e=this.video?.error,r=e?.message??"Video playback error",o=e?.code!==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED;this.options.callbacks?.onError?.(new Error(r),o),this.options.callbacks?.onStateChange?.("error");};handleResize=()=>{this.checkQualityChange();};handleProgress=()=>{this.updateBandwidthEstimate();};checkQualityChange(){let e=this.estimateCurrentQuality();e&&(!this.lastQuality||this.lastQuality.height!==e.height)&&(this.lastQuality=e,this.options.callbacks?.onQualityChange?.(e));}updateBandwidthEstimate(){if(this.video&&typeof performance<"u"&&performance.getEntriesByType){let r=performance.getEntriesByType("resource").filter(o=>o.initiatorType==="video"||o.name.includes(".ts")||o.name.includes(".m3u8"));if(r.length>0){let n=r.slice(-5).filter(i=>i.transferSize>0&&i.duration>0).map(i=>i.transferSize*8/(i.duration/1e3));if(n.length>0){let i=n.reduce((a,u)=>a+u,0)/n.length;this.bandwidthSamples.push(i),this.bandwidthSamples.length>10&&this.bandwidthSamples.shift(),this.options.callbacks?.onBandwidthUpdate?.(i);}}}}};var Le=class{callbacks={};currentInfo;constructor(){this.currentInfo=this.detectNetwork(),this.setupListeners();}detectNetwork(){let e=navigator.connection;return {online:navigator.onLine,effectiveType:e?.effectiveType??"unknown",downlink:e?.downlink??null,rtt:e?.rtt??null,saveData:e?.saveData??false,type:e?.type??"unknown"}}setupListeners(){window.addEventListener("online",this.handleOnline),window.addEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.addEventListener("change",this.handleConnectionChange);}handleOnline=()=>{this.currentInfo={...this.currentInfo,online:true},this.callbacks.onOnline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleOffline=()=>{this.currentInfo={...this.currentInfo,online:false},this.callbacks.onOffline?.(),this.callbacks.onNetworkChange?.(this.currentInfo);};handleConnectionChange=()=>{this.currentInfo=this.detectNetwork(),this.callbacks.onNetworkChange?.(this.currentInfo);};subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isSlowNetwork(){let{effectiveType:e}=this.currentInfo;return e==="slow-2g"||e==="2g"}getRecommendedConfig(){let{effectiveType:e,saveData:r}=this.currentInfo;return r||e==="slow-2g"||e==="2g"?{maxBufferLength:10,maxMaxBufferLength:20,startLevel:0}:e==="3g"?{maxBufferLength:20,maxMaxBufferLength:40,startLevel:1}:{}}estimateDownloadTime(e){let{downlink:r}=this.currentInfo;if(!r||r===0)return 1/0;let o=r*1e6/8;return e/o}destroy(){window.removeEventListener("online",this.handleOnline),window.removeEventListener("offline",this.handleOffline);let e=navigator.connection;e&&e.removeEventListener("change",this.handleConnectionChange);}};var Re=class{callbacks={};currentInfo={batteryLevel:null,isCharging:false,isLowPowerMode:false};battery=null;constructor(){this.initBattery();}async initBattery(){try{let e=navigator;e.getBattery&&(this.battery=await e.getBattery(),this.updateInfo(),this.setupListeners());}catch{}}updateInfo(){this.battery&&(this.currentInfo={batteryLevel:this.battery.level,isCharging:this.battery.charging,isLowPowerMode:this.battery.level<.2},this.callbacks.onPowerChange?.(this.currentInfo),this.currentInfo.batteryLevel!==null&&this.currentInfo.batteryLevel<.15&&this.callbacks.onLowBattery?.());}setupListeners(){this.battery&&(this.battery.addEventListener("levelchange",()=>this.updateInfo()),this.battery.addEventListener("chargingchange",()=>this.updateInfo()));}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getInfo(){return this.currentInfo}isPowerSaving(){return this.currentInfo.isLowPowerMode&&!this.currentInfo.isCharging}getRecommendedConfig(){return this.isPowerSaving()?{maxBufferLength:15,capLevelToPlayerSize:true}:{}}destroy(){this.callbacks={};}};var Ie=class{queue=[];preloaded=new Set;loading=new Set;callbacks={};options;paused=false;velocityThreshold=2e3;constructor(e={}){this.options={maxConcurrent:e.maxConcurrent??2,maxQueue:e.maxQueue??5};}enqueue(e){let r=e.id??e.url;if(!(this.preloaded.has(e.url)||this.queue.some(o=>o.url===e.url))){if(this.queue.length>=this.options.maxQueue){let o=this.queue.shift();o&&this.callbacks.onPreloadCancel?.(o);}this.queue.push({...e,id:r,status:"pending"}),this.queue.sort((o,n)=>n.priority-o.priority),this.processQueue();}}enqueueMany(e){e.forEach(r=>this.enqueue(r));}cancel(e){let r=this.queue.find(o=>o.url===e);r&&(this.queue=this.queue.filter(o=>o.url!==e),this.loading.delete(r.id),this.callbacks.onPreloadCancel?.(r));}cancelAll(){this.queue.forEach(e=>{this.callbacks.onPreloadCancel?.(e);}),this.queue=[],this.loading.clear();}add(e,r,o=0){this.enqueue({id:e,url:r,priority:o});}remove(e){this.queue=this.queue.filter(r=>r.id!==e),this.loading.delete(e);}clear(){this.cancelAll(),this.preloaded.clear();}setPaused(e){this.paused=e,e||this.processQueue();}handleScrollVelocity(e){Math.abs(e)>this.velocityThreshold?this.setPaused(true):this.setPaused(false);}isPreloaded(e){return this.preloaded.has(e)}getStatus(e){let r=this.queue.find(o=>o.url===e);return r?r.status:this.preloaded.has(e)?"loaded":null}getAllStatuses(){return this.queue.map(e=>e.status)}getPreloadedUrls(){return Array.from(this.preloaded)}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}processQueue(){if(!this.paused)for(;this.loading.size<this.options.maxConcurrent&&this.queue.some(e=>e.status==="pending");){let e=this.queue.find(r=>r.status==="pending");e&&this.preloadItem(e);}}async preloadItem(e){e.status="loading",this.loading.add(e.id),this.callbacks.onPreloadStart?.(e);try{let r=document.createElement("link");r.rel="preload",r.as="fetch",r.href=e.url,r.crossOrigin="anonymous",document.head.appendChild(r),await new Promise((o,n)=>{r.onload=()=>o(),r.onerror=()=>n(new Error("Preload failed"));}),e.status="loaded",this.preloaded.add(e.url),this.callbacks.onPreloadComplete?.(e);}catch(r){e.status="error",this.callbacks.onPreloadError?.(e,r);}finally{this.loading.delete(e.id),this.processQueue();}}destroy(){this.clear(),this.callbacks={};}};var Me=class{metrics=this.createEmptyMetrics();callbacks={};bufferingStartTime=null;playStartTime=null;isPlaying=false;createEmptyMetrics(){return {videoId:null,sessionStartTime:null,playbackStartTime:null,totalPlayTime:0,totalBufferingTime:0,bufferingCount:0,qualitySwitches:[],errors:[],seeks:[],avgBitrate:0,startupTime:null}}startSession(e,r){this.metrics={...this.createEmptyMetrics(),videoId:e,sessionStartTime:Date.now()},this.notifyUpdate();}endSession(){this.isPlaying&&this.playStartTime&&(this.metrics.totalPlayTime+=Date.now()-this.playStartTime),this.isPlaying=false,this.playStartTime=null;let e={...this.metrics};return this.callbacks.onSessionEnd?.(e),e}trackFirstFrame(){this.metrics.sessionStartTime&&!this.metrics.playbackStartTime&&(this.metrics.playbackStartTime=Date.now(),this.metrics.startupTime=this.metrics.playbackStartTime-this.metrics.sessionStartTime,this.isPlaying=true,this.playStartTime=Date.now(),this.notifyUpdate());}trackBuffering(e){let r=Date.now();e&&!this.bufferingStartTime?(this.bufferingStartTime=r,this.metrics.bufferingCount++):!e&&this.bufferingStartTime&&(this.metrics.totalBufferingTime+=r-this.bufferingStartTime,this.bufferingStartTime=null),this.notifyUpdate();}trackQualitySwitch(e,r,o){this.metrics.qualitySwitches.push({timestamp:Date.now(),fromLevel:e,toLevel:r,automatic:o}),this.notifyUpdate();}trackError(e,r,o){let n=typeof e=="string"?e:e.message;this.metrics.errors.push({timestamp:Date.now(),message:n,recoverable:r}),this.notifyUpdate();}trackBitrate(e){this.metrics.avgBitrate=e,this.notifyUpdate();}trackReplay(){this.playStartTime=Date.now(),this.isPlaying=true,this.notifyUpdate();}trackSeek(e,r,o){this.metrics.seeks.push({timestamp:Date.now(),from:e,to:r,latency:o}),this.notifyUpdate();}subscribe(e){return this.callbacks={...this.callbacks,...e},()=>{this.callbacks={};}}getMetrics(){return {...this.metrics}}notifyUpdate(){this.callbacks.onMetricsUpdate?.(this.getMetrics());}destroy(){this.endSession(),this.callbacks={};}};var je=class{engine=null;video=null;options;isNative=false;animationFrameId=null;isTracking=false;networkDetector=null;powerManager=null;preloadManager=null;analytics=null;cleanupFunctions=[];wasPlayingBeforeOffline=false;wasPlayingBeforeLowBattery=false;constructor(e={}){this.options={enableNetworkAdaptation:true,enablePowerAdaptation:true,enableAnalytics:false,...e},this.isNative=this.shouldUseNative(),this.initializeServices();}static isSupported(){return Ue.isSupported()||Te.isSupported()}attach(e,r,o){this.video=e,this.destroyEngine(),this.setupVideoListeners(),this.analytics&&o&&this.analytics.startSession(o,e);let n=this.getAdaptedConfig();this.isNative?this.engine=new Te({callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture,onQualityChange:i=>{this.options.callbacks?.onQualityChange?.(-1,i);}}}):this.engine=new Ue({config:n,callbacks:{onStateChange:this.options.callbacks?.onStateChange,onError:this.options.callbacks?.onError,onQualityLevelsLoaded:this.options.callbacks?.onQualityLevelsLoaded,onBandwidthUpdate:this.options.callbacks?.onBandwidthUpdate,onQualityChange:(i,a)=>{let u=this.engine?.getQualityLevels()??[],d=i>=0&&i<u.length?u[i]:void 0;this.options.callbacks?.onQualityChange?.(a?-1:i,d);}}}),this.engine.attach(e,r);}loadSource(e,r){if(!this.engine||!this.video)throw new Error("Player not attached to video element");this.analytics&&(this.analytics.endSession(),r&&this.analytics.startSession(r,this.video)),this.engine.loadSource(e);}destroy(){this.destroyEngine(),this.destroyServices();}async play(){return this.video?this.isNative&&this.engine instanceof Te?this.engine.play():pt(this.video,{onNeedsUserGesture:this.options.callbacks?.onNeedsUserGesture}):{success:false,reason:"unknown"}}pause(){this.video?.pause();}async togglePlay(){return this.video?.paused?this.play():(this.pause(),{success:true})}seek(e){if(this.video){let r=this.video.currentTime;this.video.currentTime=Math.max(0,Math.min(e,this.video.duration||0)),this.analytics?.trackSeek(r,e,0);}}seekForward(e=10){this.video&&this.seek(this.video.currentTime+e);}seekBackward(e=10){this.video&&this.seek(this.video.currentTime-e);}getCurrentTime(){return this.video?.currentTime??0}getDuration(){return this.video?.duration??0}setVolume(e){this.video&&(this.video.volume=Math.max(0,Math.min(1,e)));}getVolume(){return this.video?.volume??1}setMuted(e){this.video&&(this.video.muted=e);}isMuted(){return this.video?.muted??true}toggleMute(){this.setMuted(!this.isMuted());}setPlaybackRate(e){this.video&&(this.video.playbackRate=e);}getPlaybackRate(){return this.video?.playbackRate??1}getQualityLevels(){return this.engine?.getQualityLevels()??[]}setQuality(e){let r=this.getCurrentQuality();this.engine?.setQuality(e),r!==e&&this.analytics?.trackQualitySwitch(r,e,e===-1);}getCurrentQuality(){return this.engine?.getCurrentQuality()??-1}isUsingNative(){return this.isNative}getVideoElement(){return this.video}getBuffered(){if(!this.video)return 0;let e=this.video.buffered,r=this.video.currentTime;for(let o=0;o<e.length;o++)if(r>=e.start(o)&&r<=e.end(o))return e.end(o)-r;return 0}getNetworkInfo(){return this.networkDetector?.getInfo()??null}getPowerInfo(){return this.powerManager?.getInfo()??null}getPreloadManager(){return this.preloadManager}getAnalytics(){return this.analytics?.getMetrics()??null}isSlowNetwork(){return this.networkDetector?.isSlowNetwork()??false}isPowerSaving(){return this.powerManager?.isPowerSaving()??false}shouldUseNative(){return this.options.preferNative!==false&&Te.isSupported()?true:!Ue.isSupported()}initializeServices(){if(this.options.enableNetworkAdaptation){this.networkDetector=new Le;let e=this.networkDetector.subscribe({onNetworkChange:this.handleNetworkChange,onOffline:()=>this.options.callbacks?.onError?.(new Error("Network offline"),true)});this.cleanupFunctions.push(e);}if(this.options.enablePowerAdaptation){this.powerManager=new Re;let e=this.powerManager.subscribe({onPowerChange:this.handlePowerChange});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.powerManager?.destroy());}if(this.options.preloadConfig&&(this.preloadManager=new Ie(this.options.preloadConfig),this.cleanupFunctions.push(()=>this.preloadManager?.destroy())),this.options.enableAnalytics){this.analytics=new Me;let e=this.analytics.subscribe({onMetricsUpdate:r=>this.options.callbacks?.onAnalyticsUpdate?.(r)});this.cleanupFunctions.push(e),this.cleanupFunctions.push(()=>this.analytics?.destroy());}}destroyServices(){this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[],this.networkDetector=null,this.powerManager=null,this.preloadManager=null,this.analytics=null;}destroyEngine(){this.stopProgressTracking(),this.removeVideoListeners(),this.engine&&(this.engine.destroy(),this.engine=null);}getAdaptedConfig(){let e={};return this.networkDetector&&(e={...e,...this.networkDetector.getRecommendedConfig()}),this.powerManager&&(e={...e,...this.powerManager.getRecommendedConfig()}),e}isNetworkBelowThreshold(e,r){let o=["slow-2g","2g","3g","4g","5g","unknown"],n=o.indexOf(e),i=o.indexOf(r);return e==="unknown"?false:n>=0&&n<=i}handleNetworkChange=e=>{this.options.callbacks?.onNetworkChange?.(e);let r=this.options.lowQualityThreshold??"2g",o=this.isNetworkBelowThreshold(e.effectiveType,r);this.options.autoQualityOnNetworkChange&&this.engine&&(o?this.setQuality(0):(e.effectiveType==="4g"||e.effectiveType==="5g")&&this.setQuality(-1)),this.options.autoPauseOnOffline&&!e.online&&(this.wasPlayingBeforeOffline=this.video?!this.video.paused:false,this.pause()),this.options.autoResumeOnOnline&&e.online&&this.wasPlayingBeforeOffline&&(this.play(),this.wasPlayingBeforeOffline=false),this.preloadManager&&this.preloadManager.setPaused(e.effectiveType==="2g"||!e.online);};handlePowerChange=e=>{this.options.callbacks?.onPowerChange?.(e);let r=this.options.lowBatteryThreshold??.15,o=e.batteryLevel!==null&&e.batteryLevel<r;this.options.autoPauseOnLowBattery&&o&&!e.isCharging&&(this.wasPlayingBeforeLowBattery=this.video?!this.video.paused:false,this.pause()),this.wasPlayingBeforeLowBattery&&(e.isCharging||e.batteryLevel!==null&&e.batteryLevel>=r+.05)&&(this.play(),this.wasPlayingBeforeLowBattery=false),this.preloadManager&&e.isLowPowerMode&&this.preloadManager.setPaused(true);};setupVideoListeners(){this.video&&(this.video.addEventListener("timeupdate",this.handleTimeUpdate),this.video.addEventListener("progress",this.handleProgress),this.video.addEventListener("volumechange",this.handleVolumeChange),this.video.addEventListener("ratechange",this.handleRateChange),this.video.addEventListener("play",this.handlePlay),this.video.addEventListener("pause",this.handlePause),this.video.addEventListener("ended",this.handleEnded),this.video.addEventListener("waiting",this.handleWaiting),this.video.addEventListener("playing",this.handlePlaying));}removeVideoListeners(){this.video&&(this.video.removeEventListener("timeupdate",this.handleTimeUpdate),this.video.removeEventListener("progress",this.handleProgress),this.video.removeEventListener("volumechange",this.handleVolumeChange),this.video.removeEventListener("ratechange",this.handleRateChange),this.video.removeEventListener("play",this.handlePlay),this.video.removeEventListener("pause",this.handlePause),this.video.removeEventListener("ended",this.handleEnded),this.video.removeEventListener("waiting",this.handleWaiting),this.video.removeEventListener("playing",this.handlePlaying));}handleTimeUpdate=()=>{this.video&&this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0);};handleProgress=()=>{this.options.callbacks?.onProgress?.(this.getBuffered());};handleVolumeChange=()=>{this.video&&this.options.callbacks?.onVolumeChange?.(this.video.volume,this.video.muted);};handleRateChange=()=>{this.video&&this.options.callbacks?.onRateChange?.(this.video.playbackRate);};handlePlay=()=>{this.options.enableSmoothTimeUpdates&&this.startProgressTracking();};handlePause=()=>{this.stopProgressTracking();};handleEnded=()=>{this.stopProgressTracking(),this.analytics&&this.analytics.endSession();};handleWaiting=()=>{this.analytics?.trackBuffering(true);};handlePlaying=()=>{this.analytics?.trackBuffering(false),this.analytics?.trackFirstFrame();};startProgressTracking(){if(this.isTracking||!this.video)return;this.isTracking=true;let e=()=>{if(!this.video||this.video.paused||this.video.ended){this.isTracking=false,this.animationFrameId=null;return}this.options.callbacks?.onTimeUpdate?.(this.video.currentTime,this.video.duration||0),this.animationFrameId=requestAnimationFrame(e);};this.animationFrameId=requestAnimationFrame(e);}stopProgressTracking(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.isTracking=false;}};var No=[{from:"idle",to:"loading"},{from:"loading",to:"ready"},{from:"loading",to:"error"},{from:"ready",to:"playing"},{from:"ready",to:"loading"},{from:"ready",to:"error"},{from:"playing",to:"paused"},{from:"playing",to:"buffering"},{from:"playing",to:"ended"},{from:"playing",to:"error"},{from:"playing",to:"loading"},{from:"paused",to:"playing"},{from:"paused",to:"buffering"},{from:"paused",to:"loading"},{from:"paused",to:"error"},{from:"buffering",to:"playing"},{from:"buffering",to:"paused"},{from:"buffering",to:"stalled"},{from:"buffering",to:"error"},{from:"stalled",to:"playing"},{from:"stalled",to:"buffering"},{from:"stalled",to:"error"},{from:"stalled",to:"loading"},{from:"ended",to:"playing"},{from:"ended",to:"loading"},{from:"ended",to:"idle"},{from:"error",to:"loading"},{from:"error",to:"idle"},{from:"*",to:"idle"}],Wt=class{_state="idle";listeners=new Set;stalledTimeout=null;stalledThreshold=3e3;get state(){return this._state}transition(e){if(!this.canTransition(e))return console.warn(`[PlayerStateMachine] Invalid transition: ${this._state} -> ${e}`),false;let o=this._state;return this._state=e,e==="buffering"?this.startStalledTimer():this.clearStalledTimer(),this.listeners.forEach(n=>n(e,o)),true}canTransition(e){let r=No.find(o=>(o.from===this._state||o.from==="*")&&o.to===e);return !(!r||r.guard&&!r.guard())}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}reset(){this.clearStalledTimer(),this._state="idle";}isPlaying(){return this._state==="playing"}canPlay(){return ["ready","paused","ended"].includes(this._state)}isLoading(){return ["loading","buffering"].includes(this._state)}hasError(){return this._state==="error"}startStalledTimer(){this.clearStalledTimer(),this.stalledTimeout=setTimeout(()=>{this._state==="buffering"&&this.transition("stalled");},this.stalledThreshold);}clearStalledTimer(){this.stalledTimeout&&(clearTimeout(this.stalledTimeout),this.stalledTimeout=null);}};function kr(){return new Wt}function Gt(){let t=useMemo(()=>kr(),[]),[e,r]=useState(t.state);useEffect(()=>t.subscribe(a=>{r(a);}),[t]);let o=useCallback(i=>t.transition(i),[t]),n=useCallback(()=>{t.reset(),r("idle");},[t]);return {state:e,isPlaying:e==="playing",isPaused:e==="paused",isLoading:e==="loading",isBuffering:e==="buffering",isStalled:e==="stalled",isEnded:e==="ended",hasError:e==="error",canPlay:t.canPlay(),transition:o,reset:n}}function ft(t){let{volume:e,isMuted:r,setVolume:o,toggleMute:n,setMuted:i}=Ne();useEffect(()=>{let s=t.current;s&&(s.volume=e,s.muted=r);},[t,e,r]),useEffect(()=>{let s=t.current;if(!s)return;let l=()=>{s.volume!==e&&o(s.volume),s.muted!==r&&i(s.muted);};return s.addEventListener("volumechange",l),()=>s.removeEventListener("volumechange",l)},[t,e,r,o,i]);let a=useCallback(s=>{let l=Math.max(0,Math.min(1,s));o(l),t.current&&(t.current.volume=l),l>0&&r&&(i(false),t.current&&(t.current.muted=false));},[t,r,o,i]),u=useCallback(()=>{n(),t.current&&(t.current.muted=!r);},[t,r,n]),d=useCallback(()=>{r||(i(true),t.current&&(t.current.muted=true));},[t,r,i]),f=useCallback(()=>{r&&(i(false),t.current&&(t.current.muted=false));},[t,r,i]);return {volume:e,isMuted:r,setVolume:a,toggleMute:u,mute:d,unmute:f}}function yt(t,e={}){let{enableSmoothTracking:r=false}=e,[o,n]=useState(0),[i,a]=useState(0),[u,d]=useState(0),[f,s]=useState([]),l=useRef(null),c=useRef(false),y=i>0?o/i*100:0,h=useCallback(p=>{let b=[],v=p.buffered;for(let V=0;V<v.length;V++)b.push({start:v.start(V),end:v.end(V)});s(b);let M=0;for(let V of b)if(p.currentTime>=V.start&&p.currentTime<=V.end){M=V.end-p.currentTime;break}d(M);},[]),m=useCallback(()=>{l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),c.current=false;},[]),P=useCallback(()=>{let p=t.current;if(!p||c.current)return;c.current=true;let b=()=>{if(!p||p.paused||p.ended){c.current=false,l.current=null;return}n(p.currentTime),l.current=requestAnimationFrame(b);};l.current=requestAnimationFrame(b);},[t]);useEffect(()=>{let p=t.current;if(!p)return;let b=()=>{n(p.currentTime);},v=()=>{a(p.duration||0);},M=()=>{a(p.duration||0);},V=()=>{h(p);},D=()=>{r&&P();},A=()=>{m();},_=()=>{m();},U=()=>{n(p.currentTime);},g=()=>{n(p.currentTime),h(p);};return p.addEventListener("timeupdate",b),p.addEventListener("loadedmetadata",v),p.addEventListener("durationchange",M),p.addEventListener("progress",V),p.addEventListener("play",D),p.addEventListener("pause",A),p.addEventListener("ended",_),p.addEventListener("seeking",U),p.addEventListener("seeked",g),p.readyState>=1&&(a(p.duration||0),n(p.currentTime)),p.readyState>=3&&h(p),!p.paused&&r&&P(),()=>{p.removeEventListener("timeupdate",b),p.removeEventListener("loadedmetadata",v),p.removeEventListener("durationchange",M),p.removeEventListener("progress",V),p.removeEventListener("play",D),p.removeEventListener("pause",A),p.removeEventListener("ended",_),p.removeEventListener("seeking",U),p.removeEventListener("seeked",g),m();}},[t,r,h,P,m]);let S=useCallback(p=>{let b=t.current;if(!b||!isFinite(b.duration))return;let v=Math.max(0,Math.min(p,b.duration));b.currentTime=v,n(v);},[t]),L=useCallback(p=>{let b=t.current;if(!b||!isFinite(b.duration))return;let M=Math.max(0,Math.min(100,p))/100*b.duration;b.currentTime=M,n(M);},[t]),H=i>0&&isFinite(i);return {currentTime:o,duration:i,buffered:u,progress:y,bufferedRanges:f,seek:S,seekToProgress:L,isSeekable:H,startSmoothTracking:P,stopSmoothTracking:m}}function gt(t){let{quality:e,setQuality:r}=Ne(),[o,n]=useState(-1),[i,a]=useState([]);useEffect(()=>{if(!t)return;let s=t.getQualityLevels();a(s),n(t.getCurrentQuality());},[t]),useEffect(()=>{if(!(!t||i.length===0))if(e==="auto")t.setQuality(-1),n(-1);else {let s=parseInt(e.replace("p","")),l=i.findIndex(c=>c.height===s);l!==-1&&(t.setQuality(l),n(l));}},[t,e,i]);let u=o===-1,d=useCallback(s=>{if(t)if(typeof s=="number")if(t.setQuality(s),n(s),s===-1)r("auto");else {let l=i[s];l&&r(`${l.height}p`);}else r(s);},[t,i,r]),f=useCallback(()=>{d("auto");},[d]);return {quality:e,currentLevel:o,availableLevels:i,isAuto:u,setQuality:d,setAuto:f}}function $t(t){return t<1e3?t.toString():t<1e4?`${(t/1e3).toFixed(1)}K`:t<1e6?`${Math.floor(t/1e3)}K`:`${(t/1e6).toFixed(1)}M`}var Xo={position:"absolute",right:spacing[4],bottom:160,display:"flex",flexDirection:"column",alignItems:"center",gap:components.actionBar.gap,zIndex:10},Yo={display:"flex",flexDirection:"column",alignItems:"center",gap:components.actionBar.iconCountGap,background:"none",border:"none",padding:0,cursor:"pointer"},Ko={width:components.actionBar.iconSize,height:components.actionBar.iconSize,display:"flex",alignItems:"center",justifyContent:"center"},jo={fontSize:fontSizes.xs,fontWeight:fontWeights.normal,color:colors.text,textShadow:shadows.text,lineHeight:components.actionBar.counterLineHeight,textAlign:"center"},Zo={display:"flex",flexDirection:"column",alignItems:"center",position:"relative",width:components.profileAction.avatarSize,height:55},Or={width:components.profileAction.avatarSize,height:components.profileAction.avatarSize,borderRadius:"50%",objectFit:"cover",cursor:"pointer",background:colors.surface},Jo={position:"absolute",bottom:0,left:"50%",transform:"translateX(-50%)",width:components.profileAction.followButtonSize,height:components.profileAction.followButtonSize,borderRadius:"50%",backgroundColor:colors.like,border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},en=({filled:t,color:e="white"})=>t?jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:e})}):jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 24 24",fill:"none",children:[jsx("path",{d:"M15.21 5.5C14.7957 5.5 14.46 5.83579 14.46 6.25C14.46 6.66421 14.7957 7 15.21 7C16.819 7 17.996 8.3642 17.996 10.1346C17.996 10.5488 18.3317 10.8846 18.746 10.8846C19.1602 10.8846 19.496 10.5488 19.496 10.1346C19.496 7.7358 17.8342 5.5 15.21 5.5Z",fill:e}),jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.89327 2.25C3.85788 2.25 1.24994 5.6858 1.24994 9.47438C1.24994 13.301 3.5604 16.37 5.9378 18.4936C8.31629 20.6183 10.9036 21.9251 11.7628 22.2115L11.9999 22.2906L12.2371 22.2115C13.0963 21.9251 15.6836 20.6183 18.0621 18.4936C20.4395 16.37 22.7499 13.301 22.7499 9.47438C22.7499 5.6858 20.142 2.25 16.1066 2.25C14.2397 2.25 12.8941 3.06969 11.9999 3.91063C11.1058 3.06969 9.76018 2.25 7.89327 2.25ZM2.74994 9.47438C2.74994 6.3142 4.8731 3.75 7.89327 3.75C9.60588 3.75 10.7397 4.66987 11.4269 5.48383L11.9999 6.16259L12.573 5.48383C13.2602 4.66987 14.394 3.75 16.1066 3.75C19.1268 3.75 21.2499 6.3142 21.2499 9.47438C21.2499 12.6733 19.3104 15.3672 17.0628 17.375C15.0361 19.1854 12.8741 20.3336 11.9999 20.6978C11.1257 20.3336 8.96379 19.1854 6.93708 17.375C4.68948 15.3672 2.74994 12.6733 2.74994 9.47438Z",fill:e})]}),tn=()=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsx("path",{d:"M14 1.45801C7.07347 1.45801 1.45837 7.0731 1.45837 13.9997C1.45837 16.3815 2.1232 18.6107 3.27778 20.5088L2.36541 23.0178C1.77294 24.6471 3.35258 26.2268 4.98188 25.6343L7.49089 24.7219C9.389 25.8765 11.6182 26.5413 14 26.5413C20.9266 26.5413 26.5417 20.9262 26.5417 13.9997C26.5417 7.0731 20.9266 1.45801 14 1.45801Z",fill:"white"})}),rn=({filled:t})=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:components.actionBar.iconSize,height:components.actionBar.iconSize,viewBox:"0 0 28 28",fill:"none",children:jsx("path",{d:"M16.6904 1.45801H11.2789C10.2487 1.458 9.4224 1.45799 8.75434 1.51253C8.06795 1.56857 7.47186 1.68652 6.92253 1.96632C6.90122 1.97718 6.88036 1.98891 6.86 2.00147C5.64436 2.75199 4.94533 3.52276 4.62739 4.64643C4.48015 5.1668 4.42512 5.72644 4.40084 6.3243C4.38332 6.75558 4.3811 7.24294 4.37866 7.77623C4.37775 7.97537 4.37678 8.18091 4.375 8.39232V24.8275C4.375 25.7739 5.14242 26.5413 6.08883 26.5413C6.51994 26.5413 6.93517 26.3792 7.25226 26.0859L13.3276 20.4783C13.3386 20.4682 13.3493 20.4578 13.3597 20.4471C13.5821 20.2197 13.743 20.0895 13.8601 20.0183C13.9156 19.9846 13.9524 19.9697 13.9731 19.9631C13.9833 19.9599 13.9898 19.9585 13.9933 19.958L13.9975 19.9575L13.9992 19.9574C13.9992 19.9574 14.0065 19.9571 14.0257 19.9632C14.0466 19.9698 14.0837 19.9849 14.1394 20.0187C14.2569 20.0901 14.4182 20.2206 14.641 20.4479C14.6512 20.4583 14.6616 20.4684 14.6724 20.4783L20.7477 26.0859C21.0648 26.3792 21.4801 26.5413 21.9112 26.5413C22.8576 26.5413 23.625 25.7739 23.625 24.8275V8.3619C23.625 7.33168 23.625 6.5054 23.5705 5.83735C23.5144 5.15096 23.3965 4.55487 23.1167 4.00554C23.1058 3.98416 23.094 3.96325 23.0814 3.94284C22.3309 2.72781 21.5599 2.0287 20.4364 1.71046C19.9159 1.56305 19.3562 1.50785 18.7583 1.48352C18.3245 1.46588 17.8344 1.46376 17.2978 1.46144C17.1014 1.46059 16.8988 1.45968 16.6904 1.45801Z",fill:t?colors.warning:"white"})}),on=()=>jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:28,height:28,viewBox:"0 0 28 28",fill:"none",children:[jsx("path",{d:"M20.6583 8.99195C21.1139 8.53634 21.1139 7.79765 20.6583 7.34203L14.8249 1.5087C14.6061 1.28991 14.3094 1.16699 14 1.16699C13.6905 1.16699 13.3938 1.28991 13.175 1.5087L7.34167 7.34204C6.88606 7.79765 6.88606 8.53634 7.34167 8.99195C7.79728 9.44756 8.53597 9.44756 8.99158 8.99195L12.8333 5.15024L12.8333 17.5003C12.8333 18.1447 13.3556 18.667 14 18.667C14.6443 18.667 15.1666 18.1447 15.1666 17.5003L15.1666 5.15024L19.0083 8.99195C19.4639 9.44756 20.2026 9.44756 20.6583 8.99195Z",fill:"white"}),jsx("path",{d:"M24.4562 22.2708C24.4991 21.7457 24.5 21.0663 24.5 20.067V16.3337C24.5 15.6893 25.0223 15.167 25.6666 15.167C26.311 15.167 26.8333 15.6893 26.8333 16.3337L26.8333 20.1152C26.8333 21.0543 26.8333 21.8294 26.7817 22.4608C26.7282 23.1166 26.6132 23.7194 26.3247 24.2856C25.8772 25.1637 25.1633 25.8776 24.2852 26.325C23.719 26.6135 23.1162 26.7285 22.4604 26.7821C21.829 26.8337 21.054 26.8337 20.1149 26.8337H7.88508C6.94599 26.8337 6.17087 26.8337 5.5395 26.7821C4.88372 26.7285 4.28089 26.6135 3.71467 26.325C2.83658 25.8776 2.12267 25.1637 1.67526 24.2856C1.38676 23.7194 1.27176 23.1166 1.21819 22.4608C1.1666 21.8294 1.16661 21.0543 1.16663 20.1152V16.3337C1.16663 15.6893 1.68896 15.167 2.33329 15.167C2.97762 15.167 3.49996 15.6893 3.49996 16.3337L3.49996 20.067C3.49996 21.0663 3.50087 21.7457 3.54377 22.2708C3.58556 22.7823 3.66131 23.0438 3.75428 23.2263C3.97798 23.6653 4.33494 24.0223 4.77398 24.246C4.95645 24.339 5.21802 24.4147 5.7295 24.4565C6.25461 24.4994 6.93395 24.5003 7.93329 24.5003H20.0666C21.066 24.5003 21.7453 24.4994 22.2704 24.4565C22.7819 24.4147 23.0435 24.339 23.2259 24.246C23.665 24.0223 24.0219 23.6653 24.2456 23.2263C24.3386 23.0438 24.4144 22.7823 24.4562 22.2708Z",fill:"white"})]}),nn=()=>jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 12 12",fill:"white",children:jsx("path",{d:"M6 1V11M1 6H11",stroke:"white",strokeWidth:2,strokeLinecap:"round"})}),sn=()=>jsx("svg",{width:12,height:12,viewBox:"0 0 12 12",fill:"none",children:jsx("path",{d:"M2 6L5 9L10 3",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})});function an({avatarUrl:t,isFollowed:e=false,onClick:r,onFollow:o}){return jsxs("div",{style:Zo,children:[jsx(motion.button,{style:{background:"none",border:"none",padding:0,cursor:"pointer"},onClick:r,whileTap:{scale:.95},"aria-label":"View profile",children:t?jsx("img",{src:t,alt:"Profile",style:Or}):jsx("div",{style:Or})}),!e&&o&&jsx(motion.button,{style:Jo,onClick:n=>{n.stopPropagation(),o();},whileTap:{scale:.9},animate:e?{scale:[1,1.2,1]}:{scale:1},transition:{type:"spring",...springs.bouncy},"aria-label":e?"Following":"Follow",children:e?jsx(sn,{}):jsx(nn,{})})]})}function vt({icon:t,count:e,isActive:r=false,onClick:o,label:n}){return jsxs(motion.button,{style:Yo,onClick:o,"aria-label":n,whileTap:{scale:.9},transition:{type:"spring",...springs.bouncy},children:[jsx(motion.div,{style:Ko,animate:r?{scale:[1,1.2,1]}:{scale:1},transition:r?{duration:.3,ease:[.32,.72,0,1]}:{type:"spring",...springs.default},children:t}),e!==void 0&&jsx("span",{style:jo,children:$t(e)})]})}function St({likeCount:t,commentCount:e,shareCount:r,saveCount:o,isLiked:n=false,isSaved:i=false,onLike:a,onComment:u,onShare:d,onSave:f,avatarUrl:s,onProfileClick:l,onFollow:c,isFollowed:y=false,style:h,className:m=""}){return jsxs("div",{style:mergeStyles(Xo,h),className:m,children:[s&&jsx(an,{avatarUrl:s,isFollowed:y,onClick:l,onFollow:c}),jsx(vt,{icon:jsx(en,{filled:n,color:n?colors.like:"white"}),count:t,isActive:n,onClick:a,label:n?"Unlike":"Like"}),jsx(vt,{icon:jsx(tn,{}),count:e,onClick:u,label:"Comments"}),jsx(vt,{icon:jsx(rn,{filled:i}),count:o,isActive:i,onClick:f,label:i?"Unsave":"Save"}),jsx(vt,{icon:jsx(on,{}),count:r,onClick:d,label:"Share"})]})}var mn={display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",cursor:"pointer",borderRadius:radii.full,transitionProperty:"background-color, transform, opacity",transitionDuration:durations.fast,transitionTimingFunction:easings.xhubReel,userSelect:"none"},fn={sm:{width:32,height:32},md:{width:components.tapArea,height:components.tapArea},lg:{width:56,height:56}},hn={default:{backgroundColor:colors.surface,color:colors.text},ghost:{backgroundColor:"transparent",color:colors.text},glass:{backgroundColor:"rgba(0, 0, 0, 0.2)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)",color:colors.text}},yn={opacity:.5,cursor:"not-allowed",pointerEvents:"none"},Xt=forwardRef(({icon:t,size:e="md",variant:r="ghost",disabled:o,style:n,className:i="",...a},u)=>jsx("button",{ref:u,type:"button",disabled:o,style:mergeStyles(mn,fn[e],hn[r],o&&yn,n),className:i,...a,children:t}));Xt.displayName="IconButton";var Cn={position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:zIndices.overlay},xn={display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",borderRadius:"50%",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",cursor:"pointer"},kn=({size:t})=>jsx("svg",{width:t*.4,height:t*.4,viewBox:"0 0 24 24",fill:colors.text,children:jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),Tn=({size:t})=>jsxs("svg",{width:t*.35,height:t*.35,viewBox:"0 0 24 24",fill:colors.text,children:[jsx("rect",{x:"6",y:"4",width:"4",height:"16"}),jsx("rect",{x:"14",y:"4",width:"4",height:"16"})]});function wt({isPlaying:t,show:e,onToggle:r,size:o=72,autoHideDelay:n=1e3,showOnStateChange:i=true,style:a,className:u=""}){let[d,f]=useState(false),[s,l]=useState(false),c=e!==void 0,y=c?e:d;useEffect(()=>{if(!(c||!i||!s)&&(f(true),n>0)){let S=setTimeout(()=>{f(false);},n);return ()=>clearTimeout(S)}},[t,c,i,n,s]);let h=useCallback(()=>{r&&(l(true),f(true),r());},[r]),m=!!r,P=m?"auto":"none";return jsx(AnimatePresence,{children:y&&jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},style:mergeStyles(Cn,{pointerEvents:P},a),className:u,onClick:h,children:jsx(motion.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.8,opacity:0},transition:{type:"spring",...springs.default},whileTap:m?{scale:.9}:void 0,style:{...xn,width:o,height:o,cursor:m?"pointer":"default"},children:t?jsx(Tn,{size:o}):jsx(kn,{size:o})})})})}var Hn={position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.6)",zIndex:zIndices.modal},An={position:"fixed",left:0,right:0,bottom:0,backgroundColor:colors.overlay,backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",borderTopLeftRadius:radii.xl,borderTopRightRadius:radii.xl,zIndex:zIndices.modal+1,display:"flex",flexDirection:"column",maxHeight:"90vh"},Fn={width:components.bottomSheet.handleWidth,height:components.bottomSheet.handleHeight,backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:2,margin:"12px auto 0",flexShrink:0},Dn={display:"flex",alignItems:"center",justifyContent:"space-between",padding:`${spacing[4]}px ${spacing[4]}px ${spacing[3]}px`,flexShrink:0},Nn={fontSize:18,fontWeight:600,color:colors.text},Bn={width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",cursor:"pointer",color:colors.textSecondary,borderRadius:"50%"},Un={flex:1,overflow:"auto",WebkitOverflowScrolling:"touch"},_n=()=>jsxs("svg",{width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]});function Qr({isOpen:t,onClose:e,title:r,children:o,height:n="60vh",maxHeight:i="90vh",showClose:a=true,showHandle:u=true,style:d,className:f=""}){let s=useCallback(l=>{l.key==="Escape"&&e();},[e]);return useEffect(()=>(t&&(document.addEventListener("keydown",s),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",s),document.body.style.overflow="";}),[t,s]),jsx(AnimatePresence,{children:t&&jsxs(Fragment,{children:[jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:Hn,onClick:e}),jsxs(motion.div,{initial:{y:"100%"},animate:{y:0},exit:{y:"100%"},transition:{type:"spring",...springs.default},drag:"y",dragConstraints:{top:0,bottom:0},dragElastic:{top:0,bottom:.5},onDragEnd:(l,c)=>{(c.offset.y>100||c.velocity.y>500)&&e();},style:mergeStyles(An,{height:n,maxHeight:i,touchAction:"none"},d),className:f,children:[u&&jsx("div",{style:Fn}),(r||a)&&jsxs("div",{style:Dn,children:[jsx("span",{style:Nn,children:r}),a&&jsx("button",{style:Bn,onClick:e,"aria-label":"Close",children:jsx(_n,{})})]}),jsx("div",{style:Un,children:o})]})]})})}function Wr({size:t=24,color:e=colors.text,thickness:r=2,style:o,className:n=""}){return jsxs(Fragment,{children:[jsx("style",{children:`
|
|
2
2
|
@keyframes xhub-reel-spin {
|
|
3
3
|
to { transform: rotate(360deg); }
|
|
4
4
|
}
|
|
5
|
-
`}),jsx("div",{role:"status","aria-label":"Loading",style:mergeStyles({width:e,height:e,borderWidth:n,borderStyle:"solid",borderColor:`${t}30`,borderTopColor:t,borderRadius:"50%",animation:"xhub-reel-spin 1s linear infinite"},r),className:o})]})}var Hi={position:"fixed",left:spacing[4],right:spacing[4],zIndex:zIndices.toast,display:"flex",justifyContent:"center",pointerEvents:"none"},Di={display:"flex",alignItems:"center",gap:spacing[3],padding:`${spacing[3]}px ${spacing[4]}px`,backgroundColor:colors.surface,borderRadius:radii.lg,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.5)",pointerEvents:"auto",maxWidth:400},Bi={default:{},success:{borderLeft:`3px solid ${colors.success}`},error:{borderLeft:`3px solid ${colors.error}`},warning:{borderLeft:`3px solid ${colors.warning}`}},Ni={flex:1,fontSize:fontSizes.sm,color:colors.text,lineHeight:1.4},_i={padding:`${spacing[1]}px ${spacing[3]}px`,backgroundColor:"transparent",border:"none",color:colors.accent,fontSize:fontSizes.sm,fontWeight:600,cursor:"pointer",borderRadius:radii.sm};function Fn({message:e,isVisible:t,onClose:n,duration:r=3e3,variant:o="default",action:s,position:a="bottom",style:d,className:u=""}){useEffect(()=>{if(t&&r>0){let i=setTimeout(n,r);return ()=>clearTimeout(i)}},[t,r,n]);let h=a==="top"?{top:spacing[4]}:{bottom:spacing[4]+80};return jsx(AnimatePresence,{children:t&&jsx("div",{style:{...Hi,...h},children:jsxs(motion.div,{initial:{opacity:0,y:a==="top"?-20:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:a==="top"?-20:20,scale:.95},transition:{type:"spring",...springs.default},style:mergeStyles(Di,Bi[o],d),className:u,children:[jsx("span",{style:Ni,children:e}),s&&jsx("button",{style:_i,onClick:()=>{s.onClick(),n();},children:s.label})]})})})}var Gi={position:"absolute",pointerEvents:"none",zIndex:zIndices.overlay},$i={filter:"drop-shadow(0 4px 8px rgba(255, 45, 85, 0.5))"};function ht(){let[e,t]=useState(false),[n,r]=useState({x:0,y:0}),o=useCallback((a,d)=>{let u=a??(typeof window<"u"?window.innerWidth/2:200),h=d??(typeof window<"u"?window.innerHeight/2:400);r({x:u,y:h}),t(true),setTimeout(()=>{t(false);},800);},[]),s=useCallback(()=>{t(false);},[]);return {isShowing:e,position:n,showHeart:o,hideHeart:s}}var qi=({size:e,color:t})=>jsx("svg",{style:$i,xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 28 28",fill:t,children:jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:t})});function pt({show:e,position:t={x:0,y:0},size:n=100,color:r=colors.like,showParticles:o=true,particleCount:s=8,onComplete:a,style:d,className:u=""}){return jsx(AnimatePresence,{onExitComplete:a,children:e&&jsxs(motion.div,{initial:{opacity:0,scale:0},animate:{opacity:[0,1,1,0],scale:[0,1.3,1,.8],y:[0,-20,-20,-40]},exit:{scale:0,opacity:0},transition:{duration:.8,times:[0,.2,.6,1],ease:"easeOut"},style:{...Gi,left:t.x-n/2,top:t.y-n/2,width:n,height:n,...d},className:u,children:[jsx(qi,{size:n,color:r}),o&&[...Array(s)].map((h,i)=>jsx(motion.div,{style:{position:"absolute",width:12,height:12,borderRadius:"50%",backgroundColor:r,left:n/2-6,top:n/2-6},initial:{opacity:1,scale:1},animate:{opacity:0,scale:.5,x:Math.cos(i*Math.PI*2/s)*60,y:Math.sin(i*Math.PI*2/s)*60},transition:{duration:.5,delay:.1,ease:"easeOut"}},i))]})})}function Bn(e){let[t,n]=useState(false),r=typeof document<"u"&&!!(document.fullscreenEnabled||document.webkitFullscreenElement!==void 0||document.mozFullScreenElement!==void 0||document.msFullscreenElement!==void 0),o=()=>{let i=document;return i.fullscreenElement||i.webkitFullscreenElement||i.mozFullScreenElement||i.msFullscreenElement||null},s=async i=>{let l=i;l.requestFullscreen?await l.requestFullscreen():l.webkitRequestFullscreen?await l.webkitRequestFullscreen():l.mozRequestFullScreen?await l.mozRequestFullScreen():l.msRequestFullscreen&&await l.msRequestFullscreen();},a=async()=>{let i=document;i.exitFullscreen?await i.exitFullscreen():i.webkitExitFullscreen?await i.webkitExitFullscreen():i.mozCancelFullScreen?await i.mozCancelFullScreen():i.msExitFullscreen&&await i.msExitFullscreen();};useEffect(()=>{let i=()=>{let l=o();n(l===e.current);};return document.addEventListener("fullscreenchange",i),document.addEventListener("webkitfullscreenchange",i),document.addEventListener("mozfullscreenchange",i),document.addEventListener("MSFullscreenChange",i),()=>{document.removeEventListener("fullscreenchange",i),document.removeEventListener("webkitfullscreenchange",i),document.removeEventListener("mozfullscreenchange",i),document.removeEventListener("MSFullscreenChange",i);}},[e]);let d=useCallback(async()=>{let i=e.current;if(!(!i||!r))try{await s(i),n(!0);let l=screen.orientation;if(l?.lock)try{await l.lock("landscape");}catch{}}catch(l){console.error("[useFullscreen] Failed to enter fullscreen:",l);}},[e,r]),u=useCallback(async()=>{if(r)try{await a(),n(!1);let i=screen.orientation;i?.unlock&&i.unlock();}catch(i){console.error("[useFullscreen] Failed to exit fullscreen:",i);}},[r]),h=useCallback(async()=>{t?await u():await d();},[t,d,u]);return {isFullscreen:t,isSupported:r,toggleFullscreen:h,enterFullscreen:d,exitFullscreen:u}}var Ji={feed:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},watch:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},auto:{autoQualitySwitch:true,pauseOnOffline:true,resumeOnOnline:true,lowQualityOn:"2g"},manual:{autoQualitySwitch:false,pauseOnOffline:false,resumeOnOnline:false}},eo={aggressive:{autoPauseOnLowBattery:true,pauseThreshold:.2},moderate:{autoPauseOnLowBattery:true,pauseThreshold:.15},conservative:{autoPauseOnLowBattery:true,pauseThreshold:.1},manual:{autoPauseOnLowBattery:false}};function $e(e,t,n={}){let r=useRef(null),o=useRef(null),s=t??o,[a,d]=useState(false),u=gn(),h=yn(e),i=vn(e),l=bn(r.current),p=Bn(s),f=useRef(n);f.current=n;let{networkBehavior:y,powerBehavior:m}=n,b=useMemo(()=>{if(y)return typeof y=="string"?Ji[y]:y},[y]),S=useMemo(()=>{if(m)return typeof m=="string"?eo[m]:m},[m]),V=useMemo(()=>({onStateChange:g=>{u.transition(g),f.current.onStateChange?.(g),g==="ready"&&!a&&(d(true),f.current.onReady?.());},onError:(g,B)=>{f.current.onError?.(g,B);},onTimeUpdate:(g,B)=>{f.current.onTimeUpdate?.(g,B);},onQualityLevelsLoaded:g=>{f.current.onQualityLevelsLoaded?.(g);},onNetworkChange:g=>{b?.onNetworkChange?.(g),f.current.onNetworkChange?.(g);},onPowerChange:g=>{S?.onPowerChange?.(g),f.current.onPowerChange?.(g);},onAnalyticsUpdate:g=>{f.current.onAnalyticsUpdate?.(g);}}),[u,a,b,S]);useEffect(()=>{let g=e.current;if(!g)return;let B=()=>f.current.onPlay?.(),q=()=>f.current.onPause?.(),oe=()=>f.current.onEnded?.();return g.addEventListener("play",B),g.addEventListener("pause",q),g.addEventListener("ended",oe),()=>{g.removeEventListener("play",B),g.removeEventListener("pause",q),g.removeEventListener("ended",oe);}},[e]);let H=useCallback((g,B)=>{let q=e.current;if(!q){console.error("[usePlayer] No video element");return}d(false),r.current&&r.current.destroy(),r.current=new mn({preferNative:f.current.preferNative,enableSmoothTimeUpdates:f.current.enableSmoothTimeUpdates,enableNetworkAdaptation:f.current.enableNetworkAdaptation,enablePowerAdaptation:f.current.enablePowerAdaptation,enableAnalytics:f.current.enableAnalytics,preloadConfig:f.current.preloadConfig,callbacks:V,autoQualityOnNetworkChange:b?.autoQualitySwitch,autoPauseOnOffline:b?.pauseOnOffline,autoResumeOnOnline:b?.resumeOnOnline,lowQualityThreshold:b?.lowQualityOn,autoPauseOnLowBattery:S?.autoPauseOnLowBattery,lowBatteryThreshold:S?.pauseThreshold}),r.current.attach(q,g,B);},[e,V,b,S]),c=useCallback(()=>{r.current&&(r.current.destroy(),r.current=null),u.reset(),d(false);},[u]),v=useCallback(async()=>{await r.current?.play();},[]),P=useCallback(()=>{r.current?.pause();},[]),x=useCallback(async()=>{await r.current?.togglePlay();},[]),R=useCallback(g=>{r.current?.seek(g);},[]),A=useCallback((g=10)=>{r.current?.seekForward(g);},[]),D=useCallback((g=10)=>{r.current?.seekBackward(g);},[]),z=useCallback(g=>{r.current?.setPlaybackRate(g);},[]),_=useCallback(()=>{let g=e.current;g&&(g.currentTime=0,g.play().catch(()=>{}));},[e]);return {playerCore:r.current,videoRef:e,containerRef:s,state:u,isReady:a,play:v,pause:P,togglePlay:x,seek:R,seekForward:A,seekBackward:D,setPlaybackSpeed:z,restart:_,volume:h,progress:i,quality:l,fullscreen:p,attach:H,destroy:c}}var ro={position:"relative",width:"100%",height:"100%",backgroundColor:colors.background},io={width:"100%",height:"100%",objectFit:"contain"},Ut=forwardRef(({video:e,autoPlay:t=true,muted:n=true,loop:r=true,poster:o,children:s,style:a,className:d="",onPlay:u,onPause:h,onEnded:i,onError:l,onStateChange:p,onTimeUpdate:f,onQualityLevelsLoaded:y,onReady:m},b)=>{let S=useRef(null),V=useRef(null),H=typeof e=="string"?e:e.url,c=o??(typeof e=="object"?e.thumbnail:void 0),v=$e(S,V,{onStateChange:p,onError:P=>l?.(P),onTimeUpdate:f,onQualityLevelsLoaded:y,onPlay:u,onPause:h,onEnded:i,onReady:m});return useEffect(()=>(H&&v.attach(H),()=>{v.destroy();}),[H]),useEffect(()=>{let P=S.current;P&&(P.muted=n,P.loop=r);},[n,r]),useEffect(()=>{let P=S.current;!P||!v.isReady||!t||P.play().catch(x=>{x.name==="NotAllowedError"&&(P.muted=true,P.play().catch(()=>{}));});},[t,v.isReady]),useImperativeHandle(b,()=>({play:v.play,pause:v.pause,togglePlay:v.togglePlay,seek:v.seek,seekForward:v.seekForward,seekBackward:v.seekBackward,restart:v.restart,setVolume:v.volume.setVolume,toggleMute:v.volume.toggleMute,setPlaybackSpeed:v.setPlaybackSpeed,setQuality:v.quality.setQuality,getQualityLevels:()=>v.quality.availableLevels,getVideoElement:()=>S.current,getCurrentTime:()=>v.progress.currentTime,getDuration:()=>v.progress.duration,isPaused:()=>S.current?.paused??true}),[v]),jsxs("div",{ref:V,style:Y(ro,a),className:d,children:[jsx("video",{ref:S,poster:c,playsInline:true,preload:"auto",style:io}),s]})});Ut.displayName="VideoPlayer";var co=30,ho=1e3/co,J={container:{position:"absolute",bottom:0,left:0,right:0,zIndex:zIndices.sticky,touchAction:"none",userSelect:"none",WebkitUserSelect:"none",transition:"all 0.125s ease-in-out"},collapsed:{height:Ne.HEIGHT_DEFAULT,paddingInline:spacing[3],cursor:"pointer"},expanded:{padding:`${spacing[2]}px ${spacing[3]}px`,paddingBottom:`calc(${spacing[1]}px + env(safe-area-inset-bottom, 0px))`,background:"linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%)"},timeContainer:{display:"flex",justifyContent:"center",alignItems:"center",marginBottom:spacing[2]},timeText:{fontSize:fontSizes.sm,fontWeight:fontWeights.semibold,color:colors.text,textShadow:shadows.text,fontVariantNumeric:"tabular-nums",backgroundColor:"rgba(0, 0, 0, 0.6)",padding:`${spacing[1]}px ${spacing[3]}px`,borderRadius:radii.md},track:{position:"relative",width:"100%",backgroundColor:"rgba(255, 255, 255, 0.2)",borderRadius:radii.full,overflow:"hidden"},trackCollapsed:{height:Ne.HEIGHT_DEFAULT},trackExpanded:{height:Ne.HEIGHT_ACTIVE},buffer:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:radii.full},progress:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:colors.text,borderRadius:radii.full},scrubber:{position:"absolute",top:"50%",width:16,height:16,marginLeft:-8,marginTop:-8,backgroundColor:colors.text,borderRadius:radii.full,boxShadow:"0 2px 4px rgba(0,0,0,0.3)",transform:"scale(0)",transition:"transform 150ms ease"},scrubberVisible:{transform:"scale(1)"},touchArea:{position:"absolute",top:-12,left:0,right:0,bottom:-12,cursor:"pointer"}};function ge(e){if(!isFinite(e)||isNaN(e))return "0:00";let t=Math.floor(e/60),n=Math.floor(e%60);return `${t}:${n.toString().padStart(2,"0")}`}function po(e){if(e.buffered.length===0)return 0;for(let t=0;t<e.buffered.length;t++)if(e.buffered.start(t)<=e.currentTime&&e.buffered.end(t)>=e.currentTime)return e.buffered.end(t);return e.buffered.end(e.buffered.length-1)}var ft=forwardRef(({videoRef:e,expanded:t=false,onSeekStart:n,onSeek:r,onSeekEnd:o,onExpandedChange:s,style:a,className:d=""},u)=>{let h=useRef(null),i=useRef(null),l=useRef(null),p=useRef(null),f=useRef(null),y=useRef(0),[m,b]=useState({currentTime:0,duration:0}),S=useRef(null),V=useRef(0),H=useRef(0),c=useRef(false),v=useRef(t);useEffect(()=>{v.current=t;},[t]);let P=useCallback(C=>{let E=e.current;if(!E||c.current)return;let k=E.duration||0,L=E.currentTime||0,O=po(E),Se=k>0?L/k*100:0,w=k>0?O/k*100:0;i.current&&(i.current.style.width=`${Se}%`),l.current&&(l.current.style.width=`${w}%`),p.current&&v.current&&(p.current.style.left=`${Se}%`),y.current=k,f.current&&(f.current.textContent=`${ge(L)} / ${ge(k)}`);let N=C??performance.now();N-H.current>=500&&(H.current=N,b(j=>Math.abs(j.currentTime-L)>=.5||j.duration!==k?{currentTime:Math.floor(L),duration:Math.floor(k)}:j));},[e]),x=useCallback(C=>{C-V.current>=ho&&(V.current=C,P()),S.current=requestAnimationFrame(x);},[P]);useEffect(()=>(S.current=requestAnimationFrame(x),()=>{S.current&&cancelAnimationFrame(S.current);}),[x]);let R=useCallback(C=>{let E=h.current,k=e.current;if(!E||!k)return 0;let L=E.getBoundingClientRect(),O=C-L.left;return Math.max(0,Math.min(1,O/L.width))*(k.duration||0)},[e]),A=useCallback(C=>{c.current=true,n?.();let E=R(C);r?.(E);let k=e.current;if(k&&i.current){let L=k.duration||y.current||1,O=E/L*100;i.current.style.width=`${O}%`,p.current&&(p.current.style.left=`${O}%`),f.current&&(f.current.textContent=`${ge(E)} / ${ge(L)}`);}},[R,r,n,e]),D=useCallback(C=>{if(!c.current)return;let E=R(C);r?.(E);let k=e.current;if(k&&i.current){let L=k.duration||y.current||1,O=E/L*100;i.current.style.width=`${O}%`,p.current&&(p.current.style.left=`${O}%`),f.current&&(f.current.textContent=`${ge(E)} / ${ge(L)}`);}},[R,r,e]),z=useCallback(C=>{if(!c.current)return;c.current=false;let E=R(C);o?.(E);let k=e.current;k&&(k.currentTime=E);},[R,o,e]),_=useCallback(C=>{let E=C.touches[0];E&&A(E.clientX);},[A]),g=useCallback(C=>{let E=C.touches[0];E&&D(E.clientX);},[D]),B=useCallback(C=>{let E=C.changedTouches[0];E&&z(E.clientX);},[z]),q=useCallback(C=>{A(C.clientX);let E=L=>D(L.clientX),k=L=>{z(L.clientX),document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",k);};document.addEventListener("mousemove",E),document.addEventListener("mouseup",k);},[A,D,z]),oe=useCallback(()=>{t||s?.(true);},[t,s]),X=useCallback(C=>{let E=e.current;if(!E)return;let k=E.duration||0,L=E.currentTime||0,O=L;switch(C.key){case "ArrowLeft":O=Math.max(0,L-5);break;case "ArrowRight":O=Math.min(k,L+5);break;case "ArrowUp":O=Math.min(k,L+10);break;case "ArrowDown":O=Math.max(0,L-10);break;case "Home":O=0;break;case "End":O=k;break;default:return}C.preventDefault(),E.currentTime=O,r?.(O),P();},[e,r,P]);useImperativeHandle(u,()=>({update:P,setExpanded:C=>{s?.(C);}}));let $={...J.container,...t?J.expanded:J.collapsed,...a},K={...J.track,...t?J.trackExpanded:J.trackCollapsed},se={...J.scrubber,...t?J.scrubberVisible:{}};return jsxs("div",{ref:h,style:$,className:d,onClick:t?void 0:oe,onTouchStart:_,onTouchMove:g,onTouchEnd:B,onTouchCancel:B,onMouseDown:q,onKeyDown:X,role:"slider","aria-label":"Video progress","aria-valuemin":0,"aria-valuemax":m.duration,"aria-valuenow":m.currentTime,"aria-valuetext":`${ge(m.currentTime)} of ${ge(m.duration)}`,tabIndex:0,children:[t&&jsx("div",{style:J.timeContainer,children:jsx("span",{ref:f,style:J.timeText,children:"0:00 / 0:00"})}),jsxs("div",{style:K,"aria-hidden":"true",children:[jsx("div",{style:J.touchArea}),jsx("div",{ref:l,style:J.buffer}),jsx("div",{ref:i,style:J.progress}),t&&jsx("div",{ref:p,style:se})]})]})});ft.displayName="Timeline";var fo={DOUBLE_TAP_DELAY:200},mo={THRESHOLD:500},qe={VERTICAL_THRESHOLD:.3,HORIZONTAL_THRESHOLD:.4,MIN_VELOCITY:.5},mt={THRESHOLD:10};var ye={TAP_DELAY:fo.DOUBLE_TAP_DELAY,LONG_PRESS_THRESHOLD:mo.THRESHOLD,SWIPE_VERTICAL_THRESHOLD:qe.VERTICAL_THRESHOLD,SWIPE_HORIZONTAL_THRESHOLD:qe.HORIZONTAL_THRESHOLD,DRAG_THRESHOLD:mt.THRESHOLD};function Qn(){return typeof navigator<"u"&&"vibrate"in navigator}function gt(){Qn()&&navigator.vibrate(10);}function zn(){Qn()&&navigator.vibrate(20);}function Wn(e,t){let n=e.currentTarget||e.target;if(!n||typeof n.getBoundingClientRect!="function")return "center";let r=n.getBoundingClientRect(),o=e.clientX-r.left,s=r.width;if(s===0)return "center";let a=s*.33,d=s*.67;return o<a?"left":o>d?"right":"center"}function yt(e){let t=useRef(0),n=useRef("center"),r=useRef(null),o=useRef(null),s=useRef(false),a=useRef(false),d=useRef({x:0,y:0}),u=useCallback(i=>{if(a.current){a.current=false;return}let l=Wn(i),p=Date.now(),f=p-t.current,y={x:i.clientX,y:i.clientY};f<ye.TAP_DELAY&&n.current===l?(r.current&&(clearTimeout(r.current),r.current=null),gt(),e.onDoubleTap?.(l,y)):r.current=setTimeout(()=>{e.onSingleTap?.(l),r.current=null;},ye.TAP_DELAY),t.current=p,n.current=l;},[e]);return useGesture({onPointerDown:({event:i})=>{let l=i;d.current={x:l.clientX,y:l.clientY},a.current=false;let p=setTimeout(()=>{s.current=true,e.onHoldStart?.();},150);o.current=setTimeout(()=>{a.current=true,zn();let y=l.target.getBoundingClientRect();e.onLongPress?.({x:l.clientX-y.left,y:l.clientY-y.top});},ye.LONG_PRESS_THRESHOLD),i.target.dataset.holdTimeout=String(p);},onPointerUp:({event:i})=>{let l=i.target.dataset.holdTimeout;l&&clearTimeout(Number(l)),o.current&&(clearTimeout(o.current),o.current=null),s.current&&(s.current=false,e.onHoldEnd?.());},onPointerMove:({event:i})=>{let l=i,p=Math.abs(l.clientX-d.current.x),f=Math.abs(l.clientY-d.current.y);(p>10||f>10)&&o.current&&(clearTimeout(o.current),o.current=null);},onClick:({event:i})=>{u(i);},onDrag:({movement:[i,l],direction:[p,f],velocity:[y,m],last:b,event:S})=>{if(S.preventDefault(),!b)return;let V=window.innerWidth,H=window.innerHeight;if(Math.abs(l)>H*ye.SWIPE_VERTICAL_THRESHOLD){f>0?e.onSwipeDown?.():e.onSwipeUp?.();return}if(Math.abs(i)>V*ye.SWIPE_HORIZONTAL_THRESHOLD){p>0?e.onSwipeRight?.():e.onSwipeLeft?.();return}Math.abs(i)>ye.DRAG_THRESHOLD&&Math.abs(y)>Math.abs(m)&&e.onSeekDrag?.(i);}},{drag:{threshold:ye.DRAG_THRESHOLD,filterTaps:true},eventOptions:{passive:false}})}var wo=800,Po=.05,Eo=.95;function Qt({onSwipeUp:e,onSwipeDown:t,onSwipeProgress:n,onSwipeCancel:r,threshold:o=qe.VERTICAL_THRESHOLD,velocityThreshold:s=qe.MIN_VELOCITY,hapticEnabled:a=true,disabled:d=false,enableProgressState:u=false}={}){let h=Math.max(Po,Math.min(Eo,o)),[i,l]=useState({progress:0,direction:null,isSwiping:false}),p=useRef({onSwipeUp:e,onSwipeDown:t,onSwipeProgress:n,onSwipeCancel:r}),f=useRef(typeof window<"u"?window.innerHeight:wo);return p.current={onSwipeUp:e,onSwipeDown:t,onSwipeProgress:n,onSwipeCancel:r},useEffect(()=>{let m=()=>{f.current=window.innerHeight;},b=()=>{setTimeout(()=>{f.current=window.innerHeight;},100);};return window.addEventListener("resize",m,{passive:true}),window.addEventListener("orientationchange",b,{passive:true}),()=>{window.removeEventListener("resize",m),window.removeEventListener("orientationchange",b);}},[]),{bind:useDrag(({movement:[,m],velocity:[,b],active:S,cancel:V})=>{if(d){V?.();return}let c=f.current*h,v=Math.min(1,Math.abs(m)/c),P=m<0?"up":"down";if(S)p.current.onSwipeProgress?.(v,P,m),u&&l({progress:v,direction:P,isSwiping:true});else {let x=Math.abs(m)>=c,R=Math.abs(b)>=s;x||R?(a&>(),P==="up"?p.current.onSwipeUp?.():p.current.onSwipeDown?.()):p.current.onSwipeCancel?.(),l({progress:0,direction:null,isSwiping:false});}},{axis:"y",threshold:mt.THRESHOLD,filterTaps:true,pointer:{touch:true},eventOptions:{passive:true}}),...i}}var Oe={container:{position:"relative",width:"100%",height:"100%",backgroundColor:colors.background},video:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"contain"},placeholder:{position:"absolute",inset:0,backgroundSize:"cover",backgroundPosition:"center"},tapArea:{zIndex:zIndices.base},pauseOverlay:{zIndex:zIndices.overlay},pauseIconWrapper:{borderRadius:radii.full,transition:`opacity ${durations.normal}ms ${easings.xhubReel}, transform ${durations.normal}ms ${easings.xhubReel}`}};var zt=createContext(null);function pe(){let e=useContext(zt);if(!e)throw new Error("VideoFeedItem compound components must be used within a VideoFeedItem");return e}function $n({elementRef:e,activateThreshold:t=et.ACTIVATION_THRESHOLD,deactivateThreshold:n=et.DEACTIVATION_THRESHOLD,rootMargin:r="0px",onVisibilityChange:o}){let[s,a]=useState(false),[d,u]=useState(false),[h,i]=useState(0),l=useRef(null);return useEffect(()=>{let p=e.current;if(!p)return;l.current&&l.current.disconnect();let f=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1];return l.current=new IntersectionObserver(y=>{y.forEach(m=>{let b=m.intersectionRatio;i(b),a(b>0),b>=t?u(true):b<n&&u(false),o?.(b>0,b);});},{threshold:f,rootMargin:r}),l.current.observe(p),()=>{l.current?.disconnect();}},[e,t,n,r,o]),{isVisible:s,isActive:d,visibilityRatio:h}}function Yn({containerRef:e,videoRef:t,isCurrentVideo:n=false,onActivate:r,onDeactivate:o,autoActivate:s=true,trackVisibility:a=false,onVisibilityChange:d}){let u=useRef(false),{isVisible:h,isActive:i,visibilityRatio:l}=$n({elementRef:e??{current:null},onVisibilityChange:a?d:void 0}),p=a?i:n;useEffect(()=>{s&&(p&&!u.current?(u.current=true,r?.()):!p&&u.current&&(u.current=false,o?.()));},[p,r,o,s]);let f=useCallback(()=>{let m=t.current;m&&m.play().catch(()=>{m.muted=true,m.play().catch(()=>{});}),r?.();},[t,r]),y=useCallback(()=>{let m=t.current;m&&(m.pause(),m.currentTime=0),o?.();},[t,o]);return {isActive:p,isVisible:a?h:n,visibilityRatio:a?l:n?1:0,activate:f,deactivate:y}}var Gt=class{entries=new Map;listeners=new Set;memoryWarningThreshold;constructor(){this.memoryWarningThreshold=Re.MAX_TOTAL_MEMORY/(1024*1024),this.setupMemoryPressureListener();}register(t,n=10){this.entries.set(t,{videoId:t,inDom:false,hasDecodedFrames:false,estimatedSizeMB:n,lastAccessed:Date.now()}),this.notifyListeners();}unregister(t){this.entries.delete(t),this.notifyListeners();}setInDom(t,n){let r=this.entries.get(t);r&&(r.inDom=n,r.lastAccessed=Date.now(),this.notifyListeners());}setHasDecodedFrames(t,n){let r=this.entries.get(t);r&&(r.hasDecodedFrames=n,r.lastAccessed=Date.now(),this.notifyListeners());}getState(){let t=0,n=0,r=0;return this.entries.forEach(o=>{o.inDom&&t++,o.hasDecodedFrames&&n++,r+=o.estimatedSizeMB;}),{videosInDom:t,decodedVideos:n,estimatedMemoryMB:r,isLowMemory:r>this.memoryWarningThreshold}}getVideosToDispose(){let t=this.getState(),n=[],r=Re?.MAX_VIDEOS_IN_DOM,o=Re?.MAX_DECODED_FRAMES,s=Array.from(this.entries.values()).sort((a,d)=>a.lastAccessed-d.lastAccessed);if(t.videosInDom>r){let a=t.videosInDom-r,d=0;for(let u of s){if(d>=a)break;u.inDom&&(n.push(u.videoId),d++);}}if(t.decodedVideos>o){let a=t.decodedVideos-o,d=0;for(let u of s){if(d>=a)break;u.hasDecodedFrames&&!n.includes(u.videoId)&&(n.push(u.videoId),d++);}}return n}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}forceCleanup(){let t=this.getVideosToDispose();return t.forEach(n=>this.unregister(n)),t}notifyListeners(){let t=this.getState();this.listeners.forEach(n=>n(t));}setupMemoryPressureListener(){typeof window>"u"||"memory"in performance&&setInterval(()=>{this.getState().isLowMemory&&(console.warn("[MemoryManager] Low memory warning, forcing cleanup"),this.forceCleanup());},5e3);}},ve=new Gt;function Zn({videoId:e,estimatedSizeMB:t=10,onShouldDispose:n}){let[r,o]=useState(()=>ve.getState()),[s,a]=useState(false);useEffect(()=>(ve.register(e,t),()=>{ve.unregister(e);}),[e,t]),useEffect(()=>ve.subscribe(i=>{o(i);let p=ve.getVideosToDispose().includes(e);p&&!s?(a(true),n?.()):!p&&s&&a(false);}),[e,s,n]);let d=useCallback(h=>{ve.setInDom(e,h);},[e]),u=useCallback(h=>{ve.setHasDecodedFrames(e,h);},[e]);return {memoryState:r,setInDom:d,setHasDecodedFrames:u,shouldDispose:s}}function er({video:e,isActive:t,priority:n,initialMuted:r=true,onLike:o,onComment:s,onShare:a,onAuthorClick:d}){let u=useRef(null),h=useRef(null),i=useRef(false),[l,p]=useState(false),[f,y]=useState(false),[m,b]=useState(false),{isShowing:S,position:V,showHeart:H}=ht(),c=useMemo(()=>({maxConcurrent:2,maxBufferSize:10*1024*1024,priorityLevels:10}),[]),v=useCallback(w=>{},[]),P=useCallback(w=>{},[]),x=useCallback(w=>{w.startupTime&&w.startupTime>1e3&&console.warn("[VideoFeedItem] Slow startup:",w.startupTime,"ms",e.id);},[e.id]),{state:R}=$e(h,u,{preferNative:true,enableSmoothTimeUpdates:true,networkBehavior:"feed",powerBehavior:"moderate",preloadConfig:c,enableAnalytics:true,onPlay:()=>{p(false),y(false);},onPause:()=>{h.current?.seeking||(p(true),y(true));},onNetworkChange:v,onPowerChange:P,onAnalyticsUpdate:x}),A=useCallback(async()=>{let w=h.current;if(w){w.muted=r;try{await w.play();}catch(N){if(N.name==="NotAllowedError"&&!r){console.warn("[VideoFeedItem] Autoplay blocked, falling back to muted"),w.muted=true;try{await w.play();}catch(j){console.warn("[VideoFeedItem] Play failed even muted:",j.message);}}else console.warn("[VideoFeedItem] Play failed:",N.message);}}},[r]),D=useCallback(()=>{let w=h.current;w&&w.pause();},[]),z=useCallback(w=>{let N=h.current;N&&(N.currentTime=w);},[]),[_,g]=useState(false);useEffect(()=>{let w=h.current;if(!w)return;let N=()=>g(true),j=()=>g(false),Ze=()=>g(false);return w.addEventListener("play",N),w.addEventListener("pause",j),w.addEventListener("ended",Ze),g(!w.paused),()=>{w.removeEventListener("play",N),w.removeEventListener("pause",j),w.removeEventListener("ended",Ze);}},[e.id]);let B=_||R.state==="playing",{setInDom:q,setHasDecodedFrames:oe,shouldDispose:X}=Zn({videoId:e.id,onShouldDispose:()=>{D(),h.current&&(h.current.src="",h.current.load());}}),$=!X&&n!=="none",K=useRef(false);Yn({videoRef:h,isCurrentVideo:t,onActivate:()=>{console.log("[VideoFeedItem] onActivate called, videoRef:",h.current?.src),oe(true),h.current?A():(console.log("[VideoFeedItem] Video element not ready, marking pending play"),K.current=true);},onDeactivate:()=>{console.log("[VideoFeedItem] onDeactivate called"),K.current=false,oe(false),D(),z(0);},autoActivate:true}),useEffect(()=>{h.current&&K.current&&t&&(console.log("[VideoFeedItem] Video element now available, executing pending play"),K.current=false,A());}),useEffect(()=>(q(true),()=>q(false)),[q]),useEffect(()=>{let w=h.current;if(!w)return;b(false);let N=()=>{console.log("[VideoFeedItem] Video loadeddata:",e.id,{isActive:t,priority:n}),n==="high"&&!t?requestAnimationFrame(()=>{w.readyState>=2&&(w.currentTime=.01,b(true),console.log("[VideoFeedItem] First frame decoded (preloaded):",e.id));}):t&&b(true);},j=()=>{n==="high"&&!m&&b(true);};return w.addEventListener("loadeddata",N),w.addEventListener("canplay",j),w.readyState>=2&&N(),()=>{w.removeEventListener("loadeddata",N),w.removeEventListener("canplay",j);}},[e.id,t,n,m]),useEffect(()=>{console.log("[VideoFeedItem] State:",{videoId:e.id,isActive:t,priority:n,shouldRenderVideo:$,hasVideoElement:!!h.current,videoSrc:h.current?.src});},[e.id,t,n,$]);let se=useMemo(()=>{switch(n){case "high":return "auto";case "medium":return "metadata";case "low":case "metadata":return "none";default:return "none"}},[n]),C=useCallback(()=>{i.current=B,y(true),p(false),D();},[B,D]),E=useCallback(w=>{z(w),i.current?(A(),y(false)):p(true);},[z,A]),k=useCallback(()=>{B?D():A();},[B,A,D]),L=useCallback((w,N)=>{H(N.x,N.y),o?.();},[H,o]),O=useCallback(()=>{},[]),Se=yt({onSingleTap:k,onDoubleTap:L,onLongPress:O});return {video:e,isActive:t,shouldRenderVideo:$,preload:se,isPreloaded:m,initialMuted:r,containerRef:u,videoRef:h,isPlaying:B,showPauseOverlay:l,timelineExpanded:f,play:A,pause:D,seek:z,setShowPauseOverlay:p,setTimelineExpanded:y,gestureBindings:Se,showHeart:S,heartPosition:V,triggerHeart:H,onLike:o,onComment:s,onShare:a,onAuthorClick:d,handleSeekStart:C,handleSeekEnd:E}}var St=forwardRef(({placeholder:e,...t},n)=>{let{video:r,videoRef:o,shouldRenderVideo:s,preload:a,isPreloaded:d,initialMuted:u}=pe();if(!s)return e??jsx("div",{...t,style:{...Oe.placeholder,backgroundImage:`url(${r.thumbnail})`,...t.style}});let h=!d;return jsx("video",{ref:i=>{typeof n=="function"?n(i):n&&(n.current=i),o.current=i;},src:r.url,poster:h?r.thumbnail:void 0,preload:a,loop:true,playsInline:true,muted:u,style:Oe.video})});St.displayName="VideoFeedItemPlayer";var wt=forwardRef(({onLike:e,onComment:t,onShare:n,...r},o)=>{let{video:s,onLike:a,onComment:d,onShare:u}=pe();return jsx("div",{ref:o,...r,children:jsx(at,{avatarUrl:s.author.avatar,likeCount:s.stats.likes,commentCount:s.stats.comments,shareCount:s.stats.shares,isLiked:s.isLiked,onLike:e??a,onComment:t??d,onShare:n??u})})});wt.displayName="VideoFeedItemActions";var Pt=forwardRef(({expanded:e,...t},n)=>{let{videoRef:r,shouldRenderVideo:o,timelineExpanded:s,setTimelineExpanded:a,handleSeekStart:d,handleSeekEnd:u}=pe();return o?jsx("div",{ref:n,...t,children:jsx(ft,{videoRef:r,expanded:e??s,onSeekStart:d,onSeekEnd:u,onExpandedChange:a})}):null});Pt.displayName="VideoFeedItemTimeline";var He={container:{position:"absolute",bottom:0,left:0,right:64,padding:spacing[4],paddingBottom:"env(safe-area-inset-bottom, 16px)",zIndex:zIndices.base},containerWithTimeline:{paddingBottom:"calc(env(safe-area-inset-bottom, 16px) + 48px)"},authorButton:{gap:spacing[2],marginBottom:spacing[3]},avatar:{borderRadius:radii.full,border:`2px solid ${colors.text}`},username:{color:colors.text,fontWeight:fontWeights.semibold,fontSize:fontSizes.sm,textShadow:shadows.text},caption:{color:colors.text,fontSize:fontSizes.sm,lineHeight:1.4,textShadow:shadows.text,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:spacing[1]},author:{color:colors.text,fontSize:fontSizes.sm,fontWeight:fontWeights.semibold,textShadow:shadows.text,display:"-webkit-box",WebkitLineClamp:1,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:spacing[1]},hashtags:{display:"flex",flexWrap:"wrap",gap:spacing[1],marginTop:spacing[2],paddingBottom:spacing[1]},hashtag:{color:colors.accent,fontSize:fontSizes.sm,fontWeight:fontWeights.medium,textShadow:shadows.text}};function or({video:e,timelineExpanded:t=false,style:n,className:r=""}){let o=Y(He.container,t&&He.containerWithTimeline,n);return jsxs("div",{style:o,className:r,children:[e.author&&jsx("p",{style:He.author,children:e.author.displayName}),e.caption&&jsx("p",{style:He.caption,children:e.caption}),e.hashtags&&e.hashtags.length>0&&jsx("div",{style:He.hashtags,children:e.hashtags.slice(0,3).map((s,a)=>jsxs("span",{style:He.hashtag,children:["#",s]},a))})]})}var Et=forwardRef(({showPlayPause:e=true,showDoubleTapHeart:t=true,showVideoInfo:n=true,...r},o)=>{let{video:s,isPlaying:a,showPauseOverlay:d,timelineExpanded:u,showHeart:h,heartPosition:i,onAuthorClick:l}=pe();return jsxs("div",{ref:o,...r,children:[e&&jsx(dt,{isPlaying:a,show:d,size:64,autoHideDelay:800,showOnStateChange:false}),t&&jsx(pt,{show:h,position:i,size:100,showParticles:true,particleCount:8}),n&&jsx(or,{video:s,onAuthorClick:l,timelineExpanded:u})]})});Et.displayName="VideoFeedItemOverlay";var Be=forwardRef(({video:e,isActive:t=false,priority:n="none",initialMuted:r=true,showTimeline:o=true,onLike:s,onComment:a,onShare:d,onAuthorClick:u,style:h,className:i="",children:l},p)=>{let f=er({video:e,isActive:t,priority:n,initialMuted:r,onLike:s,onComment:a,onShare:d,onAuthorClick:u}),y=l??jsxs(Fragment,{children:[jsx(St,{}),jsx(Et,{}),jsx(wt,{}),o&&jsx(Pt,{})]});return jsx(zt.Provider,{value:f,children:jsx("div",{ref:m=>{typeof p=="function"?p(m):p&&(p.current=m),f.containerRef.current=m;},style:Y(Oe.container,h),className:i,...f.gestureBindings(),children:y})})});Be.displayName="VideoFeedItem";function sr(e,t){let n=e-t;return n===0||n===-1||n===1?"high":n===2?"medium":n===3?"low":Math.abs(n)<=5?"metadata":"none"}var Bo="cubic-bezier(0.32, 0.72, 0, 1)",No=300,_o=800,Uo=50;function lr({trackRef:e,transitionDuration:t=No,easing:n=Bo,onTransitionEnd:r}){let o=useRef(typeof window<"u"?window.innerHeight:_o),s=useRef(0),a=useRef(null),d=useRef(false),u=useRef(true);useEffect(()=>{let f=()=>{o.current=window.innerHeight;},y=()=>{setTimeout(()=>{o.current=window.innerHeight;},100);};return window.addEventListener("resize",f,{passive:true}),window.addEventListener("orientationchange",y,{passive:true}),()=>{window.removeEventListener("resize",f),window.removeEventListener("orientationchange",y);}},[]);let h=useCallback(f=>{s.current=f,a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{let y=e.current;y&&(y.style.transition="none",y.style.transform=`translateY(${f}px)`),a.current=null;});},[e]),i=useCallback(f=>new Promise(y=>{let m=e.current;if(!m||!u.current){y();return}if(d.current){y();return}d.current=true,s.current=f;let b=null,S=null,V=H=>{H.propertyName==="transform"&&(b?.(),u.current&&(d.current=false,r?.()),y());};b=()=>{m.removeEventListener("transitionend",V),S&&(clearTimeout(S),S=null);},m.addEventListener("transitionend",V),S=setTimeout(()=>{b?.(),u.current&&d.current&&(d.current=false,r?.()),y();},t+Uo),m.offsetHeight,m.style.transition=`transform ${t}ms ${n}`,m.style.transform=`translateY(${f}px)`;}),[e,t,n,r]),l=useCallback(()=>i(0),[i]),p=useCallback(()=>s.current,[]);return useEffect(()=>(u.current=true,()=>{u.current=false,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null);}),[]),{setTranslateY:h,animateTo:i,snapBack:l,getCurrentY:p,viewportHeight:o.current,isAnimating:d.current}}var Wo=300,Go=50,$o=.3,qo="cubic-bezier(0.32, 0.72, 0, 1)",be={container:{position:"fixed",inset:0,overflow:"hidden",backgroundColor:colors.background,touchAction:"none",userSelect:"none",WebkitUserSelect:"none"},track:{position:"relative",width:"100%",height:"100%",willChange:"transform"},slide:{position:"absolute",left:0,width:"100%",height:"100%",backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},loadingIndicator:{position:"absolute",bottom:80,left:0,right:0,display:"flex",justifyContent:"center",zIndex:zIndices.base,pointerEvents:"none"},spinner:{width:24,height:24,borderWidth:2,borderStyle:"solid",borderColor:"rgba(255, 255, 255, 0.3)",borderTopColor:colors.text,borderRadius:radii.full,animation:"xhub-reel-spin 1s linear infinite"}},Ke=forwardRef(({videos:e,initialIndex:t=0,onLoadMore:n,onVideoChange:r,onLike:o,onComment:s,onShare:a,onAuthorClick:d,isLoading:u=false,hasMore:h=false,loadMoreThreshold:i=3,transitionDuration:l=Wo,swipeThreshold:p=Go,velocityThreshold:f=$o,gesturesDisabled:y=false,hapticEnabled:m=true,initialMuted:b=true,style:S,className:V=""},H)=>{let[c,v]=useState(()=>Math.min(Math.max(0,t),Math.max(0,e.length-1))),[P,x]=useState(false),[R,A]=useState(false),D=useRef(null),z=useRef(null),_=useRef(e),g=useRef(c),B=useRef(u),q=useRef(h),oe=useRef(P),{setCurrentIndex:X}=Tt(),{setTranslateY:$,animateTo:K,snapBack:se,viewportHeight:C}=lr({trackRef:z,transitionDuration:l,easing:qo});useEffect(()=>{_.current=e;},[e]),useEffect(()=>{g.current=c;},[c]),useEffect(()=>{B.current=u;},[u]),useEffect(()=>{q.current=h;},[h]),useEffect(()=>{oe.current=P;},[P]),useEffect(()=>{if(e.length===0){v(0);return}if(c>=e.length){let I=e.length-1,U=e[I];v(I),X(I),U&&r?.(U,I);}},[e.length,c,X,r,e]);let E=useCallback(I=>sr(I,c),[c]),k=useCallback(I=>{let U=_.current;q.current&&!B.current&&U.length-I<=i&&n?.();},[i,n]),L=useCallback(async(I,U=true)=>{if(oe.current)return;let F=_.current,M=Math.max(0,Math.min(I,F.length-1)),ae=g.current;if(M===ae){$(0);return}let xe=M>ae?-1:1;if(U){x(true),A(true),await K(xe*C),v(M),X(M),$(0);let we=F[M];we&&r?.(we,M),k(M),A(false),x(false);}else {v(M),X(M),$(0);let we=F[M];we&&(r?.(we,M),k(M));}},[C,K,$,X,r,k]),O=useCallback((I=true)=>{let U=_.current,F=g.current;F<U.length-1&&L(F+1,I);},[L]),Se=useCallback((I=true)=>{let U=g.current;U>0&&L(U-1,I);},[L]),w=useCallback((I,U,F)=>{let M=_.current,ae=g.current,xe=ae>0,we=ae<M.length-1,Kt=F;(U==="down"&&!xe||U==="up"&&!we)&&(Kt*=.3),$(Kt);},[$]),N=useCallback(async()=>{let I=_.current;if(!(g.current<I.length-1)){await se();return}x(true),A(true),await K(-C);let M=g.current+1,ae=_.current;if(M<ae.length){v(M),X(M);let xe=ae[M];xe&&r?.(xe,M),k(M);}$(0),A(false),x(false);},[C,K,se,$,X,r,k]),j=useCallback(async()=>{if(!(g.current>0)){await se();return}x(true),A(true),await K(C);let F=g.current-1;if(F>=0){v(F),X(F);let M=_.current[F];M&&r?.(M,F);}$(0),A(false),x(false);},[C,K,se,$,X,r]),Ze=useCallback(async()=>{await se();},[se]),{bind:cr}=Qt({onSwipeUp:N,onSwipeDown:j,onSwipeProgress:w,onSwipeCancel:Ze,threshold:p/C,velocityThreshold:f,hapticEnabled:m,disabled:y||P,enableProgressState:false});useImperativeHandle(H,()=>({slideTo:L,slideNext:O,slidePrev:Se,get activeIndex(){return g.current},get totalSlides(){return _.current.length},get isBeginning(){return g.current===0},get isEnd(){return g.current===_.current.length-1}})),useEffect(()=>{let I=e[c];I&&r?.(I,c);},[]);let Je=[];if(c>0&&Je.push({index:c-1,position:-1}),Je.push({index:c,position:0}),c<e.length-1&&Je.push({index:c+1,position:1}),e.length===0)return jsx("div",{ref:D,style:Y(be.container,S),className:V,"data-xhub-reel-feed":true,children:u&&jsx("div",{style:{...be.loadingIndicator,top:"50%",bottom:"auto"},children:jsx("div",{style:be.spinner})})});let hr={...be.track};return jsxs("div",{ref:D,...cr(),style:Y(be.container,S),className:V,"data-xhub-reel-feed":true,children:[jsx("style",{children:`
|
|
5
|
+
`}),jsx("div",{role:"status","aria-label":"Loading",style:mergeStyles({width:t,height:t,borderWidth:r,borderStyle:"solid",borderColor:`${e}30`,borderTopColor:e,borderRadius:"50%",animation:"xhub-reel-spin 1s linear infinite"},o),className:n})]})}var Jn={position:"fixed",left:spacing[4],right:spacing[4],zIndex:zIndices.toast,display:"flex",justifyContent:"center",pointerEvents:"none"},ei={display:"flex",alignItems:"center",gap:spacing[3],padding:`${spacing[3]}px ${spacing[4]}px`,backgroundColor:colors.surface,borderRadius:radii.lg,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.5)",pointerEvents:"auto",maxWidth:400},ti={default:{},success:{borderLeft:`3px solid ${colors.success}`},error:{borderLeft:`3px solid ${colors.error}`},warning:{borderLeft:`3px solid ${colors.warning}`}},ri={flex:1,fontSize:fontSizes.sm,color:colors.text,lineHeight:1.4},oi={padding:`${spacing[1]}px ${spacing[3]}px`,backgroundColor:"transparent",border:"none",color:colors.accent,fontSize:fontSizes.sm,fontWeight:600,cursor:"pointer",borderRadius:radii.sm};function qr({message:t,isVisible:e,onClose:r,duration:o=3e3,variant:n="default",action:i,position:a="bottom",style:u,className:d=""}){useEffect(()=>{if(e&&o>0){let s=setTimeout(r,o);return ()=>clearTimeout(s)}},[e,o,r]);let f=a==="top"?{top:spacing[4]}:{bottom:spacing[4]+80};return jsx(AnimatePresence,{children:e&&jsx("div",{style:{...Jn,...f},children:jsxs(motion.div,{initial:{opacity:0,y:a==="top"?-20:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:a==="top"?-20:20,scale:.95},transition:{type:"spring",...springs.default},style:mergeStyles(ei,ti[n],u),className:d,children:[jsx("span",{style:ri,children:t}),i&&jsx("button",{style:oi,onClick:()=>{i.onClick(),r();},children:i.label})]})})})}var li={position:"absolute",pointerEvents:"none",zIndex:zIndices.overlay},ui={filter:"drop-shadow(0 4px 8px rgba(255, 45, 85, 0.5))"};function xt(){let[t,e]=useState(false),[r,o]=useState({x:0,y:0}),n=useCallback((a,u)=>{let d=a??(typeof window<"u"?window.innerWidth/2:200),f=u??(typeof window<"u"?window.innerHeight/2:400);o({x:d,y:f}),e(true),setTimeout(()=>{e(false);},800);},[]),i=useCallback(()=>{e(false);},[]);return {isShowing:t,position:r,showHeart:n,hideHeart:i}}var di=({size:t,color:e})=>jsx("svg",{style:ui,xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 28 28",fill:e,children:jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1.74988 11.0538C1.74988 6.75595 4.69822 2.91699 9.20877 2.91699C11.4347 2.91699 12.9986 3.9593 13.9999 4.96978C15.0011 3.95929 16.565 2.91699 18.791 2.91699C23.3015 2.91699 26.2499 6.75595 26.2499 11.0538C26.2499 15.3962 23.6265 18.9036 20.8781 21.3587C18.1288 23.8145 15.1442 25.3171 14.1843 25.6371L13.9999 25.6985L13.8154 25.6371C12.8555 25.3171 9.87093 23.8145 7.12168 21.3587C4.37329 18.9036 1.74988 15.3962 1.74988 11.0538ZM17.7449 6.41699C17.2617 6.41699 16.8699 6.80874 16.8699 7.29199C16.8699 7.77524 17.2617 8.16699 17.7449 8.16699C19.6221 8.16699 20.9952 9.75855 20.9952 11.8241C20.9952 12.3073 21.387 12.6991 21.8702 12.6991C22.3535 12.6991 22.7452 12.3073 22.7452 11.8241C22.7452 9.02543 20.8066 6.41699 17.7449 6.41699Z",fill:e})});function kt({show:t,position:e={x:0,y:0},size:r=100,color:o=colors.like,showParticles:n=true,particleCount:i=8,onComplete:a,style:u,className:d=""}){return jsx(AnimatePresence,{onExitComplete:a,children:t&&jsxs(motion.div,{initial:{opacity:0,scale:0},animate:{opacity:[0,1,1,0],scale:[0,1.3,1,.8],y:[0,-20,-20,-40]},exit:{scale:0,opacity:0},transition:{duration:.8,times:[0,.2,.6,1],ease:"easeOut"},style:{...li,left:e.x-r/2,top:e.y-r/2,width:r,height:r,...u},className:d,children:[jsx(di,{size:r,color:o}),n&&[...Array(i)].map((f,s)=>jsx(motion.div,{style:{position:"absolute",width:12,height:12,borderRadius:"50%",backgroundColor:o,left:r/2-6,top:r/2-6},initial:{opacity:1,scale:1},animate:{opacity:0,scale:.5,x:Math.cos(s*Math.PI*2/i)*60,y:Math.sin(s*Math.PI*2/i)*60},transition:{duration:.5,delay:.1,ease:"easeOut"}},s))]})})}function jr(t){let[e,r]=useState(false),o=typeof document<"u"&&!!(document.fullscreenEnabled||document.webkitFullscreenElement!==void 0||document.mozFullScreenElement!==void 0||document.msFullscreenElement!==void 0),n=()=>{let s=document;return s.fullscreenElement||s.webkitFullscreenElement||s.mozFullScreenElement||s.msFullscreenElement||null},i=async s=>{let l=s;l.requestFullscreen?await l.requestFullscreen():l.webkitRequestFullscreen?await l.webkitRequestFullscreen():l.mozRequestFullScreen?await l.mozRequestFullScreen():l.msRequestFullscreen&&await l.msRequestFullscreen();},a=async()=>{let s=document;s.exitFullscreen?await s.exitFullscreen():s.webkitExitFullscreen?await s.webkitExitFullscreen():s.mozCancelFullScreen?await s.mozCancelFullScreen():s.msExitFullscreen&&await s.msExitFullscreen();};useEffect(()=>{let s=()=>{let l=n();r(l===t.current);};return document.addEventListener("fullscreenchange",s),document.addEventListener("webkitfullscreenchange",s),document.addEventListener("mozfullscreenchange",s),document.addEventListener("MSFullscreenChange",s),()=>{document.removeEventListener("fullscreenchange",s),document.removeEventListener("webkitfullscreenchange",s),document.removeEventListener("mozfullscreenchange",s),document.removeEventListener("MSFullscreenChange",s);}},[t]);let u=useCallback(async()=>{let s=t.current;if(!(!s||!o))try{await i(s),r(!0);let l=screen.orientation;if(l?.lock)try{await l.lock("landscape");}catch{}}catch(l){console.error("[useFullscreen] Failed to enter fullscreen:",l);}},[t,o]),d=useCallback(async()=>{if(o)try{await a(),r(!1);let s=screen.orientation;s?.unlock&&s.unlock();}catch(s){console.error("[useFullscreen] Failed to exit fullscreen:",s);}},[o]),f=useCallback(async()=>{e?await d():await u();},[e,u,d]);return {isFullscreen:e,isSupported:o,toggleFullscreen:f,enterFullscreen:u,exitFullscreen:d}}var yi={feed:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},watch:{autoQualitySwitch:true,pauseOnOffline:false,resumeOnOnline:false,lowQualityOn:"2g"},auto:{autoQualitySwitch:true,pauseOnOffline:true,resumeOnOnline:true,lowQualityOn:"2g"},manual:{autoQualitySwitch:false,pauseOnOffline:false,resumeOnOnline:false}},gi={aggressive:{autoPauseOnLowBattery:true,pauseThreshold:.2},moderate:{autoPauseOnLowBattery:true,pauseThreshold:.15},conservative:{autoPauseOnLowBattery:true,pauseThreshold:.1},manual:{autoPauseOnLowBattery:false}};function rt(t,e,r={}){let o=useRef(null),n=useRef(null),i=e??n,[a,u]=useState(false),d=Gt(),f=ft(t),s=yt(t),l=gt(o.current),c=jr(i),y=useRef(r);y.current=r;let{networkBehavior:h,powerBehavior:m}=r,P=useMemo(()=>{if(h)return typeof h=="string"?yi[h]:h},[h]),S=useMemo(()=>{if(m)return typeof m=="string"?gi[m]:m},[m]),L=useMemo(()=>({onStateChange:g=>{d.transition(g),y.current.onStateChange?.(g),g==="ready"&&!a&&(u(true),y.current.onReady?.());},onError:(g,B)=>{y.current.onError?.(g,B);},onTimeUpdate:(g,B)=>{y.current.onTimeUpdate?.(g,B);},onQualityLevelsLoaded:g=>{y.current.onQualityLevelsLoaded?.(g);},onNetworkChange:g=>{P?.onNetworkChange?.(g),y.current.onNetworkChange?.(g);},onPowerChange:g=>{S?.onPowerChange?.(g),y.current.onPowerChange?.(g);},onAnalyticsUpdate:g=>{y.current.onAnalyticsUpdate?.(g);}}),[d,a,P,S]);useEffect(()=>{let g=t.current;if(!g)return;let B=()=>y.current.onPlay?.(),Q=()=>y.current.onPause?.(),j=()=>y.current.onEnded?.();return g.addEventListener("play",B),g.addEventListener("pause",Q),g.addEventListener("ended",j),()=>{g.removeEventListener("play",B),g.removeEventListener("pause",Q),g.removeEventListener("ended",j);}},[t]);let H=useCallback((g,B)=>{let Q=t.current;if(!Q){console.error("[usePlayer] No video element");return}u(false),o.current&&o.current.destroy(),o.current=new je({preferNative:y.current.preferNative,enableSmoothTimeUpdates:y.current.enableSmoothTimeUpdates,enableNetworkAdaptation:y.current.enableNetworkAdaptation,enablePowerAdaptation:y.current.enablePowerAdaptation,enableAnalytics:y.current.enableAnalytics,preloadConfig:y.current.preloadConfig,callbacks:L,autoQualityOnNetworkChange:P?.autoQualitySwitch,autoPauseOnOffline:P?.pauseOnOffline,autoResumeOnOnline:P?.resumeOnOnline,lowQualityThreshold:P?.lowQualityOn,autoPauseOnLowBattery:S?.autoPauseOnLowBattery,lowBatteryThreshold:S?.pauseThreshold}),o.current.attach(Q,g,B);},[t,L,P,S]),p=useCallback(()=>{o.current&&(o.current.destroy(),o.current=null),d.reset(),u(false);},[d]),b=useCallback(async()=>{await o.current?.play();},[]),v=useCallback(()=>{o.current?.pause();},[]),M=useCallback(async()=>{await o.current?.togglePlay();},[]),V=useCallback(g=>{o.current?.seek(g);},[]),D=useCallback((g=10)=>{o.current?.seekForward(g);},[]),A=useCallback((g=10)=>{o.current?.seekBackward(g);},[]),_=useCallback(g=>{o.current?.setPlaybackRate(g);},[]),U=useCallback(()=>{let g=t.current;g&&(g.currentTime=0,g.play().catch(()=>{}));},[t]);return {playerCore:o.current,videoRef:t,containerRef:i,state:d,isReady:a,play:b,pause:v,togglePlay:M,seek:V,seekForward:D,seekBackward:A,setPlaybackSpeed:_,restart:U,volume:f,progress:s,quality:l,fullscreen:c,attach:H,destroy:p}}var Si={position:"relative",width:"100%",height:"100%",backgroundColor:colors.background},Pi={width:"100%",height:"100%",objectFit:"contain"},tr=forwardRef(({video:t,autoPlay:e=true,muted:r=true,loop:o=true,poster:n,children:i,style:a,className:u="",onPlay:d,onPause:f,onEnded:s,onError:l,onStateChange:c,onTimeUpdate:y,onQualityLevelsLoaded:h,onReady:m},P)=>{let S=useRef(null),L=useRef(null),H=typeof t=="string"?t:t.url,p=n??(typeof t=="object"?t.thumbnail:void 0),b=rt(S,L,{onStateChange:c,onError:v=>l?.(v),onTimeUpdate:y,onQualityLevelsLoaded:h,onPlay:d,onPause:f,onEnded:s,onReady:m});return useEffect(()=>(H&&b.attach(H),()=>{b.destroy();}),[H]),useEffect(()=>{let v=S.current;v&&(v.muted=r,v.loop=o);},[r,o]),useEffect(()=>{let v=S.current;!v||!b.isReady||!e||v.play().catch(M=>{M.name==="NotAllowedError"&&(v.muted=true,v.play().catch(()=>{}));});},[e,b.isReady]),useImperativeHandle(P,()=>({play:b.play,pause:b.pause,togglePlay:b.togglePlay,seek:b.seek,seekForward:b.seekForward,seekBackward:b.seekBackward,restart:b.restart,setVolume:b.volume.setVolume,toggleMute:b.volume.toggleMute,setPlaybackSpeed:b.setPlaybackSpeed,setQuality:b.quality.setQuality,getQualityLevels:()=>b.quality.availableLevels,getVideoElement:()=>S.current,getCurrentTime:()=>b.progress.currentTime,getDuration:()=>b.progress.duration,isPaused:()=>S.current?.paused??true}),[b]),jsxs("div",{ref:L,style:J(Si,a),className:u,children:[jsx("video",{ref:S,poster:p,playsInline:true,preload:"auto",style:Pi}),i]})});tr.displayName="VideoPlayer";var Ti=30,Li=1e3/Ti,eo=150,$={container:{position:"absolute",bottom:0,left:0,right:0,zIndex:zIndices.sticky,touchAction:"none",userSelect:"none",WebkitUserSelect:"none",transition:"all 0.125s ease-in-out"},collapsed:{height:Xe.HEIGHT_DEFAULT,paddingInline:spacing[3],cursor:"pointer"},expanded:{padding:`${spacing[2]}px ${spacing[3]}px`,paddingBottom:`calc(${spacing[1]}px + env(safe-area-inset-bottom, 0px))`,background:"linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%)"},timeContainer:{display:"flex",justifyContent:"center",alignItems:"center",marginBottom:spacing[2]},timeText:{fontSize:fontSizes.sm,fontWeight:fontWeights.semibold,color:colors.text,textShadow:shadows.text,fontVariantNumeric:"tabular-nums",backgroundColor:"rgba(0, 0, 0, 0.6)",padding:`${spacing[1]}px ${spacing[3]}px`,borderRadius:radii.md},trackWrapper:{position:"relative",width:"100%"},track:{position:"relative",width:"100%",backgroundColor:"rgba(255, 255, 255, 0.2)",borderRadius:radii.full,overflow:"hidden"},trackCollapsed:{height:Xe.HEIGHT_DEFAULT},trackExpanded:{height:Xe.HEIGHT_ACTIVE},buffer:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.3)",borderRadius:radii.full},progress:{position:"absolute",top:0,left:0,height:"100%",backgroundColor:colors.text,borderRadius:radii.full},scrubber:{position:"absolute",top:"50%",width:16,height:16,marginLeft:-8,marginTop:-8,backgroundColor:colors.text,borderRadius:radii.full,boxShadow:"0 2px 4px rgba(0,0,0,0.3)",transform:"scale(0)",transition:"transform 150ms ease"},scrubberVisible:{transform:"scale(1)"},touchArea:{position:"absolute",top:-12,left:0,right:0,bottom:-12,cursor:"pointer"},previewContainer:{position:"absolute",bottom:"100%",marginBottom:spacing[3],transform:"translateX(-50%)",display:"flex",flexDirection:"column",alignItems:"center",gap:spacing[1],pointerEvents:"none",zIndex:zIndices.popover,opacity:0,transition:`opacity ${eo}ms ease, transform ${eo}ms ease`},previewThumbnail:{borderRadius:radii.lg,overflow:"hidden",backgroundColor:"rgba(0, 0, 0, 0.8)",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.4)",border:"2px solid rgba(255, 255, 255, 0.2)"},previewImage:{width:"100%",height:"100%",objectFit:"cover"},previewTime:{fontSize:fontSizes.xs,fontWeight:fontWeights.semibold,color:colors.text,textShadow:shadows.text,fontVariantNumeric:"tabular-nums",backgroundColor:"rgba(0, 0, 0, 0.8)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",padding:`${spacing[1]}px ${spacing[2]}px`,borderRadius:radii.full,whiteSpace:"nowrap"},previewLine:{position:"absolute",bottom:0,width:2,height:spacing[2],backgroundColor:colors.text,borderRadius:radii.full,transform:"translateX(-50%)"}};function ue(t){if(!isFinite(t)||isNaN(t))return "0:00";let e=Math.floor(t/60),r=Math.floor(t%60);return `${e}:${r.toString().padStart(2,"0")}`}function Ri(t){if(t.buffered.length===0)return 0;for(let e=0;e<t.buffered.length;e++)if(t.buffered.start(e)<=t.currentTime&&t.buffered.end(e)>=t.currentTime)return t.buffered.end(e);return t.buffered.end(t.buffered.length-1)}function Ii(t){return Math.max(10,Math.min(90,t))}var Lt=forwardRef(({videoRef:t,expanded:e=false,onSeekStart:r,onSeek:o,onSeekEnd:n,onExpandedChange:i,showPreview:a=false,getThumbnailUrl:u,previewWidth:d=120,previewHeight:f=68,style:s,className:l=""},c)=>{let y=useRef(null),h=useRef(null),m=useRef(null),P=useRef(null),S=useRef(null),L=useRef(0),H=useRef(null),p=useRef(null),b=useRef(null),[v,M]=useState({currentTime:0,duration:0}),V=useRef(null),D=useRef(0),A=useRef(0),_=useRef(false),U=useRef(e);useEffect(()=>{U.current=e;},[e]);let g=useCallback(k=>{let C=t.current;if(!C||_.current)return;let x=C.duration||0,T=C.currentTime||0,w=Ri(C),F=x>0?T/x*100:0,O=x>0?w/x*100:0;h.current&&(h.current.style.width=`${F}%`),m.current&&(m.current.style.width=`${O}%`),P.current&&U.current&&(P.current.style.left=`${F}%`),L.current=x,S.current&&(S.current.textContent=`${ue(T)} / ${ue(x)}`);let R=k??performance.now();R-A.current>=500&&(A.current=R,M(X=>Math.abs(X.currentTime-T)>=.5||X.duration!==x?{currentTime:Math.floor(T),duration:Math.floor(x)}:X));},[t]),B=useCallback(k=>{k-D.current>=Li&&(D.current=k,g()),V.current=requestAnimationFrame(B);},[g]);useEffect(()=>(V.current=requestAnimationFrame(B),()=>{V.current&&cancelAnimationFrame(V.current);}),[B]);let Q=useCallback(k=>{let C=y.current,x=t.current;if(!C||!x)return {time:0,percent:0};let T=C.getBoundingClientRect(),w=k-T.left,F=Math.max(0,Math.min(1,w/T.width));return {time:F*(x.duration||0),percent:F*100}},[t]),j=useCallback((k,C,x)=>{if(!a)return;let T=H.current,w=p.current,F=b.current;if(T)if(x){let O=Ii(C);T.style.left=`${O}%`,T.style.opacity="1",T.style.transform="translateX(-50%) translateY(0)";let R=L.current;if(F&&(F.textContent=`${ue(k)} / ${ue(R)}`),w&&u){let X=u(k);X?(w.src=X,w.style.display="block"):w.style.display="none";}}else T.style.opacity="0",T.style.transform="translateX(-50%) translateY(8px)";},[a,u]),Y=useCallback(k=>{_.current=true,r?.();let{time:C,percent:x}=Q(k);o?.(C);let T=t.current;if(T&&h.current){let w=T.duration||L.current||1;h.current.style.width=`${x}%`,P.current&&(P.current.style.left=`${x}%`),S.current&&(S.current.textContent=`${ue(C)} / ${ue(w)}`);}j(C,x,true);},[Q,o,r,t,j]),z=useCallback(k=>{if(!_.current)return;let{time:C,percent:x}=Q(k);o?.(C);let T=t.current;if(T&&h.current){let w=T.duration||L.current||1;h.current.style.width=`${x}%`,P.current&&(P.current.style.left=`${x}%`),S.current&&(S.current.textContent=`${ue(C)} / ${ue(w)}`);}j(C,x,true);},[Q,o,t,j]),K=useCallback(k=>{if(!_.current)return;_.current=false;let{time:C}=Q(k);n?.(C);let x=t.current;x&&(x.currentTime=C),setTimeout(()=>{j(0,0,false);},100);},[Q,n,t,j]),se=useCallback(k=>{let C=k.touches[0];C&&Y(C.clientX);},[Y]),re=useCallback(k=>{let C=k.touches[0];C&&z(C.clientX);},[z]),Ae=useCallback(k=>{let C=k.changedTouches[0];C&&K(C.clientX);},[K]),ce=useCallback(k=>{Y(k.clientX);let C=T=>z(T.clientX),x=T=>{K(T.clientX),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",x);};document.addEventListener("mousemove",C),document.addEventListener("mouseup",x);},[Y,z,K]),pe=useCallback(()=>{e||i?.(true);},[e,i]),$e=useCallback(k=>{let C=t.current;if(!C)return;let x=C.duration||0,T=C.currentTime||0,w=T;switch(k.key){case "ArrowLeft":w=Math.max(0,T-5);break;case "ArrowRight":w=Math.min(x,T+5);break;case "ArrowUp":w=Math.min(x,T+10);break;case "ArrowDown":w=Math.max(0,T-10);break;case "Home":w=0;break;case "End":w=x;break;default:return}k.preventDefault(),C.currentTime=w,o?.(w),g();},[t,o,g]);useImperativeHandle(c,()=>({update:g,setExpanded:k=>{i?.(k);}}));let qe={...$.container,...e?$.expanded:$.collapsed,...s},E={...$.track,...e?$.trackExpanded:$.trackCollapsed},W={...$.scrubber,...e?$.scrubberVisible:{}},ne={...$.previewThumbnail,width:d,height:f};return jsxs("div",{ref:y,style:qe,className:l,onClick:e?void 0:pe,onTouchStart:se,onTouchMove:re,onTouchEnd:Ae,onTouchCancel:Ae,onMouseDown:ce,onKeyDown:$e,role:"slider","aria-label":"Video progress","aria-valuemin":0,"aria-valuemax":v.duration,"aria-valuenow":v.currentTime,"aria-valuetext":`${ue(v.currentTime)} of ${ue(v.duration)}`,tabIndex:0,children:[e&&jsx("div",{style:$.timeContainer,children:jsx("span",{ref:S,style:$.timeText,children:"0:00 / 0:00"})}),jsxs("div",{style:$.trackWrapper,children:[a&&jsxs("div",{ref:H,style:$.previewContainer,"aria-hidden":"true",children:[u&&jsx("div",{style:ne,children:jsx("img",{ref:p,style:$.previewImage,alt:"Seek preview"})}),jsx("span",{ref:b,style:$.previewTime,children:"0:00 / 0:00"}),jsx("div",{style:$.previewLine})]}),jsxs("div",{style:E,"aria-hidden":"true",children:[jsx("div",{style:$.touchArea}),jsx("div",{ref:m,style:$.buffer}),jsx("div",{ref:h,style:$.progress}),e&&jsx("div",{ref:P,style:W})]})]})]})});Lt.displayName="Timeline";var Mi={DOUBLE_TAP_DELAY:200},Vi={THRESHOLD:500},ot={VERTICAL_THRESHOLD:.3,HORIZONTAL_THRESHOLD:.4,MIN_VELOCITY:.5},Rt={THRESHOLD:10};var Pe={TAP_DELAY:Mi.DOUBLE_TAP_DELAY,LONG_PRESS_THRESHOLD:Vi.THRESHOLD,SWIPE_VERTICAL_THRESHOLD:ot.VERTICAL_THRESHOLD,SWIPE_HORIZONTAL_THRESHOLD:ot.HORIZONTAL_THRESHOLD,DRAG_THRESHOLD:Rt.THRESHOLD};function to(){return typeof navigator<"u"&&"vibrate"in navigator}function It(){to()&&navigator.vibrate(10);}function ro(){to()&&navigator.vibrate(20);}function oo(t,e){let r=t.currentTarget||t.target;if(!r||typeof r.getBoundingClientRect!="function")return "center";let o=r.getBoundingClientRect(),n=t.clientX-o.left,i=o.width;if(i===0)return "center";let a=i*.33,u=i*.67;return n<a?"left":n>u?"right":"center"}function Mt(t){let e=useRef(0),r=useRef("center"),o=useRef(null),n=useRef(null),i=useRef(false),a=useRef(false),u=useRef({x:0,y:0}),d=useCallback(s=>{if(a.current){a.current=false;return}let l=oo(s),c=Date.now(),y=c-e.current,h={x:s.clientX,y:s.clientY};y<Pe.TAP_DELAY&&r.current===l?(o.current&&(clearTimeout(o.current),o.current=null),It(),t.onDoubleTap?.(l,h)):o.current=setTimeout(()=>{t.onSingleTap?.(l),o.current=null;},Pe.TAP_DELAY),e.current=c,r.current=l;},[t]);return useGesture({onPointerDown:({event:s})=>{let l=s;u.current={x:l.clientX,y:l.clientY},a.current=false;let c=setTimeout(()=>{i.current=true,t.onHoldStart?.();},150);n.current=setTimeout(()=>{a.current=true,ro();let h=l.target.getBoundingClientRect();t.onLongPress?.({x:l.clientX-h.left,y:l.clientY-h.top});},Pe.LONG_PRESS_THRESHOLD),s.target.dataset.holdTimeout=String(c);},onPointerUp:({event:s})=>{let l=s.target.dataset.holdTimeout;l&&clearTimeout(Number(l)),n.current&&(clearTimeout(n.current),n.current=null),i.current&&(i.current=false,t.onHoldEnd?.());},onPointerMove:({event:s})=>{let l=s,c=Math.abs(l.clientX-u.current.x),y=Math.abs(l.clientY-u.current.y);(c>10||y>10)&&n.current&&(clearTimeout(n.current),n.current=null);},onClick:({event:s})=>{d(s);},onDrag:({movement:[s,l],direction:[c,y],velocity:[h,m],last:P,event:S})=>{if(S.preventDefault(),!P)return;let L=window.innerWidth,H=window.innerHeight;if(Math.abs(l)>H*Pe.SWIPE_VERTICAL_THRESHOLD){y>0?t.onSwipeDown?.():t.onSwipeUp?.();return}if(Math.abs(s)>L*Pe.SWIPE_HORIZONTAL_THRESHOLD){c>0?t.onSwipeRight?.():t.onSwipeLeft?.();return}Math.abs(s)>Pe.DRAG_THRESHOLD&&Math.abs(h)>Math.abs(m)&&t.onSeekDrag?.(s);}},{drag:{threshold:Pe.DRAG_THRESHOLD,filterTaps:true},eventOptions:{passive:false}})}var Ni=800,Bi=.05,Ui=.95;function rr({onSwipeUp:t,onSwipeDown:e,onSwipeProgress:r,onSwipeCancel:o,threshold:n=ot.VERTICAL_THRESHOLD,velocityThreshold:i=ot.MIN_VELOCITY,hapticEnabled:a=true,disabled:u=false,enableProgressState:d=false}={}){let f=Math.max(Bi,Math.min(Ui,n)),[s,l]=useState({progress:0,direction:null,isSwiping:false}),c=useRef({onSwipeUp:t,onSwipeDown:e,onSwipeProgress:r,onSwipeCancel:o}),y=useRef(typeof window<"u"?window.innerHeight:Ni);return c.current={onSwipeUp:t,onSwipeDown:e,onSwipeProgress:r,onSwipeCancel:o},useEffect(()=>{let m=()=>{y.current=window.innerHeight;},P=()=>{setTimeout(()=>{y.current=window.innerHeight;},100);};return window.addEventListener("resize",m,{passive:true}),window.addEventListener("orientationchange",P,{passive:true}),()=>{window.removeEventListener("resize",m),window.removeEventListener("orientationchange",P);}},[]),{bind:useDrag(({movement:[,m],velocity:[,P],active:S,cancel:L})=>{if(u){L?.();return}let p=y.current*f,b=Math.min(1,Math.abs(m)/p),v=m<0?"up":"down";if(S)c.current.onSwipeProgress?.(b,v,m),d&&l({progress:b,direction:v,isSwiping:true});else {let M=Math.abs(m)>=p,V=Math.abs(P)>=i;M||V?(a&&It(),v==="up"?c.current.onSwipeUp?.():c.current.onSwipeDown?.()):c.current.onSwipeCancel?.(),l({progress:0,direction:null,isSwiping:false});}},{axis:"y",threshold:Rt.THRESHOLD,filterTaps:true,pointer:{touch:true},eventOptions:{passive:true}}),...s}}var we={container:{position:"relative",width:"100%",height:"100%",backgroundColor:colors.background},video:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"contain"},placeholder:{position:"absolute",inset:0,backgroundSize:"contain",backgroundPosition:"center",backgroundRepeat:"no-repeat"},tapArea:{zIndex:zIndices.base},pauseOverlay:{zIndex:zIndices.overlay},pauseIconWrapper:{borderRadius:radii.full,transition:`opacity ${durations.normal}ms ${easings.xhubReel}, transform ${durations.normal}ms ${easings.xhubReel}`}};var or=createContext(null);function ye(){let t=useContext(or);if(!t)throw new Error("VideoFeedItem compound components must be used within a VideoFeedItem");return t}function io({elementRef:t,activateThreshold:e=lt.ACTIVATION_THRESHOLD,deactivateThreshold:r=lt.DEACTIVATION_THRESHOLD,rootMargin:o="0px",onVisibilityChange:n}){let[i,a]=useState(false),[u,d]=useState(false),[f,s]=useState(0),l=useRef(null);return useEffect(()=>{let c=t.current;if(!c)return;l.current&&l.current.disconnect();let y=[0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1];return l.current=new IntersectionObserver(h=>{h.forEach(m=>{let P=m.intersectionRatio;s(P),a(P>0),P>=e?d(true):P<r&&d(false),n?.(P>0,P);});},{threshold:y,rootMargin:o}),l.current.observe(c),()=>{l.current?.disconnect();}},[t,e,r,o,n]),{isVisible:i,isActive:u,visibilityRatio:f}}function ao({containerRef:t,videoRef:e,isCurrentVideo:r=false,onActivate:o,onDeactivate:n,autoActivate:i=true,trackVisibility:a=false,onVisibilityChange:u}){let d=useRef(false),{isVisible:f,isActive:s,visibilityRatio:l}=io({elementRef:t??{current:null},onVisibilityChange:a?u:void 0}),c=a?s:r;useEffect(()=>{i&&(c&&!d.current?(d.current=true,o?.()):!c&&d.current&&(d.current=false,n?.()));},[c,o,n,i]);let y=useCallback(()=>{let m=e.current;m&&m.play().catch(()=>{m.muted=true,m.play().catch(()=>{});}),o?.();},[e,o]),h=useCallback(()=>{let m=e.current;m&&(m.pause(),m.currentTime=0),n?.();},[e,n]);return {isActive:c,isVisible:a?f:r,visibilityRatio:a?l:r?1:0,activate:y,deactivate:h}}var ir=class{entries=new Map;listeners=new Set;memoryWarningThreshold;constructor(){this.memoryWarningThreshold=De.MAX_TOTAL_MEMORY/(1024*1024),this.setupMemoryPressureListener();}register(e,r=10){this.entries.set(e,{videoId:e,inDom:false,hasDecodedFrames:false,estimatedSizeMB:r,lastAccessed:Date.now()}),this.notifyListeners();}unregister(e){this.entries.delete(e),this.notifyListeners();}setInDom(e,r){let o=this.entries.get(e);o&&(o.inDom=r,o.lastAccessed=Date.now(),this.notifyListeners());}setHasDecodedFrames(e,r){let o=this.entries.get(e);o&&(o.hasDecodedFrames=r,o.lastAccessed=Date.now(),this.notifyListeners());}getState(){let e=0,r=0,o=0;return this.entries.forEach(n=>{n.inDom&&e++,n.hasDecodedFrames&&r++,o+=n.estimatedSizeMB;}),{videosInDom:e,decodedVideos:r,estimatedMemoryMB:o,isLowMemory:o>this.memoryWarningThreshold}}getVideosToDispose(){let e=this.getState(),r=[],o=De?.MAX_VIDEOS_IN_DOM,n=De?.MAX_DECODED_FRAMES,i=Array.from(this.entries.values()).sort((a,u)=>a.lastAccessed-u.lastAccessed);if(e.videosInDom>o){let a=e.videosInDom-o,u=0;for(let d of i){if(u>=a)break;d.inDom&&(r.push(d.videoId),u++);}}if(e.decodedVideos>n){let a=e.decodedVideos-n,u=0;for(let d of i){if(u>=a)break;d.hasDecodedFrames&&!r.includes(d.videoId)&&(r.push(d.videoId),u++);}}return r}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}forceCleanup(){let e=this.getVideosToDispose();return e.forEach(r=>this.unregister(r)),e}notifyListeners(){let e=this.getState();this.listeners.forEach(r=>r(e));}setupMemoryPressureListener(){typeof window>"u"||"memory"in performance&&setInterval(()=>{this.getState().isLowMemory&&(console.warn("[MemoryManager] Low memory warning, forcing cleanup"),this.forceCleanup());},5e3);}},Ee=new ir;function po({videoId:t,estimatedSizeMB:e=10,onShouldDispose:r}){let[o,n]=useState(()=>Ee.getState()),[i,a]=useState(false);useEffect(()=>(Ee.register(t,e),()=>{Ee.unregister(t);}),[t,e]),useEffect(()=>Ee.subscribe(s=>{n(s);let c=Ee.getVideosToDispose().includes(t);c&&!i?(a(true),r?.()):!c&&i&&a(false);}),[t,i,r]);let u=useCallback(f=>{Ee.setInDom(t,f);},[t]),d=useCallback(f=>{Ee.setHasDecodedFrames(t,f);},[t]);return {memoryState:o,setInDom:u,setHasDecodedFrames:d,shouldDispose:i}}function fo({video:t,isActive:e,priority:r,initialMuted:o=true,onLike:n,onComment:i,onShare:a,onAuthorClick:u}){let d=useRef(null),f=useRef(null),s=useRef(false),[l,c]=useState(false),[y,h]=useState(false),[m,P]=useState(false),{isShowing:S,position:L,showHeart:H}=xt(),p=useMemo(()=>({maxConcurrent:2,maxBufferSize:10*1024*1024,priorityLevels:10}),[]),b=useCallback(E=>{},[]),v=useCallback(E=>{},[]),M=useCallback(E=>{E.startupTime&&E.startupTime>1e3&&console.warn("[VideoFeedItem] Slow startup:",E.startupTime,"ms",t.id);},[t.id]),{state:V}=rt(f,d,{preferNative:true,enableSmoothTimeUpdates:true,networkBehavior:"feed",powerBehavior:"moderate",preloadConfig:p,enableAnalytics:true,onPlay:()=>{c(false),h(false);},onPause:()=>{f.current?.seeking||(c(true),h(true));},onNetworkChange:b,onPowerChange:v,onAnalyticsUpdate:M}),D=useCallback(async()=>{let E=f.current;if(E){E.muted=o;try{await E.play();}catch(W){if(W.name==="NotAllowedError"&&!o){console.warn("[VideoFeedItem] Autoplay blocked, falling back to muted"),E.muted=true;try{await E.play();}catch(ne){console.warn("[VideoFeedItem] Play failed even muted:",ne.message);}}else console.warn("[VideoFeedItem] Play failed:",W.message);}}},[o]),A=useCallback(()=>{let E=f.current;E&&E.pause();},[]),_=useCallback(E=>{let W=f.current;W&&(W.currentTime=E);},[]),[U,g]=useState(false);useEffect(()=>{let E=f.current;if(!E)return;let W=()=>g(true),ne=()=>g(false),k=()=>g(false);return E.addEventListener("play",W),E.addEventListener("pause",ne),E.addEventListener("ended",k),g(!E.paused),()=>{E.removeEventListener("play",W),E.removeEventListener("pause",ne),E.removeEventListener("ended",k);}},[t.id]);let B=U||V.state==="playing",{setInDom:Q,setHasDecodedFrames:j,shouldDispose:Y}=po({videoId:t.id,onShouldDispose:()=>{A(),f.current&&(f.current.src="",f.current.load());}}),z=!Y&&r!=="none",K=useRef(false);ao({videoRef:f,isCurrentVideo:e,onActivate:()=>{console.log("[VideoFeedItem] onActivate called, videoRef:",f.current?.src),j(true),f.current?D():(console.log("[VideoFeedItem] Video element not ready, marking pending play"),K.current=true);},onDeactivate:()=>{console.log("[VideoFeedItem] onDeactivate called"),K.current=false,j(false),A(),_(0);},autoActivate:true}),useEffect(()=>{f.current&&K.current&&e&&(console.log("[VideoFeedItem] Video element now available, executing pending play"),K.current=false,D());}),useEffect(()=>(Q(true),()=>Q(false)),[Q]),useEffect(()=>{let E=f.current;if(!E)return;P(false);let W=()=>{console.log("[VideoFeedItem] Video loadeddata:",t.id,{isActive:e,priority:r}),r==="high"&&!e?requestAnimationFrame(()=>{E.readyState>=2&&(E.currentTime=.01,P(true),console.log("[VideoFeedItem] First frame decoded (preloaded):",t.id));}):e&&P(true);},ne=()=>{r==="high"&&!m&&P(true);};return E.addEventListener("loadeddata",W),E.addEventListener("canplay",ne),E.readyState>=2&&W(),()=>{E.removeEventListener("loadeddata",W),E.removeEventListener("canplay",ne);}},[t.id,e,r,m]),useEffect(()=>{console.log("[VideoFeedItem] State:",{videoId:t.id,isActive:e,priority:r,shouldRenderVideo:z,hasVideoElement:!!f.current,videoSrc:f.current?.src});},[t.id,e,r,z]);let se=useMemo(()=>{switch(r){case "high":return "auto";case "medium":return "metadata";case "low":case "metadata":return "none";default:return "none"}},[r]),re=useCallback(()=>{s.current=B,h(true),c(false),A();},[B,A]),Ae=useCallback(E=>{_(E),s.current?(D(),h(false)):c(true);},[_,D]),ce=useCallback(()=>{B?A():D();},[B,D,A]),pe=useCallback((E,W)=>{H(W.x,W.y),n?.();},[H,n]),$e=useCallback(()=>{},[]),qe=Mt({onSingleTap:ce,onDoubleTap:pe,onLongPress:$e});return {video:t,isActive:e,priority:r,shouldRenderVideo:z,preload:se,isPreloaded:m,initialMuted:o,containerRef:d,videoRef:f,isPlaying:B,showPauseOverlay:l,timelineExpanded:y,play:D,pause:A,seek:_,setShowPauseOverlay:c,setTimelineExpanded:h,gestureBindings:qe,showHeart:S,heartPosition:L,triggerHeart:H,onLike:n,onComment:i,onShare:a,onAuthorClick:u,handleSeekStart:re,handleSeekEnd:Ae}}var yo=createContext(null);function go(){return useContext(yo)?.pool??null}function vo(){return useContext(yo)?.isReady??false}var Ht=forwardRef(({placeholder:t,forceNative:e=false,...r},o)=>{let{video:n,videoRef:i,shouldRenderVideo:a,preload:u,isPreloaded:d,initialMuted:f,isActive:s,priority:l}=ye(),c=go(),y=vo(),h=useRef(null),m=useRef(null),[P,S]=useState(false),L=useRef(false),H=c&&y&&!e,p=useCallback((v,M)=>{if(!h.current)return false;m.current&&m.current.parentNode&&m.current.parentNode.removeChild(m.current),Object.assign(v.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"contain",zIndex:"1",opacity:M?"1":"0",transition:"opacity 0.15s ease-out"});let V=()=>{v.style.opacity="1",S(false);};return v.readyState>=3?V():v.addEventListener("canplay",V,{once:true}),h.current.appendChild(v),m.current=v,typeof o=="function"?o(v):o&&(o.current=v),i.current=v,true},[o,i]);if(useEffect(()=>{if(!H||!c||!a){S(false),L.current=false;return}let v=n.id,M=n.url,V=c.getElement(v);if(V){let A=c.isReady(v);if(p(V,A)){A||(S(true),c.prepare(v,M,{priority:"high"}).catch(()=>{})),console.log("[VideoFeedItemPlayer] Attached existing element:",v,{isReady:A});return}}if(L.current)return;L.current=true,S(true);let D=s||l==="high"?"high":"medium";return c.prepare(v,M,{priority:D}).then(()=>{let A=c.getElement(v);A&&(p(A,true),console.log("[VideoFeedItemPlayer] Prepared and attached:",v));}).catch(A=>{console.warn("[VideoFeedItemPlayer] Prepare failed:",v,A),S(false);}),()=>{m.current&&m.current.parentNode===h.current&&h.current?.removeChild(m.current),m.current=null,L.current=false;}},[H,c,n.id,n.url,a,s,l,p]),useEffect(()=>{if(!H||!c)return;let v=n.id;s?c.activate(v):c.deactivate(v);},[H,c,n.id,s]),!a)return t??jsx("div",{...r,style:{...we.placeholder,backgroundImage:`url(${n.thumbnail})`,...r.style}});if(H)return jsxs("div",{ref:h,style:{...we.video,position:"relative"},...r,children:[jsx("style",{children:`
|
|
6
|
+
@keyframes xhub-reel-spin {
|
|
7
|
+
to { transform: rotate(360deg); }
|
|
8
|
+
}
|
|
9
|
+
`}),jsx("div",{style:{...we.placeholder,backgroundImage:`url(${n.thumbnail})`,position:"absolute",inset:0,zIndex:0}}),P&&jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:2,pointerEvents:"none"},children:jsx("div",{style:{width:40,height:40,borderWidth:3,borderStyle:"solid",borderColor:"rgba(255, 255, 255, 0.2)",borderTopColor:"#8B5CF6",borderRadius:"50%",animation:"xhub-reel-spin 0.8s linear infinite"}})})]});let b=!d;return jsx("video",{ref:v=>{typeof o=="function"?o(v):o&&(o.current=v),i.current=v;},src:n.url,poster:b?n.thumbnail:void 0,preload:u,loop:true,playsInline:true,muted:f,style:we.video})});Ht.displayName="VideoFeedItemPlayer";var At=forwardRef(({onLike:t,onComment:e,onShare:r,...o},n)=>{let{video:i,onLike:a,onComment:u,onShare:d}=ye();return jsx("div",{ref:n,...o,children:jsx(St,{avatarUrl:i.author.avatar,likeCount:i.stats.likes,commentCount:i.stats.comments,shareCount:i.stats.shares,isLiked:i.isLiked,onLike:t??a,onComment:e??u,onShare:r??d})})});At.displayName="VideoFeedItemActions";var Ft=forwardRef(({expanded:t,showPreview:e=false,getThumbnailUrl:r,previewWidth:o,previewHeight:n,...i},a)=>{let{video:u,videoRef:d,shouldRenderVideo:f,timelineExpanded:s,setTimelineExpanded:l,handleSeekStart:c,handleSeekEnd:y}=ye(),h=useCallback(m=>u.thumbnail||void 0,[u.thumbnail]);return f?jsx("div",{ref:a,...i,children:jsx(Lt,{videoRef:d,expanded:t??s,onSeekStart:c,onSeekEnd:y,onExpandedChange:l,showPreview:e,getThumbnailUrl:r??(e?h:void 0),previewWidth:o,previewHeight:n})}):null});Ft.displayName="VideoFeedItemTimeline";var ze={container:{position:"absolute",bottom:0,left:0,right:64,padding:spacing[4],paddingBottom:"env(safe-area-inset-bottom, 16px)",zIndex:zIndices.base},containerWithTimeline:{paddingBottom:"calc(env(safe-area-inset-bottom, 16px) + 48px)"},authorButton:{gap:spacing[2],marginBottom:spacing[3]},avatar:{borderRadius:radii.full,border:`2px solid ${colors.text}`},username:{color:colors.text,fontWeight:fontWeights.semibold,fontSize:fontSizes.sm,textShadow:shadows.text},caption:{color:colors.text,fontSize:fontSizes.sm,lineHeight:1.4,textShadow:shadows.text,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:spacing[1]},author:{color:colors.text,fontSize:fontSizes.sm,fontWeight:fontWeights.semibold,textShadow:shadows.text,display:"-webkit-box",WebkitLineClamp:1,WebkitBoxOrient:"vertical",overflow:"hidden",paddingBottom:spacing[1]},hashtags:{display:"flex",flexWrap:"wrap",gap:spacing[1],marginTop:spacing[2],paddingBottom:spacing[1]},hashtag:{color:colors.accent,fontSize:fontSizes.sm,fontWeight:fontWeights.medium,textShadow:shadows.text}};function Eo({video:t,timelineExpanded:e=false,style:r,className:o=""}){let n=J(ze.container,e&&ze.containerWithTimeline,r);return jsxs("div",{style:n,className:o,children:[t.author&&jsx("p",{style:ze.author,children:t.author.displayName}),t.caption&&jsx("p",{style:ze.caption,children:t.caption}),t.hashtags&&t.hashtags.length>0&&jsx("div",{style:ze.hashtags,children:t.hashtags.slice(0,3).map((i,a)=>jsxs("span",{style:ze.hashtag,children:["#",i]},a))})]})}var Dt=forwardRef(({showPlayPause:t=true,showDoubleTapHeart:e=true,showVideoInfo:r=true,...o},n)=>{let{video:i,isPlaying:a,showPauseOverlay:u,timelineExpanded:d,showHeart:f,heartPosition:s,onAuthorClick:l}=ye();return jsxs("div",{ref:n,...o,children:[t&&jsx(wt,{isPlaying:a,show:u,size:64,autoHideDelay:800,showOnStateChange:false}),e&&jsx(kt,{show:f,position:s,size:100,showParticles:true,particleCount:8}),r&&jsx(Eo,{video:i,onAuthorClick:l,timelineExpanded:d})]})});Dt.displayName="VideoFeedItemOverlay";var Ge=forwardRef(({video:t,isActive:e=false,priority:r="none",initialMuted:o=true,showTimeline:n=true,onLike:i,onComment:a,onShare:u,onAuthorClick:d,style:f,className:s="",children:l},c)=>{let y=fo({video:t,isActive:e,priority:r,initialMuted:o,onLike:i,onComment:a,onShare:u,onAuthorClick:d}),h=l??jsxs(Fragment,{children:[jsx(Ht,{}),jsx(Dt,{}),jsx(At,{}),n&&jsx(Ft,{})]});return jsx(or.Provider,{value:y,children:jsx("div",{ref:m=>{typeof c=="function"?c(m):c&&(c.current=m),y.containerRef.current=m;},style:J(we.container,f),className:s,...y.gestureBindings(),children:h})})});Ge.displayName="VideoFeedItem";function Co(t,e){let r=t-e;return r===0||r===-1||r===1?"high":r===2?"medium":r===3?"low":Math.abs(r)<=5?"metadata":"none"}var ss="cubic-bezier(0.32, 0.72, 0, 1)",as=300,ls=800,us=50;function ko({trackRef:t,transitionDuration:e=as,easing:r=ss,onTransitionEnd:o}){let n=useRef(typeof window<"u"?window.innerHeight:ls),i=useRef(0),a=useRef(null),u=useRef(false),d=useRef(true);useEffect(()=>{let y=()=>{n.current=window.innerHeight;},h=()=>{setTimeout(()=>{n.current=window.innerHeight;},100);};return window.addEventListener("resize",y,{passive:true}),window.addEventListener("orientationchange",h,{passive:true}),()=>{window.removeEventListener("resize",y),window.removeEventListener("orientationchange",h);}},[]);let f=useCallback(y=>{i.current=y,a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{let h=t.current;h&&(h.style.transition="none",h.style.transform=`translateY(${y}px)`),a.current=null;});},[t]),s=useCallback(y=>new Promise(h=>{let m=t.current;if(!m||!d.current){h();return}if(u.current){h();return}u.current=true,i.current=y;let P=null,S=null,L=H=>{H.propertyName==="transform"&&(P?.(),d.current&&(u.current=false,o?.()),h());};P=()=>{m.removeEventListener("transitionend",L),S&&(clearTimeout(S),S=null);},m.addEventListener("transitionend",L),S=setTimeout(()=>{P?.(),d.current&&u.current&&(u.current=false,o?.()),h();},e+us),m.offsetHeight,m.style.transition=`transform ${e}ms ${r}`,m.style.transform=`translateY(${y}px)`;}),[t,e,r,o]),l=useCallback(()=>s(0),[s]),c=useCallback(()=>i.current,[]);return useEffect(()=>(d.current=true,()=>{d.current=false,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null);}),[]),{setTranslateY:f,animateTo:s,snapBack:l,getCurrentY:c,viewportHeight:n.current,isAnimating:u.current}}var ps=300,ms=50,fs=.3,hs="cubic-bezier(0.32, 0.72, 0, 1)",Ce={container:{position:"fixed",inset:0,overflow:"hidden",backgroundColor:colors.background,touchAction:"none",userSelect:"none",WebkitUserSelect:"none"},track:{position:"relative",width:"100%",height:"100%",willChange:"transform"},slide:{position:"absolute",left:0,width:"100%",height:"100%",backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},loadingIndicator:{position:"absolute",bottom:80,left:0,right:0,display:"flex",justifyContent:"center",zIndex:zIndices.base,pointerEvents:"none"},spinner:{width:24,height:24,borderWidth:2,borderStyle:"solid",borderColor:"rgba(255, 255, 255, 0.3)",borderTopColor:colors.text,borderRadius:radii.full,animation:"xhub-reel-spin 1s linear infinite"}},st=forwardRef(({videos:t,initialIndex:e=0,onLoadMore:r,onVideoChange:o,onLike:n,onComment:i,onShare:a,onAuthorClick:u,isLoading:d=false,hasMore:f=false,loadMoreThreshold:s=3,transitionDuration:l=ps,swipeThreshold:c=ms,velocityThreshold:y=fs,gesturesDisabled:h=false,hapticEnabled:m=true,initialMuted:P=true,style:S,className:L=""},H)=>{let[p,b]=useState(()=>Math.min(Math.max(0,e),Math.max(0,t.length-1))),[v,M]=useState(false),[V,D]=useState(false),A=useRef(null),_=useRef(null),U=useRef(t),g=useRef(p),B=useRef(d),Q=useRef(f),j=useRef(v),{setCurrentIndex:Y}=_t(),{setTranslateY:z,animateTo:K,snapBack:se,viewportHeight:re}=ko({trackRef:_,transitionDuration:l,easing:hs});useEffect(()=>{U.current=t;},[t]),useEffect(()=>{g.current=p;},[p]),useEffect(()=>{B.current=d;},[d]),useEffect(()=>{Q.current=f;},[f]),useEffect(()=>{j.current=v;},[v]),useEffect(()=>{if(t.length===0){b(0);return}if(p>=t.length){let w=t.length-1,F=t[w];b(w),Y(w),F&&o?.(F,w);}},[t.length,p,Y,o,t]);let Ae=useCallback(w=>Co(w,p),[p]),ce=useCallback(w=>{let F=U.current;Q.current&&!B.current&&F.length-w<=s&&r?.();},[s,r]),pe=useCallback(async(w,F=true)=>{if(j.current)return;let O=U.current,R=Math.max(0,Math.min(w,O.length-1)),X=g.current;if(R===X){z(0);return}let Fe=R>X?-1:1;if(F){M(true),D(true),await K(Fe*re),b(R),Y(R),z(0);let xe=O[R];xe&&o?.(xe,R),ce(R),D(false),M(false);}else {b(R),Y(R),z(0);let xe=O[R];xe&&(o?.(xe,R),ce(R));}},[re,K,z,Y,o,ce]),$e=useCallback((w=true)=>{let F=U.current,O=g.current;O<F.length-1&&pe(O+1,w);},[pe]),qe=useCallback((w=true)=>{let F=g.current;F>0&&pe(F-1,w);},[pe]),E=useCallback((w,F,O)=>{let R=U.current,X=g.current,Fe=X>0,xe=X<R.length-1,cr=O;(F==="down"&&!Fe||F==="up"&&!xe)&&(cr*=.3),z(cr);},[z]),W=useCallback(async()=>{let w=U.current;if(!(g.current<w.length-1)){await se();return}M(true),D(true),await K(-re);let R=g.current+1,X=U.current;if(R<X.length){b(R),Y(R);let Fe=X[R];Fe&&o?.(Fe,R),ce(R);}z(0),D(false),M(false);},[re,K,se,z,Y,o,ce]),ne=useCallback(async()=>{if(!(g.current>0)){await se();return}M(true),D(true),await K(re);let O=g.current-1;if(O>=0){b(O),Y(O);let R=U.current[O];R&&o?.(R,O);}z(0),D(false),M(false);},[re,K,se,z,Y,o]),k=useCallback(async()=>{await se();},[se]),{bind:C}=rr({onSwipeUp:W,onSwipeDown:ne,onSwipeProgress:E,onSwipeCancel:k,threshold:c/re,velocityThreshold:y,hapticEnabled:m,disabled:h||v,enableProgressState:false});useImperativeHandle(H,()=>({slideTo:pe,slideNext:$e,slidePrev:qe,get activeIndex(){return g.current},get totalSlides(){return U.current.length},get isBeginning(){return g.current===0},get isEnd(){return g.current===U.current.length-1}})),useEffect(()=>{let w=t[p];w&&o?.(w,p);},[]);let x=[];if(p>0&&x.push({index:p-1,position:-1}),x.push({index:p,position:0}),p<t.length-1&&x.push({index:p+1,position:1}),t.length===0)return jsx("div",{ref:A,style:J(Ce.container,S),className:L,"data-xhub-reel-feed":true,children:d&&jsx("div",{style:{...Ce.loadingIndicator,top:"50%",bottom:"auto"},children:jsx("div",{style:Ce.spinner})})});let T={...Ce.track};return jsxs("div",{ref:A,...C(),style:J(Ce.container,S),className:L,"data-xhub-reel-feed":true,children:[jsx("style",{children:`
|
|
6
10
|
@keyframes xhub-reel-spin {
|
|
7
11
|
to { transform: rotate(360deg); }
|
|
8
12
|
}
|
|
9
|
-
`}),jsx("div",{ref:
|
|
13
|
+
`}),jsx("div",{ref:_,style:T,children:x.map(({index:w,position:F})=>{let O=t[w];if(!O)return null;let R=Ae(w),X=w===p&&!V;return jsx("div",{"data-index":w,style:{...Ce.slide,top:F*re},children:jsx(Ge,{video:O,isActive:X,priority:R,initialMuted:P,onLike:()=>n?.(O),onComment:()=>i?.(O),onShare:()=>a?.(O),onAuthorClick:()=>u?.(O)})},O.id)})}),d&&jsx("div",{style:Ce.loadingIndicator,children:jsx("div",{style:Ce.spinner})})]})});st.displayName="VideoFeed";function dr({videos:t,initialIndex:e=0,onLoadMore:r,hasMore:o=true,isLoading:n=false,onLike:i,onComment:a,onShare:u,onAuthorClick:d,onVideoChange:f,className:s=""}){let l=useRef(null),c=useCallback((S,L)=>{f?.(S,L);},[f]),y=useCallback(S=>{i?.(S);},[i]),h=useCallback(S=>{a?.(S);},[a]),m=useCallback(S=>{u?.(S);},[u]),P=useCallback(S=>{d?.(S);},[d]);return jsx("div",{className:`h-screen w-full overflow-hidden bg-black ${s}`,children:jsx(st,{ref:l,videos:t,initialIndex:e,onLoadMore:r,hasMore:o,isLoading:n,onVideoChange:c,onLike:y,onComment:h,onShare:m,onAuthorClick:P})})}function Lo(t){let{container:e,...r}=t,o=typeof e=="string"?document.querySelector(e):e;if(!o||!(o instanceof HTMLElement))throw new Error("[XHubReelEmbed] Invalid container element");let n=createRoot(o),i=r,a=u=>{i=u,n.render(createElement(dr,u));};return a(r),{updateVideos:u=>{a({...i,videos:u});},destroy:()=>{n.unmount();}}}typeof window<"u"&&(window.XHubReel=Lo);export{St as ActionBar,Qr as BottomSheet,Xt as IconButton,wt as PlayPauseOverlay,Wr as Spinner,qr as Toast,st as VideoFeed,Ge as VideoFeedItem,tr as VideoPlayer,dr as XHubReelEmbed,Lo as createXHubReelEmbed,Mt as useVideoGestures};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xhub-reel/embed",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Embeddable widget for XHubReel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "XHubReel Team",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@xhub-reel/core": "0.2.
|
|
38
|
+
"@xhub-reel/core": "0.2.3",
|
|
39
39
|
"@xhub-reel/design-tokens": "0.0.2",
|
|
40
|
+
"@xhub-reel/feed": "0.2.3",
|
|
40
41
|
"@xhub-reel/gestures": "0.2.0",
|
|
41
|
-
"@xhub-reel/player
|
|
42
|
-
"@xhub-reel/player": "0.
|
|
43
|
-
"@xhub-reel/player-
|
|
44
|
-
"@xhub-reel/feed": "0.2.2",
|
|
42
|
+
"@xhub-reel/player": "0.2.3",
|
|
43
|
+
"@xhub-reel/player-engine": "0.0.3",
|
|
44
|
+
"@xhub-reel/player-core": "0.0.4",
|
|
45
45
|
"@xhub-reel/types": "0.0.2",
|
|
46
|
-
"@xhub-reel/ui": "0.2.
|
|
46
|
+
"@xhub-reel/ui": "0.2.3"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"react": ">=18.0.0",
|