@internetarchive/bookreader 5.0.0-6-14 → 5.0.0-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. package/.eslintrc.js +17 -15
  2. package/.github/workflows/node.js.yml +72 -10
  3. package/.github/workflows/npm-publish.yml +6 -20
  4. package/.testcaferc.js +10 -0
  5. package/BookReader/BookReader.css +241 -140
  6. package/BookReader/BookReader.js +1 -1
  7. package/BookReader/BookReader.js.LICENSE.txt +24 -20
  8. package/BookReader/BookReader.js.map +1 -1
  9. package/BookReader/ia-bookreader-bundle.js +1519 -0
  10. package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +17 -0
  11. package/BookReader/ia-bookreader-bundle.js.map +1 -0
  12. package/BookReader/icons/close-circle-dark.svg +1 -0
  13. package/BookReader/icons/magnify-minus.svg +1 -1
  14. package/BookReader/icons/magnify-plus.svg +1 -1
  15. package/BookReader/icons/pause.svg +1 -1
  16. package/BookReader/icons/playback-speed.svg +1 -1
  17. package/BookReader/icons/read-aloud.svg +1 -1
  18. package/BookReader/icons/voice.svg +1 -0
  19. package/BookReader/images/BRicons.svg +2 -2
  20. package/BookReader/images/books_graphic.svg +1 -1
  21. package/BookReader/images/icon_book.svg +1 -1
  22. package/BookReader/images/icon_gear.svg +1 -1
  23. package/BookReader/images/icon_info.svg +1 -1
  24. package/BookReader/images/icon_playback-rate.svg +1 -1
  25. package/BookReader/images/icon_search_button.svg +1 -1
  26. package/BookReader/images/icon_share.svg +1 -1
  27. package/BookReader/images/icon_speaker.svg +1 -1
  28. package/BookReader/images/icon_speaker_open.svg +1 -1
  29. package/BookReader/images/marker_chap-off.svg +1 -1
  30. package/BookReader/images/marker_chap-on.svg +1 -1
  31. package/BookReader/images/marker_srch-on.svg +1 -1
  32. package/BookReader/jquery-3.js +2 -0
  33. package/BookReader/jquery-3.js.LICENSE.txt +24 -0
  34. package/BookReader/plugins/plugin.archive_analytics.js +1 -1
  35. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  36. package/BookReader/plugins/plugin.autoplay.js +1 -1
  37. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  38. package/BookReader/plugins/plugin.chapters.js +1 -1
  39. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  40. package/BookReader/plugins/plugin.iframe.js +1 -1
  41. package/BookReader/plugins/plugin.iframe.js.map +1 -1
  42. package/BookReader/plugins/plugin.mobile_nav.js +1 -1
  43. package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
  44. package/BookReader/plugins/plugin.resume.js +1 -1
  45. package/BookReader/plugins/plugin.resume.js.map +1 -1
  46. package/BookReader/plugins/plugin.search.js +1 -1
  47. package/BookReader/plugins/plugin.search.js.map +1 -1
  48. package/BookReader/plugins/plugin.text_selection.js +1 -1
  49. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  50. package/BookReader/plugins/plugin.tts.js +1 -1
  51. package/BookReader/plugins/plugin.tts.js.map +1 -1
  52. package/BookReader/plugins/plugin.url.js +1 -1
  53. package/BookReader/plugins/plugin.url.js.map +1 -1
  54. package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
  55. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
  56. package/BookReader/webcomponents-bundle.js +3 -0
  57. package/BookReader/webcomponents-bundle.js.LICENSE.txt +9 -0
  58. package/BookReader/webcomponents-bundle.js.map +1 -0
  59. package/BookReaderDemo/BookReaderDemo.css +14 -1
  60. package/BookReaderDemo/BookReaderJSAutoplay.js +4 -1
  61. package/BookReaderDemo/BookReaderJSSimple.js +1 -0
  62. package/BookReaderDemo/IADemoBr.js +147 -0
  63. package/BookReaderDemo/demo-advanced.html +2 -2
  64. package/BookReaderDemo/demo-autoplay.html +2 -1
  65. package/BookReaderDemo/demo-embed-iframe-src.html +2 -1
  66. package/BookReaderDemo/demo-fullscreen-mobile.html +2 -1
  67. package/BookReaderDemo/demo-fullscreen.html +2 -1
  68. package/BookReaderDemo/demo-iiif.html +2 -1
  69. package/BookReaderDemo/demo-internetarchive.html +84 -17
  70. package/BookReaderDemo/demo-multiple.html +2 -1
  71. package/BookReaderDemo/demo-preview-pages.html +2 -1
  72. package/BookReaderDemo/demo-simple.html +2 -1
  73. package/BookReaderDemo/demo-vendor-fullscreen.html +2 -1
  74. package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
  75. package/BookReaderDemo/immersion-1up.html +2 -1
  76. package/BookReaderDemo/immersion-mode.html +2 -1
  77. package/BookReaderDemo/toggle_controls.html +2 -1
  78. package/BookReaderDemo/view_mode.html +2 -1
  79. package/BookReaderDemo/viewmode-cycle.html +2 -3
  80. package/CHANGELOG.md +244 -0
  81. package/README.md +14 -1
  82. package/babel.config.js +19 -0
  83. package/codecov.yml +6 -0
  84. package/index.html +3 -0
  85. package/jsconfig.json +19 -0
  86. package/netlify.toml +5 -0
  87. package/package.json +70 -59
  88. package/renovate.json +52 -0
  89. package/scripts/preversion.js +4 -1
  90. package/src/BookNavigator/assets/bookmark-colors.js +1 -1
  91. package/src/BookNavigator/assets/button-base.js +9 -2
  92. package/src/BookNavigator/assets/ia-logo.js +17 -0
  93. package/src/BookNavigator/assets/icon_checkmark.js +1 -1
  94. package/src/BookNavigator/assets/icon_close.js +1 -1
  95. package/src/BookNavigator/assets/icon_sort_asc.js +5 -0
  96. package/src/BookNavigator/assets/icon_sort_desc.js +5 -0
  97. package/src/BookNavigator/assets/icon_sort_neutral.js +5 -0
  98. package/src/BookNavigator/assets/icon_volumes.js +11 -0
  99. package/src/BookNavigator/book-navigator.js +585 -0
  100. package/src/BookNavigator/bookmarks/bookmark-button.js +3 -2
  101. package/src/BookNavigator/bookmarks/bookmark-edit.js +3 -4
  102. package/src/BookNavigator/bookmarks/bookmarks-list.js +2 -3
  103. package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +3 -8
  104. package/src/BookNavigator/bookmarks/bookmarks-provider.js +27 -17
  105. package/src/BookNavigator/bookmarks/ia-bookmarks.js +116 -67
  106. package/src/BookNavigator/delete-modal-actions.js +1 -1
  107. package/src/BookNavigator/downloads/downloads-provider.js +36 -21
  108. package/src/BookNavigator/downloads/downloads.js +41 -25
  109. package/src/BookNavigator/search/search-provider.js +80 -28
  110. package/src/BookNavigator/search/search-results.js +34 -25
  111. package/src/BookNavigator/sharing.js +27 -0
  112. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +11 -10
  113. package/src/BookNavigator/visual-adjustments/visual-adjustments.js +3 -3
  114. package/src/BookNavigator/volumes/volumes-provider.js +111 -0
  115. package/src/BookNavigator/volumes/volumes.js +188 -0
  116. package/src/BookReader/BookModel.js +59 -30
  117. package/src/BookReader/DebugConsole.js +3 -3
  118. package/src/BookReader/DragScrollable.js +233 -0
  119. package/src/BookReader/Mode1Up.js +56 -351
  120. package/src/BookReader/Mode1UpLit.js +391 -0
  121. package/src/BookReader/Mode2Up.js +73 -1318
  122. package/src/BookReader/Mode2UpLit.js +781 -0
  123. package/src/BookReader/ModeCoordinateSpace.js +29 -0
  124. package/src/BookReader/ModeSmoothZoom.js +211 -0
  125. package/src/BookReader/ModeThumb.js +17 -11
  126. package/src/BookReader/Navbar/Navbar.js +10 -36
  127. package/src/BookReader/PageContainer.js +69 -6
  128. package/src/BookReader/ReduceSet.js +1 -1
  129. package/src/BookReader/Toolbar/Toolbar.js +10 -37
  130. package/src/BookReader/events.js +2 -0
  131. package/src/BookReader/options.js +24 -2
  132. package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
  133. package/src/BookReader/utils/ScrollClassAdder.js +31 -0
  134. package/src/BookReader/utils.js +108 -13
  135. package/src/BookReader.js +481 -828
  136. package/src/assets/icons/close-circle-dark.svg +1 -0
  137. package/src/assets/icons/magnify-minus.svg +3 -7
  138. package/src/assets/icons/magnify-plus.svg +3 -7
  139. package/src/assets/icons/voice.svg +1 -0
  140. package/src/css/_BRBookmarks.scss +1 -1
  141. package/src/css/_BRComponent.scss +1 -1
  142. package/src/css/_BRmain.scss +33 -0
  143. package/src/css/_BRnav.scss +4 -26
  144. package/src/css/_BRpages.scss +147 -40
  145. package/src/css/_BRsearch.scss +25 -11
  146. package/src/css/_TextSelection.scss +16 -17
  147. package/src/css/_colorbox.scss +2 -2
  148. package/src/css/_controls.scss +17 -5
  149. package/src/css/_icons.scss +7 -1
  150. package/src/ia-bookreader/ia-bookreader.js +224 -0
  151. package/src/plugins/plugin.archive_analytics.js +3 -3
  152. package/src/plugins/plugin.autoplay.js +4 -9
  153. package/src/plugins/plugin.chapters.js +28 -35
  154. package/src/plugins/plugin.mobile_nav.js +11 -10
  155. package/src/plugins/plugin.resume.js +3 -3
  156. package/src/plugins/plugin.text_selection.js +32 -41
  157. package/src/plugins/plugin.vendor-fullscreen.js +4 -4
  158. package/src/plugins/search/plugin.search.js +179 -103
  159. package/src/plugins/search/view.js +59 -44
  160. package/src/plugins/tts/AbstractTTSEngine.js +46 -37
  161. package/src/plugins/tts/FestivalTTSEngine.js +13 -14
  162. package/src/plugins/tts/PageChunk.js +15 -21
  163. package/src/plugins/tts/PageChunkIterator.js +8 -12
  164. package/src/plugins/tts/WebTTSEngine.js +87 -71
  165. package/src/plugins/tts/plugin.tts.js +94 -125
  166. package/src/plugins/tts/utils.js +0 -25
  167. package/src/plugins/url/UrlPlugin.js +193 -0
  168. package/src/plugins/{plugin.url.js → url/plugin.url.js} +45 -16
  169. package/src/util/docCookies.js +21 -2
  170. package/tests/e2e/README.md +37 -0
  171. package/tests/e2e/autoplay.test.js +2 -2
  172. package/tests/e2e/base.test.js +7 -7
  173. package/tests/e2e/helpers/base.js +28 -23
  174. package/tests/e2e/helpers/debug.js +1 -1
  175. package/tests/e2e/helpers/desktopSearch.js +14 -13
  176. package/tests/e2e/helpers/mobileSearch.js +3 -3
  177. package/tests/e2e/helpers/params.js +17 -0
  178. package/tests/e2e/helpers/rightToLeft.js +4 -10
  179. package/tests/e2e/models/Navigation.js +13 -4
  180. package/tests/e2e/rightToLeft.test.js +4 -5
  181. package/tests/e2e/viewmode.test.js +40 -33
  182. package/tests/jest/BookNavigator/book-navigator.test.js +658 -0
  183. package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +43 -0
  184. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-edit.test.js +25 -26
  185. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmarks-list.test.js +41 -42
  186. package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +45 -0
  187. package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +67 -0
  188. package/tests/jest/BookNavigator/downloads/downloads.test.js +53 -0
  189. package/tests/jest/BookNavigator/search/search-provider.test.js +167 -0
  190. package/tests/{karma/BookNavigator → jest/BookNavigator/search}/search-results.test.js +104 -60
  191. package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +49 -0
  192. package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
  193. package/tests/jest/BookNavigator/volumes/volumes-provider.test.js +184 -0
  194. package/tests/jest/BookNavigator/volumes/volumes.test.js +97 -0
  195. package/tests/{BookReader → jest/BookReader}/BookModel.test.js +59 -14
  196. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +193 -0
  197. package/tests/{BookReader → jest/BookReader}/DebugConsole.test.js +1 -1
  198. package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
  199. package/tests/jest/BookReader/Mode1UpLit.test.js +73 -0
  200. package/tests/jest/BookReader/Mode2Up.test.js +98 -0
  201. package/tests/jest/BookReader/Mode2UpLit.test.js +190 -0
  202. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +16 -0
  203. package/tests/jest/BookReader/ModeSmoothZoom.test.js +175 -0
  204. package/tests/jest/BookReader/ModeThumb.test.js +71 -0
  205. package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +10 -10
  206. package/tests/{BookReader → jest/BookReader}/PageContainer.test.js +88 -6
  207. package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +1 -1
  208. package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +2 -2
  209. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +59 -0
  210. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
  211. package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
  212. package/tests/jest/BookReader/utils.test.js +217 -0
  213. package/tests/jest/BookReader.keyboard.test.js +190 -0
  214. package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +9 -1
  215. package/tests/{BookReader.test.js → jest/BookReader.test.js} +26 -37
  216. package/tests/{plugins → jest/plugins}/plugin.archive_analytics.test.js +2 -2
  217. package/tests/{plugins → jest/plugins}/plugin.autoplay.test.js +4 -4
  218. package/tests/{plugins → jest/plugins}/plugin.chapters.test.js +10 -11
  219. package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +2 -2
  220. package/tests/{plugins → jest/plugins}/plugin.mobile_nav.test.js +5 -5
  221. package/tests/{plugins → jest/plugins}/plugin.resume.test.js +3 -3
  222. package/tests/{plugins → jest/plugins}/plugin.text_selection.test.js +39 -47
  223. package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
  224. package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +57 -47
  225. package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +35 -6
  226. package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +9 -9
  227. package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +4 -4
  228. package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +1 -1
  229. package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +3 -3
  230. package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +47 -1
  231. package/tests/{plugins → jest/plugins}/tts/utils.test.js +1 -60
  232. package/tests/jest/plugins/url/UrlPlugin.test.js +190 -0
  233. package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +53 -14
  234. package/tests/jest/setup.js +3 -0
  235. package/tests/{util → jest/util}/browserSniffing.test.js +1 -1
  236. package/tests/jest/util/docCookies.test.js +24 -0
  237. package/tests/{util → jest/util}/strings.test.js +1 -1
  238. package/tests/{utils.js → jest/utils.js} +38 -0
  239. package/webpack.config.js +11 -5
  240. package/.babelrc +0 -12
  241. package/.dependabot/config.yml +0 -6
  242. package/.testcaferc.json +0 -5
  243. package/BookReader/bookreader-component-bundle.js +0 -1450
  244. package/BookReader/bookreader-component-bundle.js.LICENSE.txt +0 -38
  245. package/BookReader/bookreader-component-bundle.js.map +0 -1
  246. package/BookReader/jquery-1.10.1.js +0 -2
  247. package/BookReader/jquery-1.10.1.js.LICENSE.txt +0 -24
  248. package/BookReader/plugins/plugin.menu_toggle.js +0 -2
  249. package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
  250. package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
  251. package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
  252. package/karma.conf.js +0 -23
  253. package/src/BookNavigator/BookModel.js +0 -14
  254. package/src/BookNavigator/BookNavigator.js +0 -438
  255. package/src/BookNavigator/assets/book-loader.js +0 -27
  256. package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
  257. package/src/BookNavigator/search/a-search-result.js +0 -55
  258. package/src/BookReaderComponent/BookReaderComponent.js +0 -112
  259. package/src/ItemNavigator/ItemNavigator.js +0 -372
  260. package/src/ItemNavigator/providers/sharing.js +0 -29
  261. package/src/dragscrollable-br.js +0 -261
  262. package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
  263. package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
  264. package/tests/BookReader/Mode1Up.test.js +0 -164
  265. package/tests/BookReader/Mode2Up.test.js +0 -247
  266. package/tests/BookReader/utils.test.js +0 -109
  267. package/tests/e2e/ia-production/ia-prod-base.js +0 -17
  268. package/tests/karma/BookNavigator/book-navigator.test.js +0 -132
  269. package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
  270. package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
  271. package/tests/util/docCookies.test.js +0 -15
