@internetarchive/bookreader 5.0.0-43 → 5.0.0-44-a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. package/BookReader/BookReader.css +1 -2
  2. package/BookReader/BookReader.js +1 -1
  3. package/BookReader/BookReader.js.map +1 -1
  4. package/BookReader/ia-bookreader-bundle.js +35 -35
  5. package/BookReader/ia-bookreader-bundle.js.map +1 -1
  6. package/BookReader/plugins/plugin.tts.js +1 -1
  7. package/BookReader/plugins/plugin.tts.js.map +1 -1
  8. package/BookReaderDemo/IADemoBr.js +30 -0
  9. package/BookReaderDemo/demo-internetarchive.html +3 -0
  10. package/babel.config.js +1 -1
  11. package/package.json +10 -16
  12. package/renovate.json +7 -4
  13. package/src/BookNavigator/book-navigator.js +4 -0
  14. package/src/BookNavigator/downloads/downloads-provider.js +14 -5
  15. package/src/BookNavigator/downloads/downloads.js +23 -1
  16. package/src/css/_controls.scss +1 -2
  17. package/src/plugins/tts/plugin.tts.js +15 -3
  18. package/tests/{karma → jest}/BookNavigator/book-navigator.test.js +119 -104
  19. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-button.test.js +13 -14
  20. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-edit.test.js +25 -26
  21. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmarks-list.test.js +41 -42
  22. package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +45 -0
  23. package/tests/{karma → jest}/BookNavigator/downloads/downloads-provider.test.js +18 -18
  24. package/tests/{karma → jest}/BookNavigator/downloads/downloads.test.js +7 -8
  25. package/tests/{karma → jest}/BookNavigator/sharing/sharing-provider.test.js +8 -8
  26. package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
  27. package/tests/{karma → jest}/BookNavigator/volumes/volumes-provider.test.js +38 -38
  28. package/tests/{karma → jest}/BookNavigator/volumes/volumes.test.js +15 -16
  29. package/tests/jest/plugins/tts/AbstractTTSEngine.test.js +3 -3
  30. package/karma.conf.js +0 -23
  31. package/tests/karma/BookNavigator/bookmarks/ia-bookmarks.test.js +0 -57
  32. package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
@@ -14,6 +14,25 @@ const searchTerm = urlParams.get('q');
14
14
 
15
15
  const iaBookReader = document.querySelector('ia-bookreader');
16
16
 
