/*! @name @videojs/vhs-utils @version 3.0.4 @license MIT */ !function(r,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(r="undefined"!=typeof globalThis?globalThis:r||self).vhsUtils=t()}(this,(function(){"use strict";var r,t,e={mp4:/^(av0?1|avc0?[1234]|vp0?9|flac|opus|mp3|mp4a|mp4v|stpp.ttml.im1t)/,webm:/^(vp0?[89]|av0?1|opus|vorbis)/,ogg:/^(vp0?[89]|theora|flac|opus|vorbis)/,video:/^(av0?1|avc0?[1234]|vp0?[89]|hvc1|hev1|theora|mp4v)/,audio:/^(mp4a|flac|vorbis|opus|ac-[34]|ec-3|alac|mp3|speex|aac)/,text:/^(stpp.ttml.im1t)/,muxerVideo:/^(avc0?1)/,muxerAudio:/^(mp4a)/,muxerText:/a^/},n=["video","audio","text"],o=["Video","Audio","Text"],i=function(r){return r?r.replace(/avc1\.(\d+)\.(\d+)/i,(function(r,t,e){return"avc1."+("00"+Number(t).toString(16)).slice(-2)+"00"+("00"+Number(e).toString(16)).slice(-2)})):r},a=function(r){return r.map(i)},u=function(r){void 0===r&&(r="");var t=r.split(","),o=[];return t.forEach((function(r){var t;r=r.trim(),n.forEach((function(n){var i=e[n].exec(r.toLowerCase());if(i&&!(i.length<=1)){t=n;var a=r.substring(0,i[1].length),u=r.replace(a,"");o.push({type:a,details:u,mediaType:n})}})),t||o.push({type:r,details:"",mediaType:"unknown"})})),o},f=function(r){return void 0===r&&(r=""),e.audio.test(r.trim().toLowerCase())},s=function(r){return void 0===r&&(r=""),e.text.test(r.trim().toLowerCase())},c=function(r){if(r&&"string"==typeof r){var t=r.toLowerCase().split(",").map((function(r){return i(r.trim())})),n="video";1===t.length&&f(t[0])?n="audio":1===t.length&&s(t[0])&&(n="application");var o="mp4";return t.every((function(r){return e.mp4.test(r)}))?o="mp4":t.every((function(r){return e.webm.test(r)}))?o="webm":t.every((function(r){return e.ogg.test(r)}))&&(o="ogg"),n+"/"+o+';codecs="'+r+'"'}},l=Object.freeze({__proto__:null,translateLegacyCodec:i,translateLegacyCodecs:a,mapLegacyAvcCodecs:function(r){return r.replace(/avc1\.(\d+)\.(\d+)/i,(function(r){return a([r])[0]}))},parseCodecs:u,codecsFromDefault:function(r,t){if(!r.mediaGroups.AUDIO||!t)return null;var e=r.mediaGroups.AUDIO[t];if(!e)return null;for(var n in e){var o=e[n];if(o.default&&o.playlists)return u(o.playlists[0].attributes.CODECS)}return null},isVideoCodec:function(r){return void 0===r&&(r=""),e.video.test(r.trim().toLowerCase())},isAudioCodec:f,isTextCodec:s,getMimeForCodec:c,browserSupportsCodec:function(r){return void 0===r&&(r=""),window.MediaSource&&window.MediaSource.isTypeSupported&&window.MediaSource.isTypeSupported(c(r))||!1},muxerSupportsCodec:function(r){return void 0===r&&(r=""),r.toLowerCase().split(",").every((function(r){r=r.trim();for(var t=0;ts&&(f-=s,f-=s,f-=m(2))}return Number(f)},U=function(r,t){var e=(void 0===t?{}:t).le,n=void 0!==e&&e;("bigint"!=typeof r&&"number"!=typeof r||"number"==typeof r&&r!=r)&&(r=0),r=m(r);for(var o=h(r),i=new Uint8Array(new ArrayBuffer(o)),a=0;a=t.length&&f.call(t,(function(t,e){return t===(u[e]?u[e]&r[i+e]:r[i+e])}))},C=Object.freeze({__proto__:null,countBits:p,countBytes:h,padStart:v,isTypedArray:y,toUint8:g,toHexString:function(r){r=g(r);for(var t="",e=0;e>>0,u=t.subarray(i+4,i+8);if(0===a)break;var f=i+a;if(f>t.length){if(n)break;f=t.length}var s=t.subarray(i+8,f);T(u,e[0])&&(1===e.length?o.push(s):o.push.apply(o,r(s,e.slice(1),n))),i=f}return o},k={EBML:g([26,69,223,163]),DocType:g([66,130]),Segment:g([24,83,128,103]),SegmentInfo:g([21,73,169,102]),Tracks:g([22,84,174,107]),Track:g([174]),TrackNumber:g([215]),DefaultDuration:g([35,227,131]),TrackEntry:g([174]),TrackType:g([131]),FlagDefault:g([136]),CodecID:g([134]),CodecPrivate:g([99,162]),VideoTrack:g([224]),AudioTrack:g([225]),Cluster:g([31,67,182,117]),Timestamp:g([231]),TimestampScale:g([42,215,177]),BlockGroup:g([160]),BlockDuration:g([155]),Block:g([161]),SimpleBlock:g([163])},_=[128,64,32,16,8,4,2,1],B=function(r,t,e,n){void 0===e&&(e=!0),void 0===n&&(n=!1);var o=function(r){for(var t=1,e=0;e<_.length&&!(r&_[e]);e++)t++;return t}(r[t]),i=r.subarray(t,t+o);return e&&((i=Array.prototype.slice.call(r,t,t+o))[0]^=_[o-1]),{length:o,value:L(i,{signed:n}),bytes:i}},D=function r(t){return"string"==typeof t?t.match(/.{1,2}/g).map((function(t){return r(t)})):"number"==typeof t?U(t):t},R=function r(t,e,n){if(n>=e.length)return e.length;var o=B(e,n,!1);if(T(t.bytes,o.bytes))return n;var i=B(e,n+o.length);return r(t,e,n+i.length+i.value+o.length)},I=function r(t,e){e=function(r){return Array.isArray(r)?r.map((function(r){return D(r)})):[D(r)]}(e),t=g(t);var n=[];if(!e.length)return n;for(var o=0;ot.length?t.length:u+a.value,s=t.subarray(u,f);T(e[0],i.bytes)&&(1===e.length?n.push(s):n=n.concat(r(s,e.slice(1)))),o+=i.length+a.length+s.length}return n},N=g([73,68,51]),O=function r(t,e){return void 0===e&&(e=0),(t=g(t)).length-e<10||!T(t,N,{offset:e})?e:(e+=function(r,t){void 0===t&&(t=0);var e=(r=g(r))[t+5],n=r[t+6]<<21|r[t+7]<<14|r[t+8]<<7|r[t+9];return(16&e)>>4?n+20:n+10}(t,e),r(t,e))},z=g([0,0,0,1]),M=g([0,0,1]),F=g([0,0,3]),P=function(r){for(var t=[],e=1;e>1&63),-1!==e.indexOf(f)&&(o=i+u),i+=u+("h264"===t?1:2)}else i++}return r.subarray(0,0)},q={webm:g([119,101,98,109]),matroska:g([109,97,116,114,111,115,107,97]),flac:g([102,76,97,67]),ogg:g([79,103,103,83]),ac3:g([11,119]),riff:g([82,73,70,70]),avi:g([65,86,73]),wav:g([87,65,86,69]),"3gp":g([102,116,121,112,51,103]),mp4:g([102,116,121,112]),fmp4:g([115,116,121,112]),mov:g([102,116,121,112,113,116]),moov:g([109,111,111,118]),moof:g([109,111,111,102])},G={aac:function(r){var t=O(r);return T(r,[255,16],{offset:t,mask:[255,22]})},mp3:function(r){var t=O(r);return T(r,[255,2],{offset:t,mask:[255,6]})},webm:function(r){var t=I(r,[k.EBML,k.DocType])[0];return T(t,q.webm)},mkv:function(r){var t=I(r,[k.EBML,k.DocType])[0];return T(t,q.matroska)},mp4:function(r){return!G["3gp"](r)&&!G.mov(r)&&(!(!T(r,q.mp4,{offset:4})&&!T(r,q.fmp4,{offset:4}))||(!(!T(r,q.moof,{offset:4})&&!T(r,q.moov,{offset:4}))||void 0))},mov:function(r){return T(r,q.mov,{offset:4})},"3gp":function(r){return T(r,q["3gp"],{offset:4})},ac3:function(r){var t=O(r);return T(r,q.ac3,{offset:t})},ts:function(r){if(r.length<189&&r.length>=1)return 71===r[0];for(var t=0;t+1880}});var Z=Object.freeze({__proto__:null,forEachMediaGroup:function(r,t,e){t.forEach((function(t){for(var n in r.mediaGroups[t])for(var o in r.mediaGroups[t][n]){var i=r.mediaGroups[t][n][o];e(i,t,n,o)}}))}});var J=function(r,t,e){return r(e={path:t,exports:{},require:function(r,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&e.path)}},e.exports),e.exports}((function(r,t){var e,n,o,i,a;e=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#.*)?$/,n=/^([^\/?#]*)(.*)$/,o=/(?:\/|^)\.(?=\/)/g,i=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,a={buildAbsoluteURL:function(r,t,e){if(e=e||{},r=r.trim(),!(t=t.trim())){if(!e.alwaysNormalize)return r;var o=a.parseURL(r);if(!o)throw new Error("Error trying to parse base URL.");return o.path=a.normalizePath(o.path),a.buildURLFromParts(o)}var i=a.parseURL(t);if(!i)throw new Error("Error trying to parse relative URL.");if(i.scheme)return e.alwaysNormalize?(i.path=a.normalizePath(i.path),a.buildURLFromParts(i)):t;var u=a.parseURL(r);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var f=n.exec(u.path);u.netLoc=f[1],u.path=f[2]}u.netLoc&&!u.path&&(u.path="/");var s={scheme:u.scheme,netLoc:i.netLoc,path:null,params:i.params,query:i.query,fragment:i.fragment};if(!i.netLoc&&(s.netLoc=u.netLoc,"/"!==i.path[0]))if(i.path){var c=u.path,l=c.substring(0,c.lastIndexOf("/")+1)+i.path;s.path=a.normalizePath(l)}else s.path=u.path,i.params||(s.params=u.params,i.query||(s.query=u.query));return null===s.path&&(s.path=e.alwaysNormalize?a.normalizePath(i.path):i.path),a.buildURLFromParts(s)},parseURL:function(r){var t=e.exec(r);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(r){for(r=r.split("").reverse().join("").replace(o,"");r.length!==(r=r.replace(i,"")).length;);return r.split("").reverse().join("")},buildURLFromParts:function(r){return r.scheme+r.netLoc+r.path+r.params+r.query+r.fragment}},r.exports=a})),K="http://example.com",Q=function(){function r(){this.listeners={}}var t=r.prototype;return t.on=function(r,t){this.listeners[r]||(this.listeners[r]=[]),this.listeners[r].push(t)},t.off=function(r,t){if(!this.listeners[r])return!1;var e=this.listeners[r].indexOf(t);return this.listeners[r]=this.listeners[r].slice(0),this.listeners[r].splice(e,1),e>-1},t.trigger=function(r){var t=this.listeners[r];if(t)if(2===arguments.length)for(var e=t.length,n=0;n