pdfjs-dist 2.2.228 → 2.6.347

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 (229) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +8816 -19300
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +27185 -35746
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +26665 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/es5/build/pdf.min.js +22 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +61231 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/build/pdf.worker.min.js +22 -0
  17. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  18. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  19. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  20. package/es5/web/images/annotation-check.svg +11 -0
  21. package/es5/web/images/annotation-comment.svg +16 -0
  22. package/es5/web/images/annotation-help.svg +26 -0
  23. package/es5/web/images/annotation-insert.svg +10 -0
  24. package/es5/web/images/annotation-key.svg +11 -0
  25. package/es5/web/images/annotation-newparagraph.svg +11 -0
  26. package/es5/web/images/annotation-noicon.svg +7 -0
  27. package/es5/web/images/annotation-note.svg +42 -0
  28. package/es5/web/images/annotation-paragraph.svg +16 -0
  29. package/es5/web/images/loading-icon.gif +0 -0
  30. package/es5/web/images/shadow.png +0 -0
  31. package/es5/web/pdf_viewer.css +406 -0
  32. package/es5/web/pdf_viewer.js +7886 -0
  33. package/es5/web/pdf_viewer.js.map +1 -0
  34. package/image_decoders/pdf.image_decoders.js +1498 -4832
  35. package/image_decoders/pdf.image_decoders.js.map +1 -1
  36. package/image_decoders/pdf.image_decoders.min.js +22 -1
  37. package/lib/README.md +7 -0
  38. package/lib/core/annotation.js +1144 -927
  39. package/lib/core/arithmetic_decoder.js +81 -97
  40. package/lib/core/bidi.js +54 -46
  41. package/lib/core/ccitt.js +88 -81
  42. package/lib/core/ccitt_stream.js +15 -14
  43. package/lib/core/cff_parser.js +747 -716
  44. package/lib/core/charsets.js +4 -4
  45. package/lib/core/chunked_stream.js +462 -553
  46. package/lib/core/cmap.js +231 -277
  47. package/lib/core/colorspace.js +715 -857
  48. package/lib/core/core_utils.js +57 -52
  49. package/lib/core/crypto.js +416 -437
  50. package/lib/core/document.js +629 -670
  51. package/lib/core/encodings.js +15 -15
  52. package/lib/core/evaluator.js +3229 -2800
  53. package/lib/core/font_renderer.js +135 -178
  54. package/lib/core/fonts.js +602 -534
  55. package/lib/core/function.js +355 -279
  56. package/lib/core/glyphlist.js +4527 -4526
  57. package/lib/core/image.js +442 -439
  58. package/lib/core/image_utils.js +221 -61
  59. package/lib/core/jbig2.js +325 -316
  60. package/lib/core/jbig2_stream.js +18 -17
  61. package/lib/core/jpeg_stream.js +21 -26
  62. package/lib/core/jpg.js +289 -233
  63. package/lib/core/jpx.js +161 -143
  64. package/lib/core/jpx_stream.js +28 -28
  65. package/lib/core/metrics.js +2928 -2928
  66. package/lib/core/murmurhash3.js +87 -102
  67. package/lib/core/obj.js +1343 -1300
  68. package/lib/core/operator_list.js +90 -67
  69. package/lib/core/parser.js +990 -987
  70. package/lib/core/pattern.js +105 -77
  71. package/lib/core/pdf_manager.js +149 -316
  72. package/lib/core/primitives.js +156 -104
  73. package/lib/core/ps_parser.js +175 -214
  74. package/lib/core/standard_fonts.js +237 -236
  75. package/lib/core/stream.js +94 -74
  76. package/lib/core/type1_parser.js +89 -69
  77. package/lib/core/unicode.js +1654 -1654
  78. package/lib/core/worker.js +275 -290
  79. package/lib/core/worker_stream.js +101 -210
  80. package/lib/core/writer.js +242 -0
  81. package/lib/display/annotation_layer.js +772 -1041
  82. package/lib/display/annotation_storage.js +89 -0
  83. package/lib/display/api.js +1575 -1868
  84. package/lib/display/api_compatibility.js +12 -17
  85. package/lib/display/canvas.js +370 -222
  86. package/lib/display/content_disposition.js +40 -59
  87. package/lib/display/display_utils.js +341 -536
  88. package/lib/display/fetch_stream.js +188 -304
  89. package/lib/display/font_loader.js +282 -414
  90. package/lib/display/metadata.js +81 -99
  91. package/lib/display/network.js +362 -511
  92. package/lib/display/network_utils.js +25 -18
  93. package/lib/display/node_stream.js +283 -465
  94. package/lib/display/node_utils.js +87 -0
  95. package/lib/display/optional_content_config.js +184 -0
  96. package/lib/display/pattern_helper.js +93 -44
  97. package/lib/display/svg.js +1163 -1401
  98. package/lib/display/text_layer.js +154 -137
  99. package/lib/display/transport_stream.js +237 -375
  100. package/lib/display/webgl.js +70 -83
  101. package/lib/display/worker_options.js +3 -3
  102. package/lib/display/xml_parser.js +303 -392
  103. package/lib/examples/node/domstubs.js +37 -37
  104. package/lib/pdf.js +220 -58
  105. package/lib/pdf.worker.js +14 -6
  106. package/lib/shared/compatibility.js +3 -246
  107. package/lib/shared/is_node.js +7 -6
  108. package/lib/shared/message_handler.js +327 -332
  109. package/lib/shared/util.js +271 -306
  110. package/lib/test/unit/annotation_spec.js +1902 -763
  111. package/lib/test/unit/annotation_storage_spec.js +83 -0
  112. package/lib/test/unit/api_spec.js +790 -592
  113. package/lib/test/unit/bidi_spec.js +7 -7
  114. package/lib/test/unit/cff_parser_spec.js +73 -72
  115. package/lib/test/unit/clitests_helper.js +7 -9
  116. package/lib/test/unit/cmap_spec.js +86 -88
  117. package/lib/test/unit/colorspace_spec.js +346 -154
  118. package/lib/test/unit/core_utils_spec.js +125 -105
  119. package/lib/test/unit/crypto_spec.js +232 -185
  120. package/lib/test/unit/custom_spec.js +150 -24
  121. package/lib/test/unit/display_svg_spec.js +34 -39
  122. package/lib/test/unit/display_utils_spec.js +139 -149
  123. package/lib/test/unit/document_spec.js +128 -17
  124. package/lib/test/unit/encodings_spec.js +12 -34
  125. package/lib/test/unit/evaluator_spec.js +112 -91
  126. package/lib/test/unit/fetch_stream_spec.js +31 -29
  127. package/lib/test/unit/function_spec.js +206 -204
  128. package/lib/test/unit/jasmine-boot.js +48 -32
  129. package/lib/test/unit/message_handler_spec.js +173 -159
  130. package/lib/test/unit/metadata_spec.js +71 -71
  131. package/lib/test/unit/murmurhash3_spec.js +12 -12
  132. package/lib/test/unit/network_spec.js +13 -11
  133. package/lib/test/unit/network_utils_spec.js +158 -144
  134. package/lib/test/unit/node_stream_spec.js +76 -90
  135. package/lib/test/unit/parser_spec.js +108 -114
  136. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  137. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  138. package/lib/test/unit/pdf_history_spec.js +32 -32
  139. package/lib/test/unit/primitives_spec.js +337 -156
  140. package/lib/test/unit/stream_spec.js +16 -14
  141. package/lib/test/unit/test_utils.js +91 -304
  142. package/lib/test/unit/testreporter.js +33 -22
  143. package/lib/test/unit/type1_parser_spec.js +42 -42
  144. package/lib/test/unit/ui_utils_spec.js +299 -461
  145. package/lib/test/unit/unicode_spec.js +42 -42
  146. package/lib/test/unit/util_spec.js +129 -149
  147. package/lib/test/unit/writer_spec.js +84 -0
  148. package/lib/web/annotation_layer_builder.js +78 -111
  149. package/lib/web/app.js +1542 -1267
  150. package/lib/web/app_options.js +76 -91
  151. package/lib/web/base_tree_viewer.js +100 -0
  152. package/lib/web/base_viewer.js +869 -834
  153. package/lib/web/chromecom.js +165 -252
  154. package/lib/web/debugger.js +149 -205
  155. package/lib/web/download_manager.js +34 -58
  156. package/lib/web/firefox_print_service.js +62 -34
  157. package/lib/web/firefoxcom.js +206 -374
  158. package/lib/web/genericcom.js +26 -108
  159. package/lib/web/genericl10n.js +24 -153
  160. package/lib/web/grab_to_pan.js +30 -30
  161. package/lib/web/interfaces.js +80 -254
  162. package/lib/web/overlay_manager.js +70 -246
  163. package/lib/web/password_prompt.js +38 -64
  164. package/lib/web/pdf_attachment_viewer.js +150 -126
  165. package/lib/web/pdf_cursor_tools.js +75 -102
  166. package/lib/web/pdf_document_properties.js +229 -383
  167. package/lib/web/pdf_find_bar.js +136 -170
  168. package/lib/web/pdf_find_controller.js +492 -548
  169. package/lib/web/pdf_find_utils.js +13 -13
  170. package/lib/web/pdf_history.js +397 -406
  171. package/lib/web/pdf_layer_viewer.js +208 -0
  172. package/lib/web/pdf_link_service.js +304 -348
  173. package/lib/web/pdf_outline_viewer.js +119 -212
  174. package/lib/web/pdf_page_view.js +474 -513
  175. package/lib/web/pdf_presentation_mode.js +308 -357
  176. package/lib/web/pdf_print_service.js +96 -110
  177. package/lib/web/pdf_rendering_queue.js +87 -108
  178. package/lib/web/pdf_sidebar.js +286 -302
  179. package/lib/web/pdf_sidebar_resizer.js +92 -119
  180. package/lib/web/pdf_single_page_viewer.js +77 -126
  181. package/lib/web/pdf_thumbnail_view.js +289 -297
  182. package/lib/web/pdf_thumbnail_viewer.js +202 -206
  183. package/lib/web/pdf_viewer.component.js +20 -21
  184. package/lib/web/pdf_viewer.js +55 -115
  185. package/lib/web/preferences.js +69 -273
  186. package/lib/web/secondary_toolbar.js +164 -196
  187. package/lib/web/text_layer_builder.js +284 -319
  188. package/lib/web/toolbar.js +217 -210
  189. package/lib/web/ui_utils.js +274 -421
  190. package/lib/web/view_history.js +52 -226
  191. package/lib/web/viewer_compatibility.js +21 -6
  192. package/package.json +4 -9
  193. package/types/display/annotation_layer.d.ts +61 -0
  194. package/types/display/annotation_storage.d.ts +36 -0
  195. package/types/display/api.d.ts +1107 -0
  196. package/types/display/api_compatibility.d.ts +1 -0
  197. package/types/display/canvas.d.ts +4 -0
  198. package/types/display/content_disposition.d.ts +7 -0
  199. package/types/display/display_utils.d.ts +243 -0
  200. package/types/display/fetch_stream.d.ts +67 -0
  201. package/types/display/font_loader.d.ts +19 -0
  202. package/types/display/metadata.d.ts +9 -0
  203. package/types/display/network.d.ts +80 -0
  204. package/types/display/network_utils.d.ts +14 -0
  205. package/types/display/node_stream.d.ts +72 -0
  206. package/types/display/node_utils.d.ts +6 -0
  207. package/types/display/optional_content_config.d.ts +12 -0
  208. package/types/display/pattern_helper.d.ts +5 -0
  209. package/types/display/svg.d.ts +2 -0
  210. package/types/display/text_layer.d.ts +83 -0
  211. package/types/display/transport_stream.d.ts +57 -0
  212. package/types/display/webgl.d.ts +20 -0
  213. package/types/display/worker_options.d.ts +27 -0
  214. package/types/display/xml_parser.d.ts +35 -0
  215. package/types/pdf.d.ts +33 -0
  216. package/types/shared/compatibility.d.ts +1 -0
  217. package/types/shared/is_node.d.ts +1 -0
  218. package/types/shared/message_handler.d.ts +62 -0
  219. package/types/shared/util.d.ts +421 -0
  220. package/web/images/shadow.png +0 -0
  221. package/web/pdf_viewer.css +29 -27
  222. package/web/pdf_viewer.js +3524 -4746
  223. package/web/pdf_viewer.js.map +1 -1
  224. package/webpack.js +6 -5
  225. package/external/streams/streams-lib.js +0 -3962
  226. package/external/url/url-lib.js +0 -627
  227. package/lib/shared/streams_polyfill.js +0 -43
  228. package/lib/shared/url_polyfill.js +0 -56
  229. package/web/images/texture.png +0 -0
@@ -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 2019 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.
@@ -24,195 +24,194 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
+ exports.getQuadPoints = getQuadPoints;
27
28
  exports.MarkupAnnotation = exports.AnnotationFactory = exports.AnnotationBorderStyle = exports.Annotation = void 0;
28
29
 
29
- var _util = require("../shared/util");
30
+ var _util = require("../shared/util.js");
30
31
 
31
- var _obj = require("./obj");
32
+ var _obj = require("./obj.js");
32
33
 
33
- var _primitives = require("./primitives");
34
+ var _primitives = require("./primitives.js");
34
35
 
35
- var _colorspace = require("./colorspace");
36
+ var _colorspace = require("./colorspace.js");
36
37
 
37
- var _core_utils = require("./core_utils");
38
+ var _core_utils = require("./core_utils.js");
38
39
 
39
- var _operator_list = require("./operator_list");
40
+ var _operator_list = require("./operator_list.js");
40
41
 
