react-book-reader 1.0.0
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/LICENSE +201 -0
- package/README.md +23 -0
- package/lib/comic-book-D2H5riQt.js +29 -0
- package/lib/epub-BZxdKHA1.js +730 -0
- package/lib/fb2-DHUjllK8.js +263 -0
- package/lib/fflate-9VGFqnqw.js +162 -0
- package/lib/fixed-layout-DpOZsuor.js +223 -0
- package/lib/index-DjYU7mCB.js +1720 -0
- package/lib/mobi-Di0D6QEl.js +1036 -0
- package/lib/paginator-zvlJVmJl.js +722 -0
- package/lib/pdf-7wZ7-Bhj.js +563 -0
- package/lib/react-book-reader.es.js +7 -0
- package/lib/react-book-reader.umd.js +715 -0
- package/lib/search-Dw1WQJVD.js +78 -0
- package/lib/tts-CuDZu6rz.js +242 -0
- package/lib/zip-BLPDOR3v.js +1614 -0
- package/package.json +43 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const I = (e) => e.replace(/\s+/g, " "), T = (e, { startIndex: g, startOffset: l, endIndex: a, endOffset: c }) => {
|
|
2
|
+
const r = e[g], s = e[a], m = r === s ? r.slice(l, c) : r.slice(l) + e.slice(r + 1, s).join("") + s.slice(0, c), d = I(r.slice(0, l)).trimStart(), t = I(s.slice(c)).trimEnd(), n = d.length < 50 ? "" : "…", o = t.length < 50 ? "" : "…", i = `${n}${d.slice(-50)}`, u = `${t.slice(0, 50)}${o}`;
|
|
3
|
+
return { pre: i, match: m, post: u };
|
|
4
|
+
}, E = function* (e, g, l = {}) {
|
|
5
|
+
const { locales: a = "en", sensitivity: c } = l, r = c === "variant", s = e.join(""), m = r ? s : s.toLocaleLowerCase(a), d = r ? g : g.toLocaleLowerCase(a), t = d.length;
|
|
6
|
+
let n = -1, o = -1, i = 0;
|
|
7
|
+
do
|
|
8
|
+
if (n = m.indexOf(d, n + 1), n > -1) {
|
|
9
|
+
for (; i <= n; )
|
|
10
|
+
i += e[++o].length;
|
|
11
|
+
const u = o, f = n - (i - e[o].length), h = n + t;
|
|
12
|
+
for (; i <= h; )
|
|
13
|
+
i += e[++o].length;
|
|
14
|
+
const p = o, x = h - (i - e[o].length), y = { startIndex: u, startOffset: f, endIndex: p, endOffset: x };
|
|
15
|
+
yield { range: y, excerpt: T(e, y) };
|
|
16
|
+
}
|
|
17
|
+
while (n > -1);
|
|
18
|
+
}, L = function* (e, g, l = {}) {
|
|
19
|
+
var i;
|
|
20
|
+
const { locales: a = "en", granularity: c = "word", sensitivity: r = "base" } = l;
|
|
21
|
+
let s, m;
|
|
22
|
+
try {
|
|
23
|
+
s = new Intl.Segmenter(a, { usage: "search", granularity: c }), m = new Intl.Collator(a, { sensitivity: r });
|
|
24
|
+
} catch (u) {
|
|
25
|
+
console.warn(u), s = new Intl.Segmenter("en", { usage: "search", granularity: c }), m = new Intl.Collator("en", { sensitivity: r });
|
|
26
|
+
}
|
|
27
|
+
const d = Array.from(s.segment(g)).length, t = [];
|
|
28
|
+
let n = 0, o = s.segment(e[n])[Symbol.iterator]();
|
|
29
|
+
e:
|
|
30
|
+
for (; n < e.length; ) {
|
|
31
|
+
for (; t.length < d; ) {
|
|
32
|
+
const { done: f, value: h } = o.next();
|
|
33
|
+
if (f)
|
|
34
|
+
if (n++, n < e.length) {
|
|
35
|
+
o = s.segment(e[n])[Symbol.iterator]();
|
|
36
|
+
continue;
|
|
37
|
+
} else
|
|
38
|
+
break e;
|
|
39
|
+
const { index: p, segment: x } = h;
|
|
40
|
+
if (/[^\p{Format}]/u.test(x)) {
|
|
41
|
+
if (/\s/u.test(x)) {
|
|
42
|
+
/\s/u.test((i = t[t.length - 1]) == null ? void 0 : i.segment) || t.push({ strIndex: n, index: p, segment: " " });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
h.strIndex = n, t.push(h);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const u = t.map((f) => f.segment).join("");
|
|
49
|
+
if (m.compare(g, u) === 0) {
|
|
50
|
+
const f = n, h = t[t.length - 1], p = h.index + h.segment.length, x = t[0].strIndex, y = t[0].index, w = { startIndex: x, startOffset: y, endIndex: f, endOffset: p };
|
|
51
|
+
yield { range: w, excerpt: T(e, w) };
|
|
52
|
+
}
|
|
53
|
+
t.shift();
|
|
54
|
+
}
|
|
55
|
+
}, C = (e, g, l) => {
|
|
56
|
+
const { granularity: a = "grapheme", sensitivity: c = "base" } = l;
|
|
57
|
+
return !(Intl != null && Intl.Segmenter) || a === "grapheme" && (c === "variant" || c === "accent") ? E(e, g, l) : L(e, g, l);
|
|
58
|
+
}, N = (e, g) => {
|
|
59
|
+
const { defalutLocale: l, matchCase: a, matchDiacritics: c, matchWholeWords: r } = g;
|
|
60
|
+
return function* (s, m) {
|
|
61
|
+
const d = e(s, function* (t, n) {
|
|
62
|
+
for (const o of C(t, m, {
|
|
63
|
+
locales: s.body.lang || s.documentElement.lang || l || "en",
|
|
64
|
+
granularity: r ? "word" : "grapheme",
|
|
65
|
+
sensitivity: c && a ? "variant" : c && !a ? "accent" : !c && a ? "case" : "base"
|
|
66
|
+
})) {
|
|
67
|
+
const { startIndex: i, startOffset: u, endIndex: f, endOffset: h } = o.range;
|
|
68
|
+
o.range = n(i, u, f, h), yield o;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
for (const t of d)
|
|
72
|
+
yield t;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
C as search,
|
|
77
|
+
N as searchMatcher
|
|
78
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
var R = (n, t, e) => {
|
|
2
|
+
if (!t.has(n))
|
|
3
|
+
throw TypeError("Cannot " + e);
|
|
4
|
+
};
|
|
5
|
+
var s = (n, t, e) => (R(n, t, "read from private field"), e ? e.call(n) : t.get(n)), f = (n, t, e) => {
|
|
6
|
+
if (t.has(n))
|
|
7
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
+
t instanceof WeakSet ? t.add(n) : t.set(n, e);
|
|
9
|
+
}, c = (n, t, e, i) => (R(n, t, "write to private field"), i ? i.call(n, e) : t.set(n, e), e);
|
|
10
|
+
var b = (n, t, e) => (R(n, t, "access private method"), e);
|
|
11
|
+
const l = {
|
|
12
|
+
XML: "http://www.w3.org/XML/1998/namespace",
|
|
13
|
+
SSML: "http://www.w3.org/2001/10/synthesis"
|
|
14
|
+
}, D = /* @__PURE__ */ new Set([
|
|
15
|
+
"article",
|
|
16
|
+
"aside",
|
|
17
|
+
"audio",
|
|
18
|
+
"blockquote",
|
|
19
|
+
"caption",
|
|
20
|
+
"details",
|
|
21
|
+
"dialog",
|
|
22
|
+
"div",
|
|
23
|
+
"dl",
|
|
24
|
+
"dt",
|
|
25
|
+
"dd",
|
|
26
|
+
"figure",
|
|
27
|
+
"footer",
|
|
28
|
+
"form",
|
|
29
|
+
"figcaption",
|
|
30
|
+
"h1",
|
|
31
|
+
"h2",
|
|
32
|
+
"h3",
|
|
33
|
+
"h4",
|
|
34
|
+
"h5",
|
|
35
|
+
"h6",
|
|
36
|
+
"header",
|
|
37
|
+
"hgroup",
|
|
38
|
+
"hr",
|
|
39
|
+
"li",
|
|
40
|
+
"main",
|
|
41
|
+
"math",
|
|
42
|
+
"nav",
|
|
43
|
+
"ol",
|
|
44
|
+
"p",
|
|
45
|
+
"pre",
|
|
46
|
+
"section",
|
|
47
|
+
"tr"
|
|
48
|
+
]), _ = (n) => {
|
|
49
|
+
var e;
|
|
50
|
+
const t = n.lang || ((e = n == null ? void 0 : n.getAttributeNS) == null ? void 0 : e.call(n, l.XML, "lang"));
|
|
51
|
+
return t || (n.parentElement ? _(n.parentElement) : null);
|
|
52
|
+
}, O = (n) => {
|
|
53
|
+
var e;
|
|
54
|
+
const t = (e = n == null ? void 0 : n.getAttributeNS) == null ? void 0 : e.call(n, l.XML, "lang");
|
|
55
|
+
return t || (n.parentElement ? O(n.parentElement) : null);
|
|
56
|
+
}, q = (n = "en", t = "word") => {
|
|
57
|
+
const e = new Intl.Segmenter(n, { granularity: t }), i = t === "word";
|
|
58
|
+
return function* (r, a) {
|
|
59
|
+
const g = r.join("");
|
|
60
|
+
let N = 0, o = -1, u = 0;
|
|
61
|
+
for (const { index: x, segment: E, isWordLike: p } of e.segment(g)) {
|
|
62
|
+
if (i && !p)
|
|
63
|
+
continue;
|
|
64
|
+
for (; u <= x; )
|
|
65
|
+
u += r[++o].length;
|
|
66
|
+
const L = o, W = x - (u - r[o].length), v = x + E.length;
|
|
67
|
+
if (v < g.length)
|
|
68
|
+
for (; u <= v; )
|
|
69
|
+
u += r[++o].length;
|
|
70
|
+
const z = o, B = v - (u - r[o].length);
|
|
71
|
+
yield [
|
|
72
|
+
(N++).toString(),
|
|
73
|
+
a(L, W, z, B)
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}, F = (n, t) => {
|
|
78
|
+
const e = document.implementation.createDocument(l.SSML, "speak"), { lang: i } = t;
|
|
79
|
+
i && e.documentElement.setAttributeNS(l.XML, "lang", i);
|
|
80
|
+
const r = (a, g, N) => {
|
|
81
|
+
if (!a)
|
|
82
|
+
return;
|
|
83
|
+
if (a.nodeType === 3)
|
|
84
|
+
return e.createTextNode(a.textContent);
|
|
85
|
+
if (a.nodeType === 4)
|
|
86
|
+
return e.createCDATASection(a.textContent);
|
|
87
|
+
if (a.nodeType !== 1)
|
|
88
|
+
return;
|
|
89
|
+
let o;
|
|
90
|
+
const u = a.nodeName.toLowerCase();
|
|
91
|
+
u === "foliate-mark" ? (o = e.createElementNS(l.SSML, "mark"), o.setAttribute("name", a.dataset.name)) : u === "br" ? o = e.createElementNS(l.SSML, "break") : (u === "em" || u === "strong") && (o = e.createElementNS(l.SSML, "emphasis"));
|
|
92
|
+
const x = a.lang || a.getAttributeNS(l.XML, "lang");
|
|
93
|
+
x && (o || (o = e.createElementNS(l.SSML, "lang")), o.setAttributeNS(l.XML, "lang", x));
|
|
94
|
+
const E = a.getAttributeNS(l.SSML, "alphabet") || N;
|
|
95
|
+
if (!o) {
|
|
96
|
+
const L = a.getAttributeNS(l.SSML, "ph");
|
|
97
|
+
L && (o = e.createElementNS(l.SSML, "phoneme"), E && o.setAttribute("alphabet", E), o.setAttribute("ph", L));
|
|
98
|
+
}
|
|
99
|
+
o || (o = g);
|
|
100
|
+
let p = a.firstChild;
|
|
101
|
+
for (; p; ) {
|
|
102
|
+
const L = r(p, o, E);
|
|
103
|
+
L && o !== L && o.append(L), p = p.nextSibling;
|
|
104
|
+
}
|
|
105
|
+
return o;
|
|
106
|
+
};
|
|
107
|
+
return r(n.firstChild, e.documentElement, t.alphabet), e;
|
|
108
|
+
}, P = (n, t, e) => {
|
|
109
|
+
const i = _(n.commonAncestorContainer), r = O(n.commonAncestorContainer), a = q(i, e), g = n.cloneContents(), N = [...t(n, a)], o = [...t(g, a)];
|
|
110
|
+
for (const [x, E] of o) {
|
|
111
|
+
const p = document.createElement("foliate-mark");
|
|
112
|
+
p.dataset.name = x, E.insertNode(p);
|
|
113
|
+
}
|
|
114
|
+
const u = F(g, { lang: i, alphabet: r });
|
|
115
|
+
return { entries: N, ssml: u };
|
|
116
|
+
}, X = (n) => !n.toString().trim();
|
|
117
|
+
function* j(n) {
|
|
118
|
+
let t;
|
|
119
|
+
const e = n.createTreeWalker(n.body, NodeFilter.SHOW_ELEMENT);
|
|
120
|
+
for (let i = e.nextNode(); i; i = e.nextNode()) {
|
|
121
|
+
const r = i.tagName.toLowerCase();
|
|
122
|
+
D.has(r) && (t && (t.setEndBefore(i), X(t) || (yield t)), t = n.createRange(), t.setStart(i, 0));
|
|
123
|
+
}
|
|
124
|
+
t || (t = n.createRange(), t.setStart(n.body.firstChild ?? n.body, 0)), t.setEndAfter(n.body.lastChild ?? n.body), X(t) || (yield t);
|
|
125
|
+
}
|
|
126
|
+
var h, k, m, d;
|
|
127
|
+
class H {
|
|
128
|
+
constructor(t, e = (i) => i) {
|
|
129
|
+
f(this, h, []);
|
|
130
|
+
f(this, k, void 0);
|
|
131
|
+
f(this, m, -1);
|
|
132
|
+
f(this, d, void 0);
|
|
133
|
+
c(this, k, t), c(this, d, e);
|
|
134
|
+
}
|
|
135
|
+
current() {
|
|
136
|
+
if (s(this, h)[s(this, m)])
|
|
137
|
+
return s(this, d).call(this, s(this, h)[s(this, m)]);
|
|
138
|
+
}
|
|
139
|
+
first() {
|
|
140
|
+
if (s(this, h)[0])
|
|
141
|
+
return c(this, m, 0), s(this, d).call(this, s(this, h)[0]);
|
|
142
|
+
}
|
|
143
|
+
prev() {
|
|
144
|
+
const t = s(this, m) - 1;
|
|
145
|
+
if (s(this, h)[t])
|
|
146
|
+
return c(this, m, t), s(this, d).call(this, s(this, h)[t]);
|
|
147
|
+
}
|
|
148
|
+
next() {
|
|
149
|
+
const t = s(this, m) + 1;
|
|
150
|
+
if (s(this, h)[t])
|
|
151
|
+
return c(this, m, t), s(this, d).call(this, s(this, h)[t]);
|
|
152
|
+
for (; ; ) {
|
|
153
|
+
const { done: e, value: i } = s(this, k).next();
|
|
154
|
+
if (e)
|
|
155
|
+
break;
|
|
156
|
+
if (s(this, h).push(i), s(this, h)[t])
|
|
157
|
+
return c(this, m, t), s(this, d).call(this, s(this, h)[t]);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
find(t) {
|
|
161
|
+
const e = s(this, h).findIndex((i) => t(i));
|
|
162
|
+
if (e > -1)
|
|
163
|
+
return c(this, m, e), s(this, d).call(this, s(this, h)[e]);
|
|
164
|
+
for (; ; ) {
|
|
165
|
+
const { done: i, value: r } = s(this, k).next();
|
|
166
|
+
if (i)
|
|
167
|
+
break;
|
|
168
|
+
if (s(this, h).push(r), t(r))
|
|
169
|
+
return c(this, m, s(this, h).length - 1), s(this, d).call(this, r);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
h = new WeakMap(), k = new WeakMap(), m = new WeakMap(), d = new WeakMap();
|
|
174
|
+
var w, A, S, C, y, I, M, T;
|
|
175
|
+
class G {
|
|
176
|
+
constructor(t, e, i) {
|
|
177
|
+
f(this, y);
|
|
178
|
+
f(this, M);
|
|
179
|
+
f(this, w, void 0);
|
|
180
|
+
f(this, A, void 0);
|
|
181
|
+
f(this, S, void 0);
|
|
182
|
+
f(this, C, new XMLSerializer());
|
|
183
|
+
this.doc = t, this.highlight = i, c(this, w, new H(j(t), (r) => {
|
|
184
|
+
const { entries: a, ssml: g } = P(r, e);
|
|
185
|
+
return c(this, A, new Map(a)), [g, r];
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
start() {
|
|
189
|
+
c(this, S, null);
|
|
190
|
+
const [t] = s(this, w).first() ?? [];
|
|
191
|
+
return t ? b(this, M, T).call(this, t, (e) => b(this, y, I).call(this, e, s(this, S))) : this.next();
|
|
192
|
+
}
|
|
193
|
+
resume() {
|
|
194
|
+
const [t] = s(this, w).current() ?? [];
|
|
195
|
+
return t ? b(this, M, T).call(this, t, (e) => b(this, y, I).call(this, e, s(this, S))) : this.next();
|
|
196
|
+
}
|
|
197
|
+
prev(t) {
|
|
198
|
+
c(this, S, null);
|
|
199
|
+
const [e, i] = s(this, w).prev() ?? [];
|
|
200
|
+
return t && i && this.highlight(i.cloneRange()), b(this, M, T).call(this, e);
|
|
201
|
+
}
|
|
202
|
+
next(t) {
|
|
203
|
+
c(this, S, null);
|
|
204
|
+
const [e, i] = s(this, w).next() ?? [];
|
|
205
|
+
return t && i && this.highlight(i.cloneRange()), b(this, M, T).call(this, e);
|
|
206
|
+
}
|
|
207
|
+
from(t) {
|
|
208
|
+
c(this, S, null);
|
|
209
|
+
const [e] = s(this, w).find((r) => t.compareBoundaryPoints(Range.END_TO_START, r) <= 0);
|
|
210
|
+
let i;
|
|
211
|
+
for (const [r, a] of s(this, A).entries())
|
|
212
|
+
if (t.compareBoundaryPoints(Range.START_TO_START, a) <= 0) {
|
|
213
|
+
i = r;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
return b(this, M, T).call(this, e, (r) => b(this, y, I).call(this, r, i));
|
|
217
|
+
}
|
|
218
|
+
setMark(t) {
|
|
219
|
+
const e = s(this, A).get(t);
|
|
220
|
+
e && (c(this, S, t), this.highlight(e.cloneRange()));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
w = new WeakMap(), A = new WeakMap(), S = new WeakMap(), C = new WeakMap(), y = new WeakSet(), I = function(t, e) {
|
|
224
|
+
return e ? t.querySelector(`mark[name="${CSS.escape(e)}"`) : null;
|
|
225
|
+
}, M = new WeakSet(), T = function(t, e) {
|
|
226
|
+
var a, g;
|
|
227
|
+
if (!t)
|
|
228
|
+
return;
|
|
229
|
+
if (!e)
|
|
230
|
+
return s(this, C).serializeToString(t);
|
|
231
|
+
const i = document.implementation.createDocument(l.SSML, "speak");
|
|
232
|
+
i.documentElement.replaceWith(i.importNode(t.documentElement, !0));
|
|
233
|
+
let r = (a = e(i)) == null ? void 0 : a.previousSibling;
|
|
234
|
+
for (; r; ) {
|
|
235
|
+
const N = r.previousSibling ?? ((g = r.parentNode) == null ? void 0 : g.previousSibling);
|
|
236
|
+
r.parentNode.removeChild(r), r = N;
|
|
237
|
+
}
|
|
238
|
+
return s(this, C).serializeToString(i);
|
|
239
|
+
};
|
|
240
|
+
export {
|
|
241
|
+
G as TTS
|
|
242
|
+
};
|