@internetarchive/bookreader 5.0.0-24-sortingstate-2 → 5.0.0-24-sortingstate-6

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.
Files changed (74) hide show
  1. package/BookReader/BookReader.js +1 -1
  2. package/BookReader/icons/1up.svg +12 -1
  3. package/BookReader/icons/2up.svg +15 -1
  4. package/BookReader/icons/advance.svg +26 -3
  5. package/BookReader/icons/chevron-right.svg +1 -1
  6. package/BookReader/icons/close-circle-dark.svg +1 -1
  7. package/BookReader/icons/close-circle.svg +1 -1
  8. package/BookReader/icons/fullscreen.svg +17 -1
  9. package/BookReader/icons/fullscreen_exit.svg +17 -1
  10. package/BookReader/icons/hamburger.svg +15 -1
  11. package/BookReader/icons/left-arrow.svg +12 -1
  12. package/BookReader/icons/magnify-minus.svg +16 -1
  13. package/BookReader/icons/magnify-plus.svg +17 -1
  14. package/BookReader/icons/magnify.svg +15 -1
  15. package/BookReader/icons/pause.svg +23 -1
  16. package/BookReader/icons/play.svg +22 -1
  17. package/BookReader/icons/playback-speed.svg +34 -1
  18. package/BookReader/icons/read-aloud.svg +22 -1
  19. package/BookReader/icons/review.svg +22 -3
  20. package/BookReader/icons/thumbnails.svg +17 -1
  21. package/BookReader/icons/voice.svg +1 -1
  22. package/BookReader/icons/volume-full.svg +22 -1
  23. package/BookReader/images/BRicons.svg +94 -5
  24. package/BookReader/images/books_graphic.svg +177 -1
  25. package/BookReader/images/icon_book.svg +12 -1
  26. package/BookReader/images/icon_bookmark.svg +12 -1
  27. package/BookReader/images/icon_gear.svg +14 -1
  28. package/BookReader/images/icon_hamburger.svg +20 -1
  29. package/BookReader/images/icon_home.svg +21 -1
  30. package/BookReader/images/icon_info.svg +11 -1
  31. package/BookReader/images/icon_one_page.svg +8 -1
  32. package/BookReader/images/icon_pause.svg +1 -1
  33. package/BookReader/images/icon_play.svg +1 -1
  34. package/BookReader/images/icon_playback-rate.svg +15 -1
  35. package/BookReader/images/icon_search_button.svg +8 -1
  36. package/BookReader/images/icon_share.svg +9 -1
  37. package/BookReader/images/icon_skip-ahead.svg +6 -1
  38. package/BookReader/images/icon_skip-back.svg +13 -2
  39. package/BookReader/images/icon_speaker.svg +18 -1
  40. package/BookReader/images/icon_speaker_open.svg +10 -1
  41. package/BookReader/images/icon_thumbnails.svg +12 -1
  42. package/BookReader/images/icon_toc.svg +5 -1
  43. package/BookReader/images/icon_two_pages.svg +9 -1
  44. package/BookReader/images/marker_chap-off.svg +11 -1
  45. package/BookReader/images/marker_chap-on.svg +11 -1
  46. package/BookReader/images/marker_srch-on.svg +11 -1
  47. package/BookReader/jquery-1.10.1.js +108 -2
  48. package/BookReader/plugins/plugin.archive_analytics.js +170 -1
  49. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  50. package/BookReader/plugins/plugin.autoplay.js +163 -1
  51. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  52. package/BookReader/plugins/plugin.chapters.js +333 -1
  53. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  54. package/BookReader/plugins/plugin.iframe.js +72 -1
  55. package/BookReader/plugins/plugin.iframe.js.map +1 -1
  56. package/BookReader/plugins/plugin.mobile_nav.js +332 -1
  57. package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
  58. package/BookReader/plugins/plugin.resume.js +241 -1
  59. package/BookReader/plugins/plugin.resume.js.map +1 -1
  60. package/BookReader/plugins/plugin.search.js +1263 -1
  61. package/BookReader/plugins/plugin.search.js.map +1 -1
  62. package/BookReader/plugins/plugin.text_selection.js +839 -1
  63. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  64. package/BookReader/plugins/plugin.tts.js +9114 -2
  65. package/BookReader/plugins/plugin.tts.js.map +1 -1
  66. package/BookReader/plugins/plugin.url.js +17 -15
  67. package/BookReader/plugins/plugin.url.js.map +1 -1
  68. package/BookReader/plugins/plugin.vendor-fullscreen.js +326 -1
  69. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
  70. package/BookReader/webcomponents-bundle.js +411 -2
  71. package/BookReader/webcomponents-bundle.js.map +1 -1
  72. package/package.json +1 -1
  73. package/src/plugins/plugin.url.js +9 -9
  74. package/tests/jest/plugins/plugin.url.test.js +11 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/bookreader",
