pdfjs-dist 2.0.943 → 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/CODE_OF_CONDUCT.md +15 -0
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- 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 +25500 -26628
- 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 +2887 -4094
- 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 +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- 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 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -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.
|
@@ -19,293 +19,316 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var
|
24
|
+
var _ui_utils = require("../../web/ui_utils.js");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _util = require("../../shared/util.js");
|
27
27
|
|
28
|
-
var
|
28
|
+
var _is_node = require("../../shared/is_node.js");
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
var _is_node2 = _interopRequireDefault(_is_node);
|
33
|
-
|
34
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
35
|
-
|
36
|
-
describe('ui_utils', function () {
|
37
|
-
describe('binary search', function () {
|
30
|
+
describe("ui_utils", function () {
|
31
|
+
describe("binary search", function () {
|
38
32
|
function isTrue(boolean) {
|
39
33
|
return boolean;
|
40
34
|
}
|
35
|
+
|
41
36
|
function isGreater3(number) {
|
42
37
|
return number > 3;
|
43
38
|
}
|
44
|
-
|
39
|
+
|
40
|
+
it("empty array", function () {
|
45
41
|
expect((0, _ui_utils.binarySearchFirstItem)([], isTrue)).toEqual(0);
|
46
42
|
});
|
47
|
-
it(
|
43
|
+
it("single boolean entry", function () {
|
48
44
|
expect((0, _ui_utils.binarySearchFirstItem)([false], isTrue)).toEqual(1);
|
49
45
|
expect((0, _ui_utils.binarySearchFirstItem)([true], isTrue)).toEqual(0);
|
50
46
|
});
|
51
|
-
it(
|
47
|
+
it("three boolean entries", function () {
|
52
48
|
expect((0, _ui_utils.binarySearchFirstItem)([true, true, true], isTrue)).toEqual(0);
|
53
49
|
expect((0, _ui_utils.binarySearchFirstItem)([false, true, true], isTrue)).toEqual(1);
|
54
50
|
expect((0, _ui_utils.binarySearchFirstItem)([false, false, true], isTrue)).toEqual(2);
|
55
51
|
expect((0, _ui_utils.binarySearchFirstItem)([false, false, false], isTrue)).toEqual(3);
|
56
52
|
});
|
57
|
-
it(
|
53
|
+
it("three numeric entries", function () {
|
58
54
|
expect((0, _ui_utils.binarySearchFirstItem)([0, 1, 2], isGreater3)).toEqual(3);
|
59
55
|
expect((0, _ui_utils.binarySearchFirstItem)([2, 3, 4], isGreater3)).toEqual(2);
|
60
56
|
expect((0, _ui_utils.binarySearchFirstItem)([4, 5, 6], isGreater3)).toEqual(0);
|
61
57
|
});
|
62
58
|
});
|
63
|
-
describe(
|
64
|
-
it(
|
65
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
66
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
67
|
-
});
|
68
|
-
it(
|
69
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
70
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
71
|
-
});
|
72
|
-
it(
|
73
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
74
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
75
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
76
|
-
});
|
77
|
-
it(
|
78
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(null)).toEqual(
|
79
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(null,
|
80
|
-
});
|
81
|
-
it(
|
82
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
83
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
84
|
-
});
|
85
|
-
it(
|
86
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
87
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
88
|
-
});
|
89
|
-
it(
|
90
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
91
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
92
|
-
});
|
93
|
-
it(
|
94
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
95
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
96
|
-
});
|
97
|
-
it(
|
98
|
-
var encodedUrl = encodeURIComponent(
|
99
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrl)).toEqual(
|
100
|
-
var encodedUrlWithQuery = encodeURIComponent(
|
101
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrlWithQuery)).toEqual(
|
102
|
-
});
|
103
|
-
it(
|
104
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
105
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
106
|
-
});
|
107
|
-
it(
|
108
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
109
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
110
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(
|
111
|
-
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");
|
112
108
|
});
|
113
109
|
it('gets PDF filename from query string appended to "blob:" URL', function () {
|
114
|
-
if (
|
115
|
-
pending(
|
110
|
+
if (_is_node.isNodeJS) {
|
111
|
+
pending("Blob in not supported in Node.js.");
|
116
112
|
}
|
113
|
+
|
117
114
|
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
118
|
-
var blobUrl = (0, _util.createObjectURL)(typedArray,
|
119
|
-
expect(blobUrl.
|
120
|
-
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");
|
121
118
|
});
|
122
119
|
it('gets fallback filename from query string appended to "data:" URL', function () {
|
123
120
|
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
124
|
-
var dataUrl = (0, _util.createObjectURL)(typedArray,
|
125
|
-
expect(dataUrl.
|
126
|
-
expect((0, _ui_utils.getPDFFileNameFromURL)(dataUrl +
|
127
|
-
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");
|
128
125
|
});
|
129
126
|
});
|
130
|
-
describe(
|
131
|
-
it(
|
127
|
+
describe("EventBus", function () {
|
128
|
+
it("dispatch event", function () {
|
132
129
|
var eventBus = new _ui_utils.EventBus();
|
133
130
|
var count = 0;
|
134
|
-
eventBus.on(
|
131
|
+
eventBus.on("test", function (evt) {
|
135
132
|
expect(evt).toEqual(undefined);
|
136
133
|
count++;
|
137
134
|
});
|
138
|
-
eventBus.dispatch(
|
135
|
+
eventBus.dispatch("test");
|
139
136
|
expect(count).toEqual(1);
|
140
137
|
});
|
141
|
-
it(
|
142
|
-
|
143
|
-
|
144
|
-
eventBus.on(
|
145
|
-
expect(evt).toEqual({
|
138
|
+
it("dispatch event with arguments", function () {
|
139
|
+
const eventBus = new _ui_utils.EventBus();
|
140
|
+
let count = 0;
|
141
|
+
eventBus.on("test", function (evt) {
|
142
|
+
expect(evt).toEqual({
|
143
|
+
abc: 123
|
144
|
+
});
|
146
145
|
count++;
|
147
146
|
});
|
148
|
-
eventBus.dispatch(
|
147
|
+
eventBus.dispatch("test", {
|
148
|
+
abc: 123
|
149
|
+
});
|
149
150
|
expect(count).toEqual(1);
|
150
151
|
});
|
151
|
-
it(
|
152
|
+
it("dispatch different event", function () {
|
152
153
|
var eventBus = new _ui_utils.EventBus();
|
153
154
|
var count = 0;
|
154
|
-
eventBus.on(
|
155
|
+
eventBus.on("test", function () {
|
155
156
|
count++;
|
156
157
|
});
|
157
|
-
eventBus.dispatch(
|
158
|
+
eventBus.dispatch("nottest");
|
158
159
|
expect(count).toEqual(0);
|
159
160
|
});
|
160
|
-
it(
|
161
|
+
it("dispatch event multiple times", function () {
|
161
162
|
var eventBus = new _ui_utils.EventBus();
|
162
163
|
var count = 0;
|
163
|
-
eventBus.dispatch(
|
164
|
-
eventBus.on(
|
164
|
+
eventBus.dispatch("test");
|
165
|
+
eventBus.on("test", function () {
|
165
166
|
count++;
|
166
167
|
});
|
167
|
-
eventBus.dispatch(
|
168
|
-
eventBus.dispatch(
|
168
|
+
eventBus.dispatch("test");
|
169
|
+
eventBus.dispatch("test");
|
169
170
|
expect(count).toEqual(2);
|
170
171
|
});
|
171
|
-
it(
|
172
|
+
it("dispatch event to multiple handlers", function () {
|
172
173
|
var eventBus = new _ui_utils.EventBus();
|
173
174
|
var count = 0;
|
174
|
-
eventBus.on(
|
175
|
+
eventBus.on("test", function () {
|
175
176
|
count++;
|
176
177
|
});
|
177
|
-
eventBus.on(
|
178
|
+
eventBus.on("test", function () {
|
178
179
|
count++;
|
179
180
|
});
|
180
|
-
eventBus.dispatch(
|
181
|
+
eventBus.dispatch("test");
|
181
182
|
expect(count).toEqual(2);
|
182
183
|
});
|
183
|
-
it(
|
184
|
+
it("dispatch to detached", function () {
|
184
185
|
var eventBus = new _ui_utils.EventBus();
|
185
186
|
var count = 0;
|
186
|
-
|
187
|
+
|
188
|
+
var listener = function () {
|
187
189
|
count++;
|
188
190
|
};
|
189
|
-
|
190
|
-
eventBus.
|
191
|
-
eventBus.
|
192
|
-
eventBus.
|
191
|
+
|
192
|
+
eventBus.on("test", listener);
|
193
|
+
eventBus.dispatch("test");
|
194
|
+
eventBus.off("test", listener);
|
195
|
+
eventBus.dispatch("test");
|
193
196
|
expect(count).toEqual(1);
|
194
197
|
});
|
195
|
-
it(
|
198
|
+
it("dispatch to wrong detached", function () {
|
196
199
|
var eventBus = new _ui_utils.EventBus();
|
197
200
|
var count = 0;
|
198
|
-
eventBus.on(
|
201
|
+
eventBus.on("test", function () {
|
199
202
|
count++;
|
200
203
|
});
|
201
|
-
eventBus.dispatch(
|
202
|
-
eventBus.off(
|
204
|
+
eventBus.dispatch("test");
|
205
|
+
eventBus.off("test", function () {
|
203
206
|
count++;
|
204
207
|
});
|
205
|
-
eventBus.dispatch(
|
208
|
+
eventBus.dispatch("test");
|
206
209
|
expect(count).toEqual(2);
|
207
210
|
});
|
208
|
-
it(
|
211
|
+
it("dispatch to detached during handling", function () {
|
209
212
|
var eventBus = new _ui_utils.EventBus();
|
210
213
|
var count = 0;
|
211
|
-
|
212
|
-
|
214
|
+
|
215
|
+
var listener1 = function () {
|
216
|
+
eventBus.off("test", listener2);
|
213
217
|
count++;
|
214
218
|
};
|
215
|
-
|
216
|
-
|
219
|
+
|
220
|
+
var listener2 = function () {
|
221
|
+
eventBus.off("test", listener1);
|
217
222
|
count++;
|
218
223
|
};
|
219
|
-
|
220
|
-
eventBus.on(
|
221
|
-
eventBus.
|
222
|
-
eventBus.dispatch(
|
224
|
+
|
225
|
+
eventBus.on("test", listener1);
|
226
|
+
eventBus.on("test", listener2);
|
227
|
+
eventBus.dispatch("test");
|
228
|
+
eventBus.dispatch("test");
|
223
229
|
expect(count).toEqual(2);
|
224
230
|
});
|
225
|
-
it(
|
226
|
-
if (
|
227
|
-
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.");
|
228
234
|
}
|
229
|
-
|
230
|
-
|
231
|
-
|
235
|
+
|
236
|
+
const eventBus = new _ui_utils.EventBus();
|
237
|
+
let count = 0;
|
238
|
+
eventBus.on("test", function (evt) {
|
232
239
|
expect(evt).toEqual(undefined);
|
233
240
|
count++;
|
234
241
|
});
|
242
|
+
|
235
243
|
function domEventListener() {
|
236
|
-
done.fail(
|
244
|
+
done.fail("shall not dispatch DOM event.");
|
237
245
|
}
|
238
|
-
|
239
|
-
|
240
|
-
|
246
|
+
|
247
|
+
document.addEventListener("test", domEventListener);
|
248
|
+
eventBus.dispatch("test");
|
249
|
+
Promise.resolve().then(() => {
|
241
250
|
expect(count).toEqual(1);
|
242
|
-
document.removeEventListener(
|
251
|
+
document.removeEventListener("test", domEventListener);
|
243
252
|
done();
|
244
253
|
});
|
245
254
|
});
|
246
|
-
it(
|
247
|
-
if (
|
248
|
-
pending(
|
255
|
+
it("should re-dispatch to DOM", function (done) {
|
256
|
+
if (_is_node.isNodeJS) {
|
257
|
+
pending("Document in not supported in Node.js.");
|
249
258
|
}
|
250
|
-
|
251
|
-
|
252
|
-
|
259
|
+
|
260
|
+
const eventBus = new _ui_utils.EventBus({
|
261
|
+
dispatchToDOM: true
|
262
|
+
});
|
263
|
+
let count = 0;
|
264
|
+
eventBus.on("test", function (evt) {
|
253
265
|
expect(evt).toEqual(undefined);
|
254
266
|
count++;
|
255
267
|
});
|
268
|
+
|
256
269
|
function domEventListener(evt) {
|
257
270
|
expect(evt.detail).toEqual({});
|
258
271
|
count++;
|
259
272
|
}
|
260
|
-
|
261
|
-
|
262
|
-
|
273
|
+
|
274
|
+
document.addEventListener("test", domEventListener);
|
275
|
+
eventBus.dispatch("test");
|
276
|
+
Promise.resolve().then(() => {
|
263
277
|
expect(count).toEqual(2);
|
264
|
-
document.removeEventListener(
|
278
|
+
document.removeEventListener("test", domEventListener);
|
265
279
|
done();
|
266
280
|
});
|
267
281
|
});
|
268
|
-
it(
|
269
|
-
if (
|
270
|
-
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.");
|
271
285
|
}
|
272
|
-
|
273
|
-
|
286
|
+
|
287
|
+
const eventBus = new _ui_utils.EventBus({
|
288
|
+
dispatchToDOM: true
|
289
|
+
});
|
290
|
+
let count = 0;
|
291
|
+
|
274
292
|
function domEventListener(evt) {
|
275
|
-
expect(evt.detail).toEqual({
|
293
|
+
expect(evt.detail).toEqual({
|
294
|
+
abc: 123
|
295
|
+
});
|
276
296
|
count++;
|
277
297
|
}
|
278
|
-
|
279
|
-
|
280
|
-
|
298
|
+
|
299
|
+
document.addEventListener("test", domEventListener);
|
300
|
+
eventBus.dispatch("test", {
|
301
|
+
abc: 123
|
302
|
+
});
|
303
|
+
Promise.resolve().then(() => {
|
281
304
|
expect(count).toEqual(1);
|
282
|
-
document.removeEventListener(
|
305
|
+
document.removeEventListener("test", domEventListener);
|
283
306
|
done();
|
284
307
|
});
|
285
308
|
});
|
286
309
|
});
|
287
|
-
describe(
|
288
|
-
it(
|
310
|
+
describe("isValidRotation", function () {
|
311
|
+
it("should reject non-integer angles", function () {
|
289
312
|
expect((0, _ui_utils.isValidRotation)()).toEqual(false);
|
290
313
|
expect((0, _ui_utils.isValidRotation)(null)).toEqual(false);
|
291
314
|
expect((0, _ui_utils.isValidRotation)(NaN)).toEqual(false);
|
292
315
|
expect((0, _ui_utils.isValidRotation)([90])).toEqual(false);
|
293
|
-
expect((0, _ui_utils.isValidRotation)(
|
316
|
+
expect((0, _ui_utils.isValidRotation)("90")).toEqual(false);
|
294
317
|
expect((0, _ui_utils.isValidRotation)(90.5)).toEqual(false);
|
295
318
|
});
|
296
|
-
it(
|
319
|
+
it("should reject non-multiple of 90 degree angles", function () {
|
297
320
|
expect((0, _ui_utils.isValidRotation)(45)).toEqual(false);
|
298
321
|
expect((0, _ui_utils.isValidRotation)(-123)).toEqual(false);
|
299
322
|
});
|
300
|
-
it(
|
323
|
+
it("should accept valid angles", function () {
|
301
324
|
expect((0, _ui_utils.isValidRotation)(0)).toEqual(true);
|
302
325
|
expect((0, _ui_utils.isValidRotation)(90)).toEqual(true);
|
303
326
|
expect((0, _ui_utils.isValidRotation)(-270)).toEqual(true);
|
304
327
|
expect((0, _ui_utils.isValidRotation)(540)).toEqual(true);
|
305
328
|
});
|
306
329
|
});
|
307
|
-
describe(
|
308
|
-
it(
|
330
|
+
describe("isPortraitOrientation", function () {
|
331
|
+
it("should be portrait orientation", function () {
|
309
332
|
expect((0, _ui_utils.isPortraitOrientation)({
|
310
333
|
width: 200,
|
311
334
|
height: 400
|
@@ -315,15 +338,15 @@ describe('ui_utils', function () {
|
|
315
338
|
height: 500
|
316
339
|
})).toEqual(true);
|
317
340
|
});
|
318
|
-
it(
|
341
|
+
it("should be landscape orientation", function () {
|
319
342
|
expect((0, _ui_utils.isPortraitOrientation)({
|
320
343
|
width: 600,
|
321
344
|
height: 300
|
322
345
|
})).toEqual(false);
|
323
346
|
});
|
324
347
|
});
|
325
|
-
describe(
|
326
|
-
|
348
|
+
describe("waitOnEventOrTimeout", function () {
|
349
|
+
let eventBus;
|
327
350
|
beforeAll(function (done) {
|
328
351
|
eventBus = new _ui_utils.EventBus();
|
329
352
|
done();
|
@@ -331,42 +354,43 @@ describe('ui_utils', function () {
|
|
331
354
|
afterAll(function () {
|
332
355
|
eventBus = null;
|
333
356
|
});
|
334
|
-
it(
|
335
|
-
|
336
|
-
target:
|
337
|
-
name:
|
357
|
+
it("should reject invalid parameters", function (done) {
|
358
|
+
const invalidTarget = (0, _ui_utils.waitOnEventOrTimeout)({
|
359
|
+
target: "window",
|
360
|
+
name: "DOMContentLoaded"
|
338
361
|
}).then(function () {
|
339
|
-
throw new Error(
|
362
|
+
throw new Error("Should reject invalid parameters.");
|
340
363
|
}, function (reason) {
|
341
364
|
expect(reason instanceof Error).toEqual(true);
|
342
365
|
});
|
343
|
-
|
366
|
+
const invalidName = (0, _ui_utils.waitOnEventOrTimeout)({
|
344
367
|
target: eventBus,
|
345
|
-
name:
|
368
|
+
name: ""
|
346
369
|
}).then(function () {
|
347
|
-
throw new Error(
|
370
|
+
throw new Error("Should reject invalid parameters.");
|
348
371
|
}, function (reason) {
|
349
372
|
expect(reason instanceof Error).toEqual(true);
|
350
373
|
});
|
351
|
-
|
374
|
+
const invalidDelay = (0, _ui_utils.waitOnEventOrTimeout)({
|
352
375
|
target: eventBus,
|
353
|
-
name:
|
376
|
+
name: "pagerendered",
|
354
377
|
delay: -1000
|
355
378
|
}).then(function () {
|
356
|
-
throw new Error(
|
379
|
+
throw new Error("Should reject invalid parameters.");
|
357
380
|
}, function (reason) {
|
358
381
|
expect(reason instanceof Error).toEqual(true);
|
359
382
|
});
|
360
383
|
Promise.all([invalidTarget, invalidName, invalidDelay]).then(done, done.fail);
|
361
384
|
});
|
362
|
-
it(
|
363
|
-
if (
|
364
|
-
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.");
|
365
388
|
}
|
366
|
-
|
367
|
-
|
389
|
+
|
390
|
+
const button = document.createElement("button");
|
391
|
+
const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
368
392
|
target: button,
|
369
|
-
name:
|
393
|
+
name: "click",
|
370
394
|
delay: 10000
|
371
395
|
});
|
372
396
|
button.click();
|
@@ -375,14 +399,15 @@ describe('ui_utils', function () {
|
|
375
399
|
done();
|
376
400
|
}, done.fail);
|
377
401
|
});
|
378
|
-
it(
|
379
|
-
if (
|
380
|
-
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.");
|
381
405
|
}
|
382
|
-
|
383
|
-
|
406
|
+
|
407
|
+
const button = document.createElement("button");
|
408
|
+
const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
384
409
|
target: button,
|
385
|
-
name:
|
410
|
+
name: "click",
|
386
411
|
delay: 10
|
387
412
|
});
|
388
413
|
buttonClicked.then(function (type) {
|
@@ -390,22 +415,22 @@ describe('ui_utils', function () {
|
|
390
415
|
done();
|
391
416
|
}, done.fail);
|
392
417
|
});
|
393
|
-
it(
|
394
|
-
|
418
|
+
it("should resolve on event, using the EventBus", function (done) {
|
419
|
+
const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
|
395
420
|
target: eventBus,
|
396
|
-
name:
|
421
|
+
name: "pagerendered",
|
397
422
|
delay: 10000
|
398
423
|
});
|
399
|
-
eventBus.dispatch(
|
424
|
+
eventBus.dispatch("pagerendered");
|
400
425
|
pageRendered.then(function (type) {
|
401
426
|
expect(type).toEqual(_ui_utils.WaitOnType.EVENT);
|
402
427
|
done();
|
403
428
|
}, done.fail);
|
404
429
|
});
|
405
|
-
it(
|
406
|
-
|
430
|
+
it("should resolve on timeout, using the EventBus", function (done) {
|
431
|
+
const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
|
407
432
|
target: eventBus,
|
408
|
-
name:
|
433
|
+
name: "pagerendered",
|
409
434
|
delay: 10
|
410
435
|
});
|
411
436
|
pageRendered.then(function (type) {
|
@@ -414,196 +439,134 @@ describe('ui_utils', function () {
|
|
414
439
|
}, done.fail);
|
415
440
|
});
|
416
441
|
});
|
417
|
-
describe(
|
418
|
-
it(
|
419
|
-
|
442
|
+
describe("getPageSizeInches", function () {
|
443
|
+
it("gets page size (in inches)", function () {
|
444
|
+
const page = {
|
420
445
|
view: [0, 0, 595.28, 841.89],
|
421
446
|
userUnit: 1.0,
|
422
447
|
rotate: 0
|
423
448
|
};
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
449
|
+
const {
|
450
|
+
width,
|
451
|
+
height
|
452
|
+
} = (0, _ui_utils.getPageSizeInches)(page);
|
429
453
|
expect(+width.toPrecision(3)).toEqual(8.27);
|
430
454
|
expect(+height.toPrecision(4)).toEqual(11.69);
|
431
455
|
});
|
432
|
-
it(
|
433
|
-
|
456
|
+
it("gets page size (in inches), for non-default /Rotate entry", function () {
|
457
|
+
const pdfPage1 = {
|
434
458
|
view: [0, 0, 612, 792],
|
435
459
|
userUnit: 1,
|
436
460
|
rotate: 0
|
437
461
|
};
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
462
|
+
const {
|
463
|
+
width: width1,
|
464
|
+
height: height1
|
465
|
+
} = (0, _ui_utils.getPageSizeInches)(pdfPage1);
|
443
466
|
expect(width1).toEqual(8.5);
|
444
467
|
expect(height1).toEqual(11);
|
445
|
-
|
468
|
+
const pdfPage2 = {
|
446
469
|
view: [0, 0, 612, 792],
|
447
470
|
userUnit: 1,
|
448
471
|
rotate: 90
|
449
472
|
};
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
473
|
+
const {
|
474
|
+
width: width2,
|
475
|
+
height: height2
|
476
|
+
} = (0, _ui_utils.getPageSizeInches)(pdfPage2);
|
455
477
|
expect(width2).toEqual(11);
|
456
478
|
expect(height2).toEqual(8.5);
|
457
479
|
});
|
458
480
|
});
|
459
|
-
describe(
|
460
|
-
|
461
|
-
|
481
|
+
describe("getVisibleElements", function () {
|
482
|
+
const BORDER_WIDTH = 9;
|
483
|
+
const SPACING = 2 * BORDER_WIDTH - 7;
|
484
|
+
|
462
485
|
function makePages(lines) {
|
463
|
-
|
464
|
-
|
486
|
+
const result = [];
|
487
|
+
let lineTop = 0,
|
465
488
|
id = 0;
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
var clientHeight = _ref2[1];
|
490
|
-
|
491
|
-
var offsetTop = lineTop + (lineHeight - clientHeight) / 2 - BORDER_WIDTH;
|
492
|
-
var div = {
|
493
|
-
offsetLeft: offsetLeft,
|
494
|
-
offsetTop: offsetTop,
|
495
|
-
clientWidth: clientWidth,
|
496
|
-
clientHeight: clientHeight,
|
497
|
-
clientLeft: BORDER_WIDTH,
|
498
|
-
clientTop: BORDER_WIDTH
|
499
|
-
};
|
500
|
-
result.push({
|
501
|
-
id: id,
|
502
|
-
div: div
|
503
|
-
});
|
504
|
-
++id;
|
505
|
-
offsetLeft += clientWidth + SPACING;
|
506
|
-
}
|
507
|
-
} catch (err) {
|
508
|
-
_didIteratorError2 = true;
|
509
|
-
_iteratorError2 = err;
|
510
|
-
} finally {
|
511
|
-
try {
|
512
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
513
|
-
_iterator2.return();
|
514
|
-
}
|
515
|
-
} finally {
|
516
|
-
if (_didIteratorError2) {
|
517
|
-
throw _iteratorError2;
|
518
|
-
}
|
519
|
-
}
|
520
|
-
}
|
521
|
-
|
522
|
-
lineTop += lineHeight + SPACING;
|
523
|
-
}
|
524
|
-
} catch (err) {
|
525
|
-
_didIteratorError = true;
|
526
|
-
_iteratorError = err;
|
527
|
-
} finally {
|
528
|
-
try {
|
529
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
530
|
-
_iterator.return();
|
531
|
-
}
|
532
|
-
} finally {
|
533
|
-
if (_didIteratorError) {
|
534
|
-
throw _iteratorError;
|
535
|
-
}
|
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;
|
536
512
|
}
|
513
|
+
|
514
|
+
lineTop += lineHeight + SPACING;
|
537
515
|
}
|
538
516
|
|
539
517
|
return result;
|
540
518
|
}
|
519
|
+
|
541
520
|
function slowGetVisibleElements(scroll, pages) {
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
percent: percent
|
572
|
-
});
|
573
|
-
}
|
574
|
-
}
|
575
|
-
} catch (err) {
|
576
|
-
_didIteratorError3 = true;
|
577
|
-
_iteratorError3 = err;
|
578
|
-
} finally {
|
579
|
-
try {
|
580
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
581
|
-
_iterator3.return();
|
582
|
-
}
|
583
|
-
} finally {
|
584
|
-
if (_didIteratorError3) {
|
585
|
-
throw _iteratorError3;
|
586
|
-
}
|
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
|
+
});
|
587
550
|
}
|
588
551
|
}
|
589
552
|
|
590
553
|
return {
|
591
554
|
first: views[0],
|
592
555
|
last: views[views.length - 1],
|
593
|
-
views
|
556
|
+
views
|
594
557
|
};
|
595
558
|
}
|
596
|
-
function scrollOverDocument(pages) {
|
597
|
-
var horizontally = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
598
|
-
|
599
|
-
var size = pages.reduce(function (max, _ref3) {
|
600
|
-
var div = _ref3.div;
|
601
559
|
|
560
|
+
function scrollOverDocument(pages, horizontally = false) {
|
561
|
+
const size = pages.reduce(function (max, {
|
562
|
+
div
|
563
|
+
}) {
|
602
564
|
return Math.max(max, horizontally ? div.offsetLeft + div.clientLeft + div.clientWidth : div.offsetTop + div.clientTop + div.clientHeight);
|
603
565
|
}, 0);
|
604
|
-
|
605
|
-
|
606
|
-
|
566
|
+
|
567
|
+
for (let i = 0; i < size; i += 7) {
|
568
|
+
for (let j = i + 5; j < size; j += j - i) {
|
569
|
+
const scroll = horizontally ? {
|
607
570
|
scrollTop: 0,
|
608
571
|
scrollLeft: i,
|
609
572
|
clientHeight: 10000,
|
@@ -618,74 +581,127 @@ describe('ui_utils', function () {
|
|
618
581
|
}
|
619
582
|
}
|
620
583
|
}
|
621
|
-
|
622
|
-
|
584
|
+
|
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]]]);
|
623
587
|
scrollOverDocument(pages);
|
624
588
|
});
|
625
|
-
it(
|
626
|
-
|
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]]]);
|
627
591
|
scrollOverDocument(pages);
|
628
592
|
});
|
629
|
-
it(
|
630
|
-
|
593
|
+
it("works with horizontal scrolling", function () {
|
594
|
+
const pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
|
631
595
|
scrollOverDocument(pages, true);
|
632
596
|
});
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
597
|
+
it("handles `sortByVisibility` correctly", function () {
|
598
|
+
const scrollEl = {
|
599
|
+
scrollTop: 75,
|
600
|
+
scrollLeft: 0,
|
601
|
+
clientHeight: 750,
|
602
|
+
clientWidth: 1500
|
603
|
+
};
|
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);
|
612
|
+
}
|
613
|
+
|
614
|
+
for (const view of visibleSorted.views) {
|
615
|
+
viewsSortedOrder.push(view.id);
|
616
|
+
}
|
617
|
+
|
618
|
+
expect(viewsOrder).toEqual([0, 1, 2]);
|
619
|
+
expect(viewsSortedOrder).toEqual([1, 2, 0]);
|
620
|
+
});
|
621
|
+
it("handles views being empty", function () {
|
622
|
+
const scrollEl = {
|
623
|
+
scrollTop: 10,
|
624
|
+
scrollLeft: 0,
|
625
|
+
clientHeight: 750,
|
626
|
+
clientWidth: 1500
|
627
|
+
};
|
628
|
+
const views = [];
|
629
|
+
expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
|
630
|
+
first: undefined,
|
631
|
+
last: undefined,
|
632
|
+
views: []
|
633
|
+
});
|
634
|
+
});
|
635
|
+
it("handles all views being hidden (without errors)", function () {
|
636
|
+
const scrollEl = {
|
637
|
+
scrollTop: 100000,
|
638
|
+
scrollLeft: 0,
|
639
|
+
clientHeight: 750,
|
640
|
+
clientWidth: 1500
|
641
|
+
};
|
642
|
+
const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
|
643
|
+
expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
|
644
|
+
first: undefined,
|
645
|
+
last: undefined,
|
646
|
+
views: []
|
647
|
+
});
|
648
|
+
});
|
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;
|
641
657
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
642
658
|
});
|
643
|
-
it(
|
644
|
-
|
645
|
-
|
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;
|
646
662
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
647
663
|
});
|
648
|
-
it(
|
649
|
-
|
650
|
-
|
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;
|
651
667
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
|
652
668
|
});
|
653
|
-
it(
|
654
|
-
|
655
|
-
|
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;
|
656
672
|
expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top2)).toEqual(4);
|
657
673
|
});
|
658
674
|
});
|
659
675
|
});
|
660
|
-
describe(
|
661
|
-
it(
|
662
|
-
|
676
|
+
describe("moveToEndOfArray", function () {
|
677
|
+
it("works on empty arrays", function () {
|
678
|
+
const data = [];
|
663
679
|
(0, _ui_utils.moveToEndOfArray)(data, function () {});
|
664
680
|
expect(data).toEqual([]);
|
665
681
|
});
|
666
|
-
it(
|
667
|
-
|
682
|
+
it("works when moving everything", function () {
|
683
|
+
const data = [1, 2, 3, 4, 5];
|
668
684
|
(0, _ui_utils.moveToEndOfArray)(data, function () {
|
669
685
|
return true;
|
670
686
|
});
|
671
687
|
expect(data).toEqual([1, 2, 3, 4, 5]);
|
672
688
|
});
|
673
|
-
it(
|
674
|
-
|
689
|
+
it("works when moving some things", function () {
|
690
|
+
const data = [1, 2, 3, 4, 5];
|
675
691
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
676
692
|
return x % 2 === 0;
|
677
693
|
});
|
678
694
|
expect(data).toEqual([1, 3, 5, 2, 4]);
|
679
695
|
});
|
680
|
-
it(
|
681
|
-
|
696
|
+
it("works when moving one thing", function () {
|
697
|
+
const data = [1, 2, 3, 4, 5];
|
682
698
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
683
699
|
return x === 1;
|
684
700
|
});
|
685
701
|
expect(data).toEqual([2, 3, 4, 5, 1]);
|
686
702
|
});
|
687
|
-
it(
|
688
|
-
|
703
|
+
it("works when moving nothing", function () {
|
704
|
+
const data = [1, 2, 3, 4, 5];
|
689
705
|
(0, _ui_utils.moveToEndOfArray)(data, function (x) {
|
690
706
|
return x === 0;
|
691
707
|
});
|