@internetarchive/bookreader 5.0.0-6-14 → 5.0.0-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. package/.eslintrc.js +17 -15
  2. package/.github/workflows/node.js.yml +72 -10
  3. package/.github/workflows/npm-publish.yml +6 -20
  4. package/.testcaferc.js +10 -0
  5. package/BookReader/BookReader.css +241 -140
  6. package/BookReader/BookReader.js +1 -1
  7. package/BookReader/BookReader.js.LICENSE.txt +24 -20
  8. package/BookReader/BookReader.js.map +1 -1
  9. package/BookReader/ia-bookreader-bundle.js +1519 -0
  10. package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +17 -0
  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/pause.svg +1 -1
  16. package/BookReader/icons/playback-speed.svg +1 -1
  17. package/BookReader/icons/read-aloud.svg +1 -1
  18. package/BookReader/icons/voice.svg +1 -0
  19. package/BookReader/images/BRicons.svg +2 -2
  20. package/BookReader/images/books_graphic.svg +1 -1
  21. package/BookReader/images/icon_book.svg +1 -1
  22. package/BookReader/images/icon_gear.svg +1 -1
  23. package/BookReader/images/icon_info.svg +1 -1
  24. package/BookReader/images/icon_playback-rate.svg +1 -1
  25. package/BookReader/images/icon_search_button.svg +1 -1
  26. package/BookReader/images/icon_share.svg +1 -1
  27. package/BookReader/images/icon_speaker.svg +1 -1
  28. package/BookReader/images/icon_speaker_open.svg +1 -1
  29. package/BookReader/images/marker_chap-off.svg +1 -1
  30. package/BookReader/images/marker_chap-on.svg +1 -1
  31. package/BookReader/images/marker_srch-on.svg +1 -1
  32. package/BookReader/jquery-3.js +2 -0
  33. package/BookReader/jquery-3.js.LICENSE.txt +24 -0
  34. package/BookReader/plugins/plugin.archive_analytics.js +1 -1
  35. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  36. package/BookReader/plugins/plugin.autoplay.js +1 -1
  37. package/BookReader/plugins/plugin.autoplay.js.map +1 -1
  38. package/BookReader/plugins/plugin.chapters.js +1 -1
  39. package/BookReader/plugins/plugin.chapters.js.map +1 -1
  40. package/BookReader/plugins/plugin.iframe.js +1 -1
  41. package/BookReader/plugins/plugin.iframe.js.map +1 -1
  42. package/BookReader/plugins/plugin.mobile_nav.js +1 -1
  43. package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
  44. package/BookReader/plugins/plugin.resume.js +1 -1
  45. package/BookReader/plugins/plugin.resume.js.map +1 -1
  46. package/BookReader/plugins/plugin.search.js +1 -1
  47. package/BookReader/plugins/plugin.search.js.map +1 -1
  48. package/BookReader/plugins/plugin.text_selection.js +1 -1
  49. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  50. package/BookReader/plugins/plugin.tts.js +1 -1
  51. package/BookReader/plugins/plugin.tts.js.map +1 -1
  52. package/BookReader/plugins/plugin.url.js +1 -1
  53. package/BookReader/plugins/plugin.url.js.map +1 -1
  54. package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
  55. package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
  56. package/BookReader/webcomponents-bundle.js +3 -0
  57. package/BookReader/webcomponents-bundle.js.LICENSE.txt +9 -0
  58. package/BookReader/webcomponents-bundle.js.map +1 -0
  59. package/BookReaderDemo/BookReaderDemo.css +14 -1
  60. package/BookReaderDemo/BookReaderJSAutoplay.js +4 -1
  61. package/BookReaderDemo/BookReaderJSSimple.js +1 -0
  62. package/BookReaderDemo/IADemoBr.js +147 -0
  63. package/BookReaderDemo/demo-advanced.html +2 -2
  64. package/BookReaderDemo/demo-autoplay.html +2 -1
  65. package/BookReaderDemo/demo-embed-iframe-src.html +2 -1
  66. package/BookReaderDemo/demo-fullscreen-mobile.html +2 -1
  67. package/BookReaderDemo/demo-fullscreen.html +2 -1
  68. package/BookReaderDemo/demo-iiif.html +2 -1
  69. package/BookReaderDemo/demo-internetarchive.html +84 -17
  70. package/BookReaderDemo/demo-multiple.html +2 -1
  71. package/BookReaderDemo/demo-preview-pages.html +2 -1
  72. package/BookReaderDemo/demo-simple.html +2 -1
  73. package/BookReaderDemo/demo-vendor-fullscreen.html +2 -1
  74. package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
  75. package/BookReaderDemo/immersion-1up.html +2 -1
  76. package/BookReaderDemo/immersion-mode.html +2 -1
  77. package/BookReaderDemo/toggle_controls.html +2 -1
  78. package/BookReaderDemo/view_mode.html +2 -1
  79. package/BookReaderDemo/viewmode-cycle.html +2 -3
  80. package/CHANGELOG.md +244 -0
  81. package/README.md +14 -1
  82. package/babel.config.js +19 -0
  83. package/codecov.yml +6 -0
  84. package/index.html +3 -0
  85. package/jsconfig.json +19 -0
  86. package/netlify.toml +5 -0
  87. package/package.json +70 -59
  88. package/renovate.json +52 -0
  89. package/scripts/preversion.js +4 -1
  90. package/src/BookNavigator/assets/bookmark-colors.js +1 -1
  91. package/src/BookNavigator/assets/button-base.js +9 -2
  92. package/src/BookNavigator/assets/ia-logo.js +17 -0
  93. package/src/BookNavigator/assets/icon_checkmark.js +1 -1
  94. package/src/BookNavigator/assets/icon_close.js +1 -1
  95. package/src/BookNavigator/assets/icon_sort_asc.js +5 -0
  96. package/src/BookNavigator/assets/icon_sort_desc.js +5 -0
  97. package/src/BookNavigator/assets/icon_sort_neutral.js +5 -0
  98. package/src/BookNavigator/assets/icon_volumes.js +11 -0
  99. package/src/BookNavigator/book-navigator.js +585 -0
  100. package/src/BookNavigator/bookmarks/bookmark-button.js +3 -2
  101. package/src/BookNavigator/bookmarks/bookmark-edit.js +3 -4
  102. package/src/BookNavigator/bookmarks/bookmarks-list.js +2 -3
  103. package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +3 -8
  104. package/src/BookNavigator/bookmarks/bookmarks-provider.js +27 -17
  105. package/src/BookNavigator/bookmarks/ia-bookmarks.js +116 -67
  106. package/src/BookNavigator/delete-modal-actions.js +1 -1
  107. package/src/BookNavigator/downloads/downloads-provider.js +36 -21
  108. package/src/BookNavigator/downloads/downloads.js +41 -25
  109. package/src/BookNavigator/search/search-provider.js +80 -28
  110. package/src/BookNavigator/search/search-results.js +34 -25
  111. package/src/BookNavigator/sharing.js +27 -0
  112. package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +11 -10
  113. package/src/BookNavigator/visual-adjustments/visual-adjustments.js +3 -3
  114. package/src/BookNavigator/volumes/volumes-provider.js +111 -0
  115. package/src/BookNavigator/volumes/volumes.js +188 -0
  116. package/src/BookReader/BookModel.js +59 -30
  117. package/src/BookReader/DebugConsole.js +3 -3
  118. package/src/BookReader/DragScrollable.js +233 -0
  119. package/src/BookReader/Mode1Up.js +56 -351
  120. package/src/BookReader/Mode1UpLit.js +391 -0
  121. package/src/BookReader/Mode2Up.js +73 -1318
  122. package/src/BookReader/Mode2UpLit.js +781 -0
  123. package/src/BookReader/ModeCoordinateSpace.js +29 -0
  124. package/src/BookReader/ModeSmoothZoom.js +211 -0
  125. package/src/BookReader/ModeThumb.js +17 -11
  126. package/src/BookReader/Navbar/Navbar.js +10 -36
  127. package/src/BookReader/PageContainer.js +69 -6
  128. package/src/BookReader/ReduceSet.js +1 -1
  129. package/src/BookReader/Toolbar/Toolbar.js +10 -37
  130. package/src/BookReader/events.js +2 -0
  131. package/src/BookReader/options.js +24 -2
  132. package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
  133. package/src/BookReader/utils/ScrollClassAdder.js +31 -0
  134. package/src/BookReader/utils.js +108 -13
  135. package/src/BookReader.js +481 -828
  136. package/src/assets/icons/close-circle-dark.svg +1 -0
  137. package/src/assets/icons/magnify-minus.svg +3 -7
  138. package/src/assets/icons/magnify-plus.svg +3 -7
  139. package/src/assets/icons/voice.svg +1 -0
  140. package/src/css/_BRBookmarks.scss +1 -1
  141. package/src/css/_BRComponent.scss +1 -1
  142. package/src/css/_BRmain.scss +33 -0
  143. package/src/css/_BRnav.scss +4 -26
  144. package/src/css/_BRpages.scss +147 -40
  145. package/src/css/_BRsearch.scss +25 -11
  146. package/src/css/_TextSelection.scss +16 -17
  147. package/src/css/_colorbox.scss +2 -2
  148. package/src/css/_controls.scss +17 -5
  149. package/src/css/_icons.scss +7 -1
  150. package/src/ia-bookreader/ia-bookreader.js +224 -0
  151. package/src/plugins/plugin.archive_analytics.js +3 -3
  152. package/src/plugins/plugin.autoplay.js +4 -9
  153. package/src/plugins/plugin.chapters.js +28 -35
  154. package/src/plugins/plugin.mobile_nav.js +11 -10
  155. package/src/plugins/plugin.resume.js +3 -3
  156. package/src/plugins/plugin.text_selection.js +32 -41
  157. package/src/plugins/plugin.vendor-fullscreen.js +4 -4
  158. package/src/plugins/search/plugin.search.js +179 -103
  159. package/src/plugins/search/view.js +59 -44
  160. package/src/plugins/tts/AbstractTTSEngine.js +46 -37
  161. package/src/plugins/tts/FestivalTTSEngine.js +13 -14
  162. package/src/plugins/tts/PageChunk.js +15 -21
  163. package/src/plugins/tts/PageChunkIterator.js +8 -12
  164. package/src/plugins/tts/WebTTSEngine.js +87 -71
  165. package/src/plugins/tts/plugin.tts.js +94 -125
  166. package/src/plugins/tts/utils.js +0 -25
  167. package/src/plugins/url/UrlPlugin.js +193 -0
  168. package/src/plugins/{plugin.url.js → url/plugin.url.js} +45 -16
  169. package/src/util/docCookies.js +21 -2
  170. package/tests/e2e/README.md +37 -0
  171. package/tests/e2e/autoplay.test.js +2 -2
  172. package/tests/e2e/base.test.js +7 -7
  173. package/tests/e2e/helpers/base.js +28 -23
  174. package/tests/e2e/helpers/debug.js +1 -1
  175. package/tests/e2e/helpers/desktopSearch.js +14 -13
  176. package/tests/e2e/helpers/mobileSearch.js +3 -3
  177. package/tests/e2e/helpers/params.js +17 -0
  178. package/tests/e2e/helpers/rightToLeft.js +4 -10
  179. package/tests/e2e/models/Navigation.js +13 -4
  180. package/tests/e2e/rightToLeft.test.js +4 -5
  181. package/tests/e2e/viewmode.test.js +40 -33
  182. package/tests/jest/BookNavigator/book-navigator.test.js +658 -0
  183. package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +43 -0
  184. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-edit.test.js +25 -26
  185. package/tests/{karma → jest}/BookNavigator/bookmarks/bookmarks-list.test.js +41 -42
  186. package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +45 -0
  187. package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +67 -0
  188. package/tests/jest/BookNavigator/downloads/downloads.test.js +53 -0
  189. package/tests/jest/BookNavigator/search/search-provider.test.js +167 -0
  190. package/tests/{karma/BookNavigator → jest/BookNavigator/search}/search-results.test.js +104 -60
  191. package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +49 -0
  192. package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
  193. package/tests/jest/BookNavigator/volumes/volumes-provider.test.js +184 -0
  194. package/tests/jest/BookNavigator/volumes/volumes.test.js +97 -0
  195. package/tests/{BookReader → jest/BookReader}/BookModel.test.js +59 -14
  196. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +193 -0
  197. package/tests/{BookReader → jest/BookReader}/DebugConsole.test.js +1 -1
  198. package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
  199. package/tests/jest/BookReader/Mode1UpLit.test.js +73 -0
  200. package/tests/jest/BookReader/Mode2Up.test.js +98 -0
  201. package/tests/jest/BookReader/Mode2UpLit.test.js +190 -0
  202. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +16 -0
  203. package/tests/jest/BookReader/ModeSmoothZoom.test.js +175 -0
  204. package/tests/jest/BookReader/ModeThumb.test.js +71 -0
  205. package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +10 -10
  206. package/tests/{BookReader → jest/BookReader}/PageContainer.test.js +88 -6
  207. package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +1 -1
  208. package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +2 -2
  209. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +59 -0
  210. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
  211. package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
  212. package/tests/jest/BookReader/utils.test.js +217 -0
  213. package/tests/jest/BookReader.keyboard.test.js +190 -0
  214. package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +9 -1
  215. package/tests/{BookReader.test.js → jest/BookReader.test.js} +26 -37
  216. package/tests/{plugins → jest/plugins}/plugin.archive_analytics.test.js +2 -2
  217. package/tests/{plugins → jest/plugins}/plugin.autoplay.test.js +4 -4
  218. package/tests/{plugins → jest/plugins}/plugin.chapters.test.js +10 -11
  219. package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +2 -2
  220. package/tests/{plugins → jest/plugins}/plugin.mobile_nav.test.js +5 -5
  221. package/tests/{plugins → jest/plugins}/plugin.resume.test.js +3 -3
  222. package/tests/{plugins → jest/plugins}/plugin.text_selection.test.js +39 -47
  223. package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
  224. package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +57 -47
  225. package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +35 -6
  226. package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +9 -9
  227. package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +4 -4
  228. package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +1 -1
  229. package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +3 -3
  230. package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +47 -1
  231. package/tests/{plugins → jest/plugins}/tts/utils.test.js +1 -60
  232. package/tests/jest/plugins/url/UrlPlugin.test.js +190 -0
  233. package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +53 -14
  234. package/tests/jest/setup.js +3 -0
  235. package/tests/{util → jest/util}/browserSniffing.test.js +1 -1
  236. package/tests/jest/util/docCookies.test.js +24 -0
  237. package/tests/{util → jest/util}/strings.test.js +1 -1
  238. package/tests/{utils.js → jest/utils.js} +38 -0
  239. package/webpack.config.js +11 -5
  240. package/.babelrc +0 -12
  241. package/.dependabot/config.yml +0 -6
  242. package/.testcaferc.json +0 -5
  243. package/BookReader/bookreader-component-bundle.js +0 -1450
  244. package/BookReader/bookreader-component-bundle.js.LICENSE.txt +0 -38
  245. package/BookReader/bookreader-component-bundle.js.map +0 -1
  246. package/BookReader/jquery-1.10.1.js +0 -2
  247. package/BookReader/jquery-1.10.1.js.LICENSE.txt +0 -24
  248. package/BookReader/plugins/plugin.menu_toggle.js +0 -2
  249. package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
  250. package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
  251. package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
  252. package/karma.conf.js +0 -23
  253. package/src/BookNavigator/BookModel.js +0 -14
  254. package/src/BookNavigator/BookNavigator.js +0 -438
  255. package/src/BookNavigator/assets/book-loader.js +0 -27
  256. package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
  257. package/src/BookNavigator/search/a-search-result.js +0 -55
  258. package/src/BookReaderComponent/BookReaderComponent.js +0 -112
  259. package/src/ItemNavigator/ItemNavigator.js +0 -372
  260. package/src/ItemNavigator/providers/sharing.js +0 -29
  261. package/src/dragscrollable-br.js +0 -261
  262. package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
  263. package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
  264. package/tests/BookReader/Mode1Up.test.js +0 -164
  265. package/tests/BookReader/Mode2Up.test.js +0 -247
  266. package/tests/BookReader/utils.test.js +0 -109
  267. package/tests/e2e/ia-production/ia-prod-base.js +0 -17
  268. package/tests/karma/BookNavigator/book-navigator.test.js +0 -132
  269. package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
  270. package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
  271. package/tests/util/docCookies.test.js +0 -15
