@internetarchive/bookreader 5.0.0-88-alpha.8 → 5.0.0-88-alpha.10

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 (182) hide show
  1. package/dist/esm/BookNavigator/assets/bookmark-colors.js +4 -0
  2. package/dist/esm/BookNavigator/assets/button-base.js +4 -0
  3. package/dist/esm/BookNavigator/assets/ia-logo.js +4 -0
  4. package/dist/esm/BookNavigator/assets/icon_checkmark.js +8 -0
  5. package/dist/esm/BookNavigator/assets/icon_close.js +4 -0
  6. package/dist/esm/BookNavigator/book-navigator.js +612 -0
  7. package/dist/esm/BookNavigator/bookmarks/bookmark-button.js +35 -0
  8. package/dist/esm/BookNavigator/bookmarks/bookmark-edit.js +78 -0
  9. package/dist/esm/BookNavigator/bookmarks/bookmarks-list.js +160 -0
  10. package/dist/esm/BookNavigator/bookmarks/bookmarks-loginCTA.js +24 -0
  11. package/dist/esm/BookNavigator/bookmarks/bookmarks-provider.js +55 -0
  12. package/dist/esm/BookNavigator/bookmarks/ia-bookmarks.js +521 -0
  13. package/dist/esm/BookNavigator/delete-modal-actions.js +29 -0
  14. package/dist/esm/BookNavigator/downloads/downloads-provider.js +84 -0
  15. package/dist/esm/BookNavigator/downloads/downloads.js +69 -0
  16. package/dist/esm/BookNavigator/search/search-provider.js +238 -0
  17. package/dist/esm/BookNavigator/search/search-results.js +161 -0
  18. package/dist/esm/BookNavigator/sharing.js +26 -0
  19. package/dist/esm/BookNavigator/viewable-files.js +94 -0
  20. package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments-provider.js +83 -0
  21. package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments.js +131 -0
  22. package/dist/esm/BookReader/BookModel.js +575 -0
  23. package/dist/esm/BookReader/DragScrollable.js +224 -0
  24. package/dist/esm/BookReader/ImageCache.js +122 -0
  25. package/dist/esm/BookReader/Mode1Up.js +114 -0
  26. package/dist/esm/BookReader/Mode1UpLit.js +579 -0
  27. package/dist/esm/BookReader/Mode2Up.js +106 -0
  28. package/dist/esm/BookReader/Mode2UpLit.js +1020 -0
  29. package/dist/esm/BookReader/ModeCoordinateSpace.js +28 -0
  30. package/dist/esm/BookReader/ModeSmoothZoom.js +318 -0
  31. package/dist/esm/BookReader/ModeThumb.js +366 -0
  32. package/dist/esm/BookReader/Navbar/Navbar.js +253 -0
  33. package/dist/esm/BookReader/PageContainer.js +165 -0
  34. package/dist/esm/BookReader/ReduceSet.js +27 -0
  35. package/dist/esm/BookReader/Toolbar/Toolbar.js +242 -0
  36. package/dist/esm/BookReader/events.js +20 -0
  37. package/dist/esm/BookReader/options.js +331 -0
  38. package/dist/esm/BookReader/utils/HTMLDimensionsCacher.js +48 -0
  39. package/dist/esm/BookReader/utils/ScrollClassAdder.js +31 -0
  40. package/dist/esm/BookReader/utils/SelectionObserver.js +42 -0
  41. package/dist/esm/BookReader/utils/classes.js +37 -0
  42. package/dist/esm/BookReader/utils.js +315 -0
  43. package/dist/esm/BookReader.js +1827 -0
  44. package/dist/esm/assets/icons/1up.svg +12 -0
  45. package/dist/esm/assets/icons/2up.svg +15 -0
  46. package/dist/esm/assets/icons/advance.svg +26 -0
  47. package/dist/esm/assets/icons/chevron-right.svg +1 -0
  48. package/dist/esm/assets/icons/close-circle-dark.svg +1 -0
  49. package/dist/esm/assets/icons/close-circle.svg +1 -0
  50. package/dist/esm/assets/icons/fullscreen.svg +17 -0
  51. package/dist/esm/assets/icons/fullscreen_exit.svg +17 -0
  52. package/dist/esm/assets/icons/hamburger.svg +15 -0
  53. package/dist/esm/assets/icons/left-arrow.svg +12 -0
  54. package/dist/esm/assets/icons/magnify-minus.svg +12 -0
  55. package/dist/esm/assets/icons/magnify-plus.svg +13 -0
  56. package/dist/esm/assets/icons/magnify.svg +15 -0
  57. package/dist/esm/assets/icons/pause.svg +23 -0
  58. package/dist/esm/assets/icons/play.svg +22 -0
  59. package/dist/esm/assets/icons/playback-speed.svg +34 -0
  60. package/dist/esm/assets/icons/read-aloud.svg +22 -0
  61. package/dist/esm/assets/icons/review.svg +22 -0
  62. package/dist/esm/assets/icons/thumbnails.svg +17 -0
  63. package/dist/esm/assets/icons/voice.svg +1 -0
  64. package/dist/esm/assets/icons/volume-full.svg +22 -0
  65. package/dist/esm/assets/images/BRicons.png +0 -0
  66. package/dist/esm/assets/images/BRicons.svg +94 -0
  67. package/dist/esm/assets/images/BRicons_ia.png +0 -0
  68. package/dist/esm/assets/images/back_pages.png +0 -0
  69. package/dist/esm/assets/images/book_bottom_icon.png +0 -0
  70. package/dist/esm/assets/images/book_down_icon.png +0 -0
  71. package/dist/esm/assets/images/book_left_icon.png +0 -0
  72. package/dist/esm/assets/images/book_leftmost_icon.png +0 -0
  73. package/dist/esm/assets/images/book_right_icon.png +0 -0
  74. package/dist/esm/assets/images/book_rightmost_icon.png +0 -0
  75. package/dist/esm/assets/images/book_top_icon.png +0 -0
  76. package/dist/esm/assets/images/book_up_icon.png +0 -0
  77. package/dist/esm/assets/images/books_graphic.svg +177 -0
  78. package/dist/esm/assets/images/booksplit.png +0 -0
  79. package/dist/esm/assets/images/control_pause_icon.png +0 -0
  80. package/dist/esm/assets/images/control_play_icon.png +0 -0
  81. package/dist/esm/assets/images/embed_icon.png +0 -0
  82. package/dist/esm/assets/images/icon-home-ia.png +0 -0
  83. package/dist/esm/assets/images/icon_OL-logo-xs.png +0 -0
  84. package/dist/esm/assets/images/icon_alert-xs.png +0 -0
  85. package/dist/esm/assets/images/icon_book.svg +12 -0
  86. package/dist/esm/assets/images/icon_bookmark.svg +12 -0
  87. package/dist/esm/assets/images/icon_close-pop.png +0 -0
  88. package/dist/esm/assets/images/icon_download.png +0 -0
  89. package/dist/esm/assets/images/icon_gear.svg +14 -0
  90. package/dist/esm/assets/images/icon_hamburger.svg +20 -0
  91. package/dist/esm/assets/images/icon_home.png +0 -0
  92. package/dist/esm/assets/images/icon_home.svg +21 -0
  93. package/dist/esm/assets/images/icon_home_ia.png +0 -0
  94. package/dist/esm/assets/images/icon_indicator.png +0 -0
  95. package/dist/esm/assets/images/icon_info.svg +11 -0
  96. package/dist/esm/assets/images/icon_one_page.svg +8 -0
  97. package/dist/esm/assets/images/icon_pause.svg +1 -0
  98. package/dist/esm/assets/images/icon_play.svg +1 -0
  99. package/dist/esm/assets/images/icon_playback-rate.svg +15 -0
  100. package/dist/esm/assets/images/icon_return.png +0 -0
  101. package/dist/esm/assets/images/icon_search_button.svg +8 -0
  102. package/dist/esm/assets/images/icon_share.svg +9 -0
  103. package/dist/esm/assets/images/icon_skip-ahead.svg +6 -0
  104. package/dist/esm/assets/images/icon_skip-back.svg +13 -0
  105. package/dist/esm/assets/images/icon_speaker.svg +18 -0
  106. package/dist/esm/assets/images/icon_speaker_open.svg +10 -0
  107. package/dist/esm/assets/images/icon_thumbnails.svg +12 -0
  108. package/dist/esm/assets/images/icon_toc.svg +5 -0
  109. package/dist/esm/assets/images/icon_two_pages.svg +9 -0
  110. package/dist/esm/assets/images/icon_zoomer.png +0 -0
  111. package/dist/esm/assets/images/loading.gif +0 -0
  112. package/dist/esm/assets/images/logo_icon.png +0 -0
  113. package/dist/esm/assets/images/marker_chap-off.png +0 -0
  114. package/dist/esm/assets/images/marker_chap-off.svg +11 -0
  115. package/dist/esm/assets/images/marker_chap-off_ia.png +0 -0
  116. package/dist/esm/assets/images/marker_chap-on.png +0 -0
  117. package/dist/esm/assets/images/marker_chap-on.svg +11 -0
  118. package/dist/esm/assets/images/marker_srch-on.svg +11 -0
  119. package/dist/esm/assets/images/marker_srchchap-off.png +0 -0
  120. package/dist/esm/assets/images/marker_srchchap-on.png +0 -0
  121. package/dist/esm/assets/images/nav_control-dn.png +0 -0
  122. package/dist/esm/assets/images/nav_control-dn_ia.png +0 -0
  123. package/dist/esm/assets/images/nav_control-up.png +0 -0
  124. package/dist/esm/assets/images/nav_control-up_ia.png +0 -0
  125. package/dist/esm/assets/images/nav_control.png +0 -0
  126. package/dist/esm/assets/images/one_page_mode_icon.png +0 -0
  127. package/dist/esm/assets/images/paper-badge.png +0 -0
  128. package/dist/esm/assets/images/print_icon.png +0 -0
  129. package/dist/esm/assets/images/progressbar.gif +0 -0
  130. package/dist/esm/assets/images/right_edges.png +0 -0
  131. package/dist/esm/assets/images/slider.png +0 -0
  132. package/dist/esm/assets/images/slider_ia.png +0 -0
  133. package/dist/esm/assets/images/thumbnail_mode_icon.png +0 -0
  134. package/dist/esm/assets/images/transparent.png +0 -0
  135. package/dist/esm/assets/images/two_page_mode_icon.png +0 -0
  136. package/dist/esm/assets/images/unviewable_page.png +0 -0
  137. package/dist/esm/assets/images/zoom_in_icon.png +0 -0
  138. package/dist/esm/assets/images/zoom_out_icon.png +0 -0
  139. package/dist/esm/css/BookReader.scss +85 -0
  140. package/dist/esm/css/_BRBookmarks.scss +29 -0
  141. package/dist/esm/css/_BRComponent.scss +13 -0
  142. package/dist/esm/css/_BRfloat.scss +197 -0
  143. package/dist/esm/css/_BRicon.scss +54 -0
  144. package/dist/esm/css/_BRmain.scss +262 -0
  145. package/dist/esm/css/_BRnav.scss +354 -0
  146. package/dist/esm/css/_BRpages.scss +213 -0
  147. package/dist/esm/css/_BRsearch.scss +268 -0
  148. package/dist/esm/css/_BRtoolbar.scss +84 -0
  149. package/dist/esm/css/_BRvendor.scss +5 -0
  150. package/dist/esm/css/_TextSelection.scss +108 -0
  151. package/dist/esm/css/_colorbox.scss +52 -0
  152. package/dist/esm/css/_controls.scss +257 -0
  153. package/dist/esm/css/_icons.scss +121 -0
  154. package/dist/esm/ia-bookreader/ia-bookreader.js +141 -0
  155. package/dist/esm/jquery-wrapper.js +3 -0
  156. package/dist/esm/plugins/plugin.archive_analytics.js +72 -0
  157. package/dist/esm/plugins/plugin.autoplay.js +119 -0
  158. package/dist/esm/plugins/plugin.chapters.js +288 -0
  159. package/dist/esm/plugins/plugin.iframe.js +44 -0
  160. package/dist/esm/plugins/plugin.iiif.js +146 -0
  161. package/dist/esm/plugins/plugin.resume.js +66 -0
  162. package/dist/esm/plugins/plugin.text_selection.js +621 -0
  163. package/dist/esm/plugins/plugin.vendor-fullscreen.js +227 -0
  164. package/dist/esm/plugins/search/plugin.search.js +499 -0
  165. package/dist/esm/plugins/search/utils.js +42 -0
  166. package/dist/esm/plugins/search/view.js +360 -0
  167. package/dist/esm/plugins/tts/AbstractTTSEngine.js +282 -0
  168. package/dist/esm/plugins/tts/FestivalTTSEngine.js +192 -0
  169. package/dist/esm/plugins/tts/PageChunk.js +105 -0
  170. package/dist/esm/plugins/tts/PageChunkIterator.js +155 -0
  171. package/dist/esm/plugins/tts/WebTTSEngine.js +364 -0
  172. package/dist/esm/plugins/tts/plugin.tts.js +315 -0
  173. package/dist/esm/plugins/tts/tooltip_dict.js +14 -0
  174. package/dist/esm/plugins/tts/utils.js +79 -0
  175. package/dist/esm/plugins/url/UrlPlugin.js +197 -0
  176. package/dist/esm/plugins/url/plugin.url.js +212 -0
  177. package/dist/esm/util/browserSniffing.js +56 -0
  178. package/dist/esm/util/debouncer.js +25 -0
  179. package/dist/esm/util/docCookies.js +75 -0
  180. package/dist/esm/util/strings.js +34 -0
  181. package/jsconfig.json +1 -0
  182. package/package.json +1 -7
