@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,315 @@
|
|
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
|
+
/**
|
4
|
+
* Bind mouse handlers
|
5
|
+
* Disable mouse click to avoid selected/highlighted page images
|
6
|
+
* @param {JQuery} jObject
|
7
|
+
*/
|
8
|
+
export function disableSelect(jObject) {
|
9
|
+
// $$$ check here for right-click and don't disable. Also use jQuery style
|
10
|
+
// for stopping propagation. See https://bugs.edge.launchpad.net/gnubook/+bug/362626
|
11
|
+
jObject.bind('mousedown', () => false);
|
12
|
+
// Special hack for IE7
|
13
|
+
jObject[0].onselectstart = () => false;
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @param {number} value
|
18
|
+
* @param {number} min
|
19
|
+
* @param {number} max
|
20
|
+
* @return {number}
|
21
|
+
*/
|
22
|
+
export function clamp(value, min, max) {
|
23
|
+
return Math.min(Math.max(value, min), max);
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Given value and maximum, calculate a percentage suitable for CSS
|
28
|
+
* @param {number} value
|
29
|
+
* @param {number} max
|
30
|
+
* @return {string}
|
31
|
+
*/
|
32
|
+
export function cssPercentage(value, max) {
|
33
|
+
return value / max * 100 + '%';
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* @param {*} value
|
38
|
+
* @param {Array} array
|
39
|
+
* @return {boolean}
|
40
|
+
*/
|
41
|
+
export function notInArray(value, array) {
|
42
|
+
return !array.includes(value);
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Determines the active element, going into shadow doms.
|
47
|
+
* @return {Element}
|
48
|
+
*/
|
49
|
+
export function getActiveElement() {
|
50
|
+
var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
|
51
|
+
var recurseShadowDom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
52
|
+
var activeElement = doc.activeElement;
|
53
|
+
if (recurseShadowDom && activeElement !== null && activeElement !== void 0 && activeElement.shadowRoot) {
|
54
|
+
return getActiveElement(activeElement.shadowRoot, true);
|
55
|
+
}
|
56
|
+
return activeElement;
|
57
|
+
}
|
58
|
+
|
59
|
+
/** Check if an input field/textarea is active. Also checks shadow DOMs. */
|
60
|
+
export function isInputActive() {
|
61
|
+
var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
|
62
|
+
var activeEl = getActiveElement(doc);
|
63
|
+
return (activeEl === null || activeEl === void 0 ? void 0 : activeEl.tagName) == "INPUT" || (activeEl === null || activeEl === void 0 ? void 0 : activeEl.tagName) == "TEXTAREA";
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @param {HTMLIFrameElement} iframe
|
68
|
+
* @return {Document}
|
69
|
+
*/
|
70
|
+
export function getIFrameDocument(iframe) {
|
71
|
+
// Adapted from http://xkr.us/articles/dom/iframe-document/
|
72
|
+
var outer = iframe.contentWindow || iframe.contentDocument;
|
73
|
+
return outer.document || outer;
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @param {string} str
|
78
|
+
* @return {string}
|
79
|
+
*/
|
80
|
+
export function escapeHTML(str) {
|
81
|
+
return str.replace(/&/g, '&').replace(/>/g, '>').replace(/</g, '<').replace(/"/g, '"');
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Decodes a URI component and converts '+' to ' '
|
86
|
+
* @param {string} value
|
87
|
+
* @return {string}
|
88
|
+
*/
|
89
|
+
export function decodeURIComponentPlus(value) {
|
90
|
+
return decodeURIComponent(value).replace(/\+/g, ' ');
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Encodes a URI component and converts ' ' to '+'
|
95
|
+
* @param {string|number|boolean} value
|
96
|
+
* @return {string};
|
97
|
+
*/
|
98
|
+
export function encodeURIComponentPlus(value) {
|
99
|
+
return encodeURIComponent(value).replace(/%20/g, '+');
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* @template {Function} T
|
104
|
+
* Returns a function, that, as long as it continues to be invoked, will not
|
105
|
+
* be triggered. The function will be called after it stops being called for
|
106
|
+
* N milliseconds. If `immediate` is passed, trigger the function on the
|
107
|
+
* leading edge, instead of the trailing.
|
108
|
+
* @see https://davidwalsh.name/javascript-debounce-function
|
109
|
+
*
|
110
|
+
* @param {T} func
|
111
|
+
* @param {number} wait
|
112
|
+
* @param {boolean} immediate
|
113
|
+
* @return {T}
|
114
|
+
*/
|
115
|
+
export function debounce(func, wait, immediate) {
|
116
|
+
var timeout;
|
117
|
+
return function () {
|
118
|
+
var context = this;
|
119
|
+
var args = arguments;
|
120
|
+
var later = () => {
|
121
|
+
timeout = null;
|
122
|
+
if (!immediate) func.apply(context, args);
|
123
|
+
};
|
124
|
+
var callNow = immediate && !timeout;
|
125
|
+
clearTimeout(timeout);
|
126
|
+
timeout = setTimeout(later, wait);
|
127
|
+
if (callNow) func.apply(context, args);
|
128
|
+
};
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* @template T
|
133
|
+
* Throttle function
|
134
|
+
* @see https://remysharp.com/2010/07/21/throttling-function-calls
|
135
|
+
* @param {T} fn
|
136
|
+
* @param {number} threshold
|
137
|
+
* @param {boolean} delay
|
138
|
+
* @return {T}
|
139
|
+
*/
|
140
|
+
export function throttle(fn, threshold, delay) {
|
141
|
+
threshold || (threshold = 250);
|
142
|
+
var last;
|
143
|
+
var deferTimer;
|
144
|
+
if (delay) last = +new Date();
|
145
|
+
return function () {
|
146
|
+
var context = this;
|
147
|
+
var now = +new Date();
|
148
|
+
var args = arguments;
|
149
|
+
if (last && now < last + threshold) {
|
150
|
+
// hold on to it
|
151
|
+
clearTimeout(deferTimer);
|
152
|
+
deferTimer = setTimeout(() => {
|
153
|
+
last = now;
|
154
|
+
fn.apply(context, args);
|
155
|
+
}, threshold);
|
156
|
+
} else {
|
157
|
+
last = now;
|
158
|
+
fn.apply(context, args);
|
159
|
+
}
|
160
|
+
};
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* FIXME we need a better way to do this :/ This is not automatically poly-filled by
|
165
|
+
* core-js https://github.com/zloirock/core-js/issues/354
|
166
|
+
* @param {Window} window
|
167
|
+
*/
|
168
|
+
export function polyfillCustomEvent(window) {
|
169
|
+
if (typeof window.CustomEvent === "function") return false;
|
170
|
+
window.CustomEvent = PolyfilledCustomEvent;
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* https://caniuse.com/customevent has issues on older browsers where it can't be
|
175
|
+
* called as a constructor, so we have to use older methods.
|
176
|
+
* @param {String} eventName
|
177
|
+
* @return {CustomEvent}
|
178
|
+
*/
|
179
|
+
export function PolyfilledCustomEvent(eventName) {
|
180
|
+
var {
|
181
|
+
bubbles = false,
|
182
|
+
cancelable = false,
|
183
|
+
detail = null
|
184
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
185
|
+
var event = document.createEvent('CustomEvent');
|
186
|
+
event.initCustomEvent(eventName, bubbles, cancelable, detail);
|
187
|
+
return event;
|
188
|
+
}
|
189
|
+
|
190
|
+
/*
|
191
|
+
* Returns the number pixels something should be rendered at to be ~1n on the users
|
192
|
+
* screen when measured with a ruler.
|
193
|
+
*/
|
194
|
+
export function calcScreenDPI() {
|
195
|
+
var el = document.createElement('div');
|
196
|
+
el.style.width = '1in';
|
197
|
+
document.body.appendChild(el);
|
198
|
+
var dpi = el.offsetWidth;
|
199
|
+
document.body.removeChild(el);
|
200
|
+
|
201
|
+
// Do you believe in magic... numbers? We tested on some devices, and the displayed
|
202
|
+
// size of `width: 1in` was less than desired. On @pezvi's mac, it was ~75% ; on
|
203
|
+
// @cdrini's laptop it was ~85%. Since we want to avoid things appearing too small,
|
204
|
+
// let's just use a multiplier of 1.25
|
205
|
+
var screenDPI = dpi * 1.25;
|
206
|
+
// This will return 0 in testing; never want it to be 0!
|
207
|
+
return screenDPI == 0 ? 100 : screenDPI;
|
208
|
+
}
|
209
|
+
|
210
|
+
/**
|
211
|
+
* @param {number[]} nums
|
212
|
+
* @returns {number}
|
213
|
+
*/
|
214
|
+
export function sum(nums) {
|
215
|
+
return nums.reduce((cur, acc) => cur + acc, 0);
|
216
|
+
}
|
217
|
+
|
218
|
+
/**
|
219
|
+
* @template T
|
220
|
+
* @param {Generator<T>} gen
|
221
|
+
* @returns {T[]}
|
222
|
+
*/
|
223
|
+
export function genToArray(gen) {
|
224
|
+
var result = [];
|
225
|
+
for (var item of gen) {
|
226
|
+
result.push(item);
|
227
|
+
}
|
228
|
+
return result;
|
229
|
+
}
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Check if arrays contain the same elements. Does reference comparison.
|
233
|
+
* @param {Array} arr1
|
234
|
+
* @param {Array} arr2
|
235
|
+
*/
|
236
|
+
export function arrEquals(arr1, arr2) {
|
237
|
+
return arr1.length == arr2.length && arr1.every((x, i) => x == arr2[i]);
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Check if array has changed; namely to be used with lit's property.hasChanged
|
242
|
+
* @param {Array} [arr1]
|
243
|
+
* @param {Array} [arr2]
|
244
|
+
*/
|
245
|
+
export function arrChanged(arr1, arr2) {
|
246
|
+
return arr1 && arr2 && !arrEquals(arr1, arr2);
|
247
|
+
}
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Waits the provided number of ms and then resolves with a promise
|
251
|
+
* @param {number} ms
|
252
|
+
**/
|
253
|
+
export function sleep(_x) {
|
254
|
+
return _sleep2.apply(this, arguments);
|
255
|
+
}
|
256
|
+
|
257
|
+
/**
|
258
|
+
* @template T
|
259
|
+
* @param {function(): T} fn
|
260
|
+
* @param {Object} options
|
261
|
+
* @param {function(T): boolean} [options.until]
|
262
|
+
* @return {T | undefined}
|
263
|
+
*/
|
264
|
+
function _sleep2() {
|
265
|
+
_sleep2 = _asyncToGenerator(function* (ms) {
|
266
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
267
|
+
});
|
268
|
+
return _sleep2.apply(this, arguments);
|
269
|
+
}
|
270
|
+
export function poll(_x2) {
|
271
|
+
return _poll.apply(this, arguments);
|
272
|
+
}
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Convert a EventTarget style event into a promise
|
276
|
+
* @param {EventTarget} target
|
277
|
+
* @param {string} eventType
|
278
|
+
* @return {Promise<Event>}
|
279
|
+
*/
|
280
|
+
function _poll() {
|
281
|
+
_poll = _asyncToGenerator(function* (fn) {
|
282
|
+
var {
|
283
|
+
step = 50,
|
284
|
+
timeout = 500,
|
285
|
+
until = val => Boolean(val),
|
286
|
+
_sleep = sleep
|
287
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
288
|
+
var startTime = Date.now();
|
289
|
+
while (Date.now() - startTime < timeout) {
|
290
|
+
var result = fn();
|
291
|
+
if (until(result)) return result;
|
292
|
+
yield _sleep(step);
|
293
|
+
}
|
294
|
+
});
|
295
|
+
return _poll.apply(this, arguments);
|
296
|
+
}
|
297
|
+
export function promisifyEvent(target, eventType) {
|
298
|
+
return new Promise(res => {
|
299
|
+
var resolver = ev => {
|
300
|
+
target.removeEventListener(eventType, resolver);
|
301
|
+
res(ev);
|
302
|
+
};
|
303
|
+
target.addEventListener(eventType, resolver);
|
304
|
+
});
|
305
|
+
}
|
306
|
+
|
307
|
+
/**
|
308
|
+
* Escapes regex special characters in a string. Allows for safe usage in regexes.
|
309
|
+
* Src: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
|
310
|
+
* @param {string} string
|
311
|
+
* @returns {string}
|
312
|
+
*/
|
313
|
+
export function escapeRegExp(string) {
|
314
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
|
315
|
+
}
|