@internetarchive/bookreader 5.0.0-94 → 5.0.0-96

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 (167) hide show
  1. package/BookReader/BookReader.js +1 -1
  2. package/BookReader/hypothesis/LICENSE +50 -0
  3. package/BookReader/hypothesis/README.md +55 -0
  4. package/BookReader/hypothesis/build/boot.js +1 -0
  5. package/BookReader/hypothesis/build/manifest.json +20 -0
  6. package/BookReader/hypothesis/build/scripts/annotator.bundle.js +184 -0
  7. package/BookReader/hypothesis/build/scripts/annotator.bundle.js.map +1 -0
  8. package/BookReader/hypothesis/build/scripts/sidebar.bundle.js +798 -0
  9. package/BookReader/hypothesis/build/scripts/sidebar.bundle.js.map +1 -0
  10. package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js +711 -0
  11. package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js.map +1 -0
  12. package/BookReader/hypothesis/build/styles/annotator.css +2235 -0
  13. package/BookReader/hypothesis/build/styles/annotator.css.map +1 -0
  14. package/BookReader/hypothesis/build/styles/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  15. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  16. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  17. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  18. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  19. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Bold.woff2 +0 -0
  20. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  21. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Italic.woff2 +0 -0
  22. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Regular.woff2 +0 -0
  23. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  24. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-Italic.woff2 +0 -0
  25. package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  26. package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  27. package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  28. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Script-Regular.woff2 +0 -0
  29. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  30. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  31. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  32. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  33. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  34. package/BookReader/hypothesis/build/styles/highlights.css +2 -0
  35. package/BookReader/hypothesis/build/styles/highlights.css.map +1 -0
  36. package/BookReader/hypothesis/build/styles/katex.min.css +2 -0
  37. package/BookReader/hypothesis/build/styles/katex.min.css.map +1 -0
  38. package/BookReader/hypothesis/build/styles/pdfjs-overrides.css +2 -0
  39. package/BookReader/hypothesis/build/styles/pdfjs-overrides.css.map +1 -0
  40. package/BookReader/hypothesis/build/styles/sidebar.css +2731 -0
  41. package/BookReader/hypothesis/build/styles/sidebar.css.map +1 -0
  42. package/BookReader/hypothesis/build/styles/ui-playground.css +2659 -0
  43. package/BookReader/hypothesis/build/styles/ui-playground.css.map +1 -0
  44. package/BookReader/hypothesis/package.json +126 -0
  45. package/README.md +0 -2
  46. package/package.json +6 -1
  47. package/.eslintrc.cjs +0 -51
  48. package/.gitattributes +0 -2
  49. package/.github/ISSUE_TEMPLATE/bug.md +0 -32
  50. package/.github/ISSUE_TEMPLATE/feature-request.md +0 -30
  51. package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +0 -15
  52. package/.github/workflows/node.js.yml +0 -102
  53. package/.github/workflows/npm-publish.yml +0 -33
  54. package/.testcaferc.cjs +0 -10
  55. package/BookReaderDemo/BookReaderDemo.css +0 -40
  56. package/BookReaderDemo/BookReaderJSAdvanced.js +0 -112
  57. package/BookReaderDemo/BookReaderJSSimple.js +0 -56
  58. package/BookReaderDemo/IADemoBr.js +0 -149
  59. package/BookReaderDemo/assets/v5/Bookreader-logo-cool-grad.svg +0 -1
  60. package/BookReaderDemo/assets/v5/Bookreader-logo-flat.svg +0 -1
  61. package/BookReaderDemo/assets/v5/Bookreader-logo-hex-cool-grad.png +0 -0
  62. package/BookReaderDemo/assets/v5/Bookreader-logo-hex-flat.png +0 -0
  63. package/BookReaderDemo/assets/v5/Bookreader-logo-lines.png +0 -0
  64. package/BookReaderDemo/assets/v5/Bookreader-logo-lines.svg +0 -1
  65. package/BookReaderDemo/assets/v5/Bookreader-logo-warm.svg +0 -1
  66. package/BookReaderDemo/assets/v5/bookreader-logo-renders@1x.png +0 -0
  67. package/BookReaderDemo/assets/v5/bookreader-logo-renders@2x.png +0 -0
  68. package/BookReaderDemo/assets/v5/bookreader-v5-screenshot.png +0 -0
  69. package/BookReaderDemo/demo-advanced.html +0 -33
  70. package/BookReaderDemo/demo-embed-iframe-src.html +0 -85
  71. package/BookReaderDemo/demo-embed.html +0 -26
  72. package/BookReaderDemo/demo-fullscreen-mobile.html +0 -34
  73. package/BookReaderDemo/demo-fullscreen.html +0 -31
  74. package/BookReaderDemo/demo-iiif.html +0 -121
  75. package/BookReaderDemo/demo-internetarchive.html +0 -271
  76. package/BookReaderDemo/demo-multiple.html +0 -44
  77. package/BookReaderDemo/demo-preview-pages.html +0 -1093
  78. package/BookReaderDemo/demo-simple.html +0 -35
  79. package/BookReaderDemo/demo-vendor-fullscreen.html +0 -34
  80. package/BookReaderDemo/ia-multiple-volumes-manifest.js +0 -169
  81. package/BookReaderDemo/immersion-1up.html +0 -64
  82. package/BookReaderDemo/immersion-mode.html +0 -33
  83. package/BookReaderDemo/toggle_controls.html +0 -54
  84. package/BookReaderDemo/view_mode.html +0 -40
  85. package/BookReaderDemo/viewmode-cycle.html +0 -40
  86. package/CHANGELOG.md +0 -1080
  87. package/CONTRIBUTING.md +0 -7
  88. package/babel.config.cjs +0 -20
  89. package/codecov.yml +0 -23
  90. package/index.html +0 -34
  91. package/netlify.toml +0 -9
  92. package/renovate.json +0 -52
  93. package/screenshot.png +0 -0
  94. package/scripts/postversion.js +0 -11
  95. package/scripts/preversion.js +0 -15
  96. package/scripts/version.js +0 -27
  97. package/tests/e2e/README.md +0 -112
  98. package/tests/e2e/autoplay.test.js +0 -16
  99. package/tests/e2e/base.test.js +0 -27
  100. package/tests/e2e/helpers/base.js +0 -263
  101. package/tests/e2e/helpers/debug.js +0 -13
  102. package/tests/e2e/helpers/mockSearch.js +0 -90
  103. package/tests/e2e/helpers/params.js +0 -17
  104. package/tests/e2e/helpers/rightToLeft.js +0 -23
  105. package/tests/e2e/helpers/search.js +0 -73
  106. package/tests/e2e/models/BookReader.js +0 -11
  107. package/tests/e2e/models/Navigation.js +0 -39
  108. package/tests/e2e/rightToLeft.test.js +0 -19
  109. package/tests/e2e/viewmode.test.js +0 -44
  110. package/tests/jest/BookNavigator/book-navigator.test.js +0 -653
  111. package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +0 -43
  112. package/tests/jest/BookNavigator/bookmarks/bookmark-edit.test.js +0 -132
  113. package/tests/jest/BookNavigator/bookmarks/bookmarks-list.test.js +0 -221
  114. package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +0 -45
  115. package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +0 -67
  116. package/tests/jest/BookNavigator/downloads/downloads.test.js +0 -53
  117. package/tests/jest/BookNavigator/search/search-provider.test.js +0 -179
  118. package/tests/jest/BookNavigator/search/search-results.test.js +0 -289
  119. package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +0 -49
  120. package/tests/jest/BookNavigator/viewable-files/viewable-files-provider.test.js +0 -80
  121. package/tests/jest/BookNavigator/visual-adjustments.test.js +0 -200
  122. package/tests/jest/BookReader/BookModel.test.js +0 -372
  123. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +0 -263
  124. package/tests/jest/BookReader/ImageCache.test.js +0 -150
  125. package/tests/jest/BookReader/Mode1UpLit.test.js +0 -73
  126. package/tests/jest/BookReader/Mode2Up.test.js +0 -98
  127. package/tests/jest/BookReader/Mode2UpLit.test.js +0 -190
  128. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +0 -16
  129. package/tests/jest/BookReader/ModeSmoothZoom.test.js +0 -218
  130. package/tests/jest/BookReader/ModeThumb.test.js +0 -71
  131. package/tests/jest/BookReader/Navbar/Navbar.test.js +0 -182
  132. package/tests/jest/BookReader/PageContainer.test.js +0 -249
  133. package/tests/jest/BookReader/ReduceSet.test.js +0 -38
  134. package/tests/jest/BookReader/Toolbar/Toolbar.test.js +0 -26
  135. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +0 -59
  136. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +0 -49
  137. package/tests/jest/BookReader/utils/SelectionObserver.test.js +0 -57
  138. package/tests/jest/BookReader/utils/classes.test.js +0 -88
  139. package/tests/jest/BookReader/utils.test.js +0 -250
  140. package/tests/jest/BookReader.keyboard.test.js +0 -190
  141. package/tests/jest/BookReader.options.test.js +0 -47
  142. package/tests/jest/BookReader.test.js +0 -316
  143. package/tests/jest/plugins/plugin.archive_analytics.test.js +0 -20
  144. package/tests/jest/plugins/plugin.autoplay.test.js +0 -35
  145. package/tests/jest/plugins/plugin.chapters.test.js +0 -193
  146. package/tests/jest/plugins/plugin.iframe.test.js +0 -42
  147. package/tests/jest/plugins/plugin.resume.test.js +0 -85
  148. package/tests/jest/plugins/plugin.text_selection.test.js +0 -447
  149. package/tests/jest/plugins/plugin.vendor-fullscreen.test.js +0 -65
  150. package/tests/jest/plugins/search/plugin.search.test.js +0 -120
  151. package/tests/jest/plugins/search/plugin.search.view.test.js +0 -131
  152. package/tests/jest/plugins/search/utils.js +0 -25
  153. package/tests/jest/plugins/search/utils.test.js +0 -29
  154. package/tests/jest/plugins/tts/AbstractTTSEngine.test.js +0 -173
  155. package/tests/jest/plugins/tts/FestivalTTSEngine.test.js +0 -59
  156. package/tests/jest/plugins/tts/PageChunk.test.js +0 -57
  157. package/tests/jest/plugins/tts/PageChunkIterator.test.js +0 -179
  158. package/tests/jest/plugins/tts/WebTTSEngine.test.js +0 -178
  159. package/tests/jest/plugins/tts/utils.test.js +0 -74
  160. package/tests/jest/plugins/url/UrlPlugin.test.js +0 -198
  161. package/tests/jest/plugins/url/plugin.url.test.js +0 -168
  162. package/tests/jest/setup.js +0 -3
  163. package/tests/jest/util/browserSniffing.test.js +0 -62
  164. package/tests/jest/util/docCookies.test.js +0 -24
  165. package/tests/jest/util/strings.test.js +0 -63
  166. package/tests/jest/utils.js +0 -83
  167. package/webpack.config.js +0 -97
