@internetarchive/bookreader 5.0.0-38 → 5.0.0-39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. package/BookReader/BookReader.css +8 -0
  2. package/BookReader/BookReader.js +1 -1
  3. package/BookReader/BookReader.js.map +1 -1
  4. package/BookReader/ia-bookreader-bundle.js +99 -75
  5. package/BookReader/ia-bookreader-bundle.js.map +1 -1
  6. package/BookReader/icons/magnify-minus.svg +1 -1
  7. package/BookReader/icons/magnify-plus.svg +1 -1
  8. package/BookReader/plugins/plugin.autoplay.js +1 -1
  9. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  10. package/BookReader/plugins/plugin.chapters.js +1 -1
  11. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  12. package/BookReader/plugins/plugin.mobile_nav.js +1 -1
  13. package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
  14. package/BookReader/plugins/plugin.resume.js +1 -1
  15. package/BookReader/plugins/plugin.resume.js.map +1 -1
  16. package/BookReader/plugins/plugin.search.js +1 -1
  17. package/BookReader/plugins/plugin.search.js.map +1 -1
  18. package/BookReader/plugins/plugin.text_selection.js +1 -1
  19. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  20. package/BookReader/plugins/plugin.tts.js +1 -1
  21. package/BookReader/plugins/plugin.tts.js.map +1 -1
  22. package/BookReader/plugins/plugin.url.js +1 -1
  23. package/BookReader/plugins/plugin.url.js.map +1 -1
  24. package/CHANGELOG.md +5 -0
  25. package/README.md +13 -0
  26. package/package.json +14 -14
  27. package/renovate.json +1 -1
  28. package/src/BookReader/Mode1UpLit.js +7 -1
  29. package/src/BookReader/Mode2Up.js +11 -0
  30. package/src/BookReader/ModeSmoothZoom.js +2 -0
  31. package/src/BookReader/PageContainer.js +10 -4
  32. package/src/BookReader/utils/ScrollClassAdder.js +31 -0
  33. package/src/assets/icons/magnify-minus.svg +3 -7
  34. package/src/assets/icons/magnify-plus.svg +3 -7
  35. package/src/css/_TextSelection.scss +13 -0
  36. package/tests/jest/BookReader/PageContainer.test.js +5 -4
  37. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
  38. package/.husky/_/husky.sh +0 -30
  39. package/stat/BookNavigator/BookModel.js +0 -14
  40. package/stat/BookNavigator/BookNavigator.js +0 -524
  41. package/stat/BookNavigator/assets/bookmark-colors.js +0 -15
  42. package/stat/BookNavigator/assets/button-base.js +0 -61
  43. package/stat/BookNavigator/assets/ia-logo.js +0 -17
  44. package/stat/BookNavigator/assets/icon_checkmark.js +0 -6
  45. package/stat/BookNavigator/assets/icon_close.js +0 -3
  46. package/stat/BookNavigator/assets/icon_sort_asc.js +0 -5
  47. package/stat/BookNavigator/assets/icon_sort_desc.js +0 -5
  48. package/stat/BookNavigator/assets/icon_sort_neutral.js +0 -5
  49. package/stat/BookNavigator/assets/icon_volumes.js +0 -11
  50. package/stat/BookNavigator/bookmarks/bookmark-button.js +0 -64
  51. package/stat/BookNavigator/bookmarks/bookmark-edit.js +0 -215
  52. package/stat/BookNavigator/bookmarks/bookmarks-list.js +0 -285
  53. package/stat/BookNavigator/bookmarks/bookmarks-loginCTA.js +0 -28
  54. package/stat/BookNavigator/bookmarks/bookmarks-provider.js +0 -56
  55. package/stat/BookNavigator/bookmarks/ia-bookmarks.js +0 -523
  56. package/stat/BookNavigator/br-fullscreen-mgr.js +0 -82
  57. package/stat/BookNavigator/delete-modal-actions.js +0 -49
  58. package/stat/BookNavigator/downloads/downloads-provider.js +0 -72
  59. package/stat/BookNavigator/downloads/downloads.js +0 -139
  60. package/stat/BookNavigator/provider-config.js +0 -0
  61. package/stat/BookNavigator/search/a-search-result.js +0 -55
  62. package/stat/BookNavigator/search/search-provider.js +0 -180
  63. package/stat/BookNavigator/search/search-results.js +0 -360
  64. package/stat/BookNavigator/sharing.js +0 -31
  65. package/stat/BookNavigator/visual-adjustments/visual-adjustments-provider.js +0 -94
  66. package/stat/BookNavigator/visual-adjustments/visual-adjustments.js +0 -280
  67. package/stat/BookNavigator/volumes/volumes-provider.js +0 -83
  68. package/stat/BookNavigator/volumes/volumes.js +0 -178
  69. package/stat/BookReader/BookModel.js +0 -518
  70. package/stat/BookReader/DebugConsole.js +0 -54
  71. package/stat/BookReader/DragScrollable.js +0 -233
  72. package/stat/BookReader/ImageCache.js +0 -116
  73. package/stat/BookReader/Mode1Up.js +0 -102
  74. package/stat/BookReader/Mode1UpLit.js +0 -434
  75. package/stat/BookReader/Mode2Up.js +0 -1372
  76. package/stat/BookReader/ModeSmoothZoom.js +0 -177
  77. package/stat/BookReader/ModeThumb.js +0 -344
  78. package/stat/BookReader/Navbar/Navbar.js +0 -310
  79. package/stat/BookReader/PageContainer.js +0 -120
  80. package/stat/BookReader/ReduceSet.js +0 -26
  81. package/stat/BookReader/Toolbar/Toolbar.js +0 -384
  82. package/stat/BookReader/events.js +0 -20
  83. package/stat/BookReader/options.js +0 -324
  84. package/stat/BookReader/utils/HTMLDimensionsCacher.js +0 -44
  85. package/stat/BookReader/utils/classes.js +0 -36
  86. package/stat/BookReader/utils.js +0 -240
  87. package/stat/BookReader.js +0 -2550
  88. package/stat/BookReaderComponent/BookReaderComponent.js +0 -117
  89. package/stat/assets/icons/1up.svg +0 -12
  90. package/stat/assets/icons/2up.svg +0 -15
  91. package/stat/assets/icons/advance.svg +0 -26
  92. package/stat/assets/icons/chevron-right.svg +0 -1
  93. package/stat/assets/icons/close-circle-dark.svg +0 -1
  94. package/stat/assets/icons/close-circle.svg +0 -1
  95. package/stat/assets/icons/fullscreen.svg +0 -17
  96. package/stat/assets/icons/fullscreen_exit.svg +0 -17
  97. package/stat/assets/icons/hamburger.svg +0 -15
  98. package/stat/assets/icons/left-arrow.svg +0 -12
  99. package/stat/assets/icons/magnify-minus.svg +0 -16
  100. package/stat/assets/icons/magnify-plus.svg +0 -17
  101. package/stat/assets/icons/magnify.svg +0 -15
  102. package/stat/assets/icons/pause.svg +0 -23
  103. package/stat/assets/icons/play.svg +0 -22
  104. package/stat/assets/icons/playback-speed.svg +0 -34
  105. package/stat/assets/icons/read-aloud.svg +0 -22
  106. package/stat/assets/icons/review.svg +0 -22
  107. package/stat/assets/icons/thumbnails.svg +0 -17
  108. package/stat/assets/icons/voice.svg +0 -1
  109. package/stat/assets/icons/volume-full.svg +0 -22
  110. package/stat/assets/images/BRicons.png +0 -0
  111. package/stat/assets/images/BRicons.svg +0 -94
  112. package/stat/assets/images/BRicons_ia.png +0 -0
  113. package/stat/assets/images/back_pages.png +0 -0
  114. package/stat/assets/images/book_bottom_icon.png +0 -0
  115. package/stat/assets/images/book_down_icon.png +0 -0
  116. package/stat/assets/images/book_left_icon.png +0 -0
  117. package/stat/assets/images/book_leftmost_icon.png +0 -0
  118. package/stat/assets/images/book_right_icon.png +0 -0
  119. package/stat/assets/images/book_rightmost_icon.png +0 -0
  120. package/stat/assets/images/book_top_icon.png +0 -0
  121. package/stat/assets/images/book_up_icon.png +0 -0
  122. package/stat/assets/images/books_graphic.svg +0 -177
  123. package/stat/assets/images/booksplit.png +0 -0
  124. package/stat/assets/images/control_pause_icon.png +0 -0
  125. package/stat/assets/images/control_play_icon.png +0 -0
  126. package/stat/assets/images/embed_icon.png +0 -0
  127. package/stat/assets/images/icon-home-ia.png +0 -0
  128. package/stat/assets/images/icon_OL-logo-xs.png +0 -0
  129. package/stat/assets/images/icon_alert-xs.png +0 -0
  130. package/stat/assets/images/icon_book.svg +0 -12
  131. package/stat/assets/images/icon_bookmark.svg +0 -12
  132. package/stat/assets/images/icon_close-pop.png +0 -0
  133. package/stat/assets/images/icon_download.png +0 -0
  134. package/stat/assets/images/icon_gear.svg +0 -14
  135. package/stat/assets/images/icon_hamburger.svg +0 -20
  136. package/stat/assets/images/icon_home.png +0 -0
  137. package/stat/assets/images/icon_home.svg +0 -21
  138. package/stat/assets/images/icon_home_ia.png +0 -0
  139. package/stat/assets/images/icon_indicator.png +0 -0
  140. package/stat/assets/images/icon_info.svg +0 -11
  141. package/stat/assets/images/icon_one_page.svg +0 -8
  142. package/stat/assets/images/icon_pause.svg +0 -1
  143. package/stat/assets/images/icon_play.svg +0 -1
  144. package/stat/assets/images/icon_playback-rate.svg +0 -15
  145. package/stat/assets/images/icon_return.png +0 -0
  146. package/stat/assets/images/icon_search_button.svg +0 -8
  147. package/stat/assets/images/icon_share.svg +0 -9
  148. package/stat/assets/images/icon_skip-ahead.svg +0 -6
  149. package/stat/assets/images/icon_skip-back.svg +0 -13
  150. package/stat/assets/images/icon_speaker.svg +0 -18
  151. package/stat/assets/images/icon_speaker_open.svg +0 -10
  152. package/stat/assets/images/icon_thumbnails.svg +0 -12
  153. package/stat/assets/images/icon_toc.svg +0 -5
  154. package/stat/assets/images/icon_two_pages.svg +0 -9
  155. package/stat/assets/images/icon_zoomer.png +0 -0
  156. package/stat/assets/images/loading.gif +0 -0
  157. package/stat/assets/images/logo_icon.png +0 -0
  158. package/stat/assets/images/marker_chap-off.png +0 -0
  159. package/stat/assets/images/marker_chap-off.svg +0 -11
  160. package/stat/assets/images/marker_chap-off_ia.png +0 -0
  161. package/stat/assets/images/marker_chap-on.png +0 -0
  162. package/stat/assets/images/marker_chap-on.svg +0 -11
  163. package/stat/assets/images/marker_srch-on.svg +0 -11
  164. package/stat/assets/images/marker_srchchap-off.png +0 -0
  165. package/stat/assets/images/marker_srchchap-on.png +0 -0
  166. package/stat/assets/images/nav_control-dn.png +0 -0
  167. package/stat/assets/images/nav_control-dn_ia.png +0 -0
  168. package/stat/assets/images/nav_control-up.png +0 -0
  169. package/stat/assets/images/nav_control-up_ia.png +0 -0
  170. package/stat/assets/images/nav_control.png +0 -0
  171. package/stat/assets/images/one_page_mode_icon.png +0 -0
  172. package/stat/assets/images/paper-badge.png +0 -0
  173. package/stat/assets/images/print_icon.png +0 -0
  174. package/stat/assets/images/progressbar.gif +0 -0
  175. package/stat/assets/images/right_edges.png +0 -0
  176. package/stat/assets/images/slider.png +0 -0
  177. package/stat/assets/images/slider_ia.png +0 -0
  178. package/stat/assets/images/thumbnail_mode_icon.png +0 -0
  179. package/stat/assets/images/transparent.png +0 -0
  180. package/stat/assets/images/two_page_mode_icon.png +0 -0
  181. package/stat/assets/images/zoom_in_icon.png +0 -0
  182. package/stat/assets/images/zoom_out_icon.png +0 -0
  183. package/stat/css/BookReader.scss +0 -89
  184. package/stat/css/_BRBookmarks.scss +0 -29
  185. package/stat/css/_BRComponent.scss +0 -13
  186. package/stat/css/_BRfloat.scss +0 -197
  187. package/stat/css/_BRicon.scss +0 -48
  188. package/stat/css/_BRmain.scss +0 -251
  189. package/stat/css/_BRnav.scss +0 -359
  190. package/stat/css/_BRpages.scss +0 -139
  191. package/stat/css/_BRsearch.scss +0 -226
  192. package/stat/css/_BRtoolbar.scss +0 -84
  193. package/stat/css/_BRvendor.scss +0 -5
  194. package/stat/css/_MobileNav.scss +0 -194
  195. package/stat/css/_TextSelection.scss +0 -32
  196. package/stat/css/_colorbox.scss +0 -52
  197. package/stat/css/_controls.scss +0 -253
  198. package/stat/css/_icons.scss +0 -121
  199. package/stat/jquery-wrapper.js +0 -4
  200. package/stat/plugins/plugin.archive_analytics.js +0 -86
  201. package/stat/plugins/plugin.autoplay.js +0 -129
  202. package/stat/plugins/plugin.chapters.js +0 -248
  203. package/stat/plugins/plugin.iframe.js +0 -48
  204. package/stat/plugins/plugin.mobile_nav.js +0 -288
  205. package/stat/plugins/plugin.resume.js +0 -68
  206. package/stat/plugins/plugin.text_selection.js +0 -291
  207. package/stat/plugins/plugin.url.js +0 -198
  208. package/stat/plugins/plugin.vendor-fullscreen.js +0 -247
  209. package/stat/plugins/search/plugin.search.js +0 -439
  210. package/stat/plugins/search/view.js +0 -439
  211. package/stat/plugins/tts/AbstractTTSEngine.js +0 -249
  212. package/stat/plugins/tts/FestivalTTSEngine.js +0 -169
  213. package/stat/plugins/tts/PageChunk.js +0 -107
  214. package/stat/plugins/tts/PageChunkIterator.js +0 -163
  215. package/stat/plugins/tts/WebTTSEngine.js +0 -357
  216. package/stat/plugins/tts/plugin.tts.js +0 -357
  217. package/stat/plugins/tts/tooltip_dict.js +0 -15
  218. package/stat/plugins/tts/utils.js +0 -91
  219. package/stat/util/browserSniffing.js +0 -30
  220. package/stat/util/debouncer.js +0 -26
  221. package/stat/util/docCookies.js +0 -67
  222. package/stat/util/strings.js +0 -34
