FileSaver.min.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. (function (a, b) {
  2. if ("function" == typeof define && define.amd) define([], b);
  3. else if ("undefined" != typeof exports) b();
  4. else {
  5. b(), (a.FileSaver = { exports: {} }.exports);
  6. }
  7. })(this, function () {
  8. "use strict";
  9. function b(a, b) {
  10. return (
  11. "undefined" == typeof b ? (b = { autoBom: !1 }) : "object" != typeof b && (console.warn("Deprecated: Expected third argument to be a object"), (b = { autoBom: !b })),
  12. b.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type) ? new Blob(["\uFEFF", a], { type: a.type }) : a
  13. );
  14. }
  15. function c(a, b, c) {
  16. var d = new XMLHttpRequest();
  17. d.open("GET", a),
  18. (d.responseType = "blob"),
  19. (d.onload = function () {
  20. g(d.response, b, c);
  21. }),
  22. (d.onerror = function () {
  23. console.error("could not download file");
  24. }),
  25. d.send();
  26. }
  27. function d(a) {
  28. var b = new XMLHttpRequest();
  29. b.open("HEAD", a, !1);
  30. try {
  31. b.send();
  32. } catch (a) {}
  33. return 200 <= b.status && 299 >= b.status;
  34. }
  35. function e(a) {
  36. try {
  37. a.dispatchEvent(new MouseEvent("click"));
  38. } catch (c) {
  39. var b = document.createEvent("MouseEvents");
  40. b.initMouseEvent("click", !0, !0, window, 0, 0, 0, 80, 20, !1, !1, !1, !1, 0, null), a.dispatchEvent(b);
  41. }
  42. }
  43. var f =
  44. "object" == typeof window && window.window === window ? window : "object" == typeof self && self.self === self ? self : "object" == typeof global && global.global === global ? global : void 0,
  45. a = f.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent),
  46. g =
  47. f.saveAs ||
  48. ("object" != typeof window || window !== f
  49. ? function () {}
  50. : "download" in HTMLAnchorElement.prototype && !a
  51. ? function (b, g, h) {
  52. var i = f.URL || f.webkitURL,
  53. j = document.createElement("a");
  54. (g = g || b.name || "download"),
  55. (j.download = g),
  56. (j.rel = "noopener"),
  57. "string" == typeof b
  58. ? ((j.href = b), j.origin === location.origin ? e(j) : d(j.href) ? c(b, g, h) : e(j, (j.target = "_blank")))
  59. : ((j.href = i.createObjectURL(b)),
  60. setTimeout(function () {
  61. i.revokeObjectURL(j.href);
  62. }, 4e4),
  63. setTimeout(function () {
  64. e(j);
  65. }, 0));
  66. }
  67. : "msSaveOrOpenBlob" in navigator
  68. ? function (f, g, h) {
  69. if (((g = g || f.name || "download"), "string" != typeof f)) navigator.msSaveOrOpenBlob(b(f, h), g);
  70. else if (d(f)) c(f, g, h);
  71. else {
  72. var i = document.createElement("a");
  73. (i.href = f),
  74. (i.target = "_blank"),
  75. setTimeout(function () {
  76. e(i);
  77. });
  78. }
  79. }
  80. : function (b, d, e, g) {
  81. if (((g = g || open("", "_blank")), g && (g.document.title = g.document.body.innerText = "downloading..."), "string" == typeof b)) return c(b, d, e);
  82. var h = "application/octet-stream" === b.type,
  83. i = /constructor/i.test(f.HTMLElement) || f.safari,
  84. j = /CriOS\/[\d]+/.test(navigator.userAgent);
  85. if ((j || (h && i) || a) && "undefined" != typeof FileReader) {
  86. var k = new FileReader();
  87. (k.onloadend = function () {
  88. var a = k.result;
  89. (a = j ? a : a.replace(/^data:[^;]*;/, "data:attachment/file;")), g ? (g.location.href = a) : (location = a), (g = null);
  90. }),
  91. k.readAsDataURL(b);
  92. } else {
  93. var l = f.URL || f.webkitURL,
  94. m = l.createObjectURL(b);
  95. g ? (g.location = m) : (location.href = m),
  96. (g = null),
  97. setTimeout(function () {
  98. l.revokeObjectURL(m);
  99. }, 4e4);
  100. }
  101. });
  102. (f.saveAs = g.saveAs = g), "undefined" != typeof module && (module.exports = g);
  103. });
  104. //# sourceMappingURL=FileSaver.min.js.map