@@ -1,131 +0,0 @@
1
- // @ts-check
2
- import BookReader from '@/src/BookReader.js';
3
- import '@/src/plugins/search/plugin.search.js';
4
- import { marshallSearchResults } from '@/src/plugins/search/utils.js';
5
- import '@/src/plugins/search/view.js';
6
-
7
- /** @type {BookReader} */
8
- let br;
9
- const namespace = 'BookReader:';
10
- const results = {
11
- ia: "adventuresofoli00dick",
12
- q: "child",
13
- indexed: true,
14
- page_count: 644,
15
- body_length: 666,
16
- leaf0_missing: false,
17
- matches: [{
18
- text: 'For a long; time after it was ushered into this world of sorrow and trouble, by the parish surgeon, it remained a matter of considerable doubt wliether the {{{child}}} Avould survi^ e to bear any name at all; in which case it is somewhat more than probable that these memoirs would never have appeared; or, if they had, that being comprised within a couple of pages, they would have possessed the inestimable meiit of being the most concise and faithful specimen of biography, extant in the literature of any age or country.',
19
- par: [{
20
- boxes: [{r: 1221, b: 2121, t: 2075, page: 37, l: 1107}],
21
- b: 2535,
22
- t: 1942,
23
- page_width: 1790,
24
- r: 1598,
25
- l: 50,
26
- page_height: 2940,
27
- page: 37,
28
- }],
29
- }],
30
- };
31
-
32
- marshallSearchResults(results, () => '', '{{{', '}}}');
33
- const resultWithScript = {
34
- ia: "adventuresofoli00dick",
35
- q: "child",
36
- indexed: true,
37
- page_count: 644,
38
- body_length: 666,
39
- leaf0_missing: false,
40
- matches: [{
41
- text: 'foo bar <script>alert(1);</script> {{{keyword}}} baz',
42
- par: [{
43
- boxes: [{r: 1221, b: 2121, t: 2075, page: 37, l: 1107}],
44
- b: 2535,
45
- t: 1942,
46
- page_width: 1790,
47
- r: 1598,
48
- l: 50,
49
- page_height: 2940,
50
- page: 37,
51
- }],
52
- }],
53
- };
54
-
55
- marshallSearchResults(resultWithScript, () => '', '{{{', '}}}');
56
- beforeEach(() => {
57
- $.ajax = jest.fn().mockImplementation(() => {
58
- // return from:
59
- // `https://ia800304.us.archive.org/fulltext/inside.php?item_id=adventuresofoli00dick&doc=adventuresofoli00dick&path=/30/items/adventuresofoli00dick&q=child&callback=<serialized jQ CB>`
60
- return Promise.resolve(results);
61
- });
62
-
63
- $.fn.trigger = jest.fn();
64
- document.body.innerHTML = '<div id="BookReader">';
65
- br = new BookReader();
66
- br.initToolbar = jest.fn();
67
- br.showProgressPopup = jest.fn();
68
- });
69
-
70
- afterEach(() => {
71
- jest.clearAllMocks();
72
- });
73
-
74
- describe('View: Plugin: Search', () => {
75
- describe("Search results navigation bar", () => {
76
- test('Search Results callback creates the results nav', () => {
77
- br.init();
78
- const event = new CustomEvent(`${namespace}SearchCallback`);
79
- const options = { goToFirstResult: false };
80
-
81
- expect(br.plugins.search.searchView.dom.searchNavigation).toBeUndefined();
82
-
83
- br.plugins.search.searchView.handleSearchCallback(event, { results, options});
84
- expect(br.plugins.search.searchView.dom.searchNavigation).toBeDefined();
85
- });
86
- test('has controls', () => {
87
- br.init();
88
- const event = new CustomEvent(`${namespace}SearchCallback`);
89
- const options = { goToFirstResult: false };
90
- br.plugins.search.searchView.handleSearchCallback(event, { results, options});
91
-
92
- const searchResultsNav = document.querySelector('.BRsearch-navigation');
93
- expect(searchResultsNav).toBeDefined();
94
-
95
- expect(searchResultsNav.querySelectorAll('button').length).toEqual(4);
96
- expect(searchResultsNav.querySelector('.clear')).toBeDefined();
97
- expect(searchResultsNav.querySelector('.toggle-sidebar')).toBeDefined();
98
- expect(searchResultsNav.querySelector('.prev')).toBeDefined();
99
- expect(searchResultsNav.querySelector('.next')).toBeDefined();
100
- });
101
- test('disallows xss from search results', () => {
102
- br.init();
103
- const event = new CustomEvent(`${namespace}SearchCallback`);
104
- const options = { goToFirstResult: false };
105
- br.plugins.search.searchView.handleSearchCallback(event, { results: resultWithScript, options });
106
-
107
- expect(br.plugins.search.searchView.dom.searchNavigation.parent().html()).not.toContain('<script>alert(1);</script>');
108
- });
109
-
110
- describe('Click events handlers', () => {
111
- it('triggers custom event when toggling side menu', () => {
112
- br.init();
113
- let eventNameTriggered = '';
114
- br.trigger = (eventName) => eventNameTriggered = eventName;
115
-
116
- expect(eventNameTriggered).toBeFalsy();
117
- br.plugins.search.searchView.toggleSidebar();
118
- expect(eventNameTriggered).toEqual('ToggleSearchMenu');
119
- });
120
- it('triggers custom event when closing navbar', () => {
121
- br.init();
122
- let eventNameTriggered = '';
123
- br.trigger = (eventName) => eventNameTriggered = eventName;
124
-
125
- expect(eventNameTriggered).toBeFalsy();
126
- br.plugins.search.searchView.clearSearchFieldAndResults();
127
- expect(eventNameTriggered).toEqual('SearchResultsCleared');
128
- });
129
- });
130
- });
131
- });
@@ -1,25 +0,0 @@
1
- import { marshallSearchResults } from "@/src/plugins/search/utils.js";
2
-
3
- export const DUMMY_RESULTS = {
4
- ia: "adventuresofoli00dick",
5
- q: "child",
6
- indexed: true,
7
- page_count: 644,
8
- body_length: 666,
9
- leaf0_missing: false,
10
- matches: [{
11
- text: 'For a long; time after it was ushered into this world of sorrow and trouble, by the parish surgeon, it remained a matter of considerable doubt wliether the {{{child}}} Avould survi^ e to bear any name at all; in which case it is somewhat more than probable that these memoirs would never have appeared; or, if they had, that being comprised within a couple of pages, they would have possessed the inestimable meiit of being the most concise and faithful specimen of biography, extant in the literature of any age or country.',
12
- par: [{
13
- boxes: [{r: 1221, b: 2121, t: 2075, page: 37, l: 1107}],
14
- b: 2535,
15
- t: 1942,
16
- page_width: 1790,
17
- r: 1598,
18
- l: 50,
19
- page_height: 2940,
20
- page: 37,
21
- }],
22
- }],
23
- };
24
-
25
- marshallSearchResults(DUMMY_RESULTS, () => '', '{{{', '}}}');
@@ -1,29 +0,0 @@
1
- import { marshallSearchResults, renderMatch } from '@/src/plugins/search/utils.js';
2
- import { deepCopy } from '@/tests/jest/utils.js';
3
- import { DUMMY_RESULTS } from './utils.js';
4
-
5
- describe('renderMatch', () => {
6
- test('Supports custom pre/post tags', () => {
7
- const matchText = DUMMY_RESULTS.matches[0].text
8
- .replace(/\{\{\{/g, '<IA_FTS_MATCH>')
9
- .replace(/\}\}\}/g, '</IA_FTS_MATCH>');
10
- const html = renderMatch(matchText, '<IA_FTS_MATCH>', '</IA_FTS_MATCH>');
11
- expect(html).toContain('<mark>');
12
- expect(html).toContain('</mark>');
13
- });
14
- });
15
-
16
- describe('marshallSearchResults', () => {
17
- test('Adds match index', () => {
18
- const results = deepCopy(DUMMY_RESULTS);
19
- marshallSearchResults(results, x => x.toString(), '{{{', '}}}');
20
- expect(results.matches[0]).toHaveProperty('matchIndex', 0);
21
- expect(results.matches[0].par[0].boxes[0]).toHaveProperty('matchIndex', 0);
22
- });
23
-
24
- test('Adds display page number', () => {
25
- const results = deepCopy(DUMMY_RESULTS);
26
- marshallSearchResults(results, x => `n${x}`, '{{{', '}}}');
27
- expect(results.matches[0]).toHaveProperty('displayPageNumber', 'n37');
28
- });
29
- });
@@ -1,173 +0,0 @@
1
- import sinon from 'sinon';
2
- import { afterEventLoop } from '../../utils.js';
3
- import AbstractTTSEngine from '@/src/plugins/tts/AbstractTTSEngine.js';
4
- import PageChunkIterator from '@/src/plugins/tts/PageChunkIterator.js';
5
- /** @typedef {import('@/src/plugins/tts/AbstractTTSEngine.js').TTSEngineOptions} TTSEngineOptions */
6
-
7
- // Skipping because it's flaky. Fix in #672
8
- describe.skip('AbstractTTSEngine', () => {
9
- test('stops playing once done', async () => {
10
- class DummyEngine extends AbstractTTSEngine {
11
- getVoices() { return []; }
12
- }
13
- const d = new DummyEngine(DUMMY_TTS_ENGINE_OPTS);
14
- d._chunkIterator = { next: sinon.stub().resolves(PageChunkIterator.AT_END) };
15
- const stopStub = sinon.stub(d, 'stop');
16
- expect(stopStub.callCount).toBe(0);
17
- d.step();
18
- await afterEventLoop();
19
- expect(stopStub.callCount).toBe(1);
20
- });
21
- });
22
-
23
- for (const dummyVoice of [dummyVoiceHyphens, dummyVoiceUnderscores]) {
24
- describe(`getBestBookVoice with BCP47 ${dummyVoice == dummyVoiceUnderscores ? '+' : '-'} underscores`, () => {
25
- const { getBestBookVoice } = AbstractTTSEngine;
26
-
27
- test('undefined if no voices', () => {
28
- expect(getBestBookVoice([], 'en', [])).toBe(undefined);
29
- });
30
-
31
- test('returns first voice if no matching', () => {
32
- const enVoice = dummyVoice({lang: "en-US"});
33
- expect(getBestBookVoice([enVoice], 'fr', [])).toBe(enVoice);
34
- });
35
-
36
- test('choose first matching voice', () => {
37
- const voices = [
38
- dummyVoice({lang: "en-GB"}),
39
- dummyVoice({lang: "en-US"}),
40
- ];
41
- expect(getBestBookVoice(voices, 'en', [])).toBe(voices[0]);
42
- });
43
-
44
- test('choose first matching default voice', () => {
45
- const voices = [
46
- dummyVoice({lang: "en-GB"}),
47
- dummyVoice({lang: "en-US", default: true}),
48
- ];
49
- expect(getBestBookVoice(voices, 'en', [])).toBe(voices[1]);
50
- });
51
-
52
- test('does not choose default if better language match exists', () => {
53
- const voices = [
54
- dummyVoice({lang: "en-US", default: true}),
55
- dummyVoice({lang: "fr-FR"}),
56
- ];
57
- expect(getBestBookVoice(voices, 'fr', [])).toBe(voices[1]);
58
- });
59
-
60
- test('choose users dialect if present', () => {
61
- const voices = [
62
- dummyVoice({lang: "en-GB"}),
63
- dummyVoice({lang: "en-CA"}),
64
- dummyVoice({lang: "en-US"}),
65
- ];
66
- expect(getBestBookVoice(voices, 'en', ['en-CA', 'en'])).toBe(voices[1]);
67
- });
68
-
69
- test('choose users dialect even if not default', () => {
70
- const voices = [
71
- dummyVoice({lang: "en-US", default: true}),
72
- dummyVoice({lang: "en-GB"}),
73
- dummyVoice({lang: "en-CA"}),
74
- ];
75
- expect(getBestBookVoice(voices, 'en', ['en-CA', 'en'])).toBe(voices[2]);
76
- });
77
-
78
- test('choose language even if dialect does not match', () => {
79
- const voices = [
80
- dummyVoice({lang: "en-GB"}),
81
- ];
82
- expect(getBestBookVoice(voices, 'en', ['en-CA'])).toBe(voices[0]);
83
- });
84
-
85
- test('real world example', () => {
86
- // Chrome 77 @ Windows 10
87
- const voices = [
88
- { default: true, lang: "en-US", name: "Microsoft David Desktop - English (United States)", localService: true, voiceURI: "Microsoft David Desktop - English (United States)" },
89
- { default: false, lang: "de-DE", name: "Microsoft Hedda Desktop - German", localService: true, voiceURI: "Microsoft Hedda Desktop - German" },
90
- { default: false, lang: "en-US", name: "Microsoft Zira Desktop - English (United States)", localService: true, voiceURI: "Microsoft Zira Desktop - English (United States)" },
91
- { default: false, lang: "de-DE", name: "Google Deutsch", localService: false, voiceURI: "Google Deutsch" },
92
- { default: false, lang: "en-US", name: "Google US English", localService: false, voiceURI: "Google US English" },
93
- { default: false, lang: "en-GB", name: "Google UK English Female", localService: false, voiceURI: "Google UK English Female" },
94
- { default: false, lang: "en-GB", name: "Google UK English Male", localService: false, voiceURI: "Google UK English Male" },
95
- { default: false, lang: "es-ES", name: "Google español", localService: false, voiceURI: "Google español" },
96
- { default: false, lang: "es-US", name: "Google español de Estados Unidos", localService: false, voiceURI: "Google español de Estados Unidos" },
97
- { default: false, lang: "fr-FR", name: "Google français", localService: false, voiceURI: "Google français" },
98
- { default: false, lang: "hi-IN", name: "Google हिन्दी", localService: false, voiceURI: "Google हिन्दी" },
99
- { default: false, lang: "id-ID", name: "Google Bahasa Indonesia", localService: false, voiceURI: "Google Bahasa Indonesia" },
100
- { default: false, lang: "it-IT", name: "Google italiano", localService: false, voiceURI: "Google italiano" },
101
- { default: false, lang: "ja-JP", name: "Google 日本語", localService: false, voiceURI: "Google 日本語" },
102
- { default: false, lang: "ko-KR", name: "Google 한국의", localService: false, voiceURI: "Google 한국의" },
103
- { default: false, lang: "nl-NL", name: "Google Nederlands", localService: false, voiceURI: "Google Nederlands" },
104
- { default: false, lang: "pl-PL", name: "Google polski", localService: false, voiceURI: "Google polski" },
105
- { default: false, lang: "pt-BR", name: "Google português do Brasil", localService: false, voiceURI: "Google português do Brasil" },
106
- { default: false, lang: "ru-RU", name: "Google русский", localService: false, voiceURI: "Google русский" },
107
- { default: false, lang: "zh-CN", name: "Google 普通话(中国大陆)", localService: false, voiceURI: "Google 普通话(中国大陆)" },
108
- { default: false, lang: "zh-HK", name: "Google 粤語(香港)", localService: false, voiceURI: "Google 粤語(香港)" },
109
- { default: false, lang: "zh-TW", name: "Google 國語(臺灣)", localService: false, voiceURI: "Google 國語(臺灣)" },
110
- ];
111
-
112
- expect(getBestBookVoice(voices, 'en', ['en-CA', 'en'])).toBe(voices[0]);
113
- });
114
-
115
- test('choose stored language from localStorage', () => {
116
- const voices = [
117
- dummyVoice({lang: "en-US", voiceURI: "English US", default: true}),
118
- dummyVoice({lang: "en-GB", voiceURI: "English GB"}),
119
- dummyVoice({lang: "en-CA", voiceURI: "English CA"}),
120
- ];
121
- class DummyEngine extends AbstractTTSEngine {
122
- getVoices() { return voices; }
123
- }
124
- const ttsEngine = new DummyEngine({...DUMMY_TTS_ENGINE_OPTS, bookLanguage: 'en'});
125
- // simulates setting default voice on tts startup
126
- ttsEngine.updateBestVoice();
127
- // simulates user choosing a voice that matches the bookLanguage
128
- // voice will be stored in localStorage
129
- ttsEngine.setVoice(voices[2].voiceURI);
130
-
131
- // expecting the voice to be selected by getMatchingStoredVoice and returned as best voice
132
- expect(getBestBookVoice(voices, 'en', [])).toBe(voices[2]);
133
- });
134
- });
135
- }
136
-
137
- /** @type {TTSEngineOptions} */
138
- export const DUMMY_TTS_ENGINE_OPTS = {
139
- server: 'blah',
140
- bookPath: 'blah',
141
- bookLanguage: 'blah',
142
- onLoadingStart() {},
143
- onLoadingComplete() {},
144
- onDone() {},
145
- beforeChunkPlay() { return Promise.resolve(); },
146
- afterChunkPlay() {},
147
- };
148
-
149
- /**
150
- * @param {SpeechSynthesisVoice}
151
- * @return {SpeechSynthesisVoice}
152
- **/
153
- function dummyVoiceHyphens(overrides) {
154
- return Object.assign({
155
- default: false,
156
- lang: "en-US",
157
- name: "Microsoft David",
158
- localService: false,
159
- voiceURI: "",
160
- }, overrides);
161
- }
162
-
163
- /**
164
- * Construct a voice-like object using underscores instead of hyphenes
165
- * (Like Chrome/Android)
166
- * @param {SpeechSynthesisVoice}
167
- * @return {SpeechSynthesisVoice}
168
- **/
169
- function dummyVoiceUnderscores(overrides) {
170
- const voice = dummyVoiceHyphens(overrides);
171
- voice.lang = voice.lang.replace('-', '_');
172
- return voice;
173
- }
@@ -1,59 +0,0 @@
1
- import FestivalTTSEngine from '@/src/plugins/tts/FestivalTTSEngine.js';
2
- import sinon from 'sinon';
3
- import { afterEventLoop } from '../../utils.js';
4
- import { DUMMY_TTS_ENGINE_OPTS } from './AbstractTTSEngine.test.js';
5
- import PageChunk from '@/src/plugins/tts/PageChunk.js';
6
- import PageChunkIterator from '@/src/plugins/tts/PageChunkIterator.js';
7
- /** @typedef {import('@/src/plugins/tts/AbstractTTSEngine.js').TTSEngineOptions} TTSEngineOptions */
8
-
9
- describe('iOSCaptureUserIntentHack', () => {
10
- test('synchronously calls createSound/play to capture user intent', () => {
11
- const mockSound = createMockSound();
12
- const sm = {
13
- supported: sinon.stub().returns(true),
14
- createSound: sinon.stub().returns(mockSound),
15
- };
16
- window.soundManager = sm;
17
- const engine = new FestivalTTSEngine(DUMMY_TTS_ENGINE_OPTS);
18
- engine.iOSCaptureUserIntentHack();
19
-
20
- expect(sm.createSound.callCount).toBe(1);
21
- expect(mockSound.play.callCount).toBe(1);
22
- });
23
- });
24
-
25
- describe('misc', () => {
26
- test('starts playing even if onload not called until play starts', async () => {
27
- const sm = {
28
- supported: sinon.stub().returns(true),
29
- createSound: sinon.stub().returns(createMockSound()),
30
- stopAll: sinon.stub(),
31
- };
32
- window.soundManager = sm;
33
- const engine = new FestivalTTSEngine(DUMMY_TTS_ENGINE_OPTS);
34
- sinon.stub(engine, 'playSound').returns(new Promise(() => {}));
35
- sinon.stub(engine, 'stop');
36
- sinon.stub(PageChunkIterator.prototype, '_fetchPageChunks').resolves([dummyPageChunk()]);
37
- engine.start(0, 5);
38
-
39
- // because things happen in callbacks, need to run code at end of the JS event loop
40
- await afterEventLoop();
41
- expect(sm.createSound.callCount).toBe(1);
42
- expect(PageChunkIterator.prototype._fetchPageChunks.callCount).toBeGreaterThanOrEqual(1);
43
- expect(engine.playSound.callCount).toBe(1);
44
- });
45
- });
46
-
47
- /** @returns {SMSound} */
48
- function createMockSound() {
49
- return {
50
- load: sinon.stub(),
51
- play: sinon.stub(),
52
- destruct: sinon.stub(),
53
- };
54
- }
55
-
56
- /** @return {PageChunk} */
57
- function dummyPageChunk() {
58
- return new PageChunk(0, 0, 'Once upon a time', []);
59
- }
@@ -1,57 +0,0 @@
1
- import PageChunk from '@/src/plugins/tts/PageChunk.js';
2
-
3
- describe('_fixChunkRects', () => {
4
- const { _fixChunkRects } = PageChunk;
5
-
6
- test('Handles empty array', () => {
7
- const rects = [];
8
- expect(_fixChunkRects(rects)).toBe(rects);
9
- expect(rects).toEqual([]);
10
- });
11
-
12
- test('Does not modify normal values values normal', () => {
13
- const rects = [[100,100,500,80], [200,200,500,180], [300,300,500,280]];
14
- expect(_fixChunkRects(rects)).toBe(rects);
15
- expect(rects).toEqual([[100,100,500,80], [200,200,500,180], [300,300,500,280]]);
16
- });
17
-
18
- test('Fixes outlier values in first rect', () => {
19
- const rects = [[100,2300,2300,0], [200,200,200,180], [300,300,200,280]];
20
- expect(_fixChunkRects(rects)).toBe(rects);
21
- expect(rects).toEqual([[100,2300,200,2280], [200,200,200,180], [300,300,200,280]]);
22
- });
23
- });
24
-
25
- describe('_fromTextWrapperResponse', () => {
26
- const { _fromTextWrapperResponse } = PageChunk;
27
-
28
- test('Handles empty array', () => {
29
- expect(_fromTextWrapperResponse(0, [])).toEqual([]);
30
- });
31
-
32
- test('Basic test', () => {
33
- const chunks = _fromTextWrapperResponse(0, [['Line', [0,100,100,0]]]);
34
- expect(chunks).toEqual([new PageChunk(0, 0, 'Line', [[0,100,100,0]])]);
35
- });
36
- });
37
-
38
- describe('_removeDanglingHyphens', () => {
39
- const { _removeDanglingHyphens } = PageChunk;
40
-
41
- test('No change to empty string', () => {
42
- expect(_removeDanglingHyphens('')).toEqual('');
43
- });
44
-
45
- test('No change when no hyphens string', () => {
46
- expect(_removeDanglingHyphens('Hello world!')).toEqual('Hello world!');
47
- });
48
-
49
- test('No change to hyphens mid-word', () => {
50
- expect(_removeDanglingHyphens('It is mid-word!')).toEqual('It is mid-word!');
51
- });
52
-
53
- test('Removes hyphens followed by spaces', () => {
54
- expect(_removeDanglingHyphens('It is not mid- word!')).toEqual('It is not midword!');
55
- expect(_removeDanglingHyphens('mid- word fid- word')).toEqual('midword fidword');
56
- });
57
- });
@@ -1,179 +0,0 @@
1
- import sinon from 'sinon';
2
- import PageChunkIterator from "@/src/plugins/tts/PageChunkIterator.js";
3
- import PageChunk from '@/src/plugins/tts/PageChunk.js';
4
-
5
- describe('Buffers pages', () => {
6
- test('Does not error if no room for reverse buffer', async () => {
7
- const iterator = new PageChunkIterator(100, 0, {pageBufferSize: 5});
8
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
9
- await iterator.next();
10
- expect(iterator._fetchPageChunksDirect.callCount).toBe(6);
11
- expect(Object.keys(iterator._bufferedPages).length).toBe(6);
12
- });
13
-
14
- test('Does not error if no room for forward buffer', async () => {
15
- const iterator = new PageChunkIterator(100, 99, {pageBufferSize: 5});
16
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
17
- await iterator.next();
18
- expect(iterator._fetchPageChunksDirect.callCount).toBe(6);
19
- expect(Object.keys(iterator._bufferedPages).length).toBe(6);
20
- });
21
-
22
- test('Fewer pages than buffer size', async () => {
23
- const iterator = new PageChunkIterator(1, 0, {pageBufferSize: 5});
24
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
25
- await iterator.next();
26
- expect(iterator._fetchPageChunksDirect.callCount).toBe(1);
27
- expect(Object.keys(iterator._bufferedPages).length).toBe(1);
28
- });
29
-
30
- test('Buffers data before/after', async () => {
31
- const iterator = new PageChunkIterator(100, 50, {pageBufferSize: 5});
32
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
33
- await iterator.next();
34
- expect(iterator._fetchPageChunksDirect.callCount).toBe(11);
35
- expect(Object.keys(iterator._bufferedPages).length).toBe(11);
36
- });
37
-
38
- test('Buffer size does not grow indefinitely', async () => {
39
- const iterator = new PageChunkIterator(100, 50, {pageBufferSize: 5});
40
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
41
- for (let i = 0; i < 5; i++) await iterator.next();
42
- expect(Object.keys(iterator._bufferedPages).length).toBe(11);
43
- });
44
-
45
- test('Does not make a new request if buffered', async () => {
46
- const iterator = new PageChunkIterator(10, 7, {pageBufferSize: 5});
47
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
48
-
49
- await iterator.next();
50
- expect(iterator._fetchPageChunksDirect.callCount).toBe(8);
51
-
52
- await iterator.next();
53
- expect(iterator._fetchPageChunksDirect.callCount).toBe(8);
54
- });
55
- });
56
-
57
- describe('Iterates pages', () => {
58
- test('Moves between chunks before moving between pages', async () => {
59
- const iterator = new PageChunkIterator(100, 50, {pageBufferSize: 5});
60
- const chunks = [
61
- dummyPageChunk(),
62
- dummyPageChunk(),
63
- dummyPageChunk(),
64
- ];
65
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves(chunks);
66
-
67
- for (let i = 0; i < 4; i++) {
68
- expect(iterator._cursor.page).toBe(50);
69
- expect(iterator._cursor.chunk).toBe(i);
70
- await iterator.next();
71
- }
72
-
73
- expect(iterator._cursor.page).toBe(51);
74
- expect(iterator._cursor.chunk).toBe(1);
75
- });
76
-
77
- test('Fires AT_END when done', async () => {
78
- const iterator = new PageChunkIterator(1, 0, {pageBufferSize: 5});
79
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
80
-
81
- expect((await iterator.next()) instanceof PageChunk).toBe(true);
82
- expect(await iterator.next()).toBe(PageChunkIterator.AT_END);
83
- });
84
-
85
- test('Fires AT_END reaching past end', async () => {
86
- const iterator = new PageChunkIterator(1, 0, {pageBufferSize: 5});
87
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([dummyPageChunk()]);
88
-
89
- expect((await iterator.next()) instanceof PageChunk).toBe(true);
90
- expect(iterator._cursor.page).toBe(0);
91
- expect(iterator._cursor.chunk).toBe(1);
92
-
93
- for (let i = 0; i < 4; i++) {
94
- expect(await iterator.next()).toBe(PageChunkIterator.AT_END);
95
- expect(iterator._cursor.page).toBe(1);
96
- expect(iterator._cursor.chunk).toBe(0);
97
- }
98
- });
99
-
100
- test('Moves backwards between chunks/pages', async () => {
101
- const iterator = new PageChunkIterator(100, 50, {pageBufferSize: 5});
102
- const chunks = [
103
- dummyPageChunk(),
104
- dummyPageChunk(),
105
- dummyPageChunk(),
106
- ];
107
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves(chunks);
108
- expect(iterator._cursor.page).toBe(50);
109
- expect(iterator._cursor.chunk).toBe(0);
110
-
111
- for (let i = 2; i >= 0; i--) {
112
- await iterator.decrement();
113
- expect(iterator._cursor.page).toBe(49);
114
- expect(iterator._cursor.chunk).toBe(i);
115
- }
116
-
117
- await iterator.decrement();
118
- expect(iterator._cursor.page).toBe(48);
119
- expect(iterator._cursor.chunk).toBe(2);
120
- });
121
-
122
- test('Moving backwards at start refires start chunk', async () => {
123
- const iterator = new PageChunkIterator(100, 0, {pageBufferSize: 5});
124
- const chunks = [
125
- dummyPageChunk(),
126
- dummyPageChunk(),
127
- dummyPageChunk(),
128
- ];
129
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves(chunks);
130
-
131
- for (let i = 0; i < 4; i++) {
132
- expect(iterator._cursor.page).toBe(0);
133
- expect(iterator._cursor.chunk).toBe(0);
134
- await iterator.decrement();
135
- }
136
- });
137
-
138
- test('Empty book', async () => {
139
- const iterator = new PageChunkIterator(100, 0, {pageBufferSize: 5});
140
- sinon.stub(iterator, '_fetchPageChunksDirect').resolves([]);
141
- const result = await iterator.next();
142
- expect(iterator._fetchPageChunksDirect.callCount).toBe(100);
143
- expect(result).toBe(PageChunkIterator.AT_END);
144
- });
145
-
146
- test('Moving forward through empty pages', async () => {
147
- const iterator = new PageChunkIterator(10, 0, {pageBufferSize: 5});
148
- const nonEmptyPages = {
149
- 0: [dummyPageChunk()],
150
- 5: [dummyPageChunk()],
151
- };
152
- sinon.stub(iterator, '_fetchPageChunksDirect')
153
- .callsFake(async i => nonEmptyPages[i] || []);
154
-
155
- const result0 = await iterator.next();
156
- expect(result0).toBe(nonEmptyPages[0][0]);
157
-
158
- const result1 = await iterator.next();
159
- expect(result1).toBe(nonEmptyPages[5][0]);
160
- });
161
-
162
- test('Moving backward through empty pages', async () => {
163
- const iterator = new PageChunkIterator(10, 5, {pageBufferSize: 5});
164
- const nonEmptyPages = {
165
- 0: [dummyPageChunk()],
166
- 5: [dummyPageChunk()],
167
- };
168
- sinon.stub(iterator, '_fetchPageChunksDirect')
169
- .callsFake(async i => nonEmptyPages[i] || []);
170
-
171
- await iterator.decrement();
172
- const result0 = await iterator.next();
173
- expect(result0).toBe(nonEmptyPages[0][0]);
174
- });
175
- });
176
-
177
- function dummyPageChunk() {
178
- return new PageChunk(0, 0, "Line", []);
179
- }