@internetarchive/bookreader 5.0.0-94 → 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 (181) hide show
  1. package/.github/workflows/npm-publish.yml +2 -12
  2. package/CHANGELOG.md +7 -0
  3. package/README.md +0 -2
  4. package/package.json +1 -1
  5. package/scripts/version.js +0 -3
  6. package/BookReader/BookReader.css +0 -2251
  7. package/BookReader/BookReader.js +0 -3
  8. package/BookReader/BookReader.js.LICENSE.txt +0 -72
  9. package/BookReader/BookReader.js.map +0 -1
  10. package/BookReader/ia-bookreader-bundle.js +0 -1782
  11. package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +0 -7
  12. package/BookReader/ia-bookreader-bundle.js.map +0 -1
  13. package/BookReader/icons/1up.svg +0 -1
  14. package/BookReader/icons/2up.svg +0 -1
  15. package/BookReader/icons/advance.svg +0 -3
  16. package/BookReader/icons/chevron-right.svg +0 -1
  17. package/BookReader/icons/close-circle-dark.svg +0 -1
  18. package/BookReader/icons/close-circle.svg +0 -1
  19. package/BookReader/icons/fullscreen.svg +0 -1
  20. package/BookReader/icons/fullscreen_exit.svg +0 -1
  21. package/BookReader/icons/hamburger.svg +0 -1
  22. package/BookReader/icons/left-arrow.svg +0 -1
  23. package/BookReader/icons/magnify-minus.svg +0 -1
  24. package/BookReader/icons/magnify-plus.svg +0 -1
  25. package/BookReader/icons/magnify.svg +0 -1
  26. package/BookReader/icons/pause.svg +0 -1
  27. package/BookReader/icons/play.svg +0 -1
  28. package/BookReader/icons/playback-speed.svg +0 -1
  29. package/BookReader/icons/read-aloud.svg +0 -1
  30. package/BookReader/icons/review.svg +0 -3
  31. package/BookReader/icons/thumbnails.svg +0 -1
  32. package/BookReader/icons/voice.svg +0 -1
  33. package/BookReader/icons/volume-full.svg +0 -1
  34. package/BookReader/images/BRicons.png +0 -0
  35. package/BookReader/images/BRicons.svg +0 -5
  36. package/BookReader/images/BRicons_ia.png +0 -0
  37. package/BookReader/images/back_pages.png +0 -0
  38. package/BookReader/images/book_bottom_icon.png +0 -0
  39. package/BookReader/images/book_down_icon.png +0 -0
  40. package/BookReader/images/book_left_icon.png +0 -0
  41. package/BookReader/images/book_leftmost_icon.png +0 -0
  42. package/BookReader/images/book_right_icon.png +0 -0
  43. package/BookReader/images/book_rightmost_icon.png +0 -0
  44. package/BookReader/images/book_top_icon.png +0 -0
  45. package/BookReader/images/book_up_icon.png +0 -0
  46. package/BookReader/images/books_graphic.svg +0 -1
  47. package/BookReader/images/booksplit.png +0 -0
  48. package/BookReader/images/control_pause_icon.png +0 -0
  49. package/BookReader/images/control_play_icon.png +0 -0
  50. package/BookReader/images/embed_icon.png +0 -0
  51. package/BookReader/images/hypothesis.ico +0 -0
  52. package/BookReader/images/icon-home-ia.png +0 -0
  53. package/BookReader/images/icon_OL-logo-xs.png +0 -0
  54. package/BookReader/images/icon_alert-xs.png +0 -0
  55. package/BookReader/images/icon_book.svg +0 -1
  56. package/BookReader/images/icon_bookmark.svg +0 -1
  57. package/BookReader/images/icon_close-pop.png +0 -0
  58. package/BookReader/images/icon_download.png +0 -0
  59. package/BookReader/images/icon_gear.svg +0 -1
  60. package/BookReader/images/icon_hamburger.svg +0 -1
  61. package/BookReader/images/icon_home.png +0 -0
  62. package/BookReader/images/icon_home.svg +0 -1
  63. package/BookReader/images/icon_home_ia.png +0 -0
  64. package/BookReader/images/icon_indicator.png +0 -0
  65. package/BookReader/images/icon_info.svg +0 -1
  66. package/BookReader/images/icon_one_page.svg +0 -1
  67. package/BookReader/images/icon_pause.svg +0 -1
  68. package/BookReader/images/icon_play.svg +0 -1
  69. package/BookReader/images/icon_playback-rate.svg +0 -1
  70. package/BookReader/images/icon_return.png +0 -0
  71. package/BookReader/images/icon_search_button.svg +0 -1
  72. package/BookReader/images/icon_share.svg +0 -1
  73. package/BookReader/images/icon_skip-ahead.svg +0 -1
  74. package/BookReader/images/icon_skip-back.svg +0 -2
  75. package/BookReader/images/icon_speaker.svg +0 -1
  76. package/BookReader/images/icon_speaker_open.svg +0 -1
  77. package/BookReader/images/icon_thumbnails.svg +0 -1
  78. package/BookReader/images/icon_toc.svg +0 -1
  79. package/BookReader/images/icon_two_pages.svg +0 -1
  80. package/BookReader/images/icon_zoomer.png +0 -0
  81. package/BookReader/images/loading.gif +0 -0
  82. package/BookReader/images/logo_icon.png +0 -0
  83. package/BookReader/images/marker_chap-off.png +0 -0
  84. package/BookReader/images/marker_chap-off.svg +0 -1
  85. package/BookReader/images/marker_chap-off_ia.png +0 -0
  86. package/BookReader/images/marker_chap-on.png +0 -0
  87. package/BookReader/images/marker_chap-on.svg +0 -1
  88. package/BookReader/images/marker_srch-on.svg +0 -1
  89. package/BookReader/images/marker_srchchap-off.png +0 -0
  90. package/BookReader/images/marker_srchchap-on.png +0 -0
  91. package/BookReader/images/nav_control-dn.png +0 -0
  92. package/BookReader/images/nav_control-dn_ia.png +0 -0
  93. package/BookReader/images/nav_control-up.png +0 -0
  94. package/BookReader/images/nav_control-up_ia.png +0 -0
  95. package/BookReader/images/nav_control.png +0 -0
  96. package/BookReader/images/one_page_mode_icon.png +0 -0
  97. package/BookReader/images/paper-badge.png +0 -0
  98. package/BookReader/images/print_icon.png +0 -0
  99. package/BookReader/images/progressbar.gif +0 -0
  100. package/BookReader/images/right_edges.png +0 -0
  101. package/BookReader/images/slider.png +0 -0
  102. package/BookReader/images/slider_ia.png +0 -0
  103. package/BookReader/images/thumbnail_mode_icon.png +0 -0
  104. package/BookReader/images/transparent.png +0 -0
  105. package/BookReader/images/two_page_mode_icon.png +0 -0
  106. package/BookReader/images/unviewable_page.png +0 -0
  107. package/BookReader/images/zoom_in_icon.png +0 -0
  108. package/BookReader/images/zoom_out_icon.png +0 -0
  109. package/BookReader/jquery-3.js +0 -2
  110. package/BookReader/jquery-3.js.LICENSE.txt +0 -24
  111. package/BookReader/plugins/plugin.archive_analytics.js +0 -2
  112. package/BookReader/plugins/plugin.archive_analytics.js.map +0 -1
  113. package/BookReader/plugins/plugin.autoplay.js +0 -2
  114. package/BookReader/plugins/plugin.autoplay.js.map +0 -1
  115. package/BookReader/plugins/plugin.chapters.js +0 -26
  116. package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +0 -1
  117. package/BookReader/plugins/plugin.chapters.js.map +0 -1
  118. package/BookReader/plugins/plugin.experiments.js +0 -3
  119. package/BookReader/plugins/plugin.experiments.js.LICENSE.txt +0 -1
  120. package/BookReader/plugins/plugin.experiments.js.map +0 -1
  121. package/BookReader/plugins/plugin.iframe.js +0 -2
  122. package/BookReader/plugins/plugin.iframe.js.map +0 -1
  123. package/BookReader/plugins/plugin.iiif.js +0 -2
  124. package/BookReader/plugins/plugin.iiif.js.map +0 -1
  125. package/BookReader/plugins/plugin.resume.js +0 -2
  126. package/BookReader/plugins/plugin.resume.js.map +0 -1
  127. package/BookReader/plugins/plugin.search.js +0 -3
  128. package/BookReader/plugins/plugin.search.js.LICENSE.txt +0 -1
  129. package/BookReader/plugins/plugin.search.js.map +0 -1
  130. package/BookReader/plugins/plugin.text_selection.js +0 -3
  131. package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +0 -1
  132. package/BookReader/plugins/plugin.text_selection.js.map +0 -1
  133. package/BookReader/plugins/plugin.tts.js +0 -3
  134. package/BookReader/plugins/plugin.tts.js.LICENSE.txt +0 -29
  135. package/BookReader/plugins/plugin.tts.js.map +0 -1
  136. package/BookReader/plugins/plugin.url.js +0 -2
  137. package/BookReader/plugins/plugin.url.js.map +0 -1
  138. package/BookReader/plugins/plugin.vendor-fullscreen.js +0 -2
  139. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +0 -1
  140. package/BookReader/webcomponents-bundle.js +0 -3
  141. package/BookReader/webcomponents-bundle.js.LICENSE.txt +0 -9
  142. package/BookReader/webcomponents-bundle.js.map +0 -1
  143. package/src/BookReader/BookModel.js +0 -564
  144. package/src/BookReader/DragScrollable.js +0 -233
  145. package/src/BookReader/ImageCache.js +0 -149
  146. package/src/BookReader/Mode1Up.js +0 -110
  147. package/src/BookReader/Mode1UpLit.js +0 -388
  148. package/src/BookReader/Mode2Up.js +0 -107
  149. package/src/BookReader/Mode2UpLit.js +0 -777
  150. package/src/BookReader/ModeCoordinateSpace.js +0 -29
  151. package/src/BookReader/ModeSmoothZoom.js +0 -312
  152. package/src/BookReader/ModeThumb.js +0 -344
  153. package/src/BookReader/Navbar/Navbar.js +0 -355
  154. package/src/BookReader/PageContainer.js +0 -172
  155. package/src/BookReader/ReduceSet.js +0 -26
  156. package/src/BookReader/Toolbar/Toolbar.js +0 -362
  157. package/src/BookReader/events.js +0 -19
  158. package/src/BookReader/options.js +0 -387
  159. package/src/BookReader/utils/HTMLDimensionsCacher.js +0 -44
  160. package/src/BookReader/utils/ScrollClassAdder.js +0 -31
  161. package/src/BookReader/utils/SelectionObserver.js +0 -45
  162. package/src/BookReader/utils/classes.js +0 -36
  163. package/src/BookReader/utils.js +0 -313
  164. package/tests/jest/BookReader/BookModel.test.js +0 -372
  165. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +0 -263
  166. package/tests/jest/BookReader/ImageCache.test.js +0 -150
  167. package/tests/jest/BookReader/Mode1UpLit.test.js +0 -73
  168. package/tests/jest/BookReader/Mode2Up.test.js +0 -98
  169. package/tests/jest/BookReader/Mode2UpLit.test.js +0 -190
  170. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +0 -16
  171. package/tests/jest/BookReader/ModeSmoothZoom.test.js +0 -218
  172. package/tests/jest/BookReader/ModeThumb.test.js +0 -71
  173. package/tests/jest/BookReader/Navbar/Navbar.test.js +0 -182
  174. package/tests/jest/BookReader/PageContainer.test.js +0 -249
  175. package/tests/jest/BookReader/ReduceSet.test.js +0 -38
  176. package/tests/jest/BookReader/Toolbar/Toolbar.test.js +0 -26
  177. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +0 -59
  178. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +0 -49
  179. package/tests/jest/BookReader/utils/SelectionObserver.test.js +0 -57
  180. package/tests/jest/BookReader/utils/classes.test.js +0 -88
  181. package/tests/jest/BookReader/utils.test.js +0 -250
