@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,233 +0,0 @@
|
|
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
|
-
}
|
@@ -1,116 +0,0 @@
|
|
1
|
-
// @ts-check
|
2
|
-
/**
|
3
|
-
* Creates an image cache dictionary
|
4
|
-
* storing images in `<img>` tags so that
|
5
|
-
* BookReader can leverage browser caching
|
6
|
-
*/
|
7
|
-
/** @typedef {import("./BookModel").BookModel} BookModel */
|
8
|
-
/** @typedef {import("./BookModel").PageIndex} PageIndex */
|
9
|
-
/** @typedef {import("./ReduceSet").ReduceSet} ReduceSet */
|
10
|
-
|
11
|
-
import { Pow2ReduceSet } from "./ReduceSet";
|
12
|
-
|
13
|
-
export class ImageCache {
|
14
|
-
/**
|
15
|
-
* @param {BookModel} book
|
16
|
-
* @param {object} opts
|
17
|
-
* @param {boolean} [opts.useSrcSet]
|
18
|
-
* @param {ReduceSet} [opts.reduceSet]
|
19
|
-
*/
|
20
|
-
constructor(book, { useSrcSet = false, reduceSet = Pow2ReduceSet } = {}) {
|
21
|
-
this.book = book;
|
22
|
-
this.useSrcSet = useSrcSet;
|
23
|
-
this.reduceSet = reduceSet;
|
24
|
-
/** @type {{ [index: number]: { reduce: number, loaded: boolean }[] }} */
|
25
|
-
this.cache = {};
|
26
|
-
this.defaultScale = 8;
|
27
|
-
}
|
28
|
-
|
29
|
-
/**
|
30
|
-
* Get an image
|
31
|
-
* Checks cache first if image is available & of equal/better scale,
|
32
|
-
* if not, a new image gets created
|
33
|
-
*
|
34
|
-
* @param {PageIndex} index
|
35
|
-
* @param {Number} reduce
|
36
|
-
*/
|
37
|
-
image(index, reduce) {
|
38
|
-
const cachedImages = this.cache[index] || [];
|
39
|
-
const sufficientImages = cachedImages
|
40
|
-
.filter(x => x.loaded && x.reduce <= reduce);
|
41
|
-
if (sufficientImages.length) {
|
42
|
-
// Choose the largest reduction factor that meets our needs
|
43
|
-
const bestReduce = Math.max(...sufficientImages.map(e => e.reduce));
|
44
|
-
return this._serveImageElement(index, bestReduce);
|
45
|
-
} else {
|
46
|
-
// Don't use a cache entry; i.e. a fresh fetch will be made
|
47
|
-
// for this reduce
|
48
|
-
return this._serveImageElement(index, reduce);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Checks if an image of equal or greater quality has been loaded
|
54
|
-
* @param {PageIndex} index
|
55
|
-
* @param {Number} reduce
|
56
|
-
* @returns {Boolean}
|
57
|
-
*/
|
58
|
-
imageLoaded(index, reduce) {
|
59
|
-
const cacheImg = this.cache[index]?.find(e => e.reduce <= reduce);
|
60
|
-
return cacheImg?.loaded ?? false;
|
61
|
-
}
|
62
|
-
|
63
|
-
/**
|
64
|
-
* Get the best image that's already loaded for the given index,
|
65
|
-
* trying to choose values less that the given reduce
|
66
|
-
* @param {PageIndex} index
|
67
|
-
* @param idealMaxReduce
|
68
|
-
* @returns {null | number}
|
69
|
-
*/
|
70
|
-
getBestLoadedReduce(index, idealMaxReduce = Infinity) {
|
71
|
-
const candidates = this.cache[index]?.filter(x => x.loaded) || [];
|
72
|
-
if (!candidates.length) return null;
|
73
|
-
|
74
|
-
const lowerResImages = candidates.filter(e => e.reduce >= idealMaxReduce);
|
75
|
-
if (lowerResImages.length) {
|
76
|
-
// Choose the highest quality loaded lower res image
|
77
|
-
return Math.min(...lowerResImages.map(e => e.reduce));
|
78
|
-
}
|
79
|
-
// Otherwise choose whatever is closest to the reduce
|
80
|
-
const higherRestImages = candidates.filter(e => e.reduce < idealMaxReduce);
|
81
|
-
return Math.max(...higherRestImages.map(e => e.reduce));
|
82
|
-
}
|
83
|
-
|
84
|
-
/**
|
85
|
-
* @private
|
86
|
-
* Generates an image element on the fly from image info in cache
|
87
|
-
*
|
88
|
-
* @param {PageIndex} index
|
89
|
-
* @param {number} reduce
|
90
|
-
* @returns {JQuery<HTMLImageElement>} with base image classes
|
91
|
-
*/
|
92
|
-
_serveImageElement(index, reduce) {
|
93
|
-
const validReduce = this.reduceSet.floor(reduce);
|
94
|
-
let cacheEntry = this.cache[index]?.find(e => e.reduce == validReduce);
|
95
|
-
if (!cacheEntry) {
|
96
|
-
cacheEntry = { reduce: validReduce, loaded: false };
|
97
|
-
const entries = this.cache[index] || (this.cache[index] = []);
|
98
|
-
entries.push(cacheEntry);
|
99
|
-
}
|
100
|
-
const page = this.book.getPage(index);
|
101
|
-
|
102
|
-
const $img = $('<img />', {
|
103
|
-
'class': 'BRpageimage',
|
104
|
-
'alt': 'Book page image',
|
105
|
-
src: page.getURI(validReduce, 0),
|
106
|
-
})
|
107
|
-
.data('reduce', validReduce);
|
108
|
-
if (this.useSrcSet) {
|
109
|
-
$img.attr('srcset', page.getURISrcSet(validReduce));
|
110
|
-
}
|
111
|
-
if (!cacheEntry.loaded) {
|
112
|
-
$img.one('load', () => cacheEntry.loaded = true);
|
113
|
-
}
|
114
|
-
return $img;
|
115
|
-
}
|
116
|
-
}
|
@@ -1,102 +0,0 @@
|
|
1
|
-
// @ts-check
|
2
|
-
import { Mode1UpLit } from './Mode1UpLit.js';
|
3
|
-
import { DragScrollable } from './DragScrollable.js';
|
4
|
-
/** @typedef {import('../BookReader.js').default} BookReader */
|
5
|
-
/** @typedef {import('./BookModel.js').BookModel} BookModel */
|
6
|
-
/** @typedef {import('./BookModel.js').PageIndex} PageIndex */
|
7
|
-
|
8
|
-
export class Mode1Up {
|
9
|
-
/**
|
10
|
-
* @param {BookReader} br
|
11
|
-
* @param {BookModel} bookModel
|
12
|
-
*/
|
13
|
-
constructor(br, bookModel) {
|
14
|
-
this.br = br;
|
15
|
-
this.book = bookModel;
|
16
|
-
this.mode1UpLit = new Mode1UpLit(bookModel, br);
|
17
|
-
|
18
|
-
/** @private */
|
19
|
-
this.$el = $(this.mode1UpLit)
|
20
|
-
// We CANNOT use `br-mode-1up` as a class, because it's the same
|
21
|
-
// as the name of the web component, and the webcomponents polyfill
|
22
|
-
// uses the name of component as a class for style scoping 😒
|
23
|
-
.addClass('br-mode-1up__root BRmode1up');
|
24
|
-
|
25
|
-
/** Has mode1up ever been rendered before? */
|
26
|
-
this.everShown = false;
|
27
|
-
}
|
28
|
-
|
29
|
-
// TODO: Might not need this anymore? Might want to delete.
|
30
|
-
/** @private */
|
31
|
-
get $brContainer() { return this.br.refs.$brContainer; }
|
32
|
-
|
33
|
-
/**
|
34
|
-
* This is called when we switch to one page view
|
35
|
-
*/
|
36
|
-
prepare() {
|
37
|
-
const startLeaf = this.br.currentIndex();
|
38
|
-
this.$brContainer
|
39
|
-
.empty()
|
40
|
-
.css({ overflow: 'hidden' })
|
41
|
-
.append(this.$el);
|
42
|
-
|
43
|
-
// Need this in a setTimeout so that it happens after the browser has _actually_
|
44
|
-
// appended the element to the DOM
|
45
|
-
setTimeout(async () => {
|
46
|
-
if (!this.everShown) {
|
47
|
-
this.mode1UpLit.initFirstRender(startLeaf);
|
48
|
-
this.everShown = true;
|
49
|
-
await this.mode1UpLit.requestUpdate();
|
50
|
-
new DragScrollable(this.mode1UpLit, {
|
51
|
-
preventDefault: true,
|
52
|
-
dragSelector: '.br-mode-1up__visible-world',
|
53
|
-
// Only handle mouse events; let browser/HammerJS handle touch
|
54
|
-
dragstart: 'mousedown',
|
55
|
-
dragcontinue: 'mousemove',
|
56
|
-
dragend: 'mouseup',
|
57
|
-
});
|
58
|
-
}
|
59
|
-
this.mode1UpLit.jumpToIndex(startLeaf);
|
60
|
-
});
|
61
|
-
this.br.updateBrClasses();
|
62
|
-
}
|
63
|
-
|
64
|
-
/**
|
65
|
-
* BREAKING CHANGE: No longer supports pageX/pageY
|
66
|
-
* @param {PageIndex} index
|
67
|
-
* @param {number} [pageX] x position on the page (in pixels) to center on
|
68
|
-
* @param {number} [pageY] y position on the page (in pixels) to center on
|
69
|
-
* @param {boolean} [noAnimate]
|
70
|
-
*/
|
71
|
-
jumpToIndex(index, pageX, pageY, noAnimate) {
|
72
|
-
// Only smooth for small distances
|
73
|
-
const distance = Math.abs(this.br.currentIndex() - index);
|
74
|
-
const smooth = !noAnimate && distance <= 4;
|
75
|
-
this.mode1UpLit.jumpToIndex(index, { smooth });
|
76
|
-
}
|
77
|
-
|
78
|
-
/**
|
79
|
-
* @param {'in' | 'out'} direction
|
80
|
-
*/
|
81
|
-
zoom(direction) {
|
82
|
-
switch (direction) {
|
83
|
-
case 'in':
|
84
|
-
this.mode1UpLit.zoomIn();
|
85
|
-
break;
|
86
|
-
case 'out':
|
87
|
-
this.mode1UpLit.zoomOut();
|
88
|
-
break;
|
89
|
-
default:
|
90
|
-
console.error(`Unsupported direction: ${direction}`);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
/**
|
95
|
-
* Resize the current one page view
|
96
|
-
* Note this calls drawLeafs
|
97
|
-
*/
|
98
|
-
resizePageView() {
|
99
|
-
this.mode1UpLit.htmlDimensionsCacher.updateClientSizes();
|
100
|
-
this.mode1UpLit.requestUpdate();
|
101
|
-
}
|
102
|
-
}
|