@progress/kendo-pdfviewer-common 0.3.0-dev.202409251459 → 0.3.0-dev.202410100645

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.
Files changed (149) hide show
  1. package/dist/es/annotations/annotation-editor-layer-builder.js +139 -0
  2. package/dist/es/annotations/annotation-editor-layer.js +780 -0
  3. package/dist/es/annotations/annotation-editor-ui-manager.js +1690 -0
  4. package/dist/es/annotations/annotation-layer-builder.js +217 -0
  5. package/dist/es/annotations/annotation-layer.js +2793 -0
  6. package/dist/es/annotations/draw-layer-builder.js +65 -0
  7. package/dist/es/annotations/draw-layer.js +220 -0
  8. package/dist/es/annotations/editors/annotation-editor.js +1519 -0
  9. package/dist/es/annotations/editors/free-text-editor.js +783 -0
  10. package/dist/es/annotations/editors/highlight-editor.js +717 -0
  11. package/dist/es/annotations/editors/outliner.js +747 -0
  12. package/dist/es/annotations/helpers/annotation-storage.js +294 -0
  13. package/dist/es/annotations/helpers/color-manager.js +72 -0
  14. package/dist/es/annotations/helpers/command-manager.js +133 -0
  15. package/dist/es/annotations/helpers/id-manager.js +34 -0
  16. package/dist/es/annotations/helpers/image-manager.js +176 -0
  17. package/dist/es/annotations/helpers/text-accessibility-manager.js +212 -0
  18. package/dist/es/annotations/helpers/tools.js +19 -0
  19. package/dist/es/annotations/shared/display_utils.js +1024 -0
  20. package/dist/es/annotations/shared/event_utils.js +213 -0
  21. package/dist/es/annotations/shared/murmurhash3.js +126 -0
  22. package/dist/es/annotations/shared/scripting_utils.js +90 -0
  23. package/dist/es/annotations/shared/ui_utils.js +823 -0
  24. package/dist/es/annotations/shared/utils.js +909 -0
  25. package/dist/es/common/component.js +33 -0
  26. package/dist/es/common/core.js +91 -0
  27. package/dist/es/common/dom.js +11 -0
  28. package/dist/es/common/main.js +4 -0
  29. package/dist/es/common/math.js +1 -0
  30. package/dist/es/enums/PdfViewerInteractionMode.js +6 -0
  31. package/dist/es/links/link-service.js +505 -0
  32. package/dist/es/main.js +2 -0
  33. package/dist/es/scroller.js +29 -30
  34. package/dist/es/text/text-layer-builder.js +288 -0
  35. package/dist/es/utils.js +5 -5
  36. package/dist/es/widget/page.js +762 -0
  37. package/dist/es/widget/pdfviewer.js +1659 -0
  38. package/dist/es2015/annotations/annotation-editor-layer-builder.js +139 -0
  39. package/dist/es2015/annotations/annotation-editor-layer.js +780 -0
  40. package/dist/es2015/annotations/annotation-editor-ui-manager.js +1690 -0
  41. package/dist/es2015/annotations/annotation-layer-builder.js +217 -0
  42. package/dist/es2015/annotations/annotation-layer.js +2793 -0
  43. package/dist/es2015/annotations/draw-layer-builder.js +65 -0
  44. package/dist/es2015/annotations/draw-layer.js +220 -0
  45. package/dist/es2015/annotations/editors/annotation-editor.js +1519 -0
  46. package/dist/es2015/annotations/editors/free-text-editor.js +783 -0
  47. package/dist/es2015/annotations/editors/highlight-editor.js +717 -0
  48. package/dist/es2015/annotations/editors/outliner.js +747 -0
  49. package/dist/es2015/annotations/helpers/annotation-storage.js +294 -0
  50. package/dist/es2015/annotations/helpers/color-manager.js +72 -0
  51. package/dist/es2015/annotations/helpers/command-manager.js +133 -0
  52. package/dist/es2015/annotations/helpers/id-manager.js +34 -0
  53. package/dist/es2015/annotations/helpers/image-manager.js +176 -0
  54. package/dist/es2015/annotations/helpers/text-accessibility-manager.js +212 -0
  55. package/dist/es2015/annotations/helpers/tools.js +19 -0
  56. package/dist/es2015/annotations/shared/display_utils.js +1024 -0
  57. package/dist/es2015/annotations/shared/event_utils.js +213 -0
  58. package/dist/es2015/annotations/shared/murmurhash3.js +126 -0
  59. package/dist/es2015/annotations/shared/scripting_utils.js +90 -0
  60. package/dist/es2015/annotations/shared/ui_utils.js +823 -0
  61. package/dist/es2015/annotations/shared/utils.js +909 -0
  62. package/dist/es2015/common/component.js +33 -0
  63. package/dist/es2015/common/core.js +91 -0
  64. package/dist/es2015/common/dom.js +11 -0
  65. package/dist/es2015/common/main.js +4 -0
  66. package/dist/es2015/common/math.js +1 -0
  67. package/dist/es2015/enums/PdfViewerInteractionMode.js +6 -0
  68. package/dist/es2015/links/link-service.js +505 -0
  69. package/dist/es2015/main.js +2 -0
  70. package/dist/es2015/scroller.js +29 -30
  71. package/dist/es2015/text/text-layer-builder.js +288 -0
  72. package/dist/es2015/utils.js +5 -5
  73. package/dist/es2015/widget/page.js +762 -0
  74. package/dist/es2015/widget/pdfviewer.js +1659 -0
  75. package/dist/npm/annotations/annotation-editor-layer-builder.d.ts +39 -0
  76. package/dist/npm/annotations/annotation-editor-layer-builder.js +142 -0
  77. package/dist/npm/annotations/annotation-editor-layer.d.ts +196 -0
  78. package/dist/npm/annotations/annotation-editor-layer.js +783 -0
  79. package/dist/npm/annotations/annotation-editor-ui-manager.d.ts +281 -0
  80. package/dist/npm/annotations/annotation-editor-ui-manager.js +1694 -0
  81. package/dist/npm/annotations/annotation-layer-builder.d.ts +58 -0
  82. package/dist/npm/annotations/annotation-layer-builder.js +220 -0
  83. package/dist/npm/annotations/annotation-layer.d.ts +134 -0
  84. package/dist/npm/annotations/annotation-layer.js +2794 -0
  85. package/dist/npm/annotations/draw-layer-builder.d.ts +21 -0
  86. package/dist/npm/annotations/draw-layer-builder.js +68 -0
  87. package/dist/npm/annotations/draw-layer.d.ts +33 -0
  88. package/dist/npm/annotations/draw-layer.js +223 -0
  89. package/dist/npm/annotations/editors/annotation-editor.d.ts +349 -0
  90. package/dist/npm/annotations/editors/annotation-editor.js +1523 -0
  91. package/dist/npm/annotations/editors/free-text-editor.d.ts +108 -0
  92. package/dist/npm/annotations/editors/free-text-editor.js +786 -0
  93. package/dist/npm/annotations/editors/highlight-editor.d.ts +114 -0
  94. package/dist/npm/annotations/editors/highlight-editor.js +717 -0
  95. package/dist/npm/annotations/editors/outliner.d.ts +51 -0
  96. package/dist/npm/annotations/editors/outliner.js +750 -0
  97. package/dist/npm/annotations/helpers/annotation-storage.d.ts +98 -0
  98. package/dist/npm/annotations/helpers/annotation-storage.js +299 -0
  99. package/dist/npm/annotations/helpers/color-manager.d.ts +6 -0
  100. package/dist/npm/annotations/helpers/color-manager.js +76 -0
  101. package/dist/npm/annotations/helpers/command-manager.d.ts +42 -0
  102. package/dist/npm/annotations/helpers/command-manager.js +137 -0
  103. package/dist/npm/annotations/helpers/id-manager.d.ts +6 -0
  104. package/dist/npm/annotations/helpers/id-manager.js +38 -0
  105. package/dist/npm/annotations/helpers/image-manager.d.ts +18 -0
  106. package/dist/npm/annotations/helpers/image-manager.js +180 -0
  107. package/dist/npm/annotations/helpers/text-accessibility-manager.d.ts +36 -0
  108. package/dist/npm/annotations/helpers/text-accessibility-manager.js +215 -0
  109. package/dist/npm/annotations/helpers/tools.d.ts +1 -0
  110. package/dist/npm/annotations/helpers/tools.js +23 -0
  111. package/dist/npm/annotations/shared/display_utils.d.ts +6 -0
  112. package/dist/npm/annotations/shared/display_utils.js +1030 -0
  113. package/dist/npm/annotations/shared/event_utils.d.ts +33 -0
  114. package/dist/npm/annotations/shared/event_utils.js +165 -0
  115. package/dist/npm/annotations/shared/murmurhash3.d.ts +8 -0
  116. package/dist/npm/annotations/shared/murmurhash3.js +129 -0
  117. package/dist/npm/annotations/shared/scripting_utils.d.ts +17 -0
  118. package/dist/npm/annotations/shared/scripting_utils.js +93 -0
  119. package/dist/npm/annotations/shared/ui_utils.d.ts +54 -0
  120. package/dist/npm/annotations/shared/ui_utils.js +250 -0
  121. package/dist/npm/annotations/shared/utils.d.ts +148 -0
  122. package/dist/npm/annotations/shared/utils.js +872 -0
  123. package/dist/npm/common/component.d.ts +9 -0
  124. package/dist/npm/common/component.js +37 -0
  125. package/dist/npm/common/core.d.ts +18 -0
  126. package/dist/npm/common/core.js +112 -0
  127. package/dist/npm/common/dom.d.ts +3 -0
  128. package/dist/npm/common/dom.js +17 -0
  129. package/dist/npm/common/main.d.ts +4 -0
  130. package/dist/npm/common/main.js +7 -0
  131. package/dist/npm/common/math.d.ts +1 -0
  132. package/dist/npm/common/math.js +5 -0
  133. package/dist/npm/enums/PdfViewerInteractionMode.d.ts +4 -0
  134. package/dist/npm/enums/PdfViewerInteractionMode.js +9 -0
  135. package/dist/npm/links/link-service.d.ts +116 -0
  136. package/dist/npm/links/link-service.js +501 -0
  137. package/dist/npm/main.d.ts +2 -0
  138. package/dist/npm/main.js +2 -0
  139. package/dist/npm/scroller.d.ts +7 -3
  140. package/dist/npm/scroller.js +32 -32
  141. package/dist/npm/text/text-layer-builder.d.ts +30 -0
  142. package/dist/npm/text/text-layer-builder.js +291 -0
  143. package/dist/npm/utils.d.ts +20 -2
  144. package/dist/npm/utils.js +11 -8
  145. package/dist/npm/widget/page.d.ts +75 -0
  146. package/dist/npm/widget/page.js +763 -0
  147. package/dist/npm/widget/pdfviewer.d.ts +222 -0
  148. package/dist/npm/widget/pdfviewer.js +1663 -0
  149. package/package.json +13 -9
