@internetarchive/bookreader 5.0.0-93 → 5.0.0-95

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 (224) hide show
  1. package/.github/workflows/npm-publish.yml +2 -12
  2. package/BookReaderDemo/IADemoBr.js +1 -24
  3. package/BookReaderDemo/demo-internetarchive.html +1 -0
  4. package/CHANGELOG.md +19 -1
  5. package/README.md +0 -2
  6. package/package.json +8 -4
  7. package/scripts/postversion.js +3 -2
  8. package/scripts/preversion.js +3 -1
  9. package/scripts/version.js +4 -6
  10. package/src/BookNavigator/book-navigator.js +38 -12
  11. package/src/BookNavigator/downloads/downloads-provider.js +2 -2
  12. package/src/BookNavigator/search/search-provider.js +5 -5
  13. package/src/BookNavigator/search/search-results.js +1 -1
  14. package/src/BookNavigator/sharing.js +2 -2
  15. package/src/BookNavigator/viewable-files.js +2 -2
  16. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +3 -3
  17. package/src/BookNavigator/visual-adjustments/visual-adjustments.js +2 -2
  18. package/src/BookReader.js +57 -31
  19. package/src/assets/images/hypothesis.ico +0 -0
  20. package/src/css/_TextSelection.scss +3 -1
  21. package/src/plugins/plugin.autoplay.js +3 -3
  22. package/src/plugins/plugin.chapters.js +2 -2
  23. package/src/plugins/plugin.experiments.js +294 -0
  24. package/src/plugins/plugin.iiif.js +1 -1
  25. package/src/plugins/plugin.text_selection.js +112 -1
  26. package/src/plugins/search/view.js +5 -5
  27. package/src/plugins/tts/plugin.tts.js +3 -3
  28. package/src/plugins/url/plugin.url.js +2 -2
  29. package/tests/e2e/autoplay.test.js +1 -1
  30. package/tests/e2e/base.test.js +4 -4
  31. package/tests/e2e/helpers/base.js +2 -2
  32. package/tests/e2e/models/BookReader.js +1 -1
  33. package/tests/e2e/rightToLeft.test.js +4 -4
  34. package/tests/e2e/viewmode.test.js +2 -2
  35. package/tests/jest/BookNavigator/book-navigator.test.js +0 -13
  36. package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +1 -1
  37. package/tests/jest/BookNavigator/downloads/downloads.test.js +1 -1
  38. package/tests/jest/BookNavigator/search/search-provider.test.js +5 -5
  39. package/tests/jest/BookReader.test.js +10 -10
  40. package/tests/jest/plugins/plugin.autoplay.test.js +6 -6
  41. package/tests/jest/plugins/plugin.chapters.test.js +2 -2
  42. package/tests/jest/plugins/plugin.resume.test.js +13 -13
  43. package/tests/jest/plugins/plugin.text_selection.test.js +155 -24
  44. package/tests/jest/plugins/search/plugin.search.test.js +7 -7
  45. package/tests/jest/plugins/search/plugin.search.view.test.js +8 -8
  46. package/tests/jest/plugins/search/utils.js +1 -1
  47. package/tests/jest/plugins/tts/PageChunkIterator.test.js +2 -2
  48. package/tests/jest/plugins/url/UrlPlugin.test.js +1 -1
  49. package/webpack.config.js +8 -3
  50. package/BookReader/BookReader.css +0 -2250
  51. package/BookReader/BookReader.js +0 -3
  52. package/BookReader/BookReader.js.LICENSE.txt +0 -72
  53. package/BookReader/BookReader.js.map +0 -1
  54. package/BookReader/ia-bookreader-bundle.js +0 -1782
  55. package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +0 -7
  56. package/BookReader/ia-bookreader-bundle.js.map +0 -1
  57. package/BookReader/icons/1up.svg +0 -1
  58. package/BookReader/icons/2up.svg +0 -1
  59. package/BookReader/icons/advance.svg +0 -3
  60. package/BookReader/icons/chevron-right.svg +0 -1
  61. package/BookReader/icons/close-circle-dark.svg +0 -1
  62. package/BookReader/icons/close-circle.svg +0 -1
  63. package/BookReader/icons/fullscreen.svg +0 -1
  64. package/BookReader/icons/fullscreen_exit.svg +0 -1
  65. package/BookReader/icons/hamburger.svg +0 -1
  66. package/BookReader/icons/left-arrow.svg +0 -1
  67. package/BookReader/icons/magnify-minus.svg +0 -1
  68. package/BookReader/icons/magnify-plus.svg +0 -1
  69. package/BookReader/icons/magnify.svg +0 -1
  70. package/BookReader/icons/pause.svg +0 -1
  71. package/BookReader/icons/play.svg +0 -1
  72. package/BookReader/icons/playback-speed.svg +0 -1
  73. package/BookReader/icons/read-aloud.svg +0 -1
  74. package/BookReader/icons/review.svg +0 -3
  75. package/BookReader/icons/thumbnails.svg +0 -1
  76. package/BookReader/icons/voice.svg +0 -1
  77. package/BookReader/icons/volume-full.svg +0 -1
  78. package/BookReader/images/BRicons.png +0 -0
  79. package/BookReader/images/BRicons.svg +0 -5
  80. package/BookReader/images/BRicons_ia.png +0 -0
  81. package/BookReader/images/back_pages.png +0 -0
  82. package/BookReader/images/book_bottom_icon.png +0 -0
  83. package/BookReader/images/book_down_icon.png +0 -0
  84. package/BookReader/images/book_left_icon.png +0 -0
  85. package/BookReader/images/book_leftmost_icon.png +0 -0
  86. package/BookReader/images/book_right_icon.png +0 -0
  87. package/BookReader/images/book_rightmost_icon.png +0 -0
  88. package/BookReader/images/book_top_icon.png +0 -0
  89. package/BookReader/images/book_up_icon.png +0 -0
  90. package/BookReader/images/books_graphic.svg +0 -1
  91. package/BookReader/images/booksplit.png +0 -0
  92. package/BookReader/images/control_pause_icon.png +0 -0
  93. package/BookReader/images/control_play_icon.png +0 -0
  94. package/BookReader/images/embed_icon.png +0 -0
  95. package/BookReader/images/icon-home-ia.png +0 -0
  96. package/BookReader/images/icon_OL-logo-xs.png +0 -0
  97. package/BookReader/images/icon_alert-xs.png +0 -0
  98. package/BookReader/images/icon_book.svg +0 -1
  99. package/BookReader/images/icon_bookmark.svg +0 -1
  100. package/BookReader/images/icon_close-pop.png +0 -0
  101. package/BookReader/images/icon_download.png +0 -0
  102. package/BookReader/images/icon_gear.svg +0 -1
  103. package/BookReader/images/icon_hamburger.svg +0 -1
  104. package/BookReader/images/icon_home.png +0 -0
  105. package/BookReader/images/icon_home.svg +0 -1
  106. package/BookReader/images/icon_home_ia.png +0 -0
  107. package/BookReader/images/icon_indicator.png +0 -0
  108. package/BookReader/images/icon_info.svg +0 -1
  109. package/BookReader/images/icon_one_page.svg +0 -1
  110. package/BookReader/images/icon_pause.svg +0 -1
  111. package/BookReader/images/icon_play.svg +0 -1
  112. package/BookReader/images/icon_playback-rate.svg +0 -1
  113. package/BookReader/images/icon_return.png +0 -0
  114. package/BookReader/images/icon_search_button.svg +0 -1
  115. package/BookReader/images/icon_share.svg +0 -1
  116. package/BookReader/images/icon_skip-ahead.svg +0 -1
  117. package/BookReader/images/icon_skip-back.svg +0 -2
  118. package/BookReader/images/icon_speaker.svg +0 -1
  119. package/BookReader/images/icon_speaker_open.svg +0 -1
  120. package/BookReader/images/icon_thumbnails.svg +0 -1
  121. package/BookReader/images/icon_toc.svg +0 -1
  122. package/BookReader/images/icon_two_pages.svg +0 -1
  123. package/BookReader/images/icon_zoomer.png +0 -0
  124. package/BookReader/images/loading.gif +0 -0
  125. package/BookReader/images/logo_icon.png +0 -0
  126. package/BookReader/images/marker_chap-off.png +0 -0
  127. package/BookReader/images/marker_chap-off.svg +0 -1
  128. package/BookReader/images/marker_chap-off_ia.png +0 -0
  129. package/BookReader/images/marker_chap-on.png +0 -0
  130. package/BookReader/images/marker_chap-on.svg +0 -1
  131. package/BookReader/images/marker_srch-on.svg +0 -1
  132. package/BookReader/images/marker_srchchap-off.png +0 -0
  133. package/BookReader/images/marker_srchchap-on.png +0 -0
  134. package/BookReader/images/nav_control-dn.png +0 -0
  135. package/BookReader/images/nav_control-dn_ia.png +0 -0
  136. package/BookReader/images/nav_control-up.png +0 -0
  137. package/BookReader/images/nav_control-up_ia.png +0 -0
  138. package/BookReader/images/nav_control.png +0 -0
  139. package/BookReader/images/one_page_mode_icon.png +0 -0
  140. package/BookReader/images/paper-badge.png +0 -0
  141. package/BookReader/images/print_icon.png +0 -0
  142. package/BookReader/images/progressbar.gif +0 -0
  143. package/BookReader/images/right_edges.png +0 -0
  144. package/BookReader/images/slider.png +0 -0
  145. package/BookReader/images/slider_ia.png +0 -0
  146. package/BookReader/images/thumbnail_mode_icon.png +0 -0
  147. package/BookReader/images/transparent.png +0 -0
  148. package/BookReader/images/two_page_mode_icon.png +0 -0
  149. package/BookReader/images/unviewable_page.png +0 -0
  150. package/BookReader/images/zoom_in_icon.png +0 -0
  151. package/BookReader/images/zoom_out_icon.png +0 -0
  152. package/BookReader/jquery-3.js +0 -2
  153. package/BookReader/jquery-3.js.LICENSE.txt +0 -24
  154. package/BookReader/plugins/plugin.archive_analytics.js +0 -2
  155. package/BookReader/plugins/plugin.archive_analytics.js.map +0 -1
  156. package/BookReader/plugins/plugin.autoplay.js +0 -2
  157. package/BookReader/plugins/plugin.autoplay.js.map +0 -1
  158. package/BookReader/plugins/plugin.chapters.js +0 -26
  159. package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +0 -1
  160. package/BookReader/plugins/plugin.chapters.js.map +0 -1
  161. package/BookReader/plugins/plugin.iframe.js +0 -2
  162. package/BookReader/plugins/plugin.iframe.js.map +0 -1
  163. package/BookReader/plugins/plugin.iiif.js +0 -2
  164. package/BookReader/plugins/plugin.iiif.js.map +0 -1
  165. package/BookReader/plugins/plugin.resume.js +0 -2
  166. package/BookReader/plugins/plugin.resume.js.map +0 -1
  167. package/BookReader/plugins/plugin.search.js +0 -3
  168. package/BookReader/plugins/plugin.search.js.LICENSE.txt +0 -1
  169. package/BookReader/plugins/plugin.search.js.map +0 -1
  170. package/BookReader/plugins/plugin.text_selection.js +0 -3
  171. package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +0 -1
  172. package/BookReader/plugins/plugin.text_selection.js.map +0 -1
  173. package/BookReader/plugins/plugin.tts.js +0 -3
  174. package/BookReader/plugins/plugin.tts.js.LICENSE.txt +0 -29
  175. package/BookReader/plugins/plugin.tts.js.map +0 -1
  176. package/BookReader/plugins/plugin.url.js +0 -2
  177. package/BookReader/plugins/plugin.url.js.map +0 -1
  178. package/BookReader/plugins/plugin.vendor-fullscreen.js +0 -2
  179. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +0 -1
  180. package/BookReader/webcomponents-bundle.js +0 -3
  181. package/BookReader/webcomponents-bundle.js.LICENSE.txt +0 -9
  182. package/BookReader/webcomponents-bundle.js.map +0 -1
  183. package/src/BookReader/BookModel.js +0 -554
  184. package/src/BookReader/DragScrollable.js +0 -233
  185. package/src/BookReader/ImageCache.js +0 -149
  186. package/src/BookReader/Mode1Up.js +0 -108
  187. package/src/BookReader/Mode1UpLit.js +0 -388
  188. package/src/BookReader/Mode2Up.js +0 -105
  189. package/src/BookReader/Mode2UpLit.js +0 -777
  190. package/src/BookReader/ModeCoordinateSpace.js +0 -29
  191. package/src/BookReader/ModeSmoothZoom.js +0 -312
  192. package/src/BookReader/ModeThumb.js +0 -342
  193. package/src/BookReader/Navbar/Navbar.js +0 -355
  194. package/src/BookReader/PageContainer.js +0 -169
  195. package/src/BookReader/ReduceSet.js +0 -26
  196. package/src/BookReader/Toolbar/Toolbar.js +0 -362
  197. package/src/BookReader/events.js +0 -19
  198. package/src/BookReader/options.js +0 -382
  199. package/src/BookReader/utils/HTMLDimensionsCacher.js +0 -44
  200. package/src/BookReader/utils/ScrollClassAdder.js +0 -31
  201. package/src/BookReader/utils/SelectionObserver.js +0 -45
  202. package/src/BookReader/utils/classes.js +0 -36
  203. package/src/BookReader/utils.js +0 -300
  204. package/tests/jest/BookReader/BookModel.test.js +0 -372
  205. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +0 -263
  206. package/tests/jest/BookReader/ImageCache.test.js +0 -150
  207. package/tests/jest/BookReader/Mode1UpLit.test.js +0 -73
  208. package/tests/jest/BookReader/Mode2Up.test.js +0 -98
  209. package/tests/jest/BookReader/Mode2UpLit.test.js +0 -190
  210. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +0 -16
  211. package/tests/jest/BookReader/ModeSmoothZoom.test.js +0 -218
  212. package/tests/jest/BookReader/ModeThumb.test.js +0 -71
  213. package/tests/jest/BookReader/Navbar/Navbar.test.js +0 -182
  214. package/tests/jest/BookReader/PageContainer.test.js +0 -238
  215. package/tests/jest/BookReader/ReduceSet.test.js +0 -38
  216. package/tests/jest/BookReader/Toolbar/Toolbar.test.js +0 -26
  217. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +0 -59
  218. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +0 -49
  219. package/tests/jest/BookReader/utils/SelectionObserver.test.js +0 -57
  220. package/tests/jest/BookReader/utils/classes.test.js +0 -88
  221. package/tests/jest/BookReader/utils.test.js +0 -250
  222. /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
  223. /package/{.testcaferc.js → .testcaferc.cjs} +0 -0
  224. /package/{babel.config.js → babel.config.cjs} +0 -0
