index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1682324647447, function(require, module, exports) {
  8. module.exports = fetch;
  9. var asPromise = require("@protobufjs/aspromise"),
  10. inquire = require("@protobufjs/inquire");
  11. var fs = inquire("fs");
  12. /**
  13. * Node-style callback as used by {@link util.fetch}.
  14. * @typedef FetchCallback
  15. * @type {function}
  16. * @param {?Error} error Error, if any, otherwise `null`
  17. * @param {string} [contents] File contents, if there hasn't been an error
  18. * @returns {undefined}
  19. */
  20. /**
  21. * Options as used by {@link util.fetch}.
  22. * @typedef FetchOptions
  23. * @type {Object}
  24. * @property {boolean} [binary=false] Whether expecting a binary response
  25. * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
  26. */
  27. /**
  28. * Fetches the contents of a file.
  29. * @memberof util
  30. * @param {string} filename File path or url
  31. * @param {FetchOptions} options Fetch options
  32. * @param {FetchCallback} callback Callback function
  33. * @returns {undefined}
  34. */
  35. function fetch(filename, options, callback) {
  36. if (typeof options === "function") {
  37. callback = options;
  38. options = {};
  39. } else if (!options)
  40. options = {};
  41. if (!callback)
  42. return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
  43. // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
  44. if (!options.xhr && fs && fs.readFile)
  45. return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
  46. return err && typeof XMLHttpRequest !== "undefined"
  47. ? fetch.xhr(filename, options, callback)
  48. : err
  49. ? callback(err)
  50. : callback(null, options.binary ? contents : contents.toString("utf8"));
  51. });
  52. // use the XHR version otherwise.
  53. return fetch.xhr(filename, options, callback);
  54. }
  55. /**
  56. * Fetches the contents of a file.
  57. * @name util.fetch
  58. * @function
  59. * @param {string} path File path or url
  60. * @param {FetchCallback} callback Callback function
  61. * @returns {undefined}
  62. * @variation 2
  63. */
  64. /**
  65. * Fetches the contents of a file.
  66. * @name util.fetch
  67. * @function
  68. * @param {string} path File path or url
  69. * @param {FetchOptions} [options] Fetch options
  70. * @returns {Promise<string|Uint8Array>} Promise
  71. * @variation 3
  72. */
  73. /**/
  74. fetch.xhr = function fetch_xhr(filename, options, callback) {
  75. var xhr = new XMLHttpRequest();
  76. xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
  77. if (xhr.readyState !== 4)
  78. return undefined;
  79. // local cors security errors return status 0 / empty string, too. afaik this cannot be
  80. // reliably distinguished from an actually empty file for security reasons. feel free
  81. // to send a pull request if you are aware of a solution.
  82. if (xhr.status !== 0 && xhr.status !== 200)
  83. return callback(Error("status " + xhr.status));
  84. // if binary data is expected, make sure that some sort of array is returned, even if
  85. // ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
  86. if (options.binary) {
  87. var buffer = xhr.response;
  88. if (!buffer) {
  89. buffer = [];
  90. for (var i = 0; i < xhr.responseText.length; ++i)
  91. buffer.push(xhr.responseText.charCodeAt(i) & 255);
  92. }
  93. return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
  94. }
  95. return callback(null, xhr.responseText);
  96. };
  97. if (options.binary) {
  98. // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
  99. if ("overrideMimeType" in xhr)
  100. xhr.overrideMimeType("text/plain; charset=x-user-defined");
  101. xhr.responseType = "arraybuffer";
  102. }
  103. xhr.open("GET", filename);
  104. xhr.send();
  105. };
  106. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  107. return __REQUIRE__(1682324647447);
  108. })()
  109. //miniprogram-npm-outsideDeps=["@protobufjs/aspromise","@protobufjs/inquire"]
  110. //# sourceMappingURL=index.js.map