async-preloader
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var LoaderKey,tslib_1=require("tslib"),FontFaceObserver=_interopDefault(require("fontfaceobserver-es")),get=_interopDefault(require("lodash-es/get"));!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 s(){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(i){return tslib_1.__awaiter(e,void 0,void 0,function(){var t,r,n,o;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return t=s.getFileExtension(i.src),"Xml"!==(r=i.loader||s.getLoaderKey(t))||i.mimeType||(n=s.loaders.get(LoaderKey.Xml).mimeType[t]||s.loaders.get(LoaderKey.Xml).mimeType.svg,i=tslib_1.__assign({},i,{mimeType:n})),[4,this["load"+r](i)];case 1:return o=e.sent(),this.items.set(i.id||i.src,o),[2,o]}})})},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=get(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,s.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,s.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,s.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,s.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,s.fetchItem(t)];case 1:return[4,e.sent().formData()];case 2:return[2,e.sent()]}})})},this.loadImage=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[4,s.fetchItem(n)];case 1:return[4,e.sent()[n.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),n.body&&n.body!==this.defaultBodyMethod?[2,t]:((r=new Image).src=URL.createObjectURL(t),[4,new Promise(function(e,t){r.addEventListener("load",function(){return e(r)},!1),r.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadVideo=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[4,s.fetchItem(n)];case 1:return[4,e.sent()[n.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),n.body&&n.body!==this.defaultBodyMethod?[2,t]:((r=document.createElement("video")).src=URL.createObjectURL(t),[4,new Promise(function(e,t){r.addEventListener("canplaythrough",function(){return e(r)},!1),r.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadAudio=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[4,s.fetchItem(n)];case 1:return[4,e.sent()[n.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),n.body&&n.body!==this.defaultBodyMethod?[2,t]:((r=document.createElement("audio")).autoplay=!1,r.preload="auto",r.src=URL.createObjectURL(t),[4,new Promise(function(e,t){r.addEventListener("canplaythrough",function(){return e(r)},!1),r.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadXml=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[4,s.fetchItem(r)];case 1:return[4,e.sent().text()];case 2:return t=e.sent(),[2,s.domParser.parseFromString(t,r.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||s.getFileName(r.src),[4,new FontFaceObserver(t,r.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return s.fetchItem=function(e){return fetch(e.src,e.options||{})},s.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},s.getFileName=function(e){return e.replace(/^.*[\\\/]/,"").split(".").shift()},s.getLoaderKey=function(t){var e=Array.from(s.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:LoaderKey.Text},s.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"]}),s.domParser=new DOMParser,s}(),AsyncPreloaderInstance=new AsyncPreloader;exports.AsyncPreloader=AsyncPreloader,exports.default=AsyncPreloaderInstance; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var LoaderKey,tslib_1=require("tslib"),FontFaceObserver=_interopDefault(require("fontfaceobserver-es")),get=_interopDefault(require("lodash-es/get"));!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 s(){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(i){return tslib_1.__awaiter(e,void 0,void 0,function(){var t,r,n,o;return tslib_1.__generator(this,function(e){switch(e.label){case 0:return t=s.getFileExtension(i.src),"Xml"!==(r=i.loader||s.getLoaderKey(t))||i.mimeType||(n=s.loaders.get(LoaderKey.Xml).mimeType[t]||s.loaders.get(LoaderKey.Xml).mimeType.svg,i=tslib_1.__assign({},i,{mimeType:n})),[4,this["load"+r](i)];case 1:return o=e.sent(),this.items.set(i.id||i.src,o),[2,o]}})})},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=get(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,s.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,s.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,s.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,s.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,s.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,s.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body&&t.body!==this.defaultBodyMethod?[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,s.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return r=e.sent(),t.body&&t.body!==this.defaultBodyMethod?[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)})]);case 3:return[2,e.sent()]}})})},this.loadAudio=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[4,s.fetchItem(n)];case 1:return[4,e.sent()[n.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),n.body&&n.body!==this.defaultBodyMethod?[2,t]:((r=document.createElement("audio")).autoplay=!1,r.preload="auto",r.src=URL.createObjectURL(t),[4,new Promise(function(e,t){r.addEventListener("canplaythrough",function(){return e(r)},!1),r.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadXml=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[4,s.fetchItem(r)];case 1:return[4,e.sent().text()];case 2:return t=e.sent(),[2,s.domParser.parseFromString(t,r.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||s.getFileName(r.src),[4,new FontFaceObserver(t,r.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return s.fetchItem=function(e){return fetch(e.src,e.options||{})},s.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},s.getFileName=function(e){return e.replace(/^.*[\\\/]/,"").split(".").shift()},s.getLoaderKey=function(t){var e=Array.from(s.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:LoaderKey.Text},s.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"]}),s.domParser=new DOMParser,s}(),AsyncPreloaderInstance=new AsyncPreloader;exports.AsyncPreloader=AsyncPreloader,exports.default=AsyncPreloaderInstance; |
@@ -241,6 +241,6 @@ import { __awaiter, __generator, __assign } from 'tslib'; | ||
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); | ||
image.src = URL.createObjectURL(data); | ||
})]; | ||
@@ -274,6 +274,6 @@ case 3: return [2 /*return*/, _a.sent()]; | ||
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); | ||
video.src = URL.createObjectURL(data); | ||
})]; | ||
@@ -280,0 +280,0 @@ case 3: return [2 /*return*/, _a.sent()]; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("fontfaceobserver-es"),require("lodash-es/get")):"function"==typeof define&&define.amd?define(["exports","tslib","fontfaceobserver-es","lodash-es/get"],t):t(e.AsyncPreloader={},e.tslib,e.FontFaceObserver,e._.get)}(this,function(e,a,r,i){"use strict";var u,t;r=r&&r.hasOwnProperty("default")?r.default:r,i=i&&i.hasOwnProperty("default")?i.default:i,(t=u||(u={})).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 s(){var e=this;this.items=new Map,this.defaultBodyMethod="blob",this.defaultLoader=u.Text,this.loadItems=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__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(i){return a.__awaiter(e,void 0,void 0,function(){var t,n,r,o;return a.__generator(this,function(e){switch(e.label){case 0:return t=s.getFileExtension(i.src),"Xml"!==(n=i.loader||s.getLoaderKey(t))||i.mimeType||(r=s.loaders.get(u.Xml).mimeType[t]||s.loaders.get(u.Xml).mimeType.svg,i=a.__assign({},i,{mimeType:r})),[4,this["load"+n](i)];case 1:return o=e.sent(),this.items.set(i.id||i.src,o),[2,o]}})})},this.loadManifest=function(r,o){return void 0===o&&(o="items"),a.__awaiter(e,void 0,void 0,function(){var t,n;return a.__generator(this,function(e){switch(e.label){case 0:return[4,this.loadJson({src:r})];case 1:return t=e.sent(),n=i(t,o),[4,this.loadItems(n)];case 2:return[2,e.sent()]}})})},this.loadText=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().text()];case 2:return[2,e.sent()]}})})},this.loadJson=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().json()];case 2:return[2,e.sent()]}})})},this.loadArrayBuffer=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().arrayBuffer()];case 2:return[2,e.sent()]}})})},this.loadBlob=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().blob()];case 2:return[2,e.sent()]}})})},this.loadFormData=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().formData()];case 2:return[2,e.sent()]}})})},this.loadImage=function(r){return a.__awaiter(e,void 0,void 0,function(){var t,n;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(r)];case 1:return[4,e.sent()[r.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),r.body&&r.body!==this.defaultBodyMethod?[2,t]:((n=new Image).src=URL.createObjectURL(t),[4,new Promise(function(e,t){n.addEventListener("load",function(){return e(n)},!1),n.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadVideo=function(r){return a.__awaiter(e,void 0,void 0,function(){var t,n;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(r)];case 1:return[4,e.sent()[r.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),r.body&&r.body!==this.defaultBodyMethod?[2,t]:((n=document.createElement("video")).src=URL.createObjectURL(t),[4,new Promise(function(e,t){n.addEventListener("canplaythrough",function(){return e(n)},!1),n.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadAudio=function(r){return a.__awaiter(e,void 0,void 0,function(){var t,n;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(r)];case 1:return[4,e.sent()[r.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),r.body&&r.body!==this.defaultBodyMethod?[2,t]:((n=document.createElement("audio")).autoplay=!1,n.preload="auto",n.src=URL.createObjectURL(t),[4,new Promise(function(e,t){n.addEventListener("canplaythrough",function(){return e(n)},!1),n.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadXml=function(n){return a.__awaiter(e,void 0,void 0,function(){var t;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(n)];case 1:return[4,e.sent().text()];case 2:return t=e.sent(),[2,s.domParser.parseFromString(t,n.mimeType)]}})})},this.loadFont=function(n){return a.__awaiter(e,void 0,void 0,function(){var t;return a.__generator(this,function(e){switch(e.label){case 0:return t=n.id||s.getFileName(n.src),[4,new r(t,n.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return s.fetchItem=function(e){return fetch(e.src,e.options||{})},s.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},s.getFileName=function(e){return e.replace(/^.*[\\\/]/,"").split(".").shift()},s.getLoaderKey=function(t){var e=Array.from(s.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:u.Text},s.loaders=(new Map).set(u.Text,{extensions:["txt"]}).set(u.Json,{extensions:["json"]}).set(u.Image,{extensions:["jpeg","jpg","gif","png","webp"]}).set(u.Video,{extensions:["webm","ogg","mp4"]}).set(u.Audio,{extensions:["webm","ogg","mp3","wav","flac"]}).set(u.Xml,{extensions:["xml","svg","html"],mimeType:{xml:"application/xml",svg:"image/svg+xml",html:"text/html"}}).set(u.Font,{extensions:["woff2","woff","ttf","otf","eot"]}),s.domParser=new DOMParser,s}(),o=new n;e.AsyncPreloader=n,e.default=o,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("fontfaceobserver-es"),require("lodash-es/get")):"function"==typeof define&&define.amd?define(["exports","tslib","fontfaceobserver-es","lodash-es/get"],t):t(e.AsyncPreloader={},e.tslib,e.FontFaceObserver,e._.get)}(this,function(e,a,r,i){"use strict";var u,t;r=r&&r.hasOwnProperty("default")?r.default:r,i=i&&i.hasOwnProperty("default")?i.default:i,(t=u||(u={})).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 s(){var e=this;this.items=new Map,this.defaultBodyMethod="blob",this.defaultLoader=u.Text,this.loadItems=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__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(i){return a.__awaiter(e,void 0,void 0,function(){var t,n,r,o;return a.__generator(this,function(e){switch(e.label){case 0:return t=s.getFileExtension(i.src),"Xml"!==(n=i.loader||s.getLoaderKey(t))||i.mimeType||(r=s.loaders.get(u.Xml).mimeType[t]||s.loaders.get(u.Xml).mimeType.svg,i=a.__assign({},i,{mimeType:r})),[4,this["load"+n](i)];case 1:return o=e.sent(),this.items.set(i.id||i.src,o),[2,o]}})})},this.loadManifest=function(r,o){return void 0===o&&(o="items"),a.__awaiter(e,void 0,void 0,function(){var t,n;return a.__generator(this,function(e){switch(e.label){case 0:return[4,this.loadJson({src:r})];case 1:return t=e.sent(),n=i(t,o),[4,this.loadItems(n)];case 2:return[2,e.sent()]}})})},this.loadText=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().text()];case 2:return[2,e.sent()]}})})},this.loadJson=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().json()];case 2:return[2,e.sent()]}})})},this.loadArrayBuffer=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().arrayBuffer()];case 2:return[2,e.sent()]}})})},this.loadBlob=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().blob()];case 2:return[2,e.sent()]}})})},this.loadFormData=function(t){return a.__awaiter(e,void 0,void 0,function(){return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent().formData()];case 2:return[2,e.sent()]}})})},this.loadImage=function(t){return a.__awaiter(e,void 0,void 0,function(){var n,r;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body&&t.body!==this.defaultBodyMethod?[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 a.__awaiter(e,void 0,void 0,function(){var n,r;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(t)];case 1:return[4,e.sent()[t.body||this.defaultBodyMethod]()];case 2:return n=e.sent(),t.body&&t.body!==this.defaultBodyMethod?[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)})]);case 3:return[2,e.sent()]}})})},this.loadAudio=function(r){return a.__awaiter(e,void 0,void 0,function(){var t,n;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(r)];case 1:return[4,e.sent()[r.body||this.defaultBodyMethod]()];case 2:return t=e.sent(),r.body&&r.body!==this.defaultBodyMethod?[2,t]:((n=document.createElement("audio")).autoplay=!1,n.preload="auto",n.src=URL.createObjectURL(t),[4,new Promise(function(e,t){n.addEventListener("canplaythrough",function(){return e(n)},!1),n.addEventListener("error",t,!1)})]);case 3:return[2,e.sent()]}})})},this.loadXml=function(n){return a.__awaiter(e,void 0,void 0,function(){var t;return a.__generator(this,function(e){switch(e.label){case 0:return[4,s.fetchItem(n)];case 1:return[4,e.sent().text()];case 2:return t=e.sent(),[2,s.domParser.parseFromString(t,n.mimeType)]}})})},this.loadFont=function(n){return a.__awaiter(e,void 0,void 0,function(){var t;return a.__generator(this,function(e){switch(e.label){case 0:return t=n.id||s.getFileName(n.src),[4,new r(t,n.options||{}).load()];case 1:return e.sent(),[2,t]}})})}}return s.fetchItem=function(e){return fetch(e.src,e.options||{})},s.getFileExtension=function(e){return(e.match(/[^\\\/]\.([^.\\\/]+)$/)||[null]).pop()},s.getFileName=function(e){return e.replace(/^.*[\\\/]/,"").split(".").shift()},s.getLoaderKey=function(t){var e=Array.from(s.loaders).find(function(e){return e[1].extensions.includes(t)});return e?e[0]:u.Text},s.loaders=(new Map).set(u.Text,{extensions:["txt"]}).set(u.Json,{extensions:["json"]}).set(u.Image,{extensions:["jpeg","jpg","gif","png","webp"]}).set(u.Video,{extensions:["webm","ogg","mp4"]}).set(u.Audio,{extensions:["webm","ogg","mp3","wav","flac"]}).set(u.Xml,{extensions:["xml","svg","html"],mimeType:{xml:"application/xml",svg:"image/svg+xml",html:"text/html"}}).set(u.Font,{extensions:["woff2","woff","ttf","otf","eot"]}),s.domParser=new DOMParser,s}(),o=new n;e.AsyncPreloader=n,e.default=o,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "async-preloader", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Assets preloader using ES2017 async/await and fetch.", | ||
@@ -31,7 +31,7 @@ "main": "lib/async-preloader.cjs.js", | ||
"build": "rollup -c --environment NODE_ENV:production", | ||
"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 && touch docs/.nojekyll", | ||
"test": "jest test/", | ||
"preversion": "npm run clean && npm run test", | ||
"version": "npm run build && npm run docs && git add -A", | ||
"postversion": "git push && git push --tags && npm publish" | ||
"postversion": "git push origin master && git push --tags && npm publish" | ||
}, | ||
@@ -38,0 +38,0 @@ "jest": { |
@@ -23,3 +23,3 @@ # async-preloader | ||
This section covers the basic usage of `AsyncPreloader`. | ||
This section covers the basic usage of `AsyncPreloader`. For more informations about async/await, see [Async functions - making promises friendly](https://developers.google.com/web/fundamentals/primers/async-functions). | ||
@@ -133,18 +133,24 @@ ### Preload items and retrieve them | ||
async () => { | ||
let loadedCount = 0; | ||
async function preload() { | ||
await Promise.all( | ||
items.map(async item => { | ||
const data = await Preloader.loadItem(item); | ||
loadedCount++; | ||
console.log(`Progress: ${100 * loadedCount / items.length}%`); | ||
}) | ||
); | ||
} | ||
await preload(); | ||
(async () => { | ||
let loadedCount = 0; | ||
async function preload() { | ||
await Promise.all( | ||
items.map(async item => { | ||
const data = await AsyncPreloader.loadItem(item); | ||
loadedCount++; | ||
console.log(`Progress: ${100 * loadedCount / items.length}%`); | ||
}) | ||
); | ||
} | ||
await preload(); | ||
})() | ||
``` | ||
--- | ||
Note: the example above uses the async functions (which is the core of this module). You'll need to transpile it if you are targetting older browsers (namely IE11). See support [here](https://caniuse.com/#feat=async-functions). | ||
## License | ||
MIT © [Damien Seguin](https://github.com/dmnsgn) |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
8646945
29
1120
155
3
5