@embedpdf/plugin-form 2.14.4 → 3.0.0-next.0

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 (175) hide show
  1. package/LICENSE +192 -21
  2. package/dist/index.cjs +1416 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +277 -0
  5. package/dist/index.d.ts +277 -1
  6. package/dist/index.js +1398 -1779
  7. package/dist/index.js.map +1 -1
  8. package/package.json +24 -61
  9. package/dist/lib/actions.d.ts +0 -33
  10. package/dist/lib/form-plugin.d.ts +0 -59
  11. package/dist/lib/handlers/checkbox.handler.d.ts +0 -3
  12. package/dist/lib/handlers/combobox.handler.d.ts +0 -3
  13. package/dist/lib/handlers/index.d.ts +0 -5
  14. package/dist/lib/handlers/listbox.handler.d.ts +0 -3
  15. package/dist/lib/handlers/radio-button.handler.d.ts +0 -3
  16. package/dist/lib/handlers/text-field.handler.d.ts +0 -3
  17. package/dist/lib/index.d.ts +0 -10
  18. package/dist/lib/manifest.d.ts +0 -4
  19. package/dist/lib/reducer.d.ts +0 -6
  20. package/dist/lib/tools.d.ts +0 -457
  21. package/dist/lib/types.d.ts +0 -98
  22. package/dist/preact/adapter.d.ts +0 -13
  23. package/dist/preact/annotation.d.ts +0 -1
  24. package/dist/preact/core.d.ts +0 -1
  25. package/dist/preact/index.cjs +0 -2
  26. package/dist/preact/index.cjs.map +0 -1
  27. package/dist/preact/index.d.ts +0 -1
  28. package/dist/preact/index.js +0 -1359
  29. package/dist/preact/index.js.map +0 -1
  30. package/dist/react/adapter.d.ts +0 -6
  31. package/dist/react/annotation.d.ts +0 -1
  32. package/dist/react/core.d.ts +0 -1
  33. package/dist/react/index.cjs +0 -2
  34. package/dist/react/index.cjs.map +0 -1
  35. package/dist/react/index.d.ts +0 -1
  36. package/dist/react/index.js +0 -1358
  37. package/dist/react/index.js.map +0 -1
  38. package/dist/shared/components/annotations/form-checkbox.d.ts +0 -12
  39. package/dist/shared/components/annotations/form-combobox.d.ts +0 -12
  40. package/dist/shared/components/annotations/form-listbox.d.ts +0 -12
  41. package/dist/shared/components/annotations/form-radio-button.d.ts +0 -12
  42. package/dist/shared/components/annotations/form-text-field.d.ts +0 -12
  43. package/dist/shared/components/fields/checkbox.d.ts +0 -2
  44. package/dist/shared/components/fields/combobox.d.ts +0 -2
  45. package/dist/shared/components/fields/listbox.d.ts +0 -2
  46. package/dist/shared/components/fields/push-button.d.ts +0 -2
  47. package/dist/shared/components/fields/radio-button.d.ts +0 -2
  48. package/dist/shared/components/fields/style.d.ts +0 -6
  49. package/dist/shared/components/fields/text.d.ts +0 -2
  50. package/dist/shared/components/fill-mode/combobox-fill-mode.d.ts +0 -3
  51. package/dist/shared/components/fill-mode/listbox-fill-mode.d.ts +0 -3
  52. package/dist/shared/components/fill-mode/push-button-fill-mode.d.ts +0 -3
  53. package/dist/shared/components/fill-mode/radio-button-fill-mode.d.ts +0 -3
  54. package/dist/shared/components/fill-mode/text-fill-mode.d.ts +0 -3
  55. package/dist/shared/components/fill-mode/toggle-fill-mode.d.ts +0 -3
  56. package/dist/shared/components/form-renderer-registration.d.ts +0 -5
  57. package/dist/shared/components/form-renderers.d.ts +0 -9
  58. package/dist/shared/components/index.d.ts +0 -2
  59. package/dist/shared/components/render-widget.d.ts +0 -12
  60. package/dist/shared/components/types.d.ts +0 -42
  61. package/dist/shared/hooks/index.d.ts +0 -1
  62. package/dist/shared/hooks/use-form-widget-state.d.ts +0 -12
  63. package/dist/shared/hooks/use-form.d.ts +0 -16
  64. package/dist/shared/index.d.ts +0 -4
  65. package/dist/shared-preact/components/annotations/form-checkbox.d.ts +0 -12
  66. package/dist/shared-preact/components/annotations/form-combobox.d.ts +0 -12
  67. package/dist/shared-preact/components/annotations/form-listbox.d.ts +0 -12
  68. package/dist/shared-preact/components/annotations/form-radio-button.d.ts +0 -12
  69. package/dist/shared-preact/components/annotations/form-text-field.d.ts +0 -12
  70. package/dist/shared-preact/components/fields/checkbox.d.ts +0 -2
  71. package/dist/shared-preact/components/fields/combobox.d.ts +0 -2
  72. package/dist/shared-preact/components/fields/listbox.d.ts +0 -2
  73. package/dist/shared-preact/components/fields/push-button.d.ts +0 -2
  74. package/dist/shared-preact/components/fields/radio-button.d.ts +0 -2
  75. package/dist/shared-preact/components/fields/style.d.ts +0 -6
  76. package/dist/shared-preact/components/fields/text.d.ts +0 -2
  77. package/dist/shared-preact/components/fill-mode/combobox-fill-mode.d.ts +0 -3
  78. package/dist/shared-preact/components/fill-mode/listbox-fill-mode.d.ts +0 -3
  79. package/dist/shared-preact/components/fill-mode/push-button-fill-mode.d.ts +0 -3
  80. package/dist/shared-preact/components/fill-mode/radio-button-fill-mode.d.ts +0 -3
  81. package/dist/shared-preact/components/fill-mode/text-fill-mode.d.ts +0 -3
  82. package/dist/shared-preact/components/fill-mode/toggle-fill-mode.d.ts +0 -3
  83. package/dist/shared-preact/components/form-renderer-registration.d.ts +0 -5
  84. package/dist/shared-preact/components/form-renderers.d.ts +0 -9
  85. package/dist/shared-preact/components/index.d.ts +0 -2
  86. package/dist/shared-preact/components/render-widget.d.ts +0 -12
  87. package/dist/shared-preact/components/types.d.ts +0 -42
  88. package/dist/shared-preact/hooks/index.d.ts +0 -1
  89. package/dist/shared-preact/hooks/use-form-widget-state.d.ts +0 -12
  90. package/dist/shared-preact/hooks/use-form.d.ts +0 -16
  91. package/dist/shared-preact/index.d.ts +0 -4
  92. package/dist/shared-react/components/annotations/form-checkbox.d.ts +0 -12
  93. package/dist/shared-react/components/annotations/form-combobox.d.ts +0 -12
  94. package/dist/shared-react/components/annotations/form-listbox.d.ts +0 -12
  95. package/dist/shared-react/components/annotations/form-radio-button.d.ts +0 -12
  96. package/dist/shared-react/components/annotations/form-text-field.d.ts +0 -12
  97. package/dist/shared-react/components/fields/checkbox.d.ts +0 -2
  98. package/dist/shared-react/components/fields/combobox.d.ts +0 -2
  99. package/dist/shared-react/components/fields/listbox.d.ts +0 -2
  100. package/dist/shared-react/components/fields/push-button.d.ts +0 -2
  101. package/dist/shared-react/components/fields/radio-button.d.ts +0 -2
  102. package/dist/shared-react/components/fields/style.d.ts +0 -6
  103. package/dist/shared-react/components/fields/text.d.ts +0 -2
  104. package/dist/shared-react/components/fill-mode/combobox-fill-mode.d.ts +0 -3
  105. package/dist/shared-react/components/fill-mode/listbox-fill-mode.d.ts +0 -3
  106. package/dist/shared-react/components/fill-mode/push-button-fill-mode.d.ts +0 -3
  107. package/dist/shared-react/components/fill-mode/radio-button-fill-mode.d.ts +0 -3
  108. package/dist/shared-react/components/fill-mode/text-fill-mode.d.ts +0 -3
  109. package/dist/shared-react/components/fill-mode/toggle-fill-mode.d.ts +0 -3
  110. package/dist/shared-react/components/form-renderer-registration.d.ts +0 -5
  111. package/dist/shared-react/components/form-renderers.d.ts +0 -9
  112. package/dist/shared-react/components/index.d.ts +0 -2
  113. package/dist/shared-react/components/render-widget.d.ts +0 -12
  114. package/dist/shared-react/components/types.d.ts +0 -42
  115. package/dist/shared-react/hooks/index.d.ts +0 -1
  116. package/dist/shared-react/hooks/use-form-widget-state.d.ts +0 -12
  117. package/dist/shared-react/hooks/use-form.d.ts +0 -16
  118. package/dist/shared-react/index.d.ts +0 -4
  119. package/dist/svelte/components/FormRendererRegistration.svelte.d.ts +0 -18
  120. package/dist/svelte/components/RenderWidget.svelte.d.ts +0 -11
  121. package/dist/svelte/components/annotations/FormCheckbox.svelte.d.ts +0 -5
  122. package/dist/svelte/components/annotations/FormCombobox.svelte.d.ts +0 -5
  123. package/dist/svelte/components/annotations/FormListbox.svelte.d.ts +0 -5
  124. package/dist/svelte/components/annotations/FormRadioButton.svelte.d.ts +0 -5
  125. package/dist/svelte/components/annotations/FormTextField.svelte.d.ts +0 -5
  126. package/dist/svelte/components/fields/ComboboxField.svelte.d.ts +0 -4
  127. package/dist/svelte/components/fields/ListboxField.svelte.d.ts +0 -4
  128. package/dist/svelte/components/fields/TextField.svelte.d.ts +0 -4
  129. package/dist/svelte/components/fill-mode/ComboboxFillMode.svelte.d.ts +0 -5
  130. package/dist/svelte/components/fill-mode/ListboxFillMode.svelte.d.ts +0 -5
  131. package/dist/svelte/components/fill-mode/RadioButtonFillMode.svelte.d.ts +0 -5
  132. package/dist/svelte/components/fill-mode/TextFillMode.svelte.d.ts +0 -5
  133. package/dist/svelte/components/fill-mode/ToggleFillMode.svelte.d.ts +0 -5
  134. package/dist/svelte/components/form-renderers.d.ts +0 -9
  135. package/dist/svelte/components/previews/CheckboxPreview.svelte.d.ts +0 -9
  136. package/dist/svelte/components/previews/ListboxPreview.svelte.d.ts +0 -9
  137. package/dist/svelte/components/previews/RadioButtonPreview.svelte.d.ts +0 -9
  138. package/dist/svelte/components/previews/TextFieldPreview.svelte.d.ts +0 -9
  139. package/dist/svelte/hooks/index.d.ts +0 -2
  140. package/dist/svelte/hooks/use-form-widget-state.svelte.d.ts +0 -12
  141. package/dist/svelte/hooks/use-form.svelte.d.ts +0 -14
  142. package/dist/svelte/index.cjs +0 -2
  143. package/dist/svelte/index.cjs.map +0 -1
  144. package/dist/svelte/index.d.ts +0 -3
  145. package/dist/svelte/index.js +0 -1567
  146. package/dist/svelte/index.js.map +0 -1
  147. package/dist/vue/components/annotations/form-checkbox.vue.d.ts +0 -6
  148. package/dist/vue/components/annotations/form-combobox.vue.d.ts +0 -6
  149. package/dist/vue/components/annotations/form-listbox.vue.d.ts +0 -6
  150. package/dist/vue/components/annotations/form-radio-button.vue.d.ts +0 -6
  151. package/dist/vue/components/annotations/form-text-field.vue.d.ts +0 -6
  152. package/dist/vue/components/fields/combobox-field.vue.d.ts +0 -4
  153. package/dist/vue/components/fields/listbox-field.vue.d.ts +0 -4
  154. package/dist/vue/components/fields/style.d.ts +0 -6
  155. package/dist/vue/components/fields/text-field.vue.d.ts +0 -4
  156. package/dist/vue/components/fill-mode/combobox-fill-mode.vue.d.ts +0 -6
  157. package/dist/vue/components/fill-mode/listbox-fill-mode.vue.d.ts +0 -6
  158. package/dist/vue/components/fill-mode/radio-button-fill-mode.vue.d.ts +0 -6
  159. package/dist/vue/components/fill-mode/text-fill-mode.vue.d.ts +0 -6
  160. package/dist/vue/components/fill-mode/toggle-fill-mode.vue.d.ts +0 -6
  161. package/dist/vue/components/form-renderer-registration.vue.d.ts +0 -13
  162. package/dist/vue/components/form-renderers.d.ts +0 -3
  163. package/dist/vue/components/previews/checkbox-preview.vue.d.ts +0 -10
  164. package/dist/vue/components/previews/listbox-preview.vue.d.ts +0 -10
  165. package/dist/vue/components/previews/radio-button-preview.vue.d.ts +0 -10
  166. package/dist/vue/components/previews/text-field-preview.vue.d.ts +0 -10
  167. package/dist/vue/components/render-widget.vue.d.ts +0 -15
  168. package/dist/vue/hooks/index.d.ts +0 -2
  169. package/dist/vue/hooks/use-form-widget-state.d.ts +0 -12
  170. package/dist/vue/hooks/use-form.d.ts +0 -12
  171. package/dist/vue/index.cjs +0 -2
  172. package/dist/vue/index.cjs.map +0 -1
  173. package/dist/vue/index.d.ts +0 -3
  174. package/dist/vue/index.js +0 -1643
  175. package/dist/vue/index.js.map +0 -1
