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