@@ -0,0 +1,188 @@
1
+ import { css, html, LitElement, nothing } from 'lit';
2
+ import { repeat } from 'lit/directives/repeat.js';
3
+
4
+ export class Volumes extends LitElement {
5
+ static get properties() {
6
+ return {
7
+ subPrefix: { type: String },
8
+ hostUrl: { type: String },
9
+ viewableFiles: { type: Array },
10
+ sortOrderBy: { type: String },
11
+ };
12
+ }
13
+
14
+ constructor() {
15
+ super();
16
+ this.hostUrl = '';
17
+ this.sortOrderBy = '';
18
+ this.subPrefix = '';
19
+ this.viewableFiles = [];
20
+ }
21
+
22
+ firstUpdated() {
23
+ const activeFile = this.shadowRoot.querySelector('.content.active');
24
+ // allow for css animations to run before scrolling to active file
25
+ setTimeout(() => {
26
+ // scroll active file into view if needed
27
+ // note: `scrollIntoViewIfNeeded` handles auto-scroll gracefully for Chrome, Safari
28
+ // Firefox does not have this capability yet as it does not support `scrollIntoViewIfNeeded`
29
+ if (activeFile?.scrollIntoViewIfNeeded) {
30
+ activeFile?.scrollIntoViewIfNeeded(true);
31
+ return;
32
+ }
33
+
34
+ // Todo: support `scrollIntoView` or `parentContainer.crollTop = x` for FF & "IE 11"
35
+ // currently, the hard `position: absolutes` misaligns subpanel when `scrollIntoView` is applied :(
36
+ }, 350);
37
+ }
38
+
39
+ volumeItemWithImageTitle(item) {
40
+ const hrefUrl = this.sortOrderBy === 'default'
41
+ ? `${this.hostUrl}${item.url_path}`
42
+ : `${this.hostUrl}${item.url_path}?sort=${this.sortOrderBy}`;
43
+
44
+ return html`
45
+ <li class="content active">
46
+ <div class="separator"></div>
47
+ <a class="container" href="${hrefUrl}">
48
+ <div class="image">
49
+ <img src="${item.image}">
50
+ </div>
51
+ <div class="text">
52
+ <p class="item-title">${item.title}</p>
53
+ <small>by: ${item.author}</small>
54
+ </div>
55
+ </a>
56
+ </li>
57
+ `;
58
+ }
59
+
60
+ volumeItem(item) {
61
+ const activeClass = this.subPrefix === item.file_subprefix ? ' active' : '';
62
+
63
+ const hrefUrl = this.sortOrderBy === 'default'
64
+ ? `${this.hostUrl}${item.url_path}`
65
+ : `${this.hostUrl}${item.url_path}?sort=${this.sortOrderBy}`;
66
+
67
+ return html`
68
+ <li>
69
+ <div class="separator"></div>
70
+ <div class="content${activeClass}">
71
+ <a href="https://${hrefUrl}">
72
+ <p class="item-title">${item.title}</p>
73
+ </a>
74
+ </div>
75
+ </li>
76
+ `;
77
+ }
78
+
79
+ get volumesList() {
80
+ const volumes = repeat(this.viewableFiles, volume => volume?.file_prefix, this.volumeItem.bind(this));
81
+ return html`
82
+ <ul>
83
+ ${volumes}
84
+ <div class="separator"></div>
85
+ </ul>
86
+ `;
87
+ }
88
+
89
+ render() {
90
+ return html`
91
+ ${this.viewableFiles.length ? this.volumesList : nothing}
92
+ `;
93
+ }
94
+
95
+ static get styles() {
96
+ return css`
97
+ :host {
98
+ display: block;
99
+ overflow-y: auto;
100
+ box-sizing: border-box;
101
+ color: var(--primaryTextColor);
102
+ margin-top: 14px;
103
+ margin-bottom: 2rem;
104
+ --activeBorderWidth: 2px;
105
+ }
106
+
107
+ a {
108
+ color: #ffffff;
109
+ text-decoration: none
110
+ }
111
+
112
+ img {
113
+ width: 35px;
114
+ height: 45px;
115
+ }
116
+
117
+ ul {
118
+ padding: 0;
119
+ list-style: none;
120
+ margin: var(--activeBorderWidth) 0.5rem 1rem 0;
121
+ }
122
+
123
+ ul > li:first-child .separator {
124
+ display: none;
125
+ }
126
+
127
+ li {
128
+ cursor: pointer;
129
+ outline: none;
130
+ position: relative;
131
+ }
132
+
133
+ li .content {
134
+ padding: 2px 0 4px 2px;
135
+ border: var(--activeBorderWidth) solid transparent;
136
+ padding: .2rem 0 .4rem .2rem;
137
+ }
138
+
139
+ li .content.active {
140
+ border: var(--activeBorderWidth) solid #538bc5;
141
+ }
142
+
143
+ small {
144
+ font-style: italic;
145
+ white-space: initial;
146
+ }
147
+
148
+ .container {
149
+ display: flex;
150
+ align-items: center;
151
+ justify-content: center
152
+ }
153
+
154
+ .item-title {
155
+ margin-block-start: 0em;
156
+ margin-block-end: 0em;
157
+ font-size: 14px;
158
+ font-weight: bold;
159
+ word-wrap: break-word;
160
+ padding-left: 5px;
161
+ }
162
+
163
+ .separator {
164
+ background-color: var(--secondaryBGColor);
165
+ width: 98%;
166
+ margin: 1px auto;
167
+ height: 1px;
168
+ }
169
+
170
+ .text {
171
+ padding-left: 10px;
172
+ }
173
+
174
+ .icon {
175
+ display: inline-block;
176
+ width: 14px;
177
+ height: 14px;
178
+ margin-left: .7rem;
179
+ border: 1px solid var(--primaryTextColor);
180
+ border-radius: 2px;
181
+ background: var(--activeButtonBg) 50% 50% no-repeat;
182
+ }
183
+
184
+ `;
185
+ }
186
+ }
187
+
188
+ customElements.define('viewable-files', Volumes);
@@ -23,42 +23,15 @@ export class BookModel {
23
23
  this.br = br;
24
24
  this.reduceSet = br.reduceSet;
25
25
  this.ppi = br.options?.ppi ?? DEFAULT_OPTIONS.ppi;
26
+ /** @type {'lr' | 'rl'} Page progression */
27
+ this.pageProgression = br.options?.pageProgression ?? DEFAULT_OPTIONS.pageProgression;
26
28
 
27
29
  /** @type {{width: number, height: number}} memoize storage */
28
30
  this._medianPageSize = null;
29
- /** @deprecated @type {{width: number, height: number}} memoize storage */
30
- this._medianPageSizePixels = null;
31
31
  /** @type {[PageData[], number]} */
32
32
  this._getDataFlattenedCached = null;
33
33
  }
