UNPKG

@onesy/huffman-code

Version:
1,257 lines (1,106 loc) 82.3 kB
/** @license HuffmanCode v1.0.0 * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HuffmanCode = 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 global$1 = (typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function getAugmentedNamespace(n) { if (n.__esModule) return n; var a = Object.defineProperty({}, '__esModule', {value: true}); Object.keys(n).forEach(function (k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { enumerable: true, get: function () { return n[k]; } }); }); return a; } var is$1 = {exports: {}}; (function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); const optionsDefault = {}; const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; const isNodejs = !!(typeof global$1 !== 'undefined' && 'object' !== 'undefined' && module.exports); // Multiple is methods instead of one, // so it's lighter for tree shaking usability reasons function is(type, value, options_ = {}) { var _a; const options = Object.assign(Object.assign({}, optionsDefault), options_); const { variant } = options; const prototype = value && typeof value === 'object' && Object.getPrototypeOf(value); switch (type) { case 'string': return typeof value === 'string'; case 'number': return typeof value === 'number' && !Number.isNaN(value); case 'boolean': return typeof value === 'boolean'; case 'array': return Array.isArray(value); case 'object': const isObject = typeof value === 'object' && !!value && value.constructor === Object; return isObject; // Map, null, WeakMap, Date, etc. case 'object-like': return typeof value === 'object' && (value === null || value.constructor !== Object); case 'class': return ((typeof value === 'object' || typeof value === 'function') && (/class/gi.test(String(value)) || /class/gi.test(String(value === null || value === void 0 ? void 0 : value.constructor)))); case 'function': return !!(value && value instanceof Function); case 'async': // If it's browser avoid calling the method // to see if it's async func or not, // where as in nodejs we have no other choice // that i know of when using transpilation // And also it might not be always correct, as // a method that returns a promise is also async // but we can't know that until the method is called and // we inspect the method's return value return !!(is('function', value) && (isBrowser ? value.constructor.name === 'AsyncFunction' : value() instanceof Promise)); case 'map': return !!(prototype === Map.prototype); case 'weakmap': return !!(prototype === WeakMap.prototype); case 'set': return !!(prototype === Set.prototype); case 'weakset': return !!(prototype === WeakSet.prototype); case 'promise': return !!(prototype === Promise.prototype); case 'int8array': return !!(prototype === Int8Array.prototype); case 'uint8array': return !!(prototype === Uint8Array.prototype); case 'uint8clampedarray': return !!(prototype === Uint8ClampedArray.prototype); case 'int16array': return !!(prototype === Int16Array.prototype); case 'uint16array': return !!(prototype === Uint16Array.prototype); case 'int32array': return !!(prototype === Int32Array.prototype); case 'uint32array': return !!(prototype === Uint32Array.prototype); case 'float32array': return !!(prototype === Float32Array.prototype); case 'float64array': return !!(prototype === Float64Array.prototype); case 'bigint64array': return !!(prototype === BigInt64Array.prototype); case 'biguint64array': return !!(prototype === BigUint64Array.prototype); case 'typedarray': return is('int8array', value) || is('uint8array', value) || is('uint8clampedarray', value) || is('int16array', value) || is('uint16array', value) || is('int32array', value) || is('uint32array', value) || is('float32array', value) || is('float64array', value) || is('bigint64array', value) || is('biguint64array', value); case 'dataview': return !!(prototype === DataView.prototype); case 'arraybuffer': return !!(prototype === ArrayBuffer.prototype); case 'sharedarraybuffer': return typeof SharedArrayBuffer !== 'undefined' && !!(prototype === SharedArrayBuffer.prototype); case 'symbol': return !!(typeof value === 'symbol'); case 'error': return !!(value && value instanceof Error); case 'date': return !!(value && value instanceof Date); case 'regexp': return !!(value && value instanceof RegExp); case 'arguments': return !!(value && value.toString() === '[object Arguments]'); case 'null': return value === null; case 'undefined': return value === undefined; case 'blob': return isBrowser && value instanceof Blob; case 'buffer': return !!(isNodejs && typeof ((_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === 'function' && value.constructor.isBuffer(value)); case 'element': if (value) { switch (variant) { case undefined: case 'html': case 'element': return isBrowser && (typeof HTMLElement === 'object' ? value instanceof HTMLElement : value && typeof value === 'object' && value !== null && value.nodeType === 1 && typeof value.nodeName === 'string'); case 'node': return isBrowser && (typeof Node === 'object' ? value instanceof Node : value && typeof value === 'object' && value !== null && typeof value.nodeType === 'number' && typeof value.nodeName === 'string'); case 'react': return value.elementType || value.hasOwnProperty('$$typeof'); default: return false; } } return false; case 'simple': return (is('string', value, options) || is('number', value, options) || is('boolean', value, options) || is('undefined', value, options) || is('null', value, options)); case 'not-array-object': return !is('array', value, options) && !is('object', value, options); default: return false; } } exports.default = is; }(is$1, is$1.exports)); var is = /*@__PURE__*/getDefaultExportFromCjs(is$1.exports); var merge$1 = {}; var copy$1 = {}; Object.defineProperty(copy$1, "__esModule", { value: true }); const isArray = value => Array.isArray(value); const isObject = value => typeof value === 'object' && !!value && value.constructor === Object; // It keeps the references of the methods and classes, // unlike JSON.stringify usually used for deep simple copy const copy = (value, values_) => { const values = !values_ ? new WeakSet() : values_; // Ref circular value if (values.has(value)) return value; if (isObject(value) || isArray(value)) values.add(value); if (isArray(value)) return value.map(item => copy(item, values)); if (isObject(value)) { const newValue = {}; Object.keys(value).forEach(key => newValue[key] = copy(value[key], values)); return newValue; } return value; }; var _default$4 = copy$1.default = copy; var __importDefault$7 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(merge$1, "__esModule", { value: true }); const is_1$5 = __importDefault$7(is$1.exports); const copy_1 = __importDefault$7(copy$1); const optionsDefault$3 = { copy: false, merge: { array: false, }, }; const merge = (target, source, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault$3), options_); if (options.merge.array && (0, is_1$5.default)('array', target) && (0, is_1$5.default)('array', source)) { const length = Math.max(target.length, source.length); for (let i = 0; i < length; i++) { if (target[i] === undefined) target[i] = source[i]; if (((0, is_1$5.default)('object', target[i]) && (0, is_1$5.default)('object', source[i])) || (0, is_1$5.default)('array', target[i]) && (0, is_1$5.default)('array', source[i])) target[i] = merge(target[i], source[i], options); } } if ((0, is_1$5.default)('object', target) && (0, is_1$5.default)('object', source)) { Object.keys(source).forEach(key => { // We only care about direct target object properties // not about inherited properties from a prototype chain if (target.hasOwnProperty(key)) { if ((0, is_1$5.default)('object', target[key]) && (0, is_1$5.default)('object', source[key])) target[key] = merge(target[key], source[key], options); } else target[key] = options.copy ? (0, copy_1.default)(source[key]) : source[key]; }); } return target; }; var _default$3 = merge$1.default = merge; var to$1 = {}; var isValid$1 = {}; // Unique ID creation requires a high quality random # generator. In the browser we therefore // require the crypto API and do not support built-in fallback to lower quality random number // generators (like Math.random()). var getRandomValues; var rnds8 = new Uint8Array(16); function rng() { // lazy load so that environments that need to polyfill have a chance to do so if (!getRandomValues) { // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also, // find the complete implementation of crypto (msCrypto) on IE11. getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto); if (!getRandomValues) { throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'); } } return getRandomValues(rnds8); } var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; function validate(uuid) { return typeof uuid === 'string' && REGEX.test(uuid); } /** * Convert array of 16 byte values to UUID string format of the form: * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */ var byteToHex = []; for (var i = 0; i < 256; ++i) { byteToHex.push((i + 0x100).toString(16).substr(1)); } function stringify$2(arr) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; // Note: Be careful editing this code! It's been tuned for performance // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434 var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one // of the following: // - One or more input array values don't map to a hex octet (leading to // "undefined" in the uuid) // - Invalid input values for the RFC `version` or `variant` fields if (!validate(uuid)) { throw TypeError('Stringified UUID is invalid'); } return uuid; } // // Inspired by https://github.com/LiosK/UUID.js // and http://docs.python.org/library/uuid.html var _nodeId; var _clockseq; // Previous uuid creation time var _lastMSecs = 0; var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details function v1(options, buf, offset) { var i = buf && offset || 0; var b = buf || new Array(16); options = options || {}; var node = options.node || _nodeId; var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not // specified. We do this lazily to minimize issues related to insufficient // system entropy. See #189 if (node == null || clockseq == null) { var seedBytes = options.random || (options.rng || rng)(); if (node == null) { // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1) node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]]; } if (clockseq == null) { // Per 4.2.2, randomize (14 bit) clockseq clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff; } } // UUID timestamps are 100 nano-second units since the Gregorian epoch, // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs' // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00. var msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock // cycle to simulate higher resolution clock var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs) var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression if (dt < 0 && options.clockseq === undefined) { clockseq = clockseq + 1 & 0x3fff; } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new // time interval if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) { nsecs = 0; } // Per 4.2.1.2 Throw error if too many uuids are requested if (nsecs >= 10000) { throw new Error("uuid.v1(): Can't create more than 10M uuids/sec"); } _lastMSecs = msecs; _lastNSecs = nsecs; _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch msecs += 12219292800000; // `time_low` var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; b[i++] = tl >>> 24 & 0xff; b[i++] = tl >>> 16 & 0xff; b[i++] = tl >>> 8 & 0xff; b[i++] = tl & 0xff; // `time_mid` var tmh = msecs / 0x100000000 * 10000 & 0xfffffff; b[i++] = tmh >>> 8 & 0xff; b[i++] = tmh & 0xff; // `time_high_and_version` b[i++] = tmh >>> 24 & 0xf | 0x10; // include version b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant) b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low` b[i++] = clockseq & 0xff; // `node` for (var n = 0; n < 6; ++n) { b[i + n] = node[n]; } return buf || stringify$2(b); } function parse(uuid) { if (!validate(uuid)) { throw TypeError('Invalid UUID'); } var v; var arr = new Uint8Array(16); // Parse ########-....-....-....-............ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24; arr[1] = v >>> 16 & 0xff; arr[2] = v >>> 8 & 0xff; arr[3] = v & 0xff; // Parse ........-####-....-....-............ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8; arr[5] = v & 0xff; // Parse ........-....-####-....-............ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8; arr[7] = v & 0xff; // Parse ........-....-....-####-............ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8; arr[9] = v & 0xff; // Parse ........-....-....-....-############ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes) arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff; arr[11] = v / 0x100000000 & 0xff; arr[12] = v >>> 24 & 0xff; arr[13] = v >>> 16 & 0xff; arr[14] = v >>> 8 & 0xff; arr[15] = v & 0xff; return arr; } function stringToBytes(str) { str = unescape(encodeURIComponent(str)); // UTF8 escape var bytes = []; for (var i = 0; i < str.length; ++i) { bytes.push(str.charCodeAt(i)); } return bytes; } var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; var URL$1 = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'; function v35 (name, version, hashfunc) { function generateUUID(value, namespace, buf, offset) { if (typeof value === 'string') { value = stringToBytes(value); } if (typeof namespace === 'string') { namespace = parse(namespace); } if (namespace.length !== 16) { throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)'); } // Compute hash of namespace and value, Per 4.3 // Future: Use spread syntax when supported on all platforms, e.g. `bytes = // hashfunc([...namespace, ... value])` var bytes = new Uint8Array(16 + value.length); bytes.set(namespace); bytes.set(value, namespace.length); bytes = hashfunc(bytes); bytes[6] = bytes[6] & 0x0f | version; bytes[8] = bytes[8] & 0x3f | 0x80; if (buf) { offset = offset || 0; for (var i = 0; i < 16; ++i) { buf[offset + i] = bytes[i]; } return buf; } return stringify$2(bytes); } // Function#name is not settable on some platforms (#270) try { generateUUID.name = name; // eslint-disable-next-line no-empty } catch (err) {} // For CommonJS default export support generateUUID.DNS = DNS; generateUUID.URL = URL$1; return generateUUID; } /* * Browser-compatible JavaScript MD5 * * Modification of JavaScript MD5 * https://github.com/blueimp/JavaScript-MD5 * * Copyright 2011, Sebastian Tschan * https://blueimp.net * * Licensed under the MIT license: * https://opensource.org/licenses/MIT * * Based on * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for more info. */ function md5(bytes) { if (typeof bytes === 'string') { var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape bytes = new Uint8Array(msg.length); for (var i = 0; i < msg.length; ++i) { bytes[i] = msg.charCodeAt(i); } } return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8)); } /* * Convert an array of little-endian words to an array of bytes */ function md5ToHexEncodedArray(input) { var output = []; var length32 = input.length * 32; var hexTab = '0123456789abcdef'; for (var i = 0; i < length32; i += 8) { var x = input[i >> 5] >>> i % 32 & 0xff; var hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16); output.push(hex); } return output; } /** * Calculate output length with padding and bit length */ function getOutputLength(inputLength8) { return (inputLength8 + 64 >>> 9 << 4) + 14 + 1; } /* * Calculate the MD5 of an array of little-endian words, and a bit length. */ function wordsToMd5(x, len) { /* append padding */ x[len >> 5] |= 0x80 << len % 32; x[getOutputLength(len) - 1] = len; var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for (var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = md5ff(a, b, c, d, x[i], 7, -680876936); d = md5ff(d, a, b, c, x[i + 1], 12, -389564586); c = md5ff(c, d, a, b, x[i + 2], 17, 606105819); b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330); a = md5ff(a, b, c, d, x[i + 4], 7, -176418897); d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426); c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341); b = md5ff(b, c, d, a, x[i + 7], 22, -45705983); a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416); d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417); c = md5ff(c, d, a, b, x[i + 10], 17, -42063); b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162); a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682); d = md5ff(d, a, b, c, x[i + 13], 12, -40341101); c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290); b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329); a = md5gg(a, b, c, d, x[i + 1], 5, -165796510); d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632); c = md5gg(c, d, a, b, x[i + 11], 14, 643717713); b = md5gg(b, c, d, a, x[i], 20, -373897302); a = md5gg(a, b, c, d, x[i + 5], 5, -701558691); d = md5gg(d, a, b, c, x[i + 10], 9, 38016083); c = md5gg(c, d, a, b, x[i + 15], 14, -660478335); b = md5gg(b, c, d, a, x[i + 4], 20, -405537848); a = md5gg(a, b, c, d, x[i + 9], 5, 568446438); d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690); c = md5gg(c, d, a, b, x[i + 3], 14, -187363961); b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501); a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467); d = md5gg(d, a, b, c, x[i + 2], 9, -51403784); c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473); b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734); a = md5hh(a, b, c, d, x[i + 5], 4, -378558); d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463); c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562); b = md5hh(b, c, d, a, x[i + 14], 23, -35309556); a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060); d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353); c = md5hh(c, d, a, b, x[i + 7], 16, -155497632); b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640); a = md5hh(a, b, c, d, x[i + 13], 4, 681279174); d = md5hh(d, a, b, c, x[i], 11, -358537222); c = md5hh(c, d, a, b, x[i + 3], 16, -722521979); b = md5hh(b, c, d, a, x[i + 6], 23, 76029189); a = md5hh(a, b, c, d, x[i + 9], 4, -640364487); d = md5hh(d, a, b, c, x[i + 12], 11, -421815835); c = md5hh(c, d, a, b, x[i + 15], 16, 530742520); b = md5hh(b, c, d, a, x[i + 2], 23, -995338651); a = md5ii(a, b, c, d, x[i], 6, -198630844); d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415); c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905); b = md5ii(b, c, d, a, x[i + 5], 21, -57434055); a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571); d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606); c = md5ii(c, d, a, b, x[i + 10], 15, -1051523); b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799); a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359); d = md5ii(d, a, b, c, x[i + 15], 10, -30611744); c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380); b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649); a = md5ii(a, b, c, d, x[i + 4], 6, -145523070); d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379); c = md5ii(c, d, a, b, x[i + 2], 15, 718787259); b = md5ii(b, c, d, a, x[i + 9], 21, -343485551); a = safeAdd(a, olda); b = safeAdd(b, oldb); c = safeAdd(c, oldc); d = safeAdd(d, oldd); } return [a, b, c, d]; } /* * Convert an array bytes to an array of little-endian words * Characters >255 have their high-byte silently ignored. */ function bytesToWords(input) { if (input.length === 0) { return []; } var length8 = input.length * 8; var output = new Uint32Array(getOutputLength(length8)); for (var i = 0; i < length8; i += 8) { output[i >> 5] |= (input[i / 8] & 0xff) << i % 32; } return output; } /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ function safeAdd(x, y) { var lsw = (x & 0xffff) + (y & 0xffff); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return msw << 16 | lsw & 0xffff; } /* * Bitwise rotate a 32-bit number to the left. */ function bitRotateLeft(num, cnt) { return num << cnt | num >>> 32 - cnt; } /* * These functions implement the four basic operations the algorithm uses. */ function md5cmn(q, a, b, x, s, t) { return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b); } function md5ff(a, b, c, d, x, s, t) { return md5cmn(b & c | ~b & d, a, b, x, s, t); } function md5gg(a, b, c, d, x, s, t) { return md5cmn(b & d | c & ~d, a, b, x, s, t); } function md5hh(a, b, c, d, x, s, t) { return md5cmn(b ^ c ^ d, a, b, x, s, t); } function md5ii(a, b, c, d, x, s, t) { return md5cmn(c ^ (b | ~d), a, b, x, s, t); } var v3 = v35('v3', 0x30, md5); var v3$1 = v3; function v4(options, buf, offset) { options = options || {}; var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` rnds[6] = rnds[6] & 0x0f | 0x40; rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided if (buf) { offset = offset || 0; for (var i = 0; i < 16; ++i) { buf[offset + i] = rnds[i]; } return buf; } return stringify$2(rnds); } // Adapted from Chris Veness' SHA1 code at // http://www.movable-type.co.uk/scripts/sha1.html function f(s, x, y, z) { switch (s) { case 0: return x & y ^ ~x & z; case 1: return x ^ y ^ z; case 2: return x & y ^ x & z ^ y & z; case 3: return x ^ y ^ z; } } function ROTL(x, n) { return x << n | x >>> 32 - n; } function sha1(bytes) { var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]; var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]; if (typeof bytes === 'string') { var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape bytes = []; for (var i = 0; i < msg.length; ++i) { bytes.push(msg.charCodeAt(i)); } } else if (!Array.isArray(bytes)) { // Convert Array-like to Array bytes = Array.prototype.slice.call(bytes); } bytes.push(0x80); var l = bytes.length / 4 + 2; var N = Math.ceil(l / 16); var M = new Array(N); for (var _i = 0; _i < N; ++_i) { var arr = new Uint32Array(16); for (var j = 0; j < 16; ++j) { arr[j] = bytes[_i * 64 + j * 4] << 24 | bytes[_i * 64 + j * 4 + 1] << 16 | bytes[_i * 64 + j * 4 + 2] << 8 | bytes[_i * 64 + j * 4 + 3]; } M[_i] = arr; } M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32); M[N - 1][14] = Math.floor(M[N - 1][14]); M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff; for (var _i2 = 0; _i2 < N; ++_i2) { var W = new Uint32Array(80); for (var t = 0; t < 16; ++t) { W[t] = M[_i2][t]; } for (var _t = 16; _t < 80; ++_t) { W[_t] = ROTL(W[_t - 3] ^ W[_t - 8] ^ W[_t - 14] ^ W[_t - 16], 1); } var a = H[0]; var b = H[1]; var c = H[2]; var d = H[3]; var e = H[4]; for (var _t2 = 0; _t2 < 80; ++_t2) { var s = Math.floor(_t2 / 20); var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[_t2] >>> 0; e = d; d = c; c = ROTL(b, 30) >>> 0; b = a; a = T; } H[0] = H[0] + a >>> 0; H[1] = H[1] + b >>> 0; H[2] = H[2] + c >>> 0; H[3] = H[3] + d >>> 0; H[4] = H[4] + e >>> 0; } return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff]; } var v5 = v35('v5', 0x50, sha1); var v5$1 = v5; var nil = '00000000-0000-0000-0000-000000000000'; function version(uuid) { if (!validate(uuid)) { throw TypeError('Invalid UUID'); } return parseInt(uuid.substr(14, 1), 16); } var esmBrowser = /*#__PURE__*/Object.freeze({ __proto__: null, v1: v1, v3: v3$1, v4: v4, v5: v5$1, NIL: nil, version: version, validate: validate, stringify: stringify$2, parse: parse }); var require$$0 = /*@__PURE__*/getAugmentedNamespace(esmBrowser); var isEnvironment$1 = {}; var __importDefault$6 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(isEnvironment$1, "__esModule", { value: true }); const is_1$4 = __importDefault$6(is$1.exports); function isEnvironment(type, value) { let value_; switch (type) { case 'browser': return typeof window !== 'undefined' && typeof window.document !== 'undefined'; case 'worker': return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope; case 'nodejs': return (new Function('try {return this===global;}catch(e){return false;}'))(); case 'localhost': value_ = value !== undefined ? value : (isEnvironment('browser') && window.location.hostname); return (0, is_1$4.default)('string', value_) && ['localhost', '127.0.0.1'].some(value__ => value_.indexOf(value__) > -1); default: return false; } } isEnvironment$1.default = isEnvironment; var equalDeep$1 = {}; Object.defineProperty(equalDeep$1, "__esModule", { value: true }); const isObjectLike = (value) => typeof value === 'object' && value !== null && !Array.isArray(value); const equalDeep = (valueA, valueB) => { if (valueA === valueB) return true; if (Number.isNaN(valueA) && Number.isNaN(valueB)) return true; if ((typeof valueA !== typeof valueB) && !(isObjectLike(valueA) && isObjectLike(valueB))) return false; if (Array.isArray(valueA) && valueA.length === valueB.length) return valueA.every((item, index) => equalDeep(item, valueB[index])); if (isObjectLike(valueA)) { const valueA_ = Object.assign({}, valueA); const valueB_ = Object.assign({}, valueB); return Object.keys(valueA_).every(key => equalDeep(valueA_[key], valueB_[key])); } return false; }; equalDeep$1.default = equalDeep; var __importDefault$5 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(isValid$1, "__esModule", { value: true }); const uuid_1 = require$$0; const is_1$3 = __importDefault$5(is$1.exports); const isEnvironment_1 = __importDefault$5(isEnvironment$1); const equalDeep_1 = __importDefault$5(equalDeep$1); const optionsDefault$2 = {}; function isValid(type, value, options_ = {}) { var _a; const options = Object.assign(Object.assign({}, optionsDefault$2), options_); let valueA; let valueB; let operator; let operators; let pattern; let value_; switch (type) { case 'date': return isValid('timestamp', new Date(value).getTime()); case 'unix': return (Number.isInteger(value) && String(value).length === 10 && new Date(value * 1000).getTime() > 0); case 'timestamp': return (Number.isInteger(value) && String(value).length >= 10 && (new Date(value).getTime() > 0 || new Date(value * 1000).getTime() > 0)); case 'uuid': return (0, uuid_1.validate)(value); case 'binary-string': value_ = ['0', '1']; return (0, is_1$3.default)('string', value) && [...value].every(item => value_.indexOf(item) > -1); case 'hexadecimal-string': value_ = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; return (0, is_1$3.default)('string', value) && [...value].every(item => value_.indexOf(item) > -1); case 'url': pattern = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/; return pattern.test(value); case 'url-path': pattern = /^\/([^\/][A-Za-z0-9\-._~!$&'()*+,;=:@\/?#%]*)?$/; return pattern.test(value); case 'domain-name': pattern = /^[a-z0-9\-]+$/; const valueCleanedUp = value.replace(/--/g, '-'); const length = value === null || value === void 0 ? void 0 : value.length; return pattern.test(value) && !value.startsWith('-') && !value.endsWith('-') && valueCleanedUp.length === value.length && length > 1 && length < 254; case 'compare': ({ valueA, valueB, operator } = options); operators = { 'less-than': valueA < valueB, 'less-than-equal': valueA <= valueB, 'equal': (0, equalDeep_1.default)(valueA, valueB), 'not-equal': !(0, equalDeep_1.default)(valueA, valueB), 'greater-than-equal': valueA >= valueB, 'greater-than': valueA > valueB, 'array-all': (0, is_1$3.default)('array', valueA) && (0, is_1$3.default)('array', valueB) && valueA.every((_, index) => (0, equalDeep_1.default)(valueA[index], valueB[index])), 'array-some': (0, is_1$3.default)('array', valueA) && (0, is_1$3.default)('array', valueB) && valueA.some((_, index) => (0, equalDeep_1.default)(valueA[index], valueB[index])), 'starts-with': (0, is_1$3.default)('string', valueA) && valueA.indexOf(valueB) === 0, 'contains': (0, is_1$3.default)('string', valueA) && valueA.indexOf(valueB) > -1, }; return operators[operator]; case 'semver': pattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; return pattern.test(value); case 'semver-compare': ({ valueA, valueB, operator } = options); if (!(isValid('semver', valueA) && isValid('semver', valueB))) return false; valueA = (valueA.match(/\d+(\.|\-|\+){0,1}/g) || []).map((item) => item.replace(/[,\-\+\.]/g, '')); valueB = (valueB.match(/\d+(\.|\-|\+){0,1}/g) || []).map((item) => item.replace(/[,\-\+\.]/g, '')); operators = { 'less-than': false, 'less-than-equal': false, 'equal': valueA.every((item, index) => item === valueB[index]), 'greater-than-equal': false, 'greater-than': false, }; // Less then valueA.forEach((item, index) => { if (!operators['less-than']) operators['less-than'] = item < valueB[index]; }); // Greater then valueA.forEach((item, index) => { if (!operators['greater-than']) operators['greater-than'] = item > valueB[index]; }); // Other or operator values operators['less-than-equal'] = operators['less-than'] || operators['equal']; operators['greater-than-equal'] = operators['greater-than'] || operators['equal']; return operators[operator]; case 'mobile': pattern = /^(\+\d{1,2}\s?)?1?-?\.?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/; return pattern.test(value) && !Number.isInteger(value); case 'email': pattern = /\S+@\S+\.\S+/; return pattern.test(value); case 'password': const values = []; if (!(0, is_1$3.default)('string', value)) return false; const min_ = options.min !== undefined ? options.min : 7; const max_ = options.max !== undefined ? options.max : 440; // min 7, max 440 characters if (value.length >= min_ && value.length <= max_) values.push('length'); // lowercase characters if (value.match(/[a-z]+/)) values.push('lowercase'); // uppercase characters if (value.match(/[A-Z]+/)) values.push('uppercase'); // numbers if (value.match(/[0-9]+/)) values.push('number'); return options.variant === 'value' ? values : values.length >= 4; case 'hash': pattern = /^(0x)?[a-f0-9]{64}$/gi; return (0, is_1$3.default)('string', value) && pattern.test(value); case 'color': return isValid('color-rgb', value, options) || isValid('color-hex', value, options) || isValid('color-hsl', value, options); case 'color-rgb': // Matches rgb() and rgba(), with values divided with ',' and spaces (optionaly) pattern = /rgb(a)?\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(\.\d+)?,\s*(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(\.\d+)?,\s*(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(\.\d+)?(,\s*(?:0(?:\.[0-9]{1,2})?|1(?:\.00?)?))?\)/; return pattern.test(value); case 'color-hex': // Matches #nnn, #nnnnnn and #nnnnnnnn (where last nn's are for alpha (optionaly)) pattern = /^#((?:[0-9a-fA-F]){3}|(?:[0-9a-fA-F]){6}|(?:[0-9a-fA-F]){8})$/; return pattern.test(value); case 'color-hsl': // Matches hsl() and hsla(), with values divided with ',' and spaces (optionaly) pattern = /hsl(a)?\((0|[1-9][0-9]?|[12][0-9][0-9]|3[0-5][0-9])(\.\d+)?,\s*([0-9]|[1-9][0-9]|100)(\.\d+)?%,\s*([0-9]|[1-9][0-9]|100)(\.\d+)?%(,\s*(?:0(?:\.[0-9]{1,2})?|1(?:\.00?)?))?\)/; return pattern.test(value); case 'json': try { value_ = JSON.parse(value); } catch (error) { return false; } return (0, is_1$3.default)('object', value_, options) || (0, is_1$3.default)('array', value_, options); case 'min': return value >= options.min; case 'max': return value <= options.max; case 'min-max': return isValid('min', value, options) && isValid('max', value, options); case 'same-origin': try { value_ = new URL(value); } catch (error) { } return (0, isEnvironment_1.default)('browser') && (isValid('url-path', value, options) || (window.location.hostname === ((_a = value_) === null || _a === void 0 ? void 0 : _a.hostname))); case 'js-chunk': return (0, is_1$3.default)('object', value, options) && !!value.__esModule && (value.default instanceof Function || value.default instanceof Object); case 'http-method': const methods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'PATCH']; return (0, is_1$3.default)('string', value, options) && methods.indexOf(value.toUpperCase()) > -1; case 'base64': value_ = typeof value === 'string' ? value.trim() : value; return (0, is_1$3.default)('string', value_, options) && value_.length >= 1 && /^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?$/gi.test(value_); case 'datauri': value_ = typeof value === 'string' ? value.trim() : value; return ((0, is_1$3.default)('string', value_, options) && /^data:\w+\/[-+.\w]+;base64,(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?$/gi.test(value_) || /^data:(\w+\/[-+.\w]+)?(;charset=[\w-]+)?,(.*)?/gi.test(value_)); case 'pascal-case': pattern = /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/; return pattern.test(value); case 'camel-case': pattern = /^[a-z]+(?:[A-Z][a-z]+)*$/; return pattern.test(value); default: return false; } } isValid$1.default = isValid; var stringify$1 = {}; Object.defineProperty(stringify$1, "__esModule", { value: true }); // Fix for undefined // + ref circular values const method = () => { const values = new WeakSet(); return (property, value) => { // Ref circular values const getValue = (property_, value_) => { if (typeof value_ === 'object' && value_ !== null) { if (values.has(value_)) return; values.add(value_); } return value_; }; if (getValue(property, value) === undefined || value === undefined) return undefined; return value; }; }; const stringify = (value_, spaces = 2, replacer = method()) => { try { let value = JSON.stringify(value_, replacer, spaces); // Array circular ref value update // value = value // // first item // .replace(/(?!\[)\n* *null,/g, '') // // index 1+ // .replace(/,\n* *null/g, ''); return value; } catch (error) { } return String(value_); }; stringify$1.default = stringify; var castParam$1 = {}; var __importDefault$4 = (undefined && undefined.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(castParam$1, "__esModule", { value: true }); const is_1$2 = __importDefault$4(is$1.exports); const optionsDefault$1 = { decode: false, decodeMethod: decodeURIComponent, }; const castParam = (value, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault$1), options_); let newValue = value; try { if ((0, is_1$2.default)('string', value) && options.decode && (0, is_1$2.default)('function', options.decodeMethod)) newValue = options.decodeMethod(value); } catch (error) { } try { if ((0, is_1$2.default)('string', newValue)) { if ('undefined' === newValue) return undefined; if ('NaN' === newValue) return NaN; return JSON.parse(newValue); } return newValue; } catch (error) { } return newValue; }; castParam$1.default = castParam; (function (exports) { var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sizeFormat = exports.blobToDataURI = exports.dataUriToBuffer = exports.dataUriToBlob = void 0; const is_1 = __importDefault(is$1.exports); const isValid_1 = __importDefault(isValid$1); const isEnvironment_1 = __importDefault(isEnvironment$1); const stringify_1 = __importDefault(stringify$1); const castParam_1 = __importDefault(castParam$1); // Only for browser, since browser only has Blob const dataUriToBlob = (value, arrayBuffer = false) => { if ((0, isValid_1.default)('datauri', value) || (0, isValid_1.default)('base64', value)) { try { // Convert base64 to raw binary data held in a string const byteString = atob((0, isValid_1.default)('datauri', value) ? value.split(',')[1] : value); // Separate out the mime component const mimeString = (0, isValid_1.default)('datauri', value) && value.split(',')[0].split(':')[1].split(';')[0]; // Write the bytes of the string to an ArrayBuffer const ab = new ArrayBuffer(byteString.length * 2); // create a view into the buffer const ia = new Uint16Array(ab); // Set the bytes of the buffer to the correct values for (let i = 0; i < byteString.length; i++) ia[i] = byteString.charCodeAt(i); if (arrayBuffer) return ab; // Write the ArrayBuffer to a blob, and you're done const blob = new Blob([ab], { type: mimeString }); return blob; } catch (error) { return; } } }; exports.dataUriToBlob = dataUriToBlob; // Only for nodejs, since only nodejs has Buffer const dataUriToBuffer = (value) => { if ((0, isValid_1.default)('datauri', value) || (0, isValid_1.default)('base64', value)) { try { // Extract the base64 data from dataUri const data = (0, isValid_1.default)('datauri', value) ? value.split(',')[1] : value; // Create buffer from base64 string return Buffer.from(data, 'base64'); } catch (error) { return; } } }; exports.dataUriToBuffer = dataUriToBuffer; const blobToDataURI = blob => new Promise(resolve => { const fileReader = new FileReader(); fileReader.onload = event => resolve(event.target.result); fileReader.readAsDataURL(blob); }); exports.blobToDataURI = blobToDataURI; const sizeFormat = (value, decimals = 2, thousand = 1000) => { if (!(0, is_1.default)('number', value) || value <= 0) return '0 Bytes'; const k = thousand; const dm = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const unitIndex = Math.floor(Math.log(value) / Math.log(k)); return `${parseFloat((value / Math.pow(k, unitIndex)).toFixed(dm))} ${sizes[unitIndex]}`; }; exports.sizeFormat = sizeFormat; const optionsDefault = { thousand: 1000, decimals: 2, mime: 'text/plain', }; const to = (value_, type = 'arraybuffer', options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault), options_); let value = value_; switch (type) { case 'string': if ((0, is_1.default)('arraybuffer', value)) return String.fromCharCode.apply(null, new Uint16Array(value)); if ((0, is_1.default)('buffer', value)) return value.toString('utf-8'); if ((0, isValid_1.default)('base64', value)) { if ((0, isEnvironment_1.default)('browser')) return atob(value); if ((0, isEnvironment_1.default)('nodejs')) return Buffer.from(value, 'base64').toString('binary'); } if ((0, isValid_1.default)('datauri', value)) { if ((0, isEnvironment_1.default)('browser'))