text: (function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
    typeof define === 'function' && define.amd ? define(factory) :
    (global = global || self, global.ICanvasWxgame = factory());
  }(this, (function () { 'use strict';
  
    function _defineProperty(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;
    }
  
    var defineProperty = _defineProperty;
  
    var has = Object.prototype.hasOwnProperty;
    var isArray = Array.isArray;
  
    var hexTable = (function () {
        var array = [];
        for (var i = 0; i < 256; ++i) {
            array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
        }
  
        return array;
    }());
  
    var compactQueue = function compactQueue(queue) {
        while (queue.length > 1) {
            var item = queue.pop();
            var obj = item.obj[item.prop];
  
            if (isArray(obj)) {
                var compacted = [];
  
                for (var j = 0; j < obj.length; ++j) {
                    if (typeof obj[j] !== 'undefined') {
                        compacted.push(obj[j]);
                    }
                }
  
                item.obj[item.prop] = compacted;
            }
        }
    };
  
    var arrayToObject = function arrayToObject(source, options) {
        var obj = options && options.plainObjects ? Object.create(null) : {};
        for (var i = 0; i < source.length; ++i) {
            if (typeof source[i] !== 'undefined') {
                obj[i] = source[i];
            }
        }
  
        return obj;
    };
  
    var merge = function merge(target, source, options) {
        /* eslint no-param-reassign: 0 */
        if (!source) {
            return target;
        }
  
        if (typeof source !== 'object') {
            if (isArray(target)) {
                target.push(source);
            } else if (target && typeof target === 'object') {
                if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
                    target[source] = true;
                }
            } else {
                return [target, source];
            }
  
            return target;
        }
  
        if (!target || typeof target !== 'object') {
            return [target].concat(source);
        }
  
        var mergeTarget = target;
        if (isArray(target) && !isArray(source)) {
            mergeTarget = arrayToObject(target, options);
        }
  
        if (isArray(target) && isArray(source)) {
            source.forEach(function (item, i) {
                if (has.call(target, i)) {
                    var targetItem = target[i];
                    if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
                        target[i] = merge(targetItem, item, options);
                    } else {
                        target.push(item);
                    }
                } else {
                    target[i] = item;
                }
            });
            return target;
        }
  
        return Object.keys(source).reduce(function (acc, key) {
            var value = source[key];
  
            if (has.call(acc, key)) {
                acc[key] = merge(acc[key], value, options);
            } else {
                acc[key] = value;
            }
            return acc;
        }, mergeTarget);
    };
  
    var assign = function assignSingleSource(target, source) {
        return Object.keys(source).reduce(function (acc, key) {
            acc[key] = source[key];
            return acc;
        }, target);
    };
  
    var decode = function (str, decoder, charset) {
        var strWithoutPlus = str.replace(/\+/g, ' ');
        if (charset === 'iso-8859-1') {
            // unescape never throws, no try...catch needed:
            return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
        }
        // utf-8
        try {
            return decodeURIComponent(strWithoutPlus);
        } catch (e) {
            return strWithoutPlus;
        }
    };
  
    var encode = function encode(str, defaultEncoder, charset) {
        // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
        // It has been adapted here for stricter adherence to RFC 3986
        if (str.length === 0) {
            return str;
        }
  
        var string = str;
        if (typeof str === 'symbol') {
            string = Symbol.prototype.toString.call(str);
        } else if (typeof str !== 'string') {
            string = String(str);
        }
  
        if (charset === 'iso-8859-1') {
            return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
                return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
            });
        }
  
        var out = '';
        for (var i = 0; i < string.length; ++i) {
            var c = string.charCodeAt(i);
  
            if (
                c === 0x2D // -
                || c === 0x2E // .
                || c === 0x5F // _
                || c === 0x7E // ~
                || (c >= 0x30 && c <= 0x39) // 0-9
                || (c >= 0x41 && c <= 0x5A) // a-z
                || (c >= 0x61 && c <= 0x7A) // A-Z
            ) {
                out += string.charAt(i);
                continue;
            }
  
            if (c < 0x80) {
                out = out + hexTable[c];
                continue;
            }
  
            if (c < 0x800) {
                out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
                continue;
            }
  
            if (c < 0xD800 || c >= 0xE000) {
                out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
                continue;
            }
  
            i += 1;
            c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
            out += hexTable[0xF0 | (c >> 18)]
                + hexTable[0x80 | ((c >> 12) & 0x3F)]
                + hexTable[0x80 | ((c >> 6) & 0x3F)]
                + hexTable[0x80 | (c & 0x3F)];
        }
  
        return out;
    };
  
    var compact = function compact(value) {
        var queue = [{ obj: { o: value }, prop: 'o' }];
        var refs = [];
  
        for (var i = 0; i < queue.length; ++i) {
            var item = queue[i];
            var obj = item.obj[item.prop];
  
            var keys = Object.keys(obj);
            for (var j = 0; j < keys.length; ++j) {
                var key = keys[j];
                var val = obj[key];
                if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
                    queue.push({ obj: obj, prop: key });
                    refs.push(val);
                }
            }
        }
  
        compactQueue(queue);
  
        return value;
    };
  
    var isRegExp = function isRegExp(obj) {
        return Object.prototype.toString.call(obj) === '[object RegExp]';
    };
  
    var isBuffer = function isBuffer(obj) {
        if (!obj || typeof obj !== 'object') {
            return false;
        }
  
        return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
    };
  
    var combine = function combine(a, b) {
        return [].concat(a, b);
    };
  
    var utils = {
        arrayToObject: arrayToObject,
        assign: assign,
        combine: combine,
        compact: compact,
        decode: decode,
        encode: encode,
        isBuffer: isBuffer,
        isRegExp: isRegExp,
        merge: merge
    };
  
    var replace = String.prototype.replace;
    var percentTwenties = /%20/g;
  
  
  
    var Format = {
        RFC1738: 'RFC1738',
        RFC3986: 'RFC3986'
    };
  
    var formats = utils.assign(
        {
            'default': Format.RFC3986,
            formatters: {
                RFC1738: function (value) {
                    return replace.call(value, percentTwenties, '+');
                },
                RFC3986: function (value) {
                    return String(value);
                }
            }
        },
        Format
    );
  
    var has$1 = Object.prototype.hasOwnProperty;
  
    var arrayPrefixGenerators = {
        brackets: function brackets(prefix) {
            return prefix + '[]';
        },
        comma: 'comma',
        indices: function indices(prefix, key) {
            return prefix + '[' + key + ']';
        },
        repeat: function repeat(prefix) {
            return prefix;
        }
    };
  
    var isArray$1 = Array.isArray;
    var push = Array.prototype.push;
    var pushToArray = function (arr, valueOrArray) {
        push.apply(arr, isArray$1(valueOrArray) ? valueOrArray : [valueOrArray]);
    };
  
    var toISO = Date.prototype.toISOString;
  
    var defaultFormat = formats['default'];
    var defaults = {
        addQueryPrefix: false,
        allowDots: false,
        charset: 'utf-8',
        charsetSentinel: false,
        delimiter: '&',
        encode: true,
        encoder: utils.encode,
        encodeValuesOnly: false,
        format: defaultFormat,
        formatter: formats.formatters[defaultFormat],
        // deprecated
        indices: false,
        serializeDate: function serializeDate(date) {
            return toISO.call(date);
        },
        skipNulls: false,
        strictNullHandling: false
    };
  
    var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
        return typeof v === 'string'
            || typeof v === 'number'
            || typeof v === 'boolean'
            || typeof v === 'symbol'
            || typeof v === 'bigint';
    };
  
    var stringify = function stringify(
        object,
        prefix,
        generateArrayPrefix,
        strictNullHandling,
        skipNulls,
        encoder,
        filter,
        sort,
        allowDots,
        serializeDate,
        formatter,
        encodeValuesOnly,
        charset
    ) {
        var obj = object;
        if (typeof filter === 'function') {
            obj = filter(prefix, obj);
        } else if (obj instanceof Date) {
            obj = serializeDate(obj);
        } else if (generateArrayPrefix === 'comma' && isArray$1(obj)) {
            obj = obj.join(',');
        }
  
        if (obj === null) {
            if (strictNullHandling) {
                return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key') : prefix;
            }
  
            obj = '';
        }
  
        if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
            if (encoder) {
                var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key');
                return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value'))];
            }
            return [formatter(prefix) + '=' + formatter(String(obj))];
        }
  
        var values = [];
  
        if (typeof obj === 'undefined') {
            return values;
        }
  
        var objKeys;
        if (isArray$1(filter)) {
            objKeys = filter;
        } else {
            var keys = Object.keys(obj);
            objKeys = sort ? keys.sort(sort) : keys;
        }
  
        for (var i = 0; i < objKeys.length; ++i) {
            var key = objKeys[i];
  
            if (skipNulls && obj[key] === null) {
                continue;
            }
  
            if (isArray$1(obj)) {
                pushToArray(values, stringify(
                    obj[key],
                    typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix,
                    generateArrayPrefix,
                    strictNullHandling,
                    skipNulls,
                    encoder,
                    filter,
                    sort,
                    allowDots,
                    serializeDate,
                    formatter,
                    encodeValuesOnly,
                    charset
                ));
            } else {
                pushToArray(values, stringify(
                    obj[key],
                    prefix + (allowDots ? '.' + key : '[' + key + ']'),
                    generateArrayPrefix,
                    strictNullHandling,
                    skipNulls,
                    encoder,
                    filter,
                    sort,
                    allowDots,
                    serializeDate,
                    formatter,
                    encodeValuesOnly,
                    charset
                ));
            }
        }
  
        return values;
    };
  
    var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
        if (!opts) {
            return defaults;
        }
  
        if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
            throw new TypeError('Encoder has to be a function.');
        }
  
        var charset = opts.charset || defaults.charset;
        if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
            throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
        }
  
        var format = formats['default'];
        if (typeof opts.format !== 'undefined') {
            if (!has$1.call(formats.formatters, opts.format)) {
                throw new TypeError('Unknown format option provided.');
            }
            format = opts.format;
        }
        var formatter = formats.formatters[format];
  
        var filter = defaults.filter;
        if (typeof opts.filter === 'function' || isArray$1(opts.filter)) {
            filter = opts.filter;
        }
  
        return {
            addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
            allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
            charset: charset,
            charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
            delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
            encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
            encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
            encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
            filter: filter,
            formatter: formatter,
            serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
            skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
            sort: typeof opts.sort === 'function' ? opts.sort : null,
            strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
        };
    };
  
    var stringify_1 = function (object, opts) {
        var obj = object;
        var options = normalizeStringifyOptions(opts);
  
        var objKeys;
        var filter;
  
        if (typeof options.filter === 'function') {
            filter = options.filter;
            obj = filter('', obj);
        } else if (isArray$1(options.filter)) {
            filter = options.filter;
            objKeys = filter;
        }
  
        var keys = [];
  
        if (typeof obj !== 'object' || obj === null) {
            return '';
        }
  
        var arrayFormat;
        if (opts && opts.arrayFormat in arrayPrefixGenerators) {
            arrayFormat = opts.arrayFormat;
        } else if (opts && 'indices' in opts) {
            arrayFormat = opts.indices ? 'indices' : 'repeat';
        } else {
            arrayFormat = 'indices';
        }
  
        var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
  
        if (!objKeys) {
            objKeys = Object.keys(obj);
        }
  
        if (options.sort) {
            objKeys.sort(options.sort);
        }
  
        for (var i = 0; i < objKeys.length; ++i) {
            var key = objKeys[i];
  
            if (options.skipNulls && obj[key] === null) {
                continue;
            }
            pushToArray(keys, stringify(
                obj[key],
                key,
                generateArrayPrefix,
                options.strictNullHandling,
                options.skipNulls,
                options.encode ? options.encoder : null,
                options.filter,
                options.sort,
                options.allowDots,
                options.serializeDate,
                options.formatter,
                options.encodeValuesOnly,
                options.charset
            ));
        }
  
        var joined = keys.join(options.delimiter);
        var prefix = options.addQueryPrefix === true ? '?' : '';
  
        if (options.charsetSentinel) {
            if (options.charset === 'iso-8859-1') {
                // encodeURIComponent('&#10003;'), the "numeric entity" representation of a checkmark
                prefix += 'utf8=%26%2310003%3B&';
            } else {
                // encodeURIComponent('✓')
                prefix += 'utf8=%E2%9C%93&';
            }
        }
  
        return joined.length > 0 ? prefix + joined : '';
    };
  
    var has$2 = Object.prototype.hasOwnProperty;
    var isArray$2 = Array.isArray;
  
    var defaults$1 = {
        allowDots: false,
        allowPrototypes: false,
        arrayLimit: 20,
        charset: 'utf-8',
        charsetSentinel: false,
        comma: false,
        decoder: utils.decode,
        delimiter: '&',
        depth: 5,
        ignoreQueryPrefix: false,
        interpretNumericEntities: false,
        parameterLimit: 1000,
        parseArrays: true,
        plainObjects: false,
        strictNullHandling: false
    };
  
    var interpretNumericEntities = function (str) {
        return str.replace(/&#(\d+);/g, function ($0, numberStr) {
            return String.fromCharCode(parseInt(numberStr, 10));
        });
    };
  
    // This is what browsers will submit when the ✓ character occurs in an
    // application/x-www-form-urlencoded body and the encoding of the page containing
    // the form is iso-8859-1, or when the submitted form has an accept-charset
    // attribute of iso-8859-1. Presumably also with other charsets that do not contain
    // the ✓ character, such as us-ascii.
    var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('&#10003;')
  
    // These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
    var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
  
    var parseValues = function parseQueryStringValues(str, options) {
        var obj = {};
        var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
        var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
        var parts = cleanStr.split(options.delimiter, limit);
        var skipIndex = -1; // Keep track of where the utf8 sentinel was found
        var i;
  
        var charset = options.charset;
        if (options.charsetSentinel) {
            for (i = 0; i < parts.length; ++i) {
                if (parts[i].indexOf('utf8=') === 0) {
                    if (parts[i] === charsetSentinel) {
                        charset = 'utf-8';
                    } else if (parts[i] === isoSentinel) {
                        charset = 'iso-8859-1';
                    }
                    skipIndex = i;
                    i = parts.length; // The eslint settings do not allow break;
                }
            }
        }
  
        for (i = 0; i < parts.length; ++i) {
            if (i === skipIndex) {
                continue;
            }
            var part = parts[i];
  
            var bracketEqualsPos = part.indexOf(']=');
            var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
  
            var key, val;
            if (pos === -1) {
                key = options.decoder(part, defaults$1.decoder, charset, 'key');
                val = options.strictNullHandling ? null : '';
            } else {
                key = options.decoder(part.slice(0, pos), defaults$1.decoder, charset, 'key');
                val = options.decoder(part.slice(pos + 1), defaults$1.decoder, charset, 'value');
            }
  
            if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
                val = interpretNumericEntities(val);
            }
  
            if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
                val = val.split(',');
            }
  
            if (part.indexOf('[]=') > -1) {
                val = isArray$2(val) ? [val] : val;
            }
  
            if (has$2.call(obj, key)) {
                obj[key] = utils.combine(obj[key], val);
            } else {
                obj[key] = val;
            }
        }
  
        return obj;
    };
  
    var parseObject = function (chain, val, options) {
        var leaf = val;
  
        for (var i = chain.length - 1; i >= 0; --i) {
            var obj;
            var root = chain[i];
  
            if (root === '[]' && options.parseArrays) {
                obj = [].concat(leaf);
            } else {
                obj = options.plainObjects ? Object.create(null) : {};
                var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
                var index = parseInt(cleanRoot, 10);
                if (!options.parseArrays && cleanRoot === '') {
                    obj = { 0: leaf };
                } else if (
                    !isNaN(index)
                    && root !== cleanRoot
                    && String(index) === cleanRoot
                    && index >= 0
                    && (options.parseArrays && index <= options.arrayLimit)
                ) {
                    obj = [];
                    obj[index] = leaf;
                } else {
                    obj[cleanRoot] = leaf;
                }
            }
  
            leaf = obj;
        }
  
        return leaf;
    };
  
    var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
        if (!givenKey) {
            return;
        }
  
        // Transform dot notation to bracket notation
        var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
  
        // The regex chunks
  
        var brackets = /(\[[^[\]]*])/;
        var child = /(\[[^[\]]*])/g;
  
        // Get the parent
  
        var segment = options.depth > 0 && brackets.exec(key);
        var parent = segment ? key.slice(0, segment.index) : key;
  
        // Stash the parent if it exists
  
        var keys = [];
        if (parent) {
            // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
            if (!options.plainObjects && has$2.call(Object.prototype, parent)) {
                if (!options.allowPrototypes) {
                    return;
                }
            }
  
            keys.push(parent);
        }
  
        // Loop through children appending to the array until we hit depth
  
        var i = 0;
        while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
            i += 1;
            if (!options.plainObjects && has$2.call(Object.prototype, segment[1].slice(1, -1))) {
                if (!options.allowPrototypes) {
                    return;
                }
            }
            keys.push(segment[1]);
        }
  
        // If there's a remainder, just add whatever is left
  
        if (segment) {
            keys.push('[' + key.slice(segment.index) + ']');
        }
  
        return parseObject(keys, val, options);
    };
  
    var normalizeParseOptions = function normalizeParseOptions(opts) {
        if (!opts) {
            return defaults$1;
        }
  
        if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
            throw new TypeError('Decoder has to be a function.');
        }
  
        if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
            throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
        }
        var charset = typeof opts.charset === 'undefined' ? defaults$1.charset : opts.charset;
  
        return {
            allowDots: typeof opts.allowDots === 'undefined' ? defaults$1.allowDots : !!opts.allowDots,
            allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults$1.allowPrototypes,
            arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults$1.arrayLimit,
            charset: charset,
            charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults$1.charsetSentinel,
            comma: typeof opts.comma === 'boolean' ? opts.comma : defaults$1.comma,
            decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults$1.decoder,
            delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults$1.delimiter,
            // eslint-disable-next-line no-implicit-coercion, no-extra-parens
            depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults$1.depth,
            ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
            interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults$1.interpretNumericEntities,
            parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults$1.parameterLimit,
            parseArrays: opts.parseArrays !== false,
            plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults$1.plainObjects,
            strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults$1.strictNullHandling
        };
    };
  
    var parse = function (str, opts) {
        var options = normalizeParseOptions(opts);
  
        if (str === '' || str === null || typeof str === 'undefined') {
            return options.plainObjects ? Object.create(null) : {};
        }
  
        var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
        var obj = options.plainObjects ? Object.create(null) : {};
  
        // Iterate over the keys and setup the new object
  
        var keys = Object.keys(tempObj);
        for (var i = 0; i < keys.length; ++i) {
            var key = keys[i];
            var newObj = parseKeys(key, tempObj[key], options);
            obj = utils.merge(obj, newObj, options);
        }
  
        return utils.compact(obj);
    };
  
    var lib = {
        formats: formats,
        parse: parse,
        stringify: stringify_1
    };
  
    var qsConfig = {
      arrayFormat: 'indices',
      encodeValuesOnly: true
    };
  
    function mergeDefaultConfig() {
      var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var getMethods = arguments.length > 1 ? arguments[1] : undefined;
      var postMethods = arguments.length > 2 ? arguments[2] : undefined;
      var method = config.method || 'get';
      var baseURL = config.baseURL || '';
      var configHeaders = config.headers || {};
      var headers = {
        common: Object.assign({}, configHeaders.common)
      };
      getMethods.forEach(function (method) {
        headers[method] = Object.assign({}, configHeaders[method]);
      });
      postMethods.forEach(function (method) {
        headers[method] = Object.assign({}, configHeaders[method]);
      });
      var params = config.params ? JSON.parse(JSON.stringify(config.params)) : {};
      var data = config.data ? JSON.parse(JSON.stringify(config.data)) : {};
      return {
        method: method,
        baseURL: baseURL,
        headers: headers,
        params: params,
        data: data
      };
    }
  
    function request(defaultConfig) {
      var urlOrConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      var getConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
      var interceptors = arguments.length > 3 ? arguments[3] : undefined;
      var method = getConfig.method || urlOrConfig.method || defaultConfig.method;
      var header = Object.assign({}, defaultConfig.headers.common, defaultConfig.headers[method], urlOrConfig.header, getConfig.header);
      var url = (getConfig.baseURL || urlOrConfig.baseURL || defaultConfig.baseURL || '') + (getConfig.url || urlOrConfig.url || defaultConfig.url);
      var params = Object.assign({}, defaultConfig.params, urlOrConfig.params, getConfig.params);
      var data = Object.assign({}, defaultConfig.data, urlOrConfig.data, getConfig.data);
      var dataType = getConfig.dataType || urlOrConfig.dataType || defaultConfig.dataType || 'json';
      var responseType = getConfig.responseType || urlOrConfig.responseType || defaultConfig.responseType || 'text';
  
      if (method == 'get') {
        params = Object.assign(data, params);
        data = null;
      }
  
      var promiseConfig = Promise.resolve({
        method: method,
        url: url + '?' + lib.stringify(params, qsConfig),
        data: data,
        header: header,
        dataType: dataType,
        responseType: responseType
      });
      var transformRequest = getConfig.transformRequest || urlOrConfig.transformRequest || interceptors.request.transform;
  
      if (transformRequest) {
        promiseConfig = transformRequest.reduce(function (promise, fn) {
          if (!fn) return promise;
          if (typeof fn == 'function') return promise.then(function (res) {
            return fn(res) || res;
          });
          if (fn.resolve) promise = promise.then(function (res) {
            return fn.resolve(res) || res;
          });
          if (fn.reject) promise = promise["catch"](function (res) {
            return fn.reject(res) || res;
          });
          return promise;
        }, promiseConfig);
      }
  
      var promiseRequest = promiseConfig.then(function (Config) {
        return new Promise(function (resolve, reject) {
          Config.success = function (res) {
            Config.response = res;
            resolve(Config);
          };
  
          Config.fail = function (res) {
            Config.error = res;
            reject(Config);
          };
  
          wx.request(Config);
        });
      });
      var transformResponse = getConfig.transformResponse || urlOrConfig.transformResponse || interceptors.response.transform;
  
      if (transformResponse) {
        promiseRequest = transformResponse.reduce(function (promise, fn) {
          if (!fn) return promise;
          if (typeof fn == 'function') return promise.then(function (res) {
            return fn(res) || res;
          });
          if (fn.resolve) promise = promise.then(function (res) {
            return fn.resolve(res) || res;
          });
          if (fn.reject) promise = promise["catch"](function (res) {
            return fn.reject(res) || res;
          });
          return promise;
        }, promiseRequest);
      }
  
      return promiseRequest;
    }
  
    function createInterceptors(resolve, reject) {
      this.transform.push(reject ? {
        resolve: resolve,
        reject: reject
      } : resolve);
      return this;
    }
  
    function createInstance(defaultConfig) {
      var getMethods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['get'];
      var postMethods = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['post'];
  
      var axios = function axios(urlOrConfig, getConfig) {
        if (typeof urlOrConfig == 'string') {
          urlOrConfig = {
            url: urlOrConfig,
            method: 'get'
          };
        }
  
        return request(axios.defaults, urlOrConfig, getConfig, axios.interceptors);
      };
  
      axios.defaults = mergeDefaultConfig(defaultConfig, getMethods, postMethods);
      axios.interceptors = {
        request: {
          transform: [],
          use: createInterceptors
        },
        response: {
          transform: [],
          use: createInterceptors
        }
      };
      axios.create = createInstance;
      axios.request = axios;
      getMethods.forEach(function (method) {
        axios[method] = function (url, params, config) {
          return axios({
            url: url,
            method: method,
            params: params
          }, config);
        };
      });
      postMethods.forEach(function (method) {
        axios[method] = function (url, data, config) {
          return axios({
            url: url,
            method: method,
            data: data
          }, config);
        };
      });
      return axios;
    }
  
    function _classCallCheck(instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    }
  
    var classCallCheck = _classCallCheck;
  
    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);
      }
    }
  
    function _createClass(Constructor, protoProps, staticProps) {
      if (protoProps) _defineProperties(Constructor.prototype, protoProps);
      if (staticProps) _defineProperties(Constructor, staticProps);
      return Constructor;
    }
  
    var createClass = _createClass;
  
    var Audio =
    /*#__PURE__*/
    function () {
      function Audio(src) {
        var _this = this;
  
        classCallCheck(this, Audio);
  
        this._source = wx.createInnerAudioContext();
        this._state = 0; //开始、载入中、载入完毕、已卸载
  
        this._currentTime = 0;
        this._loop = false;
        this._volume = 1;
        this._muted = false;
        this._paused = true;
  
        this._source.onCanplay(function () {
          if (_this._state !== 1) return;
          if (_this.oncanplay) _this.oncanplay();
          _this._state = 2;
          _this._source.loop = _this._loop;
          _this._source.volume = _this._muted ? 0 : _this._volume;
          if (_this._currentTime) _this._source.seek(_this._currentTime);
          if (!_this._paused) _this._source.play();
        });
  
        this._source.onEnded(function () {
          if (_this.onended) _this.onended();
          _this.paused = !_this.loop;
        });
  
        if (src) this.src = src;
      }
  
      createClass(Audio, [{
        key: "play",
        value: function play() {
          this._paused = false;
          if (this._state == 2) this._source.play();
        }
      }, {
        key: "pause",
        value: function pause() {
          this._paused = true;
          if (this._state == 2) this._source.pause();
        }
      }, {
        key: "destroy",
        value: function destroy() {
          if (this._state == 3) return;
          this._state = 3;
  
          this._source.stop();
  
          this._source.destroy();
        }
      }, {
        key: "duration",
        get: function get() {
          if (this._state !== 2) return 0;
          return this._source.duration;
        }
      }, {
        key: "currentTime",
        get: function get() {
          if (this._state !== 2) return 0;
          return this._source.currentTime;
        },
        set: function set(currentTime) {
          this._currentTime = currentTime;
          if (this._state == 2) this._source.seek(currentTime);
        }
      }, {
        key: "loop",
        get: function get() {
          return this._loop;
        },
        set: function set(loop) {
          this._loop = loop;
          if (this._state == 2) this._source.loop = loop;
        }
      }, {
        key: "volume",
        get: function get() {
          return this._volume;
        },
        set: function set(volume) {
          this._volume = volume;
          if (this._state == 2) this._source.volume = volume;
        }
      }, {
        key: "muted",
        get: function get() {
          return this._muted;
        },
        set: function set(muted) {
          this._muted = muted;
          if (this._state == 2) this._source.volume = muted ? 0 : this._volume;
        }
      }, {
        key: "paused",
        get: function get() {
          return this._paused;
        },
        set: function set(paused) {
          paused ? this.pause() : this.play();
        }
      }, {
        key: "src",
        get: function get() {
          return this._source.src;
        },
        set: function set(src) {
          if (this._state !== 0) return;
          this._state = 1;
          this._source.src = src;
        }
      }]);
  
      return Audio;
    }();
  
    function polyfill() {
      if (GameGlobal.axios) return;
  
      if (!GameGlobal.document) {
        GameGlobal.document = {};
  
        GameGlobal.document.createElement = function (type) {
          if (type == 'canvas') return wx.createCanvas();
          if (type == 'image') return wx.createImage();
          if (type == 'audio') return new Audio();
        };
      }
  
      GameGlobal.document.mainCanvas = wx.createCanvas();
  
      GameGlobal.Image = function () {
        return wx.createImage();
      };
  
      GameGlobal.Audio = Audio;
  
      GameGlobal.addEventListener = function (type, callback) {
        if (type == 'touchstart') return wx.onTouchStart(callback);
        if (type == 'touchmove') return wx.onTouchMove(callback);
        if (type == 'touchend') return wx.onTouchEnd(callback);
        if (type == 'touchcancel') return wx.onTouchCancel(callback);
      };
      /**
       * 大致模拟axios
       */
  
  
      GameGlobal.axios = createInstance();
      /**
       * 将微信方法进行变种
       * @param {string} action 方法名
       * @param {Any} root 根元素/上下文
       * @param {Number} mode 变种方式 0:Promise返回success和fail,1:Promise返回执行结果,2:原样子调用
       */
  
      GameGlobal.vary = function (action) {
        var root = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : wx;
        var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  
        if (mode == 2) {
          return root[action];
        } else if (mode == 1) {
          return function (args, key) {
            return new Promise(function (resolve) {
              return resolve(root[action](key ? defineProperty({}, key, args) : args));
            });
          };
        } else if (mode == 0) {
          return function (args, key) {
            return new Promise(function (success, fail) {
              return root[action](Object.assign({
                success: success,
                fail: fail
              }, key ? defineProperty({}, key, args) : args));
            });
          };
        }
      };
    }
  
    return polyfill;
  
  })));
  