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,350 +19,404 @@
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.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = undefined;
27
+ exports.getQuadPoints = getQuadPoints;
28
+ exports.MarkupAnnotation = exports.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = void 0;
28
29
 
29
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
30
+ var _util = require("../shared/util.js");
30
31
 
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; }; }();
32
+ var _obj = require("./obj.js");
32
33
 
33
- var _util = require('../shared/util');
34
+ var _primitives = require("./primitives.js");
34
35
 
35
- var _obj = require('./obj');
36
+ var _colorspace = require("./colorspace.js");
36
37
 
37
- var _primitives = require('./primitives');
38
+ var _core_utils = require("./core_utils.js");
38
39
 
39
- var _colorspace = require('./colorspace');
40
+ var _operator_list = require("./operator_list.js");
40
41
 
41
- var _operator_list = require('./operator_list');
42
+ var _stream = require("./stream.js");
42
43
 
43
- var _stream = require('./stream');
44
+ class AnnotationFactory {
45
+ static create(xref, ref, pdfManager, idFactory) {
46
+ return pdfManager.ensure(this, "_create", [xref, ref, pdfManager, idFactory]);
47
+ }
48
+
49
+ static _create(xref, ref, pdfManager, idFactory) {
50
+ const dict = xref.fetchIfRef(ref);
51
+
52
+ if (!(0, _primitives.isDict)(dict)) {
53
+ return undefined;
54
+ }
44
55
 
45
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
56
+ const id = (0, _primitives.isRef)(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`;
57
+ let subtype = dict.get("Subtype");
58
+ subtype = (0, _primitives.isName)(subtype) ? subtype.name : null;
59
+ const parameters = {
60
+ xref,
61
+ dict,
62
+ subtype,
63
+ id,
64
+ pdfManager
65
+ };
46
66
 
47
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
67
+ switch (subtype) {
68
+ case "Link":
69
+ return new LinkAnnotation(parameters);
48
70
 
49
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
71
+ case "Text":
72
+ return new TextAnnotation(parameters);
50
73
 
51
- var AnnotationFactory = function () {
52
- function AnnotationFactory() {
53
- _classCallCheck(this, AnnotationFactory);
54
- }
74
+ case "Widget":
75
+ let fieldType = (0, _core_utils.getInheritableProperty)({
76
+ dict,
77
+ key: "FT"
78
+ });
79
+ fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
80
+
81
+ switch (fieldType) {
82
+ case "Tx":
83
+ return new TextWidgetAnnotation(parameters);
84
+
85
+ case "Btn":
86
+ return new ButtonWidgetAnnotation(parameters);
87
+
88
+ case "Ch":
89
+ return new ChoiceWidgetAnnotation(parameters);
90
+ }
91
+
92
+ (0, _util.warn)('Unimplemented widget field type "' + fieldType + '", ' + "falling back to base field type.");
93
+ return new WidgetAnnotation(parameters);
94
+
95
+ case "Popup":
96
+ return new PopupAnnotation(parameters);
97
+
98
+ case "FreeText":
99
+ return new FreeTextAnnotation(parameters);
100
+
101
+ case "Line":
102
+ return new LineAnnotation(parameters);
103
+
104
+ case "Square":
105
+ return new SquareAnnotation(parameters);
106
+
107
+ case "Circle":
108
+ return new CircleAnnotation(parameters);
109
+
110
+ case "PolyLine":
111
+ return new PolylineAnnotation(parameters);
112
+
113
+ case "Polygon":
114
+ return new PolygonAnnotation(parameters);
115
+
116
+ case "Caret":
117
+ return new CaretAnnotation(parameters);
118
+
119
+ case "Ink":
120
+ return new InkAnnotation(parameters);
121
+
122
+ case "Highlight":
123
+ return new HighlightAnnotation(parameters);
124
+
125
+ case "Underline":
126
+ return new UnderlineAnnotation(parameters);
55
127
 
56
- _createClass(AnnotationFactory, null, [{
57
- key: 'create',
58
- value: function create(xref, ref, pdfManager, idFactory) {
59
- return pdfManager.ensure(this, '_create', [xref, ref, pdfManager, idFactory]);
128
+ case "Squiggly":
129
+ return new SquigglyAnnotation(parameters);
130
+
131
+ case "StrikeOut":
132
+ return new StrikeOutAnnotation(parameters);
133
+
134
+ case "Stamp":
135
+ return new StampAnnotation(parameters);
136
+
137
+ case "FileAttachment":
138
+ return new FileAttachmentAnnotation(parameters);
139
+
140
+ default:
141
+ if (!subtype) {
142
+ (0, _util.warn)("Annotation is missing the required /Subtype.");
143
+ } else {
144
+ (0, _util.warn)('Unimplemented annotation type "' + subtype + '", ' + "falling back to base annotation.");
145
+ }
146
+
147
+ return new Annotation(parameters);
60
148
  }
61
- }, {
62
- key: '_create',
63
- value: function _create(xref, ref, pdfManager, idFactory) {
64
- var dict = xref.fetchIfRef(ref);
65
- if (!(0, _primitives.isDict)(dict)) {
66
- return;
67
- }
68
- var id = (0, _primitives.isRef)(ref) ? ref.toString() : 'annot_' + idFactory.createObjId();
69
- var subtype = dict.get('Subtype');
70
- subtype = (0, _primitives.isName)(subtype) ? subtype.name : null;
71
- var parameters = {
72
- xref: xref,
73
- dict: dict,
74
- ref: (0, _primitives.isRef)(ref) ? ref : null,
75
- subtype: subtype,
76
- id: id,
77
- pdfManager: pdfManager
78
- };
79
- switch (subtype) {
80
- case 'Link':
81
- return new LinkAnnotation(parameters);
82
- case 'Text':
83
- return new TextAnnotation(parameters);
84
- case 'Widget':
85
- var fieldType = (0, _util.getInheritableProperty)({
86
- dict: dict,
87
- key: 'FT'
88
- });
89
- fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
90
- switch (fieldType) {
91
- case 'Tx':
92
- return new TextWidgetAnnotation(parameters);
93
- case 'Btn':
94
- return new ButtonWidgetAnnotation(parameters);
95
- case 'Ch':
96
- return new ChoiceWidgetAnnotation(parameters);
97
- }
98
- (0, _util.warn)('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
99
- return new WidgetAnnotation(parameters);
100
- case 'Popup':
101
- return new PopupAnnotation(parameters);
102
- case 'Line':
103
- return new LineAnnotation(parameters);
104
- case 'Square':
105
- return new SquareAnnotation(parameters);
106
- case 'Circle':
107
- return new CircleAnnotation(parameters);
108
- case 'PolyLine':
109
- return new PolylineAnnotation(parameters);
110
- case 'Polygon':
111
- return new PolygonAnnotation(parameters);
112
- case 'Ink':
113
- return new InkAnnotation(parameters);
114
- case 'Highlight':
115
- return new HighlightAnnotation(parameters);
116
- case 'Underline':
117
- return new UnderlineAnnotation(parameters);
118
- case 'Squiggly':
119
- return new SquigglyAnnotation(parameters);
120
- case 'StrikeOut':
121
- return new StrikeOutAnnotation(parameters);
122
- case 'Stamp':
123
- return new StampAnnotation(parameters);
124
- case 'FileAttachment':
125
- return new FileAttachmentAnnotation(parameters);
126
- default:
127
- if (!subtype) {
128
- (0, _util.warn)('Annotation is missing the required /Subtype.');
129
- } else {
130
- (0, _util.warn)('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
131
- }
132
- return new Annotation(parameters);
149
+ }
150
+
151
+ }
152
+
153
+ exports.AnnotationFactory = AnnotationFactory;
154
+
155
+ function getQuadPoints(dict, rect) {
156
+ if (!dict.has("QuadPoints")) {
157
+ return null;
158
+ }
159
+
160
+ const quadPoints = dict.getArray("QuadPoints");
161
+
162
+ if (!Array.isArray(quadPoints) || quadPoints.length % 8 > 0) {
163
+ return null;
164
+ }
165
+
166
+ const quadPointsLists = [];
167
+
168
+ for (let i = 0, ii = quadPoints.length / 8; i < ii; i++) {
169
+ quadPointsLists.push([]);
170
+
171
+ for (let j = i * 8, jj = i * 8 + 8; j < jj; j += 2) {
172
+ const x = quadPoints[j];
173
+ const y = quadPoints[j + 1];
174
+
175
+ if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) {
176
+ return null;
133
177
  }
178
+
179
+ quadPointsLists[i].push({
180
+ x,
181
+ y
182
+ });
134
183
  }
135
- }]);
184
+ }
136
185
 
137
- return AnnotationFactory;
138
- }();
186
+ return quadPointsLists;
187
+ }
139
188
 
140
189
  function getTransformMatrix(rect, bbox, matrix) {
141
- var bounds = _util.Util.getAxialAlignedBoundingBox(bbox, matrix);
142
- var minX = bounds[0];
143
- var minY = bounds[1];
144
- var maxX = bounds[2];
145
- var maxY = bounds[3];
190
+ const [minX, minY, maxX, maxY] = _util.Util.getAxialAlignedBoundingBox(bbox, matrix);
191
+
146
192
  if (minX === maxX || minY === maxY) {
147
193
  return [1, 0, 0, 1, rect[0], rect[1]];
148
194
  }
149
- var xRatio = (rect[2] - rect[0]) / (maxX - minX);
150
- var yRatio = (rect[3] - rect[1]) / (maxY - minY);
195
+
196
+ const xRatio = (rect[2] - rect[0]) / (maxX - minX);
197
+ const yRatio = (rect[3] - rect[1]) / (maxY - minY);
151
198
  return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio];
152
199
  }
153
200
 
154
- var Annotation = function () {
155
- function Annotation(params) {
156
- _classCallCheck(this, Annotation);
157
-
158
- var dict = params.dict;
159
- this.setFlags(dict.get('F'));
160
- this.setRectangle(dict.getArray('Rect'));
161
- this.setColor(dict.getArray('C'));
201
+ class Annotation {
202
+ constructor(params) {
203
+ const dict = params.dict;
204
+ this.setContents(dict.get("Contents"));
205
+ this.setModificationDate(dict.get("M"));
206
+ this.setFlags(dict.get("F"));
207
+ this.setRectangle(dict.getArray("Rect"));
208
+ this.setColor(dict.getArray("C"));
162
209
  this.setBorderStyle(dict);
163
210
  this.setAppearance(dict);
164
211
  this.data = {
165
212
  annotationFlags: this.flags,
166
213
  borderStyle: this.borderStyle,
167
214
  color: this.color,
215
+ contents: this.contents,
168
216
  hasAppearance: !!this.appearance,
169
217
  id: params.id,
218
+ modificationDate: this.modificationDate,
170
219
  rect: this.rectangle,
171
220
  subtype: params.subtype
172
221
  };
173
222
  }
174
223
 
175
- _createClass(Annotation, [{
176
- key: '_hasFlag',
177
- value: function _hasFlag(flags, flag) {
178
- return !!(flags & flag);
179
- }
180
- }, {
181
- key: '_isViewable',
182
- value: function _isViewable(flags) {
183
- return !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN) && !this._hasFlag(flags, _util.AnnotationFlag.NOVIEW);
184
- }
185
- }, {
186
- key: '_isPrintable',
187
- value: function _isPrintable(flags) {
188
- return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN);
189
- }
190
- }, {
191
- key: 'setFlags',
192
- value: function setFlags(flags) {
193
- this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
194
- }
195
- }, {
196
- key: 'hasFlag',
197
- value: function hasFlag(flag) {
198
- return this._hasFlag(this.flags, flag);
199
- }
200
- }, {
201
- key: 'setRectangle',
202
- value: function setRectangle(rectangle) {
203
- if (Array.isArray(rectangle) && rectangle.length === 4) {
204
- this.rectangle = _util.Util.normalizeRect(rectangle);
205
- } else {
206
- this.rectangle = [0, 0, 0, 0];
207
- }
224
+ _hasFlag(flags, flag) {
225
+ return !!(flags & flag);
226
+ }
227
+
228
+ _isViewable(flags) {
229
+ return !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN) && !this._hasFlag(flags, _util.AnnotationFlag.NOVIEW);
230
+ }
231
+
232
+ _isPrintable(flags) {
233
+ return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN);
234
+ }
235
+
236
+ get viewable() {
237
+ if (this.flags === 0) {
238
+ return true;
239
+ }
240
+
241
+ return this._isViewable(this.flags);
242
+ }
243
+
244
+ get printable() {
245
+ if (this.flags === 0) {
246
+ return false;
208
247
  }
209
- }, {
210
- key: 'setColor',
211
- value: function setColor(color) {
212
- var rgbColor = new Uint8ClampedArray(3);
213
- if (!Array.isArray(color)) {
248
+
249
+ return this._isPrintable(this.flags);
250
+ }
251
+
252
+ setContents(contents) {
253
+ this.contents = (0, _util.stringToPDFString)(contents || "");
254
+ }
255
+
256
+ setModificationDate(modificationDate) {
257
+ this.modificationDate = (0, _util.isString)(modificationDate) ? modificationDate : null;
258
+ }
259
+
260
+ setFlags(flags) {
261
+ this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
262
+ }
263
+
264
+ hasFlag(flag) {
265
+ return this._hasFlag(this.flags, flag);
266
+ }
267
+
268
+ setRectangle(rectangle) {
269
+ if (Array.isArray(rectangle) && rectangle.length === 4) {
270
+ this.rectangle = _util.Util.normalizeRect(rectangle);
271
+ } else {
272
+ this.rectangle = [0, 0, 0, 0];
273
+ }
274
+ }
275
+
276
+ setColor(color) {
277
+ const rgbColor = new Uint8ClampedArray(3);
278
+
279
+ if (!Array.isArray(color)) {
280
+ this.color = rgbColor;
281
+ return;
282
+ }
283
+
284
+ switch (color.length) {
285
+ case 0:
286
+ this.color = null;
287
+ break;
288
+
289
+ case 1:
290
+ _colorspace.ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
291
+
214
292
  this.color = rgbColor;
215
- return;
216
- }
217
- switch (color.length) {
218
- case 0:
219
- this.color = null;
220
- break;
221
- case 1:
222
- _colorspace.ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
223
- this.color = rgbColor;
224
- break;
225
- case 3:
226
- _colorspace.ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
227
- this.color = rgbColor;
228
- break;
229
- case 4:
230
- _colorspace.ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
231
- this.color = rgbColor;
232
- break;
233
- default:
234
- this.color = rgbColor;
235
- break;
236
- }
293
+ break;
294
+
295
+ case 3:
296
+ _colorspace.ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
297
+
298
+ this.color = rgbColor;
299
+ break;
300
+
301
+ case 4:
302
+ _colorspace.ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
303
+
304
+ this.color = rgbColor;
305
+ break;
306
+
307
+ default:
308
+ this.color = rgbColor;
309
+ break;
310
+ }
311
+ }
312
+
313
+ setBorderStyle(borderStyle) {
314
+ this.borderStyle = new AnnotationBorderStyle();
315
+
316
+ if (!(0, _primitives.isDict)(borderStyle)) {
317
+ return;
237
318
  }
238
- }, {
239
- key: 'setBorderStyle',
240
- value: function setBorderStyle(borderStyle) {
241
- this.borderStyle = new AnnotationBorderStyle();
242
- if (!(0, _primitives.isDict)(borderStyle)) {
243
- return;
319
+
320
+ if (borderStyle.has("BS")) {
321
+ const dict = borderStyle.get("BS");
322
+ const dictType = dict.get("Type");
323
+
324
+ if (!dictType || (0, _primitives.isName)(dictType, "Border")) {
325
+ this.borderStyle.setWidth(dict.get("W"), this.rectangle);
326
+ this.borderStyle.setStyle(dict.get("S"));
327
+ this.borderStyle.setDashArray(dict.getArray("D"));
244
328
  }
245
- if (borderStyle.has('BS')) {
246
- var dict = borderStyle.get('BS');
247
- var dictType = dict.get('Type');
248
- if (!dictType || (0, _primitives.isName)(dictType, 'Border')) {
249
- this.borderStyle.setWidth(dict.get('W'));
250
- this.borderStyle.setStyle(dict.get('S'));
251
- this.borderStyle.setDashArray(dict.getArray('D'));
252
- }
253
- } else if (borderStyle.has('Border')) {
254
- var array = borderStyle.getArray('Border');
255
- if (Array.isArray(array) && array.length >= 3) {
256
- this.borderStyle.setHorizontalCornerRadius(array[0]);
257
- this.borderStyle.setVerticalCornerRadius(array[1]);
258
- this.borderStyle.setWidth(array[2]);
259
- if (array.length === 4) {
260
- this.borderStyle.setDashArray(array[3]);
261
- }
329
+ } else if (borderStyle.has("Border")) {
330
+ const array = borderStyle.getArray("Border");
331
+
332
+ if (Array.isArray(array) && array.length >= 3) {
333
+ this.borderStyle.setHorizontalCornerRadius(array[0]);
334
+ this.borderStyle.setVerticalCornerRadius(array[1]);
335
+ this.borderStyle.setWidth(array[2], this.rectangle);
336
+
337
+ if (array.length === 4) {
338
+ this.borderStyle.setDashArray(array[3]);
262
339
  }
263
- } else {
264
- this.borderStyle.setWidth(0);
265
340
  }
341
+ } else {
342
+ this.borderStyle.setWidth(0);
266
343
  }
267
- }, {
268
- key: 'setAppearance',
269
- value: function setAppearance(dict) {
270
- this.appearance = null;
271
- var appearanceStates = dict.get('AP');
272
- if (!(0, _primitives.isDict)(appearanceStates)) {
273
- return;
274
- }
275
- var normalAppearanceState = appearanceStates.get('N');
276
- if ((0, _primitives.isStream)(normalAppearanceState)) {
277
- this.appearance = normalAppearanceState;
278
- return;
279
- }
280
- if (!(0, _primitives.isDict)(normalAppearanceState)) {
281
- return;
282
- }
283
- var as = dict.get('AS');
284
- if (!(0, _primitives.isName)(as) || !normalAppearanceState.has(as.name)) {
285
- return;
286
- }
287
- this.appearance = normalAppearanceState.get(as.name);
344
+ }
345
+
346
+ setAppearance(dict) {
347
+ this.appearance = null;
348
+ const appearanceStates = dict.get("AP");
349
+
350
+ if (!(0, _primitives.isDict)(appearanceStates)) {
351
+ return;
288
352
  }
289
- }, {
290
- key: '_preparePopup',
291
- value: function _preparePopup(dict) {
292
- if (!dict.has('C')) {
293
- this.data.color = null;
294
- }
295
- this.data.hasPopup = dict.has('Popup');
296
- this.data.title = (0, _util.stringToPDFString)(dict.get('T') || '');
297
- this.data.contents = (0, _util.stringToPDFString)(dict.get('Contents') || '');
298
- }
299
- }, {
300
- key: 'loadResources',
301
- value: function loadResources(keys) {
302
- return this.appearance.dict.getAsync('Resources').then(function (resources) {
303
- if (!resources) {
304
- return;
305
- }
306
- var objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref);
307
- return objectLoader.load().then(function () {
308
- return resources;
309
- });
310
- });
353
+
354
+ const normalAppearanceState = appearanceStates.get("N");
355
+
356
+ if ((0, _primitives.isStream)(normalAppearanceState)) {
357
+ this.appearance = normalAppearanceState;
358
+ return;
311
359
  }
312
- }, {
313
- key: 'getOperatorList',
314
- value: function getOperatorList(evaluator, task, renderForms) {
315
- var _this = this;
316
360
 
317
- if (!this.appearance) {
318
- return Promise.resolve(new _operator_list.OperatorList());
319
- }
320
- var data = this.data;
321
- var appearanceDict = this.appearance.dict;
322
- var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']);
323
- var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
324
- var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0];
325
- var transform = getTransformMatrix(data.rect, bbox, matrix);
326
- return resourcesPromise.then(function (resources) {
327
- var opList = new _operator_list.OperatorList();
328
- opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
329
- return evaluator.getOperatorList({
330
- stream: _this.appearance,
331
- task: task,
332
- resources: resources,
333
- operatorList: opList
334
- }).then(function () {
335
- opList.addOp(_util.OPS.endAnnotation, []);
336
- _this.appearance.reset();
337
- return opList;
338
- });
339
- });
361
+ if (!(0, _primitives.isDict)(normalAppearanceState)) {
362
+ return;
340
363
  }
341
- }, {
342
- key: 'viewable',
343
- get: function get() {
344
- if (this.flags === 0) {
345
- return true;
346
- }
347
- return this._isViewable(this.flags);
364
+
365
+ const as = dict.get("AS");
366
+
367
+ if (!(0, _primitives.isName)(as) || !normalAppearanceState.has(as.name)) {
368
+ return;
348
369
  }
349
- }, {
350
- key: 'printable',
351
- get: function get() {
352
- if (this.flags === 0) {
353
- return false;
370
+
371
+ this.appearance = normalAppearanceState.get(as.name);
372
+ }
373
+
374
+ loadResources(keys) {
375
+ return this.appearance.dict.getAsync("Resources").then(resources => {
376
+ if (!resources) {
377
+ return undefined;
354
378
  }
355
- return this._isPrintable(this.flags);
379
+
380
+ const objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref);
381
+ return objectLoader.load().then(function () {
382
+ return resources;
383
+ });
384
+ });
385
+ }
386
+
387
+ getOperatorList(evaluator, task, renderForms) {
388
+ if (!this.appearance) {
389
+ return Promise.resolve(new _operator_list.OperatorList());
356
390
  }
357
- }]);
358
391
 
359
- return Annotation;
360
- }();
392
+ const data = this.data;
393
+ const appearanceDict = this.appearance.dict;
394
+ const resourcesPromise = this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"]);
395
+ const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
396
+ const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
397
+ const transform = getTransformMatrix(data.rect, bbox, matrix);
398
+ return resourcesPromise.then(resources => {
399
+ const opList = new _operator_list.OperatorList();
400
+ opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
401
+ return evaluator.getOperatorList({
402
+ stream: this.appearance,
403
+ task,
404
+ resources,
405
+ operatorList: opList
406
+ }).then(() => {
407
+ opList.addOp(_util.OPS.endAnnotation, []);
408
+ this.appearance.reset();
409
+ return opList;
410
+ });
411
+ });
412
+ }
361
413
 
362
- var AnnotationBorderStyle = function () {
363
- function AnnotationBorderStyle() {
364
- _classCallCheck(this, AnnotationBorderStyle);
414
+ }
415
+
416
+ exports.Annotation = Annotation;
365
417
 
418
+ class AnnotationBorderStyle {
419
+ constructor() {
366
420
  this.width = 1;
367
421
  this.style = _util.AnnotationBorderStyleType.SOLID;
368
422
  this.dashArray = [3];
@@ -370,652 +424,675 @@ var AnnotationBorderStyle = function () {
370
424
  this.verticalCornerRadius = 0;
371
425
  }
372
426
 
373
- _createClass(AnnotationBorderStyle, [{
374
- key: 'setWidth',
375
- value: function setWidth(width) {
376
- if (Number.isInteger(width)) {
377
- this.width = width;
378
- }
427
+ setWidth(width, rect = [0, 0, 0, 0]) {
428
+ if ((0, _primitives.isName)(width)) {
429
+ this.width = 0;
430
+ return;
379
431
  }
380
- }, {
381
- key: 'setStyle',
382
- value: function setStyle(style) {
383
- if (!style) {
384
- return;
385
- }
386
- switch (style.name) {
387
- case 'S':
388
- this.style = _util.AnnotationBorderStyleType.SOLID;
389
- break;
390
- case 'D':
391
- this.style = _util.AnnotationBorderStyleType.DASHED;
392
- break;
393
- case 'B':
394
- this.style = _util.AnnotationBorderStyleType.BEVELED;
395
- break;
396
- case 'I':
397
- this.style = _util.AnnotationBorderStyleType.INSET;
398
- break;
399
- case 'U':
400
- this.style = _util.AnnotationBorderStyleType.UNDERLINE;
401
- break;
402
- default:
403
- break;
432
+
433
+ if (Number.isInteger(width)) {
434
+ if (width > 0) {
435
+ const maxWidth = (rect[2] - rect[0]) / 2;
436
+ const maxHeight = (rect[3] - rect[1]) / 2;
437
+
438
+ if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) {
439
+ (0, _util.warn)(`AnnotationBorderStyle.setWidth - ignoring width: ${width}`);
440
+ width = 1;
441
+ }
404
442
  }
443
+
444
+ this.width = width;
405
445
  }
406
- }, {
407
- key: 'setDashArray',
408
- value: function setDashArray(dashArray) {
409
- if (Array.isArray(dashArray) && dashArray.length > 0) {
410
- var isValid = true;
411
- var allZeros = true;
412
- for (var i = 0, len = dashArray.length; i < len; i++) {
413
- var element = dashArray[i];
414
- var validNumber = +element >= 0;
415
- if (!validNumber) {
416
- isValid = false;
417
- break;
418
- } else if (element > 0) {
419
- allZeros = false;
420
- }
421
- }
422
- if (isValid && !allZeros) {
423
- this.dashArray = dashArray;
424
- } else {
425
- this.width = 0;
446
+ }
447
+
448
+ setStyle(style) {
449
+ if (!(0, _primitives.isName)(style)) {
450
+ return;
451
+ }
452
+
453
+ switch (style.name) {
454
+ case "S":
455
+ this.style = _util.AnnotationBorderStyleType.SOLID;
456
+ break;
457
+
458
+ case "D":
459
+ this.style = _util.AnnotationBorderStyleType.DASHED;
460
+ break;
461
+
462
+ case "B":
463
+ this.style = _util.AnnotationBorderStyleType.BEVELED;
464
+ break;
465
+
466
+ case "I":
467
+ this.style = _util.AnnotationBorderStyleType.INSET;
468
+ break;
469
+
470
+ case "U":
471
+ this.style = _util.AnnotationBorderStyleType.UNDERLINE;
472
+ break;
473
+
474
+ default:
475
+ break;
476
+ }
477
+ }
478
+
479
+ setDashArray(dashArray) {
480
+ if (Array.isArray(dashArray) && dashArray.length > 0) {
481
+ let isValid = true;
482
+ let allZeros = true;
483
+
484
+ for (const element of dashArray) {
485
+ const validNumber = +element >= 0;
486
+
487
+ if (!validNumber) {
488
+ isValid = false;
489
+ break;
490
+ } else if (element > 0) {
491
+ allZeros = false;
426
492
  }
427
- } else if (dashArray) {
493
+ }
494
+
495
+ if (isValid && !allZeros) {
496
+ this.dashArray = dashArray;
497
+ } else {
428
498
  this.width = 0;
429
499
  }
500
+ } else if (dashArray) {
501
+ this.width = 0;
430
502
  }
431
- }, {
432
- key: 'setHorizontalCornerRadius',
433
- value: function setHorizontalCornerRadius(radius) {
434
- if (Number.isInteger(radius)) {
435
- this.horizontalCornerRadius = radius;
436
- }
503
+ }
504
+
505
+ setHorizontalCornerRadius(radius) {
506
+ if (Number.isInteger(radius)) {
507
+ this.horizontalCornerRadius = radius;
437
508
  }
438
- }, {
439
- key: 'setVerticalCornerRadius',
440
- value: function setVerticalCornerRadius(radius) {
441
- if (Number.isInteger(radius)) {
442
- this.verticalCornerRadius = radius;
443
- }
509
+ }
510
+
511
+ setVerticalCornerRadius(radius) {
512
+ if (Number.isInteger(radius)) {
513
+ this.verticalCornerRadius = radius;
444
514
  }
445
- }]);
515
+ }
516
+
517
+ }
446
518
 
447
- return AnnotationBorderStyle;
448
- }();
519
+ exports.AnnotationBorderStyle = AnnotationBorderStyle;
520
+
521
+ class MarkupAnnotation extends Annotation {
522
+ constructor(parameters) {
523
+ super(parameters);
524
+ const dict = parameters.dict;
449
525
 
450
- var WidgetAnnotation = function (_Annotation) {
451
- _inherits(WidgetAnnotation, _Annotation);
526
+ if (dict.has("IRT")) {
527
+ const rawIRT = dict.getRaw("IRT");
528
+ this.data.inReplyTo = (0, _primitives.isRef)(rawIRT) ? rawIRT.toString() : null;
529
+ const rt = dict.get("RT");
530
+ this.data.replyType = (0, _primitives.isName)(rt) ? rt.name : _util.AnnotationReplyType.REPLY;
531
+ }
452
532
 
453
- function WidgetAnnotation(params) {
454
- _classCallCheck(this, WidgetAnnotation);
533
+ if (this.data.replyType === _util.AnnotationReplyType.GROUP) {
534
+ const parent = dict.get("IRT");
535
+ this.data.title = (0, _util.stringToPDFString)(parent.get("T") || "");
536
+ this.setContents(parent.get("Contents"));
537
+ this.data.contents = this.contents;
455
538
 
456
- var _this2 = _possibleConstructorReturn(this, (WidgetAnnotation.__proto__ || Object.getPrototypeOf(WidgetAnnotation)).call(this, params));
539
+ if (!parent.has("CreationDate")) {
540
+ this.data.creationDate = null;
541
+ } else {
542
+ this.setCreationDate(parent.get("CreationDate"));
543
+ this.data.creationDate = this.creationDate;
544
+ }
457
545
 
458
- var dict = params.dict;
459
- var data = _this2.data;
546
+ if (!parent.has("M")) {
547
+ this.data.modificationDate = null;
548
+ } else {
549
+ this.setModificationDate(parent.get("M"));
550
+ this.data.modificationDate = this.modificationDate;
551
+ }
552
+
553
+ this.data.hasPopup = parent.has("Popup");
554
+
555
+ if (!parent.has("C")) {
556
+ this.data.color = null;
557
+ } else {
558
+ this.setColor(parent.getArray("C"));
559
+ this.data.color = this.color;
560
+ }
561
+ } else {
562
+ this.data.title = (0, _util.stringToPDFString)(dict.get("T") || "");
563
+ this.setCreationDate(dict.get("CreationDate"));
564
+ this.data.creationDate = this.creationDate;
565
+ this.data.hasPopup = dict.has("Popup");
566
+
567
+ if (!dict.has("C")) {
568
+ this.data.color = null;
569
+ }
570
+ }
571
+ }
572
+
573
+ setCreationDate(creationDate) {
574
+ this.creationDate = (0, _util.isString)(creationDate) ? creationDate : null;
575
+ }
576
+
577
+ }
578
+
579
+ exports.MarkupAnnotation = MarkupAnnotation;
580
+
581
+ class WidgetAnnotation extends Annotation {
582
+ constructor(params) {
583
+ super(params);
584
+ const dict = params.dict;
585
+ const data = this.data;
460
586
  data.annotationType = _util.AnnotationType.WIDGET;
461
- data.fieldName = _this2._constructFieldName(dict);
462
- data.fieldValue = (0, _util.getInheritableProperty)({
463
- dict: dict,
464
- key: 'V',
587
+ data.fieldName = this._constructFieldName(dict);
588
+ data.fieldValue = (0, _core_utils.getInheritableProperty)({
589
+ dict,
590
+ key: "V",
465
591
  getArray: true
466
592
  });
467
- data.alternativeText = (0, _util.stringToPDFString)(dict.get('TU') || '');
468
- data.defaultAppearance = (0, _util.getInheritableProperty)({
469
- dict: dict,
470
- key: 'DA'
471
- }) || '';
472
- var fieldType = (0, _util.getInheritableProperty)({
473
- dict: dict,
474
- key: 'FT'
593
+ data.alternativeText = (0, _util.stringToPDFString)(dict.get("TU") || "");
594
+ data.defaultAppearance = (0, _core_utils.getInheritableProperty)({
595
+ dict,
596
+ key: "DA"
597
+ }) || "";
598
+ const fieldType = (0, _core_utils.getInheritableProperty)({
599
+ dict,
600
+ key: "FT"
475
601
  });
476
602
  data.fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
477
- _this2.fieldResources = (0, _util.getInheritableProperty)({
478
- dict: dict,
479
- key: 'DR'
603
+ this.fieldResources = (0, _core_utils.getInheritableProperty)({
604
+ dict,
605
+ key: "DR"
480
606
  }) || _primitives.Dict.empty;
481
- data.fieldFlags = (0, _util.getInheritableProperty)({
482
- dict: dict,
483
- key: 'Ff'
607
+ data.fieldFlags = (0, _core_utils.getInheritableProperty)({
608
+ dict,
609
+ key: "Ff"
484
610
  });
611
+
485
612
  if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
486
613
  data.fieldFlags = 0;
487
614
  }
488
- data.readOnly = _this2.hasFieldFlag(_util.AnnotationFieldFlag.READONLY);
489
- if (data.fieldType === 'Sig') {
490
- _this2.setFlags(_util.AnnotationFlag.HIDDEN);
615
+
616
+ data.readOnly = this.hasFieldFlag(_util.AnnotationFieldFlag.READONLY);
617
+
618
+ if (data.fieldType === "Sig") {
619
+ data.fieldValue = null;
620
+ this.setFlags(_util.AnnotationFlag.HIDDEN);
491
621
  }
492
- return _this2;
493
622
  }
494
623
 
495
- _createClass(WidgetAnnotation, [{
496
- key: '_constructFieldName',
497
- value: function _constructFieldName(dict) {
498
- if (!dict.has('T') && !dict.has('Parent')) {
499
- (0, _util.warn)('Unknown field name, falling back to empty field name.');
500
- return '';
501
- }
502
- if (!dict.has('Parent')) {
503
- return (0, _util.stringToPDFString)(dict.get('T'));
504
- }
505
- var fieldName = [];
506
- if (dict.has('T')) {
507
- fieldName.unshift((0, _util.stringToPDFString)(dict.get('T')));
508
- }
509
- var loopDict = dict;
510
- while (loopDict.has('Parent')) {
511
- loopDict = loopDict.get('Parent');
512
- if (!(0, _primitives.isDict)(loopDict)) {
513
- break;
514
- }
515
- if (loopDict.has('T')) {
516
- fieldName.unshift((0, _util.stringToPDFString)(loopDict.get('T')));
517
- }
624
+ _constructFieldName(dict) {
625
+ if (!dict.has("T") && !dict.has("Parent")) {
626
+ (0, _util.warn)("Unknown field name, falling back to empty field name.");
627
+ return "";
628
+ }
629
+
630
+ if (!dict.has("Parent")) {
631
+ return (0, _util.stringToPDFString)(dict.get("T"));
632
+ }
633
+
634
+ const fieldName = [];
635
+
636
+ if (dict.has("T")) {
637
+ fieldName.unshift((0, _util.stringToPDFString)(dict.get("T")));
638
+ }
639
+
640
+ let loopDict = dict;
641
+
642
+ while (loopDict.has("Parent")) {
643
+ loopDict = loopDict.get("Parent");
644
+
645
+ if (!(0, _primitives.isDict)(loopDict)) {
646
+ break;
518
647
  }
519
- return fieldName.join('.');
520
- }
521
- }, {
522
- key: 'hasFieldFlag',
523
- value: function hasFieldFlag(flag) {
524
- return !!(this.data.fieldFlags & flag);
525
- }
526
- }, {
527
- key: 'getOperatorList',
528
- value: function getOperatorList(evaluator, task, renderForms) {
529
- if (renderForms) {
530
- return Promise.resolve(new _operator_list.OperatorList());
648
+
649
+ if (loopDict.has("T")) {
650
+ fieldName.unshift((0, _util.stringToPDFString)(loopDict.get("T")));
531
651
  }
532
- return _get(WidgetAnnotation.prototype.__proto__ || Object.getPrototypeOf(WidgetAnnotation.prototype), 'getOperatorList', this).call(this, evaluator, task, renderForms);
533
652
  }
534
- }]);
535
653
 
536
- return WidgetAnnotation;
537
- }(Annotation);
654
+ return fieldName.join(".");
655
+ }
656
+
657
+ hasFieldFlag(flag) {
658
+ return !!(this.data.fieldFlags & flag);
659
+ }
538
660
 
539
- var TextWidgetAnnotation = function (_WidgetAnnotation) {
540
- _inherits(TextWidgetAnnotation, _WidgetAnnotation);
661
+ getOperatorList(evaluator, task, renderForms) {
662
+ if (renderForms) {
663
+ return Promise.resolve(new _operator_list.OperatorList());
664
+ }
541
665
 
542
- function TextWidgetAnnotation(params) {
543
- _classCallCheck(this, TextWidgetAnnotation);
666
+ return super.getOperatorList(evaluator, task, renderForms);
667
+ }
544
668
 
545
- var _this3 = _possibleConstructorReturn(this, (TextWidgetAnnotation.__proto__ || Object.getPrototypeOf(TextWidgetAnnotation)).call(this, params));
669
+ }
546
670
 
547
- var dict = params.dict;
548
- _this3.data.fieldValue = (0, _util.stringToPDFString)(_this3.data.fieldValue || '');
549
- var alignment = (0, _util.getInheritableProperty)({
550
- dict: dict,
551
- key: 'Q'
671
+ class TextWidgetAnnotation extends WidgetAnnotation {
672
+ constructor(params) {
673
+ super(params);
674
+ const dict = params.dict;
675
+ this.data.fieldValue = (0, _util.stringToPDFString)(this.data.fieldValue || "");
676
+ let alignment = (0, _core_utils.getInheritableProperty)({
677
+ dict,
678
+ key: "Q"
552
679
  });
680
+
553
681
  if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
554
682
  alignment = null;
555
683
  }
556
- _this3.data.textAlignment = alignment;
557
- var maximumLength = (0, _util.getInheritableProperty)({
558
- dict: dict,
559
- key: 'MaxLen'
684
+
685
+ this.data.textAlignment = alignment;
686
+ let maximumLength = (0, _core_utils.getInheritableProperty)({
687
+ dict,
688
+ key: "MaxLen"
560
689
  });
690
+
561
691
  if (!Number.isInteger(maximumLength) || maximumLength < 0) {
562
692
  maximumLength = null;
563
693
  }
564
- _this3.data.maxLen = maximumLength;
565
- _this3.data.multiLine = _this3.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE);
566
- _this3.data.comb = _this3.hasFieldFlag(_util.AnnotationFieldFlag.COMB) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD) && !_this3.hasFieldFlag(_util.AnnotationFieldFlag.FILESELECT) && _this3.data.maxLen !== null;
567
- return _this3;
694
+
695
+ this.data.maxLen = maximumLength;
696
+ this.data.multiLine = this.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE);
697
+ this.data.comb = this.hasFieldFlag(_util.AnnotationFieldFlag.COMB) && !this.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(_util.AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
568
698
  }
569
699
 
570
- _createClass(TextWidgetAnnotation, [{
571
- key: 'getOperatorList',
572
- value: function getOperatorList(evaluator, task, renderForms) {
573
- if (renderForms || this.appearance) {
574
- return _get(TextWidgetAnnotation.prototype.__proto__ || Object.getPrototypeOf(TextWidgetAnnotation.prototype), 'getOperatorList', this).call(this, evaluator, task, renderForms);
575
- }
576
- var operatorList = new _operator_list.OperatorList();
577
- if (!this.data.defaultAppearance) {
578
- return Promise.resolve(operatorList);
579
- }
580
- var stream = new _stream.Stream((0, _util.stringToBytes)(this.data.defaultAppearance));
581
- return evaluator.getOperatorList({
582
- stream: stream,
583
- task: task,
584
- resources: this.fieldResources,
585
- operatorList: operatorList
586
- }).then(function () {
587
- return operatorList;
588
- });
700
+ getOperatorList(evaluator, task, renderForms) {
701
+ if (renderForms || this.appearance) {
702
+ return super.getOperatorList(evaluator, task, renderForms);
589
703
  }
590
- }]);
591
704
 
592
- return TextWidgetAnnotation;
593
- }(WidgetAnnotation);
705
+ const operatorList = new _operator_list.OperatorList();
594
706
 
595
- var ButtonWidgetAnnotation = function (_WidgetAnnotation2) {
596
- _inherits(ButtonWidgetAnnotation, _WidgetAnnotation2);
707
+ if (!this.data.defaultAppearance) {
708
+ return Promise.resolve(operatorList);
709
+ }
597
710
 
598
- function ButtonWidgetAnnotation(params) {
599
- _classCallCheck(this, ButtonWidgetAnnotation);
711
+ const stream = new _stream.Stream((0, _util.stringToBytes)(this.data.defaultAppearance));
712
+ return evaluator.getOperatorList({
713
+ stream,
714
+ task,
715
+ resources: this.fieldResources,
716
+ operatorList
717
+ }).then(function () {
718
+ return operatorList;
719
+ });
720
+ }
600
721
 
601
- var _this4 = _possibleConstructorReturn(this, (ButtonWidgetAnnotation.__proto__ || Object.getPrototypeOf(ButtonWidgetAnnotation)).call(this, params));
722
+ }
602
723
 
603
- _this4.data.checkBox = !_this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
604
- _this4.data.radioButton = _this4.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
605
- _this4.data.pushButton = _this4.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
606
- if (_this4.data.checkBox) {
607
- _this4._processCheckBox(params);
608
- } else if (_this4.data.radioButton) {
609
- _this4._processRadioButton(params);
610
- } else if (_this4.data.pushButton) {
611
- _this4._processPushButton(params);
724
+ class ButtonWidgetAnnotation extends WidgetAnnotation {
725
+ constructor(params) {
726
+ super(params);
727
+ this.data.checkBox = !this.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
728
+ this.data.radioButton = this.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
729
+ this.data.pushButton = this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
730
+
731
+ if (this.data.checkBox) {
732
+ this._processCheckBox(params);
733
+ } else if (this.data.radioButton) {
734
+ this._processRadioButton(params);
735
+ } else if (this.data.pushButton) {
736
+ this._processPushButton(params);
612
737
  } else {
613
- (0, _util.warn)('Invalid field flags for button widget annotation');
738
+ (0, _util.warn)("Invalid field flags for button widget annotation");
614
739
  }
615
- return _this4;
616
740
  }
617
741
 
618
- _createClass(ButtonWidgetAnnotation, [{
619
- key: '_processCheckBox',
620
- value: function _processCheckBox(params) {
621
- if ((0, _primitives.isName)(this.data.fieldValue)) {
622
- this.data.fieldValue = this.data.fieldValue.name;
623
- }
624
- var customAppearance = params.dict.get('AP');
625
- if (!(0, _primitives.isDict)(customAppearance)) {
626
- return;
627
- }
628
- var exportValueOptionsDict = customAppearance.get('D');
629
- if (!(0, _primitives.isDict)(exportValueOptionsDict)) {
630
- return;
631
- }
632
- var exportValues = exportValueOptionsDict.getKeys();
633
- var hasCorrectOptionCount = exportValues.length === 2;
634
- if (!hasCorrectOptionCount) {
635
- return;
636
- }
637
- this.data.exportValue = exportValues[0] === 'Off' ? exportValues[1] : exportValues[0];
638
- }
639
- }, {
640
- key: '_processRadioButton',
641
- value: function _processRadioButton(params) {
642
- this.data.fieldValue = this.data.buttonValue = null;
643
- var fieldParent = params.dict.get('Parent');
644
- if ((0, _primitives.isDict)(fieldParent) && fieldParent.has('V')) {
645
- var fieldParentValue = fieldParent.get('V');
646
- if ((0, _primitives.isName)(fieldParentValue)) {
647
- this.data.fieldValue = fieldParentValue.name;
648
- }
649
- }
650
- var appearanceStates = params.dict.get('AP');
651
- if (!(0, _primitives.isDict)(appearanceStates)) {
652
- return;
653
- }
654
- var normalAppearanceState = appearanceStates.get('N');
655
- if (!(0, _primitives.isDict)(normalAppearanceState)) {
656
- return;
657
- }
658
- var keys = normalAppearanceState.getKeys();
659
- for (var i = 0, ii = keys.length; i < ii; i++) {
660
- if (keys[i] !== 'Off') {
661
- this.data.buttonValue = keys[i];
662
- break;
663
- }
664
- }
742
+ _processCheckBox(params) {
743
+ if ((0, _primitives.isName)(this.data.fieldValue)) {
744
+ this.data.fieldValue = this.data.fieldValue.name;
745
+ }
746
+
747
+ const customAppearance = params.dict.get("AP");
748
+
749
+ if (!(0, _primitives.isDict)(customAppearance)) {
750
+ return;
751
+ }
752
+
753
+ const exportValueOptionsDict = customAppearance.get("D");
754
+
755
+ if (!(0, _primitives.isDict)(exportValueOptionsDict)) {
756
+ return;
665
757
  }
666
- }, {
667
- key: '_processPushButton',
668
- value: function _processPushButton(params) {
669
- if (!params.dict.has('A')) {
670
- (0, _util.warn)('Push buttons without action dictionaries are not supported');
671
- return;
758
+
759
+ const exportValues = exportValueOptionsDict.getKeys();
760
+ const hasCorrectOptionCount = exportValues.length === 2;
761
+
762
+ if (!hasCorrectOptionCount) {
763
+ return;
764
+ }
765
+
766
+ this.data.exportValue = exportValues[0] === "Off" ? exportValues[1] : exportValues[0];
767
+ }
768
+
769
+ _processRadioButton(params) {
770
+ this.data.fieldValue = this.data.buttonValue = null;
771
+ const fieldParent = params.dict.get("Parent");
772
+
773
+ if ((0, _primitives.isDict)(fieldParent) && fieldParent.has("V")) {
774
+ const fieldParentValue = fieldParent.get("V");
775
+
776
+ if ((0, _primitives.isName)(fieldParentValue)) {
777
+ this.data.fieldValue = fieldParentValue.name;
672
778
  }
673
- _obj.Catalog.parseDestDictionary({
674
- destDict: params.dict,
675
- resultObj: this.data,
676
- docBaseUrl: params.pdfManager.docBaseUrl
677
- });
678
779
  }
679
- }]);
680
780
 
681
- return ButtonWidgetAnnotation;
682
- }(WidgetAnnotation);
781
+ const appearanceStates = params.dict.get("AP");
782
+
783
+ if (!(0, _primitives.isDict)(appearanceStates)) {
784
+ return;
785
+ }
786
+
787
+ const normalAppearanceState = appearanceStates.get("N");
683
788
 
684
- var ChoiceWidgetAnnotation = function (_WidgetAnnotation3) {
685
- _inherits(ChoiceWidgetAnnotation, _WidgetAnnotation3);
789
+ if (!(0, _primitives.isDict)(normalAppearanceState)) {
790
+ return;
791
+ }
686
792
 
687
- function ChoiceWidgetAnnotation(params) {
688
- _classCallCheck(this, ChoiceWidgetAnnotation);
793
+ for (const key of normalAppearanceState.getKeys()) {
794
+ if (key !== "Off") {
795
+ this.data.buttonValue = key;
796
+ break;
797
+ }
798
+ }
799
+ }
689
800
 
690
- var _this5 = _possibleConstructorReturn(this, (ChoiceWidgetAnnotation.__proto__ || Object.getPrototypeOf(ChoiceWidgetAnnotation)).call(this, params));
801
+ _processPushButton(params) {
802
+ if (!params.dict.has("A")) {
803
+ (0, _util.warn)("Push buttons without action dictionaries are not supported");
804
+ return;
805
+ }
691
806
 
692
- _this5.data.options = [];
693
- var options = (0, _util.getInheritableProperty)({
807
+ _obj.Catalog.parseDestDictionary({
808
+ destDict: params.dict,
809
+ resultObj: this.data,
810
+ docBaseUrl: params.pdfManager.docBaseUrl
811
+ });
812
+ }
813
+
814
+ }
815
+
816
+ class ChoiceWidgetAnnotation extends WidgetAnnotation {
817
+ constructor(params) {
818
+ super(params);
819
+ this.data.options = [];
820
+ const options = (0, _core_utils.getInheritableProperty)({
694
821
  dict: params.dict,
695
- key: 'Opt'
822
+ key: "Opt"
696
823
  });
824
+
697
825
  if (Array.isArray(options)) {
698
- var xref = params.xref;
699
- for (var i = 0, ii = options.length; i < ii; i++) {
700
- var option = xref.fetchIfRef(options[i]);
701
- var isOptionArray = Array.isArray(option);
702
- _this5.data.options[i] = {
826
+ const xref = params.xref;
827
+
828
+ for (let i = 0, ii = options.length; i < ii; i++) {
829
+ const option = xref.fetchIfRef(options[i]);
830
+ const isOptionArray = Array.isArray(option);
831
+ this.data.options[i] = {
703
832
  exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
704
833
  displayValue: (0, _util.stringToPDFString)(isOptionArray ? xref.fetchIfRef(option[1]) : option)
705
834
  };
706
835
  }
707
836
  }
708
- if (!Array.isArray(_this5.data.fieldValue)) {
709
- _this5.data.fieldValue = [_this5.data.fieldValue];
710
- }
711
- _this5.data.combo = _this5.hasFieldFlag(_util.AnnotationFieldFlag.COMBO);
712
- _this5.data.multiSelect = _this5.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT);
713
- return _this5;
714
- }
715
837
 
716
- return ChoiceWidgetAnnotation;
717
- }(WidgetAnnotation);
838
+ if (!Array.isArray(this.data.fieldValue)) {
839
+ this.data.fieldValue = [this.data.fieldValue];
840
+ }
718
841
 
719
- var TextAnnotation = function (_Annotation2) {
720
- _inherits(TextAnnotation, _Annotation2);
842
+ this.data.combo = this.hasFieldFlag(_util.AnnotationFieldFlag.COMBO);
843
+ this.data.multiSelect = this.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT);
844
+ }
721
845
 
722
- function TextAnnotation(parameters) {
723
- _classCallCheck(this, TextAnnotation);
846
+ }
724
847
 
725
- var DEFAULT_ICON_SIZE = 22;
848
+ class TextAnnotation extends MarkupAnnotation {
849
+ constructor(parameters) {
850
+ const DEFAULT_ICON_SIZE = 22;
851
+ super(parameters);
852
+ const dict = parameters.dict;
853
+ this.data.annotationType = _util.AnnotationType.TEXT;
726
854
 
727
- var _this6 = _possibleConstructorReturn(this, (TextAnnotation.__proto__ || Object.getPrototypeOf(TextAnnotation)).call(this, parameters));
855
+ if (this.data.hasAppearance) {
856
+ this.data.name = "NoIcon";
857
+ } else {
858
+ this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
859
+ this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
860
+ this.data.name = dict.has("Name") ? dict.get("Name").name : "Note";
861
+ }
728
862
 
729
- _this6.data.annotationType = _util.AnnotationType.TEXT;
730
- if (_this6.data.hasAppearance) {
731
- _this6.data.name = 'NoIcon';
863
+ if (dict.has("State")) {
864
+ this.data.state = dict.get("State") || null;
865
+ this.data.stateModel = dict.get("StateModel") || null;
732
866
  } else {
733
- _this6.data.rect[1] = _this6.data.rect[3] - DEFAULT_ICON_SIZE;
734
- _this6.data.rect[2] = _this6.data.rect[0] + DEFAULT_ICON_SIZE;
735
- _this6.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
867
+ this.data.state = null;
868
+ this.data.stateModel = null;
736
869
  }
737
- _this6._preparePopup(parameters.dict);
738
- return _this6;
739
870
  }
740
871
 
741
- return TextAnnotation;
742
- }(Annotation);
743
-
744
- var LinkAnnotation = function (_Annotation3) {
745
- _inherits(LinkAnnotation, _Annotation3);
872
+ }
746
873
 
747
- function LinkAnnotation(params) {
748
- _classCallCheck(this, LinkAnnotation);
874
+ class LinkAnnotation extends Annotation {
875
+ constructor(params) {
876
+ super(params);
877
+ this.data.annotationType = _util.AnnotationType.LINK;
878
+ const quadPoints = getQuadPoints(params.dict, this.rectangle);
749
879
 
750
- var _this7 = _possibleConstructorReturn(this, (LinkAnnotation.__proto__ || Object.getPrototypeOf(LinkAnnotation)).call(this, params));
880
+ if (quadPoints) {
881
+ this.data.quadPoints = quadPoints;
882
+ }
751
883
 
752
- _this7.data.annotationType = _util.AnnotationType.LINK;
753
884
  _obj.Catalog.parseDestDictionary({
754
885
  destDict: params.dict,
755
- resultObj: _this7.data,
886
+ resultObj: this.data,
756
887
  docBaseUrl: params.pdfManager.docBaseUrl
757
888
  });
758
- return _this7;
759
889
  }
760
890
 
761
- return LinkAnnotation;
762
- }(Annotation);
763
-
764
- var PopupAnnotation = function (_Annotation4) {
765
- _inherits(PopupAnnotation, _Annotation4);
766
-
767
- function PopupAnnotation(parameters) {
768
- _classCallCheck(this, PopupAnnotation);
891
+ }
769
892
 
770
- var _this8 = _possibleConstructorReturn(this, (PopupAnnotation.__proto__ || Object.getPrototypeOf(PopupAnnotation)).call(this, parameters));
893
+ class PopupAnnotation extends Annotation {
894
+ constructor(parameters) {
895
+ super(parameters);
896
+ this.data.annotationType = _util.AnnotationType.POPUP;
897
+ let parentItem = parameters.dict.get("Parent");
771
898
 
772
- _this8.data.annotationType = _util.AnnotationType.POPUP;
773
- var dict = parameters.dict;
774
- var parentItem = dict.get('Parent');
775
899
  if (!parentItem) {
776
- (0, _util.warn)('Popup annotation has a missing or invalid parent annotation.');
777
- return _possibleConstructorReturn(_this8);
778
- }
779
- var parentSubtype = parentItem.get('Subtype');
780
- _this8.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null;
781
- _this8.data.parentId = dict.getRaw('Parent').toString();
782
- _this8.data.title = (0, _util.stringToPDFString)(parentItem.get('T') || '');
783
- _this8.data.contents = (0, _util.stringToPDFString)(parentItem.get('Contents') || '');
784
- if (!parentItem.has('C')) {
785
- _this8.data.color = null;
786
- } else {
787
- _this8.setColor(parentItem.getArray('C'));
788
- _this8.data.color = _this8.color;
789
- }
790
- if (!_this8.viewable) {
791
- var parentFlags = parentItem.get('F');
792
- if (_this8._isViewable(parentFlags)) {
793
- _this8.setFlags(parentFlags);
794
- }
900
+ (0, _util.warn)("Popup annotation has a missing or invalid parent annotation.");
901
+ return;
795
902
  }
796
- return _this8;
797
- }
798
-
799
- return PopupAnnotation;
800
- }(Annotation);
801
903
 
802
- var LineAnnotation = function (_Annotation5) {
803
- _inherits(LineAnnotation, _Annotation5);
904
+ const parentSubtype = parentItem.get("Subtype");
905
+ this.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null;
906
+ const rawParent = parameters.dict.getRaw("Parent");
907
+ this.data.parentId = (0, _primitives.isRef)(rawParent) ? rawParent.toString() : null;
908
+ const rt = parentItem.get("RT");
804
909
 
805
- function LineAnnotation(parameters) {
806
- _classCallCheck(this, LineAnnotation);
910
+ if ((0, _primitives.isName)(rt, _util.AnnotationReplyType.GROUP)) {
911
+ parentItem = parentItem.get("IRT");
912
+ }
807
913
 
808
- var _this9 = _possibleConstructorReturn(this, (LineAnnotation.__proto__ || Object.getPrototypeOf(LineAnnotation)).call(this, parameters));
914
+ if (!parentItem.has("M")) {
915
+ this.data.modificationDate = null;
916
+ } else {
917
+ this.setModificationDate(parentItem.get("M"));
918
+ this.data.modificationDate = this.modificationDate;
919
+ }
809
920
 
810
- _this9.data.annotationType = _util.AnnotationType.LINE;
811
- var dict = parameters.dict;
812
- _this9.data.lineCoordinates = _util.Util.normalizeRect(dict.getArray('L'));
813
- _this9._preparePopup(dict);
814
- return _this9;
815
- }
921
+ if (!parentItem.has("C")) {
922
+ this.data.color = null;
923
+ } else {
924
+ this.setColor(parentItem.getArray("C"));
925
+ this.data.color = this.color;
926
+ }
816
927
 
817
- return LineAnnotation;
818
- }(Annotation);
928
+ if (!this.viewable) {
929
+ const parentFlags = parentItem.get("F");
819
930
 
820
- var SquareAnnotation = function (_Annotation6) {
821
- _inherits(SquareAnnotation, _Annotation6);
931
+ if (this._isViewable(parentFlags)) {
932
+ this.setFlags(parentFlags);
933
+ }
934
+ }
822
935
 
823
- function SquareAnnotation(parameters) {
824
- _classCallCheck(this, SquareAnnotation);
936
+ this.data.title = (0, _util.stringToPDFString)(parentItem.get("T") || "");
937
+ this.data.contents = (0, _util.stringToPDFString)(parentItem.get("Contents") || "");
938
+ }
825
939
 
826
- var _this10 = _possibleConstructorReturn(this, (SquareAnnotation.__proto__ || Object.getPrototypeOf(SquareAnnotation)).call(this, parameters));
940
+ }
827
941
 
828
- _this10.data.annotationType = _util.AnnotationType.SQUARE;
829
- _this10._preparePopup(parameters.dict);
830
- return _this10;
942
+ class FreeTextAnnotation extends MarkupAnnotation {
943
+ constructor(parameters) {
944
+ super(parameters);
945
+ this.data.annotationType = _util.AnnotationType.FREETEXT;
831
946
  }
832
947
 
833
- return SquareAnnotation;
834
- }(Annotation);
835
-
836
- var CircleAnnotation = function (_Annotation7) {
837
- _inherits(CircleAnnotation, _Annotation7);
948
+ }
838
949
 
839
- function CircleAnnotation(parameters) {
840
- _classCallCheck(this, CircleAnnotation);
950
+ class LineAnnotation extends MarkupAnnotation {
951
+ constructor(parameters) {
952
+ super(parameters);
953
+ this.data.annotationType = _util.AnnotationType.LINE;
954
+ this.data.lineCoordinates = _util.Util.normalizeRect(parameters.dict.getArray("L"));
955
+ }
841
956
 
842
- var _this11 = _possibleConstructorReturn(this, (CircleAnnotation.__proto__ || Object.getPrototypeOf(CircleAnnotation)).call(this, parameters));
957
+ }
843
958
 
844
- _this11.data.annotationType = _util.AnnotationType.CIRCLE;
845
- _this11._preparePopup(parameters.dict);
846
- return _this11;
959
+ class SquareAnnotation extends MarkupAnnotation {
960
+ constructor(parameters) {
961
+ super(parameters);
962
+ this.data.annotationType = _util.AnnotationType.SQUARE;
847
963
  }
848
964
 
849
- return CircleAnnotation;
850
- }(Annotation);
965
+ }
851
966
 
852
- var PolylineAnnotation = function (_Annotation8) {
853
- _inherits(PolylineAnnotation, _Annotation8);
967
+ class CircleAnnotation extends MarkupAnnotation {
968
+ constructor(parameters) {
969
+ super(parameters);
970
+ this.data.annotationType = _util.AnnotationType.CIRCLE;
971
+ }
854
972
 
855
- function PolylineAnnotation(parameters) {
856
- _classCallCheck(this, PolylineAnnotation);
973
+ }
857
974
 
858
- var _this12 = _possibleConstructorReturn(this, (PolylineAnnotation.__proto__ || Object.getPrototypeOf(PolylineAnnotation)).call(this, parameters));
975
+ class PolylineAnnotation extends MarkupAnnotation {
976
+ constructor(parameters) {
977
+ super(parameters);
978
+ this.data.annotationType = _util.AnnotationType.POLYLINE;
979
+ const rawVertices = parameters.dict.getArray("Vertices");
980
+ this.data.vertices = [];
859
981
 
860
- _this12.data.annotationType = _util.AnnotationType.POLYLINE;
861
- var dict = parameters.dict;
862
- var rawVertices = dict.getArray('Vertices');
863
- _this12.data.vertices = [];
864
- for (var i = 0, ii = rawVertices.length; i < ii; i += 2) {
865
- _this12.data.vertices.push({
982
+ for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
983
+ this.data.vertices.push({
866
984
  x: rawVertices[i],
867
985
  y: rawVertices[i + 1]
868
986
  });
869
987
  }
870
- _this12._preparePopup(dict);
871
- return _this12;
872
988
  }
873
989
 
874
- return PolylineAnnotation;
875
- }(Annotation);
876
-
877
- var PolygonAnnotation = function (_PolylineAnnotation) {
878
- _inherits(PolygonAnnotation, _PolylineAnnotation);
990
+ }
879
991
 
880
- function PolygonAnnotation(parameters) {
881
- _classCallCheck(this, PolygonAnnotation);
992
+ class PolygonAnnotation extends PolylineAnnotation {
993
+ constructor(parameters) {
994
+ super(parameters);
995
+ this.data.annotationType = _util.AnnotationType.POLYGON;
996
+ }
882
997
 
883
- var _this13 = _possibleConstructorReturn(this, (PolygonAnnotation.__proto__ || Object.getPrototypeOf(PolygonAnnotation)).call(this, parameters));
998
+ }
884
999
 
885
- _this13.data.annotationType = _util.AnnotationType.POLYGON;
886
- return _this13;
1000
+ class CaretAnnotation extends MarkupAnnotation {
1001
+ constructor(parameters) {
1002
+ super(parameters);
1003
+ this.data.annotationType = _util.AnnotationType.CARET;
887
1004
  }
888
1005
 
889
- return PolygonAnnotation;
890
- }(PolylineAnnotation);
891
-
892
- var InkAnnotation = function (_Annotation9) {
893
- _inherits(InkAnnotation, _Annotation9);
1006
+ }
894
1007
 
895
- function InkAnnotation(parameters) {
896
- _classCallCheck(this, InkAnnotation);
1008
+ class InkAnnotation extends MarkupAnnotation {
1009
+ constructor(parameters) {
1010
+ super(parameters);
1011
+ this.data.annotationType = _util.AnnotationType.INK;
1012
+ const xref = parameters.xref;
1013
+ const originalInkLists = parameters.dict.getArray("InkList");
1014
+ this.data.inkLists = [];
897
1015
 
898
- var _this14 = _possibleConstructorReturn(this, (InkAnnotation.__proto__ || Object.getPrototypeOf(InkAnnotation)).call(this, parameters));
1016
+ for (let i = 0, ii = originalInkLists.length; i < ii; ++i) {
1017
+ this.data.inkLists.push([]);
899
1018
 
900
- _this14.data.annotationType = _util.AnnotationType.INK;
901
- var dict = parameters.dict;
902
- var xref = parameters.xref;
903
- var originalInkLists = dict.getArray('InkList');
904
- _this14.data.inkLists = [];
905
- for (var i = 0, ii = originalInkLists.length; i < ii; ++i) {
906
- _this14.data.inkLists.push([]);
907
- for (var j = 0, jj = originalInkLists[i].length; j < jj; j += 2) {
908
- _this14.data.inkLists[i].push({
1019
+ for (let j = 0, jj = originalInkLists[i].length; j < jj; j += 2) {
1020
+ this.data.inkLists[i].push({
909
1021
  x: xref.fetchIfRef(originalInkLists[i][j]),
910
1022
  y: xref.fetchIfRef(originalInkLists[i][j + 1])
911
1023
  });
912
1024
  }
913
1025
  }
914
- _this14._preparePopup(dict);
915
- return _this14;
916
1026
  }
917
1027
 
918
- return InkAnnotation;
919
- }(Annotation);
920
-
921
- var HighlightAnnotation = function (_Annotation10) {
922
- _inherits(HighlightAnnotation, _Annotation10);
923
-
924
- function HighlightAnnotation(parameters) {
925
- _classCallCheck(this, HighlightAnnotation);
1028
+ }
926
1029
 
927
- var _this15 = _possibleConstructorReturn(this, (HighlightAnnotation.__proto__ || Object.getPrototypeOf(HighlightAnnotation)).call(this, parameters));
1030
+ class HighlightAnnotation extends MarkupAnnotation {
1031
+ constructor(parameters) {
1032
+ super(parameters);
1033
+ this.data.annotationType = _util.AnnotationType.HIGHLIGHT;
1034
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
928
1035
 
929
- _this15.data.annotationType = _util.AnnotationType.HIGHLIGHT;
930
- _this15._preparePopup(parameters.dict);
931
- return _this15;
1036
+ if (quadPoints) {
1037
+ this.data.quadPoints = quadPoints;
1038
+ }
932
1039
  }
933
1040
 
934
- return HighlightAnnotation;
935
- }(Annotation);
936
-
937
- var UnderlineAnnotation = function (_Annotation11) {
938
- _inherits(UnderlineAnnotation, _Annotation11);
939
-
940
- function UnderlineAnnotation(parameters) {
941
- _classCallCheck(this, UnderlineAnnotation);
1041
+ }
942
1042
 
943
- var _this16 = _possibleConstructorReturn(this, (UnderlineAnnotation.__proto__ || Object.getPrototypeOf(UnderlineAnnotation)).call(this, parameters));
1043
+ class UnderlineAnnotation extends MarkupAnnotation {
1044
+ constructor(parameters) {
1045
+ super(parameters);
1046
+ this.data.annotationType = _util.AnnotationType.UNDERLINE;
1047
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
944
1048
 
945
- _this16.data.annotationType = _util.AnnotationType.UNDERLINE;
946
- _this16._preparePopup(parameters.dict);
947
- return _this16;
1049
+ if (quadPoints) {
1050
+ this.data.quadPoints = quadPoints;
1051
+ }
948
1052
  }
949
1053
 
950
- return UnderlineAnnotation;
951
- }(Annotation);
952
-
953
- var SquigglyAnnotation = function (_Annotation12) {
954
- _inherits(SquigglyAnnotation, _Annotation12);
955
-
956
- function SquigglyAnnotation(parameters) {
957
- _classCallCheck(this, SquigglyAnnotation);
1054
+ }
958
1055
 
959
- var _this17 = _possibleConstructorReturn(this, (SquigglyAnnotation.__proto__ || Object.getPrototypeOf(SquigglyAnnotation)).call(this, parameters));
1056
+ class SquigglyAnnotation extends MarkupAnnotation {
1057
+ constructor(parameters) {
1058
+ super(parameters);
1059
+ this.data.annotationType = _util.AnnotationType.SQUIGGLY;
1060
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
960
1061
 
961
- _this17.data.annotationType = _util.AnnotationType.SQUIGGLY;
962
- _this17._preparePopup(parameters.dict);
963
- return _this17;
1062
+ if (quadPoints) {
1063
+ this.data.quadPoints = quadPoints;
1064
+ }
964
1065
  }
965
1066
 
966
- return SquigglyAnnotation;
967
- }(Annotation);
968
-
969
- var StrikeOutAnnotation = function (_Annotation13) {
970
- _inherits(StrikeOutAnnotation, _Annotation13);
971
-
972
- function StrikeOutAnnotation(parameters) {
973
- _classCallCheck(this, StrikeOutAnnotation);
1067
+ }
974
1068
 
975
- var _this18 = _possibleConstructorReturn(this, (StrikeOutAnnotation.__proto__ || Object.getPrototypeOf(StrikeOutAnnotation)).call(this, parameters));
1069
+ class StrikeOutAnnotation extends MarkupAnnotation {
1070
+ constructor(parameters) {
1071
+ super(parameters);
1072
+ this.data.annotationType = _util.AnnotationType.STRIKEOUT;
1073
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
976
1074
 
977
- _this18.data.annotationType = _util.AnnotationType.STRIKEOUT;
978
- _this18._preparePopup(parameters.dict);
979
- return _this18;
1075
+ if (quadPoints) {
1076
+ this.data.quadPoints = quadPoints;
1077
+ }
980
1078
  }
981
1079
 
982
- return StrikeOutAnnotation;
983
- }(Annotation);
984
-
985
- var StampAnnotation = function (_Annotation14) {
986
- _inherits(StampAnnotation, _Annotation14);
987
-
988
- function StampAnnotation(parameters) {
989
- _classCallCheck(this, StampAnnotation);
990
-
991
- var _this19 = _possibleConstructorReturn(this, (StampAnnotation.__proto__ || Object.getPrototypeOf(StampAnnotation)).call(this, parameters));
1080
+ }
992
1081
 
993
- _this19.data.annotationType = _util.AnnotationType.STAMP;
994
- _this19._preparePopup(parameters.dict);
995
- return _this19;
1082
+ class StampAnnotation extends MarkupAnnotation {
1083
+ constructor(parameters) {
1084
+ super(parameters);
1085
+ this.data.annotationType = _util.AnnotationType.STAMP;
996
1086
  }
997
1087
 
998
- return StampAnnotation;
999
- }(Annotation);
1000
-
1001
- var FileAttachmentAnnotation = function (_Annotation15) {
1002
- _inherits(FileAttachmentAnnotation, _Annotation15);
1003
-
1004
- function FileAttachmentAnnotation(parameters) {
1005
- _classCallCheck(this, FileAttachmentAnnotation);
1006
-
1007
- var _this20 = _possibleConstructorReturn(this, (FileAttachmentAnnotation.__proto__ || Object.getPrototypeOf(FileAttachmentAnnotation)).call(this, parameters));
1088
+ }
1008
1089
 
1009
- var file = new _obj.FileSpec(parameters.dict.get('FS'), parameters.xref);
1010
- _this20.data.annotationType = _util.AnnotationType.FILEATTACHMENT;
1011
- _this20.data.file = file.serializable;
1012
- _this20._preparePopup(parameters.dict);
1013
- return _this20;
1090
+ class FileAttachmentAnnotation extends MarkupAnnotation {
1091
+ constructor(parameters) {
1092
+ super(parameters);
1093
+ const file = new _obj.FileSpec(parameters.dict.get("FS"), parameters.xref);
1094
+ this.data.annotationType = _util.AnnotationType.FILEATTACHMENT;
1095
+ this.data.file = file.serializable;
1014
1096
  }
1015
1097
 
1016
- return FileAttachmentAnnotation;
1017
- }(Annotation);
1018
-
1019
- exports.Annotation = Annotation;
1020
- exports.AnnotationBorderStyle = AnnotationBorderStyle;
1021
- exports.AnnotationFactory = AnnotationFactory;
1098
+ }