1import{a as C}from"./chunk-3QL42QYE.min.js";import{a as L}from"./chunk-EFXIJJHH.min.js";import{a as I}from"./chunk-U5HAZR6E.min.js";import{d as g,e as D}from"./chunk-PQ6TEFDV.min.js";import{b as w,c as x}from"./chunk-DD3HAZO3.min.js";import"./chunk-KTCF7UDY.min.js";import"./chunk-DPSDMXYX.min.js";import{a as u,b}from"./chunk-7KYGJIQS.min.js";import{c as T,l as k}from"./chunk-HQJI3RMI.min.js";import{S as m,a as p,m as v,q as l,s as S,u as E,v as d,x as y}from"./chunk-4JTI5JCN.min.js";import"./chunk-B2HEEVD7.min.js";var A=t=>m(t),_=class{#e;#t;#i=null;#n=null;config={};#r=new Set;get instance(){return this.#i}constructor(t,i){this.#e=t,this.#t=i}setup(t){let{streamType:i}=this.#t.$state,e=p(i).includes("live"),o=p(i).includes("ll-"),s=this.#i=new t({lowLatencyMode:o,backBufferLength:o?4:e?8:void 0,renderTextTracksNatively:!1,...this.config}),n=c=>(a,h)=>{this.#i===s&&c(a,h)},r=n(this.#h.bind(this));for(let c of Object.values(t.Events))s.on(c,r);s.on(t.Events.ERROR,n(this.#v.bind(this)));for(let c of this.#r)c(s);this.#t.player.dispatch("hls-instance",{detail:s}),s.attachMedia(this.#e),s.on(t.Events.AUDIO_TRACK_SWITCHED,n(this.#l.bind(this))),s.on(t.Events.LEVEL_SWITCHED,n(this.#u.bind(this))),s.on(t.Events.LEVEL_LOADED,n(this.#f.bind(this,s))),s.on(t.Events.LEVEL_UPDATED,n(this.#p.bind(this))),s.on(t.Events.NON_NATIVE_TEXT_TRACKS_FOUND,n(this.#c.bind(this,s))),s.on(t.Events.CUES_PARSED,n(this.#d.bind(this,s))),this.#t.qualities[L.enableAuto]=this.#g.bind(this),y(this.#t.qualities,"change",this.#L.bind(this)),y(this.#t.audioTracks,"change",this.#S.bind(this)),this.#n=E(this.#o.bind(this))}#s(t,i){return new d(A(t),{detail:i})}#o(){if(!this.#t.$state.live())return;let t=new b(this.#a.bind(this));return t.start(),t.stop.bind(t)}#a(){this.#t.$state.liveSyncPosition.set(this.#i?.liveSyncPosition??1/0)}#h(t,i){this.#t.player?.dispatch(this.#s(t,i))}#c(t,i,e){let o=this.#s(i,e),s=-1;for(let n=0;n<e.tracks.length;n++){let r=e.tracks[n],c=r.subtitleTrack??r.closedCaptions,a=new D({id:`hls-${r.kind}-${n}`,src:c?.url,label:r.label,language:c?.lang,kind:r.kind,default:r.default});a[g.readyState]=2,a[g.onModeChange]=()=>{this.#i===t&&(a.mode==="showing"?(t.subtitleTrack=n,s=n):s===n&&(t.subtitleTrack=-1,s=-1))},this.#t.textTracks.add(a,o)}}#d(t,i,e){let o=t.subtitleTrack,s=this.#t.textTracks.getById(`hls-${e.type}-${o}`);if(!s)return;let n=this.#s(i,e);for(let r of e.cues)r.positionAlign="auto",s.addCue(r,n)}#l(t,i){let e=this.#t.audioTracks[i.id];if(e){let o=this.#s(t,i);this.#t.audioTracks[u.select](e,!0,o)}}#u(t,i){let e=this.#t.qualities[i.level];if(e){let o=this.#s(t,i);this.#t.qualities[u.select](e,!0,o)}}#p(t,i){i.details.totalduration>0&&this.#t.$state.inferredLiveDVRWindow.set(i.details.totalduration)}#f(t,i,e){if(this.#t.$state.canPlay())return;let o=t.media;if(!o)return;let{type:s,live:n,totalduration:r,targetduration:c}=e.details,a=this.#s(i,e);this.#t.notify("stream-type-change",n?s==="EVENT"&&Number.isFinite(r)&&c>=10?"live:dvr":"live":"on-demand",a),this.#t.notify("duration-change",r,a),t.currentLevel===-1&&this.#t.qualities[L.setAuto](!0,a);for(let h of t.audioTracks){let f={id:h.id.toString(),label:h.name,language:h.lang||"",kind:"main"};this.#t.audioTracks[u.add](f,a)}for(let h of t.levels){let f={id:h.id?.toString()??h.height+"p",width:h.width,height:h.height,codec:h.codecSet,bitrate:h.bitrate};this.#t.qualities[u.add](f,a)}o.dispatchEvent(new d("canplay",{trigger:a}))}#v(t,i){i.fatal&&(i.type==="mediaError"?this.#i?.recoverMediaError():this.#y(i.error))}#y(t){this.#t.notify("error",{message:t.message,code:1,error:t})}#g(){this.#i&&(this.#i.currentLevel=-1)}#L(){let{qualities:t}=this.#t;!this.#i||t.auto||(this.#i[t.switch+"Level"]=t.selectedIndex,T&&(this.#e.currentTime=this.#e.currentTime))}#S(){let{audioTracks:t}=this.#t;this.#i&&this.#i.audioTrack!==t.selectedIndex&&(this.#i.audioTrack=t.selectedIndex)}onInstance(t){return this.#r.add(t),()=>this.#r.delete(t)}loadSource(t){l(t.src)&&this.#i?.loadSource(t.src)}destroy(){this.#i?.destroy(),this.#i=null,this.#n?.(),this.#n=null}},H=class{#e;#t;#i;constructor(t,i,e){this.#e=t,this.#t=i,this.#i=e,this.#n()}async#n(){let t={onLoadStart:this.#r.bind(this),onLoaded:this.#s.bind(this),onLoadError:this.#o.bind(this)},i=await R(this.#e,t);if(v(i)&&!l(this.#e)&&(i=await $(this.#e,t)),!i)return null;if(!i.isSupported()){let e="[vidstack] `hls.js` is not supported in this environment";
1return this.#t.player.dispatch(new d("hls-unsupported")),this.#t.notify("error",{message:e,code:4}),null}return i}#r(){this.#t.player.dispatch(new d("hls-lib-load-start"))}#s(t){this.#t.player.dispatch(new d("hls-lib-loaded",{detail:t})),this.#i(t)}#o(t){let i=C(t);this.#t.player.dispatch(new d("hls-lib-load-error",{detail:i})),this.#t.notify("error",{message:i.message,code:4,error:i})}};async function $(t,i={}){if(!v(t)){if(i.onLoadStart?.(),t.prototype&&t.prototype!==Function)return i.onLoaded?.(t),t;try{let e=(await t())?.default;if(e&&e.isSupported)i.onLoaded?.(e);else throw Error("");return e}catch(e){i.onLoadError?.(e)}}}async function R(t,i={}){if(l(t)){i.onLoadStart?.();try{if(await x(t),!S(window.Hls))throw Error("");let e=window.Hls;return i.onLoaded?.(e),e}catch(e){i.onLoadError?.(e)}}}var O="https://cdn.jsdelivr.net",Q=class extends I{$$PROVIDER_TYPE="HLS";#e=null;#t=new _(this.video,this.ctx);get ctor(){return this.#e}get instance(){return this.#t.instance}static supported=k();get type(){return"hls"}get canLiveSync(){return!0}#i=`${O}/npm/hls.js@^1.5.0/dist/hls.min.js`;get config(){return this.#t.config}set config(t){this.#t.config=t}get library(){return this.#i}set library(t){this.#i=t}preconnect(){l(this.#i)&&w(this.#i)}setup(){super.setup(),new H(this.#i,this.ctx,t=>{this.#e=t,this.#t.setup(t),this.ctx.notify("provider-setup",this);let i=p(this.ctx.$state.source);i&&this.loadSource(i)})}async loadSource(t,i){if(!l(t.src)){this.removeSource();return}this.media.preload=i||"",this.appendSource(t,"application/x-mpegurl"),this.#t.loadSource(t),this.currentSrc=t}onInstance(t){let i=this.#t.instance;return i&&t(i),this.#t.onInstance(t)}destroy(){this.#t.destroy()}};export{Q as HLSProvider};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.