@internetarchive/bookreader 5.0.0-34 → 5.0.0-37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.eslintrc.js +1 -11
  2. package/.github/workflows/node.js.yml +3 -3
  3. package/.github/workflows/npm-publish.yml +2 -16
  4. package/BookReader/BookReader.css +1 -1
  5. package/BookReader/BookReader.js +1 -1
  6. package/BookReader/BookReader.js.LICENSE.txt +8 -29
  7. package/BookReader/BookReader.js.map +1 -1
  8. package/BookReader/ia-bookreader-bundle.js +103 -102
  9. package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +15 -12
  10. package/BookReader/ia-bookreader-bundle.js.map +1 -1
  11. package/BookReader/plugins/plugin.chapters.js +1 -1
  12. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  13. package/BookReader/plugins/plugin.search.js +1 -1
  14. package/BookReader/plugins/plugin.search.js.map +1 -1
  15. package/BookReader/plugins/plugin.text_selection.js +1 -1
  16. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  17. package/BookReader/plugins/plugin.tts.js +1 -1
  18. package/BookReader/plugins/plugin.tts.js.map +1 -1
  19. package/BookReader/plugins/plugin.url.js +1 -1
  20. package/BookReader/plugins/plugin.url.js.map +1 -1
  21. package/CHANGELOG.md +21 -0
  22. package/README.md +1 -1
  23. package/package.json +7 -10
  24. package/src/BookNavigator/assets/bookmark-colors.js +1 -1
  25. package/src/BookNavigator/assets/button-base.js +1 -1
  26. package/src/BookNavigator/assets/ia-logo.js +1 -1
  27. package/src/BookNavigator/assets/icon_checkmark.js +1 -1
  28. package/src/BookNavigator/assets/icon_close.js +1 -1
  29. package/src/BookNavigator/assets/icon_sort_asc.js +1 -1
  30. package/src/BookNavigator/assets/icon_sort_desc.js +1 -1
  31. package/src/BookNavigator/assets/icon_sort_neutral.js +1 -1
  32. package/src/BookNavigator/assets/icon_volumes.js +1 -1
  33. package/src/BookNavigator/book-navigator.js +15 -4
  34. package/src/BookNavigator/bookmarks/bookmark-button.js +1 -1
  35. package/src/BookNavigator/bookmarks/bookmark-edit.js +2 -3
  36. package/src/BookNavigator/bookmarks/bookmarks-list.js +2 -3
  37. package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +1 -1
  38. package/src/BookNavigator/bookmarks/bookmarks-provider.js +1 -1
  39. package/src/BookNavigator/bookmarks/ia-bookmarks.js +30 -34
  40. package/src/BookNavigator/delete-modal-actions.js +1 -1
  41. package/src/BookNavigator/downloads/downloads-provider.js +1 -1
  42. package/src/BookNavigator/downloads/downloads.js +1 -2
  43. package/src/BookNavigator/search/a-search-result.js +2 -3
  44. package/src/BookNavigator/search/search-provider.js +3 -4
  45. package/src/BookNavigator/search/search-results.js +1 -2
  46. package/src/BookNavigator/sharing.js +1 -1
  47. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +1 -1
  48. package/src/BookNavigator/visual-adjustments/visual-adjustments.js +3 -3
  49. package/src/BookNavigator/volumes/volumes-provider.js +1 -1
  50. package/src/BookNavigator/volumes/volumes.js +2 -3
  51. package/src/BookReader/Mode1Up.js +2 -1
  52. package/src/BookReader/Mode1UpLit.js +3 -2
  53. package/src/BookReader/Toolbar/Toolbar.js +2 -2
  54. package/src/BookReader.js +59 -57
  55. package/src/css/_colorbox.scss +2 -2
  56. package/src/ia-bookreader/ia-bookreader.js +5 -2
  57. package/src/plugins/plugin.chapters.js +11 -15
  58. package/src/plugins/plugin.text_selection.js +9 -10
  59. package/src/plugins/search/plugin.search.js +3 -3
  60. package/src/plugins/tts/AbstractTTSEngine.js +31 -34
  61. package/src/plugins/tts/FestivalTTSEngine.js +10 -11
  62. package/src/plugins/tts/PageChunk.js +11 -20
  63. package/src/plugins/tts/PageChunkIterator.js +8 -12
  64. package/src/plugins/tts/WebTTSEngine.js +59 -68
  65. package/src/plugins/tts/plugin.tts.js +16 -10
  66. package/src/plugins/url/UrlPlugin.js +1 -1
  67. package/tests/e2e/base.test.js +7 -4
  68. package/tests/e2e/helpers/params.js +1 -1
  69. package/tests/e2e/viewmode.test.js +30 -30
  70. package/tests/jest/BookReader/Mode1UpLit.test.js +2 -1
  71. package/tests/jest/plugins/plugin.text_selection.test.js +25 -23
  72. package/tests/jest/plugins/search/plugin.search.test.js +12 -20
  73. package/tests/jest/plugins/tts/AbstractTTSEngine.test.js +3 -3
  74. package/tests/jest/plugins/url/UrlPlugin.test.js +15 -0
  75. package/tests/karma/BookNavigator/book-navigator.test.js +9 -0
  76. package/tests/karma/BookNavigator/bookmarks/bookmarks-list.test.js +2 -2
  77. package/tests/karma/BookNavigator/downloads/downloads.test.js +1 -1
  78. package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +3 -3
  79. package/webpack.config.js +1 -1
  80. package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
