@internetarchive/bookreader 5.0.0-28-remove-url-defaults → 5.0.0-30-b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. package/.husky/_/husky.sh +30 -0
  2. package/BookReader/BookReader.css +1 -1
  3. package/BookReader/BookReader.js +1 -1
  4. package/BookReader/BookReader.js.map +1 -1
  5. package/BookReader/ia-bookreader-bundle.js +1458 -0
  6. package/BookReader/{bookreader-component-bundle.js.LICENSE.txt → ia-bookreader-bundle.js.LICENSE.txt} +12 -0
  7. package/BookReader/ia-bookreader-bundle.js.map +1 -0
  8. package/BookReader/plugins/plugin.search.js +1 -1
  9. package/BookReader/plugins/plugin.search.js.map +1 -1
  10. package/BookReaderDemo/BookReaderDemo.css +14 -1
  11. package/BookReaderDemo/IADemoBr.js +107 -0
  12. package/BookReaderDemo/demo-internetarchive.html +64 -99
  13. package/CHANGELOG.md +4 -0
  14. package/package.json +9 -6
  15. package/src/BookNavigator/assets/ia-logo.js +17 -0
  16. package/src/BookNavigator/book-navigator.js +528 -0
  17. package/src/BookNavigator/bookmarks/bookmark-button.js +2 -1
  18. package/src/BookNavigator/bookmarks/bookmarks-provider.js +20 -8
  19. package/src/BookNavigator/bookmarks/ia-bookmarks.js +84 -51
  20. package/src/BookNavigator/downloads/downloads-provider.js +5 -9
  21. package/src/BookNavigator/downloads/downloads.js +1 -0
  22. package/src/BookNavigator/search/search-provider.js +15 -8
  23. package/src/BookNavigator/sharing.js +27 -0
  24. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +9 -8
  25. package/src/BookNavigator/volumes/volumes-provider.js +3 -4
  26. package/src/BookReader/options.js +6 -0
  27. package/src/BookReader.js +20 -8
  28. package/src/css/_BRComponent.scss +1 -1
  29. package/src/ia-bookreader/ia-bookreader.js +209 -0
  30. package/src/plugins/search/plugin.search.js +9 -9
  31. package/{src → stat}/BookNavigator/BookModel.js +0 -0
  32. package/{src → stat}/BookNavigator/BookNavigator.js +109 -102
  33. package/stat/BookNavigator/assets/bookmark-colors.js +15 -0
  34. package/stat/BookNavigator/assets/button-base.js +61 -0
  35. package/stat/BookNavigator/assets/ia-logo.js +17 -0
  36. package/stat/BookNavigator/assets/icon_checkmark.js +6 -0
  37. package/stat/BookNavigator/assets/icon_close.js +3 -0
  38. package/stat/BookNavigator/assets/icon_sort_asc.js +5 -0
  39. package/stat/BookNavigator/assets/icon_sort_desc.js +5 -0
  40. package/stat/BookNavigator/assets/icon_sort_neutral.js +5 -0
  41. package/stat/BookNavigator/assets/icon_volumes.js +11 -0
  42. package/stat/BookNavigator/bookmarks/bookmark-button.js +64 -0
  43. package/stat/BookNavigator/bookmarks/bookmark-edit.js +215 -0
  44. package/stat/BookNavigator/bookmarks/bookmarks-list.js +285 -0
  45. package/stat/BookNavigator/bookmarks/bookmarks-loginCTA.js +28 -0
  46. package/stat/BookNavigator/bookmarks/bookmarks-provider.js +56 -0
  47. package/stat/BookNavigator/bookmarks/ia-bookmarks.js +523 -0
  48. package/{src → stat}/BookNavigator/br-fullscreen-mgr.js +1 -2
  49. package/stat/BookNavigator/delete-modal-actions.js +49 -0
  50. package/stat/BookNavigator/downloads/downloads-provider.js +72 -0
  51. package/stat/BookNavigator/downloads/downloads.js +139 -0
  52. package/stat/BookNavigator/provider-config.js +0 -0
  53. package/stat/BookNavigator/search/a-search-result.js +55 -0
  54. package/stat/BookNavigator/search/search-provider.js +180 -0
  55. package/stat/BookNavigator/search/search-results.js +360 -0
  56. package/{src/ItemNavigator/providers → stat/BookNavigator}/sharing.js +3 -5
  57. package/stat/BookNavigator/visual-adjustments/visual-adjustments-provider.js +94 -0
  58. package/stat/BookNavigator/visual-adjustments/visual-adjustments.js +280 -0
  59. package/stat/BookNavigator/volumes/volumes-provider.js +83 -0
  60. package/stat/BookNavigator/volumes/volumes.js +178 -0
  61. package/stat/BookReader/BookModel.js +518 -0
  62. package/stat/BookReader/DebugConsole.js +54 -0
  63. package/stat/BookReader/DragScrollable.js +233 -0
  64. package/stat/BookReader/ImageCache.js +116 -0
  65. package/stat/BookReader/Mode1Up.js +102 -0
  66. package/stat/BookReader/Mode1UpLit.js +434 -0
  67. package/stat/BookReader/Mode2Up.js +1372 -0
  68. package/stat/BookReader/ModeSmoothZoom.js +177 -0
  69. package/stat/BookReader/ModeThumb.js +344 -0
  70. package/stat/BookReader/Navbar/Navbar.js +310 -0
  71. package/stat/BookReader/PageContainer.js +120 -0
  72. package/stat/BookReader/ReduceSet.js +26 -0
  73. package/stat/BookReader/Toolbar/Toolbar.js +384 -0
  74. package/stat/BookReader/events.js +20 -0
  75. package/stat/BookReader/options.js +324 -0
  76. package/stat/BookReader/utils/HTMLDimensionsCacher.js +44 -0
  77. package/stat/BookReader/utils/classes.js +36 -0
  78. package/stat/BookReader/utils.js +240 -0
  79. package/stat/BookReader.js +2550 -0
  80. package/{src → stat}/BookReaderComponent/BookReaderComponent.js +15 -10
  81. package/stat/assets/icons/1up.svg +12 -0
  82. package/stat/assets/icons/2up.svg +15 -0
  83. package/stat/assets/icons/advance.svg +26 -0
  84. package/stat/assets/icons/chevron-right.svg +1 -0
  85. package/stat/assets/icons/close-circle-dark.svg +1 -0
  86. package/stat/assets/icons/close-circle.svg +1 -0
  87. package/stat/assets/icons/fullscreen.svg +17 -0
  88. package/stat/assets/icons/fullscreen_exit.svg +17 -0
  89. package/stat/assets/icons/hamburger.svg +15 -0
  90. package/stat/assets/icons/left-arrow.svg +12 -0
  91. package/stat/assets/icons/magnify-minus.svg +16 -0
  92. package/stat/assets/icons/magnify-plus.svg +17 -0
  93. package/stat/assets/icons/magnify.svg +15 -0
  94. package/stat/assets/icons/pause.svg +23 -0
  95. package/stat/assets/icons/play.svg +22 -0
  96. package/stat/assets/icons/playback-speed.svg +34 -0
  97. package/stat/assets/icons/read-aloud.svg +22 -0
  98. package/stat/assets/icons/review.svg +22 -0
  99. package/stat/assets/icons/thumbnails.svg +17 -0
  100. package/stat/assets/icons/voice.svg +1 -0
  101. package/stat/assets/icons/volume-full.svg +22 -0
  102. package/stat/assets/images/BRicons.png +0 -0
  103. package/stat/assets/images/BRicons.svg +94 -0
  104. package/stat/assets/images/BRicons_ia.png +0 -0
  105. package/stat/assets/images/back_pages.png +0 -0
  106. package/stat/assets/images/book_bottom_icon.png +0 -0
  107. package/stat/assets/images/book_down_icon.png +0 -0
  108. package/stat/assets/images/book_left_icon.png +0 -0
  109. package/stat/assets/images/book_leftmost_icon.png +0 -0
  110. package/stat/assets/images/book_right_icon.png +0 -0
  111. package/stat/assets/images/book_rightmost_icon.png +0 -0
  112. package/stat/assets/images/book_top_icon.png +0 -0
  113. package/stat/assets/images/book_up_icon.png +0 -0
  114. package/stat/assets/images/books_graphic.svg +177 -0
  115. package/stat/assets/images/booksplit.png +0 -0
  116. package/stat/assets/images/control_pause_icon.png +0 -0
  117. package/stat/assets/images/control_play_icon.png +0 -0
  118. package/stat/assets/images/embed_icon.png +0 -0
  119. package/stat/assets/images/icon-home-ia.png +0 -0
  120. package/stat/assets/images/icon_OL-logo-xs.png +0 -0
  121. package/stat/assets/images/icon_alert-xs.png +0 -0
  122. package/stat/assets/images/icon_book.svg +12 -0
  123. package/stat/assets/images/icon_bookmark.svg +12 -0
  124. package/stat/assets/images/icon_close-pop.png +0 -0
  125. package/stat/assets/images/icon_download.png +0 -0
  126. package/stat/assets/images/icon_gear.svg +14 -0
  127. package/stat/assets/images/icon_hamburger.svg +20 -0
  128. package/stat/assets/images/icon_home.png +0 -0
  129. package/stat/assets/images/icon_home.svg +21 -0
  130. package/stat/assets/images/icon_home_ia.png +0 -0
  131. package/stat/assets/images/icon_indicator.png +0 -0
  132. package/stat/assets/images/icon_info.svg +11 -0
  133. package/stat/assets/images/icon_one_page.svg +8 -0
  134. package/stat/assets/images/icon_pause.svg +1 -0
  135. package/stat/assets/images/icon_play.svg +1 -0
  136. package/stat/assets/images/icon_playback-rate.svg +15 -0
  137. package/stat/assets/images/icon_return.png +0 -0
  138. package/stat/assets/images/icon_search_button.svg +8 -0
  139. package/stat/assets/images/icon_share.svg +9 -0
  140. package/stat/assets/images/icon_skip-ahead.svg +6 -0
  141. package/stat/assets/images/icon_skip-back.svg +13 -0
  142. package/stat/assets/images/icon_speaker.svg +18 -0
  143. package/stat/assets/images/icon_speaker_open.svg +10 -0
  144. package/stat/assets/images/icon_thumbnails.svg +12 -0
  145. package/stat/assets/images/icon_toc.svg +5 -0
  146. package/stat/assets/images/icon_two_pages.svg +9 -0
  147. package/stat/assets/images/icon_zoomer.png +0 -0
  148. package/stat/assets/images/loading.gif +0 -0
  149. package/stat/assets/images/logo_icon.png +0 -0
  150. package/stat/assets/images/marker_chap-off.png +0 -0
  151. package/stat/assets/images/marker_chap-off.svg +11 -0
  152. package/stat/assets/images/marker_chap-off_ia.png +0 -0
  153. package/stat/assets/images/marker_chap-on.png +0 -0
  154. package/stat/assets/images/marker_chap-on.svg +11 -0
  155. package/stat/assets/images/marker_srch-on.svg +11 -0
  156. package/stat/assets/images/marker_srchchap-off.png +0 -0
  157. package/stat/assets/images/marker_srchchap-on.png +0 -0
  158. package/stat/assets/images/nav_control-dn.png +0 -0
  159. package/stat/assets/images/nav_control-dn_ia.png +0 -0
  160. package/stat/assets/images/nav_control-up.png +0 -0
  161. package/stat/assets/images/nav_control-up_ia.png +0 -0
  162. package/stat/assets/images/nav_control.png +0 -0
  163. package/stat/assets/images/one_page_mode_icon.png +0 -0
  164. package/stat/assets/images/paper-badge.png +0 -0
  165. package/stat/assets/images/print_icon.png +0 -0
  166. package/stat/assets/images/progressbar.gif +0 -0
  167. package/stat/assets/images/right_edges.png +0 -0
  168. package/stat/assets/images/slider.png +0 -0
  169. package/stat/assets/images/slider_ia.png +0 -0
  170. package/stat/assets/images/thumbnail_mode_icon.png +0 -0
  171. package/stat/assets/images/transparent.png +0 -0
  172. package/stat/assets/images/two_page_mode_icon.png +0 -0
  173. package/stat/assets/images/zoom_in_icon.png +0 -0
  174. package/stat/assets/images/zoom_out_icon.png +0 -0
  175. package/stat/css/BookReader.scss +89 -0
  176. package/stat/css/_BRBookmarks.scss +29 -0
  177. package/stat/css/_BRComponent.scss +13 -0
  178. package/stat/css/_BRfloat.scss +197 -0
  179. package/stat/css/_BRicon.scss +48 -0
  180. package/stat/css/_BRmain.scss +251 -0
  181. package/stat/css/_BRnav.scss +359 -0
  182. package/stat/css/_BRpages.scss +139 -0
  183. package/stat/css/_BRsearch.scss +226 -0
  184. package/stat/css/_BRtoolbar.scss +84 -0
  185. package/stat/css/_BRvendor.scss +5 -0
  186. package/stat/css/_MobileNav.scss +194 -0
  187. package/stat/css/_TextSelection.scss +32 -0
  188. package/stat/css/_colorbox.scss +52 -0
  189. package/stat/css/_controls.scss +253 -0
  190. package/stat/css/_icons.scss +121 -0
  191. package/stat/jquery-wrapper.js +4 -0
  192. package/stat/plugins/plugin.archive_analytics.js +86 -0
  193. package/stat/plugins/plugin.autoplay.js +129 -0
  194. package/stat/plugins/plugin.chapters.js +248 -0
  195. package/stat/plugins/plugin.iframe.js +48 -0
  196. package/stat/plugins/plugin.mobile_nav.js +288 -0
  197. package/stat/plugins/plugin.resume.js +68 -0
  198. package/stat/plugins/plugin.text_selection.js +291 -0
  199. package/stat/plugins/plugin.url.js +198 -0
  200. package/stat/plugins/plugin.vendor-fullscreen.js +247 -0
  201. package/stat/plugins/search/plugin.search.js +439 -0
  202. package/stat/plugins/search/view.js +439 -0
  203. package/stat/plugins/tts/AbstractTTSEngine.js +249 -0
  204. package/stat/plugins/tts/FestivalTTSEngine.js +169 -0
  205. package/stat/plugins/tts/PageChunk.js +107 -0
  206. package/stat/plugins/tts/PageChunkIterator.js +163 -0
  207. package/stat/plugins/tts/WebTTSEngine.js +357 -0
  208. package/stat/plugins/tts/plugin.tts.js +357 -0
  209. package/stat/plugins/tts/tooltip_dict.js +15 -0
  210. package/stat/plugins/tts/utils.js +91 -0
  211. package/stat/util/browserSniffing.js +30 -0
  212. package/stat/util/debouncer.js +26 -0
  213. package/stat/util/docCookies.js +67 -0
  214. package/stat/util/strings.js +34 -0
  215. package/tests/e2e/viewmode.test.js +30 -30
  216. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +64 -52
  217. package/tests/karma/BookNavigator/book-navigator.test.js +413 -108
  218. package/tests/karma/BookNavigator/bookmarks/bookmark-button.test.js +44 -0
  219. package/tests/karma/BookNavigator/downloads/downloads-provider.test.js +6 -3
  220. package/tests/karma/BookNavigator/search/search-provider.test.js +106 -6
  221. package/tests/karma/BookNavigator/search/search-results.test.js +0 -2
  222. package/tests/karma/BookNavigator/sharing/sharing-provider.test.js +29 -20
  223. package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +41 -17
  224. package/webpack.config.js +1 -1
  225. package/.nvmrc +0 -1
  226. package/BookReader/bookreader-component-bundle.js +0 -1436
  227. package/BookReader/bookreader-component-bundle.js.map +0 -1
  228. package/src/BookNavigator/assets/book-loader.js +0 -27
  229. package/src/ItemNavigator/ItemNavigator.js +0 -377
