pdfjs-dist 2.1.266 → 2.5.207
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/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8382 -18492
- 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 +20417 -29816
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25688 -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 +58239 -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 +403 -0
- package/es5/web/pdf_viewer.js +7742 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1475 -4897
- 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 +750 -899
- 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 +235 -183
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +447 -542
- package/lib/core/cmap.js +222 -264
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +573 -660
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +1103 -868
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +570 -491
- package/lib/core/function.js +291 -288
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +145 -149
- package/lib/core/image_utils.js +170 -0
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +284 -232
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2929 -2929
- package/lib/core/murmurhash3.js +90 -101
- package/lib/core/obj.js +1183 -1157
- package/lib/core/operator_list.js +99 -67
- package/lib/core/parser.js +972 -911
- package/lib/core/pattern.js +87 -70
- package/lib/core/pdf_manager.js +150 -315
- package/lib/core/primitives.js +83 -56
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +87 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +193 -390
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +741 -972
- package/lib/display/api.js +1500 -1791
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +165 -165
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +515 -0
- package/lib/display/fetch_stream.js +183 -298
- package/lib/display/font_loader.js +273 -413
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +266 -359
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +285 -458
- package/lib/display/pattern_helper.js +113 -65
- package/lib/display/svg.js +1166 -901
- package/lib/display/text_layer.js +156 -132
- package/lib/display/transport_stream.js +262 -278
- 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 +40 -37
- package/lib/pdf.js +226 -59
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +266 -416
- package/lib/test/unit/annotation_spec.js +1555 -701
- package/lib/test/unit/api_spec.js +802 -604
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +84 -69
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +74 -76
- package/lib/test/unit/colorspace_spec.js +166 -161
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +20 -22
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +16 -21
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +83 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +46 -30
- package/lib/test/unit/message_handler_spec.js +173 -159
- 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 +13 -61
- package/lib/test/unit/network_utils_spec.js +183 -119
- package/lib/test/unit/node_stream_spec.js +78 -92
- package/lib/test/unit/parser_spec.js +172 -114
- 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 +140 -125
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +131 -143
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +297 -459
- package/lib/test/unit/unicode_spec.js +38 -38
- package/lib/test/unit/util_spec.js +121 -305
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1328 -1214
- package/lib/web/app_options.js +105 -107
- package/lib/web/base_viewer.js +824 -838
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +39 -55
- package/lib/web/firefox_print_service.js +37 -27
- package/lib/web/firefoxcom.js +212 -363
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +32 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +113 -131
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +221 -306
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +491 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +140 -175
- package/lib/web/pdf_page_view.js +452 -523
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +84 -108
- package/lib/web/pdf_sidebar.js +276 -306
- 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 +82 -286
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +282 -339
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +267 -420
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +35 -25
- package/web/pdf_viewer.js +3489 -4855
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -494
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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,24 +21,14 @@
|
|
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
33
|
-
|
34
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
35
|
-
|
36
|
-
function _iterableToArrayLimit(arr, i) { 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 () {
|
30
|
+
describe("ui_utils", function () {
|
31
|
+
describe("binary search", function () {
|
42
32
|
function isTrue(boolean) {
|
43
33
|
return boolean;
|
44
34
|
}
|
@@ -47,298 +37,244 @@ describe('ui_utils', function () {
|
|
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 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(
|
262
|
-
done();
|
263
|
-
});
|
264
|
-
});
|
265
|
-
it('should re-dispatch to DOM', function (done) {
|
266
|
-
if ((0, _is_node.default)()) {
|
267
|
-
pending('Document in not supported in Node.js.');
|
268
|
-
}
|
269
|
-
|
270
|
-
var eventBus = new _ui_utils.EventBus({
|
271
|
-
dispatchToDOM: true
|
272
|
-
});
|
273
|
-
var count = 0;
|
274
|
-
eventBus.on('test', function (evt) {
|
275
|
-
expect(evt).toEqual(undefined);
|
276
|
-
count++;
|
277
|
-
});
|
278
|
-
|
279
|
-
function domEventListener(evt) {
|
280
|
-
expect(evt.detail).toEqual({});
|
281
|
-
count++;
|
282
|
-
}
|
283
|
-
|
284
|
-
document.addEventListener('test', domEventListener);
|
285
|
-
eventBus.dispatch('test');
|
286
|
-
Promise.resolve().then(function () {
|
287
|
-
expect(count).toEqual(2);
|
288
|
-
document.removeEventListener('test', domEventListener);
|
289
|
-
done();
|
290
|
-
});
|
291
|
-
});
|
292
|
-
it('should re-dispatch to DOM, with arguments (without internal listeners)', function (done) {
|
293
|
-
if ((0, _is_node.default)()) {
|
294
|
-
pending('Document in not supported in Node.js.');
|
295
|
-
}
|
296
|
-
|
297
|
-
var eventBus = new _ui_utils.EventBus({
|
298
|
-
dispatchToDOM: true
|
299
|
-
});
|
300
|
-
var count = 0;
|
301
|
-
|
302
|
-
function domEventListener(evt) {
|
303
|
-
expect(evt.detail).toEqual({
|
304
|
-
abc: 123
|
305
|
-
});
|
306
|
-
count++;
|
307
|
-
}
|
308
|
-
|
309
|
-
document.addEventListener('test', domEventListener);
|
310
|
-
eventBus.dispatch('test', {
|
311
|
-
abc: 123
|
312
|
-
});
|
313
|
-
Promise.resolve().then(function () {
|
314
|
-
expect(count).toEqual(1);
|
315
|
-
document.removeEventListener('test', domEventListener);
|
251
|
+
document.removeEventListener("test", domEventListener);
|
316
252
|
done();
|
317
253
|
});
|
318
254
|
});
|
319
255
|
});
|
320
|
-
describe(
|
321
|
-
it(
|
256
|
+
describe("isValidRotation", function () {
|
257
|
+
it("should reject non-integer angles", function () {
|
322
258
|
expect((0, _ui_utils.isValidRotation)()).toEqual(false);
|
323
259
|
expect((0, _ui_utils.isValidRotation)(null)).toEqual(false);
|
324
260
|
expect((0, _ui_utils.isValidRotation)(NaN)).toEqual(false);
|
325
261
|
expect((0, _ui_utils.isValidRotation)([90])).toEqual(false);
|
326
|
-
expect((0, _ui_utils.isValidRotation)(
|
262
|
+
expect((0, _ui_utils.isValidRotation)("90")).toEqual(false);
|
327
263
|
expect((0, _ui_utils.isValidRotation)(90.5)).toEqual(false);
|
328
264
|
});
|
329
|
-
it(
|
265
|
+
it("should reject non-multiple of 90 degree angles", function () {
|
330
266
|
expect((0, _ui_utils.isValidRotation)(45)).toEqual(false);
|
331
267
|
expect((0, _ui_utils.isValidRotation)(-123)).toEqual(false);
|
332
268
|
});
|
333
|
-
it(
|
269
|
+
it("should accept valid angles", function () {
|
334
270
|
expect((0, _ui_utils.isValidRotation)(0)).toEqual(true);
|
335
271
|
expect((0, _ui_utils.isValidRotation)(90)).toEqual(true);
|
336
272
|
expect((0, _ui_utils.isValidRotation)(-270)).toEqual(true);
|
337
273
|
expect((0, _ui_utils.isValidRotation)(540)).toEqual(true);
|
338
274
|
});
|
339
275
|
});
|
340
|
-
describe(
|
341
|
-
it(
|
276
|
+
describe("isPortraitOrientation", function () {
|
277
|
+
it("should be portrait orientation", function () {
|
342
278
|
expect((0, _ui_utils.isPortraitOrientation)({
|
343
279
|
width: 200,
|
344
280
|
height: 400
|
@@ -348,15 +284,15 @@ describe('ui_utils', function () {
|
|
348
284
|
height: 500
|
349
285
|
})).toEqual(true);
|
350
286
|
});
|
351
|
-
it(
|
287
|
+
it("should be landscape orientation", function () {
|
352
288
|
expect((0, _ui_utils.isPortraitOrientation)({
|
353
289
|
width: 600,
|
354
290
|
height: 300
|
355
291
|
})).toEqual(false);
|
356
292
|
});
|
357
293
|
});
|
358
|
-
describe(
|
359
|
-
|
294
|
+
describe("waitOnEventOrTimeout", function () {
|
295
|
+
let eventBus;
|
360
296
|
beforeAll(function (done) {
|
361
297
|
eventBus = new _ui_utils.EventBus();
|
362
298
|
done();
|
@@ -364,43 +300,43 @@ describe('ui_utils', function () {
|
|
364
300
|
afterAll(function () {
|
365
301
|
eventBus = null;
|
366
302
|
});
|
367
|
-
it(
|
368
|
-
|
369
|
-
target:
|
370
|
-
name:
|
303
|
+
it("should reject invalid parameters", function (done) {
|
304
|
+
const invalidTarget = (0, _ui_utils.waitOnEventOrTimeout)({
|
305
|
+
target: "window",
|
306
|
+
name: "DOMContentLoaded"
|
371
307
|
}).then(function () {
|
372
|
-
throw new Error(
|
308
|
+
throw new Error("Should reject invalid parameters.");
|
373
309
|
}, function (reason) {
|
374
310
|
expect(reason instanceof Error).toEqual(true);
|
375
311
|
});
|
376
|
-
|
312
|
+
const invalidName = (0, _ui_utils.waitOnEventOrTimeout)({
|
377
313
|
target: eventBus,
|
378
|
-
name:
|
314
|
+
name: ""
|
379
315
|
}).then(function () {
|
380
|
-
throw new Error(
|
316
|
+
throw new Error("Should reject invalid parameters.");
|
381
317
|
}, function (reason) {
|
382
318
|
expect(reason instanceof Error).toEqual(true);
|
383
319
|
});
|
384
|
-
|
320
|
+
const invalidDelay = (0, _ui_utils.waitOnEventOrTimeout)({
|
385
321
|
target: eventBus,
|
386
|
-
name:
|
322
|
+
name: "pagerendered",
|
387
323
|
delay: -1000
|
388
324
|
}).then(function () {
|
389
|
-
throw new Error(
|
325
|
+
throw new Error("Should reject invalid parameters.");
|
390
326
|
}, function (reason) {
|
391
327
|
expect(reason instanceof Error).toEqual(true);
|
392
328
|
});
|
393
329
|
Promise.all([invalidTarget, invalidName, invalidDelay]).then(done, done.fail);
|
394
330
|
});
|
395
|
-
it(
|
396
|
-
if (
|
397
|
-
pending(
|
331
|
+
it("should resolve on event, using the DOM", function (done) {
|
332
|
+
if (_is_node.isNodeJS) {
|
333
|
+
pending("Document in not supported in Node.js.");
|
398
334
|
}
|
399
335
|
|
400
|
-
|
401
|
-
|
336
|
+
const button = document.createElement("button");
|
337
|
+
const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
402
338
|
target: button,
|
403
|
-
name:
|
339
|
+
name: "click",
|
404
340
|
delay: 10000
|
405
341
|
});
|
406
342
|
button.click();
|
@@ -409,15 +345,15 @@ describe('ui_utils', function () {
|
|
409
345
|
done();
|
410
346
|
}, done.fail);
|
411
347
|
});
|
412
|
-
it(
|
413
|
-
if (
|
414
|
-
pending(
|
348
|
+
it("should resolve on timeout, using the DOM", function (done) {
|
349
|
+
if (_is_node.isNodeJS) {
|
350
|
+
pending("Document in not supported in Node.js.");
|
415
351
|
}
|
416
352
|
|
417
|
-
|
418
|
-
|
353
|
+
const button = document.createElement("button");
|
354
|
+
const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
419
355
|
target: button,
|
420
|
-
name:
|
356
|
+
name: "click",
|
421
357
|
delay: 10
|
422
358
|
});
|
423
359
|
buttonClicked.then(function (type) {
|
@@ -425,22 +361,22 @@ describe('ui_utils', function () {
|
|
425
361
|
done();
|
426
362
|
}, done.fail);
|
427
363
|
});
|
428
|
-
it(
|
429
|
-
|
364
|
+
it("should resolve on event, using the EventBus", function (done) {
|
365
|
+
const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
|
430
366
|
target: eventBus,
|
431
|
-
name:
|
367
|
+
name: "pagerendered",
|
432
368
|
delay: 10000
|
433
369
|
});
|
434
|
-
eventBus.dispatch(
|
370
|
+
eventBus.dispatch("pagerendered");
|
435
371
|
pageRendered.then(function (type) {
|
436
372
|
expect(type).toEqual(_ui_utils.WaitOnType.EVENT);
|
437
373
|
done();
|
438
374
|
}, done.fail);
|
439
375
|
});
|
440
|
-
it(
|
441
|
-
|
376
|
+
it("should resolve on timeout, using the EventBus", function (done) {
|
377
|
+
const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
|
442
378
|
target: eventBus,
|
443
|
-
name:
|
379
|
+
name: "pagerendered",
|
444
380
|
delay: 10
|
445
381
|
});
|
446
382
|
pageRendered.then(function (type) {
|
@@ -449,193 +385,134 @@ describe('ui_utils', function () {
|
|
449
385
|
}, done.fail);
|
450
386
|
});
|
451
387
|
});
|
452
|
-
describe(
|
453
|
-
it(
|
454
|
-
|
388
|
+
describe("getPageSizeInches", function () {
|
389
|
+
it("gets page size (in inches)", function () {
|
390
|
+
const page = {
|
455
391
|
view: [0, 0, 595.28, 841.89],
|
456
392
|
userUnit: 1.0,
|
457
393
|
rotate: 0
|
458
394
|
};
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
395
|
+
const {
|
396
|
+
width,
|
397
|
+
height
|
398
|
+
} = (0, _ui_utils.getPageSizeInches)(page);
|
464
399
|
expect(+width.toPrecision(3)).toEqual(8.27);
|
465
400
|
expect(+height.toPrecision(4)).toEqual(11.69);
|
466
401
|
});
|
467
|
-
it(
|
468
|
-
|
402
|
+
it("gets page size (in inches), for non-default /Rotate entry", function () {
|
403
|
+
const pdfPage1 = {
|
469
404
|
view: [0, 0, 612, 792],
|
470
405
|
userUnit: 1,
|
471
406
|
rotate: 0
|
472
407
|
};
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
408
|
+
const {
|
409
|
+
width: width1,
|
410
|
+
height: height1
|
411
|
+
} = (0, _ui_utils.getPageSizeInches)(pdfPage1);
|
478
412
|
expect(width1).toEqual(8.5);
|
479
413
|
expect(height1).toEqual(11);
|
480
|
-
|
414
|
+
const pdfPage2 = {
|
481
415
|
view: [0, 0, 612, 792],
|
482
416
|
userUnit: 1,
|
483
417
|
rotate: 90
|
484
418
|
};
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
419
|
+
const {
|
420
|
+
width: width2,
|
421
|
+
height: height2
|
422
|
+
} = (0, _ui_utils.getPageSizeInches)(pdfPage2);
|
490
423
|
expect(width2).toEqual(11);
|
491
424
|
expect(height2).toEqual(8.5);
|
492
425
|
});
|
493
426
|
});
|
494
|
-
describe(
|
495
|
-
|
496
|
-
|
427
|
+
describe("getVisibleElements", function () {
|
428
|
+
const BORDER_WIDTH = 9;
|
429
|
+
const SPACING = 2 * BORDER_WIDTH - 7;
|
497
430
|
|
498
431
|
function makePages(lines) {
|
499
|
-
|
500
|
-
|
432
|
+
const result = [];
|
433
|
+
let lineTop = 0,
|
501
434
|
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
|
-
}
|
435
|
+
|
436
|
+
for (const line of lines) {
|
437
|
+
const lineHeight = line.reduce(function (maxHeight, pair) {
|
438
|
+
return Math.max(maxHeight, pair[1]);
|
439
|
+
}, 0);
|
440
|
+
let offsetLeft = -BORDER_WIDTH;
|
441
|
+
|
442
|
+
for (const [clientWidth, clientHeight] of line) {
|
443
|
+
const offsetTop = lineTop + (lineHeight - clientHeight) / 2 - BORDER_WIDTH;
|
444
|
+
const div = {
|
445
|
+
offsetLeft,
|
446
|
+
offsetTop,
|
447
|
+
clientWidth,
|
448
|
+
clientHeight,
|
449
|
+
clientLeft: BORDER_WIDTH,
|
450
|
+
clientTop: BORDER_WIDTH
|
451
|
+
};
|
452
|
+
result.push({
|
453
|
+
id,
|
454
|
+
div
|
455
|
+
});
|
456
|
+
++id;
|
457
|
+
offsetLeft += clientWidth + SPACING;
|
568
458
|
}
|
459
|
+
|
460
|
+
lineTop += lineHeight + SPACING;
|
569
461
|
}
|
570
462
|
|
571
463
|
return result;
|
572
464
|
}
|
573
465
|
|
574
466
|
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
|
-
}
|
467
|
+
const views = [];
|
468
|
+
const {
|
469
|
+
scrollLeft,
|
470
|
+
scrollTop
|
471
|
+
} = scroll;
|
472
|
+
const scrollRight = scrollLeft + scroll.clientWidth;
|
473
|
+
const scrollBottom = scrollTop + scroll.clientHeight;
|
474
|
+
|
475
|
+
for (const view of pages) {
|
476
|
+
const {
|
477
|
+
div
|
478
|
+
} = view;
|
479
|
+
const viewLeft = div.offsetLeft + div.clientLeft;
|
480
|
+
const viewRight = viewLeft + div.clientWidth;
|
481
|
+
const viewTop = div.offsetTop + div.clientTop;
|
482
|
+
const viewBottom = viewTop + div.clientHeight;
|
483
|
+
|
484
|
+
if (viewLeft < scrollRight && viewRight > scrollLeft && viewTop < scrollBottom && viewBottom > scrollTop) {
|
485
|
+
const hiddenHeight = Math.max(0, scrollTop - viewTop) + Math.max(0, viewBottom - scrollBottom);
|
486
|
+
const hiddenWidth = Math.max(0, scrollLeft - viewLeft) + Math.max(0, viewRight - scrollRight);
|
487
|
+
const visibleArea = (div.clientHeight - hiddenHeight) * (div.clientWidth - hiddenWidth);
|
488
|
+
const percent = visibleArea * 100 / div.clientHeight / div.clientWidth | 0;
|
489
|
+
views.push({
|
490
|
+
id: view.id,
|
491
|
+
x: viewLeft,
|
492
|
+
y: viewTop,
|
493
|
+
view,
|
494
|
+
percent
|
495
|
+
});
|
619
496
|
}
|
620
497
|
}
|
621
498
|
|
622
499
|
return {
|
623
500
|
first: views[0],
|
624
501
|
last: views[views.length - 1],
|
625
|
-
views
|
502
|
+
views
|
626
503
|
};
|
627
504
|
}
|
628
505
|
|
629
|
-
function scrollOverDocument(pages) {
|
630
|
-
|
631
|
-
|
632
|
-
|
506
|
+
function scrollOverDocument(pages, horizontally = false) {
|
507
|
+
const size = pages.reduce(function (max, {
|
508
|
+
div
|
509
|
+
}) {
|
633
510
|
return Math.max(max, horizontally ? div.offsetLeft + div.clientLeft + div.clientWidth : div.offsetTop + div.clientTop + div.clientHeight);
|
634
511
|
}, 0);
|
635
512
|
|
636
|
-
for (
|
637
|
-
for (
|
638
|
-
|
513
|
+
for (let i = 0; i < size; i += 7) {
|
514
|
+
for (let j = i + 5; j < size; j += j - i) {
|
515
|
+
const scroll = horizontally ? {
|
639
516
|
scrollTop: 0,
|
640
517
|
scrollLeft: i,
|
641
518
|
clientHeight: 10000,
|
@@ -651,165 +528,126 @@ describe('ui_utils', function () {
|
|
651
528
|
}
|
652
529
|
}
|
653
530
|
|
654
|
-
it(
|
655
|
-
|
531
|
+
it("with pages of varying height", function () {
|
532
|
+
const pages = makePages([[[50, 20], [20, 50]], [[30, 12], [12, 30]], [[20, 50], [50, 20]], [[50, 20], [20, 50]]]);
|
656
533
|
scrollOverDocument(pages);
|
657
534
|
});
|
658
|
-
it(
|
659
|
-
|
535
|
+
it("widescreen challenge", function () {
|
536
|
+
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
537
|
scrollOverDocument(pages);
|
661
538
|
});
|
662
|
-
it(
|
663
|
-
|
539
|
+
it("works with horizontal scrolling", function () {
|
540
|
+
const pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
|
664
541
|
scrollOverDocument(pages, true);
|
665
542
|
});
|
666
|
-
it(
|
667
|
-
|
543
|
+
it("handles `sortByVisibility` correctly", function () {
|
544
|
+
const scrollEl = {
|
668
545
|
scrollTop: 75,
|
669
546
|
scrollLeft: 0,
|
670
547
|
clientHeight: 750,
|
671
548
|
clientWidth: 1500
|
672
549
|
};
|
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
|
-
}
|
550
|
+
const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
|
551
|
+
const visible = (0, _ui_utils.getVisibleElements)(scrollEl, views);
|
552
|
+
const visibleSorted = (0, _ui_utils.getVisibleElements)(scrollEl, views, true);
|
553
|
+
const viewsOrder = [],
|
554
|
+
viewsSortedOrder = [];
|
555
|
+
|
556
|
+
for (const view of visible.views) {
|
557
|
+
viewsOrder.push(view.id);
|
700
558
|
}
|
701
559
|
|
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
|
-
}
|
560
|
+
for (const view of visibleSorted.views) {
|
561
|
+
viewsSortedOrder.push(view.id);
|
724
562
|
}
|
725
563
|
|
726
564
|
expect(viewsOrder).toEqual([0, 1, 2]);
|
727
565
|
expect(viewsSortedOrder).toEqual([1, 2, 0]);
|
728
566
|
});
|
729
|
-
it(
|
730
|
-
|
567
|
+
it("handles views being empty", function () {
|
568
|
+
const scrollEl = {
|
731
569
|
scrollTop: 10,
|
732
570
|
scrollLeft: 0,
|
733
571
|
clientHeight: 750,
|
734
572
|
clientWidth: 1500
|
735
573
|
};
|
736
|
-
|
574
|
+
const views = [];
|
737
575
|
expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
|
738
576
|
first: undefined,
|
739
577
|
last: undefined,
|
740
578
|
views: []
|
741
579
|
});
|
742
580
|
});
|
743
|
-
it(
|
744
|
-
|
581
|
+
it("handles all views being hidden (without errors)", function () {
|
582
|
+
const scrollEl = {
|
745
583
|
scrollTop: 100000,
|
746
584
|
scrollLeft: 0,
|
747
585
|
clientHeight: 750,
|
748
586
|
clientWidth: 1500
|
749
587
|
};
|
750
|
-
|
588
|
+
const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
|
751
589
|
expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
|
752
590
|
first: undefined,
|
753
591
|
last: undefined,
|
754
592
|
views: []
|
755
593
|
});
|
756
594
|
});
|
757
|
-
describe(
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
it(
|
763
|
-
|
764
|
-
|
595
|
+
describe("backtrackBeforeAllVisibleElements", function () {
|
596
|
+
const tallPage = [10, 50];
|
597
|
+
const shortPage = [10, 10];
|
598
|
+
const top1 = 20 + SPACING + 40;
|
599
|
+
const top2 = 20 + SPACING + 10;
|
600
|
+
it("handles case 1", function () {
|
601
|
+
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]]]);
|
602
|
+
const bsResult = 4;
|
765
603
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
766
604
|
});
|
767
|
-
it(
|
768
|
-
|
769
|
-
|
605
|
+
it("handles case 2", function () {
|
606
|
+
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]]]);
|
607
|
+
const bsResult = 6;
|
770
608
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
771
609
|
});
|
772
|
-
it(
|
773
|
-
|
774
|
-
|
610
|
+
it("handles case 3", function () {
|
611
|
+
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]]]);
|
612
|
+
const bsResult = 8;
|
775
613
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
776
614
|
});
|
777
|
-
it(
|
778
|
-
|
779
|
-
|
615
|
+
it("handles case 4", function () {
|
616
|
+
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]]]);
|
617
|
+
const bsResult = 4;
|
780
618
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top2)).toEqual(4);
|
781
619
|
});
|
782
620
|
});
|
783
621
|
});
|
784
|
-
describe(
|
785
|
-
it(
|
786
|
-
|
622
|
+
describe("moveToEndOfArray", function () {
|
623
|
+
it("works on empty arrays", function () {
|
624
|
+
const data = [];
|
787
625
|
(0, _ui_utils.moveToEndOfArray)(data, function () {});
|
788
626
|
expect(data).toEqual([]);
|
789
627
|
});
|
790
|
-
it(
|
791
|
-
|
628
|
+
it("works when moving everything", function () {
|
629
|
+
const data = [1, 2, 3, 4, 5];
|
792
630
|
(0, _ui_utils.moveToEndOfArray)(data, function () {
|
793
631
|
return true;
|
794
632
|
});
|
795
633
|
expect(data).toEqual([1, 2, 3, 4, 5]);
|
796
634
|
});
|
797
|
-
it(
|
798
|
-
|
635
|
+
it("works when moving some things", function () {
|
636
|
+
const data = [1, 2, 3, 4, 5];
|
799
637
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
800
638
|
return x % 2 === 0;
|
801
639
|
});
|
802
640
|
expect(data).toEqual([1, 3, 5, 2, 4]);
|
803
641
|
});
|
804
|
-
it(
|
805
|
-
|
642
|
+
it("works when moving one thing", function () {
|
643
|
+
const data = [1, 2, 3, 4, 5];
|
806
644
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
807
645
|
return x === 1;
|
808
646
|
});
|
809
647
|
expect(data).toEqual([2, 3, 4, 5, 1]);
|
810
648
|
});
|
811
|
-
it(
|
812
|
-
|
649
|
+
it("works when moving nothing", function () {
|
650
|
+
const data = [1, 2, 3, 4, 5];
|
813
651
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
814
652
|
return x === 0;
|
815
653
|
});
|