17
+ const downloadListWithLCP = [
18
+ [
19
+ "PDF",
20
+ "regular pdf link"
21
+ ],
22
+ [
23
+ "lcpPDF",
24
+ "link to lcp pdf"
25
+ ],
26
+ [
27
+ "ePub",
28
+ "link to epub"
29
+ ],
30
+ [
31
+ "lcpEPUB",
32
+ "link to lcp epub"
33
+ ]
34
+ ];
35
+
17
36
  if (openFullImmersionTheater) {
18
37
  $(document.body).addClass('BRfullscreenActive');
19
38
  iaBookReader.fullscreen = openFullImmersionTheater;
@@ -78,6 +97,17 @@ const initializeBookReader = (brManifest) => {
78
97
 
79
98
  window.initializeBookReader = initializeBookReader;
80
99
 
100
+ const showLCP = document.querySelector('#show-lcp');
101
+ showLCP.addEventListener('click', async () => {
102
+ const iaBr = document.querySelector('ia-bookreader');
103
+ const bookNav = iaBr.shadowRoot.querySelector('book-navigator');
104
+
105
+ bookNav.downloadableTypes = downloadListWithLCP;
106
+
107
+ bookNav.updateMenuContents();
108
+ await bookNav.updateComplete;
109
+ });
110
+
81
111
  const multiVolume = document.querySelector('#multi-volume');
82
112
  multiVolume.addEventListener('click', () => {
83
113
  // remove everything
@@ -77,6 +77,9 @@
77
77
  <p>Features behind signed in gate: Bookmarks</p>
78
78
  <p>Logged In Status: <span id="logged-in-status">Logged Out</span></p>
79
79
  </div>
80
+ <div class="demo">
81
+ <button id="show-lcp">LCP Download option</button>
82
+ </div>
80
83
  <div class="demo">
81
84
  <button id="multi-volume">Multiple books</button>
82
85
  </div>
package/babel.config.js CHANGED
@@ -2,7 +2,7 @@ module.exports = {
2
2
  presets: [
3
3
  [
4
4
  "@babel/preset-env",
5
- {
5
+ process.env.NODE_ENV == 'test' ? { targets: {esmodules: true} } : {
6
6
  targets: "> 2%, ie 11, edge 14, samsung > 9, OperaMini all, UCAndroid > 12, Safari >= 9",
7
7
  useBuiltIns: "usage",
8
8
  corejs: 3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/bookreader",
3
- "version": "5.0.0-43",
3
+ "version": "5.0.0-44-a1",
4
4
  "description": "The Internet Archive BookReader.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,9 +46,8 @@
46
46
  "@babel/plugin-proposal-class-properties": "7.16.7",
47
47
  "@babel/plugin-proposal-decorators": "7.17.9",
48
48
  "@babel/preset-env": "7.16.11",
49
- "@open-wc/testing": "^3.1.4",
50
- "@open-wc/testing-karma": "^4.0.9",
51
- "@types/jest": "^27.4.1",
49
+ "@open-wc/testing-helpers": "^2.1.2",
50
+ "@types/jest": "^27.5.1",
52
51
  "@webcomponents/webcomponentsjs": "^2.6.0",
53
52
  "babel-loader": "8.2.5",
54
53
  "codecov": "^3.8.3",
@@ -61,20 +60,19 @@
61
60
  "hammerjs": "^2.0.8",
62
61
  "http-server": "14.1.0",
63
62
  "iso-language-codes": "1.1.0",
64
- "jest": "^28.0.3",
65
- "jest-environment-jsdom": "^28.0.2",
63
+ "jest": "^28.1.0",
64
+ "jest-environment-jsdom": "^28.1.0",
66
65
  "jquery": "1.12.4",
67
66
  "jquery-colorbox": "1.6.4",
68
67
  "jquery-ui": "1.12.1",
69
68
  "jquery-ui-touch-punch": "0.2.3",
70
69
  "jquery.browser": "0.1.0",
71
70
  "jquery.mmenu": "5.6.5",
72
- "karma-coverage": "^2.1.0",
73
71
  "live-server": "1.2.2",
74
72
  "node-fetch": "3.2.4",
75
73
  "regenerator-runtime": "0.13.9",
76
74
  "sass": "1.51.0",
77
- "sinon": "^13.0.2",
75
+ "sinon": "^14.0.0",
78
76
  "soundmanager2": "2.97.20170602",
79
77
  "svgo": "2.8.0",
80
78
  "testcafe": "^1.18.6",
@@ -96,8 +94,7 @@
96
94
  "roots": [
97
95
  "<rootDir>/src/",
98
96
  "<rootDir>/tests/jest/"
99
- ],
100
- "coverageDirectory": "<rootDir>/coverage-jest"
97
+ ]
101
98
  },
102
99
  "scripts": {
103
100
  "preversion": "npm run test && node scripts/preversion.js",
@@ -116,15 +113,12 @@
116
113
  "serve": "npx http-server . --port 8000",
117
114
  "serve-live": "npx live-server . --port 8000 --watch=index.html,BookReader,BookReaderDemo",
118
115
  "serve-dev": "npm run build-css && npx concurrently --kill-others npm:serve-live npm:build-*:watch",
119
- "test": "npx concurrently --group npm:test-jest npm:test-karma",
116
+ "test": "npx jest --coverage --colors",
117
+ "test:watch": "npx jest --watch",
120
118
  "test:e2e": "npm run build && npx testcafe",
121
119
  "test:e2e:dev": "npx testcafe --live --dev",
122
- "test-jest:watch": "npx jest --watch",
123
- "test-jest": "npx jest --coverage --colors",
124
- "test-karma": "npx karma start --coverage",
125
- "test-karma:watch": "npx karma start --auto-watch=true --single-run=false",
126
120
  "DOCS:update:test-deps": "If CI succeeds, these should be good to update",
127
- "update:test-deps": "npm i @babel/eslint-parser@latest @open-wc/testing@latest @open-wc/testing-karma@latest @types/jest@latest codecov@latest eslint@latest eslint-plugin-testcafe@latest jest@latest karma-coverage@latest sinon@latest testcafe@latest",
121
+ "update:test-deps": "npm i @babel/eslint-parser@latest @open-wc/testing-helpers@latest @types/jest@latest codecov@latest eslint@latest eslint-plugin-testcafe@latest jest@latest sinon@latest testcafe@latest",
128
122
  "DOCS:update:build-deps": "These can cause strange changes, so do an npm run build + check file size (git diff --stat), and check the site is as expected",
129
123
  "update:build-deps": "npm i @babel/core@latest @babel/preset-env@latest babel-loader@latest core-js@latest regenerator-runtime@latest sass@latest svgo@latest webpack@latest webpack-cli@latest",
130
124
  "codecov": "npx codecov"
package/renovate.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "extends": [
3
- "config:base"
3
+ "config:base",
4
+ "schedule:monthly"
4
5
  ],
5
6
  "packageRules": [
6
7
  {
7
8
  "matchPackageNames": [
8
9
  "@babel/eslint-parser",
9
- "@open-wc/testing",
10
- "@open-wc/testing-karma",
10
+ "@open-wc/testing-helpers",
11
11
  "@types/jest",
12
12
  "codecov",
13
13
  "eslint",
@@ -15,7 +15,6 @@
15
15
  "eslint-plugin-testcafe",
16
16
  "jest",
17
17
  "jest-environment-jsdom",
18
- "karma-coverage",
19
18
  "sinon",
20
19
  "testcafe"
21
20
  ],
@@ -44,6 +43,10 @@
44
43
  "matchPackagePatterns": ["^actions/"],
45
44
  "groupName": "GitHub Actions",
46
45
  "automerge": true
46
+ },
47
+ {
48
+ "matchPackagePatterns": ["^@internetarchive"],
49
+ "schedule": ["at any time"]
47
50
  }
48
51
  ]
49
52
  }
@@ -106,6 +106,10 @@ export class BookNavigator extends LitElement {
106
106
  this.loadSharedObserver();
107
107
  this.initializeBookSubmenus();
108
108
  }
109
+
110
+ if (changed.has('downloadableTypes')) {
111
+ this.initializeBookSubmenus();
112
+ }
109
113
  }
110
114
 
111
115
  /**
@@ -8,16 +8,28 @@ const menuBase = {
8
8
  url: '#',
9
9
  note: 'PDF files contain high quality images of pages.',
10
10
  },
11
+ lcppdf: {
12
+ type: 'Get LCP PDF',
13
+ url: '#',
14
+ note: 'PDF files contain high quality images of pages.',
15
+ },
16
+ lcpepub: {
17
+ type: 'Get LCP ePub',
18
+ url: '#',
19
+ note: 'ePub files are smaller in size, but may contain errors.',
20
+ },
11
21
  epub: {
12
22
  type: 'Encrypted Adobe ePub',
13
23
  url: '#',
14
24
  note: 'ePub files are smaller in size, but may contain errors.',
15
- }
25
+ },
16
26
  };
17
27
 
18
28
  const publicMenuBase = {
19
29
  pdf: "PDF",
20
- epub: "ePub"
30
+ epub: "ePub",
31
+ lcppdf: "LCP PDF",
32
+ lcpepub: "LCP ePub",
21
33
  };
22
34
 
23
35
  export default class DownloadsProvider {
@@ -30,9 +42,6 @@ export default class DownloadsProvider {
30
42
  this.id = 'downloads';
31
43
  this.component = '';
32
44
  this.isBookProtected = bookreader?.options?.isProtected || false;
33
-
34
- this.computeAvailableTypes = this.computeAvailableTypes.bind(this);
35
- this.update = this.update.bind(this);
36
45
  }
37
46
 
38
47
  update(downloadTypes) {
@@ -40,6 +40,16 @@ export class IABookDownloads extends LitElement {
40
40
  ));
41
41
  }
42
42
 
43
+ /**
44
+ * checks if downloads list contains an LCP option
45
+ * @return {boolean}
46
+ */
47
+ get hasLCPOption() {
48
+ const regex = /^(LCP)/g;
49
+ const lcpAvailable = this.downloads.some(option => option.type?.match(regex));
50
+ return lcpAvailable;
51
+ }
52
+
43
53
  get header() {
44
54
  if (!this.renderHeader) {
45
55
  return nothing;
@@ -59,12 +69,24 @@ export class IABookDownloads extends LitElement {
59
69
  `;
60
70
  }
61
71
 
72
+ get installSimplyEAldikoThoriumMsg() {
73
+ return html`
74
+ <p>For LCP downloads, make sure you have SimplyE or Aldiko Next installed on mobile or Thorium on desktop.</p>
75
+ <ul>
76
+ <li><a href="https://librarysimplified.org/simplye/" rel="noopener noreferrer" target="_blank">Install SimplyE</a></li>
77
+ <li><a href="https://www.demarque.com/en-aldiko" rel="noopener noreferrer" target="_blank">Install Aldiko</a></li>
78
+ <li><a href="https://www.edrlab.org/software/thorium-reader/" rel="noopener noreferrer" target="_blank">Install Thorium</a></li>
79
+ </ul>
80
+ `;
81
+ }
82
+
62
83
  render() {
63
84
  return html`
64
85
  ${this.header}
65
86
  ${this.loanExpiryMessage}
66
87
  <ul>${this.renderDownloadOptions()}</ul>
67
- ${this.isBookProtected ? this.accessProtectedBook : nothing}
88
+ ${this.hasLCPOption ? this.installSimplyEAldikoThoriumMsg : nothing}
89
+ ${this.isBookProtected && !this.hasLCPOption ? this.accessProtectedBook : nothing}
68
90
  `;
69
91
  }
70
92
 
@@ -34,12 +34,11 @@
34
34
  -webkit-appearance: none;
35
35
  appearance: none;
36
36
  font-size: 10px;
37
- text-align: center;
38
37
  text-align-last: center;
39
38
  color: $controlsText;
40
39
  border: none;
41
40
  cursor: pointer;
42
- option {
41
+ option, optgroup {
43
42
  background: $controlsBG;
44
43
  }
45
44
  }
@@ -158,18 +158,30 @@ BookReader.prototype.initNavbar = (function (super_) {
158
158
 
159
159
  $el.find('.BRcontrols').prepend(this.refs.$BRReadAloudToolbar);
160
160
 
161
+ const renderVoiceOption = (voices) => {
162
+ return voices.map(voice =>
163
+ `<option value="${voice.voiceURI}">${voice.lang} - ${voice.name}</option>`).join('');
164
+ };
165
+
166
+ const voiceSortOrder = (a,b) => `${a.lang} - ${a.name}`.localeCompare(`${b.lang} - ${b.name}`);
167
+
161
168
  const renderVoicesMenu = (voicesMenu) => {
162
169
  voicesMenu.empty();
170
+ const bookLanguage = this.ttsEngine.opts.bookLanguage;
171
+ const bookLanguages = this.ttsEngine.getVoices().filter(v => v.lang.startsWith(bookLanguage)).sort(voiceSortOrder);
172
+ const otherLanguages = this.ttsEngine.getVoices().filter(v => !v.lang.startsWith(bookLanguage)).sort(voiceSortOrder);
173
+
163
174
  if (this.ttsEngine.getVoices().length > 1) {
164
- voicesMenu.append(this.ttsEngine.getVoices().map(
165
- voice =>
166
- $(`<option value="${voice.voiceURI}">${voice.lang} - ${voice.name}</option>`)));
175
+ voicesMenu.append($(`<optgroup label="Book Language (${bookLanguage})"> ${renderVoiceOption(bookLanguages)} </optgroup>`));
176
+ voicesMenu.append($(`<optgroup label="Other Languages"> ${renderVoiceOption(otherLanguages)} </optgroup>`));
177
+
167
178
  voicesMenu.val(this.ttsEngine.voice.voiceURI);
168
179
  voicesMenu.show();
169
180
  } else {
170
181
  voicesMenu.hide();
171
182
  }
172
183
  };
184
+
173
185
  const voicesMenu = this.refs.$BRReadAloudToolbar.find('[name=playback-voice]');
174
186
  renderVoicesMenu(voicesMenu);
175
187
  voicesMenu.on("change", ev => this.ttsEngine.setVoice(voicesMenu.val()));