nprogress.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import {
  2. __commonJS
  3. } from "./chunk-HM4MQYWN.js";
  4. // node_modules/nprogress/nprogress.js
  5. var require_nprogress = __commonJS({
  6. "node_modules/nprogress/nprogress.js"(exports, module) {
  7. (function(root, factory) {
  8. if (typeof define === "function" && define.amd) {
  9. define(factory);
  10. } else if (typeof exports === "object") {
  11. module.exports = factory();
  12. } else {
  13. root.NProgress = factory();
  14. }
  15. })(exports, function() {
  16. var NProgress = {};
  17. NProgress.version = "0.2.0";
  18. var Settings = NProgress.settings = {
  19. minimum: 0.08,
  20. easing: "ease",
  21. positionUsing: "",
  22. speed: 200,
  23. trickle: true,
  24. trickleRate: 0.02,
  25. trickleSpeed: 800,
  26. showSpinner: true,
  27. barSelector: '[role="bar"]',
  28. spinnerSelector: '[role="spinner"]',
  29. parent: "body",
  30. template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
  31. };
  32. NProgress.configure = function(options) {
  33. var key, value;
  34. for (key in options) {
  35. value = options[key];
  36. if (value !== void 0 && options.hasOwnProperty(key))
  37. Settings[key] = value;
  38. }
  39. return this;
  40. };
  41. NProgress.status = null;
  42. NProgress.set = function(n) {
  43. var started = NProgress.isStarted();
  44. n = clamp(n, Settings.minimum, 1);
  45. NProgress.status = n === 1 ? null : n;
  46. var progress = NProgress.render(!started), bar = progress.querySelector(Settings.barSelector), speed = Settings.speed, ease = Settings.easing;
  47. progress.offsetWidth;
  48. queue(function(next) {
  49. if (Settings.positionUsing === "")
  50. Settings.positionUsing = NProgress.getPositioningCSS();
  51. css(bar, barPositionCSS(n, speed, ease));
  52. if (n === 1) {
  53. css(progress, {
  54. transition: "none",
  55. opacity: 1
  56. });
  57. progress.offsetWidth;
  58. setTimeout(function() {
  59. css(progress, {
  60. transition: "all " + speed + "ms linear",
  61. opacity: 0
  62. });
  63. setTimeout(function() {
  64. NProgress.remove();
  65. next();
  66. }, speed);
  67. }, speed);
  68. } else {
  69. setTimeout(next, speed);
  70. }
  71. });
  72. return this;
  73. };
  74. NProgress.isStarted = function() {
  75. return typeof NProgress.status === "number";
  76. };
  77. NProgress.start = function() {
  78. if (!NProgress.status)
  79. NProgress.set(0);
  80. var work = function() {
  81. setTimeout(function() {
  82. if (!NProgress.status)
  83. return;
  84. NProgress.trickle();
  85. work();
  86. }, Settings.trickleSpeed);
  87. };
  88. if (Settings.trickle)
  89. work();
  90. return this;
  91. };
  92. NProgress.done = function(force) {
  93. if (!force && !NProgress.status)
  94. return this;
  95. return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
  96. };
  97. NProgress.inc = function(amount) {
  98. var n = NProgress.status;
  99. if (!n) {
  100. return NProgress.start();
  101. } else {
  102. if (typeof amount !== "number") {
  103. amount = (1 - n) * clamp(Math.random() * n, 0.1, 0.95);
  104. }
  105. n = clamp(n + amount, 0, 0.994);
  106. return NProgress.set(n);
  107. }
  108. };
  109. NProgress.trickle = function() {
  110. return NProgress.inc(Math.random() * Settings.trickleRate);
  111. };
  112. (function() {
  113. var initial = 0, current = 0;
  114. NProgress.promise = function($promise) {
  115. if (!$promise || $promise.state() === "resolved") {
  116. return this;
  117. }
  118. if (current === 0) {
  119. NProgress.start();
  120. }
  121. initial++;
  122. current++;
  123. $promise.always(function() {
  124. current--;
  125. if (current === 0) {
  126. initial = 0;
  127. NProgress.done();
  128. } else {
  129. NProgress.set((initial - current) / initial);
  130. }
  131. });
  132. return this;
  133. };
  134. })();
  135. NProgress.render = function(fromStart) {
  136. if (NProgress.isRendered())
  137. return document.getElementById("nprogress");
  138. addClass(document.documentElement, "nprogress-busy");
  139. var progress = document.createElement("div");
  140. progress.id = "nprogress";
  141. progress.innerHTML = Settings.template;
  142. var bar = progress.querySelector(Settings.barSelector), perc = fromStart ? "-100" : toBarPerc(NProgress.status || 0), parent = document.querySelector(Settings.parent), spinner;
  143. css(bar, {
  144. transition: "all 0 linear",
  145. transform: "translate3d(" + perc + "%,0,0)"
  146. });
  147. if (!Settings.showSpinner) {
  148. spinner = progress.querySelector(Settings.spinnerSelector);
  149. spinner && removeElement(spinner);
  150. }
  151. if (parent != document.body) {
  152. addClass(parent, "nprogress-custom-parent");
  153. }
  154. parent.appendChild(progress);
  155. return progress;
  156. };
  157. NProgress.remove = function() {
  158. removeClass(document.documentElement, "nprogress-busy");
  159. removeClass(document.querySelector(Settings.parent), "nprogress-custom-parent");
  160. var progress = document.getElementById("nprogress");
  161. progress && removeElement(progress);
  162. };
  163. NProgress.isRendered = function() {
  164. return !!document.getElementById("nprogress");
  165. };
  166. NProgress.getPositioningCSS = function() {
  167. var bodyStyle = document.body.style;
  168. var vendorPrefix = "WebkitTransform" in bodyStyle ? "Webkit" : "MozTransform" in bodyStyle ? "Moz" : "msTransform" in bodyStyle ? "ms" : "OTransform" in bodyStyle ? "O" : "";
  169. if (vendorPrefix + "Perspective" in bodyStyle) {
  170. return "translate3d";
  171. } else if (vendorPrefix + "Transform" in bodyStyle) {
  172. return "translate";
  173. } else {
  174. return "margin";
  175. }
  176. };
  177. function clamp(n, min, max) {
  178. if (n < min)
  179. return min;
  180. if (n > max)
  181. return max;
  182. return n;
  183. }
  184. function toBarPerc(n) {
  185. return (-1 + n) * 100;
  186. }
  187. function barPositionCSS(n, speed, ease) {
  188. var barCSS;
  189. if (Settings.positionUsing === "translate3d") {
  190. barCSS = { transform: "translate3d(" + toBarPerc(n) + "%,0,0)" };
  191. } else if (Settings.positionUsing === "translate") {
  192. barCSS = { transform: "translate(" + toBarPerc(n) + "%,0)" };
  193. } else {
  194. barCSS = { "margin-left": toBarPerc(n) + "%" };
  195. }
  196. barCSS.transition = "all " + speed + "ms " + ease;
  197. return barCSS;
  198. }
  199. var queue = function() {
  200. var pending = [];
  201. function next() {
  202. var fn = pending.shift();
  203. if (fn) {
  204. fn(next);
  205. }
  206. }
  207. return function(fn) {
  208. pending.push(fn);
  209. if (pending.length == 1)
  210. next();
  211. };
  212. }();
  213. var css = function() {
  214. var cssPrefixes = ["Webkit", "O", "Moz", "ms"], cssProps = {};
  215. function camelCase(string) {
  216. return string.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function(match, letter) {
  217. return letter.toUpperCase();
  218. });
  219. }
  220. function getVendorProp(name) {
  221. var style = document.body.style;
  222. if (name in style)
  223. return name;
  224. var i = cssPrefixes.length, capName = name.charAt(0).toUpperCase() + name.slice(1), vendorName;
  225. while (i--) {
  226. vendorName = cssPrefixes[i] + capName;
  227. if (vendorName in style)
  228. return vendorName;
  229. }
  230. return name;
  231. }
  232. function getStyleProp(name) {
  233. name = camelCase(name);
  234. return cssProps[name] || (cssProps[name] = getVendorProp(name));
  235. }
  236. function applyCss(element, prop, value) {
  237. prop = getStyleProp(prop);
  238. element.style[prop] = value;
  239. }
  240. return function(element, properties) {
  241. var args = arguments, prop, value;
  242. if (args.length == 2) {
  243. for (prop in properties) {
  244. value = properties[prop];
  245. if (value !== void 0 && properties.hasOwnProperty(prop))
  246. applyCss(element, prop, value);
  247. }
  248. } else {
  249. applyCss(element, args[1], args[2]);
  250. }
  251. };
  252. }();
  253. function hasClass(element, name) {
  254. var list = typeof element == "string" ? element : classList(element);
  255. return list.indexOf(" " + name + " ") >= 0;
  256. }
  257. function addClass(element, name) {
  258. var oldList = classList(element), newList = oldList + name;
  259. if (hasClass(oldList, name))
  260. return;
  261. element.className = newList.substring(1);
  262. }
  263. function removeClass(element, name) {
  264. var oldList = classList(element), newList;
  265. if (!hasClass(element, name))
  266. return;
  267. newList = oldList.replace(" " + name + " ", " ");
  268. element.className = newList.substring(1, newList.length - 1);
  269. }
  270. function classList(element) {
  271. return (" " + (element.className || "") + " ").replace(/\s+/gi, " ");
  272. }
  273. function removeElement(element) {
  274. element && element.parentNode && element.parentNode.removeChild(element);
  275. }
  276. return NProgress;
  277. });
  278. }
  279. });
  280. export default require_nprogress();
  281. /*! Bundled license information:
  282. nprogress/nprogress.js:
  283. (* NProgress, (c) 2013, 2014 Rico Sta. Cruz - http://ricostacruz.com/nprogress
  284. * @license MIT *)
  285. */
  286. //# sourceMappingURL=nprogress.js.map