@@ -0,0 +1,193 @@
1
+ import BookReader from '@/src/BookReader';
2
+ import { sleep } from '@/src/BookReader/utils.js';
3
+ import sinon from 'sinon';
4
+
5
+ beforeAll(() => {
6
+ global.alert = sinon.fake();
7
+ });
8
+ afterEach(() => {
9
+ sinon.restore();
10
+ });
11
+
12
+ describe('BookReader.prototype.toggleFullscreen', () => {
13
+ test('uses `isFullscreen` to check fullscreen state', () => {
14
+ const isFSmock = sinon.fake();
15
+ // isFSmock.mockReturnValueOnce(false);
16
+ const br = new BookReader();
17
+ br.mode = br.constMode1up;
18
+ br.enterFullscreen = sinon.fake();
19
+ br.isFullscreen = isFSmock;
20
+
21
+ br.toggleFullscreen();
22
+ expect(br.isFullscreen.callCount).toEqual(1);
23
+ });
24
+
25
+ test('will always emit an event', async () => {
26
+ const br = new BookReader();
27
+ br.mode = br.constMode2up;
28
+ br.trigger = sinon.fake();
29
+ br.switchMode = sinon.fake();
30
+ br.updateBrClasses = sinon.fake();
31
+ br.jumpToIndex = sinon.fake();
32
+ br.refs.$brContainer = {
33
+ css: sinon.fake(),
34
+ animate: (options, speed, style, callback) => callback()
35
+ };
36
+ br.refs.$br = {
37
+ updateBrClasses: sinon.fake(),
38
+ removeClass: sinon.fake(),
39
+ addClass: sinon.fake(),
40
+ css: sinon.fake(),
41
+ animate: (options, speed, style, callback) => callback()
42
+ };
43
+
44
+ await br.toggleFullscreen();
45
+ expect(br.trigger.callCount).toBeGreaterThan(0);
46
+ });
47
+
48
+ test('will start with opening fullscreen', () => {
49
+ const br = new BookReader();
50
+ br.mode = br.constMode2up;
51
+ br.enterFullscreen = sinon.fake();
52
+
53
+ br.toggleFullscreen();
54
+ expect(br.enterFullscreen.callCount).toEqual(1);
55
+ });
56
+
57
+ test('will close fullscreen if BookReader is in fullscreen', () => {
58
+ const br = new BookReader();
59
+ br.mode = br.constMode1up;
60
+ br.exitFullScreen = sinon.fake();
61
+ br.isFullscreenActive = true;
62
+
63
+ br.toggleFullscreen();
64
+ expect(br.exitFullScreen.callCount).toEqual(1);
65
+ });
66
+ });
67
+
68
+ describe('BookReader.prototype.enterFullscreen', () => {
69
+ test('will bind `_fullscreenCloseHandler` by default', () => {
70
+ const br = new BookReader();
71
+ br.mode = br.constMode1up;
72
+ br.switchMode = sinon.fake();
73
+ br.updateBrClasses = sinon.fake();
74
+ br.refs.$br = {
75
+ css: sinon.fake(),
76
+ animate: sinon.fake(),
77
+ addClass: sinon.fake(),
78
+ };
79
+ expect(br._fullscreenCloseHandler).toBeUndefined();
80
+
81
+ br.enterFullscreen();
82
+ expect(br._fullscreenCloseHandler).toBeDefined();
83
+ });
84
+
85
+ test('fires certain events when called', async () => {
86
+ const br = new BookReader();
87
+ br.mode = br.constMode2up;
88
+ br.switchMode = sinon.fake();
89
+ br.updateBrClasses = sinon.fake();
90
+ br.trigger = sinon.fake();
91
+ br.resize = sinon.fake();
92
+ br.jumpToIndex = sinon.fake();
93
+ br.refs.$br = {
94
+ addClass: sinon.fake(),
95
+ removeClass: sinon.fake(),
96
+ };
97
+ br.refs.$brContainer = {
98
+ css: sinon.fake(),
99
+ animate: (options, speed, style, callback) => callback(),
100
+ };
101
+
102
+ await br.enterFullscreen();
103
+ expect(br.switchMode.callCount).toEqual(1);
104
+ expect(br.updateBrClasses.callCount).toEqual(1);
105
+ expect(br.trigger.callCount).toEqual(2); // fragmentChange, fullscreenToggled
106
+ expect(br.jumpToIndex.callCount).toEqual(1);
107
+
108
+ await sleep(0);
109
+ expect(br.resize.callCount).toEqual(1);
110
+ });
111
+ });
112
+
113
+ describe('BookReader.prototype.exitFullScreen', () => {
114
+ test('fires certain events when called', async () => {
115
+ const br = new BookReader();
116
+ br.mode = br.constMode2up;
117
+ br.switchMode = sinon.fake();
118
+ br.updateBrClasses = sinon.fake();
119
+ br.trigger = sinon.fake();
120
+ br.resize = sinon.fake();
121
+ br.refs.$br = {
122
+ addClass: sinon.fake(),
123
+ removeClass: sinon.fake(),
124
+ };
125
+ br.refs.$brContainer = {
126
+ css: sinon.fake(),
127
+ animate: (options, speed, style, callback) => callback()
128
+ };
129
+ await br.exitFullScreen();
130
+ expect(br.switchMode.callCount).toEqual(1);
131
+ expect(br.updateBrClasses.callCount).toEqual(1);
132
+ expect(br.trigger.callCount).toEqual(2); // fragmentChange, fullscreenToggled
133
+ expect(br.resize.callCount).toEqual(1);
134
+ });
135
+ });
136
+
137
+ describe('BookReader.prototype.trigger', () => {
138
+ test('fires custom event', () => {
139
+ const br = new BookReader();
140
+ global.br = br;
141
+ global.dispatchEvent = sinon.fake();
142
+
143
+ const props = {bar: 1};
144
+ br.trigger('foo', props);
145
+ expect(global.dispatchEvent.callCount).toBe(1);
146
+ });
147
+ });
148
+
149
+ describe('`BookReader.prototype.prev`', () => {
150
+ let br;
151
+ let flipAnimationStub;
152
+ beforeEach(() => {
153
+ br = new BookReader();
154
+ global.br = br;
155
+ br.trigger = sinon.fake();
156
+ br.jumpToIndex = sinon.fake();
157
+ flipAnimationStub = sinon.stub(br._modes.mode2Up.mode2UpLit, 'flipAnimation');
158
+ });
159
+
160
+ afterEach(() => {
161
+ sinon.restore();
162
+ });
163
+
164
+ test('does not take action if user is on front page', () => {
165
+ br.firstIndex = 0;
166
+ br.prev();
167
+ expect(br.trigger.callCount).toBe(0);
168
+ expect(flipAnimationStub.callCount).toBe(0);
169
+ expect(br.jumpToIndex.callCount).toBe(0);
170
+ });
171
+
172
+ describe('2up mode', () => {
173
+ test('fires event and turns the page', () => {
174
+ br.firstIndex = 10;
175
+ br.mode = br.constMode2up;
176
+ br.prev();
177
+ expect(br.jumpToIndex.callCount).toBe(0); // <-- does not get called
178
+ expect(br.trigger.callCount).toBe(1);
179
+ expect(flipAnimationStub.callCount).toBe(1);
180
+ });
181
+ });
182
+
183
+ describe('non 2up mode', () => {
184
+ test('jumps to provided index', () => {
185
+ br.firstIndex = 100;
186
+ br.mode = br.constMode1up;
187
+ br.prev();
188
+ expect(br.jumpToIndex.callCount).toBe(1); // <-- gets called
189
+ expect(flipAnimationStub.callCount).toBe(0); // <-- gets called by `jumpToIndex` internally
190
+ });
191
+ });
192
+ });
193
+
@@ -1,5 +1,5 @@
1
1
  import sinon from 'sinon';