@@ -1,1359 +0,0 @@
1
- import { createPluginPackage } from "@embedpdf/core";
2
- import { initialDocumentState, FormPlugin, FormPluginPackage as FormPluginPackage$1 } from "@embedpdf/plugin-form";
3
- export * from "@embedpdf/plugin-form";
4
- import { useIOSZoomPrevention, createRenderer, useRegisterRenderers } from "@embedpdf/plugin-annotation/preact";
5
- import { jsx, jsxs } from "preact/jsx-runtime";
6
- import { PDF_FORM_FIELD_TYPE, PDF_FORM_FIELD_FLAG, standardFontCssProperties, isWidgetChecked, ignore, PdfErrorCode, PdfAnnotationSubtype } from "@embedpdf/models";
7
- import { Fragment } from "preact";
8
- import { useState, useEffect, useMemo, useCallback, useRef } from "preact/hooks";
9
- import { useCapability, usePlugin } from "@embedpdf/core/preact";
10
- const selectProps = (isMultiple, selectedValues) => ({
11
- value: isMultiple ? void 0 : selectedValues[0] || ""
12
- });
13
- const optionProps = (isMultiple, selectedValues, optionValue) => ({
14
- selected: isMultiple ? selectedValues.includes(optionValue) : void 0
15
- });
16
- function FormTextField({
17
- annotation,
18
- isSelected,
19
- scale,
20
- onClick,
21
- style
22
- }) {
23
- const [isHovered, setIsHovered] = useState(false);
24
- const { object } = annotation;
25
- const field = object.field;
26
- const isTextField = field.type === PDF_FORM_FIELD_TYPE.TEXTFIELD;
27
- const value = isTextField ? field.value : "";
28
- const isComb = isTextField && !!(field.flag & PDF_FORM_FIELD_FLAG.TEXT_COMB) && !!field.maxLen;
29
- const isMultiline = isTextField && !!(field.flag & PDF_FORM_FIELD_FLAG.TEXT_MULTIPLINE);
30
- const maxLen = isTextField ? field.maxLen : void 0;
31
- const borderWidth = (object.strokeWidth ?? 1) * scale;
32
- const fontStyle = {
33
- fontSize: (object.fontSize ?? 12) * scale,
34
- ...standardFontCssProperties(object.fontFamily),
35
- color: object.fontColor ?? "#000000",
36
- lineHeight: 1.2
37
- };
38
- return /* @__PURE__ */ jsx(
39
- "div",
40
- {
41
- onPointerDown: !isSelected ? onClick : void 0,
42
- onMouseEnter: () => setIsHovered(true),
43
- onMouseLeave: () => setIsHovered(false),
44
- style: {
45
- position: "absolute",
46
- inset: 0,
47
- background: object.color ?? "rgba(255, 255, 255, 0.9)",
48
- border: `${borderWidth}px solid ${object.strokeColor ?? "rgba(0, 0, 0, 0.2)"}`,
49
- outline: isHovered || isSelected ? "1px solid rgba(66, 133, 244, 0.5)" : "none",
50
- outlineOffset: -1,
51
- boxSizing: "border-box",
52
- pointerEvents: "auto",
53
- cursor: isSelected ? "move" : "pointer",
54
- display: "flex",
55
- alignItems: isMultiline ? "flex-start" : "center",
56
- overflow: "hidden",
57
- ...!isComb ? { padding: `${borderWidth}px ${borderWidth}px` } : {},
58
- ...style
59
- },
60
- children: isComb && maxLen ? /* @__PURE__ */ jsx(
61
- CombPreview,
62
- {
63
- value: value ?? "",
64
- maxLen,
65
- scale,
66
- width: object.rect.size.width,
67
- fontStyle,
68
- strokeColor: object.strokeColor ?? "rgba(0, 0, 0, 0.2)"
69
- }
70
- ) : /* @__PURE__ */ jsx(
71
- "span",
72
- {
73
- style: {
74
- ...fontStyle,
75
- display: "block",
76
- width: "100%",
77
- whiteSpace: isMultiline ? "pre-wrap" : "nowrap",
78
- wordBreak: isMultiline ? "break-word" : "normal",
79
- overflowWrap: isMultiline ? "break-word" : "normal",
80
- overflow: "hidden",
81
- textOverflow: isMultiline ? "clip" : "ellipsis"
82
- },
83
- children: value
84
- }
85
- )
86
- }
87
- );
88
- }
89
- function CombPreview({
90
- value,
91
- maxLen,
92
- scale,
93
- width,
94
- fontStyle,
95
- strokeColor
96
- }) {
97
- const cellWidth = width * scale / maxLen;
98
- const chars = value.split("");
99
- return /* @__PURE__ */ jsx("div", { style: { position: "relative", width: "100%", height: "100%" }, children: Array.from({ length: maxLen }).map((_, i) => /* @__PURE__ */ jsx(
100
- "span",
101
- {
102
- style: {
103
- position: "absolute",
104
- top: 0,
105
- left: i * cellWidth,
106
- width: cellWidth,
107
- height: "100%",
108
- display: "flex",
109
- alignItems: "center",
110
- justifyContent: "center",
111
- borderRight: i < maxLen - 1 ? `1px solid ${strokeColor}` : "none",
112
- boxSizing: "border-box",
113
- ...fontStyle
114
- },
115
- children: chars[i] || ""
116
- },
117
- i
118
- )) });
119
- }
120
- function FormCheckbox({ annotation, isSelected, scale, onClick, style }) {
121
- const [isHovered, setIsHovered] = useState(false);
122
- const { object } = annotation;
123
- const isChecked = isWidgetChecked(object);
124
- return /* @__PURE__ */ jsx(
125
- "div",
126
- {
127
- onPointerDown: !isSelected ? onClick : void 0,
128
- onMouseEnter: () => setIsHovered(true),
129
- onMouseLeave: () => setIsHovered(false),
130
- style: {
131
- position: "absolute",
132
- inset: 0,
133
- background: object.color ?? "#FFFFFF",
134
- border: `${(object.strokeWidth ?? 1) * scale}px solid ${object.strokeColor ?? "#000000"}`,
135
- outline: isHovered || isSelected ? "1px solid rgba(66, 133, 244, 0.5)" : "none",
136
- outlineOffset: -1,
137
- boxSizing: "border-box",
138
- pointerEvents: "auto",
139
- cursor: isSelected ? "move" : "pointer",
140
- display: "flex",
141
- alignItems: "center",
142
- justifyContent: "center",
143
- ...style
144
- },
145
- children: isChecked && /* @__PURE__ */ jsx(
146
- "svg",
147
- {
148
- viewBox: "0 0 100 100",
149
- style: {
150
- width: "100%",
151
- height: "100%"
152
- },
153
- children: /* @__PURE__ */ jsx(
154
- "path",
155
- {
156
- d: "M28 48C27.45 50.21 29.45 63.13 30 67C30.55 69.21 34.58 72 39 72C44.52 71.45 76.55 32.55 76 32C77.1 31.45 76 25 76 25C74.34 22.24 68 25.45 68 26C68 26 43.55 53 43 53C41.34 53 40.55 41.1 40 40C33.37 36.69 29.1 45.79 28 48Z",
157
- fill: "#000000"
158
- }
159
- )
160
- }
161
- )
162
- }
163
- );
164
- }
165
- function FormRadioButton({
166
- annotation,
167
- isSelected,
168
- scale,
169
- onClick,
170
- style
171
- }) {
172
- const [isHovered, setIsHovered] = useState(false);
173
- const { object } = annotation;
174
- const isChecked = isWidgetChecked(object);
175
- return /* @__PURE__ */ jsx(
176
- "div",
177
- {
178
- onPointerDown: !isSelected ? onClick : void 0,
179
- onMouseEnter: () => setIsHovered(true),
180
- onMouseLeave: () => setIsHovered(false),
181
- style: {
182
- position: "absolute",
183
- inset: 0,
184
- background: object.color ?? "#FFFFFF",
185
- border: `${(object.strokeWidth ?? 1) * scale}px solid ${object.strokeColor ?? "#000000"}`,
186
- borderRadius: "50%",
187
- outline: isHovered || isSelected ? "1px solid rgba(66, 133, 244, 0.5)" : "none",
188
- outlineOffset: -1,
189
- boxSizing: "border-box",
190
- pointerEvents: "auto",
191
- cursor: isSelected ? "move" : "pointer",
192
- display: "flex",
193
- alignItems: "center",
194
- justifyContent: "center",
195
- ...style
196
- },
197
- children: isChecked && /* @__PURE__ */ jsx(
198
- "div",
199
- {
200
- style: {
201
- width: "50%",
202
- height: "50%",
203
- borderRadius: "50%",
204
- background: "#000000"
205
- }
206
- }
207
- )
208
- }
209
- );
210
- }
211
- function FormCombobox({ annotation, isSelected, scale, onClick, style }) {
212
- var _a;
213
- const [isHovered, setIsHovered] = useState(false);
214
- const { object } = annotation;
215
- const field = object.field;
216
- const options = field.type === PDF_FORM_FIELD_TYPE.COMBOBOX ? field.options : [];
217
- const selectedLabel = ((_a = options.find((o) => o.isSelected)) == null ? void 0 : _a.label) ?? "";
218
- const borderWidth = (object.strokeWidth ?? 1) * scale;
219
- const fontSize = (object.fontSize ?? 12) * scale;
220
- return /* @__PURE__ */ jsxs(
221
- "div",
222
- {
223
- onPointerDown: !isSelected ? onClick : void 0,
224
- onMouseEnter: () => setIsHovered(true),
225
- onMouseLeave: () => setIsHovered(false),
226
- style: {
227
- position: "absolute",
228
- inset: 0,
229
- background: object.color ?? "#FFFFFF",
230
- border: `${borderWidth}px solid ${object.strokeColor ?? "#000000"}`,
231
- outline: isHovered || isSelected ? "1px solid rgba(66, 133, 244, 0.5)" : "none",
232
- outlineOffset: -1,
233
- boxSizing: "border-box",
234
- pointerEvents: "auto",
235
- cursor: isSelected ? "move" : "pointer",
236
- display: "flex",
237
- alignItems: "center",
238
- overflow: "hidden",
239
- ...style
240
- },
241
- children: [
242
- /* @__PURE__ */ jsx(
243
- "span",
244
- {
245
- style: {
246
- flex: 1,
247
- padding: `0 ${4 * scale}px`,
248
- fontSize,
249
- ...standardFontCssProperties(object.fontFamily),
250
- color: object.fontColor ?? "#000000",
251
- whiteSpace: "nowrap",
252
- overflow: "hidden",
253
- textOverflow: "ellipsis"
254
- },
255
- children: selectedLabel
256
- }
257
- ),
258
- /* @__PURE__ */ jsx(
259
- "div",
260
- {
261
- style: {
262
- width: 13 * scale,
263
- minWidth: 13 * scale,
264
- height: "100%",
265
- display: "flex",
266
- alignItems: "center",
267
- justifyContent: "center",
268
- borderLeft: `1px solid ${object.strokeColor ?? "#000000"}`
269
- },
270
- children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 10 6", style: { width: 8 * scale, height: 5 * scale }, fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M0 0 L5 6 L10 0 Z" }) })
271
- }
272
- )
273
- ]
274
- }
275
- );
276
- }
277
- function FormListbox({ annotation, isSelected, scale, onClick, style }) {
278
- const [isHovered, setIsHovered] = useState(false);
279
- const { object } = annotation;
280
- const field = object.field;
281
- const options = field.type === PDF_FORM_FIELD_TYPE.LISTBOX ? field.options : [];
282
- const borderWidth = (object.strokeWidth ?? 1) * scale;
283
- const fontSize = (object.fontSize ?? 12) * scale;
284
- const lineHeight = fontSize * 1.2;
285
- return /* @__PURE__ */ jsx(
286
- "div",
287
- {
288
- onPointerDown: !isSelected ? onClick : void 0,
289
- onMouseEnter: () => setIsHovered(true),
290
- onMouseLeave: () => setIsHovered(false),
291
- style: {
292
- position: "absolute",
293
- inset: 0,
294
- background: object.color ?? "#FFFFFF",
295
- border: `${borderWidth}px solid ${object.strokeColor ?? "#000000"}`,
296
- outline: isHovered || isSelected ? "1px solid rgba(66, 133, 244, 0.5)" : "none",
297
- outlineOffset: -1,
298
- boxSizing: "border-box",
299
- pointerEvents: "auto",
300
- cursor: isSelected ? "move" : "pointer",
301
- overflow: "hidden",
302
- display: "flex",
303
- flexDirection: "column",
304
- ...style
305
- },
306
- children: options.map((opt, i) => /* @__PURE__ */ jsx(
307
- "div",
308
- {
309
- style: {
310
- padding: `0 ${4 * scale}px`,
311
- fontSize,
312
- lineHeight: `${lineHeight}px`,
313
- ...standardFontCssProperties(object.fontFamily),
314
- color: opt.isSelected ? "#FFFFFF" : object.fontColor ?? "#000000",
315
- background: opt.isSelected ? "rgba(0, 51, 113, 1)" : "transparent",
316
- whiteSpace: "nowrap",
317
- overflow: "hidden",
318
- textOverflow: "ellipsis"
319
- },
320
- children: opt.label
321
- },
322
- i
323
- ))
324
- }
325
- );
326
- }
327
- const useFormPlugin = () => usePlugin(FormPlugin.id);
328
- const useFormCapability = () => useCapability(FormPlugin.id);
329
- const useFormDocumentState = (documentId) => {
330
- var _a;
331
- const { provides } = useFormCapability();
332
- const [state, setState] = useState(
333
- ((_a = provides == null ? void 0 : provides.forDocument(documentId)) == null ? void 0 : _a.getState()) ?? { ...initialDocumentState }
334
- );
335
- useEffect(() => {
336
- if (!provides) return;
337
- const scope = provides.forDocument(documentId);
338
- setState(scope.getState());
339
- return scope.onStateChange((newState) => {
340
- setState(newState);
341
- });
342
- }, [provides, documentId]);
343
- return state;
344
- };
345
- function useFormWidgetState(props) {
346
- const { currentObject: annotation, scale, pageIndex } = props;
347
- const field = annotation.field;
348
- const { provides: formProvides } = useFormCapability();
349
- const [renderKey, setRenderKey] = useState(0);
350
- const isReadOnly = !!(field.flag & PDF_FORM_FIELD_FLAG.READONLY);
351
- const scope = useMemo(
352
- () => formProvides == null ? void 0 : formProvides.forDocument(props.documentId),
353
- [formProvides, props.documentId]
354
- );
355
- useEffect(() => {
356
- if (!scope) return;
357
- return scope.onFieldValueChange((event) => {
358
- if (event.annotationId === annotation.id) {
359
- setRenderKey((k) => k + 1);
360
- }
361
- });
362
- }, [scope, annotation.id]);
363
- const handleChangeField = useCallback(
364
- (newField) => {
365
- if (!scope) return;
366
- scope.setFormFieldValues(pageIndex, annotation, newField);
367
- },
368
- [scope, pageIndex, annotation]
369
- );
370
- return { annotation, field, scale, pageIndex, scope, handleChangeField, renderKey, isReadOnly };
371
- }
372
- function RenderWidget({
373
- pageIndex,
374
- annotation,
375
- scaleFactor = 1,
376
- renderKey = 0,
377
- style,
378
- ...props
379
- }) {
380
- const { provides: formProvides } = useFormCapability();
381
- const [imageUrl, setImageUrl] = useState(null);
382
- const urlRef = useRef(null);
383
- const { width, height } = annotation.rect.size;
384
- useEffect(() => {
385
- if (!formProvides) return;
386
- const task = formProvides.renderWidget({
387
- pageIndex,
388
- annotation,
389
- options: {
390
- scaleFactor,
391
- dpr: window.devicePixelRatio
392
- }
393
- });
394
- task.wait((blob) => {
395
- const url = URL.createObjectURL(blob);
396
- if (urlRef.current) {
397
- URL.revokeObjectURL(urlRef.current);
398
- }
399
- urlRef.current = url;
400
- setImageUrl(url);
401
- }, ignore);
402
- return () => {
403
- task.abort({
404
- code: PdfErrorCode.Cancelled,
405
- message: "canceled render task"
406
- });
407
- };
408
- }, [pageIndex, scaleFactor, formProvides, annotation.id, width, height, renderKey]);
409
- useEffect(() => {
410
- return () => {
411
- if (urlRef.current) {
412
- URL.revokeObjectURL(urlRef.current);
413
- urlRef.current = null;
414
- }
415
- };
416
- }, []);
417
- return /* @__PURE__ */ jsx(Fragment, { children: imageUrl && /* @__PURE__ */ jsx(
418
- "img",
419
- {
420
- src: imageUrl,
421
- ...props,
422
- style: {
423
- width: "100%",
424
- height: "100%",
425
- display: "block",
426
- ...style || {}
427
- }
428
- }
429
- ) });
430
- }
431
- const baseStyle = {
432
- position: "absolute",
433
- top: 0,
434
- left: 0,
435
- padding: 0,
436
- margin: 0,
437
- width: "100%",
438
- height: "100%"
439
- };
440
- const baseInputStyle = {
441
- ...baseStyle,
442
- borderRadius: 0,
443
- outline: "none",
444
- boxSizing: "border-box"
445
- };
446
- const inputStyle = baseInputStyle;
447
- const selectStyle = {
448
- ...baseInputStyle,
449
- cursor: "inherit"
450
- };
451
- const textareaStyle = {
452
- ...baseInputStyle,
453
- resize: "none",
454
- lineHeight: 1.14
455
- };
456
- const combContainerStyle = {
457
- position: "relative",
458
- width: "100%",
459
- height: "100%",
460
- borderRadius: 0,
461
- boxSizing: "border-box"
462
- };
463
- const combHiddenInputStyle = {
464
- position: "absolute",
465
- top: 0,
466
- left: 0,
467
- width: "100%",
468
- height: "100%",
469
- opacity: 0,
470
- padding: 0,
471
- margin: 0,
472
- border: "none",
473
- zIndex: 1
474
- };
475
- const combCellStyle = {
476
- position: "absolute",
477
- top: 0,
478
- height: "100%",
479
- display: "flex",
480
- alignItems: "center",
481
- justifyContent: "center",
482
- pointerEvents: "none"
483
- };
484
- const combCaretStyle = {
485
- position: "absolute",
486
- top: "15%",
487
- height: "70%",
488
- width: 1,
489
- backgroundColor: "black",
490
- pointerEvents: "none"
491
- };
492
- function CombField(props) {
493
- const {
494
- inputRef,
495
- required,
496
- disabled,
497
- password,
498
- name,
499
- value,
500
- maxLen,
501
- cellWidth,
502
- chars,
503
- caretIndex,
504
- containerStyle,
505
- cellFontStyle,
506
- onFocus,
507
- onChange,
508
- onBlur
509
- } = props;
510
- const [caretVisible, setCaretVisible] = useState(true);
511
- useEffect(() => {
512
- setCaretVisible(true);
513
- const id = setInterval(() => setCaretVisible((v) => !v), 530);
514
- return () => clearInterval(id);
515
- }, [caretIndex]);
516
- const showCaret = caretIndex < maxLen;
517
- return /* @__PURE__ */ jsxs("div", { style: containerStyle, children: [
518
- /* @__PURE__ */ jsx(
519
- "input",
520
- {
521
- ref: inputRef,
522
- required,
523
- disabled,
524
- type: password ? "password" : "text",
525
- name,
526
- "aria-label": name,
527
- value,
528
- maxLength: maxLen,
529
- onFocus,
530
- onChange,
531
- onBlur,
532
- style: combHiddenInputStyle
533
- }
534
- ),
535
- Array.from({ length: maxLen }).map((_, i) => /* @__PURE__ */ jsx(
536
- "span",
537
- {
538
- style: {
539
- ...combCellStyle,
540
- ...cellFontStyle,
541
- left: i * cellWidth,
542
- width: cellWidth
543
- },
544
- children: chars[i] || ""
545
- },
546
- i
547
- )),
548
- showCaret && /* @__PURE__ */ jsx(
549
- "span",
550
- {
551
- style: {
552
- ...combCaretStyle,
553
- left: caretIndex * cellWidth + cellWidth / 2,
554
- opacity: caretVisible ? 1 : 0
555
- }
556
- }
557
- )
558
- ] });
559
- }
560
- function TextField(props) {
561
- const {
562
- annotation,
563
- isEditable,
564
- onChangeField,
565
- onFocus,
566
- onBlur,
567
- inputRef,
568
- scale,
569
- syncExternalValue = true
570
- } = props;
571
- const field = annotation.field;
572
- const { flag } = field;
573
- const name = field.name;
574
- const value = field.value;
575
- const [localValue, setLocalValue] = useState(value);
576
- useEffect(() => {
577
- if (!syncExternalValue) return;
578
- setLocalValue(value);
579
- }, [value, syncExternalValue]);
580
- const changeValue = useCallback(
581
- (evt) => {
582
- const newValue = evt.target.value;
583
- setLocalValue(newValue);
584
- onChangeField == null ? void 0 : onChangeField({ ...field, value: newValue });
585
- },
586
- [onChangeField, field]
587
- );
588
- const bw = (annotation.strokeWidth ?? 0) * scale;
589
- const fontCss = standardFontCssProperties(annotation.fontFamily);
590
- const { adjustedFontPx, wrapperStyle } = useIOSZoomPrevention(annotation.fontSize * scale, true);
591
- const visualStyle = useMemo(
592
- () => ({
593
- backgroundColor: annotation.color ?? "transparent",
594
- borderStyle: "solid",
595
- borderColor: annotation.strokeColor ?? "transparent",
596
- borderWidth: bw,
597
- color: annotation.fontColor,
598
- ...fontCss,
599
- fontSize: adjustedFontPx,
600
- padding: `${bw}px ${bw}px`
601
- }),
602
- [annotation.color, annotation.strokeColor, annotation.fontColor, adjustedFontPx, bw, fontCss]
603
- );
604
- const isDisabled = !isEditable || !!(flag & PDF_FORM_FIELD_FLAG.READONLY);
605
- const isRequired = !!(flag & PDF_FORM_FIELD_FLAG.REQUIRED);
606
- const isPassword = !!(flag & PDF_FORM_FIELD_FLAG.TEXT_PASSWORD);
607
- const isMultipleLine = !!(flag & PDF_FORM_FIELD_FLAG.TEXT_MULTIPLINE);
608
- const isComb = !!(flag & PDF_FORM_FIELD_FLAG.TEXT_COMB);
609
- const maxLen = field.maxLen;
610
- if (isComb && maxLen) {
611
- const cellWidth = annotation.rect.size.width * scale / maxLen;
612
- const chars = (localValue || "").split("");
613
- const caretIndex = chars.length;
614
- const combContainer = {
615
- ...combContainerStyle,
616
- backgroundColor: annotation.color ?? "transparent",
617
- borderStyle: "solid",
618
- borderColor: annotation.strokeColor ?? "transparent",
619
- borderWidth: bw
620
- };
621
- const cellFont = {
622
- color: annotation.fontColor,
623
- ...fontCss,
624
- fontSize: adjustedFontPx
625
- };
626
- const combContent = /* @__PURE__ */ jsx(
627
- CombField,
628
- {
629
- inputRef,
630
- required: isRequired,
631
- disabled: isDisabled,
632
- password: isPassword,
633
- name,
634
- value: localValue,
635
- maxLen,
636
- cellWidth,
637
- chars,
638
- caretIndex,
639
- containerStyle: combContainer,
640
- cellFontStyle: cellFont,
641
- onFocus,
642
- onChange: changeValue,
643
- onBlur
644
- }
645
- );
646
- return wrapperStyle ? /* @__PURE__ */ jsx("div", { style: wrapperStyle, children: combContent }) : combContent;
647
- }
648
- const inputContent = isMultipleLine ? /* @__PURE__ */ jsx(
649
- "textarea",
650
- {
651
- ref: inputRef,
652
- required: isRequired,
653
- disabled: isDisabled,
654
- name,
655
- "aria-label": name,
656
- value: localValue,
657
- maxLength: maxLen,
658
- onFocus,
659
- onChange: changeValue,
660
- onBlur,
661
- style: { ...textareaStyle, ...visualStyle }
662
- }
663
- ) : /* @__PURE__ */ jsx(
664
- "input",
665
- {
666
- ref: inputRef,
667
- required: isRequired,
668
- disabled: isDisabled,
669
- type: isPassword ? "password" : "text",
670
- name,
671
- "aria-label": name,
672
- value: localValue,
673
- maxLength: maxLen,
674
- onFocus,
675
- onChange: changeValue,
676
- onBlur,
677
- style: { ...inputStyle, ...visualStyle }
678
- }
679
- );
680
- return wrapperStyle ? /* @__PURE__ */ jsx("div", { style: wrapperStyle, children: inputContent }) : inputContent;
681
- }
682
- function TextFillMode(props) {
683
- const { annotation, scale, pageIndex, scope, handleChangeField, renderKey, isReadOnly } = useFormWidgetState(props);
684
- const formState = useFormDocumentState(props.documentId);
685
- const [editing, setEditing] = useState(false);
686
- const inputRef = useRef(null);
687
- const isFocused = formState.selectedFieldId === annotation.id;
688
- useEffect(() => {
689
- if (isFocused && inputRef.current && document.activeElement !== inputRef.current) {
690
- inputRef.current.focus();
691
- }
692
- }, [isFocused]);
693
- const handleFocus = useCallback(() => {
694
- if (isReadOnly) return;
695
- scope == null ? void 0 : scope.selectField(annotation.id);
696
- setEditing(true);
697
- }, [isReadOnly, scope, annotation.id]);
698
- const handleBlur = useCallback(() => {
699
- setEditing(false);
700
- if ((scope == null ? void 0 : scope.getSelectedFieldId()) === annotation.id) {
701
- scope == null ? void 0 : scope.deselectField();
702
- }
703
- }, [scope, annotation.id]);
704
- const handleInputRef = useCallback((el) => {
705
- inputRef.current = el;
706
- }, []);
707
- return /* @__PURE__ */ jsxs(
708
- "div",
709
- {
710
- style: {
711
- width: "100%",
712
- height: "100%",
713
- overflow: "hidden",
714
- position: "relative",
715
- pointerEvents: "auto",
716
- outline: "none"
717
- },
718
- children: [
719
- /* @__PURE__ */ jsx(
720
- RenderWidget,
721
- {
722
- pageIndex,
723
- annotation,
724
- scaleFactor: scale,
725
- renderKey,
726
- style: {
727
- position: "absolute",
728
- inset: 0,
729
- pointerEvents: "none",
730
- visibility: editing ? "hidden" : "visible"
731
- }
732
- }
733
- ),
734
- /* @__PURE__ */ jsx(
735
- "div",
736
- {
737
- style: {
738
- position: "absolute",
739
- inset: 0,
740
- zIndex: 1,
741
- opacity: editing ? 1 : 0
742
- },
743
- children: /* @__PURE__ */ jsx(
744
- TextField,
745
- {
746
- annotation,
747
- scale,
748
- pageIndex,
749
- isEditable: true,
750
- onChangeField: handleChangeField,
751
- syncExternalValue: !editing,
752
- onFocus: handleFocus,
753
- onBlur: handleBlur,
754
- inputRef: handleInputRef
755
- }
756
- )
757
- }
758
- )
759
- ]
760
- }
761
- );
762
- }
763
- function ToggleFillMode(props) {
764
- const { annotation, field, scale, pageIndex, scope, handleChangeField, renderKey, isReadOnly } = useFormWidgetState(props);
765
- const formState = useFormDocumentState(props.documentId);
766
- const wrapperRef = useRef(null);
767
- const isFocused = formState.selectedFieldId === annotation.id;
768
- useEffect(() => {
769
- if (isFocused && wrapperRef.current && document.activeElement !== wrapperRef.current) {
770
- wrapperRef.current.focus();
771
- }
772
- }, [isFocused]);
773
- const toggle = useCallback(() => {
774
- if (isReadOnly) return;
775
- const checked = isWidgetChecked(annotation);
776
- const newValue = checked ? "Off" : annotation.exportValue ?? "Yes";
777
- handleChangeField({ ...field, value: newValue });
778
- }, [isReadOnly, annotation, field, handleChangeField]);
779
- const handleClick = useCallback(() => {
780
- if (isReadOnly) return;
781
- scope == null ? void 0 : scope.selectField(annotation.id);
782
- toggle();
783
- }, [isReadOnly, scope, annotation.id, toggle]);
784
- const handleFocus = useCallback(() => {
785
- if (isReadOnly) return;
786
- scope == null ? void 0 : scope.selectField(annotation.id);
787
- }, [isReadOnly, scope, annotation.id]);
788
- const handleBlur = useCallback(() => {
789
- if ((scope == null ? void 0 : scope.getSelectedFieldId()) === annotation.id) {
790
- scope == null ? void 0 : scope.deselectField();
791
- }
792
- }, [scope, annotation.id]);
793
- const handleKeyDown = useCallback(
794
- (e) => {
795
- if (e.key === " " || e.key === "Enter") {
796
- e.preventDefault();
797
- toggle();
798
- }
799
- },
800
- [toggle]
801
- );
802
- return /* @__PURE__ */ jsx(
803
- "div",
804
- {
805
- ref: wrapperRef,
806
- tabIndex: isReadOnly ? -1 : 0,
807
- onClick: handleClick,
808
- onFocus: handleFocus,
809
- onBlur: handleBlur,
810
- onKeyDown: handleKeyDown,
811
- style: {
812
- width: "100%",
813
- height: "100%",
814
- overflow: "hidden",
815
- cursor: isReadOnly ? "default" : "pointer",
816
- pointerEvents: "auto",
817
- outline: isFocused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
818
- outlineOffset: -2
819
- },
820
- children: /* @__PURE__ */ jsx(
821
- RenderWidget,
822
- {
823
- pageIndex,
824
- annotation,
825
- scaleFactor: scale,
826
- renderKey,
827
- style: { pointerEvents: "none" }
828
- }
829
- )
830
- }
831
- );
832
- }
833
- function RadioButtonFillMode(props) {
834
- const { annotation, field, scale, pageIndex, scope, handleChangeField, renderKey, isReadOnly } = useFormWidgetState(props);
835
- const formState = useFormDocumentState(props.documentId);
836
- const wrapperRef = useRef(null);
837
- const isFocused = formState.selectedFieldId === annotation.id;
838
- useEffect(() => {
839
- if (isFocused && wrapperRef.current && document.activeElement !== wrapperRef.current) {
840
- wrapperRef.current.focus();
841
- }
842
- }, [isFocused]);
843
- const selectRadio = useCallback(() => {
844
- if (isReadOnly) return;
845
- if (!isWidgetChecked(annotation) && annotation.exportValue) {
846
- handleChangeField({ ...field, value: annotation.exportValue });
847
- }
848
- }, [isReadOnly, annotation, field, handleChangeField]);
849
- const handleClick = useCallback(() => {
850
- if (isReadOnly) return;
851
- scope == null ? void 0 : scope.selectField(annotation.id);
852
- selectRadio();
853
- }, [isReadOnly, scope, annotation.id, selectRadio]);
854
- const handleFocus = useCallback(() => {
855
- if (isReadOnly) return;
856
- scope == null ? void 0 : scope.selectField(annotation.id);
857
- }, [isReadOnly, scope, annotation.id]);
858
- const handleBlur = useCallback(() => {
859
- if ((scope == null ? void 0 : scope.getSelectedFieldId()) === annotation.id) {
860
- scope == null ? void 0 : scope.deselectField();
861
- }
862
- }, [scope, annotation.id]);
863
- const handleKeyDown = useCallback(
864
- (e) => {
865
- if (e.key === " " || e.key === "Enter") {
866
- e.preventDefault();
867
- selectRadio();
868
- }
869
- },
870
- [selectRadio]
871
- );
872
- return /* @__PURE__ */ jsx(
873
- "div",
874
- {
875
- ref: wrapperRef,
876
- tabIndex: isReadOnly ? -1 : 0,
877
- onClick: handleClick,
878
- onFocus: handleFocus,
879
- onBlur: handleBlur,
880
- onKeyDown: handleKeyDown,
881
- style: {
882
- width: "100%",
883
- height: "100%",
884
- overflow: "hidden",
885
- cursor: isReadOnly ? "default" : "pointer",
886
- pointerEvents: "auto",
887
- outline: isFocused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
888
- outlineOffset: -2
889
- },
890
- children: /* @__PURE__ */ jsx(
891
- RenderWidget,
892
- {
893
- pageIndex,
894
- annotation,
895
- scaleFactor: scale,
896
- renderKey,
897
- style: { pointerEvents: "none" }
898
- }
899
- )
900
- }
901
- );
902
- }
903
- function ComboboxField(props) {
904
- const { annotation, isEditable, onChangeField, onBlur, inputRef } = props;
905
- const field = annotation.field;
906
- const { flag, options } = field;
907
- const name = field.alternateName || field.name;
908
- const isDisabled = !isEditable || !!(flag & PDF_FORM_FIELD_FLAG.READONLY);
909
- const isRequired = !!(flag & PDF_FORM_FIELD_FLAG.REQUIRED);
910
- const handleChange = useCallback(
911
- (evt) => {
912
- const select = evt.target;
913
- const updatedOptions = options.map((opt, i) => ({
914
- ...opt,
915
- isSelected: i === select.selectedIndex
916
- }));
917
- onChangeField == null ? void 0 : onChangeField({ ...field, options: updatedOptions });
918
- },
919
- [onChangeField, field, options]
920
- );
921
- const selectedTexts = options.filter((opt) => opt.isSelected).map((opt) => opt.label);
922
- return /* @__PURE__ */ jsx(
923
- "select",
924
- {
925
- ref: inputRef,
926
- required: isRequired,
927
- disabled: isDisabled,
928
- name,
929
- "aria-label": name,
930
- ...selectProps(false, selectedTexts),
931
- onChange: handleChange,
932
- onBlur,
933
- style: { ...selectStyle, opacity: 0 },
934
- children: options.map((option, index) => {
935
- return /* @__PURE__ */ jsx(
936
- "option",
937
- {
938
- value: option.label,
939
- ...optionProps(false, selectedTexts, option.label),
940
- children: option.label
941
- },
942
- index
943
- );
944
- })
945
- }
946
- );
947
- }
948
- function ComboboxFillMode(props) {
949
- const { annotation, scale, pageIndex, scope, handleChangeField, renderKey, isReadOnly } = useFormWidgetState(props);
950
- const formState = useFormDocumentState(props.documentId);
951
- const wrapperRef = useRef(null);
952
- const selectElRef = useRef(null);
953
- const isFocused = formState.selectedFieldId === annotation.id;
954
- useEffect(() => {
955
- if (isFocused && wrapperRef.current && !wrapperRef.current.contains(document.activeElement)) {
956
- (selectElRef.current ?? wrapperRef.current).focus();
957
- }
958
- }, [isFocused]);
959
- const handleFocus = useCallback(() => {
960
- scope == null ? void 0 : scope.selectField(annotation.id);
961
- }, [scope, annotation.id]);
962
- const handleBlur = useCallback(() => {
963
- requestAnimationFrame(() => {
964
- var _a;
965
- if ((_a = wrapperRef.current) == null ? void 0 : _a.contains(document.activeElement)) return;
966
- if ((scope == null ? void 0 : scope.getSelectedFieldId()) === annotation.id) {
967
- scope == null ? void 0 : scope.deselectField();
968
- }
969
- });
970
- }, [scope, annotation.id]);
971
- const selectInputRef = useCallback((el) => {
972
- selectElRef.current = el;
973
- }, []);
974
- return /* @__PURE__ */ jsxs(
975
- "div",
976
- {
977
- ref: wrapperRef,
978
- onFocus: handleFocus,
979
- onBlur: handleBlur,
980
- style: {
981
- width: "100%",
982
- height: "100%",
983
- overflow: "hidden",
984
- cursor: isReadOnly ? "default" : "pointer",
985
- pointerEvents: "auto",
986
- outline: isFocused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
987
- outlineOffset: -2
988
- },
989
- children: [
990
- /* @__PURE__ */ jsx(
991
- RenderWidget,
992
- {
993
- pageIndex,
994
- annotation,
995
- scaleFactor: scale,
996
- renderKey,
997
- style: { pointerEvents: "none" }
998
- }
999
- ),
1000
- /* @__PURE__ */ jsx(
1001
- ComboboxField,
1002
- {
1003
- annotation,
1004
- scale,
1005
- pageIndex,
1006
- isEditable: true,
1007
- onChangeField: handleChangeField,
1008
- inputRef: selectInputRef
1009
- }
1010
- )
1011
- ]
1012
- }
1013
- );
1014
- }
1015
- function ListboxField(props) {
1016
- const { annotation, isEditable, onChangeField, onBlur, inputRef, scale } = props;
1017
- const field = annotation.field;
1018
- const { flag, options } = field;
1019
- const isDisabled = !isEditable || !!(flag & PDF_FORM_FIELD_FLAG.READONLY);
1020
- const isMultipleChoice = !!(flag & PDF_FORM_FIELD_FLAG.CHOICE_MULTL_SELECT);
1021
- const bw = (annotation.strokeWidth ?? 0) * scale;
1022
- const fontSize = (annotation.fontSize ?? 12) * scale;
1023
- const lineHeight = fontSize * 1.2;
1024
- const fontCss = standardFontCssProperties(annotation.fontFamily);
1025
- const containerStyle = useMemo(
1026
- () => ({
1027
- position: "absolute",
1028
- top: 0,
1029
- left: 0,
1030
- width: "100%",
1031
- height: "100%",
1032
- background: annotation.color ?? "#FFFFFF",
1033
- borderStyle: "solid",
1034
- borderColor: annotation.strokeColor ?? "#000000",
1035
- borderWidth: bw,
1036
- boxSizing: "border-box",
1037
- overflow: "auto",
1038
- display: "flex",
1039
- flexDirection: "column",
1040
- outline: "none"
1041
- }),
1042
- [annotation.color, annotation.strokeColor, bw]
1043
- );
1044
- const handleOptionClick = useCallback(
1045
- (clickedIndex) => {
1046
- if (isDisabled) return;
1047
- const updatedOptions = options.map((opt, i) => ({
1048
- ...opt,
1049
- isSelected: isMultipleChoice ? i === clickedIndex ? !opt.isSelected : opt.isSelected : i === clickedIndex
1050
- }));
1051
- onChangeField == null ? void 0 : onChangeField({ ...field, options: updatedOptions });
1052
- },
1053
- [isDisabled, isMultipleChoice, options, field, onChangeField]
1054
- );
1055
- return /* @__PURE__ */ jsx(
1056
- "div",
1057
- {
1058
- ref: inputRef,
1059
- onBlur,
1060
- style: containerStyle,
1061
- children: options.map((opt, i) => /* @__PURE__ */ jsx(
1062
- "div",
1063
- {
1064
- onClick: () => handleOptionClick(i),
1065
- style: {
1066
- padding: `0 ${4 * scale}px`,
1067
- fontSize,
1068
- lineHeight: `${lineHeight}px`,
1069
- ...fontCss,
1070
- color: opt.isSelected ? "#FFFFFF" : annotation.fontColor ?? "#000000",
1071
- background: opt.isSelected ? "rgba(0, 51, 113, 1)" : "transparent",
1072
- whiteSpace: "nowrap",
1073
- overflow: "hidden",
1074
- textOverflow: "ellipsis",
1075
- cursor: isDisabled ? "default" : "pointer"
1076
- },
1077
- children: opt.label
1078
- },
1079
- i
1080
- ))
1081
- }
1082
- );
1083
- }
1084
- function ListboxFillMode(props) {
1085
- const { annotation, scale, pageIndex, scope, handleChangeField, renderKey, isReadOnly } = useFormWidgetState(props);
1086
- const formState = useFormDocumentState(props.documentId);
1087
- const [editing, setEditing] = useState(false);
1088
- const wrapperRef = useRef(null);
1089
- const isFocused = formState.selectedFieldId === annotation.id;
1090
- useEffect(() => {
1091
- if (isFocused && wrapperRef.current && !wrapperRef.current.contains(document.activeElement)) {
1092
- wrapperRef.current.focus();
1093
- }
1094
- }, [isFocused]);
1095
- const handleFocus = useCallback(() => {
1096
- if (isReadOnly) return;
1097
- scope == null ? void 0 : scope.selectField(annotation.id);
1098
- setEditing(true);
1099
- }, [isReadOnly, scope, annotation.id]);
1100
- const handleBlur = useCallback(() => {
1101
- requestAnimationFrame(() => {
1102
- var _a;
1103
- if ((_a = wrapperRef.current) == null ? void 0 : _a.contains(document.activeElement)) return;
1104
- setEditing(false);
1105
- if ((scope == null ? void 0 : scope.getSelectedFieldId()) === annotation.id) {
1106
- scope == null ? void 0 : scope.deselectField();
1107
- }
1108
- });
1109
- }, [scope, annotation.id]);
1110
- return /* @__PURE__ */ jsxs(
1111
- "div",
1112
- {
1113
- ref: wrapperRef,
1114
- tabIndex: isReadOnly ? -1 : 0,
1115
- onFocus: handleFocus,
1116
- onBlur: handleBlur,
1117
- style: {
1118
- width: "100%",
1119
- height: "100%",
1120
- overflow: "hidden",
1121
- cursor: isReadOnly ? "default" : "pointer",
1122
- pointerEvents: "auto",
1123
- outline: isFocused && !editing ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
1124
- outlineOffset: -2
1125
- },
1126
- children: [
1127
- /* @__PURE__ */ jsx(
1128
- ListboxField,
1129
- {
1130
- annotation,
1131
- scale,
1132
- pageIndex,
1133
- isEditable: true,
1134
- onChangeField: handleChangeField
1135
- }
1136
- ),
1137
- !editing && /* @__PURE__ */ jsx(
1138
- RenderWidget,
1139
- {
1140
- pageIndex,
1141
- annotation,
1142
- scaleFactor: scale,
1143
- renderKey,
1144
- style: { pointerEvents: "none" }
1145
- }
1146
- )
1147
- ]
1148
- }
1149
- );
1150
- }
1151
- const formRenderers = [
1152
- createRenderer({
1153
- id: "formTextField",
1154
- matches: (a) => {
1155
- var _a;
1156
- return a.type === PdfAnnotationSubtype.WIDGET && ((_a = a.field) == null ? void 0 : _a.type) === PDF_FORM_FIELD_TYPE.TEXTFIELD;
1157
- },
1158
- render: ({ annotation, isSelected, scale, pageIndex, onClick }) => /* @__PURE__ */ jsx(
1159
- FormTextField,
1160
- {
1161
- annotation,
1162
- isSelected,
1163
- scale,
1164
- pageIndex,
1165
- onClick
1166
- }
1167
- ),
1168
- renderPreview: ({ bounds, scale }) => /* @__PURE__ */ jsx(
1169
- "div",
1170
- {
1171
- style: {
1172
- position: "absolute",
1173
- left: 0,
1174
- top: 0,
1175
- width: bounds.size.width * scale,
1176
- height: bounds.size.height * scale,
1177
- border: "1px dashed rgba(66, 133, 244, 0.6)",
1178
- backgroundColor: "rgba(255, 255, 255, 0.9)",
1179
- boxSizing: "border-box",
1180
- display: "flex",
1181
- alignItems: "center",
1182
- padding: `0 ${2 * scale}px`,
1183
- overflow: "hidden"
1184
- }
1185
- }
1186
- ),
1187
- interactionDefaults: { isDraggable: false, isResizable: true, isRotatable: false },
1188
- useAppearanceStream: false,
1189
- renderLocked: (props) => /* @__PURE__ */ jsx(TextFillMode, { ...props })
1190
- }),
1191
- createRenderer({
1192
- id: "formCheckbox",
1193
- matches: (a) => {
1194
- var _a;
1195
- return a.type === PdfAnnotationSubtype.WIDGET && ((_a = a.field) == null ? void 0 : _a.type) === PDF_FORM_FIELD_TYPE.CHECKBOX;
1196
- },
1197
- render: ({ annotation, isSelected, scale, pageIndex, onClick }) => /* @__PURE__ */ jsx(
1198
- FormCheckbox,
1199
- {
1200
- annotation,
1201
- isSelected,
1202
- scale,
1203
- pageIndex,
1204
- onClick
1205
- }
1206
- ),
1207
- renderPreview: ({ bounds, scale }) => /* @__PURE__ */ jsx(
1208
- "div",
1209
- {
1210
- style: {
1211
- position: "absolute",
1212
- left: 0,
1213
- top: 0,
1214
- width: bounds.size.width * scale,
1215
- height: bounds.size.height * scale,
1216
- border: "1px dashed rgba(66, 133, 244, 0.6)",
1217
- backgroundColor: "rgba(255, 255, 255, 0.9)",
1218
- boxSizing: "border-box",
1219
- display: "flex",
1220
- alignItems: "center",
1221
- justifyContent: "center"
1222
- }
1223
- }
1224
- ),
1225
- interactionDefaults: { isDraggable: false, isResizable: true, isRotatable: false },
1226
- useAppearanceStream: false,
1227
- renderLocked: (props) => /* @__PURE__ */ jsx(ToggleFillMode, { ...props })
1228
- }),
1229
- createRenderer({
1230
- id: "formRadioButton",
1231
- matches: (a) => {
1232
- var _a;
1233
- return a.type === PdfAnnotationSubtype.WIDGET && ((_a = a.field) == null ? void 0 : _a.type) === PDF_FORM_FIELD_TYPE.RADIOBUTTON;
1234
- },
1235
- render: ({ annotation, isSelected, scale, pageIndex, onClick }) => /* @__PURE__ */ jsx(
1236
- FormRadioButton,
1237
- {
1238
- annotation,
1239
- isSelected,
1240
- scale,
1241
- pageIndex,
1242
- onClick
1243
- }
1244
- ),
1245
- renderPreview: ({ bounds, scale }) => /* @__PURE__ */ jsx(
1246
- "div",
1247
- {
1248
- style: {
1249
- position: "absolute",
1250
- left: 0,
1251
- top: 0,
1252
- width: bounds.size.width * scale,
1253
- height: bounds.size.height * scale,
1254
- border: "1px dashed rgba(66, 133, 244, 0.6)",
1255
- backgroundColor: "rgba(255, 255, 255, 0.9)",
1256
- borderRadius: "50%",
1257
- boxSizing: "border-box",
1258
- display: "flex",
1259
- alignItems: "center",
1260
- justifyContent: "center"
1261
- }
1262
- }
1263
- ),
1264
- interactionDefaults: { isDraggable: false, isResizable: true, isRotatable: false },
1265
- useAppearanceStream: false,
1266
- renderLocked: (props) => /* @__PURE__ */ jsx(RadioButtonFillMode, { ...props })
1267
- }),
1268
- createRenderer({
1269
- id: "formCombobox",
1270
- matches: (a) => {
1271
- var _a;
1272
- return a.type === PdfAnnotationSubtype.WIDGET && ((_a = a.field) == null ? void 0 : _a.type) === PDF_FORM_FIELD_TYPE.COMBOBOX;
1273
- },
1274
- render: ({ annotation, isSelected, scale, pageIndex, onClick }) => /* @__PURE__ */ jsx(
1275
- FormCombobox,
1276
- {
1277
- annotation,
1278
- isSelected,
1279
- scale,
1280
- pageIndex,
1281
- onClick
1282
- }
1283
- ),
1284
- renderPreview: ({ bounds, scale }) => /* @__PURE__ */ jsx(
1285
- "div",
1286
- {
1287
- style: {
1288
- position: "absolute",
1289
- left: 0,
1290
- top: 0,
1291
- width: bounds.size.width * scale,
1292
- height: bounds.size.height * scale,
1293
- border: "1px dashed rgba(66, 133, 244, 0.6)",
1294
- backgroundColor: "rgba(255, 255, 255, 0.9)",
1295
- boxSizing: "border-box",
1296
- display: "flex",
1297
- alignItems: "center",
1298
- padding: `0 ${2 * scale}px`,
1299
- overflow: "hidden"
1300
- }
1301
- }
1302
- ),
1303
- interactionDefaults: { isDraggable: false, isResizable: true, isRotatable: false },
1304
- useAppearanceStream: false,
1305
- renderLocked: (props) => /* @__PURE__ */ jsx(ComboboxFillMode, { ...props })
1306
- }),
1307
- createRenderer({
1308
- id: "formListbox",
1309
- matches: (a) => {
1310
- var _a;
1311
- return a.type === PdfAnnotationSubtype.WIDGET && ((_a = a.field) == null ? void 0 : _a.type) === PDF_FORM_FIELD_TYPE.LISTBOX;
1312
- },
1313
- render: ({ annotation, isSelected, scale, pageIndex, onClick }) => /* @__PURE__ */ jsx(
1314
- FormListbox,
1315
- {
1316
- annotation,
1317
- isSelected,
1318
- scale,
1319
- pageIndex,
1320
- onClick
1321
- }
1322
- ),
1323
- renderPreview: ({ bounds, scale }) => /* @__PURE__ */ jsx(
1324
- "div",
1325
- {
1326
- style: {
1327
- position: "absolute",
1328
- left: 0,
1329
- top: 0,
1330
- width: bounds.size.width * scale,
1331
- height: bounds.size.height * scale,
1332
- border: "1px dashed rgba(66, 133, 244, 0.6)",
1333
- backgroundColor: "rgba(255, 255, 255, 0.9)",
1334
- boxSizing: "border-box",
1335
- display: "flex",
1336
- flexDirection: "column",
1337
- overflow: "hidden"
1338
- }
1339
- }
1340
- ),
1341
- interactionDefaults: { isDraggable: false, isResizable: true, isRotatable: false },
1342
- useAppearanceStream: false,
1343
- renderLocked: (props) => /* @__PURE__ */ jsx(ListboxFillMode, { ...props })
1344
- })
1345
- ];
1346
- function FormRendererRegistration() {
1347
- useRegisterRenderers(formRenderers);
1348
- return null;
1349
- }
1350
- const FormPluginPackage = createPluginPackage(FormPluginPackage$1).addUtility(FormRendererRegistration).build();
1351
- export {
1352
- FormPluginPackage,
1353
- FormRendererRegistration,
1354
- formRenderers,
1355
- useFormCapability,
1356
- useFormDocumentState,
1357
- useFormPlugin
1358
- };
1359
- //# sourceMappingURL=index.js.map