@internetarchive/bookreader 5.0.0-96 → 5.0.0-98
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.
- package/BookReader/474.js +2 -0
- package/BookReader/474.js.map +1 -0
- package/BookReader/BookReader.css +39 -34
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/bergamot-translator-worker.js +2966 -0
- package/BookReader/bergamot-translator-worker.wasm +0 -0
- package/BookReader/ia-bookreader-bundle.js +1 -1
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/images/icon_experiment.svg +1 -0
- package/BookReader/images/translate.svg +1 -0
- package/BookReader/plugins/plugin.experiments.js +1 -1
- package/BookReader/plugins/plugin.experiments.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +1 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.translate.js +3 -0
- package/BookReader/plugins/plugin.translate.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.translate.js.map +1 -0
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/translator-worker.js +2 -0
- package/BookReader/plugins/translator-worker.js.map +1 -0
- package/BookReader/silence.mp3 +0 -0
- package/BookReader/translator-worker.js +475 -0
- package/package.json +6 -3
- package/src/BookNavigator/book-navigator.js +1 -0
- package/src/BookReader/Mode1UpLit.js +6 -1
- package/src/BookReader/Mode2UpLit.js +11 -1
- package/src/BookReader/Navbar/Navbar.js +61 -0
- package/src/BookReader/options.js +12 -8
- package/src/BookReader.js +67 -140
- package/src/assets/images/icon_experiment.svg +1 -0
- package/src/assets/images/translate.svg +1 -0
- package/src/assets/silence.mp3 +0 -0
- package/src/css/_BRnav.scss +0 -24
- package/src/css/_BRsearch.scss +1 -5
- package/src/css/_TextSelection.scss +38 -9
- package/src/plugins/plugin.experiments.js +34 -9
- package/src/plugins/plugin.text_selection.js +17 -20
- package/src/plugins/translate/TranslationManager.js +170 -0
- package/src/plugins/translate/plugin.translate.js +489 -0
- package/src/plugins/tts/AbstractTTSEngine.js +3 -4
- package/src/plugins/tts/PageChunk.js +28 -9
- package/src/plugins/tts/WebTTSEngine.js +5 -7
- package/src/plugins/tts/plugin.tts.js +40 -4
- package/src/plugins/tts/utils.js +21 -22
- package/src/util/cache.js +20 -0
package/src/plugins/tts/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import langs from 'iso-language-codes
|
|
1
|
+
import langs from 'iso-language-codes';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Use regex to approximate word count in a string
|
|
@@ -19,49 +19,48 @@ export function isAndroid(userAgent = navigator.userAgent) {
|
|
|
19
19
|
return /android/i.test(userAgent);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/** @type {{[lang: string]: string}} */
|
|
23
|
+
// Handle odd one-off language pairs that might show up over time
|
|
24
|
+
const specialLangs = {
|
|
25
|
+
"zh-hans": "中文 (Zhōngwén)",
|
|
26
|
+
};
|
|
22
27
|
/**
|
|
23
28
|
* @typedef {string} ISO6391
|
|
24
29
|
* Language code in ISO 639-1 format. e.g. en, fr, zh
|
|
30
|
+
* Can also retrieve language native name + ISO 639-1 code
|
|
25
31
|
**/
|
|
26
32
|
|
|
27
|
-
/** Each lang is an array, with each index mapping to a different property */
|
|
28
|
-
const COLUMN_TO_LANG_INDEX = {
|
|
29
|
-
'Name': 0,
|
|
30
|
-
'Endonym': 1,
|
|
31
|
-
'ISO 639-1': 2,
|
|
32
|
-
'ISO 639-2/T': 3,
|
|
33
|
-
'ISO 639-2/B': 4,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
33
|
/**
|
|
37
34
|
* @param {string} language in some format
|
|
35
|
+
* @param {boolean?} getName gets Native Name + language code if true
|
|
38
36
|
* @return {ISO6391?}
|
|
39
37
|
*/
|
|
40
|
-
export function toISO6391(language) {
|
|
38
|
+
export function toISO6391(language, getName = false) {
|
|
41
39
|
if (!language) return null;
|
|
42
40
|
language = language.toLowerCase();
|
|
43
41
|
|
|
44
|
-
return searchForISO6391(language, ['
|
|
45
|
-
searchForISO6391(language, ['
|
|
46
|
-
searchForISO6391(language, ['
|
|
42
|
+
return searchForISO6391(language, ['iso639_1'], getName) ||
|
|
43
|
+
searchForISO6391(language, ['iso639_2T'], getName) ||
|
|
44
|
+
searchForISO6391(language, ['iso639_2B', 'nativeName', 'name'], getName);
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
48
|
* Searches for the given long in the given columns.
|
|
51
49
|
* @param {string} language
|
|
52
|
-
* @param {Array<keyof
|
|
50
|
+
* @param {Array<keyof import('iso-language-codes').Code>} columnsToSearch
|
|
51
|
+
* @param {boolean?} getName
|
|
53
52
|
* @return {ISO6391?}
|
|
54
53
|
*/
|
|
55
|
-
function searchForISO6391(language, columnsToSearch) {
|
|
56
|
-
for (
|
|
57
|
-
for (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return langs[i][COLUMN_TO_LANG_INDEX['ISO 639-1']];
|
|
54
|
+
function searchForISO6391(language, columnsToSearch, getName) {
|
|
55
|
+
for (const lang of langs) {
|
|
56
|
+
for (const colName of columnsToSearch) {
|
|
57
|
+
if (lang[colName].split(', ').map(x => x.toLowerCase()).indexOf(language) != -1) {
|
|
58
|
+
if (getName) return `${lang.nativeName.split(", ")[0]} (${lang.iso639_1})`;
|
|
59
|
+
return lang.iso639_1;
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
}
|
|
63
|
+
if (specialLangs[language]) return `${specialLangs[language]} (${language})`;
|
|
65
64
|
return null;
|
|
66
65
|
}
|
|
67
66
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
*/
|
|
4
|
+
export class Cache {
|
|
5
|
+
constructor(maxSize = 10) {
|
|
6
|
+
this.maxSize = maxSize;
|
|
7
|
+
/** @type {T[]} */
|
|
8
|
+
this.entries = [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {T} entry
|
|
13
|
+
*/
|
|
14
|
+
add(entry) {
|
|
15
|
+
if (this.entries.length >= this.maxSize) {
|
|
16
|
+
this.entries.shift();
|
|
17
|
+
}
|
|
18
|
+
this.entries.push(entry);
|
|
19
|
+
}
|
|
20
|
+
}
|