import{t as l,P as o,Q as u,R as p,w as h,H as P,K as f,A as g,T as k,S as n}from"./app-Bo-5wkbo.js";import{H as m,a as x}from"./vidstack-Bq6c3Bam-BVtYGVt3.js";import"./Button-C102TjBP.js";import"./vidstack-DqAw8m9J-Cka89Bkm.js";class T{#t;#i;constructor(t,e){this.#t=t,this.#i=e,t.textTracks.onaddtrack=this.#e.bind(this),h(this.#s.bind(this))}#e(t){const e=t.track;if(!e||y(this.#t,e))return;const i=new k({id:e.id,kind:e.kind,label:e.label??"",language:e.language,type:"vtt"});i[n.native]={track:e},i[n.readyState]=2,i[n.nativeHLS]=!0;let a=0;const c=d=>{if(e.cues)for(let r=a;r<e.cues.length;r++)i.addCue(e.cues[r],d),a++};c(t),e.oncuechange=c,this.#i.textTracks.add(i,t),i.setMode(e.mode,t)}#s(){this.#t.textTracks.onaddtrack=null;for(const t of this.#i.textTracks){const e=t[n.native]?.track;e?.oncuechange&&(e.oncuechange=null)}}}function y(s,t){return Array.from(s.children).find(e=>e.track===t)}class v{#t;#i;constructor(t,e){this.#t=t,this.#i=e,new g(t).add("enterpictureinpicture",this.#e.bind(this)).add("leavepictureinpicture",this.#s.bind(this))}get active(){return document.pictureInPictureElement===this.#t}get supported(){return u(this.#t)}async enter(){return this.#t.requestPictureInPicture()}exit(){return document.exitPictureInPicture()}#e(t){this.#n(!0,t)}#s(t){this.#n(!1,t)}#n=(t,e)=>{this.#i.notify("picture-in-picture-change",t,e)}}class M{#t;#i;#e="inline";get mode(){return this.#e}constructor(t,e){this.#t=t,this.#i=e,P(t,"webkitpresentationmodechanged",this.#s.bind(this))}get supported(){return o(this.#t)}async setPresentationMode(t){this.#e!==t&&this.#t.webkitSetPresentationMode(t)}#s(t){const e=this.#e;this.#e=this.#t.webkitPresentationMode,this.#i.player?.dispatch(new f("video-presentation-change",{detail:this.#e,trigger:t})),["fullscreen","picture-in-picture"].forEach(i=>{(this.#e===i||e===i)&&this.#i.notify(`${i}-change`,this.#e===i,t)})}}class w{#t;get active(){return this.#t.mode==="fullscreen"}get supported(){return this.#t.supported}constructor(t){this.#t=t}async enter(){this.#t.setPresentationMode("fullscreen")}async exit(){this.#t.setPresentationMode("inline")}}class I{#t;get active(){return this.#t.mode==="picture-in-picture"}get supported(){return this.#t.supported}constructor(t){this.#t=t}async enter(){this.#t.setPresentationMode("picture-in-picture")}async exit(){this.#t.setPresentationMode("inline")}}class H extends m{$$PROVIDER_TYPE="VIDEO";get type(){return"video"}airPlay;fullscreen;pictureInPicture;constructor(t,e){super(t,e),l(()=>{if(this.airPlay=new x(t,e),o(t)){const i=new M(t,e);this.fullscreen=new w(i),this.pictureInPicture=new I(i)}else u(t)&&(this.pictureInPicture=new v(t,e))},this.scope)}setup(){super.setup(),p(this.video)&&new T(this.video,this.ctx),this.ctx.textRenderers.attachVideo(this.video),h(()=>{this.ctx.textRenderers.attachVideo(null)}),this.type==="video"&&this.ctx.notify("provider-setup",this)}get video(){return this.media}}export{H as VideoProvider};
