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