pdfjs-dist 2.0.550 → 2.3.200

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 (168) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +21618 -14369
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +22758 -11399
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +11500 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +767 -258
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +433 -61
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +428 -157
  20. package/lib/core/cmap.js +326 -87
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/core_utils.js +173 -0
  23. package/lib/core/crypto.js +290 -45
  24. package/lib/core/document.js +575 -272
  25. package/lib/core/encodings.js +19 -10
  26. package/lib/core/evaluator.js +1032 -351
  27. package/lib/core/font_renderer.js +331 -97
  28. package/lib/core/fonts.js +813 -196
  29. package/lib/core/function.js +253 -27
  30. package/lib/core/glyphlist.js +5 -3
  31. package/lib/core/image.js +169 -62
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +502 -72
  34. package/lib/core/jbig2_stream.js +19 -8
  35. package/lib/core/jpeg_stream.js +38 -13
  36. package/lib/core/jpg.js +293 -52
  37. package/lib/core/jpx.js +419 -12
  38. package/lib/core/jpx_stream.js +18 -6
  39. package/lib/core/metrics.js +15 -15
  40. package/lib/core/murmurhash3.js +56 -34
  41. package/lib/core/obj.js +1368 -500
  42. package/lib/core/operator_list.js +159 -43
  43. package/lib/core/parser.js +544 -199
  44. package/lib/core/pattern.js +170 -21
  45. package/lib/core/pdf_manager.js +324 -134
  46. package/lib/core/primitives.js +169 -61
  47. package/lib/core/ps_parser.js +134 -45
  48. package/lib/core/standard_fonts.js +17 -17
  49. package/lib/core/stream.js +327 -34
  50. package/lib/core/type1_parser.js +148 -8
  51. package/lib/core/unicode.js +32 -5
  52. package/lib/core/worker.js +215 -229
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +618 -192
  55. package/lib/display/api.js +1798 -882
  56. package/lib/display/api_compatibility.js +5 -10
  57. package/lib/display/canvas.js +366 -45
  58. package/lib/display/content_disposition.js +71 -24
  59. package/lib/display/display_utils.js +777 -0
  60. package/lib/display/fetch_stream.js +205 -87
  61. package/lib/display/font_loader.js +468 -236
  62. package/lib/display/metadata.js +38 -16
  63. package/lib/display/network.js +635 -428
  64. package/lib/display/network_utils.js +38 -19
  65. package/lib/display/node_stream.js +367 -175
  66. package/lib/display/pattern_helper.js +103 -36
  67. package/lib/display/svg.js +1232 -519
  68. package/lib/display/text_layer.js +208 -75
  69. package/lib/display/transport_stream.js +345 -94
  70. package/lib/display/webgl.js +64 -18
  71. package/lib/display/worker_options.js +5 -4
  72. package/lib/display/xml_parser.js +166 -53
  73. package/lib/examples/node/domstubs.js +60 -4
  74. package/lib/pdf.js +35 -14
  75. package/lib/pdf.worker.js +5 -3
  76. package/lib/shared/compatibility.js +170 -572
  77. package/lib/shared/global_scope.js +2 -2
  78. package/lib/shared/is_node.js +4 -4
  79. package/lib/shared/message_handler.js +216 -163
  80. package/lib/shared/streams_polyfill.js +21 -17
  81. package/lib/shared/util.js +495 -385
  82. package/lib/test/unit/annotation_spec.js +1464 -401
  83. package/lib/test/unit/api_spec.js +718 -361
  84. package/lib/test/unit/bidi_spec.js +7 -7
  85. package/lib/test/unit/cff_parser_spec.js +54 -11
  86. package/lib/test/unit/clitests_helper.js +9 -10
  87. package/lib/test/unit/cmap_spec.js +95 -41
  88. package/lib/test/unit/colorspace_spec.js +115 -63
  89. package/lib/test/unit/core_utils_spec.js +191 -0
  90. package/lib/test/unit/crypto_spec.js +17 -5
  91. package/lib/test/unit/custom_spec.js +43 -55
  92. package/lib/test/unit/display_svg_spec.js +34 -18
  93. package/lib/test/unit/display_utils_spec.js +273 -0
  94. package/lib/test/unit/document_spec.js +8 -13
  95. package/lib/test/unit/encodings_spec.js +25 -45
  96. package/lib/test/unit/evaluator_spec.js +59 -20
  97. package/lib/test/unit/fetch_stream_spec.js +111 -0
  98. package/lib/test/unit/function_spec.js +17 -5
  99. package/lib/test/unit/jasmine-boot.js +33 -20
  100. package/lib/test/unit/message_handler_spec.js +30 -13
  101. package/lib/test/unit/metadata_spec.js +71 -11
  102. package/lib/test/unit/murmurhash3_spec.js +3 -3
  103. package/lib/test/unit/network_spec.js +22 -55
  104. package/lib/test/unit/network_utils_spec.js +105 -14
  105. package/lib/test/unit/node_stream_spec.js +58 -34
  106. package/lib/test/unit/parser_spec.js +162 -71
  107. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  108. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  109. package/lib/test/unit/pdf_history_spec.js +21 -9
  110. package/lib/test/unit/primitives_spec.js +55 -22
  111. package/lib/test/unit/stream_spec.js +12 -4
  112. package/lib/test/unit/test_utils.js +273 -56
  113. package/lib/test/unit/testreporter.js +21 -3
  114. package/lib/test/unit/type1_parser_spec.js +9 -7
  115. package/lib/test/unit/ui_utils_spec.js +236 -36
  116. package/lib/test/unit/unicode_spec.js +18 -15
  117. package/lib/test/unit/util_spec.js +87 -128
  118. package/lib/web/annotation_layer_builder.js +39 -22
  119. package/lib/web/app.js +1252 -609
  120. package/lib/web/app_options.js +103 -65
  121. package/lib/web/base_viewer.js +522 -242
  122. package/lib/web/chromecom.js +259 -117
  123. package/lib/web/debugger.js +166 -22
  124. package/lib/web/download_manager.js +31 -12
  125. package/lib/web/firefox_print_service.js +27 -14
  126. package/lib/web/firefoxcom.js +318 -78
  127. package/lib/web/genericcom.js +89 -30
  128. package/lib/web/genericl10n.js +142 -30
  129. package/lib/web/grab_to_pan.js +28 -4
  130. package/lib/web/interfaces.js +174 -47
  131. package/lib/web/overlay_manager.js +235 -85
  132. package/lib/web/password_prompt.js +22 -14
  133. package/lib/web/pdf_attachment_viewer.js +38 -18
  134. package/lib/web/pdf_cursor_tools.js +39 -16
  135. package/lib/web/pdf_document_properties.js +255 -136
  136. package/lib/web/pdf_find_bar.js +84 -40
  137. package/lib/web/pdf_find_controller.js +495 -184
  138. package/lib/web/pdf_find_utils.js +111 -0
  139. package/lib/web/pdf_history.js +190 -53
  140. package/lib/web/pdf_link_service.js +144 -79
  141. package/lib/web/pdf_outline_viewer.js +124 -47
  142. package/lib/web/pdf_page_view.js +194 -74
  143. package/lib/web/pdf_presentation_mode.js +99 -34
  144. package/lib/web/pdf_print_service.js +59 -13
  145. package/lib/web/pdf_rendering_queue.js +28 -9
  146. package/lib/web/pdf_sidebar.js +144 -81
  147. package/lib/web/pdf_sidebar_resizer.js +42 -16
  148. package/lib/web/pdf_single_page_viewer.js +74 -66
  149. package/lib/web/pdf_thumbnail_view.js +104 -33
  150. package/lib/web/pdf_thumbnail_viewer.js +66 -26
  151. package/lib/web/pdf_viewer.component.js +112 -32
  152. package/lib/web/pdf_viewer.js +82 -87
  153. package/lib/web/preferences.js +284 -91
  154. package/lib/web/secondary_toolbar.js +132 -59
  155. package/lib/web/text_layer_builder.js +134 -59
  156. package/lib/web/toolbar.js +80 -43
  157. package/lib/web/ui_utils.js +400 -134
  158. package/lib/web/view_history.js +215 -67
  159. package/lib/web/viewer_compatibility.js +3 -8
  160. package/package.json +3 -2
  161. package/web/pdf_viewer.css +23 -15
  162. package/web/pdf_viewer.js +3429 -1245
  163. package/web/pdf_viewer.js.map +1 -1
  164. package/external/streams/streams-lib.js +0 -3962
  165. package/lib/display/dom_utils.js +0 -429
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
  167. package/lib/test/unit/fonts_spec.js +0 -81
  168. package/lib/web/dom_events.js +0 -137
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2019 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,28 +19,34 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _slicedToArray = function () { function sliceIterator(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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
24
+ var _ui_utils = require("../../web/ui_utils");
25
25
 
26
- var _ui_utils = require('../../web/ui_utils');
26
+ var _util = require("../../shared/util");
27
27
 
28
- var _util = require('../../shared/util');
28
+ var _is_node = _interopRequireDefault(require("../../shared/is_node"));
29
29
 
30
- var _is_node = require('../../shared/is_node');
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
31
31
 
32
- var _is_node2 = _interopRequireDefault(_is_node);
32
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
33
33
 
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
35
39
 
36
40
  describe('ui_utils', function () {
37
41
  describe('binary search', function () {
38
- function isTrue(boolean) {
39
- return boolean;
42
+ function isTrue(_boolean) {
43
+ return _boolean;
40
44
  }
45
+
41
46
  function isGreater3(number) {
42
47
  return number > 3;
43
48
  }
49
+
44
50
  it('empty array', function () {
45
51
  expect((0, _ui_utils.binarySearchFirstItem)([], isTrue)).toEqual(0);
46
52
  });
@@ -74,6 +80,10 @@ describe('ui_utils', function () {
74
80
  expect((0, _ui_utils.getPDFFileNameFromURL)('http://www.example.com/pdfs/file2.txt', 'qwerty2.pdf')).toEqual('qwerty2.pdf');
75
81
  expect((0, _ui_utils.getPDFFileNameFromURL)('/pdfs/file3.txt', '')).toEqual('');
76
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
+ });
77
87
  it('gets PDF filename from URL containing leading/trailing whitespace', function () {
78
88
  expect((0, _ui_utils.getPDFFileNameFromURL)(' /pdfs/file1.pdf ')).toEqual('file1.pdf');
79
89
  expect((0, _ui_utils.getPDFFileNameFromURL)(' http://www.example.com/pdfs/file2.pdf ')).toEqual('file2.pdf');
@@ -107,18 +117,19 @@ describe('ui_utils', function () {
107
117
  expect((0, _ui_utils.getPDFFileNameFromURL)('ftp://www.example.com/file4.pdf')).toEqual('file4.pdf');
108
118
  });
109
119
  it('gets PDF filename from query string appended to "blob:" URL', function () {
110
- if ((0, _is_node2.default)()) {
120
+ if ((0, _is_node["default"])()) {
111
121
  pending('Blob in not supported in Node.js.');
112
122
  }
123
+
113
124
  var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
114
125
  var blobUrl = (0, _util.createObjectURL)(typedArray, 'application/pdf');
115
- expect(blobUrl.indexOf('blob:') === 0).toEqual(true);
126
+ expect(blobUrl.startsWith('blob:')).toEqual(true);
116
127
  expect((0, _ui_utils.getPDFFileNameFromURL)(blobUrl + '?file.pdf')).toEqual('file.pdf');
117
128
  });
118
129
  it('gets fallback filename from query string appended to "data:" URL', function () {
119
130
  var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
120
131
  var dataUrl = (0, _util.createObjectURL)(typedArray, 'application/pdf', true);
121
- expect(dataUrl.indexOf('data:') === 0).toEqual(true);
132
+ expect(dataUrl.startsWith('data:')).toEqual(true);
122
133
  expect((0, _ui_utils.getPDFFileNameFromURL)(dataUrl + '?file1.pdf')).toEqual('document.pdf');
123
134
  expect((0, _ui_utils.getPDFFileNameFromURL)(' ' + dataUrl + '?file2.pdf')).toEqual('document.pdf');
124
135
  });
@@ -127,12 +138,27 @@ describe('ui_utils', function () {
127
138
  it('dispatch event', function () {
128
139
  var eventBus = new _ui_utils.EventBus();
129
140
  var count = 0;
130
- eventBus.on('test', function () {
141
+ eventBus.on('test', function (evt) {
142
+ expect(evt).toEqual(undefined);
131
143
  count++;
132
144
  });
133
145
  eventBus.dispatch('test');
134
146
  expect(count).toEqual(1);
135
147
  });
148
+ it('dispatch event with arguments', function () {
149
+ var eventBus = new _ui_utils.EventBus();
150
+ var count = 0;
151
+ eventBus.on('test', function (evt) {
152
+ expect(evt).toEqual({
153
+ abc: 123
154
+ });
155
+ count++;
156
+ });
157
+ eventBus.dispatch('test', {
158
+ abc: 123
159
+ });
160
+ expect(count).toEqual(1);
161
+ });
136
162
  it('dispatch different event', function () {
137
163
  var eventBus = new _ui_utils.EventBus();
138
164
  var count = 0;
@@ -168,9 +194,11 @@ describe('ui_utils', function () {
168
194
  it('dispatch to detached', function () {
169
195
  var eventBus = new _ui_utils.EventBus();
170
196
  var count = 0;
197
+
171
198
  var listener = function listener() {
172
199
  count++;
173
200
  };
201
+
174
202
  eventBus.on('test', listener);
175
203
  eventBus.dispatch('test');
176
204
  eventBus.off('test', listener);
@@ -193,20 +221,101 @@ describe('ui_utils', function () {
193
221
  it('dispatch to detached during handling', function () {
194
222
  var eventBus = new _ui_utils.EventBus();
195
223
  var count = 0;
224
+
196
225
  var listener1 = function listener1() {
197
226
  eventBus.off('test', listener2);
198
227
  count++;
199
228
  };
229
+
200
230
  var listener2 = function listener2() {
201
231
  eventBus.off('test', listener1);
202
232
  count++;
203
233
  };
234
+
204
235
  eventBus.on('test', listener1);
205
236
  eventBus.on('test', listener2);
206
237
  eventBus.dispatch('test');
207
238
  eventBus.dispatch('test');
208
239
  expect(count).toEqual(2);
209
240
  });
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.');
244
+ }
245
+
246
+ var eventBus = new _ui_utils.EventBus();
247
+ var count = 0;
248
+ eventBus.on('test', function (evt) {
249
+ expect(evt).toEqual(undefined);
250
+ count++;
251
+ });
252
+
253
+ function domEventListener() {
254
+ done.fail('shall not dispatch DOM event.');
255
+ }
256
+
257
+ document.addEventListener('test', domEventListener);
258
+ eventBus.dispatch('test');
259
+ Promise.resolve().then(function () {
260
+ 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);
316
+ done();
317
+ });
318
+ });
210
319
  });
211
320
  describe('isValidRotation', function () {
212
321
  it('should reject non-integer angles', function () {
@@ -247,7 +356,7 @@ describe('ui_utils', function () {
247
356
  });
248
357
  });
249
358
  describe('waitOnEventOrTimeout', function () {
250
- var eventBus = void 0;
359
+ var eventBus;
251
360
  beforeAll(function (done) {
252
361
  eventBus = new _ui_utils.EventBus();
253
362
  done();
@@ -284,9 +393,10 @@ describe('ui_utils', function () {
284
393
  Promise.all([invalidTarget, invalidName, invalidDelay]).then(done, done.fail);
285
394
  });
286
395
  it('should resolve on event, using the DOM', function (done) {
287
- if ((0, _is_node2.default)()) {
396
+ if ((0, _is_node["default"])()) {
288
397
  pending('Document in not supported in Node.js.');
289
398
  }
399
+
290
400
  var button = document.createElement('button');
291
401
  var buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
292
402
  target: button,
@@ -300,9 +410,10 @@ describe('ui_utils', function () {
300
410
  }, done.fail);
301
411
  });
302
412
  it('should resolve on timeout, using the DOM', function (done) {
303
- if ((0, _is_node2.default)()) {
413
+ if ((0, _is_node["default"])()) {
304
414
  pending('Document in not supported in Node.js.');
305
415
  }
416
+
306
417
  var button = document.createElement('button');
307
418
  var buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
308
419
  target: button,
@@ -383,6 +494,7 @@ describe('ui_utils', function () {
383
494
  describe('getVisibleElements', function () {
384
495
  var BORDER_WIDTH = 9;
385
496
  var SPACING = 2 * BORDER_WIDTH - 7;
497
+
386
498
  function makePages(lines) {
387
499
  var result = [];
388
500
  var lineTop = 0,
@@ -394,7 +506,6 @@ describe('ui_utils', function () {
394
506
  try {
395
507
  for (var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
396
508
  var line = _step.value;
397
-
398
509
  var lineHeight = line.reduce(function (maxHeight, pair) {
399
510
  return Math.max(maxHeight, pair[1]);
400
511
  }, 0);
@@ -405,12 +516,9 @@ describe('ui_utils', function () {
405
516
 
406
517
  try {
407
518
  for (var _iterator2 = line[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
408
- var _ref = _step2.value;
409
-
410
- var _ref2 = _slicedToArray(_ref, 2);
411
-
412
- var clientWidth = _ref2[0];
413
- var clientHeight = _ref2[1];
519
+ var _step2$value = _slicedToArray(_step2.value, 2),
520
+ clientWidth = _step2$value[0],
521
+ clientHeight = _step2$value[1];
414
522
 
415
523
  var offsetTop = lineTop + (lineHeight - clientHeight) / 2 - BORDER_WIDTH;
416
524
  var div = {
@@ -433,8 +541,8 @@ describe('ui_utils', function () {
433
541
  _iteratorError2 = err;
434
542
  } finally {
435
543
  try {
436
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
437
- _iterator2.return();
544
+ if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
545
+ _iterator2["return"]();
438
546
  }
439
547
  } finally {
440
548
  if (_didIteratorError2) {
@@ -450,8 +558,8 @@ describe('ui_utils', function () {
450
558
  _iteratorError = err;
451
559
  } finally {
452
560
  try {
453
- if (!_iteratorNormalCompletion && _iterator.return) {
454
- _iterator.return();
561
+ if (!_iteratorNormalCompletion && _iterator["return"] != null) {
562
+ _iterator["return"]();
455
563
  }
456
564
  } finally {
457
565
  if (_didIteratorError) {
@@ -462,11 +570,11 @@ describe('ui_utils', function () {
462
570
 
463
571
  return result;
464
572
  }
573
+
465
574
  function slowGetVisibleElements(scroll, pages) {
466
575
  var views = [];
467
576
  var scrollLeft = scroll.scrollLeft,
468
577
  scrollTop = scroll.scrollTop;
469
-
470
578
  var scrollRight = scrollLeft + scroll.clientWidth;
471
579
  var scrollBottom = scrollTop + scroll.clientHeight;
472
580
  var _iteratorNormalCompletion3 = true;
@@ -477,11 +585,11 @@ describe('ui_utils', function () {
477
585
  for (var _iterator3 = pages[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
478
586
  var view = _step3.value;
479
587
  var div = view.div;
480
-
481
588
  var viewLeft = div.offsetLeft + div.clientLeft;
482
589
  var viewRight = viewLeft + div.clientWidth;
483
590
  var viewTop = div.offsetTop + div.clientTop;
484
591
  var viewBottom = viewTop + div.clientHeight;
592
+
485
593
  if (viewLeft < scrollRight && viewRight > scrollLeft && viewTop < scrollBottom && viewBottom > scrollTop) {
486
594
  var hiddenHeight = Math.max(0, scrollTop - viewTop) + Math.max(0, viewBottom - scrollBottom);
487
595
  var hiddenWidth = Math.max(0, scrollLeft - viewLeft) + Math.max(0, viewRight - scrollRight);
@@ -501,8 +609,8 @@ describe('ui_utils', function () {
501
609
  _iteratorError3 = err;
502
610
  } finally {
503
611
  try {
504
- if (!_iteratorNormalCompletion3 && _iterator3.return) {
505
- _iterator3.return();
612
+ if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
613
+ _iterator3["return"]();
506
614
  }
507
615
  } finally {
508
616
  if (_didIteratorError3) {
@@ -517,14 +625,14 @@ describe('ui_utils', function () {
517
625
  views: views
518
626
  };
519
627
  }
628
+
520
629
  function scrollOverDocument(pages) {
521
630
  var horizontally = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
522
-
523
- var size = pages.reduce(function (max, _ref3) {
524
- var div = _ref3.div;
525
-
631
+ var size = pages.reduce(function (max, _ref) {
632
+ var div = _ref.div;
526
633
  return Math.max(max, horizontally ? div.offsetLeft + div.clientLeft + div.clientWidth : div.offsetTop + div.clientTop + div.clientHeight);
527
634
  }, 0);
635
+
528
636
  for (var i = 0; i < size; i += 7) {
529
637
  for (var j = i + 5; j < size; j += j - i) {
530
638
  var scroll = horizontally ? {
@@ -542,6 +650,7 @@ describe('ui_utils', function () {
542
650
  }
543
651
  }
544
652
  }
653
+
545
654
  it('with pages of varying height', function () {
546
655
  var pages = makePages([[[50, 20], [20, 50]], [[30, 12], [12, 30]], [[20, 50], [50, 20]], [[50, 20], [20, 50]]]);
547
656
  scrollOverDocument(pages);
@@ -554,6 +663,97 @@ describe('ui_utils', function () {
554
663
  var pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
555
664
  scrollOverDocument(pages, true);
556
665
  });
666
+ it('handles `sortByVisibility` correctly', function () {
667
+ var scrollEl = {
668
+ scrollTop: 75,
669
+ scrollLeft: 0,
670
+ clientHeight: 750,
671
+ clientWidth: 1500
672
+ };
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
+ }
700
+ }
701
+
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
+ }
724
+ }
725
+
726
+ expect(viewsOrder).toEqual([0, 1, 2]);
727
+ expect(viewsSortedOrder).toEqual([1, 2, 0]);
728
+ });
729
+ it('handles views being empty', function () {
730
+ var scrollEl = {
731
+ scrollTop: 10,
732
+ scrollLeft: 0,
733
+ clientHeight: 750,
734
+ clientWidth: 1500
735
+ };
736
+ var views = [];
737
+ expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
738
+ first: undefined,
739
+ last: undefined,
740
+ views: []
741
+ });
742
+ });
743
+ it('handles all views being hidden (without errors)', function () {
744
+ var scrollEl = {
745
+ scrollTop: 100000,
746
+ scrollLeft: 0,
747
+ clientHeight: 750,
748
+ clientWidth: 1500
749
+ };
750
+ var views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
751
+ expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
752
+ first: undefined,
753
+ last: undefined,
754
+ views: []
755
+ });
756
+ });
557
757
  describe('backtrackBeforeAllVisibleElements', function () {
558
758
  var tallPage = [10, 50];
559
759
  var shortPage = [10, 10];
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2019 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,11 +19,11 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _glyphlist = require('../../core/glyphlist');
24
+ var _glyphlist = require("../../core/glyphlist");
25
25
 
26
- var _unicode = require('../../core/unicode');
26
+ var _unicode = require("../../core/unicode");
27
27
 
28
28
  describe('unicode', function () {
29
29
  describe('mapSpecialUnicodeValues', function () {
@@ -80,8 +80,8 @@ describe('unicode', function () {
80
80
  NormalizedUnicodes = null;
81
81
  });
82
82
  it('should get normalized Unicode values for ligatures', function () {
83
- expect(NormalizedUnicodes['\uFB01']).toEqual('fi');
84
- expect(NormalizedUnicodes['\u0675']).toEqual('\u0627\u0674');
83
+ expect(NormalizedUnicodes["\uFB01"]).toEqual('fi');
84
+ expect(NormalizedUnicodes["\u0675"]).toEqual("\u0627\u0674");
85
85
  });
86
86
  it('should not normalize standard characters', function () {
87
87
  expect(NormalizedUnicodes['A']).toEqual(undefined);
@@ -89,12 +89,15 @@ describe('unicode', function () {
89
89
  });
90
90
  describe('reverseIfRtl', function () {
91
91
  var NormalizedUnicodes;
92
- function getGlyphUnicode(char) {
93
- if (NormalizedUnicodes[char] !== undefined) {
94
- return NormalizedUnicodes[char];
92
+
93
+ function getGlyphUnicode(_char) {
94
+ if (NormalizedUnicodes[_char] !== undefined) {
95
+ return NormalizedUnicodes[_char];
95
96
  }
96
- return char;
97
+
98
+ return _char;
97
99
  }
100
+
98
101
  beforeAll(function (done) {
99
102
  NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
100
103
  done();
@@ -105,14 +108,14 @@ describe('unicode', function () {
105
108
  it('should not reverse LTR characters', function () {
106
109
  var A = getGlyphUnicode('A');
107
110
  expect((0, _unicode.reverseIfRtl)(A)).toEqual('A');
108
- var fi = getGlyphUnicode('\uFB01');
111
+ var fi = getGlyphUnicode("\uFB01");
109
112
  expect((0, _unicode.reverseIfRtl)(fi)).toEqual('fi');
110
113
  });
111
114
  it('should reverse RTL characters', function () {
112
- var heAlef = getGlyphUnicode('\u05D0');
113
- expect((0, _unicode.reverseIfRtl)(heAlef)).toEqual('\u05D0');
114
- var arAlef = getGlyphUnicode('\u0675');
115
- expect((0, _unicode.reverseIfRtl)(arAlef)).toEqual('\u0674\u0627');
115
+ var heAlef = getGlyphUnicode("\u05D0");
116
+ expect((0, _unicode.reverseIfRtl)(heAlef)).toEqual("\u05D0");
117
+ var arAlef = getGlyphUnicode("\u0675");
118
+ expect((0, _unicode.reverseIfRtl)(arAlef)).toEqual("\u0674\u0627");
116
119
  });
117
120
  });
118
121
  });