@@ -1,6 +1,6 @@
1
- import { css, html, LitElement } from "lit-element";
2
- import { repeat } from "lit-html/directives/repeat.js";
3
- import { nothing } from "lit-html";
1
+ import { css, html, LitElement } from "lit";
2
+ import { repeat } from "lit/directives/repeat.js";
3
+ import { nothing } from "lit";
4
4
  import checkmarkIcon from '../assets/icon_checkmark.js';
5
5
  import "@internetarchive/icon-magnify-minus/icon-magnify-minus";
6
6
  import "@internetarchive/icon-magnify-plus/icon-magnify-plus";
@@ -1,4 +1,4 @@
1
- import { html } from 'lit-element';
1
+ import { html } from 'lit';
2
2
 
3
3
  import sortDescIcon from '../assets/icon_sort_desc.js';
4
4
  import sortAscIcon from '../assets/icon_sort_asc.js';
@@ -1,6 +1,5 @@
1
- import { css, html, LitElement } from 'lit-element';
2
- import { nothing } from 'lit-html';
3
- import { repeat } from 'lit-html/directives/repeat';
1
+ import { css, html, LitElement, nothing } from 'lit';
2
+ import { repeat } from 'lit/directives/repeat.js';
4
3
 
5
4
  export class Volumes extends LitElement {
6
5
  static get properties() {
@@ -46,7 +46,8 @@ export class Mode1Up {
46
46
  if (!this.everShown) {
47
47
  this.mode1UpLit.initFirstRender(startLeaf);
48
48
  this.everShown = true;
49
- await this.mode1UpLit.requestUpdate();
49
+ this.mode1UpLit.requestUpdate();
50
+ await this.mode1UpLit.updateComplete;
50
51
  new DragScrollable(this.mode1UpLit, {
51
52
  preventDefault: true,
52
53
  dragSelector: '.br-mode-1up__visible-world',
@@ -1,6 +1,7 @@
1
1
  // @ts-check
2
- import { customElement, html, LitElement, property, query } from 'lit-element';
3
- import { styleMap } from 'lit-html/directives/style-map';
2
+ import { customElement, property, query } from 'lit/decorators.js';
3
+ import {LitElement, html} from 'lit';
4
+ import { styleMap } from 'lit/directives/style-map.js';
4
5
  import { ModeSmoothZoom } from './ModeSmoothZoom';
5
6
  import { arrChanged, calcScreenDPI, genToArray, sum, throttle } from './utils';
6
7
  import { HTMLDimensionsCacher } from "./utils/HTMLDimensionsCacher";
@@ -335,7 +335,7 @@ export function blankInfoDiv() {
335
335
  return $(`
336
336
  <div class="BRfloat BRinfo">
337
337
  <div class="BRfloatHead">About this book
338
- <button class="floatShut" href="javascript:;" onclick="$.fn.colorbox.close();"><span class="shift">Close</span></button>
338
+ <button class="floatShut" href="javascript:;" onclick="$.fn.colorbox.close();"><span class="br-colorbox-shift">Close</span></button>
339
339
  </div>
340
340
  <div class="BRfloatBody">
341
341
  <div class="BRfloatCover"></div>
@@ -356,7 +356,7 @@ export function blankShareDiv() {
356
356
  <div class="BRfloat BRshare">
357
357
  <div class="BRfloatHead">
358
358
  Share
359
- <button class="floatShut" href="javascript:;" onclick="$.fn.colorbox.close();"><span class="shift">Close</span></button>
359
+ <button class="floatShut" href="javascript:;" onclick="$.fn.colorbox.close();"><span class="br-colorbox-shift">Close</span></button>
360
360
  </div>
361
361
  </div>`);
362
362
  }
package/src/BookReader.js CHANGED
@@ -333,9 +333,9 @@ BookReader.util = utils;
333
333
  * @private
334
334
  */
335
335
  BookReader.prototype.extendParams = function(params, newParams) {
336
- var modifiedNewParams = $.extend({}, newParams);
336
+ const modifiedNewParams = $.extend({}, newParams);
337
337
  if ('undefined' != typeof(modifiedNewParams.page)) {
338
- var pageIndex = this._models.book.parsePageString(modifiedNewParams.page);
338
+ const pageIndex = this._models.book.parsePageString(modifiedNewParams.page);
339
339
  if (!isNaN(pageIndex))
340
340
  modifiedNewParams.index = pageIndex;
341
341
  delete modifiedNewParams.page;
@@ -349,7 +349,7 @@ BookReader.prototype.extendParams = function(params, newParams) {
349
349
  * @return {object} the parsed params
350
350
  */
351
351
  BookReader.prototype.initParams = function() {
352
- var params = {};
352
+ const params = {};
353
353
  // Flag initializing for updateFromParams()
354
354
  params.init = true;
355
355
 
@@ -398,7 +398,7 @@ BookReader.prototype.initParams = function() {
398
398
  // Check for URL plugin
399
399
  if (this.options.enableUrlPlugin) {
400
400
  // Params explicitly set in URL take precedence over all other methods
401
- var urlParams = this.paramsFromFragment(this.urlReadFragment());
401
+ let urlParams = this.paramsFromFragment(this.urlReadFragment());
402
402
 
403
403
  // Get params if hash fragment available with 'history' urlMode
404
404
  const hasHashURL = !Object.keys(urlParams).length && this.urlReadHashFragment();
@@ -481,8 +481,8 @@ BookReader.prototype.readQueryString = function() {
481
481
  */
482
482
  BookReader.prototype.getInitialMode = function(params) {
483
483
  // Use params or browser width to set view mode
484
- var windowWidth = $(window).width();
485
- var nextMode;
484
+ const windowWidth = $(window).width();
485
+ let nextMode;
486
486
  if ('undefined' != typeof(params.mode)) {
487
487
  nextMode = params.mode;
488
488
  } else if (this.ui == 'full'
@@ -509,7 +509,7 @@ BookReader.prototype.init = function() {
509
509
  this.init.initComplete = false;
510
510
  this.pageScale = this.reduce; // preserve current reduce
511
511
 
512
- var params = this.initParams();
512
+ const params = this.initParams();
513
513
 
514
514
  this.firstIndex = params.index ? params.index : 0;
515
515
 
@@ -653,8 +653,8 @@ BookReader.prototype.resize = function() {
653
653
  } else {
654
654
  // used when zoomed in
655
655
  // Re-center if the scrollbars have disappeared
656
- var center = this.twoPageGetViewCenter();
657
- var doRecenter = false;
656
+ const center = this.twoPageGetViewCenter();
657
+ let doRecenter = false;
658
658
  if (this.twoPage.totalWidth < this.refs.$brContainer.prop('clientWidth')) {
659
659
  center.percentageX = 0.5;
660
660
  doRecenter = true;
@@ -816,8 +816,8 @@ BookReader.prototype.bindGestures = function(jElement) {
816
816
  // when you move the book with one finger and then add another
817
817
  // finger to pinch. Gestures are aware of scroll state.
818
818
 
819
- var self = this;
820
- var numTouches = 1;
819
+ const self = this;
820
+ let numTouches = 1;
821
821
 
822
822
  jElement.unbind('touchmove').bind('touchmove', function(e) {
823
823
  if (e.originalEvent.cancelable) numTouches = e.originalEvent.touches.length;
@@ -901,8 +901,8 @@ BookReader.prototype.resizeBRcontainer = function(animate) {
901
901
  };
902
902
 
903
903
  BookReader.prototype.centerPageView = function() {
904
- var scrollWidth = this.refs.$brContainer.prop('scrollWidth');
905
- var clientWidth = this.refs.$brContainer.prop('clientWidth');
904
+ const scrollWidth = this.refs.$brContainer.prop('scrollWidth');
905
+ const clientWidth = this.refs.$brContainer.prop('clientWidth');
906
906
  if (scrollWidth > clientWidth) {
907
907
  this.refs.$brContainer.prop('scrollLeft', (scrollWidth - clientWidth) / 2);
908
908
  }
@@ -990,7 +990,7 @@ BookReader.prototype._reduceSort = (a, b) => a.reduce - b.reduce;
990
990
  * @return {boolean} Returns true if page could be found, false otherwise.
991
991
  */
992
992
  BookReader.prototype.jumpToPage = function(pageNum) {
993
- var pageIndex = this._models.book.parsePageString(pageNum);
993
+ const pageIndex = this._models.book.parsePageString(pageNum);
994
994
 
995
995
  if ('undefined' != typeof(pageIndex)) {
996
996
  this.jumpToIndex(pageIndex);
@@ -1119,14 +1119,14 @@ BookReader.prototype.switchMode = function(
1119
1119
  if (!(this.suppressFragmentChange || suppressFragmentChange)) {
1120
1120
  this.trigger(BookReader.eventNames.fragmentChange);
1121
1121
  }
1122
- var eventName = mode + 'PageViewSelected';
1122
+ const eventName = mode + 'PageViewSelected';
1123
1123
  this.trigger(BookReader.eventNames[eventName]);
1124
1124
 
1125
1125
  this.textSelectionPlugin?.stopPageFlip(this.refs.$brContainer);
1126
1126
  };
1127
1127
 
1128
1128
  BookReader.prototype.updateBrClasses = function() {
1129
- var modeToClass = {};
1129
+ const modeToClass = {};
1130
1130
  modeToClass[this.constMode1up] = 'BRmode1up';
1131
1131
  modeToClass[this.constMode2up] = 'BRmode2Up';
1132
1132
  modeToClass[this.constModeThumb] = 'BRmodeThumb';
@@ -1192,7 +1192,8 @@ BookReader.prototype.enterFullscreen = async function(bindKeyboardControls = tru
1192
1192
  if (this.activeMode instanceof Mode1Up) {
1193
1193
  this.activeMode.mode1UpLit.scale = this.activeMode.mode1UpLit.computeDefaultScale(this._models.book.getPage(currentIndex));
1194
1194
  // Need the new scale to be applied before calling jumpToIndex
1195
- await this.activeMode.mode1UpLit.requestUpdate();
1195
+ this.activeMode.mode1UpLit.requestUpdate();
1196
+ await this.activeMode.mode1UpLit.updateComplete;
1196
1197
  }
1197
1198
  this.jumpToIndex(currentIndex);
1198
1199
  this.animating = false;
@@ -1222,7 +1223,7 @@ BookReader.prototype.exitFullScreen = async function () {
1222
1223
 
1223
1224
  $(document).off('keyup', this._fullscreenCloseHandler);
1224
1225
 
1225
- var windowWidth = $(window).width();
1226
+ const windowWidth = $(window).width();
1226
1227
 
1227
1228
  const canShow2up = this.options.controls.twoPage.visible;
1228
1229
  if (canShow2up && (windowWidth <= this.onePageMinBreakpoint)) {
@@ -1241,7 +1242,8 @@ BookReader.prototype.exitFullScreen = async function () {
1241
1242
 
1242
1243
  if (this.activeMode instanceof Mode1Up) {
1243
1244
  this.activeMode.mode1UpLit.scale = this.activeMode.mode1UpLit.computeDefaultScale(this._models.book.getPage(this.currentIndex()));
1244
- await this.activeMode.mode1UpLit.requestUpdate();
1245
+ this.activeMode.mode1UpLit.requestUpdate();
1246
+ await this.activeMode.mode1UpLit.updateComplete;
1245
1247
  }
1246
1248
 
1247
1249
  this.animating = false;
@@ -1706,7 +1708,7 @@ BookReader.prototype.bindNavigationHandlers = function() {
1706
1708
  },
1707
1709
  full: () => {
1708
1710
  if (this.ui == 'embed') {
1709
- var url = this.$('.BRembedreturn a').attr('href');
1711
+ const url = this.$('.BRembedreturn a').attr('href');
1710
1712
  window.open(url);
1711
1713
  } else {
1712
1714
  this.toggleFullscreen();
@@ -1725,12 +1727,12 @@ BookReader.prototype.bindNavigationHandlers = function() {
1725
1727
  });
1726
1728
  }
1727
1729
 
1728
- var $brNavCntlBtmEl = this.$('.BRnavCntlBtm');
1729
- var $brNavCntlTopEl = this.$('.BRnavCntlTop');
1730
+ const $brNavCntlBtmEl = this.$('.BRnavCntlBtm');
1731
+ const $brNavCntlTopEl = this.$('.BRnavCntlTop');
1730
1732
 
1731
1733
  this.$('.BRnavCntl').click(
1732
1734
  function() {
1733
- var promises = [];
1735
+ const promises = [];
1734
1736
  // TODO don't use magic constants
1735
1737
  // TODO move this to a function
1736
1738
  if ($brNavCntlBtmEl.hasClass('BRdn')) {
@@ -1827,7 +1829,7 @@ BookReader.prototype.navigationMousemoveHandler = function(event) {
1827
1829
  if (event.data['br'].uiAutoHide) {
1828
1830
  // 77px is an approximate height of the Internet Archive Top Nav
1829
1831
  // 75 & 76 (pixels) provide used in this context is checked against the IA top nav height
1830
- var navkey = $(document).height() - 75;
1832
+ const navkey = $(document).height() - 75;
1831
1833
  if ((event.pageY < 76) || (event.pageY > navkey)) {
1832
1834
  // inside or near navigation elements
1833
1835
  event.data['br'].hideNavigation();
@@ -1858,7 +1860,7 @@ BookReader.prototype.initSwipeData = function(clientX, clientY) {
1858
1860
  };
1859
1861
 
1860
1862
  BookReader.prototype.swipeMousedownHandler = function(event) {
1861
- var self = event.data['br'];
1863
+ const self = event.data['br'];
1862
1864
 
1863
1865
  // We should be the last bubble point for the page images
1864
1866
  // Disable image drag and select, but keep right-click
@@ -1888,8 +1890,8 @@ BookReader.prototype.swipeMousedownHandler = function(event) {
1888
1890
  };
1889
1891
 
1890
1892
  BookReader.prototype.swipeMousemoveHandler = function(event) {
1891
- var self = event.data['br'];
1892
- var _swipe = self._swipe;
1893
+ const self = event.data['br'];
1894
+ const _swipe = self._swipe;
1893
1895
  if (! _swipe.mightBeSwiping) {
1894
1896
  return;
1895
1897
  }
@@ -1899,12 +1901,12 @@ BookReader.prototype.swipeMousemoveHandler = function(event) {
1899
1901
  _swipe.deltaY = event.clientY - _swipe.startY;
1900
1902
  _swipe.deltaT = (new Date).getTime() - _swipe.startTime;
1901
1903
 
1902
- var absX = Math.abs(_swipe.deltaX);
1903
- var absY = Math.abs(_swipe.deltaY);
1904
+ const absX = Math.abs(_swipe.deltaX);
1905
+ const absY = Math.abs(_swipe.deltaY);
1904
1906
 
1905
1907
  // Minimum distance in the amount of tim to trigger the swipe
1906
- var minSwipeLength = Math.min(self.refs.$br.width() / 5, 80);
1907
- var maxSwipeTime = 400;
1908
+ const minSwipeLength = Math.min(self.refs.$br.width() / 5, 80);
1909
+ const maxSwipeTime = 400;
1908
1910
 
1909
1911
  // Check for horizontal swipe
1910
1912
  if (absX > absY && (absX > minSwipeLength) && _swipe.deltaT < maxSwipeTime) {
@@ -1938,7 +1940,7 @@ BookReader.prototype.swipeMousemoveHandler = function(event) {
1938
1940
  };
1939
1941
 
1940
1942
  BookReader.prototype.swipeMouseupHandler = function(event) {
1941
- var _swipe = event.data['br']._swipe;
1943
+ const _swipe = event.data['br']._swipe;
1942
1944
  _swipe.mightBeSwiping = false;
1943
1945
  _swipe.mightBeDragging = false;
1944
1946
 
@@ -1955,7 +1957,7 @@ BookReader.prototype.swipeMouseupHandler = function(event) {
1955
1957
  };
1956
1958
 
1957
1959
  BookReader.prototype.bindMozTouchHandlers = function() {
1958
- var self = this;
1960
+ const self = this;
1959
1961
 
1960
1962
  // Currently only want touch handlers in 2up
1961
1963
  this.refs.$br
@@ -1982,8 +1984,8 @@ BookReader.prototype.bindMozTouchHandlers = function() {
1982
1984
  */
1983
1985
  BookReader.prototype.navigationIsVisible = function() {
1984
1986
  // $$$ doesn't account for transitioning states, nav must be fully visible to return true
1985
- var toolpos = this.refs.$BRtoolbar.position();
1986
- var tooltop = toolpos.top;
1987
+ const toolpos = this.refs.$BRtoolbar.position();
1988
+ const tooltop = toolpos.top;
1987
1989
  return tooltop == 0;
1988
1990
  };
1989
1991
 
@@ -1992,19 +1994,19 @@ BookReader.prototype.navigationIsVisible = function() {
1992
1994
  * Defaults to SHOW the navigation chrome
1993
1995
  */
1994
1996
  BookReader.prototype.setNavigationView = function brSetNavigationView(hide) {
1995
- var animationLength = this.constNavAnimationDuration;
1996
- var animationType = 'linear';
1997
- var resizePageContainer = function resizePageContainer () {
1997
+ const animationLength = this.constNavAnimationDuration;
1998
+ const animationType = 'linear';
1999
+ const resizePageContainer = function resizePageContainer () {
1998
2000
  /* main page container fills whole container */
1999
2001
  if (this.constMode2up !== this.mode) {
2000
- var animate = true;
2002
+ const animate = true;
2001
2003
  this.resizeBRcontainer(animate);
2002
2004
  }
2003
2005
  this.trigger(BookReader.eventNames.navToggled);
2004
2006
  }.bind(this);
2005
2007
 
2006
- var toolbarHeight = 0;
2007
- var navbarHeight = 0;
2008
+ let toolbarHeight = 0;
2009
+ let navbarHeight = 0;
2008
2010
  if (hide) {
2009
2011
  toolbarHeight = this.getToolBarHeight() * -1;
2010
2012
  navbarHeight = this.getFooterHeight() * -1;
@@ -2035,7 +2037,7 @@ BookReader.prototype.setNavigationView = function brSetNavigationView(hide) {
2035
2037
  BookReader.prototype.hideNavigation = function() {
2036
2038
  // Check if navigation is showing
2037
2039
  if (this.navigationIsVisible()) {
2038
- var hide = true;
2040
+ const hide = true;
2039
2041
  this.setNavigationView(hide);
2040
2042
  }
2041
2043
  };
@@ -2086,7 +2088,7 @@ BookReader.prototype.firstDisplayableIndex = function() {
2086
2088
  */
2087
2089
  BookReader.prototype.lastDisplayableIndex = function() {
2088
2090
 
2089
- var lastIndex = this._models.book.getNumLeafs() - 1;
2091
+ const lastIndex = this._models.book.getNumLeafs() - 1;
2090
2092
 
2091
2093
  if (this.mode != this.constMode2up) {
2092
2094
  return lastIndex;
@@ -2325,7 +2327,7 @@ BookReader.prototype.initUIStrings = function() {
2325
2327
  // the toolbar and nav bar easier
2326
2328
 
2327
2329
  // Setup tooltips -- later we could load these from a file for i18n
2328
- var titles = {
2330
+ const titles = {
2329
2331
  '.logo': 'Go to Archive.org', // $$$ update after getting OL record
2330
2332
  '.zoom_in': 'Zoom in',
2331
2333
  '.zoom_out': 'Zoom out',
@@ -2357,7 +2359,7 @@ BookReader.prototype.initUIStrings = function() {
2357
2359
  titles['.book_rightmost'] = 'First page';
2358
2360
  }
2359
2361
 
2360
- for (var icon in titles) {
2362
+ for (const icon in titles) {
2361
2363
  this.$(icon).prop('title', titles[icon]);
2362
2364
  }
2363
2365
  };
@@ -2368,7 +2370,7 @@ BookReader.prototype.initUIStrings = function() {
2368
2370
  BookReader.prototype.reloadImages = function() {
2369
2371
  this.refs.$brContainer.find('img').each(function(index, elem) {
2370
2372
  if (!elem.complete || elem.naturalHeight === 0) {
2371
- var src = elem.src;
2373
+ const src = elem.src;
2372
2374
  elem.src = '';
2373
2375
  setTimeout(function() {
2374
2376
  elem.src = src;
@@ -2382,10 +2384,10 @@ BookReader.prototype.reloadImages = function() {
2382
2384
  * @return {number}
2383
2385
  */
2384
2386
  BookReader.prototype.getFooterHeight = function() {
2385
- var $heightEl = this.mode == this.constMode2up ? this.refs.$BRfooter : this.refs.$BRnav;
2387
+ const $heightEl = this.mode == this.constMode2up ? this.refs.$BRfooter : this.refs.$BRnav;
2386
2388
  if ($heightEl && this.refs.$BRfooter) {
2387
- var outerHeight = $heightEl.outerHeight();
2388
- var bottom = parseInt(this.refs.$BRfooter.css('bottom'));
2389
+ const outerHeight = $heightEl.outerHeight();
2390
+ const bottom = parseInt(this.refs.$BRfooter.css('bottom'));
2389
2391
  if (!isNaN(outerHeight) && !isNaN(bottom)) {
2390
2392
  return outerHeight + bottom;
2391
2393
  }
@@ -2401,11 +2403,11 @@ BookReader.prototype.getFooterHeight = function() {
2401
2403
  * @return {Object}
2402
2404
  */
2403
2405
  BookReader.prototype.paramsFromCurrent = function() {
2404
- var params = {};
2406
+ const params = {};
2405
2407
 
2406
2408
  // Path params
2407
- var index = this.currentIndex();
2408
- var pageNum = this._models.book.getPageNum(index);
2409
+ const index = this.currentIndex();
2410
+ const pageNum = this._models.book.getPageNum(index);
2409
2411
  if ((pageNum === 0) || pageNum) {
2410
2412
  params.page = pageNum;
2411
2413
  }
@@ -2444,7 +2446,7 @@ BookReader.prototype.paramsFromCurrent = function() {
2444
2446
  * @return {Object}
2445
2447
  */
2446
2448
  BookReader.prototype.paramsFromFragment = function(fragment) {
2447
- var params = {};
2449
+ const params = {};
2448
2450
 
2449
2451
  // For backwards compatibility we allow an initial # character
2450
2452
  // (as from window.location.hash) but don't require it
@@ -2453,7 +2455,7 @@ BookReader.prototype.paramsFromFragment = function(fragment) {
2453
2455
  }
2454
2456
 
2455
2457
  // Simple #nn syntax
2456
- var oldStyleLeafNum = parseInt( /^\d+$/.exec(fragment) );
2458
+ const oldStyleLeafNum = parseInt( /^\d+$/.exec(fragment) );
2457
2459
  if ( !isNaN(oldStyleLeafNum) ) {
2458
2460
  params.index = oldStyleLeafNum;
2459
2461
 
@@ -2462,9 +2464,9 @@ BookReader.prototype.paramsFromFragment = function(fragment) {
2462
2464
  }
2463
2465
 
2464
2466
  // Split into key-value pairs
2465
- var urlArray = fragment.split('/');
2466
- var urlHash = {};
2467
- for (var i = 0; i < urlArray.length; i += 2) {
2467
+ const urlArray = fragment.split('/');
2468
+ const urlHash = {};
2469
+ for (let i = 0; i < urlArray.length; i += 2) {
2468
2470
  urlHash[urlArray[i]] = urlArray[i + 1];
2469
2471
  }
2470
2472
 
@@ -46,7 +46,7 @@
46
46
  }
47
47
  #cboxLoadingOverlay{background:transparent;}
48
48
 
49
- .shift{
49
+ .br-colorbox-shift {
50
50
  position: absolute !important;
51
51
  left: -10000px !important;
52
- }
52
+ }
@@ -2,7 +2,7 @@
2
2
  * BookReaderTemplate to load BookNavigator components
3
3
  */
4
4
 
5
- import { LitElement, html, css } from 'lit-element';
5
+ import { LitElement, html, css } from 'lit';
6
6
 
7
7
  import '@internetarchive/ia-item-navigator';
8
8
  import '../BookNavigator/book-navigator.js';
@@ -40,6 +40,7 @@ export class IaBookReader extends LitElement {
40
40
  this.loaded = false;
41
41
  this.menuShortcuts = [];
42
42
  this.menuContents = [];
43
+ this.openMenuName = '';
43
44
  }
44
45
 
45
46
  updated() {
@@ -98,10 +99,11 @@ export class IaBookReader extends LitElement {
98
99
  return;
99
100
  }
100
101
 
102
+ this.openMenuName = menuId;
103
+
101
104
  if (action === 'open') {
102
105
  this.itemNav?.openShortcut(menuId);
103
106
  } else if (action === 'toggle') {
104
- this.itemNav?.openMenu(menuId);
105
107
  this.itemNav?.toggleMenu();
106
108
  }
107
109
  }
@@ -119,6 +121,7 @@ export class IaBookReader extends LitElement {
119
121
  ?signedIn=${this.signedIn}
120
122
  .menuShortcuts=${this.menuShortcuts}
121
123
  .menuContents=${this.menuContents}
124
+ .openMenu=${this.openMenuName}
122
125
  >
123
126
  <div slot="header">
124
127
  <slot name="header"></slot>
@@ -174,7 +174,7 @@ BookReader.prototype.addChapterFromEntry = function(tocEntryObject) {
174
174
  * This makes a call to OL API and calls the given callback function with the
175
175
  * response from the API.
176
176
  */
177
- BookReader.prototype.getOpenLibraryRecord = function () {
177
+ BookReader.prototype.getOpenLibraryRecord = async function () {
178
178
  // Try looking up by ocaid first, then by source_record
179
179
  const baseURL = `${this.olHost}/query.json?type=/type/edition&*=`;
180
180
  const fetchUrlByBookId = `${baseURL}&ocaid=${this.bookId}`;
@@ -190,20 +190,16 @@ BookReader.prototype.getOpenLibraryRecord = function () {
190
190
  }
191
191
  };
192
192
 
193
- $.ajax({ url: fetchUrlByBookId, dataType: 'jsonp' })
194
- .then(data => {
195
- if (data && data.length > 0) {
196
- return data;
197
- } else {
198
- // try sourceid
199
- return $.ajax({ url: `${baseURL}&source_records=ia:${this.bookId}`, dataType: 'jsonp' });
200
- }
201
- })
202
- .then(data => {
203
- if (data && data.length > 0) {
204
- setUpChapterMarkers(data[0]);
205
- }
206
- });
193
+ let data = await $.ajax({ url: fetchUrlByBookId, dataType: 'jsonp' });
194
+
195
+ if (!data || !data.length) {
196
+ // try sourceid
197
+ data = await $.ajax({ url: `${baseURL}&source_records=ia:${this.bookId}`, dataType: 'jsonp' });
198
+ }
199
+
200
+ if (data && data.length > 0) {
201
+ setUpChapterMarkers(data[0]);
202
+ }
207
203
  };
208
204
 
209
205
  // Extend buildMobileDrawerElement with table of contents list
@@ -96,21 +96,20 @@ export class TextSelectionPlugin {
96
96
  if (cachedEntry) {
97
97
  return cachedEntry.response;
98
98
  }
99
- return $.ajax({
99
+ const res = await $.ajax({
100
100
  type: "GET",
101
101
  url: applyVariables(this.options.singlePageDjvuXmlUrl, this.optionVariables, { pageIndex: index }),
102
102
  dataType: "html",
103
103
  error: (e) => undefined,
104
- }).then((res) => {
105
- try {
106
- const xmlDoc = $.parseXML(res);
107
- const result = xmlDoc && $(xmlDoc).find("OBJECT")[0];
108
- this.pageTextCache.add({ index, response: result });
109
- return result;
110
- } catch (e) {
111
- return undefined;
112
- }
113
104
  });
105
+ try {
106
+ const xmlDoc = $.parseXML(res);
107
+ const result = xmlDoc && $(xmlDoc).find("OBJECT")[0];
108
+ this.pageTextCache.add({ index, response: result });
109
+ return result;
110
+ } catch (e) {
111
+ return undefined;
112
+ }
114
113
  } else {
115
114
  const XMLpagesArr = await this.djvuPagesPromise;
116
115
  if (XMLpagesArr) return XMLpagesArr[index];
@@ -132,7 +132,7 @@ BookReader.prototype._createPageContainer = (function (super_) {
132
132
  * @param {string} term
133
133
  * @param {SearchOptions} overrides
134
134
  */
135
- BookReader.prototype.search = function(term = '', overrides = {}) {
135
+ BookReader.prototype.search = async function(term = '', overrides = {}) {
136
136
  /** @type {SearchOptions} */
137
137
  const defaultOptions = {
138
138
  goToFirstResult: false, /* jump to the first result (default=false) */
@@ -210,13 +210,13 @@ BookReader.prototype.search = function(term = '', overrides = {}) {
210
210
  };
211
211
 
212
212
  this.trigger('SearchStarted', { term: this.searchTerm, instance: this });
213
- return $.ajax({
213
+ return processSearchResults(await $.ajax({
214
214
  url: url,
215
215
  dataType: 'jsonp',
216
216
  cache: true,
217
217
  beforeSend,
218
218
  jsonpCallback: 'BRSearchInProgress'
219
- }).then(processSearchResults);
219
+ }));
220
220
  };
221
221
 
222
222
  /**
@@ -125,13 +125,13 @@ export default class AbstractTTSEngine {
125
125
  }
126
126
 
127
127
  /** @public */
128
- jumpBackward() {
129
- Promise.all([
128
+ async jumpBackward() {
129
+ await Promise.all([
130
130
  this.activeSound.stop(),
131
131
  this._chunkIterator.decrement()
132
132
  .then(() => this._chunkIterator.decrement())
133
- ])
134
- .then(() => this.step());
133
+ ]);
134
+ this.step();
135
135
  }
136
136
 
137
137
  /** @param {number} newRate */
@@ -147,36 +147,33 @@ export default class AbstractTTSEngine {
147
147
  }
148
148
 
149
149
  /** @private */
150
- step() {
151
- this._chunkIterator.next()
152
- .then(chunk => {
153
- if (chunk == PageChunkIterator.AT_END) {
154
- this.stop();
155
- this.opts.onDone();
156
- return;
157
- }
158
-
159
- this.opts.onLoadingStart();
160
- const sound = this.createSound(chunk);
161
- sound.chunk = chunk;
162
- sound.rate = this.playbackRate;
163
- sound.voice = this.voice;
164
- sound.load(() => this.opts.onLoadingComplete());
165
-
166
- this.opts.onLoadingComplete();
167
- return this.opts.beforeChunkPlay(chunk).then(() => sound);
168
- })
169
- .then(sound => {
170
- if (!this.playing) return;
171
-
172
- const playPromise = this.playSound(sound)
173
- .then(() => this.opts.afterChunkPlay(sound.chunk));
174
- if (this.paused) this.pause();
175
- return playPromise;
176
- })
177
- .then(() => {
178
- if (this.playing) return this.step();
179
- });
150
+ async step() {
151
+ const chunk = await this._chunkIterator.next();
152
+ if (chunk == PageChunkIterator.AT_END) {
153
+ this.stop();
154
+ this.opts.onDone();
155
+ return;
156
+ }
157
+ this.opts.onLoadingStart();
158
+ const sound = this.createSound(chunk);
159
+ sound.chunk = chunk;
160
+ sound.rate = this.playbackRate;
161
+ sound.voice = this.voice;
162
+ sound.load(() => this.opts.onLoadingComplete());
163
+
164
+ this.opts.onLoadingComplete();
165
+
166
+ await this.opts.beforeChunkPlay(chunk);
167
+
168
+ if (!this.playing) return;
169
+
170
+ const playPromise = await this.playSound(sound)
171
+ .then(()=> this.opts.afterChunkPlay(sound.chunk));
172
+
173
+ if (this.paused) this.pause();
174
+ await playPromise;
175
+
176
+ if (this.playing) return this.step();
180
177
  }
181
178
 
182
179
  /**