/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _webgl = __webpack_require__(1);
var _preloader = __webpack_require__(11);
var _play = __webpack_require__(17);
var _play2 = _interopRequireDefault(_play);
var _runandgundemo = __webpack_require__(27);
var _runandgundemo2 = _interopRequireDefault(_runandgundemo);
var _assetmgr = __webpack_require__(7);
var _sound = __webpack_require__(31);
var _font = __webpack_require__(14);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var game = {};
window.theGame = game;
window.onload = function () {
var clickState = false;
var lastClickState = false;
try {
var canvas = document.getElementById("gamecanvas");
game.render = (0, _webgl.WebGLRenderer)(game, canvas, canvas.getContext("webgl", {
alpha: true,
stencil: true
}) || canvas.getContext("experimental-webgl", {
alpha: true,
stencil: true
}));
game.sound = (0, _sound.SoundEngine)(game);
game.mouse = {
x: 0, y: 0,
justClicked: function justClicked() {
return clickState && !lastClickState;
}
};
game.switchState = function (newstate) {
if (game.state && game.state.destroy) {
game.state.destroy();
}
game.state = newstate;
if (newstate.initialize) {
newstate.initialize();
}
};
game.switchState((0, _preloader.PreloaderState)(game, _play2.default));
_assetmgr.AssetManager.addAssetLoader(game.render.assetLoader());
_assetmgr.AssetManager.addAssetLoader(game.sound.createAssetLoader());
_assetmgr.AssetManager.addAssetLoader(_font.FontLoader);
} catch (err) {
document.write(err);
return;
}
var lastTick = performance.now();
var lastFrameDone = 0;
game.tick = function (timestamp) {
var delta = timestamp - lastTick;
lastTick = timestamp;
game.render.prepareFrame();
if (game.state && game.state.tick) {
game.state.tick(delta);
}
if (game.state && game.state.getKeyboard) {
game.state.getKeyboard().update();
}
lastClickState = clickState;
game.render.finalizeFrame();
window.requestAnimationFrame(game.tick);
lastFrameDone = performance.now();
};
window.requestAnimationFrame(game.tick);
document.addEventListener("keydown", function (evt) {
if (game.state && game.state.getKeyboard) {
game.state.getKeyboard().keyDown(evt);
}
});
document.addEventListener("keyup", function (evt) {
if (game.state && game.state.getKeyboard) {
game.state.getKeyboard().keyUp(evt);
}
});
document.addEventListener("mousemove", function (evt) {
game.mouse.x = evt.clientX;
game.mouse.y = evt.clientY;
});
document.addEventListener("mousedown", function (evt) {
clickState = true;
});
document.addEventListener("mouseup", function (evt) {
clickState = false;
});
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WebGLRenderer = undefined;
var _blobUtil = __webpack_require__(2);
var BlobUtil = _interopRequireWildcard(_blobUtil);
var _assetmgr = __webpack_require__(7);
var _math = __webpack_require__(8);
var _util = __webpack_require__(9);
var _gfxutils = __webpack_require__(10);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var WebGLRenderer = exports.WebGLRenderer = function WebGLRenderer(game, canvas, gl) {
if (!gl) {
if (!canvas.getContext("webgl")) {
throw "Could not open WebGL context (no parameters)";
}
if (!canvas.getContext("webgl", { alpha: false })) {
throw "Could not open WebGL context {alpha: false}";
}
if (!canvas.getContext("webgl", { stencil: true })) {
throw "Could not open WebGL context {stencil: true}";
}
if (!canvas.getContext("webgl", { alpha: false, stencil: true })) {
throw "Could not open WebGL context {alpha: false, stencil: true}";
}
throw "Could not open WebGL context, all tests passed?!";
}
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
var pixelMatrix = _math.Mat4.create();
var currentMaterial = null;
var currentMaterialFlush = null;
var currentFramebuffer = null;
var r = {
gl: gl,
width: 0,
height: 0,
cwidth: 0,
cheight: 0,
manageSize: function manageSize() {
if (canvas.width != window.innerWidth || canvas.height != window.innerHeight) {
r.width = r.cwidth = canvas.width = window.innerWidth;
r.height = r.cheight = canvas.height = window.innerHeight;
gl.viewport(0, 0, canvas.width, canvas.height);
if (game.state && game.state.updateSize) {
game.state.updateSize(canvas.width, canvas.height);
}
}
},
clear: function clear(color) {
gl.clearColor(color.r, color.g, color.b, color.a);
gl.clear(gl.COLOR_BUFFER_BIT);
},
prepareFrame: function prepareFrame() {
r.manageSize();
currentMaterial = null;
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.blendEquation(gl.FUNC_ADD);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
},
finalizeFrame: function finalizeFrame() {
r.flushMaterials();
},
// padding is extra space beyond the edges of the canvas that is guarenteed to be there
// margin space is not guarenteed to be there; it serves only to make resizing smoother
// margin defaults to 50 pixels
createFramebuffer: function createFramebuffer(padding) {
var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
var width = r.width + 2 * padding + 2 * margin;
var height = r.height + 2 * padding + 2 * margin;
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
var colorBuffer = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, colorBuffer);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, colorBuffer, 0);
switch (gl.checkFramebufferStatus(gl.FRAMEBUFFER)) {
case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
throw "FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
throw "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
throw "FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
case gl.FRAMEBUFFER_UNSUPPORTED:
throw "FRAMEBUFFER_UNSUPPORTED";
case gl.FRAMEBUFFER_COMPLETE:
break;
default:
throw "WTF?";
}
gl.bindTexture(gl.TEXTURE_2D, null);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
var colorBufferObj = {
glTex: colorBuffer,
width: width,
height: height
};
var matrix = _math.Mat4.create();
var originalMatrix = _math.Mat4.create();
var workingMatrix = _math.Mat4.create();
var computeMatrix = function computeMatrix() {
matrix.load.scale(canvas.width / width, canvas.height / height);
};
computeMatrix();
var self = {
boundsMatrix: matrix,
bind: function bind(modMat) {
if (canvas.width + 2 * padding > width || canvas.height + 2 * padding > height) {
width = r.cwidth + 2 * padding + 2 * margin;
height = r.cheight + 2 * padding + 2 * margin;
colorBufferObj.width = width;
colorBufferObj.height = height;
gl.bindTexture(gl.TEXTURE_2D, colorBuffer); // resize color buffer
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.bindTexture(gl.TEXTURE_2D, null);
}
computeMatrix();
originalMatrix.load.from(modMat);
workingMatrix.load.from(matrix);
workingMatrix.multiply(modMat);
modMat.load.from(workingMatrix);
//modMat.multiply(matrix);
if (currentMaterial) {
currentMaterialFlush();
}
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
currentFramebuffer = self;
r.width = width;
r.height = height;
gl.viewport(0, 0, r.width, r.height);
},
unbind: function unbind(modMat) {
if (currentMaterial) {
currentMaterialFlush();
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
currentFramebuffer = null;
r.width = canvas.width;
r.height = canvas.height;
gl.viewport(0, 0, r.width, r.height);
modMat.load.from(originalMatrix);
},
draw: function draw(material) {
var origMat = material.getMatrix();
material.setMatrix(_math.Mat4.identity);
material.rect(-1.0 - (width - canvas.width) / canvas.width, -1.0 - (height - canvas.height) / canvas.height, width * 2 / canvas.width, height * 2 / canvas.height, colorBufferObj);
material.setMatrix(origMat);
}
};
return self;
},
assetLoader: function assetLoader() {
var loaders = {
texture: function texture(placeholder) {
return _assetmgr.AssetManager.getFile(placeholder.spec.src).then(function (blob) {
return (0, _util.blobToImage)(blob);
}).then(function (img) {
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
//gl.generateMipmap(gl.TEXTURE_2D);
gl.bindTexture(gl.TEXTURE_2D, null);
return {
glTex: texture,
width: img.width,
height: img.height
};
});
},
shader: function shader(placeholder) {
if (placeholder.spec.shaderType != "fragment" && placeholder.spec.shaderType != "vertex") {
return Promise.reject("unrecognized shader type '" + placeholder.spec.shaderType + "'");
}
return _assetmgr.AssetManager.getFile(placeholder.spec.src).then(function (blob) {
return BlobUtil.blobToBinaryString(blob);
}).then(function (src) {
var shader = gl.createShader({ fragment: gl.FRAGMENT_SHADER, vertex: gl.VERTEX_SHADER }[placeholder.spec.shaderType]);
gl.shaderSource(shader, src);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
var log = gl.getShaderInfoLog(shader);
gl.deleteShader(shader);
throw "Could not compile shader: " + log;
}
return {
glObject: shader,
attributes: placeholder.spec.attributes || [],
uniforms: placeholder.spec.uniforms || []
};
});
},
program: function program(placeholder) {
return Promise.all(placeholder.spec.shaders.map(function (id) {
return placeholder.depend(id);
})).then(function (shaders) {
var program = gl.createProgram();
for (var i = 0; i < shaders.length; i++) {
gl.attachShader(program, shaders[i].glObject);
}
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
var log = gl.getProgramInfoLog(program);
gl.deleteProgram(program);
throw "Could not link program: " + log;
}
var attributeList = Array.prototype.concat.apply([], shaders.map(function (s) {
return s.attributes;
}));
var uniformList = Array.prototype.concat.apply([], shaders.map(function (s) {
return s.uniforms;
}));
var attributes = {};
var uniforms = {};
attributeList.forEach(function (spec) {
spec.location = gl.getAttribLocation(program, spec.name);
if (spec.location < 0) {
// throw "Could not find attribtue '" + spec.name + "'";
}
if (attributes[spec.name]) {
var a = attributes[spec.name];
if (a.dataType != spec.dataType || a.components != spec.components) {
throw "Conflicting definitions for attribute '" + spec.name + "'";
}
} else {
attributes[spec.name] = spec;
}
});
uniformList.forEach(function (spec) {
spec.location = gl.getUniformLocation(program, spec.name);
if (!spec.location) {
// throw "Could not find uniform '" + spec.name + "'";
}
if (uniforms[spec.name]) {
var a = uniforms[spec.name];
if (a.dataType != spec.dataType || a.components != spec.components) {
throw "Conflicting definitions for uniform '" + spec.name + "'";
}
} else {
uniforms[spec.name] = spec;
}
});
return {
program: program,
attributes: attributes,
uniforms: uniforms
};
});
}
};
return {
canLoad: function canLoad(placeholder) {
return loaders[placeholder.spec.type] != undefined;
},
load: function load(placeholder) {
return loaders[placeholder.spec.type](placeholder);
}
};
},
changeMaterial: function changeMaterial(material, flush) {
if (currentMaterial && currentMaterial != material) {
currentMaterialFlush();
}
currentMaterial = material;
currentMaterialFlush = flush;
},
unbindMaterial: function unbindMaterial() {
currentMaterial = null;
},
flushMaterials: function flushMaterials() {
r.changeMaterial(null);
}
};
return r;
};
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
/* jshint -W079 */
var Blob = __webpack_require__(3);
var Promise = __webpack_require__(4);
//
// PRIVATE
//
// From http://stackoverflow.com/questions/14967647/ (continues on next line)
// encode-decode-image-with-base64-breaks-image (2013-04-21)
function binaryStringToArrayBuffer(binary) {
var length = binary.length;
var buf = new ArrayBuffer(length);
var arr = new Uint8Array(buf);
var i = -1;
while (++i < length) {
arr[i] = binary.charCodeAt(i);
}
return buf;
}
// Can't find original post, but this is close
// http://stackoverflow.com/questions/6965107/ (continues on next line)
// converting-between-strings-and-arraybuffers
function arrayBufferToBinaryString(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var length = bytes.byteLength;
var i = -1;
while (++i < length) {
binary += String.fromCharCode(bytes[i]);
}
return binary;
}
// doesn't download the image more than once, because
// browsers aren't dumb. uses the cache
function loadImage(src, crossOrigin) {
return new Promise(function (resolve, reject) {
var img = new Image();
if (crossOrigin) {
img.crossOrigin = crossOrigin;
}
img.onload = function () {
resolve(img);
};
img.onerror = reject;
img.src = src;
});
}
function imgToCanvas(img) {
var canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
// copy the image contents to the canvas
var context = canvas.getContext('2d');
context.drawImage(
img,
0, 0,
img.width, img.height,
0, 0,
img.width, img.height);
return canvas;
}
//
// PUBLIC
//
/**
* Shim for
* [new Blob()]{@link https://developer.mozilla.org/en-US/docs/Web/API/Blob.Blob}
* to support
* [older browsers that use the deprecated BlobBuilder
API]{@link http://caniuse.com/blob}.
*
* @param {Array} parts - content of the Blob
* @param {Object} options - usually just {type: myContentType}
* @returns {Blob}
*/
function createBlob(parts, options) {
options = options || {};
if (typeof options === 'string') {
options = {type: options}; // do you a solid here
}
return new Blob(parts, options);
}
/**
* Shim for
* [URL.createObjectURL()]{@link https://developer.mozilla.org/en-US/docs/Web/API/URL.createObjectURL}
* to support browsers that only have the prefixed
* webkitURL
(e.g. Android <4.4).
* @param {Blob} blob
* @returns {string} url
*/
function createObjectURL(blob) {
return (window.URL || window.webkitURL).createObjectURL(blob);
}
/**
* Shim for
* [URL.revokeObjectURL()]{@link https://developer.mozilla.org/en-US/docs/Web/API/URL.revokeObjectURL}
* to support browsers that only have the prefixed
* webkitURL
(e.g. Android <4.4).
* @param {string} url
*/
function revokeObjectURL(url) {
return (window.URL || window.webkitURL).revokeObjectURL(url);
}
/**
* Convert a Blob
to a binary string. Returns a Promise.
*
* @param {Blob} blob
* @returns {Promise} Promise that resolves with the binary string
*/
function blobToBinaryString(blob) {
return new Promise(function (resolve, reject) {
var reader = new FileReader();
var hasBinaryString = typeof reader.readAsBinaryString === 'function';
reader.onloadend = function (e) {
var result = e.target.result || '';
if (hasBinaryString) {
return resolve(result);
}
resolve(arrayBufferToBinaryString(result));
};
reader.onerror = reject;
if (hasBinaryString) {
reader.readAsBinaryString(blob);
} else {
reader.readAsArrayBuffer(blob);
}
});
}
/**
* Convert a base64-encoded string to a Blob
. Returns a Promise.
* @param {string} base64
* @param {string|undefined} type - the content type (optional)
* @returns {Promise} Promise that resolves with the Blob
*/
function base64StringToBlob(base64, type) {
return Promise.resolve().then(function () {
var parts = [binaryStringToArrayBuffer(atob(base64))];
return type ? createBlob(parts, {type: type}) : createBlob(parts);
});
}
/**
* Convert a binary string to a Blob
. Returns a Promise.
* @param {string} binary
* @param {string|undefined} type - the content type (optional)
* @returns {Promise} Promise that resolves with the Blob
*/
function binaryStringToBlob(binary, type) {
return Promise.resolve().then(function () {
return base64StringToBlob(btoa(binary), type);
});
}
/**
* Convert a Blob
to a binary string. Returns a Promise.
* @param {Blob} blob
* @returns {Promise} Promise that resolves with the binary string
*/
function blobToBase64String(blob) {
return blobToBinaryString(blob).then(function (binary) {
return btoa(binary);
});
}
/**
* Convert a data URL string
* (e.g. 'data:image/png;base64,iVBORw0KG...'
)
* to a Blob
. Returns a Promise.
* @param {string} dataURL
* @returns {Promise} Promise that resolves with the Blob
*/
function dataURLToBlob(dataURL) {
return Promise.resolve().then(function () {
var type = dataURL.match(/data:([^;]+)/)[1];
var base64 = dataURL.replace(/^[^,]+,/, '');
var buff = binaryStringToArrayBuffer(atob(base64));
return createBlob([buff], {type: type});
});
}
/**
* Convert an image's src
URL to a data URL by loading the image and painting
* it to a canvas
. Returns a Promise.
*
*
canvas
to a Blob
. Returns a Promise.
* @param {string} canvas
* @param {string|undefined} type - the content type (optional, defaults to 'image/png')
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the Blob
*/
function canvasToBlob(canvas, type, quality) {
return Promise.resolve().then(function () {
if (typeof canvas.toBlob === 'function') {
return new Promise(function (resolve) {
canvas.toBlob(resolve, type, quality);
});
}
return dataURLToBlob(canvas.toDataURL(type, quality));
});
}
/**
* Convert an image's src
URL to a Blob
by loading the image and painting
* it to a canvas
. Returns a Promise.
*
* Note: this will coerce the image to the desired content type, and it
* will only paint the first frame of an animated GIF.
*
* @param {string} src
* @param {string|undefined} type - the content type (optional, defaults to 'image/png')
* @param {string|undefined} crossOrigin - for CORS-enabled images, set this to
* 'Anonymous' to avoid "tainted canvas" errors
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the Blob
*/
function imgSrcToBlob(src, type, crossOrigin, quality) {
type = type || 'image/png';
return loadImage(src, crossOrigin).then(function (img) {
return imgToCanvas(img);
}).then(function (canvas) {
return canvasToBlob(canvas, type, quality);
});
}
/**
* Convert an ArrayBuffer
to a Blob
. Returns a Promise.
*
* @param {ArrayBuffer} buffer
* @param {string|undefined} type - the content type (optional)
* @returns {Promise} Promise that resolves with the Blob
*/
function arrayBufferToBlob(buffer, type) {
return Promise.resolve().then(function () {
return createBlob([buffer], type);
});
}
/**
* Convert a Blob
to an ArrayBuffer
. Returns a Promise.
* @param {Blob} blob
* @returns {Promise} Promise that resolves with the ArrayBuffer
*/
function blobToArrayBuffer(blob) {
return new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onloadend = function (e) {
var result = e.target.result || new ArrayBuffer(0);
resolve(result);
};
reader.onerror = reject;
reader.readAsArrayBuffer(blob);
});
}
module.exports = {
createBlob : createBlob,
createObjectURL : createObjectURL,
revokeObjectURL : revokeObjectURL,
imgSrcToBlob : imgSrcToBlob,
imgSrcToDataURL : imgSrcToDataURL,
canvasToBlob : canvasToBlob,
dataURLToBlob : dataURLToBlob,
blobToBase64String : blobToBase64String,
base64StringToBlob : base64StringToBlob,
binaryStringToBlob : binaryStringToBlob,
blobToBinaryString : blobToBinaryString,
arrayBufferToBlob : arrayBufferToBlob,
blobToArrayBuffer : blobToArrayBuffer
};
/***/ }),
/* 3 */
/***/ (function(module, exports) {
/* WEBPACK VAR INJECTION */(function(global) {/**
* Create a blob builder even when vendor prefixes exist
*/
var BlobBuilder = global.BlobBuilder
|| global.WebKitBlobBuilder
|| global.MSBlobBuilder
|| global.MozBlobBuilder;
/**
* Check if Blob constructor is supported
*/
var blobSupported = (function() {
try {
var a = new Blob(['hi']);
return a.size === 2;
} catch(e) {
return false;
}
})();
/**
* Check if Blob constructor supports ArrayBufferViews
* Fails in Safari 6, so we need to map to ArrayBuffers there.
*/
var blobSupportsArrayBufferView = blobSupported && (function() {
try {
var b = new Blob([new Uint8Array([1,2])]);
return b.size === 2;
} catch(e) {
return false;
}
})();
/**
* Check if BlobBuilder is supported
*/
var blobBuilderSupported = BlobBuilder
&& BlobBuilder.prototype.append
&& BlobBuilder.prototype.getBlob;
/**
* Helper function that maps ArrayBufferViews to ArrayBuffers
* Used by BlobBuilder constructor and old browsers that didn't
* support it in the Blob constructor.
*/
function mapArrayBufferViews(ary) {
for (var i = 0; i < ary.length; i++) {
var chunk = ary[i];
if (chunk.buffer instanceof ArrayBuffer) {
var buf = chunk.buffer;
// if this is a subarray, make a copy so we only
// include the subarray region from the underlying buffer
if (chunk.byteLength !== buf.byteLength) {
var copy = new Uint8Array(chunk.byteLength);
copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength));
buf = copy.buffer;
}
ary[i] = buf;
}
}
}
function BlobBuilderConstructor(ary, options) {
options = options || {};
var bb = new BlobBuilder();
mapArrayBufferViews(ary);
for (var i = 0; i < ary.length; i++) {
bb.append(ary[i]);
}
return (options.type) ? bb.getBlob(options.type) : bb.getBlob();
};
function BlobConstructor(ary, options) {
mapArrayBufferViews(ary);
return new Blob(ary, options || {});
};
module.exports = (function() {
if (blobSupported) {
return blobSupportsArrayBufferView ? global.Blob : BlobConstructor;
} else if (blobBuilderSupported) {
return BlobBuilderConstructor;
} else {
return undefined;
}
})();
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = typeof Promise === 'function' ? Promise : __webpack_require__(5);
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var immediate = __webpack_require__(6);
/* istanbul ignore next */
function INTERNAL() {}
var handlers = {};
var REJECTED = ['REJECTED'];
var FULFILLED = ['FULFILLED'];
var PENDING = ['PENDING'];
module.exports = Promise;
function Promise(resolver) {
if (typeof resolver !== 'function') {
throw new TypeError('resolver must be a function');
}
this.state = PENDING;
this.queue = [];
this.outcome = void 0;
if (resolver !== INTERNAL) {
safelyResolveThenable(this, resolver);
}
}
Promise.prototype["catch"] = function (onRejected) {
return this.then(null, onRejected);
};
Promise.prototype.then = function (onFulfilled, onRejected) {
if (typeof onFulfilled !== 'function' && this.state === FULFILLED ||
typeof onRejected !== 'function' && this.state === REJECTED) {
return this;
}
var promise = new this.constructor(INTERNAL);
if (this.state !== PENDING) {
var resolver = this.state === FULFILLED ? onFulfilled : onRejected;
unwrap(promise, resolver, this.outcome);
} else {
this.queue.push(new QueueItem(promise, onFulfilled, onRejected));
}
return promise;
};
function QueueItem(promise, onFulfilled, onRejected) {
this.promise = promise;
if (typeof onFulfilled === 'function') {
this.onFulfilled = onFulfilled;
this.callFulfilled = this.otherCallFulfilled;
}
if (typeof onRejected === 'function') {
this.onRejected = onRejected;
this.callRejected = this.otherCallRejected;
}
}
QueueItem.prototype.callFulfilled = function (value) {
handlers.resolve(this.promise, value);
};
QueueItem.prototype.otherCallFulfilled = function (value) {
unwrap(this.promise, this.onFulfilled, value);
};
QueueItem.prototype.callRejected = function (value) {
handlers.reject(this.promise, value);
};
QueueItem.prototype.otherCallRejected = function (value) {
unwrap(this.promise, this.onRejected, value);
};
function unwrap(promise, func, value) {
immediate(function () {
var returnValue;
try {
returnValue = func(value);
} catch (e) {
return handlers.reject(promise, e);
}
if (returnValue === promise) {
handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));
} else {
handlers.resolve(promise, returnValue);
}
});
}
handlers.resolve = function (self, value) {
var result = tryCatch(getThen, value);
if (result.status === 'error') {
return handlers.reject(self, result.value);
}
var thenable = result.value;
if (thenable) {
safelyResolveThenable(self, thenable);
} else {
self.state = FULFILLED;
self.outcome = value;
var i = -1;
var len = self.queue.length;
while (++i < len) {
self.queue[i].callFulfilled(value);
}
}
return self;
};
handlers.reject = function (self, error) {
self.state = REJECTED;
self.outcome = error;
var i = -1;
var len = self.queue.length;
while (++i < len) {
self.queue[i].callRejected(error);
}
return self;
};
function getThen(obj) {
// Make sure we only access the accessor once as required by the spec
var then = obj && obj.then;
if (obj && typeof obj === 'object' && typeof then === 'function') {
return function appyThen() {
then.apply(obj, arguments);
};
}
}
function safelyResolveThenable(self, thenable) {
// Either fulfill, reject or reject with error
var called = false;
function onError(value) {
if (called) {
return;
}
called = true;
handlers.reject(self, value);
}
function onSuccess(value) {
if (called) {
return;
}
called = true;
handlers.resolve(self, value);
}
function tryToUnwrap() {
thenable(onSuccess, onError);
}
var result = tryCatch(tryToUnwrap);
if (result.status === 'error') {
onError(result.value);
}
}
function tryCatch(func, value) {
var out = {};
try {
out.value = func(value);
out.status = 'success';
} catch (e) {
out.status = 'error';
out.value = e;
}
return out;
}
Promise.resolve = resolve;
function resolve(value) {
if (value instanceof this) {
return value;
}
return handlers.resolve(new this(INTERNAL), value);
}
Promise.reject = reject;
function reject(reason) {
var promise = new this(INTERNAL);
return handlers.reject(promise, reason);
}
Promise.all = all;
function all(iterable) {
var self = this;
if (Object.prototype.toString.call(iterable) !== '[object Array]') {
return this.reject(new TypeError('must be an array'));
}
var len = iterable.length;
var called = false;
if (!len) {
return this.resolve([]);
}
var values = new Array(len);
var resolved = 0;
var i = -1;
var promise = new this(INTERNAL);
while (++i < len) {
allResolver(iterable[i], i);
}
return promise;
function allResolver(value, i) {
self.resolve(value).then(resolveFromAll, function (error) {
if (!called) {
called = true;
handlers.reject(promise, error);
}
});
function resolveFromAll(outValue) {
values[i] = outValue;
if (++resolved === len && !called) {
called = true;
handlers.resolve(promise, values);
}
}
}
}
Promise.race = race;
function race(iterable) {
var self = this;
if (Object.prototype.toString.call(iterable) !== '[object Array]') {
return this.reject(new TypeError('must be an array'));
}
var len = iterable.length;
var called = false;
if (!len) {
return this.resolve([]);
}
var i = -1;
var promise = new this(INTERNAL);
while (++i < len) {
resolver(iterable[i]);
}
return promise;
function resolver(value) {
self.resolve(value).then(function (response) {
if (!called) {
called = true;
handlers.resolve(promise, response);
}
}, function (error) {
if (!called) {
called = true;
handlers.reject(promise, error);
}
});
}
}
/***/ }),
/* 6 */
/***/ (function(module, exports) {
/* WEBPACK VAR INJECTION */(function(global) {'use strict';
var Mutation = global.MutationObserver || global.WebKitMutationObserver;
var scheduleDrain;
{
if (Mutation) {
var called = 0;
var observer = new Mutation(nextTick);
var element = global.document.createTextNode('');
observer.observe(element, {
characterData: true
});
scheduleDrain = function () {
element.data = (called = ++called % 2);
};
} else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
var channel = new global.MessageChannel();
channel.port1.onmessage = nextTick;
scheduleDrain = function () {
channel.port2.postMessage(0);
};
} else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
scheduleDrain = function () {
// Create a