leancloud-storage
Version:
LeanCloud JavaScript SDK.
1,472 lines (1,263 loc) • 570 kB
JavaScript
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _defineProperty2(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
(function (f) {
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") {
module.exports = f();
} else if (typeof define === "function" && define.amd) {
define([], f);
} else {
var g;if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
g = this;
}g.AV = f();
}
})(function () {
var define, module, exports;return function e(t, n, r) {
function s(o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);var f = new Error("Cannot find module '" + o + "'");throw f.code = "MODULE_NOT_FOUND", f;
}var l = n[o] = { exports: {} };t[o][0].call(l.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, l, l.exports, e, t, n, r);
}return n[o].exports;
}var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) {
s(r[o]);
}return s;
}({ 1: [function (require, module, exports) {}, {}], 2: [function (require, module, exports) {
var charenc = {
// UTF-8 encoding
utf8: {
// Convert a string to a byte array
stringToBytes: function stringToBytes(str) {
return charenc.bin.stringToBytes(unescape(encodeURIComponent(str)));
},
// Convert a byte array to a string
bytesToString: function bytesToString(bytes) {
return decodeURIComponent(escape(charenc.bin.bytesToString(bytes)));
}
},
// Binary encoding
bin: {
// Convert a string to a byte array
stringToBytes: function stringToBytes(str) {
for (var bytes = [], i = 0; i < str.length; i++) {
bytes.push(str.charCodeAt(i) & 0xFF);
}return bytes;
},
// Convert a byte array to a string
bytesToString: function bytesToString(bytes) {
for (var str = [], i = 0; i < bytes.length; i++) {
str.push(String.fromCharCode(bytes[i]));
}return str.join('');
}
}
};
module.exports = charenc;
}, {}], 3: [function (require, module, exports) {
/**
* Expose `Emitter`.
*/
if (typeof module !== 'undefined') {
module.exports = Emitter;
}
/**
* Initialize a new `Emitter`.
*
* @api public
*/
function Emitter(obj) {
if (obj) return mixin(obj);
};
/**
* Mixin the emitter properties.
*
* @param {Object} obj
* @return {Object}
* @api private
*/
function mixin(obj) {
for (var key in Emitter.prototype) {
obj[key] = Emitter.prototype[key];
}
return obj;
}
/**
* Listen on the given `event` with `fn`.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
this._callbacks = this._callbacks || {};
(this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
return this;
};
/**
* Adds an `event` listener that will be invoked a single
* time then automatically removed.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.once = function (event, fn) {
function on() {
this.off(event, on);
fn.apply(this, arguments);
}
on.fn = fn;
this.on(event, on);
return this;
};
/**
* Remove the given callback for `event` or all
* registered callbacks.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
this._callbacks = this._callbacks || {};
// all
if (0 == arguments.length) {
this._callbacks = {};
return this;
}
// specific event
var callbacks = this._callbacks['$' + event];
if (!callbacks) return this;
// remove all handlers
if (1 == arguments.length) {
delete this._callbacks['$' + event];
return this;
}
// remove specific handler
var cb;
for (var i = 0; i < callbacks.length; i++) {
cb = callbacks[i];
if (cb === fn || cb.fn === fn) {
callbacks.splice(i, 1);
break;
}
}
return this;
};
/**
* Emit `event` with the given args.
*
* @param {String} event
* @param {Mixed} ...
* @return {Emitter}
*/
Emitter.prototype.emit = function (event) {
this._callbacks = this._callbacks || {};
var args = [].slice.call(arguments, 1),
callbacks = this._callbacks['$' + event];
if (callbacks) {
callbacks = callbacks.slice(0);
for (var i = 0, len = callbacks.length; i < len; ++i) {
callbacks[i].apply(this, args);
}
}
return this;
};
/**
* Return array of callbacks for `event`.
*
* @param {String} event
* @return {Array}
* @api public
*/
Emitter.prototype.listeners = function (event) {
this._callbacks = this._callbacks || {};
return this._callbacks['$' + event] || [];
};
/**
* Check if this emitter has `event` handlers.
*
* @param {String} event
* @return {Boolean}
* @api public
*/
Emitter.prototype.hasListeners = function (event) {
return !!this.listeners(event).length;
};
}, {}], 4: [function (require, module, exports) {
(function () {
var base64map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
crypt = {
// Bit-wise rotation left
rotl: function rotl(n, b) {
return n << b | n >>> 32 - b;
},
// Bit-wise rotation right
rotr: function rotr(n, b) {
return n << 32 - b | n >>> b;
},
// Swap big-endian to little-endian and vice versa
endian: function endian(n) {
// If number given, swap endian
if (n.constructor == Number) {
return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;
}
// Else, assume array and swap all items
for (var i = 0; i < n.length; i++) {
n[i] = crypt.endian(n[i]);
}return n;
},
// Generate an array of any length of random bytes
randomBytes: function randomBytes(n) {
for (var bytes = []; n > 0; n--) {
bytes.push(Math.floor(Math.random() * 256));
}return bytes;
},
// Convert a byte array to big-endian 32-bit words
bytesToWords: function bytesToWords(bytes) {
for (var words = [], i = 0, b = 0; i < bytes.length; i++, b += 8) {
words[b >>> 5] |= bytes[i] << 24 - b % 32;
}return words;
},
// Convert big-endian 32-bit words to a byte array
wordsToBytes: function wordsToBytes(words) {
for (var bytes = [], b = 0; b < words.length * 32; b += 8) {
bytes.push(words[b >>> 5] >>> 24 - b % 32 & 0xFF);
}return bytes;
},
// Convert a byte array to a hex string
bytesToHex: function bytesToHex(bytes) {
for (var hex = [], i = 0; i < bytes.length; i++) {
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join('');
},
// Convert a hex string to a byte array
hexToBytes: function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}return bytes;
},
// Convert a byte array to a base-64 string
bytesToBase64: function bytesToBase64(bytes) {
for (var base64 = [], i = 0; i < bytes.length; i += 3) {
var triplet = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
for (var j = 0; j < 4; j++) {
if (i * 8 + j * 6 <= bytes.length * 8) base64.push(base64map.charAt(triplet >>> 6 * (3 - j) & 0x3F));else base64.push('=');
}
}
return base64.join('');
},
// Convert a base-64 string to a byte array
base64ToBytes: function base64ToBytes(base64) {
// Remove non-base-64 characters
base64 = base64.replace(/[^A-Z0-9+\/]/ig, '');
for (var bytes = [], i = 0, imod4 = 0; i < base64.length; imod4 = ++i % 4) {
if (imod4 == 0) continue;
bytes.push((base64map.indexOf(base64.charAt(i - 1)) & Math.pow(2, -2 * imod4 + 8) - 1) << imod4 * 2 | base64map.indexOf(base64.charAt(i)) >>> 6 - imod4 * 2);
}
return bytes;
}
};
module.exports = crypt;
})();
}, {}], 5: [function (require, module, exports) {
(function (process) {
/**
* This is the web browser implementation of `debug()`.
*
* Expose `debug()` as the module.
*/
exports = module.exports = require('./debug');
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.storage = 'undefined' != typeof chrome && 'undefined' != typeof chrome.storage ? chrome.storage.local : localstorage();
/**
* Colors.
*/
exports.colors = ['lightseagreen', 'forestgreen', 'goldenrod', 'dodgerblue', 'darkorchid', 'crimson'];
/**
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
* and the Firebug extension (any Firefox version) are known
* to support "%c" CSS customizations.
*
* TODO: add a `localStorage` variable to explicitly enable/disable colors
*/
function useColors() {
// is webkit? http://stackoverflow.com/a/16459606/376773
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
return typeof document !== 'undefined' && 'WebkitAppearance' in document.documentElement.style ||
// is firebug? http://stackoverflow.com/a/398120/376773
window.console && (console.firebug || console.exception && console.table) ||
// is firefox >= v31?
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31;
}
/**
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
*/
exports.formatters.j = function (v) {
return JSON.stringify(v);
};
/**
* Colorize log arguments if enabled.
*
* @api public
*/
function formatArgs() {
var args = arguments;
var useColors = this.useColors;
args[0] = (useColors ? '%c' : '') + this.namespace + (useColors ? ' %c' : ' ') + args[0] + (useColors ? '%c ' : ' ') + '+' + exports.humanize(this.diff);
if (!useColors) return args;
var c = 'color: ' + this.color;
args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
// the final "%c" is somewhat tricky, because there could be other
// arguments passed either before or after the %c, so we need to
// figure out the correct index to insert the CSS into
var index = 0;
var lastC = 0;
args[0].replace(/%[a-z%]/g, function (match) {
if ('%%' === match) return;
index++;
if ('%c' === match) {
// we only are interested in the *last* %c
// (the user may have provided their own)
lastC = index;
}
});
args.splice(lastC, 0, c);
return args;
}
/**
* Invokes `console.log()` when available.
* No-op when `console.log` is not a "function".
*
* @api public
*/
function log() {
// this hackery is required for IE8/9, where
// the `console.log` function doesn't have 'apply'
return 'object' === (typeof console === "undefined" ? "undefined" : _typeof(console)) && console.log && Function.prototype.apply.call(console.log, console, arguments);
}
/**
* Save `namespaces`.
*
* @param {String} namespaces
* @api private
*/
function save(namespaces) {
try {
if (null == namespaces) {
exports.storage.removeItem('debug');
} else {
exports.storage.debug = namespaces;
}
} catch (e) {}
}
/**
* Load `namespaces`.
*
* @return {String} returns the previously persisted debug modes
* @api private
*/
function load() {
var r;
try {
r = exports.storage.debug;
} catch (e) {}
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
if ('env' in (typeof process === 'undefined' ? {} : process)) {
r = process.env.DEBUG;
}
return r;
}
/**
* Enable namespaces listed in `localStorage.debug` initially.
*/
exports.enable(load());
/**
* Localstorage attempts to return the localstorage.
*
* This is necessary because safari throws
* when a user disables cookies/localstorage
* and you attempt to access it.
*
* @return {LocalStorage}
* @api private
*/
function localstorage() {
try {
return window.localStorage;
} catch (e) {}
}
}).call(this, require('_process'));
}, { "./debug": 6, "_process": 15 }], 6: [function (require, module, exports) {
/**
* This is the common logic for both the Node.js and web browser
* implementations of `debug()`.
*
* Expose `debug()` as the module.
*/
exports = module.exports = debug.debug = debug;
exports.coerce = coerce;
exports.disable = disable;
exports.enable = enable;
exports.enabled = enabled;
exports.humanize = require('ms');
/**
* The currently active debug mode names, and names to skip.
*/
exports.names = [];
exports.skips = [];
/**
* Map of special "%n" handling functions, for the debug "format" argument.
*
* Valid key names are a single, lowercased letter, i.e. "n".
*/
exports.formatters = {};
/**
* Previously assigned color.
*/
var prevColor = 0;
/**
* Previous log timestamp.
*/
var prevTime;
/**
* Select a color.
*
* @return {Number}
* @api private
*/
function selectColor() {
return exports.colors[prevColor++ % exports.colors.length];
}
/**
* Create a debugger with the given `namespace`.
*
* @param {String} namespace
* @return {Function}
* @api public
*/
function debug(namespace) {
// define the `disabled` version
function disabled() {}
disabled.enabled = false;
// define the `enabled` version
function enabled() {
var self = enabled;
// set `diff` timestamp
var curr = +new Date();
var ms = curr - (prevTime || curr);
self.diff = ms;
self.prev = prevTime;
self.curr = curr;
prevTime = curr;
// add the `color` if not set
if (null == self.useColors) self.useColors = exports.useColors();
if (null == self.color && self.useColors) self.color = selectColor();
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
args[0] = exports.coerce(args[0]);
if ('string' !== typeof args[0]) {
// anything else let's inspect with %o
args = ['%o'].concat(args);
}
// apply any `formatters` transformations
var index = 0;
args[0] = args[0].replace(/%([a-z%])/g, function (match, format) {
// if we encounter an escaped % then don't increase the array index
if (match === '%%') return match;
index++;
var formatter = exports.formatters[format];
if ('function' === typeof formatter) {
var val = args[index];
match = formatter.call(self, val);
// now we need to remove `args[index]` since it's inlined in the `format`
args.splice(index, 1);
index--;
}
return match;
});
// apply env-specific formatting
args = exports.formatArgs.apply(self, args);
var logFn = enabled.log || exports.log || console.log.bind(console);
logFn.apply(self, args);
}
enabled.enabled = true;
var fn = exports.enabled(namespace) ? enabled : disabled;
fn.namespace = namespace;
return fn;
}
/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
*
* @param {String} namespaces
* @api public
*/
function enable(namespaces) {
exports.save(namespaces);
var split = (namespaces || '').split(/[\s,]+/);
var len = split.length;
for (var i = 0; i < len; i++) {
if (!split[i]) continue; // ignore empty strings
namespaces = split[i].replace(/[\\^$+?.()|[\]{}]/g, '\\$&').replace(/\*/g, '.*?');
if (namespaces[0] === '-') {
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
} else {
exports.names.push(new RegExp('^' + namespaces + '$'));
}
}
}
/**
* Disable debug output.
*
* @api public
*/
function disable() {
exports.enable('');
}
/**
* Returns true if the given mode name is enabled, false otherwise.
*
* @param {String} name
* @return {Boolean}
* @api public
*/
function enabled(name) {
var i, len;
for (i = 0, len = exports.skips.length; i < len; i++) {
if (exports.skips[i].test(name)) {
return false;
}
}
for (i = 0, len = exports.names.length; i < len; i++) {
if (exports.names[i].test(name)) {
return true;
}
}
return false;
}
/**
* Coerce `val`.
*
* @param {Mixed} val
* @return {Mixed}
* @api private
*/
function coerce(val) {
if (val instanceof Error) return val.stack || val.message;
return val;
}
}, { "ms": 14 }], 7: [function (require, module, exports) {
/**
* @author Toru Nagashima
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";
/**
* Creates a unique key.
*
* @param {string} name - A name to create.
* @returns {symbol|string}
* @private
*/
var createUniqueKey = exports.createUniqueKey = typeof Symbol !== "undefined" ? Symbol : function createUniqueKey(name) {
return "[[" + name + "_" + Math.random().toFixed(8).slice(2) + "]]";
};
/**
* The key of listeners.
*
* @type {symbol|string}
* @private
*/
exports.LISTENERS = createUniqueKey("listeners");
/**
* A value of kind for listeners which are registered in the capturing phase.
*
* @type {number}
* @private
*/
exports.CAPTURE = 1;
/**
* A value of kind for listeners which are registered in the bubbling phase.
*
* @type {number}
* @private
*/
exports.BUBBLE = 2;
/**
* A value of kind for listeners which are registered as an attribute.
*
* @type {number}
* @private
*/
exports.ATTRIBUTE = 3;
/**
* @typedef object ListenerNode
* @property {function} listener - A listener function.
* @property {number} kind - The kind of the listener.
* @property {ListenerNode|null} next - The next node.
* If this node is the last, this is `null`.
*/
/**
* Creates a node of singly linked list for a list of listeners.
*
* @param {function} listener - A listener function.
* @param {number} kind - The kind of the listener.
* @returns {ListenerNode} The created listener node.
*/
exports.newNode = function newNode(listener, kind) {
return { listener: listener, kind: kind, next: null };
};
}, {}], 8: [function (require, module, exports) {
/**
* @author Toru Nagashima
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";
//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
var Commons = require("./commons");
var LISTENERS = Commons.LISTENERS;
var ATTRIBUTE = Commons.ATTRIBUTE;
var newNode = Commons.newNode;
//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------
/**
* Gets a specified attribute listener from a given EventTarget object.
*
* @param {EventTarget} eventTarget - An EventTarget object to get.
* @param {string} type - An event type to get.
* @returns {function|null} The found attribute listener.
*/
function getAttributeListener(eventTarget, type) {
var node = eventTarget[LISTENERS][type];
while (node != null) {
if (node.kind === ATTRIBUTE) {
return node.listener;
}
node = node.next;
}
return null;
}
/**
* Sets a specified attribute listener to a given EventTarget object.
*
* @param {EventTarget} eventTarget - An EventTarget object to set.
* @param {string} type - An event type to set.
* @param {function|null} listener - A listener to be set.
* @returns {void}
*/
function setAttributeListener(eventTarget, type, listener) {
if (typeof listener !== "function" && (typeof listener === "undefined" ? "undefined" : _typeof(listener)) !== "object") {
listener = null; // eslint-disable-line no-param-reassign
}
var prev = null;
var node = eventTarget[LISTENERS][type];
while (node != null) {
if (node.kind === ATTRIBUTE) {
// Remove old value.
if (prev == null) {
eventTarget[LISTENERS][type] = node.next;
} else {
prev.next = node.next;
}
} else {
prev = node;
}
node = node.next;
}
// Add new value.
if (listener != null) {
if (prev == null) {
eventTarget[LISTENERS][type] = newNode(listener, ATTRIBUTE);
} else {
prev.next = newNode(listener, ATTRIBUTE);
}
}
}
//-----------------------------------------------------------------------------
// Public Interface
//-----------------------------------------------------------------------------
/**
* Defines an `EventTarget` implementation which has `onfoobar` attributes.
*
* @param {EventTarget} EventTargetBase - A base implementation of EventTarget.
* @param {string[]} types - A list of event types which are defined as attribute listeners.
* @returns {EventTarget} The defined `EventTarget` implementation which has attribute listeners.
*/
exports.defineCustomEventTarget = function (EventTargetBase, types) {
function EventTarget() {
EventTargetBase.call(this);
}
var descripter = {
constructor: {
value: EventTarget,
configurable: true,
writable: true
}
};
types.forEach(function (type) {
descripter["on" + type] = {
get: function get() {
return getAttributeListener(this, type);
},
set: function set(listener) {
setAttributeListener(this, type, listener);
},
configurable: true,
enumerable: true
};
});
EventTarget.prototype = Object.create(EventTargetBase.prototype, descripter);
return EventTarget;
};
}, { "./commons": 7 }], 9: [function (require, module, exports) {
/**
* @author Toru Nagashima
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";
//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
var Commons = require("./commons");
var CustomEventTarget = require("./custom-event-target");
var EventWrapper = require("./event-wrapper");
var LISTENERS = Commons.LISTENERS;
var CAPTURE = Commons.CAPTURE;
var BUBBLE = Commons.BUBBLE;
var ATTRIBUTE = Commons.ATTRIBUTE;
var newNode = Commons.newNode;
var defineCustomEventTarget = CustomEventTarget.defineCustomEventTarget;
var createEventWrapper = EventWrapper.createEventWrapper;
var STOP_IMMEDIATE_PROPAGATION_FLAG = EventWrapper.STOP_IMMEDIATE_PROPAGATION_FLAG;
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
/**
* A flag which shows there is the native `EventTarget` interface object.
*
* @type {boolean}
* @private
*/
var HAS_EVENTTARGET_INTERFACE = typeof window !== "undefined" && typeof window.EventTarget !== "undefined";
//-----------------------------------------------------------------------------
// Public Interface
//-----------------------------------------------------------------------------
/**
* An implementation for `EventTarget` interface.
*
* @constructor
* @public
*/
var EventTarget = module.exports = function EventTarget() {
if (this instanceof EventTarget) {
// this[LISTENERS] is a Map.
// Its key is event type.
// Its value is ListenerNode object or null.
//
// interface ListenerNode {
// var listener: Function
// var kind: CAPTURE|BUBBLE|ATTRIBUTE
// var next: ListenerNode|null
// }
Object.defineProperty(this, LISTENERS, { value: Object.create(null) });
} else if (arguments.length === 1 && Array.isArray(arguments[0])) {
return defineCustomEventTarget(EventTarget, arguments[0]);
} else if (arguments.length > 0) {
var types = Array(arguments.length);
for (var i = 0; i < arguments.length; ++i) {
types[i] = arguments[i];
}
// To use to extend with attribute listener properties.
// e.g.
// class MyCustomObject extends EventTarget("message", "error") {
// //...
// }
return defineCustomEventTarget(EventTarget, types);
} else {
throw new TypeError("Cannot call a class as a function");
}
};
EventTarget.prototype = Object.create((HAS_EVENTTARGET_INTERFACE ? window.EventTarget : Object).prototype, {
constructor: {
value: EventTarget,
writable: true,
configurable: true
},
addEventListener: {
value: function addEventListener(type, listener, capture) {
if (listener == null) {
return false;
}
if (typeof listener !== "function" && (typeof listener === "undefined" ? "undefined" : _typeof(listener)) !== "object") {
throw new TypeError("\"listener\" is not an object.");
}
var kind = capture ? CAPTURE : BUBBLE;
var node = this[LISTENERS][type];
if (node == null) {
this[LISTENERS][type] = newNode(listener, kind);
return true;
}
var prev = null;
while (node != null) {
if (node.listener === listener && node.kind === kind) {
// Should ignore a duplicated listener.
return false;
}
prev = node;
node = node.next;
}
prev.next = newNode(listener, kind);
return true;
},
configurable: true,
writable: true
},
removeEventListener: {
value: function removeEventListener(type, listener, capture) {
if (listener == null) {
return false;
}
var kind = capture ? CAPTURE : BUBBLE;
var prev = null;
var node = this[LISTENERS][type];
while (node != null) {
if (node.listener === listener && node.kind === kind) {
if (prev == null) {
this[LISTENERS][type] = node.next;
} else {
prev.next = node.next;
}
return true;
}
prev = node;
node = node.next;
}
return false;
},
configurable: true,
writable: true
},
dispatchEvent: {
value: function dispatchEvent(event) {
// If listeners aren't registered, terminate.
var node = this[LISTENERS][event.type];
if (node == null) {
return true;
}
// Since we cannot rewrite several properties, so wrap object.
var wrapped = createEventWrapper(event, this);
// This doesn't process capturing phase and bubbling phase.
// This isn't participating in a tree.
while (node != null) {
if (typeof node.listener === "function") {
node.listener.call(this, wrapped);
} else if (node.kind !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
node.listener.handleEvent(wrapped);
}
if (wrapped[STOP_IMMEDIATE_PROPAGATION_FLAG]) {
break;
}
node = node.next;
}
return !wrapped.defaultPrevented;
},
configurable: true,
writable: true
}
});
}, { "./commons": 7, "./custom-event-target": 8, "./event-wrapper": 10 }], 10: [function (require, module, exports) {
/**
* @author Toru Nagashima
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";
//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
var createUniqueKey = require("./commons").createUniqueKey;
//-----------------------------------------------------------------------------
// Constsnts
//-----------------------------------------------------------------------------
/**
* The key of the flag which is turned on by `stopImmediatePropagation` method.
*
* @type {symbol|string}
* @private
*/
var STOP_IMMEDIATE_PROPAGATION_FLAG = createUniqueKey("stop_immediate_propagation_flag");
/**
* The key of the flag which is turned on by `preventDefault` method.
*
* @type {symbol|string}
* @private
*/
var CANCELED_FLAG = createUniqueKey("canceled_flag");
/**
* The key of the original event object.
*
* @type {symbol|string}
* @private
*/
var ORIGINAL_EVENT = createUniqueKey("original_event");
/**
* Method definitions for the event wrapper.
*
* @type {object}
* @private
*/
var wrapperPrototypeDefinition = Object.freeze({
stopPropagation: Object.freeze({
value: function stopPropagation() {
var e = this[ORIGINAL_EVENT];
if (typeof e.stopPropagation === "function") {
e.stopPropagation();
}
},
writable: true,
configurable: true
}),
stopImmediatePropagation: Object.freeze({
value: function stopImmediatePropagation() {
this[STOP_IMMEDIATE_PROPAGATION_FLAG] = true;
var e = this[ORIGINAL_EVENT];
if (typeof e.stopImmediatePropagation === "function") {
e.stopImmediatePropagation();
}
},
writable: true,
configurable: true
}),
preventDefault: Object.freeze({
value: function preventDefault() {
if (this.cancelable === true) {
this[CANCELED_FLAG] = true;
}
var e = this[ORIGINAL_EVENT];
if (typeof e.preventDefault === "function") {
e.preventDefault();
}
},
writable: true,
configurable: true
}),
defaultPrevented: Object.freeze({
get: function defaultPrevented() {
return this[CANCELED_FLAG];
},
enumerable: true,
configurable: true
})
});
//-----------------------------------------------------------------------------
// Public Interface
//-----------------------------------------------------------------------------
exports.STOP_IMMEDIATE_PROPAGATION_FLAG = STOP_IMMEDIATE_PROPAGATION_FLAG;
/**
* Creates an event wrapper.
*
* We cannot modify several properties of `Event` object, so we need to create the wrapper.
* Plus, this wrapper supports non `Event` objects.
*
* @param {Event|{type: string}} event - An original event to create the wrapper.
* @param {EventTarget} eventTarget - The event target of the event.
* @returns {Event} The created wrapper. This object is implemented `Event` interface.
* @private
*/
exports.createEventWrapper = function createEventWrapper(event, eventTarget) {
var timeStamp = typeof event.timeStamp === "number" ? event.timeStamp : Date.now();
var propertyDefinition = {
type: { value: event.type, enumerable: true },
target: { value: eventTarget, enumerable: true },
currentTarget: { value: eventTarget, enumerable: true },
eventPhase: { value: 2, enumerable: true },
bubbles: { value: Boolean(event.bubbles), enumerable: true },
cancelable: { value: Boolean(event.cancelable), enumerable: true },
timeStamp: { value: timeStamp, enumerable: true },
isTrusted: { value: false, enumerable: true }
};
propertyDefinition[STOP_IMMEDIATE_PROPAGATION_FLAG] = { value: false, writable: true };
propertyDefinition[CANCELED_FLAG] = { value: false, writable: true };
propertyDefinition[ORIGINAL_EVENT] = { value: event };
// For CustomEvent.
if (typeof event.detail !== "undefined") {
propertyDefinition.detail = { value: event.detail, enumerable: true };
}
return Object.create(Object.create(event, wrapperPrototypeDefinition), propertyDefinition);
};
}, { "./commons": 7 }], 11: [function (require, module, exports) {
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/
// The _isBuffer check is for Safari 5-7 support, because it's missing
// Object.prototype.constructor. Remove this eventually
module.exports = function (obj) {
return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer);
};
function isBuffer(obj) {
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
}
// For Node v0.10 support. Remove this eventually.
function isSlowBuffer(obj) {
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0));
}
}, {}], 12: [function (require, module, exports) {
(function (root) {
var localStorageMemory = {};
var cache = {};
/**
* number of stored items.
*/
localStorageMemory.length = 0;
/**
* returns item for passed key, or null
*
* @para {String} key
* name of item to be returned
* @returns {String|null}
*/
localStorageMemory.getItem = function (key) {
return cache[key] || null;
};
/**
* sets item for key to passed value, as String
*
* @para {String} key
* name of item to be set
* @para {String} value
* value, will always be turned into a String
* @returns {undefined}
*/
localStorageMemory.setItem = function (key, value) {
if (typeof value === 'undefined') {
localStorageMemory.removeItem(key);
} else {
if (!cache.hasOwnProperty(key)) {
localStorageMemory.length++;
}
cache[key] = '' + value;
}
};
/**
* removes item for passed key
*
* @para {String} key
* name of item to be removed
* @returns {undefined}
*/
localStorageMemory.removeItem = function (key) {
if (cache.hasOwnProperty(key)) {
delete cache[key];
localStorageMemory.length--;
}
};
/**
* returns name of key at passed index
*
* @para {Number} index
* Position for key to be returned (starts at 0)
* @returns {String|null}
*/
localStorageMemory.key = function (index) {
return Object.keys(cache)[index] || null;
};
/**
* removes all stored items and sets length to 0
*
* @returns {undefined}
*/
localStorageMemory.clear = function () {
cache = {};
localStorageMemory.length = 0;
};
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object') {
module.exports = localStorageMemory;
} else {
root.localStorageMemory = localStorageMemory;
}
})(this);
}, {}], 13: [function (require, module, exports) {
(function () {
var crypt = require('crypt'),
utf8 = require('charenc').utf8,
isBuffer = require('is-buffer'),
bin = require('charenc').bin,
// The core
md5 = function md5(message, options) {
// Convert to byte array
if (message.constructor == String) {
if (options && options.encoding === 'binary') message = bin.stringToBytes(message);else message = utf8.stringToBytes(message);
} else if (isBuffer(message)) message = Array.prototype.slice.call(message, 0);else if (!Array.isArray(message)) message = message.toString();
// else, assume byte array already
var m = crypt.bytesToWords(message),
l = message.length * 8,
a = 1732584193,
b = -271733879,
c = -1732584194,
d = 271733878;
// Swap endian
for (var i = 0; i < m.length; i++) {
m[i] = (m[i] << 8 | m[i] >>> 24) & 0x00FF00FF | (m[i] << 24 | m[i] >>> 8) & 0xFF00FF00;
}
// Padding
m[l >>> 5] |= 0x80 << l % 32;
m[(l + 64 >>> 9 << 4) + 14] = l;
// Method shortcuts
var FF = md5._ff,
GG = md5._gg,
HH = md5._hh,
II = md5._ii;
for (var i = 0; i < m.length; i += 16) {
var aa = a,
bb = b,
cc = c,
dd = d;
a = FF(a, b, c, d, m[i + 0], 7, -680876936);
d = FF(d, a, b, c, m[i + 1], 12, -389564586);
c = FF(c, d, a, b, m[i + 2], 17, 606105819);
b = FF(b, c, d, a, m[i + 3], 22, -1044525330);
a = FF(a, b, c, d, m[i + 4], 7, -176418897);
d = FF(d, a, b, c, m[i + 5], 12, 1200080426);
c = FF(c, d, a, b, m[i + 6], 17, -1473231341);
b = FF(b, c, d, a, m[i + 7], 22, -45705983);
a = FF(a, b, c, d, m[i + 8], 7, 1770035416);
d = FF(d, a, b, c, m[i + 9], 12, -1958414417);
c = FF(c, d, a, b, m[i + 10], 17, -42063);
b = FF(b, c, d, a, m[i + 11], 22, -1990404162);
a = FF(a, b, c, d, m[i + 12], 7, 1804603682);
d = FF(d, a, b, c, m[i + 13], 12, -40341101);
c = FF(c, d, a, b, m[i + 14], 17, -1502002290);
b = FF(b, c, d, a, m[i + 15], 22, 1236535329);
a = GG(a, b, c, d, m[i + 1], 5, -165796510);
d = GG(d, a, b, c, m[i + 6], 9, -1069501632);
c = GG(c, d, a, b, m[i + 11], 14, 643717713);
b = GG(b, c, d, a, m[i + 0], 20, -373897302);
a = GG(a, b, c, d, m[i + 5], 5, -701558691);
d = GG(d, a, b, c, m[i + 10], 9, 38016083);
c = GG(c, d, a, b, m[i + 15], 14, -660478335);
b = GG(b, c, d, a, m[i + 4], 20, -405537848);
a = GG(a, b, c, d, m[i + 9], 5, 568446438);
d = GG(d, a, b, c, m[i + 14], 9, -1019803690);
c = GG(c, d, a, b, m[i + 3], 14, -187363961);
b = GG(b, c, d, a, m[i + 8], 20, 1163531501);
a = GG(a, b, c, d, m[i + 13], 5, -1444681467);
d = GG(d, a, b, c, m[i + 2], 9, -51403784);
c = GG(c, d, a, b, m[i + 7], 14, 1735328473);
b = GG(b, c, d, a, m[i + 12], 20, -1926607734);
a = HH(a, b, c, d, m[i + 5], 4, -378558);
d = HH(d, a, b, c, m[i + 8], 11, -2022574463);
c = HH(c, d, a, b, m[i + 11], 16, 1839030562);
b = HH(b, c, d, a, m[i + 14], 23, -35309556);
a = HH(a, b, c, d, m[i + 1], 4, -1530992060);
d = HH(d, a, b, c, m[i + 4], 11, 1272893353);
c = HH(c, d, a, b, m[i + 7], 16, -155497632);
b = HH(b, c, d, a, m[i + 10], 23, -1094730640);
a = HH(a, b, c, d, m[i + 13], 4, 681279174);
d = HH(d, a, b, c, m[i + 0], 11, -358537222);
c = HH(c, d, a, b, m[i + 3], 16, -722521979);
b = HH(b, c, d, a, m[i + 6], 23, 76029189);
a = HH(a, b, c, d, m[i + 9], 4, -640364487);
d = HH(d, a, b, c, m[i + 12], 11, -421815835);
c = HH(c, d, a, b, m[i + 15], 16, 530742520);
b = HH(b, c, d, a, m[i + 2], 23, -995338651);
a = II(a, b, c, d, m[i + 0], 6, -198630844);
d = II(d, a, b, c, m[i + 7], 10, 1126891415);
c = II(c, d, a, b, m[i + 14], 15, -1416354905);
b = II(b, c, d, a, m[i + 5], 21, -57434055);
a = II(a, b, c, d, m[i + 12], 6, 1700485571);
d = II(d, a, b, c, m[i + 3], 10, -1894986606);
c = II(c, d, a, b, m[i + 10], 15, -1051523);
b = II(b, c, d, a, m[i + 1], 21, -2054922799);
a = II(a, b, c, d, m[i + 8], 6, 1873313359);
d = II(d, a, b, c, m[i + 15], 10, -30611744);
c = II(c, d, a, b, m[i + 6], 15, -1560198380);
b = II(b, c, d, a, m[i + 13], 21, 1309151649);
a = II(a, b, c, d, m[i + 4], 6, -145523070);
d = II(d, a, b, c, m[i + 11], 10, -1120210379);
c = II(c, d, a, b, m[i + 2], 15, 718787259);
b = II(b, c, d, a, m[i + 9], 21, -343485551);
a = a + aa >>> 0;
b = b + bb >>> 0;
c = c + cc >>> 0;
d = d + dd >>> 0;
}
return crypt.endian([a, b, c, d]);
};
// Auxiliary functions
md5._ff = function (a, b, c, d, x, s, t) {
var n = a + (b & c | ~b & d) + (x >>> 0) + t;
return (n << s | n >>> 32 - s) + b;
};
md5._gg = function (a, b, c, d, x, s, t) {
var n = a + (b & d | c & ~d) + (x >>> 0) + t;
return (n << s | n >>> 32 - s) + b;
};
md5._hh = function (a, b, c, d, x, s, t) {
var n = a + (b ^ c ^ d) + (x >>> 0) + t;
return (n << s | n >>> 32 - s) + b;
};
md5._ii = function (a, b, c, d, x, s, t) {
var n = a + (c ^ (b | ~d)) + (x >>> 0) + t;
return (n << s | n >>> 32 - s) + b;
};
// Package private blocksize
md5._blocksize = 16;
md5._digestsize = 16;
module.exports = function (message, options) {
if (message === undefined || message === null) throw new Error('Illegal argument ' + message);
var digestbytes = crypt.wordsToBytes(md5(message, options));
return options && options.asBytes ? digestbytes : options && options.asString ? bin.bytesToString(digestbytes) : crypt.bytesToHex(digestbytes);
};
})();
}, { "charenc": 2, "crypt": 4, "is-buffer": 11 }], 14: [function (require, module, exports) {
/**
* Helpers.
*/
var s = 1000;
var m = s * 60;
var h = m * 60;
var d = h * 24;
var y = d * 365.25;
/**
* Parse or format the given `val`.
*
* Options:
*
* - `long` verbose formatting [false]
*
* @param {String|Number} val
* @param {Object} options
* @throws {Error} thr