@internetarchive/bookreader 5.0.0-38 → 5.0.0-39
Sign up to get free protection for your applications and to get access to all the features.
- package/BookReader/BookReader.css +8 -0
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +99 -75
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/icons/magnify-minus.svg +1 -1
- package/BookReader/icons/magnify-plus.svg +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +1 -1
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1 -1
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +1 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/CHANGELOG.md +5 -0
- package/README.md +13 -0
- package/package.json +14 -14
- package/renovate.json +1 -1
- package/src/BookReader/Mode1UpLit.js +7 -1
- package/src/BookReader/Mode2Up.js +11 -0
- package/src/BookReader/ModeSmoothZoom.js +2 -0
- package/src/BookReader/PageContainer.js +10 -4
- package/src/BookReader/utils/ScrollClassAdder.js +31 -0
- package/src/assets/icons/magnify-minus.svg +3 -7
- package/src/assets/icons/magnify-plus.svg +3 -7
- package/src/css/_TextSelection.scss +13 -0
- package/tests/jest/BookReader/PageContainer.test.js +5 -4
- package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
- package/.husky/_/husky.sh +0 -30
- package/stat/BookNavigator/BookModel.js +0 -14
- package/stat/BookNavigator/BookNavigator.js +0 -524
- package/stat/BookNavigator/assets/bookmark-colors.js +0 -15
- package/stat/BookNavigator/assets/button-base.js +0 -61
- package/stat/BookNavigator/assets/ia-logo.js +0 -17
- package/stat/BookNavigator/assets/icon_checkmark.js +0 -6
- package/stat/BookNavigator/assets/icon_close.js +0 -3
- package/stat/BookNavigator/assets/icon_sort_asc.js +0 -5
- package/stat/BookNavigator/assets/icon_sort_desc.js +0 -5
- package/stat/BookNavigator/assets/icon_sort_neutral.js +0 -5
- package/stat/BookNavigator/assets/icon_volumes.js +0 -11
- package/stat/BookNavigator/bookmarks/bookmark-button.js +0 -64
- package/stat/BookNavigator/bookmarks/bookmark-edit.js +0 -215
- package/stat/BookNavigator/bookmarks/bookmarks-list.js +0 -285
- package/stat/BookNavigator/bookmarks/bookmarks-loginCTA.js +0 -28
- package/stat/BookNavigator/bookmarks/bookmarks-provider.js +0 -56
- package/stat/BookNavigator/bookmarks/ia-bookmarks.js +0 -523
- package/stat/BookNavigator/br-fullscreen-mgr.js +0 -82
- package/stat/BookNavigator/delete-modal-actions.js +0 -49
- package/stat/BookNavigator/downloads/downloads-provider.js +0 -72
- package/stat/BookNavigator/downloads/downloads.js +0 -139
- package/stat/BookNavigator/provider-config.js +0 -0
- package/stat/BookNavigator/search/a-search-result.js +0 -55
- package/stat/BookNavigator/search/search-provider.js +0 -180
- package/stat/BookNavigator/search/search-results.js +0 -360
- package/stat/BookNavigator/sharing.js +0 -31
- package/stat/BookNavigator/visual-adjustments/visual-adjustments-provider.js +0 -94
- package/stat/BookNavigator/visual-adjustments/visual-adjustments.js +0 -280
- package/stat/BookNavigator/volumes/volumes-provider.js +0 -83
- package/stat/BookNavigator/volumes/volumes.js +0 -178
- package/stat/BookReader/BookModel.js +0 -518
- package/stat/BookReader/DebugConsole.js +0 -54
- package/stat/BookReader/DragScrollable.js +0 -233
- package/stat/BookReader/ImageCache.js +0 -116
- package/stat/BookReader/Mode1Up.js +0 -102
- package/stat/BookReader/Mode1UpLit.js +0 -434
- package/stat/BookReader/Mode2Up.js +0 -1372
- package/stat/BookReader/ModeSmoothZoom.js +0 -177
- package/stat/BookReader/ModeThumb.js +0 -344
- package/stat/BookReader/Navbar/Navbar.js +0 -310
- package/stat/BookReader/PageContainer.js +0 -120
- package/stat/BookReader/ReduceSet.js +0 -26
- package/stat/BookReader/Toolbar/Toolbar.js +0 -384
- package/stat/BookReader/events.js +0 -20
- package/stat/BookReader/options.js +0 -324
- package/stat/BookReader/utils/HTMLDimensionsCacher.js +0 -44
- package/stat/BookReader/utils/classes.js +0 -36
- package/stat/BookReader/utils.js +0 -240
- package/stat/BookReader.js +0 -2550
- package/stat/BookReaderComponent/BookReaderComponent.js +0 -117
- package/stat/assets/icons/1up.svg +0 -12
- package/stat/assets/icons/2up.svg +0 -15
- package/stat/assets/icons/advance.svg +0 -26
- package/stat/assets/icons/chevron-right.svg +0 -1
- package/stat/assets/icons/close-circle-dark.svg +0 -1
- package/stat/assets/icons/close-circle.svg +0 -1
- package/stat/assets/icons/fullscreen.svg +0 -17
- package/stat/assets/icons/fullscreen_exit.svg +0 -17
- package/stat/assets/icons/hamburger.svg +0 -15
- package/stat/assets/icons/left-arrow.svg +0 -12
- package/stat/assets/icons/magnify-minus.svg +0 -16
- package/stat/assets/icons/magnify-plus.svg +0 -17
- package/stat/assets/icons/magnify.svg +0 -15
- package/stat/assets/icons/pause.svg +0 -23
- package/stat/assets/icons/play.svg +0 -22
- package/stat/assets/icons/playback-speed.svg +0 -34
- package/stat/assets/icons/read-aloud.svg +0 -22
- package/stat/assets/icons/review.svg +0 -22
- package/stat/assets/icons/thumbnails.svg +0 -17
- package/stat/assets/icons/voice.svg +0 -1
- package/stat/assets/icons/volume-full.svg +0 -22
- package/stat/assets/images/BRicons.png +0 -0
- package/stat/assets/images/BRicons.svg +0 -94
- package/stat/assets/images/BRicons_ia.png +0 -0
- package/stat/assets/images/back_pages.png +0 -0
- package/stat/assets/images/book_bottom_icon.png +0 -0
- package/stat/assets/images/book_down_icon.png +0 -0
- package/stat/assets/images/book_left_icon.png +0 -0
- package/stat/assets/images/book_leftmost_icon.png +0 -0
- package/stat/assets/images/book_right_icon.png +0 -0
- package/stat/assets/images/book_rightmost_icon.png +0 -0
- package/stat/assets/images/book_top_icon.png +0 -0
- package/stat/assets/images/book_up_icon.png +0 -0
- package/stat/assets/images/books_graphic.svg +0 -177
- package/stat/assets/images/booksplit.png +0 -0
- package/stat/assets/images/control_pause_icon.png +0 -0
- package/stat/assets/images/control_play_icon.png +0 -0
- package/stat/assets/images/embed_icon.png +0 -0
- package/stat/assets/images/icon-home-ia.png +0 -0
- package/stat/assets/images/icon_OL-logo-xs.png +0 -0
- package/stat/assets/images/icon_alert-xs.png +0 -0
- package/stat/assets/images/icon_book.svg +0 -12
- package/stat/assets/images/icon_bookmark.svg +0 -12
- package/stat/assets/images/icon_close-pop.png +0 -0
- package/stat/assets/images/icon_download.png +0 -0
- package/stat/assets/images/icon_gear.svg +0 -14
- package/stat/assets/images/icon_hamburger.svg +0 -20
- package/stat/assets/images/icon_home.png +0 -0
- package/stat/assets/images/icon_home.svg +0 -21
- package/stat/assets/images/icon_home_ia.png +0 -0
- package/stat/assets/images/icon_indicator.png +0 -0
- package/stat/assets/images/icon_info.svg +0 -11
- package/stat/assets/images/icon_one_page.svg +0 -8
- package/stat/assets/images/icon_pause.svg +0 -1
- package/stat/assets/images/icon_play.svg +0 -1
- package/stat/assets/images/icon_playback-rate.svg +0 -15
- package/stat/assets/images/icon_return.png +0 -0
- package/stat/assets/images/icon_search_button.svg +0 -8
- package/stat/assets/images/icon_share.svg +0 -9
- package/stat/assets/images/icon_skip-ahead.svg +0 -6
- package/stat/assets/images/icon_skip-back.svg +0 -13
- package/stat/assets/images/icon_speaker.svg +0 -18
- package/stat/assets/images/icon_speaker_open.svg +0 -10
- package/stat/assets/images/icon_thumbnails.svg +0 -12
- package/stat/assets/images/icon_toc.svg +0 -5
- package/stat/assets/images/icon_two_pages.svg +0 -9
- package/stat/assets/images/icon_zoomer.png +0 -0
- package/stat/assets/images/loading.gif +0 -0
- package/stat/assets/images/logo_icon.png +0 -0
- package/stat/assets/images/marker_chap-off.png +0 -0
- package/stat/assets/images/marker_chap-off.svg +0 -11
- package/stat/assets/images/marker_chap-off_ia.png +0 -0
- package/stat/assets/images/marker_chap-on.png +0 -0
- package/stat/assets/images/marker_chap-on.svg +0 -11
- package/stat/assets/images/marker_srch-on.svg +0 -11
- package/stat/assets/images/marker_srchchap-off.png +0 -0
- package/stat/assets/images/marker_srchchap-on.png +0 -0
- package/stat/assets/images/nav_control-dn.png +0 -0
- package/stat/assets/images/nav_control-dn_ia.png +0 -0
- package/stat/assets/images/nav_control-up.png +0 -0
- package/stat/assets/images/nav_control-up_ia.png +0 -0
- package/stat/assets/images/nav_control.png +0 -0
- package/stat/assets/images/one_page_mode_icon.png +0 -0
- package/stat/assets/images/paper-badge.png +0 -0
- package/stat/assets/images/print_icon.png +0 -0
- package/stat/assets/images/progressbar.gif +0 -0
- package/stat/assets/images/right_edges.png +0 -0
- package/stat/assets/images/slider.png +0 -0
- package/stat/assets/images/slider_ia.png +0 -0
- package/stat/assets/images/thumbnail_mode_icon.png +0 -0
- package/stat/assets/images/transparent.png +0 -0
- package/stat/assets/images/two_page_mode_icon.png +0 -0
- package/stat/assets/images/zoom_in_icon.png +0 -0
- package/stat/assets/images/zoom_out_icon.png +0 -0
- package/stat/css/BookReader.scss +0 -89
- package/stat/css/_BRBookmarks.scss +0 -29
- package/stat/css/_BRComponent.scss +0 -13
- package/stat/css/_BRfloat.scss +0 -197
- package/stat/css/_BRicon.scss +0 -48
- package/stat/css/_BRmain.scss +0 -251
- package/stat/css/_BRnav.scss +0 -359
- package/stat/css/_BRpages.scss +0 -139
- package/stat/css/_BRsearch.scss +0 -226
- package/stat/css/_BRtoolbar.scss +0 -84
- package/stat/css/_BRvendor.scss +0 -5
- package/stat/css/_MobileNav.scss +0 -194
- package/stat/css/_TextSelection.scss +0 -32
- package/stat/css/_colorbox.scss +0 -52
- package/stat/css/_controls.scss +0 -253
- package/stat/css/_icons.scss +0 -121
- package/stat/jquery-wrapper.js +0 -4
- package/stat/plugins/plugin.archive_analytics.js +0 -86
- package/stat/plugins/plugin.autoplay.js +0 -129
- package/stat/plugins/plugin.chapters.js +0 -248
- package/stat/plugins/plugin.iframe.js +0 -48
- package/stat/plugins/plugin.mobile_nav.js +0 -288
- package/stat/plugins/plugin.resume.js +0 -68
- package/stat/plugins/plugin.text_selection.js +0 -291
- package/stat/plugins/plugin.url.js +0 -198
- package/stat/plugins/plugin.vendor-fullscreen.js +0 -247
- package/stat/plugins/search/plugin.search.js +0 -439
- package/stat/plugins/search/view.js +0 -439
- package/stat/plugins/tts/AbstractTTSEngine.js +0 -249
- package/stat/plugins/tts/FestivalTTSEngine.js +0 -169
- package/stat/plugins/tts/PageChunk.js +0 -107
- package/stat/plugins/tts/PageChunkIterator.js +0 -163
- package/stat/plugins/tts/WebTTSEngine.js +0 -357
- package/stat/plugins/tts/plugin.tts.js +0 -357
- package/stat/plugins/tts/tooltip_dict.js +0 -15
- package/stat/plugins/tts/utils.js +0 -91
- package/stat/util/browserSniffing.js +0 -30
- package/stat/util/debouncer.js +0 -26
- package/stat/util/docCookies.js +0 -67
- package/stat/util/strings.js +0 -34
@@ -1,72 +0,0 @@
|
|
1
|
-
import { html } from 'lit-element';
|
2
|
-
import '@internetarchive/icon-dl/icon-dl';
|
3
|
-
import './downloads';
|
4
|
-
|
5
|
-
const menuBase = {
|
6
|
-
pdf: {
|
7
|
-
type: 'Encrypted Adobe PDF',
|
8
|
-
url: '#',
|
9
|
-
note: 'PDF files contain high quality images of pages.',
|
10
|
-
},
|
11
|
-
epub: {
|
12
|
-
type: 'Encrypted Adobe ePub',
|
13
|
-
url: '#',
|
14
|
-
note: 'ePub files are smaller in size, but may contain errors.',
|
15
|
-
}
|
16
|
-
};
|
17
|
-
|
18
|
-
const publicMenuBase = {
|
19
|
-
pdf: "PDF",
|
20
|
-
epub: "ePub"
|
21
|
-
};
|
22
|
-
|
23
|
-
export default class DownloadsProvider {
|
24
|
-
|
25
|
-
constructor(isBookProtected) {
|
26
|
-
this.icon = html`<ia-icon-dl style="width: var(--iconWidth); height: var(--iconHeight);"></ia-icon-dl>`;
|
27
|
-
this.label = 'Downloadable files';
|
28
|
-
this.menuDetails = '';
|
29
|
-
this.downloads = [];
|
30
|
-
this.id = 'downloads';
|
31
|
-
this.component = '';
|
32
|
-
this.isBookProtected = isBookProtected;
|
33
|
-
|
34
|
-
this.computeAvailableTypes = this.computeAvailableTypes.bind(this);
|
35
|
-
this.update = this.update.bind(this);
|
36
|
-
}
|
37
|
-
|
38
|
-
update(downloadTypes) {
|
39
|
-
this.computeAvailableTypes(downloadTypes);
|
40
|
-
this.component = this.menu;
|
41
|
-
this.component.isBookProtected = this.isBookProtected;
|
42
|
-
|
43
|
-
const ending = this.downloads.length === 1 ? '' : 's';
|
44
|
-
this.menuDetails = `(${this.downloads.length} format${ending})`;
|
45
|
-
}
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Generates Download Menu Info for available types
|
49
|
-
* sets global `downloads`
|
50
|
-
* @param availableTypes
|
51
|
-
*/
|
52
|
-
computeAvailableTypes(availableTypes = []) {
|
53
|
-
const menuData = availableTypes.reduce((found, incoming = []) => {
|
54
|
-
const [ type = '', link = '' ] = incoming;
|
55
|
-
const formattedType = type.toLowerCase();
|
56
|
-
const downloadOption = menuBase[formattedType] || null;
|
57
|
-
|
58
|
-
if (downloadOption) {
|
59
|
-
const menuButtonText = this.isBookProtected ? menuBase[formattedType].type : publicMenuBase[formattedType];
|
60
|
-
const menuInfo = Object.assign({}, downloadOption, { url: link, type: menuButtonText});
|
61
|
-
found.push(menuInfo);
|
62
|
-
}
|
63
|
-
return found;
|
64
|
-
}, []);
|
65
|
-
|
66
|
-
this.downloads = menuData;
|
67
|
-
}
|
68
|
-
|
69
|
-
get menu () {
|
70
|
-
return html`<ia-book-downloads .downloads=${this.downloads}></ia-book-downloads>`;
|
71
|
-
}
|
72
|
-
}
|
@@ -1,139 +0,0 @@
|
|
1
|
-
import { css, html, LitElement } from 'lit-element';
|
2
|
-
import { nothing } from 'lit-html';
|
3
|
-
import buttonStyles from '../assets/button-base.js';
|
4
|
-
export class IABookDownloads extends LitElement {
|
5
|
-
static get properties() {
|
6
|
-
return {
|
7
|
-
downloads: { type: Array },
|
8
|
-
expiration: { type: Number },
|
9
|
-
renderHeader: { type: Boolean },
|
10
|
-
isBookProtected: { type: Boolean },
|
11
|
-
};
|
12
|
-
}
|
13
|
-
|
14
|
-
constructor() {
|
15
|
-
super();
|
16
|
-
this.downloads = [];
|
17
|
-
this.expiration = 0;
|
18
|
-
this.renderHeader = false;
|
19
|
-
this.isBookProtected = false;
|
20
|
-
}
|
21
|
-
|
22
|
-
get formatsCount() {
|
23
|
-
const count = this.downloads.length;
|
24
|
-
return count ? html`<p>${count} format${count > 1 ? 's' : ''}</p>` : html``;
|
25
|
-
}
|
26
|
-
|
27
|
-
get loanExpiryMessage() {
|
28
|
-
return this.expiration
|
29
|
-
? html`<h2>These files will expire in ${this.expiration} days.</h2>`
|
30
|
-
: html``;
|
31
|
-
}
|
32
|
-
|
33
|
-
renderDownloadOptions() {
|
34
|
-
return this.downloads.map(option => (
|
35
|
-
html`
|
36
|
-
<li>
|
37
|
-
<a class="ia-button link primary" href="${option.url}">Get ${option.type}</a>
|
38
|
-
${option.note ? html`<p>${option.note}</p>` : html``}
|
39
|
-
</li>
|
40
|
-
`
|
41
|
-
));
|
42
|
-
}
|
43
|
-
|
44
|
-
get header() {
|
45
|
-
if (!this.renderHeader) {
|
46
|
-
return nothing;
|
47
|
-
}
|
48
|
-
return html`
|
49
|
-
<header>
|
50
|
-
<h3>Downloadable files</h3>
|
51
|
-
${this.formatsCount}
|
52
|
-
</header>
|
53
|
-
`;
|
54
|
-
}
|
55
|
-
|
56
|
-
get accessProtectedBook() {
|
57
|
-
return html`
|
58
|
-
<p>To access downloaded books, you need Adobe-compliant software on your device. The Internet Archive will administer this loan, but Adobe may also collect some information.</p>
|
59
|
-
<a class="ia-button external primary" href="https://www.adobe.com/solutions/ebook/digital-editions/download.html" rel="noopener noreferrer" target="_blank">Install Adobe Digital Editions</a>
|
60
|
-
`;
|
61
|
-
}
|
62
|
-
|
63
|
-
render() {
|
64
|
-
return html`
|
65
|
-
${this.header}
|
66
|
-
${this.loanExpiryMessage}
|
67
|
-
<ul>${this.renderDownloadOptions()}</ul>
|
68
|
-
${this.isBookProtected ? this.accessProtectedBook : nothing}
|
69
|
-
`;
|
70
|
-
}
|
71
|
-
|
72
|
-
static get styles() {
|
73
|
-
const mainCss = css`
|
74
|
-
:host {
|
75
|
-
display: block;
|
76
|
-
height: 100%;
|
77
|
-
padding: 1.5rem 0;
|
78
|
-
overflow-y: auto;
|
79
|
-
font-size: 1.4rem;
|
80
|
-
box-sizing: border-box;
|
81
|
-
}
|
82
|
-
|
83
|
-
a.close ia-icon {
|
84
|
-
--iconWidth: 18px;
|
85
|
-
--iconHeight: 18px;
|
86
|
-
}
|
87
|
-
a.close {
|
88
|
-
justify-self: end;
|
89
|
-
}
|
90
|
-
|
91
|
-
header {
|
92
|
-
display: flex;
|
93
|
-
align-items: center;
|
94
|
-
padding: 0 2rem;
|
95
|
-
}
|
96
|
-
header p {
|
97
|
-
padding: 0;
|
98
|
-
margin: 0;
|
99
|
-
font-size: 1.2rem;
|
100
|
-
font-weight: bold;
|
101
|
-
font-style: italic;
|
102
|
-
}
|
103
|
-
header div {
|
104
|
-
display: flex;
|
105
|
-
align-items: baseline;
|
106
|
-
}
|
107
|
-
|
108
|
-
h2 {
|
109
|
-
font-size: 1.6rem;
|
110
|
-
}
|
111
|
-
|
112
|
-
h3 {
|
113
|
-
padding: 0;
|
114
|
-
margin: 0 1rem 0 0;
|
115
|
-
font-size: 1.4rem;
|
116
|
-
}
|
117
|
-
|
118
|
-
ul {
|
119
|
-
padding: 0;
|
120
|
-
margin: 0;
|
121
|
-
list-style: none;
|
122
|
-
}
|
123
|
-
|
124
|
-
p {
|
125
|
-
margin: .3rem 0 0 0;
|
126
|
-
}
|
127
|
-
|
128
|
-
li,
|
129
|
-
ul + p {
|
130
|
-
padding-bottom: 1.2rem;
|
131
|
-
font-size: 1.2rem;
|
132
|
-
line-height: 140%;
|
133
|
-
}
|
134
|
-
`;
|
135
|
-
|
136
|
-
return [buttonStyles, mainCss];
|
137
|
-
}
|
138
|
-
}
|
139
|
-
customElements.define('ia-book-downloads', IABookDownloads);
|
File without changes
|
@@ -1,55 +0,0 @@
|
|
1
|
-
import { nothing } from 'lit-html';
|
2
|
-
import { html, LitElement } from 'lit-element';
|
3
|
-
import { unsafeHTML } from 'lit-html/directives/unsafe-html';
|
4
|
-
|
5
|
-
export class BookSearchResult extends LitElement {
|
6
|
-
static get properties() {
|
7
|
-
return {
|
8
|
-
match: { type: Object },
|
9
|
-
};
|
10
|
-
}
|
11
|
-
|
12
|
-
constructor() {
|
13
|
-
super();
|
14
|
-
|
15
|
-
this.matchRegex = new RegExp('{{{(.+?)}}}', 'g');
|
16
|
-
}
|
17
|
-
|
18
|
-
createRenderRoot() {
|
19
|
-
return this;
|
20
|
-
}
|
21
|
-
|
22
|
-
highlightedHit(hit) {
|
23
|
-
return html`
|
24
|
-
<p>${unsafeHTML(hit.replace(this.matchRegex, '<mark>$1</mark>'))}</p>
|
25
|
-
`;
|
26
|
-
}
|
27
|
-
|
28
|
-
resultSelected() {
|
29
|
-
this.dispatchEvent(new CustomEvent('resultSelected', {
|
30
|
-
bubbles: true,
|
31
|
-
composed: true,
|
32
|
-
detail: {
|
33
|
-
match: this.match,
|
34
|
-
},
|
35
|
-
}));
|
36
|
-
}
|
37
|
-
|
38
|
-
render() {
|
39
|
-
const { match } = this;
|
40
|
-
const { par = [] } = match;
|
41
|
-
const [resultDetails = {}] = par;
|
42
|
-
const pageNumber = Number.isInteger(resultDetails.page)
|
43
|
-
? html`<p class="page-num">Page -${resultDetails.page}-</p>` : nothing;
|
44
|
-
const coverImage = html`<img src="${match.cover}" />`;
|
45
|
-
return html`
|
46
|
-
<li @click=${this.resultSelected}>
|
47
|
-
${match.cover ? coverImage : nothing}
|
48
|
-
<h4>${match.title || nothing}</h4>
|
49
|
-
${pageNumber}
|
50
|
-
${this.highlightedHit(match.text)}
|
51
|
-
</li>
|
52
|
-
`;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
customElements.define('book-search-result', BookSearchResult);
|
@@ -1,180 +0,0 @@
|
|
1
|
-
import { html } from 'lit-element';
|
2
|
-
import { nothing } from 'lit-html';
|
3
|
-
import '@internetarchive/icon-search/icon-search';
|
4
|
-
import './search-results';
|
5
|
-
|
6
|
-
let searchState = {
|
7
|
-
query: '',
|
8
|
-
results: [],
|
9
|
-
resultsCount: 0,
|
10
|
-
queryInProgress: false,
|
11
|
-
errorMessage: '',
|
12
|
-
};
|
13
|
-
export default class {
|
14
|
-
constructor(onSearchChange = () => {}, brInstance) {
|
15
|
-
/* search menu events */
|
16
|
-
this.onBookSearchInitiated = this.onBookSearchInitiated.bind(this);
|
17
|
-
/* bookreader search events */
|
18
|
-
this.onSearchStarted = this.onSearchStarted.bind(this);
|
19
|
-
this.onSearchRequestError = this.onSearchRequestError.bind(this);
|
20
|
-
this.onSearchResultsClicked = this.onSearchResultsClicked.bind(this);
|
21
|
-
this.onSearchResultsChange = this.onSearchResultsChange.bind(this);
|
22
|
-
this.onSearchResultsCleared = this.onSearchResultsCleared.bind(this);
|
23
|
-
this.searchCanceledInMenu = this.searchCanceledInMenu.bind(this);
|
24
|
-
|
25
|
-
/* class methods */
|
26
|
-
this.bindEventListeners = this.bindEventListeners.bind(this);
|
27
|
-
this.getMenuDetails = this.getMenuDetails.bind(this);
|
28
|
-
this.getComponent = this.getComponent.bind(this);
|
29
|
-
this.advanceToPage = this.advanceToPage.bind(this);
|
30
|
-
this.updateMenu = this.updateMenu.bind(this);
|
31
|
-
|
32
|
-
this.onSearchChange = onSearchChange;
|
33
|
-
this.bookreader = brInstance;
|
34
|
-
this.icon = html`<ia-icon-search style="width: var(--iconWidth); height: var(--iconHeight);"></ia-icon-search>`;
|
35
|
-
this.label = 'Search inside';
|
36
|
-
this.menuDetails = this.getMenuDetails();
|
37
|
-
this.id = 'search';
|
38
|
-
this.component = this.getComponent();
|
39
|
-
this.bindEventListeners();
|
40
|
-
}
|
41
|
-
|
42
|
-
getMenuDetails() {
|
43
|
-
const { resultsCount, query, queryInProgress } = searchState;
|
44
|
-
if (queryInProgress || !query) { return nothing; }
|
45
|
-
const unit = resultsCount === 1 ? 'result' : 'results';
|
46
|
-
return html`(${resultsCount} ${unit})`;
|
47
|
-
}
|
48
|
-
|
49
|
-
bindEventListeners() {
|
50
|
-
window.addEventListener('BookReader:SearchStarted', this.onSearchStarted);
|
51
|
-
window.addEventListener('BookReader:SearchCallback', this.onSearchResultsChange);
|
52
|
-
window.addEventListener('BookReader:SearchCallbackEmpty', (event) => { this.onSearchRequestError(event, 'noResults'); });
|
53
|
-
window.addEventListener('BookReader:SearchCallbackNotIndexed', (event) => { this.onSearchRequestError(event, 'notIndexed'); });
|
54
|
-
window.addEventListener('BookReader:SearchCallbackError', (event) => { this.onSearchRequestError(event); });
|
55
|
-
window.addEventListener('BookReader:SearchResultsCleared', () => { this.onSearchResultsCleared(); });
|
56
|
-
window.addEventListener('BookReader:SearchCanceled', (e) => { this.onSearchCanceled(e); });
|
57
|
-
}
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Cancel search handler
|
61
|
-
* resets `searchState`
|
62
|
-
*/
|
63
|
-
onSearchCanceled() {
|
64
|
-
searchState = {
|
65
|
-
query: '',
|
66
|
-
results: [],
|
67
|
-
resultsCount: 0,
|
68
|
-
queryInProgress: false,
|
69
|
-
errorMessage: '',
|
70
|
-
};
|
71
|
-
const updateMenuFor = {
|
72
|
-
searchCanceled: true
|
73
|
-
};
|
74
|
-
this.updateMenu(updateMenuFor);
|
75
|
-
}
|
76
|
-
|
77
|
-
onSearchStarted(e) {
|
78
|
-
const { term = '' } = e.detail.props;
|
79
|
-
searchState.query = term;
|
80
|
-
searchState.results = [];
|
81
|
-
searchState.resultsCount = 0;
|
82
|
-
searchState.queryInProgress = true;
|
83
|
-
searchState.errorMessage = '';
|
84
|
-
this.updateMenu();
|
85
|
-
}
|
86
|
-
|
87
|
-
onBookSearchInitiated({ detail }) {
|
88
|
-
searchState.query = detail.query;
|
89
|
-
this.bookreader.search(searchState.query);
|
90
|
-
}
|
91
|
-
|
92
|
-
onSearchRequestError(event, errorType = 'default') {
|
93
|
-
const { detail: { props = {} } } = event;
|
94
|
-
const { instance = null } = props;
|
95
|
-
if (instance) {
|
96
|
-
/* keep bookreader instance reference up-to-date */
|
97
|
-
this.bookreader = instance;
|
98
|
-
}
|
99
|
-
const errorMessages = {
|
100
|
-
noResults: '0 results',
|
101
|
-
notIndexed: `This book hasn't been indexed for searching yet. We've just started indexing it,
|
102
|
-
so search should be available soon. Please try again later. Thanks!`,
|
103
|
-
default: 'Sorry, there was an error with your search. Please try again.',
|
104
|
-
};
|
105
|
-
|
106
|
-
const messageToShow = errorMessages[errorType] ?? errorMessages.default;
|
107
|
-
searchState.results = [];
|
108
|
-
searchState.resultsCount = 0;
|
109
|
-
searchState.queryInProgress = false;
|
110
|
-
searchState.errorMessage = html`<p class="error">${messageToShow}</p>`;
|
111
|
-
this.updateMenu();
|
112
|
-
}
|
113
|
-
|
114
|
-
onSearchResultsChange({ detail: { props = {} } }) {
|
115
|
-
const { instance = null, results: searchResults = [] } = props;
|
116
|
-
if (instance) {
|
117
|
-
/* keep bookreader instance reference up-to-date */
|
118
|
-
this.bookreader = instance;
|
119
|
-
}
|
120
|
-
const results = searchResults.matches || [];
|
121
|
-
const resultsCount = results.length;
|
122
|
-
const query = searchResults.q;
|
123
|
-
const queryInProgress = false;
|
124
|
-
searchState = { results, resultsCount, query, queryInProgress, errorMessage: '' };
|
125
|
-
this.updateMenu();
|
126
|
-
}
|
127
|
-
|
128
|
-
searchCanceledInMenu() {
|
129
|
-
this.bookreader?.cancelSearchRequest();
|
130
|
-
}
|
131
|
-
|
132
|
-
onSearchResultsCleared() {
|
133
|
-
searchState = {
|
134
|
-
query: '',
|
135
|
-
results: [],
|
136
|
-
resultsCount: 0,
|
137
|
-
queryInProgress: false,
|
138
|
-
errorMessage: '',
|
139
|
-
};
|
140
|
-
this.updateMenu();
|
141
|
-
this.bookreader?.searchView?.clearSearchFieldAndResults();
|
142
|
-
}
|
143
|
-
|
144
|
-
/**
|
145
|
-
* Relays how to update side menu given the context of a search update
|
146
|
-
@param {{searchCanceled: boolean}} searchUpdates
|
147
|
-
*/
|
148
|
-
updateMenu(searchUpdates = {}) {
|
149
|
-
this.menuDetails = this.getMenuDetails();
|
150
|
-
this.component = this.getComponent();
|
151
|
-
this.onSearchChange(this.bookreader, searchUpdates);
|
152
|
-
}
|
153
|
-
|
154
|
-
getComponent() {
|
155
|
-
const { query, results, queryInProgress, errorMessage } = searchState;
|
156
|
-
return html`
|
157
|
-
<ia-book-search-results
|
158
|
-
.query=${query}
|
159
|
-
.results=${results}
|
160
|
-
.errorMessage=${errorMessage}
|
161
|
-
?queryInProgress=${queryInProgress}
|
162
|
-
?renderSearchAllFiles=${false}
|
163
|
-
@resultSelected=${this.onSearchResultsClicked}
|
164
|
-
@bookSearchInitiated=${this.onBookSearchInitiated}
|
165
|
-
@bookSearchResultsCleared=${this.onSearchResultsCleared}
|
166
|
-
@bookSearchCanceled=${this.searchCanceledInMenu}
|
167
|
-
></ia-book-search-results>
|
168
|
-
`;
|
169
|
-
}
|
170
|
-
|
171
|
-
onSearchResultsClicked({ detail }) {
|
172
|
-
const page = detail.match.par[0].page;
|
173
|
-
this.advanceToPage(page);
|
174
|
-
}
|
175
|
-
|
176
|
-
advanceToPage(leaf) {
|
177
|
-
const page = this.bookreader.leafNumToIndex(leaf);
|
178
|
-
this.bookreader._searchPluginGoToResult(page);
|
179
|
-
}
|
180
|
-
}
|