pdfjs-dist 2.0.943 → 2.1.266
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/bower.json +1 -1
- package/build/pdf.js +15329 -11095
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +12497 -4184
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +3438 -1209
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +335 -109
- package/lib/core/arithmetic_decoder.js +274 -244
- package/lib/core/bidi.js +64 -5
- package/lib/core/ccitt.js +172 -17
- package/lib/core/ccitt_stream.js +14 -5
- package/lib/core/cff_parser.js +304 -28
- package/lib/core/charsets.js +4 -3
- package/lib/core/chunked_stream.js +379 -149
- package/lib/core/cmap.js +210 -40
- package/lib/core/colorspace.js +332 -187
- package/lib/core/crypto.js +289 -44
- package/lib/core/document.js +508 -249
- package/lib/core/encodings.js +18 -9
- package/lib/core/evaluator.js +657 -119
- package/lib/core/font_renderer.js +217 -34
- package/lib/core/fonts.js +632 -41
- package/lib/core/function.js +252 -26
- package/lib/core/glyphlist.js +2 -1
- package/lib/core/image.js +124 -27
- package/lib/core/jbig2.js +425 -65
- package/lib/core/jbig2_stream.js +18 -7
- package/lib/core/jpeg_stream.js +24 -8
- package/lib/core/jpg.js +208 -16
- package/lib/core/jpx.js +395 -5
- package/lib/core/jpx_stream.js +17 -5
- package/lib/core/metrics.js +3 -3
- package/lib/core/murmurhash3.js +23 -5
- package/lib/core/obj.js +625 -132
- package/lib/core/operator_list.js +104 -3
- package/lib/core/parser.js +262 -25
- package/lib/core/pattern.js +144 -12
- package/lib/core/pdf_manager.js +104 -70
- package/lib/core/primitives.js +74 -21
- package/lib/core/ps_parser.js +133 -44
- package/lib/core/standard_fonts.js +9 -9
- package/lib/core/stream.js +283 -31
- package/lib/core/type1_parser.js +138 -6
- package/lib/core/unicode.js +28 -1
- package/lib/core/worker.js +192 -57
- package/lib/display/annotation_layer.js +303 -123
- package/lib/display/api.js +1073 -574
- package/lib/display/api_compatibility.js +4 -1
- package/lib/display/canvas.js +314 -18
- package/lib/display/content_disposition.js +70 -23
- package/lib/display/dom_utils.js +112 -59
- package/lib/display/fetch_stream.js +95 -50
- package/lib/display/font_loader.js +250 -132
- package/lib/display/metadata.js +37 -15
- package/lib/display/network.js +123 -34
- package/lib/display/network_utils.js +23 -10
- package/lib/display/node_stream.js +162 -65
- package/lib/display/pattern_helper.js +57 -6
- package/lib/display/svg.js +194 -18
- package/lib/display/text_layer.js +128 -14
- package/lib/display/transport_stream.js +83 -27
- package/lib/display/webgl.js +63 -17
- package/lib/display/worker_options.js +4 -3
- package/lib/display/xml_parser.js +162 -52
- package/lib/examples/node/domstubs.js +56 -3
- package/lib/pdf.js +15 -2
- package/lib/pdf.worker.js +4 -2
- package/lib/shared/compatibility.js +129 -26
- package/lib/shared/global_scope.js +1 -1
- package/lib/shared/is_node.js +3 -3
- package/lib/shared/message_handler.js +103 -45
- package/lib/shared/streams_polyfill.js +20 -16
- package/lib/shared/url_polyfill.js +8 -2
- package/lib/shared/util.js +246 -84
- package/lib/test/unit/annotation_spec.js +99 -73
- package/lib/test/unit/api_spec.js +347 -113
- package/lib/test/unit/bidi_spec.js +6 -6
- package/lib/test/unit/cff_parser_spec.js +17 -5
- package/lib/test/unit/clitests_helper.js +7 -8
- package/lib/test/unit/cmap_spec.js +79 -25
- package/lib/test/unit/colorspace_spec.js +65 -18
- package/lib/test/unit/crypto_spec.js +16 -4
- package/lib/test/unit/custom_spec.js +40 -52
- package/lib/test/unit/display_svg_spec.js +32 -16
- package/lib/test/unit/document_spec.js +2 -2
- package/lib/test/unit/dom_utils_spec.js +8 -8
- package/lib/test/unit/encodings_spec.js +24 -44
- package/lib/test/unit/evaluator_spec.js +15 -8
- package/lib/test/unit/function_spec.js +16 -4
- package/lib/test/unit/jasmine-boot.js +29 -16
- package/lib/test/unit/message_handler_spec.js +19 -6
- package/lib/test/unit/metadata_spec.js +64 -11
- package/lib/test/unit/murmurhash3_spec.js +2 -2
- package/lib/test/unit/network_spec.js +19 -4
- package/lib/test/unit/network_utils_spec.js +6 -4
- package/lib/test/unit/node_stream_spec.js +50 -26
- package/lib/test/unit/parser_spec.js +13 -29
- package/lib/test/unit/pdf_find_controller_spec.js +144 -32
- package/lib/test/unit/pdf_find_utils_spec.js +10 -9
- package/lib/test/unit/pdf_history_spec.js +20 -8
- package/lib/test/unit/primitives_spec.js +23 -3
- package/lib/test/unit/stream_spec.js +8 -3
- package/lib/test/unit/test_utils.js +89 -26
- package/lib/test/unit/testreporter.js +19 -1
- package/lib/test/unit/type1_parser_spec.js +7 -5
- package/lib/test/unit/ui_utils_spec.js +162 -38
- package/lib/test/unit/unicode_spec.js +13 -10
- package/lib/test/unit/util_spec.js +89 -9
- package/lib/web/annotation_layer_builder.js +38 -21
- package/lib/web/app.js +610 -245
- package/lib/web/app_options.js +54 -34
- package/lib/web/base_viewer.js +359 -162
- package/lib/web/chromecom.js +159 -80
- package/lib/web/debugger.js +161 -17
- package/lib/web/download_manager.js +29 -11
- package/lib/web/firefox_print_service.js +16 -8
- package/lib/web/firefoxcom.js +127 -91
- package/lib/web/genericcom.js +50 -31
- package/lib/web/genericl10n.js +46 -34
- package/lib/web/grab_to_pan.js +25 -3
- package/lib/web/interfaces.js +108 -61
- package/lib/web/overlay_manager.js +67 -45
- package/lib/web/password_prompt.js +20 -12
- package/lib/web/pdf_attachment_viewer.js +37 -17
- package/lib/web/pdf_cursor_tools.js +38 -15
- package/lib/web/pdf_document_properties.js +65 -24
- package/lib/web/pdf_find_bar.js +48 -20
- package/lib/web/pdf_find_controller.js +290 -89
- package/lib/web/pdf_find_utils.js +19 -3
- package/lib/web/pdf_history.js +186 -49
- package/lib/web/pdf_link_service.js +127 -52
- package/lib/web/pdf_outline_viewer.js +71 -21
- package/lib/web/pdf_page_view.js +188 -63
- package/lib/web/pdf_presentation_mode.js +98 -33
- package/lib/web/pdf_print_service.js +54 -10
- package/lib/web/pdf_rendering_queue.js +26 -4
- package/lib/web/pdf_sidebar.js +116 -62
- package/lib/web/pdf_sidebar_resizer.js +41 -15
- package/lib/web/pdf_single_page_viewer.js +65 -68
- package/lib/web/pdf_thumbnail_view.js +102 -31
- package/lib/web/pdf_thumbnail_viewer.js +62 -22
- package/lib/web/pdf_viewer.component.js +111 -31
- package/lib/web/pdf_viewer.js +80 -60
- package/lib/web/preferences.js +61 -39
- package/lib/web/secondary_toolbar.js +101 -82
- package/lib/web/text_layer_builder.js +124 -69
- package/lib/web/toolbar.js +67 -27
- package/lib/web/ui_utils.js +284 -128
- package/lib/web/view_history.js +75 -51
- package/lib/web/viewer_compatibility.js +2 -1
- package/package.json +1 -1
- package/web/pdf_viewer.css +1 -1
- package/web/pdf_viewer.js +2200 -973
- package/web/pdf_viewer.js.map +1 -1
- package/lib/web/dom_events.js +0 -140
@@ -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
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var
|
24
|
+
var _ui_utils = require("../../web/ui_utils");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _util = require("../../shared/util");
|
27
27
|
|
28
|
-
var
|
28
|
+
var _is_node = _interopRequireDefault(require("../../shared/is_node"));
|
29
29
|
|
30
|
-
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
31
|
|
32
|
-
|
32
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
33
33
|
|
34
|
-
function
|
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; }
|
35
39
|
|
36
40
|
describe('ui_utils', function () {
|
37
41
|
describe('binary search', function () {
|
38
42
|
function isTrue(boolean) {
|
39
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
|
});
|
@@ -111,18 +117,19 @@ describe('ui_utils', function () {
|
|
111
117
|
expect((0, _ui_utils.getPDFFileNameFromURL)('ftp://www.example.com/file4.pdf')).toEqual('file4.pdf');
|
112
118
|
});
|
113
119
|
it('gets PDF filename from query string appended to "blob:" URL', function () {
|
114
|
-
if ((0,
|
120
|
+
if ((0, _is_node.default)()) {
|
115
121
|
pending('Blob in not supported in Node.js.');
|
116
122
|
}
|
123
|
+
|
117
124
|
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
118
125
|
var blobUrl = (0, _util.createObjectURL)(typedArray, 'application/pdf');
|
119
|
-
expect(blobUrl.
|
126
|
+
expect(blobUrl.startsWith('blob:')).toEqual(true);
|
120
127
|
expect((0, _ui_utils.getPDFFileNameFromURL)(blobUrl + '?file.pdf')).toEqual('file.pdf');
|
121
128
|
});
|
122
129
|
it('gets fallback filename from query string appended to "data:" URL', function () {
|
123
130
|
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
|
124
131
|
var dataUrl = (0, _util.createObjectURL)(typedArray, 'application/pdf', true);
|
125
|
-
expect(dataUrl.
|
132
|
+
expect(dataUrl.startsWith('data:')).toEqual(true);
|
126
133
|
expect((0, _ui_utils.getPDFFileNameFromURL)(dataUrl + '?file1.pdf')).toEqual('document.pdf');
|
127
134
|
expect((0, _ui_utils.getPDFFileNameFromURL)(' ' + dataUrl + '?file2.pdf')).toEqual('document.pdf');
|
128
135
|
});
|
@@ -142,10 +149,14 @@ describe('ui_utils', function () {
|
|
142
149
|
var eventBus = new _ui_utils.EventBus();
|
143
150
|
var count = 0;
|
144
151
|
eventBus.on('test', function (evt) {
|
145
|
-
expect(evt).toEqual({
|
152
|
+
expect(evt).toEqual({
|
153
|
+
abc: 123
|
154
|
+
});
|
146
155
|
count++;
|
147
156
|
});
|
148
|
-
eventBus.dispatch('test', {
|
157
|
+
eventBus.dispatch('test', {
|
158
|
+
abc: 123
|
159
|
+
});
|
149
160
|
expect(count).toEqual(1);
|
150
161
|
});
|
151
162
|
it('dispatch different event', function () {
|
@@ -183,9 +194,11 @@ describe('ui_utils', function () {
|
|
183
194
|
it('dispatch to detached', function () {
|
184
195
|
var eventBus = new _ui_utils.EventBus();
|
185
196
|
var count = 0;
|
197
|
+
|
186
198
|
var listener = function listener() {
|
187
199
|
count++;
|
188
200
|
};
|
201
|
+
|
189
202
|
eventBus.on('test', listener);
|
190
203
|
eventBus.dispatch('test');
|
191
204
|
eventBus.off('test', listener);
|
@@ -208,14 +221,17 @@ describe('ui_utils', function () {
|
|
208
221
|
it('dispatch to detached during handling', function () {
|
209
222
|
var eventBus = new _ui_utils.EventBus();
|
210
223
|
var count = 0;
|
224
|
+
|
211
225
|
var listener1 = function listener1() {
|
212
226
|
eventBus.off('test', listener2);
|
213
227
|
count++;
|
214
228
|
};
|
229
|
+
|
215
230
|
var listener2 = function listener2() {
|
216
231
|
eventBus.off('test', listener1);
|
217
232
|
count++;
|
218
233
|
};
|
234
|
+
|
219
235
|
eventBus.on('test', listener1);
|
220
236
|
eventBus.on('test', listener2);
|
221
237
|
eventBus.dispatch('test');
|
@@ -223,18 +239,21 @@ describe('ui_utils', function () {
|
|
223
239
|
expect(count).toEqual(2);
|
224
240
|
});
|
225
241
|
it('should not, by default, re-dispatch to DOM', function (done) {
|
226
|
-
if ((0,
|
242
|
+
if ((0, _is_node.default)()) {
|
227
243
|
pending('Document in not supported in Node.js.');
|
228
244
|
}
|
245
|
+
|
229
246
|
var eventBus = new _ui_utils.EventBus();
|
230
247
|
var count = 0;
|
231
248
|
eventBus.on('test', function (evt) {
|
232
249
|
expect(evt).toEqual(undefined);
|
233
250
|
count++;
|
234
251
|
});
|
252
|
+
|
235
253
|
function domEventListener() {
|
236
254
|
done.fail('shall not dispatch DOM event.');
|
237
255
|
}
|
256
|
+
|
238
257
|
document.addEventListener('test', domEventListener);
|
239
258
|
eventBus.dispatch('test');
|
240
259
|
Promise.resolve().then(function () {
|
@@ -244,19 +263,24 @@ describe('ui_utils', function () {
|
|
244
263
|
});
|
245
264
|
});
|
246
265
|
it('should re-dispatch to DOM', function (done) {
|
247
|
-
if ((0,
|
266
|
+
if ((0, _is_node.default)()) {
|
248
267
|
pending('Document in not supported in Node.js.');
|
249
268
|
}
|
250
|
-
|
269
|
+
|
270
|
+
var eventBus = new _ui_utils.EventBus({
|
271
|
+
dispatchToDOM: true
|
272
|
+
});
|
251
273
|
var count = 0;
|
252
274
|
eventBus.on('test', function (evt) {
|
253
275
|
expect(evt).toEqual(undefined);
|
254
276
|
count++;
|
255
277
|
});
|
278
|
+
|
256
279
|
function domEventListener(evt) {
|
257
280
|
expect(evt.detail).toEqual({});
|
258
281
|
count++;
|
259
282
|
}
|
283
|
+
|
260
284
|
document.addEventListener('test', domEventListener);
|
261
285
|
eventBus.dispatch('test');
|
262
286
|
Promise.resolve().then(function () {
|
@@ -266,17 +290,26 @@ describe('ui_utils', function () {
|
|
266
290
|
});
|
267
291
|
});
|
268
292
|
it('should re-dispatch to DOM, with arguments (without internal listeners)', function (done) {
|
269
|
-
if ((0,
|
293
|
+
if ((0, _is_node.default)()) {
|
270
294
|
pending('Document in not supported in Node.js.');
|
271
295
|
}
|
272
|
-
|
296
|
+
|
297
|
+
var eventBus = new _ui_utils.EventBus({
|
298
|
+
dispatchToDOM: true
|
299
|
+
});
|
273
300
|
var count = 0;
|
301
|
+
|
274
302
|
function domEventListener(evt) {
|
275
|
-
expect(evt.detail).toEqual({
|
303
|
+
expect(evt.detail).toEqual({
|
304
|
+
abc: 123
|
305
|
+
});
|
276
306
|
count++;
|
277
307
|
}
|
308
|
+
|
278
309
|
document.addEventListener('test', domEventListener);
|
279
|
-
eventBus.dispatch('test', {
|
310
|
+
eventBus.dispatch('test', {
|
311
|
+
abc: 123
|
312
|
+
});
|
280
313
|
Promise.resolve().then(function () {
|
281
314
|
expect(count).toEqual(1);
|
282
315
|
document.removeEventListener('test', domEventListener);
|
@@ -323,7 +356,7 @@ describe('ui_utils', function () {
|
|
323
356
|
});
|
324
357
|
});
|
325
358
|
describe('waitOnEventOrTimeout', function () {
|
326
|
-
var eventBus
|
359
|
+
var eventBus;
|
327
360
|
beforeAll(function (done) {
|
328
361
|
eventBus = new _ui_utils.EventBus();
|
329
362
|
done();
|
@@ -360,9 +393,10 @@ describe('ui_utils', function () {
|
|
360
393
|
Promise.all([invalidTarget, invalidName, invalidDelay]).then(done, done.fail);
|
361
394
|
});
|
362
395
|
it('should resolve on event, using the DOM', function (done) {
|
363
|
-
if ((0,
|
396
|
+
if ((0, _is_node.default)()) {
|
364
397
|
pending('Document in not supported in Node.js.');
|
365
398
|
}
|
399
|
+
|
366
400
|
var button = document.createElement('button');
|
367
401
|
var buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
368
402
|
target: button,
|
@@ -376,9 +410,10 @@ describe('ui_utils', function () {
|
|
376
410
|
}, done.fail);
|
377
411
|
});
|
378
412
|
it('should resolve on timeout, using the DOM', function (done) {
|
379
|
-
if ((0,
|
413
|
+
if ((0, _is_node.default)()) {
|
380
414
|
pending('Document in not supported in Node.js.');
|
381
415
|
}
|
416
|
+
|
382
417
|
var button = document.createElement('button');
|
383
418
|
var buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
|
384
419
|
target: button,
|
@@ -459,6 +494,7 @@ describe('ui_utils', function () {
|
|
459
494
|
describe('getVisibleElements', function () {
|
460
495
|
var BORDER_WIDTH = 9;
|
461
496
|
var SPACING = 2 * BORDER_WIDTH - 7;
|
497
|
+
|
462
498
|
function makePages(lines) {
|
463
499
|
var result = [];
|
464
500
|
var lineTop = 0,
|
@@ -470,7 +506,6 @@ describe('ui_utils', function () {
|
|
470
506
|
try {
|
471
507
|
for (var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
472
508
|
var line = _step.value;
|
473
|
-
|
474
509
|
var lineHeight = line.reduce(function (maxHeight, pair) {
|
475
510
|
return Math.max(maxHeight, pair[1]);
|
476
511
|
}, 0);
|
@@ -481,12 +516,9 @@ describe('ui_utils', function () {
|
|
481
516
|
|
482
517
|
try {
|
483
518
|
for (var _iterator2 = line[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
484
|
-
var
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
var clientWidth = _ref2[0];
|
489
|
-
var clientHeight = _ref2[1];
|
519
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
520
|
+
clientWidth = _step2$value[0],
|
521
|
+
clientHeight = _step2$value[1];
|
490
522
|
|
491
523
|
var offsetTop = lineTop + (lineHeight - clientHeight) / 2 - BORDER_WIDTH;
|
492
524
|
var div = {
|
@@ -509,7 +541,7 @@ describe('ui_utils', function () {
|
|
509
541
|
_iteratorError2 = err;
|
510
542
|
} finally {
|
511
543
|
try {
|
512
|
-
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
544
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
513
545
|
_iterator2.return();
|
514
546
|
}
|
515
547
|
} finally {
|
@@ -526,7 +558,7 @@ describe('ui_utils', function () {
|
|
526
558
|
_iteratorError = err;
|
527
559
|
} finally {
|
528
560
|
try {
|
529
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
561
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
530
562
|
_iterator.return();
|
531
563
|
}
|
532
564
|
} finally {
|
@@ -538,11 +570,11 @@ describe('ui_utils', function () {
|
|
538
570
|
|
539
571
|
return result;
|
540
572
|
}
|
573
|
+
|
541
574
|
function slowGetVisibleElements(scroll, pages) {
|
542
575
|
var views = [];
|
543
576
|
var scrollLeft = scroll.scrollLeft,
|
544
577
|
scrollTop = scroll.scrollTop;
|
545
|
-
|
546
578
|
var scrollRight = scrollLeft + scroll.clientWidth;
|
547
579
|
var scrollBottom = scrollTop + scroll.clientHeight;
|
548
580
|
var _iteratorNormalCompletion3 = true;
|
@@ -553,11 +585,11 @@ describe('ui_utils', function () {
|
|
553
585
|
for (var _iterator3 = pages[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
554
586
|
var view = _step3.value;
|
555
587
|
var div = view.div;
|
556
|
-
|
557
588
|
var viewLeft = div.offsetLeft + div.clientLeft;
|
558
589
|
var viewRight = viewLeft + div.clientWidth;
|
559
590
|
var viewTop = div.offsetTop + div.clientTop;
|
560
591
|
var viewBottom = viewTop + div.clientHeight;
|
592
|
+
|
561
593
|
if (viewLeft < scrollRight && viewRight > scrollLeft && viewTop < scrollBottom && viewBottom > scrollTop) {
|
562
594
|
var hiddenHeight = Math.max(0, scrollTop - viewTop) + Math.max(0, viewBottom - scrollBottom);
|
563
595
|
var hiddenWidth = Math.max(0, scrollLeft - viewLeft) + Math.max(0, viewRight - scrollRight);
|
@@ -577,7 +609,7 @@ describe('ui_utils', function () {
|
|
577
609
|
_iteratorError3 = err;
|
578
610
|
} finally {
|
579
611
|
try {
|
580
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
612
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
581
613
|
_iterator3.return();
|
582
614
|
}
|
583
615
|
} finally {
|
@@ -593,14 +625,14 @@ describe('ui_utils', function () {
|
|
593
625
|
views: views
|
594
626
|
};
|
595
627
|
}
|
628
|
+
|
596
629
|
function scrollOverDocument(pages) {
|
597
630
|
var horizontally = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
598
|
-
|
599
|
-
|
600
|
-
var div = _ref3.div;
|
601
|
-
|
631
|
+
var size = pages.reduce(function (max, _ref) {
|
632
|
+
var div = _ref.div;
|
602
633
|
return Math.max(max, horizontally ? div.offsetLeft + div.clientLeft + div.clientWidth : div.offsetTop + div.clientTop + div.clientHeight);
|
603
634
|
}, 0);
|
635
|
+
|
604
636
|
for (var i = 0; i < size; i += 7) {
|
605
637
|
for (var j = i + 5; j < size; j += j - i) {
|
606
638
|
var scroll = horizontally ? {
|
@@ -618,6 +650,7 @@ describe('ui_utils', function () {
|
|
618
650
|
}
|
619
651
|
}
|
620
652
|
}
|
653
|
+
|
621
654
|
it('with pages of varying height', function () {
|
622
655
|
var pages = makePages([[[50, 20], [20, 50]], [[30, 12], [12, 30]], [[20, 50], [50, 20]], [[50, 20], [20, 50]]]);
|
623
656
|
scrollOverDocument(pages);
|
@@ -630,6 +663,97 @@ describe('ui_utils', function () {
|
|
630
663
|
var pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
|
631
664
|
scrollOverDocument(pages, true);
|
632
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
|
+
});
|
633
757
|
describe('backtrackBeforeAllVisibleElements', function () {
|
634
758
|
var tallPage = [10, 50];
|
635
759
|
var shortPage = [10, 10];
|
@@ -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
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var _glyphlist = require(
|
24
|
+
var _glyphlist = require("../../core/glyphlist");
|
25
25
|
|
26
|
-
var _unicode = require(
|
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[
|
84
|
-
expect(NormalizedUnicodes[
|
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
|
+
|
92
93
|
function getGlyphUnicode(char) {
|
93
94
|
if (NormalizedUnicodes[char] !== undefined) {
|
94
95
|
return NormalizedUnicodes[char];
|
95
96
|
}
|
97
|
+
|
96
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(
|
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(
|
113
|
-
expect((0, _unicode.reverseIfRtl)(heAlef)).toEqual(
|
114
|
-
var arAlef = getGlyphUnicode(
|
115
|
-
expect((0, _unicode.reverseIfRtl)(arAlef)).toEqual(
|
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
|
});
|
@@ -19,15 +19,15 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var
|
24
|
+
var _util = require("../../shared/util");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _primitives = require("../../core/primitives");
|
27
27
|
|
28
|
-
var
|
28
|
+
var _test_utils = require("./test_utils");
|
29
29
|
|
30
|
-
|
30
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
31
31
|
|
32
32
|
describe('util', function () {
|
33
33
|
describe('bytesToString', function () {
|
@@ -43,9 +43,11 @@ describe('util', function () {
|
|
43
43
|
it('handles array arguments with a length exceeding the maximum', function () {
|
44
44
|
var length = 10000;
|
45
45
|
var bytes = new Uint8Array(length);
|
46
|
+
|
46
47
|
for (var i = 0; i < length; i++) {
|
47
48
|
bytes[i] = 'a'.charCodeAt(0);
|
48
49
|
}
|
50
|
+
|
49
51
|
var string = Array(length + 1).join('a');
|
50
52
|
expect((0, _util.bytesToString)(bytes)).toEqual(string);
|
51
53
|
});
|
@@ -148,11 +150,13 @@ describe('util', function () {
|
|
148
150
|
var dict = new _primitives.Dict();
|
149
151
|
var currentDict = dict;
|
150
152
|
var parentDict = null;
|
153
|
+
|
151
154
|
for (var i = 0; i < 150; i++) {
|
152
155
|
parentDict = new _primitives.Dict();
|
153
156
|
currentDict.set('Parent', parentDict);
|
154
157
|
currentDict = parentDict;
|
155
158
|
}
|
159
|
+
|
156
160
|
parentDict.set('foo', 'bar');
|
157
161
|
expect((0, _util.getInheritableProperty)({
|
158
162
|
dict: dict,
|
@@ -198,7 +202,9 @@ describe('util', function () {
|
|
198
202
|
expect((0, _util.isEmptyObj)({})).toEqual(true);
|
199
203
|
});
|
200
204
|
it('handles non-empty objects', function () {
|
201
|
-
expect((0, _util.isEmptyObj)({
|
205
|
+
expect((0, _util.isEmptyObj)({
|
206
|
+
foo: 'bar'
|
207
|
+
})).toEqual(false);
|
202
208
|
});
|
203
209
|
});
|
204
210
|
describe('isNum', function () {
|
@@ -253,6 +259,13 @@ describe('util', function () {
|
|
253
259
|
expect((0, _util.log2)(3.14)).toEqual(2);
|
254
260
|
});
|
255
261
|
});
|
262
|
+
describe('string32', function () {
|
263
|
+
it('converts unsigned 32-bit integers to strings', function () {
|
264
|
+
expect((0, _util.string32)(0x74727565)).toEqual('true');
|
265
|
+
expect((0, _util.string32)(0x74797031)).toEqual('typ1');
|
266
|
+
expect((0, _util.string32)(0x4F54544F)).toEqual('OTTO');
|
267
|
+
});
|
268
|
+
});
|
256
269
|
describe('stringToBytes', function () {
|
257
270
|
it('handles non-string arguments', function () {
|
258
271
|
expect(function () {
|
@@ -267,7 +280,7 @@ describe('util', function () {
|
|
267
280
|
describe('stringToPDFString', function () {
|
268
281
|
it('handles ISO Latin 1 strings', function () {
|
269
282
|
var str = '\x8Dstring\x8E';
|
270
|
-
expect((0, _util.stringToPDFString)(str)).toEqual(
|
283
|
+
expect((0, _util.stringToPDFString)(str)).toEqual("\u201Cstring\u201D");
|
271
284
|
});
|
272
285
|
it('handles UTF-16BE strings', function () {
|
273
286
|
var str = '\xFE\xFF\x00\x73\x00\x74\x00\x72\x00\x69\x00\x6E\x00\x67';
|
@@ -293,17 +306,57 @@ describe('util', function () {
|
|
293
306
|
describe('ReadableStream', function () {
|
294
307
|
it('should return an Object', function () {
|
295
308
|
var readable = new _util.ReadableStream();
|
296
|
-
expect(
|
309
|
+
expect(_typeof(readable)).toEqual('object');
|
297
310
|
});
|
298
311
|
it('should have property getReader', function () {
|
299
312
|
var readable = new _util.ReadableStream();
|
300
313
|
expect(_typeof(readable.getReader)).toEqual('function');
|
301
314
|
});
|
302
315
|
});
|
316
|
+
describe('toRomanNumerals', function () {
|
317
|
+
it('handles invalid arguments', function () {
|
318
|
+
var _arr = ['foo', -1, 0];
|
319
|
+
|
320
|
+
var _loop = function _loop() {
|
321
|
+
var input = _arr[_i];
|
322
|
+
expect(function () {
|
323
|
+
(0, _util.toRomanNumerals)(input);
|
324
|
+
}).toThrow(new Error('The number should be a positive integer.'));
|
325
|
+
};
|
326
|
+
|
327
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
328
|
+
_loop();
|
329
|
+
}
|
330
|
+
});
|
331
|
+
it('converts numbers to uppercase Roman numerals', function () {
|
332
|
+
expect((0, _util.toRomanNumerals)(1)).toEqual('I');
|
333
|
+
expect((0, _util.toRomanNumerals)(6)).toEqual('VI');
|
334
|
+
expect((0, _util.toRomanNumerals)(7)).toEqual('VII');
|
335
|
+
expect((0, _util.toRomanNumerals)(8)).toEqual('VIII');
|
336
|
+
expect((0, _util.toRomanNumerals)(10)).toEqual('X');
|
337
|
+
expect((0, _util.toRomanNumerals)(40)).toEqual('XL');
|
338
|
+
expect((0, _util.toRomanNumerals)(100)).toEqual('C');
|
339
|
+
expect((0, _util.toRomanNumerals)(500)).toEqual('D');
|
340
|
+
expect((0, _util.toRomanNumerals)(1000)).toEqual('M');
|
341
|
+
expect((0, _util.toRomanNumerals)(2019)).toEqual('MMXIX');
|
342
|
+
});
|
343
|
+
it('converts numbers to lowercase Roman numerals', function () {
|
344
|
+
expect((0, _util.toRomanNumerals)(1, true)).toEqual('i');
|
345
|
+
expect((0, _util.toRomanNumerals)(6, true)).toEqual('vi');
|
346
|
+
expect((0, _util.toRomanNumerals)(7, true)).toEqual('vii');
|
347
|
+
expect((0, _util.toRomanNumerals)(8, true)).toEqual('viii');
|
348
|
+
expect((0, _util.toRomanNumerals)(10, true)).toEqual('x');
|
349
|
+
expect((0, _util.toRomanNumerals)(40, true)).toEqual('xl');
|
350
|
+
expect((0, _util.toRomanNumerals)(100, true)).toEqual('c');
|
351
|
+
expect((0, _util.toRomanNumerals)(500, true)).toEqual('d');
|
352
|
+
expect((0, _util.toRomanNumerals)(1000, true)).toEqual('m');
|
353
|
+
expect((0, _util.toRomanNumerals)(2019, true)).toEqual('mmxix');
|
354
|
+
});
|
355
|
+
});
|
303
356
|
describe('URL', function () {
|
304
357
|
it('should return an Object', function () {
|
305
358
|
var url = new _util.URL('https://example.com');
|
306
|
-
expect(
|
359
|
+
expect(_typeof(url)).toEqual('object');
|
307
360
|
});
|
308
361
|
it('should have property `href`', function () {
|
309
362
|
var url = new _util.URL('https://example.com');
|
@@ -342,4 +395,31 @@ describe('util', function () {
|
|
342
395
|
expect((0, _util.createValidAbsoluteUrl)('/foo', 'tel:0123456789')).toEqual(null);
|
343
396
|
});
|
344
397
|
});
|
398
|
+
describe('createPromiseCapability', function () {
|
399
|
+
it('should resolve with correct data', function (done) {
|
400
|
+
var promiseCapability = (0, _util.createPromiseCapability)();
|
401
|
+
expect(promiseCapability.settled).toEqual(false);
|
402
|
+
promiseCapability.resolve({
|
403
|
+
test: 'abc'
|
404
|
+
});
|
405
|
+
promiseCapability.promise.then(function (data) {
|
406
|
+
expect(promiseCapability.settled).toEqual(true);
|
407
|
+
expect(data).toEqual({
|
408
|
+
test: 'abc'
|
409
|
+
});
|
410
|
+
done();
|
411
|
+
}, done.fail);
|
412
|
+
});
|
413
|
+
it('should reject with correct reason', function (done) {
|
414
|
+
var promiseCapability = (0, _util.createPromiseCapability)();
|
415
|
+
expect(promiseCapability.settled).toEqual(false);
|
416
|
+
promiseCapability.reject(new Error('reason'));
|
417
|
+
promiseCapability.promise.then(done.fail, function (reason) {
|
418
|
+
expect(promiseCapability.settled).toEqual(true);
|
419
|
+
expect(reason instanceof Error).toEqual(true);
|
420
|
+
expect(reason.message).toEqual('reason');
|
421
|
+
done();
|
422
|
+
});
|
423
|
+
});
|
424
|
+
});
|
345
425
|
});
|