function e(e,t){for(let n of Object.getOwnPropertyNames(t)){if(n in e.prototype)continue;let r=Object.getOwnPropertyDescriptor(t,n);if(!r)continue;let i={};typeof r.value==`function`?i.value=function(...e){return this.call?.(n,...e)}:r.get&&(i.get=function(){return this.get?.(n)},r.set&&(i.set=function(e){this.set?.(n,e)})),Object.defineProperty(e.prototype,n,i)}}function t(t,n){class r extends t{#e=new n;get(e){return e in this.#e?this.#e[e]:super.get?.(e)}set(e,t){if(e in this.#e){this.#e[e]=t;return}super.set?.(e,t)}call(e,...t){return e in this.#e?this.#e[e](...t):super.call?.(e,...t)}attach(e){super.attach?.(e),this.#e.attach?.(e)}detach(){this.#e.detach?.(),super.detach?.()}}for(let t=n.prototype;t&&t!==Object.prototype;t=Object.getPrototypeOf(t))e(r,t);return r}const n=`abort.canplay.canplaythrough.durationchange.emptied.encrypted.ended.error.loadeddata.loadedmetadata.loadstart.pause.play.playing.progress.ratechange.seeked.seeking.stalled.suspend.timeupdate.volumechange.waiting.waitingforkey.resize.enterpictureinpicture.leavepictureinpicture.webkitbeginfullscreen.webkitendfullscreen.webkitpresentationmodechanged`.split(`.`),r=[`autopictureinpicture`,`disablepictureinpicture`,`disableremoteplayback`,`autoplay`,`controls`,`controlslist`,`crossorigin`,`loop`,`muted`,`playsinline`,`poster`,`preload`,`src`];function i(e){return`
    <style>
      :host {
        display: inline-flex;
        line-height: 0;
        flex-direction: column;
        justify-content: end;
      }

      audio {
        width: 100%;
      }
    </style>
    <slot name="media">
      <audio${c(e)}></audio>
    </slot>
    <slot></slot>
  `}function a(e){return`
    <style>
      :host {
        display: inline-block;
        line-height: 0;
      }

      video {
        max-width: 100%;
        max-height: 100%;
        min-width: 100%;
        min-height: 100%;
        object-fit: var(--media-object-fit, contain);
        object-position: var(--media-object-position, 50% 50%);
      }

      video::-webkit-media-text-track-container {
        transform: var(--media-webkit-text-track-transform);
        transition: var(--media-webkit-text-track-transition);
      }
    </style>
    <slot name="media">
      <video${c(e)}></video>
    </slot>
    <slot></slot>
  `}function o(e,{tag:t,is:o}){let c=globalThis.document?.createElement?.(t,{is:o}),u=c?s(c):[];return class s extends e{static getTemplateHTML=t.endsWith(`audio`)?i:a;static shadowRootOptions={mode:`open`};static Events=n;static#e=!1;static#t;static get observedAttributes(){return s.#n(),[...c?.constructor?.observedAttributes??[],...r]}static#n(){if(!s.#e){s.#e=!0,s.#t=new Set(s.observedAttributes),s.#t.delete(`muted`);for(let e of u)if(!(e in s.prototype))if(typeof c[e]==`function`)s.prototype[e]=function(...t){return this.#s(),this.call(e,...t)};else{let t={get(){return this.#s(),this.get(e)}};e!==e.toUpperCase()&&(t.set=function(t){this.#s(),this.set(e,t)}),Object.defineProperty(s.prototype,e,t)}}}#r=!1;#i=null;#a=new Map;#o;get(e){let t=e.toLowerCase();if(s.#t.has(t)){let e=this.getAttribute(t);return e===null?!1:e===``?!0:e}return this.target?.[e]}set(e,t){let n=e.toLowerCase();if(s.#t.has(n)){t===!0||t===!1||t==null?this.toggleAttribute(n,!!t):this.setAttribute(n,t);return}this.target&&(this.target[e]=t)}call(e,...t){return(this.target?.[e])?.apply(this.target,t)}get target(){return this.#s(),this.#i??this.querySelector(`:scope > [slot=media]`)??this.querySelector(t)??this.shadowRoot?.querySelector(t)??null}set target(e){this.#i=e}get defaultMuted(){return this.#s(),this.get(`muted`)}set defaultMuted(e){this.#s(),this.set(`muted`,e)}#s(){this.#r||(this.#r=!0,this.init())}init(){if(!this.shadowRoot){this.attachShadow({mode:`open`});let e=l(this.attributes);o&&(e.is=o),t&&(e.part=t),this.shadowRoot.innerHTML=this.constructor.getTemplateHTML(e)}this.target.muted=this.hasAttribute(`muted`);for(let e of u)this.#d(e);this.#o=new MutationObserver(this.#l.bind(this)),this.shadowRoot.addEventListener(`slotchange`,()=>this.#c()),this.#c();for(let e of this.constructor.Events)this.shadowRoot.addEventListener(e,this,!0)}handleEvent(e){e.target===this.target&&this.dispatchEvent(new CustomEvent(e.type,{detail:e.detail}))}#c(){let e=new Map(this.#a);((this.shadowRoot?.querySelector(`slot:not([name])`))?.assignedElements({flatten:!0}).filter(e=>[`track`,`source`].includes(e.localName))).forEach(t=>{e.delete(t);let n=this.#a.get(t);n||(n=t.cloneNode(),this.#a.set(t,n),this.#o?.observe(t,{attributes:!0})),this.target?.append(n),this.#u(n)}),e.forEach((e,t)=>{e.remove(),this.#a.delete(t)})}#l(e){for(let t of e)if(t.type===`attributes`){let{target:e,attributeName:n}=t,r=this.#a.get(e);r&&n&&(r.setAttribute(n,e.getAttribute(n)??``),this.#u(r))}}#u(e){e&&e.localName===`track`&&e.default&&(e.kind===`chapters`||e.kind===`metadata`)&&e.track.mode===`disabled`&&(e.track.mode=`hidden`)}#d(e){if(Object.hasOwn(this,e)){let t=this[e];delete this[e],this[e]=t}}attributeChangedCallback(e,t,n){this.#s(),this.#f(e,t,n)}#f(e,t,n){[`id`,`class`].includes(e)||!s.observedAttributes.includes(e)&&this.constructor.observedAttributes.includes(e)||(n===null?this.target?.removeAttribute(e):this.target?.getAttribute(e)!==n&&this.target?.setAttribute(e,n))}connectedCallback(){this.#s()}}}function s(e){let t=[];for(let n=Object.getPrototypeOf(e);n&&n!==HTMLElement.prototype;n=Object.getPrototypeOf(n)){let e=Object.getOwnPropertyNames(n);t.push(...e)}return t}function c(e){let t=``;for(let n in e){if(!r.includes(n))continue;let i=e[n];i===``?t+=` ${n}`:t+=` ${n}="${i}"`}return t}function l(e){let t={};for(let n of e)t[n.name]=n.value;return t}o(globalThis.HTMLElement??class{},{tag:`video`}),o(globalThis.HTMLElement??class{},{tag:`audio`});function u(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function d(e){return e==null}const f=Symbol(`@videojs/spf/state`);function p(e,t){return Object.is(e,t)}var m=class{[f]=!0;#e;#t=null;#n=!1;#r;#i=new Set;#a=new Set;constructor(e,t){this.#e=typeof e==`object`&&e?{...e}:e,this.#r=t?.equalityFn??p}get current(){return this.#t??this.#e}patch(e){let t=this.#t??this.#e;if(typeof t!=`object`||!t){let n=e;Object.is(t,n)||(this.#t=n,this.#o());return}let n={...t},r=!1;for(let i in e){if(!Object.hasOwn(e,i))continue;let a=e[i];Object.is(t[i],a)||(n[i]=a,r=!0)}r&&(this.#t=n,this.#o())}subscribe(e,t,n){if(t===void 0){let t=e;return this.#i.add(t),t(this.current),()=>{this.#i.delete(t)}}let r=e,i=t,a={selector:r,listener:i,options:n??{}};return this.#a.add(a),i(r(this.current)),()=>{this.#a.delete(a)}}flush(){if(this.#t===null)return;let e=this.#e,t=this.#t;if(this.#t=null,this.#n=!1,!this.#r(e,t)){this.#e=t;for(let e of this.#i)e(this.#e);for(let t of this.#a){let n=t.selector(e),r=t.selector(this.#e);(t.options.equalityFn??Object.is)(n,r)||t.listener(r)}}}#o(){this.#n||(this.#n=!0,queueMicrotask(()=>this.flush()))}};function h(e,t){return new m(e,t)}function ee(e){let t=new Map;for(let n of e.matchAll(/([A-Z0-9-]+)=(?:"([^"]*)"|([^,]*))/g)){let e=n[1],r=n[2]??n[3]??``;e&&t.set(e,r)}return t}function te(e){let t=/^(\d+)x(\d+)$/.exec(e);return t?{width:Number.parseInt(t[1],10),height:Number.parseInt(t[2],10)}:null}function ne(e){let t=Number.parseFloat(e);if(!(Number.isNaN(t)||t<=0))return Math.abs(t-23.976)<.01?{frameRateNumerator:24e3,frameRateDenominator:1001}:Math.abs(t-29.97)<.01?{frameRateNumerator:3e4,frameRateDenominator:1001}:Math.abs(t-59.94)<.01?{frameRateNumerator:6e4,frameRateDenominator:1001}:(t%1,{frameRateNumerator:Math.round(t)})}function g(e){let t=e.split(`,`).map(e=>e.trim()),n={};for(let e of t)e.startsWith(`avc1.`)||e.startsWith(`hvc1.`)||e.startsWith(`hev1.`)?n.video=e:e.startsWith(`mp4a.`)&&(n.audio=e);return n}function re(e){let t=e.split(`,`)[0]??e,n=Number.parseFloat(t);return Number.isNaN(n)?0:n}function _(e,t){let n=/^(\d+)(?:@(\d+))?$/.exec(e);if(!n)return null;let r=Number.parseInt(n[1],10);if(Number.isNaN(r))return null;let i;if(n[2]!==void 0){if(i=Number.parseInt(n[2],10),Number.isNaN(i))return null}else if(t!==void 0)i=t;else return null;return{start:i,end:i+r-1}}function ie(e){let t=ee(e);return{get(e){return t.get(e)},getInt(e,n){let r=t.get(e);if(r===void 0)return n;let i=Number.parseInt(r,10);return Number.isNaN(i)?n:i},getFloat(e,n){let r=t.get(e);if(r===void 0)return n;let i=Number.parseFloat(r);return Number.isNaN(i)?n:i},getBool(e){return t.get(e)===`YES`},getResolution(e){let n=t.get(e);if(n)return te(n)??void 0},getFrameRate(e){let n=t.get(e);if(n)return ne(n)}}}function v(e,t){let n=`#${t}:`;return e.startsWith(n)?ie(e.slice(n.length)):null}function y(e,t){return new URL(e,t).href}function ae(e,t){let n=e.split(/\r?\n/),r=t.url,i=[],a,o,s=0,c,l=0,u=0,d;for(let e of n){let t=e.trim();if(!t||t.startsWith(`#`)&&!t.startsWith(`#EXT`)||t===`#EXTM3U`||t.startsWith(`#EXT-X-VERSION:`)||t.startsWith(`#EXT-X-TARGETDURATION:`)||t.startsWith(`#EXT-X-PLAYLIST-TYPE:`)||t.startsWith(`#EXT-X-INDEPENDENT-SEGMENTS`))continue;let n=v(t,`EXT-X-MAP`);if(n){let e=n.get(`URI`);if(e){a=y(e,r);let t=n.get(`BYTERANGE`);t&&(o=_(t,0)??void 0)}continue}if(t.startsWith(`#EXTINF:`)){s=re(t.slice(8));continue}if(t.startsWith(`#EXT-X-BYTERANGE:`)){c=_(t.slice(17),d)??void 0;continue}if(t!==`#EXT-X-ENDLIST`&&!t.startsWith(`#`)&&s>0){let e={id:`segment-${u}`,url:y(t,r),duration:s,startTime:l};c?(e.byteRange=c,d=c.end+1):d=void 0,i.push(e),l+=s,u++,s=0,c=void 0}}let f=l,p=t.type===`text`&&!a?void 0:a?{url:a,...o?{byteRange:o}:{}}:{url:``};return{...t,startTime:0,duration:f,segments:i,initialization:p}}function b(){return`${Date.now()}-${Math.floor(Math.random()*1e6)}`}function oe(e,t){let n=t.url,r=e.split(/\r?\n/),i=[],a=[],o=[],s=null;for(let e of r){let t=e.trim();if(!t||t.startsWith(`#`)&&!t.startsWith(`#EXT`)||t===`#EXTM3U`||t.startsWith(`#EXT-X-VERSION:`)||t.startsWith(`#EXT-X-INDEPENDENT-SEGMENTS`))continue;let r=v(t,`EXT-X-MEDIA`);if(r){let e=r.get(`TYPE`),t=r.get(`GROUP-ID`),i=r.get(`NAME`);if(e===`AUDIO`&&t&&i){let e=r.get(`URI`);a.push({groupId:t,name:i,language:r.get(`LANGUAGE`),uri:e?y(e,n):void 0,default:r.getBool(`DEFAULT`),autoselect:r.getBool(`AUTOSELECT`)})}if(e===`SUBTITLES`&&t&&i){let e=r.get(`URI`);e&&o.push({groupId:t,name:i,language:r.get(`LANGUAGE`),uri:y(e,n),default:r.getBool(`DEFAULT`),autoselect:r.getBool(`AUTOSELECT`),forced:r.getBool(`FORCED`)})}continue}let c=v(t,`EXT-X-STREAM-INF`);if(c){s={bandwidth:c.getInt(`BANDWIDTH`,0),resolution:c.getResolution(`RESOLUTION`),codecs:c.get(`CODECS`),frameRate:c.getFrameRate(`FRAME-RATE`),audioGroupId:c.get(`AUDIO`)};continue}!t.startsWith(`#`)&&s&&(i.push({...s,uri:y(t,n)}),s=null)}let c=[],l=[];for(let e of i){if(!e.codecs){c.push(e);continue}let t=g(e.codecs);e.codecs.split(`,`).length===1&&t.audio&&!t.video?l.push(e):c.push(e)}let u=c.map(e=>{let t=e.codecs?g(e.codecs):void 0,n={type:`video`,id:b(),url:e.uri,bandwidth:e.bandwidth,mimeType:`video/mp4`,codecs:[]};return e.resolution?.width!==void 0&&(n.width=e.resolution.width),e.resolution?.height!==void 0&&(n.height=e.resolution.height),t?.video&&(n.codecs=[t.video]),e.frameRate&&(n.frameRate=e.frameRate),e.audioGroupId&&(n.audioGroupId=e.audioGroupId),n}),d=l.map(e=>{let t=e.codecs?g(e.codecs):void 0;return{type:`audio`,id:b(),url:e.uri,bandwidth:e.bandwidth,mimeType:`audio/mp4`,codecs:t?.audio?[t.audio]:[],groupId:e.audioGroupId||`default`,name:`Default`,sampleRate:48e3,channels:2}}),f=[...a.map(e=>{let t;for(let n of i)if(n.audioGroupId===e.groupId&&n.codecs){let e=g(n.codecs);if(e.audio){t=[e.audio];break}}let n={type:`audio`,id:b(),url:e.uri??``,groupId:e.groupId,name:e.name,mimeType:`audio/mp4`,bandwidth:0,sampleRate:48e3,channels:2,codecs:[]};return e.language&&(n.language=e.language),t&&(n.codecs=t),e.default&&(n.default=e.default),e.autoselect&&(n.autoselect=e.autoselect),n}),...d],p=o.map(e=>{let t={type:`text`,id:b(),url:e.uri,groupId:e.groupId,label:e.name,kind:`subtitles`,mimeType:`text/vtt`,bandwidth:0};return e.language&&(t.language=e.language),e.default&&e.autoselect&&(t.default=!0),e.autoselect&&(t.autoselect=e.autoselect),e.forced&&(t.forced=e.forced),t}),m=[];if(u.length>0){let e={id:b(),type:`video`,tracks:u},t={id:b(),type:`video`,switchingSets:[e]};m.push(t)}if(f.length>0){let e={id:b(),type:`audio`,tracks:f},t={id:b(),type:`audio`,switchingSets:[e]};m.push(t)}if(p.length>0){let e={id:b(),type:`text`,tracks:p},t={id:b(),type:`text`,switchingSets:[e]};m.push(t)}return{id:b(),url:t.url,startTime:0,selectionSets:m}}function x(e){return Math.exp(Math.log(.5)/e)}function S(e,t,n,r){let i=x(r)**n;return t*(1-i)+i*e}function se(e,t,n){return t===0?0:e/(1-x(n)**t)}const C={fastHalfLife:2,slowHalfLife:5,minTotalBytes:128e3,minBytes:16e3,minDuration:5};function ce(e,t,n,r=C){let i=e.bytesSampled+n;if(n<r.minBytes||t<r.minDuration)return{...e,bytesSampled:i};let a=8e3*n/t,o=t/1e3;return{fastEstimate:S(e.fastEstimate,a,o,r.fastHalfLife),fastTotalWeight:e.fastTotalWeight+o,slowEstimate:S(e.slowEstimate,a,o,r.slowHalfLife),slowTotalWeight:e.slowTotalWeight+o,bytesSampled:i}}function le(e,t,n=C){if(e.bytesSampled<n.minTotalBytes)return t;let r=se(e.fastEstimate,e.fastTotalWeight,n.fastHalfLife),i=se(e.slowEstimate,e.slowTotalWeight,n.slowHalfLife);return Math.min(r,i)}const ue={safetyMargin:.85};function de(e,t,n=ue){if(e.length===0)return;let r=e.slice().sort((e,t)=>e.bandwidth-t.bandwidth),i;for(let e of r)t>=e.bandwidth/n.safetyMargin&&(!i||e.bandwidth>i.bandwidth||e.bandwidth===i.bandwidth&&fe(e,i))&&(i=e);return i??r[0]}function fe(e,t){return(e.width??0)*(e.height??0)>(t.width??0)*(t.height??0)}const pe={keepSegments:2};function me(e,t,n=pe){if(e.length===0)return 0;let r=e.filter(e=>e.startTime<t);if(r.length===0)return 0;let i=r.length-n.keepSegments;return i<=0?0:i>=r.length?t:r[i].startTime}const w={bufferDuration:30};function he(e,t,n=w){if(e.length===0)return 1/0;let r=t+n.bufferDuration,i=e.filter(e=>e.startTime>=r);return i.length===0?1/0:Math.min(...i.map(e=>e.startTime))}function T(e,t,n,r=w){if(e.length===0)return[];let i=n+r.bufferDuration,a=new Set(t.map(e=>e.startTime));return e.filter(e=>{let t=e.startTime+e.duration,r=e.startTime<i&&t>n,o=!a.has(e.startTime);return r&&o})}function E(e){return`segments`in e}function ge(e){return e.duration!==void 0}function D(){return typeof MediaSource<`u`}function O(){return typeof ManagedMediaSource<`u`}function _e(e={}){let{preferManaged:t=!1}=e;if(t&&O())return new ManagedMediaSource;if(D())return new MediaSource;throw Error(`MediaSource API is not supported`)}function ve(e,t){if(O()&&e instanceof ManagedMediaSource)return t.disableRemotePlayback=!0,t.srcObject=e,{url:``,detach:()=>{t.srcObject=null,t.load()}};let n=URL.createObjectURL(e);return t.src=n,{url:n,detach:()=>{t.removeAttribute(`src`),t.load(),URL.revokeObjectURL(n)}}}function ye(e,t){return new Promise((n,r)=>{if(e.readyState===`open`){n();return}if(t?.aborted){r(new DOMException(`Aborted`,`AbortError`));return}let i=new AbortController,a={signal:i.signal};e.addEventListener(`sourceopen`,()=>{i.abort(),n()},a),t?.addEventListener(`abort`,()=>{i.abort(),r(new DOMException(`Aborted`,`AbortError`))},a)})}function k(e,t){if(e.readyState!==`open`)throw Error(`MediaSource is not open`);if(!be(t))throw Error(`Codec not supported: ${t}`);return e.addSourceBuffer(t)}function be(e){return D()?MediaSource.isTypeSupported(e):!1}const xe=2**17;var A=class{minChunkSize;#e;constructor(e,{minChunkSize:t=xe}={}){this.#e=e,this.minChunkSize=t}async*[Symbol.asyncIterator](){let e,t=this.#e.getReader();try{for(;;){let{done:n,value:r}=await t.read();if(n){e&&(yield e);break}e=e?Se(e,r):r,e.length>=this.minChunkSize&&(yield e,e=void 0)}}finally{t.releaseLock()}}};function Se(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}async function j(e,t){let n=new Headers(t?.headers);if(e.byteRange){let{start:t,end:r}=e.byteRange;n.set(`Range`,`bytes=${t}-${r}`)}let r=new Request(e.url,{method:`GET`,headers:n,...t});return fetch(r)}function M(e){return e.text()}const Ce=Symbol(`@videojs/event-stream`);function we(){let e=new Set;return{[Ce]:!0,dispatch(t){let n=Array.from(e);for(let e of n)e(t)},subscribe(t){return e.add(t),()=>e.delete(t)}}}function N(e){let t=t=>{let n=Array(e.length),r=Array(e.length).fill(!1),i=[];for(let a=0;a<e.length;a++){let o=e[a].subscribe(e=>{n[a]=e,r[a]=!0,r.every(e=>e)&&t([...n])});i.push(o)}return()=>{for(let e of i)e()}};return{subscribe(e,n,r){if(n===void 0)return t(e);let i=e,a=n,o=r?.equalityFn??Object.is,s,c=!1;return t(e=>{let t=i(e);(!c||!o(s,t))&&(s=t,c=!0,a(t))})}}}function Te(e){return e!==void 0&&`url`in e&&!(`id`in e)}function Ee(e){return Te(e.presentation)}function De(e,t){let{preload:n}=e;return[`auto`,`metadata`].includes(n)||t.type===`play`}function Oe(e,t){return t.subscribe(t=>{let n=t.mediaElement?.preload||void 0;e.patch({preload:n})})}function ke({state:e,events:t}){let n=!1,r=null,i=N([e,t]).subscribe(async([t,i])=>{if(!(!Ee(t)||!De(t,i)||n))try{n=!0,r=new AbortController;let{presentation:i}=t,a=oe(await M(await j(i,{signal:r.signal})),i);e.patch({presentation:a})}catch(e){if(e instanceof Error&&e.name===`AbortError`)return;throw e}finally{n=!1,r=null}});return()=>{r?.abort(),i()}}const P={safetyMargin:.85,minUpgradeInterval:8e3,defaultBandwidth:5e6};function Ae(e){return(e.selectionSets?.find(e=>e.type===`video`))?.switchingSets[0]?.tracks??[]}function je({state:e},t={}){let n=t.safetyMargin??P.safetyMargin,r=t.minUpgradeInterval??P.minUpgradeInterval,i=t.defaultBandwidth??P.defaultBandwidth,a=Date.now(),o=!0;return e.subscribe(t=>{let{presentation:s,bandwidthState:c,selectedVideoTrackId:l,abrDisabled:u}=t;if(u===!0||!s||!c)return;let d=Ae(s);if(d.length===0)return;let f=o;o=!1;let p=de(d,le(c,i),{safetyMargin:n});if(!p||p.id===l)return;let m=d.find(e=>e.id===l);if(!m||p.bandwidth>m.bandwidth){let e=Date.now();if(!f&&e-a<r)return;a=e}e.patch({selectedVideoTrackId:p.id})})}const F={video:`selectedVideoTrackId`,audio:`selectedAudioTrackId`,text:`selectedTextTrackId`};function I(e,t){let{presentation:n}=e;if(!n||!(`id`in n))return;let r=e[F[t]];return n.selectionSets.find(({type:e})=>e===t)?.switchingSets[0]?.tracks.find(({id:e})=>e===r)}function Me(e,t){let n=null,r=null,i=null,a=null,o=!1,s=!1,c=t=>{let n=new Set(e.snapshot.context.segments.filter(e=>!e.partial).map(e=>e.id));return t.filter(e=>n.has(e.id))},l=t=>{let{track:n,range:r}=t,i=e.snapshot.context,a=c(n.segments),o=r?.start??0,s=[];if(r){let e=he(a,o);e<1/0&&s.push({type:`remove`,start:e,end:1/0});let t=me(a,o);t>0&&s.push({type:`remove`,start:0,end:t})}if(i.initTrackId!==n.id&&s.push({type:`append-init`,meta:{trackId:n.id},url:n.initialization.url,...n.initialization.byteRange!==void 0&&{byteRange:n.initialization.byteRange}}),r){let e=T(n.segments,a,o).filter(e=>{let t=i.segments.find(t=>Math.abs(t.startTime-e.startTime)<1e-4);return t?.partial||!t?.trackBandwidth||!n.bandwidth?!0:n.bandwidth>t.trackBandwidth});for(let t of e)s.push({type:`append-segment`,meta:{id:t.id,startTime:t.startTime,duration:t.duration,trackId:n.id,trackBandwidth:n.bandwidth},url:t.url,...t.byteRange!==void 0&&{byteRange:t.byteRange}})}return s},u=async o=>{let s=a.signal;try{if(o.type===`remove`){await e.send(o,s);return}if(o.type===`append-init`){if(r=o.meta.trackId,!s.aborted){let r=await t(o,{signal:s,minChunkSize:1/0}),i=n?.some(e=>e.type===`append-init`&&e.meta.trackId!==o.meta.trackId);if(!s.aborted||!i){let t=s.aborted?new AbortController().signal:s;await e.send({type:`append-init`,data:r,meta:o.meta},t)}}return}if(i=o.meta.id,!s.aborted){let n=await t(o,{signal:s});s.aborted||await e.send({type:`append-segment`,data:n,meta:o.meta},s)}}finally{r=null,i=null}},d=async e=>{o=!0,a=new AbortController;let t=e;for(;t.length>0&&!s;){let e=t[0];t=t.slice(1);try{await u(e)}catch(e){e instanceof Error&&e.name===`AbortError`||(console.error(`Unexpected error in segment loader:`,e),t=[])}if(n!==null)t=n,n=null,a=new AbortController;else if(a.signal.aborted)break}a=null,o=!1};return{send(e){if(s)return;let t=l(e);if(!o){if(t.length===0)return;d(t);return}i!==null&&t.some(e=>e.type===`append-segment`&&e.meta.id===i)||r!==null&&t.some(e=>e.type===`append-init`&&e.meta.trackId===r)?n=t.filter(e=>!(e.type===`append-segment`&&e.meta.id===i)&&!(e.type===`append-init`&&e.meta.trackId===r)):(n=t,a?.abort())},destroy(){s=!0,a?.abort()}}}const Ne={video:`videoBufferActor`,audio:`audioBufferActor`};function Pe(e,t){return async(n,r)=>{let{minChunkSize:i,...a}=r??{},o=await j(n,a);if(!o.body)throw Error(`Response has no body`);let s=o.body;return{[Symbol.asyncIterator]:async function*(){let n=performance.now();for await(let r of new A(s,...i===void 0?[]:[{minChunkSize:i}])){let i=performance.now()-n,a=ce(e.current,i,r.byteLength);e.patch(a),e.flush(),t?.(a),yield r,n=performance.now()}}}}}async function Fe(e,t){let{minChunkSize:n,...r}=t??{},i=await j(e,r);if(!i.body)throw Error(`Response has no body`);return new A(i.body,...n===void 0?[]:[{minChunkSize:n}])}function Ie([e,t],n){let{playbackInitiated:r,preload:i,currentTime:a}=t;return{playbackInitiated:r,preload:i,currentTime:a,track:I(t,n),segmentsCanLoad:e}}const L=(e,t)=>{if(e!=null)return t?.segments.find(({startTime:t,duration:n},r,i)=>e>=t&&(e<t+n||r===i.length-1))?.startTime};function Le(e,t){return t.segmentsCanLoad?t.playbackInitiated?!e.playbackInitiated&&t.playbackInitiated&&e.preload!==`auto`?!1:!t.track||!E(t.track)?!0:e.track?.id!==t.track.id&&E(t.track)?!1:L(e.currentTime,t.track)===L(t.currentTime,t.track):t.preload===`none`?!0:t.preload===e.preload:!0}function R({state:e,owners:t},n){let{type:r}=n,i=Ne[r],a=e.current.bandwidthState,o=h(a??{fastEstimate:0,fastTotalWeight:0,slowEstimate:0,slowTotalWeight:0,bytesSampled:0}),s=r===`video`?Pe(o,a===void 0?void 0:t=>{e.patch({bandwidthState:t}),e.flush()}):Fe,c=h(void 0),l=t.subscribe(e=>e[i],e=>(e?c.patch(Me(e,s)):!e&&c.current&&(c.current.destroy(),c.patch(void 0)),()=>{c.current?.destroy(),c.patch(void 0)})),u=h(!1),d=N([e,c]).subscribe(([e,t])=>{let n=I(e,r),i=!!n&&E(n),a=!!t;u.patch(i&&a)}),f=N([u,e]).subscribe(([e,t])=>Ie([e,t],r),({preload:e,playbackInitiated:t,currentTime:n,track:r})=>{e===`auto`||t?c.current?.send({type:`load`,track:r,range:{start:n,end:n+w.bufferDuration}}):c.current?.send({type:`load`,track:r})},{equalityFn:Le});return()=>{d(),f(),l()}}let z=null;function Re(){return z||(z=document.createElement(`video`),z.muted=!0,z.preload=`none`,z.style.display=`none`,z.crossOrigin=`anonymous`),z}function ze(e){let t=Re(),n=document.createElement(`track`);return n.kind=`subtitles`,n.default=!0,new Promise((r,i)=>{let a=()=>{let e=[],t=n.track;if(t.cues)for(let n=0;n<t.cues.length;n++){let r=t.cues[n];r&&e.push(r)}s(),r(e)},o=()=>{s(),i(Error(`Failed to load VTT segment: ${e}`))},s=()=>{n.removeEventListener(`load`,a),n.removeEventListener(`error`,o),t.removeChild(n)};n.addEventListener(`load`,a),n.addEventListener(`error`,o),t.appendChild(n),n.src=e})}function Be(){z=null}function Ve(e,t){let{cues:n}=t;if(!n)return!1;for(let t=0;t<n.length;t++){let r=n[t];if(r.startTime===e.startTime&&r.endTime===e.endTime&&r.text===e.text)return!0}return!1}const He=async({segment:e},t)=>{let n=await ze(e.url);for(let e of n)Ve(e,t.textTrack)||t.textTrack.addCue(e)},Ue=async({currentState:e},t)=>{let n=B(e);if(!n||!E(n))return;let{segments:r}=n;if(r.length===0)return;let i=n.id,a=new Set((e.textBufferState?.[i]?.segments??[]).map(e=>e.id)),o=T(r,r.filter(e=>a.has(e.id)),e.currentTime??0).filter(e=>!a.has(e.id));if(o.length!==0){for(let e of o){if(t.signal.aborted)break;try{await He({segment:e},{textTrack:t.textTrack});let n=t.state.current.textBufferState??{},r=n[i]??{segments:[]};t.state.patch({textBufferState:{...n,[i]:{segments:[...r.segments,{id:e.id}]}}})}catch(e){if(e instanceof Error&&e.name===`AbortError`)break;console.error(`Failed to load VTT segment:`,e)}}t.textTrack.mode===`showing`&&t.textTrack.cues&&Array.from(t.textTrack.cues).forEach(e=>{t.textTrack.addCue(e)}),await new Promise(e=>requestAnimationFrame(e))}};function B(e){if(!e.presentation||!e.selectedTextTrackId)return;let t=e.presentation.selectionSets.find(e=>e.type===`text`);if(t?.switchingSets?.[0]?.tracks)return t.switchingSets[0].tracks.find(t=>t.id===e.selectedTextTrackId)}function V(e,t){let n=e.selectedTextTrackId;if(!(!n||!t.textTracks))return t.textTracks.get(n)?.track}function We(e,t){return!!e.selectedTextTrackId&&!!t.textTracks&&t.textTracks.has(e.selectedTextTrackId)}function Ge(e,t){if(!We(e,t))return!1;let n=B(e);return!(!n||!E(n)||n.segments.length===0||!V(e,t))}function Ke({state:e,owners:t}){let n=null,r=null,i,a=N([e,t]).subscribe(async([t,a])=>{if(t.selectedTextTrackId!==i&&(i=t.selectedTextTrackId,r?.abort(),n=null),n||!Ge(t,a))return;let o=V(t,a);o&&(r=new AbortController,n=Ue({currentState:t},{signal:r.signal,textTrack:o,state:e}).finally(()=>{n=null}))});return()=>{r?.abort(),a()}}function qe({state:e,owners:t}){let n,r=null,i=t.subscribe(t=>{let{mediaElement:i}=t;if(i===n||(r?.(),r=null,n=i,!i))return;e.patch({currentTime:i.currentTime});let a=()=>e.patch({currentTime:i.currentTime}),o=u(i,`timeupdate`,a),s=u(i,`seeking`,a);r=()=>{o(),s()}});return()=>{r?.(),i()}}function Je({state:e,owners:t,events:n}){let r,i=null,a,o=e.subscribe(t=>{let n=t.presentation?.url;n!==a&&(a!==void 0&&e.patch({playbackInitiated:!1}),a=n)}),s=t.subscribe(t=>{let{mediaElement:a}=t;a!==r&&(i?.(),i=null,r=a,a&&(i=u(a,`play`,()=>{e.patch({playbackInitiated:!0}),n.dispatch({type:`play`})})))});return()=>{i?.(),o(),s()}}async function H(e,t,n){if(t instanceof ArrayBuffer)await U(e,t);else for await(let r of t){if(n?.aborted)throw n.reason??new DOMException(`Aborted`,`AbortError`);await U(e,r)}}async function U(e,t){return e.updating&&await new Promise(t=>{let n=()=>{e.removeEventListener(`updateend`,n),t()};e.addEventListener(`updateend`,n)}),new Promise((n,r)=>{let i=()=>{o(),n()},a=e=>{o(),r(Error(`SourceBuffer append error: ${e.type}`))},o=()=>{e.removeEventListener(`updateend`,i),e.removeEventListener(`error`,a)};e.addEventListener(`updateend`,i),e.addEventListener(`error`,a);try{e.appendBuffer(t)}catch(e){o(),r(e)}})}async function Ye(e,t,n){return e.updating&&await new Promise(t=>{let n=()=>{e.removeEventListener(`updateend`,n),t()};e.addEventListener(`updateend`,n)}),new Promise((r,i)=>{let a=()=>{s(),r()},o=e=>{s(),i(Error(`SourceBuffer remove error: ${e.type}`))},s=()=>{e.removeEventListener(`updateend`,a),e.removeEventListener(`error`,o)};e.addEventListener(`updateend`,a),e.addEventListener(`error`,o);try{e.remove(t,n)}catch(e){s(),i(e)}})}function Xe(e){return e.presentation?!!(e.selectedVideoTrackId||e.selectedAudioTrackId):!1}function Ze(e){if(!Xe(e))return!1;let{presentation:t}=e;if(t.duration!==void 0)return!1;let n=e.selectedVideoTrackId?I(e,`video`):void 0,r=e.selectedAudioTrackId?I(e,`audio`):void 0;return!!(n&&E(n)||r&&E(r))}function Qe(e){let t=e.selectedVideoTrackId?I(e,`video`):void 0;if(t&&E(t))return t.duration;let n=e.selectedAudioTrackId?I(e,`audio`):void 0;if(n&&E(n))return n.duration}function $e({state:e}){return N([e]).subscribe(([t])=>{if(!Ze(t))return;let n=Qe(t);if(n===void 0||!Number.isFinite(n))return;let{presentation:r}=t;e.patch({presentation:{...r,duration:n}})})}var W=class{id;#e;#t=new AbortController;#n;#r=`pending`;#i=void 0;#a=void 0;constructor(e,t){this.#e=e;let n=t?.id;this.id=typeof n==`function`?n():n??b(),this.#n=t?.signal?AbortSignal.any([this.#t.signal,t.signal]):this.#t.signal}get status(){return this.#r}get value(){return this.#i}get error(){return this.#a}async run(){this.#r=`running`;try{let e=await this.#e(this.#n);return this.#i=e,this.#r=`done`,e}catch(e){throw this.#a=e,this.#r=`error`,e}}abort(){this.#t.abort()}},et=class{#e=new Map;schedule(e){this.#e.has(e.id)||(this.#e.set(e.id,e),e.run().catch(e=>{if(!(e instanceof Error&&e.name===`AbortError`))throw e}).finally(()=>{this.#e.delete(e.id)}))}abortAll(){for(let e of this.#e.values())e.abort();this.#e.clear()}},tt=class{#e=Promise.resolve();#t=new Set;#n=null;schedule(e){let t=e;this.#t.add(t);let n=this.#e.then(()=>(this.#t.delete(t),this.#n=t,e.run())).finally(()=>{this.#n=null});return this.#e=n.then(()=>{},()=>{}),n}abortAll(){for(let e of this.#t)e.abort();this.#t.clear(),this.#n?.abort()}destroy(){this.abortAll()}};function nt(e,t){let n=I(e,t.type);return n?!E(n):!1}function rt(e,t){return!0}function it(e,t){let n=t.id;return{...e,selectionSets:e.selectionSets.map(e=>({...e,switchingSets:e.switchingSets.map(e=>({...e,tracks:e.tracks.map(e=>e.id===n?t:e)}))}))}}function G({state:e,events:t},n){let r=new et,i=N([e,t]).subscribe(([t,i])=>{if(!nt(t,n)||!rt(t,i))return;let a=I(t,n.type);if(!a)return;let o=a;r.schedule(new W(async t=>{let n=ae(await M(await j(o,{signal:t})),o),r=e.current.presentation,i=it(r,n);e.patch({presentation:i})},{id:a.id}))});return()=>{r.abortAll(),i()}}function at(e,t){let n=e.selectionSets.find(e=>e.type===`text`);if(!n?.switchingSets?.[0]?.tracks.length)return;let r=n.switchingSets[0].tracks,i=t.includeForcedTracks?r:r.filter(e=>!e.forced);if(i.length===0)return;let{preferredSubtitleLanguage:a,enableDefaultTrack:o=!1}=t;if(a){let e=i.find(e=>e.language===a);if(e)return e.id}if(o){let e=i.find(e=>e.default===!0);if(e)return e.id}}function K(e,t){return!!e?.presentation?.selectionSets?.find(({type:e})=>e===t.type)?.switchingSets?.[0]?.tracks.length}function q(e,t){return!e[F[t.type]]}function ot({state:e},t={type:`video`}){let n=!1;return e.subscribe(async r=>{if(!(!K(r,t)||!q(r,t)||n))try{n=!0;let i=r.presentation?.selectionSets.find(({type:e})=>e===t.type)?.switchingSets[0]?.tracks[0]?.id;if(i){let n=F[t.type];e.patch({[n]:i})}}finally{n=!1}})}function st({state:e},t={type:`audio`}){let n=!1;return e.subscribe(async r=>{if(!(!K(r,t)||!q(r,t)||n))try{n=!0;let t=r.presentation?.selectionSets.find(({type:e})=>e===`audio`)?.switchingSets[0]?.tracks[0]?.id;t&&e.patch({selectedAudioTrackId:t})}finally{n=!1}})}function ct({state:e},t={type:`text`}){let n=!1;return e.subscribe(async r=>{if(!(!K(r,t)||!q(r,t)||n))try{n=!0;let i=at(r.presentation,t);i&&e.patch({selectedTextTrackId:i})}finally{n=!1}})}function J(e,t){if(e.length===0)return!0;let n=e[e.length-1];return n?t?.snapshot.context.segments.some(e=>e.id===n.id&&!e.partial)??!1:!1}function lt(e,t){let n=e.selectedVideoTrackId?I(e,`video`):void 0,r=e.selectedAudioTrackId?I(e,`audio`):void 0;return!(n&&!E(n)||r&&!E(r)||n&&E(n)&&!J(n.segments,t.videoBufferActor)||r&&E(r)&&!J(r.segments,t.audioBufferActor))}function ut(e,t){return!!(t.mediaSource&&e.presentation)}function dt(e,t){if(!ut(e,t))return!1;let{mediaSource:n,mediaElement:r}=t;if(n.readyState!==`open`||r&&r.readyState<HTMLMediaElement.HAVE_METADATA)return!1;let i=!!e.selectedVideoTrackId,a=!!e.selectedAudioTrackId;if(i&&!t.videoBuffer||a&&!t.audioBuffer||t.videoBufferActor?.snapshot.status===`updating`||t.audioBufferActor?.snapshot.status===`updating`||!lt(e,t))return!1;if(r){let t=i?I(e,`video`):void 0,n=a?I(e,`audio`):void 0,o=t&&E(t)?t:n&&E(n)?n:void 0;if(o&&o.segments.length>0){let e=o.segments[o.segments.length-1];if(r.currentTime<e.startTime)return!1}}return!0}function ft(e){let t=[e.videoBufferActor,e.audioBufferActor].filter(e=>e!==void 0&&e.snapshot.status===`updating`);return t.length===0?Promise.resolve():Promise.all(t.map(e=>new Promise(t=>{let n=e.subscribe(e=>{e.status!==`updating`&&(n(),t())})}))).then(()=>void 0)}function pt(e){let t=0;for(let n of[e.videoBuffer,e.audioBuffer])if(n&&n.buffered.length>0){let e=n.buffered.end(n.buffered.length-1);e>t&&(t=e)}return t}const mt=async({currentOwners:e},t)=>{let{mediaSource:n}=e;if(n.readyState===`ended`||(await ft(e),n.readyState!==`open`))return;let r=pt(e);r>0&&(n.duration=r),n.endOfStream(),await new Promise(e=>requestAnimationFrame(e))};function ht({state:e,owners:t}){let n=!1,r=!1,i=[],a=async()=>{if(r)return;let i=e.current,a=t.current;if(n){if(a.mediaSource?.readyState!==`open`)return;n=!1}if(dt(i,a)){n=!0;try{await mt({currentOwners:a},{})}catch(e){console.error(`Failed to call endOfStream:`,e)}}},o=t.subscribe(e=>{i.forEach(e=>e()),i.length=0;for(let t of[e.videoBufferActor,e.audioBufferActor]){if(!t)continue;let e=!0;i.push(t.subscribe(()=>{if(e){e=!1;return}a()}))}}),s=N([e,t]).subscribe(async()=>a());return()=>{r=!0,i.forEach(e=>e()),o(),s()}}function gt(e,t){return!d(t.mediaElement)&&!d(e.presentation?.url)}function _t(e,t){return d(t.mediaSource)}function vt({state:e,owners:t}){let n=!1,r=null,i=N([e,t]).subscribe(async([e,i])=>{if(!(!gt(e,i)||!_t(e,i)||n))try{n=!0,r=new AbortController;let e=_e({preferManaged:!0});ve(e,i.mediaElement),await ye(e,r.signal),t.patch({mediaSource:e})}catch(e){if(e instanceof DOMException&&e.name===`AbortError`)return;throw e}finally{n=!1}});return()=>{r?.abort(),i()}}var Y=class extends Error{constructor(e){super(e),this.name=`SourceBufferActorError`}};function X(e){let t=[];for(let n=0;n<e.length;n++)t.push({start:e.start(n),end:e.end(n)});return t}function yt(e,{signal:t,getCtx:n,sourceBuffer:r}){return new W(async t=>{let i=n();return t.aborted?i:(await H(r,e.data),{...i,initTrackId:e.meta.trackId})},{signal:t})}function bt(e,{signal:t,getCtx:n,sourceBuffer:r,onPartialContext:i}){return new W(async t=>{let a=n();if(t.aborted)return a;let{meta:o}=e,s=a.segments.filter(e=>Math.abs(e.startTime-o.startTime)>=1e-4);return e.data instanceof ArrayBuffer||i({...a,segments:[...s,{id:o.id,startTime:o.startTime,duration:o.duration,trackId:o.trackId,...o.trackBandwidth!==void 0&&{trackBandwidth:o.trackBandwidth},partial:!0}],bufferedRanges:a.bufferedRanges}),await H(r,e.data,t),{...a,segments:[...s,{id:o.id,startTime:o.startTime,duration:o.duration,trackId:o.trackId,...o.trackBandwidth!==void 0&&{trackBandwidth:o.trackBandwidth}}],bufferedRanges:X(r.buffered)}},{signal:t})}function xt(e,{signal:t,getCtx:n,sourceBuffer:r}){return new W(async t=>{let i=n();if(t.aborted)return i;await Ye(r,e.start,e.end);let a=X(r.buffered),o=i.segments.filter(e=>{let t=e.startTime+e.duration/2;return a.some(e=>t>=e.start&&t<e.end)});return{...i,segments:o,bufferedRanges:a}},{signal:t})}const St={"append-init":yt,"append-segment":bt,remove:xt};function Z(e,t){let n=St[e.type];return n(e,t)}function Q(e,t){let n=h({status:`idle`,context:{segments:[],bufferedRanges:[],initTrackId:void 0,...t}}),r=new tt;function i(e){let t=n.current.status===`destroyed`?`destroyed`:`idle`;n.patch({status:t,context:e}),n.flush()}function a(e){let t=n.current.status===`destroyed`?`destroyed`:`idle`;throw n.patch({status:t}),n.flush(),e}return{get snapshot(){return n.current},subscribe(e){return n.subscribe(e)},send(t,o){if(n.current.status!==`idle`)return Promise.reject(new Y(`send() called while actor is ${n.current.status}`));n.patch({status:`updating`});let s=Z(t,{signal:o,getCtx:()=>n.current.context,sourceBuffer:e,onPartialContext:e=>{n.patch({status:`updating`,context:e}),n.flush()}});return r.schedule(s).then(i).catch(a)},batch(t,o){if(n.current.status!==`idle`)return Promise.reject(new Y(`batch() called while actor is ${n.current.status}`));if(t.length===0)return Promise.resolve();n.patch({status:`updating`});let s=n.current.context,c=e=>{n.patch({status:`updating`,context:e}),n.flush()};for(let n of t.slice(0,-1)){let t=Z(n,{signal:o,getCtx:()=>s,sourceBuffer:e,onPartialContext:c});r.schedule(t).then(e=>{s=e})}let l=Z(t[t.length-1],{signal:o,getCtx:()=>s,sourceBuffer:e,onPartialContext:c});return r.schedule(l).then(i).catch(a)},destroy(){n.patch({status:`destroyed`}),n.flush(),r.destroy()}}}function $(e){let t=e.codecs?.join(`,`)??``;return`${e.mimeType}; codecs="${t}"`}function Ct({state:e,owners:t}){let n=!1;return N([e,t]).subscribe(async([e,r])=>{if(n||!r.mediaSource)return;let i=!!e.selectedVideoTrackId,a=!!e.selectedAudioTrackId;if(!i&&!a)return;let o=i?I(e,`video`):null,s=a?I(e,`audio`):null;if(i&&(!o||!E(o)||!o.codecs?.length)||a&&(!s||!E(s)||!s.codecs?.length))return;n=!0;let c={};if(i&&o&&E(o)){let e=k(r.mediaSource,$(o));c.videoBuffer=e,c.videoBufferActor=Q(e)}if(a&&s&&E(s)){let e=k(r.mediaSource,$(s));c.audioBuffer=e,c.audioBufferActor=Q(e)}t.patch(c),await new Promise(e=>requestAnimationFrame(e))})}function wt(e){if(!e?.selectionSets)return[];let t=e.selectionSets.find(e=>e.type===`text`);return t?.switchingSets?.[0]?.tracks?t.switchingSets[0].tracks:[]}function Tt(e,t){return!!t.mediaElement&&!!wt(e.presentation).length}function Et(e){return!e.textTracks}function Dt(e){let t=document.createElement(`track`);return t.id=e.id,t.kind=e.kind,t.label=e.label,e.language&&(t.srclang=e.language),e.default&&(t.default=!0),t.src=e.url,t}function Ot({state:e,owners:t}){let n=!1,r=[],i=N([e,t]).subscribe(([e,i])=>{if(n||!Tt(e,i)||!Et(i))return;n=!0;let a=wt(e.presentation);if(a.length===0)return;let o=new Map;for(let e of a){let t=Dt(e);i.mediaElement.appendChild(t),o.set(e.id,t),r.push(t)}t.patch({textTracks:o})});return()=>{for(let e of r)e.remove();r=[],i()}}function kt({state:e,owners:t}){let n,r=null,i=t.subscribe(t=>{let{mediaElement:i}=t;i===n||(r?.(),r=null,n=i,!i)||(r=u(i.textTracks,`change`,()=>{let t=Array.from(i.textTracks).find(e=>e.mode===`showing`&&(e.kind===`subtitles`||e.kind===`captions`))?.id||void 0,n=e.current;if(n.selectedTextTrackId!==t)if(t)e.patch({selectedTextTrackId:t});else{let t=n.selectedTextTrackId;if(t&&n.textBufferState?.[t]){let r={...n.textBufferState};delete r[t],e.patch({selectedTextTrackId:void 0,textBufferState:r})}else e.patch({selectedTextTrackId:void 0})}}))});return()=>{r?.(),i()}}function At(e){return!!e.textTracks&&e.textTracks.size>0}function jt({state:e,owners:t}){return N([e,t]).subscribe(([e,t])=>{if(!At(t))return;let n=e.selectedTextTrackId;for(let[e,r]of t.textTracks)e===n?r.track.mode=`showing`:r.track.mode=`hidden`})}function Mt(e,t){return!!(t.mediaSource&&e.presentation&&ge(e.presentation))}function Nt(e){let t=0,n=[e.videoSourceBuffer,e.audioSourceBuffer].filter(e=>e!==void 0);for(let e of n){let{buffered:n}=e;if(n.length>0){let e=n.end(n.length-1);e>t&&(t=e)}}return t}function Pt(e,t){if(!Mt(e,t))return!1;let{mediaSource:n}=t,{presentation:r}=e;if(n.readyState!==`open`)return!1;let i=r.duration;return!Number.isFinite(i)||Number.isNaN(i)||i<=0?!1:Number.isNaN(n.duration)}function Ft(e){let t=[e.videoSourceBuffer,e.audioSourceBuffer].filter(e=>e?.updating===!0);return t.length===0?Promise.resolve():Promise.all(t.map(e=>new Promise(t=>e.addEventListener(`updateend`,()=>t(),{once:!0})))).then(()=>void 0)}function It({state:e,owners:t}){let n=!1,r=N([e,t]).subscribe(async([e,t])=>{if(!Pt(e,t))return;let{mediaSource:r}=t;if(await Ft(t),n||r.readyState!==`open`)return;let i=e.presentation.duration,a=Nt(t);a>i&&(i=a),r.duration=i});return()=>{n=!0,r()}}function Lt(e={}){let t=h({bandwidthState:{fastEstimate:0,fastTotalWeight:0,slowEstimate:0,slowTotalWeight:0,bytesSampled:0}}),n=h({}),r=we(),i=[Oe(t,n),Je({state:t,owners:n,events:r}),ke({state:t,events:r}),ot({state:t,owners:n,events:r},{type:`video`,...e.initialBandwidth!==void 0&&{initialBandwidth:e.initialBandwidth}}),st({state:t,owners:n,events:r},{type:`audio`,...e.preferredAudioLanguage!==void 0&&{preferredAudioLanguage:e.preferredAudioLanguage}}),ct({state:t,owners:n,events:r},{type:`text`,...e.preferredSubtitleLanguage!==void 0&&{preferredSubtitleLanguage:e.preferredSubtitleLanguage},...e.includeForcedTracks!==void 0&&{includeForcedTracks:e.includeForcedTracks},...e.enableDefaultTrack!==void 0&&{enableDefaultTrack:e.enableDefaultTrack}}),G({state:t,events:r},{type:`video`}),G({state:t,events:r},{type:`audio`}),G({state:t,events:r},{type:`text`}),$e({state:t}),vt({state:t,owners:n}),It({state:t,owners:n}),Ct({state:t,owners:n}),qe({state:t,owners:n}),je({state:t}),R({state:t,owners:n},{type:`video`}),R({state:t,owners:n},{type:`audio`}),ht({state:t,owners:n}),Ot({state:t,owners:n}),jt({state:t,owners:n}),kt({state:t,owners:n}),Ke({state:t,owners:n})];return r.dispatch({type:`@@INITIALIZE@@`}),{state:t,owners:n,events:r,destroy:()=>{i.forEach(e=>e()),Be()}}}var Rt=class{#e;#t;#n=null;constructor(e={}){this.#t=e,this.#e=Lt(e)}get engine(){return this.#e}attach(e){this.#e.owners.patch({mediaElement:e})}detach(){this.#r(),this.#e.owners.patch({mediaElement:void 0})}destroy(){this.#r(),this.#e.destroy()}get src(){return this.#e.state.current.presentation?.url??``}set src(e){let t=this.#e.owners.current.mediaElement;this.#r(),this.#e.destroy(),this.#e=Lt(this.#t),t&&this.#e.owners.patch({mediaElement:t}),e&&this.#e.state.patch({presentation:{url:e}})}play(){let{mediaElement:e}=this.#e.owners.current;return e?(this.#e.state.patch({playbackInitiated:!0}),e.play().catch(t=>{if(this.src)return new Promise((t,n)=>{let r=()=>{this.#n=null,e.play().then(t,n)};this.#n=r,e.addEventListener(`loadstart`,r,{once:!0})});throw t})):Promise.reject(Error(`SpfMedia: no media element attached`))}#r(){if(!this.#n)return;let{mediaElement:e}=this.#e.owners.current;e?.removeEventListener(`loadstart`,this.#n),this.#n=null}},zt=class extends t(o(globalThis.HTMLElement??class{},{tag:`video`}),Rt){},Bt=class extends zt{static getTemplateHTML(e){let{src:t,...n}=e;return super.getTemplateHTML(n)}constructor(){super(),this.attach(this.target)}attributeChangedCallback(e,t,n){e!==`src`&&super.attributeChangedCallback(e,t,n),e===`src`&&t!==n&&(this.src=n??``)}},Vt=class extends Bt{static{this.tagName=`simple-hls-video`}};customElements.define(Vt.tagName,Vt);
//# sourceMappingURL=simple-hls-video.js.map