@embedpdf/react 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 (141) hide show
  1. package/LICENSE +192 -0
  2. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.cts +2593 -0
  3. package/dist/AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.d.ts +2593 -0
  4. package/dist/annotation-B6jwfTCh.d.cts +173 -0
  5. package/dist/annotation-Ct6dFtzJ.cjs +913 -0
  6. package/dist/annotation-Ct6dFtzJ.cjs.map +1 -0
  7. package/dist/annotation-DjGWJljY.js +829 -0
  8. package/dist/annotation-DjGWJljY.js.map +1 -0
  9. package/dist/annotation-menu.cjs +115 -0
  10. package/dist/annotation-menu.cjs.map +1 -0
  11. package/dist/annotation-menu.d.cts +7 -0
  12. package/dist/annotation-menu.d.ts +7 -0
  13. package/dist/annotation-menu.js +99 -0
  14. package/dist/annotation-menu.js.map +1 -0
  15. package/dist/annotation-nUMefyjw.d.ts +173 -0
  16. package/dist/annotation.cjs +25 -0
  17. package/dist/annotation.d.cts +3 -0
  18. package/dist/annotation.d.ts +3 -0
  19. package/dist/annotation.js +4 -0
  20. package/dist/commands.cjs +59 -0
  21. package/dist/commands.cjs.map +1 -0
  22. package/dist/commands.d.cts +20 -0
  23. package/dist/commands.d.ts +20 -0
  24. package/dist/commands.js +47 -0
  25. package/dist/commands.js.map +1 -0
  26. package/dist/form.cjs +560 -0
  27. package/dist/form.cjs.map +1 -0
  28. package/dist/form.d.cts +52 -0
  29. package/dist/form.d.ts +52 -0
  30. package/dist/form.js +545 -0
  31. package/dist/form.js.map +1 -0
  32. package/dist/i18n.cjs +52 -0
  33. package/dist/i18n.cjs.map +1 -0
  34. package/dist/i18n.d.cts +30 -0
  35. package/dist/i18n.d.ts +30 -0
  36. package/dist/i18n.js +42 -0
  37. package/dist/i18n.js.map +1 -0
  38. package/dist/index.cjs +240 -0
  39. package/dist/index.d.cts +37 -0
  40. package/dist/index.d.ts +37 -0
  41. package/dist/index.js +37 -0
  42. package/dist/interaction.cjs +152 -0
  43. package/dist/interaction.cjs.map +1 -0
  44. package/dist/interaction.d.cts +46 -0
  45. package/dist/interaction.d.ts +46 -0
  46. package/dist/interaction.js +139 -0
  47. package/dist/interaction.js.map +1 -0
  48. package/dist/link.cjs +108 -0
  49. package/dist/link.cjs.map +1 -0
  50. package/dist/link.d.cts +16 -0
  51. package/dist/link.d.ts +16 -0
  52. package/dist/link.js +98 -0
  53. package/dist/link.js.map +1 -0
  54. package/dist/metadata.cjs +25 -0
  55. package/dist/metadata.cjs.map +1 -0
  56. package/dist/metadata.d.cts +11 -0
  57. package/dist/metadata.d.ts +11 -0
  58. package/dist/metadata.js +16 -0
  59. package/dist/metadata.js.map +1 -0
  60. package/dist/page-edit.cjs +20 -0
  61. package/dist/page-edit.cjs.map +1 -0
  62. package/dist/page-edit.d.cts +7 -0
  63. package/dist/page-edit.d.ts +7 -0
  64. package/dist/page-edit.js +11 -0
  65. package/dist/page-edit.js.map +1 -0
  66. package/dist/page-view.cjs +107 -0
  67. package/dist/page-view.cjs.map +1 -0
  68. package/dist/page-view.d.cts +23 -0
  69. package/dist/page-view.d.ts +23 -0
  70. package/dist/page-view.js +95 -0
  71. package/dist/page-view.js.map +1 -0
  72. package/dist/redaction.cjs +35 -0
  73. package/dist/redaction.cjs.map +1 -0
  74. package/dist/redaction.d.cts +14 -0
  75. package/dist/redaction.d.ts +14 -0
  76. package/dist/redaction.js +25 -0
  77. package/dist/redaction.js.map +1 -0
  78. package/dist/render.cjs +142 -0
  79. package/dist/render.cjs.map +1 -0
  80. package/dist/render.d.cts +32 -0
  81. package/dist/render.d.ts +32 -0
  82. package/dist/render.js +131 -0
  83. package/dist/render.js.map +1 -0
  84. package/dist/rolldown-runtime-DDXJien1.cjs +50 -0
  85. package/dist/runtime-CMxIuF2O.d.cts +195 -0
  86. package/dist/runtime-DV98q7I0.d.ts +195 -0
  87. package/dist/runtime.cjs +314 -0
  88. package/dist/runtime.cjs.map +1 -0
  89. package/dist/runtime.d.cts +3 -0
  90. package/dist/runtime.d.ts +3 -0
  91. package/dist/runtime.js +287 -0
  92. package/dist/runtime.js.map +1 -0
  93. package/dist/scrollbar.cjs +241 -0
  94. package/dist/scrollbar.cjs.map +1 -0
  95. package/dist/scrollbar.d.cts +42 -0
  96. package/dist/scrollbar.d.ts +42 -0
  97. package/dist/scrollbar.js +213 -0
  98. package/dist/scrollbar.js.map +1 -0
  99. package/dist/search.cjs +70 -0
  100. package/dist/search.cjs.map +1 -0
  101. package/dist/search.d.cts +35 -0
  102. package/dist/search.d.ts +35 -0
  103. package/dist/search.js +58 -0
  104. package/dist/search.js.map +1 -0
  105. package/dist/selection.cjs +60 -0
  106. package/dist/selection.cjs.map +1 -0
  107. package/dist/selection.d.cts +12 -0
  108. package/dist/selection.d.ts +12 -0
  109. package/dist/selection.js +49 -0
  110. package/dist/selection.js.map +1 -0
  111. package/dist/shell.cjs +57 -0
  112. package/dist/shell.cjs.map +1 -0
  113. package/dist/shell.d.cts +27 -0
  114. package/dist/shell.d.ts +27 -0
  115. package/dist/shell.js +46 -0
  116. package/dist/shell.js.map +1 -0
  117. package/dist/stage.cjs +343 -0
  118. package/dist/stage.cjs.map +1 -0
  119. package/dist/stage.d.cts +104 -0
  120. package/dist/stage.d.ts +104 -0
  121. package/dist/stage.js +327 -0
  122. package/dist/stage.js.map +1 -0
  123. package/dist/stamp.cjs +76 -0
  124. package/dist/stamp.cjs.map +1 -0
  125. package/dist/stamp.d.cts +28 -0
  126. package/dist/stamp.d.ts +28 -0
  127. package/dist/stamp.js +63 -0
  128. package/dist/stamp.js.map +1 -0
  129. package/dist/toolbar.cjs +515 -0
  130. package/dist/toolbar.cjs.map +1 -0
  131. package/dist/toolbar.d.cts +100 -0
  132. package/dist/toolbar.d.ts +100 -0
  133. package/dist/toolbar.js +505 -0
  134. package/dist/toolbar.js.map +1 -0
  135. package/dist/views.cjs +35 -0
  136. package/dist/views.cjs.map +1 -0
  137. package/dist/views.d.cts +21 -0
  138. package/dist/views.d.ts +21 -0
  139. package/dist/views.js +26 -0
  140. package/dist/views.js.map +1 -0
  141. package/package.json +158 -0
