pdfjs-dist 2.3.200 → 2.4.456
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.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +19303 -29896
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1333 -4839
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +683 -1066
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -21,257 +21,247 @@
|
|
21
21
|
*/
|
22
22
|
"use strict";
|
23
23
|
|
24
|
-
var _ui_utils = require("../../web/ui_utils");
|
24
|
+
var _ui_utils = require("../../web/ui_utils.js");
|
25
25
|
|
26
|
-
var _util = require("../../shared/util");
|
26
|
+
var _util = require("../../shared/util.js");
|
27
27
|
|
28
|
-
var _is_node =
|
28
|
+
var _is_node = require("../../shared/is_node.js");
|
29
29
|
|
30
|
-
function
|
31
|
-
|
32
|
-
function
|
33
|
-
|
34
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
35
|
-
|
36
|
-
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
37
|
-
|
38
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
39
|
-
|
40
|
-
describe('ui_utils', function () {
|
41
|
-
describe('binary search', function () {
|
42
|
-
function isTrue(_boolean) {
|
43
|
-
return _boolean;
|
30
|
+
describe("ui_utils", function () {
|
31
|
+
describe("binary search", function () {
|
32
|
+
function isTrue(boolean) {
|
33
|
+
return boolean;
|
44
34
|
}
|
45
35
|
|
46
36
|
function isGreater3(number) {
|
47
37
|
return number > 3;
|
48
38
|
}
|
49
39
|
|
50
|
-
it(
|
40
|
+
it("empty array", function () {
|
51
41
|
expect((0, _ui_utils.binarySearchFirstItem)([], isTrue)).toEqual(0);
|
52
42
|
});
|
53
|
-
it(
|
43
|
+
it("single boolean entry", function () {
|
54
44
|
expect((0, _ui_utils.binarySearchFirstItem)([false], isTrue)).toEqual(1);
|
55
45
|
expect((0, _ui_utils.binarySearchFirstItem)([true], isTrue)).toEqual(0);
|
56
46
|
});
|
57
|
-
it(
|
47
|
+
it("three boolean entries", function () {
|
58
48
|
expect((0, _ui_utils.binarySearchFirstItem)([true, true, true], isTrue)).toEqual(0);
|
59
49
|
expect((0, _ui_utils.binarySearchFirstItem)([false, true, true], isTrue)).toEqual(1);
|
60
50
|
expect((0, _ui_utils.binarySearchFirstItem)([false, false, true], isTrue)).toEqual(2);
|
61
51
|
expect((0, _ui_utils.binarySearchFirstItem)([false, false, false], isTrue)).toEqual(3);
|
62
52
|
});
|
63
|
-
it(
|
53
|
+
it("three numeric entries", function () {
|
64
54
|
expect((0, _ui_utils.binarySearchFirstItem)([0, 1, 2], isGreater3)).toEqual(3);
|
65
55
|
expect((0, _ui_utils.binarySearchFirstItem)([2, 3, 4], isGreater3)).toEqual(2);
|
66
56
|
expect((0, _ui_utils.binarySearchFirstItem)([4, 5, 6], isGreater3)).toEqual(0);
|
67
57
|
});
|
68
58
|
});
|
69
|
-
describe(
|
70
|
-
it(
|
71
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
72
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
73
|
-
});
|
74
|
-
it(
|
75
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
76
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
77
|
-
});
|
78
|
-
it(
|
79
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
80
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
81
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
82
|
-
});
|
83
|
-
it(
|
84
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(null)).toEqual(
|
85
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(null,
|
86
|
-
});
|
87
|
-
it(
|
88
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
89
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
90
|
-
});
|
91
|
-
it(
|
92
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
93
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
94
|
-
});
|
95
|
-
it(
|
96
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
97
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
98
|
-
});
|
99
|
-
it(
|
100
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
101
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
102
|
-
});
|
103
|
-
it(
|
104
|
-
var encodedUrl = encodeURIComponent(
|
105
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrl)).toEqual(
|
106
|
-
var encodedUrlWithQuery = encodeURIComponent(
|
107
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrlWithQuery)).toEqual(
|
108
|
-
});
|
109
|
-
it(
|
110
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
111
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
112
|
-
});
|
113
|
-
it(
|
114
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
115
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
116
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
117
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
59
|
+
describe("getPDFFileNameFromURL", function () {
|
60
|
+
it("gets PDF filename", function () {
|
61
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/file1.pdf")).toEqual("file1.pdf");
|
62
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/pdfs/file2.pdf")).toEqual("file2.pdf");
|
63
|
+
});
|
64
|
+
it("gets fallback filename", function () {
|
65
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/file1.txt")).toEqual("document.pdf");
|
66
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/pdfs/file2.txt")).toEqual("document.pdf");
|
67
|
+
});
|
68
|
+
it("gets custom fallback filename", function () {
|
69
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/file1.txt", "qwerty1.pdf")).toEqual("qwerty1.pdf");
|
70
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/pdfs/file2.txt", "qwerty2.pdf")).toEqual("qwerty2.pdf");
|
71
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/file3.txt", "")).toEqual("");
|
72
|
+
});
|
73
|
+
it("gets fallback filename when url is not a string", function () {
|
74
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(null)).toEqual("document.pdf");
|
75
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(null, "file.pdf")).toEqual("file.pdf");
|
76
|
+
});
|
77
|
+
it("gets PDF filename from URL containing leading/trailing whitespace", function () {
|
78
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(" /pdfs/file1.pdf ")).toEqual("file1.pdf");
|
79
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(" http://www.example.com/pdfs/file2.pdf ")).toEqual("file2.pdf");
|
80
|
+
});
|
81
|
+
it("gets PDF filename from query string", function () {
|
82
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/pdfs.html?name=file1.pdf")).toEqual("file1.pdf");
|
83
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/pdfs/pdf.html?file2.pdf")).toEqual("file2.pdf");
|
84
|
+
});
|
85
|
+
it("gets PDF filename from hash string", function () {
|
86
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/pdfs.html#name=file1.pdf")).toEqual("file1.pdf");
|
87
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/pdfs/pdf.html#file2.pdf")).toEqual("file2.pdf");
|
88
|
+
});
|
89
|
+
it("gets correct PDF filename when multiple ones are present", function () {
|
90
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/file1.pdf?name=file.pdf")).toEqual("file1.pdf");
|
91
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/pdfs/file2.pdf#file.pdf")).toEqual("file2.pdf");
|
92
|
+
});
|
93
|
+
it("gets PDF filename from URI-encoded data", function () {
|
94
|
+
var encodedUrl = encodeURIComponent("http://www.example.com/pdfs/file1.pdf");
|
95
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrl)).toEqual("file1.pdf");
|
96
|
+
var encodedUrlWithQuery = encodeURIComponent("http://www.example.com/pdfs/file.txt?file2.pdf");
|
97
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrlWithQuery)).toEqual("file2.pdf");
|
98
|
+
});
|
99
|
+
it("gets PDF filename from data mistaken for URI-encoded", function () {
|
100
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/%AA.pdf")).toEqual("%AA.pdf");
|
101
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("/pdfs/%2F.pdf")).toEqual("%2F.pdf");
|
102
|
+
});
|
103
|
+
it("gets PDF filename from (some) standard protocols", function () {
|
104
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/file1.pdf")).toEqual("file1.pdf");
|
105
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("https://www.example.com/file2.pdf")).toEqual("file2.pdf");
|
106
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("file:///path/to/files/file3.pdf")).toEqual("file3.pdf");
|
107
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)("ftp://www.example.com/file4.pdf")).toEqual("file4.pdf");
|
118
108
|
});
|
119
109
|
it('gets PDF filename from query string appended to "blob:" URL', function () {
|
120
|
-
if (
|
121
|
-
pending(
|
110
|
+
if (_is_node.isNodeJS) {
|
111
|
+
pending("Blob in not supported in Node.js.");
|
122
112
|
}
|
123
113
|
|
124
114
|
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
125
|
-
var blobUrl = (0, _util.createObjectURL)(typedArray,
|
126
|
-
expect(blobUrl.startsWith(
|
127
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(blobUrl +
|
115
|
+
var blobUrl = (0, _util.createObjectURL)(typedArray, "application/pdf");
|
116
|
+
expect(blobUrl.startsWith("blob:")).toEqual(true);
|
117
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(blobUrl + "?file.pdf")).toEqual("file.pdf");
|
128
118
|
});
|
129
119
|
it('gets fallback filename from query string appended to "data:" URL', function () {
|
130
120
|
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
131
|
-
var dataUrl = (0, _util.createObjectURL)(typedArray,
|
132
|
-
expect(dataUrl.startsWith(
|
133
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(dataUrl +
|
134
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
121
|
+
var dataUrl = (0, _util.createObjectURL)(typedArray, "application/pdf", true);
|
122
|
+
expect(dataUrl.startsWith("data:")).toEqual(true);
|
123
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(dataUrl + "?file1.pdf")).toEqual("document.pdf");
|
124
|
+
expect((0, _ui_utils.getPDFFileNameFromURL)(" " + dataUrl + "?file2.pdf")).toEqual("document.pdf");
|
135
125
|
});
|
136
126
|
});
|
137
|
-
describe(
|
138
|
-
it(
|
127
|
+
describe("EventBus", function () {
|
128
|
+
it("dispatch event", function () {
|
139
129
|
var eventBus = new _ui_utils.EventBus();
|
140
130
|
var count = 0;
|
141
|
-
eventBus.on(
|
131
|
+
eventBus.on("test", function (evt) {
|
142
132
|
expect(evt).toEqual(undefined);
|
143
133
|
count++;
|
144
134
|
});
|
145
|
-
eventBus.dispatch(
|
135
|
+
eventBus.dispatch("test");
|
146
136
|
expect(count).toEqual(1);
|
147
137
|
});
|
148
|
-
it(
|
149
|
-
|
150
|
-
|
151
|
-
eventBus.on(
|
138
|
+
it("dispatch event with arguments", function () {
|
139
|
+
const eventBus = new _ui_utils.EventBus();
|
140
|
+
let count = 0;
|
141
|
+
eventBus.on("test", function (evt) {
|
152
142
|
expect(evt).toEqual({
|
153
143
|
abc: 123
|
154
144
|
});
|
155
145
|
count++;
|
156
146
|
});
|
157
|
-
eventBus.dispatch(
|
147
|
+
eventBus.dispatch("test", {
|
158
148
|
abc: 123
|
159
149
|
});
|
160
150
|
expect(count).toEqual(1);
|
161
151
|
});
|
162
|
-
it(
|
152
|
+
it("dispatch different event", function () {
|
163
153
|
var eventBus = new _ui_utils.EventBus();
|
164
154
|
var count = 0;
|
165
|
-
eventBus.on(
|
155
|
+
eventBus.on("test", function () {
|
166
156
|
count++;
|
167
157
|
});
|
168
|
-
eventBus.dispatch(
|
158
|
+
eventBus.dispatch("nottest");
|
169
159
|
expect(count).toEqual(0);
|
170
160
|
});
|
171
|
-
it(
|
161
|
+
it("dispatch event multiple times", function () {
|
172
162
|
var eventBus = new _ui_utils.EventBus();
|
173
163
|
var count = 0;
|
174
|
-
eventBus.dispatch(
|
175
|
-
eventBus.on(
|
164
|
+
eventBus.dispatch("test");
|
165
|
+
eventBus.on("test", function () {
|
176
166
|
count++;
|
177
167
|
});
|
178
|
-
eventBus.dispatch(
|
179
|
-
eventBus.dispatch(
|
168
|
+
eventBus.dispatch("test");
|
169
|
+
eventBus.dispatch("test");
|
180
170
|
expect(count).toEqual(2);
|
181
171
|
});
|
182
|
-
it(
|
172
|
+
it("dispatch event to multiple handlers", function () {
|
183
173
|
var eventBus = new _ui_utils.EventBus();
|
184
174
|
var count = 0;
|
185
|
-
eventBus.on(
|
175
|
+
eventBus.on("test", function () {
|
186
176
|
count++;
|
187
177
|
});
|
188
|
-
eventBus.on(
|
178
|
+
eventBus.on("test", function () {
|
189
179
|
count++;
|
190
180
|
});
|
191
|
-
eventBus.dispatch(
|
181
|
+
eventBus.dispatch("test");
|
192
182
|
expect(count).toEqual(2);
|
193
183
|
});
|
194
|
-
it(
|
184
|
+
it("dispatch to detached", function () {
|
195
185
|
var eventBus = new _ui_utils.EventBus();
|
196
186
|
var count = 0;
|
197
187
|
|
198
|
-
var listener = function
|
188
|
+
var listener = function () {
|
199
189
|
count++;
|
200
190
|
};
|
201
191
|
|
202
|
-
eventBus.on(
|
203
|
-
eventBus.dispatch(
|
204
|
-
eventBus.off(
|
205
|
-
eventBus.dispatch(
|
192
|
+
eventBus.on("test", listener);
|
193
|
+
eventBus.dispatch("test");
|
194
|
+
eventBus.off("test", listener);
|
195
|
+
eventBus.dispatch("test");
|
206
196
|
expect(count).toEqual(1);
|
207
197
|
});
|
208
|
-
it(
|
198
|
+
it("dispatch to wrong detached", function () {
|
209
199
|
var eventBus = new _ui_utils.EventBus();
|
210
200
|
var count = 0;
|
211
|
-
eventBus.on(
|
201
|
+
eventBus.on("test", function () {
|
212
202
|
count++;
|
213
203
|
});
|
214
|
-
eventBus.dispatch(
|
215
|
-
eventBus.off(
|
204
|
+
eventBus.dispatch("test");
|
205
|
+
eventBus.off("test", function () {
|
216
206
|
count++;
|
217
207
|
});
|
218
|
-
eventBus.dispatch(
|
208
|
+
eventBus.dispatch("test");
|
219
209
|
expect(count).toEqual(2);
|
220
210
|
});
|
221
|
-
it(
|
211
|
+
it("dispatch to detached during handling", function () {
|
222
212
|
var eventBus = new _ui_utils.EventBus();
|
223
213
|
var count = 0;
|
224
214
|
|
225
|
-
var listener1 = function
|
226
|
-
eventBus.off(
|
215
|
+
var listener1 = function () {
|
216
|
+
eventBus.off("test", listener2);
|
227
217
|
count++;
|
228
218
|
};
|
229
219
|
|
230
|
-
var listener2 = function
|
231
|
-
eventBus.off(
|
220
|
+
var listener2 = function () {
|
221
|
+
eventBus.off("test", listener1);
|
232
222
|
count++;
|
233
223
|
};
|
234
224
|
|
235
|
-
eventBus.on(
|
236
|
-
eventBus.on(
|
237
|
-
eventBus.dispatch(
|
238
|
-
eventBus.dispatch(
|
225
|
+
eventBus.on("test", listener1);
|
226
|
+
eventBus.on("test", listener2);
|
227
|
+
eventBus.dispatch("test");
|
228
|
+
eventBus.dispatch("test");
|
239
229
|
expect(count).toEqual(2);
|
240
230
|
});
|
241
|
-
it(
|
242
|
-
if (
|
243
|
-
pending(
|
231
|
+
it("should not, by default, re-dispatch to DOM", function (done) {
|
232
|
+
if (_is_node.isNodeJS) {
|
233
|
+
pending("Document in not supported in Node.js.");
|
244
234
|
}
|
245
235
|
|
246
|
-
|
247
|
-
|
248
|
-
eventBus.on(
|
236
|
+
const eventBus = new _ui_utils.EventBus();
|
237
|
+
let count = 0;
|
238
|
+
eventBus.on("test", function (evt) {
|
249
239
|
expect(evt).toEqual(undefined);
|
250
240
|
count++;
|
251
241
|
});
|
252
242
|
|
253
243
|
function domEventListener() {
|
254
|
-
done.fail(
|
244
|
+
done.fail("shall not dispatch DOM event.");
|
255
245
|
}
|
256
246
|
|
257
|
-
document.addEventListener(
|
258
|
-
eventBus.dispatch(
|
259
|
-
Promise.resolve().then(
|
247
|
+
document.addEventListener("test", domEventListener);
|
248
|
+
eventBus.dispatch("test");
|
249
|
+
Promise.resolve().then(() => {
|
260
250
|
expect(count).toEqual(1);
|
261
|
-
document.removeEventListener(
|
251
|
+
document.removeEventListener("test", domEventListener);
|
262
252
|
done();
|
263
253
|
});
|
264
254
|
});
|
265
|
-
it(
|
266
|
-
if (
|
267
|
-
pending(
|
255
|
+
it("should re-dispatch to DOM", function (done) {
|
256
|
+
if (_is_node.isNodeJS) {
|
257
|
+
pending("Document in not supported in Node.js.");
|
268
258
|
}
|
269
259
|
|
270
|
-
|
260
|
+
const eventBus = new _ui_utils.EventBus({
|
271
261
|
dispatchToDOM: true
|
272
262
|
});
|
273
|
-
|
274
|
-
eventBus.on(
|
263
|
+
let count = 0;
|
264
|
+
eventBus.on("test", function (evt) {
|
275
265
|
expect(evt).toEqual(undefined);
|
276
266
|
count++;
|
277
267
|
});
|
@@ -281,23 +271,23 @@ describe('ui_utils', function () {
|
|
281
271
|
count++;
|
282
272
|
}
|
283
273
|
|
284
|
-
document.addEventListener(
|
285
|
-
eventBus.dispatch(
|
286
|
-
Promise.resolve().then(
|
274
|
+
document.addEventListener("test", domEventListener);
|
275
|
+
eventBus.dispatch("test");
|
276
|
+
Promise.resolve().then(() => {
|
287
277
|
expect(count).toEqual(2);
|
288
|
-
document.removeEventListener(
|
278
|
+
document.removeEventListener("test", domEventListener);
|
289
279
|
done();
|
290
280
|
});
|
291
281
|
});
|
292
|
-
it(
|
293
|
-
if (
|
294
|
-
pending(
|
282
|
+
it("should re-dispatch to DOM, with arguments (without internal listeners)", function (done) {
|
283
|
+
if (_is_node.isNodeJS) {
|
284
|
+
pending("Document in not supported in Node.js.");
|
295
285
|
}
|
296
286
|
|
297
|
-
|
287
|
+
const eventBus = new _ui_utils.EventBus({
|
298
288
|
dispatchToDOM: true
|
299
289
|
});
|
300
|
-
|
290
|
+
let count = 0;
|
301
291
|
|
302
292
|
function domEventListener(evt) {
|
303
293
|
expect(evt.detail).toEqual({
|
@@ -306,39 +296,39 @@ describe('ui_utils', function () {
|
|
306
296
|
count++;
|
307
297
|
}
|
308
298
|
|
309
|
-
document.addEventListener(
|
310
|
-
eventBus.dispatch(
|
299
|
+
document.addEventListener("test", domEventListener);
|
300
|
+
eventBus.dispatch("test", {
|
311
301
|
abc: 123
|
312
302
|
});
|
313
|
-
Promise.resolve().then(
|
303
|
+
Promise.resolve().then(() => {
|
314
304
|
expect(count).toEqual(1);
|
315
|
-
document.removeEventListener(
|
305
|
+
document.removeEventListener("test", domEventListener);
|
316
306
|
done();
|
317
307
|
});
|
318
308
|
});
|
319
309
|
});
|
320
|
-
describe(
|
321
|
-
it(
|
310
|
+
describe("isValidRotation", function () {
|
311
|
+
it("should reject non-integer angles", function () {
|
322
312
|
expect((0, _ui_utils.isValidRotation)()).toEqual(false);
|
323
313
|
expect((0, _ui_utils.isValidRotation)(null)).toEqual(false);
|
324
314
|
expect((0, _ui_utils.isValidRotation)(NaN)).toEqual(false);
|
325
315
|
expect((0, _ui_utils.isValidRotation)([90])).toEqual(false);
|
326
|
-
expect((0, _ui_utils.isValidRotation)(
|
316
|
+
expect((0, _ui_utils.isValidRotation)("90")).toEqual(false);
|
327
317
|
expect((0, _ui_utils.isValidRotation)(90.5)).toEqual(false);
|
328
318
|
});
|
329
|
-
it(
|
319
|
+
it("should reject non-multiple of 90 degree angles", function () {
|
330
320
|
expect((0, _ui_utils.isValidRotation)(45)).toEqual(false);
|
331
321
|
expect((0, _ui_utils.isValidRotation)(-123)).toEqual(false);
|
332
322
|
});
|
333
|
-
it(
|
323
|
+
it("should accept valid angles", function () {
|
334
324
|
expect((0, _ui_utils.isValidRotation)(0)).toEqual(true);
|
335
325
|
expect((0, _ui_utils.isValidRotation)(90)).toEqual(true);
|
336
326
|
expect((0, _ui_utils.isValidRotation)(-270)).toEqual(true);
|
337
327
|
expect((0, _ui_utils.isValidRotation)(540)).toEqual(true);
|
338
328
|
});
|
339
329
|
});
|
340
|
-
describe(
|
341
|
-
it(
|
330
|
+
describe("isPortraitOrientation", function () {
|
331
|
+
it("should be portrait orientation", function () {
|
342
332
|
expect((0, _ui_utils.isPortraitOrientation)({
|
343
333
|
width: 200,
|
344
334
|
height: 400
|
@@ -348,15 +338,15 @@ describe('ui_utils', function () {
|
|
348
338
|
height: 500
|
349
339
|
})).toEqual(true);
|
350
340
|
});
|
351
|
-
it(
|
341
|
+
it("should be landscape orientation", function () {
|
352
342
|
expect((0, _ui_utils.isPortraitOrientation)({
|
353
343
|
width: 600,
|
354
344
|
height: 300
|
355
345
|
})).toEqual(false);
|
356
346
|
});
|
357
347
|
});
|
358
|
-
describe(
|
359
|
-
|
348
|
+
describe("waitOnEventOrTimeout", function () {
|
349
|
+
let eventBus;
|
360
350
|
beforeAll(function (done) {
|
361
351
|
eventBus = new _ui_utils.EventBus();
|
362
352
|
done();
|
@@ -364,43 +354,43 @@ describe('ui_utils', function () {
|
|
364
354
|
afterAll(function () {
|
365
355
|
eventBus = null;
|
366
356
|
});
|
367
|
-
it(
|
368
|
-
|
369
|
-
target:
|
370
|
-
name:
|
357
|
+
it("should reject invalid parameters", function (done) {
|
358
|
+
const invalidTarget = (0, _ui_utils.waitOnEventOrTimeout)({
|
359
|
+
target: "window",
|
360
|
+
name: "DOMContentLoaded"
|
371
361
|
}).then(function () {
|
372
|
-
throw new Error(
|
362
|
+
throw new Error("Should reject invalid parameters.");
|
373
363
|
}, function (reason) {
|
374
364
|
expect(reason instanceof Error).toEqual(true);
|
375
365
|
});
|
376
|
-
|
366
|
+
const invalidName = (0, _ui_utils.waitOnEventOrTimeout)({
|
377
367
|
target: eventBus,
|
378
|
-
name:
|
368
|
+
name: ""
|
379
369
|
}).then(function () {
|
380
|
-
throw new Error(
|
370
|
+
throw new Error("Should reject invalid parameters.");
|
381
371
|
}, function (reason) {
|
382
372
|
expect(reason instanceof Error).toEqual(true);
|
383
373
|
});
|
384
|
-
|
374
|
+
const invalidDelay = (0, _ui_utils.waitOnEventOrTimeout)({
|
385
375
|
target: eventBus,
|
386
|
-
name:
|
376
|
+
name: "pagerendered",
|
387
377
|
delay: -1000
|
388
378
|
}).then(function () {
|
389
|
-
throw new Error(
|
379
|
+
throw new Error("Should reject invalid parameters.");
|
390
380
|
}, function (reason) {
|
391
381
|
expect(reason instanceof Error).toEqual(true);
|
392
382
|
});
|
393
383
|
Promise.all([invalidTarget, invalidName, invalidDelay]).then(done, done.fail);
|
394
384
|
});
|
395
|
-
it(
|
396
|
-
if (
|
397
|
-
pending(
|
385
|
+
it("should resolve on event, using the DOM", function (done) {
|
386
|
+
if (_is_node.isNodeJS) {
|
387
|
+
pending("Document in not supported in Node.js.");
|
398
388
|
}
|
399
389
|
|
400
|
-
|
401
|
-
|
390
|
+
const button = document.createElement("button");
|
391
|
+
const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
402
392
|
target: button,
|
403
|
-
name:
|
393
|
+
name: "click",
|
404
394
|
delay: 10000
|
405
395
|
});
|
406
396
|
button.click();
|
@@ -409,15 +399,15 @@ describe('ui_utils', function () {
|
|
409
399
|
done();
|
410
400
|
}, done.fail);
|
411
401
|
});
|
412
|
-
it(
|
413
|
-
if (
|
414
|
-
pending(
|
402
|
+
it("should resolve on timeout, using the DOM", function (done) {
|
403
|
+
if (_is_node.isNodeJS) {
|
404
|
+
pending("Document in not supported in Node.js.");
|
415
405
|
}
|
416
406
|
|
417
|
-
|
418
|
-
|
407
|
+
const button = document.createElement("button");
|
408
|
+
const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
419
409
|
target: button,
|
420
|
-
name:
|
410
|
+
name: "click",
|
421
411
|
delay: 10
|
422
412
|
});
|
423
413
|
buttonClicked.then(function (type) {
|
@@ -425,22 +415,22 @@ describe('ui_utils', function () {
|
|
425
415
|
done();
|
426
416
|
}, done.fail);
|
427
417
|
});
|
428
|
-
it(
|
429
|
-
|
418
|
+
it("should resolve on event, using the EventBus", function (done) {
|
419
|
+
const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
|
430
420
|
target: eventBus,
|
431
|
-
name:
|
421
|
+
name: "pagerendered",
|
432
422
|
delay: 10000
|
433
423
|
});
|
434
|
-
eventBus.dispatch(
|
424
|
+
eventBus.dispatch("pagerendered");
|
435
425
|
pageRendered.then(function (type) {
|
436
426
|
expect(type).toEqual(_ui_utils.WaitOnType.EVENT);
|
437
427
|
done();
|
438
428
|
}, done.fail);
|
439
429
|
});
|
440
|
-
it(
|
441
|
-
|
430
|
+
it("should resolve on timeout, using the EventBus", function (done) {
|
431
|
+
const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
|
442
432
|
target: eventBus,
|
443
|
-
name:
|
433
|
+
name: "pagerendered",
|
444
434
|
delay: 10
|
445
435
|
});
|
446
436
|
pageRendered.then(function (type) {
|
@@ -449,193 +439,134 @@ describe('ui_utils', function () {
|
|
449
439
|
}, done.fail);
|
450
440
|
});
|
451
441
|
});
|
452
|
-
describe(
|
453
|
-
it(
|
454
|
-
|
442
|
+
describe("getPageSizeInches", function () {
|
443
|
+
it("gets page size (in inches)", function () {
|
444
|
+
const page = {
|
455
445
|
view: [0, 0, 595.28, 841.89],
|
456
446
|
userUnit: 1.0,
|
457
447
|
rotate: 0
|
458
448
|
};
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
449
|
+
const {
|
450
|
+
width,
|
451
|
+
height
|
452
|
+
} = (0, _ui_utils.getPageSizeInches)(page);
|
464
453
|
expect(+width.toPrecision(3)).toEqual(8.27);
|
465
454
|
expect(+height.toPrecision(4)).toEqual(11.69);
|
466
455
|
});
|
467
|
-
it(
|
468
|
-
|
456
|
+
it("gets page size (in inches), for non-default /Rotate entry", function () {
|
457
|
+
const pdfPage1 = {
|
469
458
|
view: [0, 0, 612, 792],
|
470
459
|
userUnit: 1,
|
471
460
|
rotate: 0
|
472
461
|
};
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
462
|
+
const {
|
463
|
+
width: width1,
|
464
|
+
height: height1
|
465
|
+
} = (0, _ui_utils.getPageSizeInches)(pdfPage1);
|
478
466
|
expect(width1).toEqual(8.5);
|
479
467
|
expect(height1).toEqual(11);
|
480
|
-
|
468
|
+
const pdfPage2 = {
|
481
469
|
view: [0, 0, 612, 792],
|
482
470
|
userUnit: 1,
|
483
471
|
rotate: 90
|
484
472
|
};
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
473
|
+
const {
|
474
|
+
width: width2,
|
475
|
+
height: height2
|
476
|
+
} = (0, _ui_utils.getPageSizeInches)(pdfPage2);
|
490
477
|
expect(width2).toEqual(11);
|
491
478
|
expect(height2).toEqual(8.5);
|
492
479
|
});
|
493
480
|
});
|
494
|
-
describe(
|
495
|
-
|
496
|
-
|
481
|
+
describe("getVisibleElements", function () {
|
482
|
+
const BORDER_WIDTH = 9;
|
483
|
+
const SPACING = 2 * BORDER_WIDTH - 7;
|
497
484
|
|
498
485
|
function makePages(lines) {
|
499
|
-
|
500
|
-
|
486
|
+
const result = [];
|
487
|
+
let lineTop = 0,
|
501
488
|
id = 0;
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
offsetLeft: offsetLeft,
|
526
|
-
offsetTop: offsetTop,
|
527
|
-
clientWidth: clientWidth,
|
528
|
-
clientHeight: clientHeight,
|
529
|
-
clientLeft: BORDER_WIDTH,
|
530
|
-
clientTop: BORDER_WIDTH
|
531
|
-
};
|
532
|
-
result.push({
|
533
|
-
id: id,
|
534
|
-
div: div
|
535
|
-
});
|
536
|
-
++id;
|
537
|
-
offsetLeft += clientWidth + SPACING;
|
538
|
-
}
|
539
|
-
} catch (err) {
|
540
|
-
_didIteratorError2 = true;
|
541
|
-
_iteratorError2 = err;
|
542
|
-
} finally {
|
543
|
-
try {
|
544
|
-
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
545
|
-
_iterator2["return"]();
|
546
|
-
}
|
547
|
-
} finally {
|
548
|
-
if (_didIteratorError2) {
|
549
|
-
throw _iteratorError2;
|
550
|
-
}
|
551
|
-
}
|
552
|
-
}
|
553
|
-
|
554
|
-
lineTop += lineHeight + SPACING;
|
555
|
-
}
|
556
|
-
} catch (err) {
|
557
|
-
_didIteratorError = true;
|
558
|
-
_iteratorError = err;
|
559
|
-
} finally {
|
560
|
-
try {
|
561
|
-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
562
|
-
_iterator["return"]();
|
563
|
-
}
|
564
|
-
} finally {
|
565
|
-
if (_didIteratorError) {
|
566
|
-
throw _iteratorError;
|
567
|
-
}
|
489
|
+
|
490
|
+
for (const line of lines) {
|
491
|
+
const lineHeight = line.reduce(function (maxHeight, pair) {
|
492
|
+
return Math.max(maxHeight, pair[1]);
|
493
|
+
}, 0);
|
494
|
+
let offsetLeft = -BORDER_WIDTH;
|
495
|
+
|
496
|
+
for (const [clientWidth, clientHeight] of line) {
|
497
|
+
const offsetTop = lineTop + (lineHeight - clientHeight) / 2 - BORDER_WIDTH;
|
498
|
+
const div = {
|
499
|
+
offsetLeft,
|
500
|
+
offsetTop,
|
501
|
+
clientWidth,
|
502
|
+
clientHeight,
|
503
|
+
clientLeft: BORDER_WIDTH,
|
504
|
+
clientTop: BORDER_WIDTH
|
505
|
+
};
|
506
|
+
result.push({
|
507
|
+
id,
|
508
|
+
div
|
509
|
+
});
|
510
|
+
++id;
|
511
|
+
offsetLeft += clientWidth + SPACING;
|
568
512
|
}
|
513
|
+
|
514
|
+
lineTop += lineHeight + SPACING;
|
569
515
|
}
|
570
516
|
|
571
517
|
return result;
|
572
518
|
}
|
573
519
|
|
574
520
|
function slowGetVisibleElements(scroll, pages) {
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
});
|
605
|
-
}
|
606
|
-
}
|
607
|
-
} catch (err) {
|
608
|
-
_didIteratorError3 = true;
|
609
|
-
_iteratorError3 = err;
|
610
|
-
} finally {
|
611
|
-
try {
|
612
|
-
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
613
|
-
_iterator3["return"]();
|
614
|
-
}
|
615
|
-
} finally {
|
616
|
-
if (_didIteratorError3) {
|
617
|
-
throw _iteratorError3;
|
618
|
-
}
|
521
|
+
const views = [];
|
522
|
+
const {
|
523
|
+
scrollLeft,
|
524
|
+
scrollTop
|
525
|
+
} = scroll;
|
526
|
+
const scrollRight = scrollLeft + scroll.clientWidth;
|
527
|
+
const scrollBottom = scrollTop + scroll.clientHeight;
|
528
|
+
|
529
|
+
for (const view of pages) {
|
530
|
+
const {
|
531
|
+
div
|
532
|
+
} = view;
|
533
|
+
const viewLeft = div.offsetLeft + div.clientLeft;
|
534
|
+
const viewRight = viewLeft + div.clientWidth;
|
535
|
+
const viewTop = div.offsetTop + div.clientTop;
|
536
|
+
const viewBottom = viewTop + div.clientHeight;
|
537
|
+
|
538
|
+
if (viewLeft < scrollRight && viewRight > scrollLeft && viewTop < scrollBottom && viewBottom > scrollTop) {
|
539
|
+
const hiddenHeight = Math.max(0, scrollTop - viewTop) + Math.max(0, viewBottom - scrollBottom);
|
540
|
+
const hiddenWidth = Math.max(0, scrollLeft - viewLeft) + Math.max(0, viewRight - scrollRight);
|
541
|
+
const visibleArea = (div.clientHeight - hiddenHeight) * (div.clientWidth - hiddenWidth);
|
542
|
+
const percent = visibleArea * 100 / div.clientHeight / div.clientWidth | 0;
|
543
|
+
views.push({
|
544
|
+
id: view.id,
|
545
|
+
x: viewLeft,
|
546
|
+
y: viewTop,
|
547
|
+
view,
|
548
|
+
percent
|
549
|
+
});
|
619
550
|
}
|
620
551
|
}
|
621
552
|
|
622
553
|
return {
|
623
554
|
first: views[0],
|
624
555
|
last: views[views.length - 1],
|
625
|
-
views
|
556
|
+
views
|
626
557
|
};
|
627
558
|
}
|
628
559
|
|
629
|
-
function scrollOverDocument(pages) {
|
630
|
-
|
631
|
-
|
632
|
-
|
560
|
+
function scrollOverDocument(pages, horizontally = false) {
|
561
|
+
const size = pages.reduce(function (max, {
|
562
|
+
div
|
563
|
+
}) {
|
633
564
|
return Math.max(max, horizontally ? div.offsetLeft + div.clientLeft + div.clientWidth : div.offsetTop + div.clientTop + div.clientHeight);
|
634
565
|
}, 0);
|
635
566
|
|
636
|
-
for (
|
637
|
-
for (
|
638
|
-
|
567
|
+
for (let i = 0; i < size; i += 7) {
|
568
|
+
for (let j = i + 5; j < size; j += j - i) {
|
569
|
+
const scroll = horizontally ? {
|
639
570
|
scrollTop: 0,
|
640
571
|
scrollLeft: i,
|
641
572
|
clientHeight: 10000,
|
@@ -651,165 +582,126 @@ describe('ui_utils', function () {
|
|
651
582
|
}
|
652
583
|
}
|
653
584
|
|
654
|
-
it(
|
655
|
-
|
585
|
+
it("with pages of varying height", function () {
|
586
|
+
const pages = makePages([[[50, 20], [20, 50]], [[30, 12], [12, 30]], [[20, 50], [50, 20]], [[50, 20], [20, 50]]]);
|
656
587
|
scrollOverDocument(pages);
|
657
588
|
});
|
658
|
-
it(
|
659
|
-
|
589
|
+
it("widescreen challenge", function () {
|
590
|
+
const pages = makePages([[[10, 50], [10, 60], [10, 70], [10, 80], [10, 90]], [[10, 90], [10, 80], [10, 70], [10, 60], [10, 50]], [[10, 50], [10, 60], [10, 70], [10, 80], [10, 90]]]);
|
660
591
|
scrollOverDocument(pages);
|
661
592
|
});
|
662
|
-
it(
|
663
|
-
|
593
|
+
it("works with horizontal scrolling", function () {
|
594
|
+
const pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
|
664
595
|
scrollOverDocument(pages, true);
|
665
596
|
});
|
666
|
-
it(
|
667
|
-
|
597
|
+
it("handles `sortByVisibility` correctly", function () {
|
598
|
+
const scrollEl = {
|
668
599
|
scrollTop: 75,
|
669
600
|
scrollLeft: 0,
|
670
601
|
clientHeight: 750,
|
671
602
|
clientWidth: 1500
|
672
603
|
};
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
try {
|
683
|
-
for (var _iterator4 = visible.views[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
684
|
-
var view = _step4.value;
|
685
|
-
viewsOrder.push(view.id);
|
686
|
-
}
|
687
|
-
} catch (err) {
|
688
|
-
_didIteratorError4 = true;
|
689
|
-
_iteratorError4 = err;
|
690
|
-
} finally {
|
691
|
-
try {
|
692
|
-
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
|
693
|
-
_iterator4["return"]();
|
694
|
-
}
|
695
|
-
} finally {
|
696
|
-
if (_didIteratorError4) {
|
697
|
-
throw _iteratorError4;
|
698
|
-
}
|
699
|
-
}
|
604
|
+
const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
|
605
|
+
const visible = (0, _ui_utils.getVisibleElements)(scrollEl, views);
|
606
|
+
const visibleSorted = (0, _ui_utils.getVisibleElements)(scrollEl, views, true);
|
607
|
+
const viewsOrder = [],
|
608
|
+
viewsSortedOrder = [];
|
609
|
+
|
610
|
+
for (const view of visible.views) {
|
611
|
+
viewsOrder.push(view.id);
|
700
612
|
}
|
701
613
|
|
702
|
-
|
703
|
-
|
704
|
-
var _iteratorError5 = undefined;
|
705
|
-
|
706
|
-
try {
|
707
|
-
for (var _iterator5 = visibleSorted.views[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
708
|
-
var _view = _step5.value;
|
709
|
-
viewsSortedOrder.push(_view.id);
|
710
|
-
}
|
711
|
-
} catch (err) {
|
712
|
-
_didIteratorError5 = true;
|
713
|
-
_iteratorError5 = err;
|
714
|
-
} finally {
|
715
|
-
try {
|
716
|
-
if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) {
|
717
|
-
_iterator5["return"]();
|
718
|
-
}
|
719
|
-
} finally {
|
720
|
-
if (_didIteratorError5) {
|
721
|
-
throw _iteratorError5;
|
722
|
-
}
|
723
|
-
}
|
614
|
+
for (const view of visibleSorted.views) {
|
615
|
+
viewsSortedOrder.push(view.id);
|
724
616
|
}
|
725
617
|
|
726
618
|
expect(viewsOrder).toEqual([0, 1, 2]);
|
727
619
|
expect(viewsSortedOrder).toEqual([1, 2, 0]);
|
728
620
|
});
|
729
|
-
it(
|
730
|
-
|
621
|
+
it("handles views being empty", function () {
|
622
|
+
const scrollEl = {
|
731
623
|
scrollTop: 10,
|
732
624
|
scrollLeft: 0,
|
733
625
|
clientHeight: 750,
|
734
626
|
clientWidth: 1500
|
735
627
|
};
|
736
|
-
|
628
|
+
const views = [];
|
737
629
|
expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
|
738
630
|
first: undefined,
|
739
631
|
last: undefined,
|
740
632
|
views: []
|
741
633
|
});
|
742
634
|
});
|
743
|
-
it(
|
744
|
-
|
635
|
+
it("handles all views being hidden (without errors)", function () {
|
636
|
+
const scrollEl = {
|
745
637
|
scrollTop: 100000,
|
746
638
|
scrollLeft: 0,
|
747
639
|
clientHeight: 750,
|
748
640
|
clientWidth: 1500
|
749
641
|
};
|
750
|
-
|
642
|
+
const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
|
751
643
|
expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
|
752
644
|
first: undefined,
|
753
645
|
last: undefined,
|
754
646
|
views: []
|
755
647
|
});
|
756
648
|
});
|
757
|
-
describe(
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
it(
|
763
|
-
|
764
|
-
|
649
|
+
describe("backtrackBeforeAllVisibleElements", function () {
|
650
|
+
const tallPage = [10, 50];
|
651
|
+
const shortPage = [10, 10];
|
652
|
+
const top1 = 20 + SPACING + 40;
|
653
|
+
const top2 = 20 + SPACING + 10;
|
654
|
+
it("handles case 1", function () {
|
655
|
+
const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]], [[10, 20]]]);
|
656
|
+
const bsResult = 4;
|
765
657
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
766
658
|
});
|
767
|
-
it(
|
768
|
-
|
769
|
-
|
659
|
+
it("handles case 2", function () {
|
660
|
+
const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, tallPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
|
661
|
+
const bsResult = 6;
|
770
662
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
771
663
|
});
|
772
|
-
it(
|
773
|
-
|
774
|
-
|
664
|
+
it("handles case 3", function () {
|
665
|
+
const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
|
666
|
+
const bsResult = 8;
|
775
667
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
776
668
|
});
|
777
|
-
it(
|
778
|
-
|
779
|
-
|
669
|
+
it("handles case 4", function () {
|
670
|
+
const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
|
671
|
+
const bsResult = 4;
|
780
672
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top2)).toEqual(4);
|
781
673
|
});
|
782
674
|
});
|
783
675
|
});
|
784
|
-
describe(
|
785
|
-
it(
|
786
|
-
|
676
|
+
describe("moveToEndOfArray", function () {
|
677
|
+
it("works on empty arrays", function () {
|
678
|
+
const data = [];
|
787
679
|
(0, _ui_utils.moveToEndOfArray)(data, function () {});
|
788
680
|
expect(data).toEqual([]);
|
789
681
|
});
|
790
|
-
it(
|
791
|
-
|
682
|
+
it("works when moving everything", function () {
|
683
|
+
const data = [1, 2, 3, 4, 5];
|
792
684
|
(0, _ui_utils.moveToEndOfArray)(data, function () {
|
793
685
|
return true;
|
794
686
|
});
|
795
687
|
expect(data).toEqual([1, 2, 3, 4, 5]);
|
796
688
|
});
|
797
|
-
it(
|
798
|
-
|
689
|
+
it("works when moving some things", function () {
|
690
|
+
const data = [1, 2, 3, 4, 5];
|
799
691
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
800
692
|
return x % 2 === 0;
|
801
693
|
});
|
802
694
|
expect(data).toEqual([1, 3, 5, 2, 4]);
|
803
695
|
});
|
804
|
-
it(
|
805
|
-
|
696
|
+
it("works when moving one thing", function () {
|
697
|
+
const data = [1, 2, 3, 4, 5];
|
806
698
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
807
699
|
return x === 1;
|
808
700
|
});
|
809
701
|
expect(data).toEqual([2, 3, 4, 5, 1]);
|
810
702
|
});
|
811
|
-
it(
|
812
|
-
|
703
|
+
it("works when moving nothing", function () {
|
704
|
+
const data = [1, 2, 3, 4, 5];
|
813
705
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
814
706
|
return x === 0;
|
815
707
|
});
|