@internetarchive/bookreader 5.0.0-4 → 5.0.0-40-a1

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 (228) hide show
  1. package/.eslintrc.js +17 -15
  2. package/.github/workflows/node.js.yml +75 -4
  3. package/.github/workflows/npm-publish.yml +2 -16
  4. package/.testcaferc.js +10 -0
  5. package/BookReader/BookReader.css +83 -323
  6. package/BookReader/BookReader.js +1 -1
  7. package/BookReader/BookReader.js.LICENSE.txt +24 -0
  8. package/BookReader/BookReader.js.map +1 -1
  9. package/BookReader/ia-bookreader-bundle.js +1623 -0
  10. package/BookReader/{bookreader-component-bundle.js.LICENSE.txt → ia-bookreader-bundle.js.LICENSE.txt} +14 -10
  11. package/BookReader/ia-bookreader-bundle.js.map +1 -0
  12. package/BookReader/icons/close-circle-dark.svg +1 -0
  13. package/BookReader/icons/magnify-minus.svg +1 -1
  14. package/BookReader/icons/magnify-plus.svg +1 -1
  15. package/BookReader/icons/voice.svg +1 -0
  16. package/BookReader/plugins/plugin.archive_analytics.js +1 -1
  17. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  18. package/BookReader/plugins/plugin.autoplay.js +1 -1
  19. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  20. package/BookReader/plugins/plugin.chapters.js +1 -1
  21. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  22. package/BookReader/plugins/plugin.iframe.js +1 -1
  23. package/BookReader/plugins/plugin.iframe.js.map +1 -1
  24. package/BookReader/plugins/plugin.mobile_nav.js +1 -1
  25. package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
  26. package/BookReader/plugins/plugin.resume.js +1 -1
  27. package/BookReader/plugins/plugin.resume.js.map +1 -1
  28. package/BookReader/plugins/plugin.search.js +1 -1
  29. package/BookReader/plugins/plugin.search.js.map +1 -1
  30. package/BookReader/plugins/plugin.text_selection.js +1 -1
  31. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  32. package/BookReader/plugins/plugin.tts.js +1 -1
  33. package/BookReader/plugins/plugin.tts.js.map +1 -1
  34. package/BookReader/plugins/plugin.url.js +1 -1
  35. package/BookReader/plugins/plugin.url.js.map +1 -1
  36. package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
  37. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
  38. package/BookReader/webcomponents-bundle.js +3 -0
  39. package/BookReader/webcomponents-bundle.js.LICENSE.txt +9 -0
  40. package/BookReader/webcomponents-bundle.js.map +1 -0
  41. package/BookReaderDemo/BookReaderDemo.css +14 -1
  42. package/BookReaderDemo/IADemoBr.js +120 -0
  43. package/BookReaderDemo/demo-advanced.html +1 -1
  44. package/BookReaderDemo/demo-autoplay.html +1 -0
  45. package/BookReaderDemo/demo-embed-iframe-src.html +1 -0
  46. package/BookReaderDemo/demo-fullscreen-mobile.html +1 -0
  47. package/BookReaderDemo/demo-fullscreen.html +1 -0
  48. package/BookReaderDemo/demo-iiif.html +1 -0
  49. package/BookReaderDemo/demo-internetarchive.html +74 -17
  50. package/BookReaderDemo/demo-multiple.html +1 -0
  51. package/BookReaderDemo/demo-preview-pages.html +1 -0
  52. package/BookReaderDemo/demo-simple.html +1 -0
  53. package/BookReaderDemo/demo-vendor-fullscreen.html +1 -0
  54. package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
  55. package/BookReaderDemo/immersion-1up.html +1 -0
  56. package/BookReaderDemo/immersion-mode.html +1 -0
  57. package/BookReaderDemo/toggle_controls.html +1 -0
  58. package/BookReaderDemo/view_mode.html +1 -0
  59. package/BookReaderDemo/viewmode-cycle.html +1 -2
  60. package/CHANGELOG.md +166 -0
  61. package/README.md +14 -1
  62. package/babel.config.js +18 -0
  63. package/codecov.yml +6 -0
  64. package/index.html +3 -0
  65. package/jsconfig.json +19 -0
  66. package/package.json +62 -47
  67. package/renovate.json +43 -0
  68. package/src/BookNavigator/assets/bookmark-colors.js +1 -1
  69. package/src/BookNavigator/assets/button-base.js +9 -2
  70. package/src/BookNavigator/assets/ia-logo.js +17 -0
  71. package/src/BookNavigator/assets/icon_checkmark.js +1 -1
  72. package/src/BookNavigator/assets/icon_close.js +1 -1
  73. package/src/BookNavigator/assets/icon_sort_asc.js +5 -0
  74. package/src/BookNavigator/assets/icon_sort_desc.js +5 -0
  75. package/src/BookNavigator/assets/icon_sort_neutral.js +5 -0
  76. package/src/BookNavigator/assets/icon_volumes.js +11 -0
  77. package/src/BookNavigator/book-navigator.js +556 -0
  78. package/src/BookNavigator/bookmarks/bookmark-button.js +3 -2
  79. package/src/BookNavigator/bookmarks/bookmark-edit.js +4 -4
  80. package/src/BookNavigator/bookmarks/bookmarks-list.js +3 -3
  81. package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +3 -8
  82. package/src/BookNavigator/bookmarks/bookmarks-provider.js +23 -12
  83. package/src/BookNavigator/bookmarks/ia-bookmarks.js +98 -62
  84. package/src/BookNavigator/delete-modal-actions.js +1 -1
  85. package/src/BookNavigator/downloads/downloads-provider.js +23 -17
  86. package/src/BookNavigator/downloads/downloads.js +17 -25
  87. package/src/BookNavigator/search/a-search-result.js +3 -3
  88. package/src/BookNavigator/search/search-provider.js +57 -24
  89. package/src/BookNavigator/search/search-results.js +8 -20
  90. package/src/BookNavigator/sharing.js +27 -0
  91. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +11 -13
  92. package/src/BookNavigator/visual-adjustments/visual-adjustments.js +4 -3
  93. package/src/BookNavigator/volumes/volumes-provider.js +114 -0
  94. package/src/BookNavigator/volumes/volumes.js +188 -0
  95. package/src/BookReader/DebugConsole.js +3 -3
  96. package/src/BookReader/DragScrollable.js +233 -0
  97. package/src/BookReader/Mode1Up.js +51 -351
  98. package/src/BookReader/Mode1UpLit.js +441 -0
  99. package/src/BookReader/Mode2Up.js +104 -71
  100. package/src/BookReader/ModeSmoothZoom.js +179 -0
  101. package/src/BookReader/ModeThumb.js +16 -8
  102. package/src/BookReader/Navbar/Navbar.js +2 -31
  103. package/src/BookReader/PageContainer.js +57 -6
  104. package/src/BookReader/ReduceSet.js +1 -1
  105. package/src/BookReader/Toolbar/Toolbar.js +7 -7
  106. package/src/BookReader/options.js +10 -0
  107. package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
  108. package/src/BookReader/utils/ScrollClassAdder.js +31 -0
  109. package/src/BookReader/utils.js +68 -13
  110. package/src/BookReader.js +375 -289
  111. package/src/assets/icons/close-circle-dark.svg +1 -0
  112. package/src/assets/icons/magnify-minus.svg +3 -7
  113. package/src/assets/icons/magnify-plus.svg +3 -7
  114. package/src/assets/icons/voice.svg +1 -0
  115. package/src/css/BookReader.scss +0 -12
  116. package/src/css/_BRComponent.scss +1 -1
  117. package/src/css/_BRmain.scss +19 -24
  118. package/src/css/_BRnav.scss +4 -26
  119. package/src/css/_BRpages.scss +35 -0
  120. package/src/css/_BRsearch.scss +11 -215
  121. package/src/css/_TextSelection.scss +14 -17
  122. package/src/css/_colorbox.scss +2 -2
  123. package/src/css/_controls.scss +16 -3
  124. package/src/css/_icons.scss +6 -0
  125. package/src/ia-bookreader/ia-bookreader.js +224 -0
  126. package/src/plugins/plugin.chapters.js +26 -33
  127. package/src/plugins/plugin.mobile_nav.js +11 -10
  128. package/src/plugins/plugin.resume.js +3 -3
  129. package/src/plugins/plugin.text_selection.js +26 -39
  130. package/src/plugins/plugin.vendor-fullscreen.js +4 -4
  131. package/src/plugins/search/plugin.search.js +106 -107
  132. package/src/plugins/search/view.js +50 -163
  133. package/src/plugins/tts/AbstractTTSEngine.js +46 -37
  134. package/src/plugins/tts/FestivalTTSEngine.js +12 -13
  135. package/src/plugins/tts/PageChunk.js +15 -21
  136. package/src/plugins/tts/PageChunkIterator.js +8 -12
  137. package/src/plugins/tts/WebTTSEngine.js +64 -68
  138. package/src/plugins/tts/plugin.tts.js +79 -108
  139. package/src/plugins/url/UrlPlugin.js +184 -0
  140. package/src/plugins/{plugin.url.js → url/plugin.url.js} +28 -6
  141. package/tests/e2e/README.md +37 -0
  142. package/tests/e2e/autoplay.test.js +2 -2
  143. package/tests/e2e/base.test.js +7 -7
  144. package/tests/e2e/helpers/base.js +8 -3
  145. package/tests/e2e/helpers/debug.js +1 -1
  146. package/tests/e2e/helpers/desktopSearch.js +14 -13
  147. package/tests/e2e/helpers/mobileSearch.js +3 -3
  148. package/tests/e2e/helpers/params.js +17 -0
  149. package/tests/e2e/models/Navigation.js +12 -3
  150. package/tests/e2e/rightToLeft.test.js +4 -5
  151. package/tests/e2e/viewmode.test.js +38 -33
  152. package/tests/{BookReader → jest/BookReader}/BookModel.test.js +3 -3
  153. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +176 -0
  154. package/tests/{BookReader → jest/BookReader}/DebugConsole.test.js +1 -1
  155. package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
  156. package/tests/jest/BookReader/Mode1UpLit.test.js +88 -0
  157. package/tests/{BookReader → jest/BookReader}/Mode2Up.test.js +5 -7
  158. package/tests/jest/BookReader/ModeSmoothZoom.test.js +149 -0
  159. package/tests/jest/BookReader/ModeThumb.test.js +71 -0
  160. package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +7 -7
  161. package/tests/{BookReader → jest/BookReader}/PageContainer.test.js +79 -6
  162. package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +1 -1
  163. package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +2 -2
  164. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +59 -0
  165. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
  166. package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
  167. package/tests/jest/BookReader/utils.test.js +136 -0
  168. package/tests/jest/BookReader.keyboard.test.js +190 -0
  169. package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +9 -1
  170. package/tests/{BookReader.test.js → jest/BookReader.test.js} +20 -4
  171. package/tests/{plugins → jest/plugins}/plugin.archive_analytics.test.js +2 -2
  172. package/tests/{plugins → jest/plugins}/plugin.autoplay.test.js +2 -2
  173. package/tests/{plugins → jest/plugins}/plugin.chapters.test.js +8 -8
  174. package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +2 -2
  175. package/tests/{plugins → jest/plugins}/plugin.mobile_nav.test.js +5 -5
  176. package/tests/{plugins → jest/plugins}/plugin.resume.test.js +3 -3
  177. package/tests/{plugins → jest/plugins}/plugin.text_selection.test.js +39 -47
  178. package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
  179. package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +24 -25
  180. package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +6 -6
  181. package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +6 -6
  182. package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +4 -4
  183. package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +1 -1
  184. package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +3 -3
  185. package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +1 -1
  186. package/tests/{plugins → jest/plugins}/tts/utils.test.js +3 -3
  187. package/tests/jest/plugins/url/UrlPlugin.test.js +190 -0
  188. package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +33 -14
  189. package/tests/{util → jest/util}/browserSniffing.test.js +1 -1
  190. package/tests/{util → jest/util}/docCookies.test.js +1 -1
  191. package/tests/{util → jest/util}/strings.test.js +1 -1
  192. package/tests/{utils.js → jest/utils.js} +38 -0
  193. package/tests/karma/BookNavigator/book-navigator.test.js +501 -0
  194. package/tests/karma/BookNavigator/bookmarks/bookmark-button.test.js +44 -0
  195. package/tests/karma/BookNavigator/bookmarks/bookmark-edit.test.js +1 -3
  196. package/tests/karma/BookNavigator/bookmarks/bookmarks-list.test.js +3 -4
  197. package/tests/karma/BookNavigator/bookmarks/ia-bookmarks.test.js +57 -0
  198. package/tests/karma/BookNavigator/downloads/downloads-provider.test.js +67 -0
  199. package/tests/karma/BookNavigator/downloads/downloads.test.js +54 -0
  200. package/tests/karma/BookNavigator/search/search-provider.test.js +123 -0
  201. package/tests/karma/BookNavigator/{search-results.test.js → search/search-results.test.js} +1 -4
  202. package/tests/karma/BookNavigator/sharing/sharing-provider.test.js +49 -0
  203. package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -2
  204. package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +184 -0
  205. package/tests/karma/BookNavigator/volumes/volumes.test.js +98 -0
  206. package/webpack.config.js +10 -4
  207. package/.babelrc +0 -12
  208. package/.dependabot/config.yml +0 -6
  209. package/.testcaferc.json +0 -5
  210. package/BookReader/bookreader-component-bundle.js +0 -1450
  211. package/BookReader/bookreader-component-bundle.js.map +0 -1
  212. package/BookReader/plugins/plugin.menu_toggle.js +0 -2
  213. package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
  214. package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
  215. package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
  216. package/src/BookNavigator/BookModel.js +0 -14
  217. package/src/BookNavigator/BookNavigator.js +0 -435
  218. package/src/BookNavigator/assets/book-loader.js +0 -27
  219. package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
  220. package/src/BookReaderComponent/BookReaderComponent.js +0 -112
  221. package/src/ItemNavigator/ItemNavigator.js +0 -372
  222. package/src/ItemNavigator/providers/sharing.js +0 -29
  223. package/src/dragscrollable-br.js +0 -261
  224. package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
  225. package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
  226. package/tests/BookReader/Mode1Up.test.js +0 -164
  227. package/tests/BookReader/utils.test.js +0 -109
  228. package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
