ui_utils.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.isValidRotation = isValidRotation;
  27. exports.isValidScrollMode = isValidScrollMode;
  28. exports.isValidSpreadMode = isValidSpreadMode;
  29. exports.isPortraitOrientation = isPortraitOrientation;
  30. exports.clamp = clamp;
  31. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  32. exports.noContextMenuHandler = noContextMenuHandler;
  33. exports.parseQueryString = parseQueryString;
  34. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  35. exports.getVisibleElements = getVisibleElements;
  36. exports.roundToDivide = roundToDivide;
  37. exports.getPageSizeInches = getPageSizeInches;
  38. exports.approximateFraction = approximateFraction;
  39. exports.getOutputScale = getOutputScale;
  40. exports.scrollIntoView = scrollIntoView;
  41. exports.watchScroll = watchScroll;
  42. exports.binarySearchFirstItem = binarySearchFirstItem;
  43. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  44. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  45. exports.moveToEndOfArray = moveToEndOfArray;
  46. exports.WaitOnType = exports.animationStarted = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.SpreadMode = exports.ScrollMode = exports.TextLayerMode = exports.RendererType = exports.PresentationModeState = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = exports.AutoPrintRegExp = void 0;
  47. const CSS_UNITS = 96.0 / 72.0;
  48. exports.CSS_UNITS = CSS_UNITS;
  49. const DEFAULT_SCALE_VALUE = "auto";
  50. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  51. const DEFAULT_SCALE = 1.0;
  52. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  53. const MIN_SCALE = 0.1;
  54. exports.MIN_SCALE = MIN_SCALE;
  55. const MAX_SCALE = 10.0;
  56. exports.MAX_SCALE = MAX_SCALE;
  57. const UNKNOWN_SCALE = 0;
  58. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  59. const MAX_AUTO_SCALE = 1.25;
  60. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  61. const SCROLLBAR_PADDING = 40;
  62. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  63. const VERTICAL_PADDING = 5;
  64. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  65. const PresentationModeState = {
  66. UNKNOWN: 0,
  67. NORMAL: 1,
  68. CHANGING: 2,
  69. FULLSCREEN: 3
  70. };
  71. exports.PresentationModeState = PresentationModeState;
  72. const RendererType = {
  73. CANVAS: "canvas",
  74. SVG: "svg"
  75. };
  76. exports.RendererType = RendererType;
  77. const TextLayerMode = {
  78. DISABLE: 0,
  79. ENABLE: 1,
  80. ENABLE_ENHANCE: 2
  81. };
  82. exports.TextLayerMode = TextLayerMode;
  83. const ScrollMode = {
  84. UNKNOWN: -1,
  85. VERTICAL: 0,
  86. HORIZONTAL: 1,
  87. WRAPPED: 2
  88. };
  89. exports.ScrollMode = ScrollMode;
  90. const SpreadMode = {
  91. UNKNOWN: -1,
  92. NONE: 0,
  93. ODD: 1,
  94. EVEN: 2
  95. };
  96. exports.SpreadMode = SpreadMode;
  97. const AutoPrintRegExp = /\bprint\s*\(/;
  98. exports.AutoPrintRegExp = AutoPrintRegExp;
  99. function formatL10nValue(text, args) {
  100. if (!args) {
  101. return text;
  102. }
  103. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  104. return name in args ? args[name] : "{{" + name + "}}";
  105. });
  106. }
  107. const NullL10n = {
  108. async getLanguage() {
  109. return "en-us";
  110. },
  111. async getDirection() {
  112. return "ltr";
  113. },
  114. async get(property, args, fallback) {
  115. return formatL10nValue(fallback, args);
  116. },
  117. async translate(element) {}
  118. };
  119. exports.NullL10n = NullL10n;
  120. function getOutputScale(ctx) {
  121. const devicePixelRatio = window.devicePixelRatio || 1;
  122. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  123. const pixelRatio = devicePixelRatio / backingStoreRatio;
  124. return {
  125. sx: pixelRatio,
  126. sy: pixelRatio,
  127. scaled: pixelRatio !== 1
  128. };
  129. }
  130. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  131. let parent = element.offsetParent;
  132. if (!parent) {
  133. console.error("offsetParent is not set -- cannot scroll");
  134. return;
  135. }
  136. let offsetY = element.offsetTop + element.clientTop;
  137. let offsetX = element.offsetLeft + element.clientLeft;
  138. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  139. if (parent.dataset._scaleY) {
  140. offsetY /= parent.dataset._scaleY;
  141. offsetX /= parent.dataset._scaleX;
  142. }
  143. offsetY += parent.offsetTop;
  144. offsetX += parent.offsetLeft;
  145. parent = parent.offsetParent;
  146. if (!parent) {
  147. return;
  148. }
  149. }
  150. if (spot) {
  151. if (spot.top !== undefined) {
  152. offsetY += spot.top;
  153. }
  154. if (spot.left !== undefined) {
  155. offsetX += spot.left;
  156. parent.scrollLeft = offsetX;
  157. }
  158. }
  159. parent.scrollTop = offsetY;
  160. }
  161. function watchScroll(viewAreaElement, callback) {
  162. const debounceScroll = function (evt) {
  163. if (rAF) {
  164. return;
  165. }
  166. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  167. rAF = null;
  168. const currentX = viewAreaElement.scrollLeft;
  169. const lastX = state.lastX;
  170. if (currentX !== lastX) {
  171. state.right = currentX > lastX;
  172. }
  173. state.lastX = currentX;
  174. const currentY = viewAreaElement.scrollTop;
  175. const lastY = state.lastY;
  176. if (currentY !== lastY) {
  177. state.down = currentY > lastY;
  178. }
  179. state.lastY = currentY;
  180. callback(state);
  181. });
  182. };
  183. const state = {
  184. right: true,
  185. down: true,
  186. lastX: viewAreaElement.scrollLeft,
  187. lastY: viewAreaElement.scrollTop,
  188. _eventHandler: debounceScroll
  189. };
  190. let rAF = null;
  191. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  192. return state;
  193. }
  194. function parseQueryString(query) {
  195. const parts = query.split("&");
  196. const params = Object.create(null);
  197. for (let i = 0, ii = parts.length; i < ii; ++i) {
  198. const param = parts[i].split("=");
  199. const key = param[0].toLowerCase();
  200. const value = param.length > 1 ? param[1] : null;
  201. params[decodeURIComponent(key)] = decodeURIComponent(value);
  202. }
  203. return params;
  204. }
  205. function binarySearchFirstItem(items, condition) {
  206. let minIndex = 0;
  207. let maxIndex = items.length - 1;
  208. if (maxIndex < 0 || !condition(items[maxIndex])) {
  209. return items.length;
  210. }
  211. if (condition(items[minIndex])) {
  212. return minIndex;
  213. }
  214. while (minIndex < maxIndex) {
  215. const currentIndex = minIndex + maxIndex >> 1;
  216. const currentItem = items[currentIndex];
  217. if (condition(currentItem)) {
  218. maxIndex = currentIndex;
  219. } else {
  220. minIndex = currentIndex + 1;
  221. }
  222. }
  223. return minIndex;
  224. }
  225. function approximateFraction(x) {
  226. if (Math.floor(x) === x) {
  227. return [x, 1];
  228. }
  229. const xinv = 1 / x;
  230. const limit = 8;
  231. if (xinv > limit) {
  232. return [1, limit];
  233. } else if (Math.floor(xinv) === xinv) {
  234. return [1, xinv];
  235. }
  236. const x_ = x > 1 ? xinv : x;
  237. let a = 0,
  238. b = 1,
  239. c = 1,
  240. d = 1;
  241. while (true) {
  242. const p = a + c,
  243. q = b + d;
  244. if (q > limit) {
  245. break;
  246. }
  247. if (x_ <= p / q) {
  248. c = p;
  249. d = q;
  250. } else {
  251. a = p;
  252. b = q;
  253. }
  254. }
  255. let result;
  256. if (x_ - a / b < c / d - x_) {
  257. result = x_ === x ? [a, b] : [b, a];
  258. } else {
  259. result = x_ === x ? [c, d] : [d, c];
  260. }
  261. return result;
  262. }
  263. function roundToDivide(x, div) {
  264. const r = x % div;
  265. return r === 0 ? x : Math.round(x - r + div);
  266. }
  267. function getPageSizeInches({
  268. view,
  269. userUnit,
  270. rotate
  271. }) {
  272. const [x1, y1, x2, y2] = view;
  273. const changeOrientation = rotate % 180 !== 0;
  274. const width = (x2 - x1) / 72 * userUnit;
  275. const height = (y2 - y1) / 72 * userUnit;
  276. return {
  277. width: changeOrientation ? height : width,
  278. height: changeOrientation ? width : height
  279. };
  280. }
  281. function backtrackBeforeAllVisibleElements(index, views, top) {
  282. if (index < 2) {
  283. return index;
  284. }
  285. let elt = views[index].div;
  286. let pageTop = elt.offsetTop + elt.clientTop;
  287. if (pageTop >= top) {
  288. elt = views[index - 1].div;
  289. pageTop = elt.offsetTop + elt.clientTop;
  290. }
  291. for (let i = index - 2; i >= 0; --i) {
  292. elt = views[i].div;
  293. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  294. break;
  295. }
  296. index = i;
  297. }
  298. return index;
  299. }
  300. function getVisibleElements(scrollEl, views, sortByVisibility = false, horizontal = false) {
  301. const top = scrollEl.scrollTop,
  302. bottom = top + scrollEl.clientHeight;
  303. const left = scrollEl.scrollLeft,
  304. right = left + scrollEl.clientWidth;
  305. function isElementBottomAfterViewTop(view) {
  306. const element = view.div;
  307. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  308. return elementBottom > top;
  309. }
  310. function isElementRightAfterViewLeft(view) {
  311. const element = view.div;
  312. const elementRight = element.offsetLeft + element.clientLeft + element.clientWidth;
  313. return elementRight > left;
  314. }
  315. const visible = [],
  316. numViews = views.length;
  317. let firstVisibleElementInd = numViews === 0 ? 0 : binarySearchFirstItem(views, horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop);
  318. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  319. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  320. }
  321. let lastEdge = horizontal ? right : -1;
  322. for (let i = firstVisibleElementInd; i < numViews; i++) {
  323. const view = views[i],
  324. element = view.div;
  325. const currentWidth = element.offsetLeft + element.clientLeft;
  326. const currentHeight = element.offsetTop + element.clientTop;
  327. const viewWidth = element.clientWidth,
  328. viewHeight = element.clientHeight;
  329. const viewRight = currentWidth + viewWidth;
  330. const viewBottom = currentHeight + viewHeight;
  331. if (lastEdge === -1) {
  332. if (viewBottom >= bottom) {
  333. lastEdge = viewBottom;
  334. }
  335. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  336. break;
  337. }
  338. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  339. continue;
  340. }
  341. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  342. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  343. const percent = (viewHeight - hiddenHeight) * (viewWidth - hiddenWidth) * 100 / viewHeight / viewWidth | 0;
  344. visible.push({
  345. id: view.id,
  346. x: currentWidth,
  347. y: currentHeight,
  348. view,
  349. percent
  350. });
  351. }
  352. const first = visible[0],
  353. last = visible[visible.length - 1];
  354. if (sortByVisibility) {
  355. visible.sort(function (a, b) {
  356. const pc = a.percent - b.percent;
  357. if (Math.abs(pc) > 0.001) {
  358. return -pc;
  359. }
  360. return a.id - b.id;
  361. });
  362. }
  363. return {
  364. first,
  365. last,
  366. views: visible
  367. };
  368. }
  369. function noContextMenuHandler(evt) {
  370. evt.preventDefault();
  371. }
  372. function isDataSchema(url) {
  373. let i = 0;
  374. const ii = url.length;
  375. while (i < ii && url[i].trim() === "") {
  376. i++;
  377. }
  378. return url.substring(i, i + 5).toLowerCase() === "data:";
  379. }
  380. function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
  381. if (typeof url !== "string") {
  382. return defaultFilename;
  383. }
  384. if (isDataSchema(url)) {
  385. console.warn("getPDFFileNameFromURL: " + 'ignoring "data:" URL for performance reasons.');
  386. return defaultFilename;
  387. }
  388. const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  389. const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  390. const splitURI = reURI.exec(url);
  391. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  392. if (suggestedFilename) {
  393. suggestedFilename = suggestedFilename[0];
  394. if (suggestedFilename.includes("%")) {
  395. try {
  396. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  397. } catch (ex) {}
  398. }
  399. }
  400. return suggestedFilename || defaultFilename;
  401. }
  402. function normalizeWheelEventDelta(evt) {
  403. let delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
  404. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  405. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  406. delta = -delta;
  407. }
  408. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  409. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  410. const MOUSE_PIXELS_PER_LINE = 30;
  411. const MOUSE_LINES_PER_PAGE = 30;
  412. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  413. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  414. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  415. delta /= MOUSE_LINES_PER_PAGE;
  416. }
  417. return delta;
  418. }
  419. function isValidRotation(angle) {
  420. return Number.isInteger(angle) && angle % 90 === 0;
  421. }
  422. function isValidScrollMode(mode) {
  423. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  424. }
  425. function isValidSpreadMode(mode) {
  426. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  427. }
  428. function isPortraitOrientation(size) {
  429. return size.width <= size.height;
  430. }
  431. const WaitOnType = {
  432. EVENT: "event",
  433. TIMEOUT: "timeout"
  434. };
  435. exports.WaitOnType = WaitOnType;
  436. function waitOnEventOrTimeout({
  437. target,
  438. name,
  439. delay = 0
  440. }) {
  441. return new Promise(function (resolve, reject) {
  442. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  443. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  444. }
  445. function handler(type) {
  446. if (target instanceof EventBus) {
  447. target._off(name, eventHandler);
  448. } else {
  449. target.removeEventListener(name, eventHandler);
  450. }
  451. if (timeout) {
  452. clearTimeout(timeout);
  453. }
  454. resolve(type);
  455. }
  456. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  457. if (target instanceof EventBus) {
  458. target._on(name, eventHandler);
  459. } else {
  460. target.addEventListener(name, eventHandler);
  461. }
  462. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  463. const timeout = setTimeout(timeoutHandler, delay);
  464. });
  465. }
  466. const animationStarted = new Promise(function (resolve) {
  467. window.requestAnimationFrame(resolve);
  468. });
  469. exports.animationStarted = animationStarted;
  470. function dispatchDOMEvent(eventName, args = null) {
  471. throw new Error("Not implemented: dispatchDOMEvent");
  472. }
  473. class EventBus {
  474. constructor(options) {
  475. this._listeners = Object.create(null);
  476. }
  477. on(eventName, listener) {
  478. this._on(eventName, listener, {
  479. external: true
  480. });
  481. }
  482. off(eventName, listener) {
  483. this._off(eventName, listener, {
  484. external: true
  485. });
  486. }
  487. dispatch(eventName) {
  488. const eventListeners = this._listeners[eventName];
  489. if (!eventListeners || eventListeners.length === 0) {
  490. return;
  491. }
  492. const args = Array.prototype.slice.call(arguments, 1);
  493. let externalListeners;
  494. eventListeners.slice(0).forEach(function ({
  495. listener,
  496. external
  497. }) {
  498. if (external) {
  499. if (!externalListeners) {
  500. externalListeners = [];
  501. }
  502. externalListeners.push(listener);
  503. return;
  504. }
  505. listener.apply(null, args);
  506. });
  507. if (externalListeners) {
  508. externalListeners.forEach(function (listener) {
  509. listener.apply(null, args);
  510. });
  511. externalListeners = null;
  512. }
  513. }
  514. _on(eventName, listener, options = null) {
  515. let eventListeners = this._listeners[eventName];
  516. if (!eventListeners) {
  517. this._listeners[eventName] = eventListeners = [];
  518. }
  519. eventListeners.push({
  520. listener,
  521. external: (options && options.external) === true
  522. });
  523. }
  524. _off(eventName, listener, options = null) {
  525. const eventListeners = this._listeners[eventName];
  526. if (!eventListeners) {
  527. return;
  528. }
  529. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  530. if (eventListeners[i].listener === listener) {
  531. eventListeners.splice(i, 1);
  532. return;
  533. }
  534. }
  535. }
  536. }
  537. exports.EventBus = EventBus;
  538. function clamp(v, min, max) {
  539. return Math.min(Math.max(v, min), max);
  540. }
  541. class ProgressBar {
  542. constructor(id, {
  543. height,
  544. width,
  545. units
  546. } = {}) {
  547. this.visible = true;
  548. this.div = document.querySelector(id + " .progress");
  549. this.bar = this.div.parentNode;
  550. this.height = height || 100;
  551. this.width = width || 100;
  552. this.units = units || "%";
  553. this.div.style.height = this.height + this.units;
  554. this.percent = 0;
  555. }
  556. _updateBar() {
  557. if (this._indeterminate) {
  558. this.div.classList.add("indeterminate");
  559. this.div.style.width = this.width + this.units;
  560. return;
  561. }
  562. this.div.classList.remove("indeterminate");
  563. const progressSize = this.width * this._percent / 100;
  564. this.div.style.width = progressSize + this.units;
  565. }
  566. get percent() {
  567. return this._percent;
  568. }
  569. set percent(val) {
  570. this._indeterminate = isNaN(val);
  571. this._percent = clamp(val, 0, 100);
  572. this._updateBar();
  573. }
  574. setWidth(viewer) {
  575. if (!viewer) {
  576. return;
  577. }
  578. const container = viewer.parentNode;
  579. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  580. if (scrollbarWidth > 0) {
  581. this.bar.style.width = `calc(100% - ${scrollbarWidth}px)`;
  582. }
  583. }
  584. hide() {
  585. if (!this.visible) {
  586. return;
  587. }
  588. this.visible = false;
  589. this.bar.classList.add("hidden");
  590. document.body.classList.remove("loadingInProgress");
  591. }
  592. show() {
  593. if (this.visible) {
  594. return;
  595. }
  596. this.visible = true;
  597. document.body.classList.add("loadingInProgress");
  598. this.bar.classList.remove("hidden");
  599. }
  600. }
  601. exports.ProgressBar = ProgressBar;
  602. function moveToEndOfArray(arr, condition) {
  603. const moved = [],
  604. len = arr.length;
  605. let write = 0;
  606. for (let read = 0; read < len; ++read) {
  607. if (condition(arr[read])) {
  608. moved.push(arr[read]);
  609. } else {
  610. arr[write] = arr[read];
  611. ++write;
  612. }
  613. }
  614. for (let read = 0; write < len; ++read, ++write) {
  615. arr[write] = moved[read];
  616. }
  617. }