@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,382 +0,0 @@
1
- // @ts-check
2
- /** @typedef {import('./BookModel.js').PageNumString} PageNumString */
3
- /** @typedef {import('./BookModel.js').LeafNum} LeafNum */
4
-
5
- export const DEFAULT_OPTIONS = {
6
- /**
7
- * @type {string} A string, such as "mode/1up". See
8
- * http://openlibrary.org/dev/docs/bookurls for valid syntax
9
- */
10
- defaults: null,
11
-
12
- /** Padding in 1up */
13
- padding: 10,
14
-
15
- /** @type {'full' | 'embed' | 'responsive'} UI mode */
16
- ui: 'full',
17
-
18
- /** Controls whether nav/toolbar will autohide */
19
- uiAutoHide: false,
20
-
21
- /** thumbnail mode */
22
- /** number of rows to pre-cache out a view */
23
- thumbRowBuffer: 1,
24
- thumbColumns: 6,
25
- /** number of thumbnails to load at once */
26
- thumbMaxLoading: 4,
27
- /** spacing between thumbnails */
28
- thumbPadding: 10,
29
- /** min zoom in columns */
30
- thumbMinZoomColumns: 2,
31
- /** max zoom out columns */
32
- thumbMaxZoomColumns: 8,
33
-
34
- /** @type {number | 'fast' | 'slow'} speed for flip animation */
35
- flipSpeed: 400,
36
-
37
- showToolbar: true,
38
- showNavbar: true,
39
- navBarTitle: '',
40
-
41
- showLogo: true,
42
- /** Where the logo links to */
43
- logoURL: 'https://archive.org',
44
-
45
- /**
46
- * Base URL for UI images - should be overridden (before init) by
47
- * custom implementations.
48
- * $$$ This is the same directory as the images referenced by relative
49
- * path in the CSS. Would be better to automagically find that path.
50
- */
51
- imagesBaseURL: '/BookReader/images/',
52
-
53
- /** @type {'pow2' | 'integer'} What reduces are valid for getURI. */
54
- reduceSet: 'pow2',
55
-
56
- /**
57
- * Zoom levels
58
- * @type {ReductionFactor[]}
59
- * $$$ provide finer grained zooming, {reduce: 8, autofit: null}, {reduce: 16, autofit: null}
60
- * The autofit code ensures that fit to width and fit to height will be available
61
- */
62
- reductionFactors: [
63
- {reduce: 0.25, autofit: null},
64
- {reduce: 0.5, autofit: null},
65
- {reduce: 1, autofit: null},
66
- {reduce: 2, autofit: null},
67
- {reduce: 3, autofit: null},
68
- {reduce: 4, autofit: null},
69
- {reduce: 6, autofit: null},
70
- ],
71
-
72
- /** Object to hold parameters related to 1up mode */
73
- onePage: {
74
- /** @type {AutoFitValues} */
75
- autofit: 'auto',
76
- },
77
-
78
- /** Object to hold parameters related to 2up mode */
79
- twoPage: {
80
- /** Width of cover */
81
- coverInternalPadding: 0,
82
- /** Padding outside of cover */
83
- coverExternalPadding: 0,
84
- /** Width of book spine $$$ consider sizing based on book length */
85
- bookSpineDivWidth: 64,
86
- /** @type {AutoFitValues} */
87
- autofit: 'auto',
88
- },
89
-
90
- onePageMinBreakpoint: 800,
91
-
92
- bookTitle: '',
93
- /** @type {string} */
94
- bookUrl: null,
95
- /** @type {string} */
96
- bookUrlText: null,
97
- /** @type {string} */
98
- bookUrlTitle: null,
99
- enableBookTitleLink: true,
100
- /**
101
- * @type {string} language in ISO 639-1 (PRIVATE: Will also
102
- * handle language name in English, native name, 639-2/T, or 639-2/B . (archive.org books
103
- * appear to use 639-2/B ? But I don't think that's a guarantee). See
104
- * https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ) */
105
- bookLanguage: null,
106
-
107
- /**
108
- * @type {Array<{label: string, value: *, extraValueClass: string?}>}
109
- * Fields used to populate the info window
110
- * @example [
111
- * {label: 'Title', value: 'Open Library BookReader Presentation'},
112
- * {label: 'Author', value: 'Internet Archive'},
113
- * {label: 'Demo Info', value: 'This demo shows how one could use BookReader with their own content.'},
114
- * ]
115
- **/
116
- metadata: [],
117
- /** @type {string} */
118
- thumbnail: null,
119
- /** @type {string} */
120
- bookUrlMoreInfo: null,
121
-
122
- /** Experimental Controls (eg b/w) */
123
- enableExperimentalControls: false,
124
-
125
- /** CSS selectors */
126
- /** Where BookReader mounts to */
127
- el: '#BookReader',
128
-
129
- /** @type {'lr' | 'rl'} Page progression */
130
- pageProgression: 'lr',
131
-
132
- /** The PPI the book is scanned at **/
133
- ppi: 500,
134
-
135
- /** Should image downloads be blocked */
136
- protected: false,
137
-
138
- /**
139
- * Settings for individual plugins. Note they have to be imported first.
140
- * WIP: Most plugins just put their options anywhere in this global options file,
141
- * but going forward we'll keep them here.
142
- **/
143
- plugins: {
144
- /** @type {Partial<import('../plugins/plugin.archive_analytics.js').ArchiveAnalyticsPlugin['options'>]}*/
145
- archiveAnalytics: null,
146
- /** @type {Partial<import('../plugins/plugin.autoplay.js').AutoplayPlugin['options'>]}*/
147
- autoplay: null,
148
- /** @type {Partial<import('../plugins/plugin.chapters.js').ChaptersPlugin['options']>} */
149
- chapters: null,
150
- /** @type {Partial<import('../plugins/plugin.iiif.js').IiifPlugin['options']>} */
151
- iiif: null,
152
- /** @type {Partial<import('../plugins/plugin.resume.js').ResumePlugin['options']>} */
153
- resume: null,
154
- /** @type {Partial<import('../plugins/search/plugin.search.js').SearchPlugin['options']>} */
155
- search: null,
156
- /** @type {Partial<import('../plugins/plugin.text_selection.js').TextSelectionPlugin['options']>} */
157
- textSelection: null,
158
- /** @type {Partial<import('../plugins/tts/plugin.tts.js').TtsPlugin['options']>} */
159
- tts: null,
160
- },
161
-
162
- /**
163
- * Any variables you want to define. If an option has a StringWithVars type, or
164
- * has something like `{{server}}/foo.com` in its value, these variables replace
165
- * the `{{foo}}`.
166
- * @type { {[var_name: string]: any } }
167
- */
168
- vars: {},
169
-
170
- /**
171
- * @type {Array<[PageData, PageData]|[PageData]>}
172
- * Data is a simple way to populate the bookreader
173
- *
174
- * Example:
175
- * ```
176
- * [
177
- * // Each child is a spread
178
- * [
179
- * {
180
- * width: 123,
181
- * height: 123,
182
- * // Optional: If not provided, include a getPageURI
183
- * uri: 'https://archive.org/image.jpg',
184
- * // Optional: Shown instead of leaf number if present.
185
- * pageNum: '1'
186
- * },
187
- * {width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '2'},
188
- * ]
189
- * ],
190
- * ```
191
- *
192
- * Note if URI is omitted, a custom getPageURI can be provided. This allows the page
193
- * URI to the result of a function, which allows for things such as dynamic
194
- * page scaling.
195
- */
196
- data: [],
197
-
198
- /** @type {import('../plugins/plugin.chapters.js').TocEntry[]} */
199
- table_of_contents: null,
200
-
201
- /**
202
- * Advanced methods for page rendering.
203
- * All option functions have their `this` object set to the BookReader instance.
204
- **/
205
-
206
- /** @type {() => number} */
207
- getNumLeafs: null,
208
- /** @type {(index: number) => number} */
209
- getPageWidth: null,
210
- /** @type {(index: number) => number} */
211
- getPageHeight: null,
212
- /** @type {(index: number, reduce: number, rotate: number) => string} */
213
- getPageURI: null,
214
-
215
- /**
216
- * @type {(img: HTMLImageElement, uri: string) => Promise<void>}
217
- * Render the page URI into the image element. Perform any necessary preloading,
218
- * authentication, etc.
219
- */
220
- renderPageURI(img, uri) {
221
- img.src = uri;
222
- },
223
-
224
- /**
225
- * @type {(index: number) => 'L' | 'R'}
226
- * Return which side, left or right, that a given page should be displayed on
227
- */
228
- getPageSide: null,
229
-
230
- /**
231
- * @type {(pindex: number) => [number, number]}
232
- * This function returns the left and right indices for the user-visible
233
- * spread that contains the given index. The return values may be
234
- * null if there is no facing page or the index is invalid.
235
- */
236
- getSpreadIndices: null,
237
-
238
- /** @type {(index: number) => string} */
239
- getPageNum: null,
240
- /** @type {(index: number) => *} */
241
- getPageProp: null,
242
- /** @type {(index: number) => number} */
243
- leafNumToIndex: null,
244
-
245
- /**
246
- * @type {(frameWidth: number|string, frameHeight: number|string, viewParams) => *}
247
- * Optional: if present, and embed code will be shown in the share dialog
248
- */
249
- getEmbedCode: null,
250
-
251
- controls: {
252
- bookLeft: {
253
- visible: true,
254
- label: 'Flip left',
255
- className: 'book_left',
256
- iconClassName: 'left-arrow',
257
- },
258
- bookRight: {
259
- visible: true,
260
- label: 'Flip right',
261
- className: 'book_right',
262
- iconClassName: 'left-arrow hflip',
263
- },
264
- onePage: {
265
- visible: true,
266
- label: 'One-page view',
267
- className: 'onepg',
268
- iconClassName: 'onepg',
269
- },
270
- twoPage: {
271
- visible: true,
272
- label: 'Two-page view',
273
- className: 'twopg',
274
- iconClassName: 'twopg',
275
- },
276
- thumbnail: {
277
- visible: true,
278
- label: 'Thumbnail view',
279
- className: 'thumb',
280
- iconClassName: 'thumb',
281
- },
282
- viewmode: {
283
- visible: true,
284
- className: 'viewmode',
285
- excludedModes: [],
286
- },
287
- zoomOut: {
288
- visible: true,
289
- label: 'Zoom out',
290
- className: 'zoom_out',
291
- iconClassName: 'magnify',
292
- },
293
- zoomIn: {
294
- visible: true,
295
- label: 'Zoom in',
296
- className: 'zoom_in',
297
- iconClassName: 'magnify plus',
298
- },
299
- fullScreen: {
300
- visible: true,
301
- label: 'Toggle fullscreen',
302
- className: 'full',
303
- iconClassName: 'fullscreen',
304
- },
305
- },
306
-
307
- /**
308
- * @type {Boolean}
309
- * Optional: if true, starts in fullscreen mode
310
- */
311
- startFullscreen: false,
312
-
313
- /**
314
- * @type {Boolean}
315
- * will show logo at fullscreen mode
316
- */
317
- enableFSLogoShortcut: false,
318
-
319
- /**
320
- * @type {Boolean}
321
- * On init, by default, we want to handle resizing bookreader
322
- * when browser window changes size (inc. `orientationchange` event)
323
- * toggle off if you want to handle this outside of bookreader
324
- */
325
- autoResize: true,
326
-
327
- /**
328
- * @type {Boolean}
329
- * On init, by default, we want to use srcSet for images
330
- */
331
- useSrcSet: false,
332
-
333
- /**
334
- * @type {string}
335
- * Path to the image to display when a page is unviewable (i.e. when
336
- * displaying a preview of a book).
337
- *
338
- * Relative to the imagesBaseURL if a relative path is specified.
339
- */
340
- unviewablePageURI: './unviewable_page.png',
341
- };
342
-
343
- /**
344
- * @typedef {'width' | 'height' | 'auto' | 'none'} AutoFitValues
345
- * - width: fill the width of the container
346
- * - height: fill the height of the container
347
- * - auto: fill the width or height of the container, whichever is smaller
348
- * - none: do not autofit
349
- **/
350
-
351
- /**
352
- * @typedef {object} ReductionFactor
353
- * @property {number} reduce
354
- * @property {AutoFitValues} [autofit] If set, the corresponding reduction factors
355
- * are what will be used when the user tries to autofit by width/height.
356
- */
357
-
358
- /**
359
- * @typedef {Object} PageData
360
- * @property {number} width
361
- * @property {number} height
362
- * @property {string} [uri] If not provided, include a getPageURI
363
- * @property {PageNumString} [pageNum] Shown instead of leaf number if present
364
- * @property {LeafNum} [leafNum] Sometimes specified in Internet Archive books
365
- * @property {number} [ppi] The resolution of the page if different from {@see BookReaderOptions.ppi}
366
- * @property {'L' | 'R'} [pageSide] PRIVATE; computed automatically
367
- * @property {boolean} [viewable=true] Set false if page is not viewable. Displays a dummy preview image.
368
- * @property {number} [unviewablesStart] PRIVATE; index where the chunk of unviewable pages started
369
- *
370
- * Note if URI is omitted, a custom getPageURI can be provided. This allows the page
371
- * URI to the result of a function, which allows for things such as dynamic
372
- * page scaling.
373
- */
374
-
375
- /** @typedef {typeof DEFAULT_OPTIONS} BookReaderOptions */
376
-
377
- /**
378
- * Thrown when an error occurs while parsing options.
379
- * Potentially recoverable and non-halting.
380
- */
381
- export class OptionsParseError extends Error {
382
- }
@@ -1,44 +0,0 @@
1
- // @ts-check
2
- import { debounce } from '../utils';
3
-
4
- /**
5
- * Computing these things repeatedly is expensive (the browser needs to
6
- * do a lot of computations/redrawing to make sure these are correct),
7
- * so we store them here, and only recompute them when necessary:
8
- * - window resize could have cause the container to change size
9
- * - zoom could have cause scrollbars to appear/disappear, changing
10
- * the client size.
11
- */
12
- export class HTMLDimensionsCacher {
13
- clientWidth = 100;
14
- clientHeight = 100;
15
-
16
- boundingClientRect = { top: 0, left: 0 };
17
-
18
- /**
19
- * @param {HTMLElement} element
20
- */
21
- constructor(element) {
22
- /** @type {HTMLElement} */
23
- this.element = element;
24
- }
25
-
26
- updateClientSizes = () => {
27
- const bc = this.element.getBoundingClientRect();
28
- this.clientWidth = this.element.clientWidth;
29
- this.clientHeight = this.element.clientHeight;
30
- this.boundingClientRect.top = bc.top;
31
- this.boundingClientRect.left = bc.left;
32
- }
33
- debouncedUpdateClientSizes = debounce(this.updateClientSizes, 150, false);
34
-
35
- /** @param {EventTarget} win */
36
- attachResizeListener(win = window) {
37
- win.addEventListener('resize', this.debouncedUpdateClientSizes);
38
- }
39
-
40
- /** @param {EventTarget} win */
41
- detachResizeListener(win = window) {
42
- win.removeEventListener('resize', this.debouncedUpdateClientSizes);
43
- }
44
- }
@@ -1,31 +0,0 @@
1
- /** Adds a class while the given element is experiencing scrolling */
2
- export class ScrollClassAdder {
3
- /**
4
- * @param {HTMLElement} element
5
- * @param {string} className
6
- */
7
- constructor(element, className) {
8
- /** @type {HTMLElement} */
9
- this.element = element;
10
- /** @type {string} */
11
- this.className = className;
12
- this.timeout = null;
13
- }
14
-
15
- attach() {
16
- this.element.addEventListener('scroll', this.onScroll);
17
- }
18
-
19
- detach() {
20
- this.element.removeEventListener('scroll', this.onScroll);
21
- }
22
-
23
- onScroll = () => {
24
- this.element.classList.add(this.className);
25
- clearTimeout(this.timeout);
26
- // TODO: Also remove class on mousemove, touch, click, etc.
27
- this.timeout = setTimeout(() => {
28
- this.element.classList.remove(this.className);
29
- }, 600);
30
- }
31
- }
@@ -1,45 +0,0 @@
1
- // @ts-check
2
- export class SelectionObserver {
3
- selecting = false;
4
- startedInSelector = false;
5
- /** @type {HTMLElement} */
6
- target = null;
7
-
8
- /**
9
- * @param {string} selector
10
- * @param {function('started' | 'cleared', HTMLElement): any} handler
11
- */
12
- constructor(selector, handler) {
13
- this.selector = selector;
14
- this.handler = handler;
15
- }
16
-
17
- attach() {
18
- // We can't just use selectstart, because safari on iOS just
19
- // randomly decides when to fire it 😤
20
- // document.addEventListener("selectstart", this._onSelectStart);
21
- // This has to be on document :/
22
- document.addEventListener("selectionchange", this._onSelectionChange);
23
- }
24
-
25
- detach() {
26
- document.removeEventListener("selectionchange", this._onSelectionChange);
27
- }
28
-
29
- _onSelectionChange = () => {
30
- const sel = window.getSelection();
31
-
32
- if (!this.selecting && sel.toString()) {
33
- const target = $(sel.anchorNode).closest(this.selector)[0];
34
- if (!target) return;
35
- this.target = target;
36
- this.selecting = true;
37
- this.handler('started', this.target);
38
- }
39
-
40
- if (this.selecting && (sel.isCollapsed || !sel.toString() || !$(sel.anchorNode).closest(this.selector)[0])) {
41
- this.selecting = false;
42
- this.handler('cleared', this.target);
43
- }
44
- };
45
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Exposes a function from one class (FromClass) to another (ToClass), in such a way
3
- * that if the ToClass's method is overridden, the FromClass's method is also overridden.
4
- * WARNING: This modifies FromClass' prototype! So FromClasses cannot be shared between
5
- * different ToClasses.
6
- * @param {new () => TFrom} FromClass the class to get the method from
7
- * @param {keyof TFrom} fromMethod the method's name in FromClass
8
- * @param {function(TFrom): TTo} fromTransform how to get the TTo `this` to use when setting the method on TFrom
9
- * @param {new () => TTo} ToClass the class to add the method to
10
- * @param {string} toMethod the name of the method to add to TTo (likely will be equal to fromMethod)
11
- * @param {function(TTo): TFrom} toTransform how to get the TFrom this to use when calling the new method
12
- * @template TFrom type of FromClass for type-checking/autocomplete
13
- * @template TTo type of ToClass for type-checking/autocomplete
14
- */
15
- export function exposeOverrideable(FromClass, fromMethod, fromTransform, ToClass, toMethod, toTransform) {
16
- // Wrapper function needed to "capture" the current version of fromMethod
17
- let wrapper = (fn => {
18
- return function () {
19
- return fn.apply(toTransform(this), arguments);
20
- };
21
- })(FromClass.prototype[fromMethod]);
22
-
23
- Object.defineProperty(ToClass.prototype, toMethod, {
24
- get() { return wrapper; },
25
- set(overrideFn) {
26
- // overrideFn expects `this` to be ToClass, so ensure as such
27
- // But we can also call this method from FromClass; need to ensure
28
- // it's always called with a ToClass
29
- FromClass.prototype[fromMethod] = function () {
30
- const newThis = this instanceof FromClass ? fromTransform(this) : this;
31
- return overrideFn.apply(newThis, arguments);
32
- };
33
- wrapper = overrideFn;
34
- },
35
- });
36
- }