UNPKG

@tindtechnologies/universalviewer

Version:

The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎

2 lines 979 kB
/*! For license information please see 3989.603bfee8206c700cf726.js.LICENSE.txt */ (self.webpackChunkUV=self.webpackChunkUV||[]).push([[3989],{3989:(t,e,i)=>{"use strict";i.d(e,{ZM:()=>It});var n=i(6346);class r{}r.NEXT_RANGE="nextrange",r.PAUSECANVAS="pause",r.PLAYCANVAS="play",r.PREVIOUS_RANGE="previousrange";var a=i(3664);class s{}function o(t,e){const i=n.Utils.getTemporalComponent(e);if(i){let n=0;const r=e.substr(0,e.indexOf("#"));for(let e=0;e<t.length;e++){const i=t[e];if(i.id.includes(r))break;{const t=i.getDuration();t&&(n+=t)}}return i[0]=Number(i[0])+n,i[1]=Number(i[1])+n,r+"#t="+i[0]+","+i[1]}}s.VOLUME_CHANGED="volumechanged";var l=i(4692);i(4692);class u{constructor(){this.canvases=[],this.durationMap={},this.totalDuration=0,this.id=String((new Date).valueOf())}addCanvas(t){this.canvases.push(l.extend(!0,{},t));const e=t.getDuration()||0;this.totalDuration+=e,this.durationMap[t.id]={duration:e,runningDuration:this.totalDuration}}getContent(){const t=[];return this.canvases.forEach((e=>{const i=e.getContent();i.forEach((t=>{const i=t.getTarget();i&&(n.Utils.getTemporalComponent(i)||(t.__jsonld.target+="#t=0,"+e.getDuration()))})),i.forEach((t=>{const e=t.getTarget();e&&(t.__jsonld.target=o(this.canvases,e))})),t.push(...i)})),t}getDuration(){let t=0;return this.canvases.forEach((e=>{const i=e.getDuration();i&&(t+=i)})),Math.floor(t)}getWidth(){return this.canvases.length?this.canvases[0].getWidth():0}getHeight(){return this.canvases.length?this.canvases[0].getHeight():0}}function c(){try{return window.Hls}catch(t){return null}}class d{constructor(t,e={}){this.source=t,this.options=e}attachTo(t){t.setAttribute("src",this.source)}}class h extends d{constructor(t,e={}){super(t,e),this.player=dashjs.MediaPlayer().create(),this.player.getDebug().setLogToBrowserConsole(!1),e.adaptiveAuthEnabled&&this.player.setXHRWithCredentialsForType("MPD",!0)}attachTo(t){this.player.initialize(t,this.source,!1)}debug(){this.player.getDebug().setLogToBrowserConsole(!0),this.player.getDebug().setLogLevel(4)}}class f extends d{constructor(t,e={}){super(t,e);const i=c();i&&(e.adaptiveAuthEnabled?this.hls=new i({xhrSetup:t=>{t.withCredentials=!0}}):this.hls=new i,this.hls.loadSource(this.source))}attachTo(t){this.hls&&this.hls.attachMedia(t)}}class p extends d{constructor(t,e={}){super(t,e)}attachTo(t){t.src=this.source}}class g extends d{constructor(t,e={}){super(t,e)}}const m={enabled:!0,log(...t){this.enabled},warn(...t){this.enabled},error(...t){this.enabled},groupCollapsed(...t){this.enabled},group(...t){this.enabled},groupEnd(){this.enabled}};const v=i(4692);class A{constructor(t,e={}){switch(this.playWasRequested=!1,this.pauseWasRequested=!1,this.lastPause=0,this.isPausing=!1,this.source=t,this.mediaSource=t.mediaSource,this.type=t.type.toString().toLowerCase(),this.format=t.format?t.format.toString():void 0,this.mediaSyncMarginSecs=e.mediaSyncMarginSecs||1,this.type){case"video":this.element=document.createElement("video");break;case"sound":case"audio":this.element=document.createElement("audio");break;default:return}this.isDash()?this.instance=new h(this.mediaSource,e):this.isHls()?this.instance=new f(this.mediaSource,e):this.isMpeg()?this.instance=new p(this.mediaSource,e):this.instance=new g(this.mediaSource,e),this.element.classList.add("anno"),e.probed||(this.element.crossOrigin="anonymous"),this.element.preload="metadata",this.instance.attachTo(this.element),this.element.currentTime=this.source.start,this.element.addEventListener("play",(()=>{setTimeout((()=>{this.playWasRequested=!1,this.pauseWasRequested=!1}),0)})),this.element.addEventListener("pause",(()=>{setTimeout((()=>{this.playWasRequested=!1,this.pauseWasRequested=!1}),0)})),this._pauseElement()}_playElement(){return this.playWasRequested=!0,this.pauseWasRequested&&(this.pauseWasRequested=!1),m.log(`HTMLElement.play() request - ${this.element.src}`),this.element.play()}_pauseElement(){this.pauseWasRequested=!0,this.playWasRequested&&(this.playWasRequested=!1),m.log(`HTMLElement.pause() request - ${this.element.src}`);try{this.element.pause()}catch(t){}}syncClock(t){t>this.element.duration?m.error(`Clock synced out of bounds (max: ${this.element.duration}, got: ${t})`):Math.abs(this.element.currentTime-t)>this.mediaSyncMarginSecs&&(this.element.currentTime=t)}getElementTime(){return this.element.currentTime}getCanvasId(){return this.source.canvasId}isWithinRange(t){return this.source.start<=t&&this.source.end>=t}load(t=!1){return e=this,i=void 0,r=function*(){t&&this.element.load(),yield new Promise((t=>{this.element.addEventListener("loadedmetadata",(()=>{t()}))}))},new((n=void 0)||(n=Promise))((function(t,a){function s(t){try{l(r.next(t))}catch(t){a(t)}}function o(t){try{l(r.throw(t))}catch(t){a(t)}}function l(e){var i;e.done?t(e.value):(i=e.value,i instanceof n?i:new n((function(t){t(i)}))).then(s,o)}l((r=r.apply(e,i||[])).next())}));var e,i,n,r}setSize(t,e,i,n){v(this.element).css({top:`${t}%`,left:`${e}%`,width:`${i}%`,height:`${n}%`})}isDash(){return this.format&&"application/dash+xml"===this.format.toString()&&"undefined"!=typeof dashjs}isHls(){const t=c();return this.format&&"application/vnd.apple.mpegurl"===this.format.toString()&&null!=t&&t.isSupported()}isMpeg(){return!this.element.canPlayType||""!==this.element.canPlayType("application/vnd.apple.mpegurl")}stop(){this._pauseElement(),this.element.currentTime=this.source.start}play(t){return m.log(`MediaElement.play(${t}) - ${this.element.src}`),void 0!==t&&(this.element.currentTime=t),this._playElement()}pause(){m.log(`MediaElement.pause() request - ${this.element.src}`);const t=Date.now();if(this.lastPause+1e3>t){if(this.isPausing)return;return this.isPausing=!0,void setTimeout((()=>{this._pauseElement(),this.isPausing=!1,this.lastPause=Date.now()}),500)}this.lastPause=Date.now(),this._pauseElement()}addEventListener(t,e){this.element.addEventListener(t,(()=>{"play"!==t?("pause"!==t||this.pauseWasRequested)&&e():this.playWasRequested&&e()}))}getRawElement(){return this.element}isPaused(){return this.element.paused}setVolume(t){this.element.volume=t}isBuffering(){return this.element.readyState<3}}function _(t,e){return t+e}function y(t,e){return t-e}function b(t){return 1e3*t}function T(t){return t/1e3}var E=function(t,e,i,n){return new(i||(i=Promise))((function(r,a){function s(t){try{l(n.next(t))}catch(t){a(t)}}function o(t){try{l(n.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,o)}l((n=n.apply(t,e||[])).next())}))};class w{constructor(t,e,i,n,r,a){this.continuous=!0,this.playing=!1,this._time=0,m.log("TimePlanPlayer",{media:t,plan:e}),this.media=t,this.plan=e,this.fullPlan=e,this.currentStop=e.stops[0];const s=()=>{};this.notifyRangeChange=i||s,this.notifyTimeChange=n||s,this.notifyPlaying=r||s,this.notifyBuffering=a||s,this.logging=!0,this.currentRange=this.currentStop.rangeStack[0],this.setTime(this.currentStop.start),t.onPlay(((t,e,i)=>{t===this.currentStop.canvasId&&(this.playing||this.notifyPlaying(!0))})),t.onBuffering((()=>{this.notifyBuffering()})),t.onPause(((t,e,i)=>{i.isBuffering()||t===this.currentStop.canvasId&&this.playing&&this.notifyPlaying(!1)}))}selectPlan({reset:t,rangeId:e}={}){if(t)return this.initialisePlan(this.fullPlan);if(e){let t=[];for(const i of this.fullPlan.stops){const n=i.rangeStack.indexOf(e);-1!==i.rangeStack.indexOf(e)&&(t=i.rangeStack.slice(1,n+1))}let i=this.fullPlan;for(const e of t)for(const t of i.items)if("time-plan"===t.type&&t.rangeId===e){i=t;break}if(i)return this.initialisePlan(i)}}initialisePlan(t){this.plan=t}getCurrentRange(){const t=this.currentRange,e=this.currentRange===this.currentStop.rangeId,i=e?this.plan.stops:this.fullPlan.stops,n=[],r=[];for(const a of i)-1!==a.rangeStack.indexOf(t)&&(n.push(a.start),r.push(a.end)),e&&a.rangeId===t&&(n.push(a.start),r.push(a.end));const a=Math.min(...n),s=Math.max(...r);return m.log("Range duration",{starting:n,ending:r,rangeId:t,isRangeWithStop:e,stopsToCheck:i,start:a-this.plan.start,end:s-this.plan.start,planStart:this.plan.start,duration:s-a,currentStop:this.currentStop}),{start:a-this.plan.start,end:s-this.plan.start,duration:s-a}}getTime(){return this._time}setInternalTime(t){return this._time=t,this.notifyTimeChange(t),this._time}log(...t){this.logging&&m.log("TimePlanPlayer",...t)}setContinuousPlayback(t){this.continuous=t}setIsPlaying(t){this.playing=t}play(){return this.log("Play",this.getTime()),this.playing||(this.setIsPlaying(!0),this.media.play(this.currentStop.canvasId).catch((t=>{console.log("Err",t),this.setIsPlaying(!1),this.notifyPlaying(!1)}))),this.getTime()}currentTimelineTime(){return this.getTime()}currentMediaTime(){return m.log(`Current media time:\n - Current start: ${this.currentStop.start}\n - Current canvas: ${this.currentStop.canvasTime.start}\n - Current time: ${this.getTime()}\n `,this),_(y(this.getTime(),this.currentStop.start),this.currentStop.canvasTime.start)}validateExternalTime(t){const e=this.findStop(t),i=this.findStop(t+1);return i&&e!==i?(m.log("Skipping to next stop",{nextStop:i,currentStop:e}),null==i?void 0:i.start):t}pause(){return this.log("Pause",this.getTime()),this.setIsPlaying(!1),this.media.pause(),this.getTime()}setVolume(t){this.media.setVolume(t)}findStop(t){for(const e of this.plan.stops)if(e.start-.001<=t&&e.end-.001>t)return e;if(this.plan.stops[this.plan.stops.length-1].end===t)return this.plan.stops[this.plan.stops.length-1]}setTime(t,e=!0){return E(this,void 0,void 0,(function*(){if(m.groupCollapsed(`TimeplanPlayer.setTime(${t}, ${e?"true":"false"})`),this.getTime()!==t){this.log("set time",{from:this.getTime(),to:t}),this.setInternalTime(t);const i=this.findStop(t);i&&i!==this.currentStop&&(e&&(this.currentRange=i.rangeId),yield this.advanceToStop(this.currentStop,i,void 0,t,!this.playing))}m.groupEnd()}))}next(){return E(this,void 0,void 0,(function*(){const t=this.plan.rangeOrder.indexOf(this.currentRange),e=t>=0&&t===this.plan.rangeOrder.length-1?void 0:this.plan.rangeOrder.indexOf(this.currentRange)+1;let i=void 0!==e?this.plan.rangeOrder[e]:void 0;const n=this.plan.stops.indexOf(this.currentStop);let r,a=0,s=!0;for(;s;){if(a++,r=this.plan.stops[n+a],!r){s=!1;break}if(!r.noNav&&r.rangeId!==this.currentStop.rangeId){s=!1;break}}return this.playing&&r&&(i=r.rangeId),i&&r&&r.rangeId!==i?(this.playing||-1===this.currentStop.rangeStack.indexOf(i)&&-1!==r.rangeStack.indexOf(i)?(this.currentRange=this.playing?r.rangeId:i,this.setInternalTime(r.start),yield this.advanceToStop(this.currentStop,r,this.playing?r.rangeId:i)):(this.currentRange=i,this.setInternalTime(this.currentStop.start),yield this.advanceToStop(this.currentStop,this.currentStop,i)),this.getTime()):(r?(this.setInternalTime(r.start),this.currentRange=r.rangeId,yield this.advanceToStop(this.currentStop,r,r.rangeId)):yield this.goToEndOfRange(this.currentStop.rangeId),setTimeout((()=>{this.playing&&this.play()}),100),this.getTime())}))}goToEndOfRange(t){return E(this,void 0,void 0,(function*(){let e;for(let i=0;i<this.plan.stops.length;i++){const n=this.plan.stops[i];n.rangeId===t&&(!e||n.canvasIndex>=e.canvasIndex&&n.end>e.end)&&(e=n)}e&&(yield this.advanceToStop(this.currentStop,e,t),this.setInternalTime(e.end))}))}goToStartOfRange(t){let e;for(let i=this.plan.stops.length-1;i>=0;i--){const n=this.plan.stops[i];n.rangeId===t&&(!e||n.canvasIndex<=e.canvasIndex&&n.start<e.start)&&(e=n)}e&&(e!==this.currentStop&&this.advanceToStop(this.currentStop,e,t),this.setInternalTime(e.start))}setRangeTime(t,e,i=!1){return E(this,void 0,void 0,(function*(){let n;if(this.plan.rangeId===t?n=this.plan:this.fullPlan.rangeId===t?n=this.fullPlan:this.currentStop.rangeId===t&&(n=this.currentStop),n){let t=n.start+e;i&&(t=this.validateExternalTime(t)),yield this.setTime(t,!1)}}))}previous(){const t=0===this.plan.rangeOrder.indexOf(this.currentRange)?void 0:this.plan.rangeOrder.indexOf(this.currentRange)-1;let e=void 0!==t?this.plan.rangeOrder[t]:void 0,i=this.currentStop;const n=this.plan.stops.indexOf(this.currentStop);let r=n,a=this.plan.stops[n-1];const s=this.plan.stops[0];let o=!0;const l=t=>!t.noNav||t===s;for(;o;){const t=this.plan.stops[r-1];if(!t){o=!1;break}if(l(t)&&l(a)&&(t.rangeId===this.currentRange&&(i=t),a.rangeId!==t.rangeId)){o=!1;break}t&&(l(t)&&(a=t),r-=1)}const u=this._time-(i.start+2)>0,c=this.playing&&a&&a.rangeId!==this.currentStop.rangeId,d=0===n||!e&&0===r,h=e&&-1===this.currentStop.rangeStack.indexOf(e)&&(-1!==a.rangeStack.indexOf(e)||a.rangeId===e),f=e&&-1!==this.currentStop.rangeStack.indexOf(e);return m.log("TimePlanPlayer.previous() => variables",{goBackToStartOfRange:u,isPreviousRangeDifferent:c,isDefinitelyFirstRange:d,isPreviousRangeNotAParent:h,isPreviousRangeInStack:f,prevStop:a}),u?(m.log("TimePlanPlayer.previous() => goBackToStartOfRange",{currentStopHead:i}),i!==this.currentStop&&this.advanceToStop(this.currentStop,i,i.rangeId),this.setInternalTime(i.start),this.getTime()):(c&&(e=a.rangeId),d?(this.goToStartOfRange(e||this.currentStop.rangeId),e&&this.currentStop.rangeId!==e&&(this.currentRange=e,this.advanceToStop(this.currentStop,i,e)),this.getTime()):e&&(h||a===s)?(this.setInternalTime(a.start),this.currentRange=e,this.advanceToStop(this.currentStop,a,e),this.getTime()):e&&f?(this.setInternalTime(this.currentStop.start),this.currentRange=e,this.advanceToStop(this.currentStop,i,e),this.getTime()):this.getTime())}setRange(t){if(m.group("setRange",t),t===this.currentRange)return m.log("id === this.currentRange"),this.getTime();if(this.currentRange=t,t===this.currentStop.rangeId)return m.log("id === this.currentStop.rangeId"),this.getTime();m.log("Looking for stop",this.plan.stops);for(const e of this.plan.stops)if(e.rangeId===t){m.log("Found stop, setting internalTime",e.start),this.setInternalTime(e.start),this.advanceToStop(this.currentStop,e,t,void 0,!this.playing);break}for(const e of this.plan.stops)if(-1!==e.rangeStack.indexOf(t)){m.log("Found stop in rangeStack, setting internalTime",e.start),this.setInternalTime(e.start),this.advanceToStop(this.currentStop,e,t,void 0,!this.playing);break}return m.groupEnd(),this.getTime()}isBuffering(){return this.media.isBuffering()}advanceToTime(t,e){m.groupCollapsed(`TimeplanPlayer.advanceToTime(${t}, ${e?"true":"false"})`);const i=this.findStop(t);return i&&this.currentStop!==i?(m.log("advanceToTime.a"),this.setInternalTime(t),this.advanceToStop(this.currentStop,i,void 0,t,e),m.groupEnd(),{buffering:this.isBuffering(),time:t}):(this.playing&&this.currentRange!==this.currentStop.rangeId&&(this.currentRange=this.currentStop.rangeId,this.notifyRangeChange(this.currentStop.rangeId,{from:this.currentStop,to:this.currentStop})),i?(m.log("advanceToTime.c",{time:this.getTime()}),this.setInternalTime(t),this.media.syncClock(this.currentMediaTime()),m.groupEnd(),{time:t}):(m.log("advanceToTime.b"),this.pause(),this.setTime(this.currentStop.end),m.groupEnd(),{paused:!0,buffering:this.isBuffering(),time:this.currentStop.end}))}hasEnded(){return this.currentStop.end===this.getTime()}advanceToStop(t,e,i,n,r){return E(this,void 0,void 0,(function*(){if(m.log("TimeplanPlayer.advanceToStop",{from:t,to:e,rangeId:i}),t===e)return void(i&&this.notifyRangeChange(i||e.rangeId,{to:e,from:t}));let a;this.log("advanceToStop",e.start);const s=this.currentStop.canvasId!==e.canvasId;this.currentStop=e,this.setInternalTime(void 0!==n?n:e.start),s&&!r?a=this.media.play(e.canvasId,this.currentMediaTime()):(this.log(`advanceToStop -> seekToMediaTime(${this.currentMediaTime()}) ${r?"paused":"playing"}`),a=this.media.seekToMediaTime(this.currentMediaTime(),e.canvasId,r)),this.notifyRangeChange(i||e.rangeId,{to:e,from:t}),yield a}))}getStartTime(){return this.plan.start}getDuration(){return this.plan.duration}}const C=["application/vnd.apple.mpegurl","vnd.apple.mpegurl","audio/mpegurl","audio/x-mpegurl","application/x-mpegurl","video/x-mpegurl","video/mpegurl","application/mpegurl"];function I(t){return C.includes(t.toString())}function x(t){return"application/dash+xml"===t.toString()}function D(){const t=c(),e="object"==typeof document&&document,i=e&&e.createElement("video");return C.some((t=>!!i&&/maybe|probably/i.test(i.canPlayType(t))))||t&&t.isSupported()}function S(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function M(t){const e=t.getBody();if(!e.length)return null;for(let t=0;t<e.length;t++){const i=e[t],n=i.getFormat();if(n&&I(n)&&D())return i}for(let t=0;t<e.length;t++){const i=e[t],n=i.getFormat();if(n&&x(n)&&!S())return i}for(let t=0;t<e.length;t++){const i=e[t],n=i.getFormat();if(n&&!I(n)&&!x(n))return i}return null}const R=i(4692);class P extends a.${constructor(t){super(t),this._lastVolume=1,this._data={volume:1},this._init(),this._resize()}_init(){const t=super._init();this._$element=R(this.el),t||m.error("Component failed to initialise"),this._$volumeMute=R(`\n <button class="btn volume-mute" title="${this.options.data.content.mute}">\n <i class="av-icon av-icon-mute on" aria-hidden="true"></i>\n <span class="sr-only>${this.options.data.content.mute}</span>\n </button>\n `),this._$volumeSlider=R('<div class="volume-slider"></div>'),this._$element.append(this._$volumeMute,this._$volumeSlider);const e=this;return this._$volumeMute.on("touchstart click",(t=>{t.preventDefault(),0!==this._data.volume?(this._lastVolume=this._data.volume,this._data.volume=0):this._data.volume=this._lastVolume,this.fire(s.VOLUME_CHANGED,this._data.volume)})),this._$volumeSlider.slider({value:e._data.volume,step:.1,orientation:"horizontal",range:"min",min:0,max:1,animate:!1,create:function(){},slide:function(t,i){e._data.volume=i.value,0===e._data.volume&&(e._lastVolume=0),e.fire(s.VOLUME_CHANGED,e._data.volume)},stop:function(t,e){}}),t}set(t){this._data=Object.assign(this._data,t),this._render()}_render(){if(void 0!==this._data.volume)if(this._$volumeSlider.slider({value:this._data.volume}),0===this._data.volume){const t=this.options.data.content.unmute;this._$volumeMute.prop("title",t),this._$volumeMute.find("i").switchClass("on","off")}else{const t=this.options.data.content.mute;this._$volumeMute.prop("title",t),this._$volumeMute.find("i").switchClass("off","on")}}_resize(){}}var N=function(t,e,i,n){return new(i||(i=Promise))((function(r,a){function s(t){try{l(n.next(t))}catch(t){a(t)}}function o(t){try{l(n.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,o)}l((n=n.apply(t,e||[])).next())}))};class k{constructor(t){this.elements=[],this.playing=!1,this.canvasMap={},this._onPlay=[],this._onPause=[],this._onBuffering=[],m.log("Composite media element",t),this.elements=t;for(const e of t){const t=e.getCanvasId();this.canvasMap[t]=this.canvasMap[t]?this.canvasMap[t]:[],this.canvasMap[t].push(e),e.addEventListener("play",(()=>{e===this.activeElement&&(m.log("HTMLElement.play() response",{paused:e.getRawElement().paused,readState:e.getRawElement().readyState}),this._onPlay.forEach((i=>i(t,e.getElementTime(),e))))})),e.addEventListener("pause",(()=>{e===this.activeElement&&(m.log("HTMLElement.pause() response"),this._onPause.forEach((i=>i(t,e.getElementTime(),e))))})),e.addEventListener("waiting",(()=>{e===this.activeElement&&this._onBuffering.forEach((i=>i(t,e.getElementTime(),e)))}))}this.activeElement=t[0]}syncClock(t,e){if(m.group("CompositeMediaElement.syncClock"),m.log(`syncClock: ${t}`),m.log({fromTime:t,toTime:t,instance:this}),this.activeElement){const i=e||this.activeElement.getCanvasId();this.updateActiveElement(i,t,this.playing);const n=y(t,this.activeElement.source.start);this.activeElement.syncClock(n)}m.groupEnd()}updateActiveElement(t,e,i){const n=this.findElementInRange(t,e);return this.activeElement&&n&&n!==this.activeElement?(m.log(`CompositeMediaElement.updateActiveElement(canvasId: ${t}, time: ${e})`,{canvasId:n?n.source.canvasId:null,newElement:n}),this.activeElement.stop(),this.activeElement=n,i?(m.log("CompositeMediaElement play=true"),n.play(e)):m.log("CompositeMediaElement play=false"),n):null}onPlay(t){this._onPlay.push(t)}onPause(t){this._onPause.push(t)}onBuffering(t){this._onBuffering.push(t)}findElementInRange(t,e){if(this.canvasMap[t])for(const i of this.canvasMap[t].reverse())if(i.isWithinRange(e))return i}appendTo(t){t.append(this.elements.map((t=>t.getRawElement())))}load(){return N(this,void 0,void 0,(function*(){yield Promise.all(this.elements.map((t=>t.load())))}))}seekToMediaTime(t,e,i){return N(this,void 0,void 0,(function*(){i&&this.pause();const n=this.activeElement;if(m.groupCollapsed("CompositeMediaElement.seekToMediaTime Buffering",{playing:this.playing}),this.activeElement){const i=e||this.activeElement.getCanvasId(),r=this.updateActiveElement(i,t,!1),a=y(t,this.activeElement.source.start);let s;const o=new Promise((t=>s=t));if(this.playing){if(m.log(`CompositeMediaElement.seekToMediaItem(${t})`),yield this.activeElement.play(a).catch((t=>{console.log("ERROR",t),this.playing=!1})),n!==this.activeElement&&r&&(m.log("Active element changed..."),r.isBuffering()||r.isPaused())){const t=setInterval((()=>{this.isBuffering()||s()}),200);yield o,clearInterval(t),m.log("ActiveElement nudge (play)"),yield r.play()}}else this.activeElement.syncClock(a)}m.groupEnd()}))}seekTo(t,e){return N(this,void 0,void 0,(function*(){return this.updateActiveElement(t,e),this.seekToMediaTime(e)}))}play(t,e){return N(this,void 0,void 0,(function*(){if(m.log(`CompositeMediaElement.play(${t}, ${e})`,{hasActive:!!this.activeElement}),this.playing=!0,t&&void 0!==e&&(yield this.seekTo(t,e)),this.activeElement)return this.activeElement.play(e).catch((t=>{console.log("err",t),this.playing=!1}))}))}pause(){m.log("Composite.pause()"),this.playing=!1,this.activeElement&&!this.activeElement.isPaused()&&this.activeElement.pause()}setVolume(t){for(const e of this.elements)e.setVolume(t)}isBuffering(){return!!this.activeElement&&this.activeElement.isBuffering()}}function O(t){const e=/xywh=([^&]+)/g.exec(t);let i=null;return e&&e[1]&&(i=e[1].split(",")),i}function B(t,e,i){const r=e.getType(),a=e.getFormat()||void 0,s=e.id.split("#")[0],o=t.getTarget();if(!o)throw new Error("No target");if(!r)throw new Error("Unknown media type");const[l,u,c,d]=O(o)||[0,0,i.width||0,i.height||0],[h,f]=n.Utils.getTemporalComponent(o)||[0,i.duration],[,p,g,m]=e.id.match(/(.*)#t=([0-9.]+),?([0-9.]+)?/)||[void 0,e.id,void 0,void 0];return{type:r,format:a,mediaSource:s,canvasId:i.id,x:l,y:u,width:void 0===c?void 0:parseInt(String(c),10),height:void 0===d?void 0:parseInt(String(d),10),start:Number(Number(h).toFixed(2)),end:Number(Number(f).toFixed(2)),bodyId:p,offsetStart:void 0===g?void 0:parseFloat(g),offsetEnd:void 0===m?void 0:parseFloat(m)}}class F{}function L(t){let e,i,n,r,a=Math.max(0,t);return Number.isNaN(a)&&(a=0),a<.5&&(a=0),Number.isFinite(a)||(a=0),n=Math.ceil(a),e=Math.floor(n/3600),e=e>=10?e:"0"+e,i=Math.floor(n%3600/60),i=i>=10?i:"0"+i,n=Math.floor(n%3600%60),n=n>=10?n:"0"+n,r=e>=1?e+":":"",r+i+":"+n}function U(t,e){const i=[];return Object.keys(t).forEach((n=>{Object.is(e[n],t[n])||i.push(n)})),i}function H(t,e){return Array.from(new Set(U(t,e).concat(U(e,t))))}function W(t){return!!t&&t instanceof u}F.PLAY="play",F.PAUSE="pause",F.MEDIA_READY="mediaready",F.MEDIA_ERROR="mediaerror",F.LOG="log",F.RANGE_CHANGED="rangechanged",F.WAVEFORM_READY="waveformready",F.WAVEFORMS_READY="waveformsready";var G=Object.defineProperty,z=(t,e,i)=>(((t,e,i)=>{e in t?G(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);const V=t=>{let e;const i=new Set,n=(t,n)=>{const r="function"==typeof t?t(e):t;if(!Object.is(r,e)){const t=e;e=(null!=n?n:"object"!=typeof r)?r:Object.assign({},e,r),i.forEach((i=>i(e,t)))}},r=()=>e,a={setState:n,getState:r,subscribe:t=>(i.add(t),()=>i.delete(t)),destroy:()=>i.clear()};return e=t(n,r,a),a};function Y(t,e){const i=(t||"").replace(/\n/,"").trim();return void 0!==e?i.split(e):i}function j(t,e){this._waveformData=t,this._channelIndex=e}j.prototype.min_sample=function(t){var e=2*(t*this._waveformData.channels+this._channelIndex);return this._waveformData._at(e)},j.prototype.max_sample=function(t){var e=2*(t*this._waveformData.channels+this._channelIndex)+1;return this._waveformData._at(e)},j.prototype.set_min_sample=function(t,e){var i=2*(t*this._waveformData.channels+this._channelIndex);return this._waveformData._set_at(i,e)},j.prototype.set_max_sample=function(t,e){var i=2*(t*this._waveformData.channels+this._channelIndex)+1;return this._waveformData._set_at(i,e)},j.prototype.min_array=function(){return this._waveformData._offsetValues(0,this._waveformData.length,2*this._channelIndex)},j.prototype.max_array=function(){return this._waveformData._offsetValues(0,this._waveformData.length,2*this._channelIndex+1)};var q=127,X=-128;function K(t){return(K="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var Q,Z=("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9jb2RlLmdvb2dsZS5jb20vcC9hdWRhY2l0eS9zb3VyY2UvYnJvd3NlL2F1ZGFjaXR5LXNyYy90cnVuay9zcmMvQmxvY2tGaWxlLmNwcAogICAqLwogIHZhciBJTlQ4X01BWCA9IDEyNzsKICB2YXIgSU5UOF9NSU4gPSAtMTI4OwoKICBmdW5jdGlvbiBjYWxjdWxhdGVXYXZlZm9ybURhdGFMZW5ndGgoYXVkaW9fc2FtcGxlX2NvdW50LCBzY2FsZSkgewogICAgdmFyIGRhdGFfbGVuZ3RoID0gTWF0aC5mbG9vcihhdWRpb19zYW1wbGVfY291bnQgLyBzY2FsZSk7CiAgICB2YXIgc2FtcGxlc19yZW1haW5pbmcgPSBhdWRpb19zYW1wbGVfY291b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uZWwgPSAwOyBjaGFubmVsIDwgY2hhbm5lbHMubGVuZ3RoOyArK2NoYW5uZWwpIHsKICAgICAgICAgIHNhbXBsZSArPSBjaGFubmVsc1tjaGFubmVsXVtpXTsKICAgICAgICB9CgogICAgICAgIHNhbXBsZSA9IE1hdGguZmxvb3IoSU5UOF9NQVggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwoKICAgICAgICBpZiAoc2FtcGxlIDwgbWluX3ZhbHVlWzBdKSB7CiAgICAgICAgICBtaW5fdmFsdWVbMF0gPSBzYW1wbGU7CgogICAgICAgICAgaWYgKG1pbl92YWx1ZVswXSA8IElOVDhfTUlOKSB7CiAgICAgICAgICAgIG1pbl92YWx1ZVswXSA9IElOVDhfTUlOOwogICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaWYgKHNhbXBsZSA+IG1heF92YWx1ZVswXSkgewogICAgICAgICAgbWF4X3ZhbHVlWzBdID0gc2FtcGxlOwoKICAgICAgICAgIGlmIChtYXhfdmFsdWVbMF0gPiBJTlQ4X01BWCkgewogICAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBJTlQ4X01BWDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yIChjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgKytjaGFubmVsKSB7CiAgICAgICAgICBzYW1wbGUgPSBNYXRoLmZsb29yKElOVDhfTUFYICogY2hhbm5lbHNbY2hhbm5lbF1baV0gKiBhbXBsaXR1ZGVfc2NhbGUpOwoKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbY2hhbm5lbF0pIHsKICAgICAgICAgICAgbWluX3ZhbHVlW2NoYW5uZWxdID0gc2FtcGxlOwoKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtjaGFubmVsXSA8IElOVDhfTUlOKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW2NoYW5uZWxdID0gSU5UOF9NSU47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KCiAgICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlW2NoYW5uZWxdKSB7CiAgICAgICAgICAgIG1heF92YWx1ZVtjaGFubmVsXSA9IHNhbXBsZTsKCiAgICAgICAgICAgIGlmIChtYXhfdmFsdWVbY2hhbm5lbF0gPiBJTlQ4X01BWCkgewogICAgICAgICAgICAgIG1heF92YWx1ZVtjaGFubmVsXSA9IElOVDhfTUFYOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CgogICAgICBpZiAoKytzY2FsZV9jb3VudGVyID09PSBzY2FsZSkgewogICAgICAgIGZvciAoY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBvdXRwdXRfY2hhbm5lbHM7IGNoYW5uZWwrKykgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1pbl92YWx1ZVtjaGFubmVsXSk7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWF4X3ZhbHVlW2NoYW5uZWxdKTsKICAgICAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICAgICAgbWF4X3ZhbHVlW2NoYW5uZWxdID0gLUluZmluaXR5OwogICAgICAgIH0KCiAgICAgICAgc2NhbGVfY291bnRlciA9IDA7CiAgICAgIH0KICAgIH0KCiAgICBpZiAoc2NhbGVfY291bnRlciA+IDApIHsKICAgICAgZm9yIChjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1pbl92YWx1ZVtjaGFubmVsXSk7CiAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtjaGFubmVsXSk7CiAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gYnVmZmVyOwogIH0KCiAgb25tZXNzYWdlID0gZnVuY3Rpb24gb25tZXNzYWdlKGV2dCkgewogICAgdmFyIGJ1ZmZlciA9IGdlbmVyYXRlV2F2ZWZvcm1EYXRhKGV2dC5kYXRhKTsgLy8gVHJhbnNmZXIgYnVmZmVyIHRvIHRoZSBjYWxsaW5nIHRocmVhZAoKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Cgo=",null,!1,function(t){return Q=Q||function(t,e,i){var n=void 0===e?null:e,r=function(t,e){var i=atob(t);if(e){for(var n=new Uint8Array(i.length),r=0,a=i.length;r<a;++r)n[r]=i.charCodeAt(r);return String.fromCharCode.apply(null,new Uint16Array(n.buffer))}return i}(t,void 0!==i&&i),a=r.indexOf("\n",10)+1,s=r.substring(a)+(n?"//# sourceMappingURL="+n:""),o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9jb2RlLmdvb2dsZS5jb20vcC9hdWRhY2l0eS9zb3VyY2UvYnJvd3NlL2F1ZGFjaXR5LXNyYy90cnVuay9zcmMvQmxvY2tGaWxlLmNwcAogICAqLwogIHZhciBJTlQ4X01BWCA9IDEyNzsKICB2YXIgSU5UOF9NSU4gPSAtMTI4OwoKICBmdW5jdGlvbiBjYWxjdWxhdGVXYXZlZm9ybURhdGFMZW5ndGgoYX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XRfY2hhbm5lbHMsIHRydWUpOwogICAgfQoKICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7IGkrKykgewogICAgICB2YXIgc2FtcGxlID0gMDsKCiAgICAgIGlmIChvdXRwdXRfY2hhbm5lbHMgPT09IDEpIHsKICAgICAgICBmb3IgKGNoYW5uZWwgPSAwOyBjaGFubmVsIDwgY2hhbm5lbHMubGVuZ3RoOyArK2NoYW5uZWwpIHsKICAgICAgICAgIHNhbXBsZSArPSBjaGFubmVsc1tjaGFubmVsXVtpXTsKICAgICAgICB9CgogICAgICAgIHNhbXBsZSA9IE1hdGguZmxvb3IoSU5UOF9NQVggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwoKICAgICAgICBpZiAoc2FtcGxlIDwgbWluX3ZhbHVlWzBdKSB7CiAgICAgICAgICBtaW5fdmFsdWVbMF0gPSBzYW1wbGU7CgogICAgICAgICAgaWYgKG1pbl92YWx1ZVswXSA8IElOVDhfTUlOKSB7CiAgICAgICAgICAgIG1pbl92YWx1ZVswXSA9IElOVDhfTUlOOwogICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaWYgKHNhbXBsZSA+IG1heF92YWx1ZVswXSkgewogICAgICAgICAgbWF4X3ZhbHVlWzBdID0gc2FtcGxlOwoKICAgICAgICAgIGlmIChtYXhfdmFsdWVbMF0gPiBJTlQ4X01BWCkgewogICAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBJTlQ4X01BWDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yIChjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgKytjaGFubmVsKSB7CiAgICAgICAgICBzYW1wbGUgPSBNYXRoLmZsb29yKElOVDhfTUFYICogY2hhbm5lbHNbY2hhbm5lbF1baV0gKiBhbXBsaXR1ZGVfc2NhbGUpOwoKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbY2hhbm5lbF0pIHsKICAgICAgICAgICAgbWluX3ZhbHVlW2NoYW5uZWxdID0gc2FtcGxlOwoKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtjaGFubmVsXSA8IElOVDhfTUlOKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW2NoYW5uZWxdID0gSU5UOF9NSU47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KCiAgICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlW2NoYW5uZWxdKSB7CiAgICAgICAgICAgIG1heF92YWx1ZVtjaGFubmVsXSA9IHNhbXBsZTsKCiAgICAgICAgICAgIGlmIChtYXhfdmFsdWVbY2hhbm5lbF0gPiBJTlQ4X01BWCkgewogICAgICAgICAgICAgIG1heF92YWx1ZVtjaGFubmVsXSA9IElOVDhfTUFYOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CgogICAgICBpZiAoKytzY2FsZV9jb3VudGVyID09PSBzY2FsZSkgewogICAgICAgIGZvciAoY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBvdXRwdXRfY2hhbm5lbHM7IGNoYW5uZWwrKykgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1pbl92YWx1ZVtjaGFubmVsXSk7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWF4X3ZhbHVlW2NoYW5uZWxdKTsKICAgICAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICAgICAgbWF4X3ZhbHVlW2NoYW5uZWxdID0gLUluZmluaXR5OwogICAgICAgIH0KCiAgICAgICAgc2NhbGVfY291bnRlciA9IDA7CiAgICAgIH0KICAgIH0KCiAgICBpZiAoc2NhbGVfY291bnRlciA+IDApIHsKICAgICAgZm9yIChjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1pbl92YWx1ZVtjaGFubmVsXSk7CiAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtjaGFubmVsXSk7CiAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gYnVmZmVyOwogIH0KCiAgb25tZXNzYWdlID0gZnVuY3Rpb24gb25tZXNzYWdlKGV2dCkgewogICAgdmFyIGJ1ZmZlciA9IGdlbmVyYXRlV2F2ZWZvcm1EYXRhKGV2dC5kYXRhKTsgLy8gVHJhbnNmZXIgYnVmZmVyIHRvIHRoZSBjYWxsaW5nIHRocmVhZAoKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Cgo=",null,false),new Worker(Q,t)});function J(t){if(function(t){return t&&"object"===K(t)&&"sample_rate"in t&&"samples_per_pixel"in t&&"bits"in t&&"length"in t&&"data"in t}(t)&&(t=function(t){var e=t.data,i=t.channels||1,n=8===t.bits?1:2,r=2*t.length*i;if(e.length!==r)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var a=24+e.length*n,s=new ArrayBuffer(a),o=new DataView(s);o.setInt32(0,2,!0),o.setUint32(4,8===t.bits,!0),o.setInt32(8,t.sample_rate,!0),o.setInt32(12,t.samples_per_pixel,!0),o.setInt32(16,t.length,!0),o.setInt32(20,i,!0);var l,u=24;if(8===t.bits)for(l=0;l<e.length;l++)o.setInt8(u++,e[l],!0);else for(l=0;l<e.length;l++)o.setInt16(u,e[l],!0),u+=2;return s}(t)),!function(t){var e=t&&"object"===K(t)&&"byteLength"in t;if(e){var i=new DataView(t).getInt32(0,!0);if(1!==i&&2!==i)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return e}(t))throw new TypeError("WaveformData.create(): Unknown data format");this._data=new DataView(t),this._offset=2===this._version()?24:20,this._channels=[];for(var e=0;e<this.channels;e++)this._channels[e]=new j(this,e)}function $(t,e,i){var n=function(t){for(var e=[],i=0;i<t.numberOfChannels;++i)e.push(t.getChannelData(i).buffer);return e}(t);if(e.disable_worker){var r=function(t){var e,i,n=t.scale,r=t.amplitude_scale,a=t.split_channels,s=t.length,o=t.sample_rate,l=t.channels.map((function(t){return new Float32Array(t)})),u=a?l.length:1,c=1===u?1:2,d=1===c?20:24,h=function(t,e){var i=Math.floor(t/e);return t-i*e>0&&i++,i}(s,n),f=new ArrayBuffer(d+2*h*u),p=new DataView(f),g=0,m=d,v=new Array(u),A=new Array(u);for(e=0;e<u;e++)v[e]=1/0,A[e]=-1/0;for(p.setInt32(0,c,!0),p.setUint32(4,1,!0),p.setInt32(8,o,!0),p.setInt32(12,n,!0),p.setInt32(16,h,!0),2===c&&p.setInt32(20,u,!0),i=0;i<s;i++){var _=0;if(1===u){for(e=0;e<l.length;++e)_+=l[e][i];(_=Math.floor(q*_*r/l.length))<v[0]&&(v[0]=_,v[0]<X&&(v[0]=X)),_>A[0]&&(A[0]=_,A[0]>q&&(A[0]=q))}else for(e=0;e<u;++e)(_=Math.floor(q*l[e][i]*r))<v[e]&&(v[e]=_,v[e]<X&&(v[e]=X)),_>A[e]&&(A[e]=_,A[e]>q&&(A[e]=q));if(++g===n){for(e=0;e<u;e++)p.setInt8(m++,v[e]),p.setInt8(m++,A[e]),v[e]=1/0,A[e]=-1/0;g=0}}if(g>0)for(e=0;e<u;e++)p.setInt8(m++,v[e]),p.setInt8(m++,A[e]);return f}({scale:e.scale,amplitude_scale:e.amplitude_scale,split_channels:e.split_channels,length:t.length,sample_rate:t.sampleRate,channels:n});i(null,new J(r),t)}else{var a=new Z;a.onmessage=function(e){i(null,new J(e.data),t)},a.postMessage({scale:e.scale,amplitude_scale:e.amplitude_scale,split_channels:e.split_channels,length:t.length,sample_rate:t.sampleRate,channels:n},n)}}J.create=function(t){return new J(t)},J.createFromAudio=function(t,e){var i=function(t){return{scale:t.scale||512,amplitude_scale:t.amplitude_scale||1,split_channels:t.split_channels||false,disable_worker:t.disable_worker||false}}(t);if(t.audio_context&&t.array_buffer)return function(t,e,i,n){t.decodeAudioData(e,(function(t){$(t,i,n)}),(function(t){t||(t=new DOMException("EncodingError")),n(t)}))}(t.audio_context,t.array_buffer,i,e);if(t.audio_buffer)return $(t.audio_buffer,i,e);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")},J.prototype={resample:function(t){if(t.scale="number"==typeof t.scale?t.scale:null,t.width="number"==typeof t.width?t.width:null,null!=t.width&&t.width<=0)throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(null!=t.scale&&t.scale<=0)throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!t.scale&&!t.width)throw new Error("WaveformData.resample(): Missing scale or width option");var e=t.scale||Math.floor(this.duration*this.sample_rate/t.width),i=this.scale,n=this.length,r=n*this.scale,a=Math.ceil(r/e),s=8===this.bits?1:2,o=24+2*a*this.channels*s,l=new ArrayBuffer(o),u=new DataView(l);u.setInt32(0,2,!0),u.setUint32(4,8===this.bits,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,e,!0),u.setInt32(16,a,!0),u.setInt32(20,this.channels,!0);var c,d=new J(l),h=0,f=0,p=this.channels,g=new Array(p),m=new Array(p);for(c=0;c<p;++c)n>0?(g[c]=this.channel(c).min_sample(h),m[c]=this.channel(c).max_sample(h)):(g[c]=0,m[c]=0);var v,A,_,y,b=8===this.bits?-128:-32768,T=8===this.bits?127:32767;if(e<i)throw new Error("WaveformData.resample(): Zoom level "+e+" too low, minimum: "+i);function E(t){return Math.floor(t*e)}for(;h<n;){for(;Math.floor(E(f)/i)===h;){if(f>0)for(c=0;c<p;++c)d.channel(c).set_min_sample(f-1,g[c]),d.channel(c).set_max_sample(f-1,m[c]);if(y=h,(v=E(++f))!==E(f-1))for(c=0;c<p;++c)g[c]=T,m[c]=b}for(v=E(f),(A=Math.floor(v/i))>n&&(A=n);h<A;){for(c=0;c<p;++c)(_=this.channel(c).min_sample(h))<g[c]&&(g[c]=_),(_=this.channel(c).max_sample(h))>m[c]&&(m[c]=_);h++}}if(h!==y)for(c=0;c<p;++c)d.channel(c).set_min_sample(f-1,g[c]),d.channel(c).set_max_sample(f-1,m[c]);return d},concat:function(){var t=this,e=Array.prototype.slice.call(arguments);e.forEach((function(e){if(t.channels!==e.channels||t.sample_rate!==e.sample_rate||t.bits!==e.bits||t.scale!==e.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")}));var i=this._concatBuffers.apply(this,e);return J.create(i)},_concatBuffers:function(){var t,e,i=Array.prototype.slice.call(arguments),n=this._offset,r=n,a=0,s=[this].concat(i).map((function(t){return t._data.buffer}));for(t=0;t<s.length;t++){e=s[t];var o=new DataView(e).getInt32(16,!0);r+=e.byteLength-n,a+=o}var l=new ArrayBuffer(r),u=new DataView(s[0]),c=new DataView(l);for(t=0;t<n;t++)c.setUint8(t,u.getUint8(t));c.setInt32(16,a,!0);var d=0,h=new Uint8Array(l,n);for(t=0;t<s.length;t++)e=s[t],h.set(new Uint8Array(e,n),d),d+=e.byteLength-n;return l},_offsetValues:function(t,e,i){var n=[],r=this.channels;i+=t*r*2;for(var a=0;a<e;a++)n.push(this._at(a*r*2+i));return n},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){return Boolean(this._data.getUint32(4,!0))?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return 2===this._version()?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return 8===this.bits?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+2*t,!0)},_set_at:function(t,e){return 8===this.bits?this._data.setInt8(this._offset+t,e):this._data.setInt16(this._offset+2*t,e,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},e=0;e<this.length;e++)for(var i=0;i<this.channels;i++)t.data.push(this.channel(i).min_sample(e)),t.data.push(this.channel(i).max_sample(e));return t},toArrayBuffer:function(){return this._data.buffer}};const tt={};function et(t,e,i=128){return 0===i&&(i=1),e-(t+i/2)*e/i}function it(t,e){const i=document.createElementNS("http://www.w3.org/2000/svg",t);for(const t of Object.keys(e)){const n=e[t];i.setAttributeNS(null,t,n)}return i}class nt extends HTMLElement{constructor(){super(),z(this,"store"),z(this,"hasInitialised",!1),z(this,"initialAttributes",{}),z(this,"unsubscribe"),z(this,"invalidation",{dimensions:!1,sequence:!1}),z(this,"svg"),z(this,"svgParts"),z(this,"buffered"),z(this,"waveformCache",{}),z(this,"lastBufferedStarts",[]),z(this,"lastWidth",-1),z(this,"lastHeight",-1),z(this,"resizeTimout",-1),z(this,"requeueResize",!1),z(this,"resize",(()=>{-1===this.resizeTimout&&(this.resizeTimout=setTimeout(this.forceResize,0))})),z(this,"isAlreadyResizing",!1),z(this,"forceResize",(()=>{this.resizeTimout=-1;const t=this.getBoundingClientRect(),e=window.devicePixelRatio||1;this.store.getState().setDimensions(t,e);const{width:i,height:n}=this.getBoundingClientRect();if(this.lastWidth=i,this.lastHeight=n,this.svg.setAttributeNS(null,"height",`${n}px`),this.svg.setAttributeNS(null,"width","100%"),this.svg.setAttributeNS(null,"preserveAspectRatio","none"),this.svg.setAttributeNS(null,"viewBox",`0 0 ${i} ${n}`),this.hasInitialised){if(this.isAlreadyResizing)return void(this.requeueResize=!0);this.isAlreadyResizing=!0,this.setIsLoading(!0),this.store.getState().resize((()=>this.requeueResize)).then((()=>{this.setIsLoading(!1),this.resizeTimout=-1,this.isAlreadyResizing=!1,this.requeueResize&&(this.resize(),this.requeueResize=!1)}))}})),z(this,"attributeQueue",{}),z(this,"attributeTimeout",-1),z(this,"isAlreadyUpdating",!1),z(this,"requeueUpdate",!1),z(this,"windowEvent",!1),this.attachShadow({mode:"open"});const t=document.createElement("style");var e;t.innerHTML="\n :host {\n display: block;\n --waveform-background: #000;\n --waveform-base: #8a9aa1;\n --waveform-hover: #14a4c3;\n --waveform-buffered: #fff;\n --waveform-progress: rgba(255, 255, 255, .4);\n }\n\n svg {\n background: var(--waveform-background, #000);\n }\n\n svg .waveforms {\n transition: opacity 140ms;\n }\n\n svg rect.hover {\n fill: var(--waveform-hover, #14a4c3);\n }\n\n svg rect.base {\n fill: var(--waveform-base, #8a9aa1);\n }\n\n svg rect.progress {\n fill: var(--waveform-progress, #14a4c3);\n }\n\n svg .buffered rect {\n fill: var(--waveform-buffered, #fff);\n }\n\n svg .loading {\n translate: 0px -0.5px;\n }\n ",this.store=(e={},V(((t,i,n)=>({sources:[],sequence:[],...e,duration:0,currentTime:0,hoverTime:0,quality:1,bufferedSlices:[],waveforms:[],dimensions:{pageX:0,pageY:0,height:0,width:0,dpi:0},isLoading:!0,pointer:{isDown:!1},mouse:{isHover:!1,isActive:!1},setDimensions(e,i=0){t({dimensions:{width:e.width,height:e.height,pageY:e.y,pageX:e.x,dpi:i}})},setHover(e){t((t=>{const i=Math.abs(e)/t.dimensions.width;return{hoverTime:t.duration*i}}))},async fetchWaveform(e){if(e)return fetch(e).then((t=>t.arrayBuffer())).then((t=>async function(t){return J.create(t)}(t))).then((i=>(t((t=>({sources:(t.sources||[]).map((t=>t.waveform===e?{...t,duration:i.duration,data:i}:t))}))),i)))},resize:async function(e){const n=i(),r=[];let a=!1,s=0;const o=n.sequence&&0!==n.sequence.length?n.sequence:(n.sources||[]).map(((t,e)=>({startTime:t.segment?t.segment.start:0,endTime:t.segment?t.segment.end:n.duration,id:t.id,source:t.id+e,waveform:null}))),l=[];for(let t of o){const e=(n.sources||[]).filter((e=>{if(e.id===t.id){if(e.segment){const i=e.segment;return t.endTime>i.start&&t.startTime<i.end}return!0}return!1}));if(e.length>1){const i=t;for(let t=0;t<e.length;t++){const n=e[t],r=n.segment?Math.max(i.startTime,n.segment.start):i.startTime,a=n.segment?Math.min(i.endTime,n.segment.end):i.endTime;l.push({...i,source:i.id+"__"+r+"__"+a,startTime:r,endTime:a})}}else l.push(t)}let u=l.length;for(let i=0;i<l.length;i++){let o=l[i];if(e())return;t({loadingProgress:i/u});const c=(n.sources||[]).find((t=>!(t.id!==o.id)&&(!t.segment||o.startTime>=t.segment.start&&o.endTime<=t.segment.end))),d=c.segment?o.startTime-c.segment.start:o.startTime,h=c.segment?o.endTime-c.segment.start:o.endTime;if(!(h-d<=0)){if(c&&c.data&&n.dimensions.width){let t=n.quality;const e=(h||c.data.duration)-(d||0),i=e/n.duration,l=n.dimensions.width*i,u=Math.min(1,e/c.data.duration),f=s/n.duration*n.dimensions.width;let p=t*l*(1/u);const g=Math.floor(c.data.duration*c.data.sample_rate/p);g<c.data.scale&&(t*=g/c.data.scale,p=t*l*(1/u),console.warn("Selected quality too high, or segment too small",{quality:t,newWidth:p}));try{const e=c.data.resample({width:p});await new Promise((t=>setTimeout(t,0))),a=!0,r.push({...o,waveform:{data:e,atWidth:l,startPixel:f,quality:t,segment:c.segment}})}catch(t){console.error(t)}}else r.push(o);s+=h-d}}a&&t({sequence:r,loadingProgress:0})},async setAttributes(e,n,r){const a=[],s={isLoading:!0},o=[];if(void 0!==e.duration){const t=parseFloat(e.duration);Number.isNaN(t)||(s.duration=t)}if(void 0!==e["current-time"]&&(s.currentTime=Number(e["current-time"])),void 0!==e.srcset){const t=function(t){const e=[];if(-1===t.indexOf("#")&&-1!==t.indexOf(",")){const i=Y(t,",");for(const t of i){const[i,n=i]=Y(t," ");n&&i&&e.push({id:n,waveform:i,data:null})}}else{const i=Y(t,"|");for(const t of i){const[i,n]=Y(t," "),r={id:n,waveform:i,data:null};if(n&&-1!==n.indexOf("#t=")){const[t,e]=Y(n,"#t="),[i,a]=Y(e,","),s=parseFloat(i),o=parseFloat(a);Number.isNaN(s)||Number.isNaN(o)||(r.segment={start:s,end:o,id:n},r.id=t,r.duration=o-s)}n&&i&&e.push(r)}}return e}(e.srcset);for(const e of t)tt[e.id]=tt[e.id]?tt[e.id]:[],tt[e.id].push((()=>this.fetchWaveform(e.waveform)));s.sources=t}else if(void 0!==e.src){const[i,n=i]=Y(e.src," ");i&&(s.sources=[{id:n,waveform:i,data:null,duration:-1}],a.push(this.fetchWaveform(i).then((e=>{t((t=>t.duration?{}:{duration:e.duration}))}))))}if(void 0!==e.quality){const t=parseFloat(e.quality);t&&!Number.isNaN(t)&&(s.quality=t)}if(void 0!==e.sequence){const t=[],i=Y(e.sequence,"|");let n=0;for(const e of i){const[i,r]=Y(e,"#t="),[s,l]=Y(r,","),u=tt[i];u&&!o.includes(i)&&(o.push(i),a.push(...u.map((t=>t()))),tt[i]=null);const c=p