@@ -1,190 +0,0 @@
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
- });
@@ -1,16 +0,0 @@
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
- });
@@ -1,218 +0,0 @@
1
- import sinon from 'sinon';
2
- import interact from 'interactjs';
3
- import { EventTargetSpy, afterEventLoop } from '../utils.js';
4
- import { ModeSmoothZoom, TouchesMonitor } from '@/src/BookReader/ModeSmoothZoom.js';
5
- /** @typedef {import('@/src/BookReader/ModeSmoothZoom.js').SmoothZoomable} SmoothZoomable */
6
-
7
- /**
8
- * @param {Partial<SmoothZoomable>} overrides
9
- * @returns {SmoothZoomable}
10
- */
11
- function dummy_mode(overrides = {}) {
12
- return {
13
- $container: document.createElement('div'),
14
- $visibleWorld: document.createElement('div'),
15
- scale: 1,
16
- htmlDimensionsCacher: {
17
- clientWidth: 100,
18
- clientHeight: 100,
19
- boundingClientRect: { left: 0, top: 0 },
20
- },
21
- scaleCenter: {x: 0.5, y: 0.5},
22
- ...overrides,
23
- };
24
- }
25
-
26
- afterEach(() => {
27
- sinon.restore();
28
- try {
29
- interact.removeDocument(document);
30
- } catch (e) {}
31
- });
32
-
33
- describe('ModeSmoothZoom', () => {
34
- test('handle iOS-only gesture events', () => {
35
- const mode = dummy_mode();
36
- const msz = new ModeSmoothZoom(mode);
37
- sinon.stub(msz, '_pinchStart');
38
- sinon.stub(msz, '_pinchMove');
39
- sinon.stub(msz, '_pinchEnd');
40
-
41
- msz.attach();
42
-
43
- const gesturestart = new Event('gesturestart', {});
44
- mode.$container.dispatchEvent(gesturestart);
45
- expect(msz._pinchStart.callCount).toBe(1);
46
- });
47
-
48
- test('sets will-change', async () => {
49
- const mode = dummy_mode();
50
- const msz = new ModeSmoothZoom(mode);
51
- msz.attach();
52
- expect(mode.$visibleWorld.style.willChange).toBeFalsy();
53
- msz._pinchStart();
54
- expect(mode.$visibleWorld.style.willChange).toBe('transform');
55
- await msz._pinchEnd();
56
- expect(mode.$visibleWorld.style.willChange).toBe('auto');
57
- });
58
-
59
- test('pinch move updates scale', () => {
60
- const mode = dummy_mode();
61
- const msz = new ModeSmoothZoom(mode);
62
- msz.attach();
63
- // disable buffering
64
- msz.bufferFn = (callback) => callback();
65
- msz._pinchStart();
66
- expect(mode.scale).toBe(1);
67
- msz._pinchMove({ scale: 2, center: { x: 0, y: 0 }});
68
- expect(mode.scale).toBe(2);
69
- });
70
-
71
- test('updateScaleCenter sets scaleCenter in unitless coordinates', () => {
72
- const mode = dummy_mode({
73
- htmlDimensionsCacher: {
74
- clientWidth: 200,
75
- clientHeight: 100,
76
- boundingClientRect: {
77
- left: 5,
78
- top: 50,
79
- },
80
- },
81
- });
82
- const msz = new ModeSmoothZoom(mode);
83
- expect(msz.scaleCenter).toEqual({ x: 0.5, y: 0.5 });
84
- msz.updateScaleCenter({ clientX: 85, clientY: 110 });
85
- expect(msz.scaleCenter).toEqual({ x: 0.4, y: 0.6 });
86
- });
87
-
88
- test('detaches all listeners', async () => {
89
- const mode = dummy_mode();
90
- const msz = new ModeSmoothZoom(mode);
91
-
92
- const documentEventSpy = EventTargetSpy.wrap(document);
93
- const containerEventSpy = EventTargetSpy.wrap(mode.$container);
94
- const visibleWorldSpy = EventTargetSpy.wrap(mode.$visibleWorld);
95
-
96
- msz.attach();
97
- await afterEventLoop();
98
- expect(documentEventSpy._totalListenerCount).toBeGreaterThan(0);
99
- expect(containerEventSpy._totalListenerCount).toBeGreaterThan(0);
100
-
101
- msz.detach();
102
- expect(documentEventSpy._totalListenerCount).toBe(0);
103
- expect(containerEventSpy._totalListenerCount).toBe(0);
104
- expect(visibleWorldSpy._totalListenerCount).toBe(0);
105
- });
106
-
107
- test('attach can be called twice without double attachments', () => {
108
- const mode = dummy_mode();
109
- const msz = new ModeSmoothZoom(mode);
110
-
111
- const documentEventSpy = EventTargetSpy.wrap(document);
112
- const containerEventSpy = EventTargetSpy.wrap(mode.$container);
113
- const visibleWorldSpy = EventTargetSpy.wrap(mode.$visibleWorld);
114
-
115
- msz.attach();
116
- const documentListenersCount = documentEventSpy._totalListenerCount;
117
- const containerListenersCount = containerEventSpy._totalListenerCount;
118
- const visibleWorldListenersCount = visibleWorldSpy._totalListenerCount;
119
-
120
- msz.attach();
121
- expect(documentEventSpy._totalListenerCount).toBe(documentListenersCount);
122
- expect(containerEventSpy._totalListenerCount).toBe(containerListenersCount);
123
- expect(visibleWorldSpy._totalListenerCount).toBe(visibleWorldListenersCount);
124
- });
125
-
126
- describe('_handleCtrlWheel', () => {
127
- test('non-ctrl wheel events ignored', () => {
128
- const mode = dummy_mode();
129
- const msz = new ModeSmoothZoom(mode);
130
- expect(mode.scale).toBe(1);
131
- const ev = new WheelEvent('wheel', { ctrlKey: false, deltaY: 20 });
132
- const preventDefaultSpy = sinon.spy(ev, 'preventDefault');
133
- msz._handleCtrlWheel(ev);
134
- expect(preventDefaultSpy.callCount).toBe(0);
135
- expect(mode.scale).toBe(1);
136
- });
137
-
138
- test('ctrl-wheel events update scale', () => {
139
- const mode = dummy_mode();
140
- const msz = new ModeSmoothZoom(mode);
141
- expect(mode.scale).toBe(1);
142
- const ev = new WheelEvent('wheel', { ctrlKey: true, deltaY: 20 });
143
- const preventDefaultSpy = sinon.spy(ev, 'preventDefault');
144
- msz._handleCtrlWheel(ev);
145
- expect(preventDefaultSpy.callCount).toBe(1);
146
- expect(mode.scale).not.toBe(1);
147
- });
148
- });
149
-
150
- describe("updateViewportOnZoom", () => {
151
- test("adjusts scroll position when zooming in", () => {
152
- const mode = dummy_mode();
153
- const msz = new ModeSmoothZoom(mode);
154
- mode.$container.scrollTop = 100;
155
- mode.$container.scrollLeft = 100;
156
-
157
- msz.updateViewportOnZoom(2, 1);
158
-
159
- expect(mode.$container.scrollTop).toBeGreaterThan(100);
160
- expect(mode.$container.scrollLeft).toBeGreaterThan(100);
161
- });
162
-
163
- test("updates scroll position when zooming out", () => {
164
- const mode = dummy_mode();
165
- const msz = new ModeSmoothZoom(mode);
166
- mode.$container.scrollTop = 100;
167
- mode.$container.scrollLeft = 100;
168
-
169
- msz.updateViewportOnZoom(0.5, 1);
170
-
171
- expect(mode.$container.scrollTop).toBeLessThan(100);
172
- expect(mode.$container.scrollLeft).toBeLessThan(100);
173
- });
174
- });
175
- });
176
-
177
-
178
- describe("TouchesMonitor", () => {
179
- /** @type {HTMLElement} */
180
- let container;
181
- /** @type {TouchesMonitor} */
182
- let monitor;
183
-
184
- beforeEach(() => {
185
- container = document.createElement("div");
186
- monitor = new TouchesMonitor(container);
187
- });
188
-
189
- afterEach(() => {
190
- monitor.detach();
191
- });
192
-
193
- test("should start with 0 touches", () => {
194
- expect(monitor.touches).toBe(0);
195
- });
196
-
197
- test("should update touch count on touch events", () => {
198
- monitor.attach();
199
- container.dispatchEvent(new TouchEvent("touchstart", { touches: [{}] }));
200
- expect(monitor.touches).toBe(1);
201
-
202
- container.dispatchEvent(new TouchEvent("touchstart", { touches: [{}, {}] }));
203
- expect(monitor.touches).toBe(2);
204
-
205
- container.dispatchEvent(new TouchEvent("touchend", { touches: [{}] }));
206
- expect(monitor.touches).toBe(1);
207
-
208
- container.dispatchEvent(new TouchEvent("touchend", { touches: [] }));
209
- });
210
-
211
- test("should detach all listeners", () => {
212
- const spy = EventTargetSpy.wrap(container);
213
- monitor.attach();
214
- expect(spy._totalListenerCount).toBeGreaterThan(0);
215
- monitor.detach();
216
- expect(spy._totalListenerCount).toBe(0);
217
- });
218
- });
@@ -1,71 +0,0 @@
1
-
2
- import sinon from 'sinon';
3
- import BookReader from '@/src/BookReader.js';
4
- /** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
5
-
6
- beforeAll(() => {
7
- global.alert = jest.fn();
8
- });
9
- afterEach(() => {
10
- jest.restoreAllMocks();
11
- sinon.restore();
12
- });
13
-
14
- /** @type {BookReaderOptions['data']} */
15
- const SAMPLE_DATA = [
16
- [
17
- { width: 123, height: 123, uri: 'https://archive.org/image0.jpg', pageNum: '1' },
18
- ],
19
- [
20
- { width: 123, height: 123, uri: 'https://archive.org/image1.jpg', pageNum: '2' },
21
- { width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '3' },
22
- ],
23
- [
24
- { width: 123, height: 123, uri: 'https://archive.org/image3.jpg', pageNum: '4' },
25
- { width: 123, height: 123, uri: 'https://archive.org/image4.jpg', pageNum: '5' },
26
- ],
27
- [
28
- { width: 123, height: 123, uri: 'https://archive.org/image5.jpg', pageNum: '6' },
29
- ],
30
- ];
31
-
32
- describe('zoom', () => {
33
- const br = new BookReader({ data: SAMPLE_DATA });
34
- br.init();
35
-
36
- test('initializes with default columns', () => {
37
- expect(br.thumbColumns).toBe(br.options.thumbColumns);
38
- });
39
-
40
- test('removes column and redraws zooming in', () => {
41
- const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
42
- const startColumns = br.thumbColumns;
43
- br._modes.modeThumb.zoom('in');
44
- expect(br.thumbColumns).toBe(startColumns - 1);
45
- expect(prepare.callCount).toBe(1);
46
- });
47
-
48
- test('adds column and redraws zooming out', () => {
49
- const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
50
- const startColumns = br.thumbColumns;
51
- br._modes.modeThumb.zoom('out');
52
- expect(br.thumbColumns).toBe(startColumns + 1);
53
- expect(prepare.callCount).toBe(1);
54
- });
55
-
56
- test('keeps columns and no redraw at zooming in limit', () => {
57
- const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
58
- br.thumbColumns = br.options.thumbMinZoomColumns;
59
- br._modes.modeThumb.zoom('in');
60
- expect(br.thumbColumns).toBe(br.options.thumbMinZoomColumns);
61
- expect(prepare.callCount).toBe(0);
62
- });
63
-
64
- test('keeps columns and no redraw at zooming out limit', () => {
65
- const prepare = sinon.spy(br._modes.modeThumb, 'prepare');
66
- br.thumbColumns = br.options.thumbMaxZoomColumns;
67
- br._modes.modeThumb.zoom('out');
68
- expect(br.thumbColumns).toBe(br.options.thumbMaxZoomColumns);
69
- expect(prepare.callCount).toBe(0);
70
- });
71
- });
@@ -1,182 +0,0 @@
1
- import sinon from 'sinon';
2
- import { getNavPageNumHtml } from '@/src/BookReader/Navbar/Navbar.js';
3
- import BookReader from '@/src/BookReader.js';
4
-
5
- describe('getNavPageNumHtml', () => {
6
- const f = getNavPageNumHtml;
7
-
8
- test('handle n-prefixed page numbers-min format', () => {
9
- expect(f(3, 40, 'n3', '', 40)).toBe('(4 of 40)');
10
- });
11
-
12
- test('handle regular page numbers-min format', () => {
13
- expect(f(3, 40, '14', '', 40)).toBe('14 of 40');
14
- });
15
-
16
- test('handle no max page-min format', () => {
17
- expect(f(3, 40, '14', '', null)).toBe('14');
18
- });
19
-
20
- test('handle n-prefixed page numbers-max format', () => {
21
- expect(f(3, 40, 'n3', '', 40, true)).toBe('Page — (4/40)');
22
- });
23
-
24
- test('handle regular page numbers-max format', () => {
25
- expect(f(3, 40, '14', '', 40, true)).toBe('Page 14 (4/40)');
26
- });
27
-
28
- test('handle no max page-max format', () => {
29
- expect(f(3, 40, '14', '', null, true)).toBe('Page 14 (4/40)');
30
- });
31
- });
32
-
33
- /** @type {BookReader} */
34
- let br;
35
- /** @type {Navbar} */
36
- let navbar;
37
- beforeEach(() => {
38
- document.body.innerHTML = '<div id="BookReader">';
39
- br = new BookReader({
40
- data: [
41
- [
42
- { width: 800, height: 1200,
43
- uri: '//archive.org/download/BookReader/img/page001.jpg' },
44
- ],
45
- [
46
- { width: 800, height: 1200,
47
- uri: '//archive.org/download/BookReader/img/page002.jpg' },
48
- { width: 800, height: 1200,
49
- uri: '//archive.org/download/BookReader/img/page003.jpg' },
50
- ],
51
- [
52
- { width: 800, height: 1200,
53
- uri: '//archive.org/download/BookReader/img/page004.jpg' },
54
- { width: 800, height: 1200,
55
- uri: '//archive.org/download/BookReader/img/page005.jpg' },
56
- ],
57
- ],
58
- });
59
- br.init();
60
- navbar = br._components.navbar;
61
- });
62
-
63
- afterEach(() => sinon.restore());
64
-
65
- describe('Navbar slider', () => {
66
- test('while sliding, visible page number updates, but does not flip', () => {
67
- const $slider = navbar.$root.find('.BRpager');
68
- const jumpToIndexSpy = sinon.spy(br, 'jumpToIndex');
69
- expect(br.currentIndex()).toBe(0);
70
-
71
- $slider.trigger('slide', { value: 3 });
72
-
73
- expect(navbar.$root.find('.BRcurrentpage').text().includes('3'));
74
- expect(jumpToIndexSpy.callCount).toBe(0);
75
- });
76
-
77
- test('on slide change, actual page changes', () => {
78
- const $slider = navbar.$root.find('.BRpager');
79
- const jumpToIndexStub = sinon.stub(br, 'jumpToIndex');
80
- expect(br.currentIndex()).toBe(0);
81
-
82
- $slider.trigger('slidechange', { value: 3 });
83
-
84
- expect(navbar.$root.find('.BRcurrentpage').text().includes('3'));
85
- expect(jumpToIndexStub.callCount).toBe(1);
86
- expect(jumpToIndexStub.args[0][0]).toBe(3);
87
- });
88
- });
89
-
90
- describe('Navbar controls overrides', () => {
91
- const createBRWithOverrides = (overrides) => {
92
- br = new BookReader($.extend(true, br.options, overrides));
93
- br.init();
94
- navbar = br._components.navbar;
95
- };
96
-
97
- test(`when a view mode is excluded,
98
- the mode should not be used in viewport toggling`, () => {
99
- const overrides = {
100
- controls: {
101
- viewmode: {
102
- visible: true,
103
- className: 'viewmode',
104
- excludedModes: [1],
105
- },
106
- },
107
- };
108
- createBRWithOverrides(overrides);
109
-
110
- const $viewMode = navbar.$root.find('.viewmode');
111
-
112
- expect($viewMode.find('.icon-thumb').length).toBe(1);
113
- $viewMode.trigger("click");
114
- expect($viewMode.find('.icon-twopg').length).toBe(1);
115
- $viewMode.trigger("click");
116
- expect($viewMode.find('.icon-thumb').length).toBe(1);
117
- });
118
-
119
- test('when a control is set to visible: false, do not return a button template', () => {
120
- const overrides = {
121
- controls: {
122
- onePage: {
123
- visible: false,
124
- },
125
- },
126
- };
127
- createBRWithOverrides(overrides);
128
-
129
- expect(navbar.$root.find('.onepg').length).toBe(0);
130
- expect(navbar.$root.find('.twopg').length).toBe(1);
131
- });
132
-
133
- test(`when a control's className is overridden,
134
- the class should be used in place of the default`, () => {
135
- const overrides = {
136
- controls: {
137
- onePage: {
138
- className: 'foo',
139
- },
140
- },
141
- };
142
- createBRWithOverrides(overrides);
143
-
144
- expect(navbar.$root.find(`.${overrides.controls.onePage.className}`).length).toBe(1);
145
- expect(navbar.$root.find('.onepg').length).toBe(0);
146
- });
147
-
148
- test(`when a control's template is overridden,
149
- the HTML output should match the template provided`, () => {
150
- const overrides = {
151
- controls: {
152
- onePage: {
153
- template: () => (
154
- '<button id="foo"></button>'
155
- ),
156
- },
157
- },
158
- };
159
- createBRWithOverrides(overrides);
160
-
161
- expect(navbar.$root.find('#foo').length).toBe(1);
162
- expect(navbar.$root.find('.onepg').length).toBe(0);
163
- });
164
-
165
- test(`when viewmode control set to visible,
166
- the individual view mode controls are not rendered`, () => {
167
- const overrides = {
168
- controls: {
169
- viewmode: {
170
- visible: true,
171
- },
172
- onePage: {
173
- visible: false,
174
- },
175
- },
176
- };
177
- createBRWithOverrides(overrides);
178
-
179
- expect(navbar.$root.find('.viewmode').length).toBe(1);
180
- expect(navbar.$root.find('.onepg').length).toBe(0);
181
- });
182
- });