@internetarchive/bookreader 5.0.0-88-alpha.11 → 5.0.0-89

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 (243) hide show
  1. package/BookReader/BookReader.css +17 -3
  2. package/BookReader/BookReader.js +1 -1
  3. package/BookReader/BookReader.js.map +1 -1
  4. package/BookReader/ia-bookreader-bundle.js +87 -108
  5. package/BookReader/ia-bookreader-bundle.js.map +1 -1
  6. package/BookReader/plugins/plugin.archive_analytics.js +1 -1
  7. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  8. package/BookReader/plugins/plugin.autoplay.js +1 -1
  9. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  10. package/BookReader/plugins/plugin.iiif.js +1 -1
  11. package/BookReader/plugins/plugin.iiif.js.map +1 -1
  12. package/BookReader/plugins/plugin.resume.js +1 -1
  13. package/BookReader/plugins/plugin.resume.js.map +1 -1
  14. package/BookReader/plugins/plugin.search.js +1 -1
  15. package/BookReader/plugins/plugin.search.js.map +1 -1
  16. package/BookReader/plugins/plugin.text_selection.js +1 -1
  17. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  18. package/BookReader/plugins/plugin.tts.js +1 -1
  19. package/BookReader/plugins/plugin.tts.js.map +1 -1
  20. package/BookReader/plugins/plugin.url.js +1 -1
  21. package/BookReader/plugins/plugin.url.js.map +1 -1
  22. package/CHANGELOG.md +14 -0
  23. package/babel.config.js +12 -30
  24. package/codecov.yml +1 -1
  25. package/jsconfig.json +1 -3
  26. package/package.json +14 -16
  27. package/src/BookNavigator/search/search-results.js +1 -1
  28. package/src/BookReader/ImageCache.js +48 -15
  29. package/src/BookReader/Mode1UpLit.js +56 -86
  30. package/src/BookReader/Mode2UpLit.js +5 -5
  31. package/src/BookReader/Navbar/Navbar.js +53 -11
  32. package/src/BookReader/PageContainer.js +41 -22
  33. package/src/BookReader/options.js +27 -3
  34. package/src/BookReader/utils.js +10 -0
  35. package/src/BookReader.js +120 -21
  36. package/src/BookReaderPlugin.js +44 -0
  37. package/src/css/_BRnav.scss +0 -3
  38. package/src/css/_BRpages.scss +21 -2
  39. package/src/css/_controls.scss +4 -0
  40. package/src/plugins/plugin.archive_analytics.js +84 -78
  41. package/src/plugins/plugin.autoplay.js +98 -102
  42. package/src/plugins/plugin.chapters.js +17 -22
  43. package/src/plugins/plugin.iiif.js +16 -30
  44. package/src/plugins/plugin.resume.js +54 -51
  45. package/src/plugins/plugin.text_selection.js +68 -76
  46. package/src/plugins/tts/AbstractTTSEngine.js +2 -4
  47. package/src/plugins/tts/PageChunk.js +5 -9
  48. package/src/plugins/tts/PageChunkIterator.js +3 -5
  49. package/src/plugins/tts/plugin.tts.js +309 -329
  50. package/src/plugins/url/plugin.url.js +1 -1
  51. package/src/util/strings.js +1 -0
  52. package/tests/e2e/autoplay.test.js +8 -5
  53. package/tests/e2e/helpers/base.js +2 -2
  54. package/tests/e2e/helpers/mockSearch.js +6 -9
  55. package/tests/jest/BookReader/Navbar/Navbar.test.js +16 -3
  56. package/tests/jest/BookReader/PageContainer.test.js +96 -55
  57. package/tests/jest/BookReader/utils.test.js +21 -0
  58. package/tests/jest/BookReader.test.js +13 -12
  59. package/tests/jest/plugins/plugin.archive_analytics.test.js +8 -11
  60. package/tests/jest/plugins/plugin.autoplay.test.js +9 -22
  61. package/tests/jest/plugins/plugin.resume.test.js +19 -32
  62. package/tests/jest/plugins/plugin.text_selection.test.js +23 -24
  63. package/dist/esm/BookNavigator/assets/bookmark-colors.js +0 -4
  64. package/dist/esm/BookNavigator/assets/button-base.js +0 -4
  65. package/dist/esm/BookNavigator/assets/ia-logo.js +0 -4
  66. package/dist/esm/BookNavigator/assets/icon_checkmark.js +0 -8
  67. package/dist/esm/BookNavigator/assets/icon_close.js +0 -4
  68. package/dist/esm/BookNavigator/book-navigator.js +0 -612
  69. package/dist/esm/BookNavigator/bookmarks/bookmark-button.js +0 -35
  70. package/dist/esm/BookNavigator/bookmarks/bookmark-edit.js +0 -78
  71. package/dist/esm/BookNavigator/bookmarks/bookmarks-list.js +0 -160
  72. package/dist/esm/BookNavigator/bookmarks/bookmarks-loginCTA.js +0 -24
  73. package/dist/esm/BookNavigator/bookmarks/bookmarks-provider.js +0 -55
  74. package/dist/esm/BookNavigator/bookmarks/ia-bookmarks.js +0 -521
  75. package/dist/esm/BookNavigator/delete-modal-actions.js +0 -29
  76. package/dist/esm/BookNavigator/downloads/downloads-provider.js +0 -84
  77. package/dist/esm/BookNavigator/downloads/downloads.js +0 -69
  78. package/dist/esm/BookNavigator/search/search-provider.js +0 -238
  79. package/dist/esm/BookNavigator/search/search-results.js +0 -161
  80. package/dist/esm/BookNavigator/sharing.js +0 -26
  81. package/dist/esm/BookNavigator/viewable-files.js +0 -94
  82. package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments-provider.js +0 -83
  83. package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments.js +0 -131
  84. package/dist/esm/BookReader/BookModel.js +0 -575
  85. package/dist/esm/BookReader/DragScrollable.js +0 -224
  86. package/dist/esm/BookReader/ImageCache.js +0 -122
  87. package/dist/esm/BookReader/Mode1Up.js +0 -114
  88. package/dist/esm/BookReader/Mode1UpLit.js +0 -579
  89. package/dist/esm/BookReader/Mode2Up.js +0 -106
  90. package/dist/esm/BookReader/Mode2UpLit.js +0 -1020
  91. package/dist/esm/BookReader/ModeCoordinateSpace.js +0 -28
  92. package/dist/esm/BookReader/ModeSmoothZoom.js +0 -318
  93. package/dist/esm/BookReader/ModeThumb.js +0 -366
  94. package/dist/esm/BookReader/Navbar/Navbar.js +0 -253
  95. package/dist/esm/BookReader/PageContainer.js +0 -165
  96. package/dist/esm/BookReader/ReduceSet.js +0 -27
  97. package/dist/esm/BookReader/Toolbar/Toolbar.js +0 -242
  98. package/dist/esm/BookReader/events.js +0 -20
  99. package/dist/esm/BookReader/options.js +0 -331
  100. package/dist/esm/BookReader/utils/HTMLDimensionsCacher.js +0 -48
  101. package/dist/esm/BookReader/utils/ScrollClassAdder.js +0 -31
  102. package/dist/esm/BookReader/utils/SelectionObserver.js +0 -42
  103. package/dist/esm/BookReader/utils/classes.js +0 -37
  104. package/dist/esm/BookReader/utils.js +0 -315
  105. package/dist/esm/BookReader.js +0 -1828
  106. package/dist/esm/assets/icons/1up.svg +0 -12
  107. package/dist/esm/assets/icons/2up.svg +0 -15
  108. package/dist/esm/assets/icons/advance.svg +0 -26
  109. package/dist/esm/assets/icons/chevron-right.svg +0 -1
  110. package/dist/esm/assets/icons/close-circle-dark.svg +0 -1
  111. package/dist/esm/assets/icons/close-circle.svg +0 -1
  112. package/dist/esm/assets/icons/fullscreen.svg +0 -17
  113. package/dist/esm/assets/icons/fullscreen_exit.svg +0 -17
  114. package/dist/esm/assets/icons/hamburger.svg +0 -15
  115. package/dist/esm/assets/icons/left-arrow.svg +0 -12
  116. package/dist/esm/assets/icons/magnify-minus.svg +0 -12
  117. package/dist/esm/assets/icons/magnify-plus.svg +0 -13
  118. package/dist/esm/assets/icons/magnify.svg +0 -15
  119. package/dist/esm/assets/icons/pause.svg +0 -23
  120. package/dist/esm/assets/icons/play.svg +0 -22
  121. package/dist/esm/assets/icons/playback-speed.svg +0 -34
  122. package/dist/esm/assets/icons/read-aloud.svg +0 -22
  123. package/dist/esm/assets/icons/review.svg +0 -22
  124. package/dist/esm/assets/icons/thumbnails.svg +0 -17
  125. package/dist/esm/assets/icons/voice.svg +0 -1
  126. package/dist/esm/assets/icons/volume-full.svg +0 -22
  127. package/dist/esm/assets/images/BRicons.png +0 -0
  128. package/dist/esm/assets/images/BRicons.svg +0 -94
  129. package/dist/esm/assets/images/BRicons_ia.png +0 -0
  130. package/dist/esm/assets/images/back_pages.png +0 -0
  131. package/dist/esm/assets/images/book_bottom_icon.png +0 -0
  132. package/dist/esm/assets/images/book_down_icon.png +0 -0
  133. package/dist/esm/assets/images/book_left_icon.png +0 -0
  134. package/dist/esm/assets/images/book_leftmost_icon.png +0 -0
  135. package/dist/esm/assets/images/book_right_icon.png +0 -0
  136. package/dist/esm/assets/images/book_rightmost_icon.png +0 -0
  137. package/dist/esm/assets/images/book_top_icon.png +0 -0
  138. package/dist/esm/assets/images/book_up_icon.png +0 -0
  139. package/dist/esm/assets/images/books_graphic.svg +0 -177
  140. package/dist/esm/assets/images/booksplit.png +0 -0
  141. package/dist/esm/assets/images/control_pause_icon.png +0 -0
  142. package/dist/esm/assets/images/control_play_icon.png +0 -0
  143. package/dist/esm/assets/images/embed_icon.png +0 -0
  144. package/dist/esm/assets/images/icon-home-ia.png +0 -0
  145. package/dist/esm/assets/images/icon_OL-logo-xs.png +0 -0
  146. package/dist/esm/assets/images/icon_alert-xs.png +0 -0
  147. package/dist/esm/assets/images/icon_book.svg +0 -12
  148. package/dist/esm/assets/images/icon_bookmark.svg +0 -12
  149. package/dist/esm/assets/images/icon_close-pop.png +0 -0
  150. package/dist/esm/assets/images/icon_download.png +0 -0
  151. package/dist/esm/assets/images/icon_gear.svg +0 -14
  152. package/dist/esm/assets/images/icon_hamburger.svg +0 -20
  153. package/dist/esm/assets/images/icon_home.png +0 -0
  154. package/dist/esm/assets/images/icon_home.svg +0 -21
  155. package/dist/esm/assets/images/icon_home_ia.png +0 -0
  156. package/dist/esm/assets/images/icon_indicator.png +0 -0
  157. package/dist/esm/assets/images/icon_info.svg +0 -11
  158. package/dist/esm/assets/images/icon_one_page.svg +0 -8
  159. package/dist/esm/assets/images/icon_pause.svg +0 -1
  160. package/dist/esm/assets/images/icon_play.svg +0 -1
  161. package/dist/esm/assets/images/icon_playback-rate.svg +0 -15
  162. package/dist/esm/assets/images/icon_return.png +0 -0
  163. package/dist/esm/assets/images/icon_search_button.svg +0 -8
  164. package/dist/esm/assets/images/icon_share.svg +0 -9
  165. package/dist/esm/assets/images/icon_skip-ahead.svg +0 -6
  166. package/dist/esm/assets/images/icon_skip-back.svg +0 -13
  167. package/dist/esm/assets/images/icon_speaker.svg +0 -18
  168. package/dist/esm/assets/images/icon_speaker_open.svg +0 -10
  169. package/dist/esm/assets/images/icon_thumbnails.svg +0 -12
  170. package/dist/esm/assets/images/icon_toc.svg +0 -5
  171. package/dist/esm/assets/images/icon_two_pages.svg +0 -9
  172. package/dist/esm/assets/images/icon_zoomer.png +0 -0
  173. package/dist/esm/assets/images/loading.gif +0 -0
  174. package/dist/esm/assets/images/logo_icon.png +0 -0
  175. package/dist/esm/assets/images/marker_chap-off.png +0 -0
  176. package/dist/esm/assets/images/marker_chap-off.svg +0 -11
  177. package/dist/esm/assets/images/marker_chap-off_ia.png +0 -0
  178. package/dist/esm/assets/images/marker_chap-on.png +0 -0
  179. package/dist/esm/assets/images/marker_chap-on.svg +0 -11
  180. package/dist/esm/assets/images/marker_srch-on.svg +0 -11
  181. package/dist/esm/assets/images/marker_srchchap-off.png +0 -0
  182. package/dist/esm/assets/images/marker_srchchap-on.png +0 -0
  183. package/dist/esm/assets/images/nav_control-dn.png +0 -0
  184. package/dist/esm/assets/images/nav_control-dn_ia.png +0 -0
  185. package/dist/esm/assets/images/nav_control-up.png +0 -0
  186. package/dist/esm/assets/images/nav_control-up_ia.png +0 -0
  187. package/dist/esm/assets/images/nav_control.png +0 -0
  188. package/dist/esm/assets/images/one_page_mode_icon.png +0 -0
  189. package/dist/esm/assets/images/paper-badge.png +0 -0
  190. package/dist/esm/assets/images/print_icon.png +0 -0
  191. package/dist/esm/assets/images/progressbar.gif +0 -0
  192. package/dist/esm/assets/images/right_edges.png +0 -0
  193. package/dist/esm/assets/images/slider.png +0 -0
  194. package/dist/esm/assets/images/slider_ia.png +0 -0
  195. package/dist/esm/assets/images/thumbnail_mode_icon.png +0 -0
  196. package/dist/esm/assets/images/transparent.png +0 -0
  197. package/dist/esm/assets/images/two_page_mode_icon.png +0 -0
  198. package/dist/esm/assets/images/unviewable_page.png +0 -0
  199. package/dist/esm/assets/images/zoom_in_icon.png +0 -0
  200. package/dist/esm/assets/images/zoom_out_icon.png +0 -0
  201. package/dist/esm/css/BookReader.scss +0 -85
  202. package/dist/esm/css/_BRBookmarks.scss +0 -29
  203. package/dist/esm/css/_BRComponent.scss +0 -13
  204. package/dist/esm/css/_BRfloat.scss +0 -197
  205. package/dist/esm/css/_BRicon.scss +0 -54
  206. package/dist/esm/css/_BRmain.scss +0 -262
  207. package/dist/esm/css/_BRnav.scss +0 -354
  208. package/dist/esm/css/_BRpages.scss +0 -213
  209. package/dist/esm/css/_BRsearch.scss +0 -268
  210. package/dist/esm/css/_BRtoolbar.scss +0 -84
  211. package/dist/esm/css/_BRvendor.scss +0 -5
  212. package/dist/esm/css/_TextSelection.scss +0 -108
  213. package/dist/esm/css/_colorbox.scss +0 -52
  214. package/dist/esm/css/_controls.scss +0 -257
  215. package/dist/esm/css/_icons.scss +0 -121
  216. package/dist/esm/ia-bookreader/ia-bookreader.js +0 -141
  217. package/dist/esm/jquery-wrapper.js +0 -3
  218. package/dist/esm/plugins/plugin.archive_analytics.js +0 -72
  219. package/dist/esm/plugins/plugin.autoplay.js +0 -119
  220. package/dist/esm/plugins/plugin.chapters.js +0 -288
  221. package/dist/esm/plugins/plugin.iframe.js +0 -44
  222. package/dist/esm/plugins/plugin.iiif.js +0 -146
  223. package/dist/esm/plugins/plugin.resume.js +0 -66
  224. package/dist/esm/plugins/plugin.text_selection.js +0 -621
  225. package/dist/esm/plugins/plugin.vendor-fullscreen.js +0 -227
  226. package/dist/esm/plugins/search/plugin.search.js +0 -499
  227. package/dist/esm/plugins/search/utils.js +0 -42
  228. package/dist/esm/plugins/search/view.js +0 -360
  229. package/dist/esm/plugins/tts/AbstractTTSEngine.js +0 -282
  230. package/dist/esm/plugins/tts/FestivalTTSEngine.js +0 -192
  231. package/dist/esm/plugins/tts/PageChunk.js +0 -105
  232. package/dist/esm/plugins/tts/PageChunkIterator.js +0 -155
  233. package/dist/esm/plugins/tts/WebTTSEngine.js +0 -364
  234. package/dist/esm/plugins/tts/plugin.tts.js +0 -315
  235. package/dist/esm/plugins/tts/tooltip_dict.js +0 -14
  236. package/dist/esm/plugins/tts/utils.js +0 -79
  237. package/dist/esm/plugins/url/UrlPlugin.js +0 -197
  238. package/dist/esm/plugins/url/plugin.url.js +0 -212
  239. package/dist/esm/util/browserSniffing.js +0 -56
  240. package/dist/esm/util/debouncer.js +0 -25
  241. package/dist/esm/util/docCookies.js +0 -75
  242. package/dist/esm/util/strings.js +0 -34
  243. package/index.js +0 -2
