diff --git a/dist/imagepack.js b/dist/imagepack.js index d2eea6e..8a37925 100644 --- a/dist/imagepack.js +++ b/dist/imagepack.js @@ -97,8 +97,8 @@ function Imagepack(options) { function load(path) { var request = new XMLHttpRequest(); - request.responseType = 'arraybuffer'; request.open('GET', path, true); + request.responseType = 'arraybuffer'; request.addEventListener('load', function() { if (request.status < 400) { decode(request.response); @@ -527,4 +527,4 @@ module.exports = Emitter; },{"events":2}]},{},[1])(1) }); -//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvaW1hZ2VwYWNrLmpzIiwibm9kZV9tb2R1bGVzL2V2ZW50cy9ldmVudHMuanMiLCJzcmMvZW1pdHRlci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7Q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lbmVycygpO1xufTtcblxubW9kdWxlLmV4cG9ydHMgPSBFbWl0dGVyO1xuIl19 diff --git a/dist/imagepack.min.js b/dist/imagepack.min.js index 5ea544e..be2832e 100644 --- a/dist/imagepack.min.js +++ b/dist/imagepack.min.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Imagepack=e()}}(function(){return function e(t,r,n){function s(o,a){if(!r[o]){if(!t[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var h=r[o]={exports:{}};t[o][0].call(h.exports,function(e){var r=t[o][1][e];return s(r?r:e)},h,h.exports,e,t,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o Unpacked",t,"image/"+r.type,n)}l[t]=r}function r(e){return e.replace(/\0/g,"")}function n(e){var t=String.fromCharCode.apply(null,new Uint8Array(e));return r(t)}function i(e){var t=new Image,r=function(){t.removeEventListener("load",r),URL.revokeObjectURL(t.src),t=null};return t.addEventListener("load",r),t.src=o(e),t}function o(e){var t=l[e];if(!t)throw new Error("[ERROR] Imagepack "+e+" not found");var r=new Blob([new Uint8Array(t.contents)],{type:"image/"+t.type});return URL.createObjectURL(r)}function a(){return Object.keys(l)}function u(r){for(var s=new DataView(r),i=128,o=4,u=8,f=0;f Unpacked "+a().length+" images"),v.emit("complete",a())}function f(t){var r=new XMLHttpRequest;r.responseType="arraybuffer",r.open("GET",t,!0),r.addEventListener("load",function(){r.status<400?u(r.response):n()}),r.addEventListener("progress",function(e){e.lengthComputable&&v.emit("progress",e.loaded/e.total)});var n=function(){var t="[ERROR] imagepack "+r.status+" "+e.path;if(!v.listeners("error").length)throw new Error(t);v.emit("error",t)};return r.addEventListener("error",n),r.send(),v}function h(){return l={},v}window.Blob&&window.DataView||console.warn("Imagepack --> Unspported browser");var v,l={};return v=Object.create(s.prototype,{_events:{value:{}},load:{value:f},getURI:{value:o},getImage:{value:i},getKeys:{value:a},destroy:{value:h}}),Object.freeze(v)}var s=e("./emitter.js");if(!ArrayBuffer.prototype.slice){var i=ArrayBuffer.prototype;i.slice=function(e,t){if(void 0===e&&(e=0),void 0===t&&(t=this.byteLength),e=Math.floor(e),t=Math.floor(t),0>e&&(e+=this.byteLength),0>t&&(t+=this.byteLength),e=Math.min(Math.max(0,e),this.byteLength),t=Math.min(Math.max(0,t),this.byteLength),0>=t-e)return new ArrayBuffer(0);var r=new ArrayBuffer(t-e),n=new Uint8Array(r),s=new Uint8Array(this,e,t-e);return n.set(s),r}}"object"==typeof t&&t.exports&&(t.exports=n)},{"./emitter.js":3}],2:[function(e,t,r){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function s(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,r,n,i,u,f;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[e],a(r))return!1;if(s(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,i=new Array(n-1),u=1;n>u;u++)i[u-1]=arguments[u];r.apply(this,i)}else if(o(r)){for(n=arguments.length,i=new Array(n-1),u=1;n>u;u++)i[u-1]=arguments[u];for(f=r.slice(),n=f.length,u=0;n>u;u++)f[u].apply(this,i)}return!0},n.prototype.addListener=function(e,t){var r;if(!s(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,s(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned){var r;r=a(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function r(){this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}if(!s(t))throw TypeError("listener must be a function");var n=!1;return r.listener=t,this.on(e,r),this},n.prototype.removeListener=function(e,t){var r,n,i,a;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],i=r.length,n=-1,r===t||s(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(r)){for(a=i;a-->0;)if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}if(0>n)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],s(r))this.removeListener(e,r);else for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?s(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var r;return r=e._events&&e._events[t]?s(e._events[t])?1:e._events[t].length:0}},{}],3:[function(e,t,r){"use strict";function n(){s.call(this),this.setMaxListeners(20)}var s=e("events").EventEmitter;n.prototype=Object.create(s.prototype),n.prototype.constructor=n,n.prototype.off=function(e,t){return t?this.removeListener(e,t):e?this.removeAllListeners(e):this.removeAllListeners()},t.exports=n},{events:2}]},{},[1])(1)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Imagepack=e()}}(function(){return function e(t,r,n){function s(o,a){if(!r[o]){if(!t[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var h=r[o]={exports:{}};t[o][0].call(h.exports,function(e){var r=t[o][1][e];return s(r?r:e)},h,h.exports,e,t,r,n)}return r[o].exports}for(var i="function"==typeof require&&require,o=0;o Unpacked",t,"image/"+r.type,n)}l[t]=r}function r(e){return e.replace(/\0/g,"")}function n(e){var t=String.fromCharCode.apply(null,new Uint8Array(e));return r(t)}function i(e){var t=new Image,r=function(){t.removeEventListener("load",r),URL.revokeObjectURL(t.src),t=null};return t.addEventListener("load",r),t.src=o(e),t}function o(e){var t=l[e];if(!t)throw new Error("[ERROR] Imagepack "+e+" not found");var r=new Blob([new Uint8Array(t.contents)],{type:"image/"+t.type});return URL.createObjectURL(r)}function a(){return Object.keys(l)}function u(r){for(var s=new DataView(r),i=128,o=4,u=8,f=0;f Unpacked "+a().length+" images"),v.emit("complete",a())}function f(t){var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.addEventListener("load",function(){r.status<400?u(r.response):n()}),r.addEventListener("progress",function(e){e.lengthComputable&&v.emit("progress",e.loaded/e.total)});var n=function(){var t="[ERROR] imagepack "+r.status+" "+e.path;if(!v.listeners("error").length)throw new Error(t);v.emit("error",t)};return r.addEventListener("error",n),r.send(),v}function h(){return l={},v}window.Blob&&window.DataView||console.warn("Imagepack --> Unspported browser");var v,l={};return v=Object.create(s.prototype,{_events:{value:{}},load:{value:f},getURI:{value:o},getImage:{value:i},getKeys:{value:a},destroy:{value:h}}),Object.freeze(v)}var s=e("./emitter.js");if(!ArrayBuffer.prototype.slice){var i=ArrayBuffer.prototype;i.slice=function(e,t){if(void 0===e&&(e=0),void 0===t&&(t=this.byteLength),e=Math.floor(e),t=Math.floor(t),0>e&&(e+=this.byteLength),0>t&&(t+=this.byteLength),e=Math.min(Math.max(0,e),this.byteLength),t=Math.min(Math.max(0,t),this.byteLength),0>=t-e)return new ArrayBuffer(0);var r=new ArrayBuffer(t-e),n=new Uint8Array(r),s=new Uint8Array(this,e,t-e);return n.set(s),r}}"object"==typeof t&&t.exports&&(t.exports=n)},{"./emitter.js":3}],2:[function(e,t,r){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function s(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,r,n,i,u,f;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[e],a(r))return!1;if(s(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,i=new Array(n-1),u=1;n>u;u++)i[u-1]=arguments[u];r.apply(this,i)}else if(o(r)){for(n=arguments.length,i=new Array(n-1),u=1;n>u;u++)i[u-1]=arguments[u];for(f=r.slice(),n=f.length,u=0;n>u;u++)f[u].apply(this,i)}return!0},n.prototype.addListener=function(e,t){var r;if(!s(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,s(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned){var r;r=a(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function r(){this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}if(!s(t))throw TypeError("listener must be a function");var n=!1;return r.listener=t,this.on(e,r),this},n.prototype.removeListener=function(e,t){var r,n,i,a;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],i=r.length,n=-1,r===t||s(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(r)){for(a=i;a-->0;)if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}if(0>n)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],s(r))this.removeListener(e,r);else for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?s(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var r;return r=e._events&&e._events[t]?s(e._events[t])?1:e._events[t].length:0}},{}],3:[function(e,t,r){"use strict";function n(){s.call(this),this.setMaxListeners(20)}var s=e("events").EventEmitter;n.prototype=Object.create(s.prototype),n.prototype.constructor=n,n.prototype.off=function(e,t){return t?this.removeListener(e,t):e?this.removeAllListeners(e):this.removeAllListeners()},t.exports=n},{events:2}]},{},[1])(1)}); \ No newline at end of file diff --git a/example/index.html b/example/index.html index 68620e2..55377d0 100644 --- a/example/index.html +++ b/example/index.html @@ -24,7 +24,7 @@

imagepack

- + diff --git a/src/imagepack.js b/src/imagepack.js index 3f0e04c..c573922 100644 --- a/src/imagepack.js +++ b/src/imagepack.js @@ -96,8 +96,8 @@ function Imagepack(options) { function load(path) { var request = new XMLHttpRequest(); - request.responseType = 'arraybuffer'; request.open('GET', path, true); + request.responseType = 'arraybuffer'; request.addEventListener('load', function() { if (request.status < 400) { decode(request.response);