pdfjs-dist 2.0.943 → 2.4.456

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

Potentially problematic release.


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

Files changed (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -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 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,336 +19,297 @@
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
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.PDFDocumentProperties = undefined;
27
+ exports.PDFDocumentProperties = void 0;
28
28
 
29
- 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"); } }; }();
29
+ var _pdf = require("../pdf");
30
30
 
31
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
31
+ var _ui_utils = require("./ui_utils.js");
32
32
 
33
- var _ui_utils = require('./ui_utils');
34
-
35
- var _pdf = require('../pdf');
36
-
37
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
38
-
39
- var DEFAULT_FIELD_CONTENT = '-';
40
- var NON_METRIC_LOCALES = ['en-us', 'en-lr', 'my'];
41
- var US_PAGE_NAMES = {
42
- '8.5x11': 'Letter',
43
- '8.5x14': 'Legal'
33
+ const DEFAULT_FIELD_CONTENT = "-";
34
+ const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
35
+ const US_PAGE_NAMES = {
36
+ "8.5x11": "Letter",
37
+ "8.5x14": "Legal"
44
38
  };
45
- var METRIC_PAGE_NAMES = {
46
- '297x420': 'A3',
47
- '210x297': 'A4'
39
+ const METRIC_PAGE_NAMES = {
40
+ "297x420": "A3",
41
+ "210x297": "A4"
48
42
  };
43
+
49
44
  function getPageName(size, isPortrait, pageNames) {
50
- var width = isPortrait ? size.width : size.height;
51
- var height = isPortrait ? size.height : size.width;
52
- return pageNames[width + 'x' + height];
45
+ const width = isPortrait ? size.width : size.height;
46
+ const height = isPortrait ? size.height : size.width;
47
+ return pageNames[`${width}x${height}`];
53
48
  }
54
49
 
55
- var PDFDocumentProperties = function () {
56
- function PDFDocumentProperties(_ref, overlayManager, eventBus) {
57
- var overlayName = _ref.overlayName,
58
- fields = _ref.fields,
59
- container = _ref.container,
60
- closeButton = _ref.closeButton;
61
-
62
- var _this = this;
63
-
64
- var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
65
-
66
- _classCallCheck(this, PDFDocumentProperties);
67
-
50
+ class PDFDocumentProperties {
51
+ constructor({
52
+ overlayName,
53
+ fields,
54
+ container,
55
+ closeButton
56
+ }, overlayManager, eventBus, l10n = _ui_utils.NullL10n) {
68
57
  this.overlayName = overlayName;
69
58
  this.fields = fields;
70
59
  this.container = container;
71
60
  this.overlayManager = overlayManager;
72
61
  this.l10n = l10n;
62
+
73
63
  this._reset();
64
+
74
65
  if (closeButton) {
75
- closeButton.addEventListener('click', this.close.bind(this));
66
+ closeButton.addEventListener("click", this.close.bind(this));
76
67
  }
68
+
77
69
  this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
70
+
78
71
  if (eventBus) {
79
- eventBus.on('pagechanging', function (evt) {
80
- _this._currentPageNumber = evt.pageNumber;
72
+ eventBus._on("pagechanging", evt => {
73
+ this._currentPageNumber = evt.pageNumber;
81
74
  });
82
- eventBus.on('rotationchanging', function (evt) {
83
- _this._pagesRotation = evt.pagesRotation;
75
+
76
+ eventBus._on("rotationchanging", evt => {
77
+ this._pagesRotation = evt.pagesRotation;
84
78
  });
85
79
  }
80
+
86
81
  this._isNonMetricLocale = true;
87
- l10n.getLanguage().then(function (locale) {
88
- _this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
82
+ l10n.getLanguage().then(locale => {
83
+ this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
89
84
  });
90
85
  }
91
86
 
92
- _createClass(PDFDocumentProperties, [{
93
- key: 'open',
94
- value: function open() {
95
- var _this2 = this;
96
-
97
- var freezeFieldData = function freezeFieldData(data) {
98
- Object.defineProperty(_this2, 'fieldData', {
99
- value: Object.freeze(data),
100
- writable: false,
101
- enumerable: true,
102
- configurable: true
87
+ open() {
88
+ const freezeFieldData = data => {
89
+ Object.defineProperty(this, "fieldData", {
90
+ value: Object.freeze(data),
91
+ writable: false,
92
+ enumerable: true,
93
+ configurable: true
94
+ });
95
+ };
96
+
97
+ Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(() => {
98
+ const currentPageNumber = this._currentPageNumber;
99
+ const pagesRotation = this._pagesRotation;
100
+
101
+ if (this.fieldData && currentPageNumber === this.fieldData["_currentPageNumber"] && pagesRotation === this.fieldData["_pagesRotation"]) {
102
+ this._updateUI();
103
+
104
+ return;
105
+ }
106
+
107
+ this.pdfDocument.getMetadata().then(({
108
+ info,
109
+ metadata,
110
+ contentDispositionFilename
111
+ }) => {
112
+ return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url || ""), this._parseFileSize(this.maybeFileSize), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
113
+ return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
114
+ }), this._parseLinearization(info.IsLinearized)]);
115
+ }).then(([info, metadata, fileName, fileSize, creationDate, modDate, pageSize, isLinearized]) => {
116
+ freezeFieldData({
117
+ fileName,
118
+ fileSize,
119
+ title: info.Title,
120
+ author: info.Author,
121
+ subject: info.Subject,
122
+ keywords: info.Keywords,
123
+ creationDate,
124
+ modificationDate: modDate,
125
+ creator: info.Creator,
126
+ producer: info.Producer,
127
+ version: info.PDFFormatVersion,
128
+ pageCount: this.pdfDocument.numPages,
129
+ pageSize,
130
+ linearized: isLinearized,
131
+ _currentPageNumber: currentPageNumber,
132
+ _pagesRotation: pagesRotation
103
133
  });
104
- };
105
- Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () {
106
- var currentPageNumber = _this2._currentPageNumber;
107
- var pagesRotation = _this2._pagesRotation;
108
- if (_this2.fieldData && currentPageNumber === _this2.fieldData['_currentPageNumber'] && pagesRotation === _this2.fieldData['_pagesRotation']) {
109
- _this2._updateUI();
134
+
135
+ this._updateUI();
136
+
137
+ return this.pdfDocument.getDownloadInfo();
138
+ }).then(({
139
+ length
140
+ }) => {
141
+ this.maybeFileSize = length;
142
+ return this._parseFileSize(length);
143
+ }).then(fileSize => {
144
+ if (fileSize === this.fieldData["fileSize"]) {
110
145
  return;
111
146
  }
112
- _this2.pdfDocument.getMetadata().then(function (_ref2) {
113
- var info = _ref2.info,
114
- metadata = _ref2.metadata,
115
- contentDispositionFilename = _ref2.contentDispositionFilename;
116
-
117
- return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(_this2.url || ''), _this2._parseFileSize(_this2.maybeFileSize), _this2._parseDate(info.CreationDate), _this2._parseDate(info.ModDate), _this2.pdfDocument.getPage(currentPageNumber).then(function (pdfPage) {
118
- return _this2._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
119
- }), _this2._parseLinearization(info.IsLinearized)]);
120
- }).then(function (_ref3) {
121
- var _ref4 = _slicedToArray(_ref3, 8),
122
- info = _ref4[0],
123
- metadata = _ref4[1],
124
- fileName = _ref4[2],
125
- fileSize = _ref4[3],
126
- creationDate = _ref4[4],
127
- modDate = _ref4[5],
128
- pageSize = _ref4[6],
129
- isLinearized = _ref4[7];
130
-
131
- freezeFieldData({
132
- 'fileName': fileName,
133
- 'fileSize': fileSize,
134
- 'title': info.Title,
135
- 'author': info.Author,
136
- 'subject': info.Subject,
137
- 'keywords': info.Keywords,
138
- 'creationDate': creationDate,
139
- 'modificationDate': modDate,
140
- 'creator': info.Creator,
141
- 'producer': info.Producer,
142
- 'version': info.PDFFormatVersion,
143
- 'pageCount': _this2.pdfDocument.numPages,
144
- 'pageSize': pageSize,
145
- 'linearized': isLinearized,
146
- '_currentPageNumber': currentPageNumber,
147
- '_pagesRotation': pagesRotation
148
- });
149
- _this2._updateUI();
150
- return _this2.pdfDocument.getDownloadInfo();
151
- }).then(function (_ref5) {
152
- var length = _ref5.length;
153
-
154
- _this2.maybeFileSize = length;
155
- return _this2._parseFileSize(length);
156
- }).then(function (fileSize) {
157
- if (fileSize === _this2.fieldData['fileSize']) {
158
- return;
159
- }
160
- var data = Object.assign(Object.create(null), _this2.fieldData);
161
- data['fileSize'] = fileSize;
162
- freezeFieldData(data);
163
- _this2._updateUI();
164
- });
147
+
148
+ const data = Object.assign(Object.create(null), this.fieldData);
149
+ data["fileSize"] = fileSize;
150
+ freezeFieldData(data);
151
+
152
+ this._updateUI();
165
153
  });
154
+ });
155
+ }
156
+
157
+ close() {
158
+ this.overlayManager.close(this.overlayName);
159
+ }
160
+
161
+ setDocument(pdfDocument, url = null) {
162
+ if (this.pdfDocument) {
163
+ this._reset();
164
+
165
+ this._updateUI(true);
166
166
  }
167
- }, {
168
- key: 'close',
169
- value: function close() {
170
- this.overlayManager.close(this.overlayName);
167
+
168
+ if (!pdfDocument) {
169
+ return;
171
170
  }
172
- }, {
173
- key: 'setDocument',
174
- value: function setDocument(pdfDocument) {
175
- var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
176
-
177
- if (this.pdfDocument) {
178
- this._reset();
179
- this._updateUI(true);
180
- }
181
- if (!pdfDocument) {
182
- return;
183
- }
184
- this.pdfDocument = pdfDocument;
185
- this.url = url;
186
- this._dataAvailableCapability.resolve();
171
+
172
+ this.pdfDocument = pdfDocument;
173
+ this.url = url;
174
+
175
+ this._dataAvailableCapability.resolve();
176
+ }
177
+
178
+ setFileSize(fileSize) {
179
+ if (Number.isInteger(fileSize) && fileSize > 0) {
180
+ this.maybeFileSize = fileSize;
187
181
  }
188
- }, {
189
- key: 'setFileSize',
190
- value: function setFileSize(fileSize) {
191
- if (Number.isInteger(fileSize) && fileSize > 0) {
192
- this.maybeFileSize = fileSize;
182
+ }
183
+
184
+ _reset() {
185
+ this.pdfDocument = null;
186
+ this.url = null;
187
+ this.maybeFileSize = 0;
188
+ delete this.fieldData;
189
+ this._dataAvailableCapability = (0, _pdf.createPromiseCapability)();
190
+ this._currentPageNumber = 1;
191
+ this._pagesRotation = 0;
192
+ }
193
+
194
+ _updateUI(reset = false) {
195
+ if (reset || !this.fieldData) {
196
+ for (const id in this.fields) {
197
+ this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
193
198
  }
199
+
200
+ return;
194
201
  }
195
- }, {
196
- key: '_reset',
197
- value: function _reset() {
198
- this.pdfDocument = null;
199
- this.url = null;
200
- this.maybeFileSize = 0;
201
- delete this.fieldData;
202
- this._dataAvailableCapability = (0, _pdf.createPromiseCapability)();
203
- this._currentPageNumber = 1;
204
- this._pagesRotation = 0;
202
+
203
+ if (this.overlayManager.active !== this.overlayName) {
204
+ return;
205
205
  }
206
- }, {
207
- key: '_updateUI',
208
- value: function _updateUI() {
209
- var reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
210
-
211
- if (reset || !this.fieldData) {
212
- for (var id in this.fields) {
213
- this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
214
- }
215
- return;
216
- }
217
- if (this.overlayManager.active !== this.overlayName) {
218
- return;
219
- }
220
- for (var _id in this.fields) {
221
- var content = this.fieldData[_id];
222
- this.fields[_id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
223
- }
206
+
207
+ for (const id in this.fields) {
208
+ const content = this.fieldData[id];
209
+ this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
224
210
  }
225
- }, {
226
- key: '_parseFileSize',
227
- value: function _parseFileSize() {
228
- var fileSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
229
-
230
- var kb = fileSize / 1024;
231
- if (!kb) {
232
- return Promise.resolve(undefined);
233
- } else if (kb < 1024) {
234
- return this.l10n.get('document_properties_kb', {
235
- size_kb: (+kb.toPrecision(3)).toLocaleString(),
236
- size_b: fileSize.toLocaleString()
237
- }, '{{size_kb}} KB ({{size_b}} bytes)');
238
- }
239
- return this.l10n.get('document_properties_mb', {
240
- size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
211
+ }
212
+
213
+ async _parseFileSize(fileSize = 0) {
214
+ const kb = fileSize / 1024;
215
+
216
+ if (!kb) {
217
+ return undefined;
218
+ } else if (kb < 1024) {
219
+ return this.l10n.get("document_properties_kb", {
220
+ size_kb: (+kb.toPrecision(3)).toLocaleString(),
241
221
  size_b: fileSize.toLocaleString()
242
- }, '{{size_mb}} MB ({{size_b}} bytes)');
222
+ }, "{{size_kb}} KB ({{size_b}} bytes)");
243
223
  }
244
- }, {
245
- key: '_parsePageSize',
246
- value: function _parsePageSize(pageSizeInches, pagesRotation) {
247
- var _this3 = this;
248
224
 
249
- if (!pageSizeInches) {
250
- return Promise.resolve(undefined);
251
- }
252
- if (pagesRotation % 180 !== 0) {
253
- pageSizeInches = {
254
- width: pageSizeInches.height,
255
- height: pageSizeInches.width
256
- };
257
- }
258
- var isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
259
- var sizeInches = {
260
- width: Math.round(pageSizeInches.width * 100) / 100,
261
- height: Math.round(pageSizeInches.height * 100) / 100
225
+ return this.l10n.get("document_properties_mb", {
226
+ size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
227
+ size_b: fileSize.toLocaleString()
228
+ }, "{{size_mb}} MB ({{size_b}} bytes)");
229
+ }
230
+
231
+ async _parsePageSize(pageSizeInches, pagesRotation) {
232
+ if (!pageSizeInches) {
233
+ return undefined;
234
+ }
235
+
236
+ if (pagesRotation % 180 !== 0) {
237
+ pageSizeInches = {
238
+ width: pageSizeInches.height,
239
+ height: pageSizeInches.width
262
240
  };
263
- var sizeMillimeters = {
264
- width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
265
- height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
241
+ }
242
+
243
+ const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
244
+ let sizeInches = {
245
+ width: Math.round(pageSizeInches.width * 100) / 100,
246
+ height: Math.round(pageSizeInches.height * 100) / 100
247
+ };
248
+ let sizeMillimeters = {
249
+ width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
250
+ height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
251
+ };
252
+ let pageName = null;
253
+ let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
254
+
255
+ if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
256
+ const exactMillimeters = {
257
+ width: pageSizeInches.width * 25.4,
258
+ height: pageSizeInches.height * 25.4
259
+ };
260
+ const intMillimeters = {
261
+ width: Math.round(sizeMillimeters.width),
262
+ height: Math.round(sizeMillimeters.height)
266
263
  };
267
- var pageName = null;
268
- var name = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
269
- if (!name && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
270
- var exactMillimeters = {
271
- width: pageSizeInches.width * 25.4,
272
- height: pageSizeInches.height * 25.4
273
- };
274
- var intMillimeters = {
275
- width: Math.round(sizeMillimeters.width),
276
- height: Math.round(sizeMillimeters.height)
277
- };
278
- if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
279
- name = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
280
- if (name) {
281
- sizeInches = {
282
- width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
283
- height: Math.round(intMillimeters.height / 25.4 * 100) / 100
284
- };
285
- sizeMillimeters = intMillimeters;
286
- }
264
+
265
+ if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
266
+ rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
267
+
268
+ if (rawName) {
269
+ sizeInches = {
270
+ width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
271
+ height: Math.round(intMillimeters.height / 25.4 * 100) / 100
272
+ };
273
+ sizeMillimeters = intMillimeters;
287
274
  }
288
275
  }
289
- if (name) {
290
- pageName = this.l10n.get('document_properties_page_size_name_' + name.toLowerCase(), null, name);
291
- }
292
- return Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get('document_properties_page_size_unit_' + (this._isNonMetricLocale ? 'inches' : 'millimeters'), null, this._isNonMetricLocale ? 'in' : 'mm'), pageName, this.l10n.get('document_properties_page_size_orientation_' + (isPortrait ? 'portrait' : 'landscape'), null, isPortrait ? 'portrait' : 'landscape')]).then(function (_ref6) {
293
- var _ref7 = _slicedToArray(_ref6, 4),
294
- _ref7$ = _ref7[0],
295
- width = _ref7$.width,
296
- height = _ref7$.height,
297
- unit = _ref7[1],
298
- name = _ref7[2],
299
- orientation = _ref7[3];
300
-
301
- return _this3.l10n.get('document_properties_page_size_dimension_' + (name ? 'name_' : '') + 'string', {
302
- width: width.toLocaleString(),
303
- height: height.toLocaleString(),
304
- unit: unit,
305
- name: name,
306
- orientation: orientation
307
- }, '{{width}} × {{height}} {{unit}} (' + (name ? '{{name}}, ' : '') + '{{orientation}})');
308
- });
309
276
  }
310
- }, {
311
- key: '_parseDate',
312
- value: function _parseDate(inputDate) {
313
- if (!inputDate) {
314
- return;
315
- }
316
- var dateToParse = inputDate;
317
- if (dateToParse.substring(0, 2) === 'D:') {
318
- dateToParse = dateToParse.substring(2);
319
- }
320
- var year = parseInt(dateToParse.substring(0, 4), 10);
321
- var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
322
- var day = parseInt(dateToParse.substring(6, 8), 10);
323
- var hours = parseInt(dateToParse.substring(8, 10), 10);
324
- var minutes = parseInt(dateToParse.substring(10, 12), 10);
325
- var seconds = parseInt(dateToParse.substring(12, 14), 10);
326
- var utRel = dateToParse.substring(14, 15);
327
- var offsetHours = parseInt(dateToParse.substring(15, 17), 10);
328
- var offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
329
- if (utRel === '-') {
330
- hours += offsetHours;
331
- minutes += offsetMinutes;
332
- } else if (utRel === '+') {
333
- hours -= offsetHours;
334
- minutes -= offsetMinutes;
335
- }
336
- var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
337
- var dateString = date.toLocaleDateString();
338
- var timeString = date.toLocaleTimeString();
339
- return this.l10n.get('document_properties_date_string', {
340
- date: dateString,
341
- time: timeString
342
- }, '{{date}}, {{time}}');
277
+
278
+ if (rawName) {
279
+ pageName = this.l10n.get("document_properties_page_size_name_" + rawName.toLowerCase(), null, rawName);
343
280
  }
344
- }, {
345
- key: '_parseLinearization',
346
- value: function _parseLinearization(isLinearized) {
347
- return this.l10n.get('document_properties_linearized_' + (isLinearized ? 'yes' : 'no'), null, isLinearized ? 'Yes' : 'No');
281
+
282
+ return Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get("document_properties_page_size_unit_" + (this._isNonMetricLocale ? "inches" : "millimeters"), null, this._isNonMetricLocale ? "in" : "mm"), pageName, this.l10n.get("document_properties_page_size_orientation_" + (isPortrait ? "portrait" : "landscape"), null, isPortrait ? "portrait" : "landscape")]).then(([{
283
+ width,
284
+ height
285
+ }, unit, name, orientation]) => {
286
+ return this.l10n.get("document_properties_page_size_dimension_" + (name ? "name_" : "") + "string", {
287
+ width: width.toLocaleString(),
288
+ height: height.toLocaleString(),
289
+ unit,
290
+ name,
291
+ orientation
292
+ }, "{{width}} × {{height}} {{unit}} (" + (name ? "{{name}}, " : "") + "{{orientation}})");
293
+ });
294
+ }
295
+
296
+ async _parseDate(inputDate) {
297
+ const dateObject = _pdf.PDFDateString.toDateObject(inputDate);
298
+
299
+ if (!dateObject) {
300
+ return undefined;
348
301
  }
349
- }]);
350
302
 
351
- return PDFDocumentProperties;
352
- }();
303
+ return this.l10n.get("document_properties_date_string", {
304
+ date: dateObject.toLocaleDateString(),
305
+ time: dateObject.toLocaleTimeString()
306
+ }, "{{date}}, {{time}}");
307
+ }
308
+
309
+ _parseLinearization(isLinearized) {
310
+ return this.l10n.get("document_properties_linearized_" + (isLinearized ? "yes" : "no"), null, isLinearized ? "Yes" : "No");
311
+ }
312
+
313
+ }
353
314
 
354
315
  exports.PDFDocumentProperties = PDFDocumentProperties;