34
34
 
35
- /**
36
- * @deprecated Use getMedianPageSizeInches
37
- * Memoized
38
- * @return {{width: number, height: number}}
39
- */
40
- getMedianPageSize() {
41
- if (this._medianPageSizePixels) {
42
- return this._medianPageSizePixels;
43
- }
44
-
45
- // A little expensive but we just do it once
46
- const widths = [];
47
- const heights = [];
48
- for (let i = 0; i < this.getNumLeafs(); i++) {
49
- widths.push(this.getPageWidth(i));
50
- heights.push(this.getPageHeight(i));
51
- }
52
-
53
- widths.sort();
54
- heights.sort();
55
- this._medianPageSizePixels = {
56
- width: widths[Math.floor(widths.length / 2)],
57
- height: heights[Math.floor(heights.length / 2)]
58
- };
59
- return this._medianPageSizePixels;
60
- }
61
-
62
35
  /** Get median width/height of page in inches. Memoized for performance. */
63
36
  getMedianPageSizeInches() {
64
37
  if (this._medianPageSize) {
@@ -226,7 +199,7 @@ export class BookModel {
226
199
  * @return {[PageIndex, PageIndex]} eg [0, 1]
227
200
  */
228
201
  getSpreadIndices(pindex) {
229
- if (this.br.pageProgression == 'rl') {
202
+ if (this.pageProgression == 'rl') {
230
203
  return this.getPageSide(pindex) == 'R' ? [pindex + 1, pindex] : [pindex, pindex - 1];
231
204
  } else {
232
205
  return this.getPageSide(pindex) == 'L' ? [pindex, pindex + 1] : [pindex - 1, pindex];
@@ -437,6 +410,42 @@ export class PageModel {
437
410
  return this.findNext();
438
411
  }
439
412
 
413
+ /** @type {PageModel | null} */
414
+ get left() {
415
+ return this.book.pageProgression === 'lr' ? this.prev : this.next;
416
+ }
417
+
418
+ /** @type {PageModel | null} */
419
+ get right() {
420
+ return this.book.pageProgression === 'lr' ? this.next : this.prev;
421
+ }
422
+
423
+ /**
424
+ * @type {{left: PageModel | null, right: PageModel | null}}
425
+ */
426
+ get spread() {
427
+ return {
428
+ left: this.pageSide === 'L' ? this : this.left,
429
+ right: this.pageSide === 'R' ? this : this.right,
430
+ };
431
+ }
432
+
433
+ /**
434
+ * @param {number} pages
435
+ */
436
+ goLeft(pages) {
437
+ const newIndex = this.book.pageProgression === 'lr' ? this.index - pages : this.index + pages;
438
+ return this.book.getPage(newIndex);
439
+ }
440
+
441
+ /**
442
+ * @param {number} pages
443
+ */
444
+ goRight(pages) {
445
+ const newIndex = this.book.pageProgression === 'lr' ? this.index + pages : this.index - pages;
446
+ return this.book.getPage(newIndex);
447
+ }
448
+
440
449
  /**
441
450
  * @param {number} reduce
442
451
  * @param {number} rotate
@@ -498,6 +507,26 @@ export class PageModel {
498
507
  return new PageModel(this.book, this.index - 1);
499
508
  }
500
509
  }
510
+
511
+ /**
512
+ * @param {object} [arg0]
513
+ * @param {boolean} [arg0.combineConsecutiveUnviewables] Whether to only yield the first page
514
+ * of a series of unviewable pages instead of each page
515
+ * @return {PageModel|void}
516
+ */
517
+ findLeft({ combineConsecutiveUnviewables = false } = {}) {
518
+ return this.book.pageProgression === 'lr' ? this.findPrev({ combineConsecutiveUnviewables }) : this.findNext({ combineConsecutiveUnviewables });
519
+ }
520
+
521
+ /**
522
+ * @param {object} [arg0]
523
+ * @param {boolean} [arg0.combineConsecutiveUnviewables] Whether to only yield the first page
524
+ * of a series of unviewable pages instead of each page
525
+ * @return {PageModel|void}
526
+ */
527
+ findRight({ combineConsecutiveUnviewables = false } = {}) {
528
+ return this.book.pageProgression === 'lr' ? this.findNext({ combineConsecutiveUnviewables }) : this.findPrev({ combineConsecutiveUnviewables });
529
+ }
501
530
  }
502
531
 
503
532
  // There are a few main ways we can reference a specific page in a book:
@@ -19,7 +19,7 @@ export class DebugConsole {
19
19
  </form>`);
20
20
  this.$log.append(this.$form);
21
21
 
22
- this.$form.submit(ev => {
22
+ this.$form.on("submit", ev => {
23
23
  ev.preventDefault();
24
24
  const result = eval(this.$form.find('input').val());
25
25
  this.logToScreen([result]);
@@ -29,7 +29,7 @@ export class DebugConsole {
29
29
  console.log = (...args) => {
30
30
  _realLog(...args);
31
31
  this.logToScreen(args);
32
- }
32
+ };
33
33
 
34
34
  window.onerror = (...args) => this.logToScreen(args);
35
35
  }
@@ -40,7 +40,7 @@ export class DebugConsole {
40
40
  */
41
41
  logToScreen(args) {
42
42
  const html = args.map(JSON.stringify).join(',');
43
- const $lastEntry = this.$log.children('.log-entry:last-child')
43
+ const $lastEntry = this.$log.children('.log-entry:last-child');
44
44
  if ($lastEntry.find('.entry-code').html() == html) {
45
45
  $lastEntry.find('.count').text(`(${++this.currentRun})`);
46
46
  } else {
@@ -0,0 +1,233 @@
1
+ // @ts-check
2
+ /*
3
+ * jQuery dragscrollable Plugin
4
+ * Based off version: 1.0 (25-Jun-2009)
5
+ * Copyright (c) 2009 Miquel Herrera
6
+ *
7
+ * Portions Copyright (c) 2010 Reg Braithwaite
8
+ * Copyright (c) 2010 Internet Archive / Michael Ang
9
+ * Copyright (c) 2016 Internet Archive / Richard Caceres
10
+ *
11
+ * Dual licensed under the MIT and GPL licenses:
12
+ * http://www.opensource.org/licenses/mit-license.php
13
+ * http://www.gnu.org/licenses/gpl.html
14
+ */
15
+
16
+ /**
17
+ * @param {string} string_of_events
18
+ * @param {string} ns
19
+ * @returns
20
+ */
21
+ function append_namespace(string_of_events, ns) {
22
+ return string_of_events
23
+ .split(' ')
24
+ .map(event_name => event_name + ns)
25
+ .join(' ');
26
+ }
27
+
28
+ function left_top(event) {
29
+ /** @type {number} */
30
+ let x;
31
+ /** @type {number} */
32
+ let y;
33
+ if (typeof(event.clientX) != 'undefined') {
34
+ x = event.clientX;
35
+ y = event.clientY;
36
+ }
37
+ else if (typeof(event.screenX) != 'undefined') {
38
+ x = event.screenX;
39
+ y = event.screenY;
40
+ }
41
+ else if (typeof(event.targetTouches) != 'undefined') {
42
+ x = event.targetTouches[0].pageX;
43
+ y = event.targetTouches[0].pageY;
44
+ }
45
+ else if (typeof(event.originalEvent) == 'undefined') {
46
+ console.error("don't understand x and y for " + event.type, event);
47
+ }
48
+ else if (typeof(event.originalEvent.clientX) != 'undefined') {
49
+ x = event.originalEvent.clientX;
50
+ y = event.originalEvent.clientY;
51
+ }
52
+ else if (typeof(event.originalEvent.screenX) != 'undefined') {
53
+ x = event.originalEvent.screenX;
54
+ y = event.originalEvent.screenY;
55
+ }
56
+ else if (typeof(event.originalEvent.targetTouches) != 'undefined') {
57
+ x = event.originalEvent.targetTouches[0].pageX;
58
+ y = event.originalEvent.targetTouches[0].pageY;
59
+ }
60
+
61
+ return { left: x, top: y };
62
+ }
63
+
64
+ const DEFAULT_OPTIONS = {
65
+ /**
66
+ * @type {String|HTMLElement} jQuery selector to apply to each wrapped element to
67
+ * find which will be the dragging elements. Defaults to the first child of scrollable
68
+ * element
69
+ */
70
+ dragSelector: '>:first',
71
+
72
+ /** Will the dragging element accept propagated events? default is yes, a propagated
73
+ * mouse event on a inner element will be accepted and processed. If set to false,
74
+ * only events originated on the draggable elements will be processed. */
75
+ acceptPropagatedEvent: true,
76
+
77
+ /**
78
+ * Prevents the event to propagate further effectively disabling other default actions
79
+ */
80
+ preventDefault: true,
81
+
82
+ dragstart: 'mousedown touchstart',
83
+ dragcontinue: 'mousemove touchmove',
84
+ dragend: 'mouseup touchend', // mouseleave
85
+ dragMinDistance: 5,
86
+ namespace: '.ds',
87
+
88
+ /** Scroll the window rather than the element */
89
+ scrollWindow: false,
90
+ };
91
+
92
+ /**
93
+ * Adds the ability to manage elements scroll by dragging
94
+ * one or more of its descendant elements. Options parameter
95
+ * allow to specifically select which inner elements will
96
+ * respond to the drag events.
97
+ * usage examples:
98
+ *
99
+ * To add the scroll by drag to the element id=viewport when dragging its
100
+ * first child accepting any propagated events
101
+ * `new DragScrollable($('#viewport')[0]);`
102
+ *
103
+ * To add the scroll by drag ability to any element div of class viewport
104
+ * when dragging its first descendant of class dragMe responding only to
105
+ * evcents originated on the '.dragMe' elements.
106
+ * ```js
107
+ * new DragScrollable($('div.viewport')[0], {
108
+ * dragSelector: '.dragMe:first',
109
+ * acceptPropagatedEvent: false
110
+ * });
111
+ * ```
112
+ *
113
+ * Notice that some 'viewports' could be nested within others but events
114
+ * would not interfere as acceptPropagatedEvent is set to false.
115
+ */
116
+ export class DragScrollable {
117
+ /**
118
+ * @param {HTMLElement} element
119
+ * @param {Partial<DEFAULT_OPTIONS>} options
120
+ */
121
+ constructor(element, options = {}) {
122
+ this.handling_element = $(element);
123
+ /** @type {typeof DEFAULT_OPTIONS} */
124
+ this.settings = $.extend({}, DEFAULT_OPTIONS, options || {});
125
+ this.firstCoord = { left: 0, top: 0 };
126
+ this.lastCoord = { left: 0, top: 0 };
127
+
128
+ this.settings.dragstart = append_namespace(this.settings.dragstart, this.settings.namespace);
129
+ this.settings.dragcontinue = append_namespace(this.settings.dragcontinue, this.settings.namespace);
130
+ //settings.dragend = append_namespace(settings.dragend, settings.namespace);
131
+
132
+ // Set mouse initiating event on the desired descendant
133
+ this.handling_element.find(this.settings.dragSelector)
134
+ .on(this.settings.dragstart, this._dragStartHandler);
135
+ }
136
+
137
+ _shouldAbort() {
138
+ const isTouchDevice = !!('ontouchstart' in window) || !!('msmaxtouchpoints' in window.navigator);
139
+ return isTouchDevice;
140
+ }
141
+
142
+ /** @param {MouseEvent} event */
143
+ _dragStartHandler = (event) => {
144
+ if (this._shouldAbort()) { return true; }
145
+
146
+ // mousedown, left click, check propagation
147
+ if (event.which > 1 ||
148
+ (!this.settings.acceptPropagatedEvent && event.target != this.handling_element[0])) {
149
+ return false;
150
+ }
151
+
152
+ // Initial coordinates will be the last when dragging
153
+ this.lastCoord = this.firstCoord = left_top(event);
154
+
155
+ this.handling_element
156
+ .on(this.settings.dragcontinue, this._dragContinueHandler)
157
+ //.on(this.settings.dragend, this._dragEndHandler)
158
+ ;
159
+
160
+ // Note, we bind using addEventListener so we can use "capture" binding
161
+ // instead of "bubble" binding
162
+ this.settings.dragend.split(' ').forEach(event_name => {
163
+ this.handling_element[0].addEventListener(event_name, this._dragEndHandler, true);
164
+ });
165
+
166
+ if (this.settings.preventDefault) {
167
+ event.preventDefault();
168
+ return false;
169
+ }
170
+ }
171
+
172
+ /** @param {MouseEvent} event */
173
+ _dragContinueHandler = (event) => { // User is dragging
174
+ // console.log('drag continue');
175
+ if (this._shouldAbort()) { return true; }
176
+
177
+ const lt = left_top(event);
178
+
179
+ // How much did the mouse move?
180
+ const delta = {
181
+ left: (lt.left - this.lastCoord.left),
182
+ top: (lt.top - this.lastCoord.top)
183
+ };
184
+
185
+ const scrollTarget = this.settings.scrollWindow ? $(window) : this.handling_element;
186
+
187
+ // Set the scroll position relative to what ever the scroll is now
188
+ scrollTarget.scrollLeft( scrollTarget.scrollLeft() - delta.left );
189
+ scrollTarget.scrollTop( scrollTarget.scrollTop() - delta.top );
190
+
191
+ // Save where the cursor is
192
+ this.lastCoord = lt;
193
+
194
+ if (this.settings.preventDefault) {
195
+ event.preventDefault();
196
+ return false;
197
+ }
198
+ }
199
+
200
+ /** @param {MouseEvent} event */
201
+ _dragEndHandler = (event) => { // Stop scrolling
202
+ //console.log('dragEndHandler');
203
+
204
+ if (this._shouldAbort()) { return true; }
205
+
206
+ this.handling_element
207
+ .off(this.settings.dragcontinue)
208
+ // Note, for some reason, even though I removeEventListener below,
209
+ // this call to unbind is still necessary. I don't know why.
210
+ .off(this.settings.dragend);
211
+
212
+ // Note, we bind using addEventListener so we can use "capture" binding
213
+ // instead of "bubble" binding
214
+ this.settings.dragend.split(' ').forEach(event_name => {
215
+ this.handling_element[0].removeEventListener(event_name, this._dragEndHandler, true);
216
+ });
217
+
218
+ // How much did the mouse move total?
219
+ const delta = {
220
+ left: Math.abs(this.lastCoord.left - this.firstCoord.left),
221
+ top: Math.abs(this.lastCoord.top - this.firstCoord.top)
222
+ };
223
+ const distance = Math.max(delta.left, delta.top);
224
+
225
+ // Allow event to propagate if min distance was not achieved
226
+ if (this.settings.preventDefault && distance > this.settings.dragMinDistance) {
227
+ event.preventDefault();
228
+ event.stopImmediatePropagation();
229
+ event.stopPropagation();
230
+ return false;
231
+ }
232
+ }
233
+ }