ui_utils.js 19 KB

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