@internetarchive/bookreader 5.0.0-92 → 5.0.0-94

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 (102) hide show
  1. package/BookReader/BookReader.css +2 -1
  2. package/BookReader/BookReader.js +1 -1
  3. package/BookReader/BookReader.js.map +1 -1
  4. package/BookReader/ia-bookreader-bundle.js +14 -14
  5. package/BookReader/ia-bookreader-bundle.js.map +1 -1
  6. package/BookReader/images/hypothesis.ico +0 -0
  7. package/BookReader/jquery-3.js +1 -1
  8. package/BookReader/plugins/plugin.archive_analytics.js +1 -1
  9. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  10. package/BookReader/plugins/plugin.autoplay.js +1 -1
  11. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  12. package/BookReader/plugins/plugin.chapters.js +2 -2
  13. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  14. package/BookReader/plugins/plugin.experiments.js +3 -0
  15. package/BookReader/plugins/plugin.experiments.js.LICENSE.txt +1 -0
  16. package/BookReader/plugins/plugin.experiments.js.map +1 -0
  17. package/BookReader/plugins/plugin.iframe.js +1 -1
  18. package/BookReader/plugins/plugin.iiif.js +1 -1
  19. package/BookReader/plugins/plugin.iiif.js.map +1 -1
  20. package/BookReader/plugins/plugin.resume.js +1 -1
  21. package/BookReader/plugins/plugin.resume.js.map +1 -1
  22. package/BookReader/plugins/plugin.search.js +1 -1
  23. package/BookReader/plugins/plugin.search.js.map +1 -1
  24. package/BookReader/plugins/plugin.text_selection.js +1 -1
  25. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  26. package/BookReader/plugins/plugin.tts.js +1 -1
  27. package/BookReader/plugins/plugin.tts.js.map +1 -1
  28. package/BookReader/plugins/plugin.url.js +1 -1
  29. package/BookReader/plugins/plugin.url.js.map +1 -1
  30. package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
  31. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
  32. package/BookReaderDemo/IADemoBr.js +1 -24
  33. package/BookReaderDemo/demo-internetarchive.html +1 -0
  34. package/CHANGELOG.md +14 -0
  35. package/package.json +8 -4
  36. package/scripts/postversion.js +3 -2
  37. package/scripts/preversion.js +3 -1
  38. package/scripts/version.js +4 -3
  39. package/src/BookNavigator/book-navigator.js +38 -12
  40. package/src/BookNavigator/downloads/downloads-provider.js +2 -2
  41. package/src/BookNavigator/search/search-provider.js +5 -5
  42. package/src/BookNavigator/search/search-results.js +1 -1
  43. package/src/BookNavigator/sharing.js +2 -2
  44. package/src/BookNavigator/viewable-files.js +2 -2
  45. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +3 -3
  46. package/src/BookNavigator/visual-adjustments/visual-adjustments.js +2 -2
  47. package/src/BookReader/BookModel.js +13 -3
  48. package/src/BookReader/ImageCache.js +2 -2
  49. package/src/BookReader/Mode1Up.js +2 -0
  50. package/src/BookReader/Mode1UpLit.js +5 -5
  51. package/src/BookReader/Mode2Up.js +2 -0
  52. package/src/BookReader/Mode2UpLit.js +5 -5
  53. package/src/BookReader/ModeCoordinateSpace.js +1 -1
  54. package/src/BookReader/ModeThumb.js +2 -0
  55. package/src/BookReader/PageContainer.js +4 -1
  56. package/src/BookReader/Toolbar/Toolbar.js +1 -1
  57. package/src/BookReader/options.js +5 -0
  58. package/src/BookReader/utils/HTMLDimensionsCacher.js +1 -1
  59. package/src/BookReader/utils.js +13 -0
  60. package/src/BookReader.js +57 -31
  61. package/src/assets/images/hypothesis.ico +0 -0
  62. package/src/css/_TextSelection.scss +3 -1
  63. package/src/plugins/plugin.autoplay.js +3 -3
  64. package/src/plugins/plugin.chapters.js +2 -2
  65. package/src/plugins/plugin.experiments.js +294 -0
  66. package/src/plugins/plugin.iiif.js +1 -1
  67. package/src/plugins/plugin.text_selection.js +112 -1
  68. package/src/plugins/search/plugin.search.js +2 -2
  69. package/src/plugins/search/view.js +5 -5
  70. package/src/plugins/tts/plugin.tts.js +3 -3
  71. package/src/plugins/url/plugin.url.js +2 -2
  72. package/tests/e2e/autoplay.test.js +1 -1
  73. package/tests/e2e/base.test.js +4 -4
  74. package/tests/e2e/helpers/base.js +2 -2
  75. package/tests/e2e/models/BookReader.js +1 -1
  76. package/tests/e2e/rightToLeft.test.js +4 -4
  77. package/tests/e2e/viewmode.test.js +2 -2
  78. package/tests/jest/BookNavigator/book-navigator.test.js +0 -13
  79. package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +1 -1
  80. package/tests/jest/BookNavigator/downloads/downloads.test.js +1 -1
  81. package/tests/jest/BookNavigator/search/search-provider.test.js +5 -5
  82. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +1 -1
  83. package/tests/jest/BookReader/Mode2Up.test.js +1 -1
  84. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +1 -1
  85. package/tests/jest/BookReader/PageContainer.test.js +14 -3
  86. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +1 -1
  87. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +1 -1
  88. package/tests/jest/BookReader/utils/SelectionObserver.test.js +1 -1
  89. package/tests/jest/BookReader.test.js +10 -10
  90. package/tests/jest/plugins/plugin.autoplay.test.js +6 -6
  91. package/tests/jest/plugins/plugin.chapters.test.js +2 -2
  92. package/tests/jest/plugins/plugin.resume.test.js +13 -13
  93. package/tests/jest/plugins/plugin.text_selection.test.js +155 -24
  94. package/tests/jest/plugins/search/plugin.search.test.js +7 -7
  95. package/tests/jest/plugins/search/plugin.search.view.test.js +8 -8
  96. package/tests/jest/plugins/search/utils.js +1 -1
  97. package/tests/jest/plugins/tts/PageChunkIterator.test.js +2 -2
  98. package/tests/jest/plugins/url/UrlPlugin.test.js +1 -1
  99. package/webpack.config.js +8 -3
  100. /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
  101. /package/{.testcaferc.js → .testcaferc.cjs} +0 -0
  102. /package/{babel.config.js → babel.config.cjs} +0 -0