41
- var _stream = require("./stream");
42
+ var _stream = require("./stream.js");
42
43
 
43
- function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
44
+ var _writer = require("./writer.js");
44
45
 
45
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
46
+ class AnnotationFactory {
47
+ static create(xref, ref, pdfManager, idFactory) {
48
+ return pdfManager.ensureCatalog("acroForm").then(acroForm => {
49
+ return pdfManager.ensure(this, "_create", [xref, ref, pdfManager, idFactory, acroForm]);
50
+ });
51
+ }
46
52
 
47
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
53
+ static _create(xref, ref, pdfManager, idFactory, acroForm) {
54
+ const dict = xref.fetchIfRef(ref);
48
55
 
49
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
56
+ if (!(0, _primitives.isDict)(dict)) {
57
+ return undefined;
58
+ }
50
59
 
51
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
60
+ const id = (0, _primitives.isRef)(ref) ? ref.toString() : `annot_${idFactory.createObjId()}`;
61
+ let subtype = dict.get("Subtype");
62
+ subtype = (0, _primitives.isName)(subtype) ? subtype.name : null;
63
+ const parameters = {
64
+ xref,
65
+ ref,
66
+ dict,
67
+ subtype,
68
+ id,
69
+ pdfManager,
70
+ acroForm: acroForm instanceof _primitives.Dict ? acroForm : _primitives.Dict.empty
71
+ };
52
72
 
53
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
73
+ switch (subtype) {
74
+ case "Link":
75
+ return new LinkAnnotation(parameters);
54
76
 
55
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
77
+ case "Text":
78
+ return new TextAnnotation(parameters);
56
79
 
57
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
80
+ case "Widget":
81
+ let fieldType = (0, _core_utils.getInheritableProperty)({
82
+ dict,
83
+ key: "FT"
84
+ });
85
+ fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
58
86
 
59
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
87
+ switch (fieldType) {
88
+ case "Tx":
89
+ return new TextWidgetAnnotation(parameters);
60
90
 
61
- 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); } }
91
+ case "Btn":
92
+ return new ButtonWidgetAnnotation(parameters);
62
93
 
63
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
94
+ case "Ch":
95
+ return new ChoiceWidgetAnnotation(parameters);
96
+ }
64
97
 
65
- var AnnotationFactory =
66
- /*#__PURE__*/
67
- function () {
68
- function AnnotationFactory() {
69
- _classCallCheck(this, AnnotationFactory);
70
- }
98
+ (0, _util.warn)('Unimplemented widget field type "' + fieldType + '", ' + "falling back to base field type.");
99
+ return new WidgetAnnotation(parameters);
71
100
 
72
- _createClass(AnnotationFactory, null, [{
73
- key: "create",
74
- value: function create(xref, ref, pdfManager, idFactory) {
75
- return pdfManager.ensure(this, '_create', [xref, ref, pdfManager, idFactory]);
76
- }
77
- }, {
78
- key: "_create",
79
- value: function _create(xref, ref, pdfManager, idFactory) {
80
- var dict = xref.fetchIfRef(ref);
101
+ case "Popup":
102
+ return new PopupAnnotation(parameters);
81
103
 
82
- if (!(0, _primitives.isDict)(dict)) {
83
- return undefined;
84
- }
104
+ case "FreeText":
105
+ return new FreeTextAnnotation(parameters);
85
106
 
86
- var id = (0, _primitives.isRef)(ref) ? ref.toString() : "annot_".concat(idFactory.createObjId());
87
- var subtype = dict.get('Subtype');
88
- subtype = (0, _primitives.isName)(subtype) ? subtype.name : null;
89
- var parameters = {
90
- xref: xref,
91
- dict: dict,
92
- subtype: subtype,
93
- id: id,
94
- pdfManager: pdfManager
95
- };
96
-
97
- switch (subtype) {
98
- case 'Link':
99
- return new LinkAnnotation(parameters);
100
-
101
- case 'Text':
102
- return new TextAnnotation(parameters);
103
-
104
- case 'Widget':
105
- var fieldType = (0, _core_utils.getInheritableProperty)({
106
- dict: dict,
107
- key: 'FT'
108
- });
109
- fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
110
-
111
- switch (fieldType) {
112
- case 'Tx':
113
- return new TextWidgetAnnotation(parameters);
114
-
115
- case 'Btn':
116
- return new ButtonWidgetAnnotation(parameters);
117
-
118
- case 'Ch':
119
- return new ChoiceWidgetAnnotation(parameters);
120
- }
107
+ case "Line":
108
+ return new LineAnnotation(parameters);
121
109
 
122
- (0, _util.warn)('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
123
- return new WidgetAnnotation(parameters);
110
+ case "Square":
111
+ return new SquareAnnotation(parameters);
124
112
 
125
- case 'Popup':
126
- return new PopupAnnotation(parameters);
113
+ case "Circle":
114
+ return new CircleAnnotation(parameters);
127
115
 
128
- case 'FreeText':
129
- return new FreeTextAnnotation(parameters);
116
+ case "PolyLine":
117
+ return new PolylineAnnotation(parameters);
130
118
 
131
- case 'Line':
132
- return new LineAnnotation(parameters);
119
+ case "Polygon":
120
+ return new PolygonAnnotation(parameters);
133
121
 
134
- case 'Square':
135
- return new SquareAnnotation(parameters);
122
+ case "Caret":
123
+ return new CaretAnnotation(parameters);
136
124
 
137
- case 'Circle':
138
- return new CircleAnnotation(parameters);
125
+ case "Ink":
126
+ return new InkAnnotation(parameters);
139
127
 
140
- case 'PolyLine':
141
- return new PolylineAnnotation(parameters);
128
+ case "Highlight":
129
+ return new HighlightAnnotation(parameters);
142
130
 
143
- case 'Polygon':
144
- return new PolygonAnnotation(parameters);
131
+ case "Underline":
132
+ return new UnderlineAnnotation(parameters);
145
133
 
146
- case 'Caret':
147
- return new CaretAnnotation(parameters);
134
+ case "Squiggly":
135
+ return new SquigglyAnnotation(parameters);
148
136
 
149
- case 'Ink':
150
- return new InkAnnotation(parameters);
137
+ case "StrikeOut":
138
+ return new StrikeOutAnnotation(parameters);
151
139
 
152
- case 'Highlight':
153
- return new HighlightAnnotation(parameters);
140
+ case "Stamp":
141
+ return new StampAnnotation(parameters);
154
142
 
155
- case 'Underline':
156
- return new UnderlineAnnotation(parameters);
143
+ case "FileAttachment":
144
+ return new FileAttachmentAnnotation(parameters);
157
145
 
158
- case 'Squiggly':
159
- return new SquigglyAnnotation(parameters);
146
+ default:
147
+ if (!subtype) {
148
+ (0, _util.warn)("Annotation is missing the required /Subtype.");
149
+ } else {
150
+ (0, _util.warn)('Unimplemented annotation type "' + subtype + '", ' + "falling back to base annotation.");
151
+ }
160
152
 
161
- case 'StrikeOut':
162
- return new StrikeOutAnnotation(parameters);
153
+ return new Annotation(parameters);
154
+ }
155
+ }
163
156
 
164
- case 'Stamp':
165
- return new StampAnnotation(parameters);
157
+ }
166
158
 
167
- case 'FileAttachment':
168
- return new FileAttachmentAnnotation(parameters);
159
+ exports.AnnotationFactory = AnnotationFactory;
169
160
 
170
- default:
171
- if (!subtype) {
172
- (0, _util.warn)('Annotation is missing the required /Subtype.');
173
- } else {
174
- (0, _util.warn)('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
175
- }
161
+ function getQuadPoints(dict, rect) {
162
+ if (!dict.has("QuadPoints")) {
163
+ return null;
164
+ }
165
+
166
+ const quadPoints = dict.getArray("QuadPoints");
167
+
168
+ if (!Array.isArray(quadPoints) || quadPoints.length % 8 > 0) {
169
+ return null;
170
+ }
171
+
172
+ const quadPointsLists = [];
173
+
174
+ for (let i = 0, ii = quadPoints.length / 8; i < ii; i++) {
175
+ quadPointsLists.push([]);
176
176
 
177
- return new Annotation(parameters);
177
+ for (let j = i * 8, jj = i * 8 + 8; j < jj; j += 2) {
178
+ const x = quadPoints[j];
179
+ const y = quadPoints[j + 1];
180
+
181
+ if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) {
182
+ return null;
178
183
  }
179
- }
180
- }]);
181
184
 
182
- return AnnotationFactory;
183
- }();
185
+ quadPointsLists[i].push({
186
+ x,
187
+ y
188
+ });
189
+ }
190
+ }
184
191
 
185
- exports.AnnotationFactory = AnnotationFactory;
192
+ return quadPointsLists;
193
+ }
186
194
 
187
195
  function getTransformMatrix(rect, bbox, matrix) {
188
- var bounds = _util.Util.getAxialAlignedBoundingBox(bbox, matrix);
189
-
190
- var minX = bounds[0];
191
- var minY = bounds[1];
192
- var maxX = bounds[2];
193
- var maxY = bounds[3];
196
+ const [minX, minY, maxX, maxY] = _util.Util.getAxialAlignedBoundingBox(bbox, matrix);
194
197
 
195
198
  if (minX === maxX || minY === maxY) {
196
199
  return [1, 0, 0, 1, rect[0], rect[1]];
197
200
  }
198
201
 
199
- var xRatio = (rect[2] - rect[0]) / (maxX - minX);
200
- var yRatio = (rect[3] - rect[1]) / (maxY - minY);
202
+ const xRatio = (rect[2] - rect[0]) / (maxX - minX);
203
+ const yRatio = (rect[3] - rect[1]) / (maxY - minY);
201
204
  return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio];
202
205
  }
203
206
 