@@ -1,86 +1,92 @@
1
- /* global BookReader */
2
- /**
3
- * Plugin for Archive.org analytics
4
- */
5
- jQuery.extend(BookReader.defaultOptions, {
6
- enableArchiveAnalytics: true,
7
- /** Provide a means of debugging, cause otherwise it's impossible to test locally */
8
- debugArchiveAnaltyics: false,
9
- });
10
-
11
- BookReader.prototype.init = (function(super_) {
12
- return function() {
13
- super_.call(this);
14
-
15
- if (this.options.enableArchiveAnalytics) {
16
- this.bind(BookReader.eventNames.fragmentChange, () => this.archiveAnalyticsSendFragmentChange());
17
- }
18
- };
19
- })(BookReader.prototype.init);
1
+ // @ts-check
2
+ import { BookReaderPlugin } from "../BookReaderPlugin.js";
3
+
4
+ const BookReader = /** @type {typeof import('../BookReader').default} */(window.BookReader);
5
+
20
6
 
21
- /** @private */
22
- BookReader.prototype.archiveAnalyticsSendFragmentChange = function() {
23
- if (!window.archive_analytics) {
24
- return;
7
+ export class ArchiveAnalyticsPlugin extends BookReaderPlugin {
8
+ options = {
9
+ enabled: true,
10
+ /** Provide a means of debugging, cause otherwise it's impossible to test locally */
11
+ debug: false,
25
12
  }
26
13
 
27
- const prevFragment = this.archiveAnalyticsSendFragmentChange.prevFragment;
28
-
29
- const params = this.paramsFromCurrent();
30
- const newFragment = this.fragmentFromParams(params);
31
-
32
- if (prevFragment != newFragment) {
33
- const values = {
34
- bookreader: "user_changed_view",
35
- itemid: this.bookId,
36
- cache_bust: Math.random(),
37
- };
38
- // EEK! offsite embedding and /details/ page books look the same in analytics, otherwise!
39
- values.offsite = 1;
40
- values.details = 0;
41
- try {
42
- values.offsite = window.top.location.hostname.match(/\.archive.org$/)
43
- ? 0
44
- : 1;
45
- values.details =
46
- !values.offsite && window.top.location.pathname.match(/^\/details\//)
47
- ? 1
48
- : 0;
49
- } catch (e) {}
50
- // avoids embed cross site exceptions -- but on (+) side, means it is and keeps marked offite!
51
-
52
- // Send bookreader ping
53
- window.archive_analytics.send_ping(values, null, "augment_for_ao_site");
54
-
55
- // Also send tracking event ping
56
- const additionalEventParams = this.options.lendingInfo && this.options.lendingInfo.loanId
57
- ? { loanId: this.options.lendingInfo.loanId }
58
- : {};
59
- window.archive_analytics.send_event('BookReader', 'UserChangedView', window.location.pathname, additionalEventParams);
60
-
61
- this.archiveAnalyticsSendFragmentChange.prevFragment = newFragment;
14
+ /** @type {string} */
15
+ _prevFragment = null;
16
+
17
+ /** @override */
18
+ init() {
19
+ if (this.options.enabled) {
20
+ this.br.bind(BookReader.eventNames.fragmentChange, () => this.sendFragmentChange());
21
+ }
62
22
  }
63
- };
64
-
65
- /**
66
- * Sends a tracking "Event". See https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#events
67
- * @param {string} category
68
- * @param {string} action
69
- * @param {number} [value] (must be an int)
70
- * @param {Object} [additionalEventParams]
71
- */
72
- BookReader.prototype.archiveAnalyticsSendEvent = function(category, action, value, additionalEventParams) {
73
- if (!this.options.enableArchiveAnalytics) return;
74
-
75
- if (this.options.debugArchiveAnaltyics) {
76
- console.log("archiveAnalyticsSendEvent", arguments, window.archive_analytics);
23
+
24
+ /** @private */
25
+ sendFragmentChange() {
26
+ if (!window.archive_analytics) {
27
+ return;
28
+ }
29
+
30
+ const prevFragment = this._prevFragment;
31
+
32
+ const params = this.br.paramsFromCurrent();
33
+ const newFragment = this.br.fragmentFromParams(params);
34
+
35
+ if (prevFragment != newFragment) {
36
+ const values = {
37
+ bookreader: "user_changed_view",
38
+ itemid: this.br.bookId,
39
+ cache_bust: Math.random(),
40
+ };
41
+ // EEK! offsite embedding and /details/ page books look the same in analytics, otherwise!
42
+ values.offsite = 1;
43
+ values.details = 0;
44
+ try {
45
+ values.offsite = window.top.location.hostname.match(/\.archive.org$/)
46
+ ? 0
47
+ : 1;
48
+ values.details =
49
+ !values.offsite && window.top.location.pathname.match(/^\/details\//)
50
+ ? 1
51
+ : 0;
52
+ } catch (e) { }
53
+ // avoids embed cross site exceptions -- but on (+) side, means it is and keeps marked offite!
54
+
55
+ // Send bookreader ping
56
+ window.archive_analytics.send_ping(values, null, "augment_for_ao_site");
57
+
58
+ // Also send tracking event ping
59
+ const additionalEventParams = this.br.options.lendingInfo?.loanId
60
+ ? { loanId: this.br.options.lendingInfo.loanId }
61
+ : {};
62
+ window.archive_analytics.send_event('BookReader', 'UserChangedView', window.location.pathname, additionalEventParams);
63
+
64
+ this._prevFragment = newFragment;
65
+ }
77
66
  }
78
67
 
79
- if (!window.archive_analytics) return;
68
+ /**
69
+ * Sends a tracking "Event". See https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#events
70
+ * @param {string} category
71
+ * @param {string} action
72
+ * @param {number} [value] (must be an int)
73
+ * @param {Object} [additionalEventParams]
74
+ */
75
+ sendEvent(category, action, value, additionalEventParams) {
76
+ if (!this.options.enabled) return;
80
77
 
81
- additionalEventParams = additionalEventParams || {};
82
- if (typeof(value) == 'number') {
83
- additionalEventParams.ev = value;
78
+ if (this.options.debug) {
79
+ console.log("archiveAnalyticsSendEvent", arguments, window.archive_analytics);
80
+ }
81
+
82
+ if (!window.archive_analytics) return;
83
+
84
+ additionalEventParams = additionalEventParams || {};
85
+ if (typeof (value) == 'number') {
86
+ additionalEventParams.ev = value;
87
+ }
88
+ window.archive_analytics.send_event(category, action, null, additionalEventParams);
84
89
  }
85
- window.archive_analytics.send_event(category, action, null, additionalEventParams);
86
- };
90
+ }
91
+
92
+ BookReader?.registerPlugin('archiveAnalytics', ArchiveAnalyticsPlugin);
@@ -1,128 +1,124 @@
1
- /*global BookReader */
1
+ // @ts-check
2
+ import { EVENTS } from "../BookReader/events";
3
+ import { parseAnimationSpeed } from "../BookReader/utils";
4
+ import { BookReaderPlugin } from "../BookReaderPlugin";
2
5
 
3
6
  /**
4
7
  * Plugin which adds an autoplay feature. Useful for kiosk situations.
5
8
  */
6
- jQuery.extend(BookReader.defaultOptions, {
7
- enableAutoPlayPlugin: true,
8
- });
9
-
10
- /**
11
- * @override BookReader.setup
12
- */
13
- BookReader.prototype.setup = (function(super_) {
14
- return function (options) {
15
- super_.call(this, options);
16
-
17
- this.autoTimer = null;
18
- this.flipDelay = 5000;
19
- };
20
- })(BookReader.prototype.setup);
9
+ export class AutoplayPlugin extends BookReaderPlugin {
10
+ options = {
11
+ enabled: true,
12
+ /**
13
+ * @type {number | 'fast' | 'slow'}
14
+ * How quickly the flip animation should run.
15
+ **/
16
+ flipSpeed: 1500,
17
+ /** How long to pause on each page between flips */
18
+ flipDelay: 5000,
19
+ /** Allow controlling the autoflip/speed/delay from the url */
20
+ urlParams: true,
21
+ }
21
22
 
22
- /**
23
- * @override BookReader.init
24
- */
25
- BookReader.prototype.init = (function(super_) {
26
- return function (options) {
27
- super_.call(this, options);
23
+ timer = null;
28
24
 
29
- if (!this.options.enableAutoPlayPlugin) return;
25
+ /** @override */
26
+ init() {
27
+ if (!this.options.enabled) return;
30
28
 
31
- this.bind(BookReader.eventNames.stop, () => this.autoStop());
29
+ this.br.bind(EVENTS.stop, () => this.stop());
32
30
 
33
- const urlParams = new URLSearchParams(window.location.search);
34
- if (urlParams.get('autoflip') === '1') {
35
- this.autoToggle();
31
+ if (this.options.urlParams) {
32
+ const urlParams = new URLSearchParams(window.location.search);
33
+ if (urlParams.get('flipSpeed')) {
34
+ this.options.flipSpeed = parseAnimationSpeed(urlParams.get('flipSpeed')) || this.options.flipSpeed;
35
+ }
36
+ if (urlParams.get('flipDelay')) {
37
+ this.options.flipDelay = parseAnimationSpeed(urlParams.get('flipDelay')) || this.options.flipDelay;
38
+ }
39
+ if (urlParams.get('autoflip') === '1') {
40
+ this.toggle();
41
+ }
36
42
  }
37
- };
38
- })(BookReader.prototype.init);
39
-
40
- /**
41
- * @override BookReader.bindNavigationHandlers
42
- */
43
- BookReader.prototype.bindNavigationHandlers = (function(super_) {
44
- return function() {
45
- super_.call(this);
43
+ }
46
44
 
47
- if (!this.options.enableAutoPlayPlugin) return;
45
+ /** @override */
46
+ _bindNavigationHandlers() {
47
+ if (!this.options.enabled) return;
48
48
 
49
- const jIcons = this.$('.BRicon');
49
+ const jIcons = this.br.$('.BRicon');
50
50
 
51
- jIcons.filter('.play').click(() => {
52
- this.autoToggle();
51
+ jIcons.filter('.play').on('click', () => {
52
+ this.toggle();
53
53
  return false;
54
54
  });
55
55
 
56
- jIcons.filter('.pause').click(() => {
57
- this.autoToggle();
56
+ jIcons.filter('.pause').on('click', () => {
57
+ this.toggle();
58
58
  return false;
59
59
  });
60
- };
61
- })(BookReader.prototype.bindNavigationHandlers);
62
-
63
- /**
64
- * Starts autoplay mode
65
- * @param {object} overrides
66
- * @param {number} overrides.flipSpeed
67
- * @param {number} overrides.flipDelay
68
- */
69
- BookReader.prototype.autoToggle = function(overrides) {
70
- if (!this.options.enableAutoPlayPlugin) return;
71
-
72
- const options = $.extend({
73
- flipSpeed: this.flipSpeed,
74
- flipDelay: this.flipDelay,
75
- }, overrides);
76
-
77
- this.flipSpeed = typeof options.flipSpeed === "number" ? options.flipSpeed : this.flipSpeed;
78
- this.flipDelay = typeof options.flipDelay === "number" ? options.flipDelay : this.flipDelay;
79
- this.trigger(BookReader.eventNames.stop);
80
-
81
- let bComingFrom1up = false;
82
- if (this.constMode2up != this.mode) {
83
- bComingFrom1up = true;
84
- this.switchMode(this.constMode2up);
85
60
  }
86
61
 
87
- if (null == this.autoTimer) {
88
- // $$$ Draw events currently cause layout problems when they occur during animation.
89
- // There is a specific problem when changing from 1-up immediately to autoplay in RTL so
90
- // we workaround for now by not triggering immediate animation in that case.
91
- // See https://bugs.launchpad.net/gnubook/+bug/328327
92
- if (('rl' == this.pageProgression) && bComingFrom1up) {
93
- // don't flip immediately -- wait until timer fires
94
- } else {
95
- // flip immediately
96
- this.next({ triggerStop: false });
62
+ /**
63
+ * Starts autoplay mode
64
+ * @param {object} overrides
65
+ * @param {number} overrides.flipSpeed
66
+ * @param {number} overrides.flipDelay
67
+ */
68
+ toggle(overrides = null) {
69
+ if (!this.options.enabled) return;
70
+
71
+ Object.assign(this.options, overrides);
72
+ this.br.trigger(EVENTS.stop);
73
+
74
+ let bComingFrom1up = false;
75
+ if (this.br.constMode2up != this.br.mode) {
76
+ bComingFrom1up = true;
77
+ this.br.switchMode(this.br.constMode2up);
97
78
  }
98
79
 
99
- this.$('.play').hide();
100
- this.$('.pause').show();
101
- this.autoTimer = setInterval(() => {
102
- if (this.animating) return;
103
-
104
- if (Math.max(this.twoPage.currentIndexL, this.twoPage.currentIndexR) >= this.book.getNumLeafs() - 1) {
105
- this.prev({ triggerStop: false }); // $$$ really what we want?
80
+ if (null == this.timer) {
81
+ // $$$ Draw events currently cause layout problems when they occur during animation.
82
+ // There is a specific problem when changing from 1-up immediately to autoplay in RTL so
83
+ // we workaround for now by not triggering immediate animation in that case.
84
+ // See https://bugs.launchpad.net/gnubook/+bug/328327
85
+ if (('rl' == this.br.pageProgression) && bComingFrom1up) {
86
+ // don't flip immediately -- wait until timer fires
106
87
  } else {
107
- this.next({ triggerStop: false });
88
+ // flip immediately
89
+ this.br.next({ triggerStop: false, flipSpeed: this.options.flipSpeed });
108
90
  }
109
- }, this.flipDelay);
110
- } else {
111
- this.autoStop();
91
+
92
+ this.br.$('.play').hide();
93
+ this.br.$('.pause').show();
94
+ this.timer = setInterval(() => {
95
+ if (this.br.animating) return;
96
+
97
+ if (Math.max(this.br.twoPage.currentIndexL, this.br.twoPage.currentIndexR) >= this.br.book.getNumLeafs() - 1) {
98
+ this.br.prev({ triggerStop: false, flipSpeed: this.options.flipSpeed }); // $$$ really what we want?
99
+ } else {
100
+ this.br.next({ triggerStop: false, flipSpeed: this.options.flipSpeed });
101
+ }
102
+ }, parseAnimationSpeed(this.options.flipDelay));
103
+ } else {
104
+ this.stop();
105
+ }
112
106
  }
113
- };
114
107
 
115
- /**
116
- * Stop autoplay mode, allowing animations to finish
117
- */
118
- BookReader.prototype.autoStop = function() {
119
- if (!this.options.enableAutoPlayPlugin) return;
120
-
121
- if (null != this.autoTimer) {
122
- clearInterval(this.autoTimer);
123
- this.flipSpeed = 'fast';
124
- this.$('.pause').hide();
125
- this.$('.play').show();
126
- this.autoTimer = null;
108
+ /**
109
+ * Stop autoplay mode, allowing animations to finish
110
+ */
111
+ stop() {
112
+ if (!this.options.enabled) return;
113
+
114
+ if (null != this.timer) {
115
+ clearInterval(this.timer);
116
+ this.br.$('.pause').hide();
117
+ this.br.$('.play').show();
118
+ this.timer = null;
119
+ }
127
120
  }
128
- };
121
+ }
122
+
123
+ const BookReader = /** @type {typeof import('../BookReader').default} */(window.BookReader);
124
+ BookReader?.registerPlugin('autoplay', AutoplayPlugin);
@@ -191,6 +191,7 @@ BookReader.prototype._chaptersUpdateCurrent = function(
191
191
  }
192
192
  };
193
193
 
194
+ @customElement('br-chapters-panel')
194
195
  export class BRChaptersPanel extends LitElement {
195
196
  /** @type {TocEntry[]} */
196
197
  @property({ type: Array })
@@ -213,9 +214,9 @@ export class BRChaptersPanel extends LitElement {
213
214
 
214
215
  render() {
215
216
  return html`
216
- <ol>
217
- ${this.contents.map((tocEntry) => this.renderTOCEntry(tocEntry))}
218
- </ol>
217
+ <ol>
218
+ ${this.contents.map(tocEntry => this.renderTOCEntry(tocEntry))}
219
+ </ol>
219
220
  `;
220
221
  }
221
222
 
@@ -224,29 +225,26 @@ export class BRChaptersPanel extends LitElement {
224
225
  */
225
226
  renderTOCEntry(tocEntry) {
226
227
  const chapterTitle = [tocEntry.label, tocEntry.title]
227
- .filter((x) => x)
228
+ .filter(x => x)
228
229
  .join(' ');
229
230
  const clickable = tocEntry.pageIndex != undefined;
230
231
  // note the click-tracking won't work...
231
- return html` <li
232
+ return html`
233
+ <li
232
234
  class="
233
235
  BRtable-contents-el
234
236
  ${clickable ? 'clickable' : ''}
235
237
  ${tocEntry == this.currentChapter ? 'current' : ''}
236
238
  "
237
- style="${styleMap({ marginLeft: (tocEntry.level - 1) * 10 + 'px' })}"
238
- data-event-click-tracking="${ifDefined(
239
- clickable ? 'BRTOCPanel|GoToChapter' : undefined,
240
- )}"
239
+ style="${styleMap({marginLeft: (tocEntry.level - 1) * 10 + 'px'})}"
240
+ data-event-click-tracking="${ifDefined(clickable ? "BRTOCPanel|GoToChapter" : undefined)}"
241
241
  @click="${() => this.jumpToPage(tocEntry.pageIndex)}"
242
242
  >
243
243
  ${chapterTitle}
244
- ${tocEntry.pagenum
245
- ? html`
246
- <br />
247
- <span class="BRTOCElementPage">Page ${tocEntry.pagenum}</span>
248
- `
249
- : nothing}
244
+ ${tocEntry.pagenum ? html`
245
+ <br />
246
+ <span class="BRTOCElementPage">Page ${tocEntry.pagenum}</span>
247
+ ` : nothing}
250
248
  </li>`;
251
249
  }
252
250
 
@@ -283,20 +281,17 @@ export class BRChaptersPanel extends LitElement {
283
281
  }
284
282
 
285
283
  li.clickable:not(.current):hover {
286
- background-color: rgba(255, 255, 255, 0.05);
284
+ background-color: rgba(255,255,255, 0.05);
287
285
  }
288
286
 
289
287
  li.current {
290
- background-color: rgba(255, 255, 255, 0.9);
288
+ background-color: rgba(255,255,255,0.9);
291
289
  color: #333;
292
290
  }
293
291
 
294
292
  .BRTOCElementPage {
295
293
  font-size: 0.85em;
296
- opacity: 0.8;
297
- }
298
- `;
294
+ opacity: .8;
295
+ }`;
299
296
  }
300
297
  }
301
-
302
- customElements.define('br-chapters-panel', BRChaptersPanel);
@@ -1,17 +1,22 @@
1
1
  // @ts-check
2
+ import { BookReaderPlugin } from '../BookReaderPlugin';
3
+
2
4
  const BookReader = /** @type {typeof import('../BookReader').default} */(window.BookReader);
3
5
 
4
- export const DEFAULT_OPTIONS = {
5
- enabled: true,
6
- /** @type {import('@iiif/presentation-3').Manifest | import('@iiif/presentation-2').Manifest} */
7
- manifest: null,
8
- };
6
+ export class IiifPlugin extends BookReaderPlugin {
7
+ options = {
8
+ enabled: true,
9
+ /** @type {import('@iiif/presentation-3').Manifest | import('@iiif/presentation-2').Manifest} */
10
+ manifest: null,
11
+ }
9
12
 
10
- class IIIFPlugin {
11
- constructor(options = DEFAULT_OPTIONS, optionVariables) {
12
- this.options = options;
13
- this.optionVariables = optionVariables;
14
- this.manifest = options.manifest;
13
+ setup(options) {
14
+ super.setup(options);
15
+ this.manifest = this.options.manifest;
16
+
17
+ if (this.options.enabled) {
18
+ Object.assign(this.br.options, this.load());
19
+ }
15
20
  }
16
21
 
17
22
  load() {
@@ -133,23 +138,4 @@ function resolveInternationalString(internationalString) {
133
138
  return (internationalString[navigator.language] || internationalString[anyLang])[0];
134
139
  }
135
140
 
136
- export class BookReaderWithIIIFPlugin extends BookReader {
137
- setup(options) {
138
- const pluginOpts = Object.assign(
139
- {},
140
- DEFAULT_OPTIONS,
141
- options.plugins.iiif,
142
- );
143
-
144
- if (pluginOpts.enabled) {
145
- this.iiifPlugin = new IIIFPlugin(pluginOpts, options.vars);
146
- // Write this back; this way the plugin is the source of truth, and BR just
147
- // contains a reference to it.
148
- options.plugins.iiif = this.iiifPlugin.options;
149
- Object.assign(options, this.iiifPlugin.load());
150
- }
151
- return super.setup(options);
152
- }
153
- }
154
- window.BookReader = BookReaderWithIIIFPlugin;
155
- export default BookReaderWithIIIFPlugin;
141
+ BookReader?.registerPlugin('iiif', IiifPlugin);
@@ -1,3 +1,5 @@
1
+ import { EVENTS } from '../BookReader/events.js';
2
+ import { BookReaderPlugin } from '../BookReaderPlugin.js';
1
3
  import * as docCookies from '../util/docCookies.js';
2
4
 
3
5
  /* global BookReader */
@@ -8,61 +10,62 @@ BookReader.docCookies = docCookies;
8
10
  /**
9
11
  * Plugin to remember the current page number in a cookie
10
12
  */
11
- jQuery.extend(BookReader.defaultOptions, {
12
- enablePageResume: true,
13
- /** @type {string|null} eg '/', '/details/id' */
14
- resumeCookiePath: null,
15
- });
13
+ export class ResumePlugin extends BookReaderPlugin {
14
+ options = {
15
+ enabled: true,
16
+ /** @type {string|null} eg '/', '/details/id' */
17
+ cookiePath: null,
18
+ }
16
19
 
17
- /** @override */
18
- BookReader.prototype.init = (function(super_) {
19
- return function() {
20
- super_.call(this);
21
- if (this.options.enablePageResume) {
22
- this.bind(BookReader.eventNames.fragmentChange, () => {
23
- const params = this.paramsFromCurrent();
20
+ /** @override */
21
+ init() {
22
+ if (this.options.enabled) {
23
+ this.br.bind(EVENTS.fragmentChange, () => {
24
+ const params = this.br.paramsFromCurrent();
24
25
  this.updateResumeValue(params.index);
25
26
  });
26
27
  }
27
- };
28
- })(BookReader.prototype.init);
28
+ }
29
29
 
30
- /**
31
- * Gets page resume value, for remembering reader's page
32
- * Can be overridden for different implementation
33
- *
34
- * @return {number|null}
35
- */
36
- BookReader.prototype.getResumeValue = function() {
37
- const val = BookReader.docCookies.getItem('br-resume');
38
- if (val !== null) return parseInt(val);
39
- else return null;
40
- };
30
+ /**
31
+ * Gets page resume value, for remembering reader's page
32
+ * Can be overridden for different implementation
33
+ *
34
+ * @return {number|null}
35
+ */
36
+ getResumeValue() {
37
+ const val = BookReader.docCookies.getItem('br-resume');
38
+ if (val !== null) return parseInt(val);
39
+ else return null;
40
+ }
41
41
 
42
- /**
43
- * Return cookie path using pathname up to /page/... or /mode/...
44
- * using window.location.pathname for urlPathPart:
45
- * - matches encoding
46
- * - ignores querystring part
47
- * - ignores fragment part (after #)
48
- * @param {string} urlPathPart - window.location.pathname
49
- */
50
- BookReader.prototype.getCookiePath = function(urlPathPart) {
51
- return urlPathPart.match('.+?(?=/page/|/mode/|$)')[0];
52
- };
42
+ /**
43
+ * Return cookie path using pathname up to /page/... or /mode/...
44
+ * using window.location.pathname for urlPathPart:
45
+ * - matches encoding
46
+ * - ignores querystring part
47
+ * - ignores fragment part (after #)
48
+ * @param {string} urlPathPart - window.location.pathname
49
+ */
50
+ getCookiePath(urlPathPart) {
51
+ return urlPathPart.match('.+?(?=/page/|/mode/|$)')[0];
52
+ }
53
53
 
54
- /**
55
- * Sets page resume value, for remembering reader's page
56
- * Can be overridden for different implementation
57
- *
58
- * @param {Number} index leaf index
59
- * @param {string} [cookieName]
60
- */
61
- BookReader.prototype.updateResumeValue = function(index, cookieName) {
62
- const ttl = new Date(+new Date + 12096e5); // 2 weeks
63
- // For multiple files in item, leave resumeCookiePath blank
64
- // It's likely we can remove resumeCookiePath using getCookiePath()
65
- const path = this.options.resumeCookiePath
66
- || this.getCookiePath(window.location.pathname);
67
- BookReader.docCookies.setItem(cookieName || 'br-resume', index, ttl, path, null, false);
68
- };
54
+ /**
55
+ * Sets page resume value, for remembering reader's page
56
+ * Can be overridden for different implementation
57
+ *
58
+ * @param {Number} index leaf index
59
+ * @param {string} [cookieName]
60
+ */
61
+ updateResumeValue(index, cookieName) {
62
+ const ttl = new Date(+new Date + 12096e5); // 2 weeks
63
+ // For multiple files in item, leave cookiePath blank
64
+ // It's likely we can remove cookiePath using getCookiePath()
65
+ const path = this.options.cookiePath
66
+ || this.getCookiePath(window.location.pathname);
67
+ BookReader.docCookies.setItem(cookieName || 'br-resume', index, ttl, path, null, false);
68
+ }
69
+ }
70
+
71
+ BookReader?.registerPlugin('resume', ResumePlugin);