@@ -0,0 +1,233 @@
1
+ // @ts-check
2
+ /*
3
+ * jQuery dragscrollable Plugin
4
+ * Based off version: 1.0 (25-Jun-2009)
5
+ * Copyright (c) 2009 Miquel Herrera
6
+ *
7
+ * Portions Copyright (c) 2010 Reg Braithwaite
8
+ * Copyright (c) 2010 Internet Archive / Michael Ang
9
+ * Copyright (c) 2016 Internet Archive / Richard Caceres
10
+ *
11
+ * Dual licensed under the MIT and GPL licenses:
12
+ * http://www.opensource.org/licenses/mit-license.php
13
+ * http://www.gnu.org/licenses/gpl.html
14
+ */
15
+
16
+ /**
17
+ * @param {string} string_of_events
18
+ * @param {string} ns
19
+ * @returns
20
+ */
21
+ function append_namespace(string_of_events, ns) {
22
+ return string_of_events
23
+ .split(' ')
24
+ .map(event_name => event_name + ns)
25
+ .join(' ');
26
+ }
27
+
28
+ function left_top(event) {
29
+ /** @type {number} */
30
+ let x;
31
+ /** @type {number} */
32
+ let y;
33
+ if (typeof(event.clientX) != 'undefined') {
34
+ x = event.clientX;
35
+ y = event.clientY;
36
+ }
37
+ else if (typeof(event.screenX) != 'undefined') {
38
+ x = event.screenX;
39
+ y = event.screenY;
40
+ }
41
+ else if (typeof(event.targetTouches) != 'undefined') {
42
+ x = event.targetTouches[0].pageX;
43
+ y = event.targetTouches[0].pageY;
44
+ }
45
+ else if (typeof(event.originalEvent) == 'undefined') {
46
+ console.error("don't understand x and y for " + event.type, event);
47
+ }
48
+ else if (typeof(event.originalEvent.clientX) != 'undefined') {
49
+ x = event.originalEvent.clientX;
50
+ y = event.originalEvent.clientY;
51
+ }
52
+ else if (typeof(event.originalEvent.screenX) != 'undefined') {
53
+ x = event.originalEvent.screenX;
54
+ y = event.originalEvent.screenY;
55
+ }
56
+ else if (typeof(event.originalEvent.targetTouches) != 'undefined') {
57
+ x = event.originalEvent.targetTouches[0].pageX;
58
+ y = event.originalEvent.targetTouches[0].pageY;
59
+ }
60
+
61
+ return { left: x, top: y };
62
+ }
63
+
64
+ const DEFAULT_OPTIONS = {
65
+ /**
66
+ * @type {String|HTMLElement} jQuery selector to apply to each wrapped element to
67
+ * find which will be the dragging elements. Defaults to the first child of scrollable
68
+ * element
69
+ */
70
+ dragSelector: '>:first',
71
+
72
+ /** Will the dragging element accept propagated events? default is yes, a propagated
73
+ * mouse event on a inner element will be accepted and processed. If set to false,
74
+ * only events originated on the draggable elements will be processed. */
75
+ acceptPropagatedEvent: true,
76
+
77
+ /**
78
+ * Prevents the event to propagate further effectively disabling other default actions
79
+ */
80
+ preventDefault: true,
81
+
82
+ dragstart: 'mousedown touchstart',
83
+ dragcontinue: 'mousemove touchmove',
84
+ dragend: 'mouseup touchend', // mouseleave
85
+ dragMinDistance: 5,
86
+ namespace: '.ds',
87
+
88
+ /** Scroll the window rather than the element */
89
+ scrollWindow: false,
90
+ };
91
+
92
+ /**
93
+ * Adds the ability to manage elements scroll by dragging
94
+ * one or more of its descendant elements. Options parameter
95
+ * allow to specifically select which inner elements will
96
+ * respond to the drag events.
97
+ * usage examples:
98
+ *
99
+ * To add the scroll by drag to the element id=viewport when dragging its
100
+ * first child accepting any propagated events
101
+ * `new DragScrollable($('#viewport')[0]);`
102
+ *
103
+ * To add the scroll by drag ability to any element div of class viewport
104
+ * when dragging its first descendant of class dragMe responding only to
105
+ * evcents originated on the '.dragMe' elements.
106
+ * ```js
107
+ * new DragScrollable($('div.viewport')[0], {
108
+ * dragSelector: '.dragMe:first',
109
+ * acceptPropagatedEvent: false
110
+ * });
111
+ * ```
112
+ *
113
+ * Notice that some 'viewports' could be nested within others but events
114
+ * would not interfere as acceptPropagatedEvent is set to false.
115
+ */
116
+ export class DragScrollable {
117
+ /**
118
+ * @param {HTMLElement} element
119
+ * @param {Partial<DEFAULT_OPTIONS>} options
120
+ */
121
+ constructor(element, options = {}) {
122
+ this.handling_element = $(element);
123
+ /** @type {typeof DEFAULT_OPTIONS} */
124
+ this.settings = $.extend({}, DEFAULT_OPTIONS, options || {});
125
+ this.firstCoord = { left: 0, top: 0 };
126
+ this.lastCoord = { left: 0, top: 0 };
127
+
128
+ this.settings.dragstart = append_namespace(this.settings.dragstart, this.settings.namespace);
129
+ this.settings.dragcontinue = append_namespace(this.settings.dragcontinue, this.settings.namespace);
130
+ //settings.dragend = append_namespace(settings.dragend, settings.namespace);
131
+
132
+ // Set mouse initiating event on the desired descendant
133
+ this.handling_element.find(this.settings.dragSelector)
134
+ .on(this.settings.dragstart, this._dragStartHandler);
135
+ }
136
+
137
+ _shouldAbort() {
138
+ const isTouchDevice = !!('ontouchstart' in window) || !!('msmaxtouchpoints' in window.navigator);
139
+ return isTouchDevice;
140
+ }
141
+
142
+ /** @param {MouseEvent} event */
143
+ _dragStartHandler = (event) => {
144
+ if (this._shouldAbort()) { return true; }
145
+
146
+ // mousedown, left click, check propagation
147
+ if (event.which > 1 ||
148
+ (!this.settings.acceptPropagatedEvent && event.target != this.handling_element[0])) {
149
+ return false;
150
+ }
151
+
152
+ // Initial coordinates will be the last when dragging
153
+ this.lastCoord = this.firstCoord = left_top(event);
154
+
155
+ this.handling_element
156
+ .on(this.settings.dragcontinue, this._dragContinueHandler)
157
+ //.on(this.settings.dragend, this._dragEndHandler)
158
+ ;
159
+
160
+ // Note, we bind using addEventListener so we can use "capture" binding
161
+ // instead of "bubble" binding
162
+ this.settings.dragend.split(' ').forEach(event_name => {
163
+ this.handling_element[0].addEventListener(event_name, this._dragEndHandler, true);
164
+ });
165
+
166
+ if (this.settings.preventDefault) {
167
+ event.preventDefault();
168
+ return false;
169
+ }
170
+ }
171
+
172
+ /** @param {MouseEvent} event */
173
+ _dragContinueHandler = (event) => { // User is dragging
174
+ // console.log('drag continue');
175
+ if (this._shouldAbort()) { return true; }
176
+
177
+ const lt = left_top(event);
178
+
179
+ // How much did the mouse move?
180
+ const delta = {
181
+ left: (lt.left - this.lastCoord.left),
182
+ top: (lt.top - this.lastCoord.top)
183
+ };
184
+
185
+ const scrollTarget = this.settings.scrollWindow ? $(window) : this.handling_element;
186
+
187
+ // Set the scroll position relative to what ever the scroll is now
188
+ scrollTarget.scrollLeft( scrollTarget.scrollLeft() - delta.left );
189
+ scrollTarget.scrollTop( scrollTarget.scrollTop() - delta.top );
190
+
191
+ // Save where the cursor is
192
+ this.lastCoord = lt;
193
+
194
+ if (this.settings.preventDefault) {
195
+ event.preventDefault();
196
+ return false;
197
+ }
198
+ }
199
+
200
+ /** @param {MouseEvent} event */
201
+ _dragEndHandler = (event) => { // Stop scrolling
202
+ //console.log('dragEndHandler');
203
+
204
+ if (this._shouldAbort()) { return true; }
205
+
206
+ this.handling_element
207
+ .off(this.settings.dragcontinue)
208
+ // Note, for some reason, even though I removeEventListener below,
209
+ // this call to unbind is still necessary. I don't know why.
210
+ .off(this.settings.dragend);
211
+
212
+ // Note, we bind using addEventListener so we can use "capture" binding
213
+ // instead of "bubble" binding
214
+ this.settings.dragend.split(' ').forEach(event_name => {
215
+ this.handling_element[0].removeEventListener(event_name, this._dragEndHandler, true);
216
+ });
217
+
218
+ // How much did the mouse move total?
219
+ const delta = {
220
+ left: Math.abs(this.lastCoord.left - this.firstCoord.left),
221
+ top: Math.abs(this.lastCoord.top - this.firstCoord.top)
222
+ };
223
+ const distance = Math.max(delta.left, delta.top);
224
+
225
+ // Allow event to propagate if min distance was not achieved
226
+ if (this.settings.preventDefault && distance > this.settings.dragMinDistance) {
227
+ event.preventDefault();
228
+ event.stopImmediatePropagation();
229
+ event.stopPropagation();
230
+ return false;
231
+ }
232
+ }
233
+ }
@@ -0,0 +1,116 @@
1
+ // @ts-check
2
+ /**
3
+ * Creates an image cache dictionary
4
+ * storing images in `<img>` tags so that
5
+ * BookReader can leverage browser caching
6
+ */
7
+ /** @typedef {import("./BookModel").BookModel} BookModel */
8
+ /** @typedef {import("./BookModel").PageIndex} PageIndex */
9
+ /** @typedef {import("./ReduceSet").ReduceSet} ReduceSet */
10
+
11
+ import { Pow2ReduceSet } from "./ReduceSet";
12
+
13
+ export class ImageCache {
14
+ /**
15
+ * @param {BookModel} book
16
+ * @param {object} opts
17
+ * @param {boolean} [opts.useSrcSet]
18
+ * @param {ReduceSet} [opts.reduceSet]
19
+ */
20
+ constructor(book, { useSrcSet = false, reduceSet = Pow2ReduceSet } = {}) {
21
+ this.book = book;
22
+ this.useSrcSet = useSrcSet;
23
+ this.reduceSet = reduceSet;
24
+ /** @type {{ [index: number]: { reduce: number, loaded: boolean }[] }} */
25
+ this.cache = {};
26
+ this.defaultScale = 8;
27
+ }
28
+
29
+ /**
30
+ * Get an image
31
+ * Checks cache first if image is available & of equal/better scale,
32
+ * if not, a new image gets created
33
+ *
34
+ * @param {PageIndex} index
35
+ * @param {Number} reduce
36
+ */
37
+ image(index, reduce) {
38
+ const cachedImages = this.cache[index] || [];
39
+ const sufficientImages = cachedImages
40
+ .filter(x => x.loaded && x.reduce <= reduce);
41
+ if (sufficientImages.length) {
42
+ // Choose the largest reduction factor that meets our needs
43
+ const bestReduce = Math.max(...sufficientImages.map(e => e.reduce));
44
+ return this._serveImageElement(index, bestReduce);
45
+ } else {
46
+ // Don't use a cache entry; i.e. a fresh fetch will be made
47
+ // for this reduce
48
+ return this._serveImageElement(index, reduce);
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Checks if an image of equal or greater quality has been loaded
54
+ * @param {PageIndex} index
55
+ * @param {Number} reduce
56
+ * @returns {Boolean}
57
+ */
58
+ imageLoaded(index, reduce) {
59
+ const cacheImg = this.cache[index]?.find(e => e.reduce <= reduce);
60
+ return cacheImg?.loaded ?? false;
61
+ }
62
+
63
+ /**
64
+ * Get the best image that's already loaded for the given index,
65
+ * trying to choose values less that the given reduce
66
+ * @param {PageIndex} index
67
+ * @param idealMaxReduce
68
+ * @returns {null | number}
69
+ */
70
+ getBestLoadedReduce(index, idealMaxReduce = Infinity) {
71
+ const candidates = this.cache[index]?.filter(x => x.loaded) || [];
72
+ if (!candidates.length) return null;
73
+
74
+ const lowerResImages = candidates.filter(e => e.reduce >= idealMaxReduce);
75
+ if (lowerResImages.length) {
76
+ // Choose the highest quality loaded lower res image
77
+ return Math.min(...lowerResImages.map(e => e.reduce));
78
+ }
79
+ // Otherwise choose whatever is closest to the reduce
80
+ const higherRestImages = candidates.filter(e => e.reduce < idealMaxReduce);
81
+ return Math.max(...higherRestImages.map(e => e.reduce));
82
+ }
83
+
84
+ /**
85
+ * @private
86
+ * Generates an image element on the fly from image info in cache
87
+ *
88
+ * @param {PageIndex} index
89
+ * @param {number} reduce
90
+ * @returns {JQuery<HTMLImageElement>} with base image classes
91
+ */
92
+ _serveImageElement(index, reduce) {
93
+ const validReduce = this.reduceSet.floor(reduce);
94
+ let cacheEntry = this.cache[index]?.find(e => e.reduce == validReduce);
95
+ if (!cacheEntry) {
96
+ cacheEntry = { reduce: validReduce, loaded: false };
97
+ const entries = this.cache[index] || (this.cache[index] = []);
98
+ entries.push(cacheEntry);
99
+ }
100
+ const page = this.book.getPage(index);
101
+
102
+ const $img = $('<img />', {
103
+ 'class': 'BRpageimage',
104
+ 'alt': 'Book page image',
105
+ src: page.getURI(validReduce, 0),
106
+ })
107
+ .data('reduce', validReduce);
108
+ if (this.useSrcSet) {
109
+ $img.attr('srcset', page.getURISrcSet(validReduce));
110
+ }
111
+ if (!cacheEntry.loaded) {
112
+ $img.one('load', () => cacheEntry.loaded = true);
113
+ }
114
+ return $img;
115
+ }
116
+ }
@@ -0,0 +1,102 @@
1
+ // @ts-check
2
+ import { Mode1UpLit } from './Mode1UpLit.js';
3
+ import { DragScrollable } from './DragScrollable.js';
4
+ /** @typedef {import('../BookReader.js').default} BookReader */
5
+ /** @typedef {import('./BookModel.js').BookModel} BookModel */
6
+ /** @typedef {import('./BookModel.js').PageIndex} PageIndex */
7
+
8
+ export class Mode1Up {
9
+ /**
10
+ * @param {BookReader} br
11
+ * @param {BookModel} bookModel
12
+ */
13
+ constructor(br, bookModel) {
14
+ this.br = br;
15
+ this.book = bookModel;
16
+ this.mode1UpLit = new Mode1UpLit(bookModel, br);
17
+
18
+ /** @private */
19
+ this.$el = $(this.mode1UpLit)
20
+ // We CANNOT use `br-mode-1up` as a class, because it's the same
21
+ // as the name of the web component, and the webcomponents polyfill
22
+ // uses the name of component as a class for style scoping 😒
23
+ .addClass('br-mode-1up__root BRmode1up');
24
+
25
+ /** Has mode1up ever been rendered before? */
26
+ this.everShown = false;
27
+ }
28
+
29
+ // TODO: Might not need this anymore? Might want to delete.
30
+ /** @private */
31
+ get $brContainer() { return this.br.refs.$brContainer; }
32
+
33
+ /**
34
+ * This is called when we switch to one page view
35
+ */
36
+ prepare() {
37
+ const startLeaf = this.br.currentIndex();
38
+ this.$brContainer
39
+ .empty()
40
+ .css({ overflow: 'hidden' })
41
+ .append(this.$el);
42
+
43
+ // Need this in a setTimeout so that it happens after the browser has _actually_
44
+ // appended the element to the DOM
45
+ setTimeout(async () => {
46
+ if (!this.everShown) {
47
+ this.mode1UpLit.initFirstRender(startLeaf);
48
+ this.everShown = true;
49
+ await this.mode1UpLit.requestUpdate();
50
+ new DragScrollable(this.mode1UpLit, {
51
+ preventDefault: true,
52
+ dragSelector: '.br-mode-1up__visible-world',
53
+ // Only handle mouse events; let browser/HammerJS handle touch
54
+ dragstart: 'mousedown',
55
+ dragcontinue: 'mousemove',
56
+ dragend: 'mouseup',
57
+ });
58
+ }
59
+ this.mode1UpLit.jumpToIndex(startLeaf);
60
+ });
61
+ this.br.updateBrClasses();
62
+ }
63
+
64
+ /**
65
+ * BREAKING CHANGE: No longer supports pageX/pageY
66
+ * @param {PageIndex} index
67
+ * @param {number} [pageX] x position on the page (in pixels) to center on
68
+ * @param {number} [pageY] y position on the page (in pixels) to center on
69
+ * @param {boolean} [noAnimate]
70
+ */
71
+ jumpToIndex(index, pageX, pageY, noAnimate) {
72
+ // Only smooth for small distances
73
+ const distance = Math.abs(this.br.currentIndex() - index);
74
+ const smooth = !noAnimate && distance <= 4;
75
+ this.mode1UpLit.jumpToIndex(index, { smooth });
76
+ }
77
+
78
+ /**
79
+ * @param {'in' | 'out'} direction
80
+ */
81
+ zoom(direction) {
82
+ switch (direction) {
83
+ case 'in':
84
+ this.mode1UpLit.zoomIn();
85
+ break;
86
+ case 'out':
87
+ this.mode1UpLit.zoomOut();
88
+ break;
89
+ default:
90
+ console.error(`Unsupported direction: ${direction}`);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Resize the current one page view
96
+ * Note this calls drawLeafs
97
+ */
98
+ resizePageView() {
99
+ this.mode1UpLit.htmlDimensionsCacher.updateClientSizes();
100
+ this.mode1UpLit.requestUpdate();
101
+ }
102
+ }