@internetarchive/bookreader 5.0.0-88-alpha.10 → 5.0.0-88
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/BookReader/BookReader.css +3 -3
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +87 -108
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.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 +4 -0
- package/babel.config.js +12 -30
- package/jsconfig.json +1 -3
- package/package.json +14 -16
- package/src/BookNavigator/search/search-results.js +1 -1
- package/src/BookReader/Mode1UpLit.js +56 -86
- package/src/BookReader/Mode2UpLit.js +2 -3
- package/src/BookReader/Navbar/Navbar.js +53 -11
- package/src/BookReader/options.js +3 -0
- package/src/BookReader.js +49 -1
- package/src/BookReaderPlugin.js +28 -0
- package/src/css/_BRnav.scss +0 -3
- package/src/css/_controls.scss +4 -0
- package/src/plugins/plugin.archive_analytics.js +84 -78
- package/src/plugins/plugin.chapters.js +17 -22
- package/src/plugins/plugin.text_selection.js +1 -1
- package/src/plugins/tts/plugin.tts.js +2 -2
- package/tests/jest/BookReader/Navbar/Navbar.test.js +16 -3
- package/tests/jest/plugins/plugin.archive_analytics.test.js +8 -11
- package/dist/esm/BookNavigator/assets/bookmark-colors.js +0 -4
- package/dist/esm/BookNavigator/assets/button-base.js +0 -4
- package/dist/esm/BookNavigator/assets/ia-logo.js +0 -4
- package/dist/esm/BookNavigator/assets/icon_checkmark.js +0 -8
- package/dist/esm/BookNavigator/assets/icon_close.js +0 -4
- package/dist/esm/BookNavigator/book-navigator.js +0 -612
- package/dist/esm/BookNavigator/bookmarks/bookmark-button.js +0 -35
- package/dist/esm/BookNavigator/bookmarks/bookmark-edit.js +0 -78
- package/dist/esm/BookNavigator/bookmarks/bookmarks-list.js +0 -160
- package/dist/esm/BookNavigator/bookmarks/bookmarks-loginCTA.js +0 -24
- package/dist/esm/BookNavigator/bookmarks/bookmarks-provider.js +0 -55
- package/dist/esm/BookNavigator/bookmarks/ia-bookmarks.js +0 -521
- package/dist/esm/BookNavigator/delete-modal-actions.js +0 -29
- package/dist/esm/BookNavigator/downloads/downloads-provider.js +0 -84
- package/dist/esm/BookNavigator/downloads/downloads.js +0 -69
- package/dist/esm/BookNavigator/search/search-provider.js +0 -238
- package/dist/esm/BookNavigator/search/search-results.js +0 -161
- package/dist/esm/BookNavigator/sharing.js +0 -26
- package/dist/esm/BookNavigator/viewable-files.js +0 -94
- package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments-provider.js +0 -83
- package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments.js +0 -131
- package/dist/esm/BookReader/BookModel.js +0 -575
- package/dist/esm/BookReader/DragScrollable.js +0 -224
- package/dist/esm/BookReader/ImageCache.js +0 -122
- package/dist/esm/BookReader/Mode1Up.js +0 -114
- package/dist/esm/BookReader/Mode1UpLit.js +0 -579
- package/dist/esm/BookReader/Mode2Up.js +0 -106
- package/dist/esm/BookReader/Mode2UpLit.js +0 -1020
- package/dist/esm/BookReader/ModeCoordinateSpace.js +0 -28
- package/dist/esm/BookReader/ModeSmoothZoom.js +0 -318
- package/dist/esm/BookReader/ModeThumb.js +0 -366
- package/dist/esm/BookReader/Navbar/Navbar.js +0 -253
- package/dist/esm/BookReader/PageContainer.js +0 -165
- package/dist/esm/BookReader/ReduceSet.js +0 -27
- package/dist/esm/BookReader/Toolbar/Toolbar.js +0 -242
- package/dist/esm/BookReader/events.js +0 -20
- package/dist/esm/BookReader/options.js +0 -331
- package/dist/esm/BookReader/utils/HTMLDimensionsCacher.js +0 -48
- package/dist/esm/BookReader/utils/ScrollClassAdder.js +0 -31
- package/dist/esm/BookReader/utils/SelectionObserver.js +0 -42
- package/dist/esm/BookReader/utils/classes.js +0 -37
- package/dist/esm/BookReader/utils.js +0 -315
- package/dist/esm/BookReader.js +0 -1827
- package/dist/esm/assets/icons/1up.svg +0 -12
- package/dist/esm/assets/icons/2up.svg +0 -15
- package/dist/esm/assets/icons/advance.svg +0 -26
- package/dist/esm/assets/icons/chevron-right.svg +0 -1
- package/dist/esm/assets/icons/close-circle-dark.svg +0 -1
- package/dist/esm/assets/icons/close-circle.svg +0 -1
- package/dist/esm/assets/icons/fullscreen.svg +0 -17
- package/dist/esm/assets/icons/fullscreen_exit.svg +0 -17
- package/dist/esm/assets/icons/hamburger.svg +0 -15
- package/dist/esm/assets/icons/left-arrow.svg +0 -12
- package/dist/esm/assets/icons/magnify-minus.svg +0 -12
- package/dist/esm/assets/icons/magnify-plus.svg +0 -13
- package/dist/esm/assets/icons/magnify.svg +0 -15
- package/dist/esm/assets/icons/pause.svg +0 -23
- package/dist/esm/assets/icons/play.svg +0 -22
- package/dist/esm/assets/icons/playback-speed.svg +0 -34
- package/dist/esm/assets/icons/read-aloud.svg +0 -22
- package/dist/esm/assets/icons/review.svg +0 -22
- package/dist/esm/assets/icons/thumbnails.svg +0 -17
- package/dist/esm/assets/icons/voice.svg +0 -1
- package/dist/esm/assets/icons/volume-full.svg +0 -22
- package/dist/esm/assets/images/BRicons.png +0 -0
- package/dist/esm/assets/images/BRicons.svg +0 -94
- 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 +0 -177
- 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 +0 -12
- package/dist/esm/assets/images/icon_bookmark.svg +0 -12
- 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 +0 -14
- package/dist/esm/assets/images/icon_hamburger.svg +0 -20
- package/dist/esm/assets/images/icon_home.png +0 -0
- package/dist/esm/assets/images/icon_home.svg +0 -21
- 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 +0 -11
- package/dist/esm/assets/images/icon_one_page.svg +0 -8
- package/dist/esm/assets/images/icon_pause.svg +0 -1
- package/dist/esm/assets/images/icon_play.svg +0 -1
- package/dist/esm/assets/images/icon_playback-rate.svg +0 -15
- package/dist/esm/assets/images/icon_return.png +0 -0
- package/dist/esm/assets/images/icon_search_button.svg +0 -8
- package/dist/esm/assets/images/icon_share.svg +0 -9
- package/dist/esm/assets/images/icon_skip-ahead.svg +0 -6
- package/dist/esm/assets/images/icon_skip-back.svg +0 -13
- package/dist/esm/assets/images/icon_speaker.svg +0 -18
- package/dist/esm/assets/images/icon_speaker_open.svg +0 -10
- package/dist/esm/assets/images/icon_thumbnails.svg +0 -12
- package/dist/esm/assets/images/icon_toc.svg +0 -5
- package/dist/esm/assets/images/icon_two_pages.svg +0 -9
- 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 +0 -11
- 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 +0 -11
- package/dist/esm/assets/images/marker_srch-on.svg +0 -11
- 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 +0 -85
- package/dist/esm/css/_BRBookmarks.scss +0 -29
- package/dist/esm/css/_BRComponent.scss +0 -13
- package/dist/esm/css/_BRfloat.scss +0 -197
- package/dist/esm/css/_BRicon.scss +0 -54
- package/dist/esm/css/_BRmain.scss +0 -262
- package/dist/esm/css/_BRnav.scss +0 -354
- package/dist/esm/css/_BRpages.scss +0 -213
- package/dist/esm/css/_BRsearch.scss +0 -268
- package/dist/esm/css/_BRtoolbar.scss +0 -84
- package/dist/esm/css/_BRvendor.scss +0 -5
- package/dist/esm/css/_TextSelection.scss +0 -108
- package/dist/esm/css/_colorbox.scss +0 -52
- package/dist/esm/css/_controls.scss +0 -257
- package/dist/esm/css/_icons.scss +0 -121
- package/dist/esm/ia-bookreader/ia-bookreader.js +0 -141
- package/dist/esm/jquery-wrapper.js +0 -3
- package/dist/esm/plugins/plugin.archive_analytics.js +0 -72
- package/dist/esm/plugins/plugin.autoplay.js +0 -119
- package/dist/esm/plugins/plugin.chapters.js +0 -288
- package/dist/esm/plugins/plugin.iframe.js +0 -44
- package/dist/esm/plugins/plugin.iiif.js +0 -146
- package/dist/esm/plugins/plugin.resume.js +0 -66
- package/dist/esm/plugins/plugin.text_selection.js +0 -621
- package/dist/esm/plugins/plugin.vendor-fullscreen.js +0 -227
- package/dist/esm/plugins/search/plugin.search.js +0 -499
- package/dist/esm/plugins/search/utils.js +0 -42
- package/dist/esm/plugins/search/view.js +0 -360
- package/dist/esm/plugins/tts/AbstractTTSEngine.js +0 -282
- package/dist/esm/plugins/tts/FestivalTTSEngine.js +0 -192
- package/dist/esm/plugins/tts/PageChunk.js +0 -105
- package/dist/esm/plugins/tts/PageChunkIterator.js +0 -155
- package/dist/esm/plugins/tts/WebTTSEngine.js +0 -364
- package/dist/esm/plugins/tts/plugin.tts.js +0 -315
- package/dist/esm/plugins/tts/tooltip_dict.js +0 -14
- package/dist/esm/plugins/tts/utils.js +0 -79
- package/dist/esm/plugins/url/UrlPlugin.js +0 -197
- package/dist/esm/plugins/url/plugin.url.js +0 -212
- package/dist/esm/util/browserSniffing.js +0 -56
- package/dist/esm/util/debouncer.js +0 -25
- package/dist/esm/util/docCookies.js +0 -75
- package/dist/esm/util/strings.js +0 -34
- package/index.js +0 -2
@@ -1,28 +0,0 @@
|
|
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
|
-
}
|
@@ -1,318 +0,0 @@
|
|
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
|
-
}
|