@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,212 @@
1
+ /* global BookReader */
2
+
3
+ import { UrlPlugin } from "./UrlPlugin";
4
+
5
+ /**
6
+ * Plugin for URL management in BookReader
7
+ * Note read more about the url "fragment" here:
8
+ * https://openlibrary.org/dev/docs/bookurls
9
+ */
10
+
11
+ jQuery.extend(BookReader.defaultOptions, {
12
+ enableUrlPlugin: true,
13
+ bookId: '',
14
+ /** @type {string} Defaults can be a urlFragment string */
15
+ defaults: null,
16
+ updateWindowTitle: false,
17
+ /** @type {'history' | 'hash'} */
18
+ urlMode: 'hash',
19
+ /**
20
+ * When using 'history' mode, this part of the URL is kept constant
21
+ * @example /details/plato/
22
+ */
23
+ urlHistoryBasePath: '/',
24
+ /** Only these params will be reflected onto the URL */
25
+ urlTrackedParams: ['page', 'search', 'mode', 'region', 'highlight', 'view'],
26
+ /** If true, don't update the URL when `page == n0 (eg "/page/n0")` */
27
+ urlTrackIndex0: false
28
+ });
29
+
30
+ /** @override */
31
+ BookReader.prototype.setup = function (super_) {
32
+ return function (options) {
33
+ super_.call(this, options);
34
+ this.bookId = options.bookId;
35
+ this.defaults = options.defaults;
36
+ this.locationPollId = null;
37
+ this.oldLocationHash = null;
38
+ this.oldUserHash = null;
39
+ };
40
+ }(BookReader.prototype.setup);
41
+
42
+ /** @override */
43
+ BookReader.prototype.init = function (super_) {
44
+ return function () {
45
+ if (this.options.enableUrlPlugin) {
46
+ this.bind(BookReader.eventNames.PostInit, () => {
47
+ var {
48
+ updateWindowTitle,
49
+ urlMode
50
+ } = this.options;
51
+ if (updateWindowTitle) {
52
+ document.title = this.shortTitle(this.bookTitle, 50);
53
+ }
54
+ if (urlMode === 'hash') {
55
+ this.urlStartLocationPolling();
56
+ }
57
+ });
58
+ this.bind(BookReader.eventNames.fragmentChange, this.urlUpdateFragment.bind(this));
59
+ }
60
+ super_.call(this);
61
+ };
62
+ }(BookReader.prototype.init);
63
+
64
+ /**
65
+ * Returns a shortened version of the title with the maximum number of characters
66
+ * @param {number} maximumCharacters
67
+ * @return {string}
68
+ */
69
+ BookReader.prototype.shortTitle = function (maximumCharacters) {
70
+ if (this.bookTitle.length < maximumCharacters) {
71
+ return this.bookTitle;
72
+ }
73
+ var title = "".concat(this.bookTitle.substr(0, maximumCharacters - 3), "...");
74
+ return title;
75
+ };
76
+
77
+ /**
78
+ * Starts polling of window.location to see hash fragment changes
79
+ */
80
+ BookReader.prototype.urlStartLocationPolling = function () {
81
+ this.oldLocationHash = this.urlReadFragment();
82
+ if (this.locationPollId) {
83
+ clearInterval(this.locationPollId);
84
+ this.locationPollId = null;
85
+ }
86
+ var updateHash = () => {
87
+ var newFragment = this.urlReadFragment();
88
+ var hasFragmentChange = newFragment != this.oldLocationHash && newFragment != this.oldUserHash;
89
+ if (!hasFragmentChange) {
90
+ return;
91
+ }
92
+ var params = this.paramsFromFragment(newFragment);
93
+ var updateParams = () => this.updateFromParams(params);
94
+ this.trigger(BookReader.eventNames.stop);
95
+ if (this.animating) {
96
+ // Queue change if animating
97
+ if (this.autoStop) this.autoStop();
98
+ this.animationFinishedCallback = updateParams;
99
+ } else {
100
+ // update immediately
101
+ updateParams();
102
+ }
103
+ this.oldUserHash = newFragment;
104
+ };
105
+ this.locationPollId = setInterval(updateHash, 500);
106
+ };
107
+
108
+ /**
109
+ * Update URL from the current parameters.
110
+ * Call this instead of manually using window.location.replace
111
+ */
112
+ BookReader.prototype.urlUpdateFragment = function () {
113
+ var allParams = this.paramsFromCurrent();
114
+ var {
115
+ urlTrackIndex0,
116
+ urlTrackedParams
117
+ } = this.options;
118
+ if (!urlTrackIndex0 && typeof allParams.index !== 'undefined' && allParams.index === 0) {
119
+ delete allParams.index;
120
+ delete allParams.page;
121
+ }
122
+ var params = urlTrackedParams.reduce((validParams, paramName) => {
123
+ if (paramName in allParams) {
124
+ validParams[paramName] = allParams[paramName];
125
+ }
126
+ return validParams;
127
+ }, {});
128
+ var newFragment = this.fragmentFromParams(params, this.options.urlMode);
129
+ var currFragment = this.urlReadFragment();
130
+ var currQueryString = this.getLocationSearch();
131
+ var newQueryString = this.queryStringFromParams(params, currQueryString, this.options.urlMode);
132
+ if (currFragment === newFragment && currQueryString === newQueryString) {
133
+ return;
134
+ }
135
+ if (this.options.urlMode === 'history') {
136
+ if (!window.history || !window.history.replaceState) {
137
+ this.options.urlMode = 'hash';
138
+ } else {
139
+ var baseWithoutSlash = this.options.urlHistoryBasePath.replace(/\/+$/, '');
140
+ var newFragmentWithSlash = newFragment === '' ? '' : "/".concat(newFragment);
141
+ var newUrlPath = "".concat(baseWithoutSlash).concat(newFragmentWithSlash).concat(newQueryString);
142
+ try {
143
+ window.history.replaceState({}, null, newUrlPath);
144
+ this.oldLocationHash = newFragment + newQueryString;
145
+ } catch (e) {
146
+ // DOMException on Chrome when in sandboxed iframe
147
+ this.options.urlMode = 'hash';
148
+ }
149
+ }
150
+ }
151
+ if (this.options.urlMode === 'hash') {
152
+ var newQueryStringSearch = this.urlParamsFiltersOnlySearch(this.readQueryString());
153
+ window.location.replace('#' + newFragment + newQueryStringSearch);
154
+ this.oldLocationHash = newFragment + newQueryStringSearch;
155
+ }
156
+ };
157
+
158
+ /**
159
+ * @private
160
+ * Filtering query parameters to select only book search param (?q=foo)
161
+ This needs to be updated/URL system modified if future query params are to be added
162
+ * @param {string} url
163
+ * @return {string}
164
+ * */
165
+ BookReader.prototype.urlParamsFiltersOnlySearch = function (url) {
166
+ var params = new URLSearchParams(url);
167
+ return params.has('q') ? "?".concat(new URLSearchParams({
168
+ q: params.get('q')
169
+ })) : '';
170
+ };
171
+
172
+ /**
173
+ * Will read either the hash or URL and return the bookreader fragment
174
+ * @return {string}
175
+ */
176
+ BookReader.prototype.urlReadFragment = function () {
177
+ var {
178
+ urlMode,
179
+ urlHistoryBasePath
180
+ } = this.options;
181
+ if (urlMode === 'history') {
182
+ return window.location.pathname.substr(urlHistoryBasePath.length);
183
+ } else {
184
+ return window.location.hash.substr(1);
185
+ }
186
+ };
187
+
188
+ /**
189
+ * Will read the hash return the bookreader fragment
190
+ * @return {string}
191
+ */
192
+ BookReader.prototype.urlReadHashFragment = function () {
193
+ return window.location.hash.substr(1);
194
+ };
195
+ export class BookreaderUrlPlugin extends BookReader {
196
+ init() {
197
+ if (this.options.enableUrlPlugin) {
198
+ this.urlPlugin = new UrlPlugin(this.options);
199
+ this.bind(BookReader.eventNames.PostInit, () => {
200
+ var {
201
+ urlMode
202
+ } = this.options;
203
+ if (urlMode === 'hash') {
204
+ this.urlPlugin.listenForHashChanges();
205
+ }
206
+ });
207
+ }
208
+ super.init();
209
+ }
210
+ }
211
+ window.BookReader = BookreaderUrlPlugin;
212
+ export default BookreaderUrlPlugin;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Checks whether the current browser is a Chrome/Chromium browser
3
+ * Code from https://stackoverflow.com/a/4565120/2317712
4
+ * @param {string} [userAgent]
5
+ * @param {string} [vendor]
6
+ * @return {boolean}
7
+ */
8
+ export function isChrome() {
9
+ var userAgent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : navigator.userAgent;
10
+ var vendor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : navigator.vendor;
11
+ return /chrome/i.test(userAgent) && /google inc/i.test(vendor);
12
+ }
13
+
14
+ /**
15
+ * Checks whether the current browser is firefox
16
+ * @param {string} [userAgent]
17
+ * @return {boolean}
18
+ */
19
+ export function isFirefox() {
20
+ var userAgent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : navigator.userAgent;
21
+ return /firefox/i.test(userAgent);
22
+ }
23
+
24
+ /**
25
+ * Checks whether the current browser is safari
26
+ * https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#Browser_Name
27
+ * @param {string} [userAgent]
28
+ * @return {boolean}
29
+ */
30
+ export function isSafari() {
31
+ var userAgent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : navigator.userAgent;
32
+ return /safari/i.test(userAgent) && !/chrome|chromium/i.test(userAgent);
33
+ }
34
+
35
+ /**
36
+ * Checks whether the current browser is iOS (and hence iOS webkit)
37
+ * @return {boolean}
38
+ */
39
+ export function isIOS() {
40
+ // We can't just check the userAgent because as of iOS 13,
41
+ // the userAgent is the same as desktop Safari because
42
+ // they wanted iPad's to be served the same version of websites
43
+ // as desktops.
44
+ return 'ongesturestart' in window && navigator.maxTouchPoints > 0;
45
+ }
46
+
47
+ /**
48
+ * Checks whether the current browser is Samsung Internet
49
+ * https://stackoverflow.com/a/40684162/2317712
50
+ * @param {string} [userAgent]
51
+ * @return {boolean}
52
+ */
53
+ export function isSamsungInternet() {
54
+ var userAgent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : navigator.userAgent;
55
+ return /SamsungBrowser/i.test(userAgent);
56
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Wait until some time has passed before executing a callback.
3
+ *
4
+ * @param {Function} callback
5
+ * @param {Number} threshhold - in milliseconds
6
+ * @param {*} context - will be bound to callback as its "this" value
7
+ */
8
+ class Debouncer {
9
+ constructor(callback) {
10
+ var threshhold = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
11
+ var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
12
+ this.callback = callback;
13
+ this.threshhold = threshhold;
14
+ this.context = context;
15
+ this.deferTimeout = undefined;
16
+ }
17
+ execute() {
18
+ clearTimeout(this.deferTimeout);
19
+ this.deferTimeout = setTimeout(this.executeCallback.bind(this), this.threshhold);
20
+ }
21
+ executeCallback() {
22
+ this.callback.apply(this.context);
23
+ }
24
+ }
25
+ export { Debouncer as default };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Helper module use to get, set and remove item from cookie
3
+ *
4
+ * See more:
5
+ * https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
6
+ * https://developer.mozilla.org/User:fusionchess
7
+ * https://github.com/madmurphy/cookies.js
8
+ * This framework is released under the GNU Public License, version 3 or later.
9
+ * http://www.gnu.org/licenses/gpl-3.0-standalone.html
10
+ */
11
+
12
+ /**
13
+ * Check to see if the browser has cookies enabled.
14
+ * Accessing document.cookies errors if eg iframe with sandbox enabled.
15
+ * @returns {boolean}
16
+ */
17
+ export function areCookiesBlocked() {
18
+ var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
19
+ try {
20
+ doc.cookie;
21
+ return false;
22
+ } catch (e) {
23
+ return true;
24
+ }
25
+ }
26
+ var COOKIES_BLOCKED = areCookiesBlocked();
27
+
28
+ /**
29
+ * Get specific key's value stored in cookie
30
+ *
31
+ * @param {string} sKey
32
+ *
33
+ * @returns {string|null}
34
+ */
35
+ export function getItem(sKey) {
36
+ if (COOKIES_BLOCKED || !sKey) return null;
37
+ return decodeURIComponent(
38
+ // eslint-disable-next-line no-useless-escape
39
+ document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
40
+ }
41
+
42
+ /**
43
+ * Set specific key's value in cookie
44
+ *
45
+ * @param {string} sKey cookie name
46
+ * @param {string} sValue cookie value
47
+ * @param {string} [vEnd] expire|max-age
48
+ * @param {string} [sPath] path of current item
49
+ * @param {string} [sDomain] domain name
50
+ * @param {boolean} [bSecure]
51
+ *
52
+ * @returns {boolean}
53
+ */
54
+ export function setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure) {
55
+ if (COOKIES_BLOCKED) return false;
56
+ document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue) + (vEnd ? "; expires=".concat(vEnd.toUTCString()) : '') + (sDomain ? "; domain=".concat(sDomain) : '') + (sPath ? "; path=".concat(sPath) : '') + (bSecure ? "; secure" : '');
57
+ return true;
58
+ }
59
+
60
+ /**
61
+ * BROKEN Remove specific key's value from cookie
62
+ * @fixme hasItem isn't even implemented! This will always error.
63
+ * @param {string} sKey cookie name
64
+ * @param {string} [sPath] path of current item
65
+ * @param {string} [sDomain]
66
+ *
67
+ * @returns {boolean}
68
+ */
69
+ export function removeItem(sKey, sPath, sDomain) {
70
+ if (COOKIES_BLOCKED) return false;
71
+ // eslint-disable-next-line
72
+ if (!hasItem(sKey)) return false;
73
+ document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=".concat(sDomain) : '') + (sPath ? "; path=".concat(sPath) : '');
74
+ return true;
75
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @typedef {String} StringWithVars
3
+ * A template string with {{foo}} style variables
4
+ * Also supports filters, like {{bookPath|urlencode}} (See APPLY_FILTERS for the
5
+ * supported list of filters)
6
+ **/
7
+
8
+ /**
9
+ * @param {StringWithVars|String} template
10
+ * @param { {[varName: string]: { toString: () => string} } } vars
11
+ * @param { {[varName: string]: { toString: () => string} } } [overrides]
12
+ */
13
+ export function applyVariables(template, vars) {
14
+ var overrides = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
15
+ var possibleFilters = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : APPLY_FILTERS;
16
+ return template === null || template === void 0 ? void 0 : template.replace(/\{\{([^}]*?)\}\}/g, ($0, $1) => {
17
+ if (!$1) return $0;
18
+ /** @type {string} */
19
+ var expression = $1;
20
+ var [varName, ...filterNames] = expression.split('|').map(x => x.trim());
21
+ var defined = varName in overrides || varName in vars;
22
+
23
+ // If it's not defined, don't expand it at all
24
+ if (!defined) return $0;
25
+ var value = varName in overrides ? overrides[varName] : varName in vars ? vars[varName] : null;
26
+ var filters = filterNames.map(n => possibleFilters[n]);
27
+ return filters.reduce((acc, cur) => cur(acc), value && value.toString());
28
+ });
29
+ }
30
+
31
+ /** @type { {[filterName: String]:( string => string)} } */
32
+ export var APPLY_FILTERS = {
33
+ urlencode: encodeURIComponent
34
+ };
package/jsconfig.json CHANGED
@@ -12,6 +12,7 @@
12
12
  "index.js",
13
13
  "src/**/*.js",
14
14
  "tests/**/*.js",
15
+ "dist/**/*.js"
15
16
  ],
16
17
  "exclude": [
17
18
  "node_modules",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/bookreader",
3
- "version": "5.0.0-88-alpha.8",
3
+ "version": "5.0.0-88-alpha.10",
4
4
  "description": "The Internet Archive BookReader.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,12 +10,6 @@
10
10
  "access": "public"
11
11
  },
12
12
  "module": "dist/esm/ia-bookreader/ia-bookreader.js",
13
- "exports": {
14
- ".": {
15
- "script": "./BookReader/ia-bookreader.js",
16
- "import": "./dist/esm/ia-bookreader/ia-bookreader.js"
17
- }
18
- },
19
13
  "keywords": [
20
14
  "online",
21
15
  "bookreader",