@@ -0,0 +1,331 @@
1
+ /** @typedef {import('./BookModel.js').PageNumString} PageNumString */
2
+ /** @typedef {import('./BookModel.js').LeafNum} LeafNum */
3
+
4
+ export var DEFAULT_OPTIONS = {
5
+ /**
6
+ * @type {string} A string, such as "mode/1up". See
7
+ * http://openlibrary.org/dev/docs/bookurls for valid syntax
8
+ */
9
+ defaults: null,
10
+ /** Padding in 1up */
11
+ padding: 10,
12
+ /** @type {'full' | 'embed' | 'responsive'} UI mode */
13
+ ui: 'full',
14
+ /** Controls whether nav/toolbar will autohide */
15
+ uiAutoHide: false,
16
+ /** thumbnail mode */
17
+ /** number of rows to pre-cache out a view */
18
+ thumbRowBuffer: 1,
19
+ thumbColumns: 6,
20
+ /** number of thumbnails to load at once */
21
+ thumbMaxLoading: 4,
22
+ /** spacing between thumbnails */
23
+ thumbPadding: 10,
24
+ /** min zoom in columns */
25
+ thumbMinZoomColumns: 2,
26
+ /** max zoom out columns */
27
+ thumbMaxZoomColumns: 8,
28
+ /** @type {number | 'fast' | 'slow'} speed for flip animation */
29
+ flipSpeed: 400,
30
+ showToolbar: true,
31
+ showNavbar: true,
32
+ navBarTitle: '',
33
+ showLogo: true,
34
+ /** Where the logo links to */
35
+ logoURL: 'https://archive.org',
36
+ /**
37
+ * Base URL for UI images - should be overridden (before init) by
38
+ * custom implementations.
39
+ * $$$ This is the same directory as the images referenced by relative
40
+ * path in the CSS. Would be better to automagically find that path.
41
+ */
42
+ imagesBaseURL: '/BookReader/images/',
43
+ /** @type {'pow2' | 'integer'} What reduces are valid for getURI. */
44
+ reduceSet: 'pow2',
45
+ /**
46
+ * Zoom levels
47
+ * @type {ReductionFactor[]}
48
+ * $$$ provide finer grained zooming, {reduce: 8, autofit: null}, {reduce: 16, autofit: null}
49
+ * The autofit code ensures that fit to width and fit to height will be available
50
+ */
51
+ reductionFactors: [{
52
+ reduce: 0.25,
53
+ autofit: null
54
+ }, {
55
+ reduce: 0.5,
56
+ autofit: null
57
+ }, {
58
+ reduce: 1,
59
+ autofit: null
60
+ }, {
61
+ reduce: 2,
62
+ autofit: null
63
+ }, {
64
+ reduce: 3,
65
+ autofit: null
66
+ }, {
67
+ reduce: 4,
68
+ autofit: null
69
+ }, {
70
+ reduce: 6,
71
+ autofit: null
72
+ }],
73
+ /** Object to hold parameters related to 1up mode */
74
+ onePage: {
75
+ /** @type {AutoFitValues} */
76
+ autofit: 'auto'
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
+ onePageMinBreakpoint: 800,
90
+ bookTitle: '',
91
+ /** @type {string} */
92
+ bookUrl: null,
93
+ /** @type {string} */
94
+ bookUrlText: null,
95
+ /** @type {string} */
96
+ bookUrlTitle: null,
97
+ enableBookTitleLink: true,
98
+ /**
99
+ * @type {string} language in ISO 639-1 (PRIVATE: Will also
100
+ * handle language name in English, native name, 639-2/T, or 639-2/B . (archive.org books
101
+ * appear to use 639-2/B ? But I don't think that's a guarantee). See
102
+ * https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ) */
103
+ bookLanguage: null,
104
+ /**
105
+ * @type {Array<{label: string, value: *, extraValueClass: string?}>}
106
+ * Fields used to populate the info window
107
+ * @example [
108
+ * {label: 'Title', value: 'Open Library BookReader Presentation'},
109
+ * {label: 'Author', value: 'Internet Archive'},
110
+ * {label: 'Demo Info', value: 'This demo shows how one could use BookReader with their own content.'},
111
+ * ]
112
+ **/
113
+ metadata: [],
114
+ /** @type {string} */
115
+ thumbnail: null,
116
+ /** @type {string} */
117
+ bookUrlMoreInfo: null,
118
+ /** Experimental Controls (eg b/w) */
119
+ enableExperimentalControls: false,
120
+ /** CSS selectors */
121
+ /** Where BookReader mounts to */
122
+ el: '#BookReader',
123
+ /** @type {'lr' | 'rl'} Page progression */
124
+ pageProgression: 'lr',
125
+ /** The PPI the book is scanned at **/
126
+ ppi: 500,
127
+ /** Should image downloads be blocked */
128
+ protected: false,
129
+ /**
130
+ * Settings for individual plugins. Note they have to be imported first.
131
+ * WIP: Most plugins just put their options anywhere in this global options file,
132
+ * but going forward we'll keep them here.
133
+ **/
134
+ plugins: {
135
+ /** @type {import('../plugins/plugin.text_selection.js').TextSelectionPluginOptions} */
136
+ textSelection: null
137
+ },
138
+ /**
139
+ * Any variables you want to define. If an option has a StringWithVars type, or
140
+ * has something like `{{server}}/foo.com` in its value, these variables replace
141
+ * the `{{foo}}`.
142
+ * @type { {[var_name: string]: any } }
143
+ */
144
+ vars: {},
145
+ /**
146
+ * @type {Array<[PageData, PageData]|[PageData]>}
147
+ * Data is a simple way to populate the bookreader
148
+ *
149
+ * Example:
150
+ * ```
151
+ * [
152
+ * // Each child is a spread
153
+ * [
154
+ * {
155
+ * width: 123,
156
+ * height: 123,
157
+ * // Optional: If not provided, include a getPageURI
158
+ * uri: 'https://archive.org/image.jpg',
159
+ * // Optional: Shown instead of leaf number if present.
160
+ * pageNum: '1'
161
+ * },
162
+ * {width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '2'},
163
+ * ]
164
+ * ],
165
+ * ```
166
+ *
167
+ * Note if URI is omitted, a custom getPageURI can be provided. This allows the page
168
+ * URI to the result of a function, which allows for things such as dynamic
169
+ * page scaling.
170
+ */
171
+ data: [],
172
+ /** @type {import('../plugins/plugin.chapters.js').TocEntry[]} */
173
+ table_of_contents: null,
174
+ /** Advanced methods for page rendering */
175
+ /** @type {() => number} */
176
+ getNumLeafs: null,
177
+ /** @type {(index: number) => number} */
178
+ getPageWidth: null,
179
+ /** @type {(index: number) => number} */
180
+ getPageHeight: null,
181
+ /** @type {(index: number, reduce: number, rotate: number) => *} */
182
+ getPageURI: null,
183
+ /**
184
+ * @type {(index: number) => 'L' | 'R'}
185
+ * Return which side, left or right, that a given page should be displayed on
186
+ */
187
+ getPageSide: null,
188
+ /**
189
+ * @type {(pindex: number) => [number, number]}
190
+ * This function returns the left and right indices for the user-visible
191
+ * spread that contains the given index. The return values may be
192
+ * null if there is no facing page or the index is invalid.
193
+ */
194
+ getSpreadIndices: null,
195
+ /** @type {(index: number) => string} */
196
+ getPageNum: null,
197
+ /** @type {(index: number) => *} */
198
+ getPageProp: null,
199
+ /** @type {(index: number) => number} */
200
+ leafNumToIndex: null,
201
+ /**
202
+ * @type {(frameWidth: number|string, frameHeight: number|string, viewParams) => *}
203
+ * Optional: if present, and embed code will be shown in the share dialog
204
+ */
205
+ getEmbedCode: null,
206
+ controls: {
207
+ bookLeft: {
208
+ visible: true,
209
+ label: 'Flip left',
210
+ className: 'book_left',
211
+ iconClassName: 'left-arrow'
212
+ },
213
+ bookRight: {
214
+ visible: true,
215
+ label: 'Flip right',
216
+ className: 'book_right',
217
+ iconClassName: 'left-arrow hflip'
218
+ },
219
+ onePage: {
220
+ visible: true,
221
+ label: 'One-page view',
222
+ className: 'onepg',
223
+ iconClassName: 'onepg'
224
+ },
225
+ twoPage: {
226
+ visible: true,
227
+ label: 'Two-page view',
228
+ className: 'twopg',
229
+ iconClassName: 'twopg'
230
+ },
231
+ thumbnail: {
232
+ visible: true,
233
+ label: 'Thumbnail view',
234
+ className: 'thumb',
235
+ iconClassName: 'thumb'
236
+ },
237
+ viewmode: {
238
+ visible: true,
239
+ className: 'viewmode',
240
+ excludedModes: []
241
+ },
242
+ zoomOut: {
243
+ visible: true,
244
+ label: 'Zoom out',
245
+ className: 'zoom_out',
246
+ iconClassName: 'magnify'
247
+ },
248
+ zoomIn: {
249
+ visible: true,
250
+ label: 'Zoom in',
251
+ className: 'zoom_in',
252
+ iconClassName: 'magnify plus'
253
+ },
254
+ fullScreen: {
255
+ visible: true,
256
+ label: 'Toggle fullscreen',
257
+ className: 'full',
258
+ iconClassName: 'fullscreen'
259
+ }
260
+ },
261
+ /**
262
+ * @type {Boolean}
263
+ * Optional: if true, starts in fullscreen mode
264
+ */
265
+ startFullscreen: false,
266
+ /**
267
+ * @type {Boolean}
268
+ * will show logo at fullscreen mode
269
+ */
270
+ enableFSLogoShortcut: false,
271
+ /**
272
+ * @type {Boolean}
273
+ * On init, by default, we want to handle resizing bookreader
274
+ * when browser window changes size (inc. `orientationchange` event)
275
+ * toggle off if you want to handle this outside of bookreader
276
+ */
277
+ autoResize: true,
278
+ /**
279
+ * @type {Boolean}
280
+ * On init, by default, we want to use srcSet for images
281
+ */
282
+ useSrcSet: false,
283
+ /**
284
+ * @type {string}
285
+ * Path to the image to display when a page is unviewable (i.e. when
286
+ * displaying a preview of a book).
287
+ *
288
+ * Relative to the imagesBaseURL if a relative path is specified.
289
+ */
290
+ unviewablePageURI: './unviewable_page.png'
291
+ };
292
+
293
+ /**
294
+ * @typedef {'width' | 'height' | 'auto' | 'none'} AutoFitValues
295
+ * - width: fill the width of the container
296
+ * - height: fill the height of the container
297
+ * - auto: fill the width or height of the container, whichever is smaller
298
+ * - none: do not autofit
299
+ **/
300
+
301
+ /**
302
+ * @typedef {object} ReductionFactor
303
+ * @property {number} reduce
304
+ * @property {AutoFitValues} [autofit] If set, the corresponding reduction factors
305
+ * are what will be used when the user tries to autofit by width/height.
306
+ */
307
+
308
+ /**
309
+ * @typedef {Object} PageData
310
+ * @property {number} width
311
+ * @property {number} height
312
+ * @property {string} [uri] If not provided, include a getPageURI
313
+ * @property {PageNumString} [pageNum] Shown instead of leaf number if present
314
+ * @property {LeafNum} [leafNum] Sometimes specified in Internet Archive books
315
+ * @property {number} [ppi] The resolution of the page if different from {@see BookReaderOptions.ppi}
316
+ * @property {'L' | 'R'} [pageSide] PRIVATE; computed automatically
317
+ * @property {boolean} [viewable=true] Set false if page is not viewable. Displays a dummy preview image.
318
+ * @property {number} [unviewablesStart] PRIVATE; index where the chunk of unviewable pages started
319
+ *
320
+ * Note if URI is omitted, a custom getPageURI can be provided. This allows the page
321
+ * URI to the result of a function, which allows for things such as dynamic
322
+ * page scaling.
323
+ */
324
+
325
+ /** @typedef {typeof DEFAULT_OPTIONS} BookReaderOptions */
326
+
327
+ /**
328
+ * Thrown when an error occurs while parsing options.
329
+ * Potentially recoverable and non-halting.
330
+ */
331
+ export class OptionsParseError extends Error {}
@@ -0,0 +1,48 @@
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ // @ts-check
5
+ import { debounce } from '../utils';
6
+
7
+ /**
8
+ * Computing these things repeatedly is expensive (the browser needs to
9
+ * do a lot of computations/redrawing to make sure these are correct),
10
+ * so we store them here, and only recompute them when necessary:
11
+ * - window resize could have cause the container to change size
12
+ * - zoom could have cause scrollbars to appear/disappear, changing
13
+ * the client size.
14
+ */
15
+ export class HTMLDimensionsCacher {
16
+ /**
17
+ * @param {HTMLElement} element
18
+ */
19
+ constructor(element) {
20
+ _defineProperty(this, "clientWidth", 100);
21
+ _defineProperty(this, "clientHeight", 100);
22
+ _defineProperty(this, "boundingClientRect", {
23
+ top: 0,
24
+ left: 0
25
+ });
26
+ _defineProperty(this, "updateClientSizes", () => {
27
+ var 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
+ _defineProperty(this, "debouncedUpdateClientSizes", debounce(this.updateClientSizes, 150, false));
34
+ /** @type {HTMLElement} */
35
+ this.element = element;
36
+ }
37
+ /** @param {EventTarget} win */
38
+ attachResizeListener() {
39
+ var win = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
40
+ win.addEventListener('resize', this.debouncedUpdateClientSizes);
41
+ }
42
+
43
+ /** @param {EventTarget} win */
44
+ detachResizeListener() {
45
+ var win = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
46
+ win.removeEventListener('resize', this.debouncedUpdateClientSizes);
47
+ }
48
+ }
@@ -0,0 +1,31 @@
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ /** Adds a class while the given element is experiencing scrolling */
5
+ export class ScrollClassAdder {
6
+ /**
7
+ * @param {HTMLElement} element
8
+ * @param {string} className
9
+ */
10
+ constructor(element, className) {
11
+ _defineProperty(this, "onScroll", () => {
12
+ this.element.classList.add(this.className);
13
+ clearTimeout(this.timeout);
14
+ // TODO: Also remove class on mousemove, touch, click, etc.
15
+ this.timeout = setTimeout(() => {
16
+ this.element.classList.remove(this.className);
17
+ }, 600);
18
+ });
19
+ /** @type {HTMLElement} */
20
+ this.element = element;
21
+ /** @type {string} */
22
+ this.className = className;
23
+ this.timeout = null;
24
+ }
25
+ attach() {
26
+ this.element.addEventListener('scroll', this.onScroll);
27
+ }
28
+ detach() {
29
+ this.element.removeEventListener('scroll', this.onScroll);
30
+ }
31
+ }
@@ -0,0 +1,42 @@
1
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ // @ts-check
5
+ export class SelectionObserver {
6
+ /**
7
+ * @param {string} selector
8
+ * @param {function('started' | 'cleared', HTMLElement): any} handler
9
+ */
10
+ constructor(selector, handler) {
11
+ _defineProperty(this, "selecting", false);
12
+ _defineProperty(this, "startedInSelector", false);
13
+ /** @type {HTMLElement} */
14
+ _defineProperty(this, "target", null);
15
+ _defineProperty(this, "_onSelectionChange", () => {
16
+ var sel = window.getSelection();
17
+ if (!this.selecting && sel.toString()) {
18
+ var target = $(sel.anchorNode).closest(this.selector)[0];
19
+ if (!target) return;
20
+ this.target = target;
21
+ this.selecting = true;
22
+ this.handler('started', this.target);
23
+ }
24
+ if (this.selecting && (sel.isCollapsed || !sel.toString() || !$(sel.anchorNode).closest(this.selector)[0])) {
25
+ this.selecting = false;
26
+ this.handler('cleared', this.target);
27
+ }
28
+ });
29
+ this.selector = selector;
30
+ this.handler = handler;
31
+ }
32
+ attach() {
33
+ // We can't just use selectstart, because safari on iOS just
34
+ // randomly decides when to fire it 😤
35
+ // document.addEventListener("selectstart", this._onSelectStart);
36
+ // This has to be on document :/
37
+ document.addEventListener("selectionchange", this._onSelectionChange);
38
+ }
39
+ detach() {
40
+ document.removeEventListener("selectionchange", this._onSelectionChange);
41
+ }
42
+ }
@@ -0,0 +1,37 @@
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
+ var wrapper = (fn => {
18
+ return function () {
19
+ return fn.apply(toTransform(this), arguments);
20
+ };
21
+ })(FromClass.prototype[fromMethod]);
22
+ Object.defineProperty(ToClass.prototype, toMethod, {
23
+ get() {
24
+ return wrapper;
25
+ },
26
+ set(overrideFn) {
27
+ // overrideFn expects `this` to be ToClass, so ensure as such
28
+ // But we can also call this method from FromClass; need to ensure
29
+ // it's always called with a ToClass
30
+ FromClass.prototype[fromMethod] = function () {
31
+ var newThis = this instanceof FromClass ? fromTransform(this) : this;
32
+ return overrideFn.apply(newThis, arguments);
33
+ };
34
+ wrapper = overrideFn;
35
+ }
36
+ });
37
+ }