@@ -0,0 +1,52 @@
1
+ import { n as FormSnapshot } from "./AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.cjs";
2
+ import { u as AnnotationRenderer } from "./annotation-B6jwfTCh.cjs";
3
+ import { FormFieldDTO, FormUiEffect, FormUiEffectProvider } from "@embedpdf/plugin-form";
4
+ export * from "@embedpdf/plugin-form";
5
+ //#region src/form.d.ts
6
+ interface FormScriptingUiHandlers {
7
+ alert?: (message: string, effect: Extract<FormUiEffect, {
8
+ kind: 'alert';
9
+ }>) => void;
10
+ print?: (effect: Extract<FormUiEffect, {
11
+ kind: 'print';
12
+ }>) => void;
13
+ gotoPage?: (page: number, effect: Extract<FormUiEffect, {
14
+ kind: 'gotoPage';
15
+ }>) => void;
16
+ }
17
+ /**
18
+ * Fulfil form-script UI requests for the active document. By default alerts use
19
+ * the browser dialog, page navigation uses the main Stage, and print delegates
20
+ * to the browser. Pass handlers (or one raw provider) to replace that policy.
21
+ */
22
+ declare function useFormScriptingProvider(adapter?: FormScriptingUiHandlers | FormUiEffectProvider): void;
23
+ /**
24
+ * The form plugin's renderer entry, ready for
25
+ * `<AnnotationLayer renderers={[formWidgetRenderer]} />`. It answers for the
26
+ * PLUGIN-registered 'form-widgets' Behavior — the form plugin decides when
27
+ * widgets are fill controls vs. editable annotations, never the app.
28
+ */
29
+ declare const formWidgetRenderer: AnnotationRenderer;
30
+ /**
31
+ * Fill-mode form controls for one page, positioned from the form model's own
32
+ * widget geometry — the ANNOTATION-LESS path (a fill-only viewer whose page
33
+ * pixels come from an annotated RenderLayer raster). Active whenever the
34
+ * active tool carries the 'form-fill' tag (the built-in pointer/pan tools
35
+ * do); any other tool stands the controls down. Do not mount next to an
36
+ * AnnotationLayer wired with `formWidgetBehaviors`.
37
+ */
38
+ declare function FormLayer(): import("react/jsx-runtime").JSX.Element | null;
39
+ /** The form capability — values, interchange, design-mode verbs. */
40
+ declare function useForm(): import("@embedpdf/plugin-form").FormCapability;
41
+ /** The reconciled form snapshot (null until the first load lands),
42
+ * re-rendering on every form model change. */
43
+ declare function useFormSnapshot(): FormSnapshot | null;
44
+ /**
45
+ * The FIELD behind the currently selected widget annotation (single
46
+ * selection), or null. The design-mode join: widget selection lives in the
47
+ * annotation plane, field properties live here.
48
+ */
49
+ declare function useFormField(): FormFieldDTO | null;
50
+ //#endregion
51
+ export { FormLayer, FormScriptingUiHandlers, formWidgetRenderer, useForm, useFormField, useFormScriptingProvider, useFormSnapshot };
52
+ //# sourceMappingURL=form.d.cts.map
package/dist/form.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { n as FormSnapshot } from "./AnnotationListSnapshot-W0RCsyDE-dWna4TTJ.js";
2
+ import { u as AnnotationRenderer } from "./annotation-nUMefyjw.js";
3
+ import { FormFieldDTO, FormUiEffect, FormUiEffectProvider } from "@embedpdf/plugin-form";
4
+ export * from "@embedpdf/plugin-form";
5
+ //#region src/form.d.ts
6
+ interface FormScriptingUiHandlers {
7
+ alert?: (message: string, effect: Extract<FormUiEffect, {
8
+ kind: 'alert';
9
+ }>) => void;
10
+ print?: (effect: Extract<FormUiEffect, {
11
+ kind: 'print';
12
+ }>) => void;
13
+ gotoPage?: (page: number, effect: Extract<FormUiEffect, {
14
+ kind: 'gotoPage';
15
+ }>) => void;
16
+ }
17
+ /**
18
+ * Fulfil form-script UI requests for the active document. By default alerts use
19
+ * the browser dialog, page navigation uses the main Stage, and print delegates
20
+ * to the browser. Pass handlers (or one raw provider) to replace that policy.
21
+ */
22
+ declare function useFormScriptingProvider(adapter?: FormScriptingUiHandlers | FormUiEffectProvider): void;
23
+ /**
24
+ * The form plugin's renderer entry, ready for
25
+ * `<AnnotationLayer renderers={[formWidgetRenderer]} />`. It answers for the
26
+ * PLUGIN-registered 'form-widgets' Behavior — the form plugin decides when
27
+ * widgets are fill controls vs. editable annotations, never the app.
28
+ */
29
+ declare const formWidgetRenderer: AnnotationRenderer;
30
+ /**
31
+ * Fill-mode form controls for one page, positioned from the form model's own
32
+ * widget geometry — the ANNOTATION-LESS path (a fill-only viewer whose page
33
+ * pixels come from an annotated RenderLayer raster). Active whenever the
34
+ * active tool carries the 'form-fill' tag (the built-in pointer/pan tools
35
+ * do); any other tool stands the controls down. Do not mount next to an
36
+ * AnnotationLayer wired with `formWidgetBehaviors`.
37
+ */
38
+ declare function FormLayer(): import("react/jsx-runtime").JSX.Element | null;
39
+ /** The form capability — values, interchange, design-mode verbs. */
40
+ declare function useForm(): import("@embedpdf/plugin-form").FormCapability;
41
+ /** The reconciled form snapshot (null until the first load lands),
42
+ * re-rendering on every form model change. */
43
+ declare function useFormSnapshot(): FormSnapshot | null;
44
+ /**
45
+ * The FIELD behind the currently selected widget annotation (single
46
+ * selection), or null. The design-mode join: widget selection lives in the
47
+ * annotation plane, field properties live here.
48
+ */
49
+ declare function useFormField(): FormFieldDTO | null;
50
+ //#endregion
51
+ export { FormLayer, FormScriptingUiHandlers, formWidgetRenderer, useForm, useFormField, useFormScriptingProvider, useFormSnapshot };
52
+ //# sourceMappingURL=form.d.ts.map
package/dist/form.js ADDED
@@ -0,0 +1,545 @@
1
+ import { shallowArray, useCapability, useOptionalCapability, usePage, useSelector } from "./runtime.js";
2
+ import { l as useAnnotationSelected } from "./annotation-DjGWJljY.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { StageToken } from "@embedpdf/plugin-stage";
6
+ import { InteractionToken } from "@embedpdf/plugin-interaction";
7
+ import { FormToken } from "@embedpdf/plugin-form";
8
+ export * from "@embedpdf/plugin-form";
9
+ //#region src/form.tsx
10
+ /** Content rect → a view-px box (the page wrapper's own coordinate space). */
11
+ function viewBox(r, page) {
12
+ const tl = page.transform.pageToContent({
13
+ x: r.x,
14
+ y: r.y
15
+ });
16
+ const br = page.transform.pageToContent({
17
+ x: r.x + r.width,
18
+ y: r.y + r.height
19
+ });
20
+ return {
21
+ left: tl.x,
22
+ top: tl.y,
23
+ width: br.x - tl.x,
24
+ height: br.y - tl.y
25
+ };
26
+ }
27
+ /**
28
+ * Keep the interaction hub out of gestures that begin inside a fill control.
29
+ * Native listener (not React's) so it runs during real DOM bubbling, before
30
+ * the Stage's own native listener on an ancestor — same trick as FreeText.
31
+ */
32
+ function useIsolated() {
33
+ const ref = useRef(null);
34
+ useEffect(() => {
35
+ const el = ref.current;
36
+ if (!el) return;
37
+ const stop = (e) => e.stopPropagation();
38
+ el.addEventListener("pointerdown", stop);
39
+ return () => el.removeEventListener("pointerdown", stop);
40
+ }, []);
41
+ return ref;
42
+ }
43
+ /**
44
+ * Fulfil form-script UI requests for the active document. By default alerts use
45
+ * the browser dialog, page navigation uses the main Stage, and print delegates
46
+ * to the browser. Pass handlers (or one raw provider) to replace that policy.
47
+ */
48
+ function useFormScriptingProvider(adapter) {
49
+ const form = useOptionalCapability(FormToken);
50
+ const stage = useOptionalCapability(StageToken);
51
+ const adapterRef = useRef(adapter);
52
+ adapterRef.current = adapter;
53
+ useEffect(() => {
54
+ if (!form) return;
55
+ const provider = (effect) => {
56
+ const current = adapterRef.current;
57
+ if (typeof current === "function") {
58
+ current(effect);
59
+ return;
60
+ }
61
+ switch (effect.kind) {
62
+ case "alert":
63
+ if (current?.alert) current.alert(effect.message, effect);
64
+ else if (typeof globalThis.alert === "function") globalThis.alert(effect.message);
65
+ break;
66
+ case "gotoPage":
67
+ if (current?.gotoPage) current.gotoPage(effect.page, effect);
68
+ else stage?.goToPage(effect.page);
69
+ break;
70
+ case "print":
71
+ if (current?.print) current.print(effect);
72
+ else if (typeof globalThis.print === "function") globalThis.print();
73
+ break;
74
+ }
75
+ };
76
+ form.setUiEffectProvider(provider);
77
+ return () => form.setUiEffectProvider(null);
78
+ }, [form, stage]);
79
+ }
80
+ /** The baked /AP raster, blitted by its OWN box (exactly like BakedImage). */
81
+ function Picture({ page, appearance, apBox, frame, hidden }) {
82
+ if (!appearance) return null;
83
+ const b = viewBox(apBox ?? appearance.box, page);
84
+ return /* @__PURE__ */ jsx("img", {
85
+ src: appearance.url,
86
+ alt: "",
87
+ draggable: false,
88
+ style: {
89
+ position: "absolute",
90
+ left: b.left - (frame?.left ?? 0),
91
+ top: b.top - (frame?.top ?? 0),
92
+ width: b.width,
93
+ height: b.height,
94
+ maxWidth: "none",
95
+ pointerEvents: "none",
96
+ visibility: hidden ? "hidden" : "visible"
97
+ }
98
+ });
99
+ }
100
+ /**
101
+ * Dispatch one engaged widget to its fill control. The FIELD plane (value,
102
+ * behavior, disabled) comes from the form plugin's single-widget projection;
103
+ * the WIDGET plane (live box, /DA font, baked raster) rides in on the
104
+ * renderer props — no geometry is read from the form model here.
105
+ */
106
+ function FormWidget({ item, page, appearance }) {
107
+ const annot = item.ref?.kind === "objectNumber" ? item.ref.annotObjectNumber : 0;
108
+ const fill = useSelector(FormToken, (c) => annot > 0 ? c.fillItem(annot) : null);
109
+ if (!fill) return /* @__PURE__ */ jsx(Picture, {
110
+ page,
111
+ appearance,
112
+ apBox: item.apBox
113
+ });
114
+ switch (fill.control) {
115
+ case "text": return /* @__PURE__ */ jsx(TextWidget, {
116
+ fill,
117
+ item,
118
+ page,
119
+ appearance
120
+ });
121
+ case "toggle": return /* @__PURE__ */ jsx(ToggleWidget, {
122
+ fill,
123
+ item,
124
+ page,
125
+ appearance
126
+ });
127
+ case "choice": return /* @__PURE__ */ jsx(ChoiceWidget, {
128
+ fill,
129
+ item,
130
+ page,
131
+ appearance
132
+ });
133
+ case "button": return /* @__PURE__ */ jsx(ButtonWidget, {
134
+ fill,
135
+ item,
136
+ page,
137
+ appearance
138
+ });
139
+ }
140
+ }
141
+ function ButtonWidget({ fill, item, page, appearance }) {
142
+ const form = useCapability(FormToken);
143
+ const wrap = useIsolated();
144
+ const b = viewBox(item.box, page);
145
+ return /* @__PURE__ */ jsx("button", {
146
+ ref: wrap,
147
+ type: "button",
148
+ "aria-label": fill.label,
149
+ disabled: fill.disabled,
150
+ onClick: () => {
151
+ if (item.ref) form.activateWidget(fill.key, item.ref);
152
+ },
153
+ style: {
154
+ position: "absolute",
155
+ left: b.left,
156
+ top: b.top,
157
+ width: b.width,
158
+ height: b.height,
159
+ boxSizing: "border-box",
160
+ padding: 0,
161
+ border: 0,
162
+ background: "transparent",
163
+ cursor: fill.disabled ? "default" : "pointer",
164
+ pointerEvents: fill.disabled ? "none" : "auto"
165
+ },
166
+ children: /* @__PURE__ */ jsx(Picture, {
167
+ page,
168
+ appearance,
169
+ apBox: item.apBox,
170
+ frame: b
171
+ })
172
+ });
173
+ }
174
+ function TextWidget({ fill, item, page, appearance }) {
175
+ const form = useCapability(FormToken);
176
+ const wrap = useIsolated();
177
+ const [focused, setFocused] = useState(false);
178
+ const [draft, setDraft] = useState(fill.value);
179
+ const cancelled = useRef(false);
180
+ useEffect(() => {
181
+ if (!focused) setDraft(fill.value);
182
+ }, [fill.value, focused]);
183
+ const b = viewBox(item.box, page);
184
+ const scale = item.box.width > 0 ? b.width / item.box.width : 1;
185
+ const fontSize = item.text && item.text.fontSize > 0 ? item.text.fontSize * scale : fill.multiline ? 12 * scale : Math.max(6, b.height * .72);
186
+ const editorStyle = {
187
+ position: "absolute",
188
+ inset: 0,
189
+ width: "100%",
190
+ height: "100%",
191
+ boxSizing: "border-box",
192
+ border: "none",
193
+ outline: focused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
194
+ outlineOffset: -2,
195
+ padding: "0 2px",
196
+ margin: 0,
197
+ background: item.style.interiorColor ?? "#fff",
198
+ color: item.text?.fontColor ?? "#000",
199
+ fontFamily: item.text?.fontFamily ?? "Helvetica, Arial, sans-serif",
200
+ fontSize,
201
+ textAlign: item.text?.textAlign ?? "left",
202
+ resize: "none",
203
+ cursor: "text",
204
+ opacity: focused ? 1 : 0
205
+ };
206
+ const editorProps = {
207
+ value: draft,
208
+ maxLength: fill.maxLength ?? void 0,
209
+ "aria-label": fill.label,
210
+ disabled: fill.disabled,
211
+ onFocus: () => setFocused(true),
212
+ onChange: (e) => setDraft(e.target.value),
213
+ onBlur: () => {
214
+ setFocused(false);
215
+ if (cancelled.current) {
216
+ cancelled.current = false;
217
+ setDraft(fill.value);
218
+ return;
219
+ }
220
+ if (draft !== fill.value) form.setText(fill.key, draft);
221
+ },
222
+ style: editorStyle
223
+ };
224
+ const onKeys = (e) => {
225
+ if (e.key === "Escape") {
226
+ cancelled.current = true;
227
+ e.currentTarget.blur();
228
+ }
229
+ if (e.key === "Enter" && !fill.multiline) e.currentTarget.blur();
230
+ };
231
+ return /* @__PURE__ */ jsxs("div", {
232
+ ref: wrap,
233
+ style: {
234
+ position: "absolute",
235
+ left: b.left,
236
+ top: b.top,
237
+ width: b.width,
238
+ height: b.height,
239
+ pointerEvents: fill.disabled ? "none" : "auto"
240
+ },
241
+ children: [/* @__PURE__ */ jsx(Picture, {
242
+ page,
243
+ appearance,
244
+ apBox: item.apBox,
245
+ frame: b,
246
+ hidden: focused
247
+ }), fill.multiline ? /* @__PURE__ */ jsx("textarea", {
248
+ ...editorProps,
249
+ onKeyDown: onKeys
250
+ }) : /* @__PURE__ */ jsx("input", {
251
+ ...editorProps,
252
+ type: fill.password ? "password" : "text",
253
+ onKeyDown: onKeys
254
+ })]
255
+ });
256
+ }
257
+ function ToggleWidget({ fill, item, page, appearance }) {
258
+ const form = useCapability(FormToken);
259
+ const wrap = useIsolated();
260
+ const [focused, setFocused] = useState(false);
261
+ const b = viewBox(item.box, page);
262
+ const toggle = () => {
263
+ if (fill.disabled) return;
264
+ form.toggle(fill.key, fill.kind === "checkbox" && fill.checked ? null : fill.onState);
265
+ };
266
+ return /* @__PURE__ */ jsx("div", {
267
+ ref: wrap,
268
+ role: fill.kind === "checkbox" ? "checkbox" : "radio",
269
+ "aria-checked": fill.checked,
270
+ "aria-label": fill.label,
271
+ tabIndex: fill.disabled ? -1 : 0,
272
+ onClick: toggle,
273
+ onFocus: () => setFocused(true),
274
+ onBlur: () => setFocused(false),
275
+ onKeyDown: (e) => {
276
+ if (e.key === " " || e.key === "Enter") {
277
+ e.preventDefault();
278
+ toggle();
279
+ }
280
+ },
281
+ style: {
282
+ position: "absolute",
283
+ left: b.left,
284
+ top: b.top,
285
+ width: b.width,
286
+ height: b.height,
287
+ cursor: fill.disabled ? "default" : "pointer",
288
+ pointerEvents: fill.disabled ? "none" : "auto",
289
+ outline: focused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
290
+ outlineOffset: -2
291
+ },
292
+ children: /* @__PURE__ */ jsx(Picture, {
293
+ page,
294
+ appearance,
295
+ apBox: item.apBox,
296
+ frame: b
297
+ })
298
+ });
299
+ }
300
+ function ChoiceWidget({ fill, item, page, appearance }) {
301
+ const form = useCapability(FormToken);
302
+ const wrap = useIsolated();
303
+ const [focused, setFocused] = useState(false);
304
+ const b = viewBox(item.box, page);
305
+ const multiple = fill.kind === "list" && fill.multi;
306
+ return /* @__PURE__ */ jsxs("div", {
307
+ ref: wrap,
308
+ style: {
309
+ position: "absolute",
310
+ left: b.left,
311
+ top: b.top,
312
+ width: b.width,
313
+ height: b.height,
314
+ pointerEvents: fill.disabled ? "none" : "auto",
315
+ outline: focused ? "2px solid rgba(66, 133, 244, 0.8)" : "none",
316
+ outlineOffset: -2
317
+ },
318
+ children: [/* @__PURE__ */ jsx(Picture, {
319
+ page,
320
+ appearance,
321
+ apBox: item.apBox,
322
+ frame: b
323
+ }), /* @__PURE__ */ jsx("select", {
324
+ multiple,
325
+ size: fill.kind === "list" ? Math.max(2, fill.options.length) : void 0,
326
+ defaultValue: multiple ? fill.selected : fill.selected[0] ?? "",
327
+ "aria-label": fill.label,
328
+ disabled: fill.disabled,
329
+ onFocus: () => setFocused(true),
330
+ onBlur: () => setFocused(false),
331
+ onChange: (e) => {
332
+ const values = Array.from(e.currentTarget.selectedOptions).map((o) => o.value);
333
+ form.choose(fill.key, values);
334
+ },
335
+ style: {
336
+ position: "absolute",
337
+ inset: 0,
338
+ width: "100%",
339
+ height: "100%",
340
+ opacity: 0,
341
+ cursor: fill.disabled ? "default" : "pointer"
342
+ },
343
+ children: fill.options.map((o, i) => /* @__PURE__ */ jsx("option", {
344
+ value: o.value,
345
+ children: o.label
346
+ }, i))
347
+ }, fill.selected.join("\0"))]
348
+ });
349
+ }
350
+ /**
351
+ * The form plugin's renderer entry, ready for
352
+ * `<AnnotationLayer renderers={[formWidgetRenderer]} />`. It answers for the
353
+ * PLUGIN-registered 'form-widgets' Behavior — the form plugin decides when
354
+ * widgets are fill controls vs. editable annotations, never the app.
355
+ */
356
+ const formWidgetRenderer = {
357
+ behavior: "form-widgets",
358
+ component: FormWidget
359
+ };
360
+ const controlBase = {
361
+ position: "absolute",
362
+ boxSizing: "border-box",
363
+ border: "1px solid rgba(56, 88, 233, 0.55)",
364
+ background: "rgba(255, 255, 255, 0.92)",
365
+ borderRadius: 2,
366
+ font: "inherit"
367
+ };
368
+ const fillBox = (item, page) => viewBox(item.box, page);
369
+ /** Text control: keystrokes stay LOCAL (the input is the draft store);
370
+ * the engine write happens on blur or Enter. */
371
+ function FillText({ item, page }) {
372
+ const form = useCapability(FormToken);
373
+ const [draft, setDraft] = useState(item.value);
374
+ useEffect(() => setDraft(item.value), [item.value]);
375
+ const css = fillBox(item, page);
376
+ const fontSize = Math.max(9, Math.min(css.height * .62, 24));
377
+ const commit = () => {
378
+ if (draft !== item.value) form.setText(item.key, draft).catch(() => setDraft(item.value));
379
+ };
380
+ const shared = {
381
+ ...controlBase,
382
+ ...css,
383
+ fontSize,
384
+ padding: "0 3px",
385
+ ...item.comb ? { letterSpacing: css.width / Math.max(1, item.maxLength ?? 1) / 2 } : {}
386
+ };
387
+ return item.multiline ? /* @__PURE__ */ jsx("textarea", {
388
+ "aria-label": item.label,
389
+ value: draft,
390
+ disabled: item.disabled,
391
+ onChange: (e) => setDraft(e.target.value),
392
+ onBlur: commit,
393
+ style: {
394
+ ...shared,
395
+ resize: "none"
396
+ }
397
+ }) : /* @__PURE__ */ jsx("input", {
398
+ "aria-label": item.label,
399
+ type: item.password ? "password" : "text",
400
+ value: draft,
401
+ maxLength: item.maxLength ?? void 0,
402
+ disabled: item.disabled,
403
+ onChange: (e) => setDraft(e.target.value),
404
+ onBlur: commit,
405
+ onKeyDown: (e) => {
406
+ if (e.key === "Enter") e.target.blur();
407
+ },
408
+ style: shared
409
+ });
410
+ }
411
+ function FillToggle({ item, page }) {
412
+ const form = useCapability(FormToken);
413
+ const css = fillBox(item, page);
414
+ const glyphSize = Math.min(css.width, css.height) * .72;
415
+ return /* @__PURE__ */ jsx("button", {
416
+ role: item.kind,
417
+ "aria-checked": item.checked,
418
+ "aria-label": item.label,
419
+ disabled: item.disabled,
420
+ onClick: () => void form.toggle(item.key, item.kind === "checkbox" && item.checked ? null : item.onState),
421
+ style: {
422
+ ...controlBase,
423
+ ...css,
424
+ cursor: item.disabled ? "default" : "pointer",
425
+ display: "grid",
426
+ placeItems: "center",
427
+ padding: 0,
428
+ borderRadius: item.kind === "radio" ? "50%" : 2,
429
+ fontSize: glyphSize,
430
+ lineHeight: 1,
431
+ color: "#1f2a44"
432
+ },
433
+ children: item.checked ? item.kind === "radio" ? "●" : "✓" : ""
434
+ });
435
+ }
436
+ function FillChoice({ item, page }) {
437
+ const form = useCapability(FormToken);
438
+ const css = fillBox(item, page);
439
+ return /* @__PURE__ */ jsxs("select", {
440
+ "aria-label": item.label,
441
+ multiple: item.multi,
442
+ disabled: item.disabled,
443
+ value: item.multi ? item.selected : item.selected[0] ?? "",
444
+ onChange: (e) => {
445
+ const values = item.multi ? Array.from(e.target.selectedOptions).map((o) => o.value) : [e.target.value];
446
+ form.choose(item.key, values);
447
+ },
448
+ style: {
449
+ ...controlBase,
450
+ ...css,
451
+ fontSize: Math.max(9, Math.min(css.height * .55, 18))
452
+ },
453
+ children: [!item.multi && item.selected.length === 0 && /* @__PURE__ */ jsx("option", { value: "" }), item.options.map((o) => /* @__PURE__ */ jsx("option", {
454
+ value: o.value,
455
+ children: o.label
456
+ }, o.value))]
457
+ });
458
+ }
459
+ function FillButton({ item, page }) {
460
+ const form = useCapability(FormToken);
461
+ const css = fillBox(item, page);
462
+ return /* @__PURE__ */ jsx("button", {
463
+ type: "button",
464
+ "aria-label": item.label,
465
+ disabled: item.disabled,
466
+ onClick: () => void form.activateWidget(item.key, {
467
+ kind: "objectNumber",
468
+ pageObjectNumber: page.pon,
469
+ annotObjectNumber: item.annotObjectNumber
470
+ }),
471
+ style: {
472
+ ...controlBase,
473
+ ...css,
474
+ padding: 0,
475
+ border: 0,
476
+ background: "transparent",
477
+ cursor: item.disabled ? "default" : "pointer"
478
+ }
479
+ });
480
+ }
481
+ /**
482
+ * Fill-mode form controls for one page, positioned from the form model's own
483
+ * widget geometry — the ANNOTATION-LESS path (a fill-only viewer whose page
484
+ * pixels come from an annotated RenderLayer raster). Active whenever the
485
+ * active tool carries the 'form-fill' tag (the built-in pointer/pan tools
486
+ * do); any other tool stands the controls down. Do not mount next to an
487
+ * AnnotationLayer wired with `formWidgetBehaviors`.
488
+ */
489
+ function FormLayer() {
490
+ const page = usePage();
491
+ const form = useCapability(FormToken);
492
+ const active = useSelector(InteractionToken, (c) => c.activeTool().enables.has("form-fill"));
493
+ useEffect(() => {
494
+ if (active) form.ensureGeom(page.pon);
495
+ }, [
496
+ active,
497
+ form,
498
+ page.pon
499
+ ]);
500
+ const items = useSelector(FormToken, (c) => c.fillItems(page.pon), shallowArray);
501
+ if (!active) return null;
502
+ return /* @__PURE__ */ jsx("div", {
503
+ style: {
504
+ position: "absolute",
505
+ inset: 0
506
+ },
507
+ children: items.map((item) => item.control === "text" ? /* @__PURE__ */ jsx(FillText, {
508
+ item,
509
+ page
510
+ }, `${item.key}:${item.annotObjectNumber}`) : item.control === "toggle" ? /* @__PURE__ */ jsx(FillToggle, {
511
+ item,
512
+ page
513
+ }, `${item.key}:${item.annotObjectNumber}`) : item.control === "choice" ? /* @__PURE__ */ jsx(FillChoice, {
514
+ item,
515
+ page
516
+ }, `${item.key}:${item.annotObjectNumber}`) : item.control === "button" ? /* @__PURE__ */ jsx(FillButton, {
517
+ item,
518
+ page
519
+ }, `${item.key}:${item.annotObjectNumber}`) : null)
520
+ });
521
+ }
522
+ /** The form capability — values, interchange, design-mode verbs. */
523
+ function useForm() {
524
+ return useCapability(FormToken);
525
+ }
526
+ /** The reconciled form snapshot (null until the first load lands),
527
+ * re-rendering on every form model change. */
528
+ function useFormSnapshot() {
529
+ return useSelector(FormToken, (c) => c.snapshot());
530
+ }
531
+ /**
532
+ * The FIELD behind the currently selected widget annotation (single
533
+ * selection), or null. The design-mode join: widget selection lives in the
534
+ * annotation plane, field properties live here.
535
+ */
536
+ function useFormField() {
537
+ const selected = useAnnotationSelected();
538
+ const widget = selected.length === 1 && selected[0].subtype === "widget" ? selected[0] : null;
539
+ const objnum = widget && widget.ref.kind === "objectNumber" ? widget.ref.annotObjectNumber : 0;
540
+ return useSelector(FormToken, (c) => objnum > 0 ? c.fieldForWidget(objnum) : null);
541
+ }
542
+ //#endregion
543
+ export { FormLayer, formWidgetRenderer, useForm, useFormField, useFormScriptingProvider, useFormSnapshot };
544
+
545
+ //# sourceMappingURL=form.js.map