@@ -1,357 +0,0 @@
1
- /* global br */
2
- import { isChrome, isFirefox } from '../../util/browserSniffing.js';
3
- import { sleep, promisifyEvent, isAndroid } from './utils.js';
4
- import AbstractTTSEngine from './AbstractTTSEngine.js';
5
- /** @typedef {import("./AbstractTTSEngine.js").PageChunk} PageChunk */
6
- /** @typedef {import("./AbstractTTSEngine.js").AbstractTTSSound} AbstractTTSSound */
7
- /** @typedef {import("./AbstractTTSEngine.js").TTSEngineOptions} TTSEngineOptions */
8
-
9
- /**
10
- * @extends AbstractTTSEngine
11
- * TTS using Web Speech APIs
12
- **/
13
- export default class WebTTSEngine extends AbstractTTSEngine {
14
- static isSupported() {
15
- return typeof(window.speechSynthesis) !== 'undefined' && !/samsungbrowser/i.test(navigator.userAgent);
16
- }
17
-
18
- /** @param {TTSEngineOptions} options */
19
- constructor(options) {
20
- super(options);
21
-
22
- // SAFARI doesn't have addEventListener on speechSynthesis
23
- if (speechSynthesis.addEventListener) {
24
- speechSynthesis.addEventListener('voiceschanged', () => this.events.trigger('voiceschanged'));
25
- }
26
- }
27
-
28
- /** @override */
29
- start(leafIndex, numLeafs) {
30
- // Need to run in this function to capture user intent to start playing audio
31
- if ('mediaSession' in navigator) {
32
- const audio = new Audio(SILENCE_6S_MP3);
33
- audio.loop = true;
34
-
35
- this.events.on('pause', () => audio.pause());
36
- this.events.on('resume', () => audio.play());
37
- // apparently this is what you need to do to make the media session notification go away
38
- // See https://developers.google.com/web/updates/2017/02/media-session#implementation_notes
39
- this.events.on('stop', () => audio.src = '');
40
- audio.play().then(() => {
41
- navigator.mediaSession.metadata = new MediaMetadata({
42
- title: br.bookTitle,
43
- artist: br.options.metadata.filter(m => m.label == 'Author').map(m => m.value)[0],
44
- // album: 'The Ultimate Collection (Remastered)',
45
- artwork: [
46
- { src: br.options.thumbnail, type: 'image/jpg' },
47
- ]
48
- });
49
-
50
- navigator.mediaSession.setActionHandler('play', () => {
51
- audio.play();
52
- this.resume();
53
- });
54
- navigator.mediaSession.setActionHandler('pause', () => {
55
- audio.pause();
56
- this.pause();
57
- });
58
-
59
- // navigator.mediaSession.setActionHandler('seekbackward', () => this.jumpBackward());
60
- // navigator.mediaSession.setActionHandler('seekforward', () => this.jumpForward());
61
- // Some devices only support the previoustrack/nexttrack (e.g. Win10), so show those.
62
- // Android devices do support the seek actions, but we don't want to show both buttons
63
- // and have them do the same thing.
64
- navigator.mediaSession.setActionHandler('previoustrack', () => this.jumpBackward());
65
- navigator.mediaSession.setActionHandler('nexttrack', () => this.jumpForward());
66
- });
67
- }
68
-
69
- return super.start(leafIndex, numLeafs);
70
- }
71
-
72
- /** @override */
73
- getVoices() { return speechSynthesis.getVoices(); }
74
-
75
- /** @override */
76
- createSound(chunk) {
77
- return new WebTTSSound(chunk.text);
78
- }
79
- }
80
-
81
- /** @extends AbstractTTSSound */
82
- export class WebTTSSound {
83
- /** @param {string} text **/
84
- constructor(text) {
85
- this.text = text;
86
- this.loaded = false;
87
- this.paused = false;
88
- this.started = false;
89
- /** Whether the audio was stopped with a .stop() call */
90
- this.stopped = false;
91
- this.rate = 1;
92
-
93
- /** @type {SpeechSynthesisUtterance} */
94
- this.utterance = null;
95
-
96
- /** @type {SpeechSynthesisVoice} */
97
- this.voice = null;
98
-
99
- this._lastEvents = {
100
- /** @type {SpeechSynthesisEvent} */
101
- pause: null,
102
- /** @type {SpeechSynthesisEvent} */
103
- boundary: null,
104
- /** @type {SpeechSynthesisEvent} */
105
- start: null,
106
- };
107
-
108
- /** Store where we are in the text. Only works on some browsers. */
109
- this._charIndex = 0;
110
-
111
- /** @type {Function} resolve function called when playback finished */
112
- this._finishResolver = null;
113
-
114
- /** @type {Promise} promise resolved by _finishResolver */
115
- this._finishPromise = null;
116
- }
117
-
118
- /** @override **/
119
- load(onload) {
120
- this.loaded = false;
121
- this.started = false;
122
-
123
- this.utterance = new SpeechSynthesisUtterance(this.text.slice(this._charIndex));
124
- this.utterance.voice = this.voice;
125
- // Need to also set lang (for some reason); won't set voice on Chrome@Android otherwise
126
- if (this.voice) this.utterance.lang = this.voice.lang;
127
- this.utterance.rate = this.rate;
128
-
129
- // Useful for debugging things
130
- if (location.toString().indexOf('_debugReadAloud=true') != -1) {
131
- this.utterance.addEventListener('pause', () => console.log('pause'));
132
- this.utterance.addEventListener('resume', () => console.log('resume'));
133
- this.utterance.addEventListener('start', () => console.log('start'));
134
- this.utterance.addEventListener('end', () => console.log('end'));
135
- this.utterance.addEventListener('error', () => console.log('error'));
136
- this.utterance.addEventListener('boundary', () => console.log('boundary'));
137
- this.utterance.addEventListener('mark', () => console.log('mark'));
138
- this.utterance.addEventListener('finish', () => console.log('finish'));
139
- }
140
-
141
- // Keep track of the speech synthesis events that come in; they have useful info
142
- // about progress (like charIndex)
143
- this.utterance.addEventListener('start', ev => this._lastEvents.start = ev);
144
- this.utterance.addEventListener('boundary', ev => this._lastEvents.boundary = ev);
145
- this.utterance.addEventListener('pause', ev => this._lastEvents.pause = ev);
146
-
147
- // Update our state
148
- this.utterance.addEventListener('start', () => {
149
- this.started = true;
150
- this.stopped = false;
151
- this.paused = false;
152
- });
153
- this.utterance.addEventListener('pause', () => this.paused = true);
154
- this.utterance.addEventListener('resume', () => this.paused = false);
155
- this.utterance.addEventListener('end', ev => {
156
- if (!this.paused && !this.stopped) {
157
- // Trigger a new event, finish, which only fires when audio fully completed
158
- this.utterance.dispatchEvent(new CustomEvent('finish', ev));
159
- }
160
- });
161
- this.loaded = true;
162
- onload && onload();
163
- }
164
-
165
- /**
166
- * Run whenever properties have changed. Tries to restart in the same spot it
167
- * left off.
168
- * @return {Promise<void>}
169
- */
170
- reload() {
171
- // We'll restore the pause state, so copy it here
172
- const wasPaused = this.paused;
173
- // Use recent event to determine where we'll restart from
174
- // Browser support for this is mixed, but it degrades to restarting the chunk
175
- // and that's ok
176
- const recentEvent = this._lastEvents.boundary || this._lastEvents.pause;
177
- if (recentEvent) {
178
- this._charIndex = this.text.indexOf(recentEvent.target.text) + recentEvent.charIndex;
179
- }
180
-
181
- // We can't modify the utterance object, so we have to make a new one
182
- return this.stop()
183
- .then(() => {
184
- this.load();
185
- // Instead of playing and immediately pausing, we don't start playing. Note
186
- // this is a requirement because pause doesn't work consistently across
187
- // browsers.
188
- if (!wasPaused) this.play();
189
- });
190
- }
191
-
192
- play() {
193
- this._finishPromise = this._finishPromise || new Promise(res => this._finishResolver = res);
194
- this.utterance.addEventListener('finish', this._finishResolver);
195
-
196
- // clear the queue
197
- speechSynthesis.cancel();
198
- // reset pause state
199
- speechSynthesis.resume();
200
- // Speak
201
- speechSynthesis.speak(this.utterance);
202
-
203
- const isLocalVoice = this.utterance.voice && this.utterance.voice.localService;
204
- if (isChrome() && !isLocalVoice) this._chromePausingBugFix();
205
-
206
- return this._finishPromise;
207
- }
208
-
209
- /** @return {Promise} */
210
- stop() {
211
- // 'end' won't fire if already stopped
212
- let endPromise = Promise.resolve();
213
- if (!this.stopped) {
214
- endPromise = Promise.race([
215
- promisifyEvent(this.utterance, 'end'),
216
- // Safari triggers an error when you call cancel mid-sound
217
- promisifyEvent(this.utterance, 'error'),
218
- ]);
219
- }
220
- this.stopped = true;
221
- speechSynthesis.cancel();
222
- return endPromise;
223
- }
224
-
225
- finish() {
226
- this.stop().then(() => this.utterance.dispatchEvent(new Event('finish')));
227
- }
228
-
229
- /**
230
- * @override
231
- * Will fire a pause event unless already paused
232
- **/
233
- pause() {
234
- if (this.paused) return;
235
-
236
- const pausePromise = promisifyEvent(this.utterance, 'pause');
237
- speechSynthesis.pause();
238
-
239
- // There are a few awful browser cases:
240
- // 1. Pause works and fires
241
- // 2. Pause doesn't work and doesn't fire
242
- // 3. Pause works but doesn't fire
243
- const pauseMightNotWork = (isFirefox() && isAndroid());
244
- const pauseMightNotFire = isChrome() || pauseMightNotWork;
245
-
246
- if (pauseMightNotFire) {
247
- // wait for it just in case
248
- const timeoutPromise = sleep(100).then(() => 'timeout');
249
- Promise.race([pausePromise, timeoutPromise])
250
- .then(result => {
251
- // We got our pause event; nothing to do!
252
- if (result != 'timeout') return;
253
-
254
- this.utterance.dispatchEvent(new CustomEvent('pause', this._lastEvents.start));
255
- // if pause might not work, then we'll stop entirely and restart later
256
- if (pauseMightNotWork) this.stop();
257
- });
258
- }
259
- }
260
-
261
- resume() {
262
- if (!this.started) {
263
- this.play();
264
- return;
265
- }
266
-
267
- if (!this.paused) return;
268
-
269
- // Browser cases:
270
- // 1. Resume works + fires
271
- // 2. Resume works + doesn't fire (Chrome Desktop)
272
- // 3. Resume doesn't work + doesn't fire (Chrome/FF Android)
273
- const resumeMightNotWork = (isChrome() && isAndroid()) || (isFirefox() && isAndroid());
274
- const resumeMightNotFire = isChrome() || resumeMightNotWork;
275
-
276
- // Try resume
277
- const resumePromise = promisifyEvent(this.utterance, 'resume');
278
- speechSynthesis.resume();
279
-
280
- if (resumeMightNotFire) {
281
- Promise.race([resumePromise, sleep(100).then(() => 'timeout')])
282
- .then(result => {
283
- if (result != 'timeout') return;
284
-
285
- this.utterance.dispatchEvent(new CustomEvent('resume', {}));
286
- if (resumeMightNotWork) {
287
- const reloadPromise = this.reload();
288
- reloadPromise.then(() => this.play());
289
- }
290
- });
291
- }
292
- }
293
-
294
- setPlaybackRate(rate) {
295
- this.rate = rate;
296
- this.reload();
297
- }
298
-
299
- /** @param {SpeechSynthesisVoice} voice */
300
- setVoice(voice) {
301
- this.voice = voice;
302
- this.reload();
303
- }
304
- /**
305
- * @private
306
- * Chrome has a bug where it only plays 15 seconds of TTS and then
307
- * suddenly stops (see https://bugs.chromium.org/p/chromium/issues/detail?id=679437 )
308
- * We avoid this (as described here: https://bugs.chromium.org/p/chromium/issues/detail?id=679437#c15 )
309
- * by pausing after 14 seconds and ~instantly resuming.
310
- */
311
- _chromePausingBugFix() {
312
- const timeoutPromise = sleep(14000).then(() => 'timeout');
313
- const pausePromise = promisifyEvent(this.utterance, 'pause').then(() => 'paused');
314
- const endPromise = promisifyEvent(this.utterance, 'end').then(() => 'ended');
315
- return Promise.race([timeoutPromise, pausePromise, endPromise])
316
- .then(result => {
317
- if (location.toString().indexOf('_debugReadAloud=true') != -1) {
318
- console.log(`CHROME-PAUSE-HACK: ${result}`);
319
- }
320
- switch (result) {
321
- case 'ended':
322
- // audio was stopped/finished; nothing to do
323
- break;
324
- case 'paused':
325
- // audio was paused; wait for resume
326
- // Chrome won't let you resume the audio if 14s have passed 🤷‍
327
- // We could do the same as before (but resume+pause instead of pause+resume),
328
- // but that means we'd _constantly_ be running in the background. So in that
329
- // case, let's just restart the chunk
330
- Promise.race([
331
- promisifyEvent(this.utterance, 'resume'),
332
- sleep(14000).then(() => 'timeout'),
333
- ])
334
- .then(result => {
335
- result == 'timeout' ? this.reload() : this._chromePausingBugFix();
336
- });
337
- break;
338
- case 'timeout':
339
- // We hit Chrome's secret cut off time. Pause/resume
340
- // to be able to keep TTS-ing
341
- speechSynthesis.pause();
342
- sleep(25)
343
- .then(() => {
344
- speechSynthesis.resume();
345
- this._chromePausingBugFix();
346
- });
347
- break;
348
- }
349
- });
350
- }
351
- }
352
-
353
- /**
354
- * According to https://developers.google.com/web/updates/2017/02/media-session#implementation_notes , it needs to be at least 5 seconds
355
- * long to allow usage of the media sessions api
356
- */
357
- const SILENCE_6S_MP3 = 'data:audio/mp3;base64,/+MYxAAMEAISSAhElhIpJYzz1vz9mUdlHvJwTP/n3FJesPxB9/8mp0oGaz9+7+T//8oCDhJqOMqLh4o4uhUAUUDaf//3r+///+MYxAoKy2ImKAgEqbfr/t///27/+n3s32/////+b5qMsq7vnXCKh2By3ZcIqyrUYbbRH0fp+ljtf+n2Uo72PHX/03f0df///+MYxBkKUAYmQAhEAL+2l44oKFjZMwJAOJnhguMqokFAqBKl/5f1/+f+3/v////9GT//r+//v+//////b1VvucaRChqnMqsY/+MYxCoLo2IiSAgEpRrgIRVq//p////25nl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