react-book-reader 1.0.0 → 1.1.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.
@@ -1,242 +0,0 @@
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
- };