@@ -0,0 +1,224 @@
1
+ /**
2
+ * BookReaderTemplate to load BookNavigator components
3
+ */
4
+
5
+ import { LitElement, html, css } from 'lit';
6
+
7
+ import '@internetarchive/ia-item-navigator';
8
+ import '../BookNavigator/book-navigator.js';
9
+ // eslint-disable-next-line no-unused-vars
10
+ import { ModalManager } from '@internetarchive/modal-manager';
11
+ import '@internetarchive/modal-manager';
12
+ import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
13
+
14
+ export class IaBookReader extends LitElement {
15
+ static get properties() {
16
+ return {
17
+ item: { type: Object },
18
+ baseHost: { type: String },
19
+ signedIn: { type: Boolean },
20
+ fullscreen: { type: Boolean, reflect: true, attribute: true },
21
+ sharedObserver: { type: Object, attribute: false },
22
+ modal: { type: Object, attribute: false },
23
+ loaded: { type: Boolean },
24
+ menuShortcuts: { type: Array },
25
+ menuContents: { type: Array },
26
+ };
27
+ }
28
+
29
+ constructor() {
30
+ super();
31
+ this.item = undefined;
32
+ this.bookreader = undefined;
33
+ this.baseHost = 'https://archive.org';
34
+ this.fullscreen = false;
35
+ this.signedIn = false;
36
+ /** @type {ModalManager} */
37
+ this.modal = undefined;
38
+ /** @type {SharedResizeObserver} */
39
+ this.sharedObserver = undefined;
40
+ this.loaded = false;
41
+ this.menuShortcuts = [];
42
+ this.menuContents = [];
43
+ this.openMenuName = '';
44
+ }
45
+
46
+ updated() {
47
+ if (!this.modal) {
48
+ this.setModalManager();
49
+ }
50
+
51
+ if (!this.sharedObserver) {
52
+ this.sharedObserver = new SharedResizeObserver();
53
+ }
54
+ }
55
+
56
+ get itemNav() {
57
+ return this.shadowRoot.querySelector('ia-item-navigator');
58
+ }
59
+
60
+ /** Creates modal DOM & attaches to `<body>` */
61
+ setModalManager() {
62
+ let modalManager = document.querySelector('modal-manager');
63
+ if (!modalManager) {
64
+ modalManager = document.createElement(
65
+ 'modal-manager'
66
+ );
67
+ document.body.appendChild(modalManager);
68
+ }
69
+
70
+ this.modal = modalManager;
71
+ }
72
+
73
+ manageFullscreen(e) {
74
+ const { detail } = e;
75
+ const fullscreen = !!detail.isFullScreen;
76
+ this.fullscreen = fullscreen;
77
+ this.dispatchEvent(new CustomEvent('fullscreenStateUpdated', { detail: { fullscreen }}));
78
+
79
+ }
80
+
81
+ loadingStateUpdated(e) {
82
+ const { loaded } = e.detail;
83
+ this.loaded = loaded || null;
84
+ this.dispatchEvent(new CustomEvent('loadingStateUpdated', { detail: { loaded }}));
85
+ }
86
+
87
+ setMenuShortcuts(e) {
88
+ this.menuShortcuts = [...e.detail];
89
+ }
90
+
91
+ setMenuContents(e) {
92
+ const updatedContents = [...e.detail];
93
+ this.menuContents = updatedContents;
94
+ }
95
+
96
+ manageSideMenuEvents(e) {
97
+ const { menuId, action } = e.detail;
98
+ if (!menuId) {
99
+ return;
100
+ }
101
+
102
+ this.openMenuName = menuId;
103
+
104
+ if (action === 'open') {
105
+ this.itemNav?.openShortcut(menuId);
106
+ } else if (action === 'toggle') {
107
+ this.itemNav?.toggleMenu();
108
+ }
109
+ }
110
+
111
+ render() {
112
+ return html`
113
+ <div class="main-component">
114
+ <ia-item-navigator
115
+ ?viewportInFullscreen=${this.fullscreen}
116
+ .basehost=${this.baseHost}
117
+ .item=${this.item}
118
+ .modal=${this.modal}
119
+ .loaded=${this.loaded}
120
+ .sharedObserver=${this.sharedObserver}
121
+ ?signedIn=${this.signedIn}
122
+ .menuShortcuts=${this.menuShortcuts}
123
+ .menuContents=${this.menuContents}
124
+ .openMenu=${this.openMenuName}
125
+ >
126
+ <div slot="header">
127
+ <slot name="header"></slot>
128
+ </div>
129
+ <div slot="main">
130
+ <book-navigator
131
+ .modal=${this.modal}
132
+ .baseHost=${this.baseHost}
133
+ .itemMD=${this.item}
134
+ ?signedIn=${this.signedIn}
135
+ ?sideMenuOpen=${this.menuOpened}
136
+ .sharedObserver=${this.sharedObserver}
137
+ @ViewportInFullScreen=${this.manageFullscreen}
138
+ @loadingStateUpdated=${this.loadingStateUpdated}
139
+ @updateSideMenu=${this.manageSideMenuEvents}
140
+ @menuUpdated=${this.setMenuContents}
141
+ @menuShortcutsUpdated=${this.setMenuShortcuts}
142
+ >
143
+ <div slot="main">
144
+ <slot name="main"></slot>
145
+ </div>
146
+ </book-navigator>
147
+ </div>
148
+ </ia-item-navigator>
149
+ </div>
150
+ `;
151
+ }
152
+
153
+ static get styles() {
154
+ return css`
155
+ :host {
156
+ display: block;
157
+ --primaryBGColor: var(--black, #000);
158
+ --secondaryBGColor: #222;
159
+ --tertiaryBGColor: #333;
160
+ --primaryTextColor: var(--white, #fff);
161
+ --primaryCTAFill: #194880;
162
+ --primaryCTABorder: #c5d1df;
163
+ --secondaryCTAFill: #333;
164
+ --secondaryCTABorder: #999;
165
+ --primaryErrorCTAFill: #e51c26;
166
+ --primaryErrorCTABorder: #f8c6c8;
167
+ background-color: var(--primaryBGColor);
168
+ position: relative;
169
+ }
170
+
171
+ :host([fullscreen]),
172
+ ia-item-navigator[viewportinfullscreen] {
173
+ position: fixed;
174
+ inset: 0;
175
+ height: 100%;
176
+ min-height: unset;
177
+ }
178
+
179
+ .main-component {
180
+ height: 100%;
181
+ width: 100%;
182
+ min-height: inherit;
183
+ }
184
+
185
+ div[slot="header"],
186
+ div[slot="main"] {
187
+ display: flex;
188
+ width: 100%;
189
+ }
190
+
191
+ slot {
192
+ display: block;
193
+ flex: 1;
194
+ }
195
+
196
+ ia-item-navigator {
197
+ min-height: var(--br-height, inherit);
198
+ height: var(--br-height, inherit);
199
+ display: block;
200
+ width: 100%;
201
+ color: var(--primaryTextColor);
202
+ --menuButtonLabelDisplay: block;
203
+ --menuWidth: 320px;
204
+ --menuSliderBg: var(--secondaryBGColor);
205
+ --activeButtonBg: var(--tertiaryBGColor);
206
+ --subpanelRightBorderColor: var(--secondaryCTABorder);
207
+ --animationTiming: 100ms;
208
+ --iconFillColor: var(--primaryTextColor);
209
+ --iconStrokeColor: var(--primaryTextColor);
210
+ --menuSliderHeaderIconHeight: 2rem;
211
+ --menuSliderHeaderIconWidth: 2rem;
212
+ --iconWidth: 2.4rem;
213
+ --iconHeight: 2.4rem;
214
+ --shareLinkColor: var(--primaryTextColor);
215
+ --shareIconBorder: var(--primaryTextColor);
216
+ --shareIconBg: var(--secondaryBGColor);
217
+ --activityIndicatorLoadingDotColor: var(--primaryTextColor);
218
+ --activityIndicatorLoadingRingColor: var(--primaryTextColor);
219
+ }
220
+ `;
221
+ }
222
+ }
223
+
224
+ window.customElements.define("ia-bookreader", IaBookReader);
@@ -36,14 +36,12 @@ BookReader.prototype.init = (function(super_) {
36
36
  this.updateTOCState(this.firstIndex, this._tocEntries);
37
37
  }
38
38
  }
