@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.
Files changed (215) hide show
  1. package/BookReader/BookReader.css +3 -3
  2. package/BookReader/BookReader.js +1 -1
  3. package/BookReader/BookReader.js.map +1 -1
  4. package/BookReader/ia-bookreader-bundle.js +87 -108
  5. package/BookReader/ia-bookreader-bundle.js.map +1 -1
  6. package/BookReader/plugins/plugin.archive_analytics.js +1 -1
  7. package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
  8. package/BookReader/plugins/plugin.search.js +1 -1
  9. package/BookReader/plugins/plugin.search.js.map +1 -1
  10. package/BookReader/plugins/plugin.text_selection.js +1 -1
  11. package/BookReader/plugins/plugin.text_selection.js.map +1 -1
  12. package/BookReader/plugins/plugin.tts.js +1 -1
  13. package/BookReader/plugins/plugin.tts.js.map +1 -1
  14. package/BookReader/plugins/plugin.url.js +1 -1
  15. package/BookReader/plugins/plugin.url.js.map +1 -1
  16. package/CHANGELOG.md +4 -0
  17. package/babel.config.js +12 -30
  18. package/jsconfig.json +1 -3
  19. package/package.json +14 -16
  20. package/src/BookNavigator/search/search-results.js +1 -1
  21. package/src/BookReader/Mode1UpLit.js +56 -86
  22. package/src/BookReader/Mode2UpLit.js +2 -3
  23. package/src/BookReader/Navbar/Navbar.js +53 -11
  24. package/src/BookReader/options.js +3 -0
  25. package/src/BookReader.js +49 -1
  26. package/src/BookReaderPlugin.js +28 -0
  27. package/src/css/_BRnav.scss +0 -3
  28. package/src/css/_controls.scss +4 -0
  29. package/src/plugins/plugin.archive_analytics.js +84 -78
  30. package/src/plugins/plugin.chapters.js +17 -22
  31. package/src/plugins/plugin.text_selection.js +1 -1
  32. package/src/plugins/tts/plugin.tts.js +2 -2
  33. package/tests/jest/BookReader/Navbar/Navbar.test.js +16 -3
  34. package/tests/jest/plugins/plugin.archive_analytics.test.js +8 -11
  35. package/dist/esm/BookNavigator/assets/bookmark-colors.js +0 -4
  36. package/dist/esm/BookNavigator/assets/button-base.js +0 -4
  37. package/dist/esm/BookNavigator/assets/ia-logo.js +0 -4
  38. package/dist/esm/BookNavigator/assets/icon_checkmark.js +0 -8
  39. package/dist/esm/BookNavigator/assets/icon_close.js +0 -4
  40. package/dist/esm/BookNavigator/book-navigator.js +0 -612
  41. package/dist/esm/BookNavigator/bookmarks/bookmark-button.js +0 -35
  42. package/dist/esm/BookNavigator/bookmarks/bookmark-edit.js +0 -78
  43. package/dist/esm/BookNavigator/bookmarks/bookmarks-list.js +0 -160
  44. package/dist/esm/BookNavigator/bookmarks/bookmarks-loginCTA.js +0 -24
  45. package/dist/esm/BookNavigator/bookmarks/bookmarks-provider.js +0 -55
  46. package/dist/esm/BookNavigator/bookmarks/ia-bookmarks.js +0 -521
  47. package/dist/esm/BookNavigator/delete-modal-actions.js +0 -29
  48. package/dist/esm/BookNavigator/downloads/downloads-provider.js +0 -84
  49. package/dist/esm/BookNavigator/downloads/downloads.js +0 -69
  50. package/dist/esm/BookNavigator/search/search-provider.js +0 -238
  51. package/dist/esm/BookNavigator/search/search-results.js +0 -161
  52. package/dist/esm/BookNavigator/sharing.js +0 -26
  53. package/dist/esm/BookNavigator/viewable-files.js +0 -94
  54. package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments-provider.js +0 -83
  55. package/dist/esm/BookNavigator/visual-adjustments/visual-adjustments.js +0 -131
  56. package/dist/esm/BookReader/BookModel.js +0 -575
  57. package/dist/esm/BookReader/DragScrollable.js +0 -224
  58. package/dist/esm/BookReader/ImageCache.js +0 -122
  59. package/dist/esm/BookReader/Mode1Up.js +0 -114
  60. package/dist/esm/BookReader/Mode1UpLit.js +0 -579
  61. package/dist/esm/BookReader/Mode2Up.js +0 -106
  62. package/dist/esm/BookReader/Mode2UpLit.js +0 -1020
  63. package/dist/esm/BookReader/ModeCoordinateSpace.js +0 -28
  64. package/dist/esm/BookReader/ModeSmoothZoom.js +0 -318
  65. package/dist/esm/BookReader/ModeThumb.js +0 -366
  66. package/dist/esm/BookReader/Navbar/Navbar.js +0 -253
  67. package/dist/esm/BookReader/PageContainer.js +0 -165
  68. package/dist/esm/BookReader/ReduceSet.js +0 -27
  69. package/dist/esm/BookReader/Toolbar/Toolbar.js +0 -242
  70. package/dist/esm/BookReader/events.js +0 -20
  71. package/dist/esm/BookReader/options.js +0 -331
  72. package/dist/esm/BookReader/utils/HTMLDimensionsCacher.js +0 -48
  73. package/dist/esm/BookReader/utils/ScrollClassAdder.js +0 -31
  74. package/dist/esm/BookReader/utils/SelectionObserver.js +0 -42
  75. package/dist/esm/BookReader/utils/classes.js +0 -37
  76. package/dist/esm/BookReader/utils.js +0 -315
  77. package/dist/esm/BookReader.js +0 -1827
  78. package/dist/esm/assets/icons/1up.svg +0 -12
  79. package/dist/esm/assets/icons/2up.svg +0 -15
  80. package/dist/esm/assets/icons/advance.svg +0 -26
  81. package/dist/esm/assets/icons/chevron-right.svg +0 -1
  82. package/dist/esm/assets/icons/close-circle-dark.svg +0 -1
  83. package/dist/esm/assets/icons/close-circle.svg +0 -1
  84. package/dist/esm/assets/icons/fullscreen.svg +0 -17
  85. package/dist/esm/assets/icons/fullscreen_exit.svg +0 -17
  86. package/dist/esm/assets/icons/hamburger.svg +0 -15
  87. package/dist/esm/assets/icons/left-arrow.svg +0 -12
  88. package/dist/esm/assets/icons/magnify-minus.svg +0 -12
  89. package/dist/esm/assets/icons/magnify-plus.svg +0 -13
  90. package/dist/esm/assets/icons/magnify.svg +0 -15
  91. package/dist/esm/assets/icons/pause.svg +0 -23
  92. package/dist/esm/assets/icons/play.svg +0 -22
  93. package/dist/esm/assets/icons/playback-speed.svg +0 -34
  94. package/dist/esm/assets/icons/read-aloud.svg +0 -22
  95. package/dist/esm/assets/icons/review.svg +0 -22
  96. package/dist/esm/assets/icons/thumbnails.svg +0 -17
  97. package/dist/esm/assets/icons/voice.svg +0 -1
  98. package/dist/esm/assets/icons/volume-full.svg +0 -22
  99. package/dist/esm/assets/images/BRicons.png +0 -0
  100. package/dist/esm/assets/images/BRicons.svg +0 -94
  101. package/dist/esm/assets/images/BRicons_ia.png +0 -0
  102. package/dist/esm/assets/images/back_pages.png +0 -0
  103. package/dist/esm/assets/images/book_bottom_icon.png +0 -0
  104. package/dist/esm/assets/images/book_down_icon.png +0 -0
  105. package/dist/esm/assets/images/book_left_icon.png +0 -0
  106. package/dist/esm/assets/images/book_leftmost_icon.png +0 -0
  107. package/dist/esm/assets/images/book_right_icon.png +0 -0
  108. package/dist/esm/assets/images/book_rightmost_icon.png +0 -0
  109. package/dist/esm/assets/images/book_top_icon.png +0 -0
  110. package/dist/esm/assets/images/book_up_icon.png +0 -0
  111. package/dist/esm/assets/images/books_graphic.svg +0 -177
  112. package/dist/esm/assets/images/booksplit.png +0 -0
  113. package/dist/esm/assets/images/control_pause_icon.png +0 -0
  114. package/dist/esm/assets/images/control_play_icon.png +0 -0
  115. package/dist/esm/assets/images/embed_icon.png +0 -0
  116. package/dist/esm/assets/images/icon-home-ia.png +0 -0
  117. package/dist/esm/assets/images/icon_OL-logo-xs.png +0 -0
  118. package/dist/esm/assets/images/icon_alert-xs.png +0 -0
  119. package/dist/esm/assets/images/icon_book.svg +0 -12
  120. package/dist/esm/assets/images/icon_bookmark.svg +0 -12
  121. package/dist/esm/assets/images/icon_close-pop.png +0 -0
  122. package/dist/esm/assets/images/icon_download.png +0 -0
  123. package/dist/esm/assets/images/icon_gear.svg +0 -14
  124. package/dist/esm/assets/images/icon_hamburger.svg +0 -20
  125. package/dist/esm/assets/images/icon_home.png +0 -0
  126. package/dist/esm/assets/images/icon_home.svg +0 -21
  127. package/dist/esm/assets/images/icon_home_ia.png +0 -0
  128. package/dist/esm/assets/images/icon_indicator.png +0 -0
  129. package/dist/esm/assets/images/icon_info.svg +0 -11
  130. package/dist/esm/assets/images/icon_one_page.svg +0 -8
  131. package/dist/esm/assets/images/icon_pause.svg +0 -1
  132. package/dist/esm/assets/images/icon_play.svg +0 -1
  133. package/dist/esm/assets/images/icon_playback-rate.svg +0 -15
  134. package/dist/esm/assets/images/icon_return.png +0 -0
  135. package/dist/esm/assets/images/icon_search_button.svg +0 -8
  136. package/dist/esm/assets/images/icon_share.svg +0 -9
  137. package/dist/esm/assets/images/icon_skip-ahead.svg +0 -6
  138. package/dist/esm/assets/images/icon_skip-back.svg +0 -13
  139. package/dist/esm/assets/images/icon_speaker.svg +0 -18
  140. package/dist/esm/assets/images/icon_speaker_open.svg +0 -10
  141. package/dist/esm/assets/images/icon_thumbnails.svg +0 -12
  142. package/dist/esm/assets/images/icon_toc.svg +0 -5
  143. package/dist/esm/assets/images/icon_two_pages.svg +0 -9
  144. package/dist/esm/assets/images/icon_zoomer.png +0 -0
  145. package/dist/esm/assets/images/loading.gif +0 -0
  146. package/dist/esm/assets/images/logo_icon.png +0 -0
  147. package/dist/esm/assets/images/marker_chap-off.png +0 -0
  148. package/dist/esm/assets/images/marker_chap-off.svg +0 -11
  149. package/dist/esm/assets/images/marker_chap-off_ia.png +0 -0
  150. package/dist/esm/assets/images/marker_chap-on.png +0 -0
  151. package/dist/esm/assets/images/marker_chap-on.svg +0 -11
  152. package/dist/esm/assets/images/marker_srch-on.svg +0 -11
  153. package/dist/esm/assets/images/marker_srchchap-off.png +0 -0
  154. package/dist/esm/assets/images/marker_srchchap-on.png +0 -0
  155. package/dist/esm/assets/images/nav_control-dn.png +0 -0
  156. package/dist/esm/assets/images/nav_control-dn_ia.png +0 -0
  157. package/dist/esm/assets/images/nav_control-up.png +0 -0
  158. package/dist/esm/assets/images/nav_control-up_ia.png +0 -0
  159. package/dist/esm/assets/images/nav_control.png +0 -0
  160. package/dist/esm/assets/images/one_page_mode_icon.png +0 -0
  161. package/dist/esm/assets/images/paper-badge.png +0 -0
  162. package/dist/esm/assets/images/print_icon.png +0 -0
  163. package/dist/esm/assets/images/progressbar.gif +0 -0
  164. package/dist/esm/assets/images/right_edges.png +0 -0
  165. package/dist/esm/assets/images/slider.png +0 -0
  166. package/dist/esm/assets/images/slider_ia.png +0 -0
  167. package/dist/esm/assets/images/thumbnail_mode_icon.png +0 -0
  168. package/dist/esm/assets/images/transparent.png +0 -0
  169. package/dist/esm/assets/images/two_page_mode_icon.png +0 -0
  170. package/dist/esm/assets/images/unviewable_page.png +0 -0
  171. package/dist/esm/assets/images/zoom_in_icon.png +0 -0
  172. package/dist/esm/assets/images/zoom_out_icon.png +0 -0
  173. package/dist/esm/css/BookReader.scss +0 -85
  174. package/dist/esm/css/_BRBookmarks.scss +0 -29
  175. package/dist/esm/css/_BRComponent.scss +0 -13
  176. package/dist/esm/css/_BRfloat.scss +0 -197
  177. package/dist/esm/css/_BRicon.scss +0 -54
  178. package/dist/esm/css/_BRmain.scss +0 -262
  179. package/dist/esm/css/_BRnav.scss +0 -354
  180. package/dist/esm/css/_BRpages.scss +0 -213
  181. package/dist/esm/css/_BRsearch.scss +0 -268
  182. package/dist/esm/css/_BRtoolbar.scss +0 -84
  183. package/dist/esm/css/_BRvendor.scss +0 -5
  184. package/dist/esm/css/_TextSelection.scss +0 -108
  185. package/dist/esm/css/_colorbox.scss +0 -52
  186. package/dist/esm/css/_controls.scss +0 -257
  187. package/dist/esm/css/_icons.scss +0 -121
  188. package/dist/esm/ia-bookreader/ia-bookreader.js +0 -141
  189. package/dist/esm/jquery-wrapper.js +0 -3
  190. package/dist/esm/plugins/plugin.archive_analytics.js +0 -72
  191. package/dist/esm/plugins/plugin.autoplay.js +0 -119
  192. package/dist/esm/plugins/plugin.chapters.js +0 -288
  193. package/dist/esm/plugins/plugin.iframe.js +0 -44
  194. package/dist/esm/plugins/plugin.iiif.js +0 -146
  195. package/dist/esm/plugins/plugin.resume.js +0 -66
  196. package/dist/esm/plugins/plugin.text_selection.js +0 -621
  197. package/dist/esm/plugins/plugin.vendor-fullscreen.js +0 -227
  198. package/dist/esm/plugins/search/plugin.search.js +0 -499
  199. package/dist/esm/plugins/search/utils.js +0 -42
  200. package/dist/esm/plugins/search/view.js +0 -360
  201. package/dist/esm/plugins/tts/AbstractTTSEngine.js +0 -282
  202. package/dist/esm/plugins/tts/FestivalTTSEngine.js +0 -192
  203. package/dist/esm/plugins/tts/PageChunk.js +0 -105
  204. package/dist/esm/plugins/tts/PageChunkIterator.js +0 -155
  205. package/dist/esm/plugins/tts/WebTTSEngine.js +0 -364
  206. package/dist/esm/plugins/tts/plugin.tts.js +0 -315
  207. package/dist/esm/plugins/tts/tooltip_dict.js +0 -14
  208. package/dist/esm/plugins/tts/utils.js +0 -79
  209. package/dist/esm/plugins/url/UrlPlugin.js +0 -197
  210. package/dist/esm/plugins/url/plugin.url.js +0 -212
  211. package/dist/esm/util/browserSniffing.js +0 -56
  212. package/dist/esm/util/debouncer.js +0 -25
  213. package/dist/esm/util/docCookies.js +0 -75
  214. package/dist/esm/util/strings.js +0 -34
  215. 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
- }