@@ -38,6 +38,8 @@ export class TextSelectionPlugin extends BookReaderPlugin {
38
38
  singlePageDjvuXmlUrl: null,
39
39
  /** Whether to fetch the XML as a jsonp */
40
40
  jsonp: false,
41
+ /** Mox words tha can be selected when the text layer is protected */
42
+ maxProtectedWords: 200,
41
43
  }
42
44
 
43
45
  /**@type {PromiseLike<JQuery<HTMLElement>|undefined>} */
@@ -75,7 +77,7 @@ export class TextSelectionPlugin extends BookReaderPlugin {
75
77
  new SelectionObserver('.BRtextLayer', (selectEvent) => {
76
78
  // Track how often selection is used
77
79
  if (selectEvent == 'started') {
78
- this.br._plugins.archiveAnalytics?.sendEvent('BookReader', 'SelectStart');
80
+ this.br.plugins.archiveAnalytics?.sendEvent('BookReader', 'SelectStart');
79
81
 
80
82
  // Set a class on the page to avoid hiding it when zooming/etc
81
83
  this.br.refs.$br.find('.BRpagecontainer--hasSelection').removeClass('BRpagecontainer--hasSelection');
@@ -84,6 +86,7 @@ export class TextSelectionPlugin extends BookReaderPlugin {
84
86
  }).attach();
85
87
 
86
88
  if (this.br.protected) {
89
+ document.addEventListener('selectionchange', this._limitSelection);
87
90
  // Prevent right clicking when selected text
88
91
  $(document.body).on('contextmenu dragstart copy', (e) => {
89
92
  const selection = document.getSelection();
@@ -100,6 +103,41 @@ export class TextSelectionPlugin extends BookReaderPlugin {
100
103
  }
101
104
  }
102
105
 
106
+ _limitSelection = () => {
107
+ const selection = window.getSelection();
108
+ if (!selection.rangeCount) return;
109
+
110
+ const range = selection.getRangeAt(0);
111
+
112
+ // Check if range.startContainer is inside the sub-tree of .BRContainer
113
+ const startInBr = !!range.startContainer.parentElement.closest('.BRcontainer');
114
+ const endInBr = !!range.endContainer.parentElement.closest('.BRcontainer');
115
+ if (!startInBr && !endInBr) return;
116
+ if (!startInBr || !endInBr) {
117
+ // weird case, just clear the selection
118
+ selection.removeAllRanges();
119
+ return;
120
+ }
121
+
122
+ // Find the last allowed word in the selection
123
+ const lastAllowedWord = genAt(
124
+ genFilter(
125
+ walkBetweenNodes(range.startContainer, range.endContainer),
126
+ (node) => node.classList?.contains('BRwordElement'),
127
+ ),
128
+ this.options.maxProtectedWords - 1,
129
+ );
130
+
131
+ if (!lastAllowedWord || range.endContainer.parentNode == lastAllowedWord) return;
132
+
133
+ const newRange = document.createRange();
134
+ newRange.setStart(range.startContainer, range.startOffset);
135
+ newRange.setEnd(lastAllowedWord.firstChild, lastAllowedWord.textContent.length);
136
+
137
+ selection.removeAllRanges();
138
+ selection.addRange(newRange);
139
+ };
140
+
103
141
  /**
104
142
  * @override
105
143
  * @param {PageContainer} pageContainer
@@ -511,6 +549,33 @@ function augmentLine(line) {
511
549
  };
512
550
  }
513
551
 
552
+ /**
553
+ * @template T
554
+ * Get the i-th element of an iterable
555
+ * @param {Iterable<T>} iterable
556
+ * @param {number} index
557
+ */
558
+ export function genAt(iterable, index) {
559
+ let i = 0;
560
+ for (const x of iterable) {
561
+ if (i == index) return x;
562
+ i++;
563
+ }
564
+ return undefined;
565
+ }
566
+
567
+ /**
568
+ * @template T
569
+ * Generator version of filter
570
+ * @param {Iterable<T>} iterable
571
+ * @param {function(T): boolean} fn
572
+ */
573
+ export function* genFilter(iterable, fn) {
574
+ for (const x of iterable) {
575
+ if (fn(x)) yield x;
576
+ }
577
+ }
578
+
514
579
  /**
515
580
  * @template TFrom, TTo
516
581
  * Generator version of map
@@ -647,3 +712,49 @@ class Rect {
647
712
  get top() { return this.y; }
648
713
  get left() { return this.x; }
649
714
  }
715
+
716
+ /**
717
+ * Depth traverse the DOM tree starting at `start`, and ending at `end`.
718
+ * @param {Node} start
719
+ * @param {Node} end
720
+ * @returns {Generator<Node>}
721
+ */
722
+ export function* walkBetweenNodes(start, end) {
723
+ let done = false;
724
+
725
+ /**
726
+ * @param {Node} node
727
+ */
728
+ function* walk(node, {children = true, parents = true, siblings = true} = {}) {
729
+ if (node === end) {
730
+ done = true;
731
+ yield node;
732
+ return;
733
+ }
734
+
735
+ // yield self
736
+ yield node;
737
+
738
+ // First iterate children (depth-first traversal)
739
+ if (children && node.firstChild) {
740
+ yield* walk(node.firstChild, {children: true, parents: false, siblings: true});
741
+ if (done) return;
742
+ }
743
+
744
+ // Then iterate siblings
745
+ if (siblings) {
746
+ for (let sib = node.nextSibling; sib; sib = sib.nextSibling) {
747
+ yield* walk(sib, {children: true, parents: false, siblings: false});
748
+ if (done) return;
749
+ }
750
+ }
751
+
752
+ // Finally, move up the tree
753
+ if (parents && node.parentNode) {
754
+ yield* walk(node.parentNode, {children: false, parents: true, siblings: true});
755
+ if (done) return;
756
+ }
757
+ }
758
+
759
+ yield* walk(start);
760
+ }
@@ -341,8 +341,8 @@ export class SearchPlugin extends BookReaderPlugin {
341
341
  let makeUnviewableAtEnd = false;
342
342
  if (!page.isViewable) {
343
343
  const resp = await fetch('/services/bookreader/request_page?' + new URLSearchParams({
344
- id: this.options.bookId,
345
- subprefix: this.options.subPrefix,
344
+ id: this.br.options.bookId,
345
+ subprefix: this.br.options.subPrefix,
346
346
  leafNum: page.leafNum,
347
347
  })).then(r => r.json());
348
348
 
@@ -44,7 +44,7 @@ class SearchView {
44
44
  }
45
45
 
46
46
  clearSearchFieldAndResults(dispatchEventWhenComplete = true) {
47
- this.br._plugins.search.removeSearchResults();
47
+ this.br.plugins.search.removeSearchResults();
48
48
  this.removeResultPins();
49
49
  this.emptyMatches();
50
50
  this.setQuery('');
@@ -218,7 +218,7 @@ class SearchView {
218
218
  <form class="BRbooksearch desktop">
219
219
  <input type="search" name="query" class="BRsearchInput" value="" placeholder="Search inside"/>
220
220
  <button type="submit" class="BRsearchSubmit">
221
- <img src="${this.br.imagesBaseURL}icon_search_button.svg" />
221
+ <img src="${this.br.options.imagesBaseURL}icon_search_button.svg" />
222
222
  </button>
223
223
  </form>
224
224
  `;
@@ -273,7 +273,7 @@ class SearchView {
273
273
  $(event.target).addClass('front');
274
274
  })
275
275
  .on("mouseleave", (event) => $(event.target).removeClass('front'))
276
- .on("click", () => { this.br._plugins.search.jumpToMatch(match.matchIndex); });
276
+ .on("click", () => { this.br.plugins.search.jumpToMatch(match.matchIndex); });
277
277
  });
278
278
  }
279
279
 
@@ -379,11 +379,11 @@ class SearchView {
379
379
 
380
380
  handleSearchStarted() {
381
381
  this.emptyMatches();
382
- this.br._plugins.search.removeSearchHilites();
382
+ this.br.plugins.search.removeSearchHilites();
383
383
  this.removeResultPins();
384
384
  this.toggleSearchPending(true);
385
385
  this.teardownSearchNavigation();
386
- this.setQuery(this.br._plugins.search.searchTerm);
386
+ this.setQuery(this.br.plugins.search.searchTerm);
387
387
  }
388
388
 
389
389
  /**
@@ -199,7 +199,7 @@ export class TtsPlugin extends BookReaderPlugin {
199
199
  }
200
200
 
201
201
  toggle() {
202
- this.br._plugins.autoplay?.stop();
202
+ this.br.plugins.autoplay?.stop();
203
203
  if (this.ttsEngine.playing) {
204
204
  this.stop();
205
205
  } else {
@@ -338,11 +338,11 @@ export class TtsPlugin extends BookReaderPlugin {
338
338
  * @param {number} [value]
339
339
  */
340
340
  sendAnalyticsEvent(action, value) {
341
- if (this.br._plugins.archiveAnalytics) {
341
+ if (this.br.plugins.archiveAnalytics) {
342
342
  const extraValues = {};
343
343
  const mediaLanguage = this.ttsEngine.opts.bookLanguage;
344
344
  if (mediaLanguage) extraValues.mediaLanguage = mediaLanguage;
345
- this.br._plugins.archiveAnalytics.sendEvent('BRReadAloud', action, value, extraValues);
345
+ this.br.plugins.archiveAnalytics.sendEvent('BRReadAloud', action, value, extraValues);
346
346
  }
347
347
  }
348
348
  }
@@ -1,6 +1,6 @@
1
1
  /* global BookReader */
2
2
 
3
- import { UrlPlugin } from "./UrlPlugin";
3
+ import { UrlPlugin } from "./UrlPlugin.js";
4
4
 
5
5
  /**
6
6
  * Plugin for URL management in BookReader
@@ -106,7 +106,7 @@ BookReader.prototype.urlStartLocationPolling = function() {
106
106
  this.trigger(BookReader.eventNames.stop);
107
107
  if (this.animating) {
108
108
  // Queue change if animating
109
- this._plugins.autoplay?.stop();
109
+ this.plugins.autoplay?.stop();
110
110
  this.animationFinishedCallback = updateParams;
111
111
  } else {
112
112
  // update immediately
@@ -1,5 +1,5 @@
1
1
  import { ClientFunction } from 'testcafe';
2
- import params from './helpers/params';
2
+ import params from './helpers/params.js';
3
3
 
4
4
  const getLocationHref = ClientFunction(() => window.location.href.toString());
5
5
  const FLIP_SPEED = 200;
@@ -1,7 +1,7 @@
1
- import { runBaseTests } from './helpers/base';
2
- import BookReader from './models/BookReader';
3
- import { runSearchTests } from './helpers/search';
4
- import params from './helpers/params';
1
+ import { runBaseTests } from './helpers/base.js';
2
+ import BookReader from './models/BookReader.js';
3
+ import { runSearchTests } from './helpers/search.js';
4
+ import params from './helpers/params.js';
5
5
 
6
6
  const ocaids = params.ocaids || [
7
7
  'theworksofplato01platiala',
@@ -78,8 +78,8 @@ export function runBaseTests (br) {
78
78
 
79
79
  // Check if uses plugin.resume.js
80
80
  const usesResume = ClientFunction(() => {
81
- const hasResumePlugin = typeof(br._plugins.resume) !== "undefined";
82
- const hasResumeValue = hasResumePlugin ? br._plugins.resume.getResumeValue() : false;
81
+ const hasResumePlugin = typeof(br.plugins.resume) !== "undefined";
82
+ const hasResumeValue = hasResumePlugin ? br.plugins.resume.getResumeValue() : false;
83
83
  return hasResumeValue;
84
84
  });
85
85
 
@@ -1,5 +1,5 @@
1
1
  import { Selector } from 'testcafe';
2
- import Nav from './Navigation';
2
+ import Nav from './Navigation.js';
3
3
 
4
4
  /** Model defining BookReader base elements */
5
5
  export default class BookReader {
@@ -1,8 +1,8 @@
1
- import { runBaseTests } from './helpers/base';
2
- import { runRightToLeftTests } from './helpers/rightToLeft';
3
- import params from './helpers/params';
1
+ import { runBaseTests } from './helpers/base.js';
2
+ import { runRightToLeftTests } from './helpers/rightToLeft.js';
3
+ import params from './helpers/params.js';
4
4
 
5
- import BookReader from './models/BookReader';
5
+ import BookReader from './models/BookReader.js';
6
6
 
7
7
  const ocaids = params.ocaids || [
8
8
  'gendaitankashu00meijuoft', // Right to Left book
@@ -1,6 +1,6 @@
1
1
  import { Selector } from 'testcafe';
2
- import BookReader from './models/BookReader';
3
- import params from './helpers/params';
2
+ import BookReader from './models/BookReader.js';
3
+ import params from './helpers/params.js';
4
4
 
5
5
  const ocaids = params.ocaids || ['goody'];
6
6
 
@@ -323,19 +323,6 @@ describe('<book-navigator>', () => {
323
323
  });
324
324
  });
325
325
 
326
- describe('Shortcuts', () => {
327
- test('has specific order of menu shortcuts to show', () => {
328
- const el = fixtureSync(container());
329
- expect(el.shortcutOrder).toEqual([
330
- 'fullscreen',
331
- 'volumes',
332
- 'chapters',
333
- 'search',
334
- 'bookmarks',
335
- ]);
336
- });
337
- });
338
-
339
326
  describe('Behaviors for specific menus', () => {
340
327
  describe('Search menu - ref: plugin.search.js', () => {
341
328
  test('Event: listens for `BookReader:ToggleSearchMenu to open search side panel', async () => {
@@ -1,6 +1,6 @@
1
1
  import { fixtureCleanup, fixtureSync } from '@open-wc/testing-helpers';
2
2
  import sinon from 'sinon';
3
- import DownloadsProvider from '@/src/BookNavigator/downloads/downloads-provider';
3
+ import DownloadsProvider from '@/src/BookNavigator/downloads/downloads-provider.js';
4
4
 
5
5
  const downloadableTypes = [
6
6
  ["PDF", "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.pdf"],
@@ -4,7 +4,7 @@ import {
4
4
  fixtureCleanup,
5
5
  } from '@open-wc/testing-helpers';
6
6
  import sinon from 'sinon';
7
- import '@/src/BookNavigator/downloads/downloads';
7
+ import '@/src/BookNavigator/downloads/downloads.js';
8
8
 
9
9
 
10
10
  const downloads = [
@@ -1,6 +1,6 @@
1
1
  import { fixtureCleanup, fixtureSync } from '@open-wc/testing-helpers';
2
2
  import sinon from 'sinon';
3
- import searchProvider from '@/src/BookNavigator/search/search-provider';
3
+ import searchProvider from '@/src/BookNavigator/search/search-provider.js';
4
4
 
5
5
  afterEach(() => {
6
6
  sinon.restore();
@@ -88,7 +88,7 @@ describe('Search Provider', () => {
88
88
  onProviderChange: sinon.fake(),
89
89
  bookreader: {
90
90
  leafNumToIndex: sinon.fake(),
91
- _plugins: {
91
+ plugins: {
92
92
  search: {
93
93
  jumpToMatch: sinon.fake(),
94
94
  },
@@ -104,7 +104,7 @@ describe('Search Provider', () => {
104
104
  { detail: searchResultStub }),
105
105
  );
106
106
 
107
- expect(provider.bookreader._plugins.search.jumpToMatch.callCount).toEqual(1);
107
+ expect(provider.bookreader.plugins.search.jumpToMatch.callCount).toEqual(1);
108
108
  });
109
109
  test('update url when search is cancelled or input cleared', async() => {
110
110
  const urlPluginMock = {
@@ -115,7 +115,7 @@ describe('Search Provider', () => {
115
115
  onProviderChange: sinon.fake(),
116
116
  bookreader: {
117
117
  leafNumToIndex: sinon.fake(),
118
- _plugins: {
118
+ plugins: {
119
119
  search: {
120
120
  jumpToMatch: sinon.fake(),
121
121
  },
@@ -153,7 +153,7 @@ describe('Search Provider', () => {
153
153
  onProviderChange: sinon.fake(),
154
154
  bookreader: {
155
155
  leafNumToIndex: sinon.fake(),
156
- _plugins: {
156
+ plugins: {
157
157
  search: {
158
158
  jumpToMatch: sinon.fake(),
159
159
  },
@@ -1,4 +1,4 @@
1
- import BookReader from '@/src/BookReader';
1
+ import BookReader from '@/src/BookReader.js';
2
2
  import { sleep } from '@/src/BookReader/utils.js';
3
3
  import sinon from 'sinon';
4
4
 
@@ -3,7 +3,7 @@ import sinon from 'sinon';
3
3
  import { Mode2Up } from '@/src/BookReader/Mode2Up.js';
4
4
  import BookReader from '@/src/BookReader.js';
5
5
  import { BookModel } from '@/src/BookReader/BookModel.js';
6
- import { afterEventLoop } from '../utils';
6
+ import { afterEventLoop } from '../utils.js';
7
7
  /** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
8
8
 
9
9
  beforeAll(() => {
@@ -1,4 +1,4 @@
1
- import { ModeCoordinateSpace } from "@/src/BookReader/ModeCoordinateSpace";
1
+ import { ModeCoordinateSpace } from "@/src/BookReader/ModeCoordinateSpace.js";
2
2
 
3
3
  describe("worldUnitsToRenderedPixels", () => {
4
4
  test("0 case", () => {
@@ -52,15 +52,26 @@ describe('constructor', () => {
52
52
  });
53
53
 
54
54
  test('non-empty page', () => {
55
- const pc = new PageContainer({index: 7}, {isProtected: false});
55
+ const page = {
56
+ index: 7,
57
+ getPageNum: () => '8',
58
+ };
59
+ const pc = new PageContainer(page, {isProtected: false});
56
60
  expect(pc.$container.hasClass('BRemptypage')).toBe(false);
57
61
  expect(pc.$container.hasClass('pagediv7')).toBe(true);
58
62
  });
59
63
 
60
- test('adds side attribute', () => {
61
- const pc = new PageContainer({index: 7, pageSide: 'R'}, {isProtected: false});
64
+ test('adds attributes', () => {
65
+ const page = {
66
+ index: 7,
67
+ pageSide: 'R',
68
+ getPageNum: () => '8',
69
+ };
70
+ const pc = new PageContainer(page, {isProtected: false});
62
71
  expect(pc.$container.hasClass('BRemptypage')).toBe(false);
63
72
  expect(pc.$container.attr('data-side')).toBe('R');
73
+ expect(pc.$container.attr('data-index')).toBe('7');
74
+ expect(pc.$container.attr('data-page-num')).toBe('8');
64
75
  });
65
76
  });
66
77
 
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
  import sinon from 'sinon';
3
- import { HTMLDimensionsCacher } from '@/src/BookReader/utils/HTMLDimensionsCacher';
3
+ import { HTMLDimensionsCacher } from '@/src/BookReader/utils/HTMLDimensionsCacher.js';
4
4
 
5
5
  describe('HTMLDimensionsCacher', () => {
6
6
  test('Does not read from element directly', () => {
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
  import sinon from 'sinon';
3
- import { ScrollClassAdder } from '@/src/BookReader/utils/ScrollClassAdder';
3
+ import { ScrollClassAdder } from '@/src/BookReader/utils/ScrollClassAdder.js';
4
4
 
5
5
  describe('ScrollClassAdder', () => {
6
6
  test('Does not attach during construction', () => {
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
  import sinon from "sinon";
3
- import { SelectionObserver } from "@/src/BookReader/utils/SelectionObserver";
3
+ import { SelectionObserver } from "@/src/BookReader/utils/SelectionObserver.js";
4
4
 
5
5
  afterEach(() => {
6
6
  sinon.restore();
@@ -39,35 +39,35 @@ test('has registered fullscreen toggle event', () => {
39
39
  });
40
40
 
41
41
  test('checks cookie when initParams called', () => {
42
- br._plugins.resume.getResumeValue = jest.fn(() => 15);
42
+ br.plugins.resume.getResumeValue = jest.fn(() => 15);
43
43
  br.urlReadFragment = jest.fn(() => '');
44
44
 
45
45
  const params = br.initParams();
46
- expect(br._plugins.resume.getResumeValue).toHaveBeenCalledTimes(1);
46
+ expect(br.plugins.resume.getResumeValue).toHaveBeenCalledTimes(1);
47
47
  expect(params.init).toBe(true);
48
48
  expect(params.index).toBe(15);
49
49
  expect(params.fragmentChange).toBe(true);
50
50
  });
51
51
 
52
52
  test('does not check cookie when initParams called', () => {
53
- br._plugins.resume.getResumeValue = jest.fn(() => null);
53
+ br.plugins.resume.getResumeValue = jest.fn(() => null);
54
54
  br.urlReadFragment = jest.fn(() => '');
55
55
  br.options.plugins.resume.enabled = false;
56
56
 
57
57
  const params = br.initParams();
58
- expect(br._plugins.resume.getResumeValue).toHaveBeenCalledTimes(0);
58
+ expect(br.plugins.resume.getResumeValue).toHaveBeenCalledTimes(0);
59
59
  expect(params.init).toBe(true);
60
60
  expect(params.index).toBe(0);
61
61
  expect(params.fragmentChange).toBe(false);
62
62
  });
63
63
 
64
64
  test('gets index from fragment when both fragment and cookie when InitParams called', () => {
65
- br._plugins.resume.getResumeValue = jest.fn(() => 15);
65
+ br.plugins.resume.getResumeValue = jest.fn(() => 15);
66
66
  br.urlReadFragment = jest.fn(() => 'page/n4');
67
67
  br.options.plugins.resume.enabled = true;
68
68
 
69
69
  const params = br.initParams();
70
- expect(br._plugins.resume.getResumeValue).toHaveBeenCalledTimes(1);
70
+ expect(br.plugins.resume.getResumeValue).toHaveBeenCalledTimes(1);
71
71
  expect(params.init).toBe(true);
72
72
  expect(params.index).toBe(4);
73
73
  expect(params.fragmentChange).toBe(true);
@@ -117,7 +117,7 @@ test('has added BR property: bookPath', () => {
117
117
  });
118
118
 
119
119
  test('has suppressFragmentChange true when init with no input', () => {
120
- br._plugins.resume.getResumeValue = jest.fn(() => null);
120
+ br.plugins.resume.getResumeValue = jest.fn(() => null);
121
121
  br.urlReadFragment = jest.fn(() => '');
122
122
  br.urlReadHashFragment = jest.fn(() => '');
123
123
  br.switchMode = jest.fn();
@@ -128,7 +128,7 @@ test('has suppressFragmentChange true when init with no input', () => {
128
128
  });
129
129
 
130
130
  test('has suppressFragmentChange false when init with cookie', () => {
131
- br._plugins.resume.getResumeValue = jest.fn(() => 5);
131
+ br.plugins.resume.getResumeValue = jest.fn(() => 5);
132
132
  br.urlReadFragment = jest.fn(() => '');
133
133
  br.switchMode = jest.fn();
134
134
 
@@ -138,7 +138,7 @@ test('has suppressFragmentChange false when init with cookie', () => {
138
138
  });
139
139
 
140
140
  test('has suppressFragmentChange false when init with fragment', () => {
141
- br._plugins.resume.getResumeValue = jest.fn(() => null);
141
+ br.plugins.resume.getResumeValue = jest.fn(() => null);
142
142
  br.urlReadFragment = jest.fn(() => 'mode/1up');
143
143
  br.switchMode = jest.fn();
144
144
 
@@ -148,7 +148,7 @@ test('has suppressFragmentChange false when init with fragment', () => {
148
148
  });
149
149
 
150
150
  test('has suppressFragmentChange false when init with hash fragment', () => {
151
- br._plugins.resume.getResumeValue = jest.fn(() => null);
151
+ br.plugins.resume.getResumeValue = jest.fn(() => null);
152
152
  br.urlReadFragment = jest.fn(() => '');
153
153
  br.urlReadHashFragment = jest.fn(() => 'mode/1up');
154
154
  br.switchMode = jest.fn();
@@ -15,21 +15,21 @@ afterEach(() => {
15
15
 
16
16
  describe('Plugin: Menu Toggle', () => {
17
17
  test('autoplay does not start when BookReaderInitializes', () => {
18
- br._plugins.autoplay.toggle = jest.fn();
18
+ br.plugins.autoplay.toggle = jest.fn();
19
19
  br.init();
20
- expect(br._plugins.autoplay.toggle).toHaveBeenCalledTimes(0);
20
+ expect(br.plugins.autoplay.toggle).toHaveBeenCalledTimes(0);
21
21
  });
22
22
  test('autoplay will run without `flipSpeed` parameters', () => {
23
- const initialTimer = br._plugins.autoplay.timer;
23
+ const initialTimer = br.plugins.autoplay.timer;
24
24
  br.next = jest.fn();
25
- br._plugins.autoplay.stop = jest.fn();
25
+ br.plugins.autoplay.stop = jest.fn();
26
26
  br.init();
27
- br._plugins.autoplay.toggle();
27
+ br.plugins.autoplay.toggle();
28
28
  // internally referenced functions that fire
29
29
  expect(br.next).toHaveBeenCalledTimes(1);
30
30
 
31
31
  expect(initialTimer).toBeFalsy();
32
32
  // timer changes when autoplay turns on
33
- expect(br._plugins.autoplay.timer).toBeTruthy();
33
+ expect(br.plugins.autoplay.timer).toBeTruthy();
34
34
  });
35
35
  });
@@ -2,8 +2,8 @@ import sinon from "sinon";
2
2
 
3
3
  import "@/src/BookReader.js";
4
4
  import {ChaptersPlugin} from "@/src/plugins/plugin.chapters.js";
5
- import { BookModel } from "@/src/BookReader/BookModel";
6
- import { deepCopy } from "../utils";
5
+ import { BookModel } from "@/src/BookReader/BookModel.js";
6
+ import { deepCopy } from "../utils.js";
7
7
  /** @typedef {import('@/src/plugins/plugin.chapters').TocEntry} TocEntry */
8
8
 
9
9
  /** @type {TocEntry[]} */
@@ -29,9 +29,9 @@ describe('updateResumeValue', () => {
29
29
  In this branch .toHaveBeenCalledTimes() === 1
30
30
  */
31
31
  test.skip('starts when BookReaderInit is called', () => {
32
- br._plugins.resume.updateResumeValue = jest.fn();
32
+ br.plugins.resume.updateResumeValue = jest.fn();
33
33
  br.init();
34
- expect(br._plugins.resume.updateResumeValue).toHaveBeenCalledTimes(2);
34
+ expect(br.plugins.resume.updateResumeValue).toHaveBeenCalledTimes(2);
35
35
  });
36
36
 
37
37
  test('handles cookieName=null', () => {
@@ -48,38 +48,38 @@ describe('updateResumeValue', () => {
48
48
  test('handles cookiePath not set', () => {
49
49
  const setItemSpy = sinon.spy(docCookies, 'setItem');
50
50
  // Save function
51
- const saveFn = br._plugins.resume.getCookiePath;
52
- br._plugins.resume.getCookiePath = jest.fn(() => '/details/foo');
53
- br._plugins.resume.updateResumeValue(16);
51
+ const saveFn = br.plugins.resume.getCookiePath;
52
+ br.plugins.resume.getCookiePath = jest.fn(() => '/details/foo');
53
+ br.plugins.resume.updateResumeValue(16);
54
54
  expect(setItemSpy.args[0][3]).toEqual('/details/foo');
55
55
  // Restore function
56
- br._plugins.resume.getCookiePath = saveFn;
56
+ br.plugins.resume.getCookiePath = saveFn;
57
57
  });
58
58
 
59
59
  test('handles cookie path from URL with decoration', () => {
60
60
  const complexPathWithPage = '/details/2008ELMValidityStudyFinalReportRevised/Executive%20Summary%20for%20the%20EPT%26ELM%20Validity%20Studie_20100603%20-%20Copy/page/n1/mode/2up';
61
61
  const complexPath = '/details/2008ELMValidityStudyFinalReportRevised/Executive%20Summary%20for%20the%20EPT%26ELM%20Validity%20Studie_20100603%20-%20Copy';
62
- expect(br._plugins.resume.getCookiePath(complexPathWithPage))
62
+ expect(br.plugins.resume.getCookiePath(complexPathWithPage))
63
63
  .toEqual(complexPath);
64
64
 
65
- expect(br._plugins.resume.getCookiePath('/details/item/mode/1up'))
65
+ expect(br.plugins.resume.getCookiePath('/details/item/mode/1up'))
66
66
  .toEqual('/details/item');
67
67
 
68
- expect(br._plugins.resume.getCookiePath('/details/item/inside/a/long/path/model/is/used'))
68
+ expect(br.plugins.resume.getCookiePath('/details/item/inside/a/long/path/model/is/used'))
69
69
  .toEqual('/details/item/inside/a/long/path/model/is/used');
70
70
 
71
- expect(br._plugins.resume.getCookiePath('/details/item/inside/a/long/path/mode/is/used'))
71
+ expect(br.plugins.resume.getCookiePath('/details/item/inside/a/long/path/mode/is/used'))
72
72
  .toEqual('/details/item/inside/a/long/path');
73
73
  });
74
74
 
75
75
  test('handles cookie path from URL with no decoration', () => {
76
- expect(br._plugins.resume.getCookiePath('/details/item'))
76
+ expect(br.plugins.resume.getCookiePath('/details/item'))
77
77
  .toEqual('/details/item');
78
78
 
79
- expect(br._plugins.resume.getCookiePath('/details/item/'))
79
+ expect(br.plugins.resume.getCookiePath('/details/item/'))
80
80
  .toEqual('/details/item/');
81
81
 
82
- expect(br._plugins.resume.getCookiePath('/details/item/almost/any/kind/of/long/path'))
82
+ expect(br.plugins.resume.getCookiePath('/details/item/almost/any/kind/of/long/path'))
83
83
  .toEqual('/details/item/almost/any/kind/of/long/path');
84
84
  });
85
85
  });