39
- )
40
- $(".BRmobileMenu__tableContents").click(
41
- () => {
42
- this.updateTOCState(this.firstIndex, this._tocEntries);
43
- }
44
39
  );
40
+ $(".BRmobileMenu__tableContents").on("click", () => {
41
+ this.updateTOCState(this.firstIndex, this._tocEntries);
42
+ });
45
43
  }
46
- }
44
+ };
47
45
  })(BookReader.prototype.init);
48
46
 
49
47
  /**
@@ -60,7 +58,7 @@ BookReader.prototype.addChapter = function(chapterTitle, pageNumber, pageIndex)
60
58
  this.jumpToIndex($(event.delegateTarget).data('pageIndex'));
61
59
  $('.current-chapter').removeClass('current-chapter');
62
60
  $(event.delegateTarget).addClass('current-chapter');
63
- }
61
+ };
64
62
  const title = `${chapterTitle} | `;
65
63
  const pageStr = `${uiStringPage} ${pageNumber}`;
66
64
 
@@ -79,7 +77,7 @@ BookReader.prototype.addChapter = function(chapterTitle, pageNumber, pageIndex)
79
77
  .css({ left: percentThrough })
80
78
  .appendTo(this.$('.BRnavline'))
81
79
  .data({ pageIndex })
82
- .hover(event => {
80
+ .on("mouseenter", event => {
83
81
  // remove hover effect from other markers then turn on just for this
84
82
  const marker = event.currentTarget;
85
83
  const tooltip = marker.querySelector('div');
@@ -91,9 +89,8 @@ BookReader.prototype.addChapter = function(chapterTitle, pageNumber, pageIndex)
91
89
  }
92
90
  this.$('.BRsearch,.BRchapter').removeClass('front');
93
91
  $(event.target).addClass('front');
94
- },
95
- event => $(event.target).removeClass('front')
96
- )
92
+ })
93
+ .on("mouseleave", event => $(event.target).removeClass('front'))
97
94
  .on('click', jumpToChapter);
98
95
 
99
96
  //adding clickable properties to mobile chapters
@@ -126,7 +123,7 @@ BookReader.prototype.updateTOC = function(tocEntries) {
126
123
  this._tocEntries = tocEntries;
127
124
  $('.table-contents-list').children().each((i, el) => {
128
125
  tocEntries[i].mobileHTML = el;
129
- })
126
+ });
130
127
  };
131
128
 
132
129
  /**
@@ -162,9 +159,9 @@ BookReader.prototype.addChapterFromEntry = function(tocEntryObject) {
162
159
  this.addChapter(chapterStr, tocEntryObject['pagenum'], tocEntryObject.pageIndex);
163
160
  this.$('.BRchapter, .BRsearch').each((i, el) => {
164
161
  const $el = $(el);
165
- $el.hover(
166
- () => $el.addClass('front'),
167
- () => $el.removeClass('front'));
162
+ $el
163
+ .on("mouseenter", () => $el.addClass('front'))
164
+ .on("mouseleave", () => $el.removeClass('front'));
168
165
  });
169
166
  };
170
167
 
@@ -177,7 +174,7 @@ BookReader.prototype.addChapterFromEntry = function(tocEntryObject) {
177
174
  * This makes a call to OL API and calls the given callback function with the
178
175
  * response from the API.
179
176
  */
