pdfjs-dist 2.2.228 → 2.6.347

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 (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  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 +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. package/web/images/texture.png +0 -0
@@ -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,324 +21,260 @@
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) { 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 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);
262
- done();
263
- });
264
- });
265
- it('should re-dispatch to DOM', function (done) {
266
- if ((0, _is_node["default"])()) {
267
- pending('Document in not supported in Node.js.');
268
- }
269
-
270
- var eventBus = new _ui_utils.EventBus({
271
- dispatchToDOM: true
272
- });
273
- var count = 0;
274
- eventBus.on('test', function (evt) {
275
- expect(evt).toEqual(undefined);
276
- count++;
277
- });
278
-
279
- function domEventListener(evt) {
280
- expect(evt.detail).toEqual({});
281
- count++;
282
- }
283
-
284
- document.addEventListener('test', domEventListener);
285
- eventBus.dispatch('test');
286
- Promise.resolve().then(function () {
287
- expect(count).toEqual(2);
288
- document.removeEventListener('test', domEventListener);
289
- done();
290
- });
291
- });
292
- it('should re-dispatch to DOM, with arguments (without internal listeners)', function (done) {
293
- if ((0, _is_node["default"])()) {
294
- pending('Document in not supported in Node.js.');
295
- }
296
-
297
- var eventBus = new _ui_utils.EventBus({
298
- dispatchToDOM: true
299
- });
300
- var count = 0;
301
-
302
- function domEventListener(evt) {
303
- expect(evt.detail).toEqual({
304
- abc: 123
305
- });
306
- count++;
307
- }
308
-
309
- document.addEventListener('test', domEventListener);
310
- eventBus.dispatch('test', {
311
- abc: 123
312
- });
313
- Promise.resolve().then(function () {
314
- expect(count).toEqual(1);
315
- document.removeEventListener('test', domEventListener);
251
+ document.removeEventListener("test", domEventListener);
316
252
  done();
317
253
  });
318
254
  });
319
255
  });
