123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- if (Uint8Array) {
- const _slice = Uint8Array.prototype.slice;
- try {
- // Can't be used with DOM elements in IE < 9
- _slice.call(document.documentElement);
- } catch (e) { // Fails in IE < 9
- // This will work for genuine arrays, array-like objects,
- // NamedNodeMap (attributes, entities, notations),
- // NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes),
- // and will not fail on other DOM objects (as do DOM elements in IE < 9)
- Uint8Array.prototype.slice = function(begin, end) {
- // IE < 9 gets unhappy with an undefined end argument
- end = (typeof end !== 'undefined') ? end : this.length;
- // For native Array objects, we use the native slice function
- if (Object.prototype.toString.call(this) === '[object Array]') {
- return _slice.call(this, begin, end);
- }
- // For array like object we handle it ourselves.
- let i,
- cloned = [],
- size,
- len = this.length;
- // Handle negative value for "begin"
- let start = begin || 0;
- start = (start >= 0) ? start : Math.max(0, len + start);
- // Handle negative value for "end"
- let upTo = (typeof end === 'number') ? Math.min(end, len) : len;
- if (end < 0) {
- upTo = len + end;
- }
- // Actual expected size of the slice
- size = upTo - start;
- if (size > 0) {
- cloned = new Array(size);
- if (this.charAt) {
- for (i = 0; i < size; i++) {
- cloned[i] = this.charAt(start + i);
- }
- } else {
- for (i = 0; i < size; i++) {
- cloned[i] = this[start + i];
- }
- }
- }
- return cloned;
- };
- }
- if (!Uint8Array.from) {
- Uint8Array.from = (function() {
- const toStr = Object.prototype.toString;
- const isCallable = function(fn) {
- return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
- };
- const toInteger = function(value) {
- const number = Number(value);
- if (isNaN(number)) { return 0; }
- if (number === 0 || !isFinite(number)) { return number; }
- return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
- };
- const maxSafeInteger = Math.pow(2, 53) - 1;
- const toLength = function(value) {
- const len = toInteger(value);
- return Math.min(Math.max(len, 0), maxSafeInteger);
- };
- const toItems = function(value) {
- // support set
- if (value.size > 0 && value.values) {
- const values = value.values();
- let it = values.next();
- const o = [];
- while (!it.done) {
- o.push(it.value);
- it = values.next();
- }
- return o;
- }
- return Object(value);
- };
- // The length property of the from method is 1.
- return function from(arrayLike/* , mapFn, thisArg */) {
- // 1. Let C be the this value.
- const C = this;
- // 2. Let items be ToObject(arrayLike).
- const items = toItems(arrayLike);
- // 3. ReturnIfAbrupt(items).
- if (arrayLike == null) {
- throw new TypeError('Array.from requires an array-like object - not null or undefined');
- }
- // 4. If mapfn is undefined, then let mapping be false.
- const mapFn = arguments.length > 1 ? arguments[1] : void undefined;
- let T;
- if (typeof mapFn !== 'undefined') {
- // 5. else
- // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
- if (!isCallable(mapFn)) {
- throw new TypeError('Array.from: when provided, the second argument must be a function');
- }
- // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
- if (arguments.length > 2) {
- T = arguments[2];
- }
- }
- // 10. Let lenValue be Get(items, "length").
- // 11. Let len be ToLength(lenValue).
- const len = toLength(items.length);
- // 13. If IsConstructor(C) is true, then
- // 13. a. Let A be the result of calling the [[Construct]] internal method
- // of C with an argument list containing the single item len.
- // 14. a. Else, Let A be ArrayCreate(len).
- const A = isCallable(C) ? Object(new C(len)) : new Array(len);
- // 16. Let k be 0.
- let k = 0;
- // 17. Repeat, while k < len�� (also steps a - h)
- let kValue;
- while (k < len) {
- kValue = items[k];
- if (mapFn) {
- A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
- } else {
- A[k] = kValue;
- }
- k += 1;
- }
- // 18. Let putStatus be Put(A, "length", len, true).
- A.length = len;
- // 20. Return A.
- return A;
- };
- }());
- }
- }
- (function(global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined'
- ? module.exports = factory(global)
- : typeof define === 'function' && define.amd
- ? define(factory) : factory(global);
- }((
- typeof self !== 'undefined' ? self
- : typeof window !== 'undefined' ? window
- : typeof global !== 'undefined' ? global
- : this
- ), function(global) {
- 'use strict';
- // existing version for noConflict()
- global = global || {};
- const _Base64 = global.Base64;
- const version = '2.6.2';
- // constants
- const b64chars
- = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
- const b64tab = function(bin) {
- const t = {};
- for (let i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
- return t;
- }(b64chars);
- const fromCharCode = String.fromCharCode;
- // encoder stuff
- const cb_utob = function(c) {
- if (c.length < 2) {
- var cc = c.charCodeAt(0);
- return cc < 0x80 ? c
- : cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6))
- + fromCharCode(0x80 | (cc & 0x3f)))
- : (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f))
- + fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
- + fromCharCode(0x80 | (cc & 0x3f)));
- }
- var cc = 0x10000
- + (c.charCodeAt(0) - 0xD800) * 0x400
- + (c.charCodeAt(1) - 0xDC00);
- return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07))
- + fromCharCode(0x80 | ((cc >>> 12) & 0x3f))
- + fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
- + fromCharCode(0x80 | (cc & 0x3f)));
- };
- const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
- const utob = function(u) {
- return u.replace(re_utob, cb_utob);
- };
- const cb_encode = function(ccc) {
- const padlen = [ 0, 2, 1 ][ccc.length % 3],
- ord = ccc.charCodeAt(0) << 16
- | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
- | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)),
- chars = [
- b64chars.charAt(ord >>> 18),
- b64chars.charAt((ord >>> 12) & 63),
- padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
- padlen >= 1 ? '=' : b64chars.charAt(ord & 63),
- ];
- return chars.join('');
- };
- const btoa = global.btoa && typeof global.btoa === 'function'
- ? function(b) { return global.btoa(b); } : function(b) {
- if (b.match(/[^\x00-\xFF]/)) {
- throw new RangeError(
- 'The string contains invalid characters.'
- );
- }
- return b.replace(/[\s\S]{1,3}/g, cb_encode);
- };
- const _encode = function(u) {
- return btoa(utob(String(u)));
- };
- const mkUriSafe = function(b64) {
- return b64.replace(/[+\/]/g, function(m0) {
- return m0 == '+' ? '-' : '_';
- }).replace(/=/g, '');
- };
- const encode = function(u, urisafe) {
- return urisafe ? mkUriSafe(_encode(u)) : _encode(u);
- };
- const encodeURI = function(u) { return encode(u, true); };
- let fromUint8Array;
- if (global.Uint8Array) {
- fromUint8Array = function(a, urisafe) {
- // return btoa(fromCharCode.apply(null, a));
- let b64 = '';
- for (let i = 0, l = a.length; i < l; i += 3) {
- const a0 = a[i],
- a1 = a[i + 1],
- a2 = a[i + 2];
- const ord = a0 << 16 | a1 << 8 | a2;
- b64 += b64chars.charAt(ord >>> 18)
- + b64chars.charAt((ord >>> 12) & 63)
- + (typeof a1 !== 'undefined'
- ? b64chars.charAt((ord >>> 6) & 63) : '=')
- + (typeof a2 !== 'undefined'
- ? b64chars.charAt(ord & 63) : '=');
- }
- return urisafe ? mkUriSafe(b64) : b64;
- };
- }
- // decoder stuff
- const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
- const cb_btou = function(cccc) {
- switch (cccc.length) {
- case 4:
- var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
- | ((0x3f & cccc.charCodeAt(1)) << 12)
- | ((0x3f & cccc.charCodeAt(2)) << 6)
- | (0x3f & cccc.charCodeAt(3)),
- offset = cp - 0x10000;
- return (fromCharCode((offset >>> 10) + 0xD800)
- + fromCharCode((offset & 0x3FF) + 0xDC00));
- case 3:
- return fromCharCode(
- ((0x0f & cccc.charCodeAt(0)) << 12)
- | ((0x3f & cccc.charCodeAt(1)) << 6)
- | (0x3f & cccc.charCodeAt(2))
- );
- default:
- return fromCharCode(
- ((0x1f & cccc.charCodeAt(0)) << 6)
- | (0x3f & cccc.charCodeAt(1))
- );
- }
- };
- const btou = function(b) {
- return b.replace(re_btou, cb_btou);
- };
- const cb_decode = function(cccc) {
- const len = cccc.length,
- padlen = len % 4,
- n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0)
- | (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
- | (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
- | (len > 3 ? b64tab[cccc.charAt(3)] : 0),
- chars = [
- fromCharCode(n >>> 16),
- fromCharCode((n >>> 8) & 0xff),
- fromCharCode(n & 0xff),
- ];
- chars.length -= [ 0, 0, 2, 1 ][padlen];
- return chars.join('');
- };
- const _atob = global.atob && typeof global.atob === 'function'
- ? function(a) { return global.atob(a); } : function(a) {
- return a.replace(/\S{1,4}/g, cb_decode);
- };
- const atob = function(a) {
- return _atob(String(a).replace(/[^A-Za-z0-9\+\/]/g, ''));
- };
- const _decode = function(a) { return btou(_atob(a)); };
- const decode = function(a) {
- return _decode(
- String(a).replace(/[-_]/g, function(m0) {
- return m0 == '-' ? '+' : '/';
- }).replace(/[^A-Za-z0-9\+\/]/g, '')
- );
- };
- let toUint8Array;
- if (global.Uint8Array) {
- toUint8Array = function(a) {
- return Uint8Array.from(atob(a), function(c) {
- return c.charCodeAt(0);
- });
- };
- }
- const noConflict = function() {
- const Base64 = global.Base64;
- global.Base64 = _Base64;
- return Base64;
- };
- // export Base64
- global.Base64 = {
- VERSION: version,
- atob,
- btoa,
- fromBase64: decode,
- toBase64: encode,
- utob,
- encode,
- encodeURI,
- btou,
- decode,
- noConflict,
- fromUint8Array,
- toUint8Array,
- };
- // if ES5 is available, make Base64.extendString() available
- if (typeof Object.defineProperty === 'function') {
- const noEnum = function(v) {
- return { value: v, enumerable: false, writable: true, configurable: true };
- };
- global.Base64.extendString = function() {
- Object.defineProperty(
- String.prototype, 'fromBase64', noEnum(function() {
- return decode(this);
- }));
- Object.defineProperty(
- String.prototype, 'toBase64', noEnum(function(urisafe) {
- return encode(this, urisafe);
- }));
- Object.defineProperty(
- String.prototype, 'toBase64URI', noEnum(function() {
- return encode(this, true);
- }));
- };
- }
- //
- // export Base64 to the namespace
- //
- if (global.Meteor) { // Meteor.js
- Base64 = global.Base64;
- }
- // module.exports and AMD are mutually exclusive.
- // module.exports has precedence.
- if (typeof module !== 'undefined' && module.exports) {
- module.exports.Base64 = global.Base64;
- } else if (typeof define === 'function' && define.amd) {
- // AMD. Register as an anonymous module.
- define([], function() { return global.Base64; });
- }
- // that's it!
- return { Base64: global.Base64 };
- }));
|