@internetarchive/bookreader 5.0.0-88 → 5.0.0-89
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/BookReader.css +14 -0
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.iiif.js +1 -1
- package/BookReader/plugins/plugin.iiif.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.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.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/CHANGELOG.md +10 -0
- package/codecov.yml +1 -1
- package/package.json +1 -1
- package/src/BookReader/ImageCache.js +48 -15
- package/src/BookReader/Mode2UpLit.js +3 -2
- package/src/BookReader/PageContainer.js +41 -22
- package/src/BookReader/options.js +24 -3
- package/src/BookReader/utils.js +10 -0
- package/src/BookReader.js +89 -38
- package/src/BookReaderPlugin.js +16 -0
- package/src/css/_BRpages.scss +21 -2
- package/src/plugins/plugin.autoplay.js +98 -102
- package/src/plugins/plugin.iiif.js +16 -30
- package/src/plugins/plugin.resume.js +54 -51
- package/src/plugins/plugin.text_selection.js +68 -76
- package/src/plugins/tts/AbstractTTSEngine.js +2 -4
- package/src/plugins/tts/PageChunk.js +5 -9
- package/src/plugins/tts/PageChunkIterator.js +3 -5
- package/src/plugins/tts/plugin.tts.js +309 -329
- package/src/plugins/url/plugin.url.js +1 -1
- package/src/util/strings.js +1 -0
- package/tests/e2e/autoplay.test.js +8 -5
- package/tests/e2e/helpers/base.js +2 -2
- package/tests/e2e/helpers/mockSearch.js +6 -9
- package/tests/jest/BookReader/PageContainer.test.js +96 -55
- package/tests/jest/BookReader/utils.test.js +21 -0
- package/tests/jest/BookReader.test.js +13 -12
- package/tests/jest/plugins/plugin.autoplay.test.js +9 -22
- package/tests/jest/plugins/plugin.resume.test.js +19 -32
- package/tests/jest/plugins/plugin.text_selection.test.js +23 -24
@@ -1,8 +1,7 @@
|
|
1
1
|
import sinon from 'sinon';
|
2
2
|
|
3
|
-
import '@/src/BookReader.js';
|
3
|
+
import BookReader from '@/src/BookReader.js';
|
4
4
|
import {
|
5
|
-
BookreaderWithTextSelection,
|
6
5
|
Cache,
|
7
6
|
genMap,
|
8
7
|
lookAroundWindow,
|
@@ -87,7 +86,7 @@ const FAKE_XML_EMPTY = '';
|
|
87
86
|
|
88
87
|
describe("Generic tests", () => {
|
89
88
|
document.body.innerHTML = '<div id="BookReader">';
|
90
|
-
const br = window.br = new
|
89
|
+
const br = window.br = new BookReader({
|
91
90
|
data: [
|
92
91
|
[
|
93
92
|
{ width: 800, height: 1200,
|
@@ -115,8 +114,8 @@ describe("Generic tests", () => {
|
|
115
114
|
});
|
116
115
|
|
117
116
|
test("_createPageContainer overridden function still creates a BRpagecontainer element", () => {
|
118
|
-
const spy = sinon.spy(br.
|
119
|
-
sinon.stub(br.
|
117
|
+
const spy = sinon.spy(br._plugins.textSelection, 'createTextLayer');
|
118
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
120
119
|
.returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
|
121
120
|
const container = br._createPageContainer(1, {});
|
122
121
|
expect(container).toBeTruthy();
|
@@ -125,24 +124,24 @@ describe("Generic tests", () => {
|
|
125
124
|
|
126
125
|
// test loading first object from sample data
|
127
126
|
test("_createPageContainer handles index 0", () => {
|
128
|
-
const spy = sinon.spy(br.
|
127
|
+
const spy = sinon.spy(br._plugins.textSelection, 'createTextLayer');
|
129
128
|
br._createPageContainer(0, {});
|
130
129
|
expect(spy.callCount).toBe(1);
|
131
130
|
});
|
132
131
|
|
133
132
|
// test loading last object from sample data
|
134
133
|
test("_createPageContainer handles index -1", () => {
|
135
|
-
const spy = sinon.spy(br.
|
134
|
+
const spy = sinon.spy(br._plugins.textSelection, 'createTextLayer');
|
136
135
|
br._createPageContainer(-1, {});
|
137
136
|
expect(spy.callCount).toBe(0);
|
138
137
|
});
|
139
138
|
|
140
139
|
test("createTextLayer will render the last page and create text layer properly", async () => {
|
141
140
|
const $container = br.refs.$brContainer;
|
142
|
-
sinon.stub(br.
|
141
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
143
142
|
.returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
|
144
143
|
const pageIndex = br.data.length - 1;
|
145
|
-
await br.
|
144
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: pageIndex, width: 100, height: 100 }});
|
146
145
|
expect($container.find(".BRtextLayer").length).toBe(1);
|
147
146
|
expect($container.find("p").length).toBe(1);
|
148
147
|
});
|
@@ -150,9 +149,9 @@ describe("Generic tests", () => {
|
|
150
149
|
test("createTextLayer will not create text layer if there are too many words", async () => {
|
151
150
|
const $container = br.refs.$brContainer;
|
152
151
|
const xml = FAKE_XML_1WORD.replace(/<WORD.*<\/WORD>/, FAKE_XML_1WORD.match(/<WORD.*<\/WORD>/)[0].repeat(3000));
|
153
|
-
sinon.stub(br.
|
152
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
154
153
|
.returns($(new DOMParser().parseFromString(xml, "text/xml")));
|
155
|
-
await br.
|
154
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: 0, width: 100, height: 100 }});
|
156
155
|
expect($container.find(".BRtextLayer").length).toBe(0);
|
157
156
|
expect($container.find("p").length).toBe(0);
|
158
157
|
expect($container.find(".BRwordElement").length).toBe(0);
|
@@ -160,9 +159,9 @@ describe("Generic tests", () => {
|
|
160
159
|
|
161
160
|
test("createTextLayer creates text layer with paragraph with 1 word element", async () => {
|
162
161
|
const $container = br.refs.$brContainer;
|
163
|
-
sinon.stub(br.
|
162
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
164
163
|
.returns($(new DOMParser().parseFromString(FAKE_XML_1WORD, "text/xml")));
|
165
|
-
await br.
|
164
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: 1, width: 100, height: 100 }});
|
166
165
|
expect($container.find(".BRtextLayer").length).toBe(1);
|
167
166
|
expect($container.find("p").length).toBe(1);
|
168
167
|
expect($container.find(".BRwordElement").length).toBe(1);
|
@@ -171,9 +170,9 @@ describe("Generic tests", () => {
|
|
171
170
|
|
172
171
|
test("createTextLayer creates text layer with paragraph with multiple word elements", async () => {
|
173
172
|
const $container = br.refs.$brContainer;
|
174
|
-
sinon.stub(br.
|
173
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
175
174
|
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_WORDS, "text/xml")));
|
176
|
-
await br.
|
175
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: 2, width: 100, height: 100 }});
|
177
176
|
expect($container.find(".BRtextLayer").length).toBe(1);
|
178
177
|
expect($container.find("p").length).toBe(1);
|
179
178
|
expect($container.find(".BRwordElement").length).toBe(3);
|
@@ -182,9 +181,9 @@ describe("Generic tests", () => {
|
|
182
181
|
|
183
182
|
test("createTextLayer creates text layer with paragraph with word with 5 params coordinates", async () => {
|
184
183
|
const $container = br.refs.$brContainer;
|
185
|
-
sinon.stub(br.
|
184
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
186
185
|
.returns($(new DOMParser().parseFromString(FAKE_XML_5COORDS, "text/xml")));
|
187
|
-
await br.
|
186
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
188
187
|
expect($container.find(".BRtextLayer").length).toBe(1);
|
189
188
|
expect($container.find("p").length).toBe(1);
|
190
189
|
expect($container.find(".BRwordElement").length).toBe(1);
|
@@ -192,9 +191,9 @@ describe("Generic tests", () => {
|
|
192
191
|
|
193
192
|
test("createTextLayer handles multiple lines", async () => {
|
194
193
|
const $container = br.refs.$brContainer;
|
195
|
-
sinon.stub(br.
|
194
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
196
195
|
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
|
197
|
-
await br.
|
196
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
198
197
|
expect($container.find(".BRtextLayer").length).toBe(1);
|
199
198
|
expect($container.find("p").length).toBe(1);
|
200
199
|
expect($container.find(".BRlineElement").length).toBe(3);
|
@@ -207,9 +206,9 @@ describe("Generic tests", () => {
|
|
207
206
|
|
208
207
|
test("createTextLayer repairs trailing hyphens", async () => {
|
209
208
|
const $container = br.refs.$brContainer;
|
210
|
-
sinon.stub(br.
|
209
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
211
210
|
.returns($(new DOMParser().parseFromString(FAKE_XML_MULT_LINES, "text/xml")));
|
212
|
-
await br.
|
211
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: 3, width: 100, height: 100 }});
|
213
212
|
|
214
213
|
expect($container.find(".BRwordElement--hyphen").length).toBe(1);
|
215
214
|
expect($container.find(".BRwordElement--hyphen").closest(".BRlineElement").text().endsWith(' ')).toBe(false);
|
@@ -218,9 +217,9 @@ describe("Generic tests", () => {
|
|
218
217
|
|
219
218
|
test("createTextLayer can handle empty xml", async () => {
|
220
219
|
const $container = br.refs.$brContainer;
|
221
|
-
sinon.stub(br.
|
220
|
+
sinon.stub(br._plugins.textSelection, "getPageText")
|
222
221
|
.returns($(new DOMParser().parseFromString(FAKE_XML_EMPTY, "text/xml")));
|
223
|
-
await br.
|
222
|
+
await br._plugins.textSelection.createTextLayer({ $container, page: { index: 4, width: 100, height: 100 }});
|
224
223
|
expect($container.find(".BRtextLayer").length).toBe(1);
|
225
224
|
expect($container.find("p").length).toBe(0);
|
226
225
|
expect($container.find(".BRwordElement").length).toBe(0);
|
@@ -229,7 +228,7 @@ describe("Generic tests", () => {
|
|
229
228
|
const LONG_PRESS_DURATION = 500;
|
230
229
|
test("calling stopPageFlip does not allow long click to flip the page", () => {
|
231
230
|
const $container = br.refs.$brContainer;
|
232
|
-
br.
|
231
|
+
br._plugins.textSelection.stopPageFlip($container);
|
233
232
|
const currIndex = br.currentIndex();
|
234
233
|
$container.find("BRwordElement").trigger("mousedown");
|
235
234
|
// Waits for long press
|