Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-preloader

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-preloader - npm Package Compare versions

Comparing version 4.2.0 to 4.2.1

2

lib/async-preloader.cjs.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var LoaderKey,tslib_1=require("tslib"),FontFaceObserver=require("fontfaceobserver-es");!function(e){e.Json="Json",e.ArrayBuffer="ArrayBuffer",e.Blob="Blob",e.FormData="FormData",e.Text="Text",e.Image="Image",e.Video="Video",e.Audio="Audio",e.Xml="Xml",e.Font="Font"}(LoaderKey||(LoaderKey={}));var AsyncPreloader=function(){function o(){var e=this;this.items=new Map,this.defaultBodyMethod="blob",this.defaultLoader=LoaderKey.Text,this.loadItems=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,Promise.all(t.map(this.loadItem))];case 1:return[2,e.sent()]}})})},this.loadItem=function(n){return tslib_1.__awaiter(e,void 0,void 0,function(){var t,r;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return t=o.getFileExtension(n.src),[4,this["load"+(n.loader||o.getLoaderKey(t))](n)];case 1:return r=e.sent(),this.items.set(n.id||n.src,r),[2,r]}})})},this.loadManifest=function(n,i){return void 0===i&&(i="items"),tslib_1.__awaiter(e,void 0,void 0,function(){var t,r;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,this.loadJson({src:n})];case 1:return t=e.sent(),r=o.getProp(t,i),[4,this.loadItems(r)];case 2:return[2,e.sent()]}})})},this.loadText=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent().text()];case 2:return[2,e.sent()]}})})},this.loadJson=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent().json()];case 2:return[2,e.sent()]}})})},this.loadArrayBuffer=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent().arrayBuffer()];case 2:return[2,e.sent()]}})})},this.loadBlob=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent().blob()];case 2:return[2,e.sent()]}})})},this.loadFormData=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent().formData()];case 2:return[2,e.sent()]}})})},this.loadImage=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){var r,n;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body?[2,r]:(n=new Image,[4,new Promise(function(e,t){n.addEventListener("load",function(){return e(n)},!1),n.addEventListener("error",t,!1),n.src=URL.createObjectURL(r)})]);case 3:return[2,e.sent()]}})})},this.loadVideo=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){var r,n;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body?[2,r]:(n=document.createElement("video"),[4,new Promise(function(e,t){n.addEventListener("canplaythrough",function(){return e(n)},!1),n.addEventListener("error",t,!1),n.src=URL.createObjectURL(r),n.load()})]);case 3:return[2,e.sent()]}})})},this.loadAudio=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){var r,n;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,o.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body?[2,r]:((n=document.createElement("audio")).autoplay=!1,n.preload="auto",[4,new Promise(function(e,t){n.addEventListener("canplaythrough",function(){return e(n)},!1),n.addEventListener("error",t,!1),n.src=URL.createObjectURL(r),n.load()})]);case 3:return[2,e.sent()]}})})},this.loadXml=function(n){return tslib_1.__awaiter(e,void 0,void 0,function(){var t,r;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return n.mimeType||(t=o.getFileExtension(n.src),n=tslib_1.__assign({},n,{mimeType:o.getMimeType(LoaderKey.Xml,t)})),[4,o.fetchItem(n)];case 1:return[4,e.sent().text()];case 2:return r=e.sent(),[2,o.domParser.parseFromString(r,n.mimeType)]}})})},this.loadFont=function(r){return tslib_1.__awaiter(e,void 0,void 0,function(){var t;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return t=r.id,[4,new FontFaceObserver(t,r.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return o.fetchItem=function(e){return fetch(e.src,e.options||{})},o.getProp=function(e,t){var r=Array.isArray(t)?t:t.split(".").filter(function(e){return e.length});return r.length?o.getProp(e[r.shift()],r):e},o.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},o.getLoaderKey=function(t){var e=Array.from(o.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:LoaderKey.Text},o.getMimeType=function(e,t){var r=o.loaders.get(e);return r.mimeType[t]||r.defaultMimeType},o.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"},defaultMimeType:"xml"}).set(LoaderKey.Font,{extensions:["woff2","woff","ttf","otf","eot"]}),o.domParser=new DOMParser,o}(),AsyncPreloaderInstance=new AsyncPreloader;exports.AsyncPreloader=AsyncPreloader,exports.default=AsyncPreloaderInstance;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var LoaderKey,tslib_1=require("tslib"),FontFaceObserver=require("fontfaceobserver-es");!function(e){e.Json="Json",e.ArrayBuffer="ArrayBuffer",e.Blob="Blob",e.FormData="FormData",e.Text="Text",e.Image="Image",e.Video="Video",e.Audio="Audio",e.Xml="Xml",e.Font="Font"}(LoaderKey||(LoaderKey={}));var AsyncPreloader=function(){function i(){var e=this;this.items=new Map,this.defaultBodyMethod="blob",this.defaultLoader=LoaderKey.Text,this.loadItems=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,Promise.all(t.map(this.loadItem))];case 1:return[2,e.sent()]}})})},this.loadItem=function(n){return tslib_1.__awaiter(e,void 0,void 0,function(){var t,r;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return t=i.getFileExtension(n.src),[4,this["load"+(n.loader||i.getLoaderKey(t))](n)];case 1:return r=e.sent(),this.items.set(n.id||n.src,r),[2,r]}})})},this.loadManifest=function(n,o){return void 0===o&&(o="items"),tslib_1.__awaiter(e,void 0,void 0,function(){var t,r;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,this.loadJson({src:n})];case 1:return t=e.sent(),r=i.getProp(t,o),[4,this.loadItems(r)];case 2:return[2,e.sent()]}})})},this.loadText=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().text()];case 2:return[2,e.sent()]}})})},this.loadJson=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().json()];case 2:return[2,e.sent()]}})})},this.loadArrayBuffer=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().arrayBuffer()];case 2:return[2,e.sent()]}})})},this.loadBlob=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().blob()];case 2:return[2,e.sent()]}})})},this.loadFormData=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().formData()];case 2:return[2,e.sent()]}})})},this.loadImage=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){var n,o;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body?[2,n]:(o=new Image,[4,new Promise(function(t,r){o.addEventListener("load",function e(){o.removeEventListener("load",e),t(o)}),o.addEventListener("error",function e(){o.removeEventListener("error",e),r(o)}),o.src=URL.createObjectURL(n)})]);case 3:return[2,e.sent()]}})})},this.loadVideo=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){var n,o;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body?[2,n]:(o=document.createElement("video"),[4,new Promise(function(t,r){o.addEventListener("canplaythrough",function e(){o.removeEventListener("canplaythrough",e),t(o)}),o.addEventListener("error",function e(){o.removeEventListener("error",e),r(o)});try{o.srcObject=n}catch(e){o.src=URL.createObjectURL(n)}o.load()})]);case 3:return[2,e.sent()]}})})},this.loadAudio=function(t){return tslib_1.__awaiter(e,void 0,void 0,function(){var n,o;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body?[2,n]:((o=document.createElement("audio")).autoplay=!1,o.preload="auto",[4,new Promise(function(t,r){o.addEventListener("canplaythrough",function e(){o.removeEventListener("canplaythrough",e),t(o)}),o.addEventListener("error",function e(){o.removeEventListener("error",e),r(o)});try{o.srcObject=n}catch(e){o.src=URL.createObjectURL(n)}o.load()})]);case 3:return[2,e.sent()]}})})},this.loadXml=function(n){return tslib_1.__awaiter(e,void 0,void 0,function(){var t,r;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return n.mimeType||(t=i.getFileExtension(n.src),n=tslib_1.__assign({},n,{mimeType:i.getMimeType(LoaderKey.Xml,t)})),[4,i.fetchItem(n)];case 1:return[4,e.sent().text()];case 2:return r=e.sent(),[2,i.domParser.parseFromString(r,n.mimeType)]}})})},this.loadFont=function(r){return tslib_1.__awaiter(e,void 0,void 0,function(){var t;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return t=r.id,[4,new FontFaceObserver(t,r.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return i.fetchItem=function(e){return fetch(e.src,e.options||{})},i.getProp=function(e,t){var r=Array.isArray(t)?t:t.split(".").filter(function(e){return e.length});return r.length?i.getProp(e[r.shift()],r):e},i.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},i.getLoaderKey=function(t){var e=Array.from(i.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:LoaderKey.Text},i.getMimeType=function(e,t){var r=i.loaders.get(e);return r.mimeType[t]||r.defaultMimeType},i.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"},defaultMimeType:"xml"}).set(LoaderKey.Font,{extensions:["woff2","woff","ttf","otf","eot"]}),i.domParser=new DOMParser,i}(),AsyncPreloaderInstance=new AsyncPreloader;exports.AsyncPreloader=AsyncPreloader,exports.default=AsyncPreloaderInstance;

@@ -219,3 +219,3 @@ import { __awaiter, __generator, __assign } from 'tslib';

* @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.
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLImageElement with a blob as srcObject or src.
*/

@@ -236,4 +236,10 @@ this.loadImage = function (item) { return __awaiter(_this, void 0, void 0, function () {

return [4 /*yield*/, new Promise(function (resolve, reject) {
image.addEventListener("load", function () { return resolve(image); }, false);
image.addEventListener("error", reject, false);
image.addEventListener("load", function load() {
image.removeEventListener("load", load);
resolve(image);
});
image.addEventListener("error", function error() {
image.removeEventListener("error", error);
reject(image);
});
image.src = URL.createObjectURL(data);

@@ -268,5 +274,16 @@ })];

return [4 /*yield*/, new Promise(function (resolve, reject) {
video.addEventListener("canplaythrough", function () { return resolve(video); }, false);
video.addEventListener("error", reject, false);
video.src = URL.createObjectURL(data);
video.addEventListener("canplaythrough", function canplaythrough() {
video.removeEventListener("canplaythrough", canplaythrough);
resolve(video);
});
video.addEventListener("error", function error() {
video.removeEventListener("error", error);
reject(video);
});
try {
video.srcObject = data;
}
catch (error) {
video.src = URL.createObjectURL(data);
}
video.load();

@@ -285,3 +302,3 @@ })];

* @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.
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLAudioElement with a blob as srcObject or src.
*/

@@ -304,5 +321,16 @@ this.loadAudio = function (item) { return __awaiter(_this, void 0, void 0, function () {

return [4 /*yield*/, new Promise(function (resolve, reject) {
audio.addEventListener("canplaythrough", function () { return resolve(audio); }, false);
audio.addEventListener("error", reject, false);
audio.src = URL.createObjectURL(data);
audio.addEventListener("canplaythrough", function canplaythrough() {
audio.removeEventListener("canplaythrough", canplaythrough);
resolve(audio);
});
audio.addEventListener("error", function error() {
audio.removeEventListener("error", error);
reject(audio);
});
try {
audio.srcObject = data;
}
catch (error) {
audio.src = URL.createObjectURL(data);
}
audio.load();

@@ -309,0 +337,0 @@ })];

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("fontfaceobserver-es")):"function"==typeof define&&define.amd?define(["exports","tslib","fontfaceobserver-es"],t):t(e.AsyncPreloader={},e.tslib,e.FontFaceObserver)}(this,function(e,s,r){"use strict";var o,t;(t=o||(o={})).Json="Json",t.ArrayBuffer="ArrayBuffer",t.Blob="Blob",t.FormData="FormData",t.Text="Text",t.Image="Image",t.Video="Video",t.Audio="Audio",t.Xml="Xml",t.Font="Font";var n=function(){function i(){var e=this;this.items=new Map,this.defaultBodyMethod="blob",this.defaultLoader=o.Text,this.loadItems=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,Promise.all(t.map(this.loadItem))];case 1:return[2,e.sent()]}})})},this.loadItem=function(r){return s.__awaiter(e,void 0,void 0,function(){var t,n;return s.__generator(this,function(e){switch(e.label){case 0:return t=i.getFileExtension(r.src),[4,this["load"+(r.loader||i.getLoaderKey(t))](r)];case 1:return n=e.sent(),this.items.set(r.id||r.src,n),[2,n]}})})},this.loadManifest=function(r,o){return void 0===o&&(o="items"),s.__awaiter(e,void 0,void 0,function(){var t,n;return s.__generator(this,function(e){switch(e.label){case 0:return[4,this.loadJson({src:r})];case 1:return t=e.sent(),n=i.getProp(t,o),[4,this.loadItems(n)];case 2:return[2,e.sent()]}})})},this.loadText=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().text()];case 2:return[2,e.sent()]}})})},this.loadJson=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().json()];case 2:return[2,e.sent()]}})})},this.loadArrayBuffer=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().arrayBuffer()];case 2:return[2,e.sent()]}})})},this.loadBlob=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().blob()];case 2:return[2,e.sent()]}})})},this.loadFormData=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().formData()];case 2:return[2,e.sent()]}})})},this.loadImage=function(t){return s.__awaiter(e,void 0,void 0,function(){var n,r;return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body?[2,n]:(r=new Image,[4,new Promise(function(e,t){r.addEventListener("load",function(){return e(r)},!1),r.addEventListener("error",t,!1),r.src=URL.createObjectURL(n)})]);case 3:return[2,e.sent()]}})})},this.loadVideo=function(t){return s.__awaiter(e,void 0,void 0,function(){var n,r;return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body?[2,n]:(r=document.createElement("video"),[4,new Promise(function(e,t){r.addEventListener("canplaythrough",function(){return e(r)},!1),r.addEventListener("error",t,!1),r.src=URL.createObjectURL(n),r.load()})]);case 3:return[2,e.sent()]}})})},this.loadAudio=function(t){return s.__awaiter(e,void 0,void 0,function(){var n,r;return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body?[2,n]:((r=document.createElement("audio")).autoplay=!1,r.preload="auto",[4,new Promise(function(e,t){r.addEventListener("canplaythrough",function(){return e(r)},!1),r.addEventListener("error",t,!1),r.src=URL.createObjectURL(n),r.load()})]);case 3:return[2,e.sent()]}})})},this.loadXml=function(r){return s.__awaiter(e,void 0,void 0,function(){var t,n;return s.__generator(this,function(e){switch(e.label){case 0:return r.mimeType||(t=i.getFileExtension(r.src),r=s.__assign({},r,{mimeType:i.getMimeType(o.Xml,t)})),[4,i.fetchItem(r)];case 1:return[4,e.sent().text()];case 2:return n=e.sent(),[2,i.domParser.parseFromString(n,r.mimeType)]}})})},this.loadFont=function(n){return s.__awaiter(e,void 0,void 0,function(){var t;return s.__generator(this,function(e){switch(e.label){case 0:return t=n.id,[4,new r(t,n.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return i.fetchItem=function(e){return fetch(e.src,e.options||{})},i.getProp=function(e,t){var n=Array.isArray(t)?t:t.split(".").filter(function(e){return e.length});return n.length?i.getProp(e[n.shift()],n):e},i.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},i.getLoaderKey=function(t){var e=Array.from(i.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:o.Text},i.getMimeType=function(e,t){var n=i.loaders.get(e);return n.mimeType[t]||n.defaultMimeType},i.loaders=(new Map).set(o.Text,{extensions:["txt"]}).set(o.Json,{extensions:["json"]}).set(o.Image,{extensions:["jpeg","jpg","gif","png","webp"]}).set(o.Video,{extensions:["webm","ogg","mp4"]}).set(o.Audio,{extensions:["webm","ogg","mp3","wav","flac"]}).set(o.Xml,{extensions:["xml","svg","html"],mimeType:{xml:"application/xml",svg:"image/svg+xml",html:"text/html"},defaultMimeType:"xml"}).set(o.Font,{extensions:["woff2","woff","ttf","otf","eot"]}),i.domParser=new DOMParser,i}(),i=new n;e.AsyncPreloader=n,e.default=i,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("fontfaceobserver-es")):"function"==typeof define&&define.amd?define(["exports","tslib","fontfaceobserver-es"],t):t((e=e||self).AsyncPreloader={},e.tslib,e.FontFaceObserver)}(this,function(e,s,r){"use strict";var o,t;(t=o||(o={})).Json="Json",t.ArrayBuffer="ArrayBuffer",t.Blob="Blob",t.FormData="FormData",t.Text="Text",t.Image="Image",t.Video="Video",t.Audio="Audio",t.Xml="Xml",t.Font="Font";var n=function(){function i(){var e=this;this.items=new Map,this.defaultBodyMethod="blob",this.defaultLoader=o.Text,this.loadItems=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,Promise.all(t.map(this.loadItem))];case 1:return[2,e.sent()]}})})},this.loadItem=function(r){return s.__awaiter(e,void 0,void 0,function(){var t,n;return s.__generator(this,function(e){switch(e.label){case 0:return t=i.getFileExtension(r.src),[4,this["load"+(r.loader||i.getLoaderKey(t))](r)];case 1:return n=e.sent(),this.items.set(r.id||r.src,n),[2,n]}})})},this.loadManifest=function(r,o){return void 0===o&&(o="items"),s.__awaiter(e,void 0,void 0,function(){var t,n;return s.__generator(this,function(e){switch(e.label){case 0:return[4,this.loadJson({src:r})];case 1:return t=e.sent(),n=i.getProp(t,o),[4,this.loadItems(n)];case 2:return[2,e.sent()]}})})},this.loadText=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().text()];case 2:return[2,e.sent()]}})})},this.loadJson=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().json()];case 2:return[2,e.sent()]}})})},this.loadArrayBuffer=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().arrayBuffer()];case 2:return[2,e.sent()]}})})},this.loadBlob=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().blob()];case 2:return[2,e.sent()]}})})},this.loadFormData=function(t){return s.__awaiter(e,void 0,void 0,function(){return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent().formData()];case 2:return[2,e.sent()]}})})},this.loadImage=function(t){return s.__awaiter(e,void 0,void 0,function(){var r,o;return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body?[2,r]:(o=new Image,[4,new Promise(function(t,n){o.addEventListener("load",function e(){o.removeEventListener("load",e),t(o)}),o.addEventListener("error",function e(){o.removeEventListener("error",e),n(o)}),o.src=URL.createObjectURL(r)})]);case 3:return[2,e.sent()]}})})},this.loadVideo=function(t){return s.__awaiter(e,void 0,void 0,function(){var r,o;return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body?[2,r]:(o=document.createElement("video"),[4,new Promise(function(t,n){o.addEventListener("canplaythrough",function e(){o.removeEventListener("canplaythrough",e),t(o)}),o.addEventListener("error",function e(){o.removeEventListener("error",e),n(o)});try{o.srcObject=r}catch(e){o.src=URL.createObjectURL(r)}o.load()})]);case 3:return[2,e.sent()]}})})},this.loadAudio=function(t){return s.__awaiter(e,void 0,void 0,function(){var r,o;return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body?[2,r]:((o=document.createElement("audio")).autoplay=!1,o.preload="auto",[4,new Promise(function(t,n){o.addEventListener("canplaythrough",function e(){o.removeEventListener("canplaythrough",e),t(o)}),o.addEventListener("error",function e(){o.removeEventListener("error",e),n(o)});try{o.srcObject=r}catch(e){o.src=URL.createObjectURL(r)}o.load()})]);case 3:return[2,e.sent()]}})})},this.loadXml=function(r){return s.__awaiter(e,void 0,void 0,function(){var t,n;return s.__generator(this,function(e){switch(e.label){case 0:return r.mimeType||(t=i.getFileExtension(r.src),r=s.__assign({},r,{mimeType:i.getMimeType(o.Xml,t)})),[4,i.fetchItem(r)];case 1:return[4,e.sent().text()];case 2:return n=e.sent(),[2,i.domParser.parseFromString(n,r.mimeType)]}})})},this.loadFont=function(n){return s.__awaiter(e,void 0,void 0,function(){var t;return s.__generator(this,function(e){switch(e.label){case 0:return t=n.id,[4,new r(t,n.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return i.fetchItem=function(e){return fetch(e.src,e.options||{})},i.getProp=function(e,t){var n=Array.isArray(t)?t:t.split(".").filter(function(e){return e.length});return n.length?i.getProp(e[n.shift()],n):e},i.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},i.getLoaderKey=function(t){var e=Array.from(i.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:o.Text},i.getMimeType=function(e,t){var n=i.loaders.get(e);return n.mimeType[t]||n.defaultMimeType},i.loaders=(new Map).set(o.Text,{extensions:["txt"]}).set(o.Json,{extensions:["json"]}).set(o.Image,{extensions:["jpeg","jpg","gif","png","webp"]}).set(o.Video,{extensions:["webm","ogg","mp4"]}).set(o.Audio,{extensions:["webm","ogg","mp3","wav","flac"]}).set(o.Xml,{extensions:["xml","svg","html"],mimeType:{xml:"application/xml",svg:"image/svg+xml",html:"text/html"},defaultMimeType:"xml"}).set(o.Font,{extensions:["woff2","woff","ttf","otf","eot"]}),i.domParser=new DOMParser,i}(),i=new n;e.AsyncPreloader=n,e.default=i,Object.defineProperty(e,"__esModule",{value:!0})});

@@ -110,3 +110,3 @@ import { BodyMethod, LoadItem, LoadedValue, LoadedXMLValue, LoaderKey } from "./types";

* @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.
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLImageElement with a blob as srcObject or src.
*/

@@ -131,3 +131,3 @@ loadImage: (item: LoadItem) => Promise<LoadedValue>;

* @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.
* @returns {Promise<LoadedValue>} Fulfilled value of parsed Response according to the "body" option. Defaults to an HTMLAudioElement with a blob as srcObject or src.
*/

@@ -134,0 +134,0 @@ loadAudio: (item: LoadItem) => Promise<LoadedValue>;

{
"name": "async-preloader",
"version": "4.2.0",
"version": "4.2.1",
"description": "Assets preloader using ES2017 async/await and fetch.",

@@ -65,12 +65,12 @@ "main": "lib/async-preloader.cjs.js",

"devDependencies": {
"@types/jest": "^23.3.5",
"@types/node": "^10.12.0",
"@types/jest": "^23.3.9",
"@types/node": "^10.12.5",
"jest": "^23.6.0",
"jsdom": "^12.2.0",
"node-fetch": "^2.2.0",
"prettier": "^1.14.3",
"rollup": "^0.66.6",
"jsdom": "^13.0.0",
"node-fetch": "^2.2.1",
"prettier": "^1.15.1",
"rollup": "^0.67.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-typescript2": "^0.17.1",
"rollup-plugin-typescript2": "^0.17.2",
"rollup-plugin-uglify": "^6.0.0",

@@ -80,3 +80,3 @@ "ts-jest": "^23.10.4",

"typedoc": "^0.13.0",
"typescript": "^3.1.3",
"typescript": "^3.1.6",
"xmldom": "^0.1.27"

@@ -83,0 +83,0 @@ },

@@ -6,3 +6,3 @@ # async-preloader

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest) [![Greenkeeper badge](https://badges.greenkeeper.io/dmnsgn/async-preloader.svg)](https://greenkeeper.io/)

@@ -9,0 +9,0 @@ > Assets preloader using ES2017 async/await and fetch.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc