@videojs/vhs-utils
Advanced tools
Comparing version 4.1.0 to 4.1.1
@@ -0,1 +1,8 @@ | ||
<a name="4.1.1"></a> | ||
## [4.1.1](https://github.com/videojs/vhs-utils/compare/v4.1.0...v4.1.1) (2024-07-10) | ||
### Code Refactoring | ||
* remove url-toolkit dependency ([#38](https://github.com/videojs/vhs-utils/issues/38)) ([e124470](https://github.com/videojs/vhs-utils/commit/e124470)) | ||
<a name="4.1.0"></a> | ||
@@ -2,0 +9,0 @@ # [4.1.0](https://github.com/videojs/vhs-utils/compare/v4.0.0...v4.1.0) (2023-11-28) |
@@ -10,7 +10,5 @@ "use strict"; | ||
var _urlToolkit = _interopRequireDefault(require("url-toolkit")); | ||
var _window = _interopRequireDefault(require("global/window")); | ||
var DEFAULT_LOCATION = 'http://example.com'; | ||
var DEFAULT_LOCATION = 'https://example.com'; | ||
@@ -26,7 +24,4 @@ var resolveUrl = function resolveUrl(baseUrl, relativeUrl) { | ||
baseUrl = _window.default.location && _window.default.location.href || ''; | ||
} // IE11 supports URL but not the URL constructor | ||
// feature detect the behavior we want | ||
} | ||
var nativeURL = typeof _window.default.URL === 'function'; | ||
var protocolLess = /^\/\//.test(baseUrl); // remove location if window.location isn't available (i.e. we're in node) | ||
@@ -37,23 +32,14 @@ // and if baseUrl isn't an absolute url | ||
if (nativeURL) { | ||
baseUrl = new _window.default.URL(baseUrl, _window.default.location || DEFAULT_LOCATION); | ||
} else if (!/\/\//i.test(baseUrl)) { | ||
baseUrl = _urlToolkit.default.buildAbsoluteURL(_window.default.location && _window.default.location.href || '', baseUrl); | ||
} | ||
baseUrl = new _window.default.URL(baseUrl, _window.default.location || DEFAULT_LOCATION); | ||
var newUrl = new URL(relativeUrl, baseUrl); // if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (nativeURL) { | ||
var newUrl = new URL(relativeUrl, baseUrl); // if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return newUrl.href; | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return _urlToolkit.default.buildAbsoluteURL(baseUrl, relativeUrl); | ||
return newUrl.href; | ||
}; | ||
@@ -60,0 +46,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! @name @videojs/vhs-utils @version 4.1.0 @license MIT */ | ||
/*! @name @videojs/vhs-utils @version 4.1.1 @license MIT */ | ||
(function (global, factory) { | ||
@@ -1158,178 +1158,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
var urlToolkit = {exports: {}}; | ||
const DEFAULT_LOCATION = 'https://example.com'; | ||
(function (module, exports) { | ||
// see https://tools.ietf.org/html/rfc1808 | ||
(function (root) { | ||
var URL_REGEX = /^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#.*)?$/; | ||
var FIRST_SEGMENT_REGEX = /^([^\/?#]*)(.*)$/; | ||
var SLASH_DOT_REGEX = /(?:\/|^)\.(?=\/)/g; | ||
var SLASH_DOT_DOT_REGEX = /(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g; | ||
var URLToolkit = { | ||
// If opts.alwaysNormalize is true then the path will always be normalized even when it starts with / or // | ||
// E.g | ||
// With opts.alwaysNormalize = false (default, spec compliant) | ||
// http://a.com/b/cd + /e/f/../g => http://a.com/e/f/../g | ||
// With opts.alwaysNormalize = true (not spec compliant) | ||
// http://a.com/b/cd + /e/f/../g => http://a.com/e/g | ||
buildAbsoluteURL: function (baseURL, relativeURL, opts) { | ||
opts = opts || {}; // remove any remaining space and CRLF | ||
baseURL = baseURL.trim(); | ||
relativeURL = relativeURL.trim(); | ||
if (!relativeURL) { | ||
// 2a) If the embedded URL is entirely empty, it inherits the | ||
// entire base URL (i.e., is set equal to the base URL) | ||
// and we are done. | ||
if (!opts.alwaysNormalize) { | ||
return baseURL; | ||
} | ||
var basePartsForNormalise = URLToolkit.parseURL(baseURL); | ||
if (!basePartsForNormalise) { | ||
throw new Error('Error trying to parse base URL.'); | ||
} | ||
basePartsForNormalise.path = URLToolkit.normalizePath(basePartsForNormalise.path); | ||
return URLToolkit.buildURLFromParts(basePartsForNormalise); | ||
} | ||
var relativeParts = URLToolkit.parseURL(relativeURL); | ||
if (!relativeParts) { | ||
throw new Error('Error trying to parse relative URL.'); | ||
} | ||
if (relativeParts.scheme) { | ||
// 2b) If the embedded URL starts with a scheme name, it is | ||
// interpreted as an absolute URL and we are done. | ||
if (!opts.alwaysNormalize) { | ||
return relativeURL; | ||
} | ||
relativeParts.path = URLToolkit.normalizePath(relativeParts.path); | ||
return URLToolkit.buildURLFromParts(relativeParts); | ||
} | ||
var baseParts = URLToolkit.parseURL(baseURL); | ||
if (!baseParts) { | ||
throw new Error('Error trying to parse base URL.'); | ||
} | ||
if (!baseParts.netLoc && baseParts.path && baseParts.path[0] !== '/') { | ||
// If netLoc missing and path doesn't start with '/', assume everthing before the first '/' is the netLoc | ||
// This causes 'example.com/a' to be handled as '//example.com/a' instead of '/example.com/a' | ||
var pathParts = FIRST_SEGMENT_REGEX.exec(baseParts.path); | ||
baseParts.netLoc = pathParts[1]; | ||
baseParts.path = pathParts[2]; | ||
} | ||
if (baseParts.netLoc && !baseParts.path) { | ||
baseParts.path = '/'; | ||
} | ||
var builtParts = { | ||
// 2c) Otherwise, the embedded URL inherits the scheme of | ||
// the base URL. | ||
scheme: baseParts.scheme, | ||
netLoc: relativeParts.netLoc, | ||
path: null, | ||
params: relativeParts.params, | ||
query: relativeParts.query, | ||
fragment: relativeParts.fragment | ||
}; | ||
if (!relativeParts.netLoc) { | ||
// 3) If the embedded URL's <net_loc> is non-empty, we skip to | ||
// Step 7. Otherwise, the embedded URL inherits the <net_loc> | ||
// (if any) of the base URL. | ||
builtParts.netLoc = baseParts.netLoc; // 4) If the embedded URL path is preceded by a slash "/", the | ||
// path is not relative and we skip to Step 7. | ||
if (relativeParts.path[0] !== '/') { | ||
if (!relativeParts.path) { | ||
// 5) If the embedded URL path is empty (and not preceded by a | ||
// slash), then the embedded URL inherits the base URL path | ||
builtParts.path = baseParts.path; // 5a) if the embedded URL's <params> is non-empty, we skip to | ||
// step 7; otherwise, it inherits the <params> of the base | ||
// URL (if any) and | ||
if (!relativeParts.params) { | ||
builtParts.params = baseParts.params; // 5b) if the embedded URL's <query> is non-empty, we skip to | ||
// step 7; otherwise, it inherits the <query> of the base | ||
// URL (if any) and we skip to step 7. | ||
if (!relativeParts.query) { | ||
builtParts.query = baseParts.query; | ||
} | ||
} | ||
} else { | ||
// 6) The last segment of the base URL's path (anything | ||
// following the rightmost slash "/", or the entire path if no | ||
// slash is present) is removed and the embedded URL's path is | ||
// appended in its place. | ||
var baseURLPath = baseParts.path; | ||
var newPath = baseURLPath.substring(0, baseURLPath.lastIndexOf('/') + 1) + relativeParts.path; | ||
builtParts.path = URLToolkit.normalizePath(newPath); | ||
} | ||
} | ||
} | ||
if (builtParts.path === null) { | ||
builtParts.path = opts.alwaysNormalize ? URLToolkit.normalizePath(relativeParts.path) : relativeParts.path; | ||
} | ||
return URLToolkit.buildURLFromParts(builtParts); | ||
}, | ||
parseURL: function (url) { | ||
var parts = URL_REGEX.exec(url); | ||
if (!parts) { | ||
return null; | ||
} | ||
return { | ||
scheme: parts[1] || '', | ||
netLoc: parts[2] || '', | ||
path: parts[3] || '', | ||
params: parts[4] || '', | ||
query: parts[5] || '', | ||
fragment: parts[6] || '' | ||
}; | ||
}, | ||
normalizePath: function (path) { | ||
// The following operations are | ||
// then applied, in order, to the new path: | ||
// 6a) All occurrences of "./", where "." is a complete path | ||
// segment, are removed. | ||
// 6b) If the path ends with "." as a complete path segment, | ||
// that "." is removed. | ||
path = path.split('').reverse().join('').replace(SLASH_DOT_REGEX, ''); // 6c) All occurrences of "<segment>/../", where <segment> is a | ||
// complete path segment not equal to "..", are removed. | ||
// Removal of these path segments is performed iteratively, | ||
// removing the leftmost matching pattern on each iteration, | ||
// until no matching pattern remains. | ||
// 6d) If the path ends with "<segment>/..", where <segment> is a | ||
// complete path segment not equal to "..", that | ||
// "<segment>/.." is removed. | ||
while (path.length !== (path = path.replace(SLASH_DOT_DOT_REGEX, '')).length) {} | ||
return path.split('').reverse().join(''); | ||
}, | ||
buildURLFromParts: function (parts) { | ||
return parts.scheme + parts.netLoc + parts.path + parts.params + parts.query + parts.fragment; | ||
} | ||
}; | ||
module.exports = URLToolkit; | ||
})(); | ||
})(urlToolkit); | ||
var URLToolkit = urlToolkit.exports; | ||
const DEFAULT_LOCATION = 'http://example.com'; | ||
const resolveUrl = (baseUrl, relativeUrl) => { | ||
@@ -1344,7 +1170,4 @@ // return early if we don't need to resolve | ||
baseUrl = window.location && window.location.href || ''; | ||
} // IE11 supports URL but not the URL constructor | ||
// feature detect the behavior we want | ||
} | ||
const nativeURL = typeof window.URL === 'function'; | ||
const protocolLess = /^\/\//.test(baseUrl); // remove location if window.location isn't available (i.e. we're in node) | ||
@@ -1355,23 +1178,14 @@ // and if baseUrl isn't an absolute url | ||
if (nativeURL) { | ||
baseUrl = new window.URL(baseUrl, window.location || DEFAULT_LOCATION); | ||
} else if (!/\/\//i.test(baseUrl)) { | ||
baseUrl = URLToolkit.buildAbsoluteURL(window.location && window.location.href || '', baseUrl); | ||
} | ||
baseUrl = new window.URL(baseUrl, window.location || DEFAULT_LOCATION); | ||
const newUrl = new URL(relativeUrl, baseUrl); // if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (nativeURL) { | ||
const newUrl = new URL(relativeUrl, baseUrl); // if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return newUrl.href; | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return URLToolkit.buildAbsoluteURL(baseUrl, relativeUrl); | ||
return newUrl.href; | ||
}; | ||
@@ -1378,0 +1192,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! @name @videojs/vhs-utils @version 4.1.0 @license MIT */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).vhsUtils=t()}(this,(function(){"use strict";const 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^/},t=["video","audio","text"],r=["Video","Audio","Text"],n=function(e){return e?e.replace(/avc1\.(\d+)\.(\d+)/i,(function(e,t,r){return"avc1."+("00"+Number(t).toString(16)).slice(-2)+"00"+("00"+Number(r).toString(16)).slice(-2)})):e},o=function(e){return e.map(n)},a=function(r=""){const n=r.split(","),o=[];return n.forEach((function(r){let n;r=r.trim(),t.forEach((function(t){const a=e[t].exec(r.toLowerCase());if(!a||a.length<=1)return;n=t;const i=r.substring(0,a[1].length),s=r.replace(i,"");o.push({type:i,details:s,mediaType:t})})),n||o.push({type:r,details:"",mediaType:"unknown"})})),o},i=(t="")=>e.audio.test(t.trim().toLowerCase()),s=(t="")=>e.text.test(t.trim().toLowerCase()),l=t=>{if(!t||"string"!=typeof t)return;const r=t.toLowerCase().split(",").map((e=>n(e.trim())));let o="video";1===r.length&&i(r[0])?o="audio":1===r.length&&s(r[0])&&(o="application");let a="mp4";return r.every((t=>e.mp4.test(t)))?a="mp4":r.every((t=>e.webm.test(t)))?a="webm":r.every((t=>e.ogg.test(t)))&&(a="ogg"),`${o}/${a};codecs="${t}"`};var c=Object.freeze({__proto__:null,translateLegacyCodec:n,translateLegacyCodecs:o,mapLegacyAvcCodecs:function(e){return e.replace(/avc1\.(\d+)\.(\d+)/i,(e=>o([e])[0]))},parseCodecs:a,codecsFromDefault:(e,t)=>{if(!e.mediaGroups.AUDIO||!t)return null;const r=e.mediaGroups.AUDIO[t];if(!r)return null;for(const e in r){const t=r[e];if(t.default&&t.playlists)return a(t.playlists[0].attributes.CODECS)}return null},isVideoCodec:(t="")=>e.video.test(t.trim().toLowerCase()),isAudioCodec:i,isTextCodec:s,getMimeForCodec:l,browserSupportsCodec:(e="",t=!1)=>window.MediaSource&&window.MediaSource.isTypeSupported&&window.MediaSource.isTypeSupported(l(e))||t&&window.ManagedMediaSource&&window.ManagedMediaSource.isTypeSupported&&window.ManagedMediaSource.isTypeSupported(l(e))||!1,muxerSupportsCodec:(t="")=>t.toLowerCase().split(",").every((t=>{t=t.trim();for(let n=0;n<r.length;n++){if(e[`muxer${r[n]}`].test(t))return!0}return!1})),DEFAULT_AUDIO_CODEC:"mp4a.40.2",DEFAULT_VIDEO_CODEC:"avc1.4d400d"});const u=e=>e.toString(2).length,f=e=>Math.ceil(u(e)/8),p=(e,t,r=" ")=>(function(e,t){let r="";for(;t--;)r+=e;return r}(r,t)+e.toString()).slice(-t),h=e=>"function"===ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,y=e=>h(e),g=function(e){return e instanceof Uint8Array?e:(Array.isArray(e)||y(e)||e instanceof ArrayBuffer||(e="number"!=typeof e||"number"==typeof e&&e!=e?0:[e]),new Uint8Array(e&&e.buffer||e,e&&e.byteOffset||0,e&&e.byteLength||0))},m=window.BigInt||Number,d=[m("0x1"),m("0x100"),m("0x10000"),m("0x1000000"),m("0x100000000"),m("0x10000000000"),m("0x1000000000000"),m("0x100000000000000"),m("0x10000000000000000")],b=function(){const e=new Uint16Array([65484]),t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return 255===t[0]?"big":204===t[0]?"little":"unknown"}(),v="big"===b,w="little"===b,A=function(e,{signed:t=!1,le:r=!1}={}){e=g(e);const n=r?"reduce":"reduceRight";let o=(e[n]?e[n]:Array.prototype[n]).call(e,(function(t,n,o){const a=r?o:Math.abs(o+1-e.length);return t+m(n)*d[a]}),m(0));if(t){const t=d[e.length]/m(2)-m(1);o=m(o),o>t&&(o-=t,o-=t,o-=m(2))}return Number(o)},L=function(e,{le:t=!1}={}){("bigint"!=typeof e&&"number"!=typeof e||"number"==typeof e&&e!=e)&&(e=0),e=m(e);const r=f(e),n=new Uint8Array(new ArrayBuffer(r));for(let o=0;o<r;o++){const r=t?o:Math.abs(o+1-n.length);n[r]=Number(e/d[o]&m(255)),e<0&&(n[r]=Math.abs(~n[r]),n[r]-=0===o?1:2)}return n},U=(e,t)=>{if("string"!=typeof e&&e&&"function"==typeof e.toString&&(e=e.toString()),"string"!=typeof e)return new Uint8Array;t||(e=unescape(encodeURIComponent(e)));const r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r},S=(e,t,{offset:r=0,mask:n=[]}={})=>{e=g(e);const o=(t=g(t)).every?t.every:Array.prototype.every;return t.length&&e.length-r>=t.length&&o.call(t,((t,o)=>t===(n[o]?n[o]&e[r+o]:e[r+o])))};var T=Object.freeze({__proto__:null,countBits:u,countBytes:f,padStart:p,isArrayBufferView:h,isTypedArray:y,toUint8:g,toHexString:function(e){e=g(e);let t="";for(let r=0;r<e.length;r++)t+=p(e[r].toString(16),2,"0");return t},toBinaryString:function(e){e=g(e);let t="";for(let r=0;r<e.length;r++)t+=p(e[r].toString(2),8,"0");return t},ENDIANNESS:b,IS_BIG_ENDIAN:v,IS_LITTLE_ENDIAN:w,bytesToNumber:A,numberToBytes:L,bytesToString:e=>{if(!e)return"";e=Array.prototype.slice.call(e);const t=String.fromCharCode.apply(null,g(e));try{return decodeURIComponent(escape(t))}catch(e){}return t},stringToBytes:U,concatTypedArrays:(...e)=>{if((e=e.filter((e=>e&&(e.byteLength||e.length)&&"string"!=typeof e))).length<=1)return g(e[0]);const t=e.reduce(((e,t,r)=>e+(t.byteLength||t.length)),0),r=new Uint8Array(t);let n=0;return e.forEach((function(e){e=g(e),r.set(e,n),n+=e.byteLength})),r},bytesMatch:S,sliceBytes:function(e,t,r){return Uint8Array.prototype.slice?Uint8Array.prototype.slice.call(e,t,r):new Uint8Array(Array.prototype.slice.call(e,t,r))},reverseBytes:function(e){return e.reverse?e.reverse():Array.prototype.reverse.call(e)}});const x=function(e){return"string"==typeof e?U(e):e},C=function(e,t,r=!1){t=function(e){return Array.isArray(e)?e.map((e=>x(e))):[x(e)]}(t),e=g(e);const n=[];if(!t.length)return n;let o=0;for(;o<e.length;){const a=(e[o]<<24|e[o+1]<<16|e[o+2]<<8|e[o+3])>>>0,i=e.subarray(o+4,o+8);if(0===a)break;let s=o+a;if(s>e.length){if(r)break;s=e.length}const l=e.subarray(o+8,s);S(i,t[0])&&(1===t.length?n.push(l):n.push.apply(n,C(l,t.slice(1),r))),o=s}return n},E={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])},B=[128,64,32,16,8,4,2,1],k=function(e,t,r=!0,n=!1){const o=function(e){let t=1;for(let r=0;r<B.length&&!(e&B[r]);r++)t++;return t}(e[t]);let a=e.subarray(t,t+o);return r&&(a=Array.prototype.slice.call(e,t,t+o),a[0]^=B[o-1]),{length:o,value:A(a,{signed:n}),bytes:a}},_=function(e){return"string"==typeof e?e.match(/.{1,2}/g).map((e=>_(e))):"number"==typeof e?L(e):e},D=(e,t,r)=>{if(r>=t.length)return t.length;const n=k(t,r,!1);if(S(e.bytes,n.bytes))return r;const o=k(t,r+n.length);return D(e,t,r+o.length+o.value+n.length)},M=function(e,t){t=function(e){return Array.isArray(e)?e.map((e=>_(e))):[_(e)]}(t),e=g(e);let r=[];if(!t.length)return r;let n=0;for(;n<e.length;){const o=k(e,n,!1),a=k(e,n+o.length),i=n+o.length+a.length;127===a.value&&(a.value=D(o,e,i),a.value!==e.length&&(a.value-=i));const s=i+a.value>e.length?e.length:i+a.value,l=e.subarray(i,s);S(t[0],o.bytes)&&(1===t.length?r.push(l):r=r.concat(M(l,t.slice(1))));n+=o.length+a.length+l.length}return r},R=g([73,68,51]),I=function(e,t=0){return(e=g(e)).length-t<10||!S(e,R,{offset:t})?t:(t+=function(e,t=0){const r=(e=g(e))[t+5],n=e[t+6]<<21|e[t+7]<<14|e[t+8]<<7|e[t+9];return(16&r)>>4?n+20:n+10}(e,t),I(e,t))},N=g([0,0,0,1]),O=g([0,0,1]),z=g([0,0,3]),F=function(e){const t=[];let r=1;for(;r<e.length-2;)S(e.subarray(r,r+3),z)&&(t.push(r+2),r++),r++;if(0===t.length)return e;const n=e.length-t.length,o=new Uint8Array(n);let a=0;for(r=0;r<n;a++,r++)a===t[0]&&(a++,t.shift()),o[r]=e[a];return o},P=function(e,t,r,n=1/0){e=g(e),r=[].concat(r);let o,a=0,i=0;for(;a<e.length&&(i<n||o);){let n,s;if(S(e.subarray(a),N)?n=4:S(e.subarray(a),O)&&(n=3),n){if(i++,o)return F(e.subarray(o,a));"h264"===t?s=31&e[a+n]:"h265"===t&&(s=e[a+n]>>1&63),-1!==r.indexOf(s)&&(o=a+n),a+=n+("h264"===t?1:2)}else a++}return e.subarray(0,0)},G={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])},j={aac(e){const t=I(e);return S(e,[255,16],{offset:t,mask:[255,22]})},mp3(e){const t=I(e);return S(e,[255,2],{offset:t,mask:[255,6]})},webm(e){const t=M(e,[E.EBML,E.DocType])[0];return S(t,G.webm)},mkv(e){const t=M(e,[E.EBML,E.DocType])[0];return S(t,G.matroska)},mp4:e=>!j["3gp"](e)&&!j.mov(e)&&(!(!S(e,G.mp4,{offset:4})&&!S(e,G.fmp4,{offset:4}))||(!(!S(e,G.moof,{offset:4})&&!S(e,G.moov,{offset:4}))||void 0)),mov:e=>S(e,G.mov,{offset:4}),"3gp":e=>S(e,G["3gp"],{offset:4}),ac3(e){const t=I(e);return S(e,G.ac3,{offset:t})},ts(e){if(e.length<189&&e.length>=1)return 71===e[0];let t=0;for(;t+188<e.length&&t<188;){if(71===e[t]&&71===e[t+188])return!0;t+=1}return!1},flac(e){const t=I(e);return S(e,G.flac,{offset:t})},ogg:e=>S(e,G.ogg),avi:e=>S(e,G.riff)&&S(e,G.avi,{offset:8}),wav:e=>S(e,G.riff)&&S(e,G.wav,{offset:8}),h264:e=>((e,t,r)=>P(e,"h264",t,r))(e,7,3).length,h265:e=>((e,t,r)=>P(e,"h265",t,r))(e,[32,33],3).length},V=Object.keys(j).filter((e=>"ts"!==e&&"h264"!==e&&"h265"!==e)).concat(["ts","h264","h265"]);V.forEach((function(e){const t=j[e];j[e]=e=>t(g(e))}));const q=j;var $=Object.freeze({__proto__:null,isLikely:q,detectContainerForBytes:e=>{e=g(e);for(let t=0;t<V.length;t++){const r=V[t];if(q[r](e))return r}return""},isLikelyFmp4MediaSegment:e=>C(e,["moof"]).length>0});var H=Object.freeze({__proto__:null,forEachMediaGroup:(e,t,r)=>{t.forEach((t=>{for(const n in e.mediaGroups[t])for(const o in e.mediaGroups[t][n]){const a=e.mediaGroups[t][n][o];r(a,t,n,o)}}))}}),Z={exports:{}};!function(e,t){!function(t){var r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#.*)?$/,n=/^([^\/?#]*)(.*)$/,o=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,i={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var o=i.parseURL(e);if(!o)throw new Error("Error trying to parse base URL.");return o.path=i.normalizePath(o.path),i.buildURLFromParts(o)}var a=i.parseURL(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=i.normalizePath(a.path),i.buildURLFromParts(a)):t;var s=i.parseURL(e);if(!s)throw new Error("Error trying to parse base URL.");if(!s.netLoc&&s.path&&"/"!==s.path[0]){var l=n.exec(s.path);s.netLoc=l[1],s.path=l[2]}s.netLoc&&!s.path&&(s.path="/");var c={scheme:s.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=s.netLoc,"/"!==a.path[0]))if(a.path){var u=s.path,f=u.substring(0,u.lastIndexOf("/")+1)+a.path;c.path=i.normalizePath(f)}else c.path=s.path,a.params||(c.params=s.params,a.query||(c.query=s.query));return null===c.path&&(c.path=r.alwaysNormalize?i.normalizePath(a.path):a.path),i.buildURLFromParts(c)},parseURL:function(e){var t=r.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(o,"");e.length!==(e=e.replace(a,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}};e.exports=i}()}(Z);var J=Z.exports;const K="http://example.com";var Q={codecs:c,byteHelpers:T,containers:$,decodeB64ToUint8Array:function(e){const t=(r=e,window.atob?window.atob(r):Buffer.from(r,"base64").toString("binary"));var r;const n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},mediaGroups:H,resolveUrl:(e,t)=>{if(/^[a-z]+:/i.test(t))return t;/^data:/.test(e)&&(e=window.location&&window.location.href||"");const r="function"==typeof window.URL,n=/^\/\//.test(e),o=!window.location&&!/\/\//i.test(e);if(r?e=new window.URL(e,window.location||K):/\/\//i.test(e)||(e=J.buildAbsoluteURL(window.location&&window.location.href||"",e)),r){const r=new URL(t,e);return o?r.href.slice(K.length):n?r.href.slice(r.protocol.length):r.href}return J.buildAbsoluteURL(e,t)},Stream:class{constructor(){this.listeners={}}on(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}off(e,t){if(!this.listeners[e])return!1;const r=this.listeners[e].indexOf(t);return this.listeners[e]=this.listeners[e].slice(0),this.listeners[e].splice(r,1),r>-1}trigger(e){const t=this.listeners[e];if(t)if(2===arguments.length){const e=t.length;for(let r=0;r<e;++r)t[r].call(this,arguments[1])}else{const e=Array.prototype.slice.call(arguments,1),r=t.length;for(let n=0;n<r;++n)t[n].apply(this,e)}}dispose(){this.listeners={}}pipe(e){this.on("data",(function(t){e.push(t)}))}}};return Q})); | ||
/*! @name @videojs/vhs-utils @version 4.1.1 @license MIT */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).vhsUtils=t()}(this,(function(){"use strict";const 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^/},t=["video","audio","text"],r=["Video","Audio","Text"],n=function(e){return e?e.replace(/avc1\.(\d+)\.(\d+)/i,(function(e,t,r){return"avc1."+("00"+Number(t).toString(16)).slice(-2)+"00"+("00"+Number(r).toString(16)).slice(-2)})):e},o=function(e){return e.map(n)},i=function(r=""){const n=r.split(","),o=[];return n.forEach((function(r){let n;r=r.trim(),t.forEach((function(t){const i=e[t].exec(r.toLowerCase());if(!i||i.length<=1)return;n=t;const s=r.substring(0,i[1].length),a=r.replace(s,"");o.push({type:s,details:a,mediaType:t})})),n||o.push({type:r,details:"",mediaType:"unknown"})})),o},s=(t="")=>e.audio.test(t.trim().toLowerCase()),a=(t="")=>e.text.test(t.trim().toLowerCase()),c=t=>{if(!t||"string"!=typeof t)return;const r=t.toLowerCase().split(",").map((e=>n(e.trim())));let o="video";1===r.length&&s(r[0])?o="audio":1===r.length&&a(r[0])&&(o="application");let i="mp4";return r.every((t=>e.mp4.test(t)))?i="mp4":r.every((t=>e.webm.test(t)))?i="webm":r.every((t=>e.ogg.test(t)))&&(i="ogg"),`${o}/${i};codecs="${t}"`};var l=Object.freeze({__proto__:null,translateLegacyCodec:n,translateLegacyCodecs:o,mapLegacyAvcCodecs:function(e){return e.replace(/avc1\.(\d+)\.(\d+)/i,(e=>o([e])[0]))},parseCodecs:i,codecsFromDefault:(e,t)=>{if(!e.mediaGroups.AUDIO||!t)return null;const r=e.mediaGroups.AUDIO[t];if(!r)return null;for(const e in r){const t=r[e];if(t.default&&t.playlists)return i(t.playlists[0].attributes.CODECS)}return null},isVideoCodec:(t="")=>e.video.test(t.trim().toLowerCase()),isAudioCodec:s,isTextCodec:a,getMimeForCodec:c,browserSupportsCodec:(e="",t=!1)=>window.MediaSource&&window.MediaSource.isTypeSupported&&window.MediaSource.isTypeSupported(c(e))||t&&window.ManagedMediaSource&&window.ManagedMediaSource.isTypeSupported&&window.ManagedMediaSource.isTypeSupported(c(e))||!1,muxerSupportsCodec:(t="")=>t.toLowerCase().split(",").every((t=>{t=t.trim();for(let n=0;n<r.length;n++){if(e[`muxer${r[n]}`].test(t))return!0}return!1})),DEFAULT_AUDIO_CODEC:"mp4a.40.2",DEFAULT_VIDEO_CODEC:"avc1.4d400d"});const u=e=>e.toString(2).length,f=e=>Math.ceil(u(e)/8),p=(e,t,r=" ")=>(function(e,t){let r="";for(;t--;)r+=e;return r}(r,t)+e.toString()).slice(-t),h=e=>"function"===ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,g=e=>h(e),y=function(e){return e instanceof Uint8Array?e:(Array.isArray(e)||g(e)||e instanceof ArrayBuffer||(e="number"!=typeof e||"number"==typeof e&&e!=e?0:[e]),new Uint8Array(e&&e.buffer||e,e&&e.byteOffset||0,e&&e.byteLength||0))},d=window.BigInt||Number,m=[d("0x1"),d("0x100"),d("0x10000"),d("0x1000000"),d("0x100000000"),d("0x10000000000"),d("0x1000000000000"),d("0x100000000000000"),d("0x10000000000000000")],b=function(){const e=new Uint16Array([65484]),t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return 255===t[0]?"big":204===t[0]?"little":"unknown"}(),v="big"===b,w="little"===b,A=function(e,{signed:t=!1,le:r=!1}={}){e=y(e);const n=r?"reduce":"reduceRight";let o=(e[n]?e[n]:Array.prototype[n]).call(e,(function(t,n,o){const i=r?o:Math.abs(o+1-e.length);return t+d(n)*m[i]}),d(0));if(t){const t=m[e.length]/d(2)-d(1);o=d(o),o>t&&(o-=t,o-=t,o-=d(2))}return Number(o)},S=function(e,{le:t=!1}={}){("bigint"!=typeof e&&"number"!=typeof e||"number"==typeof e&&e!=e)&&(e=0),e=d(e);const r=f(e),n=new Uint8Array(new ArrayBuffer(r));for(let o=0;o<r;o++){const r=t?o:Math.abs(o+1-n.length);n[r]=Number(e/m[o]&d(255)),e<0&&(n[r]=Math.abs(~n[r]),n[r]-=0===o?1:2)}return n},T=(e,t)=>{if("string"!=typeof e&&e&&"function"==typeof e.toString&&(e=e.toString()),"string"!=typeof e)return new Uint8Array;t||(e=unescape(encodeURIComponent(e)));const r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r},C=(e,t,{offset:r=0,mask:n=[]}={})=>{e=y(e);const o=(t=y(t)).every?t.every:Array.prototype.every;return t.length&&e.length-r>=t.length&&o.call(t,((t,o)=>t===(n[o]?n[o]&e[r+o]:e[r+o])))};var x=Object.freeze({__proto__:null,countBits:u,countBytes:f,padStart:p,isArrayBufferView:h,isTypedArray:g,toUint8:y,toHexString:function(e){e=y(e);let t="";for(let r=0;r<e.length;r++)t+=p(e[r].toString(16),2,"0");return t},toBinaryString:function(e){e=y(e);let t="";for(let r=0;r<e.length;r++)t+=p(e[r].toString(2),8,"0");return t},ENDIANNESS:b,IS_BIG_ENDIAN:v,IS_LITTLE_ENDIAN:w,bytesToNumber:A,numberToBytes:S,bytesToString:e=>{if(!e)return"";e=Array.prototype.slice.call(e);const t=String.fromCharCode.apply(null,y(e));try{return decodeURIComponent(escape(t))}catch(e){}return t},stringToBytes:T,concatTypedArrays:(...e)=>{if((e=e.filter((e=>e&&(e.byteLength||e.length)&&"string"!=typeof e))).length<=1)return y(e[0]);const t=e.reduce(((e,t,r)=>e+(t.byteLength||t.length)),0),r=new Uint8Array(t);let n=0;return e.forEach((function(e){e=y(e),r.set(e,n),n+=e.byteLength})),r},bytesMatch:C,sliceBytes:function(e,t,r){return Uint8Array.prototype.slice?Uint8Array.prototype.slice.call(e,t,r):new Uint8Array(Array.prototype.slice.call(e,t,r))},reverseBytes:function(e){return e.reverse?e.reverse():Array.prototype.reverse.call(e)}});const U=function(e){return"string"==typeof e?T(e):e},B=function(e,t,r=!1){t=function(e){return Array.isArray(e)?e.map((e=>U(e))):[U(e)]}(t),e=y(e);const n=[];if(!t.length)return n;let o=0;for(;o<e.length;){const i=(e[o]<<24|e[o+1]<<16|e[o+2]<<8|e[o+3])>>>0,s=e.subarray(o+4,o+8);if(0===i)break;let a=o+i;if(a>e.length){if(r)break;a=e.length}const c=e.subarray(o+8,a);C(s,t[0])&&(1===t.length?n.push(c):n.push.apply(n,B(c,t.slice(1),r))),o=a}return n},L={EBML:y([26,69,223,163]),DocType:y([66,130]),Segment:y([24,83,128,103]),SegmentInfo:y([21,73,169,102]),Tracks:y([22,84,174,107]),Track:y([174]),TrackNumber:y([215]),DefaultDuration:y([35,227,131]),TrackEntry:y([174]),TrackType:y([131]),FlagDefault:y([136]),CodecID:y([134]),CodecPrivate:y([99,162]),VideoTrack:y([224]),AudioTrack:y([225]),Cluster:y([31,67,182,117]),Timestamp:y([231]),TimestampScale:y([42,215,177]),BlockGroup:y([160]),BlockDuration:y([155]),Block:y([161]),SimpleBlock:y([163])},k=[128,64,32,16,8,4,2,1],_=function(e,t,r=!0,n=!1){const o=function(e){let t=1;for(let r=0;r<k.length&&!(e&k[r]);r++)t++;return t}(e[t]);let i=e.subarray(t,t+o);return r&&(i=Array.prototype.slice.call(e,t,t+o),i[0]^=k[o-1]),{length:o,value:A(i,{signed:n}),bytes:i}},D=function(e){return"string"==typeof e?e.match(/.{1,2}/g).map((e=>D(e))):"number"==typeof e?S(e):e},E=(e,t,r)=>{if(r>=t.length)return t.length;const n=_(t,r,!1);if(C(e.bytes,n.bytes))return r;const o=_(t,r+n.length);return E(e,t,r+o.length+o.value+n.length)},M=function(e,t){t=function(e){return Array.isArray(e)?e.map((e=>D(e))):[D(e)]}(t),e=y(e);let r=[];if(!t.length)return r;let n=0;for(;n<e.length;){const o=_(e,n,!1),i=_(e,n+o.length),s=n+o.length+i.length;127===i.value&&(i.value=E(o,e,s),i.value!==e.length&&(i.value-=s));const a=s+i.value>e.length?e.length:s+i.value,c=e.subarray(s,a);C(t[0],o.bytes)&&(1===t.length?r.push(c):r=r.concat(M(c,t.slice(1))));n+=o.length+i.length+c.length}return r},I=y([73,68,51]),O=function(e,t=0){return(e=y(e)).length-t<10||!C(e,I,{offset:t})?t:(t+=function(e,t=0){const r=(e=y(e))[t+5],n=e[t+6]<<21|e[t+7]<<14|e[t+8]<<7|e[t+9];return(16&r)>>4?n+20:n+10}(e,t),O(e,t))},N=y([0,0,0,1]),G=y([0,0,1]),V=y([0,0,3]),F=function(e){const t=[];let r=1;for(;r<e.length-2;)C(e.subarray(r,r+3),V)&&(t.push(r+2),r++),r++;if(0===t.length)return e;const n=e.length-t.length,o=new Uint8Array(n);let i=0;for(r=0;r<n;i++,r++)i===t[0]&&(i++,t.shift()),o[r]=e[i];return o},j=function(e,t,r,n=1/0){e=y(e),r=[].concat(r);let o,i=0,s=0;for(;i<e.length&&(s<n||o);){let n,a;if(C(e.subarray(i),N)?n=4:C(e.subarray(i),G)&&(n=3),n){if(s++,o)return F(e.subarray(o,i));"h264"===t?a=31&e[i+n]:"h265"===t&&(a=e[i+n]>>1&63),-1!==r.indexOf(a)&&(o=i+n),i+=n+("h264"===t?1:2)}else i++}return e.subarray(0,0)},z={webm:y([119,101,98,109]),matroska:y([109,97,116,114,111,115,107,97]),flac:y([102,76,97,67]),ogg:y([79,103,103,83]),ac3:y([11,119]),riff:y([82,73,70,70]),avi:y([65,86,73]),wav:y([87,65,86,69]),"3gp":y([102,116,121,112,51,103]),mp4:y([102,116,121,112]),fmp4:y([115,116,121,112]),mov:y([102,116,121,112,113,116]),moov:y([109,111,111,118]),moof:y([109,111,111,102])},R={aac(e){const t=O(e);return C(e,[255,16],{offset:t,mask:[255,22]})},mp3(e){const t=O(e);return C(e,[255,2],{offset:t,mask:[255,6]})},webm(e){const t=M(e,[L.EBML,L.DocType])[0];return C(t,z.webm)},mkv(e){const t=M(e,[L.EBML,L.DocType])[0];return C(t,z.matroska)},mp4:e=>!R["3gp"](e)&&!R.mov(e)&&(!(!C(e,z.mp4,{offset:4})&&!C(e,z.fmp4,{offset:4}))||(!(!C(e,z.moof,{offset:4})&&!C(e,z.moov,{offset:4}))||void 0)),mov:e=>C(e,z.mov,{offset:4}),"3gp":e=>C(e,z["3gp"],{offset:4}),ac3(e){const t=O(e);return C(e,z.ac3,{offset:t})},ts(e){if(e.length<189&&e.length>=1)return 71===e[0];let t=0;for(;t+188<e.length&&t<188;){if(71===e[t]&&71===e[t+188])return!0;t+=1}return!1},flac(e){const t=O(e);return C(e,z.flac,{offset:t})},ogg:e=>C(e,z.ogg),avi:e=>C(e,z.riff)&&C(e,z.avi,{offset:8}),wav:e=>C(e,z.riff)&&C(e,z.wav,{offset:8}),h264:e=>((e,t,r)=>j(e,"h264",t,r))(e,7,3).length,h265:e=>((e,t,r)=>j(e,"h265",t,r))(e,[32,33],3).length},$=Object.keys(R).filter((e=>"ts"!==e&&"h264"!==e&&"h265"!==e)).concat(["ts","h264","h265"]);$.forEach((function(e){const t=R[e];R[e]=e=>t(y(e))}));const H=R;var P=Object.freeze({__proto__:null,isLikely:H,detectContainerForBytes:e=>{e=y(e);for(let t=0;t<$.length;t++){const r=$[t];if(H[r](e))return r}return""},isLikelyFmp4MediaSegment:e=>B(e,["moof"]).length>0});var q=Object.freeze({__proto__:null,forEachMediaGroup:(e,t,r)=>{t.forEach((t=>{for(const n in e.mediaGroups[t])for(const o in e.mediaGroups[t][n]){const i=e.mediaGroups[t][n][o];r(i,t,n,o)}}))}});const J="https://example.com";var K={codecs:l,byteHelpers:x,containers:P,decodeB64ToUint8Array:function(e){const t=(r=e,window.atob?window.atob(r):Buffer.from(r,"base64").toString("binary"));var r;const n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},mediaGroups:q,resolveUrl:(e,t)=>{if(/^[a-z]+:/i.test(t))return t;/^data:/.test(e)&&(e=window.location&&window.location.href||"");const r=/^\/\//.test(e),n=!window.location&&!/\/\//i.test(e);e=new window.URL(e,window.location||J);const o=new URL(t,e);return n?o.href.slice(J.length):r?o.href.slice(o.protocol.length):o.href},Stream:class{constructor(){this.listeners={}}on(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}off(e,t){if(!this.listeners[e])return!1;const r=this.listeners[e].indexOf(t);return this.listeners[e]=this.listeners[e].slice(0),this.listeners[e].splice(r,1),r>-1}trigger(e){const t=this.listeners[e];if(t)if(2===arguments.length){const e=t.length;for(let r=0;r<e;++r)t[r].call(this,arguments[1])}else{const e=Array.prototype.slice.call(arguments,1),r=t.length;for(let n=0;n<r;++n)t[n].apply(this,e)}}dispose(){this.listeners={}}pipe(e){this.on("data",(function(t){e.push(t)}))}}};return K})); |
@@ -1,4 +0,3 @@ | ||
import URLToolkit from 'url-toolkit'; | ||
import window from 'global/window'; | ||
var DEFAULT_LOCATION = 'http://example.com'; | ||
var DEFAULT_LOCATION = 'https://example.com'; | ||
@@ -14,7 +13,4 @@ var resolveUrl = function resolveUrl(baseUrl, relativeUrl) { | ||
baseUrl = window.location && window.location.href || ''; | ||
} // IE11 supports URL but not the URL constructor | ||
// feature detect the behavior we want | ||
} | ||
var nativeURL = typeof window.URL === 'function'; | ||
var protocolLess = /^\/\//.test(baseUrl); // remove location if window.location isn't available (i.e. we're in node) | ||
@@ -25,25 +21,16 @@ // and if baseUrl isn't an absolute url | ||
if (nativeURL) { | ||
baseUrl = new window.URL(baseUrl, window.location || DEFAULT_LOCATION); | ||
} else if (!/\/\//i.test(baseUrl)) { | ||
baseUrl = URLToolkit.buildAbsoluteURL(window.location && window.location.href || '', baseUrl); | ||
} | ||
baseUrl = new window.URL(baseUrl, window.location || DEFAULT_LOCATION); | ||
var newUrl = new URL(relativeUrl, baseUrl); // if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (nativeURL) { | ||
var newUrl = new URL(relativeUrl, baseUrl); // if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return newUrl.href; | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return URLToolkit.buildAbsoluteURL(baseUrl, relativeUrl); | ||
return newUrl.href; | ||
}; | ||
export default resolveUrl; |
{ | ||
"name": "@videojs/vhs-utils", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "Objects and functions shared throughtout @videojs/http-streaming code", | ||
@@ -79,4 +79,3 @@ "repository": { | ||
"@babel/runtime": "^7.12.5", | ||
"global": "^4.4.0", | ||
"url-toolkit": "^2.2.1" | ||
"global": "^4.4.0" | ||
}, | ||
@@ -83,0 +82,0 @@ "devDependencies": { |
@@ -1,5 +0,4 @@ | ||
import URLToolkit from 'url-toolkit'; | ||
import window from 'global/window'; | ||
const DEFAULT_LOCATION = 'http://example.com'; | ||
const DEFAULT_LOCATION = 'https://example.com'; | ||
@@ -17,6 +16,2 @@ const resolveUrl = (baseUrl, relativeUrl) => { | ||
// IE11 supports URL but not the URL constructor | ||
// feature detect the behavior we want | ||
const nativeURL = typeof window.URL === 'function'; | ||
const protocolLess = (/^\/\//.test(baseUrl)); | ||
@@ -28,26 +23,19 @@ // remove location if window.location isn't available (i.e. we're in node) | ||
// if the base URL is relative then combine with the current location | ||
if (nativeURL) { | ||
baseUrl = new window.URL(baseUrl, window.location || DEFAULT_LOCATION); | ||
} else if (!(/\/\//i).test(baseUrl)) { | ||
baseUrl = URLToolkit.buildAbsoluteURL(window.location && window.location.href || '', baseUrl); | ||
} | ||
baseUrl = new window.URL(baseUrl, window.location || DEFAULT_LOCATION); | ||
if (nativeURL) { | ||
const newUrl = new URL(relativeUrl, baseUrl); | ||
const newUrl = new URL(relativeUrl, baseUrl); | ||
// if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return newUrl.href; | ||
// if we're a protocol-less url, remove the protocol | ||
// and if we're location-less, remove the location | ||
// otherwise, return the url unmodified | ||
if (removeLocation) { | ||
return newUrl.href.slice(DEFAULT_LOCATION.length); | ||
} else if (protocolLess) { | ||
return newUrl.href.slice(newUrl.protocol.length); | ||
} | ||
return URLToolkit.buildAbsoluteURL(baseUrl, relativeUrl); | ||
return newUrl.href; | ||
}; | ||
export default resolveUrl; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2
478
4482992
10470
- Removedurl-toolkit@^2.2.1
- Removedurl-toolkit@2.2.5(transitive)