nprogress.js 9.8 KB

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