204
- var Annotation =
205
- /*#__PURE__*/
206
- function () {
207
- function Annotation(params) {
208
- _classCallCheck(this, Annotation);
209
-
210
- var dict = params.dict;
211
- this.setContents(dict.get('Contents'));
212
- this.setModificationDate(dict.get('M'));
213
- this.setFlags(dict.get('F'));
214
- this.setRectangle(dict.getArray('Rect'));
215
- this.setColor(dict.getArray('C'));
207
+ class Annotation {
208
+ constructor(params) {
209
+ const dict = params.dict;
210
+ this.setContents(dict.get("Contents"));
211
+ this.setModificationDate(dict.get("M"));
212
+ this.setFlags(dict.get("F"));
213
+ this.setRectangle(dict.getArray("Rect"));
214
+ this.setColor(dict.getArray("C"));
216
215
  this.setBorderStyle(dict);
217
216
  this.setAppearance(dict);
218
217
  this.data = {
@@ -228,228 +227,207 @@ function () {
228
227
  };
229
228
  }
230
229
 
231
- _createClass(Annotation, [{
232
- key: "_hasFlag",
233
- value: function _hasFlag(flags, flag) {
234
- return !!(flags & flag);
235
- }
236
- }, {
237
- key: "_isViewable",
238
- value: function _isViewable(flags) {
239
- return !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN) && !this._hasFlag(flags, _util.AnnotationFlag.NOVIEW);
240
- }
241
- }, {
242
- key: "_isPrintable",
243
- value: function _isPrintable(flags) {
244
- return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN);
245
- }
246
- }, {
247
- key: "setContents",
248
- value: function setContents(contents) {
249
- this.contents = (0, _util.stringToPDFString)(contents || '');
250
- }
251
- }, {
252
- key: "setModificationDate",
253
- value: function setModificationDate(modificationDate) {
254
- this.modificationDate = (0, _util.isString)(modificationDate) ? modificationDate : null;
255
- }
256
- }, {
257
- key: "setFlags",
258
- value: function setFlags(flags) {
259
- this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
260
- }
261
- }, {
262
- key: "hasFlag",
263
- value: function hasFlag(flag) {
264
- return this._hasFlag(this.flags, flag);
265
- }
266
- }, {
267
- key: "setRectangle",
268
- value: function 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
- }
230
+ _hasFlag(flags, flag) {
231
+ return !!(flags & flag);
232
+ }
233
+
234
+ _isViewable(flags) {
235
+ return !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN) && !this._hasFlag(flags, _util.AnnotationFlag.NOVIEW);
236
+ }
237
+
238
+ _isPrintable(flags) {
239
+ return this._hasFlag(flags, _util.AnnotationFlag.PRINT) && !this._hasFlag(flags, _util.AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, _util.AnnotationFlag.HIDDEN);
240
+ }
241
+
242
+ get viewable() {
243
+ if (this.flags === 0) {
244
+ return true;
274
245
  }
275
- }, {
276
- key: "setColor",
277
- value: function setColor(color) {
278
- var rgbColor = new Uint8ClampedArray(3);
279
246
 
280
- if (!Array.isArray(color)) {
281
- this.color = rgbColor;
282
- return;
283
- }
247
+ return this._isViewable(this.flags);
248
+ }
284
249
 
285
- switch (color.length) {
286
- case 0:
287
- this.color = null;
288
- break;
250
+ get printable() {
251
+ if (this.flags === 0) {
252
+ return false;
253
+ }
289
254
 
290
- case 1:
291
- _colorspace.ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
255
+ return this._isPrintable(this.flags);
256
+ }
292
257
 
293
- this.color = rgbColor;
294
- break;
258
+ setContents(contents) {
259
+ this.contents = (0, _util.stringToPDFString)(contents || "");
260
+ }
295
261
 
296
- case 3:
297
- _colorspace.ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
262
+ setModificationDate(modificationDate) {
263
+ this.modificationDate = (0, _util.isString)(modificationDate) ? modificationDate : null;
264
+ }
298
265
 
299
- this.color = rgbColor;
300
- break;
266
+ setFlags(flags) {
267
+ this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
268
+ }
301
269
 
302
- case 4:
303
- _colorspace.ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
270
+ hasFlag(flag) {
271
+ return this._hasFlag(this.flags, flag);
272
+ }
304
273
 
305
- this.color = rgbColor;
306
- break;
274
+ setRectangle(rectangle) {
275
+ if (Array.isArray(rectangle) && rectangle.length === 4) {
276
+ this.rectangle = _util.Util.normalizeRect(rectangle);
277
+ } else {
278
+ this.rectangle = [0, 0, 0, 0];
279
+ }
280
+ }
307
281
 
308
- default:
309
- this.color = rgbColor;
310
- break;
311
- }
282
+ setColor(color) {
283
+ const rgbColor = new Uint8ClampedArray(3);
284
+
285
+ if (!Array.isArray(color)) {
286
+ this.color = rgbColor;
287
+ return;
312
288
  }
313
- }, {
314
- key: "setBorderStyle",
315
- value: function setBorderStyle(borderStyle) {
316
- this.borderStyle = new AnnotationBorderStyle();
317
289
 
318
- if (!(0, _primitives.isDict)(borderStyle)) {
319
- return;
320
- }
290
+ switch (color.length) {
291
+ case 0:
292
+ this.color = null;
293
+ break;
321
294
 
322
- if (borderStyle.has('BS')) {
323
- var dict = borderStyle.get('BS');
324
- var dictType = dict.get('Type');
295
+ case 1:
296
+ _colorspace.ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
325
297
 
326
- if (!dictType || (0, _primitives.isName)(dictType, 'Border')) {
327
- this.borderStyle.setWidth(dict.get('W'), this.rectangle);
328
- this.borderStyle.setStyle(dict.get('S'));
329
- this.borderStyle.setDashArray(dict.getArray('D'));
330
- }
331
- } else if (borderStyle.has('Border')) {
332
- var array = borderStyle.getArray('Border');
298
+ this.color = rgbColor;
299
+ break;
333
300
 
334
- if (Array.isArray(array) && array.length >= 3) {
335
- this.borderStyle.setHorizontalCornerRadius(array[0]);
336
- this.borderStyle.setVerticalCornerRadius(array[1]);
337
- this.borderStyle.setWidth(array[2], this.rectangle);
301
+ case 3:
302
+ _colorspace.ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
338
303
 
339
- if (array.length === 4) {
340
- this.borderStyle.setDashArray(array[3]);
341
- }
342
- }
343
- } else {
344
- this.borderStyle.setWidth(0);
345
- }
304
+ this.color = rgbColor;
305
+ break;
306
+
307
+ case 4:
308
+ _colorspace.ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
309
+
310
+ this.color = rgbColor;
311
+ break;
312
+
313
+ default:
314
+ this.color = rgbColor;
315
+ break;
346
316
  }
347
- }, {
348
- key: "setAppearance",
349
- value: function setAppearance(dict) {
350
- this.appearance = null;
351
- var appearanceStates = dict.get('AP');
317
+ }
352
318
 
353
- if (!(0, _primitives.isDict)(appearanceStates)) {
354
- return;
355
- }
319
+ setBorderStyle(borderStyle) {
320
+ this.borderStyle = new AnnotationBorderStyle();
356
321
 
357
- var normalAppearanceState = appearanceStates.get('N');
322
+ if (!(0, _primitives.isDict)(borderStyle)) {
323
+ return;
324
+ }
358
325
 
359
- if ((0, _primitives.isStream)(normalAppearanceState)) {
360
- this.appearance = normalAppearanceState;
361
- return;
362
- }
326
+ if (borderStyle.has("BS")) {
327
+ const dict = borderStyle.get("BS");
328
+ const dictType = dict.get("Type");
363
329
 
364
- if (!(0, _primitives.isDict)(normalAppearanceState)) {
365
- return;
330
+ if (!dictType || (0, _primitives.isName)(dictType, "Border")) {
331
+ this.borderStyle.setWidth(dict.get("W"), this.rectangle);
332
+ this.borderStyle.setStyle(dict.get("S"));
333
+ this.borderStyle.setDashArray(dict.getArray("D"));
366
334
  }
335
+ } else if (borderStyle.has("Border")) {
336
+ const array = borderStyle.getArray("Border");
367
337
 
368
- var as = dict.get('AS');
338
+ if (Array.isArray(array) && array.length >= 3) {
339
+ this.borderStyle.setHorizontalCornerRadius(array[0]);
340
+ this.borderStyle.setVerticalCornerRadius(array[1]);
341
+ this.borderStyle.setWidth(array[2], this.rectangle);
369
342
 
370
- if (!(0, _primitives.isName)(as) || !normalAppearanceState.has(as.name)) {
371
- return;
343
+ if (array.length === 4) {
344
+ this.borderStyle.setDashArray(array[3]);
345
+ }
372
346
  }
373
-
374
- this.appearance = normalAppearanceState.get(as.name);
347
+ } else {
348
+ this.borderStyle.setWidth(0);
375
349
  }
376
- }, {
377
- key: "loadResources",
378
- value: function loadResources(keys) {
379
- return this.appearance.dict.getAsync('Resources').then(function (resources) {
380
- if (!resources) {
381
- return undefined;
382
- }
350
+ }
383
351
 
384
- var objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref);
385
- return objectLoader.load().then(function () {
386
- return resources;
387
- });
388
- });
352
+ setAppearance(dict) {
353
+ this.appearance = null;
354
+ const appearanceStates = dict.get("AP");
355
+
356
+ if (!(0, _primitives.isDict)(appearanceStates)) {
357
+ return;
389
358
  }
390
- }, {
391
- key: "getOperatorList",
392
- value: function getOperatorList(evaluator, task, renderForms) {
393
- var _this = this;
394
359
 
395
- if (!this.appearance) {
396
- return Promise.resolve(new _operator_list.OperatorList());
397
- }
360
+ const normalAppearanceState = appearanceStates.get("N");
398
361
 
399
- var data = this.data;
400
- var appearanceDict = this.appearance.dict;
401
- var resourcesPromise = this.loadResources(['ExtGState', 'ColorSpace', 'Pattern', 'Shading', 'XObject', 'Font']);
402
- var bbox = appearanceDict.getArray('BBox') || [0, 0, 1, 1];
403
- var matrix = appearanceDict.getArray('Matrix') || [1, 0, 0, 1, 0, 0];
404
- var transform = getTransformMatrix(data.rect, bbox, matrix);
405
- return resourcesPromise.then(function (resources) {
406
- var opList = new _operator_list.OperatorList();
407
- opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
408
- return evaluator.getOperatorList({
409
- stream: _this.appearance,
410
- task: task,
411
- resources: resources,
412
- operatorList: opList
413
- }).then(function () {
414
- opList.addOp(_util.OPS.endAnnotation, []);
415
-
416
- _this.appearance.reset();
417
-
418
- return opList;
419
- });
420
- });
362
+ if ((0, _primitives.isStream)(normalAppearanceState)) {
363
+ this.appearance = normalAppearanceState;
364
+ return;
421
365
  }
422
- }, {
423
- key: "viewable",
424
- get: function get() {
425
- if (this.flags === 0) {
426
- return true;
427
- }
428
366
 
429
- return this._isViewable(this.flags);
367
+ if (!(0, _primitives.isDict)(normalAppearanceState)) {
368
+ return;
369
+ }
370
+
371
+ const as = dict.get("AS");
372
+
373
+ if (!(0, _primitives.isName)(as) || !normalAppearanceState.has(as.name)) {
374
+ return;
430
375
  }
431
- }, {
432
- key: "printable",
433
- get: function get() {
434
- if (this.flags === 0) {
435
- return false;
376
+
377
+ this.appearance = normalAppearanceState.get(as.name);
378
+ }
379
+
380
+ loadResources(keys) {
381
+ return this.appearance.dict.getAsync("Resources").then(resources => {
382
+ if (!resources) {
383
+ return undefined;
436
384
  }
437
385
 
438
- return this._isPrintable(this.flags);
386
+ const objectLoader = new _obj.ObjectLoader(resources, keys, resources.xref);
387
+ return objectLoader.load().then(function () {
388
+ return resources;
389
+ });
390
+ });
391
+ }
392
+
393
+ getOperatorList(evaluator, task, renderForms, annotationStorage) {
394
+ if (!this.appearance) {
395
+ return Promise.resolve(new _operator_list.OperatorList());
439
396
  }
440
- }]);
441
397
 
442
- return Annotation;
443
- }();
398
+ const appearance = this.appearance;
399
+ const data = this.data;
400
+ const appearanceDict = appearance.dict;
401
+ const resourcesPromise = this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"]);
402
+ const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
403
+ const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
404
+ const transform = getTransformMatrix(data.rect, bbox, matrix);
405
+ return resourcesPromise.then(resources => {
406
+ const opList = new _operator_list.OperatorList();
407
+ opList.addOp(_util.OPS.beginAnnotation, [data.rect, transform, matrix]);
408
+ return evaluator.getOperatorList({
409
+ stream: appearance,
410
+ task,
411
+ resources,
412
+ operatorList: opList
413
+ }).then(() => {
414
+ opList.addOp(_util.OPS.endAnnotation, []);
415
+ appearance.reset();
416
+ return opList;
417
+ });
418
+ });
419
+ }
444
420
 
445
- exports.Annotation = Annotation;
421
+ async save(evaluator, task, annotationStorage) {
422
+ return null;
423
+ }
446
424
 
447
- var AnnotationBorderStyle =
448
- /*#__PURE__*/
449
- function () {
450
- function AnnotationBorderStyle() {
451
- _classCallCheck(this, AnnotationBorderStyle);
425
+ }
426
+
427
+ exports.Annotation = Annotation;
452
428
 
429
+ class AnnotationBorderStyle {
430
+ constructor() {
453
431
  this.width = 1;
454
432
  this.style = _util.AnnotationBorderStyleType.SOLID;
455
433
  this.dashArray = [3];
@@ -457,861 +435,1100 @@ function () {
457
435
  this.verticalCornerRadius = 0;
458
436
  }
459
437
 
460
- _createClass(AnnotationBorderStyle, [{
461
- key: "setWidth",
462
- value: function setWidth(width) {
463
- var rect = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0, 0];
464
-
465
- if ((0, _primitives.isName)(width)) {
466
- this.width = 0;
467
- return;
468
- }
438
+ setWidth(width, rect = [0, 0, 0, 0]) {
439
+ if ((0, _primitives.isName)(width)) {
440
+ this.width = 0;
441
+ return;
442
+ }
469
443
 
470
- if (Number.isInteger(width)) {
471
- if (width > 0) {
472
- var maxWidth = (rect[2] - rect[0]) / 2;
473
- var maxHeight = (rect[3] - rect[1]) / 2;
444
+ if (Number.isInteger(width)) {
445
+ if (width > 0) {
446
+ const maxWidth = (rect[2] - rect[0]) / 2;
447
+ const maxHeight = (rect[3] - rect[1]) / 2;
474
448
 
475
- if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) {
476
- (0, _util.warn)("AnnotationBorderStyle.setWidth - ignoring width: ".concat(width));
477
- width = 1;
478
- }
449
+ if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) {
450
+ (0, _util.warn)(`AnnotationBorderStyle.setWidth - ignoring width: ${width}`);
451
+ width = 1;
479
452
  }
480
-
481
- this.width = width;
482
453
  }
454
+
455
+ this.width = width;
483
456
  }
484
- }, {
485
- key: "setStyle",
486
- value: function setStyle(style) {
487
- if (!(0, _primitives.isName)(style)) {
488
- return;
489
- }
457
+ }
490
458
 
491
- switch (style.name) {
492
- case 'S':
493
- this.style = _util.AnnotationBorderStyleType.SOLID;
494
- break;
459
+ setStyle(style) {
460
+ if (!(0, _primitives.isName)(style)) {
461
+ return;
462
+ }
495
463
 
496
- case 'D':
497
- this.style = _util.AnnotationBorderStyleType.DASHED;
498
- break;
464
+ switch (style.name) {
465
+ case "S":
466
+ this.style = _util.AnnotationBorderStyleType.SOLID;
467
+ break;
499
468
 
500
- case 'B':
501
- this.style = _util.AnnotationBorderStyleType.BEVELED;
502
- break;
469
+ case "D":
470
+ this.style = _util.AnnotationBorderStyleType.DASHED;
471
+ break;
503
472
 
504
- case 'I':
505
- this.style = _util.AnnotationBorderStyleType.INSET;
506
- break;
473
+ case "B":
474
+ this.style = _util.AnnotationBorderStyleType.BEVELED;
475
+ break;
507
476
 
508
- case 'U':
509
- this.style = _util.AnnotationBorderStyleType.UNDERLINE;
510
- break;
477
+ case "I":
478
+ this.style = _util.AnnotationBorderStyleType.INSET;
479
+ break;
511
480
 
512
- default:
513
- break;
514
- }
481
+ case "U":
482
+ this.style = _util.AnnotationBorderStyleType.UNDERLINE;
483
+ break;
484
+
485
+ default:
486
+ break;
515
487
  }
516
- }, {
517
- key: "setDashArray",
518
- value: function setDashArray(dashArray) {
519
- if (Array.isArray(dashArray) && dashArray.length > 0) {
520
- var isValid = true;
521
- var allZeros = true;
522
-
523
- for (var i = 0, len = dashArray.length; i < len; i++) {
524
- var element = dashArray[i];
525
- var validNumber = +element >= 0;
526
-
527
- if (!validNumber) {
528
- isValid = false;
529
- break;
530
- } else if (element > 0) {
531
- allZeros = false;
532
- }
533
- }
488
+ }
534
489
 
535
- if (isValid && !allZeros) {
536
- this.dashArray = dashArray;
537
- } else {
538
- this.width = 0;
490
+ setDashArray(dashArray) {
491
+ if (Array.isArray(dashArray) && dashArray.length > 0) {
492
+ let isValid = true;
493
+ let allZeros = true;
494
+
495
+ for (const element of dashArray) {
496
+ const validNumber = +element >= 0;
497
+
498
+ if (!validNumber) {
499
+ isValid = false;
500
+ break;
501
+ } else if (element > 0) {
502
+ allZeros = false;
539
503
  }
540
- } else if (dashArray) {
504
+ }
505
+
506
+ if (isValid && !allZeros) {
507
+ this.dashArray = dashArray;
508
+ } else {
541
509
  this.width = 0;
542
510
  }
511
+ } else if (dashArray) {
512
+ this.width = 0;
543
513
  }
544
- }, {
545
- key: "setHorizontalCornerRadius",
546
- value: function setHorizontalCornerRadius(radius) {
547
- if (Number.isInteger(radius)) {
548
- this.horizontalCornerRadius = radius;
549
- }
514
+ }
515
+
516
+ setHorizontalCornerRadius(radius) {
517
+ if (Number.isInteger(radius)) {
518
+ this.horizontalCornerRadius = radius;
550
519
  }
551
- }, {
552
- key: "setVerticalCornerRadius",
553
- value: function setVerticalCornerRadius(radius) {
554
- if (Number.isInteger(radius)) {
555
- this.verticalCornerRadius = radius;
556
- }
520
+ }
521
+
522
+ setVerticalCornerRadius(radius) {
523
+ if (Number.isInteger(radius)) {
524
+ this.verticalCornerRadius = radius;
557
525
  }
558
- }]);
526
+ }
559
527
 
560
- return AnnotationBorderStyle;
561
- }();
528
+ }
562
529
 
563
530
  exports.AnnotationBorderStyle = AnnotationBorderStyle;
564
531
 
565
- var MarkupAnnotation =
566
- /*#__PURE__*/
567
- function (_Annotation) {
568
- _inherits(MarkupAnnotation, _Annotation);
532
+ class MarkupAnnotation extends Annotation {
533
+ constructor(parameters) {
534
+ super(parameters);
535
+ const dict = parameters.dict;
569
536
 
570
- function MarkupAnnotation(parameters) {
571
- var _this2;
537
+ if (dict.has("IRT")) {
538
+ const rawIRT = dict.getRaw("IRT");
539
+ this.data.inReplyTo = (0, _primitives.isRef)(rawIRT) ? rawIRT.toString() : null;
540
+ const rt = dict.get("RT");
541
+ this.data.replyType = (0, _primitives.isName)(rt) ? rt.name : _util.AnnotationReplyType.REPLY;
542
+ }
543
+
544
+ if (this.data.replyType === _util.AnnotationReplyType.GROUP) {
545
+ const parent = dict.get("IRT");
546
+ this.data.title = (0, _util.stringToPDFString)(parent.get("T") || "");
547
+ this.setContents(parent.get("Contents"));
548
+ this.data.contents = this.contents;
572
549
 
573
- _classCallCheck(this, MarkupAnnotation);
550
+ if (!parent.has("CreationDate")) {
551
+ this.data.creationDate = null;
552
+ } else {
553
+ this.setCreationDate(parent.get("CreationDate"));
554
+ this.data.creationDate = this.creationDate;
555
+ }
574
556
 
575
- _this2 = _possibleConstructorReturn(this, _getPrototypeOf(MarkupAnnotation).call(this, parameters));
576
- var dict = parameters.dict;
557
+ if (!parent.has("M")) {
558
+ this.data.modificationDate = null;
559
+ } else {
560
+ this.setModificationDate(parent.get("M"));
561
+ this.data.modificationDate = this.modificationDate;
562
+ }
577
563
 
578
- if (!dict.has('C')) {
579
- _this2.data.color = null;
580
- }
564
+ this.data.hasPopup = parent.has("Popup");
581
565
 
582
- _this2.setCreationDate(dict.get('CreationDate'));
566
+ if (!parent.has("C")) {
567
+ this.data.color = null;
568
+ } else {
569
+ this.setColor(parent.getArray("C"));
570
+ this.data.color = this.color;
571
+ }
572
+ } else {
573
+ this.data.title = (0, _util.stringToPDFString)(dict.get("T") || "");
574
+ this.setCreationDate(dict.get("CreationDate"));
575
+ this.data.creationDate = this.creationDate;
576
+ this.data.hasPopup = dict.has("Popup");
583
577
 
584
- _this2.data.creationDate = _this2.creationDate;
585
- _this2.data.hasPopup = dict.has('Popup');
586
- _this2.data.title = (0, _util.stringToPDFString)(dict.get('T') || '');
587
- return _this2;
578
+ if (!dict.has("C")) {
579
+ this.data.color = null;
580
+ }
581
+ }
588
582
  }
589
583
 
590
- _createClass(MarkupAnnotation, [{
591
- key: "setCreationDate",
592
- value: function setCreationDate(creationDate) {
593
- this.creationDate = (0, _util.isString)(creationDate) ? creationDate : null;
594
- }
595
- }]);
584
+ setCreationDate(creationDate) {
585
+ this.creationDate = (0, _util.isString)(creationDate) ? creationDate : null;
586
+ }
596
587
 
597
- return MarkupAnnotation;
598
- }(Annotation);
588
+ }
599
589
 
600
590
  exports.MarkupAnnotation = MarkupAnnotation;
601
591
 
602
- var WidgetAnnotation =
603
- /*#__PURE__*/
604
- function (_Annotation2) {
605
- _inherits(WidgetAnnotation, _Annotation2);
606
-
607
- function WidgetAnnotation(params) {
608
- var _this3;
609
-
610
- _classCallCheck(this, WidgetAnnotation);
611
-
612
- _this3 = _possibleConstructorReturn(this, _getPrototypeOf(WidgetAnnotation).call(this, params));
613
- var dict = params.dict;
614
- var data = _this3.data;
592
+ class WidgetAnnotation extends Annotation {
593
+ constructor(params) {
594
+ super(params);
595
+ const dict = params.dict;
596
+ const data = this.data;
597
+ this.ref = params.ref;
615
598
  data.annotationType = _util.AnnotationType.WIDGET;
616
- data.fieldName = _this3._constructFieldName(dict);
617
- data.fieldValue = (0, _core_utils.getInheritableProperty)({
618
- dict: dict,
619
- key: 'V',
599
+ data.fieldName = this._constructFieldName(dict);
600
+ const fieldValue = (0, _core_utils.getInheritableProperty)({
601
+ dict,
602
+ key: "V",
620
603
  getArray: true
621
604
  });
622
- data.alternativeText = (0, _util.stringToPDFString)(dict.get('TU') || '');
605
+ data.fieldValue = this._decodeFormValue(fieldValue);
606
+ data.alternativeText = (0, _util.stringToPDFString)(dict.get("TU") || "");
623
607
  data.defaultAppearance = (0, _core_utils.getInheritableProperty)({
624
- dict: dict,
625
- key: 'DA'
626
- }) || '';
627
- var fieldType = (0, _core_utils.getInheritableProperty)({
628
- dict: dict,
629
- key: 'FT'
608
+ dict,
609
+ key: "DA"
610
+ }) || params.acroForm.get("DA") || "";
611
+ const fieldType = (0, _core_utils.getInheritableProperty)({
612
+ dict,
613
+ key: "FT"
630
614
  });
631
615
  data.fieldType = (0, _primitives.isName)(fieldType) ? fieldType.name : null;
632
- _this3.fieldResources = (0, _core_utils.getInheritableProperty)({
633
- dict: dict,
634
- key: 'DR'
635
- }) || _primitives.Dict.empty;
616
+ this.fieldResources = (0, _core_utils.getInheritableProperty)({
617
+ dict,
618
+ key: "DR"
619
+ }) || params.acroForm.get("DR") || _primitives.Dict.empty;
636
620
  data.fieldFlags = (0, _core_utils.getInheritableProperty)({
637
- dict: dict,
638
- key: 'Ff'
621
+ dict,
622
+ key: "Ff"
639
623
  });
640
624
 
641
625
  if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
642
626
  data.fieldFlags = 0;
643
627
  }
644
628
 
645
- data.readOnly = _this3.hasFieldFlag(_util.AnnotationFieldFlag.READONLY);
629
+ data.readOnly = this.hasFieldFlag(_util.AnnotationFieldFlag.READONLY);
646
630
 
647
- if (data.fieldType === 'Sig') {
631
+ if (data.fieldType === "Sig") {
648
632
  data.fieldValue = null;
649
-
650
- _this3.setFlags(_util.AnnotationFlag.HIDDEN);
633
+ this.setFlags(_util.AnnotationFlag.HIDDEN);
651
634
  }
652
-
653
- return _this3;
654
635
  }
655
636
 
656
- _createClass(WidgetAnnotation, [{
657
- key: "_constructFieldName",
658
- value: function _constructFieldName(dict) {
659
- if (!dict.has('T') && !dict.has('Parent')) {
660
- (0, _util.warn)('Unknown field name, falling back to empty field name.');
661
- return '';
662
- }
637
+ _constructFieldName(dict) {
638
+ if (!dict.has("T") && !dict.has("Parent")) {
639
+ (0, _util.warn)("Unknown field name, falling back to empty field name.");
640
+ return "";
641
+ }
663
642
 
664
- if (!dict.has('Parent')) {
665
- return (0, _util.stringToPDFString)(dict.get('T'));
666
- }
643
+ if (!dict.has("Parent")) {
644
+ return (0, _util.stringToPDFString)(dict.get("T"));
645
+ }
667
646
 
668
- var fieldName = [];
647
+ const fieldName = [];
669
648
 
670
- if (dict.has('T')) {
671
- fieldName.unshift((0, _util.stringToPDFString)(dict.get('T')));
672
- }
649
+ if (dict.has("T")) {
650
+ fieldName.unshift((0, _util.stringToPDFString)(dict.get("T")));
651
+ }
673
652
 
674
- var loopDict = dict;
653
+ let loopDict = dict;
675
654
 
676
- while (loopDict.has('Parent')) {
677
- loopDict = loopDict.get('Parent');
655
+ while (loopDict.has("Parent")) {
656
+ loopDict = loopDict.get("Parent");
678
657
 
679
- if (!(0, _primitives.isDict)(loopDict)) {
680
- break;
681
- }
682
-
683
- if (loopDict.has('T')) {
684
- fieldName.unshift((0, _util.stringToPDFString)(loopDict.get('T')));
685
- }
658
+ if (!(0, _primitives.isDict)(loopDict)) {
659
+ break;
686
660
  }
687
661
 
688
- return fieldName.join('.');
689
- }
690
- }, {
691
- key: "hasFieldFlag",
692
- value: function hasFieldFlag(flag) {
693
- return !!(this.data.fieldFlags & flag);
694
- }
695
- }, {
696
- key: "getOperatorList",
697
- value: function getOperatorList(evaluator, task, renderForms) {
698
- if (renderForms) {
699
- return Promise.resolve(new _operator_list.OperatorList());
662
+ if (loopDict.has("T")) {
663
+ fieldName.unshift((0, _util.stringToPDFString)(loopDict.get("T")));
700
664
  }
701
-
702
- return _get(_getPrototypeOf(WidgetAnnotation.prototype), "getOperatorList", this).call(this, evaluator, task, renderForms);
703
665
  }
704
- }]);
705
-
706
- return WidgetAnnotation;
707
- }(Annotation);
708
666
 
709
- var TextWidgetAnnotation =
710
- /*#__PURE__*/
711
- function (_WidgetAnnotation) {
712
- _inherits(TextWidgetAnnotation, _WidgetAnnotation);
667
+ return fieldName.join(".");
668
+ }
713
669
 
714
- function TextWidgetAnnotation(params) {
715
- var _this4;
670
+ _decodeFormValue(formValue) {
671
+ if (Array.isArray(formValue)) {
672
+ return formValue.filter(item => (0, _util.isString)(item)).map(item => (0, _util.stringToPDFString)(item));
673
+ } else if ((0, _primitives.isName)(formValue)) {
674
+ return (0, _util.stringToPDFString)(formValue.name);
675
+ } else if ((0, _util.isString)(formValue)) {
676
+ return (0, _util.stringToPDFString)(formValue);
677
+ }
716
678
 
717
- _classCallCheck(this, TextWidgetAnnotation);
679
+ return null;
680
+ }
718
681
 
719
- _this4 = _possibleConstructorReturn(this, _getPrototypeOf(TextWidgetAnnotation).call(this, params));
720
- var dict = params.dict;
721
- _this4.data.fieldValue = (0, _util.stringToPDFString)(_this4.data.fieldValue || '');
722
- var alignment = (0, _core_utils.getInheritableProperty)({
723
- dict: dict,
724
- key: 'Q'
725
- });
682
+ hasFieldFlag(flag) {
683
+ return !!(this.data.fieldFlags & flag);
684
+ }
726
685
 
727
- if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
728
- alignment = null;
686
+ getOperatorList(evaluator, task, renderForms, annotationStorage) {
687
+ if (renderForms) {
688
+ return Promise.resolve(new _operator_list.OperatorList());
729
689
  }
730
690
 
731
- _this4.data.textAlignment = alignment;
732
- var maximumLength = (0, _core_utils.getInheritableProperty)({
733
- dict: dict,
734
- key: 'MaxLen'
735
- });
736
-
737
- if (!Number.isInteger(maximumLength) || maximumLength < 0) {
738
- maximumLength = null;
691
+ if (!this._hasText) {
692
+ return super.getOperatorList(evaluator, task, renderForms, annotationStorage);
739
693
  }
740
694
 
741
- _this4.data.maxLen = maximumLength;
742
- _this4.data.multiLine = _this4.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE);
743
- _this4.data.comb = _this4.hasFieldFlag(_util.AnnotationFieldFlag.COMB) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD) && !_this4.hasFieldFlag(_util.AnnotationFieldFlag.FILESELECT) && _this4.data.maxLen !== null;
744
- return _this4;
745
- }
746
-
747
- _createClass(TextWidgetAnnotation, [{
748
- key: "getOperatorList",
749
- value: function getOperatorList(evaluator, task, renderForms) {
750
- if (renderForms || this.appearance) {
751
- return _get(_getPrototypeOf(TextWidgetAnnotation.prototype), "getOperatorList", this).call(this, evaluator, task, renderForms);
695
+ return this._getAppearance(evaluator, task, annotationStorage).then(content => {
696
+ if (this.appearance && content === null) {
697
+ return super.getOperatorList(evaluator, task, renderForms, annotationStorage);
752
698
  }
753
699
 
754
- var operatorList = new _operator_list.OperatorList();
700
+ const operatorList = new _operator_list.OperatorList();
755
701
 
756
- if (!this.data.defaultAppearance) {
757
- return Promise.resolve(operatorList);
702
+ if (!this.data.defaultAppearance || content === null) {
703
+ return operatorList;
758
704
  }
759
705
 
760
- var stream = new _stream.Stream((0, _util.stringToBytes)(this.data.defaultAppearance));
706
+ const matrix = [1, 0, 0, 1, 0, 0];
707
+ const bbox = [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]];
708
+ const transform = getTransformMatrix(this.data.rect, bbox, matrix);
709
+ operatorList.addOp(_util.OPS.beginAnnotation, [this.data.rect, transform, matrix]);
710
+ const stream = new _stream.StringStream(content);
761
711
  return evaluator.getOperatorList({
762
- stream: stream,
763
- task: task,
712
+ stream,
713
+ task,
764
714
  resources: this.fieldResources,
765
- operatorList: operatorList
715
+ operatorList
766
716
  }).then(function () {
717
+ operatorList.addOp(_util.OPS.endAnnotation, []);
767
718
  return operatorList;
768
719
  });
769
- }
770
- }]);
720
+ });
721
+ }
771
722
 
772
- return TextWidgetAnnotation;
773
- }(WidgetAnnotation);
723
+ async save(evaluator, task, annotationStorage) {
724
+ if (this.data.fieldValue === annotationStorage[this.data.id]) {
725
+ return null;
726
+ }
774
727
 
775
- var ButtonWidgetAnnotation =
776
- /*#__PURE__*/
777
- function (_WidgetAnnotation2) {
778
- _inherits(ButtonWidgetAnnotation, _WidgetAnnotation2);
728
+ let appearance = await this._getAppearance(evaluator, task, annotationStorage);
779
729
 
780
- function ButtonWidgetAnnotation(params) {
781
- var _this5;
730
+ if (appearance === null) {
731
+ return null;
732
+ }
782
733
 
783
- _classCallCheck(this, ButtonWidgetAnnotation);
734
+ const dict = evaluator.xref.fetchIfRef(this.ref);
784
735
 
785
- _this5 = _possibleConstructorReturn(this, _getPrototypeOf(ButtonWidgetAnnotation).call(this, params));
786
- _this5.data.checkBox = !_this5.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this5.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
787
- _this5.data.radioButton = _this5.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !_this5.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
788
- _this5.data.pushButton = _this5.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
736
+ if (!(0, _primitives.isDict)(dict)) {
737
+ return null;
738
+ }
789
739
 
790
- if (_this5.data.checkBox) {
791
- _this5._processCheckBox(params);
792
- } else if (_this5.data.radioButton) {
793
- _this5._processRadioButton(params);
794
- } else if (_this5.data.pushButton) {
795
- _this5._processPushButton(params);
796
- } else {
797
- (0, _util.warn)('Invalid field flags for button widget annotation');
740
+ const bbox = [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]];
741
+ const newRef = evaluator.xref.getNewRef();
742
+ const AP = new _primitives.Dict(evaluator.xref);
743
+ AP.set("N", newRef);
744
+ const value = annotationStorage[this.data.id];
745
+ const encrypt = evaluator.xref.encrypt;
746
+ let originalTransform = null;
747
+ let newTransform = null;
748
+
749
+ if (encrypt) {
750
+ originalTransform = encrypt.createCipherTransform(this.ref.num, this.ref.gen);
751
+ newTransform = encrypt.createCipherTransform(newRef.num, newRef.gen);
752
+ appearance = newTransform.encryptString(appearance);
798
753
  }
799
754
 
800
- return _this5;
755
+ dict.set("V", value);
756
+ dict.set("AP", AP);
757
+ dict.set("M", `D:${(0, _util.getModificationDate)()}`);
758
+ const appearanceDict = new _primitives.Dict(evaluator.xref);
759
+ appearanceDict.set("Length", appearance.length);
760
+ appearanceDict.set("Subtype", _primitives.Name.get("Form"));
761
+ appearanceDict.set("Resources", this.fieldResources);
762
+ appearanceDict.set("BBox", bbox);
763
+ const bufferOriginal = [`${this.ref.num} ${this.ref.gen} obj\n`];
764
+ (0, _writer.writeDict)(dict, bufferOriginal, originalTransform);
765
+ bufferOriginal.push("\nendobj\n");
766
+ const bufferNew = [`${newRef.num} ${newRef.gen} obj\n`];
767
+ (0, _writer.writeDict)(appearanceDict, bufferNew, newTransform);
768
+ bufferNew.push(" stream\n");
769
+ bufferNew.push(appearance);
770
+ bufferNew.push("\nendstream\nendobj\n");
771
+ return [{
772
+ ref: this.ref,
773
+ data: bufferOriginal.join("")
774
+ }, {
775
+ ref: newRef,
776
+ data: bufferNew.join("")
777
+ }];
801
778
  }
802
779
 
803
- _createClass(ButtonWidgetAnnotation, [{
804
- key: "_processCheckBox",
805
- value: function _processCheckBox(params) {
806
- if ((0, _primitives.isName)(this.data.fieldValue)) {
807
- this.data.fieldValue = this.data.fieldValue.name;
808
- }
780
+ async _getAppearance(evaluator, task, annotationStorage) {
781
+ const isPassword = this.hasFieldFlag(_util.AnnotationFieldFlag.PASSWORD);
809
782
 
810
- var customAppearance = params.dict.get('AP');
783
+ if (!annotationStorage || isPassword) {
784
+ return null;
785
+ }
811
786
 
812
- if (!(0, _primitives.isDict)(customAppearance)) {
813
- return;
814
- }
787
+ const value = annotationStorage[this.data.id];
815
788
 
816
- var exportValueOptionsDict = customAppearance.get('D');
789
+ if (value === "") {
790
+ return "";
791
+ }
817
792
 
818
- if (!(0, _primitives.isDict)(exportValueOptionsDict)) {
819
- return;
820
- }
793
+ const defaultPadding = 2;
794
+ const hPadding = defaultPadding;
795
+ const totalHeight = this.data.rect[3] - this.data.rect[1];
796
+ const totalWidth = this.data.rect[2] - this.data.rect[0];
797
+ const fontInfo = await this._getFontData(evaluator, task);
798
+ const [font, fontName] = fontInfo;
799
+ let fontSize = fontInfo[2];
800
+ fontSize = this._computeFontSize(font, fontName, fontSize, totalHeight);
801
+ let descent = font.descent;
802
+
803
+ if (isNaN(descent)) {
804
+ descent = 0;
805
+ }
821
806
 
822
- var exportValues = exportValueOptionsDict.getKeys();
823
- var hasCorrectOptionCount = exportValues.length === 2;
807
+ const vPadding = defaultPadding + Math.abs(descent) * fontSize;
808
+ const defaultAppearance = this.data.defaultAppearance;
809
+ const alignment = this.data.textAlignment;
824
810
 
825
- if (!hasCorrectOptionCount) {
826
- return;
827
- }
811
+ if (this.data.comb) {
812
+ return this._getCombAppearance(defaultAppearance, value, totalWidth, hPadding, vPadding);
813
+ }
828
814
 
829
- this.data.exportValue = exportValues[0] === 'Off' ? exportValues[1] : exportValues[0];
815
+ if (this.data.multiLine) {
816
+ return this._getMultilineAppearance(defaultAppearance, value, font, fontSize, totalWidth, totalHeight, alignment, hPadding, vPadding);
830
817
  }
831
- }, {
832
- key: "_processRadioButton",
833
- value: function _processRadioButton(params) {
834
- this.data.fieldValue = this.data.buttonValue = null;
835
- var fieldParent = params.dict.get('Parent');
836
818
 
837
- if ((0, _primitives.isDict)(fieldParent) && fieldParent.has('V')) {
838
- var fieldParentValue = fieldParent.get('V');
819
+ if (alignment === 0 || alignment > 2) {
820
+ return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 ${hPadding} ${vPadding} Tm (${(0, _util.escapeString)(value)}) Tj` + " ET Q EMC";
821
+ }
839
822
 
840
- if ((0, _primitives.isName)(fieldParentValue)) {
841
- this.data.fieldValue = fieldParentValue.name;
842
- }
843
- }
823
+ const renderedText = this._renderText(value, font, fontSize, totalWidth, alignment, hPadding, vPadding);
824
+
825
+ return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 0 0 Tm ${renderedText}` + " ET Q EMC";
826
+ }
844
827
 
845
- var appearanceStates = params.dict.get('AP');
828
+ async _getFontData(evaluator, task) {
829
+ const operatorList = new _operator_list.OperatorList();
830
+ const initialState = {
831
+ fontSize: 0,
832
+ font: null,
833
+ fontName: null,
846
834
 
847
- if (!(0, _primitives.isDict)(appearanceStates)) {
848
- return;
835
+ clone() {
836
+ return this;
849
837
  }
850
838
 
851
- var normalAppearanceState = appearanceStates.get('N');
839
+ };
840
+ await evaluator.getOperatorList({
841
+ stream: new _stream.StringStream(this.data.defaultAppearance),
842
+ task,
843
+ resources: this.fieldResources,
844
+ operatorList,
845
+ initialState
846
+ });
847
+ return [initialState.font, initialState.fontName, initialState.fontSize];
848
+ }
849
+
850
+ _computeFontSize(font, fontName, fontSize, height) {
851
+ if (fontSize === null || fontSize === 0) {
852
+ const em = font.charsToGlyphs("M", true)[0].width / 1000;
853
+ const capHeight = 0.7 * em;
854
+ fontSize = Math.max(1, Math.floor(height / (1.5 * capHeight)));
855
+ let fontRegex = new RegExp(`/${fontName}\\s+[0-9\.]+\\s+Tf`);
852
856
 
853
- if (!(0, _primitives.isDict)(normalAppearanceState)) {
854
- return;
857
+ if (this.data.defaultAppearance.search(fontRegex) === -1) {
858
+ fontRegex = new RegExp(`/${fontName}\\s+Tf`);
855
859
  }
856
860
 
857
- var keys = normalAppearanceState.getKeys();
861
+ this.data.defaultAppearance = this.data.defaultAppearance.replace(fontRegex, `/${fontName} ${fontSize} Tf`);
862
+ }
858
863
 
859
- for (var i = 0, ii = keys.length; i < ii; i++) {
860
- if (keys[i] !== 'Off') {
861
- this.data.buttonValue = keys[i];
862
- break;
863
- }
864
- }
864
+ return fontSize;
865
+ }
866
+
867
+ _renderText(text, font, fontSize, totalWidth, alignment, hPadding, vPadding) {
868
+ const glyphs = font.charsToGlyphs(text);
869
+ const scale = fontSize / 1000;
870
+ let width = 0;
871
+
872
+ for (const glyph of glyphs) {
873
+ width += glyph.width * scale;
865
874
  }
866
- }, {
867
- key: "_processPushButton",
868
- value: function _processPushButton(params) {
869
- if (!params.dict.has('A')) {
870
- (0, _util.warn)('Push buttons without action dictionaries are not supported');
871
- return;
872
- }
873
875
 
874
- _obj.Catalog.parseDestDictionary({
875
- destDict: params.dict,
876
- resultObj: this.data,
877
- docBaseUrl: params.pdfManager.docBaseUrl
878
- });
876
+ let shift;
877
+
878
+ if (alignment === 1) {
879
+ shift = (totalWidth - width) / 2;
880
+ } else if (alignment === 2) {
881
+ shift = totalWidth - width - hPadding;
882
+ } else {
883
+ shift = hPadding;
879
884
  }
880
- }]);
881
885
 
882
- return ButtonWidgetAnnotation;
883
- }(WidgetAnnotation);
886
+ shift = shift.toFixed(2);
887
+ vPadding = vPadding.toFixed(2);
888
+ return `${shift} ${vPadding} Td (${(0, _util.escapeString)(text)}) Tj`;
889
+ }
884
890
 
885
- var ChoiceWidgetAnnotation =
886
- /*#__PURE__*/
887
- function (_WidgetAnnotation3) {
888
- _inherits(ChoiceWidgetAnnotation, _WidgetAnnotation3);
891
+ }
889
892
 
890
- function ChoiceWidgetAnnotation(params) {
891
- var _this6;
893
+ class TextWidgetAnnotation extends WidgetAnnotation {
894
+ constructor(params) {
895
+ super(params);
896
+ this._hasText = true;
897
+ const dict = params.dict;
892
898
 
893
- _classCallCheck(this, ChoiceWidgetAnnotation);
899
+ if (!(0, _util.isString)(this.data.fieldValue)) {
900
+ this.data.fieldValue = "";
901
+ }
894
902
 
895
- _this6 = _possibleConstructorReturn(this, _getPrototypeOf(ChoiceWidgetAnnotation).call(this, params));
896
- _this6.data.options = [];
897
- var options = (0, _core_utils.getInheritableProperty)({
898
- dict: params.dict,
899
- key: 'Opt'
903
+ let alignment = (0, _core_utils.getInheritableProperty)({
904
+ dict,
905
+ key: "Q"
900
906
  });
901
907
 
902
- if (Array.isArray(options)) {
903
- var xref = params.xref;
904
-
905
- for (var i = 0, ii = options.length; i < ii; i++) {
906
- var option = xref.fetchIfRef(options[i]);
907
- var isOptionArray = Array.isArray(option);
908
- _this6.data.options[i] = {
909
- exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
910
- displayValue: (0, _util.stringToPDFString)(isOptionArray ? xref.fetchIfRef(option[1]) : option)
911
- };
912
- }
908
+ if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
909
+ alignment = null;
913
910
  }
914
911
 
915
- if (!Array.isArray(_this6.data.fieldValue)) {
916
- _this6.data.fieldValue = [_this6.data.fieldValue];
912
+ this.data.textAlignment = alignment;
913
+ let maximumLength = (0, _core_utils.getInheritableProperty)({
914
+ dict,
915
+ key: "MaxLen"
916
+ });
917
+
918
+ if (!Number.isInteger(maximumLength) || maximumLength < 0) {
919
+ maximumLength = null;
917
920
  }
918
921
 
919
- _this6.data.combo = _this6.hasFieldFlag(_util.AnnotationFieldFlag.COMBO);
920
- _this6.data.multiSelect = _this6.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT);
921
- return _this6;
922
+ this.data.maxLen = maximumLength;
923
+ this.data.multiLine = this.hasFieldFlag(_util.AnnotationFieldFlag.MULTILINE);
924
+ 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;
922
925
  }
923
926
 
924
- return ChoiceWidgetAnnotation;
925
- }(WidgetAnnotation);
927
+ _getCombAppearance(defaultAppearance, text, width, hPadding, vPadding) {
928
+ const combWidth = (width / this.data.maxLen).toFixed(2);
929
+ const buf = [];
926
930
 
927
- var TextAnnotation =
928
- /*#__PURE__*/
929
- function (_MarkupAnnotation) {
930
- _inherits(TextAnnotation, _MarkupAnnotation);
931
+ for (const character of text) {
932
+ buf.push(`(${(0, _util.escapeString)(character)}) Tj`);
933
+ }
931
934
 
932
- function TextAnnotation(parameters) {
933
- var _this7;
935
+ const renderedComb = buf.join(` ${combWidth} 0 Td `);
936
+ return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 ${hPadding} ${vPadding} Tm ${renderedComb}` + " ET Q EMC";
937
+ }
934
938
 
935
- _classCallCheck(this, TextAnnotation);
939
+ _getMultilineAppearance(defaultAppearance, text, font, fontSize, width, height, alignment, hPadding, vPadding) {
940
+ const lines = text.split(/\r\n|\r|\n/);
941
+ const buf = [];
942
+ const totalWidth = width - 2 * hPadding;
936
943
 
937
- var DEFAULT_ICON_SIZE = 22;
938
- _this7 = _possibleConstructorReturn(this, _getPrototypeOf(TextAnnotation).call(this, parameters));
939
- _this7.data.annotationType = _util.AnnotationType.TEXT;
944
+ for (const line of lines) {
945
+ const chunks = this._splitLine(line, font, fontSize, totalWidth);
940
946
 
941
- if (_this7.data.hasAppearance) {
942
- _this7.data.name = 'NoIcon';
943
- } else {
944
- _this7.data.rect[1] = _this7.data.rect[3] - DEFAULT_ICON_SIZE;
945
- _this7.data.rect[2] = _this7.data.rect[0] + DEFAULT_ICON_SIZE;
946
- _this7.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
947
+ for (const chunk of chunks) {
948
+ const padding = buf.length === 0 ? hPadding : 0;
949
+ buf.push(this._renderText(chunk, font, fontSize, width, alignment, padding, -fontSize));
950
+ }
947
951
  }
948
952
 
949
- return _this7;
953
+ const renderedText = buf.join("\n");
954
+ return "/Tx BMC q BT " + defaultAppearance + ` 1 0 0 1 0 ${height} Tm ${renderedText}` + " ET Q EMC";
950
955
  }
951
956
 
952
- return TextAnnotation;
953
- }(MarkupAnnotation);
954
-
955
- var LinkAnnotation =
956
- /*#__PURE__*/
957
- function (_Annotation3) {
958
- _inherits(LinkAnnotation, _Annotation3);
957
+ _splitLine(line, font, fontSize, width) {
958
+ if (line.length <= 1) {
959
+ return [line];
960
+ }
959
961
 
960
- function LinkAnnotation(params) {
961
- var _this8;
962
+ const scale = fontSize / 1000;
963
+ const whitespace = font.charsToGlyphs(" ", true)[0].width * scale;
964
+ const chunks = [];
965
+ let lastSpacePos = -1,
966
+ startChunk = 0,
967
+ currentWidth = 0;
968
+
969
+ for (let i = 0, ii = line.length; i < ii; i++) {
970
+ const character = line.charAt(i);
971
+
972
+ if (character === " ") {
973
+ if (currentWidth + whitespace > width) {
974
+ chunks.push(line.substring(startChunk, i));
975
+ startChunk = i;
976
+ currentWidth = whitespace;
977
+ lastSpacePos = -1;
978
+ } else {
979
+ currentWidth += whitespace;
980
+ lastSpacePos = i;
981
+ }
982
+ } else {
983
+ const charWidth = font.charsToGlyphs(character, false)[0].width * scale;
984
+
985
+ if (currentWidth + charWidth > width) {
986
+ if (lastSpacePos !== -1) {
987
+ chunks.push(line.substring(startChunk, lastSpacePos + 1));
988
+ startChunk = i = lastSpacePos + 1;
989
+ lastSpacePos = -1;
990
+ currentWidth = 0;
991
+ } else {
992
+ chunks.push(line.substring(startChunk, i));
993
+ startChunk = i;
994
+ currentWidth = charWidth;
995
+ }
996
+ } else {
997
+ currentWidth += charWidth;
998
+ }
999
+ }
1000
+ }
962
1001
 
963
- _classCallCheck(this, LinkAnnotation);
1002
+ if (startChunk < line.length) {
1003
+ chunks.push(line.substring(startChunk, line.length));
1004
+ }
964
1005
 
965
- _this8 = _possibleConstructorReturn(this, _getPrototypeOf(LinkAnnotation).call(this, params));
966
- _this8.data.annotationType = _util.AnnotationType.LINK;
1006
+ return chunks;
1007
+ }
967
1008
 
968
- _obj.Catalog.parseDestDictionary({
969
- destDict: params.dict,
970
- resultObj: _this8.data,
971
- docBaseUrl: params.pdfManager.docBaseUrl
972
- });
1009
+ }
973
1010
 
974
- return _this8;
1011
+ class ButtonWidgetAnnotation extends WidgetAnnotation {
1012
+ constructor(params) {
1013
+ super(params);
1014
+ this.checkedAppearance = null;
1015
+ this.uncheckedAppearance = null;
1016
+ this.data.checkBox = !this.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
1017
+ this.data.radioButton = this.hasFieldFlag(_util.AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
1018
+ this.data.pushButton = this.hasFieldFlag(_util.AnnotationFieldFlag.PUSHBUTTON);
1019
+
1020
+ if (this.data.checkBox) {
1021
+ this._processCheckBox(params);
1022
+ } else if (this.data.radioButton) {
1023
+ this._processRadioButton(params);
1024
+ } else if (this.data.pushButton) {
1025
+ this._processPushButton(params);
1026
+ } else {
1027
+ (0, _util.warn)("Invalid field flags for button widget annotation");
1028
+ }
975
1029
  }
976
1030
 
977
- return LinkAnnotation;
978
- }(Annotation);
1031
+ getOperatorList(evaluator, task, renderForms, annotationStorage) {
1032
+ if (this.data.pushButton) {
1033
+ return super.getOperatorList(evaluator, task, false, annotationStorage);
1034
+ }
979
1035
 
980
- var PopupAnnotation =
981
- /*#__PURE__*/
982
- function (_Annotation4) {
983
- _inherits(PopupAnnotation, _Annotation4);
1036
+ if (annotationStorage) {
1037
+ const value = annotationStorage[this.data.id] || false;
1038
+ let appearance;
984
1039
 
985
- function PopupAnnotation(parameters) {
986
- var _this9;
1040
+ if (value) {
1041
+ appearance = this.checkedAppearance;
1042
+ } else {
1043
+ appearance = this.uncheckedAppearance;
1044
+ }
987
1045
 
988
- _classCallCheck(this, PopupAnnotation);
1046
+ if (appearance) {
1047
+ const savedAppearance = this.appearance;
1048
+ this.appearance = appearance;
1049
+ const operatorList = super.getOperatorList(evaluator, task, renderForms, annotationStorage);
1050
+ this.appearance = savedAppearance;
1051
+ return operatorList;
1052
+ }
989
1053
 
990
- _this9 = _possibleConstructorReturn(this, _getPrototypeOf(PopupAnnotation).call(this, parameters));
991
- _this9.data.annotationType = _util.AnnotationType.POPUP;
992
- var dict = parameters.dict;
993
- var parentItem = dict.get('Parent');
1054
+ return Promise.resolve(new _operator_list.OperatorList());
1055
+ }
994
1056
 
995
- if (!parentItem) {
996
- (0, _util.warn)('Popup annotation has a missing or invalid parent annotation.');
997
- return _possibleConstructorReturn(_this9);
1057
+ return super.getOperatorList(evaluator, task, renderForms, annotationStorage);
1058
+ }
1059
+
1060
+ async save(evaluator, task, annotationStorage) {
1061
+ if (this.data.checkBox) {
1062
+ return this._saveCheckbox(evaluator, task, annotationStorage);
1063
+ }
1064
+
1065
+ if (this.data.radioButton) {
1066
+ return this._saveRadioButton(evaluator, task, annotationStorage);
998
1067
  }
999
1068
 
1000
- var parentSubtype = parentItem.get('Subtype');
1001
- _this9.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null;
1002
- _this9.data.parentId = dict.getRaw('Parent').toString();
1003
- _this9.data.title = (0, _util.stringToPDFString)(parentItem.get('T') || '');
1004
- _this9.data.contents = (0, _util.stringToPDFString)(parentItem.get('Contents') || '');
1069
+ return super.save(evaluator, task, annotationStorage);
1070
+ }
1005
1071
 
1006
- if (!parentItem.has('M')) {
1007
- _this9.data.modificationDate = null;
1008
- } else {
1009
- _this9.setModificationDate(parentItem.get('M'));
1072
+ async _saveCheckbox(evaluator, task, annotationStorage) {
1073
+ const defaultValue = this.data.fieldValue && this.data.fieldValue !== "Off";
1074
+ const value = annotationStorage[this.data.id];
1010
1075
 
1011
- _this9.data.modificationDate = _this9.modificationDate;
1076
+ if (defaultValue === value) {
1077
+ return null;
1012
1078
  }
1013
1079
 
1014
- if (!parentItem.has('C')) {
1015
- _this9.data.color = null;
1016
- } else {
1017
- _this9.setColor(parentItem.getArray('C'));
1080
+ const dict = evaluator.xref.fetchIfRef(this.ref);
1018
1081
 
1019
- _this9.data.color = _this9.color;
1082
+ if (!(0, _primitives.isDict)(dict)) {
1083
+ return null;
1020
1084
  }
1021
1085
 
1022
- if (!_this9.viewable) {
1023
- var parentFlags = parentItem.get('F');
1086
+ const name = _primitives.Name.get(value ? this.data.exportValue : "Off");
1024
1087
 
1025
- if (_this9._isViewable(parentFlags)) {
1026
- _this9.setFlags(parentFlags);
1027
- }
1088
+ dict.set("V", name);
1089
+ dict.set("AS", name);
1090
+ dict.set("M", `D:${(0, _util.getModificationDate)()}`);
1091
+ const encrypt = evaluator.xref.encrypt;
1092
+ let originalTransform = null;
1093
+
1094
+ if (encrypt) {
1095
+ originalTransform = encrypt.createCipherTransform(this.ref.num, this.ref.gen);
1028
1096
  }
1029
1097
 
1030
- return _this9;
1098
+ const buffer = [`${this.ref.num} ${this.ref.gen} obj\n`];
1099
+ (0, _writer.writeDict)(dict, buffer, originalTransform);
1100
+ buffer.push("\nendobj\n");
1101
+ return [{
1102
+ ref: this.ref,
1103
+ data: buffer.join("")
1104
+ }];
1031
1105
  }
1032
1106
 
1033
- return PopupAnnotation;
1034
- }(Annotation);
1107
+ async _saveRadioButton(evaluator, task, annotationStorage) {
1108
+ const defaultValue = this.data.fieldValue === this.data.buttonValue;
1109
+ const value = annotationStorage[this.data.id];
1035
1110
 
1036
- var FreeTextAnnotation =
1037
- /*#__PURE__*/
1038
- function (_MarkupAnnotation2) {
1039
- _inherits(FreeTextAnnotation, _MarkupAnnotation2);
1111
+ if (defaultValue === value) {
1112
+ return null;
1113
+ }
1040
1114
 
1041
- function FreeTextAnnotation(parameters) {
1042
- var _this10;
1115
+ const dict = evaluator.xref.fetchIfRef(this.ref);
1043
1116
 
1044
- _classCallCheck(this, FreeTextAnnotation);
1117
+ if (!(0, _primitives.isDict)(dict)) {
1118
+ return null;
1119
+ }
1045
1120
 
1046
- _this10 = _possibleConstructorReturn(this, _getPrototypeOf(FreeTextAnnotation).call(this, parameters));
1047
- _this10.data.annotationType = _util.AnnotationType.FREETEXT;
1048
- return _this10;
1049
- }
1121
+ const name = _primitives.Name.get(value ? this.data.buttonValue : "Off");
1050
1122
 
1051
- return FreeTextAnnotation;
1052
- }(MarkupAnnotation);
1123
+ let parentBuffer = null;
1124
+ const encrypt = evaluator.xref.encrypt;
1053
1125
 
1054
- var LineAnnotation =
1055
- /*#__PURE__*/
1056
- function (_MarkupAnnotation3) {
1057
- _inherits(LineAnnotation, _MarkupAnnotation3);
1126
+ if (value) {
1127
+ if ((0, _primitives.isRef)(this.parent)) {
1128
+ const parent = evaluator.xref.fetch(this.parent);
1129
+ let parentTransform = null;
1058
1130
 
1059
- function LineAnnotation(parameters) {
1060
- var _this11;
1131
+ if (encrypt) {
1132
+ parentTransform = encrypt.createCipherTransform(this.parent.num, this.parent.gen);
1133
+ }
1061
1134
 
1062
- _classCallCheck(this, LineAnnotation);
1135
+ parent.set("V", name);
1136
+ parentBuffer = [`${this.parent.num} ${this.parent.gen} obj\n`];
1137
+ (0, _writer.writeDict)(parent, parentBuffer, parentTransform);
1138
+ parentBuffer.push("\nendobj\n");
1139
+ } else if ((0, _primitives.isDict)(this.parent)) {
1140
+ this.parent.set("V", name);
1141
+ }
1142
+ }
1063
1143
 
1064
- _this11 = _possibleConstructorReturn(this, _getPrototypeOf(LineAnnotation).call(this, parameters));
1065
- _this11.data.annotationType = _util.AnnotationType.LINE;
1066
- var dict = parameters.dict;
1067
- _this11.data.lineCoordinates = _util.Util.normalizeRect(dict.getArray('L'));
1068
- return _this11;
1069
- }
1144
+ dict.set("AS", name);
1145
+ dict.set("M", `D:${(0, _util.getModificationDate)()}`);
1146
+ let originalTransform = null;
1070
1147
 
1071
- return LineAnnotation;
1072
- }(MarkupAnnotation);
1148
+ if (encrypt) {
1149
+ originalTransform = encrypt.createCipherTransform(this.ref.num, this.ref.gen);
1150
+ }
1073
1151
 
1074
- var SquareAnnotation =
1075
- /*#__PURE__*/
1076
- function (_MarkupAnnotation4) {
1077
- _inherits(SquareAnnotation, _MarkupAnnotation4);
1152
+ const buffer = [`${this.ref.num} ${this.ref.gen} obj\n`];
1153
+ (0, _writer.writeDict)(dict, buffer, originalTransform);
1154
+ buffer.push("\nendobj\n");
1155
+ const newRefs = [{
1156
+ ref: this.ref,
1157
+ data: buffer.join("")
1158
+ }];
1159
+
1160
+ if (parentBuffer !== null) {
1161
+ newRefs.push({
1162
+ ref: this.parent,
1163
+ data: parentBuffer.join("")
1164
+ });
1165
+ }
1078
1166
 
1079
- function SquareAnnotation(parameters) {
1080
- var _this12;
1167
+ return newRefs;
1168
+ }
1081
1169
 
1082
- _classCallCheck(this, SquareAnnotation);
1170
+ _processCheckBox(params) {
1171
+ const customAppearance = params.dict.get("AP");
1083
1172
 
1084
- _this12 = _possibleConstructorReturn(this, _getPrototypeOf(SquareAnnotation).call(this, parameters));
1085
- _this12.data.annotationType = _util.AnnotationType.SQUARE;
1086
- return _this12;
1087
- }
1173
+ if (!(0, _primitives.isDict)(customAppearance)) {
1174
+ return;
1175
+ }
1088
1176
 
1089
- return SquareAnnotation;
1090
- }(MarkupAnnotation);
1177
+ const normalAppearance = customAppearance.get("N");
1091
1178
 
1092
- var CircleAnnotation =
1093
- /*#__PURE__*/
1094
- function (_MarkupAnnotation5) {
1095
- _inherits(CircleAnnotation, _MarkupAnnotation5);
1179
+ if (!(0, _primitives.isDict)(normalAppearance)) {
1180
+ return;
1181
+ }
1096
1182
 
1097
- function CircleAnnotation(parameters) {
1098
- var _this13;
1183
+ const exportValues = normalAppearance.getKeys();
1099
1184
 
1100
- _classCallCheck(this, CircleAnnotation);
1185
+ if (!exportValues.includes("Off")) {
1186
+ exportValues.push("Off");
1187
+ }
1101
1188
 
1102
- _this13 = _possibleConstructorReturn(this, _getPrototypeOf(CircleAnnotation).call(this, parameters));
1103
- _this13.data.annotationType = _util.AnnotationType.CIRCLE;
1104
- return _this13;
1189
+ if (exportValues.length !== 2) {
1190
+ return;
1191
+ }
1192
+
1193
+ this.data.exportValue = exportValues[0] === "Off" ? exportValues[1] : exportValues[0];
1194
+ this.checkedAppearance = normalAppearance.get(this.data.exportValue);
1195
+ this.uncheckedAppearance = normalAppearance.get("Off") || null;
1105
1196
  }
1106
1197
 
1107
- return CircleAnnotation;
1108
- }(MarkupAnnotation);
1198
+ _processRadioButton(params) {
1199
+ this.data.fieldValue = this.data.buttonValue = null;
1200
+ const fieldParent = params.dict.get("Parent");
1109
1201
 
1110
- var PolylineAnnotation =
1111
- /*#__PURE__*/
1112
- function (_MarkupAnnotation6) {
1113
- _inherits(PolylineAnnotation, _MarkupAnnotation6);
1202
+ if ((0, _primitives.isDict)(fieldParent) && fieldParent.has("V")) {
1203
+ const fieldParentValue = fieldParent.get("V");
1114
1204
 
1115
- function PolylineAnnotation(parameters) {
1116
- var _this14;
1205
+ if ((0, _primitives.isName)(fieldParentValue)) {
1206
+ this.parent = params.dict.getRaw("Parent");
1207
+ this.data.fieldValue = this._decodeFormValue(fieldParentValue);
1208
+ }
1209
+ }
1117
1210
 
1118
- _classCallCheck(this, PolylineAnnotation);
1211
+ const appearanceStates = params.dict.get("AP");
1119
1212
 
1120
- _this14 = _possibleConstructorReturn(this, _getPrototypeOf(PolylineAnnotation).call(this, parameters));
1121
- _this14.data.annotationType = _util.AnnotationType.POLYLINE;
1122
- var dict = parameters.dict;
1123
- var rawVertices = dict.getArray('Vertices');
1124
- _this14.data.vertices = [];
1213
+ if (!(0, _primitives.isDict)(appearanceStates)) {
1214
+ return;
1215
+ }
1125
1216
 
1126
- for (var i = 0, ii = rawVertices.length; i < ii; i += 2) {
1127
- _this14.data.vertices.push({
1128
- x: rawVertices[i],
1129
- y: rawVertices[i + 1]
1130
- });
1217
+ const normalAppearance = appearanceStates.get("N");
1218
+
1219
+ if (!(0, _primitives.isDict)(normalAppearance)) {
1220
+ return;
1221
+ }
1222
+
1223
+ for (const key of normalAppearance.getKeys()) {
1224
+ if (key !== "Off") {
1225
+ this.data.buttonValue = key;
1226
+ break;
1227
+ }
1131
1228
  }
1132
1229
 
1133
- return _this14;
1230
+ this.checkedAppearance = normalAppearance.get(this.data.buttonValue);
1231
+ this.uncheckedAppearance = normalAppearance.get("Off") || null;
1134
1232
  }
1135
1233
 
1136
- return PolylineAnnotation;
1137
- }(MarkupAnnotation);
1234
+ _processPushButton(params) {
1235
+ if (!params.dict.has("A")) {
1236
+ (0, _util.warn)("Push buttons without action dictionaries are not supported");
1237
+ return;
1238
+ }
1138
1239
 
1139
- var PolygonAnnotation =
1140
- /*#__PURE__*/
1141
- function (_PolylineAnnotation) {
1142
- _inherits(PolygonAnnotation, _PolylineAnnotation);
1240
+ _obj.Catalog.parseDestDictionary({
1241
+ destDict: params.dict,
1242
+ resultObj: this.data,
1243
+ docBaseUrl: params.pdfManager.docBaseUrl
1244
+ });
1245
+ }
1143
1246
 
1144
- function PolygonAnnotation(parameters) {
1145
- var _this15;
1247
+ }
1146
1248
 
1147
- _classCallCheck(this, PolygonAnnotation);
1249
+ class ChoiceWidgetAnnotation extends WidgetAnnotation {
1250
+ constructor(params) {
1251
+ super(params);
1252
+ this.data.options = [];
1253
+ const options = (0, _core_utils.getInheritableProperty)({
1254
+ dict: params.dict,
1255
+ key: "Opt"
1256
+ });
1148
1257
 
1149
- _this15 = _possibleConstructorReturn(this, _getPrototypeOf(PolygonAnnotation).call(this, parameters));
1150
- _this15.data.annotationType = _util.AnnotationType.POLYGON;
1151
- return _this15;
1258
+ if (Array.isArray(options)) {
1259
+ const xref = params.xref;
1260
+
1261
+ for (let i = 0, ii = options.length; i < ii; i++) {
1262
+ const option = xref.fetchIfRef(options[i]);
1263
+ const isOptionArray = Array.isArray(option);
1264
+ this.data.options[i] = {
1265
+ exportValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[0]) : option),
1266
+ displayValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[1]) : option)
1267
+ };
1268
+ }
1269
+ }
1270
+
1271
+ if ((0, _util.isString)(this.data.fieldValue)) {
1272
+ this.data.fieldValue = [this.data.fieldValue];
1273
+ } else if (!this.data.fieldValue) {
1274
+ this.data.fieldValue = [];
1275
+ }
1276
+
1277
+ this.data.combo = this.hasFieldFlag(_util.AnnotationFieldFlag.COMBO);
1278
+ this.data.multiSelect = this.hasFieldFlag(_util.AnnotationFieldFlag.MULTISELECT);
1279
+ this._hasText = true;
1152
1280
  }
1153
1281
 
1154
- return PolygonAnnotation;
1155
- }(PolylineAnnotation);
1282
+ }
1283
+
1284
+ class TextAnnotation extends MarkupAnnotation {
1285
+ constructor(parameters) {
1286
+ const DEFAULT_ICON_SIZE = 22;
1287
+ super(parameters);
1288
+ const dict = parameters.dict;
1289
+ this.data.annotationType = _util.AnnotationType.TEXT;
1290
+
1291
+ if (this.data.hasAppearance) {
1292
+ this.data.name = "NoIcon";
1293
+ } else {
1294
+ this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
1295
+ this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
1296
+ this.data.name = dict.has("Name") ? dict.get("Name").name : "Note";
1297
+ }
1298
+
1299
+ if (dict.has("State")) {
1300
+ this.data.state = dict.get("State") || null;
1301
+ this.data.stateModel = dict.get("StateModel") || null;
1302
+ } else {
1303
+ this.data.state = null;
1304
+ this.data.stateModel = null;
1305
+ }
1306
+ }
1156
1307
 
1157
- var CaretAnnotation =
1158
- /*#__PURE__*/
1159
- function (_MarkupAnnotation7) {
1160
- _inherits(CaretAnnotation, _MarkupAnnotation7);
1308
+ }
1161
1309
 
1162
- function CaretAnnotation(parameters) {
1163
- var _this16;
1310
+ class LinkAnnotation extends Annotation {
1311
+ constructor(params) {
1312
+ super(params);
1313
+ this.data.annotationType = _util.AnnotationType.LINK;
1314
+ const quadPoints = getQuadPoints(params.dict, this.rectangle);
1164
1315
 
1165
- _classCallCheck(this, CaretAnnotation);
1316
+ if (quadPoints) {
1317
+ this.data.quadPoints = quadPoints;
1318
+ }
1166
1319
 
1167
- _this16 = _possibleConstructorReturn(this, _getPrototypeOf(CaretAnnotation).call(this, parameters));
1168
- _this16.data.annotationType = _util.AnnotationType.CARET;
1169
- return _this16;
1320
+ _obj.Catalog.parseDestDictionary({
1321
+ destDict: params.dict,
1322
+ resultObj: this.data,
1323
+ docBaseUrl: params.pdfManager.docBaseUrl
1324
+ });
1170
1325
  }
1171
1326
 
1172
- return CaretAnnotation;
1173
- }(MarkupAnnotation);
1327
+ }
1328
+
1329
+ class PopupAnnotation extends Annotation {
1330
+ constructor(parameters) {
1331
+ super(parameters);
1332
+ this.data.annotationType = _util.AnnotationType.POPUP;
1333
+ let parentItem = parameters.dict.get("Parent");
1334
+
1335
+ if (!parentItem) {
1336
+ (0, _util.warn)("Popup annotation has a missing or invalid parent annotation.");
1337
+ return;
1338
+ }
1174
1339
 
1175
- var InkAnnotation =
1176
- /*#__PURE__*/
1177
- function (_MarkupAnnotation8) {
1178
- _inherits(InkAnnotation, _MarkupAnnotation8);
1340
+ const parentSubtype = parentItem.get("Subtype");
1341
+ this.data.parentType = (0, _primitives.isName)(parentSubtype) ? parentSubtype.name : null;
1342
+ const rawParent = parameters.dict.getRaw("Parent");
1343
+ this.data.parentId = (0, _primitives.isRef)(rawParent) ? rawParent.toString() : null;
1344
+ const rt = parentItem.get("RT");
1179
1345
 
1180
- function InkAnnotation(parameters) {
1181
- var _this17;
1346
+ if ((0, _primitives.isName)(rt, _util.AnnotationReplyType.GROUP)) {
1347
+ parentItem = parentItem.get("IRT");
1348
+ }
1182
1349
 
1183
- _classCallCheck(this, InkAnnotation);
1350
+ if (!parentItem.has("M")) {
1351
+ this.data.modificationDate = null;
1352
+ } else {
1353
+ this.setModificationDate(parentItem.get("M"));
1354
+ this.data.modificationDate = this.modificationDate;
1355
+ }
1184
1356
 
1185
- _this17 = _possibleConstructorReturn(this, _getPrototypeOf(InkAnnotation).call(this, parameters));
1186
- _this17.data.annotationType = _util.AnnotationType.INK;
1187
- var dict = parameters.dict;
1188
- var xref = parameters.xref;
1189
- var originalInkLists = dict.getArray('InkList');
1190
- _this17.data.inkLists = [];
1357
+ if (!parentItem.has("C")) {
1358
+ this.data.color = null;
1359
+ } else {
1360
+ this.setColor(parentItem.getArray("C"));
1361
+ this.data.color = this.color;
1362
+ }
1191
1363
 
1192
- for (var i = 0, ii = originalInkLists.length; i < ii; ++i) {
1193
- _this17.data.inkLists.push([]);
1364
+ if (!this.viewable) {
1365
+ const parentFlags = parentItem.get("F");
1194
1366
 
1195
- for (var j = 0, jj = originalInkLists[i].length; j < jj; j += 2) {
1196
- _this17.data.inkLists[i].push({
1197
- x: xref.fetchIfRef(originalInkLists[i][j]),
1198
- y: xref.fetchIfRef(originalInkLists[i][j + 1])
1199
- });
1367
+ if (this._isViewable(parentFlags)) {
1368
+ this.setFlags(parentFlags);
1200
1369
  }
1201
1370
  }
1202
1371
 
1203
- return _this17;
1372
+ this.data.title = (0, _util.stringToPDFString)(parentItem.get("T") || "");
1373
+ this.data.contents = (0, _util.stringToPDFString)(parentItem.get("Contents") || "");
1204
1374
  }
1205
1375
 
1206
- return InkAnnotation;
1207
- }(MarkupAnnotation);
1376
+ }
1377
+
1378
+ class FreeTextAnnotation extends MarkupAnnotation {
1379
+ constructor(parameters) {
1380
+ super(parameters);
1381
+ this.data.annotationType = _util.AnnotationType.FREETEXT;
1382
+ }
1208
1383
 
1209
- var HighlightAnnotation =
1210
- /*#__PURE__*/
1211
- function (_MarkupAnnotation9) {
1212
- _inherits(HighlightAnnotation, _MarkupAnnotation9);
1384
+ }
1213
1385
 
1214
- function HighlightAnnotation(parameters) {
1215
- var _this18;
1386
+ class LineAnnotation extends MarkupAnnotation {
1387
+ constructor(parameters) {
1388
+ super(parameters);
1389
+ this.data.annotationType = _util.AnnotationType.LINE;
1390
+ this.data.lineCoordinates = _util.Util.normalizeRect(parameters.dict.getArray("L"));
1391
+ }
1216
1392
 
1217
- _classCallCheck(this, HighlightAnnotation);
1393
+ }
1218
1394
 
1219
- _this18 = _possibleConstructorReturn(this, _getPrototypeOf(HighlightAnnotation).call(this, parameters));
1220
- _this18.data.annotationType = _util.AnnotationType.HIGHLIGHT;
1221
- return _this18;
1395
+ class SquareAnnotation extends MarkupAnnotation {
1396
+ constructor(parameters) {
1397
+ super(parameters);
1398
+ this.data.annotationType = _util.AnnotationType.SQUARE;
1222
1399
  }
1223
1400
 
1224
- return HighlightAnnotation;
1225
- }(MarkupAnnotation);
1401
+ }
1226
1402
 
1227
- var UnderlineAnnotation =
1228
- /*#__PURE__*/
1229
- function (_MarkupAnnotation10) {
1230
- _inherits(UnderlineAnnotation, _MarkupAnnotation10);
1403
+ class CircleAnnotation extends MarkupAnnotation {
1404
+ constructor(parameters) {
1405
+ super(parameters);
1406
+ this.data.annotationType = _util.AnnotationType.CIRCLE;
1407
+ }
1231
1408
 
1232
- function UnderlineAnnotation(parameters) {
1233
- var _this19;
1409
+ }
1234
1410
 
1235
- _classCallCheck(this, UnderlineAnnotation);
1411
+ class PolylineAnnotation extends MarkupAnnotation {
1412
+ constructor(parameters) {
1413
+ super(parameters);
1414
+ this.data.annotationType = _util.AnnotationType.POLYLINE;
1415
+ const rawVertices = parameters.dict.getArray("Vertices");
1416
+ this.data.vertices = [];
1236
1417
 
1237
- _this19 = _possibleConstructorReturn(this, _getPrototypeOf(UnderlineAnnotation).call(this, parameters));
1238
- _this19.data.annotationType = _util.AnnotationType.UNDERLINE;
1239
- return _this19;
1418
+ for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
1419
+ this.data.vertices.push({
1420
+ x: rawVertices[i],
1421
+ y: rawVertices[i + 1]
1422
+ });
1423
+ }
1240
1424
  }
1241
1425
 
1242
- return UnderlineAnnotation;
1243
- }(MarkupAnnotation);
1244
-
1245
- var SquigglyAnnotation =
1246
- /*#__PURE__*/
1247
- function (_MarkupAnnotation11) {
1248
- _inherits(SquigglyAnnotation, _MarkupAnnotation11);
1426
+ }
1249
1427
 
1250
- function SquigglyAnnotation(parameters) {
1251
- var _this20;
1428
+ class PolygonAnnotation extends PolylineAnnotation {
1429
+ constructor(parameters) {
1430
+ super(parameters);
1431
+ this.data.annotationType = _util.AnnotationType.POLYGON;
1432
+ }
1252
1433
 
1253
- _classCallCheck(this, SquigglyAnnotation);
1434
+ }
1254
1435
 
1255
- _this20 = _possibleConstructorReturn(this, _getPrototypeOf(SquigglyAnnotation).call(this, parameters));
1256
- _this20.data.annotationType = _util.AnnotationType.SQUIGGLY;
1257
- return _this20;
1436
+ class CaretAnnotation extends MarkupAnnotation {
1437
+ constructor(parameters) {
1438
+ super(parameters);
1439
+ this.data.annotationType = _util.AnnotationType.CARET;
1258
1440
  }
1259
1441
 
1260
- return SquigglyAnnotation;
1261
- }(MarkupAnnotation);
1442
+ }
1262
1443
 
1263
- var StrikeOutAnnotation =
1264
- /*#__PURE__*/
1265
- function (_MarkupAnnotation12) {
1266
- _inherits(StrikeOutAnnotation, _MarkupAnnotation12);
1444
+ class InkAnnotation extends MarkupAnnotation {
1445
+ constructor(parameters) {
1446
+ super(parameters);
1447
+ this.data.annotationType = _util.AnnotationType.INK;
1448
+ const xref = parameters.xref;
1449
+ const originalInkLists = parameters.dict.getArray("InkList");
1450
+ this.data.inkLists = [];
1267
1451
 
1268
- function StrikeOutAnnotation(parameters) {
1269
- var _this21;
1452
+ for (let i = 0, ii = originalInkLists.length; i < ii; ++i) {
1453
+ this.data.inkLists.push([]);
1270
1454
 
1271
- _classCallCheck(this, StrikeOutAnnotation);
1455
+ for (let j = 0, jj = originalInkLists[i].length; j < jj; j += 2) {
1456
+ this.data.inkLists[i].push({
1457
+ x: xref.fetchIfRef(originalInkLists[i][j]),
1458
+ y: xref.fetchIfRef(originalInkLists[i][j + 1])
1459
+ });
1460
+ }
1461
+ }
1462
+ }
1272
1463
 
1273
- _this21 = _possibleConstructorReturn(this, _getPrototypeOf(StrikeOutAnnotation).call(this, parameters));
1274
- _this21.data.annotationType = _util.AnnotationType.STRIKEOUT;
1275
- return _this21;
1464
+ }
1465
+
1466
+ class HighlightAnnotation extends MarkupAnnotation {
1467
+ constructor(parameters) {
1468
+ super(parameters);
1469
+ this.data.annotationType = _util.AnnotationType.HIGHLIGHT;
1470
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
1471
+
1472
+ if (quadPoints) {
1473
+ this.data.quadPoints = quadPoints;
1474
+ }
1276
1475
  }
1277
1476
 
1278
- return StrikeOutAnnotation;
1279
- }(MarkupAnnotation);
1477
+ }
1478
+
1479
+ class UnderlineAnnotation extends MarkupAnnotation {
1480
+ constructor(parameters) {
1481
+ super(parameters);
1482
+ this.data.annotationType = _util.AnnotationType.UNDERLINE;
1483
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
1280
1484
 
1281
- var StampAnnotation =
1282
- /*#__PURE__*/
1283
- function (_MarkupAnnotation13) {
1284
- _inherits(StampAnnotation, _MarkupAnnotation13);
1485
+ if (quadPoints) {
1486
+ this.data.quadPoints = quadPoints;
1487
+ }
1488
+ }
1285
1489
 
1286
- function StampAnnotation(parameters) {
1287
- var _this22;
1490
+ }
1288
1491
 
1289
- _classCallCheck(this, StampAnnotation);
1492
+ class SquigglyAnnotation extends MarkupAnnotation {
1493
+ constructor(parameters) {
1494
+ super(parameters);
1495
+ this.data.annotationType = _util.AnnotationType.SQUIGGLY;
1496
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
1290
1497
 
1291
- _this22 = _possibleConstructorReturn(this, _getPrototypeOf(StampAnnotation).call(this, parameters));
1292
- _this22.data.annotationType = _util.AnnotationType.STAMP;
1293
- return _this22;
1498
+ if (quadPoints) {
1499
+ this.data.quadPoints = quadPoints;
1500
+ }
1294
1501
  }
1295
1502
 
1296
- return StampAnnotation;
1297
- }(MarkupAnnotation);
1503
+ }
1504
+
1505
+ class StrikeOutAnnotation extends MarkupAnnotation {
1506
+ constructor(parameters) {
1507
+ super(parameters);
1508
+ this.data.annotationType = _util.AnnotationType.STRIKEOUT;
1509
+ const quadPoints = getQuadPoints(parameters.dict, this.rectangle);
1298
1510
 
1299
- var FileAttachmentAnnotation =
1300
- /*#__PURE__*/
1301
- function (_MarkupAnnotation14) {
1302
- _inherits(FileAttachmentAnnotation, _MarkupAnnotation14);
1511
+ if (quadPoints) {
1512
+ this.data.quadPoints = quadPoints;
1513
+ }
1514
+ }
1515
+
1516
+ }
1303
1517
 
1304
- function FileAttachmentAnnotation(parameters) {
1305
- var _this23;
1518
+ class StampAnnotation extends MarkupAnnotation {
1519
+ constructor(parameters) {
1520
+ super(parameters);
1521
+ this.data.annotationType = _util.AnnotationType.STAMP;
1522
+ }
1306
1523
 
1307
- _classCallCheck(this, FileAttachmentAnnotation);
1524
+ }
1308
1525
 
1309
- _this23 = _possibleConstructorReturn(this, _getPrototypeOf(FileAttachmentAnnotation).call(this, parameters));
1310
- var file = new _obj.FileSpec(parameters.dict.get('FS'), parameters.xref);
1311
- _this23.data.annotationType = _util.AnnotationType.FILEATTACHMENT;
1312
- _this23.data.file = file.serializable;
1313
- return _this23;
1526
+ class FileAttachmentAnnotation extends MarkupAnnotation {
1527
+ constructor(parameters) {
1528
+ super(parameters);
1529
+ const file = new _obj.FileSpec(parameters.dict.get("FS"), parameters.xref);
1530
+ this.data.annotationType = _util.AnnotationType.FILEATTACHMENT;
1531
+ this.data.file = file.serializable;
1314
1532
  }
1315
1533
 
1316
- return FileAttachmentAnnotation;
1317
- }(MarkupAnnotation);
1534
+ }