320
- describe('isValidRotation', function () {
321
- it('should reject non-integer angles', function () {
256
+ describe("isValidRotation", function () {
257
+ it("should reject non-integer angles", function () {
322
258
  expect((0, _ui_utils.isValidRotation)()).toEqual(false);
323
259
  expect((0, _ui_utils.isValidRotation)(null)).toEqual(false);
324
260
  expect((0, _ui_utils.isValidRotation)(NaN)).toEqual(false);
325
261
  expect((0, _ui_utils.isValidRotation)([90])).toEqual(false);
326
- expect((0, _ui_utils.isValidRotation)('90')).toEqual(false);
262
+ expect((0, _ui_utils.isValidRotation)("90")).toEqual(false);
327
263
  expect((0, _ui_utils.isValidRotation)(90.5)).toEqual(false);
328
264
  });
329
- it('should reject non-multiple of 90 degree angles', function () {
265
+ it("should reject non-multiple of 90 degree angles", function () {
330
266
  expect((0, _ui_utils.isValidRotation)(45)).toEqual(false);
331
267
  expect((0, _ui_utils.isValidRotation)(-123)).toEqual(false);
332
268
  });
333
- it('should accept valid angles', function () {
269
+ it("should accept valid angles", function () {
334
270
  expect((0, _ui_utils.isValidRotation)(0)).toEqual(true);
335
271
  expect((0, _ui_utils.isValidRotation)(90)).toEqual(true);
336
272
  expect((0, _ui_utils.isValidRotation)(-270)).toEqual(true);
337
273
  expect((0, _ui_utils.isValidRotation)(540)).toEqual(true);
338
274
  });
339
275
  });
340
- describe('isPortraitOrientation', function () {
341
- it('should be portrait orientation', function () {
276
+ describe("isPortraitOrientation", function () {
277
+ it("should be portrait orientation", function () {
342
278
  expect((0, _ui_utils.isPortraitOrientation)({
343
279
  width: 200,
344
280
  height: 400
@@ -348,15 +284,15 @@ describe('ui_utils', function () {
348
284
  height: 500
349
285
  })).toEqual(true);
350
286
  });
351
- it('should be landscape orientation', function () {
287
+ it("should be landscape orientation", function () {
352
288
  expect((0, _ui_utils.isPortraitOrientation)({
353
289
  width: 600,
354
290
  height: 300
355
291
  })).toEqual(false);
356
292
  });
357
293
  });
358
- describe('waitOnEventOrTimeout', function () {
359
- var eventBus;
294
+ describe("waitOnEventOrTimeout", function () {
295
+ let eventBus;
360
296
  beforeAll(function (done) {
361
297
  eventBus = new _ui_utils.EventBus();
362
298
  done();
@@ -364,43 +300,43 @@ describe('ui_utils', function () {
364
300
  afterAll(function () {
365
301
  eventBus = null;
366
302
  });
367
- it('should reject invalid parameters', function (done) {
368
- var invalidTarget = (0, _ui_utils.waitOnEventOrTimeout)({
369
- target: 'window',
370
- name: 'DOMContentLoaded'
303
+ it("should reject invalid parameters", function (done) {
304
+ const invalidTarget = (0, _ui_utils.waitOnEventOrTimeout)({
305
+ target: "window",
306
+ name: "DOMContentLoaded"
371
307
  }).then(function () {
372
- throw new Error('Should reject invalid parameters.');
308
+ throw new Error("Should reject invalid parameters.");
373
309
  }, function (reason) {
374
310
  expect(reason instanceof Error).toEqual(true);
375
311
  });
376
- var invalidName = (0, _ui_utils.waitOnEventOrTimeout)({
312
+ const invalidName = (0, _ui_utils.waitOnEventOrTimeout)({
377
313
  target: eventBus,
378
- name: ''
314
+ name: ""
379
315
  }).then(function () {
380
- throw new Error('Should reject invalid parameters.');
316
+ throw new Error("Should reject invalid parameters.");
381
317
  }, function (reason) {
382
318
  expect(reason instanceof Error).toEqual(true);
383
319
  });
384
- var invalidDelay = (0, _ui_utils.waitOnEventOrTimeout)({
320
+ const invalidDelay = (0, _ui_utils.waitOnEventOrTimeout)({
385
321
  target: eventBus,
386
- name: 'pagerendered',
322
+ name: "pagerendered",
387
323
  delay: -1000
388
324
  }).then(function () {
389
- throw new Error('Should reject invalid parameters.');
325
+ throw new Error("Should reject invalid parameters.");
390
326
  }, function (reason) {
391
327
  expect(reason instanceof Error).toEqual(true);
392
328
  });
393
329
  Promise.all([invalidTarget, invalidName, invalidDelay]).then(done, done.fail);
394
330
  });
395
- it('should resolve on event, using the DOM', function (done) {
396
- if ((0, _is_node["default"])()) {
397
- pending('Document in not supported in Node.js.');
331
+ it("should resolve on event, using the DOM", function (done) {
332
+ if (_is_node.isNodeJS) {
333
+ pending("Document in not supported in Node.js.");
398
334
  }
399
335
 
400
- var button = document.createElement('button');
401
- var buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
336
+ const button = document.createElement("button");
337
+ const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
402
338
  target: button,
403
- name: 'click',
339
+ name: "click",
404
340
  delay: 10000
405
341
  });
406
342
  button.click();
@@ -409,15 +345,15 @@ describe('ui_utils', function () {
409
345
  done();
410
346
  }, done.fail);
411
347
  });
412
- it('should resolve on timeout, using the DOM', function (done) {
413
- if ((0, _is_node["default"])()) {
414
- pending('Document in not supported in Node.js.');
348
+ it("should resolve on timeout, using the DOM", function (done) {
349
+ if (_is_node.isNodeJS) {
350
+ pending("Document in not supported in Node.js.");
415
351
  }
416
352
 
417
- var button = document.createElement('button');
418
- var buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
353
+ const button = document.createElement("button");
354
+ const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
419
355
  target: button,
420
- name: 'click',
356
+ name: "click",
421
357
  delay: 10
422
358
  });
423
359
  buttonClicked.then(function (type) {
@@ -425,22 +361,22 @@ describe('ui_utils', function () {
425
361
  done();
426
362
  }, done.fail);
427
363
  });
428
- it('should resolve on event, using the EventBus', function (done) {
429
- var pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
364
+ it("should resolve on event, using the EventBus", function (done) {
365
+ const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
430
366
  target: eventBus,
431
- name: 'pagerendered',
367
+ name: "pagerendered",
432
368
  delay: 10000
433
369
  });
434
- eventBus.dispatch('pagerendered');
370
+ eventBus.dispatch("pagerendered");
435
371
  pageRendered.then(function (type) {
436
372
  expect(type).toEqual(_ui_utils.WaitOnType.EVENT);
437
373
  done();
438
374
  }, done.fail);
439
375
  });
440
- it('should resolve on timeout, using the EventBus', function (done) {
441
- var pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
376
+ it("should resolve on timeout, using the EventBus", function (done) {
377
+ const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
442
378
  target: eventBus,
443
- name: 'pagerendered',
379
+ name: "pagerendered",
444
380
  delay: 10
445
381
  });
446
382
  pageRendered.then(function (type) {
@@ -449,193 +385,134 @@ describe('ui_utils', function () {
449
385
  }, done.fail);
450
386
  });
451
387
  });
452
- describe('getPageSizeInches', function () {
453
- it('gets page size (in inches)', function () {
454
- var page = {
388
+ describe("getPageSizeInches", function () {
389
+ it("gets page size (in inches)", function () {
390
+ const page = {
455
391
  view: [0, 0, 595.28, 841.89],
456
392
  userUnit: 1.0,
457
393
  rotate: 0
458
394
  };
459
-
460
- var _getPageSizeInches = (0, _ui_utils.getPageSizeInches)(page),
461
- width = _getPageSizeInches.width,
462
- height = _getPageSizeInches.height;
463
-
395
+ const {
396
+ width,
397
+ height
398
+ } = (0, _ui_utils.getPageSizeInches)(page);
464
399
  expect(+width.toPrecision(3)).toEqual(8.27);
465
400
  expect(+height.toPrecision(4)).toEqual(11.69);
466
401
  });
467
- it('gets page size (in inches), for non-default /Rotate entry', function () {
468
- var pdfPage1 = {
402
+ it("gets page size (in inches), for non-default /Rotate entry", function () {
403
+ const pdfPage1 = {
469
404
  view: [0, 0, 612, 792],
470
405
  userUnit: 1,
471
406
  rotate: 0
472
407
  };
473
-
474
- var _getPageSizeInches2 = (0, _ui_utils.getPageSizeInches)(pdfPage1),
475
- width1 = _getPageSizeInches2.width,
476
- height1 = _getPageSizeInches2.height;
477
-
408
+ const {
409
+ width: width1,
410
+ height: height1
411
+ } = (0, _ui_utils.getPageSizeInches)(pdfPage1);
478
412
  expect(width1).toEqual(8.5);
479
413
  expect(height1).toEqual(11);
480
- var pdfPage2 = {
414
+ const pdfPage2 = {
481
415
  view: [0, 0, 612, 792],
482
416
  userUnit: 1,
483
417
  rotate: 90
484
418
  };
485
-
486
- var _getPageSizeInches3 = (0, _ui_utils.getPageSizeInches)(pdfPage2),
487
- width2 = _getPageSizeInches3.width,
488
- height2 = _getPageSizeInches3.height;
489
-
419
+ const {
420
+ width: width2,
421
+ height: height2
422
+ } = (0, _ui_utils.getPageSizeInches)(pdfPage2);
490
423
  expect(width2).toEqual(11);
491
424
  expect(height2).toEqual(8.5);
492
425
  });
493
426
  });
494
- describe('getVisibleElements', function () {
495
- var BORDER_WIDTH = 9;
496
- var SPACING = 2 * BORDER_WIDTH - 7;
427
+ describe("getVisibleElements", function () {
428
+ const BORDER_WIDTH = 9;
429
+ const SPACING = 2 * BORDER_WIDTH - 7;
497
430
 
498
431
  function makePages(lines) {
499
- var result = [];
500
- var lineTop = 0,
432
+ const result = [];
433
+ let lineTop = 0,
501
434
  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
- }
435
+
436
+ for (const line of lines) {
437
+ const lineHeight = line.reduce(function (maxHeight, pair) {
438
+ return Math.max(maxHeight, pair[1]);
439
+ }, 0);
440
+ let offsetLeft = -BORDER_WIDTH;
441
+
442
+ for (const [clientWidth, clientHeight] of line) {
443
+ const offsetTop = lineTop + (lineHeight - clientHeight) / 2 - BORDER_WIDTH;
444
+ const div = {
445
+ offsetLeft,
446
+ offsetTop,
447
+ clientWidth,
448
+ clientHeight,
449
+ clientLeft: BORDER_WIDTH,
450
+ clientTop: BORDER_WIDTH
451
+ };
452
+ result.push({
453
+ id,
454
+ div
455
+ });
456
+ ++id;
457
+ offsetLeft += clientWidth + SPACING;
568
458
  }
459
+
460
+ lineTop += lineHeight + SPACING;
569
461
  }
570
462
 
571
463
  return result;
572
464
  }
573
465
 
574
466
  function slowGetVisibleElements(scroll, pages) {
575
- 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
- }
467
+ const views = [];
468
+ const {
469
+ scrollLeft,
470
+ scrollTop
471
+ } = scroll;
472
+ const scrollRight = scrollLeft + scroll.clientWidth;
473
+ const scrollBottom = scrollTop + scroll.clientHeight;
474
+
475
+ for (const view of pages) {
476
+ const {
477
+ div
478
+ } = view;
479
+ const viewLeft = div.offsetLeft + div.clientLeft;
480
+ const viewRight = viewLeft + div.clientWidth;
481
+ const viewTop = div.offsetTop + div.clientTop;
482
+ const viewBottom = viewTop + div.clientHeight;
483
+
484
+ if (viewLeft < scrollRight && viewRight > scrollLeft && viewTop < scrollBottom && viewBottom > scrollTop) {
485
+ const hiddenHeight = Math.max(0, scrollTop - viewTop) + Math.max(0, viewBottom - scrollBottom);
486
+ const hiddenWidth = Math.max(0, scrollLeft - viewLeft) + Math.max(0, viewRight - scrollRight);
487
+ const visibleArea = (div.clientHeight - hiddenHeight) * (div.clientWidth - hiddenWidth);
488
+ const percent = visibleArea * 100 / div.clientHeight / div.clientWidth | 0;
489
+ views.push({
490
+ id: view.id,
491
+ x: viewLeft,
492
+ y: viewTop,
493
+ view,
494
+ percent
495
+ });
619
496
  }
620
497
  }
621
498
 
622
499
  return {
623
500
  first: views[0],
624
501
  last: views[views.length - 1],
625
- views: views
502
+ views
626
503
  };
627
504
  }
628
505
 
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;
506
+ function scrollOverDocument(pages, horizontally = false) {
507
+ const size = pages.reduce(function (max, {
508
+ div
509
+ }) {
633
510
  return Math.max(max, horizontally ? div.offsetLeft + div.clientLeft + div.clientWidth : div.offsetTop + div.clientTop + div.clientHeight);
634
511
  }, 0);
635
512
 
636
- for (var i = 0; i < size; i += 7) {
637
- for (var j = i + 5; j < size; j += j - i) {
638
- var scroll = horizontally ? {
513
+ for (let i = 0; i < size; i += 7) {
514
+ for (let j = i + 5; j < size; j += j - i) {
515
+ const scroll = horizontally ? {
639
516
  scrollTop: 0,
640
517
  scrollLeft: i,
641
518
  clientHeight: 10000,
@@ -651,165 +528,126 @@ describe('ui_utils', function () {
651
528
  }
652
529
  }
653
530
 
654
- it('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]]]);
531
+ it("with pages of varying height", function () {
532
+ const pages = makePages([[[50, 20], [20, 50]], [[30, 12], [12, 30]], [[20, 50], [50, 20]], [[50, 20], [20, 50]]]);
656
533
  scrollOverDocument(pages);
657
534
  });
658
- it('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]]]);
535
+ it("widescreen challenge", function () {
536
+ const pages = makePages([[[10, 50], [10, 60], [10, 70], [10, 80], [10, 90]], [[10, 90], [10, 80], [10, 70], [10, 60], [10, 50]], [[10, 50], [10, 60], [10, 70], [10, 80], [10, 90]]]);
660
537
  scrollOverDocument(pages);
661
538
  });
662
- it('works with horizontal scrolling', function () {
663
- var pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
539
+ it("works with horizontal scrolling", function () {
540
+ const pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
664
541
  scrollOverDocument(pages, true);
665
542
  });
666
- it('handles `sortByVisibility` correctly', function () {
667
- var scrollEl = {
543
+ it("handles `sortByVisibility` correctly", function () {
544
+ const scrollEl = {
668
545
  scrollTop: 75,
669
546
  scrollLeft: 0,
670
547
  clientHeight: 750,
671
548
  clientWidth: 1500
672
549
  };
673
- 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
- }
550
+ const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
551
+ const visible = (0, _ui_utils.getVisibleElements)(scrollEl, views);
552
+ const visibleSorted = (0, _ui_utils.getVisibleElements)(scrollEl, views, true);
553
+ const viewsOrder = [],
554
+ viewsSortedOrder = [];
555
+
556
+ for (const view of visible.views) {
557
+ viewsOrder.push(view.id);
700
558
  }
701
559
 
702
- 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
- }
560
+ for (const view of visibleSorted.views) {
561
+ viewsSortedOrder.push(view.id);
724
562
  }
725
563
 
726
564
  expect(viewsOrder).toEqual([0, 1, 2]);
727
565
  expect(viewsSortedOrder).toEqual([1, 2, 0]);
728
566
  });
729
- it('handles views being empty', function () {
730
- var scrollEl = {
567
+ it("handles views being empty", function () {
568
+ const scrollEl = {
731
569
  scrollTop: 10,
732
570
  scrollLeft: 0,
733
571
  clientHeight: 750,
734
572
  clientWidth: 1500
735
573
  };
736
- var views = [];
574
+ const views = [];
737
575
  expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
738
576
  first: undefined,
739
577
  last: undefined,
740
578
  views: []
741
579
  });
742
580
  });
743
- it('handles all views being hidden (without errors)', function () {
744
- var scrollEl = {
581
+ it("handles all views being hidden (without errors)", function () {
582
+ const scrollEl = {
745
583
  scrollTop: 100000,
746
584
  scrollLeft: 0,
747
585
  clientHeight: 750,
748
586
  clientWidth: 1500
749
587
  };
750
- var views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
588
+ const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
751
589
  expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
752
590
  first: undefined,
753
591
  last: undefined,
754
592
  views: []
755
593
  });
756
594
  });
757
- describe('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;
595
+ describe("backtrackBeforeAllVisibleElements", function () {
596
+ const tallPage = [10, 50];
597
+ const shortPage = [10, 10];
598
+ const top1 = 20 + SPACING + 40;
599
+ const top2 = 20 + SPACING + 10;
600
+ it("handles case 1", function () {
601
+ const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]], [[10, 20]]]);
602
+ const bsResult = 4;
765
603
  expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
766
604
  });
767
- it('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;
605
+ it("handles case 2", function () {
606
+ const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, tallPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
607
+ const bsResult = 6;
770
608
  expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
771
609
  });
772
- it('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;
610
+ it("handles case 3", function () {
611
+ const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
612
+ const bsResult = 8;
775
613
  expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
776
614
  });
777
- it('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;
615
+ it("handles case 4", function () {
616
+ const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
617
+ const bsResult = 4;
780
618
  expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top2)).toEqual(4);
781
619
  });
782
620
  });
783
621
  });
784
- describe('moveToEndOfArray', function () {
785
- it('works on empty arrays', function () {
786
- var data = [];
622
+ describe("moveToEndOfArray", function () {
623
+ it("works on empty arrays", function () {
624
+ const data = [];
787
625
  (0, _ui_utils.moveToEndOfArray)(data, function () {});
788
626
  expect(data).toEqual([]);
789
627
  });
790
- it('works when moving everything', function () {
791
- var data = [1, 2, 3, 4, 5];
628
+ it("works when moving everything", function () {
629
+ const data = [1, 2, 3, 4, 5];
792
630
  (0, _ui_utils.moveToEndOfArray)(data, function () {
793
631
  return true;
794
632
  });
795
633
  expect(data).toEqual([1, 2, 3, 4, 5]);
796
634
  });
797
- it('works when moving some things', function () {
798
- var data = [1, 2, 3, 4, 5];
635
+ it("works when moving some things", function () {
636
+ const data = [1, 2, 3, 4, 5];
799
637
  (0, _ui_utils.moveToEndOfArray)(data, function (x) {
800
638
  return x % 2 === 0;
801
639
  });
802
640
  expect(data).toEqual([1, 3, 5, 2, 4]);
803
641
  });
804
- it('works when moving one thing', function () {
805
- var data = [1, 2, 3, 4, 5];
642
+ it("works when moving one thing", function () {
643
+ const data = [1, 2, 3, 4, 5];
806
644
  (0, _ui_utils.moveToEndOfArray)(data, function (x) {
807
645
  return x === 1;
808
646
  });
809
647
  expect(data).toEqual([2, 3, 4, 5, 1]);
810
648
  });
811
- it('works when moving nothing', function () {
812
- var data = [1, 2, 3, 4, 5];
649
+ it("works when moving nothing", function () {
650
+ const data = [1, 2, 3, 4, 5];
813
651
  (0, _ui_utils.moveToEndOfArray)(data, function (x) {
814
652
  return x === 0;
815
653
  });