async-preloader
Advanced tools
Comparing version 3.1.1 to 3.2.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('fontfaceobserver')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'fontfaceobserver'], factory) : | ||
(factory((global.AsyncPreloader = {}),global.tslib,global.FontFaceObserver)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('tslib'), require('fontfaceobserver')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'tslib', 'fontfaceobserver'], factory) : | ||
(factory((global.AsyncPreloader = {}),global.tslib,global.FontFaceObserver)); | ||
}(this, (function (exports,tslib_1,FontFaceObserver) { 'use strict'; | ||
FontFaceObserver = FontFaceObserver && FontFaceObserver.hasOwnProperty('default') ? FontFaceObserver['default'] : FontFaceObserver; | ||
FontFaceObserver = FontFaceObserver && FontFaceObserver.hasOwnProperty('default') ? FontFaceObserver['default'] : FontFaceObserver; | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array, else `false`. | ||
* @example | ||
* | ||
* _.isArray([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArray(document.body.children); | ||
* // => false | ||
* | ||
* _.isArray('abc'); | ||
* // => false | ||
* | ||
* _.isArray(_.noop); | ||
* // => false | ||
*/ | ||
var isArray = Array.isArray; | ||
/** | ||
* Checks if `value` is classified as an `Array` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array, else `false`. | ||
* @example | ||
* | ||
* _.isArray([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isArray(document.body.children); | ||
* // => false | ||
* | ||
* _.isArray('abc'); | ||
* // => false | ||
* | ||
* _.isArray(_.noop); | ||
* // => false | ||
*/ | ||
var isArray = Array.isArray; | ||
/** Detect free variable `global` from Node.js. */ | ||
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; | ||
/** Detect free variable `global` from Node.js. */ | ||
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; | ||
/** Detect free variable `self`. */ | ||
var freeSelf = typeof self == 'object' && self && self.Object === Object && self; | ||
/** Detect free variable `self`. */ | ||
var freeSelf = typeof self == 'object' && self && self.Object === Object && self; | ||
/** Used as a reference to the global object. */ | ||
var root = freeGlobal || freeSelf || Function('return this')(); | ||
/** Used as a reference to the global object. */ | ||
var root = freeGlobal || freeSelf || Function('return this')(); | ||
/** Built-in value references. */ | ||
var Symbol = root.Symbol; | ||
/** Built-in value references. */ | ||
var Symbol = root.Symbol; | ||
/** Used for built-in method references. */ | ||
var objectProto = Object.prototype; | ||
/** Used for built-in method references. */ | ||
var objectProto = Object.prototype; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var nativeObjectToString = objectProto.toString; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var nativeObjectToString = objectProto.toString; | ||
/** Built-in value references. */ | ||
var symToStringTag = Symbol ? Symbol.toStringTag : undefined; | ||
/** Built-in value references. */ | ||
var symToStringTag = Symbol ? Symbol.toStringTag : undefined; | ||
/** | ||
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the raw `toStringTag`. | ||
*/ | ||
function getRawTag(value) { | ||
var isOwn = hasOwnProperty.call(value, symToStringTag), | ||
tag = value[symToStringTag]; | ||
/** | ||
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the raw `toStringTag`. | ||
*/ | ||
function getRawTag(value) { | ||
var isOwn = hasOwnProperty.call(value, symToStringTag), | ||
tag = value[symToStringTag]; | ||
try { | ||
value[symToStringTag] = undefined; | ||
} catch (e) {} | ||
try { | ||
value[symToStringTag] = undefined; | ||
var unmasked = true; | ||
} catch (e) {} | ||
var result = nativeObjectToString.call(value); | ||
{ | ||
if (isOwn) { | ||
value[symToStringTag] = tag; | ||
} else { | ||
delete value[symToStringTag]; | ||
} | ||
var result = nativeObjectToString.call(value); | ||
if (unmasked) { | ||
if (isOwn) { | ||
value[symToStringTag] = tag; | ||
} else { | ||
delete value[symToStringTag]; | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto$1 = Object.prototype; | ||
/** Used for built-in method references. */ | ||
var objectProto$1 = Object.prototype; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var nativeObjectToString$1 = objectProto$1.toString; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var nativeObjectToString$1 = objectProto$1.toString; | ||
/** | ||
* Converts `value` to a string using `Object.prototype.toString`. | ||
* | ||
* @private | ||
* @param {*} value The value to convert. | ||
* @returns {string} Returns the converted string. | ||
*/ | ||
function objectToString(value) { | ||
return nativeObjectToString$1.call(value); | ||
} | ||
/** | ||
* Converts `value` to a string using `Object.prototype.toString`. | ||
* | ||
* @private | ||
* @param {*} value The value to convert. | ||
* @returns {string} Returns the converted string. | ||
*/ | ||
function objectToString(value) { | ||
return nativeObjectToString$1.call(value); | ||
} | ||
/** `Object#toString` result references. */ | ||
var nullTag = '[object Null]', | ||
undefinedTag = '[object Undefined]'; | ||
/** `Object#toString` result references. */ | ||
var nullTag = '[object Null]', | ||
undefinedTag = '[object Undefined]'; | ||
/** Built-in value references. */ | ||
var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined; | ||
/** Built-in value references. */ | ||
var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined; | ||
/** | ||
* The base implementation of `getTag` without fallbacks for buggy environments. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the `toStringTag`. | ||
*/ | ||
function baseGetTag(value) { | ||
if (value == null) { | ||
return value === undefined ? undefinedTag : nullTag; | ||
} | ||
return (symToStringTag$1 && symToStringTag$1 in Object(value)) | ||
? getRawTag(value) | ||
: objectToString(value); | ||
/** | ||
* The base implementation of `getTag` without fallbacks for buggy environments. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the `toStringTag`. | ||
*/ | ||
function baseGetTag(value) { | ||
if (value == null) { | ||
return value === undefined ? undefinedTag : nullTag; | ||
} | ||
return (symToStringTag$1 && symToStringTag$1 in Object(value)) | ||
? getRawTag(value) | ||
: objectToString(value); | ||
} | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike(value) { | ||
return value != null && typeof value == 'object'; | ||
} | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike(value) { | ||
return value != null && typeof value == 'object'; | ||
} | ||
/** `Object#toString` result references. */ | ||
var symbolTag = '[object Symbol]'; | ||
/** `Object#toString` result references. */ | ||
var symbolTag = '[object Symbol]'; | ||
/** | ||
* Checks if `value` is classified as a `Symbol` primitive or object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`. | ||
* @example | ||
* | ||
* _.isSymbol(Symbol.iterator); | ||
* // => true | ||
* | ||
* _.isSymbol('abc'); | ||
* // => false | ||
*/ | ||
function isSymbol(value) { | ||
return typeof value == 'symbol' || | ||
(isObjectLike(value) && baseGetTag(value) == symbolTag); | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Symbol` primitive or object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`. | ||
* @example | ||
* | ||
* _.isSymbol(Symbol.iterator); | ||
* // => true | ||
* | ||
* _.isSymbol('abc'); | ||
* // => false | ||
*/ | ||
function isSymbol(value) { | ||
return typeof value == 'symbol' || | ||
(isObjectLike(value) && baseGetTag(value) == symbolTag); | ||
} | ||
/** Used to match property names within property paths. */ | ||
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, | ||
reIsPlainProp = /^\w*$/; | ||
/** Used to match property names within property paths. */ | ||
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, | ||
reIsPlainProp = /^\w*$/; | ||
/** | ||
* Checks if `value` is a property name and not a property path. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @param {Object} [object] The object to query keys on. | ||
* @returns {boolean} Returns `true` if `value` is a property name, else `false`. | ||
*/ | ||
function isKey(value, object) { | ||
if (isArray(value)) { | ||
return false; | ||
} | ||
var type = typeof value; | ||
if (type == 'number' || type == 'symbol' || type == 'boolean' || | ||
value == null || isSymbol(value)) { | ||
return true; | ||
} | ||
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || | ||
(object != null && value in Object(object)); | ||
/** | ||
* Checks if `value` is a property name and not a property path. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @param {Object} [object] The object to query keys on. | ||
* @returns {boolean} Returns `true` if `value` is a property name, else `false`. | ||
*/ | ||
function isKey(value, object) { | ||
if (isArray(value)) { | ||
return false; | ||
} | ||
/** | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
var type = typeof value; | ||
return value != null && (type == 'object' || type == 'function'); | ||
var type = typeof value; | ||
if (type == 'number' || type == 'symbol' || type == 'boolean' || | ||
value == null || isSymbol(value)) { | ||
return true; | ||
} | ||
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || | ||
(object != null && value in Object(object)); | ||
} | ||
/** `Object#toString` result references. */ | ||
var asyncTag = '[object AsyncFunction]', | ||
funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
proxyTag = '[object Proxy]'; | ||
/** | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject(value) { | ||
var type = typeof value; | ||
return value != null && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a function, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
if (!isObject(value)) { | ||
return false; | ||
} | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 9 which returns 'object' for typed arrays and other constructors. | ||
var tag = baseGetTag(value); | ||
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; | ||
/** `Object#toString` result references. */ | ||
var asyncTag = '[object AsyncFunction]', | ||
funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
proxyTag = '[object Proxy]'; | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a function, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
if (!isObject(value)) { | ||
return false; | ||
} | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 9 which returns 'object' for typed arrays and other constructors. | ||
var tag = baseGetTag(value); | ||
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; | ||
} | ||
/** Used to detect overreaching core-js shims. */ | ||
var coreJsData = root['__core-js_shared__']; | ||
/** Used to detect overreaching core-js shims. */ | ||
var coreJsData = root['__core-js_shared__']; | ||
/** Used to detect methods masquerading as native. */ | ||
var maskSrcKey = (function() { | ||
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); | ||
return uid ? ('Symbol(src)_1.' + uid) : ''; | ||
}()); | ||
/** Used to detect methods masquerading as native. */ | ||
var maskSrcKey = (function() { | ||
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); | ||
return uid ? ('Symbol(src)_1.' + uid) : ''; | ||
}()); | ||
/** | ||
* Checks if `func` has its source masked. | ||
* | ||
* @private | ||
* @param {Function} func The function to check. | ||
* @returns {boolean} Returns `true` if `func` is masked, else `false`. | ||
*/ | ||
function isMasked(func) { | ||
return !!maskSrcKey && (maskSrcKey in func); | ||
} | ||
/** | ||
* Checks if `func` has its source masked. | ||
* | ||
* @private | ||
* @param {Function} func The function to check. | ||
* @returns {boolean} Returns `true` if `func` is masked, else `false`. | ||
*/ | ||
function isMasked(func) { | ||
return !!maskSrcKey && (maskSrcKey in func); | ||
} | ||
/** Used for built-in method references. */ | ||
var funcProto = Function.prototype; | ||
/** Used for built-in method references. */ | ||
var funcProto = Function.prototype; | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString = funcProto.toString; | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString = funcProto.toString; | ||
/** | ||
* Converts `func` to its source code. | ||
* | ||
* @private | ||
* @param {Function} func The function to convert. | ||
* @returns {string} Returns the source code. | ||
*/ | ||
function toSource(func) { | ||
if (func != null) { | ||
try { | ||
return funcToString.call(func); | ||
} catch (e) {} | ||
try { | ||
return (func + ''); | ||
} catch (e) {} | ||
} | ||
return ''; | ||
/** | ||
* Converts `func` to its source code. | ||
* | ||
* @private | ||
* @param {Function} func The function to convert. | ||
* @returns {string} Returns the source code. | ||
*/ | ||
function toSource(func) { | ||
if (func != null) { | ||
try { | ||
return funcToString.call(func); | ||
} catch (e) {} | ||
try { | ||
return (func + ''); | ||
} catch (e) {} | ||
} | ||
return ''; | ||
} | ||
/** | ||
* Used to match `RegExp` | ||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). | ||
*/ | ||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
/** | ||
* Used to match `RegExp` | ||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). | ||
*/ | ||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
/** Used to detect host constructors (Safari). */ | ||
var reIsHostCtor = /^\[object .+?Constructor\]$/; | ||
/** Used to detect host constructors (Safari). */ | ||
var reIsHostCtor = /^\[object .+?Constructor\]$/; | ||
/** Used for built-in method references. */ | ||
var funcProto$1 = Function.prototype, | ||
objectProto$2 = Object.prototype; | ||
/** Used for built-in method references. */ | ||
var funcProto$1 = Function.prototype, | ||
objectProto$2 = Object.prototype; | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString$1 = funcProto$1.toString; | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString$1 = funcProto$1.toString; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty$1 = objectProto$2.hasOwnProperty; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty$1 = objectProto$2.hasOwnProperty; | ||
/** Used to detect if a method is native. */ | ||
var reIsNative = RegExp('^' + | ||
funcToString$1.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&') | ||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' | ||
); | ||
/** Used to detect if a method is native. */ | ||
var reIsNative = RegExp('^' + | ||
funcToString$1.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&') | ||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' | ||
); | ||
/** | ||
* The base implementation of `_.isNative` without bad shim checks. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a native function, | ||
* else `false`. | ||
*/ | ||
function baseIsNative(value) { | ||
if (!isObject(value) || isMasked(value)) { | ||
return false; | ||
} | ||
var pattern = isFunction(value) ? reIsNative : reIsHostCtor; | ||
return pattern.test(toSource(value)); | ||
/** | ||
* The base implementation of `_.isNative` without bad shim checks. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a native function, | ||
* else `false`. | ||
*/ | ||
function baseIsNative(value) { | ||
if (!isObject(value) || isMasked(value)) { | ||
return false; | ||
} | ||
var pattern = isFunction(value) ? reIsNative : reIsHostCtor; | ||
return pattern.test(toSource(value)); | ||
} | ||
/** | ||
* Gets the value at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} [object] The object to query. | ||
* @param {string} key The key of the property to get. | ||
* @returns {*} Returns the property value. | ||
*/ | ||
function getValue(object, key) { | ||
return object == null ? undefined : object[key]; | ||
} | ||
/** | ||
* Gets the value at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} [object] The object to query. | ||
* @param {string} key The key of the property to get. | ||
* @returns {*} Returns the property value. | ||
*/ | ||
function getValue(object, key) { | ||
return object == null ? undefined : object[key]; | ||
} | ||
/** | ||
* Gets the native function at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {string} key The key of the method to get. | ||
* @returns {*} Returns the function if it's native, else `undefined`. | ||
*/ | ||
function getNative(object, key) { | ||
var value = getValue(object, key); | ||
return baseIsNative(value) ? value : undefined; | ||
} | ||
/** | ||
* Gets the native function at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {string} key The key of the method to get. | ||
* @returns {*} Returns the function if it's native, else `undefined`. | ||
*/ | ||
function getNative(object, key) { | ||
var value = getValue(object, key); | ||
return baseIsNative(value) ? value : undefined; | ||
} | ||
/* Built-in method references that are verified to be native. */ | ||
var nativeCreate = getNative(Object, 'create'); | ||
/* Built-in method references that are verified to be native. */ | ||
var nativeCreate = getNative(Object, 'create'); | ||
/** | ||
* Removes all key-value entries from the hash. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf Hash | ||
*/ | ||
function hashClear() { | ||
this.__data__ = nativeCreate ? nativeCreate(null) : {}; | ||
this.size = 0; | ||
} | ||
/** | ||
* Removes all key-value entries from the hash. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf Hash | ||
*/ | ||
function hashClear() { | ||
this.__data__ = nativeCreate ? nativeCreate(null) : {}; | ||
this.size = 0; | ||
} | ||
/** | ||
* Removes `key` and its value from the hash. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf Hash | ||
* @param {Object} hash The hash to modify. | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function hashDelete(key) { | ||
var result = this.has(key) && delete this.__data__[key]; | ||
this.size -= result ? 1 : 0; | ||
return result; | ||
} | ||
/** | ||
* Removes `key` and its value from the hash. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf Hash | ||
* @param {Object} hash The hash to modify. | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function hashDelete(key) { | ||
var result = this.has(key) && delete this.__data__[key]; | ||
this.size -= result ? 1 : 0; | ||
return result; | ||
} | ||
/** Used to stand-in for `undefined` hash values. */ | ||
var HASH_UNDEFINED = '__lodash_hash_undefined__'; | ||
/** Used to stand-in for `undefined` hash values. */ | ||
var HASH_UNDEFINED = '__lodash_hash_undefined__'; | ||
/** Used for built-in method references. */ | ||
var objectProto$3 = Object.prototype; | ||
/** Used for built-in method references. */ | ||
var objectProto$3 = Object.prototype; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty$2 = objectProto$3.hasOwnProperty; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty$2 = objectProto$3.hasOwnProperty; | ||
/** | ||
* Gets the hash value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function hashGet(key) { | ||
var data = this.__data__; | ||
if (nativeCreate) { | ||
var result = data[key]; | ||
return result === HASH_UNDEFINED ? undefined : result; | ||
} | ||
return hasOwnProperty$2.call(data, key) ? data[key] : undefined; | ||
/** | ||
* Gets the hash value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function hashGet(key) { | ||
var data = this.__data__; | ||
if (nativeCreate) { | ||
var result = data[key]; | ||
return result === HASH_UNDEFINED ? undefined : result; | ||
} | ||
return hasOwnProperty$2.call(data, key) ? data[key] : undefined; | ||
} | ||
/** Used for built-in method references. */ | ||
var objectProto$4 = Object.prototype; | ||
/** Used for built-in method references. */ | ||
var objectProto$4 = Object.prototype; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty$3 = objectProto$4.hasOwnProperty; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty$3 = objectProto$4.hasOwnProperty; | ||
/** | ||
* Checks if a hash value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf Hash | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function hashHas(key) { | ||
var data = this.__data__; | ||
return nativeCreate ? (data[key] !== undefined) : hasOwnProperty$3.call(data, key); | ||
} | ||
/** | ||
* Checks if a hash value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf Hash | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function hashHas(key) { | ||
var data = this.__data__; | ||
return nativeCreate ? (data[key] !== undefined) : hasOwnProperty$3.call(data, key); | ||
} | ||
/** Used to stand-in for `undefined` hash values. */ | ||
var HASH_UNDEFINED$1 = '__lodash_hash_undefined__'; | ||
/** Used to stand-in for `undefined` hash values. */ | ||
var HASH_UNDEFINED$1 = '__lodash_hash_undefined__'; | ||
/** | ||
* Sets the hash `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the hash instance. | ||
*/ | ||
function hashSet(key, value) { | ||
var data = this.__data__; | ||
this.size += this.has(key) ? 0 : 1; | ||
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value; | ||
return this; | ||
} | ||
/** | ||
* Sets the hash `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf Hash | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the hash instance. | ||
*/ | ||
function hashSet(key, value) { | ||
var data = this.__data__; | ||
this.size += this.has(key) ? 0 : 1; | ||
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED$1 : value; | ||
return this; | ||
} | ||
/** | ||
* Creates a hash object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function Hash(entries) { | ||
var index = -1, | ||
length = entries == null ? 0 : entries.length; | ||
/** | ||
* Creates a hash object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function Hash(entries) { | ||
var index = -1, | ||
length = entries == null ? 0 : entries.length; | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
} | ||
// Add methods to `Hash`. | ||
Hash.prototype.clear = hashClear; | ||
Hash.prototype['delete'] = hashDelete; | ||
Hash.prototype.get = hashGet; | ||
Hash.prototype.has = hashHas; | ||
Hash.prototype.set = hashSet; | ||
// Add methods to `Hash`. | ||
Hash.prototype.clear = hashClear; | ||
Hash.prototype['delete'] = hashDelete; | ||
Hash.prototype.get = hashGet; | ||
Hash.prototype.has = hashHas; | ||
Hash.prototype.set = hashSet; | ||
/** | ||
* Removes all key-value entries from the list cache. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf ListCache | ||
*/ | ||
function listCacheClear() { | ||
this.__data__ = []; | ||
this.size = 0; | ||
} | ||
/** | ||
* Removes all key-value entries from the list cache. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf ListCache | ||
*/ | ||
function listCacheClear() { | ||
this.__data__ = []; | ||
this.size = 0; | ||
} | ||
/** | ||
* Performs a | ||
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) | ||
* comparison between two values to determine if they are equivalent. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to compare. | ||
* @param {*} other The other value to compare. | ||
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. | ||
* @example | ||
* | ||
* var object = { 'a': 1 }; | ||
* var other = { 'a': 1 }; | ||
* | ||
* _.eq(object, object); | ||
* // => true | ||
* | ||
* _.eq(object, other); | ||
* // => false | ||
* | ||
* _.eq('a', 'a'); | ||
* // => true | ||
* | ||
* _.eq('a', Object('a')); | ||
* // => false | ||
* | ||
* _.eq(NaN, NaN); | ||
* // => true | ||
*/ | ||
function eq(value, other) { | ||
return value === other || (value !== value && other !== other); | ||
} | ||
/** | ||
* Performs a | ||
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) | ||
* comparison between two values to determine if they are equivalent. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to compare. | ||
* @param {*} other The other value to compare. | ||
* @returns {boolean} Returns `true` if the values are equivalent, else `false`. | ||
* @example | ||
* | ||
* var object = { 'a': 1 }; | ||
* var other = { 'a': 1 }; | ||
* | ||
* _.eq(object, object); | ||
* // => true | ||
* | ||
* _.eq(object, other); | ||
* // => false | ||
* | ||
* _.eq('a', 'a'); | ||
* // => true | ||
* | ||
* _.eq('a', Object('a')); | ||
* // => false | ||
* | ||
* _.eq(NaN, NaN); | ||
* // => true | ||
*/ | ||
function eq(value, other) { | ||
return value === other || (value !== value && other !== other); | ||
} | ||
/** | ||
* Gets the index at which the `key` is found in `array` of key-value pairs. | ||
* | ||
* @private | ||
* @param {Array} array The array to inspect. | ||
* @param {*} key The key to search for. | ||
* @returns {number} Returns the index of the matched value, else `-1`. | ||
*/ | ||
function assocIndexOf(array, key) { | ||
var length = array.length; | ||
while (length--) { | ||
if (eq(array[length][0], key)) { | ||
return length; | ||
} | ||
/** | ||
* Gets the index at which the `key` is found in `array` of key-value pairs. | ||
* | ||
* @private | ||
* @param {Array} array The array to inspect. | ||
* @param {*} key The key to search for. | ||
* @returns {number} Returns the index of the matched value, else `-1`. | ||
*/ | ||
function assocIndexOf(array, key) { | ||
var length = array.length; | ||
while (length--) { | ||
if (eq(array[length][0], key)) { | ||
return length; | ||
} | ||
return -1; | ||
} | ||
return -1; | ||
} | ||
/** Used for built-in method references. */ | ||
var arrayProto = Array.prototype; | ||
/** Used for built-in method references. */ | ||
var arrayProto = Array.prototype; | ||
/** Built-in value references. */ | ||
var splice = arrayProto.splice; | ||
/** Built-in value references. */ | ||
var splice = arrayProto.splice; | ||
/** | ||
* Removes `key` and its value from the list cache. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function listCacheDelete(key) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
/** | ||
* Removes `key` and its value from the list cache. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function listCacheDelete(key) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
if (index < 0) { | ||
return false; | ||
} | ||
var lastIndex = data.length - 1; | ||
if (index == lastIndex) { | ||
data.pop(); | ||
} else { | ||
splice.call(data, index, 1); | ||
} | ||
--this.size; | ||
return true; | ||
if (index < 0) { | ||
return false; | ||
} | ||
var lastIndex = data.length - 1; | ||
if (index == lastIndex) { | ||
data.pop(); | ||
} else { | ||
splice.call(data, index, 1); | ||
} | ||
--this.size; | ||
return true; | ||
} | ||
/** | ||
* Gets the list cache value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function listCacheGet(key) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
/** | ||
* Gets the list cache value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function listCacheGet(key) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
return index < 0 ? undefined : data[index][1]; | ||
} | ||
return index < 0 ? undefined : data[index][1]; | ||
} | ||
/** | ||
* Checks if a list cache value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf ListCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function listCacheHas(key) { | ||
return assocIndexOf(this.__data__, key) > -1; | ||
} | ||
/** | ||
* Checks if a list cache value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf ListCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function listCacheHas(key) { | ||
return assocIndexOf(this.__data__, key) > -1; | ||
} | ||
/** | ||
* Sets the list cache `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the list cache instance. | ||
*/ | ||
function listCacheSet(key, value) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
/** | ||
* Sets the list cache `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf ListCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the list cache instance. | ||
*/ | ||
function listCacheSet(key, value) { | ||
var data = this.__data__, | ||
index = assocIndexOf(data, key); | ||
if (index < 0) { | ||
++this.size; | ||
data.push([key, value]); | ||
} else { | ||
data[index][1] = value; | ||
} | ||
return this; | ||
if (index < 0) { | ||
++this.size; | ||
data.push([key, value]); | ||
} else { | ||
data[index][1] = value; | ||
} | ||
return this; | ||
} | ||
/** | ||
* Creates an list cache object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function ListCache(entries) { | ||
var index = -1, | ||
length = entries == null ? 0 : entries.length; | ||
/** | ||
* Creates an list cache object. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function ListCache(entries) { | ||
var index = -1, | ||
length = entries == null ? 0 : entries.length; | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
} | ||
// Add methods to `ListCache`. | ||
ListCache.prototype.clear = listCacheClear; | ||
ListCache.prototype['delete'] = listCacheDelete; | ||
ListCache.prototype.get = listCacheGet; | ||
ListCache.prototype.has = listCacheHas; | ||
ListCache.prototype.set = listCacheSet; | ||
// Add methods to `ListCache`. | ||
ListCache.prototype.clear = listCacheClear; | ||
ListCache.prototype['delete'] = listCacheDelete; | ||
ListCache.prototype.get = listCacheGet; | ||
ListCache.prototype.has = listCacheHas; | ||
ListCache.prototype.set = listCacheSet; | ||
/* Built-in method references that are verified to be native. */ | ||
var Map$1 = getNative(root, 'Map'); | ||
/* Built-in method references that are verified to be native. */ | ||
var Map$1 = getNative(root, 'Map'); | ||
/** | ||
* Removes all key-value entries from the map. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf MapCache | ||
*/ | ||
function mapCacheClear() { | ||
this.size = 0; | ||
this.__data__ = { | ||
'hash': new Hash, | ||
'map': new (Map$1 || ListCache), | ||
'string': new Hash | ||
}; | ||
} | ||
/** | ||
* Removes all key-value entries from the map. | ||
* | ||
* @private | ||
* @name clear | ||
* @memberOf MapCache | ||
*/ | ||
function mapCacheClear() { | ||
this.size = 0; | ||
this.__data__ = { | ||
'hash': new Hash, | ||
'map': new (Map$1 || ListCache), | ||
'string': new Hash | ||
}; | ||
} | ||
/** | ||
* Checks if `value` is suitable for use as unique object key. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is suitable, else `false`. | ||
*/ | ||
function isKeyable(value) { | ||
var type = typeof value; | ||
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') | ||
? (value !== '__proto__') | ||
: (value === null); | ||
} | ||
/** | ||
* Checks if `value` is suitable for use as unique object key. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is suitable, else `false`. | ||
*/ | ||
function isKeyable(value) { | ||
var type = typeof value; | ||
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') | ||
? (value !== '__proto__') | ||
: (value === null); | ||
} | ||
/** | ||
* Gets the data for `map`. | ||
* | ||
* @private | ||
* @param {Object} map The map to query. | ||
* @param {string} key The reference key. | ||
* @returns {*} Returns the map data. | ||
*/ | ||
function getMapData(map, key) { | ||
var data = map.__data__; | ||
return isKeyable(key) | ||
? data[typeof key == 'string' ? 'string' : 'hash'] | ||
: data.map; | ||
} | ||
/** | ||
* Gets the data for `map`. | ||
* | ||
* @private | ||
* @param {Object} map The map to query. | ||
* @param {string} key The reference key. | ||
* @returns {*} Returns the map data. | ||
*/ | ||
function getMapData(map, key) { | ||
var data = map.__data__; | ||
return isKeyable(key) | ||
? data[typeof key == 'string' ? 'string' : 'hash'] | ||
: data.map; | ||
} | ||
/** | ||
* Removes `key` and its value from the map. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function mapCacheDelete(key) { | ||
var result = getMapData(this, key)['delete'](key); | ||
this.size -= result ? 1 : 0; | ||
return result; | ||
} | ||
/** | ||
* Removes `key` and its value from the map. | ||
* | ||
* @private | ||
* @name delete | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to remove. | ||
* @returns {boolean} Returns `true` if the entry was removed, else `false`. | ||
*/ | ||
function mapCacheDelete(key) { | ||
var result = getMapData(this, key)['delete'](key); | ||
this.size -= result ? 1 : 0; | ||
return result; | ||
} | ||
/** | ||
* Gets the map value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function mapCacheGet(key) { | ||
return getMapData(this, key).get(key); | ||
} | ||
/** | ||
* Gets the map value for `key`. | ||
* | ||
* @private | ||
* @name get | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to get. | ||
* @returns {*} Returns the entry value. | ||
*/ | ||
function mapCacheGet(key) { | ||
return getMapData(this, key).get(key); | ||
} | ||
/** | ||
* Checks if a map value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf MapCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function mapCacheHas(key) { | ||
return getMapData(this, key).has(key); | ||
} | ||
/** | ||
* Checks if a map value for `key` exists. | ||
* | ||
* @private | ||
* @name has | ||
* @memberOf MapCache | ||
* @param {string} key The key of the entry to check. | ||
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. | ||
*/ | ||
function mapCacheHas(key) { | ||
return getMapData(this, key).has(key); | ||
} | ||
/** | ||
* Sets the map `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the map cache instance. | ||
*/ | ||
function mapCacheSet(key, value) { | ||
var data = getMapData(this, key), | ||
size = data.size; | ||
/** | ||
* Sets the map `key` to `value`. | ||
* | ||
* @private | ||
* @name set | ||
* @memberOf MapCache | ||
* @param {string} key The key of the value to set. | ||
* @param {*} value The value to set. | ||
* @returns {Object} Returns the map cache instance. | ||
*/ | ||
function mapCacheSet(key, value) { | ||
var data = getMapData(this, key), | ||
size = data.size; | ||
data.set(key, value); | ||
this.size += data.size == size ? 0 : 1; | ||
return this; | ||
} | ||
data.set(key, value); | ||
this.size += data.size == size ? 0 : 1; | ||
return this; | ||
} | ||
/** | ||
* Creates a map cache object to store key-value pairs. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function MapCache(entries) { | ||
var index = -1, | ||
length = entries == null ? 0 : entries.length; | ||
/** | ||
* Creates a map cache object to store key-value pairs. | ||
* | ||
* @private | ||
* @constructor | ||
* @param {Array} [entries] The key-value pairs to cache. | ||
*/ | ||
function MapCache(entries) { | ||
var index = -1, | ||
length = entries == null ? 0 : entries.length; | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
this.clear(); | ||
while (++index < length) { | ||
var entry = entries[index]; | ||
this.set(entry[0], entry[1]); | ||
} | ||
} | ||
// Add methods to `MapCache`. | ||
MapCache.prototype.clear = mapCacheClear; | ||
MapCache.prototype['delete'] = mapCacheDelete; | ||
MapCache.prototype.get = mapCacheGet; | ||
MapCache.prototype.has = mapCacheHas; | ||
MapCache.prototype.set = mapCacheSet; | ||
// Add methods to `MapCache`. | ||
MapCache.prototype.clear = mapCacheClear; | ||
MapCache.prototype['delete'] = mapCacheDelete; | ||
MapCache.prototype.get = mapCacheGet; | ||
MapCache.prototype.has = mapCacheHas; | ||
MapCache.prototype.set = mapCacheSet; | ||
/** Error message constants. */ | ||
var FUNC_ERROR_TEXT = 'Expected a function'; | ||
/** Error message constants. */ | ||
var FUNC_ERROR_TEXT = 'Expected a function'; | ||
/** | ||
* Creates a function that memoizes the result of `func`. If `resolver` is | ||
* provided, it determines the cache key for storing the result based on the | ||
* arguments provided to the memoized function. By default, the first argument | ||
* provided to the memoized function is used as the map cache key. The `func` | ||
* is invoked with the `this` binding of the memoized function. | ||
* | ||
* **Note:** The cache is exposed as the `cache` property on the memoized | ||
* function. Its creation may be customized by replacing the `_.memoize.Cache` | ||
* constructor with one whose instances implement the | ||
* [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) | ||
* method interface of `clear`, `delete`, `get`, `has`, and `set`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Function | ||
* @param {Function} func The function to have its output memoized. | ||
* @param {Function} [resolver] The function to resolve the cache key. | ||
* @returns {Function} Returns the new memoized function. | ||
* @example | ||
* | ||
* var object = { 'a': 1, 'b': 2 }; | ||
* var other = { 'c': 3, 'd': 4 }; | ||
* | ||
* var values = _.memoize(_.values); | ||
* values(object); | ||
* // => [1, 2] | ||
* | ||
* values(other); | ||
* // => [3, 4] | ||
* | ||
* object.a = 2; | ||
* values(object); | ||
* // => [1, 2] | ||
* | ||
* // Modify the result cache. | ||
* values.cache.set(object, ['a', 'b']); | ||
* values(object); | ||
* // => ['a', 'b'] | ||
* | ||
* // Replace `_.memoize.Cache`. | ||
* _.memoize.Cache = WeakMap; | ||
*/ | ||
function memoize(func, resolver) { | ||
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { | ||
throw new TypeError(FUNC_ERROR_TEXT); | ||
/** | ||
* Creates a function that memoizes the result of `func`. If `resolver` is | ||
* provided, it determines the cache key for storing the result based on the | ||
* arguments provided to the memoized function. By default, the first argument | ||
* provided to the memoized function is used as the map cache key. The `func` | ||
* is invoked with the `this` binding of the memoized function. | ||
* | ||
* **Note:** The cache is exposed as the `cache` property on the memoized | ||
* function. Its creation may be customized by replacing the `_.memoize.Cache` | ||
* constructor with one whose instances implement the | ||
* [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) | ||
* method interface of `clear`, `delete`, `get`, `has`, and `set`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Function | ||
* @param {Function} func The function to have its output memoized. | ||
* @param {Function} [resolver] The function to resolve the cache key. | ||
* @returns {Function} Returns the new memoized function. | ||
* @example | ||
* | ||
* var object = { 'a': 1, 'b': 2 }; | ||
* var other = { 'c': 3, 'd': 4 }; | ||
* | ||
* var values = _.memoize(_.values); | ||
* values(object); | ||
* // => [1, 2] | ||
* | ||
* values(other); | ||
* // => [3, 4] | ||
* | ||
* object.a = 2; | ||
* values(object); | ||
* // => [1, 2] | ||
* | ||
* // Modify the result cache. | ||
* values.cache.set(object, ['a', 'b']); | ||
* values(object); | ||
* // => ['a', 'b'] | ||
* | ||
* // Replace `_.memoize.Cache`. | ||
* _.memoize.Cache = WeakMap; | ||
*/ | ||
function memoize(func, resolver) { | ||
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { | ||
throw new TypeError(FUNC_ERROR_TEXT); | ||
} | ||
var memoized = function() { | ||
var args = arguments, | ||
key = resolver ? resolver.apply(this, args) : args[0], | ||
cache = memoized.cache; | ||
if (cache.has(key)) { | ||
return cache.get(key); | ||
} | ||
var memoized = function() { | ||
var args = arguments, | ||
key = resolver ? resolver.apply(this, args) : args[0], | ||
cache = memoized.cache; | ||
var result = func.apply(this, args); | ||
memoized.cache = cache.set(key, result) || cache; | ||
return result; | ||
}; | ||
memoized.cache = new (memoize.Cache || MapCache); | ||
return memoized; | ||
} | ||
if (cache.has(key)) { | ||
return cache.get(key); | ||
} | ||
var result = func.apply(this, args); | ||
memoized.cache = cache.set(key, result) || cache; | ||
return result; | ||
}; | ||
memoized.cache = new (memoize.Cache || MapCache); | ||
return memoized; | ||
} | ||
// Expose `MapCache`. | ||
memoize.Cache = MapCache; | ||
// Expose `MapCache`. | ||
memoize.Cache = MapCache; | ||
/** Used as the maximum memoize cache size. */ | ||
var MAX_MEMOIZE_SIZE = 500; | ||
/** Used as the maximum memoize cache size. */ | ||
var MAX_MEMOIZE_SIZE = 500; | ||
/** | ||
* A specialized version of `_.memoize` which clears the memoized function's | ||
* cache when it exceeds `MAX_MEMOIZE_SIZE`. | ||
* | ||
* @private | ||
* @param {Function} func The function to have its output memoized. | ||
* @returns {Function} Returns the new memoized function. | ||
*/ | ||
function memoizeCapped(func) { | ||
var result = memoize(func, function(key) { | ||
if (cache.size === MAX_MEMOIZE_SIZE) { | ||
cache.clear(); | ||
} | ||
return key; | ||
}); | ||
/** | ||
* A specialized version of `_.memoize` which clears the memoized function's | ||
* cache when it exceeds `MAX_MEMOIZE_SIZE`. | ||
* | ||
* @private | ||
* @param {Function} func The function to have its output memoized. | ||
* @returns {Function} Returns the new memoized function. | ||
*/ | ||
function memoizeCapped(func) { | ||
var result = memoize(func, function(key) { | ||
if (cache.size === MAX_MEMOIZE_SIZE) { | ||
cache.clear(); | ||
} | ||
return key; | ||
}); | ||
var cache = result.cache; | ||
return result; | ||
} | ||
var cache = result.cache; | ||
return result; | ||
} | ||
/** Used to match property names within property paths. */ | ||
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; | ||
/** Used to match property names within property paths. */ | ||
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; | ||
/** Used to match backslashes in property paths. */ | ||
var reEscapeChar = /\\(\\)?/g; | ||
/** Used to match backslashes in property paths. */ | ||
var reEscapeChar = /\\(\\)?/g; | ||
/** | ||
* Converts `string` to a property path array. | ||
* | ||
* @private | ||
* @param {string} string The string to convert. | ||
* @returns {Array} Returns the property path array. | ||
*/ | ||
var stringToPath = memoizeCapped(function(string) { | ||
var result = []; | ||
if (string.charCodeAt(0) === 46 /* . */) { | ||
result.push(''); | ||
} | ||
string.replace(rePropName, function(match, number, quote, subString) { | ||
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); | ||
}); | ||
return result; | ||
/** | ||
* Converts `string` to a property path array. | ||
* | ||
* @private | ||
* @param {string} string The string to convert. | ||
* @returns {Array} Returns the property path array. | ||
*/ | ||
var stringToPath = memoizeCapped(function(string) { | ||
var result = []; | ||
if (string.charCodeAt(0) === 46 /* . */) { | ||
result.push(''); | ||
} | ||
string.replace(rePropName, function(match, number, quote, subString) { | ||
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); | ||
}); | ||
return result; | ||
}); | ||
/** | ||
* A specialized version of `_.map` for arrays without support for iteratee | ||
* shorthands. | ||
* | ||
* @private | ||
* @param {Array} [array] The array to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @returns {Array} Returns the new mapped array. | ||
*/ | ||
function arrayMap(array, iteratee) { | ||
var index = -1, | ||
length = array == null ? 0 : array.length, | ||
result = Array(length); | ||
/** | ||
* A specialized version of `_.map` for arrays without support for iteratee | ||
* shorthands. | ||
* | ||
* @private | ||
* @param {Array} [array] The array to iterate over. | ||
* @param {Function} iteratee The function invoked per iteration. | ||
* @returns {Array} Returns the new mapped array. | ||
*/ | ||
function arrayMap(array, iteratee) { | ||
var index = -1, | ||
length = array == null ? 0 : array.length, | ||
result = Array(length); | ||
while (++index < length) { | ||
result[index] = iteratee(array[index], index, array); | ||
} | ||
return result; | ||
while (++index < length) { | ||
result[index] = iteratee(array[index], index, array); | ||
} | ||
return result; | ||
} | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY = 1 / 0; | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY = 1 / 0; | ||
/** Used to convert symbols to primitives and strings. */ | ||
var symbolProto = Symbol ? Symbol.prototype : undefined, | ||
symbolToString = symbolProto ? symbolProto.toString : undefined; | ||
/** Used to convert symbols to primitives and strings. */ | ||
var symbolProto = Symbol ? Symbol.prototype : undefined, | ||
symbolToString = symbolProto ? symbolProto.toString : undefined; | ||
/** | ||
* The base implementation of `_.toString` which doesn't convert nullish | ||
* values to empty strings. | ||
* | ||
* @private | ||
* @param {*} value The value to process. | ||
* @returns {string} Returns the string. | ||
*/ | ||
function baseToString(value) { | ||
// Exit early for strings to avoid a performance hit in some environments. | ||
if (typeof value == 'string') { | ||
return value; | ||
} | ||
if (isArray(value)) { | ||
// Recursively convert values (susceptible to call stack limits). | ||
return arrayMap(value, baseToString) + ''; | ||
} | ||
if (isSymbol(value)) { | ||
return symbolToString ? symbolToString.call(value) : ''; | ||
} | ||
var result = (value + ''); | ||
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; | ||
/** | ||
* The base implementation of `_.toString` which doesn't convert nullish | ||
* values to empty strings. | ||
* | ||
* @private | ||
* @param {*} value The value to process. | ||
* @returns {string} Returns the string. | ||
*/ | ||
function baseToString(value) { | ||
// Exit early for strings to avoid a performance hit in some environments. | ||
if (typeof value == 'string') { | ||
return value; | ||
} | ||
/** | ||
* Converts `value` to a string. An empty string is returned for `null` | ||
* and `undefined` values. The sign of `-0` is preserved. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to convert. | ||
* @returns {string} Returns the converted string. | ||
* @example | ||
* | ||
* _.toString(null); | ||
* // => '' | ||
* | ||
* _.toString(-0); | ||
* // => '-0' | ||
* | ||
* _.toString([1, 2, 3]); | ||
* // => '1,2,3' | ||
*/ | ||
function toString(value) { | ||
return value == null ? '' : baseToString(value); | ||
if (isArray(value)) { | ||
// Recursively convert values (susceptible to call stack limits). | ||
return arrayMap(value, baseToString) + ''; | ||
} | ||
if (isSymbol(value)) { | ||
return symbolToString ? symbolToString.call(value) : ''; | ||
} | ||
var result = (value + ''); | ||
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; | ||
} | ||
/** | ||
* Casts `value` to a path array if it's not one. | ||
* | ||
* @private | ||
* @param {*} value The value to inspect. | ||
* @param {Object} [object] The object to query keys on. | ||
* @returns {Array} Returns the cast property path array. | ||
*/ | ||
function castPath(value, object) { | ||
if (isArray(value)) { | ||
return value; | ||
} | ||
return isKey(value, object) ? [value] : stringToPath(toString(value)); | ||
/** | ||
* Converts `value` to a string. An empty string is returned for `null` | ||
* and `undefined` values. The sign of `-0` is preserved. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to convert. | ||
* @returns {string} Returns the converted string. | ||
* @example | ||
* | ||
* _.toString(null); | ||
* // => '' | ||
* | ||
* _.toString(-0); | ||
* // => '-0' | ||
* | ||
* _.toString([1, 2, 3]); | ||
* // => '1,2,3' | ||
*/ | ||
function toString(value) { | ||
return value == null ? '' : baseToString(value); | ||
} | ||
/** | ||
* Casts `value` to a path array if it's not one. | ||
* | ||
* @private | ||
* @param {*} value The value to inspect. | ||
* @param {Object} [object] The object to query keys on. | ||
* @returns {Array} Returns the cast property path array. | ||
*/ | ||
function castPath(value, object) { | ||
if (isArray(value)) { | ||
return value; | ||
} | ||
return isKey(value, object) ? [value] : stringToPath(toString(value)); | ||
} | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY$1 = 1 / 0; | ||
/** Used as references for various `Number` constants. */ | ||
var INFINITY$1 = 1 / 0; | ||
/** | ||
* Converts `value` to a string key if it's not a string or symbol. | ||
* | ||
* @private | ||
* @param {*} value The value to inspect. | ||
* @returns {string|symbol} Returns the key. | ||
*/ | ||
function toKey(value) { | ||
if (typeof value == 'string' || isSymbol(value)) { | ||
return value; | ||
} | ||
var result = (value + ''); | ||
return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result; | ||
/** | ||
* Converts `value` to a string key if it's not a string or symbol. | ||
* | ||
* @private | ||
* @param {*} value The value to inspect. | ||
* @returns {string|symbol} Returns the key. | ||
*/ | ||
function toKey(value) { | ||
if (typeof value == 'string' || isSymbol(value)) { | ||
return value; | ||
} | ||
var result = (value + ''); | ||
return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result; | ||
} | ||
/** | ||
* The base implementation of `_.get` without support for default values. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} path The path of the property to get. | ||
* @returns {*} Returns the resolved value. | ||
*/ | ||
function baseGet(object, path) { | ||
path = castPath(path, object); | ||
/** | ||
* The base implementation of `_.get` without support for default values. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} path The path of the property to get. | ||
* @returns {*} Returns the resolved value. | ||
*/ | ||
function baseGet(object, path) { | ||
path = castPath(path, object); | ||
var index = 0, | ||
length = path.length; | ||
var index = 0, | ||
length = path.length; | ||
while (object != null && index < length) { | ||
object = object[toKey(path[index++])]; | ||
} | ||
return (index && index == length) ? object : undefined; | ||
while (object != null && index < length) { | ||
object = object[toKey(path[index++])]; | ||
} | ||
return (index && index == length) ? object : undefined; | ||
} | ||
/** | ||
* Gets the value at `path` of `object`. If the resolved value is | ||
* `undefined`, the `defaultValue` is returned in its place. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 3.7.0 | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} path The path of the property to get. | ||
* @param {*} [defaultValue] The value returned for `undefined` resolved values. | ||
* @returns {*} Returns the resolved value. | ||
* @example | ||
* | ||
* var object = { 'a': [{ 'b': { 'c': 3 } }] }; | ||
* | ||
* _.get(object, 'a[0].b.c'); | ||
* // => 3 | ||
* | ||
* _.get(object, ['a', '0', 'b', 'c']); | ||
* // => 3 | ||
* | ||
* _.get(object, 'a.b.c', 'default'); | ||
* // => 'default' | ||
*/ | ||
function get(object, path, defaultValue) { | ||
var result = object == null ? undefined : baseGet(object, path); | ||
return result === undefined ? defaultValue : result; | ||
} | ||
/** | ||
* Gets the value at `path` of `object`. If the resolved value is | ||
* `undefined`, the `defaultValue` is returned in its place. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 3.7.0 | ||
* @category Object | ||
* @param {Object} object The object to query. | ||
* @param {Array|string} path The path of the property to get. | ||
* @param {*} [defaultValue] The value returned for `undefined` resolved values. | ||
* @returns {*} Returns the resolved value. | ||
* @example | ||
* | ||
* var object = { 'a': [{ 'b': { 'c': 3 } }] }; | ||
* | ||
* _.get(object, 'a[0].b.c'); | ||
* // => 3 | ||
* | ||
* _.get(object, ['a', '0', 'b', 'c']); | ||
* // => 3 | ||
* | ||
* _.get(object, 'a.b.c', 'default'); | ||
* // => 'default' | ||
*/ | ||
function get(object, path, defaultValue) { | ||
var result = object == null ? undefined : baseGet(object, path); | ||
return result === undefined ? defaultValue : result; | ||
} | ||
/** | ||
* Keys used for the [[AsyncPreloader.loaders]] | ||
*/ | ||
var LoaderKey; | ||
(function (LoaderKey) { | ||
LoaderKey["Json"] = "Json"; | ||
LoaderKey["ArrayBuffer"] = "ArrayBuffer"; | ||
LoaderKey["Blob"] = "Blob"; | ||
LoaderKey["FormData"] = "FormData"; | ||
LoaderKey["Text"] = "Text"; | ||
LoaderKey["Image"] = "Image"; | ||
LoaderKey["Video"] = "Video"; | ||
LoaderKey["Audio"] = "Audio"; | ||
LoaderKey["Xml"] = "Xml"; | ||
LoaderKey["Font"] = "Font"; | ||
})(LoaderKey || (LoaderKey = {})); | ||
/** | ||
* Keys used for the [[AsyncPreloader.loaders]] | ||
*/ | ||
var LoaderKey; | ||
(function (LoaderKey) { | ||
LoaderKey["Json"] = "Json"; | ||
LoaderKey["ArrayBuffer"] = "ArrayBuffer"; | ||
LoaderKey["Blob"] = "Blob"; | ||
LoaderKey["FormData"] = "FormData"; | ||
LoaderKey["Text"] = "Text"; | ||
LoaderKey["Image"] = "Image"; | ||
LoaderKey["Video"] = "Video"; | ||
LoaderKey["Audio"] = "Audio"; | ||
LoaderKey["Xml"] = "Xml"; | ||
LoaderKey["Font"] = "Font"; | ||
})(LoaderKey || (LoaderKey = {})); | ||
/** | ||
* AsyncPreloader: assets preloader using ES2017 async/await and fetch. | ||
* | ||
* It exports an instance of itself as default so you can: | ||
* | ||
* ```js | ||
* import Preloader from "async-preloader"; | ||
* | ||
* await Preloader.loadItems([]); | ||
* ``` | ||
* | ||
* to use directly as a singleton or | ||
* | ||
* ```js | ||
* import { AsyncPreloader as Preloader } from "async-preloader"; | ||
* | ||
* const preloader = new Preloader(); | ||
* await preloader.loadItems([]); | ||
* ``` | ||
* if you need more than one instance. | ||
*/ | ||
var AsyncPreloader = /** @class */ (function () { | ||
function AsyncPreloader() { | ||
var _this = this; | ||
// Properties | ||
/** | ||
* Object that contains the loaded items | ||
*/ | ||
this.items = new Map(); | ||
/** | ||
* Default body method to be called on the Response from fetch if no body option is specified on the LoadItem | ||
*/ | ||
this.defaultBodyMethod = "blob"; | ||
/** | ||
* Default loader to use if no loader key is specified in the [[LoadItem]] or if the extension doesn't match any of the [[AsyncPreloader.loaders]] extensions | ||
*/ | ||
this.defaultLoader = LoaderKey.Text; | ||
// API | ||
/** | ||
* Load the specified manifest (array of items) | ||
* | ||
* @param {LoadItem[]} items Items to load | ||
* @returns {Promise<LoadedValue[]>} Resolve when all items are loaded, reject for any error | ||
*/ | ||
this.loadItems = function (items) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(items.map(this.loadItem))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load a single item | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Resolve when item is loaded, reject for any error | ||
*/ | ||
this.loadItem = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var extension, loaderKey, mimeType, loadedItem; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
extension = AsyncPreloader.getFileExtension(item.src); | ||
loaderKey = item.loader || AsyncPreloader.getLoaderKey(extension); | ||
if (loaderKey === "Xml" && !item.mimeType) { | ||
mimeType = AsyncPreloader.loaders.get(LoaderKey.Xml).mimeType[extension] || | ||
AsyncPreloader.loaders.get(LoaderKey.Xml).mimeType["svg"]; | ||
item = tslib_1.__assign({}, item, { mimeType: mimeType }); | ||
} | ||
return [4 /*yield*/, this["load" + loaderKey](item)]; | ||
case 1: | ||
loadedItem = _a.sent(); | ||
this.items.set(item.id || item.src, loadedItem); | ||
return [2 /*return*/, loadedItem]; | ||
} | ||
}); | ||
}); }; | ||
// Special loaders | ||
/** | ||
* Load a manifest of items | ||
* | ||
* @param {string} src Manifest src url | ||
* @param {string} [key="items"] Manifest key in the JSON object containing the array of LoadItem. Used by [lodash.get](https://lodash.com/docs/4.17.5#get). | ||
* @returns {Promise<LoadedValue[]>} | ||
*/ | ||
this.loadManifest = function (src, key) { | ||
if (key === void 0) { key = "items"; } | ||
return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var loadedManifest, items; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.loadJson({ | ||
src: src | ||
})]; | ||
case 1: | ||
loadedManifest = _a.sent(); | ||
items = get(loadedManifest, key); | ||
return [4 /*yield*/, this.loadItems(items)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
// Text loaders | ||
/** | ||
* Load an item and parse the Response as text | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadText = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.text()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as json | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadJson = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.json()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as arrayBuffer | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadArrayBuffer = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.arrayBuffer()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as blob | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadBlob = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.blob()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as formData | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadFormData = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.formData()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
// Custom loaders | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Image" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLImageElement with a blob as src. | ||
*/ | ||
this.loadImage = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data, image; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response[item.body || this.defaultBodyMethod]()]; | ||
case 2: | ||
data = _a.sent(); | ||
if (item.body && item.body !== this.defaultBodyMethod) { | ||
return [2 /*return*/, data]; | ||
} | ||
image = new Image(); | ||
image.src = URL.createObjectURL(data); | ||
return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
image.addEventListener("load", function () { return resolve(image); }, false); | ||
image.addEventListener("error", reject, false); | ||
})]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Video" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLVideoElement with a blob as src. | ||
*/ | ||
this.loadVideo = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data, video; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response[item.body || this.defaultBodyMethod]()]; | ||
case 2: | ||
data = _a.sent(); | ||
if (item.body && item.body !== this.defaultBodyMethod) { | ||
return [2 /*return*/, data]; | ||
} | ||
video = document.createElement("video"); | ||
video.src = URL.createObjectURL(data); | ||
return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
video.addEventListener("canplaythrough", function () { return resolve(video); }, false); | ||
video.addEventListener("error", reject, false); | ||
})]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Audio" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLAudioElement with a blob as src. | ||
*/ | ||
this.loadAudio = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data, audio; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response[item.body || this.defaultBodyMethod]()]; | ||
case 2: | ||
data = _a.sent(); | ||
if (item.body && item.body !== this.defaultBodyMethod) { | ||
return [2 /*return*/, data]; | ||
} | ||
audio = document.createElement("audio"); | ||
audio.autoplay = false; | ||
audio.preload = "auto"; | ||
audio.src = URL.createObjectURL(data); | ||
return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
audio.addEventListener("canplaythrough", function () { return resolve(audio); }, false); | ||
audio.addEventListener("error", reject, false); | ||
})]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Xml" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load (need a mimeType specified or default to "application/xml") | ||
* @returns {Promise<LoadedXMLValue>} Result of Response parsed as a document. | ||
*/ | ||
this.loadXml = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.text()]; | ||
case 2: | ||
data = _a.sent(); | ||
return [2 /*return*/, AsyncPreloader.domParser.parseFromString(data, item.mimeType)]; | ||
} | ||
}); | ||
}); }; | ||
this.loadFont = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var fontName, font; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
fontName = item.id || AsyncPreloader.getFileName(item.src); | ||
font = new FontFaceObserver(fontName, item.options || {}); | ||
return [4 /*yield*/, font.load()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, fontName]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
// Utils | ||
/** | ||
* Fetch wrapper for LoadItem | ||
* | ||
* @param {LoadItem} item Item to fetch | ||
* @returns {Promise<Response>} Fetch response | ||
*/ | ||
AsyncPreloader.fetchItem = function (item) { | ||
return fetch(item.src, item.options || {}); | ||
}; | ||
/** | ||
* Get file extension from path | ||
* | ||
* @param {(RequestInfo | USVString)} path | ||
* @returns {string} | ||
*/ | ||
AsyncPreloader.getFileExtension = function (path) { | ||
return (path.match(/[^\\\/]\.([^.\\\/]+)$/) || [null]).pop(); | ||
}; | ||
/** | ||
* Get file name from path | ||
* | ||
* @param {any} path | ||
* @returns {string} | ||
*/ | ||
AsyncPreloader.getFileName = function (path) { | ||
return path | ||
.replace(/^.*[\\\/]/, "") | ||
.split(".") | ||
.shift(); | ||
}; | ||
/** | ||
* Retrieve loader key from extension (when the loader option isn't specified in the LoadItem) | ||
* | ||
* @param {string} extension | ||
* @returns {LoaderKey} | ||
*/ | ||
AsyncPreloader.getLoaderKey = function (extension) { | ||
var loader = Array.from(AsyncPreloader.loaders).find(function (loader) { | ||
return loader[1].extensions.includes(extension); | ||
}); | ||
return loader ? loader[0] : LoaderKey.Text; | ||
}; | ||
/** | ||
* Loader types and the extensions they handle | ||
* | ||
* Allows the omission of the loader key in a [[LoadItem.loader]] for some generic extensions | ||
*/ | ||
AsyncPreloader.loaders = new Map() | ||
.set(LoaderKey.Text, { extensions: ["txt"] }) | ||
.set(LoaderKey.Json, { extensions: ["json"] }) | ||
.set(LoaderKey.Image, { extensions: ["jpeg", "jpg", "gif", "png", "webp"] }) | ||
.set(LoaderKey.Video, { extensions: ["webm", "ogg", "mp4"] }) | ||
.set(LoaderKey.Audio, { extensions: ["webm", "ogg", "mp3", "wav", "flac"] }) | ||
.set(LoaderKey.Xml, { | ||
extensions: ["xml", "svg", "html"], | ||
mimeType: { | ||
xml: "application/xml", | ||
svg: "image/svg+xml", | ||
html: "text/html" | ||
} | ||
}) | ||
.set(LoaderKey.Font, { | ||
extensions: ["woff2", "woff", "ttf", "otf", "eot"] | ||
}); | ||
/** | ||
* DOMParser instance for the XML loader | ||
*/ | ||
AsyncPreloader.domParser = new DOMParser(); | ||
return AsyncPreloader; | ||
}()); | ||
var AsyncPreloaderInstance = new AsyncPreloader(); | ||
/** | ||
* AsyncPreloader: assets preloader using ES2017 async/await and fetch. | ||
* | ||
* It exports an instance of itself as default so you can: | ||
* | ||
* ```js | ||
* import Preloader from "async-preloader"; | ||
* | ||
* await Preloader.loadItems([]); | ||
* ``` | ||
* | ||
* to use directly as a singleton or | ||
* | ||
* ```js | ||
* import { AsyncPreloader as Preloader } from "async-preloader"; | ||
* | ||
* const preloader = new Preloader(); | ||
* await preloader.loadItems([]); | ||
* ``` | ||
* if you need more than one instance. | ||
*/ | ||
var AsyncPreloader = /** @class */ (function () { | ||
function AsyncPreloader() { | ||
var _this = this; | ||
// Properties | ||
/** | ||
* Object that contains the loaded items | ||
*/ | ||
this.items = new Map(); | ||
/** | ||
* Default body method to be called on the Response from fetch if no body option is specified on the LoadItem | ||
*/ | ||
this.defaultBodyMethod = "blob"; | ||
/** | ||
* Default loader to use if no loader key is specified in the [[LoadItem]] or if the extension doesn't match any of the [[AsyncPreloader.loaders]] extensions | ||
*/ | ||
this.defaultLoader = LoaderKey.Text; | ||
// API | ||
/** | ||
* Load the specified manifest (array of items) | ||
* | ||
* @param {LoadItem[]} items Items to load | ||
* @returns {Promise<LoadedValue[]>} Resolve when all items are loaded, reject for any error | ||
*/ | ||
this.loadItems = function (items) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(items.map(this.loadItem))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load a single item | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Resolve when item is loaded, reject for any error | ||
*/ | ||
this.loadItem = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var extension, loaderKey, mimeType, loadedItem; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
extension = AsyncPreloader.getFileExtension(item.src); | ||
loaderKey = item.loader || AsyncPreloader.getLoaderKey(extension); | ||
if (loaderKey === "Xml" && !item.mimeType) { | ||
mimeType = AsyncPreloader.loaders.get(LoaderKey.Xml).mimeType[extension] || | ||
AsyncPreloader.loaders.get(LoaderKey.Xml).mimeType["svg"]; | ||
item = tslib_1.__assign({}, item, { mimeType: mimeType }); | ||
} | ||
return [4 /*yield*/, this["load" + loaderKey](item)]; | ||
case 1: | ||
loadedItem = _a.sent(); | ||
this.items.set(item.id || item.src, loadedItem); | ||
return [2 /*return*/, loadedItem]; | ||
} | ||
}); | ||
}); }; | ||
// Special loaders | ||
/** | ||
* Load a manifest of items | ||
* | ||
* @param {string} src Manifest src url | ||
* @param {string} [key="items"] Manifest key in the JSON object containing the array of LoadItem. Used by [lodash.get](https://lodash.com/docs/4.17.5#get). | ||
* @returns {Promise<LoadedValue[]>} | ||
*/ | ||
this.loadManifest = function (src, key) { | ||
if (key === void 0) { key = "items"; } | ||
return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var loadedManifest, items; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.loadJson({ | ||
src: src | ||
})]; | ||
case 1: | ||
loadedManifest = _a.sent(); | ||
items = get(loadedManifest, key); | ||
return [4 /*yield*/, this.loadItems(items)]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
// Text loaders | ||
/** | ||
* Load an item and parse the Response as text | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadText = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.text()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as json | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadJson = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.json()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as arrayBuffer | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadArrayBuffer = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.arrayBuffer()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as blob | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadBlob = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.blob()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item and parse the Response as formData | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response | ||
*/ | ||
this.loadFormData = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.formData()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
// Custom loaders | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Image" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLImageElement with a blob as src. | ||
*/ | ||
this.loadImage = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data, image; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response[item.body || this.defaultBodyMethod]()]; | ||
case 2: | ||
data = _a.sent(); | ||
if (item.body && item.body !== this.defaultBodyMethod) { | ||
return [2 /*return*/, data]; | ||
} | ||
image = new Image(); | ||
image.src = URL.createObjectURL(data); | ||
return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
image.addEventListener("load", function () { return resolve(image); }, false); | ||
image.addEventListener("error", reject, false); | ||
})]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Video" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLVideoElement with a blob as src. | ||
*/ | ||
this.loadVideo = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data, video; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response[item.body || this.defaultBodyMethod]()]; | ||
case 2: | ||
data = _a.sent(); | ||
if (item.body && item.body !== this.defaultBodyMethod) { | ||
return [2 /*return*/, data]; | ||
} | ||
video = document.createElement("video"); | ||
video.src = URL.createObjectURL(data); | ||
return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
video.addEventListener("canplaythrough", function () { return resolve(video); }, false); | ||
video.addEventListener("error", reject, false); | ||
})]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Audio" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load | ||
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLAudioElement with a blob as src. | ||
*/ | ||
this.loadAudio = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data, audio; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response[item.body || this.defaultBodyMethod]()]; | ||
case 2: | ||
data = _a.sent(); | ||
if (item.body && item.body !== this.defaultBodyMethod) { | ||
return [2 /*return*/, data]; | ||
} | ||
audio = document.createElement("audio"); | ||
audio.autoplay = false; | ||
audio.preload = "auto"; | ||
audio.src = URL.createObjectURL(data); | ||
return [4 /*yield*/, new Promise(function (resolve, reject) { | ||
audio.addEventListener("canplaythrough", function () { return resolve(audio); }, false); | ||
audio.addEventListener("error", reject, false); | ||
})]; | ||
case 3: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
/** | ||
* Load an item in one of the following cases: | ||
* - item's "loader" option set as "Xml" | ||
* - item's "src" option extensions matching the loaders Map | ||
* - direct call of the method | ||
* | ||
* @param {LoadItem} item Item to load (need a mimeType specified or default to "application/xml") | ||
* @returns {Promise<LoadedXMLValue>} Result of Response parsed as a document. | ||
*/ | ||
this.loadXml = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response, data; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, AsyncPreloader.fetchItem(item)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.text()]; | ||
case 2: | ||
data = _a.sent(); | ||
return [2 /*return*/, AsyncPreloader.domParser.parseFromString(data, item.mimeType)]; | ||
} | ||
}); | ||
}); }; | ||
this.loadFont = function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var fontName, font; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
fontName = item.id || AsyncPreloader.getFileName(item.src); | ||
font = new FontFaceObserver(fontName, item.options || {}); | ||
return [4 /*yield*/, font.load()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, fontName]; | ||
} | ||
}); | ||
}); }; | ||
} | ||
// Utils | ||
/** | ||
* Fetch wrapper for LoadItem | ||
* | ||
* @param {LoadItem} item Item to fetch | ||
* @returns {Promise<Response>} Fetch response | ||
*/ | ||
AsyncPreloader.fetchItem = function (item) { | ||
return fetch(item.src, item.options || {}); | ||
}; | ||
/** | ||
* Get file extension from path | ||
* | ||
* @param {(RequestInfo | USVString)} path | ||
* @returns {string} | ||
*/ | ||
AsyncPreloader.getFileExtension = function (path) { | ||
return (path.match(/[^\\\/]\.([^.\\\/]+)$/) || [null]).pop(); | ||
}; | ||
/** | ||
* Get file name from path | ||
* | ||
* @param {any} path | ||
* @returns {string} | ||
*/ | ||
AsyncPreloader.getFileName = function (path) { | ||
return path | ||
.replace(/^.*[\\\/]/, "") | ||
.split(".") | ||
.shift(); | ||
}; | ||
/** | ||
* Retrieve loader key from extension (when the loader option isn't specified in the LoadItem) | ||
* | ||
* @param {string} extension | ||
* @returns {LoaderKey} | ||
*/ | ||
AsyncPreloader.getLoaderKey = function (extension) { | ||
var loader = Array.from(AsyncPreloader.loaders).find(function (loader) { | ||
return loader[1].extensions.includes(extension); | ||
}); | ||
return loader ? loader[0] : LoaderKey.Text; | ||
}; | ||
/** | ||
* Loader types and the extensions they handle | ||
* | ||
* Allows the omission of the loader key in a [[LoadItem.loader]] for some generic extensions | ||
*/ | ||
AsyncPreloader.loaders = new Map() | ||
.set(LoaderKey.Text, { extensions: ["txt"] }) | ||
.set(LoaderKey.Json, { extensions: ["json"] }) | ||
.set(LoaderKey.Image, { extensions: ["jpeg", "jpg", "gif", "png", "webp"] }) | ||
.set(LoaderKey.Video, { extensions: ["webm", "ogg", "mp4"] }) | ||
.set(LoaderKey.Audio, { extensions: ["webm", "ogg", "mp3", "wav", "flac"] }) | ||
.set(LoaderKey.Xml, { | ||
extensions: ["xml", "svg", "html"], | ||
mimeType: { | ||
xml: "application/xml", | ||
svg: "image/svg+xml", | ||
html: "text/html" | ||
} | ||
}) | ||
.set(LoaderKey.Font, { | ||
extensions: ["woff2", "woff", "ttf", "otf", "eot"] | ||
}); | ||
/** | ||
* DOMParser instance for the XML loader | ||
*/ | ||
AsyncPreloader.domParser = new DOMParser(); | ||
return AsyncPreloader; | ||
}()); | ||
var AsyncPreloaderInstance = new AsyncPreloader(); | ||
exports.AsyncPreloader = AsyncPreloader; | ||
exports.default = AsyncPreloaderInstance; | ||
exports.AsyncPreloader = AsyncPreloader; | ||
exports.default = AsyncPreloaderInstance; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -70,6 +70,7 @@ import { __awaiter, __generator, __assign } from 'tslib'; | ||
value[symToStringTag] = undefined; | ||
var unmasked = true; | ||
} catch (e) {} | ||
var result = nativeObjectToString.call(value); | ||
{ | ||
if (unmasked) { | ||
if (isOwn) { | ||
@@ -76,0 +77,0 @@ value[symToStringTag] = tag; |
{ | ||
"name": "async-preloader", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Assets preloader using ES2017 async/await and fetch.", | ||
@@ -30,3 +30,3 @@ "main": "lib/async-preloader.js", | ||
"build": "rollup -c", | ||
"docs": "typedoc --out docs --mode modules --excludeExternals --includeDeclarations --module commonjs --theme default src", | ||
"docs": "typedoc --out docs --mode modules --excludeExternals --includeDeclarations --module commonjs --theme default src && echo '' > docs/.nojekyll", | ||
"test": "jest test/", | ||
@@ -78,5 +78,5 @@ "prepublishOnly": "npm run build && npm run docs" | ||
"fontfaceobserver": "^2.0.13", | ||
"lodash": "^4.17.5", | ||
"lodash-es": "^4.17.10", | ||
"tslib": "^1.9.0" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3100
4
110993
18
+ Addedlodash-es@^4.17.10
+ Addedlodash-es@4.17.21(transitive)
- Removedlodash@^4.17.5
- Removedlodash@4.17.21(transitive)