var o=Object.defineProperty;var g=(n,a,d)=>a in n?o(n,a,{enumerable:!0,configurable:!0,writable:!0,value:d}):n[a]=d;var l=(n,a,d)=>(g(n,typeof a!="symbol"?a+"":a,d),d);function R(n){return class extends n{constructor(){super(...arguments);l(this,"_playedRanges",[]);l(this,"_currentPlayedRange",null);l(this,"_RANGE_EPSILON",.5);l(this,"_seeking",!1)}connectedCallback(){super.connectedCallback&&super.connectedCallback(),this.addEventListener("play",()=>this.onPlaybackStart({time:this.currentTime})),this.addEventListener("pause",()=>this.onPlaybackStop({time:this.currentTime})),this.addEventListener("ended",()=>this.onPlaybackStop({time:this.currentTime})),this.addEventListener("seeking",()=>this.onSeeking()),this.addEventListener("seeked",()=>this.onSeeked({time:this.currentTime}))}onPlaybackStart(e={}){this._seeking=!1;const{time:t}=e,s=typeof t=="number"?t:this.currentTime;this._currentPlayedRange||(this._currentPlayedRange={start:s,end:s})}onSeeking(){this._seeking=!0,this._commitCurrentRange()}onSeeked(e={}){this._seeking=!1;const{time:t}=e,s=typeof t=="number"?t:this.currentTime;this._currentPlayedRange={start:s,end:s}}onPlaybackStop(e={}){const{time:t}=e,s=typeof t=="number"?t:this.currentTime;this._commitCurrentRange(s)}_commitCurrentRange(e){if(!this._currentPlayedRange)return;typeof e=="number"&&(this._currentPlayedRange.end=e);const{start:t,end:s}=this._currentPlayedRange;this._currentPlayedRange=null,this.addPlayedRange(t,s)}addPlayedRange(e,t){if(e>=t)return;const s=this._RANGE_EPSILON,h=[...this._playedRanges,{start:e,end:t}];h.sort((i,r)=>i.start-r.start);const c=[];for(const i of h){if(!c.length){c.push({...i});continue}const r=c[c.length-1];i.start<=r.end+s?(r.start=Math.min(r.start,i.start),r.end=Math.max(r.end,i.end)):c.push({...i})}this._playedRanges=c}get played(){const e=this.currentTime;return!this.paused&&!this._currentPlayedRange&&typeof e=="number"&&(this._currentPlayedRange={start:e,end:e}),this._currentPlayedRange&&typeof e=="number"&&(e>this._currentPlayedRange.end&&(this._currentPlayedRange.end=e),this.addPlayedRange(this._currentPlayedRange.start,this._currentPlayedRange.end)),this._playedRanges.length?u(this._playedRanges.map(t=>[t.start,t.end])):u([[0,0]])}}}function u(n){return Object.defineProperties(n,{start:{value:a=>n[a][0]},end:{value:a=>n[a][1]}}),n}export{R as M};