180
- BookReader.prototype.getOpenLibraryRecord = function () {
177
+ BookReader.prototype.getOpenLibraryRecord = async function () {
181
178
  // Try looking up by ocaid first, then by source_record
182
179
  const baseURL = `${this.olHost}/query.json?type=/type/edition&*=`;
183
180
  const fetchUrlByBookId = `${baseURL}&ocaid=${this.bookId}`;
@@ -193,21 +190,17 @@ BookReader.prototype.getOpenLibraryRecord = function () {
193
190
  }
194
191
  };
195
192
 
196
- $.ajax({ url: fetchUrlByBookId, dataType: 'jsonp' })
197
- .then(data => {
198
- if (data && data.length > 0) {
199
- return data;
200
- } else {
201
- // try sourceid
202
- return $.ajax({ url: `${baseURL}&source_records=ia:${this.bookId}`, dataType: 'jsonp' });
203
- }
204
- })
205
- .then(data => {
206
- if (data && data.length > 0) {
207
- setUpChapterMarkers(data[0]);
208
- }
209
- });
210
- }
193
+ let data = await $.ajax({ url: fetchUrlByBookId, dataType: 'jsonp' });
194
+
195
+ if (!data || !data.length) {
196
+ // try sourceid
197
+ data = await $.ajax({ url: `${baseURL}&source_records=ia:${this.bookId}`, dataType: 'jsonp' });
198
+ }
199
+
200
+ if (data && data.length > 0) {
201
+ setUpChapterMarkers(data[0]);
202
+ }
203
+ };
211
204
 