2
- import { DebugConsole } from '../../src/BookReader/DebugConsole.js';
2
+ import { DebugConsole } from '@/src/BookReader/DebugConsole.js';
3
3
 
4
4
  beforeEach(() => {
5
5
  sinon.stub(console, 'log');
@@ -1,8 +1,8 @@
1
1
  import sinon from 'sinon';
2
- import { BookModel } from '../../src/BookReader/BookModel.js';
3
- import { ImageCache } from '../../src/BookReader/ImageCache.js';
4
- import { Pow2ReduceSet } from '../../src/BookReader/ReduceSet.js';
5
- /** @typedef {import('../../src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
2
+ import { BookModel } from '@/src/BookReader/BookModel.js';
3
+ import { ImageCache } from '@/src/BookReader/ImageCache.js';
4
+ import { Pow2ReduceSet } from '@/src/BookReader/ReduceSet.js';
5
+ /** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
6
6
 
7
7
  afterEach(() => {
8
8
  jest.restoreAllMocks();
@@ -0,0 +1,73 @@
1
+ import { BookModel } from '@/src/BookReader/BookModel.js';
2
+ import { Mode1UpLit } from '@/src/BookReader/Mode1UpLit.js';
3
+
4
+ /** @type {import('@/src/BookReader/options.js').BookReaderOptions['data']} */
5
+ const SAMPLE_DATA = [
6
+ [
7
+ { width: 123, height: 123, uri: 'https://archive.org/image0.jpg', pageNum: '1' },
8
+ ],
9
+ [
10
+ { width: 123, height: 123, uri: 'https://archive.org/image1.jpg', pageNum: '2' },
11
+ { width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '3' },
12
+ ],
13
+ [
14
+ { width: 123, height: 123, uri: 'https://archive.org/image3.jpg', pageNum: '4' },
15
+ { width: 123, height: 123, uri: 'https://archive.org/image4.jpg', pageNum: '5' },
16
+ ],
17
+ [
18
+ { width: 123, height: 123, uri: 'https://archive.org/image5.jpg', pageNum: '6' },
19
+ ],
20
+ ];
21
+
22
+ function make_dummy_br(overrides = {}) {
23
+ return Object.assign({
24
+ updateFirstIndex() {},
25
+ _components: {
26
+ navbar: {
27
+ updateNavIndexThrottled() {},
28
+ }
29
+ },
30
+ data: []
31
+ }, overrides);
32
+ }
33
+
34
+ describe('pageTops', () => {
35
+ afterEach(() => document.body.innerHTML = '');
36
+
37
+ test('Works with empty book', async () => {
38
+ const br = make_dummy_br({ data: [] });
39
+ const book = new BookModel(br);
40
+ const mode = new Mode1UpLit(book, br);
41
+ document.body.appendChild(mode);
42
+ mode.requestUpdate();
43
+ await mode.updateComplete;
44
+ expect(mode.pageTops).toEqual({});
45
+ });
46
+
47
+ test('Iterates all pages', async () => {
48
+ const br = make_dummy_br({ data: SAMPLE_DATA });
49
+ const book = new BookModel(br);
50
+ const mode = new Mode1UpLit(book, br);
51
+ document.body.appendChild(mode);
52
+ await mode.requestUpdate();
53
+ expect(Object.values(mode.pageTops)).toHaveLength(6);
54
+ });
55
+
56
+ test('Computes tops', async () => {
57
+ const br = make_dummy_br({ data: SAMPLE_DATA });
58
+ const book = new BookModel(br);
59
+ const mode = new Mode1UpLit(book, br);
60
+ document.body.appendChild(mode);
61
+ await mode.requestUpdate();
62
+ const tops = Object.entries(mode.pageTops);
63
+ expect(tops.map(([index, top]) => [index, top.toFixed(1)])).toEqual([
64
+ // Recall these are in inches
65
+ ['0', '0.2'],
66
+ ['1', '0.6'],
67
+ ['2', '1.1'],
68
+ ['3', '1.5'],
69
+ ['4', '2.0'],
70
+ ['5', '2.4'],
71
+ ]);
72
+ });
73
+ });
@@ -0,0 +1,98 @@
1
+
2
+ import sinon from 'sinon';
3
+ import { Mode2Up } from '@/src/BookReader/Mode2Up.js';
4
+ import BookReader from '@/src/BookReader.js';
5
+ import { BookModel } from '@/src/BookReader/BookModel.js';
6
+ import { afterEventLoop } from '../utils';
7
+ /** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
8
+
9
+ beforeAll(() => {
10
+ global.alert = jest.fn();
11
+ });
12
+ afterEach(() => {
13
+ jest.restoreAllMocks();
14
+ sinon.restore();
15
+ });
16
+
17
+ /** @type {BookReaderOptions['data']} */
18
+ const SAMPLE_DATA = [
19
+ [
20
+ { width: 123, height: 123, uri: 'https://archive.org/image0.jpg', pageNum: '1' },
21
+ ],
22
+ [
23
+ { width: 123, height: 123, uri: 'https://archive.org/image1.jpg', pageNum: '2' },
24
+ { width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '3' },
25
+ ],
26
+ [
27
+ { width: 123, height: 123, uri: 'https://archive.org/image3.jpg', pageNum: '4' },
28
+ { width: 123, height: 123, uri: 'https://archive.org/image4.jpg', pageNum: '5' },
29
+ ],
30
+ [
31
+ { width: 123, height: 123, uri: 'https://archive.org/image5.jpg', pageNum: '6' },
32
+ ],
33
+ ];
34
+
35
+
36
+ describe('Mode2Up', () => {
37
+ /** @type {BookReader} */
38
+ let br;
39
+ /** @type {BookModel} */
40
+ let bookModel;
41
+ /** @type {Mode2Up} */
42
+ let mode2Up;
43
+
44
+ beforeEach(() => {
45
+ br = new BookReader({
46
+ data: SAMPLE_DATA,
47
+ el: document.createElement('div'),
48
+ });
49
+ br.init();
50
+ bookModel = new BookModel(br);
51
+ mode2Up = new Mode2Up(br, bookModel);
52
+ });
53
+
54
+ describe('prepare', () => {
55
+ it('initializes DOM properly', async () => {
56
+ const spyAppend = sinon.spy(br.refs.$brContainer, 'append');
57
+ const spyRequestUpdate = sinon.spy(mode2Up.mode2UpLit, 'requestUpdate');
58
+ const initFirstRenderSpy = sinon.spy(mode2Up.mode2UpLit, 'initFirstRender');
59
+ const jumpToIndexSpy = sinon.spy(mode2Up.mode2UpLit, 'jumpToIndex');
60
+ sinon.stub(mode2Up.mode2UpLit, 'updateComplete').get(() => Promise.resolve());
61
+ mode2Up.prepare();
62
+
63
+ expect(br.refs.$brContainer[0].style.overflow).toEqual('hidden');
64
+ expect(spyAppend.calledWith(mode2Up.$el)).toBe(true);
65
+ expect(mode2Up.mode2UpLit.style.opacity).toEqual('0');
66
+
67
+ await afterEventLoop();
68
+
69
+ expect(initFirstRenderSpy.called).toBe(true);
70
+ expect(jumpToIndexSpy.called).toBe(false);
71
+ expect(mode2Up.everShown).toBe(true);
72
+ expect(spyRequestUpdate.called).toBe(true);
73
+ expect(mode2Up.mode2UpLit.style.opacity).toEqual('1');
74
+ });
75
+ });
76
+
77
+ describe('resizePageView', () => {
78
+ it('updates autoFit when possible', async () => {
79
+ const updateClientSizesSpy = sinon.stub(mode2Up.mode2UpLit.htmlDimensionsCacher, 'updateClientSizes');
80
+ const resizeViaAutofitSpy = sinon.spy(mode2Up.mode2UpLit, 'resizeViaAutofit');
81
+ const recenterStub = sinon.stub(mode2Up.mode2UpLit, 'recenter');
82
+
83
+ mode2Up.resizePageView();
84
+ expect(updateClientSizesSpy.called).toBe(true);
85
+ expect(resizeViaAutofitSpy.called).toBe(true);
86
+ expect(recenterStub.called).toBe(true);
87
+
88
+ // Test with scale and autoFit as 'none'
89
+ mode2Up.mode2UpLit.scale = 0.1;
90
+ mode2Up.mode2UpLit.autoFit = 'none';
91
+ mode2Up.resizePageView();
92
+
93
+ expect(mode2Up.mode2UpLit.autoFit).toEqual('auto');
94
+ expect(resizeViaAutofitSpy.callCount).toEqual(2);
95
+ expect(recenterStub.callCount).toEqual(2);
96
+ });
97
+ });
98
+ });
@@ -0,0 +1,190 @@
1
+ import sinon from "sinon";
2
+ import { BookModel } from "@/src/BookReader/BookModel.js";
3
+ import { Mode2UpLit } from "@/src/BookReader/Mode2UpLit.js";
4
+
5
+ /** @type {import('@/src/BookReader/options.js').BookReaderOptions['data']} */
6
+ const SAMPLE_DATA = [
7
+ [
8
+ {
9
+ width: 123,
10
+ height: 123,
11
+ uri: "https://archive.org/image0.jpg",
12
+ pageNum: "1",
13
+ },
14
+ ],
15
+ [
16
+ {
17
+ width: 123,
18
+ height: 123,
19
+ uri: "https://archive.org/image1.jpg",
20
+ pageNum: "2",
21
+ },
22
+ {
23
+ width: 123,
24
+ height: 123,
25
+ uri: "https://archive.org/image2.jpg",
26
+ pageNum: "3",
27
+ },
28
+ ],
29
+ [
30
+ {
31
+ width: 123,
32
+ height: 123,
33
+ uri: "https://archive.org/image3.jpg",
34
+ pageNum: "4",
35
+ },
36
+ {
37
+ width: 123,
38
+ height: 123,
39
+ uri: "https://archive.org/image4.jpg",
40
+ pageNum: "5",
41
+ },
42
+ ],
43
+ [
44
+ {
45
+ width: 123,
46
+ height: 123,
47
+ uri: "https://archive.org/image5.jpg",
48
+ pageNum: "6",
49
+ },
50
+ ],
51
+ ];
52
+
53
+ function make_dummy_br(overrides = {}) {
54
+ return Object.assign({
55
+ updateFirstIndex() {},
56
+ _components: {
57
+ navbar: {
58
+ updateNavIndexThrottled() {},
59
+ },
60
+ },
61
+ data: [],
62
+ }, overrides);
63
+ }
64
+
65
+ afterEach(() => {
66
+ sinon.restore();
67
+ });
68
+
69
+ describe("computePageHeight", () => {
70
+ test("Always returns the median", () => {
71
+ const mode = new Mode2UpLit({
72
+ getMedianPageSizeInches: () => ({ width: 100, height: 200 }),
73
+ }, null);
74
+ expect(mode.computePageHeight(null)).toEqual(200);
75
+ expect(mode.computePageHeight({ widthInches: 300, heightInches: 400 }))
76
+ .toEqual(200);
77
+ });
78
+ });
79
+
80
+ describe("computePageWidth", () => {
81
+ test("returns relative to pageHeight", () => {
82
+ const mode = new Mode2UpLit(null, null);
83
+ sinon.stub(mode, "computePageHeight").returns(6);
84
+
85
+ expect(mode.computePageWidth({ widthInches: 2, heightInches: 6 })).toEqual(
86
+ 2,
87
+ );
88
+ expect(mode.computePageWidth({ widthInches: 3, heightInches: 6 })).toEqual(
89
+ 3,
90
+ );
91
+ expect(mode.computePageWidth({ widthInches: 2, heightInches: 4 })).toEqual(
92
+ 2 * 6 / 4,
93
+ );
94
+ });
95
+ });
96
+
97
+ describe("computePositions", () => {
98
+ const LEFT_COVER_EXPECTED = {
99
+ leafEdgesLeftStart: -0.246,
100
+ leafEdgesLeftMainWidth: 0,
101
+ leafEdgesLeftMovingStart: -0.246,
102
+ leafEdgesLeftMovingWidth: 0,
103
+ leafEdgesLeftEnd: -0.246,
104
+ leafEdgesLeftFullWidth: 0,
105
+ pageLeftStart: -0.246,
106
+ pageLeftWidth: 0.246,
107
+ pageLeftEnd: 0,
108
+ gutter: 0,
109
+ pageRightStart: 0,
110
+ pageRightWidth: 0.246,
111
+ pageRightEnd: 0.246,
112
+ leafEdgesRightStart: 0.246,
113
+ leafEdgesRightMovingWidth: 0,
114
+ leafEdgesRightMainStart: 0.246,
115
+ leafEdgesRightMainWidth: 0.006,
116
+ leafEdgesRightEnd: 0.252,
117
+ leafEdgesRightFullWidth: 0.006,
118
+ spreadWidth: 0.492,
119
+ bookWidth: 0.498
120
+ };
121
+ const SPREAD_EXPECTED = {
122
+ leafEdgesLeftStart: -0.246,
123
+ leafEdgesLeftMainWidth: 0.002,
124
+ leafEdgesLeftMovingStart: -0.244,
125
+ leafEdgesLeftMovingWidth: 0,
126
+ leafEdgesLeftEnd: -0.244,
127
+ leafEdgesLeftFullWidth: 0.002,
128
+ pageLeftStart: -0.244,
129
+ pageLeftWidth: 0.246,
130
+ pageLeftEnd: 0.002,
131
+ gutter: 0.002,
132
+ pageRightStart: 0.002,
133
+ pageRightWidth: 0.246,
134
+ pageRightEnd: 0.248,
135
+ leafEdgesRightStart: 0.248,
136
+ leafEdgesRightMovingWidth: 0,
137
+ leafEdgesRightMainStart: 0.248,
138
+ leafEdgesRightMainWidth: 0.004,
139
+ leafEdgesRightEnd: 0.252,
140
+ leafEdgesRightFullWidth: 0.004,
141
+ spreadWidth: 0.492,
142
+ bookWidth: 0.498
143
+ };
144
+ const RIGHT_COVER_EXPECTED = {
145
+ leafEdgesLeftStart: -0.242,
146
+ leafEdgesLeftMainWidth: 0.006,
147
+ leafEdgesLeftMovingStart: -0.236,
148
+ leafEdgesLeftMovingWidth: 0,
149
+ leafEdgesLeftEnd: -0.236,
150
+ leafEdgesLeftFullWidth: 0.006,
151
+ pageLeftStart: -0.236,
152
+ pageLeftWidth: 0.246,
153
+ pageLeftEnd: 0.01,
154
+ gutter: 0.01,
155
+ pageRightStart: 0.01,
156
+ pageRightWidth: 0,
157
+ pageRightEnd: 0.01,
158
+ leafEdgesRightStart: 0.01,
159
+ leafEdgesRightMovingWidth: 0,
160
+ leafEdgesRightMainStart: 0.01,
161
+ leafEdgesRightMainWidth: 0,
162
+ leafEdgesRightEnd: 0.01,
163
+ leafEdgesRightFullWidth: 0,
164
+ spreadWidth: 0.246,
165
+ bookWidth: 0.252
166
+ };
167
+
168
+ test("left cover page", () => {
169
+ const br = make_dummy_br({ data: SAMPLE_DATA });
170
+ const book = new BookModel(br);
171
+ const mode = new Mode2UpLit(book, br);
172
+ expect(mode.computePositions(null, book.getPage(0))).toEqual(LEFT_COVER_EXPECTED);
173
+ });
174
+
175
+ test("spread", () => {
176
+ const br = make_dummy_br({ data: SAMPLE_DATA });
177
+ const book = new BookModel(br);
178
+ const mode = new Mode2UpLit(book, br);
179
+
180
+ expect(mode.computePositions(book.getPage(1), book.getPage(2))).toEqual(SPREAD_EXPECTED);
181
+ });
182
+
183
+ test("right cover page", () => {
184
+ const br = make_dummy_br({ data: SAMPLE_DATA });
185
+ const book = new BookModel(br);
186
+ const mode = new Mode2UpLit(book, br);
187
+
188
+ expect(mode.computePositions(book.getPage(-1), null)).toEqual(RIGHT_COVER_EXPECTED);
189
+ });
190
+ });
@@ -0,0 +1,16 @@
1
+ import { ModeCoordinateSpace } from "@/src/BookReader/ModeCoordinateSpace";
2
+
3
+ describe("worldUnitsToRenderedPixels", () => {
4
+ test("0 case", () => {
5
+ const mcs = new ModeCoordinateSpace({ scale: 1 });
6
+ expect(mcs.worldUnitsToRenderedPixels(0)).toBe(0);
7
+ });
8
+
9
+ test("Misc cases", () => {
10
+ const mcs = new ModeCoordinateSpace({ scale: 1 });
11
+ mcs.screenDPI = 100;
12
+ expect(mcs.worldUnitsToRenderedPixels(1)).toBe(100);
13
+ mcs.screenDPI = 78;
14
+ expect(mcs.worldUnitsToRenderedPixels(1)).toBe(78);
15
+ });
16
+ });