index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. (function() {
  2. var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
  3. var __module = nodeEnv ? module : {exports:{}};
  4. var __filename = 'preview-scripts/__node_modules/base64-js/index.js';
  5. var __require = nodeEnv ? function (request) {
  6. return cc.require(request);
  7. } : function (request) {
  8. return __quick_compile_project__.require(request, __filename);
  9. };
  10. function __define (exports, require, module) {
  11. if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}'use strict'
  12. exports.byteLength = byteLength
  13. exports.toByteArray = toByteArray
  14. exports.fromByteArray = fromByteArray
  15. var lookup = []
  16. var revLookup = []
  17. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  18. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  19. for (var i = 0, len = code.length; i < len; ++i) {
  20. lookup[i] = code[i]
  21. revLookup[code.charCodeAt(i)] = i
  22. }
  23. // Support decoding URL-safe base64 strings, as Node.js does.
  24. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  25. revLookup['-'.charCodeAt(0)] = 62
  26. revLookup['_'.charCodeAt(0)] = 63
  27. function getLens (b64) {
  28. var len = b64.length
  29. if (len % 4 > 0) {
  30. throw new Error('Invalid string. Length must be a multiple of 4')
  31. }
  32. // Trim off extra bytes after placeholder bytes are found
  33. // See: https://github.com/beatgammit/base64-js/issues/42
  34. var validLen = b64.indexOf('=')
  35. if (validLen === -1) validLen = len
  36. var placeHoldersLen = validLen === len
  37. ? 0
  38. : 4 - (validLen % 4)
  39. return [validLen, placeHoldersLen]
  40. }
  41. // base64 is 4/3 + up to two characters of the original data
  42. function byteLength (b64) {
  43. var lens = getLens(b64)
  44. var validLen = lens[0]
  45. var placeHoldersLen = lens[1]
  46. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  47. }
  48. function _byteLength (b64, validLen, placeHoldersLen) {
  49. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  50. }
  51. function toByteArray (b64) {
  52. var tmp
  53. var lens = getLens(b64)
  54. var validLen = lens[0]
  55. var placeHoldersLen = lens[1]
  56. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  57. var curByte = 0
  58. // if there are placeholders, only get up to the last complete 4 chars
  59. var len = placeHoldersLen > 0
  60. ? validLen - 4
  61. : validLen
  62. var i
  63. for (i = 0; i < len; i += 4) {
  64. tmp =
  65. (revLookup[b64.charCodeAt(i)] << 18) |
  66. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  67. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  68. revLookup[b64.charCodeAt(i + 3)]
  69. arr[curByte++] = (tmp >> 16) & 0xFF
  70. arr[curByte++] = (tmp >> 8) & 0xFF
  71. arr[curByte++] = tmp & 0xFF
  72. }
  73. if (placeHoldersLen === 2) {
  74. tmp =
  75. (revLookup[b64.charCodeAt(i)] << 2) |
  76. (revLookup[b64.charCodeAt(i + 1)] >> 4)
  77. arr[curByte++] = tmp & 0xFF
  78. }
  79. if (placeHoldersLen === 1) {
  80. tmp =
  81. (revLookup[b64.charCodeAt(i)] << 10) |
  82. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  83. (revLookup[b64.charCodeAt(i + 2)] >> 2)
  84. arr[curByte++] = (tmp >> 8) & 0xFF
  85. arr[curByte++] = tmp & 0xFF
  86. }
  87. return arr
  88. }
  89. function tripletToBase64 (num) {
  90. return lookup[num >> 18 & 0x3F] +
  91. lookup[num >> 12 & 0x3F] +
  92. lookup[num >> 6 & 0x3F] +
  93. lookup[num & 0x3F]
  94. }
  95. function encodeChunk (uint8, start, end) {
  96. var tmp
  97. var output = []
  98. for (var i = start; i < end; i += 3) {
  99. tmp =
  100. ((uint8[i] << 16) & 0xFF0000) +
  101. ((uint8[i + 1] << 8) & 0xFF00) +
  102. (uint8[i + 2] & 0xFF)
  103. output.push(tripletToBase64(tmp))
  104. }
  105. return output.join('')
  106. }
  107. function fromByteArray (uint8) {
  108. var tmp
  109. var len = uint8.length
  110. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  111. var parts = []
  112. var maxChunkLength = 16383 // must be multiple of 3
  113. // go through the array every three bytes, we'll deal with trailing stuff later
  114. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  115. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  116. }
  117. // pad the end with zeros, but make sure to not forget the extra bytes
  118. if (extraBytes === 1) {
  119. tmp = uint8[len - 1]
  120. parts.push(
  121. lookup[tmp >> 2] +
  122. lookup[(tmp << 4) & 0x3F] +
  123. '=='
  124. )
  125. } else if (extraBytes === 2) {
  126. tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  127. parts.push(
  128. lookup[tmp >> 10] +
  129. lookup[(tmp >> 4) & 0x3F] +
  130. lookup[(tmp << 2) & 0x3F] +
  131. '='
  132. )
  133. }
  134. return parts.join('')
  135. }
  136. }
  137. if (nodeEnv) {
  138. __define(__module.exports, __require, __module);
  139. }
  140. else {
  141. __quick_compile_project__.registerModuleFunc(__filename, function () {
  142. __define(__module.exports, __require, __module);
  143. });
  144. }
  145. })();