212
205
  // Extend buildMobileDrawerElement with table of contents list
213
206
  BookReader.prototype.buildMobileDrawerElement = (function (super_) {
@@ -240,7 +233,7 @@ BookReader.prototype.buildMobileDrawerElement = (function (super_) {
240
233
  */
241
234
  BookReader.prototype.updateTOCState = function(currIndex, tocEntries) {
242
235
  //this function won't have any effects if called before OpenLibrary request is finished
243
- if (!tocEntries) {return}
236
+ if (!tocEntries) {return;}
244
237
  $('.current-chapter').removeClass('current-chapter');
245
238
  const tocEntriesIndexed = tocEntries.filter((el) => el.pageIndex != undefined).reverse();
246
239
  const currChapter = tocEntriesIndexed[tocEntriesIndexed.findIndex(
@@ -248,4 +241,4 @@ BookReader.prototype.updateTOCState = function(currIndex, tocEntries) {
248
241
  if (currChapter != undefined) {
249
242
  $(currChapter.mobileHTML).addClass('current-chapter');
250
243
  }
251
- }
244
+ };
@@ -25,7 +25,7 @@ const FILTERLIST = [
25
25
  filter: "contrast(120%)",
26
26
  label: "High contrast"
27
27
  },
28
- ]
28
+ ];
29
29
 
30
30
  jQuery.extend(BookReader.defaultOptions, {
31
31
  enableMobileNav: true,
@@ -86,15 +86,16 @@ BookReader.prototype.initToolbar = (function (super_) {
86
86
  });
87
87
 
88
88
  //apply filters when checkboxs clicked
89
- $drawerEl.find('.BRcheckbox-filters').click(() => applyFilters($drawerEl, this));
89
+ $drawerEl.find('.BRcheckbox-filters')
90
+ .on("click", () => applyFilters($drawerEl, this));
90
91
 
91
92
  // Bind mobile switch buttons
92
- $drawerEl.find('.DrawerLayoutButton.one_page_mode').click(
93
- () => this.switchMode(this.constMode1up));
94
- $drawerEl.find('.DrawerLayoutButton.two_page_mode').click(
95
- () => this.switchMode(this.constMode2up));
96
- $drawerEl.find('.DrawerLayoutButton.thumbnail_mode').click(
97
- () => this.switchMode(this.constModeThumb));
93
+ $drawerEl.find('.DrawerLayoutButton.one_page_mode')
94
+ .on("click", () => this.switchMode(this.constMode1up));
95
+ $drawerEl.find('.DrawerLayoutButton.two_page_mode')
96
+ .on("click", () => this.switchMode(this.constMode2up));
97
+ $drawerEl.find('.DrawerLayoutButton.thumbnail_mode')
98
+ .on("click", () => this.switchMode(this.constModeThumb));
98
99
 
99
100
  if (this.mobileNavFullscreenOnly) {
100
101
  $(document.body).addClass('BRbodyMobileNavEnabledFullscreen');
@@ -178,7 +179,7 @@ BookReader.prototype.buildMobileDrawerElement = function() {
178
179
 
179
180
  `;
180
181
  experimentalHtml = experimentalHtml.concat(checkboxHtml);
181
- })
182
+ });
182
183
  experimentalHtml = experimentalHtml.concat("</div>");
183
184
  }
184
185
 
@@ -284,4 +285,4 @@ const applyFilters = (drawerEl, br) => {
284
285
  filter: ${filterStr};
285
286
  -webkit-filter: ${filterStr};}`;
286
287
  document.body.appendChild(filtersSheet);
287
- }
288
+ };
@@ -37,7 +37,7 @@ BookReader.prototype.getResumeValue = function() {
37
37
  const val = BookReader.docCookies.getItem('br-resume');
38
38
  if (val !== null) return parseInt(val);
39
39
  else return null;
40
- }
40
+ };
41
41
 
42
42
  /**
43
43
  * Return cookie path using pathname up to /page/... or /mode/...
@@ -49,7 +49,7 @@ BookReader.prototype.getResumeValue = function() {
49
49
  */
50
50
  BookReader.prototype.getCookiePath = function(urlPathPart) {
51
51
  return urlPathPart.match('.+?(?=/page/|/mode/|$)')[0];
52
- }
52
+ };
53
53
 
54
54
  /**
55
55
  * Sets page resume value, for remembering reader's page
@@ -65,4 +65,4 @@ BookReader.prototype.updateResumeValue = function(index, cookieName) {
65
65
  const path = this.options.resumeCookiePath
66
66
  || this.getCookiePath(window.location.pathname);
67
67
  BookReader.docCookies.setItem(cookieName || 'br-resume', index, ttl, path, null, false);
68
- }
68
+ };
@@ -1,7 +1,9 @@
1
1
  //@ts-check
2
+ import { createSVGPageLayer } from '../BookReader/PageContainer.js';
2
3
  import { isFirefox, isSafari } from '../util/browserSniffing.js';
3
4
  import { applyVariables } from '../util/strings.js';
4
5
  /** @typedef {import('../util/strings.js').StringWithVars} StringWithVars */
6
+ /** @typedef {import('../BookReader/PageContainer.js').PageContainer} PageContainer */
5
7
 
6
8
  const BookReader = /** @type {typeof import('../BookReader').default} */(window.BookReader);
7
9
 
@@ -46,7 +48,7 @@ export class TextSelectionPlugin {
46
48
  // Tspans are necessary on Chrome because they prevent newline character after every word when copying
47
49
  this.svgParagraphElement = "text";
48
50
  this.svgWordElement = "tspan";
49
- this.insertNewlines = avoidTspans
51
+ this.insertNewlines = avoidTspans;
50
52
  // Safari has a bug where `pointer-events` doesn't work on `<tspans>`. So
51
53
  // there we will set `pointer-events: all` on the paragraph element. We don't
52
54
  // do this everywhere, because it's a worse experience. Thanks Safari :/
@@ -94,21 +96,20 @@ export class TextSelectionPlugin {
94
96
  if (cachedEntry) {
95
97
  return cachedEntry.response;
96
98
  }
97
- return $.ajax({
99
+ const res = await $.ajax({
98
100
  type: "GET",
99
101
  url: applyVariables(this.options.singlePageDjvuXmlUrl, this.optionVariables, { pageIndex: index }),
100
102
  dataType: "html",
101
103
  error: (e) => undefined,
102
- }).then((res) => {
103
- try {
104
- const xmlDoc = $.parseXML(res);
105
- const result = xmlDoc && $(xmlDoc).find("OBJECT")[0];
106
- this.pageTextCache.add({ index, response: result });
107
- return result;
108
- } catch (e) {
109
- return undefined;
110
- }
111
104
  });
105
+ try {
106
+ const xmlDoc = $.parseXML(res);
107
+ const result = xmlDoc && $(xmlDoc).find("OBJECT")[0];
108
+ this.pageTextCache.add({ index, response: result });
109
+ return result;
110
+ } catch (e) {
111
+ return undefined;
112
+ }
112
113
  } else {
113
114
  const XMLpagesArr = await this.djvuPagesPromise;
114
115
  if (XMLpagesArr) return XMLpagesArr[index];
@@ -144,8 +145,8 @@ export class TextSelectionPlugin {
144
145
  this.textSelectingMode(svg);
145
146
  }
146
147
  else svg.classList.remove("selectingSVG");
147
- })
148
- })
148
+ });
149
+ });
149
150
  }
