async-preloader
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -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 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 r,n;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 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,i.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,i.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(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; | ||
"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 r,n;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 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,i.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),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,i.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("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=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; |
@@ -271,2 +271,3 @@ import { __awaiter, __generator, __assign } from 'tslib'; | ||
video.src = URL.createObjectURL(data); | ||
video.load(); | ||
})]; | ||
@@ -302,6 +303,7 @@ case 3: return [2 /*return*/, _a.sent()]; | ||
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); | ||
audio.src = URL.createObjectURL(data); | ||
audio.load(); | ||
})]; | ||
@@ -390,3 +392,3 @@ case 3: return [2 /*return*/, _a.sent()]; | ||
* | ||
* @param {(RequestInfo | USVString)} path | ||
* @param {(RequestInfo | string)} path | ||
* @returns {string} | ||
@@ -393,0 +395,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&&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 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&&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 s.__awaiter(e,void 0,void 0,function(){var t,n;return s.__generator(this,function(e){switch(e.label){case 0:return[4,i.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(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.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&&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 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&&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),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&&t.body!==this.defaultBodyMethod?[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})}); |
@@ -169,3 +169,3 @@ import { BodyMethod, LoadItem, LoadedValue, LoadedXMLValue, LoaderKey } from "./types"; | ||
* | ||
* @param {(RequestInfo | USVString)} path | ||
* @param {(RequestInfo | string)} path | ||
* @returns {string} | ||
@@ -172,0 +172,0 @@ */ |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
export declare type BodyResolveValue = ArrayBuffer | Blob | FormData | JSON | USVString; | ||
export declare type BodyResolveValue = ArrayBuffer | Blob | FormData | JSON | string; | ||
/** | ||
@@ -25,3 +25,3 @@ * Types that can be returned by the Xml loader. See the [[LoadItem.mimeType]]. | ||
*/ | ||
src: RequestInfo | USVString; | ||
src: RequestInfo | string; | ||
/** | ||
@@ -57,3 +57,3 @@ * Optional key. | ||
*/ | ||
mimeType?: string; | ||
mimeType?: SupportedType; | ||
} | ||
@@ -89,3 +89,3 @@ /** | ||
mimeType?: { | ||
[key: string]: string; | ||
[key: string]: SupportedType; | ||
}; | ||
@@ -97,3 +97,3 @@ /** | ||
*/ | ||
defaultMimeType?: string; | ||
defaultMimeType?: SupportedType; | ||
} |
{ | ||
"name": "async-preloader", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "Assets preloader using ES2017 async/await and fetch.", | ||
@@ -65,17 +65,17 @@ "main": "lib/async-preloader.cjs.js", | ||
"devDependencies": { | ||
"@types/jest": "^23.3.2", | ||
"@types/node": "^10.9.4", | ||
"@types/jest": "^23.3.5", | ||
"@types/node": "^10.12.0", | ||
"jest": "^23.6.0", | ||
"jsdom": "^12.0.0", | ||
"jsdom": "^12.2.0", | ||
"node-fetch": "^2.2.0", | ||
"prettier": "^1.14.2", | ||
"rollup": "^0.65.2", | ||
"rollup-plugin-commonjs": "^9.1.6", | ||
"prettier": "^1.14.3", | ||
"rollup": "^0.66.6", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-typescript2": "^0.17.0", | ||
"rollup-plugin-uglify": "^5.0.2", | ||
"ts-jest": "^23.1.4", | ||
"rollup-plugin-typescript2": "^0.17.1", | ||
"rollup-plugin-uglify": "^6.0.0", | ||
"ts-jest": "^23.10.4", | ||
"tslint": "^5.11.0", | ||
"typedoc": "^0.12.0", | ||
"typescript": "^3.0.3", | ||
"typedoc": "^0.13.0", | ||
"typescript": "^3.1.3", | ||
"xmldom": "^0.1.27" | ||
@@ -82,0 +82,0 @@ }, |
50836
779