3
- "version": "5.0.0-24-sortingstate-2",
3
+ "version": "5.0.0-24-sortingstate-6",
4
4
  "description": "The Internet Archive BookReader.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -212,7 +212,7 @@ export class UrlPlugin {
212
212
  ];
213
213
 
214
214
  this.urlState = {};
215
- this.urlMode = 'hash';
215
+ this.urlMode = this.bookReaderOptions.urlMode || 'hash';
216
216
  this.urlHistoryBasePath = '/';
217
217
  this.urlLocationPollId = null;
218
218
  this.oldLocationHash = null;
@@ -222,18 +222,17 @@ export class UrlPlugin {
222
222
  /**
223
223
  * Parse JSON object URL state to string format
224
224
  * Arrange path names in an order that it is positioned on the urlSchema
225
- * @param {object} urlSchema
226
225
  * @param {string} urlState
227
226
  * @returns {string}
228
227
  */
229
- urlStateToUrlString(urlSchema, urlState) {
228
+ urlStateToUrlString(urlState) {
230
229
  const searchParams = new URLSearchParams();
231
230
  const pathParams = {};
232
231
 
233
232
  Object.keys(urlState).forEach(key => {
234
- let schema = urlSchema.find(schema => schema.name === key);
233
+ let schema = this.urlSchema.find(schema => schema.name === key);
235
234
  if (schema?.deprecated_for) {
236
- schema = urlSchema.find(schemaKey => schemaKey.name === schema.deprecated_for);
235
+ schema = this.urlSchema.find(schemaKey => schemaKey.name === schema.deprecated_for);
237
236
  }
238
237
  if (schema?.position == 'path') {
239
238
  pathParams[schema?.name] = urlState[key];
@@ -242,7 +241,7 @@ export class UrlPlugin {
242
241
  }
243
242
  });
244
243
 
245
- const strPathParams = urlSchema
244
+ const strPathParams = this.urlSchema
246
245
  .filter(s => s.position == 'path')
247
246
  .map(schema => pathParams[schema.name] ? `${schema.name}/${pathParams[schema.name]}` : '')
248
247
  .join('/');
@@ -257,16 +256,16 @@ export class UrlPlugin {
257
256
  * Example:
258
257
  * /page/n7/mode/2up => {page: 'n7', mode: '2up'}
259
258
  * /page/n7/mode/2up/search/hello => {page: 'n7', mode: '2up', q: 'hello'}
260
- * @param {array} urlSchema
261
259
  * @param {string} urlString
262
260
  * @returns {object}
263
261
  */
264
- urlStringToUrlState(urlSchema, urlString) {
262
+ urlStringToUrlState(urlString) {
265
263
  const urlState = {};
266
264
 
267
265
  // Fetch searchParams from given {urlString}
268
266
  // Note: whole URL path is needed for URLSearchParams
269
267
  const urlPath = new URL(urlString, 'http://example.com');
268
+ console.log('urlSearch: ', urlPath.searchParams, ' urlPath: ', urlPath.pathname);
270
269
  const urlSearchParamsObj = Object.fromEntries(urlPath.searchParams.entries());
271
270
  const urlStrSplitSlashObj = Object.fromEntries(urlPath.pathname
272
271
  .match(/[^\\/]+\/[^\\/]+/g)
@@ -277,7 +276,7 @@ export class UrlPlugin {
277
276
  };
278
277
 
279
278
  // Add path objects to urlState
280
- urlSchema
279
+ this.urlSchema
281
280
  .filter(schema => schema.position == 'path')
282
281
  .forEach(schema => {
283
282
  if (!urlStrSplitSlashObj[schema.name] && schema.default) {
@@ -384,6 +383,7 @@ export class UrlPlugin {
384
383
  const path = this.urlMode === 'history'
385
384
  ? (location.pathname.substr(this.urlHistoryBasePath.length) + location.search)
386
385
  : location.hash.substr(1);
386
+ console.log('path: ', path);
387
387
  this.urlState = this.urlStringToUrlState(this.urlSchema, path);
388
388
  }
389
389
  }
@@ -17,15 +17,6 @@ afterEach(() => {
17
17
 
18
18
  describe.only('UrlPlugin tests', () => {
19
19
  const urlPlugin = new UrlPlugin();
20
- const urlSchema = [
21
- { name: 'page', position: 'path', default: 'n0' },
22
- { name: 'mode', position: 'path', default: '2up' },
23
- { name: 'search', position: 'path', deprecated_for: 'q' },
24
- { name: 'q', position: 'query_param' },
25
- { name: 'sort', position: 'query_param' },
26
- { name: 'view', position: 'query_param' },
27
- { name: 'admin', position: 'query_param' },
28
- ];
29
20
 
30
21
  describe('urlStateToUrlString tests', () => {
31
22
  test('urlStateToUrlString with known states in schema', () => {
@@ -35,8 +26,8 @@ describe.only('UrlPlugin tests', () => {
35
26
  const expectedUrlFromState = '/page/n7/mode/1up?q=foo';
36
27
  const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&view=theater&sort=title_asc';
37
28
 
38
- expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
39
- expect(urlPlugin.urlStateToUrlString(urlSchema, urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
29
+ expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
30
+ expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
40
31
  });
41
32
 
42
33
  test('urlStateToUrlString with unknown states in schema', () => {
@@ -46,15 +37,15 @@ describe.only('UrlPlugin tests', () => {
46
37
  const expectedUrlFromState = '/page/n7/mode/1up';
47
38
  const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&viewer=theater&sortBy=title_asc';
48
39
 
49
- expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
50
- expect(urlPlugin.urlStateToUrlString(urlSchema, urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
40
+ expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
41
+ expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
51
42
  });
52
43
 
53
44
  test('urlStateToUrlString with boolean value', () => {
54
45
  const urlState = { page: 'n7', mode: '1up', search: 'foo', view: 'theater', wrapper: false };
55
46
  const expectedUrlFromState = '/page/n7/mode/1up?q=foo&view=theater&wrapper=false';
56
47
 
57
- expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
48
+ expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
58
49
  });
59
50
  });
60
51
 
@@ -63,24 +54,24 @@ describe.only('UrlPlugin tests', () => {
63
54
  const url = '/page/n7/mode/2up';
64
55
  const url1 = '/page/n7/mode/1up';
65
56
 
66
- expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up'});
67
- expect(urlPlugin.urlStringToUrlState(urlSchema, url1)).toEqual({page: 'n7', mode: '1up'});
57
+ expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up'});
58
+ expect(urlPlugin.urlStringToUrlState(url1)).toEqual({page: 'n7', mode: '1up'});
68
59
  });
69
60
 
70
61
  test('urlStringToUrlState with deprecated_for', () => {
71
62
  const url = '/page/n7/mode/2up/search/hello';
72
63
 
73
- expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
64
+ expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
74
65
  });
75
66
 
76
67
  test('urlStringToUrlState with query string', () => {
77
68
  const url = '/page/n7/mode/2up/search/hello?view=theather&foo=bar&sort=title_asc';
78
69
  const url1 = '/mode/2up?ref=ol&ui=embed&wrapper=false&view=theater';
79
70
 
80
- expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual(
71
+ expect(urlPlugin.urlStringToUrlState(url)).toEqual(
81
72
  {page: 'n7', mode: '2up', q: 'hello', view: 'theather', foo: 'bar', sort: 'title_asc'}
82
73
  );
83
- expect(urlPlugin.urlStringToUrlState(urlSchema, url1)).toEqual(
74
+ expect(urlPlugin.urlStringToUrlState(url1)).toEqual(
84
75
  {page: 'n0', mode: '2up', ref: 'ol', ui: 'embed', wrapper: false, view: 'theater'}
85
76
  );
86
77
  });
@@ -89,7 +80,7 @@ describe.only('UrlPlugin tests', () => {
89
80
  const url = '/page/n7/mode/2up/search/hello';
90
81
  urlPlugin.urlState = { q: 'hello' };
91
82
 
92
- expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
83
+ expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
93
84
  });
94
85
  });
95
86