@@ -1,387 +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} A globally unique URI for the book. This is used to
102
- * save data like annotations the user makes to the book.
103
- */
104
- bookUri: null,
105
- /**
106
- * @type {string} language in ISO 639-1 (PRIVATE: Will also
107
- * handle language name in English, native name, 639-2/T, or 639-2/B . (archive.org books
108
- * appear to use 639-2/B ? But I don't think that's a guarantee). See
109
- * https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ) */
110
- bookLanguage: null,
111
-
112
- /**
113
- * @type {Array<{label: string, value: *, extraValueClass: string?}>}
114
- * Fields used to populate the info window
115
- * @example [
116
- * {label: 'Title', value: 'Open Library BookReader Presentation'},
117
- * {label: 'Author', value: 'Internet Archive'},
118
- * {label: 'Demo Info', value: 'This demo shows how one could use BookReader with their own content.'},
119
- * ]
120
- **/
121
- metadata: [],
122
- /** @type {string} */
123
- thumbnail: null,
124
- /** @type {string} */
125
- bookUrlMoreInfo: null,
126
-
127
- /** Experimental Controls (eg b/w) */
128
- enableExperimentalControls: false,
129
-
130
- /** CSS selectors */
131
- /** Where BookReader mounts to */
132
- el: '#BookReader',
133
-
134
- /** @type {'lr' | 'rl'} Page progression */
135
- pageProgression: 'lr',
136
-
137
- /** The PPI the book is scanned at **/
138
- ppi: 500,
139
-
140
- /** Should image downloads be blocked */
141
- protected: false,
142
-
143
- /**
144
- * Settings for individual plugins. Note they have to be imported first.
145
- * WIP: Most plugins just put their options anywhere in this global options file,
146
- * but going forward we'll keep them here.
147
- **/
148
- plugins: {
149
- /** @type {Partial<import('../plugins/plugin.archive_analytics.js').ArchiveAnalyticsPlugin['options'>]}*/
150
- archiveAnalytics: null,
151
- /** @type {Partial<import('../plugins/plugin.autoplay.js').AutoplayPlugin['options'>]}*/
152
- autoplay: null,
153
- /** @type {Partial<import('../plugins/plugin.chapters.js').ChaptersPlugin['options']>} */
154
- chapters: null,
155
- /** @type {Partial<import('../plugins/plugin.iiif.js').IiifPlugin['options']>} */
156
- iiif: null,
157
- /** @type {Partial<import('../plugins/plugin.resume.js').ResumePlugin['options']>} */
158
- resume: null,
159
- /** @type {Partial<import('../plugins/search/plugin.search.js').SearchPlugin['options']>} */
160
- search: null,
161
- /** @type {Partial<import('../plugins/plugin.text_selection.js').TextSelectionPlugin['options']>} */
162
- textSelection: null,
163
- /** @type {Partial<import('../plugins/tts/plugin.tts.js').TtsPlugin['options']>} */
164
- tts: null,
165
- },
166
-
167
- /**
168
- * Any variables you want to define. If an option has a StringWithVars type, or
169
- * has something like `{{server}}/foo.com` in its value, these variables replace
170
- * the `{{foo}}`.
171
- * @type { {[var_name: string]: any } }
172
- */
173
- vars: {},
174
-
175
- /**
176
- * @type {Array<[PageData, PageData]|[PageData]>}
177
- * Data is a simple way to populate the bookreader
178
- *
179
- * Example:
180
- * ```
181
- * [
182
- * // Each child is a spread
183
- * [
184
- * {
185
- * width: 123,
186
- * height: 123,
187
- * // Optional: If not provided, include a getPageURI
188
- * uri: 'https://archive.org/image.jpg',
189
- * // Optional: Shown instead of leaf number if present.
190
- * pageNum: '1'
191
- * },
192
- * {width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '2'},
193
- * ]
194
- * ],
195
- * ```
196
- *
197
- * Note if URI is omitted, a custom getPageURI can be provided. This allows the page
198
- * URI to the result of a function, which allows for things such as dynamic
199
- * page scaling.
200
- */
201
- data: [],
202
-
203
- /** @type {import('../plugins/plugin.chapters.js').TocEntry[]} */
204
- table_of_contents: null,
205
-
206
- /**
207
- * Advanced methods for page rendering.
208
- * All option functions have their `this` object set to the BookReader instance.
209
- **/
210
-
211
- /** @type {() => number} */
212
- getNumLeafs: null,
213
- /** @type {(index: number) => number} */
214
- getPageWidth: null,
215
- /** @type {(index: number) => number} */
216
- getPageHeight: null,
217
- /** @type {(index: number, reduce: number, rotate: number) => string} */
218
- getPageURI: null,
219
-
220
- /**
221
- * @type {(img: HTMLImageElement, uri: string) => Promise<void>}
222
- * Render the page URI into the image element. Perform any necessary preloading,
223
- * authentication, etc.
224
- */
225
- renderPageURI(img, uri) {
226
- img.src = uri;
227
- },
228
-
229
- /**
230
- * @type {(index: number) => 'L' | 'R'}
231
- * Return which side, left or right, that a given page should be displayed on
232
- */
233
- getPageSide: null,
234
-
235
- /**
236
- * @type {(pindex: number) => [number, number]}
237
- * This function returns the left and right indices for the user-visible
238
- * spread that contains the given index. The return values may be
239
- * null if there is no facing page or the index is invalid.
240
- */
241
- getSpreadIndices: null,
242
-
243
- /** @type {(index: number) => string} */
244
- getPageNum: null,
245
- /** @type {(index: number) => *} */
246
- getPageProp: null,
247
- /** @type {(index: number) => number} */
248
- leafNumToIndex: null,
249
-
250
- /**
251
- * @type {(frameWidth: number|string, frameHeight: number|string, viewParams) => *}
252
- * Optional: if present, and embed code will be shown in the share dialog
253
- */
254
- getEmbedCode: null,
255
-
256
- controls: {
257
- bookLeft: {
258
- visible: true,
259
- label: 'Flip left',
260
- className: 'book_left',
261
- iconClassName: 'left-arrow',
262
- },
263
- bookRight: {
264
- visible: true,
265
- label: 'Flip right',
266
- className: 'book_right',
267
- iconClassName: 'left-arrow hflip',
268
- },
269
- onePage: {
270
- visible: true,
271
- label: 'One-page view',
272
- className: 'onepg',
273
- iconClassName: 'onepg',
274
- },
275
- twoPage: {
276
- visible: true,
277
- label: 'Two-page view',
278
- className: 'twopg',
279
- iconClassName: 'twopg',
280
- },
281
- thumbnail: {
282
- visible: true,
283
- label: 'Thumbnail view',
284
- className: 'thumb',
285
- iconClassName: 'thumb',
286
- },
287
- viewmode: {
288
- visible: true,
289
- className: 'viewmode',
290
- excludedModes: [],
291
- },
292
- zoomOut: {
293
- visible: true,
294
- label: 'Zoom out',
295
- className: 'zoom_out',
296
- iconClassName: 'magnify',
297
- },
298
- zoomIn: {
299
- visible: true,
300
- label: 'Zoom in',
301
- className: 'zoom_in',
302
- iconClassName: 'magnify plus',
303
- },
304
- fullScreen: {
305
- visible: true,
306
- label: 'Toggle fullscreen',
307
- className: 'full',
308
- iconClassName: 'fullscreen',
309
- },
310
- },
311
-
312
- /**
313
- * @type {Boolean}
314
- * Optional: if true, starts in fullscreen mode
315
- */
316
- startFullscreen: false,
317
-
318
- /**
319
- * @type {Boolean}
320
- * will show logo at fullscreen mode
321
- */
322
- enableFSLogoShortcut: false,
323
-
324
- /**
325
- * @type {Boolean}
326
- * On init, by default, we want to handle resizing bookreader
327
- * when browser window changes size (inc. `orientationchange` event)
328
- * toggle off if you want to handle this outside of bookreader
329
- */
330
- autoResize: true,
331
-
332
- /**
333
- * @type {Boolean}
334
- * On init, by default, we want to use srcSet for images
335
- */
336
- useSrcSet: false,
337
-
338
- /**
339
- * @type {string}
340
- * Path to the image to display when a page is unviewable (i.e. when
341
- * displaying a preview of a book).
342
- *
343
- * Relative to the imagesBaseURL if a relative path is specified.
344
- */
345
- unviewablePageURI: './unviewable_page.png',
346
- };
347
-
348
- /**
349
- * @typedef {'width' | 'height' | 'auto' | 'none'} AutoFitValues
350
- * - width: fill the width of the container
351
- * - height: fill the height of the container
352
- * - auto: fill the width or height of the container, whichever is smaller
353
- * - none: do not autofit
354
- **/
355
-
356
- /**
357
- * @typedef {object} ReductionFactor
358
- * @property {number} reduce
359
- * @property {AutoFitValues} [autofit] If set, the corresponding reduction factors
360
- * are what will be used when the user tries to autofit by width/height.
361
- */
362
-
363
- /**
364
- * @typedef {Object} PageData
365
- * @property {number} width
366
- * @property {number} height
367
- * @property {string} [uri] If not provided, include a getPageURI
368
- * @property {PageNumString} [pageNum] Shown instead of leaf number if present
369
- * @property {LeafNum} [leafNum] Sometimes specified in Internet Archive books
370
- * @property {number} [ppi] The resolution of the page if different from {@see BookReaderOptions.ppi}
371
- * @property {'L' | 'R'} [pageSide] PRIVATE; computed automatically
372
- * @property {boolean} [viewable=true] Set false if page is not viewable. Displays a dummy preview image.
373
- * @property {number} [unviewablesStart] PRIVATE; index where the chunk of unviewable pages started
374
- *
375
- * Note if URI is omitted, a custom getPageURI can be provided. This allows the page
376
- * URI to the result of a function, which allows for things such as dynamic
377
- * page scaling.
378
- */
379
-
380
- /** @typedef {typeof DEFAULT_OPTIONS} BookReaderOptions */
381
-
382
- /**
383
- * Thrown when an error occurs while parsing options.
384
- * Potentially recoverable and non-halting.
385
- */
386
- export class OptionsParseError extends Error {
387
- }
@@ -1,44 +0,0 @@
1
- // @ts-check
2
- import { debounce } from '../utils.js';
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
- }