@internetarchive/bookreader 5.0.0-88-alpha.8 → 5.0.0-88-alpha.10
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.
- package/dist/esm/BookNavigator/assets/bookmark-colors.js +4 -0
- package/dist/esm/BookNavigator/assets/button-base.js +4 -0
- package/dist/esm/BookNavigator/assets/ia-logo.js +4 -0
- package/dist/esm/BookNavigator/assets/icon_checkmark.js +8 -0
- package/dist/esm/BookNavigator/assets/icon_close.js +4 -0
- package/dist/esm/BookNavigator/book-navigator.js +612 -0
- package/dist/esm/BookNavigator/bookmarks/bookmark-button.js +35 -0
- package/dist/esm/BookNavigator/bookmarks/bookmark-edit.js +78 -0
- package/dist/esm/BookNavigator/bookmarks/bookmarks-list.js +160 -0
- package/dist/esm/BookNavigator/bookmarks/bookmarks-loginCTA.js +24 -0
- package/dist/esm/BookNavigator/bookmarks/bookmarks-provider.js +55 -0
- package/dist/esm/BookNavigator/bookmarks/ia-bookmarks.js +521 -0
- package/dist/esm/BookNavigator/delete-modal-actions.js +29 -0
- package/dist/esm/BookNavigator/downloads/downloads-provider.js +84 -0
- package/dist/esm/BookNavigator/downloads/downloads.js +69 -0
- package/dist/esm/BookNavigator/search/search-provider.js +238 -0
- package/dist/esm/BookNavigator/search/search-results.js +161 -0
- package/dist/esm/BookNavigator/sharing.js +26 -0
- package/dist/esm/BookNavigator/viewable-files.js +94 -0
- package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments-provider.js +83 -0
- package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments.js +131 -0
- package/dist/esm/BookReader/BookModel.js +575 -0
- package/dist/esm/BookReader/DragScrollable.js +224 -0
- package/dist/esm/BookReader/ImageCache.js +122 -0
- package/dist/esm/BookReader/Mode1Up.js +114 -0
- package/dist/esm/BookReader/Mode1UpLit.js +579 -0
- package/dist/esm/BookReader/Mode2Up.js +106 -0
- package/dist/esm/BookReader/Mode2UpLit.js +1020 -0
- package/dist/esm/BookReader/ModeCoordinateSpace.js +28 -0
- package/dist/esm/BookReader/ModeSmoothZoom.js +318 -0
- package/dist/esm/BookReader/ModeThumb.js +366 -0
- package/dist/esm/BookReader/Navbar/Navbar.js +253 -0
- package/dist/esm/BookReader/PageContainer.js +165 -0
- package/dist/esm/BookReader/ReduceSet.js +27 -0
- package/dist/esm/BookReader/Toolbar/Toolbar.js +242 -0
- package/dist/esm/BookReader/events.js +20 -0
- package/dist/esm/BookReader/options.js +331 -0
- package/dist/esm/BookReader/utils/HTMLDimensionsCacher.js +48 -0
- package/dist/esm/BookReader/utils/ScrollClassAdder.js +31 -0
- package/dist/esm/BookReader/utils/SelectionObserver.js +42 -0
- package/dist/esm/BookReader/utils/classes.js +37 -0
- package/dist/esm/BookReader/utils.js +315 -0
- package/dist/esm/BookReader.js +1827 -0
- package/dist/esm/assets/icons/1up.svg +12 -0
- package/dist/esm/assets/icons/2up.svg +15 -0
- package/dist/esm/assets/icons/advance.svg +26 -0
- package/dist/esm/assets/icons/chevron-right.svg +1 -0
- package/dist/esm/assets/icons/close-circle-dark.svg +1 -0
- package/dist/esm/assets/icons/close-circle.svg +1 -0
- package/dist/esm/assets/icons/fullscreen.svg +17 -0
- package/dist/esm/assets/icons/fullscreen_exit.svg +17 -0
- package/dist/esm/assets/icons/hamburger.svg +15 -0
- package/dist/esm/assets/icons/left-arrow.svg +12 -0
- package/dist/esm/assets/icons/magnify-minus.svg +12 -0
- package/dist/esm/assets/icons/magnify-plus.svg +13 -0
- package/dist/esm/assets/icons/magnify.svg +15 -0
- package/dist/esm/assets/icons/pause.svg +23 -0
- package/dist/esm/assets/icons/play.svg +22 -0
- package/dist/esm/assets/icons/playback-speed.svg +34 -0
- package/dist/esm/assets/icons/read-aloud.svg +22 -0
- package/dist/esm/assets/icons/review.svg +22 -0
- package/dist/esm/assets/icons/thumbnails.svg +17 -0
- package/dist/esm/assets/icons/voice.svg +1 -0
- package/dist/esm/assets/icons/volume-full.svg +22 -0
- package/dist/esm/assets/images/BRicons.png +0 -0
- package/dist/esm/assets/images/BRicons.svg +94 -0
- package/dist/esm/assets/images/BRicons_ia.png +0 -0
- package/dist/esm/assets/images/back_pages.png +0 -0
- package/dist/esm/assets/images/book_bottom_icon.png +0 -0
- package/dist/esm/assets/images/book_down_icon.png +0 -0
- package/dist/esm/assets/images/book_left_icon.png +0 -0
- package/dist/esm/assets/images/book_leftmost_icon.png +0 -0
- package/dist/esm/assets/images/book_right_icon.png +0 -0
- package/dist/esm/assets/images/book_rightmost_icon.png +0 -0
- package/dist/esm/assets/images/book_top_icon.png +0 -0
- package/dist/esm/assets/images/book_up_icon.png +0 -0
- package/dist/esm/assets/images/books_graphic.svg +177 -0
- package/dist/esm/assets/images/booksplit.png +0 -0
- package/dist/esm/assets/images/control_pause_icon.png +0 -0
- package/dist/esm/assets/images/control_play_icon.png +0 -0
- package/dist/esm/assets/images/embed_icon.png +0 -0
- package/dist/esm/assets/images/icon-home-ia.png +0 -0
- package/dist/esm/assets/images/icon_OL-logo-xs.png +0 -0
- package/dist/esm/assets/images/icon_alert-xs.png +0 -0
- package/dist/esm/assets/images/icon_book.svg +12 -0
- package/dist/esm/assets/images/icon_bookmark.svg +12 -0
- package/dist/esm/assets/images/icon_close-pop.png +0 -0
- package/dist/esm/assets/images/icon_download.png +0 -0
- package/dist/esm/assets/images/icon_gear.svg +14 -0
- package/dist/esm/assets/images/icon_hamburger.svg +20 -0
- package/dist/esm/assets/images/icon_home.png +0 -0
- package/dist/esm/assets/images/icon_home.svg +21 -0
- package/dist/esm/assets/images/icon_home_ia.png +0 -0
- package/dist/esm/assets/images/icon_indicator.png +0 -0
- package/dist/esm/assets/images/icon_info.svg +11 -0
- package/dist/esm/assets/images/icon_one_page.svg +8 -0
- package/dist/esm/assets/images/icon_pause.svg +1 -0
- package/dist/esm/assets/images/icon_play.svg +1 -0
- package/dist/esm/assets/images/icon_playback-rate.svg +15 -0
- package/dist/esm/assets/images/icon_return.png +0 -0
- package/dist/esm/assets/images/icon_search_button.svg +8 -0
- package/dist/esm/assets/images/icon_share.svg +9 -0
- package/dist/esm/assets/images/icon_skip-ahead.svg +6 -0
- package/dist/esm/assets/images/icon_skip-back.svg +13 -0
- package/dist/esm/assets/images/icon_speaker.svg +18 -0
- package/dist/esm/assets/images/icon_speaker_open.svg +10 -0
- package/dist/esm/assets/images/icon_thumbnails.svg +12 -0
- package/dist/esm/assets/images/icon_toc.svg +5 -0
- package/dist/esm/assets/images/icon_two_pages.svg +9 -0
- package/dist/esm/assets/images/icon_zoomer.png +0 -0
- package/dist/esm/assets/images/loading.gif +0 -0
- package/dist/esm/assets/images/logo_icon.png +0 -0
- package/dist/esm/assets/images/marker_chap-off.png +0 -0
- package/dist/esm/assets/images/marker_chap-off.svg +11 -0
- package/dist/esm/assets/images/marker_chap-off_ia.png +0 -0
- package/dist/esm/assets/images/marker_chap-on.png +0 -0
- package/dist/esm/assets/images/marker_chap-on.svg +11 -0
- package/dist/esm/assets/images/marker_srch-on.svg +11 -0
- package/dist/esm/assets/images/marker_srchchap-off.png +0 -0
- package/dist/esm/assets/images/marker_srchchap-on.png +0 -0
- package/dist/esm/assets/images/nav_control-dn.png +0 -0
- package/dist/esm/assets/images/nav_control-dn_ia.png +0 -0
- package/dist/esm/assets/images/nav_control-up.png +0 -0
- package/dist/esm/assets/images/nav_control-up_ia.png +0 -0
- package/dist/esm/assets/images/nav_control.png +0 -0
- package/dist/esm/assets/images/one_page_mode_icon.png +0 -0
- package/dist/esm/assets/images/paper-badge.png +0 -0
- package/dist/esm/assets/images/print_icon.png +0 -0
- package/dist/esm/assets/images/progressbar.gif +0 -0
- package/dist/esm/assets/images/right_edges.png +0 -0
- package/dist/esm/assets/images/slider.png +0 -0
- package/dist/esm/assets/images/slider_ia.png +0 -0
- package/dist/esm/assets/images/thumbnail_mode_icon.png +0 -0
- package/dist/esm/assets/images/transparent.png +0 -0
- package/dist/esm/assets/images/two_page_mode_icon.png +0 -0
- package/dist/esm/assets/images/unviewable_page.png +0 -0
- package/dist/esm/assets/images/zoom_in_icon.png +0 -0
- package/dist/esm/assets/images/zoom_out_icon.png +0 -0
- package/dist/esm/css/BookReader.scss +85 -0
- package/dist/esm/css/_BRBookmarks.scss +29 -0
- package/dist/esm/css/_BRComponent.scss +13 -0
- package/dist/esm/css/_BRfloat.scss +197 -0
- package/dist/esm/css/_BRicon.scss +54 -0
- package/dist/esm/css/_BRmain.scss +262 -0
- package/dist/esm/css/_BRnav.scss +354 -0
- package/dist/esm/css/_BRpages.scss +213 -0
- package/dist/esm/css/_BRsearch.scss +268 -0
- package/dist/esm/css/_BRtoolbar.scss +84 -0
- package/dist/esm/css/_BRvendor.scss +5 -0
- package/dist/esm/css/_TextSelection.scss +108 -0
- package/dist/esm/css/_colorbox.scss +52 -0
- package/dist/esm/css/_controls.scss +257 -0
- package/dist/esm/css/_icons.scss +121 -0
- package/dist/esm/ia-bookreader/ia-bookreader.js +141 -0
- package/dist/esm/jquery-wrapper.js +3 -0
- package/dist/esm/plugins/plugin.archive_analytics.js +72 -0
- package/dist/esm/plugins/plugin.autoplay.js +119 -0
- package/dist/esm/plugins/plugin.chapters.js +288 -0
- package/dist/esm/plugins/plugin.iframe.js +44 -0
- package/dist/esm/plugins/plugin.iiif.js +146 -0
- package/dist/esm/plugins/plugin.resume.js +66 -0
- package/dist/esm/plugins/plugin.text_selection.js +621 -0
- package/dist/esm/plugins/plugin.vendor-fullscreen.js +227 -0
- package/dist/esm/plugins/search/plugin.search.js +499 -0
- package/dist/esm/plugins/search/utils.js +42 -0
- package/dist/esm/plugins/search/view.js +360 -0
- package/dist/esm/plugins/tts/AbstractTTSEngine.js +282 -0
- package/dist/esm/plugins/tts/FestivalTTSEngine.js +192 -0
- package/dist/esm/plugins/tts/PageChunk.js +105 -0
- package/dist/esm/plugins/tts/PageChunkIterator.js +155 -0
- package/dist/esm/plugins/tts/WebTTSEngine.js +364 -0
- package/dist/esm/plugins/tts/plugin.tts.js +315 -0
- package/dist/esm/plugins/tts/tooltip_dict.js +14 -0
- package/dist/esm/plugins/tts/utils.js +79 -0
- package/dist/esm/plugins/url/UrlPlugin.js +197 -0
- package/dist/esm/plugins/url/plugin.url.js +212 -0
- package/dist/esm/util/browserSniffing.js +56 -0
- package/dist/esm/util/debouncer.js +25 -0
- package/dist/esm/util/docCookies.js +75 -0
- package/dist/esm/util/strings.js +34 -0
- package/jsconfig.json +1 -0
- package/package.json +1 -7
@@ -0,0 +1,28 @@
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
4
|
+
import { calcScreenDPI } from './utils';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* There are a few different "coordinate spaces" at play in BR:
|
8
|
+
* (1) World units: i.e. inches. Unless otherwise stated, all computations
|
9
|
+
* are done in world units.
|
10
|
+
* (2) Rendered Pixels: i.e. img.width = '300'. Note this does _not_ take
|
11
|
+
* into account zoom scaling.
|
12
|
+
* (3) Visible Pixels: Just rendered pixels, but taking into account scaling.
|
13
|
+
*/
|
14
|
+
export class ModeCoordinateSpace {
|
15
|
+
/**
|
16
|
+
* @param {{ scale: number }} mode
|
17
|
+
*/
|
18
|
+
constructor(mode) {
|
19
|
+
_defineProperty(this, "screenDPI", calcScreenDPI());
|
20
|
+
_defineProperty(this, "worldUnitsToRenderedPixels", (/** @type {number} */inches) => inches * this.screenDPI);
|
21
|
+
_defineProperty(this, "renderedPixelsToWorldUnits", (/** @type {number} */px) => px / this.screenDPI);
|
22
|
+
_defineProperty(this, "renderedPixelsToVisiblePixels", (/** @type {number} */px) => px * this.mode.scale);
|
23
|
+
_defineProperty(this, "visiblePixelsToRenderedPixels", (/** @type {number} */px) => px / this.mode.scale);
|
24
|
+
_defineProperty(this, "worldUnitsToVisiblePixels", (/** @type {number} */px) => this.renderedPixelsToVisiblePixels(this.worldUnitsToRenderedPixels(px)));
|
25
|
+
_defineProperty(this, "visiblePixelsToWorldUnits", (/** @type {number} */px) => this.renderedPixelsToWorldUnits(this.visiblePixelsToRenderedPixels(px)));
|
26
|
+
this.mode = mode;
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,318 @@
|
|
1
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
2
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
5
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
6
|
+
// @ts-check
|
7
|
+
import interact from 'interactjs';
|
8
|
+
import { isIOS, isSamsungInternet } from '../util/browserSniffing.js';
|
9
|
+
import { sleep } from './utils.js';
|
10
|
+
/** @typedef {import('./utils/HTMLDimensionsCacher.js').HTMLDimensionsCacher} HTMLDimensionsCacher */
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @typedef {object} SmoothZoomable
|
14
|
+
* @property {HTMLElement} $container
|
15
|
+
* @property {HTMLElement} $visibleWorld
|
16
|
+
* @property {import("./options.js").AutoFitValues} autoFit
|
17
|
+
* @property {number} scale
|
18
|
+
* @property {HTMLDimensionsCacher} htmlDimensionsCacher
|
19
|
+
* @property {function(): void} [attachScrollListeners]
|
20
|
+
* @property {function(): void} [detachScrollListeners]
|
21
|
+
*/
|
22
|
+
|
23
|
+
/** Manages pinch-zoom, ctrl-wheel, and trackpad pinch smooth zooming. */
|
24
|
+
export class ModeSmoothZoom {
|
25
|
+
/** @param {SmoothZoomable} mode */
|
26
|
+
constructor(mode) {
|
27
|
+
var _this = this;
|
28
|
+
/** Position (in unit-less, [0, 1] coordinates) in client to scale around */
|
29
|
+
_defineProperty(this, "scaleCenter", {
|
30
|
+
x: 0.5,
|
31
|
+
y: 0.5
|
32
|
+
});
|
33
|
+
/** @param {Event} ev */
|
34
|
+
_defineProperty(this, "_preventEvent", ev => {
|
35
|
+
ev.preventDefault();
|
36
|
+
return false;
|
37
|
+
});
|
38
|
+
_defineProperty(this, "_pinchStart", /*#__PURE__*/_asyncToGenerator(function* () {
|
39
|
+
var _this$mode$detachScro, _this$mode;
|
40
|
+
// Safari calls gesturestart twice!
|
41
|
+
if (_this.pinching) return;
|
42
|
+
if (isIOS()) {
|
43
|
+
// Safari sometimes causes a pinch to trigger when there's only one touch!
|
44
|
+
yield sleep(0); // touches monitor can receive the touch event late
|
45
|
+
if (_this.touchesMonitor.touches < 2) return;
|
46
|
+
}
|
47
|
+
_this.pinching = true;
|
48
|
+
|
49
|
+
// Do this in case the pinchend hasn't fired yet.
|
50
|
+
_this.oldScale = 1;
|
51
|
+
_this.mode.$visibleWorld.classList.add("BRsmooth-zooming");
|
52
|
+
_this.mode.$visibleWorld.style.willChange = "transform";
|
53
|
+
_this.mode.autoFit = "none";
|
54
|
+
_this.detachCtrlZoom();
|
55
|
+
(_this$mode$detachScro = (_this$mode = _this.mode).detachScrollListeners) === null || _this$mode$detachScro === void 0 || _this$mode$detachScro.call(_this$mode);
|
56
|
+
_this.interact.gesturable({
|
57
|
+
listeners: {
|
58
|
+
start: _this._pinchStart,
|
59
|
+
move: _this._pinchMove,
|
60
|
+
end: _this._pinchEnd
|
61
|
+
}
|
62
|
+
});
|
63
|
+
}));
|
64
|
+
/** @param {{ scale: number, clientX: number, clientY: number }}} e */
|
65
|
+
_defineProperty(this, "_pinchMove", /*#__PURE__*/function () {
|
66
|
+
var _ref2 = _asyncToGenerator(function* (e) {
|
67
|
+
if (!_this.pinching) return;
|
68
|
+
_this.lastEvent = {
|
69
|
+
scale: e.scale,
|
70
|
+
clientX: e.clientX,
|
71
|
+
clientY: e.clientY
|
72
|
+
};
|
73
|
+
if (!_this.pinchMoveFrame) {
|
74
|
+
// Buffer these events; only update the scale when request animation fires
|
75
|
+
_this.pinchMoveFrame = _this.bufferFn(_this._drawPinchZoomFrame);
|
76
|
+
}
|
77
|
+
});
|
78
|
+
return function (_x) {
|
79
|
+
return _ref2.apply(this, arguments);
|
80
|
+
};
|
81
|
+
}());
|
82
|
+
_defineProperty(this, "_pinchEnd", /*#__PURE__*/_asyncToGenerator(function* () {
|
83
|
+
var _this$mode$attachScro, _this$mode2;
|
84
|
+
if (!_this.pinching) return;
|
85
|
+
_this.pinching = false;
|
86
|
+
_this.interact.gesturable({
|
87
|
+
listeners: {
|
88
|
+
start: _this._pinchStart,
|
89
|
+
end: _this._pinchEnd
|
90
|
+
}
|
91
|
+
});
|
92
|
+
// Want this to happen after the pinchMoveFrame,
|
93
|
+
// if one is in progress; otherwise setting oldScale
|
94
|
+
// messes up the transform.
|
95
|
+
yield _this.pinchMoveFramePromise;
|
96
|
+
_this.scaleCenter = {
|
97
|
+
x: 0.5,
|
98
|
+
y: 0.5
|
99
|
+
};
|
100
|
+
_this.oldScale = 1;
|
101
|
+
_this.mode.$visibleWorld.classList.remove("BRsmooth-zooming");
|
102
|
+
_this.mode.$visibleWorld.style.willChange = "auto";
|
103
|
+
_this.attachCtrlZoom();
|
104
|
+
(_this$mode$attachScro = (_this$mode2 = _this.mode).attachScrollListeners) === null || _this$mode$attachScro === void 0 || _this$mode$attachScro.call(_this$mode2);
|
105
|
+
}));
|
106
|
+
_defineProperty(this, "_drawPinchZoomFrame", /*#__PURE__*/_asyncToGenerator(function* () {
|
107
|
+
// Because of the buffering/various timing locks,
|
108
|
+
// this can be called after the pinch has ended, which
|
109
|
+
// results in a janky zoom after the pinch.
|
110
|
+
if (!_this.pinching) {
|
111
|
+
_this.pinchMoveFrame = null;
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
_this.mode.$container.style.overflow = "hidden";
|
115
|
+
_this.pinchMoveFramePromiseRes = null;
|
116
|
+
_this.pinchMoveFramePromise = new Promise(res => _this.pinchMoveFramePromiseRes = res);
|
117
|
+
_this.updateScaleCenter({
|
118
|
+
clientX: _this.lastEvent.clientX,
|
119
|
+
clientY: _this.lastEvent.clientY
|
120
|
+
});
|
121
|
+
var curScale = _this.mode.scale;
|
122
|
+
var newScale = curScale * _this.lastEvent.scale / _this.oldScale;
|
123
|
+
if (curScale != newScale) {
|
124
|
+
_this.mode.scale = newScale;
|
125
|
+
yield _this.pinchMoveFramePromise;
|
126
|
+
}
|
127
|
+
_this.mode.$container.style.overflow = "auto";
|
128
|
+
_this.oldScale = _this.lastEvent.scale;
|
129
|
+
_this.pinchMoveFrame = null;
|
130
|
+
}));
|
131
|
+
_defineProperty(this, "_dragMove", /*#__PURE__*/function () {
|
132
|
+
var _ref5 = _asyncToGenerator(function* (e) {
|
133
|
+
if (_this.pinching) {
|
134
|
+
yield _this._pinchEnd();
|
135
|
+
}
|
136
|
+
_this.mode.$container.scrollTop -= e.dy;
|
137
|
+
_this.mode.$container.scrollLeft -= e.dx;
|
138
|
+
});
|
139
|
+
return function (_x2) {
|
140
|
+
return _ref5.apply(this, arguments);
|
141
|
+
};
|
142
|
+
}());
|
143
|
+
/** @param {WheelEvent} ev **/
|
144
|
+
_defineProperty(this, "_handleCtrlWheel", ev => {
|
145
|
+
if (!ev.ctrlKey) return;
|
146
|
+
ev.preventDefault();
|
147
|
+
var zoomMultiplier =
|
148
|
+
// Zooming on macs was painfully slow; likely due to their better
|
149
|
+
// trackpads. Give them a higher zoom rate.
|
150
|
+
/Mac/i.test(navigator.platform) ? 0.045 :
|
151
|
+
// This worked well for me on Windows
|
152
|
+
0.03;
|
153
|
+
|
154
|
+
// Zoom around the cursor
|
155
|
+
this.updateScaleCenter(ev);
|
156
|
+
this.mode.autoFit = "none";
|
157
|
+
this.mode.scale *= 1 - Math.sign(ev.deltaY) * zoomMultiplier;
|
158
|
+
});
|
159
|
+
/** @type {SmoothZoomable} */
|
160
|
+
this.mode = mode;
|
161
|
+
|
162
|
+
/** Whether a pinch is currently happening */
|
163
|
+
this.pinching = false;
|
164
|
+
/** Non-null when a scale has been enqueued/is being processed by the buffer function */
|
165
|
+
this.pinchMoveFrame = null;
|
166
|
+
/** Promise for the current/enqueued pinch move frame. Resolves when it is complete. */
|
167
|
+
this.pinchMoveFramePromise = Promise.resolve();
|
168
|
+
this.oldScale = 1;
|
169
|
+
/** @type {{ scale: number, clientX: number, clientY: number }}} */
|
170
|
+
this.lastEvent = null;
|
171
|
+
this.attached = false;
|
172
|
+
|
173
|
+
/** @type {function(function(): void): any} */
|
174
|
+
this.bufferFn = window.requestAnimationFrame.bind(window);
|
175
|
+
}
|
176
|
+
attach() {
|
177
|
+
if (this.attached) return;
|
178
|
+
this.attachCtrlZoom();
|
179
|
+
|
180
|
+
// GestureEvents work only on Safari; they're too glitchy to use
|
181
|
+
// fully, but they can sometimes help error correct when interact
|
182
|
+
// misses an end/start event on Safari due to Safari bugs.
|
183
|
+
this.mode.$container.addEventListener('gesturestart', this._pinchStart);
|
184
|
+
this.mode.$container.addEventListener('gesturechange', this._preventEvent);
|
185
|
+
this.mode.$container.addEventListener('gestureend', this._pinchEnd);
|
186
|
+
if (isIOS()) {
|
187
|
+
this.touchesMonitor = new TouchesMonitor(this.mode.$container);
|
188
|
+
this.touchesMonitor.attach();
|
189
|
+
}
|
190
|
+
this.mode.$container.style.touchAction = "pan-x pan-y";
|
191
|
+
|
192
|
+
// The pinch listeners
|
193
|
+
this.interact = interact(this.mode.$container);
|
194
|
+
this.interact.gesturable({
|
195
|
+
listeners: {
|
196
|
+
start: this._pinchStart,
|
197
|
+
end: this._pinchEnd
|
198
|
+
}
|
199
|
+
});
|
200
|
+
if (isSamsungInternet()) {
|
201
|
+
// Samsung internet pinch-zoom will not work unless we disable
|
202
|
+
// all touch actions. So use interact.js' built-in drag support
|
203
|
+
// to handle moving on that browser.
|
204
|
+
this.mode.$container.style.touchAction = "none";
|
205
|
+
this.interact.draggable({
|
206
|
+
inertia: {
|
207
|
+
resistance: 2,
|
208
|
+
minSpeed: 100,
|
209
|
+
allowResume: true
|
210
|
+
},
|
211
|
+
listeners: {
|
212
|
+
move: this._dragMove
|
213
|
+
}
|
214
|
+
});
|
215
|
+
}
|
216
|
+
this.attached = true;
|
217
|
+
}
|
218
|
+
detach() {
|
219
|
+
var _this$touchesMonitor, _this$touchesMonitor$;
|
220
|
+
this.detachCtrlZoom();
|
221
|
+
|
222
|
+
// GestureEvents work only on Safari; they interfere with Hammer,
|
223
|
+
// so block them.
|
224
|
+
this.mode.$container.removeEventListener('gesturestart', this._pinchStart);
|
225
|
+
this.mode.$container.removeEventListener('gesturechange', this._preventEvent);
|
226
|
+
this.mode.$container.removeEventListener('gestureend', this._pinchEnd);
|
227
|
+
(_this$touchesMonitor = this.touchesMonitor) === null || _this$touchesMonitor === void 0 || (_this$touchesMonitor$ = _this$touchesMonitor.detach) === null || _this$touchesMonitor$ === void 0 || _this$touchesMonitor$.call(_this$touchesMonitor);
|
228
|
+
|
229
|
+
// The pinch listeners
|
230
|
+
this.interact.unset();
|
231
|
+
interact.removeDocument(document);
|
232
|
+
this.attached = false;
|
233
|
+
}
|
234
|
+
/** @private */
|
235
|
+
attachCtrlZoom() {
|
236
|
+
window.addEventListener("wheel", this._handleCtrlWheel, {
|
237
|
+
passive: false
|
238
|
+
});
|
239
|
+
}
|
240
|
+
|
241
|
+
/** @private */
|
242
|
+
detachCtrlZoom() {
|
243
|
+
window.removeEventListener("wheel", this._handleCtrlWheel);
|
244
|
+
}
|
245
|
+
/**
|
246
|
+
* @param {object} param0
|
247
|
+
* @param {number} param0.clientX
|
248
|
+
* @param {number} param0.clientY
|
249
|
+
*/
|
250
|
+
updateScaleCenter(_ref6) {
|
251
|
+
var {
|
252
|
+
clientX,
|
253
|
+
clientY
|
254
|
+
} = _ref6;
|
255
|
+
var bc = this.mode.htmlDimensionsCacher.boundingClientRect;
|
256
|
+
this.scaleCenter = {
|
257
|
+
x: (clientX - bc.left) / this.mode.htmlDimensionsCacher.clientWidth,
|
258
|
+
y: (clientY - bc.top) / this.mode.htmlDimensionsCacher.clientHeight
|
259
|
+
};
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* @param {number} newScale
|
264
|
+
* @param {number} oldScale
|
265
|
+
*/
|
266
|
+
updateViewportOnZoom(newScale, oldScale) {
|
267
|
+
var _this$pinchMoveFrameP;
|
268
|
+
var container = this.mode.$container;
|
269
|
+
var {
|
270
|
+
scrollTop: T,
|
271
|
+
scrollLeft: L
|
272
|
+
} = container;
|
273
|
+
var W = this.mode.htmlDimensionsCacher.clientWidth;
|
274
|
+
var H = this.mode.htmlDimensionsCacher.clientHeight;
|
275
|
+
|
276
|
+
// Scale factor change
|
277
|
+
var F = newScale / oldScale;
|
278
|
+
|
279
|
+
// Where in the viewport the zoom is centered on
|
280
|
+
var XPOS = this.scaleCenter.x;
|
281
|
+
var YPOS = this.scaleCenter.y;
|
282
|
+
var oldCenter = {
|
283
|
+
x: L + XPOS * W,
|
284
|
+
y: T + YPOS * H
|
285
|
+
};
|
286
|
+
var newCenter = {
|
287
|
+
x: F * oldCenter.x,
|
288
|
+
y: F * oldCenter.y
|
289
|
+
};
|
290
|
+
container.scrollTop = newCenter.y - YPOS * H;
|
291
|
+
container.scrollLeft = newCenter.x - XPOS * W;
|
292
|
+
(_this$pinchMoveFrameP = this.pinchMoveFramePromiseRes) === null || _this$pinchMoveFrameP === void 0 || _this$pinchMoveFrameP.call(this);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
export class TouchesMonitor {
|
296
|
+
/**
|
297
|
+
* @param {HTMLElement} container
|
298
|
+
*/
|
299
|
+
constructor(container) {
|
300
|
+
/**
|
301
|
+
* @param {TouchEvent} ev
|
302
|
+
*/
|
303
|
+
_defineProperty(this, "_updateTouchCount", ev => {
|
304
|
+
this.touches = ev.touches.length;
|
305
|
+
});
|
306
|
+
/** @type {HTMLElement} */
|
307
|
+
this.container = container;
|
308
|
+
this.touches = 0;
|
309
|
+
}
|
310
|
+
attach() {
|
311
|
+
this.container.addEventListener("touchstart", this._updateTouchCount);
|
312
|
+
this.container.addEventListener("touchend", this._updateTouchCount);
|
313
|
+
}
|
314
|
+
detach() {
|
315
|
+
this.container.removeEventListener("touchstart", this._updateTouchCount);
|
316
|
+
this.container.removeEventListener("touchend", this._updateTouchCount);
|
317
|
+
}
|
318
|
+
}
|