UNPKG

@aidenlx/player

Version:

Headless web components that make integrating media on the a web a breeze.

2 lines (1 loc) 1.64 kB
import{a as d}from"./chunk.KCC3AAG2.js";import{T as p,a,b as c,f as r,fa as g,j as h,ja as y,k as f,m as v}from"./chunk.PWTX2M5C.js";var n=new Set,m=!1,u=!1,o=class extends y{constructor(){super(...arguments);this.singlePlayback=!1;this.sharedVolume=!1;this._=new h;this.xr=f(this,"vds-media-provider-connect",e=>{let{element:t,onDisconnect:l}=e.detail;this.r=t,n.add(t);let i=this.rs();if(i&&(this.r.volume=i.volume,this.r.muted=i.muted),this.singlePlayback){let s=r(t,"vds-play",this.is.bind(this));this._.add(s)}if(this.sharedVolume){let s=r(t,"vds-volume-change",g(this.ss.bind(this),10,!0));this._.add(s)}if(this.volumeStorageKey){let s=r(t,"vds-volume-change",this.ns.bind(this));this._.add(s)}this._.add(()=>{n.delete(t),this.r=void 0}),l(()=>{this._.empty()})})}disconnectedCallback(){super.disconnectedCallback(),this._.empty()}render(){return c`<slot></slot>`}get mediaProvider(){return this.r}is(){m||(m=!0,n.forEach(e=>{e!==this.r&&(e.paused=!0)}),m=!1)}ss(e){if(u)return;u=!0;let{volume:t,muted:l}=e.detail;n.forEach(i=>{i!==this.r&&(i.volume=t,i.muted=l)}),this.dispatchEvent(v("vds-media-volume-sync",{bubbles:!0,composed:!0,detail:e.detail})),u=!1}rs(){if(!!this.volumeStorageKey)try{return JSON.parse(localStorage.getItem(this.volumeStorageKey))}catch{return}}ns(e){!this.volumeStorageKey||localStorage.setItem(this.volumeStorageKey,JSON.stringify(e.detail))}};a([d({type:Boolean,attribute:"single-playback"})],o.prototype,"singlePlayback",2),a([d({type:Boolean,attribute:"shared-volume"})],o.prototype,"sharedVolume",2),a([d({attribute:"volume-storage-key"})],o.prototype,"volumeStorageKey",2);p("vds-media-sync",o);