pdfjs-dist 2.3.200 → 2.4.456

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

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