150
151
 
151
152
  /**
@@ -158,13 +159,13 @@ export class TextSelectionPlugin {
158
159
  if (window.getSelection().toString() != "") window.getSelection().removeAllRanges();
159
160
  }
160
161
  event.stopPropagation();
161
- })
162
+ });
162
163
  $(svg).on('mouseup.textSelectPluginHandler', (event) => {
163
164
  event.stopPropagation();
164
165
  if (window.getSelection().toString() == "") {
165
166
  $(svg).off(".textSelectPluginHandler");
166
167
  this.defaultMode(svg); }
167
- })
168
+ });
168
169
  }
169
170
 
170
171
  /**
@@ -175,21 +176,20 @@ export class TextSelectionPlugin {
175
176
  /** @type {JQuery<SVGElement>} */
176
177
  const $svg = $container.find('svg.textSelectionSVG');
177
178
  if (!$svg.length) return;
178
- $svg.each((i, s) => this.defaultMode(s))
179
+ $svg.each((i, s) => this.defaultMode(s));
179
180
  this.interceptCopy($container);
180
181
  }
181
182
 
182
183
  /**
183
- * @param {number} pageIndex
184
- * @param {JQuery} $container
184
+ * @param {PageContainer} pageContainer
185
185
  */
186
- async createTextLayer(pageIndex, $container) {
186
+ async createTextLayer(pageContainer) {
187
+ const pageIndex = pageContainer.page.index;
188
+ const $container = pageContainer.$container;
187
189
  const $svgLayers = $container.find('.textSelectionSVG');
188
190
  if ($svgLayers.length) return;
189
191
  const XMLpage = await this.getPageText(pageIndex);
190
192
  if (!XMLpage) return;
191
- const XMLwidth = $(XMLpage).attr("width");
192
- const XMLheight = $(XMLpage).attr("height");
193
193
 
194
194
  const totalWords = $(XMLpage).find("WORD").length;
195
195
  if (totalWords > this.maxWordRendered) {
@@ -197,19 +197,8 @@ export class TextSelectionPlugin {
197
197
  return;
198
198
  }
199
199
 
200
- const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
201
- svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
202
- svg.setAttribute("viewBox", `0 0 ${XMLwidth} ${XMLheight}`);
200
+ const svg = createSVGPageLayer(pageContainer.page, 'textSelectionSVG');
203
201
  $container.append(svg);
204
- svg.setAttribute('class', 'textSelectionSVG');
205
- svg.setAttribute('preserveAspectRatio', 'none');
206
- $(svg).css({
207
- "width": "100%",
208
- "position": "absolute",
209
- "height": "100%",
210
- "top": "0",
211
- "left": "0",
212
- });
213
202
 
214
203
  $(XMLpage).find("PARAGRAPH").each((i, paragraph) => {
215
204
  // Adding text element for each paragraph in the page
@@ -266,7 +255,7 @@ export class TextSelectionPlugin {
266
255
  const paragWordHeight = wordHeightArr[Math.floor(wordHeightArr.length * 0.85)];
267
256
  paragSvg.setAttribute("font-size", paragWordHeight.toString());
268
257
  svg.appendChild(paragSvg);
269
- })
258
+ });
270
259
  this.stopPageFlip($container);
271
260
  }
272
261
  }
