react-book-reader 1.1.6 → 1.1.8

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,109 +0,0 @@
1
- const h = async (e, i, t) => {
2
- const o = t * devicePixelRatio;
3
- i.documentElement.style.transform = `scale(${1 / devicePixelRatio})`, i.documentElement.style.transformOrigin = "top left", i.documentElement.style.setProperty("--scale-factor", o);
4
- const n = e.getViewport({ scale: o }), s = document.createElement("canvas");
5
- s.height = n.height, s.width = n.width;
6
- const g = s.getContext("2d");
7
- await e.render({ canvasContext: g, viewport: n }).promise, i.querySelector("#canvas").replaceChildren(i.adoptNode(s));
8
- const c = i.querySelector(".textLayer");
9
- await new pdfjsLib.TextLayer({
10
- textContentSource: await e.streamTextContent(),
11
- container: c,
12
- viewport: n
13
- }).render();
14
- for (const l of document.querySelectorAll(".hiddenCanvasElement"))
15
- Object.assign(l.style, {
16
- position: "absolute",
17
- top: "0",
18
- left: "0",
19
- width: "0",
20
- height: "0",
21
- display: "none"
22
- });
23
- const a = document.createElement("div");
24
- a.className = "endOfContent", c.append(a), c.onpointerdown = () => c.classList.add("selecting"), c.onpointerup = () => c.classList.remove("selecting");
25
- const d = i.querySelector(".annotationLayer");
26
- await new pdfjsLib.AnnotationLayer({ page: e, viewport: n, div: d }).render({
27
- annotations: await e.getAnnotations(),
28
- linkService: {
29
- goToDestination: () => {
30
- },
31
- getDestinationHash: (l) => JSON.stringify(l),
32
- addLinkAttributes: (l, p) => l.href = p
33
- }
34
- });
35
- }, u = async (e, i) => {
36
- const t = e.getViewport({ scale: 1 });
37
- if (i) {
38
- const s = document.createElement("canvas");
39
- s.height = t.height, s.width = t.width;
40
- const g = s.getContext("2d");
41
- return await e.render({ canvasContext: g, viewport: t }).promise, new Promise((c) => s.toBlob(c));
42
- }
43
- return { src: URL.createObjectURL(new Blob([`
44
- <!DOCTYPE html>
45
- <html lang="en">
46
- <meta charset="utf-8">
47
- <meta name="viewport" content="width=${t.width}, height=${t.height}">
48
- <style>
49
- html, body {
50
- margin: 0;
51
- padding: 0;
52
- }
53
- </style>
54
- <div id="canvas"></div>
55
- <div class="textLayer"></div>
56
- <div class="annotationLayer"></div>
57
- `], { type: "text/html" })), onZoom: ({ doc: s, scale: g }) => h(e, s, g) };
58
- }, m = (e) => ({
59
- label: e.title,
60
- href: JSON.stringify(e.dest),
61
- subitems: e.items.length ? e.items.map(m) : null
62
- }), y = async (e) => {
63
- const i = new pdfjsLib.PDFDataRangeTransport(e.size, []);
64
- i.requestDataRange = (r, a) => {
65
- e.slice(r, a).arrayBuffer().then((d) => {
66
- i.onDataRange(r, d);
67
- });
68
- };
69
- const t = await pdfjsLib.getDocument({
70
- range: i,
71
- // cMapUrl: pdfjsPath('cmaps/'),
72
- // standardFontDataUrl: pdfjsPath('standard_fonts/'),
73
- isEvalSupported: !1
74
- }).promise, o = { rendition: { layout: "pre-paginated" } }, { metadata: n, info: s } = await t.getMetadata() ?? {};
75
- o.metadata = {
76
- title: n?.get("dc:title") ?? s?.Title,
77
- author: n?.get("dc:creator") ?? s?.Author,
78
- contributor: n?.get("dc:contributor"),
79
- description: n?.get("dc:description") ?? s?.Subject,
80
- language: n?.get("dc:language"),
81
- publisher: n?.get("dc:publisher"),
82
- subject: n?.get("dc:subject"),
83
- identifier: n?.get("dc:identifier"),
84
- source: n?.get("dc:source"),
85
- rights: n?.get("dc:rights")
86
- };
87
- const g = await t.getOutline();
88
- o.toc = g?.map(m);
89
- const c = /* @__PURE__ */ new Map();
90
- return o.sections = Array.from({ length: t.numPages }).map((r, a) => ({
91
- id: a,
92
- load: async () => {
93
- const d = c.get(a);
94
- if (d) return d;
95
- const l = await u(await t.getPage(a + 1));
96
- return c.set(a, l), l;
97
- },
98
- size: 1e3
99
- })), o.isExternal = (r) => /^\w+:/i.test(r), o.resolveHref = async (r) => {
100
- const a = JSON.parse(r), d = typeof a == "string" ? await t.getDestination(a) : a;
101
- return { index: await t.getPageIndex(d[0]) };
102
- }, o.splitTOCHref = async (r) => {
103
- const a = JSON.parse(r), d = typeof a == "string" ? await t.getDestination(a) : a;
104
- return [await t.getPageIndex(d[0]), null];
105
- }, o.getTOCFragment = (r) => r.documentElement, o.getCover = async () => u(await t.getPage(1), !0), o.destroy = () => t.destroy(), o;
106
- };
107
- export {
108
- y as makePDF
109
- };
@@ -1,72 +0,0 @@
1
- const w = (e) => e.replace(/\s+/g, " "), I = (e, { startIndex: g, startOffset: a, endIndex: l, endOffset: c }) => {
2
- const r = e[g], o = e[l], h = r === o ? r.slice(a, c) : r.slice(a) + e.slice(r + 1, o).join("") + o.slice(0, c), u = w(r.slice(0, a)).trimStart(), n = w(o.slice(c)).trimEnd(), t = u.length < 50 ? "" : "…", i = n.length < 50 ? "" : "…", s = `${t}${u.slice(-50)}`, m = `${n.slice(0, 50)}${i}`;
3
- return { pre: s, match: h, post: m };
4
- }, T = function* (e, g, a = {}) {
5
- const { locales: l = "en", sensitivity: c } = a, r = c === "variant", o = e.join(""), h = r ? o : o.toLocaleLowerCase(l), u = r ? g : g.toLocaleLowerCase(l), n = u.length;
6
- let t = -1, i = -1, s = 0;
7
- do
8
- if (t = h.indexOf(u, t + 1), t > -1) {
9
- for (; s <= t; ) s += e[++i].length;
10
- const m = i, d = t - (s - e[i].length), f = t + n;
11
- for (; s <= f; ) s += e[++i].length;
12
- const x = i, y = f - (s - e[i].length), p = { startIndex: m, startOffset: d, endIndex: x, endOffset: y };
13
- yield { range: p, excerpt: I(e, p) };
14
- }
15
- while (t > -1);
16
- }, E = function* (e, g, a = {}) {
17
- const { locales: l = "en", granularity: c = "word", sensitivity: r = "base" } = a;
18
- let o, h;
19
- try {
20
- o = new Intl.Segmenter(l, { usage: "search", granularity: c }), h = new Intl.Collator(l, { sensitivity: r });
21
- } catch (s) {
22
- console.warn(s), o = new Intl.Segmenter("en", { usage: "search", granularity: c }), h = new Intl.Collator("en", { sensitivity: r });
23
- }
24
- const u = Array.from(o.segment(g)).length, n = [];
25
- let t = 0, i = o.segment(e[t])[Symbol.iterator]();
26
- e: for (; t < e.length; ) {
27
- for (; n.length < u; ) {
28
- const { done: m, value: d } = i.next();
29
- if (m)
30
- if (t++, t < e.length) {
31
- i = o.segment(e[t])[Symbol.iterator]();
32
- continue;
33
- } else break e;
34
- const { index: f, segment: x } = d;
35
- if (/[^\p{Format}]/u.test(x)) {
36
- if (/\s/u.test(x)) {
37
- /\s/u.test(n[n.length - 1]?.segment) || n.push({ strIndex: t, index: f, segment: " " });
38
- continue;
39
- }
40
- d.strIndex = t, n.push(d);
41
- }
42
- }
43
- const s = n.map((m) => m.segment).join("");
44
- if (h.compare(g, s) === 0) {
45
- const m = t, d = n[n.length - 1], f = d.index + d.segment.length, x = n[0].strIndex, y = n[0].index, p = { startIndex: x, startOffset: y, endIndex: m, endOffset: f };
46
- yield { range: p, excerpt: I(e, p) };
47
- }
48
- n.shift();
49
- }
50
- }, L = (e, g, a) => {
51
- const { granularity: l = "grapheme", sensitivity: c = "base" } = a;
52
- return !Intl?.Segmenter || l === "grapheme" && (c === "variant" || c === "accent") ? T(e, g, a) : E(e, g, a);
53
- }, C = (e, g) => {
54
- const { defaultLocale: a, matchCase: l, matchDiacritics: c, matchWholeWords: r, acceptNode: o } = g;
55
- return function* (h, u) {
56
- const n = e(h, function* (t, i) {
57
- for (const s of L(t, u, {
58
- locales: h.body.lang || h.documentElement.lang || a || "en",
59
- granularity: r ? "word" : "grapheme",
60
- sensitivity: c && l ? "variant" : c && !l ? "accent" : !c && l ? "case" : "base"
61
- })) {
62
- const { startIndex: m, startOffset: d, endIndex: f, endOffset: x } = s.range;
63
- s.range = i(m, d, f, x), yield s;
64
- }
65
- }, o);
66
- for (const t of n) yield t;
67
- };
68
- };
69
- export {
70
- L as search,
71
- C as searchMatcher
72
- };
@@ -1,212 +0,0 @@
1
- const a = {
2
- XML: "http://www.w3.org/XML/1998/namespace",
3
- SSML: "http://www.w3.org/2001/10/synthesis"
4
- }, M = /* @__PURE__ */ new Set([
5
- "article",
6
- "aside",
7
- "audio",
8
- "blockquote",
9
- "caption",
10
- "details",
11
- "dialog",
12
- "div",
13
- "dl",
14
- "dt",
15
- "dd",
16
- "figure",
17
- "footer",
18
- "form",
19
- "figcaption",
20
- "h1",
21
- "h2",
22
- "h3",
23
- "h4",
24
- "h5",
25
- "h6",
26
- "header",
27
- "hgroup",
28
- "hr",
29
- "li",
30
- "main",
31
- "math",
32
- "nav",
33
- "ol",
34
- "p",
35
- "pre",
36
- "section",
37
- "tr"
38
- ]), p = (s) => {
39
- const t = s.lang || s?.getAttributeNS?.(a.XML, "lang");
40
- return t || (s.parentElement ? p(s.parentElement) : null);
41
- }, b = (s) => {
42
- const t = s?.getAttributeNS?.(a.XML, "lang");
43
- return t || (s.parentElement ? b(s.parentElement) : null);
44
- }, N = (s = "en", t = "word") => {
45
- const e = new Intl.Segmenter(s, { granularity: t }), n = t === "word";
46
- return function* (i, o) {
47
- const l = i.join("");
48
- let g = 0, r = -1, h = 0;
49
- for (const { index: u, segment: f, isWordLike: c } of e.segment(l)) {
50
- if (n && !c) continue;
51
- for (; h <= u; ) h += i[++r].length;
52
- const m = r, w = u - (h - i[r].length), d = u + f.length - 1;
53
- if (d < l.length) for (; h <= d; ) h += i[++r].length;
54
- const x = r, L = d - (h - i[r].length) + 1;
55
- yield [
56
- (g++).toString(),
57
- o(m, w, x, L)
58
- ];
59
- }
60
- };
61
- }, E = (s, t) => {
62
- const e = document.implementation.createDocument(a.SSML, "speak"), { lang: n } = t;
63
- n && e.documentElement.setAttributeNS(a.XML, "lang", n);
64
- const i = (o, l, g) => {
65
- if (!o) return;
66
- if (o.nodeType === 3) return e.createTextNode(o.textContent);
67
- if (o.nodeType === 4) return e.createCDATASection(o.textContent);
68
- if (o.nodeType !== 1) return;
69
- let r;
70
- const h = o.nodeName.toLowerCase();
71
- h === "foliate-mark" ? (r = e.createElementNS(a.SSML, "mark"), r.setAttribute("name", o.dataset.name)) : h === "br" ? r = e.createElementNS(a.SSML, "break") : (h === "em" || h === "strong") && (r = e.createElementNS(a.SSML, "emphasis"));
72
- const u = o.lang || o.getAttributeNS(a.XML, "lang");
73
- u && (r || (r = e.createElementNS(a.SSML, "lang")), r.setAttributeNS(a.XML, "lang", u));
74
- const f = o.getAttributeNS(a.SSML, "alphabet") || g;
75
- if (!r) {
76
- const m = o.getAttributeNS(a.SSML, "ph");
77
- m && (r = e.createElementNS(a.SSML, "phoneme"), f && r.setAttribute("alphabet", f), r.setAttribute("ph", m));
78
- }
79
- r || (r = l);
80
- let c = o.firstChild;
81
- for (; c; ) {
82
- const m = i(c, r, f);
83
- m && r !== m && r.append(m), c = c.nextSibling;
84
- }
85
- return r;
86
- };
87
- return i(s.firstChild, e.documentElement, t.alphabet), e;
88
- }, T = (s, t, e) => {
89
- const n = p(s.commonAncestorContainer), i = b(s.commonAncestorContainer), o = N(n, e), l = s.cloneContents(), g = [...t(s, o)], r = [...t(l, o)];
90
- for (const [u, f] of r) {
91
- const c = document.createElement("foliate-mark");
92
- c.dataset.name = u, f.insertNode(c);
93
- }
94
- const h = E(l, { lang: n, alphabet: i });
95
- return { entries: g, ssml: h };
96
- }, S = (s) => !s.toString().trim();
97
- function* k(s) {
98
- let t;
99
- const e = s.createTreeWalker(s.body, NodeFilter.SHOW_ELEMENT);
100
- for (let n = e.nextNode(); n; n = e.nextNode()) {
101
- const i = n.tagName.toLowerCase();
102
- M.has(i) && (t && (t.setEndBefore(n), S(t) || (yield t)), t = s.createRange(), t.setStart(n, 0));
103
- }
104
- t || (t = s.createRange(), t.setStart(s.body.firstChild ?? s.body, 0)), t.setEndAfter(s.body.lastChild ?? s.body), S(t) || (yield t);
105
- }
106
- class A {
107
- #t = [];
108
- #i;
109
- #e = -1;
110
- #n;
111
- constructor(t, e = (n) => n) {
112
- this.#i = t, this.#n = e;
113
- }
114
- current() {
115
- if (this.#t[this.#e]) return this.#n(this.#t[this.#e]);
116
- }
117
- first() {
118
- if (this.#t[0])
119
- return this.#e = 0, this.#n(this.#t[0]);
120
- }
121
- prev() {
122
- const t = this.#e - 1;
123
- if (this.#t[t])
124
- return this.#e = t, this.#n(this.#t[t]);
125
- }
126
- next() {
127
- const t = this.#e + 1;
128
- if (this.#t[t])
129
- return this.#e = t, this.#n(this.#t[t]);
130
- for (; ; ) {
131
- const { done: e, value: n } = this.#i.next();
132
- if (e) break;
133
- if (this.#t.push(n), this.#t[t])
134
- return this.#e = t, this.#n(this.#t[t]);
135
- }
136
- }
137
- find(t) {
138
- const e = this.#t.findIndex((n) => t(n));
139
- if (e > -1)
140
- return this.#e = e, this.#n(this.#t[e]);
141
- for (; ; ) {
142
- const { done: n, value: i } = this.#i.next();
143
- if (n) break;
144
- if (this.#t.push(i), t(i))
145
- return this.#e = this.#t.length - 1, this.#n(i);
146
- }
147
- }
148
- }
149
- class y {
150
- #t;
151
- #i;
152
- #e;
153
- #n = new XMLSerializer();
154
- constructor(t, e, n, i) {
155
- this.doc = t, this.highlight = n, this.#t = new A(k(t), (o) => {
156
- const { entries: l, ssml: g } = T(o, e, i);
157
- return this.#i = new Map(l), [g, o];
158
- });
159
- }
160
- #r(t, e) {
161
- return e ? t.querySelector(`mark[name="${CSS.escape(e)}"`) : null;
162
- }
163
- #s(t, e) {
164
- if (!t) return;
165
- if (!e) return this.#n.serializeToString(t);
166
- const n = document.implementation.createDocument(a.SSML, "speak");
167
- n.documentElement.replaceWith(n.importNode(t.documentElement, !0));
168
- let i = e(n)?.previousSibling;
169
- for (; i; ) {
170
- const o = i.previousSibling ?? i.parentNode?.previousSibling;
171
- i.parentNode.removeChild(i), i = o;
172
- }
173
- return this.#n.serializeToString(n);
174
- }
175
- start() {
176
- this.#e = null;
177
- const [t] = this.#t.first() ?? [];
178
- return t ? this.#s(t, (e) => this.#r(e, this.#e)) : this.next();
179
- }
180
- resume() {
181
- const [t] = this.#t.current() ?? [];
182
- return t ? this.#s(t, (e) => this.#r(e, this.#e)) : this.next();
183
- }
184
- prev(t) {
185
- this.#e = null;
186
- const [e, n] = this.#t.prev() ?? [];
187
- return t && n && this.highlight(n.cloneRange()), this.#s(e);
188
- }
189
- next(t) {
190
- this.#e = null;
191
- const [e, n] = this.#t.next() ?? [];
192
- return t && n && this.highlight(n.cloneRange()), this.#s(e);
193
- }
194
- from(t) {
195
- this.#e = null;
196
- const [e] = this.#t.find((i) => t.compareBoundaryPoints(Range.END_TO_START, i) <= 0);
197
- let n;
198
- for (const [i, o] of this.#i.entries())
199
- if (t.compareBoundaryPoints(Range.START_TO_START, o) <= 0) {
200
- n = i;
201
- break;
202
- }
203
- return this.#s(e, (i) => this.#r(i, n));
204
- }
205
- setMark(t) {
206
- const e = this.#i.get(t);
207
- e && (this.#e = t, this.highlight(e.cloneRange()));
208
- }
209
- }
210
- export {
211
- y as TTS
212
- };