@internetarchive/bookreader 5.0.0-120 → 5.0.0-121

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/bookreader",
3
- "version": "5.0.0-120",
3
+ "version": "5.0.0-121",
4
4
  "description": "The Internet Archive BookReader.",
5
5
  "type": "module",
6
6
  "files": [
@@ -97,7 +97,7 @@ export class TextSelectionPlugin extends BookReaderPlugin {
97
97
  }
98
98
 
99
99
  async initTextFragment() {
100
- if (this.br.options.verifyTextFragment && !await this.br.options.verifyTextFragment(this.br.targetTextFragment)) {
100
+ if (this.br.options.verifyTextFragment && !await this.br.options.verifyTextFragment.call(this, this.br.targetTextFragment)) {
101
101
  return;
102
102
  }
103
103
 
@@ -1277,18 +1277,25 @@ export class BookReaderTextFragment {
1277
1277
  }
1278
1278
 
1279
1279
  /**
1280
- * Generates a URL pointing to the page with the text fragment highlighted. Maintains all existing
1281
- * parameters in the url.
1280
+ * Generates a URL pointing to the page with the text fragment highlighted.
1282
1281
  */
1283
1282
  toUrl() {
1284
- const params = new URLSearchParams(window.location.search);
1285
- params.set('text', this.toNormalizedString());
1283
+ // Strip all other parameters
1284
+ const params = new URLSearchParams({
1285
+ text: this.toNormalizedString(),
1286
+ });
1286
1287
 
1287
1288
  const currentUrl = window.location;
1288
- const pageNum = this.pageNumber || `n${this.pageIndex}`;
1289
- const adjustedUrlPageNumPath = currentUrl.pathname.replace(/((?:^|[#/])page)\/[^/]+/, `$1/${pageNum}`);
1290
- const hash = currentUrl.hash ? currentUrl.hash.replace(/((?:^|[#/])page)\/[^/]+/, `$1/${pageNum}`) : '';
1291
- return `${currentUrl.origin}${adjustedUrlPageNumPath}?${params}${hash}`;
1289
+ const pageNum = encodeURIComponent(this.pageNumber || `n${this.pageIndex}`);
1290
+ // In urlMode 'hash' the BookReader state lives in the hash (e.g. #page/4/mode/2up)
1291
+ const isHashMode = /^#\/?page\//.test(currentUrl.hash);
1292
+ if (isHashMode) {
1293
+ return `${currentUrl.origin}${currentUrl.pathname}?${params}#page/${pageNum}`;
1294
+ }
1295
+
1296
+ // urlMode 'history': only keep /page/X in the path, adding it if missing
1297
+ const basePath = currentUrl.pathname.replace(/\/page\/.*/, '').replace(/\/+$/, '');
1298
+ return `${currentUrl.origin}${basePath}/page/${pageNum}?${params}`;
1292
1299
  }
1293
1300
 
1294
1301
  /**