UNPKG

@7sage/vidstack

Version:

UI component library for building high-quality, accessible video and audio experiences on the web.

2 lines (1 loc) 3.18 kB
import{o,E as p,l,D as P,n as f}from"../chunks/vidstack-CYF5HBsg.js";import{h as u,j as h,k as m}from"../chunks/vidstack-0lhgLM-q.js";import{HTMLMediaProvider as g}from"./vidstack-html-DqGqfYX1.js";import{H as k}from"../chunks/vidstack-nEvfQ4dL.js";import{a as x,T as s}from"../chunks/vidstack-DI6EtP9D.js";import"../chunks/vidstack-D3XUwguk.js";import"../chunks/vidstack-BJ_Bs2CC.js";import"../chunks/vidstack-C_AxqLKV.js";import"../chunks/vidstack-BH4h6ty-.js";class T{#t;#i;constructor(t,e){this.#t=t,this.#i=e,t.textTracks.onaddtrack=this.#e.bind(this),o(this.#r.bind(this))}#e(t){const e=t.track;if(!e||y(this.#t,e))return;const i=new x({id:e.id,kind:e.kind,label:e.label??"",language:e.language,type:"vtt"});i[s.native]={track:e},i[s.readyState]=2,i[s.nativeHLS]=!0;let a=0;const c=d=>{if(e.cues)for(let n=a;n<e.cues.length;n++)i.addCue(e.cues[n],d),a++};c(t),e.oncuechange=c,this.#i.textTracks.add(i,t),i.setMode(e.mode,t)}#r(){this.#t.textTracks.onaddtrack=null;for(const t of this.#i.textTracks){const e=t[s.native]?.track;e?.oncuechange&&(e.oncuechange=null)}}}function y(r,t){return Array.from(r.children).find(e=>e.track===t)}class v{#t;#i;constructor(t,e){this.#t=t,this.#i=e,new p(t).add("enterpictureinpicture",this.#e.bind(this)).add("leavepictureinpicture",this.#r.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.#s(!0,t)}#r(t){this.#s(!1,t)}#s=(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,l(t,"webkitpresentationmodechanged",this.#r.bind(this))}get supported(){return h(this.#t)}async setPresentationMode(t){this.#e!==t&&this.#t.webkitSetPresentationMode(t)}#r(t){const e=this.#e;this.#e=this.#t.webkitPresentationMode,this.#i.player?.dispatch(new P("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 E{#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 I extends g{$$PROVIDER_TYPE="VIDEO";get type(){return"video"}airPlay;fullscreen;pictureInPicture;constructor(t,e){super(t,e),f(()=>{if(this.airPlay=new k(t,e),h(t)){const i=new M(t,e);this.fullscreen=new w(i),this.pictureInPicture=new E(i)}else u(t)&&(this.pictureInPicture=new v(t,e))},this.scope)}setup(){super.setup(),m(this.video)&&new T(this.video,this.ctx),this.ctx.textRenderers.attachVideo(this.video),o(()=>{this.ctx.textRenderers.attachVideo(null)}),this.type==="video"&&this.ctx.notify("provider-setup",this)}get video(){return this.media}}export{I as VideoProvider};