@@ -0,0 +1,2794 @@
1
+ "use strict";
2
+ /* Copyright 2014 Mozilla Foundation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var _AnnotationElement_instances, _AnnotationElement_updates, _AnnotationElement_hasBorder, _AnnotationElement_popupElement, _AnnotationElement_setRectEdited, _LinkAnnotationElement_instances, _LinkAnnotationElement_setInternalLink, _LinkAnnotationElement_bindAttachment, _LinkAnnotationElement_bindSetOCGState, _PopupElement_instances, _PopupElement_boundKeyDown, _PopupElement_boundHide, _PopupElement_boundShow, _PopupElement_boundToggle, _PopupElement_color, _PopupElement_container, _PopupElement_contentsObj, _PopupElement_dateObj, _PopupElement_elements, _PopupElement_parent, _PopupElement_parentRect, _PopupElement_pinned, _PopupElement_popup, _PopupElement_position, _PopupElement_rect, _PopupElement_richText, _PopupElement_titleObj, _PopupElement_updates, _PopupElement_wasVisible, _PopupElement_html_get, _PopupElement_fontSize_get, _PopupElement_fontColor_get, _PopupElement_makePopupContent, _PopupElement_keyDown, _PopupElement_setPosition, _PopupElement_toggle, _PopupElement_show, _PopupElement_hide, _AnnotationLayer_instances, _AnnotationLayer_accessibilityManager, _AnnotationLayer_annotationCanvasMap, _AnnotationLayer_editableAnnotations, _AnnotationLayer_appendElement, _AnnotationLayer_setAnnotationCanvasMap;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FreeTextAnnotationElement = exports.AnnotationLayer = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const pdf_mjs_1 = require("pdfjs-dist/legacy/build/pdf.mjs");
21
+ const utils_1 = require("./shared/utils");
22
+ const scripting_utils_1 = require("./shared/scripting_utils");
23
+ // import { AnnotationStorage } from "pdfjs-dist/types/src/display/annotation_storage";
24
+ // import { AnnotationStorage } from "pdfjs-dist/types/src/display/annotation_storage";
25
+ const DEFAULT_TAB_INDEX = 1000;
26
+ const DEFAULT_FONT_SIZE = 9;
27
+ const GetElementsByNameSet = new WeakSet();
28
+ function getRectDims(rect) {
29
+ return {
30
+ width: rect[2] - rect[0],
31
+ height: rect[3] - rect[1],
32
+ };
33
+ }
34
+ class AnnotationElementFactory {
35
+ /**
36
+ * @param {AnnotationElementParameters} parameters
37
+ * @returns {AnnotationElement}
38
+ */
39
+ static create(parameters) {
40
+ const subtype = parameters.data.annotationType;
41
+ switch (subtype) {
42
+ case utils_1.AnnotationType.LINK:
43
+ return new LinkAnnotationElement(parameters);
44
+ // case AnnotationType.TEXT:
45
+ // return new TextAnnotationElement(parameters);
46
+ // case AnnotationType.WIDGET:
47
+ // const fieldType = parameters.data.fieldType;
48
+ // switch (fieldType) {
49
+ // case "Tx":
50
+ // return new TextWidgetAnnotationElement(parameters);
51
+ // case "Btn":
52
+ // if (parameters.data.radioButton) {
53
+ // return new RadioButtonWidgetAnnotationElement(parameters);
54
+ // } else if (parameters.data.checkBox) {
55
+ // return new CheckboxWidgetAnnotationElement(parameters);
56
+ // }
57
+ // return new PushButtonWidgetAnnotationElement(parameters);
58
+ // case "Ch":
59
+ // return new ChoiceWidgetAnnotationElement(parameters);
60
+ // case "Sig":
61
+ // return new SignatureWidgetAnnotationElement(parameters);
62
+ // default: break;
63
+ // }
64
+ // return new WidgetAnnotationElement(parameters);
65
+ // case AnnotationType.POPUP:
66
+ // return new PopupAnnotationElement(parameters);
67
+ case utils_1.AnnotationType.FREETEXT:
68
+ return new FreeTextAnnotationElement(parameters);
69
+ // case AnnotationType.LINE:
70
+ // return new LineAnnotationElement(parameters);
71
+ // case AnnotationType.SQUARE:
72
+ // return new SquareAnnotationElement(parameters);
73
+ // case AnnotationType.CIRCLE:
74
+ // return new CircleAnnotationElement(parameters);
75
+ // case AnnotationType.POLYLINE:
76
+ // return new PolylineAnnotationElement(parameters);
77
+ // case AnnotationType.CARET:
78
+ // return new CaretAnnotationElement(parameters);
79
+ // case AnnotationType.INK:
80
+ // return new InkAnnotationElement(parameters);
81
+ // case AnnotationType.POLYGON:
82
+ // return new PolygonAnnotationElement(parameters);
83
+ case utils_1.AnnotationType.HIGHLIGHT:
84
+ return new HighlightAnnotationElement(parameters);
85
+ // case AnnotationType.UNDERLINE:
86
+ // return new UnderlineAnnotationElement(parameters);
87
+ // case AnnotationType.SQUIGGLY:
88
+ // return new SquigglyAnnotationElement(parameters);
89
+ // case AnnotationType.STRIKEOUT:
90
+ // return new StrikeOutAnnotationElement(parameters);
91
+ // case AnnotationType.STAMP:
92
+ // return new StampAnnotationElement(parameters);
93
+ // case AnnotationType.FILEATTACHMENT:
94
+ // return new FileAttachmentAnnotationElement(parameters);
95
+ default:
96
+ return new AnnotationElement(parameters);
97
+ }
98
+ }
99
+ }
100
+ class AnnotationElement {
101
+ constructor(parameters, { isRenderable = false, ignoreBorder = false, createQuadrilaterals = false, } = {}) {
102
+ _AnnotationElement_instances.add(this);
103
+ // todo: props
104
+ this.isRenderable = null;
105
+ this.data = null;
106
+ this.layer = null;
107
+ this.linkService = null;
108
+ this.downloadManager = null;
109
+ this.imageResourcesPath = null;
110
+ this.renderForms = null;
111
+ this.svgFactory = null;
112
+ this.annotationStorage = null;
113
+ this.enableScripting = null;
114
+ this.hasJSActions = null;
115
+ this._fieldObjects = null;
116
+ this.parent = null;
117
+ this.container = null;
118
+ this.popup = null;
119
+ this.annotationEditorType = null;
120
+ // todo: props
121
+ _AnnotationElement_updates.set(this, null);
122
+ _AnnotationElement_hasBorder.set(this, false);
123
+ _AnnotationElement_popupElement.set(this, null);
124
+ this.isRenderable = isRenderable;
125
+ this.data = parameters.data;
126
+ this.layer = parameters.layer;
127
+ this.linkService = parameters.linkService;
128
+ this.downloadManager = parameters.downloadManager;
129
+ this.imageResourcesPath = parameters.imageResourcesPath;
130
+ this.renderForms = parameters.renderForms;
131
+ this.svgFactory = parameters.svgFactory;
132
+ this.annotationStorage = parameters.annotationStorage;
133
+ this.enableScripting = parameters.enableScripting;
134
+ this.hasJSActions = parameters.hasJSActions;
135
+ this._fieldObjects = parameters.fieldObjects;
136
+ this.parent = parameters.parent;
137
+ if (isRenderable) {
138
+ this.container = this._createContainer(ignoreBorder);
139
+ }
140
+ if (createQuadrilaterals) {
141
+ this._createQuadrilaterals();
142
+ }
143
+ }
144
+ static _hasPopupData({ titleObj, contentsObj, richText }) {
145
+ return !!((titleObj === null || titleObj === void 0 ? void 0 : titleObj.str) || (contentsObj === null || contentsObj === void 0 ? void 0 : contentsObj.str) || (richText === null || richText === void 0 ? void 0 : richText.str));
146
+ }
147
+ get _isEditable() {
148
+ return this.data.isEditable;
149
+ }
150
+ get hasPopupData() {
151
+ return AnnotationElement._hasPopupData(this.data);
152
+ }
153
+ updateEdited(params) {
154
+ var _a;
155
+ if (!this.container) {
156
+ return;
157
+ }
158
+ tslib_1.__classPrivateFieldSet(this, _AnnotationElement_updates, tslib_1.__classPrivateFieldGet(this, _AnnotationElement_updates, "f") || {
159
+ rect: this.data.rect.slice(0),
160
+ }, "f");
161
+ const { rect } = params;
162
+ if (rect) {
163
+ tslib_1.__classPrivateFieldGet(this, _AnnotationElement_instances, "m", _AnnotationElement_setRectEdited).call(this, rect);
164
+ }
165
+ (_a = tslib_1.__classPrivateFieldGet(this, _AnnotationElement_popupElement, "f")) === null || _a === void 0 ? void 0 : _a.popup.updateEdited(params);
166
+ }
167
+ resetEdited() {
168
+ var _a;
169
+ if (!tslib_1.__classPrivateFieldGet(this, _AnnotationElement_updates, "f")) {
170
+ return;
171
+ }
172
+ tslib_1.__classPrivateFieldGet(this, _AnnotationElement_instances, "m", _AnnotationElement_setRectEdited).call(this, tslib_1.__classPrivateFieldGet(this, _AnnotationElement_updates, "f").rect);
173
+ (_a = tslib_1.__classPrivateFieldGet(this, _AnnotationElement_popupElement, "f")) === null || _a === void 0 ? void 0 : _a.popup.resetEdited();
174
+ tslib_1.__classPrivateFieldSet(this, _AnnotationElement_updates, null, "f");
175
+ }
176
+ /**
177
+ * Create an empty container for the annotation's HTML element.
178
+ *
179
+ * @private
180
+ * @param {boolean} ignoreBorder
181
+ * @memberof AnnotationElement
182
+ * @returns {HTMLElement} A section element.
183
+ */
184
+ _createContainer(ignoreBorder) {
185
+ const { data, parent: { page, viewport }, } = this;
186
+ const container = document.createElement("section");
187
+ container.setAttribute("data-annotation-id", data.id);
188
+ if (!(this instanceof WidgetAnnotationElement)) {
189
+ container.tabIndex = DEFAULT_TAB_INDEX;
190
+ }
191
+ const { style } = container;
192
+ // The accessibility manager will move the annotation in the DOM in
193
+ // order to match the visual ordering.
194
+ // But if an annotation is above an other one, then we must draw it
195
+ // after the other one whatever the order is in the DOM, hence the
196
+ // use of the z-index.
197
+ style.zIndex = (this.parent.zIndex++).toString();
198
+ if (data.popupRef) {
199
+ container.setAttribute("aria-haspopup", "dialog");
200
+ }
201
+ if (data.alternativeText) {
202
+ container.title = data.alternativeText;
203
+ }
204
+ if (data.noRotate) {
205
+ // container.classList.add("norotate");
206
+ }
207
+ if (!data.rect || this instanceof PopupAnnotationElement) {
208
+ const { rotation: rotationValue } = data;
209
+ if (!data.hasOwnCanvas && rotationValue !== 0) {
210
+ this.setRotation(rotationValue, container);
211
+ }
212
+ return container;
213
+ }
214
+ const { width, height } = getRectDims(data.rect);
215
+ if (!ignoreBorder && data.borderStyle.width > 0) {
216
+ style.borderWidth = `${data.borderStyle.width}px`;
217
+ const horizontalRadius = data.borderStyle.horizontalCornerRadius;
218
+ const verticalRadius = data.borderStyle.verticalCornerRadius;
219
+ if (horizontalRadius > 0 || verticalRadius > 0) {
220
+ const radius = `calc(${horizontalRadius}px * var(--scale-factor)) / calc(${verticalRadius}px * var(--scale-factor))`;
221
+ style.borderRadius = radius;
222
+ }
223
+ else if (this instanceof RadioButtonWidgetAnnotationElement) {
224
+ const radius = `calc(${width}px * var(--scale-factor)) / calc(${height}px * var(--scale-factor))`;
225
+ style.borderRadius = radius;
226
+ }
227
+ switch (data.borderStyle.style) {
228
+ case utils_1.AnnotationBorderStyleType.SOLID:
229
+ style.borderStyle = "solid";
230
+ break;
231
+ case utils_1.AnnotationBorderStyleType.DASHED:
232
+ style.borderStyle = "dashed";
233
+ break;
234
+ case utils_1.AnnotationBorderStyleType.BEVELED:
235
+ // warn("Unimplemented border style: beveled");
236
+ break;
237
+ case utils_1.AnnotationBorderStyleType.INSET:
238
+ // warn("Unimplemented border style: inset");
239
+ break;
240
+ case utils_1.AnnotationBorderStyleType.UNDERLINE:
241
+ style.borderBottomStyle = "solid";
242
+ break;
243
+ default:
244
+ break;
245
+ }
246
+ const borderColor = data.borderColor || null;
247
+ if (borderColor) {
248
+ tslib_1.__classPrivateFieldSet(this, _AnnotationElement_hasBorder, true, "f");
249
+ style.borderColor = pdf_mjs_1.Util.makeHexColor(borderColor[0] | 0, borderColor[1] | 0, borderColor[2] | 0);
250
+ }
251
+ else {
252
+ // Transparent (invisible) border, so do not draw it at all.
253
+ style.borderWidth = (0).toString();
254
+ }
255
+ }
256
+ // Do *not* modify `data.rect`, since that will corrupt the annotation
257
+ // position on subsequent calls to `_createContainer` (see issue 6804).
258
+ const rect = pdf_mjs_1.Util.normalizeRect([
259
+ data.rect[0],
260
+ page.view[3] - data.rect[1] + page.view[1],
261
+ data.rect[2],
262
+ page.view[3] - data.rect[3] + page.view[1],
263
+ ]);
264
+ const { pageWidth, pageHeight, pageX, pageY } = viewport.rawDims;
265
+ style.left = `${(100 * (rect[0] - pageX)) / pageWidth}%`;
266
+ style.top = `${(100 * (rect[1] - pageY)) / pageHeight}%`;
267
+ const { rotation } = data;
268
+ if (data.hasOwnCanvas || rotation === 0) {
269
+ style.width = `${(100 * width) / pageWidth}%`;
270
+ style.height = `${(100 * height) / pageHeight}%`;
271
+ }
272
+ else {
273
+ this.setRotation(rotation, container);
274
+ }
275
+ return container;
276
+ }
277
+ setRotation(angle, container = this.container) {
278
+ if (!this.data.rect) {
279
+ return;
280
+ }
281
+ const { pageWidth, pageHeight } = this.parent.viewport.rawDims;
282
+ const { width, height } = getRectDims(this.data.rect);
283
+ let elementWidth, elementHeight;
284
+ if (angle % 180 === 0) {
285
+ elementWidth = (100 * width) / pageWidth;
286
+ elementHeight = (100 * height) / pageHeight;
287
+ }
288
+ else {
289
+ elementWidth = (100 * height) / pageWidth;
290
+ elementHeight = (100 * width) / pageHeight;
291
+ }
292
+ container.style.width = `${elementWidth}%`;
293
+ container.style.height = `${elementHeight}%`;
294
+ container.setAttribute("data-main-rotation", (360 - angle) % 360);
295
+ }
296
+ get _commonActions() {
297
+ const setColor = (jsName, styleName, event) => {
298
+ const color = event.detail[jsName];
299
+ const colorType = color[0];
300
+ const colorArray = color.slice(1);
301
+ event.target.style[styleName] =
302
+ scripting_utils_1.ColorConverters[`${colorType}_HTML`](colorArray);
303
+ this.annotationStorage.setValue(this.data.id, {
304
+ [styleName]: scripting_utils_1.ColorConverters[`${colorType}_rgb`](colorArray),
305
+ });
306
+ };
307
+ return (0, pdf_mjs_1.shadow)(this, "_commonActions", {
308
+ display: event => {
309
+ const { display } = event.detail;
310
+ // See scripting/constants.js for the values of `Display`.
311
+ // 0 = visible, 1 = hidden, 2 = noPrint and 3 = noView.
312
+ const hidden = display % 2 === 1;
313
+ this.container.style.visibility = hidden ? "hidden" : "visible";
314
+ this.annotationStorage.setValue(this.data.id, {
315
+ noView: hidden,
316
+ noPrint: display === 1 || display === 2,
317
+ });
318
+ },
319
+ print: event => {
320
+ this.annotationStorage.setValue(this.data.id, {
321
+ noPrint: !event.detail.print,
322
+ });
323
+ },
324
+ hidden: event => {
325
+ const { hidden } = event.detail;
326
+ this.container.style.visibility = hidden ? "hidden" : "visible";
327
+ this.annotationStorage.setValue(this.data.id, {
328
+ noPrint: hidden,
329
+ noView: hidden,
330
+ });
331
+ },
332
+ focus: event => {
333
+ setTimeout(() => event.target.focus({ preventScroll: false }), 0);
334
+ },
335
+ userName: event => {
336
+ // tooltip
337
+ event.target.title = event.detail.userName;
338
+ },
339
+ readonly: event => {
340
+ event.target.disabled = event.detail.readonly;
341
+ },
342
+ required: event => {
343
+ this._setRequired(event.target, event.detail.required);
344
+ },
345
+ bgColor: event => {
346
+ setColor("bgColor", "backgroundColor", event);
347
+ },
348
+ fillColor: event => {
349
+ setColor("fillColor", "backgroundColor", event);
350
+ },
351
+ fgColor: event => {
352
+ setColor("fgColor", "color", event);
353
+ },
354
+ textColor: event => {
355
+ setColor("textColor", "color", event);
356
+ },
357
+ borderColor: event => {
358
+ setColor("borderColor", "borderColor", event);
359
+ },
360
+ strokeColor: event => {
361
+ setColor("strokeColor", "borderColor", event);
362
+ },
363
+ rotation: event => {
364
+ const angle = event.detail.rotation;
365
+ this.setRotation(angle);
366
+ this.annotationStorage.setValue(this.data.id, {
367
+ rotation: angle,
368
+ });
369
+ },
370
+ });
371
+ }
372
+ _dispatchEventFromSandbox(actions, jsEvent) {
373
+ const commonActions = this._commonActions;
374
+ for (const name of Object.keys(jsEvent.detail)) {
375
+ const action = actions[name] || commonActions[name];
376
+ action === null || action === void 0 ? void 0 : action(jsEvent);
377
+ }
378
+ }
379
+ _setDefaultPropertiesFromJS(element) {
380
+ if (!this.enableScripting) {
381
+ return;
382
+ }
383
+ // Some properties may have been updated thanks to JS.
384
+ const storedData = this.annotationStorage.getRawValue(this.data.id);
385
+ if (!storedData) {
386
+ return;
387
+ }
388
+ const commonActions = this._commonActions;
389
+ for (const [actionName, detail] of Object.entries(storedData)) {
390
+ const action = commonActions[actionName];
391
+ if (action) {
392
+ const eventProxy = {
393
+ detail: {
394
+ [actionName]: detail,
395
+ },
396
+ target: element,
397
+ };
398
+ action(eventProxy);
399
+ // The action has been consumed: no need to keep it.
400
+ delete storedData[actionName];
401
+ }
402
+ }
403
+ }
404
+ /**
405
+ * Create quadrilaterals from the annotation's quadpoints.
406
+ *
407
+ * @private
408
+ * @memberof AnnotationElement
409
+ */
410
+ _createQuadrilaterals() {
411
+ if (!this.container) {
412
+ return;
413
+ }
414
+ const { quadPoints } = this.data;
415
+ if (!quadPoints) {
416
+ return;
417
+ }
418
+ const [rectBlX, rectBlY, rectTrX, rectTrY] = this.data.rect.map(x => Math.fround(x));
419
+ if (quadPoints.length === 8) {
420
+ const [trX, trY, blX, blY] = quadPoints.subarray(2, 6);
421
+ if (rectTrX === trX &&
422
+ rectTrY === trY &&
423
+ rectBlX === blX &&
424
+ rectBlY === blY) {
425
+ // The quadpoints cover the whole annotation rectangle, so no need to
426
+ // create a quadrilateral.
427
+ return;
428
+ }
429
+ }
430
+ const { style } = this.container;
431
+ let svgBuffer;
432
+ if (tslib_1.__classPrivateFieldGet(this, _AnnotationElement_hasBorder, "f")) {
433
+ const { borderColor, borderWidth } = style;
434
+ style.borderWidth = 0;
435
+ svgBuffer = [
436
+ "url('data:image/svg+xml;utf8,",
437
+ `<svg xmlns="http://www.w3.org/2000/svg"`,
438
+ ` preserveAspectRatio="none" viewBox="0 0 1 1">`,
439
+ `<g fill="transparent" stroke="${borderColor}" stroke-width="${borderWidth}">`,
440
+ ];
441
+ // this.container.classList.add("hasBorder");
442
+ }
443
+ // todo: debug
444
+ // if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
445
+ // this.container.classList.add("hasClipPath");
446
+ // }
447
+ const width = rectTrX - rectBlX;
448
+ const height = rectTrY - rectBlY;
449
+ const { svgFactory } = this;
450
+ const svg = svgFactory.createElement("svg");
451
+ // svg.classList.add("quadrilateralsContainer");
452
+ svg.setAttribute("width", 0);
453
+ svg.setAttribute("height", 0);
454
+ const defs = svgFactory.createElement("defs");
455
+ svg.append(defs);
456
+ const clipPath = svgFactory.createElement("clipPath");
457
+ const id = `clippath_${this.data.id}`;
458
+ clipPath.setAttribute("id", id);
459
+ clipPath.setAttribute("clipPathUnits", "objectBoundingBox");
460
+ defs.append(clipPath);
461
+ for (let i = 2, ii = quadPoints.length; i < ii; i += 8) {
462
+ const trX = quadPoints[i];
463
+ const trY = quadPoints[i + 1];
464
+ const blX = quadPoints[i + 2];
465
+ const blY = quadPoints[i + 3];
466
+ const rect = svgFactory.createElement("rect");
467
+ const x = (blX - rectBlX) / width;
468
+ const y = (rectTrY - trY) / height;
469
+ const rectWidth = (trX - blX) / width;
470
+ const rectHeight = (trY - blY) / height;
471
+ rect.setAttribute("x", x);
472
+ rect.setAttribute("y", y);
473
+ rect.setAttribute("width", rectWidth);
474
+ rect.setAttribute("height", rectHeight);
475
+ clipPath.append(rect);
476
+ svgBuffer === null || svgBuffer === void 0 ? void 0 : svgBuffer.push(`<rect vector-effect="non-scaling-stroke" x="${x}" y="${y}" width="${rectWidth}" height="${rectHeight}"/>`);
477
+ }
478
+ if (tslib_1.__classPrivateFieldGet(this, _AnnotationElement_hasBorder, "f")) {
479
+ svgBuffer.push(`</g></svg>')`);
480
+ style.backgroundImage = svgBuffer.join("");
481
+ }
482
+ this.container.append(svg);
483
+ this.container.style.clipPath = `url(#${id})`;
484
+ }
485
+ /**
486
+ * Create a popup for the annotation's HTML element. This is used for
487
+ * annotations that do not have a Popup entry in the dictionary, but
488
+ * are of a type that works with popups (such as Highlight annotations).
489
+ *
490
+ * @private
491
+ * @memberof AnnotationElement
492
+ */
493
+ _createPopup() {
494
+ // const { container, data } = this;
495
+ // container.setAttribute("aria-haspopup", "dialog");
496
+ // const popup = (this.#popupElement = new PopupAnnotationElement({
497
+ // data: {
498
+ // color: data.color,
499
+ // titleObj: data.titleObj,
500
+ // modificationDate: data.modificationDate,
501
+ // contentsObj: data.contentsObj,
502
+ // richText: data.richText,
503
+ // parentRect: data.rect,
504
+ // borderStyle: 0,
505
+ // id: `popup_${data.id}`,
506
+ // rotation: data.rotation,
507
+ // },
508
+ // parent: this.parent,
509
+ // elements: [this],
510
+ // }));
511
+ // this.parent.div.append(popup.render());
512
+ }
513
+ /**
514
+ * Render the annotation's HTML element(s).
515
+ *
516
+ * @public
517
+ * @memberof AnnotationElement
518
+ */
519
+ render() {
520
+ // unreachable("Abstract method `AnnotationElement.render` called");
521
+ }
522
+ /**
523
+ * @private
524
+ * @returns {Array}
525
+ */
526
+ _getElementsByName(name, skipId = null) {
527
+ const fields = [];
528
+ if (this._fieldObjects) {
529
+ const fieldObj = this._fieldObjects[name];
530
+ if (fieldObj) {
531
+ for (const { page, id, exportValues } of fieldObj) {
532
+ if (page === -1) {
533
+ continue;
534
+ }
535
+ if (id === skipId) {
536
+ continue;
537
+ }
538
+ const exportValue = typeof exportValues === "string" ? exportValues : null;
539
+ const domElement = document.querySelector(`[data-element-id="${id}"]`);
540
+ if (domElement && !GetElementsByNameSet.has(domElement)) {
541
+ // warn(`_getElementsByName - element not allowed: ${id}`);
542
+ continue;
543
+ }
544
+ fields.push({ id, exportValue, domElement });
545
+ }
546
+ }
547
+ return fields;
548
+ }
549
+ // Fallback to a regular DOM lookup, to ensure that the standalone
550
+ // viewer components won't break.
551
+ for (const domElement of document.getElementsByName(name)) {
552
+ const { exportValue } = domElement;
553
+ const id = domElement.getAttribute("data-element-id");
554
+ if (id === skipId) {
555
+ continue;
556
+ }
557
+ if (!GetElementsByNameSet.has(domElement)) {
558
+ continue;
559
+ }
560
+ fields.push({ id, exportValue, domElement });
561
+ }
562
+ return fields;
563
+ }
564
+ show() {
565
+ var _a;
566
+ if (this.container) {
567
+ this.container.hidden = false;
568
+ }
569
+ (_a = this.popup) === null || _a === void 0 ? void 0 : _a.maybeShow();
570
+ }
571
+ hide() {
572
+ var _a;
573
+ if (this.container) {
574
+ this.container.hidden = true;
575
+ }
576
+ (_a = this.popup) === null || _a === void 0 ? void 0 : _a.forceHide();
577
+ }
578
+ /**
579
+ * Get the HTML element(s) which can trigger a popup when clicked or hovered.
580
+ *
581
+ * @public
582
+ * @memberof AnnotationElement
583
+ * @returns {Array<HTMLElement>|HTMLElement} An array of elements or an
584
+ * element.
585
+ */
586
+ getElementsToTriggerPopup() {
587
+ return this.container;
588
+ }
589
+ addHighlightArea() {
590
+ const triggers = this.getElementsToTriggerPopup();
591
+ if (Array.isArray(triggers)) {
592
+ // for (const element of triggers) {
593
+ // element.classList.add("highlightArea");
594
+ // }
595
+ }
596
+ else {
597
+ // triggers.classList.add("highlightArea");
598
+ }
599
+ }
600
+ _editOnDoubleClick() {
601
+ if (!this._isEditable) {
602
+ return;
603
+ }
604
+ const { annotationEditorType: mode, data: { id: editId }, } = this;
605
+ this.container.addEventListener("dblclick", () => {
606
+ var _a, _b;
607
+ (_b = (_a = this.linkService) === null || _a === void 0 ? void 0 : _a.eventBus) === null || _b === void 0 ? void 0 : _b.dispatch("switchannotationeditormode", {
608
+ source: this,
609
+ mode,
610
+ editId,
611
+ });
612
+ });
613
+ }
614
+ _setRequired(element, isRequired) {
615
+ if (isRequired) {
616
+ element.setAttribute("required", true);
617
+ }
618
+ else {
619
+ element.removeAttribute("required");
620
+ }
621
+ element.setAttribute("aria-required", isRequired);
622
+ }
623
+ }
624
+ _AnnotationElement_updates = new WeakMap(), _AnnotationElement_hasBorder = new WeakMap(), _AnnotationElement_popupElement = new WeakMap(), _AnnotationElement_instances = new WeakSet(), _AnnotationElement_setRectEdited = function _AnnotationElement_setRectEdited(rect) {
625
+ const { container: { style }, data: { rect: currentRect, rotation }, parent: { viewport: { rawDims: { pageWidth, pageHeight, pageX, pageY }, }, }, } = this;
626
+ currentRect === null || currentRect === void 0 ? void 0 : currentRect.splice(0, 4, ...rect);
627
+ const { width, height } = getRectDims(rect);
628
+ style.left = `${(100 * (rect[0] - pageX)) / pageWidth}%`;
629
+ style.top = `${(100 * (pageHeight - rect[3] + pageY)) / pageHeight}%`;
630
+ if (rotation === 0) {
631
+ style.width = `${(100 * width) / pageWidth}%`;
632
+ style.height = `${(100 * height) / pageHeight}%`;
633
+ }
634
+ else {
635
+ this.setRotation(rotation);
636
+ }
637
+ };
638
+ class LinkAnnotationElement extends AnnotationElement {
639
+ constructor(parameters, options = null) {
640
+ super(parameters, {
641
+ isRenderable: true,
642
+ ignoreBorder: !!(options === null || options === void 0 ? void 0 : options.ignoreBorder),
643
+ createQuadrilaterals: true,
644
+ });
645
+ _LinkAnnotationElement_instances.add(this);
646
+ this.isTooltipOnly = false;
647
+ this.isTooltipOnly = parameters.data.isTooltipOnly;
648
+ }
649
+ render() {
650
+ const { data, linkService } = this;
651
+ const link = document.createElement("a");
652
+ link.setAttribute("data-element-id", data.id);
653
+ let isBound = false;
654
+ if (data.url) {
655
+ linkService.addLinkAttributes(link, data.url, data.newWindow);
656
+ isBound = true;
657
+ }
658
+ else if (data.action) {
659
+ this._bindNamedAction(link, data.action);
660
+ isBound = true;
661
+ }
662
+ else if (data.attachment) {
663
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_bindAttachment).call(this, link, data.attachment, data.attachmentDest);
664
+ isBound = true;
665
+ }
666
+ else if (data.setOCGState) {
667
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_bindSetOCGState).call(this, link, data.setOCGState);
668
+ isBound = true;
669
+ }
670
+ else if (data.dest) {
671
+ this._bindLink(link, data.dest);
672
+ isBound = true;
673
+ }
674
+ else {
675
+ if (data.actions &&
676
+ (data.actions.Action ||
677
+ data.actions["Mouse Up"] ||
678
+ data.actions["Mouse Down"]) &&
679
+ this.enableScripting &&
680
+ this.hasJSActions) {
681
+ this._bindJSAction(link, data);
682
+ isBound = true;
683
+ }
684
+ if (data.resetForm) {
685
+ this._bindResetFormAction(link, data.resetForm);
686
+ isBound = true;
687
+ }
688
+ else if (this.isTooltipOnly && !isBound) {
689
+ this._bindLink(link, "");
690
+ isBound = true;
691
+ }
692
+ }
693
+ // todo: do not render the class as the rendering is yet to be determined
694
+ // this.container.classList.add("linkAnnotation");
695
+ // this.container.classList.add("k-link-annotation");
696
+ if (isBound) {
697
+ this.container.append(link);
698
+ }
699
+ return this.container;
700
+ }
701
+ /**
702
+ * Bind internal links to the link element.
703
+ *
704
+ * @private
705
+ * @param {Object} link
706
+ * @param {Object} destination
707
+ * @memberof LinkAnnotationElement
708
+ */
709
+ _bindLink(link, destination) {
710
+ link.href = this.linkService.getDestinationHash(destination);
711
+ link.onclick = () => {
712
+ if (destination) {
713
+ this.linkService.goToDestination(destination);
714
+ }
715
+ return false;
716
+ };
717
+ if (destination || destination === /* isTooltipOnly = */ "") {
718
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
719
+ }
720
+ }
721
+ /**
722
+ * Bind named actions to the link element.
723
+ *
724
+ * @private
725
+ * @param {Object} link
726
+ * @param {Object} action
727
+ * @memberof LinkAnnotationElement
728
+ */
729
+ _bindNamedAction(link, action) {
730
+ link.href = this.linkService.getAnchorUrl("");
731
+ link.onclick = () => {
732
+ this.linkService.executeNamedAction(action);
733
+ return false;
734
+ };
735
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
736
+ }
737
+ /**
738
+ * Bind JS actions to the link element.
739
+ *
740
+ * @private
741
+ * @param {Object} link
742
+ * @param {Object} data
743
+ * @memberof LinkAnnotationElement
744
+ */
745
+ _bindJSAction(link, data) {
746
+ link.href = this.linkService.getAnchorUrl("");
747
+ const map = new Map([
748
+ ["Action", "onclick"],
749
+ ["Mouse Up", "onmouseup"],
750
+ ["Mouse Down", "onmousedown"],
751
+ ]);
752
+ for (const name of Object.keys(data.actions)) {
753
+ const jsName = map.get(name);
754
+ if (!jsName) {
755
+ continue;
756
+ }
757
+ link[jsName] = () => {
758
+ var _a;
759
+ (_a = this.linkService.eventBus) === null || _a === void 0 ? void 0 : _a.dispatch("dispatcheventinsandbox", {
760
+ source: this,
761
+ detail: {
762
+ id: data.id,
763
+ name,
764
+ },
765
+ });
766
+ return false;
767
+ };
768
+ }
769
+ if (!link.onclick) {
770
+ link.onclick = () => false;
771
+ }
772
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
773
+ }
774
+ _bindResetFormAction(link, resetForm) {
775
+ const otherClickAction = link.onclick;
776
+ if (!otherClickAction) {
777
+ link.href = this.linkService.getAnchorUrl("");
778
+ }
779
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
780
+ if (!this._fieldObjects) {
781
+ // warn(
782
+ // `_bindResetFormAction - "resetForm" action not supported, ` +
783
+ // "ensure that the `fieldObjects` parameter is provided."
784
+ // );
785
+ if (!otherClickAction) {
786
+ link.onclick = () => false;
787
+ }
788
+ return;
789
+ }
790
+ link.onclick = () => {
791
+ var _a;
792
+ otherClickAction === null || otherClickAction === void 0 ? void 0 : otherClickAction();
793
+ const { fields: resetFormFields, refs: resetFormRefs, include, } = resetForm;
794
+ const allFields = [];
795
+ if (resetFormFields.length !== 0 || resetFormRefs.length !== 0) {
796
+ const fieldIds = new Set(resetFormRefs);
797
+ for (const fieldName of resetFormFields) {
798
+ const fields = this._fieldObjects[fieldName] || [];
799
+ for (const { id } of fields) {
800
+ fieldIds.add(id);
801
+ }
802
+ }
803
+ for (const fields of Object.values(this._fieldObjects)) {
804
+ for (const field of fields) {
805
+ if (fieldIds.has(field.id) === include) {
806
+ allFields.push(field);
807
+ }
808
+ }
809
+ }
810
+ }
811
+ else {
812
+ for (const fields of Object.values(this._fieldObjects)) {
813
+ allFields.push(...fields);
814
+ }
815
+ }
816
+ const storage = this.annotationStorage;
817
+ const allIds = [];
818
+ for (const field of allFields) {
819
+ const { id } = field;
820
+ allIds.push(id);
821
+ switch (field.type) {
822
+ case "text": {
823
+ const value = field.defaultValue || "";
824
+ storage.setValue(id, { value });
825
+ break;
826
+ }
827
+ case "checkbox":
828
+ case "radiobutton": {
829
+ const value = field.defaultValue === field.exportValues;
830
+ storage.setValue(id, { value });
831
+ break;
832
+ }
833
+ case "combobox":
834
+ case "listbox": {
835
+ const value = field.defaultValue || "";
836
+ storage.setValue(id, { value });
837
+ break;
838
+ }
839
+ default:
840
+ continue;
841
+ }
842
+ const domElement = document.querySelector(`[data-element-id="${id}"]`);
843
+ if (!domElement) {
844
+ continue;
845
+ }
846
+ else if (!GetElementsByNameSet.has(domElement)) {
847
+ // warn(`_bindResetFormAction - element not allowed: ${id}`);
848
+ continue;
849
+ }
850
+ domElement.dispatchEvent(new Event("resetform"));
851
+ }
852
+ if (this.enableScripting) {
853
+ // Update the values in the sandbox.
854
+ (_a = this.linkService.eventBus) === null || _a === void 0 ? void 0 : _a.dispatch("dispatcheventinsandbox", {
855
+ source: this,
856
+ detail: {
857
+ id: "app",
858
+ ids: allIds,
859
+ name: "ResetForm",
860
+ },
861
+ });
862
+ }
863
+ return false;
864
+ };
865
+ }
866
+ }
867
+ _LinkAnnotationElement_instances = new WeakSet(), _LinkAnnotationElement_setInternalLink = function _LinkAnnotationElement_setInternalLink() {
868
+ this.container.setAttribute("data-internal-link", "");
869
+ }, _LinkAnnotationElement_bindAttachment = function _LinkAnnotationElement_bindAttachment(link, attachment, dest = null) {
870
+ link.href = this.linkService.getAnchorUrl("");
871
+ if (attachment.description) {
872
+ link.title = attachment.description;
873
+ }
874
+ link.onclick = () => {
875
+ var _a;
876
+ (_a = this.downloadManager) === null || _a === void 0 ? void 0 : _a.openOrDownloadData(attachment.content, attachment.filename, dest);
877
+ return false;
878
+ };
879
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
880
+ }, _LinkAnnotationElement_bindSetOCGState = function _LinkAnnotationElement_bindSetOCGState(link, action) {
881
+ link.href = this.linkService.getAnchorUrl("");
882
+ link.onclick = () => {
883
+ this.linkService.executeSetOCGState(action);
884
+ return false;
885
+ };
886
+ tslib_1.__classPrivateFieldGet(this, _LinkAnnotationElement_instances, "m", _LinkAnnotationElement_setInternalLink).call(this);
887
+ };
888
+ // class TextAnnotationElement extends AnnotationElement {
889
+ // constructor(parameters) {
890
+ // super(parameters, { isRenderable: true });
891
+ // }
892
+ // render() {
893
+ // this.container.classList.add("textAnnotation");
894
+ // const image = document.createElement("img");
895
+ // image.src =
896
+ // this.imageResourcesPath +
897
+ // "annotation-" +
898
+ // this.data.name.toLowerCase() +
899
+ // ".svg";
900
+ // image.setAttribute("data-l10n-id", "pdfjs-text-annotation-type");
901
+ // image.setAttribute(
902
+ // "data-l10n-args",
903
+ // JSON.stringify({ type: this.data.name })
904
+ // );
905
+ // if (!this.data.popupRef && this.hasPopupData) {
906
+ // this._createPopup();
907
+ // }
908
+ // this.container.append(image);
909
+ // return this.container;
910
+ // }
911
+ // }
912
+ class WidgetAnnotationElement extends AnnotationElement {
913
+ render() {
914
+ // Show only the container for unsupported field types.
915
+ return this.container;
916
+ }
917
+ showElementAndHideCanvas(element) {
918
+ var _a;
919
+ if (this.data.hasOwnCanvas) {
920
+ if (((_a = element.previousSibling) === null || _a === void 0 ? void 0 : _a.nodeName) === "CANVAS") {
921
+ element.previousSibling.hidden = true;
922
+ }
923
+ element.hidden = false;
924
+ }
925
+ }
926
+ _getKeyModifier(event) {
927
+ return pdf_mjs_1.FeatureTest.platform.isMac ? event.metaKey : event.ctrlKey;
928
+ }
929
+ _setEventListener(element, elementData, baseName, eventName, valueGetter) {
930
+ if (baseName.includes("mouse")) {
931
+ // Mouse events
932
+ element.addEventListener(baseName, event => {
933
+ var _a;
934
+ (_a = this.linkService.eventBus) === null || _a === void 0 ? void 0 : _a.dispatch("dispatcheventinsandbox", {
935
+ source: this,
936
+ detail: {
937
+ id: this.data.id,
938
+ name: eventName,
939
+ value: valueGetter(event),
940
+ shift: event.shiftKey,
941
+ modifier: this._getKeyModifier(event),
942
+ },
943
+ });
944
+ });
945
+ }
946
+ else {
947
+ // Non-mouse events
948
+ element.addEventListener(baseName, event => {
949
+ var _a;
950
+ if (baseName === "blur") {
951
+ if (!elementData.focused || !event.relatedTarget) {
952
+ return;
953
+ }
954
+ elementData.focused = false;
955
+ }
956
+ else if (baseName === "focus") {
957
+ if (elementData.focused) {
958
+ return;
959
+ }
960
+ elementData.focused = true;
961
+ }
962
+ if (!valueGetter) {
963
+ return;
964
+ }
965
+ (_a = this.linkService.eventBus) === null || _a === void 0 ? void 0 : _a.dispatch("dispatcheventinsandbox", {
966
+ source: this,
967
+ detail: {
968
+ id: this.data.id,
969
+ name: eventName,
970
+ value: valueGetter(event),
971
+ },
972
+ });
973
+ });
974
+ }
975
+ }
976
+ _setEventListeners(element, elementData, names, getter) {
977
+ var _a, _b, _c;
978
+ for (const [baseName, eventName] of names) {
979
+ if (eventName === "Action" || ((_a = this.data.actions) === null || _a === void 0 ? void 0 : _a[eventName])) {
980
+ if (eventName === "Focus" || eventName === "Blur") {
981
+ elementData || (elementData = { focused: false });
982
+ }
983
+ this._setEventListener(element, elementData, baseName, eventName, getter);
984
+ if (eventName === "Focus" && !((_b = this.data.actions) === null || _b === void 0 ? void 0 : _b.Blur)) {
985
+ // Ensure that elementData will have the correct value.
986
+ this._setEventListener(element, elementData, "blur", "Blur", null);
987
+ }
988
+ else if (eventName === "Blur" && !((_c = this.data.actions) === null || _c === void 0 ? void 0 : _c.Focus)) {
989
+ this._setEventListener(element, elementData, "focus", "Focus", null);
990
+ }
991
+ }
992
+ }
993
+ }
994
+ _setBackgroundColor(element) {
995
+ const color = this.data.backgroundColor || null;
996
+ element.style.backgroundColor =
997
+ color === null
998
+ ? "transparent"
999
+ : pdf_mjs_1.Util.makeHexColor(color[0], color[1], color[2]);
1000
+ }
1001
+ /**
1002
+ * Apply text styles to the text in the element.
1003
+ *
1004
+ * @private
1005
+ * @param {HTMLDivElement} element
1006
+ * @memberof TextWidgetAnnotationElement
1007
+ */
1008
+ _setTextStyle(element) {
1009
+ const TEXT_ALIGNMENT = ["left", "center", "right"];
1010
+ const { fontColor } = this.data.defaultAppearanceData;
1011
+ const fontSize = this.data.defaultAppearanceData.fontSize || DEFAULT_FONT_SIZE;
1012
+ const style = element.style;
1013
+ // TODO: If the font-size is zero, calculate it based on the height and
1014
+ // width of the element.
1015
+ // Not setting `style.fontSize` will use the default font-size for now.
1016
+ // We don't use the font, as specified in the PDF document, for the <input>
1017
+ // element. Hence using the original `fontSize` could look bad, which is why
1018
+ // it's instead based on the field height.
1019
+ // If the height is "big" then it could lead to a too big font size
1020
+ // so in this case use the one we've in the pdf (hence the min).
1021
+ let computedFontSize;
1022
+ const BORDER_SIZE = 2;
1023
+ const roundToOneDecimal = x => Math.round(10 * x) / 10;
1024
+ if (this.data.multiLine) {
1025
+ const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
1026
+ const numberOfLines = Math.round(height / (utils_1.LINE_FACTOR * fontSize)) || 1;
1027
+ const lineHeight = height / numberOfLines;
1028
+ computedFontSize = Math.min(fontSize, roundToOneDecimal(lineHeight / utils_1.LINE_FACTOR));
1029
+ }
1030
+ else {
1031
+ const height = Math.abs(this.data.rect[3] - this.data.rect[1] - BORDER_SIZE);
1032
+ computedFontSize = Math.min(fontSize, roundToOneDecimal(height / utils_1.LINE_FACTOR));
1033
+ }
1034
+ style.fontSize = `calc(${computedFontSize}px * var(--scale-factor))`;
1035
+ style.color = pdf_mjs_1.Util.makeHexColor(fontColor[0], fontColor[1], fontColor[2]);
1036
+ if (this.data.textAlignment !== null) {
1037
+ style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
1038
+ }
1039
+ }
1040
+ _setRequired(element, isRequired) {
1041
+ if (isRequired) {
1042
+ element.setAttribute("required", true);
1043
+ }
1044
+ else {
1045
+ element.removeAttribute("required");
1046
+ }
1047
+ element.setAttribute("aria-required", isRequired);
1048
+ }
1049
+ }
1050
+ // class TextWidgetAnnotationElement extends WidgetAnnotationElement {
1051
+ // constructor(parameters) {
1052
+ // const isRenderable =
1053
+ // parameters.renderForms ||
1054
+ // parameters.data.hasOwnCanvas ||
1055
+ // (!parameters.data.hasAppearance && !!parameters.data.fieldValue);
1056
+ // super(parameters, { isRenderable });
1057
+ // }
1058
+ // setPropertyOnSiblings(base, key, value, keyInStorage) {
1059
+ // const storage = this.annotationStorage;
1060
+ // for (const element of this._getElementsByName(
1061
+ // base.name,
1062
+ // /* skipId = */ base.id
1063
+ // )) {
1064
+ // if (element.domElement) {
1065
+ // element.domElement[key] = value;
1066
+ // }
1067
+ // storage.setValue(element.id, { [keyInStorage]: value });
1068
+ // }
1069
+ // }
1070
+ // render() {
1071
+ // const storage = this.annotationStorage;
1072
+ // const id = this.data.id;
1073
+ // this.container.classList.add("textWidgetAnnotation");
1074
+ // let element = null;
1075
+ // if (this.renderForms) {
1076
+ // // NOTE: We cannot set the values using `element.value` below, since it
1077
+ // // prevents the AnnotationLayer rasterizer in `test/driver.js`
1078
+ // // from parsing the elements correctly for the reference tests.
1079
+ // const storedData = storage.getValue(id, {
1080
+ // value: this.data.fieldValue,
1081
+ // });
1082
+ // let textContent = storedData.value || "";
1083
+ // const maxLen = storage.getValue(id, {
1084
+ // charLimit: this.data.maxLen,
1085
+ // }).charLimit;
1086
+ // if (maxLen && textContent.length > maxLen) {
1087
+ // textContent = textContent.slice(0, maxLen);
1088
+ // }
1089
+ // let fieldFormattedValues =
1090
+ // storedData.formattedValue || this.data.textContent?.join("\n") || null;
1091
+ // if (fieldFormattedValues && this.data.comb) {
1092
+ // fieldFormattedValues = fieldFormattedValues.replaceAll(/\s+/g, "");
1093
+ // }
1094
+ // const elementData = {
1095
+ // userValue: textContent,
1096
+ // formattedValue: fieldFormattedValues,
1097
+ // lastCommittedValue: null,
1098
+ // commitKey: 1,
1099
+ // focused: false,
1100
+ // };
1101
+ // if (this.data.multiLine) {
1102
+ // element = document.createElement("textarea");
1103
+ // element.textContent = fieldFormattedValues ?? textContent;
1104
+ // if (this.data.doNotScroll) {
1105
+ // element.style.overflowY = "hidden";
1106
+ // }
1107
+ // } else {
1108
+ // element = document.createElement("input");
1109
+ // element.type = "text";
1110
+ // element.setAttribute("value", fieldFormattedValues ?? textContent);
1111
+ // if (this.data.doNotScroll) {
1112
+ // element.style.overflowX = "hidden";
1113
+ // }
1114
+ // }
1115
+ // if (this.data.hasOwnCanvas) {
1116
+ // element.hidden = true;
1117
+ // }
1118
+ // GetElementsByNameSet.add(element);
1119
+ // element.setAttribute("data-element-id", id);
1120
+ // element.disabled = this.data.readOnly;
1121
+ // element.name = this.data.fieldName;
1122
+ // element.tabIndex = DEFAULT_TAB_INDEX;
1123
+ // this._setRequired(element, this.data.required);
1124
+ // if (maxLen) {
1125
+ // element.maxLength = maxLen;
1126
+ // }
1127
+ // element.addEventListener("input", event => {
1128
+ // storage.setValue(id, { value: event.target.value });
1129
+ // this.setPropertyOnSiblings(
1130
+ // element,
1131
+ // "value",
1132
+ // event.target.value,
1133
+ // "value"
1134
+ // );
1135
+ // elementData.formattedValue = null;
1136
+ // });
1137
+ // element.addEventListener("resetform", () => {
1138
+ // const defaultValue = this.data.defaultFieldValue ?? "";
1139
+ // element.value = elementData.userValue = defaultValue;
1140
+ // elementData.formattedValue = null;
1141
+ // });
1142
+ // let blurListener = event => {
1143
+ // const { formattedValue } = elementData;
1144
+ // if (formattedValue !== null && formattedValue !== undefined) {
1145
+ // event.target.value = formattedValue;
1146
+ // }
1147
+ // // Reset the cursor position to the start of the field (issue 12359).
1148
+ // event.target.scrollLeft = 0;
1149
+ // };
1150
+ // if (this.enableScripting && this.hasJSActions) {
1151
+ // element.addEventListener("focus", event => {
1152
+ // if (elementData.focused) {
1153
+ // return;
1154
+ // }
1155
+ // const { target } = event;
1156
+ // if (elementData.userValue) {
1157
+ // target.value = elementData.userValue;
1158
+ // }
1159
+ // elementData.lastCommittedValue = target.value;
1160
+ // elementData.commitKey = 1;
1161
+ // if (!this.data.actions?.Focus) {
1162
+ // elementData.focused = true;
1163
+ // }
1164
+ // });
1165
+ // element.addEventListener("updatefromsandbox", jsEvent => {
1166
+ // this.showElementAndHideCanvas(jsEvent.target);
1167
+ // const actions = {
1168
+ // value(event) {
1169
+ // elementData.userValue = event.detail.value ?? "";
1170
+ // storage.setValue(id, { value: elementData.userValue.toString() });
1171
+ // event.target.value = elementData.userValue;
1172
+ // },
1173
+ // formattedValue(event) {
1174
+ // const { formattedValue } = event.detail;
1175
+ // elementData.formattedValue = formattedValue;
1176
+ // if (
1177
+ // formattedValue !== null &&
1178
+ // formattedValue !== undefined &&
1179
+ // event.target !== document.activeElement
1180
+ // ) {
1181
+ // // Input hasn't the focus so display formatted string
1182
+ // event.target.value = formattedValue;
1183
+ // }
1184
+ // storage.setValue(id, {
1185
+ // formattedValue,
1186
+ // });
1187
+ // },
1188
+ // selRange(event) {
1189
+ // event.target.setSelectionRange(...event.detail.selRange);
1190
+ // },
1191
+ // charLimit: event => {
1192
+ // const { charLimit } = event.detail;
1193
+ // const { target } = event;
1194
+ // if (charLimit === 0) {
1195
+ // target.removeAttribute("maxLength");
1196
+ // return;
1197
+ // }
1198
+ // target.setAttribute("maxLength", charLimit);
1199
+ // let value = elementData.userValue;
1200
+ // if (!value || value.length <= charLimit) {
1201
+ // return;
1202
+ // }
1203
+ // value = value.slice(0, charLimit);
1204
+ // target.value = elementData.userValue = value;
1205
+ // storage.setValue(id, { value });
1206
+ // this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
1207
+ // source: this,
1208
+ // detail: {
1209
+ // id,
1210
+ // name: "Keystroke",
1211
+ // value,
1212
+ // willCommit: true,
1213
+ // commitKey: 1,
1214
+ // selStart: target.selectionStart,
1215
+ // selEnd: target.selectionEnd,
1216
+ // },
1217
+ // });
1218
+ // },
1219
+ // };
1220
+ // this._dispatchEventFromSandbox(actions, jsEvent);
1221
+ // });
1222
+ // // Even if the field hasn't any actions
1223
+ // // leaving it can still trigger some actions with Calculate
1224
+ // element.addEventListener("keydown", event => {
1225
+ // elementData.commitKey = 1;
1226
+ // // If the key is one of Escape, Enter then the data are committed.
1227
+ // // If we've a Tab then data will be committed on blur.
1228
+ // let commitKey = -1;
1229
+ // if (event.key === "Escape") {
1230
+ // commitKey = 0;
1231
+ // } else if (event.key === "Enter" && !this.data.multiLine) {
1232
+ // // When we've a multiline field, "Enter" key is a key as the other
1233
+ // // hence we don't commit the data (Acrobat behaves the same way)
1234
+ // // (see issue #15627).
1235
+ // commitKey = 2;
1236
+ // } else if (event.key === "Tab") {
1237
+ // elementData.commitKey = 3;
1238
+ // }
1239
+ // if (commitKey === -1) {
1240
+ // return;
1241
+ // }
1242
+ // const { value } = event.target;
1243
+ // if (elementData.lastCommittedValue === value) {
1244
+ // return;
1245
+ // }
1246
+ // elementData.lastCommittedValue = value;
1247
+ // // Save the entered value
1248
+ // elementData.userValue = value;
1249
+ // this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
1250
+ // source: this,
1251
+ // detail: {
1252
+ // id,
1253
+ // name: "Keystroke",
1254
+ // value,
1255
+ // willCommit: true,
1256
+ // commitKey,
1257
+ // selStart: event.target.selectionStart,
1258
+ // selEnd: event.target.selectionEnd,
1259
+ // },
1260
+ // });
1261
+ // });
1262
+ // const _blurListener = blurListener;
1263
+ // blurListener = null;
1264
+ // element.addEventListener("blur", event => {
1265
+ // if (!elementData.focused || !event.relatedTarget) {
1266
+ // return;
1267
+ // }
1268
+ // if (!this.data.actions?.Blur) {
1269
+ // elementData.focused = false;
1270
+ // }
1271
+ // const { value } = event.target;
1272
+ // elementData.userValue = value;
1273
+ // if (elementData.lastCommittedValue !== value) {
1274
+ // this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
1275
+ // source: this,
1276
+ // detail: {
1277
+ // id,
1278
+ // name: "Keystroke",
1279
+ // value,
1280
+ // willCommit: true,
1281
+ // commitKey: elementData.commitKey,
1282
+ // selStart: event.target.selectionStart,
1283
+ // selEnd: event.target.selectionEnd,
1284
+ // },
1285
+ // });
1286
+ // }
1287
+ // _blurListener(event);
1288
+ // });
1289
+ // if (this.data.actions?.Keystroke) {
1290
+ // element.addEventListener("beforeinput", event => {
1291
+ // elementData.lastCommittedValue = null;
1292
+ // const { data, target } = event;
1293
+ // const { value, selectionStart, selectionEnd } = target;
1294
+ // let selStart = selectionStart,
1295
+ // selEnd = selectionEnd;
1296
+ // switch (event.inputType) {
1297
+ // // https://rawgit.com/w3c/input-events/v1/index.html#interface-InputEvent-Attributes
1298
+ // case "deleteWordBackward": {
1299
+ // const match = value
1300
+ // .substring(0, selectionStart)
1301
+ // .match(/\w*[^\w]*$/);
1302
+ // if (match) {
1303
+ // selStart -= match[0].length;
1304
+ // }
1305
+ // break;
1306
+ // }
1307
+ // case "deleteWordForward": {
1308
+ // const match = value
1309
+ // .substring(selectionStart)
1310
+ // .match(/^[^\w]*\w*/);
1311
+ // if (match) {
1312
+ // selEnd += match[0].length;
1313
+ // }
1314
+ // break;
1315
+ // }
1316
+ // case "deleteContentBackward":
1317
+ // if (selectionStart === selectionEnd) {
1318
+ // selStart -= 1;
1319
+ // }
1320
+ // break;
1321
+ // case "deleteContentForward":
1322
+ // if (selectionStart === selectionEnd) {
1323
+ // selEnd += 1;
1324
+ // }
1325
+ // break;
1326
+ // default: break;
1327
+ // }
1328
+ // // We handle the event ourselves.
1329
+ // event.preventDefault();
1330
+ // this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
1331
+ // source: this,
1332
+ // detail: {
1333
+ // id,
1334
+ // name: "Keystroke",
1335
+ // value,
1336
+ // change: data || "",
1337
+ // willCommit: false,
1338
+ // selStart,
1339
+ // selEnd,
1340
+ // },
1341
+ // });
1342
+ // });
1343
+ // }
1344
+ // this._setEventListeners(
1345
+ // element,
1346
+ // elementData,
1347
+ // [
1348
+ // ["focus", "Focus"],
1349
+ // ["blur", "Blur"],
1350
+ // ["mousedown", "Mouse Down"],
1351
+ // ["mouseenter", "Mouse Enter"],
1352
+ // ["mouseleave", "Mouse Exit"],
1353
+ // ["mouseup", "Mouse Up"],
1354
+ // ],
1355
+ // event => event.target.value
1356
+ // );
1357
+ // }
1358
+ // if (blurListener) {
1359
+ // element.addEventListener("blur", blurListener);
1360
+ // }
1361
+ // if (this.data.comb) {
1362
+ // const fieldWidth = this.data.rect[2] - this.data.rect[0];
1363
+ // const combWidth = fieldWidth / maxLen;
1364
+ // element.classList.add("comb");
1365
+ // element.style.letterSpacing = `calc(${combWidth}px * var(--scale-factor) - 1ch)`;
1366
+ // }
1367
+ // } else {
1368
+ // element = document.createElement("div");
1369
+ // element.textContent = this.data.fieldValue;
1370
+ // element.style.verticalAlign = "middle";
1371
+ // element.style.display = "table-cell";
1372
+ // if (this.data.hasOwnCanvas) {
1373
+ // element.hidden = true;
1374
+ // }
1375
+ // }
1376
+ // this._setTextStyle(element);
1377
+ // this._setBackgroundColor(element);
1378
+ // this._setDefaultPropertiesFromJS(element);
1379
+ // this.container.append(element);
1380
+ // return this.container;
1381
+ // }
1382
+ // }
1383
+ // class SignatureWidgetAnnotationElement extends WidgetAnnotationElement {
1384
+ // constructor(parameters) {
1385
+ // super(parameters, { isRenderable: !!parameters.data.hasOwnCanvas });
1386
+ // }
1387
+ // }
1388
+ // class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
1389
+ // constructor(parameters) {
1390
+ // super(parameters, { isRenderable: parameters.renderForms });
1391
+ // }
1392
+ // render() {
1393
+ // const storage = this.annotationStorage;
1394
+ // const data = this.data;
1395
+ // const id = data.id;
1396
+ // let value = storage.getValue(id, {
1397
+ // value: data.exportValue === data.fieldValue,
1398
+ // }).value;
1399
+ // if (typeof value === "string") {
1400
+ // // The value has been changed through js and set in annotationStorage.
1401
+ // value = value !== "Off";
1402
+ // storage.setValue(id, { value });
1403
+ // }
1404
+ // this.container.classList.add("buttonWidgetAnnotation", "checkBox");
1405
+ // const element = document.createElement("input");
1406
+ // GetElementsByNameSet.add(element);
1407
+ // element.setAttribute("data-element-id", id);
1408
+ // element.disabled = data.readOnly;
1409
+ // this._setRequired(element, this.data.required);
1410
+ // element.type = "checkbox";
1411
+ // element.name = data.fieldName;
1412
+ // if (value) {
1413
+ // element.setAttribute("checked", (true).toString());
1414
+ // }
1415
+ // element.setAttribute("exportValue", data.exportValue);
1416
+ // element.tabIndex = DEFAULT_TAB_INDEX;
1417
+ // element.addEventListener("change", event => {
1418
+ // const { name, checked } = event.target as any;
1419
+ // for (const checkbox of this._getElementsByName(name, /* skipId = */ id)) {
1420
+ // const curChecked = checked && checkbox.exportValue === data.exportValue;
1421
+ // if (checkbox.domElement) {
1422
+ // checkbox.domElement.checked = curChecked;
1423
+ // }
1424
+ // storage.setValue(checkbox.id, { value: curChecked });
1425
+ // }
1426
+ // storage.setValue(id, { value: checked });
1427
+ // });
1428
+ // element.addEventListener("resetform", event => {
1429
+ // const defaultValue = data.defaultFieldValue || "Off";
1430
+ // // @ts-expect-error(TS)
1431
+ // event.target.checked = defaultValue === data.exportValue;
1432
+ // });
1433
+ // if (this.enableScripting && this.hasJSActions) {
1434
+ // element.addEventListener("updatefromsandbox", jsEvent => {
1435
+ // const actions = {
1436
+ // value(event) {
1437
+ // event.target.checked = event.detail.value !== "Off";
1438
+ // storage.setValue(id, { value: event.target.checked });
1439
+ // },
1440
+ // };
1441
+ // this._dispatchEventFromSandbox(actions, jsEvent);
1442
+ // });
1443
+ // this._setEventListeners(
1444
+ // element,
1445
+ // null,
1446
+ // [
1447
+ // ["change", "Validate"],
1448
+ // ["change", "Action"],
1449
+ // ["focus", "Focus"],
1450
+ // ["blur", "Blur"],
1451
+ // ["mousedown", "Mouse Down"],
1452
+ // ["mouseenter", "Mouse Enter"],
1453
+ // ["mouseleave", "Mouse Exit"],
1454
+ // ["mouseup", "Mouse Up"],
1455
+ // ],
1456
+ // event => event.target.checked
1457
+ // );
1458
+ // }
1459
+ // this._setBackgroundColor(element);
1460
+ // this._setDefaultPropertiesFromJS(element);
1461
+ // this.container.append(element);
1462
+ // return this.container;
1463
+ // }
1464
+ // }
1465
+ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
1466
+ constructor(parameters) {
1467
+ super(parameters, { isRenderable: parameters.renderForms });
1468
+ }
1469
+ render() {
1470
+ this.container.classList.add("buttonWidgetAnnotation", "radioButton");
1471
+ const storage = this.annotationStorage;
1472
+ const data = this.data;
1473
+ const id = data.id;
1474
+ let value = storage.getValue(id, {
1475
+ value: data.fieldValue === data.buttonValue,
1476
+ }).value;
1477
+ if (typeof value === "string") {
1478
+ // The value has been changed through js and set in annotationStorage.
1479
+ value = value !== data.buttonValue;
1480
+ storage.setValue(id, { value });
1481
+ }
1482
+ if (value) {
1483
+ // It's possible that multiple radio buttons are checked.
1484
+ // So if this one is checked we just reset the other ones.
1485
+ // (see bug 1864136). Then when the other ones will be rendered they will
1486
+ // unchecked (because of their value in the storage).
1487
+ // Consequently, the first checked radio button will be the only checked
1488
+ // one.
1489
+ for (const radio of this._getElementsByName(data.fieldName,
1490
+ /* skipId = */ id)) {
1491
+ storage.setValue(radio.id, { value: false });
1492
+ }
1493
+ }
1494
+ const element = document.createElement("input");
1495
+ GetElementsByNameSet.add(element);
1496
+ element.setAttribute("data-element-id", id);
1497
+ element.disabled = data.readOnly;
1498
+ this._setRequired(element, this.data.required);
1499
+ element.type = "radio";
1500
+ element.name = data.fieldName;
1501
+ if (value) {
1502
+ element.setAttribute("checked", (true).toString());
1503
+ }
1504
+ element.tabIndex = DEFAULT_TAB_INDEX;
1505
+ element.addEventListener("change", event => {
1506
+ const { name, checked } = event.target;
1507
+ for (const radio of this._getElementsByName(name, /* skipId = */ id)) {
1508
+ storage.setValue(radio.id, { value: false });
1509
+ }
1510
+ storage.setValue(id, { value: checked });
1511
+ });
1512
+ element.addEventListener("resetform", event => {
1513
+ const defaultValue = data.defaultFieldValue;
1514
+ // @ts-expect-error(TS)
1515
+ event.target.checked =
1516
+ defaultValue !== null &&
1517
+ defaultValue !== undefined &&
1518
+ defaultValue === data.buttonValue;
1519
+ });
1520
+ if (this.enableScripting && this.hasJSActions) {
1521
+ const pdfButtonValue = data.buttonValue;
1522
+ element.addEventListener("updatefromsandbox", jsEvent => {
1523
+ const actions = {
1524
+ value: event => {
1525
+ const checked = pdfButtonValue === event.detail.value;
1526
+ for (const radio of this._getElementsByName(event.target.name)) {
1527
+ const curChecked = checked && radio.id === id;
1528
+ if (radio.domElement) {
1529
+ radio.domElement.checked = curChecked;
1530
+ }
1531
+ storage.setValue(radio.id, { value: curChecked });
1532
+ }
1533
+ },
1534
+ };
1535
+ this._dispatchEventFromSandbox(actions, jsEvent);
1536
+ });
1537
+ this._setEventListeners(element, null, [
1538
+ ["change", "Validate"],
1539
+ ["change", "Action"],
1540
+ ["focus", "Focus"],
1541
+ ["blur", "Blur"],
1542
+ ["mousedown", "Mouse Down"],
1543
+ ["mouseenter", "Mouse Enter"],
1544
+ ["mouseleave", "Mouse Exit"],
1545
+ ["mouseup", "Mouse Up"],
1546
+ ], event => event.target.checked);
1547
+ }
1548
+ this._setBackgroundColor(element);
1549
+ this._setDefaultPropertiesFromJS(element);
1550
+ this.container.append(element);
1551
+ return this.container;
1552
+ }
1553
+ }
1554
+ // class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
1555
+ // constructor(parameters) {
1556
+ // super(parameters, { ignoreBorder: parameters.data.hasAppearance });
1557
+ // }
1558
+ // render() {
1559
+ // // The rendering and functionality of a push button widget annotation is
1560
+ // // equal to that of a link annotation, but may have more functionality, such
1561
+ // // as performing actions on form fields (resetting, submitting, et cetera).
1562
+ // const container = super.render();
1563
+ // container.classList.add("buttonWidgetAnnotation", "pushButton");
1564
+ // const linkElement = container.lastChild;
1565
+ // if (this.enableScripting && this.hasJSActions && linkElement) {
1566
+ // this._setDefaultPropertiesFromJS(linkElement);
1567
+ // linkElement.addEventListener("updatefromsandbox", jsEvent => {
1568
+ // this._dispatchEventFromSandbox({}, jsEvent);
1569
+ // });
1570
+ // }
1571
+ // return container;
1572
+ // }
1573
+ // }
1574
+ // class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
1575
+ // constructor(parameters) {
1576
+ // super(parameters, { isRenderable: parameters.renderForms });
1577
+ // }
1578
+ // render() {
1579
+ // this.container.classList.add("choiceWidgetAnnotation");
1580
+ // const storage = this.annotationStorage;
1581
+ // const id = this.data.id;
1582
+ // const storedData = storage.getValue(id, {
1583
+ // value: this.data.fieldValue,
1584
+ // });
1585
+ // const selectElement = document.createElement("select");
1586
+ // GetElementsByNameSet.add(selectElement);
1587
+ // selectElement.setAttribute("data-element-id", id);
1588
+ // selectElement.disabled = this.data.readOnly;
1589
+ // this._setRequired(selectElement, this.data.required);
1590
+ // selectElement.name = this.data.fieldName;
1591
+ // selectElement.tabIndex = DEFAULT_TAB_INDEX;
1592
+ // let addAnEmptyEntry = this.data.combo && this.data.options.length > 0;
1593
+ // if (!this.data.combo) {
1594
+ // // List boxes have a size and (optionally) multiple selection.
1595
+ // selectElement.size = this.data.options.length;
1596
+ // if (this.data.multiSelect) {
1597
+ // selectElement.multiple = true;
1598
+ // }
1599
+ // }
1600
+ // selectElement.addEventListener("resetform", () => {
1601
+ // const defaultValue = this.data.defaultFieldValue;
1602
+ // for (const option of (selectElement as any).options) {
1603
+ // option.selected = option.value === defaultValue;
1604
+ // }
1605
+ // });
1606
+ // // Insert the options into the choice field.
1607
+ // for (const option of this.data.options) {
1608
+ // const optionElement = document.createElement("option");
1609
+ // optionElement.textContent = option.displayValue;
1610
+ // optionElement.value = option.exportValue;
1611
+ // if (storedData.value.includes(option.exportValue)) {
1612
+ // optionElement.setAttribute("selected", (true).toString());
1613
+ // addAnEmptyEntry = false;
1614
+ // }
1615
+ // selectElement.append(optionElement);
1616
+ // }
1617
+ // let removeEmptyEntry = null;
1618
+ // if (addAnEmptyEntry) {
1619
+ // const noneOptionElement = document.createElement("option");
1620
+ // noneOptionElement.value = " ";
1621
+ // noneOptionElement.setAttribute("hidden", (true).toString());
1622
+ // noneOptionElement.setAttribute("selected", (true).toString());
1623
+ // selectElement.prepend(noneOptionElement);
1624
+ // removeEmptyEntry = () => {
1625
+ // noneOptionElement.remove();
1626
+ // selectElement.removeEventListener("input", removeEmptyEntry);
1627
+ // removeEmptyEntry = null;
1628
+ // };
1629
+ // selectElement.addEventListener("input", removeEmptyEntry);
1630
+ // }
1631
+ // const getValue = isExport => {
1632
+ // const name = isExport ? "value" : "textContent";
1633
+ // const { options, multiple } = selectElement;
1634
+ // if (!multiple) {
1635
+ // return options.selectedIndex === -1
1636
+ // ? null
1637
+ // : options[options.selectedIndex][name];
1638
+ // }
1639
+ // return Array.prototype.filter
1640
+ // .call(options, option => option.selected)
1641
+ // .map(option => option[name]);
1642
+ // };
1643
+ // let selectedValues = getValue(/* isExport */ false);
1644
+ // const getItems = event => {
1645
+ // const options = event.target.options;
1646
+ // return Array.prototype.map.call(options, option => ({
1647
+ // displayValue: option.textContent,
1648
+ // exportValue: option.value,
1649
+ // }));
1650
+ // };
1651
+ // if (this.enableScripting && this.hasJSActions) {
1652
+ // selectElement.addEventListener("updatefromsandbox", jsEvent => {
1653
+ // const actions = {
1654
+ // value(event) {
1655
+ // removeEmptyEntry?.();
1656
+ // const value = event.detail.value;
1657
+ // const values = new Set(Array.isArray(value) ? value : [value]);
1658
+ // for (const option of (selectElement as any).options) {
1659
+ // option.selected = values.has(option.value);
1660
+ // }
1661
+ // storage.setValue(id, {
1662
+ // value: getValue(/* isExport */ true),
1663
+ // });
1664
+ // selectedValues = getValue(/* isExport */ false);
1665
+ // },
1666
+ // multipleSelection() {
1667
+ // selectElement.multiple = true;
1668
+ // },
1669
+ // remove(event) {
1670
+ // const options = selectElement.options;
1671
+ // const index = event.detail.remove;
1672
+ // options[index].selected = false;
1673
+ // selectElement.remove(index);
1674
+ // if (options.length > 0) {
1675
+ // const i = Array.prototype.findIndex.call(
1676
+ // options,
1677
+ // option => option.selected
1678
+ // );
1679
+ // if (i === -1) {
1680
+ // options[0].selected = true;
1681
+ // }
1682
+ // }
1683
+ // storage.setValue(id, {
1684
+ // value: getValue(/* isExport */ true),
1685
+ // items: getItems(event),
1686
+ // });
1687
+ // selectedValues = getValue(/* isExport */ false);
1688
+ // },
1689
+ // clear() {
1690
+ // while (selectElement.length !== 0) {
1691
+ // selectElement.remove(0);
1692
+ // }
1693
+ // storage.setValue(id, { value: null, items: [] });
1694
+ // selectedValues = getValue(/* isExport */ false);
1695
+ // },
1696
+ // insert(event) {
1697
+ // const { index, displayValue, exportValue } = event.detail.insert;
1698
+ // const selectChild = selectElement.children[index];
1699
+ // const optionElement = document.createElement("option");
1700
+ // optionElement.textContent = displayValue;
1701
+ // optionElement.value = exportValue;
1702
+ // if (selectChild) {
1703
+ // selectChild.before(optionElement);
1704
+ // } else {
1705
+ // selectElement.append(optionElement);
1706
+ // }
1707
+ // storage.setValue(id, {
1708
+ // value: getValue(/* isExport */ true),
1709
+ // items: getItems(event),
1710
+ // });
1711
+ // selectedValues = getValue(/* isExport */ false);
1712
+ // },
1713
+ // items(event) {
1714
+ // const { items } = event.detail;
1715
+ // while (selectElement.length !== 0) {
1716
+ // selectElement.remove(0);
1717
+ // }
1718
+ // for (const item of items) {
1719
+ // const { displayValue, exportValue } = item;
1720
+ // const optionElement = document.createElement("option");
1721
+ // optionElement.textContent = displayValue;
1722
+ // optionElement.value = exportValue;
1723
+ // selectElement.append(optionElement);
1724
+ // }
1725
+ // if (selectElement.options.length > 0) {
1726
+ // selectElement.options[0].selected = true;
1727
+ // }
1728
+ // storage.setValue(id, {
1729
+ // value: getValue(/* isExport */ true),
1730
+ // items: getItems(event),
1731
+ // });
1732
+ // selectedValues = getValue(/* isExport */ false);
1733
+ // },
1734
+ // indices(event) {
1735
+ // const indices = new Set(event.detail.indices);
1736
+ // for (const option of event.target.options) {
1737
+ // option.selected = indices.has(option.index);
1738
+ // }
1739
+ // storage.setValue(id, {
1740
+ // value: getValue(/* isExport */ true),
1741
+ // });
1742
+ // selectedValues = getValue(/* isExport */ false);
1743
+ // },
1744
+ // editable(event) {
1745
+ // event.target.disabled = !event.detail.editable;
1746
+ // },
1747
+ // };
1748
+ // this._dispatchEventFromSandbox(actions, jsEvent);
1749
+ // });
1750
+ // selectElement.addEventListener("input", event => {
1751
+ // const exportValue = getValue(/* isExport */ true);
1752
+ // const change = getValue(/* isExport */ false);
1753
+ // storage.setValue(id, { value: exportValue });
1754
+ // event.preventDefault();
1755
+ // this.linkService.eventBus?.dispatch("dispatcheventinsandbox", {
1756
+ // source: this,
1757
+ // detail: {
1758
+ // id,
1759
+ // name: "Keystroke",
1760
+ // value: selectedValues,
1761
+ // change,
1762
+ // changeEx: exportValue,
1763
+ // willCommit: false,
1764
+ // commitKey: 1,
1765
+ // keyDown: false,
1766
+ // },
1767
+ // });
1768
+ // });
1769
+ // this._setEventListeners(
1770
+ // selectElement,
1771
+ // null,
1772
+ // [
1773
+ // ["focus", "Focus"],
1774
+ // ["blur", "Blur"],
1775
+ // ["mousedown", "Mouse Down"],
1776
+ // ["mouseenter", "Mouse Enter"],
1777
+ // ["mouseleave", "Mouse Exit"],
1778
+ // ["mouseup", "Mouse Up"],
1779
+ // ["input", "Action"],
1780
+ // ["input", "Validate"],
1781
+ // ],
1782
+ // event => event.target.value
1783
+ // );
1784
+ // } else {
1785
+ // selectElement.addEventListener("input", function () {
1786
+ // storage.setValue(id, { value: getValue(/* isExport */ true) });
1787
+ // });
1788
+ // }
1789
+ // if (this.data.combo) {
1790
+ // this._setTextStyle(selectElement);
1791
+ // } else {
1792
+ // // Just use the default font size...
1793
+ // // it's a bit hard to guess what is a good size.
1794
+ // }
1795
+ // this._setBackgroundColor(selectElement);
1796
+ // this._setDefaultPropertiesFromJS(selectElement);
1797
+ // this.container.append(selectElement);
1798
+ // return this.container;
1799
+ // }
1800
+ // }
1801
+ class PopupAnnotationElement extends AnnotationElement {
1802
+ // todo: props
1803
+ constructor(parameters) {
1804
+ const { data, elements } = parameters;
1805
+ super(parameters, { isRenderable: AnnotationElement._hasPopupData(data) });
1806
+ // todo: props
1807
+ this.elements = [];
1808
+ this.elements = elements;
1809
+ this.popup = null;
1810
+ }
1811
+ render() {
1812
+ this.container.classList.add("popupAnnotation");
1813
+ const popup = (this.popup = new PopupElement({
1814
+ container: this.container,
1815
+ color: this.data.color,
1816
+ titleObj: this.data.titleObj,
1817
+ modificationDate: this.data.modificationDate,
1818
+ contentsObj: this.data.contentsObj,
1819
+ richText: this.data.richText,
1820
+ rect: this.data.rect,
1821
+ parentRect: this.data.parentRect || null,
1822
+ parent: this.parent,
1823
+ elements: this.elements,
1824
+ open: this.data.open,
1825
+ }));
1826
+ const elementIds = [];
1827
+ for (const element of this.elements) {
1828
+ element.popup = popup;
1829
+ elementIds.push(element.data.id);
1830
+ element.addHighlightArea();
1831
+ }
1832
+ this.container.setAttribute("aria-controls", elementIds.map(id => `${utils_1.AnnotationPrefix}${id}`).join(","));
1833
+ return this.container;
1834
+ }
1835
+ }
1836
+ class PopupElement {
1837
+ constructor({ container, color, elements, titleObj, modificationDate, contentsObj, richText, parent, rect, parentRect, open, }) {
1838
+ var _a;
1839
+ _PopupElement_instances.add(this);
1840
+ // todo: props
1841
+ this.trigger = null;
1842
+ // todo: props
1843
+ _PopupElement_boundKeyDown.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_keyDown).bind(this));
1844
+ _PopupElement_boundHide.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_hide).bind(this));
1845
+ _PopupElement_boundShow.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_show).bind(this));
1846
+ _PopupElement_boundToggle.set(this, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_toggle).bind(this));
1847
+ _PopupElement_color.set(this, null);
1848
+ _PopupElement_container.set(this, null);
1849
+ _PopupElement_contentsObj.set(this, null);
1850
+ _PopupElement_dateObj.set(this, null);
1851
+ _PopupElement_elements.set(this, null);
1852
+ _PopupElement_parent.set(this, null);
1853
+ _PopupElement_parentRect.set(this, null);
1854
+ _PopupElement_pinned.set(this, false);
1855
+ _PopupElement_popup.set(this, null);
1856
+ _PopupElement_position.set(this, null);
1857
+ _PopupElement_rect.set(this, null);
1858
+ _PopupElement_richText.set(this, null);
1859
+ _PopupElement_titleObj.set(this, null);
1860
+ _PopupElement_updates.set(this, null);
1861
+ _PopupElement_wasVisible.set(this, false);
1862
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_container, container, "f");
1863
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_titleObj, titleObj, "f");
1864
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_contentsObj, contentsObj, "f");
1865
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_richText, richText, "f");
1866
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_parent, parent, "f");
1867
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_color, color, "f");
1868
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_rect, rect, "f");
1869
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_parentRect, parentRect, "f");
1870
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_elements, elements, "f");
1871
+ // The modification date is shown in the popup instead of the creation
1872
+ // date if it is available and can be parsed correctly, which is
1873
+ // consistent with other viewers such as Adobe Acrobat.
1874
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_dateObj, pdf_mjs_1.PDFDateString.toDateObject(modificationDate), "f");
1875
+ this.trigger = elements.flatMap(e => e.getElementsToTriggerPopup());
1876
+ // Attach the event listeners to the trigger element.
1877
+ for (const element of this.trigger) {
1878
+ element.addEventListener("click", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundToggle, "f"));
1879
+ element.addEventListener("mouseenter", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundShow, "f"));
1880
+ element.addEventListener("mouseleave", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundHide, "f"));
1881
+ element.classList.add("popupTriggerArea");
1882
+ }
1883
+ // Attach the event listener to toggle the popup with the keyboard.
1884
+ for (const element of elements) {
1885
+ (_a = element.container) === null || _a === void 0 ? void 0 : _a.addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundKeyDown, "f"));
1886
+ }
1887
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = true;
1888
+ if (open) {
1889
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_toggle).call(this);
1890
+ }
1891
+ // if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
1892
+ // Since the popup is lazily created, we need to ensure that it'll be
1893
+ // created and displayed during reference tests.
1894
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_parent, "f").popupShow.push(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
1895
+ if (tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden) {
1896
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_show).call(this);
1897
+ }
1898
+ }));
1899
+ // }
1900
+ }
1901
+ render() {
1902
+ if (tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) {
1903
+ return;
1904
+ }
1905
+ const popup = (tslib_1.__classPrivateFieldSet(this, _PopupElement_popup, document.createElement("div"), "f"));
1906
+ popup.className = "popup";
1907
+ if (tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f")) {
1908
+ const baseColor = (popup.style.outlineColor = pdf_mjs_1.Util.makeHexColor(
1909
+ // @ts-expect-error TS(2556):
1910
+ ...tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f")));
1911
+ if (
1912
+ // (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
1913
+ CSS.supports("background-color", "color-mix(in srgb, red 30%, white)")) {
1914
+ popup.style.backgroundColor = `color-mix(in srgb, ${baseColor} 30%, white)`;
1915
+ }
1916
+ else {
1917
+ // color-mix isn't supported in some browsers hence this version.
1918
+ // See https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix#browser_compatibility
1919
+ // TODO: Use color-mix when it's supported everywhere.
1920
+ // Enlighten the color.
1921
+ const BACKGROUND_ENLIGHT = 0.7;
1922
+ popup.style.backgroundColor = pdf_mjs_1.Util.makeHexColor(
1923
+ // @ts-expect-error TS(2556):
1924
+ ...tslib_1.__classPrivateFieldGet(this, _PopupElement_color, "f").map(c => Math.floor(BACKGROUND_ENLIGHT * (255 - c) + c)));
1925
+ }
1926
+ }
1927
+ const header = document.createElement("span");
1928
+ header.className = "header";
1929
+ const title = document.createElement("h1");
1930
+ header.append(title);
1931
+ ({ dir: title.dir, str: title.textContent } = tslib_1.__classPrivateFieldGet(this, _PopupElement_titleObj, "f"));
1932
+ popup.append(header);
1933
+ if (tslib_1.__classPrivateFieldGet(this, _PopupElement_dateObj, "f")) {
1934
+ const modificationDate = document.createElement("span");
1935
+ modificationDate.classList.add("popupDate");
1936
+ modificationDate.setAttribute("data-l10n-id", "pdfjs-annotation-date-string");
1937
+ modificationDate.setAttribute("data-l10n-args", JSON.stringify({
1938
+ date: tslib_1.__classPrivateFieldGet(this, _PopupElement_dateObj, "f").toLocaleDateString(),
1939
+ time: tslib_1.__classPrivateFieldGet(this, _PopupElement_dateObj, "f").toLocaleTimeString(),
1940
+ }));
1941
+ header.append(modificationDate);
1942
+ }
1943
+ const html = tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get);
1944
+ if (html) {
1945
+ // @ts-expect-error TS(2556):
1946
+ pdf_mjs_1.XfaLayer.render({
1947
+ xfaHtml: html,
1948
+ intent: "richText",
1949
+ div: popup,
1950
+ });
1951
+ // @ts-expect-error TS(2556):
1952
+ popup.lastChild.classList.add("richText", "popupContent");
1953
+ }
1954
+ else {
1955
+ const contents = this._formatContents(tslib_1.__classPrivateFieldGet(this, _PopupElement_contentsObj, "f"));
1956
+ popup.append(contents);
1957
+ }
1958
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").append(popup);
1959
+ }
1960
+ /**
1961
+ * Format the contents of the popup by adding newlines where necessary.
1962
+ *
1963
+ * @private
1964
+ * @param {Object<string, string>} contentsObj
1965
+ * @memberof PopupElement
1966
+ * @returns {HTMLParagraphElement}
1967
+ */
1968
+ _formatContents({ str, dir }) {
1969
+ const p = document.createElement("p");
1970
+ p.classList.add("popupContent");
1971
+ p.dir = dir;
1972
+ const lines = str.split(/(?:\r\n?|\n)/);
1973
+ for (let i = 0, ii = lines.length; i < ii; ++i) {
1974
+ const line = lines[i];
1975
+ p.append(document.createTextNode(line));
1976
+ if (i < ii - 1) {
1977
+ p.append(document.createElement("br"));
1978
+ }
1979
+ }
1980
+ return p;
1981
+ }
1982
+ updateEdited({ rect, popupContent }) {
1983
+ var _a;
1984
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_updates, tslib_1.__classPrivateFieldGet(this, _PopupElement_updates, "f") || {
1985
+ contentsObj: tslib_1.__classPrivateFieldGet(this, _PopupElement_contentsObj, "f"),
1986
+ richText: tslib_1.__classPrivateFieldGet(this, _PopupElement_richText, "f"),
1987
+ }, "f");
1988
+ if (rect) {
1989
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_position, null, "f");
1990
+ }
1991
+ if (popupContent) {
1992
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_richText, tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_makePopupContent).call(this, popupContent), "f");
1993
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_contentsObj, null, "f");
1994
+ }
1995
+ (_a = tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) === null || _a === void 0 ? void 0 : _a.remove();
1996
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_popup, null, "f");
1997
+ }
1998
+ resetEdited() {
1999
+ var _a;
2000
+ var _b, _c;
2001
+ if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_updates, "f")) {
2002
+ return;
2003
+ }
2004
+ (_b = this, _c = this, { contentsObj: ({ set value(_a) { tslib_1.__classPrivateFieldSet(_b, _PopupElement_contentsObj, _a, "f"); } }).value, richText: ({ set value(_a) { tslib_1.__classPrivateFieldSet(_c, _PopupElement_richText, _a, "f"); } }).value } =
2005
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_updates, "f"));
2006
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_updates, null, "f");
2007
+ (_a = tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) === null || _a === void 0 ? void 0 : _a.remove();
2008
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_popup, null, "f");
2009
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_position, null, "f");
2010
+ }
2011
+ forceHide() {
2012
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_wasVisible, this.isVisible, "f");
2013
+ if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_wasVisible, "f")) {
2014
+ return;
2015
+ }
2016
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = true;
2017
+ }
2018
+ maybeShow() {
2019
+ if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_wasVisible, "f")) {
2020
+ return;
2021
+ }
2022
+ if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) {
2023
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_show).call(this);
2024
+ }
2025
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_wasVisible, false, "f");
2026
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = false;
2027
+ }
2028
+ get isVisible() {
2029
+ return tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden === false;
2030
+ }
2031
+ }
2032
+ _PopupElement_boundKeyDown = new WeakMap(), _PopupElement_boundHide = new WeakMap(), _PopupElement_boundShow = new WeakMap(), _PopupElement_boundToggle = new WeakMap(), _PopupElement_color = new WeakMap(), _PopupElement_container = new WeakMap(), _PopupElement_contentsObj = new WeakMap(), _PopupElement_dateObj = new WeakMap(), _PopupElement_elements = new WeakMap(), _PopupElement_parent = new WeakMap(), _PopupElement_parentRect = new WeakMap(), _PopupElement_pinned = new WeakMap(), _PopupElement_popup = new WeakMap(), _PopupElement_position = new WeakMap(), _PopupElement_rect = new WeakMap(), _PopupElement_richText = new WeakMap(), _PopupElement_titleObj = new WeakMap(), _PopupElement_updates = new WeakMap(), _PopupElement_wasVisible = new WeakMap(), _PopupElement_instances = new WeakSet(), _PopupElement_html_get = function _PopupElement_html_get() {
2033
+ const richText = tslib_1.__classPrivateFieldGet(this, _PopupElement_richText, "f");
2034
+ const contentsObj = tslib_1.__classPrivateFieldGet(this, _PopupElement_contentsObj, "f");
2035
+ if ((richText === null || richText === void 0 ? void 0 : richText.str) &&
2036
+ (!(contentsObj === null || contentsObj === void 0 ? void 0 : contentsObj.str) || contentsObj.str === richText.str)) {
2037
+ return tslib_1.__classPrivateFieldGet(this, _PopupElement_richText, "f").html || null;
2038
+ }
2039
+ return null;
2040
+ }, _PopupElement_fontSize_get = function _PopupElement_fontSize_get() {
2041
+ var _a, _b, _c;
2042
+ return ((_c = (_b = (_a = tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get)) === null || _a === void 0 ? void 0 : _a.attributes) === null || _b === void 0 ? void 0 : _b.style) === null || _c === void 0 ? void 0 : _c.fontSize) || 0;
2043
+ }, _PopupElement_fontColor_get = function _PopupElement_fontColor_get() {
2044
+ var _a, _b, _c;
2045
+ return ((_c = (_b = (_a = tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_html_get)) === null || _a === void 0 ? void 0 : _a.attributes) === null || _b === void 0 ? void 0 : _b.style) === null || _c === void 0 ? void 0 : _c.color) || null;
2046
+ }, _PopupElement_makePopupContent = function _PopupElement_makePopupContent(text) {
2047
+ const popupLines = [];
2048
+ const popupContent = {
2049
+ str: text,
2050
+ html: {
2051
+ name: "div",
2052
+ attributes: {
2053
+ dir: "auto",
2054
+ },
2055
+ children: [
2056
+ {
2057
+ name: "p",
2058
+ children: popupLines,
2059
+ },
2060
+ ],
2061
+ },
2062
+ };
2063
+ const lineAttributes = {
2064
+ style: {
2065
+ color: tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_fontColor_get),
2066
+ fontSize: tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_fontSize_get)
2067
+ ? `calc(${tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "a", _PopupElement_fontSize_get)}px * var(--scale-factor))`
2068
+ : "",
2069
+ },
2070
+ };
2071
+ for (const line of text.split("\n")) {
2072
+ popupLines.push({
2073
+ name: "span",
2074
+ value: line,
2075
+ attributes: lineAttributes,
2076
+ });
2077
+ }
2078
+ return popupContent;
2079
+ }, _PopupElement_keyDown = function _PopupElement_keyDown(event) {
2080
+ if (event.altKey || event.shiftKey || event.ctrlKey || event.metaKey) {
2081
+ return;
2082
+ }
2083
+ if (event.key === "Enter" || (event.key === "Escape" && tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f"))) {
2084
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_toggle).call(this);
2085
+ }
2086
+ }, _PopupElement_setPosition = function _PopupElement_setPosition() {
2087
+ if (tslib_1.__classPrivateFieldGet(this, _PopupElement_position, "f") !== null) {
2088
+ return;
2089
+ }
2090
+ const { page: { view }, viewport: { rawDims: { pageWidth, pageHeight, pageX, pageY }, }, } = tslib_1.__classPrivateFieldGet(this, _PopupElement_parent, "f");
2091
+ let useParentRect = !!tslib_1.__classPrivateFieldGet(this, _PopupElement_parentRect, "f");
2092
+ let rect = useParentRect ? tslib_1.__classPrivateFieldGet(this, _PopupElement_parentRect, "f") : tslib_1.__classPrivateFieldGet(this, _PopupElement_rect, "f");
2093
+ for (const element of tslib_1.__classPrivateFieldGet(this, _PopupElement_elements, "f")) {
2094
+ if (!rect || pdf_mjs_1.Util.intersect(element.data.rect, rect) !== null) {
2095
+ rect = element.data.rect;
2096
+ useParentRect = true;
2097
+ break;
2098
+ }
2099
+ }
2100
+ const normalizedRect = pdf_mjs_1.Util.normalizeRect([
2101
+ rect[0],
2102
+ view[3] - rect[1] + view[1],
2103
+ rect[2],
2104
+ view[3] - rect[3] + view[1],
2105
+ ]);
2106
+ const HORIZONTAL_SPACE_AFTER_ANNOTATION = 5;
2107
+ const parentWidth = useParentRect
2108
+ ? rect[2] - rect[0] + HORIZONTAL_SPACE_AFTER_ANNOTATION
2109
+ : 0;
2110
+ const popupLeft = normalizedRect[0] + parentWidth;
2111
+ const popupTop = normalizedRect[1];
2112
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_position, [
2113
+ (100 * (popupLeft - pageX)) / pageWidth,
2114
+ (100 * (popupTop - pageY)) / pageHeight,
2115
+ ], "f");
2116
+ const { style } = tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f");
2117
+ style.left = `${tslib_1.__classPrivateFieldGet(this, _PopupElement_position, "f")[0]}%`;
2118
+ style.top = `${tslib_1.__classPrivateFieldGet(this, _PopupElement_position, "f")[1]}%`;
2119
+ }, _PopupElement_toggle = function _PopupElement_toggle() {
2120
+ tslib_1.__classPrivateFieldSet(this, _PopupElement_pinned, !tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f"), "f");
2121
+ if (tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f")) {
2122
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_show).call(this);
2123
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").addEventListener("click", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundToggle, "f"));
2124
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").addEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundKeyDown, "f"));
2125
+ }
2126
+ else {
2127
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_hide).call(this);
2128
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").removeEventListener("click", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundToggle, "f"));
2129
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").removeEventListener("keydown", tslib_1.__classPrivateFieldGet(this, _PopupElement_boundKeyDown, "f"));
2130
+ }
2131
+ }, _PopupElement_show = function _PopupElement_show() {
2132
+ if (!tslib_1.__classPrivateFieldGet(this, _PopupElement_popup, "f")) {
2133
+ this.render();
2134
+ }
2135
+ if (!this.isVisible) {
2136
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_instances, "m", _PopupElement_setPosition).call(this);
2137
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = false;
2138
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex = (parseInt(tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex, 10) + 1000).toString();
2139
+ }
2140
+ else if (tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f")) {
2141
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").classList.add("focused");
2142
+ }
2143
+ }, _PopupElement_hide = function _PopupElement_hide() {
2144
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").classList.remove("focused");
2145
+ if (tslib_1.__classPrivateFieldGet(this, _PopupElement_pinned, "f") || !this.isVisible) {
2146
+ return;
2147
+ }
2148
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").hidden = true;
2149
+ tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex = (parseInt(tslib_1.__classPrivateFieldGet(this, _PopupElement_container, "f").style.zIndex, 10) - 1000).toString();
2150
+ };
2151
+ class FreeTextAnnotationElement extends AnnotationElement {
2152
+ // todo: props
2153
+ constructor(parameters) {
2154
+ super(parameters, { isRenderable: true, ignoreBorder: true });
2155
+ // todo: props
2156
+ this.textContent = null;
2157
+ this.textPosition = null;
2158
+ this.textContent = parameters.data.textContent;
2159
+ this.textPosition = parameters.data.textPosition;
2160
+ this.annotationEditorType = pdf_mjs_1.AnnotationEditorType.FREETEXT;
2161
+ }
2162
+ render() {
2163
+ // this.container.classList.add("freeTextAnnotation");
2164
+ // this.container.classList.add("freeTextAnnotation");
2165
+ this.container.classList.add("k-free-text-annotation");
2166
+ if (this.textContent) {
2167
+ const content = document.createElement("div");
2168
+ // content.classList.add("annotationTextContent");
2169
+ content.classList.add("k-annotation-text-content");
2170
+ content.setAttribute("role", "comment");
2171
+ for (const line of this.textContent) {
2172
+ const lineSpan = document.createElement("span");
2173
+ lineSpan.textContent = line;
2174
+ content.append(lineSpan);
2175
+ }
2176
+ this.container.append(content);
2177
+ }
2178
+ // if (!this.data.popupRef && this.hasPopupData) {
2179
+ // this._createPopup();
2180
+ // }
2181
+ this._editOnDoubleClick();
2182
+ return this.container;
2183
+ }
2184
+ }
2185
+ exports.FreeTextAnnotationElement = FreeTextAnnotationElement;
2186
+ // class LineAnnotationElement extends AnnotationElement {
2187
+ // #line = null;
2188
+ // constructor(parameters) {
2189
+ // super(parameters, { isRenderable: true, ignoreBorder: true });
2190
+ // }
2191
+ // render() {
2192
+ // this.container.classList.add("lineAnnotation");
2193
+ // // Create an invisible line with the same starting and ending coordinates
2194
+ // // that acts as the trigger for the popup. Only the line itself should
2195
+ // // trigger the popup, not the entire container.
2196
+ // const data = this.data;
2197
+ // const { width, height } = getRectDims(data.rect);
2198
+ // const svg = this.svgFactory.create(
2199
+ // width,
2200
+ // height,
2201
+ // /* skipDimensions = */ true
2202
+ // );
2203
+ // // PDF coordinates are calculated from a bottom left origin, so transform
2204
+ // // the line coordinates to a top left origin for the SVG element.
2205
+ // const line = (this.#line = this.svgFactory.createElement("svg:line"));
2206
+ // line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
2207
+ // line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
2208
+ // line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
2209
+ // line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
2210
+ // // Ensure that the 'stroke-width' is always non-zero, since otherwise it
2211
+ // // won't be possible to open/close the popup (note e.g. issue 11122).
2212
+ // line.setAttribute("stroke-width", data.borderStyle.width || 1);
2213
+ // line.setAttribute("stroke", "transparent");
2214
+ // line.setAttribute("fill", "transparent");
2215
+ // svg.append(line);
2216
+ // this.container.append(svg);
2217
+ // // Create the popup ourselves so that we can bind it to the line instead
2218
+ // // of to the entire container (which is the default).
2219
+ // if (!data.popupRef && this.hasPopupData) {
2220
+ // this._createPopup();
2221
+ // }
2222
+ // return this.container;
2223
+ // }
2224
+ // getElementsToTriggerPopup() {
2225
+ // return this.#line;
2226
+ // }
2227
+ // addHighlightArea() {
2228
+ // this.container.classList.add("highlightArea");
2229
+ // }
2230
+ // }
2231
+ // class SquareAnnotationElement extends AnnotationElement {
2232
+ // #square = null;
2233
+ // constructor(parameters) {
2234
+ // super(parameters, { isRenderable: true, ignoreBorder: true });
2235
+ // }
2236
+ // render() {
2237
+ // this.container.classList.add("squareAnnotation");
2238
+ // // Create an invisible square with the same rectangle that acts as the
2239
+ // // trigger for the popup. Only the square itself should trigger the
2240
+ // // popup, not the entire container.
2241
+ // const data = this.data;
2242
+ // const { width, height } = getRectDims(data.rect);
2243
+ // const svg = this.svgFactory.create(
2244
+ // width,
2245
+ // height,
2246
+ // /* skipDimensions = */ true
2247
+ // );
2248
+ // // The browser draws half of the borders inside the square and half of
2249
+ // // the borders outside the square by default. This behavior cannot be
2250
+ // // changed programmatically, so correct for that here.
2251
+ // const borderWidth = data.borderStyle.width;
2252
+ // const square = (this.#square = this.svgFactory.createElement("svg:rect"));
2253
+ // square.setAttribute("x", borderWidth / 2);
2254
+ // square.setAttribute("y", borderWidth / 2);
2255
+ // square.setAttribute("width", width - borderWidth);
2256
+ // square.setAttribute("height", height - borderWidth);
2257
+ // // Ensure that the 'stroke-width' is always non-zero, since otherwise it
2258
+ // // won't be possible to open/close the popup (note e.g. issue 11122).
2259
+ // square.setAttribute("stroke-width", borderWidth || 1);
2260
+ // square.setAttribute("stroke", "transparent");
2261
+ // square.setAttribute("fill", "transparent");
2262
+ // svg.append(square);
2263
+ // this.container.append(svg);
2264
+ // // Create the popup ourselves so that we can bind it to the square instead
2265
+ // // of to the entire container (which is the default).
2266
+ // if (!data.popupRef && this.hasPopupData) {
2267
+ // this._createPopup();
2268
+ // }
2269
+ // return this.container;
2270
+ // }
2271
+ // getElementsToTriggerPopup() {
2272
+ // return this.#square;
2273
+ // }
2274
+ // addHighlightArea() {
2275
+ // this.container.classList.add("highlightArea");
2276
+ // }
2277
+ // }
2278
+ // class CircleAnnotationElement extends AnnotationElement {
2279
+ // #circle = null;
2280
+ // constructor(parameters) {
2281
+ // super(parameters, { isRenderable: true, ignoreBorder: true });
2282
+ // }
2283
+ // render() {
2284
+ // this.container.classList.add("circleAnnotation");
2285
+ // // Create an invisible circle with the same ellipse that acts as the
2286
+ // // trigger for the popup. Only the circle itself should trigger the
2287
+ // // popup, not the entire container.
2288
+ // const data = this.data;
2289
+ // const { width, height } = getRectDims(data.rect);
2290
+ // const svg = this.svgFactory.create(
2291
+ // width,
2292
+ // height,
2293
+ // /* skipDimensions = */ true
2294
+ // );
2295
+ // // The browser draws half of the borders inside the circle and half of
2296
+ // // the borders outside the circle by default. This behavior cannot be
2297
+ // // changed programmatically, so correct for that here.
2298
+ // const borderWidth = data.borderStyle.width;
2299
+ // const circle = (this.#circle =
2300
+ // this.svgFactory.createElement("svg:ellipse"));
2301
+ // circle.setAttribute("cx", width / 2);
2302
+ // circle.setAttribute("cy", height / 2);
2303
+ // circle.setAttribute("rx", width / 2 - borderWidth / 2);
2304
+ // circle.setAttribute("ry", height / 2 - borderWidth / 2);
2305
+ // // Ensure that the 'stroke-width' is always non-zero, since otherwise it
2306
+ // // won't be possible to open/close the popup (note e.g. issue 11122).
2307
+ // circle.setAttribute("stroke-width", borderWidth || 1);
2308
+ // circle.setAttribute("stroke", "transparent");
2309
+ // circle.setAttribute("fill", "transparent");
2310
+ // svg.append(circle);
2311
+ // this.container.append(svg);
2312
+ // // Create the popup ourselves so that we can bind it to the circle instead
2313
+ // // of to the entire container (which is the default).
2314
+ // if (!data.popupRef && this.hasPopupData) {
2315
+ // this._createPopup();
2316
+ // }
2317
+ // return this.container;
2318
+ // }
2319
+ // getElementsToTriggerPopup() {
2320
+ // return this.#circle;
2321
+ // }
2322
+ // addHighlightArea() {
2323
+ // this.container.classList.add("highlightArea");
2324
+ // }
2325
+ // }
2326
+ // class PolylineAnnotationElement extends AnnotationElement {
2327
+ // // todo: props
2328
+ // containerClassName: any = null;
2329
+ // svgElementName: any = null;
2330
+ // // todo: props
2331
+ // #polyline = null;
2332
+ // constructor(parameters) {
2333
+ // super(parameters, { isRenderable: true, ignoreBorder: true });
2334
+ // this.containerClassName = "polylineAnnotation";
2335
+ // this.svgElementName = "svg:polyline";
2336
+ // }
2337
+ // render() {
2338
+ // this.container.classList.add(this.containerClassName);
2339
+ // // Create an invisible polyline with the same points that acts as the
2340
+ // // trigger for the popup. Only the polyline itself should trigger the
2341
+ // // popup, not the entire container.
2342
+ // const {
2343
+ // data: { rect, vertices, borderStyle, popupRef },
2344
+ // } = this;
2345
+ // if (!vertices) {
2346
+ // return this.container;
2347
+ // }
2348
+ // const { width, height } = getRectDims(rect);
2349
+ // const svg = this.svgFactory.create(
2350
+ // width,
2351
+ // height,
2352
+ // /* skipDimensions = */ true
2353
+ // );
2354
+ // // Convert the vertices array to a single points string that the SVG
2355
+ // // polyline element expects ("x1,y1 x2,y2 ..."). PDF coordinates are
2356
+ // // calculated from a bottom left origin, so transform the polyline
2357
+ // // coordinates to a top left origin for the SVG element.
2358
+ // const pointsArray = [];
2359
+ // for (let i = 0, ii = vertices.length; i < ii; i += 2) {
2360
+ // const x = vertices[i] - rect[0];
2361
+ // const y = rect[3] - vertices[i + 1];
2362
+ // pointsArray.push(`${x},${y}`);
2363
+ // }
2364
+ // const points = pointsArray.join(" ");
2365
+ // const polyline = (this.#polyline = this.svgFactory.createElement(
2366
+ // this.svgElementName
2367
+ // ));
2368
+ // polyline.setAttribute("points", points);
2369
+ // // Ensure that the 'stroke-width' is always non-zero, since otherwise it
2370
+ // // won't be possible to open/close the popup (note e.g. issue 11122).
2371
+ // polyline.setAttribute("stroke-width", borderStyle.width || 1);
2372
+ // polyline.setAttribute("stroke", "transparent");
2373
+ // polyline.setAttribute("fill", "transparent");
2374
+ // svg.append(polyline);
2375
+ // this.container.append(svg);
2376
+ // // Create the popup ourselves so that we can bind it to the polyline
2377
+ // // instead of to the entire container (which is the default).
2378
+ // if (!popupRef && this.hasPopupData) {
2379
+ // this._createPopup();
2380
+ // }
2381
+ // return this.container;
2382
+ // }
2383
+ // getElementsToTriggerPopup() {
2384
+ // return this.#polyline;
2385
+ // }
2386
+ // addHighlightArea() {
2387
+ // this.container.classList.add("highlightArea");
2388
+ // }
2389
+ // }
2390
+ // class PolygonAnnotationElement extends PolylineAnnotationElement {
2391
+ // constructor(parameters) {
2392
+ // // Polygons are specific forms of polylines, so reuse their logic.
2393
+ // super(parameters);
2394
+ // this.containerClassName = "polygonAnnotation";
2395
+ // this.svgElementName = "svg:polygon";
2396
+ // }
2397
+ // }
2398
+ // class CaretAnnotationElement extends AnnotationElement {
2399
+ // constructor(parameters) {
2400
+ // super(parameters, { isRenderable: true, ignoreBorder: true });
2401
+ // }
2402
+ // render() {
2403
+ // this.container.classList.add("caretAnnotation");
2404
+ // if (!this.data.popupRef && this.hasPopupData) {
2405
+ // this._createPopup();
2406
+ // }
2407
+ // return this.container;
2408
+ // }
2409
+ // }
2410
+ // class InkAnnotationElement extends AnnotationElement {
2411
+ // // todo: props
2412
+ // containerClassName: any = null;
2413
+ // svgElementName: any = null;
2414
+ // // todo: props
2415
+ // #polylines = [];
2416
+ // constructor(parameters) {
2417
+ // super(parameters, { isRenderable: true, ignoreBorder: true });
2418
+ // this.containerClassName = "inkAnnotation";
2419
+ // // Use the polyline SVG element since it allows us to use coordinates
2420
+ // // directly and to draw both straight lines and curves.
2421
+ // this.svgElementName = "svg:polyline";
2422
+ // this.annotationEditorType = AnnotationEditorType.INK;
2423
+ // }
2424
+ // render() {
2425
+ // this.container.classList.add(this.containerClassName);
2426
+ // // Create an invisible polyline with the same points that acts as the
2427
+ // // trigger for the popup.
2428
+ // const {
2429
+ // data: { rect, inkLists, borderStyle, popupRef },
2430
+ // } = this;
2431
+ // const { width, height } = getRectDims(rect);
2432
+ // const svg = this.svgFactory.create(
2433
+ // width,
2434
+ // height,
2435
+ // /* skipDimensions = */ true
2436
+ // );
2437
+ // for (const inkList of inkLists) {
2438
+ // // Convert the ink list to a single points string that the SVG
2439
+ // // polyline element expects ("x1,y1 x2,y2 ..."). PDF coordinates are
2440
+ // // calculated from a bottom left origin, so transform the polyline
2441
+ // // coordinates to a top left origin for the SVG element.
2442
+ // const pointsArray = [];
2443
+ // for (let i = 0, ii = inkList.length; i < ii; i += 2) {
2444
+ // const x = inkList[i] - rect[0];
2445
+ // const y = rect[3] - inkList[i + 1];
2446
+ // pointsArray.push(`${x},${y}`);
2447
+ // }
2448
+ // const points = pointsArray.join(" ");
2449
+ // const polyline = this.svgFactory.createElement(this.svgElementName);
2450
+ // this.#polylines.push(polyline);
2451
+ // polyline.setAttribute("points", points);
2452
+ // // Ensure that the 'stroke-width' is always non-zero, since otherwise it
2453
+ // // won't be possible to open/close the popup (note e.g. issue 11122).
2454
+ // polyline.setAttribute("stroke-width", borderStyle.width || 1);
2455
+ // polyline.setAttribute("stroke", "transparent");
2456
+ // polyline.setAttribute("fill", "transparent");
2457
+ // // Create the popup ourselves so that we can bind it to the polyline
2458
+ // // instead of to the entire container (which is the default).
2459
+ // if (!popupRef && this.hasPopupData) {
2460
+ // this._createPopup();
2461
+ // }
2462
+ // svg.append(polyline);
2463
+ // }
2464
+ // this.container.append(svg);
2465
+ // return this.container;
2466
+ // }
2467
+ // getElementsToTriggerPopup() {
2468
+ // return this.#polylines;
2469
+ // }
2470
+ // addHighlightArea() {
2471
+ // this.container.classList.add("highlightArea");
2472
+ // }
2473
+ // }
2474
+ class HighlightAnnotationElement extends AnnotationElement {
2475
+ constructor(parameters) {
2476
+ super(parameters, {
2477
+ isRenderable: true,
2478
+ ignoreBorder: true,
2479
+ createQuadrilaterals: true,
2480
+ });
2481
+ }
2482
+ render() {
2483
+ // if (!this.data.popupRef && this.hasPopupData) {
2484
+ // this._createPopup();
2485
+ // }
2486
+ // this.container.classList.add("highlightAnnotation");
2487
+ this.container.classList.add("k-highlight-annotation");
2488
+ return this.container;
2489
+ }
2490
+ }
2491
+ // class UnderlineAnnotationElement extends AnnotationElement {
2492
+ // constructor(parameters) {
2493
+ // super(parameters, {
2494
+ // isRenderable: true,
2495
+ // ignoreBorder: true,
2496
+ // createQuadrilaterals: true,
2497
+ // });
2498
+ // }
2499
+ // render() {
2500
+ // if (!this.data.popupRef && this.hasPopupData) {
2501
+ // this._createPopup();
2502
+ // }
2503
+ // this.container.classList.add("underlineAnnotation");
2504
+ // return this.container;
2505
+ // }
2506
+ // }
2507
+ // class SquigglyAnnotationElement extends AnnotationElement {
2508
+ // constructor(parameters) {
2509
+ // super(parameters, {
2510
+ // isRenderable: true,
2511
+ // ignoreBorder: true,
2512
+ // createQuadrilaterals: true,
2513
+ // });
2514
+ // }
2515
+ // render() {
2516
+ // if (!this.data.popupRef && this.hasPopupData) {
2517
+ // this._createPopup();
2518
+ // }
2519
+ // this.container.classList.add("squigglyAnnotation");
2520
+ // return this.container;
2521
+ // }
2522
+ // }
2523
+ // class StrikeOutAnnotationElement extends AnnotationElement {
2524
+ // constructor(parameters) {
2525
+ // super(parameters, {
2526
+ // isRenderable: true,
2527
+ // ignoreBorder: true,
2528
+ // createQuadrilaterals: true,
2529
+ // });
2530
+ // }
2531
+ // render() {
2532
+ // if (!this.data.popupRef && this.hasPopupData) {
2533
+ // this._createPopup();
2534
+ // }
2535
+ // this.container.classList.add("strikeoutAnnotation");
2536
+ // return this.container;
2537
+ // }
2538
+ // }
2539
+ // class StampAnnotationElement extends AnnotationElement {
2540
+ // constructor(parameters) {
2541
+ // super(parameters, { isRenderable: true, ignoreBorder: true });
2542
+ // }
2543
+ // render() {
2544
+ // this.container.classList.add("stampAnnotation");
2545
+ // if (!this.data.popupRef && this.hasPopupData) {
2546
+ // this._createPopup();
2547
+ // }
2548
+ // return this.container;
2549
+ // }
2550
+ // }
2551
+ // class FileAttachmentAnnotationElement extends AnnotationElement {
2552
+ // // todo: props
2553
+ // filename: any = null;
2554
+ // content: any = null;
2555
+ // // todo: props
2556
+ // #trigger = null;
2557
+ // constructor(parameters) {
2558
+ // super(parameters, { isRenderable: true });
2559
+ // const { file } = this.data;
2560
+ // this.filename = file.filename;
2561
+ // this.content = file.content;
2562
+ // this.linkService.eventBus?.dispatch("fileattachmentannotation", {
2563
+ // source: this,
2564
+ // ...file,
2565
+ // });
2566
+ // }
2567
+ // render() {
2568
+ // this.container.classList.add("fileAttachmentAnnotation");
2569
+ // const { container, data } = this;
2570
+ // let trigger;
2571
+ // if (data.hasAppearance || data.fillAlpha === 0) {
2572
+ // trigger = document.createElement("div");
2573
+ // } else {
2574
+ // // Unfortunately it seems that it's not clearly specified exactly what
2575
+ // // names are actually valid, since Table 184 contains:
2576
+ // // Conforming readers shall provide predefined icon appearances for at
2577
+ // // least the following standard names: GraphPushPin, PaperclipTag.
2578
+ // // Additional names may be supported as well. Default value: PushPin.
2579
+ // trigger = document.createElement("img");
2580
+ // trigger.src = `${this.imageResourcesPath}annotation-${/paperclip/i.test(data.name) ?
2581
+ // "paperclip" : "pushpin"}.svg`;
2582
+ // if (data.fillAlpha && data.fillAlpha < 1) {
2583
+ // trigger.style = `filter: opacity(${Math.round(
2584
+ // data.fillAlpha * 100
2585
+ // )}%);`;
2586
+ // // todo: debug
2587
+ // // if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
2588
+ // // this.container.classList.add("hasFillAlpha");
2589
+ // // }
2590
+ // }
2591
+ // }
2592
+ // trigger.addEventListener("dblclick", this.#download.bind(this));
2593
+ // this.#trigger = trigger;
2594
+ // const { isMac } = FeatureTest.platform;
2595
+ // container.addEventListener("keydown", evt => {
2596
+ // if (evt.key === "Enter" && (isMac ? evt.metaKey : evt.ctrlKey)) {
2597
+ // this.#download();
2598
+ // }
2599
+ // });
2600
+ // if (!data.popupRef && this.hasPopupData) {
2601
+ // this._createPopup();
2602
+ // } else {
2603
+ // trigger.classList.add("popupTriggerArea");
2604
+ // }
2605
+ // container.append(trigger);
2606
+ // return container;
2607
+ // }
2608
+ // getElementsToTriggerPopup() {
2609
+ // return this.#trigger;
2610
+ // }
2611
+ // addHighlightArea() {
2612
+ // this.container.classList.add("highlightArea");
2613
+ // }
2614
+ // /**
2615
+ // * Download the file attachment associated with this annotation.
2616
+ // */
2617
+ // #download() {
2618
+ // this.downloadManager?.openOrDownloadData(this.content, this.filename);
2619
+ // }
2620
+ // }
2621
+ /**
2622
+ * Manage the layer containing all the annotations.
2623
+ */
2624
+ class AnnotationLayer {
2625
+ constructor({ div, accessibilityManager, annotationCanvasMap, annotationEditorUIManager, page, viewport }) {
2626
+ _AnnotationLayer_instances.add(this);
2627
+ this.div = null;
2628
+ this.page = null;
2629
+ this.viewport = null;
2630
+ this.zIndex = null;
2631
+ this._annotationEditorUIManager = null;
2632
+ _AnnotationLayer_accessibilityManager.set(this, null);
2633
+ _AnnotationLayer_annotationCanvasMap.set(this, null);
2634
+ _AnnotationLayer_editableAnnotations.set(this, new Map());
2635
+ this.div = div;
2636
+ tslib_1.__classPrivateFieldSet(this, _AnnotationLayer_accessibilityManager, accessibilityManager, "f");
2637
+ tslib_1.__classPrivateFieldSet(this, _AnnotationLayer_annotationCanvasMap, annotationCanvasMap, "f");
2638
+ this.page = page;
2639
+ this.viewport = viewport;
2640
+ this.zIndex = 0;
2641
+ this._annotationEditorUIManager = annotationEditorUIManager;
2642
+ // if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
2643
+ // // For testing purposes.
2644
+ // Object.defineProperty(this, "showPopups", {
2645
+ // value: async () => {
2646
+ // for (const show of this.popupShow) {
2647
+ // await show();
2648
+ // }
2649
+ // },
2650
+ // });
2651
+ // this.popupShow = [];
2652
+ // }
2653
+ }
2654
+ // todo: ported from AnnotationLayerBuilder
2655
+ hide() {
2656
+ if (!this.div) {
2657
+ return;
2658
+ }
2659
+ this.div.hidden = true;
2660
+ }
2661
+ // todo: ported from AnnotationLayerBuilder
2662
+ hasEditableAnnotations() {
2663
+ return tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").size > 0;
2664
+ }
2665
+ /**
2666
+ * Render a new annotation layer with all annotation elements.
2667
+ *
2668
+ * @param {AnnotationLayerParameters} params
2669
+ * @memberof AnnotationLayer
2670
+ */
2671
+ // async render(params) {
2672
+ render(params) {
2673
+ var _a;
2674
+ const { annotations } = params;
2675
+ const layer = this.div;
2676
+ (0, pdf_mjs_1.setLayerDimensions)(layer, this.viewport);
2677
+ const popupToElements = new Map();
2678
+ const elementParams = {
2679
+ data: null,
2680
+ layer,
2681
+ linkService: params.linkService,
2682
+ downloadManager: params.downloadManager,
2683
+ imageResourcesPath: params.imageResourcesPath || "",
2684
+ renderForms: params.renderForms !== false,
2685
+ svgFactory: new pdf_mjs_1.DOMSVGFactory(),
2686
+ annotationStorage: params.annotationStorage,
2687
+ enableScripting: params.enableScripting === true,
2688
+ hasJSActions: params.hasJSActions,
2689
+ fieldObjects: params.fieldObjects,
2690
+ parent: this,
2691
+ elements: null,
2692
+ };
2693
+ for (const data of annotations) {
2694
+ if (data.noHTML) {
2695
+ continue;
2696
+ }
2697
+ const isPopupAnnotation = data.annotationType === utils_1.AnnotationType.POPUP;
2698
+ if (!isPopupAnnotation) {
2699
+ const { width, height } = getRectDims(data.rect);
2700
+ if (width <= 0 || height <= 0) {
2701
+ continue; // Ignore empty annotations.
2702
+ }
2703
+ }
2704
+ else {
2705
+ const elements = popupToElements.get(data.id);
2706
+ if (!elements) {
2707
+ // Ignore popup annotations without a corresponding annotation.
2708
+ continue;
2709
+ }
2710
+ elementParams.elements = elements;
2711
+ }
2712
+ elementParams.data = data;
2713
+ const element = AnnotationElementFactory.create(elementParams);
2714
+ if (!element.isRenderable) {
2715
+ continue;
2716
+ }
2717
+ if (!isPopupAnnotation && data.popupRef) {
2718
+ const elements = popupToElements.get(data.popupRef);
2719
+ if (!elements) {
2720
+ popupToElements.set(data.popupRef, [element]);
2721
+ }
2722
+ else {
2723
+ elements.push(element);
2724
+ }
2725
+ }
2726
+ const rendered = element.render();
2727
+ if (data.hidden) {
2728
+ rendered.style.visibility = "hidden";
2729
+ }
2730
+ tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_instances, "m", _AnnotationLayer_appendElement).call(this, rendered, data.id);
2731
+ if (element._isEditable) {
2732
+ tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").set(element.data.id, element);
2733
+ (_a = this._annotationEditorUIManager) === null || _a === void 0 ? void 0 : _a.renderAnnotationElement(element);
2734
+ }
2735
+ }
2736
+ tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_instances, "m", _AnnotationLayer_setAnnotationCanvasMap).call(this);
2737
+ }
2738
+ /**
2739
+ * Update the annotation elements on existing annotation layer.
2740
+ *
2741
+ * @param {AnnotationLayerParameters} viewport
2742
+ * @memberof AnnotationLayer
2743
+ */
2744
+ update({ viewport }) {
2745
+ const layer = this.div;
2746
+ this.viewport = viewport;
2747
+ // setLayerDimensions(layer, { rotation: viewport.rotation });
2748
+ (0, pdf_mjs_1.setLayerDimensions)(layer, viewport);
2749
+ tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_instances, "m", _AnnotationLayer_setAnnotationCanvasMap).call(this);
2750
+ layer.hidden = false;
2751
+ }
2752
+ getEditableAnnotations() {
2753
+ return Array.from(tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").values());
2754
+ }
2755
+ getEditableAnnotation(id) {
2756
+ return tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_editableAnnotations, "f").get(id);
2757
+ }
2758
+ }
2759
+ exports.AnnotationLayer = AnnotationLayer;
2760
+ _AnnotationLayer_accessibilityManager = new WeakMap(), _AnnotationLayer_annotationCanvasMap = new WeakMap(), _AnnotationLayer_editableAnnotations = new WeakMap(), _AnnotationLayer_instances = new WeakSet(), _AnnotationLayer_appendElement = function _AnnotationLayer_appendElement(element, id) {
2761
+ var _a;
2762
+ const contentElement = element.firstChild || element;
2763
+ contentElement.id = `${utils_1.AnnotationPrefix}${id}`;
2764
+ this.div.append(element);
2765
+ (_a = tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_accessibilityManager, "f")) === null || _a === void 0 ? void 0 : _a.moveElementInDOM(this.div, element, contentElement,
2766
+ /* isRemovable = */ false);
2767
+ }, _AnnotationLayer_setAnnotationCanvasMap = function _AnnotationLayer_setAnnotationCanvasMap() {
2768
+ if (!tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_annotationCanvasMap, "f")) {
2769
+ return;
2770
+ }
2771
+ const layer = this.div;
2772
+ for (const [id, canvas] of tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_annotationCanvasMap, "f")) {
2773
+ const element = layer.querySelector(`[data-annotation-id="${id}"]`);
2774
+ if (!element) {
2775
+ continue;
2776
+ }
2777
+ canvas.className = "annotationContent k-annotation-content";
2778
+ const { firstChild } = element;
2779
+ if (!firstChild) {
2780
+ element.append(canvas);
2781
+ }
2782
+ else if (firstChild.nodeName === "CANVAS") {
2783
+ firstChild.replaceWith(canvas);
2784
+ }
2785
+ else if (!firstChild.classList.contains("annotationContent") ||
2786
+ !firstChild.classList.contains("k-annotation-content ")) {
2787
+ firstChild.before(canvas);
2788
+ }
2789
+ else {
2790
+ firstChild.after(canvas);
2791
+ }
2792
+ }
2793
+ tslib_1.__classPrivateFieldGet(this, _AnnotationLayer_annotationCanvasMap, "f").clear();
2794
+ };