@internetarchive/bookreader 5.0.0-114 → 5.0.0-116
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.map +1 -1
- package/BookReader/BookReader.css +27 -10
- package/BookReader/BookReader.js +1 -43
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +63 -39
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +2 -2
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.experiments.js.map +1 -1
- package/BookReader/plugins/plugin.iframe.js +1 -1
- package/BookReader/plugins/plugin.iframe.js.map +1 -1
- package/BookReader/plugins/plugin.iiif.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1 -1
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +43 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.translate.js +45 -3
- package/BookReader/plugins/plugin.translate.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- package/BookReader/plugins/translator-worker.js.map +1 -1
- package/BookReader/webcomponents-bundle.js.map +1 -1
- package/jsconfig.json +2 -3
- package/package.json +41 -32
- package/src/BookReader/utils/SelectionObserver.js +4 -2
- package/src/BookReader.js +10 -21
- package/src/css/_TextSelection.scss +25 -10
- package/src/plugins/plugin.iiif.js +7 -1
- package/src/plugins/plugin.text_selection.js +4 -90
- package/src/plugins/search/plugin.search.js +2 -0
- package/src/plugins/tts/WebTTSEngine.js +2 -2
- package/src/plugins/tts/utils.js +0 -9
- package/src/plugins/url/UrlPlugin.js +12 -0
- package/src/util/TextSelectionManager.js +246 -173
- package/src/util/browserSniffing.js +9 -0
- package/src/util/generators.js +89 -0
|
@@ -51,6 +51,15 @@ export function isIOS() {
|
|
|
51
51
|
return 'ongesturestart' in window && navigator.maxTouchPoints > 0;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether the current browser is on android
|
|
56
|
+
* @param {string} [userAgent]
|
|
57
|
+
* @return {boolean}
|
|
58
|
+
*/
|
|
59
|
+
export function isAndroid(userAgent = navigator.userAgent) {
|
|
60
|
+
return /android/i.test(userAgent);
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
/**
|
|
55
64
|
* Checks whether the current browser is Samsung Internet
|
|
56
65
|
* https://stackoverflow.com/a/40684162/2317712
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @template T
|
|
5
|
+
* Get the i-th element of an iterable
|
|
6
|
+
* @param {Iterable<T>} iterable
|
|
7
|
+
* @param {number} index
|
|
8
|
+
*/
|
|
9
|
+
export function genAt(iterable, index) {
|
|
10
|
+
let i = 0;
|
|
11
|
+
for (const x of iterable) {
|
|
12
|
+
if (i == index) return x;
|
|
13
|
+
i++;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @template T
|
|
20
|
+
* Generator version of filter
|
|
21
|
+
* @param {Iterable<T>} iterable
|
|
22
|
+
* @param {function(T): boolean} fn
|
|
23
|
+
*/
|
|
24
|
+
export function* genFilter(iterable, fn) {
|
|
25
|
+
for (const x of iterable) {
|
|
26
|
+
if (fn(x)) yield x;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @template TFrom, TTo
|
|
32
|
+
* Generator version of map
|
|
33
|
+
* @param {Iterable<TFrom>} gen
|
|
34
|
+
* @param {function(TFrom): TTo} fn
|
|
35
|
+
* @returns {Iterable<TTo>}
|
|
36
|
+
*/
|
|
37
|
+
export function* genMap(gen, fn) {
|
|
38
|
+
for (const x of gen) yield fn(x);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @template T
|
|
43
|
+
* Generator that provides a sliding window of 3 elements,
|
|
44
|
+
* prev, current, and next.
|
|
45
|
+
* @param {Iterable<T>} gen
|
|
46
|
+
* @returns {Iterable<[T | undefined, T, T | undefined]>}
|
|
47
|
+
*/
|
|
48
|
+
export function* lookAroundWindow(gen) {
|
|
49
|
+
let prev = undefined;
|
|
50
|
+
let cur = undefined;
|
|
51
|
+
let next = undefined;
|
|
52
|
+
for (const x of gen) {
|
|
53
|
+
if (typeof cur !== 'undefined') {
|
|
54
|
+
next = x;
|
|
55
|
+
yield [prev, cur, next];
|
|
56
|
+
}
|
|
57
|
+
prev = cur;
|
|
58
|
+
cur = x;
|
|
59
|
+
next = undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof cur !== 'undefined') {
|
|
63
|
+
yield [prev, cur, next];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @template T1, T2
|
|
69
|
+
* Lazy zip implementation to avoid importing lodash
|
|
70
|
+
* Expects iterators to be of the same length
|
|
71
|
+
* @param {Iterable<T1>} gen1
|
|
72
|
+
* @param {Iterable<T2>} gen2
|
|
73
|
+
* @returns {Iterable<[T1, T2]>}
|
|
74
|
+
*/
|
|
75
|
+
export function* zip(gen1, gen2) {
|
|
76
|
+
const it1 = gen1[Symbol.iterator]();
|
|
77
|
+
const it2 = gen2[Symbol.iterator]();
|
|
78
|
+
while (true) {
|
|
79
|
+
const r1 = it1.next();
|
|
80
|
+
const r2 = it2.next();
|
|
81
|
+
if (r1.done && r2.done) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (r1.done || r2.done) {
|
|
85
|
+
throw new Error('zip: one of the iterators is done');
|
|
86
|
+
}
|
|
87
|
+
yield [r1.value, r2.value];
|
|
88
|
+
}
|
|
89
|
+
}
|