pdfjs-dist 2.6.347 → 2.7.570

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 (158) hide show
  1. package/README.md +3 -3
  2. package/bower.json +1 -1
  3. package/build/pdf.js +2050 -1087
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +18219 -10436
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/es5/build/pdf.d.ts +1 -0
  10. package/es5/build/pdf.js +6623 -6654
  11. package/es5/build/pdf.js.map +1 -1
  12. package/es5/build/pdf.min.js +1 -1
  13. package/es5/build/pdf.worker.js +20815 -13888
  14. package/es5/build/pdf.worker.js.map +1 -1
  15. package/es5/build/pdf.worker.min.js +1 -1
  16. package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
  17. package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
  18. package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
  19. package/es5/web/pdf_viewer.css +18 -15
  20. package/es5/web/pdf_viewer.js +1094 -514
  21. package/es5/web/pdf_viewer.js.map +1 -1
  22. package/image_decoders/pdf.image_decoders.js +774 -168
  23. package/image_decoders/pdf.image_decoders.js.map +1 -1
  24. package/image_decoders/pdf.image_decoders.min.js +1 -1
  25. package/lib/core/annotation.js +556 -108
  26. package/lib/core/cff_parser.js +7 -1
  27. package/lib/core/charsets.js +1 -1
  28. package/lib/core/cmap.js +20 -1
  29. package/lib/core/core_utils.js +162 -3
  30. package/lib/core/crypto.js +1 -1
  31. package/lib/core/default_appearance.js +132 -0
  32. package/lib/core/document.js +115 -9
  33. package/lib/core/encodings.js +1 -1
  34. package/lib/core/evaluator.js +168 -74
  35. package/lib/core/fonts.js +97 -11
  36. package/lib/core/function.js +5 -10
  37. package/lib/core/glyphlist.js +11 -4529
  38. package/lib/core/image_utils.js +30 -1
  39. package/lib/core/jpg.js +1 -1
  40. package/lib/core/jpx.js +5 -5
  41. package/lib/core/murmurhash3.js +1 -1
  42. package/lib/core/obj.js +123 -39
  43. package/lib/core/pattern.js +4 -4
  44. package/lib/core/primitives.js +24 -5
  45. package/lib/core/standard_fonts.js +1 -1
  46. package/lib/core/stream.js +5 -1
  47. package/lib/core/unicode.js +15 -1387
  48. package/lib/core/worker.js +58 -17
  49. package/lib/core/writer.js +68 -4
  50. package/lib/display/annotation_layer.js +712 -119
  51. package/lib/display/annotation_storage.js +21 -4
  52. package/lib/display/api.js +88 -18
  53. package/lib/display/canvas.js +414 -375
  54. package/lib/display/display_utils.js +11 -4
  55. package/lib/display/fetch_stream.js +3 -3
  56. package/lib/display/font_loader.js +2 -3
  57. package/lib/display/metadata.js +54 -20
  58. package/lib/display/node_stream.js +1 -1
  59. package/lib/display/optional_content_config.js +1 -1
  60. package/lib/display/pattern_helper.js +109 -113
  61. package/lib/display/svg.js +5 -5
  62. package/lib/display/text_layer.js +54 -54
  63. package/lib/display/transport_stream.js +4 -4
  64. package/lib/display/webgl.js +65 -68
  65. package/lib/examples/node/domstubs.js +9 -4
  66. package/lib/pdf.js +2 -2
  67. package/lib/pdf.sandbox.js +311 -0
  68. package/lib/pdf.worker.js +2 -2
  69. package/lib/shared/scripting_utils.js +84 -0
  70. package/lib/shared/util.js +129 -14
  71. package/lib/{display → shared}/xml_parser.js +112 -4
  72. package/lib/test/unit/annotation_spec.js +831 -109
  73. package/lib/test/unit/annotation_storage_spec.js +28 -10
  74. package/lib/test/unit/api_spec.js +190 -160
  75. package/lib/test/unit/bidi_spec.js +6 -6
  76. package/lib/test/unit/cff_parser_spec.js +73 -73
  77. package/lib/test/unit/clitests_helper.js +2 -0
  78. package/lib/test/unit/cmap_spec.js +48 -74
  79. package/lib/test/unit/core_utils_spec.js +34 -0
  80. package/lib/test/unit/crypto_spec.js +162 -199
  81. package/lib/test/unit/custom_spec.js +7 -18
  82. package/lib/test/unit/default_appearance_spec.js +54 -0
  83. package/lib/test/unit/display_svg_spec.js +24 -19
  84. package/lib/test/unit/display_utils_spec.js +1 -1
  85. package/lib/test/unit/document_spec.js +187 -20
  86. package/lib/test/unit/evaluator_spec.js +30 -30
  87. package/lib/test/unit/function_spec.js +165 -165
  88. package/lib/test/unit/jasmine-boot.js +52 -53
  89. package/lib/test/unit/metadata_spec.js +2 -2
  90. package/lib/test/unit/murmurhash3_spec.js +29 -16
  91. package/lib/test/unit/network_spec.js +21 -21
  92. package/lib/test/unit/pdf_find_controller_spec.js +131 -69
  93. package/lib/test/unit/pdf_find_utils_spec.js +10 -10
  94. package/lib/test/unit/scripting_spec.js +1104 -0
  95. package/lib/test/unit/stream_spec.js +8 -8
  96. package/lib/test/unit/test_utils.js +16 -19
  97. package/lib/test/unit/testreporter.js +11 -4
  98. package/lib/test/unit/type1_parser_spec.js +23 -23
  99. package/lib/test/unit/ui_utils_spec.js +78 -35
  100. package/lib/test/unit/unicode_spec.js +7 -7
  101. package/lib/test/unit/util_spec.js +26 -3
  102. package/lib/test/unit/writer_spec.js +16 -1
  103. package/lib/test/unit/xml_spec.js +117 -0
  104. package/lib/web/annotation_layer_builder.js +18 -6
  105. package/lib/web/app.js +579 -161
  106. package/lib/web/app_options.js +14 -0
  107. package/lib/web/base_tree_viewer.js +50 -0
  108. package/lib/web/base_viewer.js +350 -14
  109. package/lib/web/chromecom.js +9 -1
  110. package/lib/web/debugger.js +1 -2
  111. package/lib/web/download_manager.js +0 -15
  112. package/lib/web/firefox_print_service.js +6 -4
  113. package/lib/web/firefoxcom.js +84 -69
  114. package/lib/web/generic_scripting.js +55 -0
  115. package/lib/web/genericcom.js +9 -1
  116. package/lib/web/grab_to_pan.js +1 -1
  117. package/lib/web/interfaces.js +9 -3
  118. package/lib/web/pdf_attachment_viewer.js +1 -3
  119. package/lib/web/pdf_cursor_tools.js +20 -13
  120. package/lib/web/pdf_document_properties.js +48 -61
  121. package/lib/web/pdf_find_bar.js +1 -3
  122. package/lib/web/pdf_find_controller.js +58 -12
  123. package/lib/web/pdf_history.js +43 -21
  124. package/lib/web/pdf_layer_viewer.js +1 -9
  125. package/lib/web/pdf_link_service.js +108 -78
  126. package/lib/web/pdf_outline_viewer.js +166 -10
  127. package/lib/web/pdf_page_view.js +14 -14
  128. package/lib/web/pdf_presentation_mode.js +21 -31
  129. package/lib/web/pdf_rendering_queue.js +8 -1
  130. package/lib/web/pdf_sidebar.js +62 -107
  131. package/lib/web/pdf_sidebar_resizer.js +11 -21
  132. package/lib/web/pdf_single_page_viewer.js +8 -0
  133. package/lib/web/pdf_thumbnail_view.js +26 -26
  134. package/lib/web/pdf_thumbnail_viewer.js +13 -2
  135. package/lib/web/pdf_viewer.component.js +2 -2
  136. package/lib/web/pdf_viewer.js +3 -1
  137. package/lib/web/preferences.js +33 -44
  138. package/lib/web/text_layer_builder.js +2 -9
  139. package/lib/web/ui_utils.js +78 -46
  140. package/lib/web/viewer_compatibility.js +1 -2
  141. package/package.json +4 -1
  142. package/types/display/annotation_layer.d.ts +18 -3
  143. package/types/display/api.d.ts +110 -54
  144. package/types/display/canvas.d.ts +1 -1
  145. package/types/display/display_utils.d.ts +96 -95
  146. package/types/display/fetch_stream.d.ts +2 -2
  147. package/types/display/metadata.d.ts +4 -0
  148. package/types/display/pattern_helper.d.ts +1 -1
  149. package/types/display/text_layer.d.ts +7 -7
  150. package/types/display/transport_stream.d.ts +1 -1
  151. package/types/shared/scripting_utils.d.ts +12 -0
  152. package/types/shared/util.d.ts +281 -250
  153. package/types/shared/xml_parser.d.ts +64 -0
  154. package/web/pdf_viewer.css +18 -15
  155. package/web/pdf_viewer.js +809 -408
  156. package/web/pdf_viewer.js.map +1 -1
  157. package/webpack.js +1 -1
  158. package/types/display/xml_parser.d.ts +0 -35