@@ -290,11 +279,9 @@ export class BookreaderWithTextSelection extends BookReader {
290
279
  _createPageContainer(index) {
291
280
  const pageContainer = super._createPageContainer(index);
292
281
  // Disable if thumb mode; it's too janky
293
- // index can be -1 for "pre-cover" region
294
- // Added checking of lastPageIndex to avoid loop around index value
295
- const lastPageIndex = this.getNumLeafs() - 1;
296
- if (this.mode !== this.constModeThumb && (index >= 0 && index <= lastPageIndex)) {
297
- this.textSelectionPlugin?.createTextLayer(index, pageContainer.$container);
282
+ // .page can be null for "pre-cover" region
283
+ if (this.mode !== this.constModeThumb && pageContainer.page) {
284
+ this.textSelectionPlugin?.createTextLayer(pageContainer);
298
285
  }
299
286
  return pageContainer;
300
287
  }
@@ -56,7 +56,7 @@ if (!isMobile()) {
56
56
  $(document.body).append(cboxOverlay).append(cbox);
57
57
  }
58
58
  });
59
- }
59
+ };
60
60
  })(BookReader.prototype.init);
61
61
 
62
62
  /**
@@ -92,7 +92,7 @@ if (!isMobile()) {
92
92
  $(document).off('keyup' + EVENT_NAMESPACE);
93
93
 
94
94
  this.isFullscreenActive = false;
95
- this.updateBrClasses()
95
+ this.updateBrClasses();
96
96
 
97
97
  this.resize();
98
98
  this.refs.$brContainer.animate({ opacity: 1 }, 400, 'linear');
@@ -233,8 +233,8 @@ export function bindFullscreenChangeListener(
233
233
  'moz',
234
234
  'ms'
235
235
  ];
236
- const all_events = $.trim(event + vendor_prefixes.join(event) + event);
237
- $(document).bind(all_events, data, fullscreenchangeListener);
236
+ const all_events = (event + vendor_prefixes.join(event) + event).trim();
237
+ $(document).on(all_events, data, fullscreenchangeListener);
238
238
  }
239
239
 
240
240
  /**