@internetarchive/bookreader 5.0.0-111 → 5.0.0-113
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 +13 -7
- package/BookReader/BookReader.js +43 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +3 -45
- package/BookReader/ia-bookreader-bundle.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 +1 -1
- package/BookReader/plugins/plugin.experiments.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 +1 -23
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.translate.js +3 -25
- 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 -2
- 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/package.json +1 -1
- package/src/BookReader/Navbar/Navbar.js +9 -10
- package/src/BookReader/utils/SelectionObserver.js +2 -2
- package/src/BookReader.js +5 -4
- package/src/css/_BRpages.scss +5 -2
- package/src/css/_TextSelection.scss +15 -9
- package/src/plugins/plugin.experiments.js +31 -5
- package/src/plugins/plugin.text_selection.js +19 -56
- package/src/plugins/translate/plugin.translate.js +68 -22
- package/src/plugins/tts/utils.js +1 -1
- package/src/plugins/url/UrlPlugin.js +2 -15
- package/src/plugins/url/plugin.url.js +7 -59
- package/src/util/TextSelectionManager.js +834 -137
- package/BookReader/plugins/plugin.url.js.LICENSE.txt +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* global BookReader */
|
|
2
2
|
|
|
3
3
|
import { UrlPlugin } from "./UrlPlugin.js";
|
|
4
|
-
import { sleep } from "../../BookReader/utils.js";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Plugin for URL management in BookReader
|
|
@@ -43,10 +42,6 @@ BookReader.prototype.setup = (function(super_) {
|
|
|
43
42
|
this.locationPollId = null;
|
|
44
43
|
this.oldLocationHash = null;
|
|
45
44
|
this.oldUserHash = null;
|
|
46
|
-
// Should include the :~:text= prefix
|
|
47
|
-
this.textFragment = null;
|
|
48
|
-
// Tracks the original textFragment page num when first loaded
|
|
49
|
-
this.textFragmentPage = null;
|
|
50
45
|
};
|
|
51
46
|
})(BookReader.prototype.setup);
|
|
52
47
|
|
|
@@ -146,22 +141,16 @@ BookReader.prototype.urlUpdateFragment = function() {
|
|
|
146
141
|
}, {});
|
|
147
142
|
|
|
148
143
|
// eg 'page/3/mode/2up'; no query params (in hash mode, it might have /search/term)
|
|
149
|
-
// Does NOT have the :~:text fragment
|
|
150
144
|
const newFragment = this.fragmentFromParams(params, this.options.urlMode);
|
|
151
145
|
const newFragmentWithSlash = newFragment === '' ? '' : `/${newFragment}`;
|
|
152
146
|
// eg 'page/3/mode/2up'; no query params
|
|
153
|
-
// WILL CONTAIN the :~:text fragment in hash mode (!)
|
|
154
147
|
const currFragment = this.urlReadFragment();
|
|
155
148
|
// This should have both ?q=foo&text=bar (and any other params) as an encoded string
|
|
156
149
|
const currQueryString = this.getLocationSearch();
|
|
157
150
|
// Eg ?q=foo&text=bar; only query params, no fragment
|
|
158
151
|
const newQueryString = this.queryStringFromParams(params, currQueryString, this.options.urlMode);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// not desireable, but currently don't have a way to handle re-writing ?text to the hash text
|
|
162
|
-
// fragment form, :~:text=foo.
|
|
163
|
-
const hasTextParam = this.urlPlugin.retrieveTextFragment(currQueryString);
|
|
164
|
-
if (currFragment === newFragment && currQueryString === newQueryString && !hasTextParam) {
|
|
152
|
+
// Avoid infinite loop if there are no changes
|
|
153
|
+
if (currFragment === newFragment && currQueryString === newQueryString) {
|
|
165
154
|
return;
|
|
166
155
|
}
|
|
167
156
|
|
|
@@ -170,19 +159,11 @@ BookReader.prototype.urlUpdateFragment = function() {
|
|
|
170
159
|
this.options.urlMode = 'hash';
|
|
171
160
|
} else {
|
|
172
161
|
const baseWithoutSlash = this.options.urlHistoryBasePath.replace(/\/+$/, '');
|
|
173
|
-
const textFragment = this.urlPlugin.retrieveTextFragment(newQueryString);
|
|
174
162
|
const newUrlPath = `${baseWithoutSlash}${newFragmentWithSlash}${newQueryString}`;
|
|
175
|
-
|
|
176
|
-
if (!this.textFragmentPage && textFragment) {
|
|
177
|
-
this.textFragmentPage = extractedPage ? extractedPage : null;
|
|
178
|
-
this.textFragment = `:~:text=${textFragment}`;
|
|
179
|
-
}
|
|
163
|
+
|
|
180
164
|
try {
|
|
181
165
|
window.history.replaceState({}, null, newUrlPath);
|
|
182
166
|
this.oldLocationHash = newFragment + newQueryString;
|
|
183
|
-
if (textFragment) {
|
|
184
|
-
this.oldLocationHash += `:~:text=${textFragment[0]}`;
|
|
185
|
-
}
|
|
186
167
|
} catch (e) {
|
|
187
168
|
// DOMException on Chrome when in sandboxed iframe
|
|
188
169
|
this.options.urlMode = 'hash';
|
|
@@ -192,22 +173,8 @@ BookReader.prototype.urlUpdateFragment = function() {
|
|
|
192
173
|
|
|
193
174
|
if (this.options.urlMode === 'hash') {
|
|
194
175
|
const newQueryStringSearch = this.urlParamsFiltersOnlySearch(this.readQueryString());
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (textFragment) {
|
|
199
|
-
textFragment = `:~:text=${textFragment[0]}`;
|
|
200
|
-
} else {
|
|
201
|
-
textFragment = '';
|
|
202
|
-
}
|
|
203
|
-
if (!this.textFragmentPage && textFragment) {
|
|
204
|
-
this.textFragmentPage = extractedPage ? extractedPage : null;
|
|
205
|
-
this.textFragment = textFragment;
|
|
206
|
-
} else if (this.textFragmentPage && extractedPage != this.textFragmentPage) {
|
|
207
|
-
textFragment = '';
|
|
208
|
-
}
|
|
209
|
-
window.location.replace('#' + newFragment + newQueryStringSearch + textFragment);
|
|
210
|
-
this.oldLocationHash = newFragment + newQueryStringSearch + textFragment;
|
|
176
|
+
window.location.replace('#' + newFragment + newQueryStringSearch);
|
|
177
|
+
this.oldLocationHash = newFragment + newQueryStringSearch;
|
|
211
178
|
}
|
|
212
179
|
};
|
|
213
180
|
|
|
@@ -248,28 +215,9 @@ export class BookreaderUrlPlugin extends BookReader {
|
|
|
248
215
|
init() {
|
|
249
216
|
if (this.options.enableUrlPlugin) {
|
|
250
217
|
this.urlPlugin = new UrlPlugin(this.options);
|
|
251
|
-
const location = this.getLocationSearch();
|
|
252
|
-
if (location.includes("text=")) {
|
|
253
|
-
this.on('textLayerVisible', async (_, {pageContainerEl}) => {
|
|
254
|
-
const visiblePageNum = pageContainerEl.getAttribute('data-page-num');
|
|
255
|
-
|
|
256
|
-
// Hack: More time mode 1up page "settle down" from user scrolling
|
|
257
|
-
await sleep(this.mode === 1 ? 900 : 100);
|
|
258
|
-
|
|
259
|
-
// No textFragment found or the textFragment stored doesn't match current visible page loaded
|
|
260
|
-
if (!this.textFragment || this.textFragmentPage !== visiblePageNum) return;
|
|
261
|
-
if (this.options.urlMode === 'history') {
|
|
262
|
-
window.location.replace(`#${this.textFragment}`);
|
|
263
|
-
} else {
|
|
264
|
-
// for urlMode hash, textFragment is stored in oldLocationHash already
|
|
265
|
-
window.location.replace(`#${this.oldLocationHash}`);
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
this.bind(BookReader.eventNames.PostInit, () => {
|
|
270
|
-
const { urlMode } = this.options;
|
|
271
218
|
|
|
272
|
-
|
|
219
|
+
this.on(BookReader.eventNames.PostInit, () => {
|
|
220
|
+
if (this.options.urlMode === 'hash') {
|
|
273
221
|
this.urlPlugin.listenForHashChanges();
|
|
274
222
|
}
|
|
275
223
|
});
|