@@ -31,7 +31,7 @@ describe("stream", function () {
31
31
  toMatchTypedArray(util, customEqualityTesters) {
32
32
  return {
33
33
  compare(actual, expected) {
34
- var result = {};
34
+ const result = {};
35
35
 
36
36
  if (actual.length !== expected.length) {
37
37
  result.pass = false;
@@ -41,9 +41,9 @@ describe("stream", function () {
41
41
 
42
42
  result.pass = true;
43
43
 
44
- for (var i = 0, ii = expected.length; i < ii; i++) {
45
- var a = actual[i],
46
- b = expected[i];
44
+ for (let i = 0, ii = expected.length; i < ii; i++) {
45
+ const a = actual[i],
46
+ b = expected[i];
47
47
 
48
48
  if (a !== b) {
49
49
  result.pass = false;
@@ -61,14 +61,14 @@ describe("stream", function () {
61
61
  });
62
62
  describe("PredictorStream", function () {
63
63
  it("should decode simple predictor data", function () {
64
- var dict = new _primitives.Dict();
64
+ const dict = new _primitives.Dict();
65
65
  dict.set("Predictor", 12);
66
66
  dict.set("Colors", 1);
67
67
  dict.set("BitsPerComponent", 8);
68
68
  dict.set("Columns", 2);
69
- var input = new _stream.Stream(new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]), 0, 9, dict);
70
- var predictor = new _stream.PredictorStream(input, 9, dict);
71
- var result = predictor.getBytes(6);
69
+ const input = new _stream.Stream(new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]), 0, 9, dict);
70
+ const predictor = new _stream.PredictorStream(input, 9, dict);
71
+ const result = predictor.getBytes(6);
72
72
  expect(result).toMatchTypedArray(new Uint8Array([100, 3, 101, 2, 102, 1]));
73
73
  predictor.reset();
74
74
  const clampedResult = predictor.getBytes(6, true);
@@ -27,7 +27,7 @@ Object.defineProperty(exports, "__esModule", {
27
27
  exports.buildGetDocumentParams = buildGetDocumentParams;
28
28
  exports.createIdFactory = createIdFactory;
29
29
  exports.isEmptyObj = isEmptyObj;
30
- exports.TEST_PDFS_PATH = exports.XRefMock = exports.NodeFileReaderFactory = exports.DOMFileReaderFactory = void 0;
30
+ exports.XRefMock = exports.TEST_PDFS_PATH = exports.DefaultFileReaderFactory = exports.CMAP_PARAMS = void 0;
31
31
 
32
32
  var _primitives = require("../../core/primitives.js");
33
33
 
@@ -39,6 +39,14 @@ var _is_node = require("../../shared/is_node.js");
39
39
 
40
40
  var _stream = require("../../core/stream.js");
41
41
 
42
+ const TEST_PDFS_PATH = _is_node.isNodeJS ? "./test/pdfs/" : "../pdfs/";
43
+ exports.TEST_PDFS_PATH = TEST_PDFS_PATH;
44
+ const CMAP_PARAMS = {
45
+ cMapUrl: _is_node.isNodeJS ? "./external/bcmaps/" : "../../external/bcmaps/",
46
+ cMapPacked: true
47
+ };
48
+ exports.CMAP_PARAMS = CMAP_PARAMS;
49
+
42
50
  class DOMFileReaderFactory {
43
51
  static async fetch(params) {
44
52
  const response = await fetch(params.path);
@@ -52,8 +60,6 @@ class DOMFileReaderFactory {
52
60
 
53
61
  }
54
62
 
55
- exports.DOMFileReaderFactory = DOMFileReaderFactory;
56
-
57
63
  class NodeFileReaderFactory {
58
64
  static async fetch(params) {
59
65
  const fs = require("fs");
@@ -72,21 +78,12 @@ class NodeFileReaderFactory {
72
78
 
73
79
  }
74
80
 
75
- exports.NodeFileReaderFactory = NodeFileReaderFactory;
76
- const TEST_PDFS_PATH = {
77
- dom: "../pdfs/",
78
- node: "./test/pdfs/"
79
- };
80
- exports.TEST_PDFS_PATH = TEST_PDFS_PATH;
81
+ const DefaultFileReaderFactory = _is_node.isNodeJS ? NodeFileReaderFactory : DOMFileReaderFactory;
82
+ exports.DefaultFileReaderFactory = DefaultFileReaderFactory;
81
83
 
82
84
  function buildGetDocumentParams(filename, options) {
83
85
  const params = Object.create(null);
84
-
85
- if (_is_node.isNodeJS) {
86
- params.url = TEST_PDFS_PATH.node + filename;
87
- } else {
88
- params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
89
- }
86
+ params.url = _is_node.isNodeJS ? TEST_PDFS_PATH + filename : new URL(TEST_PDFS_PATH + filename, window.location).href;
90
87
 
91
88
  for (const option in options) {
92
89
  params[option] = options[option];
@@ -126,8 +123,8 @@ class XRefMock {
126
123
  return this._map[ref.toString()];
127
124
  }
128
125
 
129
- fetchAsync(ref) {
130
- return Promise.resolve(this.fetch(ref));
126
+ async fetchAsync(ref) {
127
+ return this.fetch(ref);
131
128
  }
132
129
 
133
130
  fetchIfRef(obj) {
@@ -138,8 +135,8 @@ class XRefMock {
138
135
  return this.fetch(obj);
139
136
  }
140
137
 
141
- fetchIfRefAsync(obj) {
142
- return Promise.resolve(this.fetchIfRef(obj));
138
+ async fetchIfRefAsync(obj) {
139
+ return this.fetchIfRef(obj);
143
140
  }
144
141
 
145
142
  }
@@ -21,9 +21,14 @@
21
21
  */
22
22
  "use strict";
23
23
 
24
- var TestReporter = function (browser) {
24
+ Object.defineProperty(exports, "__esModule", {
25
+ value: true
26
+ });
27
+ exports.TestReporter = void 0;
28
+
29
+ const TestReporter = function (browser) {
25
30
  function send(action, json, cb) {
26
- var r = new XMLHttpRequest();
31
+ const r = new XMLHttpRequest();
27
32
  r.open("POST", action, true);
28
33
  r.setRequestHeader("Content-Type", "application/json");
29
34
 
@@ -50,7 +55,7 @@ var TestReporter = function (browser) {
50
55
  }
51
56
 
52
57
  function sendResult(status, description, error) {
53
- var message = {
58
+ const message = {
54
59
  status,
55
60
  description
56
61
  };
@@ -110,4 +115,6 @@ var TestReporter = function (browser) {
110
115
  this.jasmineDone = function () {
111
116
  setTimeout(sendQuitRequest, 500);
112
117
  };
113
- };
118
+ };
119
+
120
+ exports.TestReporter = TestReporter;
@@ -29,8 +29,8 @@ var _type1_parser = require("../../core/type1_parser.js");
29
29
 
30
30
  describe("Type1Parser", function () {
31
31
  it("splits tokens", function () {
32
- var stream = new _stream.StringStream("/BlueValues[-17 0]noaccess def");
33
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
32
+ const stream = new _stream.StringStream("/BlueValues[-17 0]noaccess def");
33
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
34
34
  expect(parser.getToken()).toEqual("/");
35
35
  expect(parser.getToken()).toEqual("BlueValues");
36
36
  expect(parser.getToken()).toEqual("[");
@@ -42,60 +42,60 @@ describe("Type1Parser", function () {
42
42
  expect(parser.getToken()).toEqual(null);
43
43
  });
44
44
  it("handles glued tokens", function () {
45
- var stream = new _stream.StringStream("dup/CharStrings");
46
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
45
+ const stream = new _stream.StringStream("dup/CharStrings");
46
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
47
47
  expect(parser.getToken()).toEqual("dup");
48
48
  expect(parser.getToken()).toEqual("/");
49
49
  expect(parser.getToken()).toEqual("CharStrings");
50
50
  });
51
51
  it("ignores whitespace", function () {
52
- var stream = new _stream.StringStream("\nab c\t");
53
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
52
+ const stream = new _stream.StringStream("\nab c\t");
53
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
54
54
  expect(parser.getToken()).toEqual("ab");
55
55
  expect(parser.getToken()).toEqual("c");
56
56
  });
57
57
  it("parses numbers", function () {
58
- var stream = new _stream.StringStream("123");
59
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
58
+ const stream = new _stream.StringStream("123");
59
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
60
60
  expect(parser.readNumber()).toEqual(123);
61
61
  });
62
62
  it("parses booleans", function () {
63
- var stream = new _stream.StringStream("true false");
64
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
63
+ const stream = new _stream.StringStream("true false");
64
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
65
65
  expect(parser.readBoolean()).toEqual(1);
66
66
  expect(parser.readBoolean()).toEqual(0);
67
67
  });
68
68
  it("parses number arrays", function () {
69
- var stream = new _stream.StringStream("[1 2]");
70
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
69
+ let stream = new _stream.StringStream("[1 2]");
70
+ let parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
71
71
  expect(parser.readNumberArray()).toEqual([1, 2]);
72
72
  stream = new _stream.StringStream("[ 1 2 ]");
73
73
  parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
74
74
  expect(parser.readNumberArray()).toEqual([1, 2]);
75
75
  });
76
76
  it("skips comments", function () {
77
- var stream = new _stream.StringStream("%!PS-AdobeFont-1.0: CMSY10 003.002\n" + "%%Title: CMSY10\n" + "%Version: 003.002\n" + "FontDirectory");
78
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
77
+ const stream = new _stream.StringStream("%!PS-AdobeFont-1.0: CMSY10 003.002\n" + "%%Title: CMSY10\n" + "%Version: 003.002\n" + "FontDirectory");
78
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
79
79
  expect(parser.getToken()).toEqual("FontDirectory");
80
80
  });
81
81
  it("parses font program", function () {
82
- var stream = new _stream.StringStream("/ExpansionFactor 99\n" + "/Subrs 1 array\n" + "dup 0 1 RD x noaccess put\n" + "end\n" + "/CharStrings 46 dict dup begin\n" + "/.notdef 1 RD x ND\n" + "end");
83
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
84
- var program = parser.extractFontProgram({});
82
+ const stream = new _stream.StringStream("/ExpansionFactor 99\n" + "/Subrs 1 array\n" + "dup 0 1 RD x noaccess put\n" + "end\n" + "/CharStrings 46 dict dup begin\n" + "/.notdef 1 RD x ND\n" + "end");
83
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
84
+ const program = parser.extractFontProgram({});
85
85
  expect(program.charstrings.length).toEqual(1);
86
86
  expect(program.properties.privateData.ExpansionFactor).toEqual(99);
87
87
  });
88
88
  it("parses font header font matrix", function () {
89
- var stream = new _stream.StringStream("/FontMatrix [0.001 0 0 0.001 0 0 ]readonly def\n");
90
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
91
- var props = {};
89
+ const stream = new _stream.StringStream("/FontMatrix [0.001 0 0 0.001 0 0 ]readonly def\n");
90
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
91
+ const props = {};
92
92
  parser.extractFontHeader(props);
93
93
  expect(props.fontMatrix).toEqual([0.001, 0, 0, 0.001, 0, 0]);
94
94
  });
95
95
  it("parses font header encoding", function () {
96
- var stream = new _stream.StringStream("/Encoding 256 array\n" + "0 1 255 {1 index exch /.notdef put} for\n" + "dup 33 /arrowright put\n" + "readonly def\n");
97
- var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
98
- var props = {
96
+ const stream = new _stream.StringStream("/Encoding 256 array\n" + "0 1 255 {1 index exch /.notdef put} for\n" + "dup 33 /arrowright put\n" + "readonly def\n");
97
+ const parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
98
+ const props = {
99
99
  overridableEncoding: true
100
100
  };
101
101
  parser.extractFontHeader(props);
@@ -91,9 +91,9 @@ describe("ui_utils", function () {
91
91
  expect((0, _ui_utils.getPDFFileNameFromURL)("http://www.example.com/pdfs/file2.pdf#file.pdf")).toEqual("file2.pdf");
92
92
  });
93
93
  it("gets PDF filename from URI-encoded data", function () {
94
- var encodedUrl = encodeURIComponent("http://www.example.com/pdfs/file1.pdf");
94
+ const encodedUrl = encodeURIComponent("http://www.example.com/pdfs/file1.pdf");
95
95
  expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrl)).toEqual("file1.pdf");
96
- var encodedUrlWithQuery = encodeURIComponent("http://www.example.com/pdfs/file.txt?file2.pdf");
96
+ const encodedUrlWithQuery = encodeURIComponent("http://www.example.com/pdfs/file.txt?file2.pdf");
97
97
  expect((0, _ui_utils.getPDFFileNameFromURL)(encodedUrlWithQuery)).toEqual("file2.pdf");
98
98
  });
99
99
  it("gets PDF filename from data mistaken for URI-encoded", function () {
@@ -111,14 +111,14 @@ describe("ui_utils", function () {
111
111
  pending("Blob in not supported in Node.js.");
112
112
  }
113
113
 
114
- var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
115
- var blobUrl = (0, _util.createObjectURL)(typedArray, "application/pdf");
114
+ const typedArray = new Uint8Array([1, 2, 3, 4, 5]);
115
+ const blobUrl = (0, _util.createObjectURL)(typedArray, "application/pdf");
116
116
  expect(blobUrl.startsWith("blob:")).toEqual(true);
117
117
  expect((0, _ui_utils.getPDFFileNameFromURL)(blobUrl + "?file.pdf")).toEqual("file.pdf");
118
118
  });
119
119
  it('gets fallback filename from query string appended to "data:" URL', function () {
120
- var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
121
- var dataUrl = (0, _util.createObjectURL)(typedArray, "application/pdf", true);
120
+ const typedArray = new Uint8Array([1, 2, 3, 4, 5]);
121
+ const dataUrl = (0, _util.createObjectURL)(typedArray, "application/pdf", true);
122
122
  expect(dataUrl.startsWith("data:")).toEqual(true);
123
123
  expect((0, _ui_utils.getPDFFileNameFromURL)(dataUrl + "?file1.pdf")).toEqual("document.pdf");
124
124
  expect((0, _ui_utils.getPDFFileNameFromURL)(" " + dataUrl + "?file2.pdf")).toEqual("document.pdf");
@@ -126,8 +126,8 @@ describe("ui_utils", function () {
126
126
  });
127
127
  describe("EventBus", function () {
128
128
  it("dispatch event", function () {
129
- var eventBus = new _ui_utils.EventBus();
130
- var count = 0;
129
+ const eventBus = new _ui_utils.EventBus();
130
+ let count = 0;
131
131
  eventBus.on("test", function (evt) {
132
132
  expect(evt).toEqual(undefined);
133
133
  count++;
@@ -150,8 +150,8 @@ describe("ui_utils", function () {
150
150
  expect(count).toEqual(1);
151
151
  });
152
152
  it("dispatch different event", function () {
153
- var eventBus = new _ui_utils.EventBus();
154
- var count = 0;
153
+ const eventBus = new _ui_utils.EventBus();
154
+ let count = 0;
155
155
  eventBus.on("test", function () {
156
156
  count++;
157
157
  });
@@ -159,8 +159,8 @@ describe("ui_utils", function () {
159
159
  expect(count).toEqual(0);
160
160
  });
161
161
  it("dispatch event multiple times", function () {
162
- var eventBus = new _ui_utils.EventBus();
163
- var count = 0;
162
+ const eventBus = new _ui_utils.EventBus();
163
+ let count = 0;
164
164
  eventBus.dispatch("test");
165
165
  eventBus.on("test", function () {
166
166
  count++;
@@ -170,8 +170,8 @@ describe("ui_utils", function () {
170
170
  expect(count).toEqual(2);
171
171
  });
172
172
  it("dispatch event to multiple handlers", function () {
173
- var eventBus = new _ui_utils.EventBus();
174
- var count = 0;
173
+ const eventBus = new _ui_utils.EventBus();
174
+ let count = 0;
175
175
  eventBus.on("test", function () {
176
176
  count++;
177
177
  });
@@ -182,10 +182,10 @@ describe("ui_utils", function () {
182
182
  expect(count).toEqual(2);
183
183
  });
184
184
  it("dispatch to detached", function () {
185
- var eventBus = new _ui_utils.EventBus();
186
- var count = 0;
185
+ const eventBus = new _ui_utils.EventBus();
186
+ let count = 0;
187
187
 
188
- var listener = function () {
188
+ const listener = function () {
189
189
  count++;
190
190
  };
191
191
 
@@ -196,8 +196,8 @@ describe("ui_utils", function () {
196
196
  expect(count).toEqual(1);
197
197
  });
198
198
  it("dispatch to wrong detached", function () {
199
- var eventBus = new _ui_utils.EventBus();
200
- var count = 0;
199
+ const eventBus = new _ui_utils.EventBus();
200
+ let count = 0;
201
201
  eventBus.on("test", function () {
202
202
  count++;
203
203
  });
@@ -209,15 +209,15 @@ describe("ui_utils", function () {
209
209
  expect(count).toEqual(2);
210
210
  });
211
211
  it("dispatch to detached during handling", function () {
212
- var eventBus = new _ui_utils.EventBus();
213
- var count = 0;
212
+ const eventBus = new _ui_utils.EventBus();
213
+ let count = 0;
214
214
 
215
- var listener1 = function () {
215
+ const listener1 = function () {
216
216
  eventBus.off("test", listener2);
217
217
  count++;
218
218
  };
219
219
 
220
- var listener2 = function () {
220
+ const listener2 = function () {
221
221
  eventBus.off("test", listener1);
222
222
  count++;
223
223
  };
@@ -228,6 +228,24 @@ describe("ui_utils", function () {
228
228
  eventBus.dispatch("test");
229
229
  expect(count).toEqual(2);
230
230
  });
231
+ it("dispatch event to handlers with/without 'once' option", function () {
232
+ const eventBus = new _ui_utils.EventBus();
233
+ let multipleCount = 0,
234
+ onceCount = 0;
235
+ eventBus.on("test", function () {
236
+ multipleCount++;
237
+ });
238
+ eventBus.on("test", function () {
239
+ onceCount++;
240
+ }, {
241
+ once: true
242
+ });
243
+ eventBus.dispatch("test");
244
+ eventBus.dispatch("test");
245
+ eventBus.dispatch("test");
246
+ expect(multipleCount).toEqual(3);
247
+ expect(onceCount).toEqual(1);
248
+ });
231
249
  it("should not re-dispatch to DOM", function (done) {
232
250
  if (_is_node.isNodeJS) {
233
251
  pending("Document in not supported in Node.js.");
@@ -484,14 +502,16 @@ describe("ui_utils", function () {
484
502
  if (viewLeft < scrollRight && viewRight > scrollLeft && viewTop < scrollBottom && viewBottom > scrollTop) {
485
503
  const hiddenHeight = Math.max(0, scrollTop - viewTop) + Math.max(0, viewBottom - scrollBottom);
486
504
  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;
505
+ const fractionHeight = (div.clientHeight - hiddenHeight) / div.clientHeight;
506
+ const fractionWidth = (div.clientWidth - hiddenWidth) / div.clientWidth;
507
+ const percent = fractionHeight * fractionWidth * 100 | 0;
489
508
  views.push({
490
509
  id: view.id,
491
510
  x: viewLeft,
492
511
  y: viewTop,
493
512
  view,
494
- percent
513
+ percent,
514
+ widthPercent: fractionWidth * 100 | 0
495
515
  });
496
516
  }
497
517
  }
@@ -503,16 +523,16 @@ describe("ui_utils", function () {
503
523
  };
504
524
  }
505
525
 
506
- function scrollOverDocument(pages, horizontally = false) {
526
+ function scrollOverDocument(pages, horizontal = false, rtl = false) {
507
527
  const size = pages.reduce(function (max, {
508
528
  div
509
529
  }) {
510
- return Math.max(max, horizontally ? div.offsetLeft + div.clientLeft + div.clientWidth : div.offsetTop + div.clientTop + div.clientHeight);
530
+ return Math.max(max, horizontal ? Math.abs(div.offsetLeft + div.clientLeft + div.clientWidth) : div.offsetTop + div.clientTop + div.clientHeight);
511
531
  }, 0);
512
532
 
513
- for (let i = 0; i < size; i += 7) {
533
+ for (let i = -size; i < size; i += 7) {
514
534
  for (let j = i + 5; j < size; j += j - i) {
515
- const scroll = horizontally ? {
535
+ const scrollEl = horizontal ? {
516
536
  scrollTop: 0,
517
537
  scrollLeft: i,
518
538
  clientHeight: 10000,
@@ -523,7 +543,13 @@ describe("ui_utils", function () {
523
543
  clientHeight: j - i,
524
544
  clientWidth: 10000
525
545
  };
526
- expect((0, _ui_utils.getVisibleElements)(scroll, pages, false, horizontally)).toEqual(slowGetVisibleElements(scroll, pages));
546
+ expect((0, _ui_utils.getVisibleElements)({
547
+ scrollEl,
548
+ views: pages,
549
+ sortByVisibility: false,
550
+ horizontal,
551
+ rtl
552
+ })).toEqual(slowGetVisibleElements(scrollEl, pages));
527
553
  }
528
554
  }
529
555
  }
@@ -540,6 +566,10 @@ describe("ui_utils", function () {
540
566
  const pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
541
567
  scrollOverDocument(pages, true);
542
568
  });
569
+ it("works with horizontal scrolling with RTL-documents", function () {
570
+ const pages = makePages([[[-10, 50], [-20, 20], [-30, 10]]]);
571
+ scrollOverDocument(pages, true, true);
572
+ });
543
573
  it("handles `sortByVisibility` correctly", function () {
544
574
  const scrollEl = {
545
575
  scrollTop: 75,
@@ -548,8 +578,15 @@ describe("ui_utils", function () {
548
578
  clientWidth: 1500
549
579
  };
550
580
  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);
581
+ const visible = (0, _ui_utils.getVisibleElements)({
582
+ scrollEl,
583
+ views
584
+ });
585
+ const visibleSorted = (0, _ui_utils.getVisibleElements)({
586
+ scrollEl,
587
+ views,
588
+ sortByVisibility: true
589
+ });
553
590
  const viewsOrder = [],
554
591
  viewsSortedOrder = [];
555
592
 
@@ -572,7 +609,10 @@ describe("ui_utils", function () {
572
609
  clientWidth: 1500
573
610
  };
574
611
  const views = [];
575
- expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
612
+ expect((0, _ui_utils.getVisibleElements)({
613
+ scrollEl,
614
+ views
615
+ })).toEqual({
576
616
  first: undefined,
577
617
  last: undefined,
578
618
  views: []
@@ -586,7 +626,10 @@ describe("ui_utils", function () {
586
626
  clientWidth: 1500
587
627
  };
588
628
  const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
589
- expect((0, _ui_utils.getVisibleElements)(scrollEl, views)).toEqual({
629
+ expect((0, _ui_utils.getVisibleElements)({
630
+ scrollEl,
631
+ views
632
+ })).toEqual({
590
633
  first: undefined,
591
634
  last: undefined,
592
635
  views: []
@@ -37,7 +37,7 @@ describe("unicode", function () {
37
37
  });
38
38
  });
39
39
  describe("getUnicodeForGlyph", function () {
40
- var standardMap, dingbatsMap;
40
+ let standardMap, dingbatsMap;
41
41
  beforeAll(function (done) {
42
42
  standardMap = (0, _glyphlist.getGlyphsUnicode)();
43
43
  dingbatsMap = (0, _glyphlist.getDingbatsGlyphsUnicode)();
@@ -71,7 +71,7 @@ describe("unicode", function () {
71
71
  });
72
72
  });
73
73
  describe("getNormalizedUnicodes", function () {
74
- var NormalizedUnicodes;
74
+ let NormalizedUnicodes;
75
75
  beforeAll(function (done) {
76
76
  NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
77
77
  done();
@@ -88,7 +88,7 @@ describe("unicode", function () {
88
88
  });
89
89
  });
90
90
  describe("reverseIfRtl", function () {
91
- var NormalizedUnicodes;
91
+ let NormalizedUnicodes;
92
92
 
93
93
  function getGlyphUnicode(char) {
94
94
  if (NormalizedUnicodes[char] !== undefined) {
@@ -106,15 +106,15 @@ describe("unicode", function () {
106
106
  NormalizedUnicodes = null;
107
107
  });
108
108
  it("should not reverse LTR characters", function () {
109
- var A = getGlyphUnicode("A");
109
+ const A = getGlyphUnicode("A");
110
110
  expect((0, _unicode.reverseIfRtl)(A)).toEqual("A");
111
- var fi = getGlyphUnicode("\uFB01");
111
+ const fi = getGlyphUnicode("\uFB01");
112
112
  expect((0, _unicode.reverseIfRtl)(fi)).toEqual("fi");
113
113
  });
114
114
  it("should reverse RTL characters", function () {
115
- var heAlef = getGlyphUnicode("\u05D0");
115
+ const heAlef = getGlyphUnicode("\u05D0");
116
116
  expect((0, _unicode.reverseIfRtl)(heAlef)).toEqual("\u05D0");
117
- var arAlef = getGlyphUnicode("\u0675");
117
+ const arAlef = getGlyphUnicode("\u0675");
118
118
  expect((0, _unicode.reverseIfRtl)(arAlef)).toEqual("\u0674\u0627");
119
119
  });
120
120
  });
@@ -229,14 +229,37 @@ describe("util", function () {
229
229
  });
230
230
  });
231
231
  describe("escapeString", function () {
232
- it("should escape (, ) and \\", function () {
233
- expect((0, _util.escapeString)("((a\\a))(b(b\\b)b)")).toEqual("\\(\\(a\\\\a\\)\\)\\(b\\(b\\\\b\\)b\\)");
232
+ it("should escape (, ), \\n, \\r, and \\", function () {
233
+ expect((0, _util.escapeString)("((a\\a))\n(b(b\\b)\rb)")).toEqual("\\(\\(a\\\\a\\)\\)\\n\\(b\\(b\\\\b\\)\\rb\\)");
234
234
  });
235
235
  });
236
236
  describe("getModificationDate", function () {
237
237
  it("should get a correctly formatted date", function () {
238
238
  const date = new Date(Date.UTC(3141, 5, 9, 2, 6, 53));
239
- expect((0, _util.getModificationDate)(date)).toEqual("31410610020653");
239
+ expect((0, _util.getModificationDate)(date)).toEqual("31410609020653");
240
+ });
241
+ });
242
+ describe("encodeToXmlString", function () {
243
+ it("should get a correctly encoded string with some entities", function () {
244
+ const str = "\"\u0397ell😂' & <W😂rld>";
245
+ expect((0, _util.encodeToXmlString)(str)).toEqual("&quot;&#x397;ell&#x1F602;&apos; &amp; &lt;W&#x1F602;rld&gt;");
246
+ });
247
+ it("should get a correctly encoded basic ascii string", function () {
248
+ const str = "hello world";
249
+ expect((0, _util.encodeToXmlString)(str)).toEqual(str);
250
+ });
251
+ });
252
+ describe("isAscii", function () {
253
+ it("handles ascii/non-ascii strings", function () {
254
+ expect((0, _util.isAscii)("hello world")).toEqual(true);
255
+ expect((0, _util.isAscii)("こんにちは世界の")).toEqual(false);
256
+ expect((0, _util.isAscii)("hello world in Japanese is こんにちは世界の")).toEqual(false);
257
+ });
258
+ });
259
+ describe("stringToUTF16BEString", function () {
260
+ it("should encode a string in UTF16BE with a BOM", function () {
261
+ expect((0, _util.stringToUTF16BEString)("hello world")).toEqual("\xfe\xff\0h\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d");
262
+ expect((0, _util.stringToUTF16BEString)("こんにちは世界の")).toEqual("\xfe\xff\x30\x53\x30\x93\x30\x6b\x30\x61" + "\x30\x6f\x4e\x16\x75\x4c\x30\x6e");
240
263
  });
241
264
  });
242
265
  });
@@ -50,7 +50,11 @@ describe("Writer", function () {
50
50
  filename: "foo.pdf",
51
51
  info: {}
52
52
  };
53
- let data = (0, _writer.incrementalUpdate)(originalData, xrefInfo, newRefs);
53
+ let data = (0, _writer.incrementalUpdate)({
54
+ originalData,
55
+ xrefInfo,
56
+ newRefs
57
+ });
54
58
  data = (0, _util.bytesToString)(data);
55
59
  const expected = "\nabc\n" + "defg\n" + "789 0 obj\n" + "<< /Size 790 /Prev 314 /Type /XRef /Index [0 1 123 1 456 1 789 1] " + "/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " + "/W [1 1 2] /Length 16>> stream\n" + "\x00\x01\xff\xff" + "\x01\x01\x00\x2d" + "\x01\x05\x00\x4e" + "\x01\x0a\x00\x00\n" + "endstream\n" + "endobj\n" + "startxref\n" + "10\n" + "%%EOF\n";
56
60
  expect(data).toEqual(expected);
@@ -80,5 +84,16 @@ describe("Writer", function () {
80
84
  expect(buffer.join("")).toEqual(expected);
81
85
  done();
82
86
  });
87
+ it("should write a Dict in escaping PDF names", function (done) {
88
+ const dict = new _primitives.Dict(null);
89
+ dict.set("\xfeA#", _primitives.Name.get("hello"));
90
+ dict.set("B", _primitives.Name.get("#hello"));
91
+ dict.set("C", _primitives.Name.get("he\xfello\xff"));
92
+ const buffer = [];
93
+ (0, _writer.writeDict)(dict, buffer, null);
94
+ const expected = "<< /#feA#23 /hello /B /#23hello /C /he#fello#ff>>";
95
+ expect(buffer.join("")).toEqual(expected);
96
+ done();
97
+ });
83
98
  });
84
99
  });