@embedpdf/plugin-form 3.0.0-next.21 → 3.0.0-next.23

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.
@@ -1,6 +1,6 @@
1
1
  import { BatchResult, DeepPartial, EventHook, EventOrigin, OperationOptions, ResourceStatus, SettingsApi } from "@embedpdf/core";
2
2
  import { ScriptDiagnostic, ScriptExecutionError, ScriptUiEffect } from "@embedpdf/core-acrojs";
3
- import { AnnotationRef, FieldPosition, FormBundle, FormBundle as FormBundle$1, FormFieldDTO, FormFieldDTO as FormFieldDTO$1, FormFieldDraft, FormFieldDraft as FormFieldDraft$1, FormFieldFamily, FormFieldFamily as FormFieldFamily$1, FormFieldOption, FormFieldPatch, FormFieldPatch as FormFieldPatch$1, FormFieldRef, FormFieldRef as FormFieldRef$1, FormFieldValue, FormFieldValue as FormFieldValue$1, FormImportDrop, FormImportDrop as FormImportDrop$1, FormImportDropReason, FormImportOptions, FormImportOptions as FormImportOptions$1, FormKind, FormKind as FormKind$1, FormRepairOptions, FormRepairOptions as FormRepairOptions$1, FormRepairResult, FormRepairResult as FormRepairResult$1, FormSnapshot, FormSnapshot as FormSnapshot$1, FormWidget, PageRef, WidgetAnnotation, WidgetAnnotation as WidgetAnnotation$1, WidgetPatch, WidgetPlacement, toFieldRef } from "@embedpdf/engine-core/runtime";
3
+ import { AnnotationRef, FieldPosition, FormBundle, FormBundle as FormBundle$1, FormField, FormField as FormField$1, FormFieldDraft, FormFieldDraft as FormFieldDraft$1, FormFieldKind, FormFieldKind as FormFieldKind$1, FormFieldOption, FormFieldPatch, FormFieldPatch as FormFieldPatch$1, FormFieldRef, FormFieldRef as FormFieldRef$1, FormFieldValue, FormFieldValue as FormFieldValue$1, FormImportDrop, FormImportDrop as FormImportDrop$1, FormImportDropReason, FormImportOptions, FormImportOptions as FormImportOptions$1, FormKind, FormKind as FormKind$1, FormRepairOptions, FormRepairOptions as FormRepairOptions$1, FormRepairResult, FormRepairResult as FormRepairResult$1, FormSnapshot, FormSnapshot as FormSnapshot$1, FormWidget, PageRef, WidgetAnnotation, WidgetAnnotation as WidgetAnnotation$1, WidgetPatch, WidgetPlacement, toFieldRef } from "@embedpdf/engine-core/runtime";
4
4
  import { ActionOrigin, ActionTriggerResult } from "@embedpdf/plugin-actions/contract";
5
5
  import { FormTransfer } from "@embedpdf/engine-core/public";
6
6
  //#region src/model.d.ts
@@ -55,7 +55,7 @@ interface ShownWidget {
55
55
  /** A widget hit: the annotation under the point and the field it belongs to. */
56
56
  interface WidgetHit {
57
57
  readonly annotObjectNumber: number;
58
- readonly field: FormFieldDTO;
58
+ readonly field: FormField;
59
59
  /** The widget's page-space box. */
60
60
  readonly box: Box;
61
61
  }
@@ -155,22 +155,22 @@ interface FormSettings {
155
155
  };
156
156
  /**
157
157
  * Which fields people may fill in by hand: `true`, every one; `false`,
158
- * none; or a list of field families (`'text'`, `'checkbox'`,
158
+ * none; or a list of field kinds (`'text'`, `'checkbox'`,
159
159
  * `'signature'`…). A field left out draws as a read-only one does, and
160
160
  * takes no typing, clicks or picks. Only the interface: your code still
161
161
  * fills it in (`setValue()`, `importValues()`), and `canFill()` doesn't change.
162
162
  */
163
163
  readonly fillable: FillableFields;
164
164
  }
165
- /** Which fields people may fill in by hand: all, none, or those of these families. */
166
- type FillableFields = boolean | readonly FormFieldFamily[];
165
+ /** Which fields people may fill in by hand: all, none, or those of these kinds. */
166
+ type FillableFields = boolean | readonly FormFieldKind[];
167
167
  /** What the form settings are when the app registers none. */
168
168
  declare const FORM_DEFAULTS: FormSettings;
169
169
  /** What `formPlugin(config)` takes: any of the settings, merged over the defaults. */
170
170
  type FormConfig = DeepPartial<FormSettings>;
171
171
  /** Which fields `list()` returns: all of them, or those that match every given part. */
172
172
  interface FormFilter {
173
- readonly family?: FormFieldFamily;
173
+ readonly kind?: FormFieldKind;
174
174
  /** Fields with a box on this page: its ref or its index. */
175
175
  readonly page?: PageRef | number;
176
176
  /** One full name, such as `'billing.name'`. */
@@ -183,7 +183,7 @@ interface FormFilter {
183
183
  type FormSetValueStatus = 'applied' | 'unchanged' | 'rejected';
184
184
  /** What `setValue()` resolves: the field as it is now, and what the write did. */
185
185
  interface FormSetValueResult {
186
- readonly field: FormFieldDTO;
186
+ readonly field: FormField;
187
187
  readonly status: FormSetValueStatus;
188
188
  }
189
189
  /**
@@ -199,11 +199,11 @@ interface FormValidation {
199
199
  * The required fields you may fill in that are empty, in page order (page,
200
200
  * then top to bottom, then left to right).
201
201
  */
202
- readonly missing: readonly FormFieldDTO[];
202
+ readonly missing: readonly FormField[];
203
203
  }
204
204
  /** What `reset()` resolves: the fields it changed, as they are now. */
205
205
  interface FormResetResult {
206
- readonly fields: readonly FormFieldDTO[];
206
+ readonly fields: readonly FormField[];
207
207
  }
208
208
  /** A field setting that is on or off. */
209
209
  type FormFieldFlagSetting = 'required' | 'readOnly' | 'noExport' | 'multiline' | 'password' | 'comb' | 'radiosInUnison' | 'noToggleToOff' | 'edit' | 'multiSelect';
@@ -271,11 +271,11 @@ interface FormFieldSettings {
271
271
  }
272
272
  /** What `create()`, `update()` and `removeWidget()` resolve: the field as it is now. */
273
273
  interface FormFieldResult {
274
- readonly field: FormFieldDTO;
274
+ readonly field: FormField;
275
275
  }
276
276
  /** What `addWidget()` resolves: the field as it is now, and its new widget. */
277
277
  interface FormWidgetAddResult {
278
- readonly field: FormFieldDTO;
278
+ readonly field: FormField;
279
279
  readonly widget: WidgetAnnotation;
280
280
  }
281
281
  /** Which fields `export()` takes, each whole. Without either, every field. */
@@ -287,7 +287,7 @@ interface FormExportSelection {
287
287
  /** What `import()` did: the new fields, where each bundle field went, and what was left out. */
288
288
  interface FormImportResult {
289
289
  /** The new fields, in bundle order. */
290
- readonly fields: readonly FormFieldDTO[];
290
+ readonly fields: readonly FormField[];
291
291
  /** Each imported field's ref in the bundle, and its new ref here. */
292
292
  readonly refMap: ReadonlyArray<{
293
293
  readonly from: FormFieldRef;
@@ -304,21 +304,21 @@ interface FormImportResult {
304
304
  type WidgetAddress = AnnotationRef | FormWidget;
305
305
  /** What one widget activation did: the form's own scripts ran, or the widget's action did. */
306
306
  type WidgetActivationResult = {
307
- kind: 'form';
307
+ status: 'form';
308
308
  result: FormCommitResult;
309
309
  } | {
310
- kind: 'dispatched';
310
+ status: 'dispatched';
311
311
  result: ActionTriggerResult;
312
312
  };
313
313
  /** How a write through the document's scripts ended. */
314
314
  type FormCommitStatus = 'applied' | 'unchanged' | 'rejected' | 'failed';
315
315
  /** A write through the document's keystroke, validate, calculate and format scripts, and what they asked for. */
316
316
  interface FormCommitResult {
317
- status: FormCommitStatus;
318
- scripted: boolean;
319
- uiEffects: FormUiEffect[];
320
- diagnostics: ScriptDiagnostic[];
321
- error?: ScriptExecutionError;
317
+ readonly status: FormCommitStatus;
318
+ readonly scripted: boolean;
319
+ readonly uiEffects: FormUiEffect[];
320
+ readonly diagnostics: ScriptDiagnostic[];
321
+ readonly error?: ScriptExecutionError;
322
322
  }
323
323
  /**
324
324
  * One request a document script made of the UI, such as an alert. `phase`
@@ -355,17 +355,17 @@ interface FormFocusNextOptions {
355
355
  }
356
356
  /** A field's value changed, whoever changed it: you, the form's scripts, or another session. */
357
357
  interface FormValueChangedEvent {
358
- readonly field: FormFieldDTO;
358
+ readonly field: FormField;
359
359
  readonly origin: EventOrigin;
360
360
  }
361
361
  /** A field was added. */
362
362
  interface FormFieldCreatedEvent {
363
- readonly field: FormFieldDTO;
363
+ readonly field: FormField;
364
364
  readonly origin: EventOrigin;
365
365
  }
366
366
  /** A field's settings or boxes changed. */
367
367
  interface FormFieldUpdatedEvent {
368
- readonly field: FormFieldDTO;
368
+ readonly field: FormField;
369
369
  readonly origin: EventOrigin;
370
370
  }
371
371
  /** A field was removed, with every box it had. */
@@ -375,12 +375,12 @@ interface FormFieldDeletedEvent {
375
375
  }
376
376
  /** The form's own validation refused a value: the field kept the one it had. */
377
377
  interface FormValidationRejectedEvent {
378
- readonly field: FormFieldDTO;
378
+ readonly field: FormField;
379
379
  readonly issues: readonly ScriptDiagnostic[];
380
380
  }
381
381
  /** The cursor moved into a field, to another one, or out of the fields (`field` is then `null`). */
382
382
  interface FormFocusChangedEvent {
383
- readonly field: FormFieldDTO | null;
383
+ readonly field: FormField | null;
384
384
  /** The box the cursor is in. */
385
385
  readonly widget: AnnotationRef | null;
386
386
  }
@@ -402,11 +402,11 @@ interface FormCapability extends SettingsApi<FormSettings> {
402
402
  /** What the document has: `'none'`, `'acroform'` or `'xfa'`. */
403
403
  getFormKind(): FormKind;
404
404
  /** Every field, or the fields that match `filter`. Without a filter, the same array while nothing changes. */
405
- list(filter?: FormFilter): readonly FormFieldDTO[];
405
+ list(filter?: FormFilter): readonly FormField[];
406
406
  /** One field, or `null` when the form has no such field. */
407
- get(ref: FormFieldRef): FormFieldDTO | null;
407
+ get(ref: FormFieldRef): FormField | null;
408
408
  /** The field a widget belongs to, or `null`. */
409
- getFieldForWidget(widget: WidgetAddress): FormFieldDTO | null;
409
+ getFieldForWidget(widget: WidgetAddress): FormField | null;
410
410
  /**
411
411
  * A widget's row: where it is (`page`, `rect`), how it looks and its state,
412
412
  * or `null` when no page shows it. A field's `widgets` name them.
@@ -434,9 +434,9 @@ interface FormCapability extends SettingsApi<FormSettings> {
434
434
  y: number;
435
435
  }): WidgetHit | null;
436
436
  /** The field of the selected widget while one widget is selected (in design mode), or `null`. */
437
- getSelectedField(): FormFieldDTO | null;
437
+ getSelectedField(): FormField | null;
438
438
  /** The field the cursor is in, or `null`. */
439
- getFocusedField(): FormFieldDTO | null;
439
+ getFocusedField(): FormField | null;
440
440
  /**
441
441
  * A field's settings, described for a settings panel, which writes them
442
442
  * with `update()`; `null` for a field the form doesn't have. Every setting
@@ -561,7 +561,7 @@ interface FormCapability extends SettingsApi<FormSettings> {
561
561
  * `doc.forms.modify`.
562
562
  */
563
563
  deleteWidget(widget: AnnotationRef, options?: OperationOptions): Promise<{
564
- readonly field: FormFieldDTO | null;
564
+ readonly field: FormField | null;
565
565
  }>;
566
566
  /**
567
567
  * Change the order the fields' calculate scripts run in: the fields go
@@ -615,5 +615,5 @@ interface FormCapability extends SettingsApi<FormSettings> {
615
615
  readonly onFocusChanged: EventHook<FormFocusChangedEvent>;
616
616
  }
617
617
  //#endregion
618
- export { FormModel as $, FormKind$1 as A, FormTransfer as B, FormFocusChangedEvent as C, FormImportDropReason as D, FormImportDrop$1 as E, FormResyncedEvent as F, FormWidgetAddResult as G, FormValidation as H, FormSetValueResult as I, WidgetAnnotation$1 as J, WidgetActivationResult as K, FormSetValueStatus as L, FormRepairOptions$1 as M, FormRepairResult$1 as N, FormImportOptions$1 as O, FormResetResult as P, Box as Q, FormSettings as R, FormFilter as S, FormFocusOptions as T, FormValidationRejectedEvent as U, FormUiEffect as V, FormValueChangedEvent as W, FormToken as X, toFieldRef as Y, FormWidgetItem as Z, FormFieldResult as _, FormCommitResult as a, FormFieldUpdatedEvent as b, FormExportSelection as c, FormFieldDeletedEvent as d, FormWidgetLook as et, FormFieldDraft$1 as f, FormFieldRef$1 as g, FormFieldPatch$1 as h, FormCapability as i, FormPlainValue as j, FormImportResult as k, FormFieldCreatedEvent as l, FormFieldFlagSetting as m, FillableFields as n, WidgetHit as nt, FormCommitStatus as o, FormFieldFamily$1 as p, WidgetAddress as q, FormBundle$1 as r, FormConfig as s, FORM_DEFAULTS as t, ShownWidget as tt, FormFieldDTO$1 as u, FormFieldSetting as v, FormFocusNextOptions as w, FormFieldValue$1 as x, FormFieldSettings as y, FormSnapshot$1 as z };
619
- //# sourceMappingURL=contract-c_wuhKk1.d.cts.map
618
+ export { FormModel as $, FormKind$1 as A, FormTransfer as B, FormFocusChangedEvent as C, FormImportDropReason as D, FormImportDrop$1 as E, FormResyncedEvent as F, FormWidgetAddResult as G, FormValidation as H, FormSetValueResult as I, WidgetAnnotation$1 as J, WidgetActivationResult as K, FormSetValueStatus as L, FormRepairOptions$1 as M, FormRepairResult$1 as N, FormImportOptions$1 as O, FormResetResult as P, Box as Q, FormSettings as R, FormFilter as S, FormFocusOptions as T, FormValidationRejectedEvent as U, FormUiEffect as V, FormValueChangedEvent as W, FormToken as X, toFieldRef as Y, FormWidgetItem as Z, FormFieldResult as _, FormCommitResult as a, FormFieldUpdatedEvent as b, FormExportSelection as c, FormFieldDeletedEvent as d, FormWidgetLook as et, FormFieldDraft$1 as f, FormFieldRef$1 as g, FormFieldPatch$1 as h, FormCapability as i, FormPlainValue as j, FormImportResult as k, FormField$1 as l, FormFieldKind$1 as m, FillableFields as n, WidgetHit as nt, FormCommitStatus as o, FormFieldFlagSetting as p, WidgetAddress as q, FormBundle$1 as r, FormConfig as s, FORM_DEFAULTS as t, ShownWidget as tt, FormFieldCreatedEvent as u, FormFieldSetting as v, FormFocusNextOptions as w, FormFieldValue$1 as x, FormFieldSettings as y, FormSnapshot$1 as z };
619
+ //# sourceMappingURL=contract-Djti7ew8.d.cts.map
@@ -1,2 +1,2 @@
1
- import { A as FormKind, B as FormTransfer, C as FormFocusChangedEvent, D as FormImportDropReason, E as FormImportDrop, F as FormResyncedEvent, G as FormWidgetAddResult, H as FormValidation, I as FormSetValueResult, J as WidgetAnnotation, K as WidgetActivationResult, L as FormSetValueStatus, M as FormRepairOptions, N as FormRepairResult, O as FormImportOptions, P as FormResetResult, Q as Box, R as FormSettings, S as FormFilter, T as FormFocusOptions, U as FormValidationRejectedEvent, V as FormUiEffect, W as FormValueChangedEvent, X as FormToken, Y as toFieldRef, Z as FormWidgetItem, _ as FormFieldResult, a as FormCommitResult, b as FormFieldUpdatedEvent, c as FormExportSelection, d as FormFieldDeletedEvent, et as FormWidgetLook, f as FormFieldDraft, g as FormFieldRef, h as FormFieldPatch, i as FormCapability, j as FormPlainValue, k as FormImportResult, l as FormFieldCreatedEvent, m as FormFieldFlagSetting, n as FillableFields, nt as WidgetHit, o as FormCommitStatus, p as FormFieldFamily, q as WidgetAddress, r as FormBundle, s as FormConfig, t as FORM_DEFAULTS, u as FormFieldDTO, v as FormFieldSetting, w as FormFocusNextOptions, x as FormFieldValue, y as FormFieldSettings, z as FormSnapshot } from "./contract-c_wuhKk1.cjs";
2
- export { type Box, FORM_DEFAULTS, FillableFields, type FormBundle, FormCapability, FormCommitResult, FormCommitStatus, FormConfig, FormExportSelection, FormFieldCreatedEvent, type FormFieldDTO, FormFieldDeletedEvent, type FormFieldDraft, type FormFieldFamily, FormFieldFlagSetting, type FormFieldPatch, type FormFieldRef, FormFieldResult, FormFieldSetting, FormFieldSettings, FormFieldUpdatedEvent, type FormFieldValue, FormFilter, FormFocusChangedEvent, FormFocusNextOptions, FormFocusOptions, type FormImportDrop, type FormImportDropReason, type FormImportOptions, FormImportResult, type FormKind, FormPlainValue, type FormRepairOptions, type FormRepairResult, FormResetResult, FormResyncedEvent, FormSetValueResult, FormSetValueStatus, FormSettings, type FormSnapshot, FormToken, FormTransfer, FormUiEffect, FormValidation, FormValidationRejectedEvent, FormValueChangedEvent, FormWidgetAddResult, type FormWidgetItem, type FormWidgetLook, WidgetActivationResult, WidgetAddress, type WidgetAnnotation, type WidgetHit, toFieldRef };
1
+ import { A as FormKind, B as FormTransfer, C as FormFocusChangedEvent, D as FormImportDropReason, E as FormImportDrop, F as FormResyncedEvent, G as FormWidgetAddResult, H as FormValidation, I as FormSetValueResult, J as WidgetAnnotation, K as WidgetActivationResult, L as FormSetValueStatus, M as FormRepairOptions, N as FormRepairResult, O as FormImportOptions, P as FormResetResult, Q as Box, R as FormSettings, S as FormFilter, T as FormFocusOptions, U as FormValidationRejectedEvent, V as FormUiEffect, W as FormValueChangedEvent, X as FormToken, Y as toFieldRef, Z as FormWidgetItem, _ as FormFieldResult, a as FormCommitResult, b as FormFieldUpdatedEvent, c as FormExportSelection, d as FormFieldDeletedEvent, et as FormWidgetLook, f as FormFieldDraft, g as FormFieldRef, h as FormFieldPatch, i as FormCapability, j as FormPlainValue, k as FormImportResult, l as FormField, m as FormFieldKind, n as FillableFields, nt as WidgetHit, o as FormCommitStatus, p as FormFieldFlagSetting, q as WidgetAddress, r as FormBundle, s as FormConfig, t as FORM_DEFAULTS, u as FormFieldCreatedEvent, v as FormFieldSetting, w as FormFocusNextOptions, x as FormFieldValue, y as FormFieldSettings, z as FormSnapshot } from "./contract-Djti7ew8.cjs";
2
+ export { type Box, FORM_DEFAULTS, FillableFields, type FormBundle, FormCapability, FormCommitResult, FormCommitStatus, FormConfig, FormExportSelection, type FormField, FormFieldCreatedEvent, FormFieldDeletedEvent, type FormFieldDraft, FormFieldFlagSetting, type FormFieldKind, type FormFieldPatch, type FormFieldRef, FormFieldResult, FormFieldSetting, FormFieldSettings, FormFieldUpdatedEvent, type FormFieldValue, FormFilter, FormFocusChangedEvent, FormFocusNextOptions, FormFocusOptions, type FormImportDrop, type FormImportDropReason, type FormImportOptions, FormImportResult, type FormKind, FormPlainValue, type FormRepairOptions, type FormRepairResult, FormResetResult, FormResyncedEvent, FormSetValueResult, FormSetValueStatus, FormSettings, type FormSnapshot, FormToken, FormTransfer, FormUiEffect, FormValidation, FormValidationRejectedEvent, FormValueChangedEvent, FormWidgetAddResult, type FormWidgetItem, type FormWidgetLook, WidgetActivationResult, WidgetAddress, type WidgetAnnotation, type WidgetHit, toFieldRef };
@@ -1,2 +1,2 @@
1
- import { A as FormKind, B as FormTransfer, C as FormFocusChangedEvent, D as FormImportDropReason, E as FormImportDrop, F as FormResyncedEvent, G as FormWidgetAddResult, H as FormValidation, I as FormSetValueResult, J as WidgetAnnotation, K as WidgetActivationResult, L as FormSetValueStatus, M as FormRepairOptions, N as FormRepairResult, O as FormImportOptions, P as FormResetResult, Q as Box, R as FormSettings, S as FormFilter, T as FormFocusOptions, U as FormValidationRejectedEvent, V as FormUiEffect, W as FormValueChangedEvent, X as FormToken, Y as toFieldRef, Z as FormWidgetItem, _ as FormFieldResult, a as FormCommitResult, b as FormFieldUpdatedEvent, c as FormExportSelection, d as FormFieldDeletedEvent, et as FormWidgetLook, f as FormFieldDraft, g as FormFieldRef, h as FormFieldPatch, i as FormCapability, j as FormPlainValue, k as FormImportResult, l as FormFieldCreatedEvent, m as FormFieldFlagSetting, n as FillableFields, nt as WidgetHit, o as FormCommitStatus, p as FormFieldFamily, q as WidgetAddress, r as FormBundle, s as FormConfig, t as FORM_DEFAULTS, u as FormFieldDTO, v as FormFieldSetting, w as FormFocusNextOptions, x as FormFieldValue, y as FormFieldSettings, z as FormSnapshot } from "./contract-D_9fiTkd.js";
2
- export { type Box, FORM_DEFAULTS, FillableFields, type FormBundle, FormCapability, FormCommitResult, FormCommitStatus, FormConfig, FormExportSelection, FormFieldCreatedEvent, type FormFieldDTO, FormFieldDeletedEvent, type FormFieldDraft, type FormFieldFamily, FormFieldFlagSetting, type FormFieldPatch, type FormFieldRef, FormFieldResult, FormFieldSetting, FormFieldSettings, FormFieldUpdatedEvent, type FormFieldValue, FormFilter, FormFocusChangedEvent, FormFocusNextOptions, FormFocusOptions, type FormImportDrop, type FormImportDropReason, type FormImportOptions, FormImportResult, type FormKind, FormPlainValue, type FormRepairOptions, type FormRepairResult, FormResetResult, FormResyncedEvent, FormSetValueResult, FormSetValueStatus, FormSettings, type FormSnapshot, FormToken, FormTransfer, FormUiEffect, FormValidation, FormValidationRejectedEvent, FormValueChangedEvent, FormWidgetAddResult, type FormWidgetItem, type FormWidgetLook, WidgetActivationResult, WidgetAddress, type WidgetAnnotation, type WidgetHit, toFieldRef };
1
+ import { A as FormKind, B as FormTransfer, C as FormFocusChangedEvent, D as FormImportDropReason, E as FormImportDrop, F as FormResyncedEvent, G as FormWidgetAddResult, H as FormValidation, I as FormSetValueResult, J as WidgetAnnotation, K as WidgetActivationResult, L as FormSetValueStatus, M as FormRepairOptions, N as FormRepairResult, O as FormImportOptions, P as FormResetResult, Q as Box, R as FormSettings, S as FormFilter, T as FormFocusOptions, U as FormValidationRejectedEvent, V as FormUiEffect, W as FormValueChangedEvent, X as FormToken, Y as toFieldRef, Z as FormWidgetItem, _ as FormFieldResult, a as FormCommitResult, b as FormFieldUpdatedEvent, c as FormExportSelection, d as FormFieldDeletedEvent, et as FormWidgetLook, f as FormFieldDraft, g as FormFieldRef, h as FormFieldPatch, i as FormCapability, j as FormPlainValue, k as FormImportResult, l as FormField, m as FormFieldKind, n as FillableFields, nt as WidgetHit, o as FormCommitStatus, p as FormFieldFlagSetting, q as WidgetAddress, r as FormBundle, s as FormConfig, t as FORM_DEFAULTS, u as FormFieldCreatedEvent, v as FormFieldSetting, w as FormFocusNextOptions, x as FormFieldValue, y as FormFieldSettings, z as FormSnapshot } from "./contract-6YEsObRl.js";
2
+ export { type Box, FORM_DEFAULTS, FillableFields, type FormBundle, FormCapability, FormCommitResult, FormCommitStatus, FormConfig, FormExportSelection, type FormField, FormFieldCreatedEvent, FormFieldDeletedEvent, type FormFieldDraft, FormFieldFlagSetting, type FormFieldKind, type FormFieldPatch, type FormFieldRef, FormFieldResult, FormFieldSetting, FormFieldSettings, FormFieldUpdatedEvent, type FormFieldValue, FormFilter, FormFocusChangedEvent, FormFocusNextOptions, FormFocusOptions, type FormImportDrop, type FormImportDropReason, type FormImportOptions, FormImportResult, type FormKind, FormPlainValue, type FormRepairOptions, type FormRepairResult, FormResetResult, FormResyncedEvent, FormSetValueResult, FormSetValueStatus, FormSettings, type FormSnapshot, FormToken, FormTransfer, FormUiEffect, FormValidation, FormValidationRejectedEvent, FormValueChangedEvent, FormWidgetAddResult, type FormWidgetItem, type FormWidgetLook, WidgetActivationResult, WidgetAddress, type WidgetAnnotation, type WidgetHit, toFieldRef };
@@ -22,7 +22,7 @@ function snapshotField(snapshot, ref) {
22
22
  }
23
23
  /** A written value as scripts see it: a toggle's export value (`'Off'` when clear). */
24
24
  function scriptValueFromFormValue(field, value) {
25
- switch (field.family) {
25
+ switch (field.kind) {
26
26
  case "text":
27
27
  case "combobox":
28
28
  if ("value" in value) return value.value ?? "";
@@ -43,12 +43,12 @@ function scriptValueFromFormValue(field, value) {
43
43
  if ("selectedValues" in value) return [...value.selectedValues];
44
44
  break;
45
45
  }
46
- throw new Error(`Form field '${field.name}' (${field.family}) does not take this value`);
46
+ throw new Error(`Form field '${field.name}' (${field.kind}) does not take this value`);
47
47
  }
48
- /** A script value as the engine writes it, or null for a family that holds none. */
48
+ /** A script value as the engine writes it, or null for a kind that holds none. */
49
49
  function formValueFromScriptValue(field) {
50
50
  const value = field.value;
51
- switch (field.family) {
51
+ switch (field.kind) {
52
52
  case "text": return { value: String(value ?? "") };
53
53
  case "checkbox":
54
54
  case "radio": return { value: value === null || String(value) === "Off" ? null : String(value) };
@@ -159,7 +159,7 @@ var FormScriptingController = class {
159
159
  }
160
160
  /** The realm belongs to its owner (the actions plugin, or the caller that
161
161
  * minted a detached one) — this only fences further transactions. */
162
- dispose() {
162
+ destroy() {
163
163
  this.disposed = true;
164
164
  }
165
165
  /**
@@ -313,7 +313,7 @@ var FormScriptingController = class {
313
313
  applyEffects(overlay, activated.output.formEffects);
314
314
  }
315
315
  }
316
- if (!activation && hasProposedValue && target.actions?.keystroke && target.family === "text") {
316
+ if (!activation && hasProposedValue && target.actions?.keystroke && target.kind === "text") {
317
317
  let program;
318
318
  try {
319
319
  program = javaScriptProgramFromActionTree(target.actions.keystroke);
@@ -494,4 +494,4 @@ function createFormScriptingController(options) {
494
494
  //#endregion
495
495
  export { createFormScriptingController as n, scriptError as r, FormScriptingController as t };
496
496
 
497
- //# sourceMappingURL=controller-Sr5M_8G8.js.map
497
+ //# sourceMappingURL=controller-BbC8XWpY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller-BbC8XWpY.js","names":[],"sources":["../src/scripting/overlay.ts","../src/scripting/results.ts","../src/scripting/controller.ts"],"sourcesContent":["/**\n * The transaction overlay: a working copy of the script field view that\n * every pass mutates, and the canonical effect list diffed from it at the\n * end (values, display, appearance text; resets folded back to one effect).\n */\nimport type { ScriptFieldInput, ScriptValue } from '@embedpdf/core-acrojs';\nimport type {\n FormEffect,\n FormField,\n FormFieldRef,\n FormFieldValue,\n FormSnapshot,\n} from '@embedpdf/engine-core/runtime';\n\nexport interface Overlay {\n original: ScriptFieldInput[];\n fields: ScriptFieldInput[];\n resetKeys: Set<string>;\n appearances: Map<string, { ref: FormFieldRef; text: string }>;\n}\n\nexport const refKey = (ref: FormFieldRef): string =>\n ref.kind === 'objectNumber' ? `obj:${ref.objectNumber}` : `fqn:${ref.name}`;\n\nexport const sameRef = (left: FormFieldRef, right: FormFieldRef): boolean =>\n refKey(left) === refKey(right);\n\nexport const cloneValue = (value: ScriptValue): ScriptValue =>\n Array.isArray(value) ? [...value] : value;\n\nexport const sameValue = (left: ScriptValue, right: ScriptValue): boolean =>\n Array.isArray(left) && Array.isArray(right)\n ? left.length === right.length && left.every((value, index) => value === right[index])\n : left === right;\n\nexport function cloneFields(fields: ScriptFieldInput[]): ScriptFieldInput[] {\n return fields.map((field) => ({\n ...field,\n ref: { ...field.ref },\n value: cloneValue(field.value),\n defaultValue: cloneValue(field.defaultValue),\n ...(field.options ? { options: field.options.map((option) => ({ ...option })) } : {}),\n }));\n}\n\nexport function fieldByRef<T extends { ref: FormFieldRef }>(\n fields: T[],\n ref: FormFieldRef,\n): T | undefined {\n return fields.find((field) => sameRef(field.ref, ref));\n}\n\n/** The field a ref names: by its own ref, or by full name for `toFieldRef(name)`. */\nexport function snapshotField(snapshot: FormSnapshot, ref: FormFieldRef): FormField | undefined {\n return snapshot.fields.find(\n (field) => sameRef(field.ref, ref) || (ref.kind === 'fqn' && field.name === ref.name),\n );\n}\n\n/** A written value as scripts see it: a toggle's export value (`'Off'` when clear). */\nexport function scriptValueFromFormValue(\n field: ScriptFieldInput,\n value: FormFieldValue,\n): ScriptValue {\n switch (field.kind) {\n case 'text':\n case 'combobox':\n if ('value' in value) return value.value ?? '';\n break;\n case 'radio':\n if ('value' in value) return value.value ?? 'Off';\n break;\n case 'checkbox':\n if ('value' in value) return value.value ?? 'Off';\n if ('checked' in value) {\n if (!value.checked) return 'Off';\n const first = field.exportValues?.[0];\n if (first === undefined)\n throw new Error(`Form field '${field.name}' has no widget to check`);\n return first;\n }\n break;\n case 'listbox':\n if ('selectedValues' in value) return [...value.selectedValues];\n break;\n }\n throw new Error(`Form field '${field.name}' (${field.kind}) does not take this value`);\n}\n\n/** A script value as the engine writes it, or null for a kind that holds none. */\nexport function formValueFromScriptValue(field: ScriptFieldInput): FormFieldValue | null {\n const value = field.value;\n switch (field.kind) {\n case 'text':\n return { value: String(value ?? '') };\n case 'checkbox':\n case 'radio':\n return { value: value === null || String(value) === 'Off' ? null : String(value) };\n case 'combobox': {\n const selected = Array.isArray(value) ? value[0] : value;\n const text = selected === null || selected === undefined ? '' : String(selected);\n return { value: text === '' ? null : text };\n }\n case 'listbox':\n if (Array.isArray(value)) return { selectedValues: [...value] };\n return { selectedValues: value === null || value === '' ? [] : [String(value)] };\n default:\n return null;\n }\n}\n\nexport function applyEffects(overlay: Overlay, effects: FormEffect[]): void {\n for (const effect of effects) {\n if (effect.kind === 'reset') {\n for (const ref of effect.refs) {\n const field = fieldByRef(overlay.fields, ref);\n if (!field) continue;\n field.value = cloneValue(field.defaultValue);\n overlay.resetKeys.add(refKey(ref));\n }\n continue;\n }\n\n const field = fieldByRef(overlay.fields, effect.ref);\n if (!field) continue;\n const key = refKey(effect.ref);\n if (effect.kind === 'setValue') {\n field.value = scriptValueFromFormValue(field, effect.value);\n overlay.resetKeys.delete(key);\n } else if (effect.kind === 'setDisplay') {\n field.display = effect.display;\n } else {\n overlay.appearances.set(key, { ref: effect.ref, text: effect.text });\n }\n }\n}\n\nexport function canonicalEffects(overlay: Overlay): FormEffect[] {\n const effects: FormEffect[] = [];\n const resets: FormFieldRef[] = [];\n for (const field of overlay.fields) {\n const original = fieldByRef(overlay.original, field.ref);\n if (!original) continue;\n if (!sameValue(original.value, field.value)) {\n const key = refKey(field.ref);\n if (overlay.resetKeys.has(key) && sameValue(field.value, field.defaultValue)) {\n resets.push(field.ref);\n } else {\n const value = formValueFromScriptValue(field);\n if (value) effects.push({ kind: 'setValue', ref: field.ref, value });\n }\n }\n if (original.display !== field.display) {\n effects.push({ kind: 'setDisplay', ref: field.ref, display: field.display });\n }\n }\n if (resets.length > 0) effects.unshift({ kind: 'reset', refs: resets });\n effects.push(\n ...Array.from(overlay.appearances.values(), ({ ref, text }) => ({\n kind: 'setAppearanceText' as const,\n ref,\n text,\n })),\n );\n return effects;\n}\n","/** Result shaping for the scripting transaction: errors, budgets, page numbers. */\nimport type { DocumentMeta } from '@embedpdf/core';\nimport type { ScriptExecutionError } from '@embedpdf/core-acrojs';\nimport type { FormField } from '@embedpdf/engine-core/runtime';\n\nexport function scriptError(message: string): ScriptExecutionError {\n return { kind: 'invalid-output', message };\n}\n\nexport function utf8Length(value: string): number {\n let length = 0;\n for (let index = 0; index < value.length; index += 1) {\n const code = value.charCodeAt(index);\n if (code < 0x80) length += 1;\n else if (code < 0x800) length += 2;\n else if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length) {\n length += 4;\n index += 1;\n } else length += 3;\n }\n return length;\n}\n\nexport function pageNumberFor(meta: Pick<DocumentMeta, 'pages'> | null, field: FormField): number {\n const placed = field.widgets.find((widget) => widget.page !== null)?.page;\n if (!meta || !placed) return 0;\n const index = meta.pages.findIndex((page) => page.ref.objectNumber === placed.objectNumber);\n return Math.max(0, index);\n}\n","/**\n * The K/V/C/F passes: keystroke, validate, calculate and format scripts over\n * one working copy of the form (`overlay.ts`), inside one realm transaction.\n * The controller reads the form it is given and returns what the scripts\n * changed. Writing it is the caller's, inside the same transaction\n * (`transaction`), so the next transaction reads the form with it.\n */\nimport type { DocumentMeta } from '@embedpdf/core';\nimport {\n DEFAULT_SCRIPT_BUDGET,\n javaScriptProgramFromActionTree,\n scriptFieldsFromSnapshot,\n type ScriptBudget,\n type ScriptDiagnostic,\n type ScriptExecutionError,\n type ScriptFieldInput,\n type ScriptOutput,\n type ScriptTransaction,\n type ScriptValue,\n type ScriptWorldInput,\n} from '@embedpdf/core-acrojs';\nimport type {\n FormEffect,\n FormFieldRef,\n FormFieldValue,\n FormSnapshot,\n PdfActionTree,\n} from '@embedpdf/engine-core/runtime';\n\nimport type { FormUiEffect } from '../contract';\nimport {\n applyEffects,\n canonicalEffects,\n cloneFields,\n cloneValue,\n fieldByRef,\n refKey,\n sameRef,\n scriptValueFromFormValue,\n snapshotField,\n type Overlay,\n} from './overlay';\nimport { pageNumberFor, scriptError, utf8Length } from './results';\n\n/**\n * The controller never owns a realm. It rides a realm port — this document's\n * own (the actions plugin's per-document host) or a detached one minted by\n * the actions plugin for a document that is not displayed (stamp's\n * asset documents). Either way the owner destroys the realm; `destroy()`\n * here only fences further transactions.\n */\nexport interface FormScriptingControllerOptions {\n /** What the scripts read of the document: its name, page count and pages. */\n document(): Pick<DocumentMeta, 'name' | 'pageCount' | 'pages'> | null;\n /** The realm's transaction port ({@link ScriptTransaction}): the realm runs one at a time. */\n transaction<T>(body: (txn: ScriptTransaction) => Promise<T>): Promise<T>;\n /** The transaction aggregate (output bytes, wall-clock across passes);\n * the realm owner hands over the same budget its runs enforce. */\n budget?: ScriptBudget;\n}\n\n/** What the form's scripts made of one write, before anything is written. */\nexport interface FormScriptResult {\n /**\n * `accepted`: write `effects`. `rejected`: a keystroke or validate script refused the value,\n * so only `bootEffects` are written. `failed`: the transaction broke (a budget, a script that\n * couldn't run), so nothing is.\n */\n readonly status: 'accepted' | 'rejected' | 'failed';\n /** What the scripts changed in the form, in the order to write it (`formEffectOps`). */\n readonly effects: FormEffect[];\n /** What the document's open scripts changed: written even when the value is refused. */\n readonly bootEffects: FormEffect[];\n readonly uiEffects: FormUiEffect[];\n readonly diagnostics: ScriptDiagnostic[];\n readonly error?: ScriptExecutionError;\n}\n\n/** The scripts one transaction can run, each against the form it is given. */\nexport interface FormScripts {\n /**\n * A field's new value through its keystroke and validate scripts, then the calculations and\n * the formats. `form` is the form without the value.\n */\n commit(form: FormSnapshot, ref: FormFieldRef, value: FormFieldValue): Promise<FormScriptResult>;\n /** One widget's activation action (`/A`, with `/Next`). Only its scripts run here. */\n activate(\n form: FormSnapshot,\n ref: FormFieldRef,\n action: PdfActionTree<unknown>,\n ): Promise<FormScriptResult>;\n /** The document's open scripts (once per realm) and the calculations, without a field change. */\n recalculate(form: FormSnapshot): Promise<FormScriptResult>;\n}\n\nexport class FormScriptingController {\n private disposed = false;\n private readonly transactionBudget: ScriptBudget | undefined;\n\n constructor(private readonly options: FormScriptingControllerOptions) {\n this.transactionBudget = options.budget;\n }\n\n /** The realm belongs to its owner (the actions plugin, or the caller that\n * minted a detached one) — this only fences further transactions. */\n destroy(): void {\n this.disposed = true;\n }\n\n /**\n * One realm transaction: `body` runs its scripts and writes what they changed before the\n * next transaction starts, so that one reads the form with it.\n */\n transaction<T>(body: (scripts: FormScripts) => Promise<T>): Promise<T> {\n if (this.disposed) return Promise.reject(new Error('Form scripting controller is disposed'));\n return this.options.transaction((txn) =>\n body({\n commit: (form, ref, value) => this.run(txn, form, ref, value),\n activate: (form, ref, action) => this.run(txn, form, ref, undefined, action),\n recalculate: (form) => this.run(txn, form, undefined),\n }),\n );\n }\n\n /**\n * Load the realm before the first write needs it: the scripts' engine starts, and the\n * document's open scripts run, their effects kept for the first write as without warming.\n * Nothing is written.\n */\n async warm(form: FormSnapshot): Promise<void> {\n if (this.disposed) return;\n const budget = this.transactionBudget ?? DEFAULT_SCRIPT_BUDGET;\n await this.options.transaction((txn) =>\n txn.run(\n '',\n { fields: scriptFieldsFromSnapshot(form), event: { kind: 'name-tree-boot' } },\n budget,\n ),\n );\n }\n\n /** {@link FormScripts.commit} in a transaction of its own. */\n commit(form: FormSnapshot, ref: FormFieldRef, value: FormFieldValue): Promise<FormScriptResult> {\n return this.transaction((scripts) => scripts.commit(form, ref, value));\n }\n\n /** {@link FormScripts.activate} in a transaction of its own. */\n activate(\n form: FormSnapshot,\n ref: FormFieldRef,\n action: PdfActionTree<unknown>,\n ): Promise<FormScriptResult> {\n return this.transaction((scripts) => scripts.activate(form, ref, action));\n }\n\n /** {@link FormScripts.recalculate} in a transaction of its own. */\n recalculate(form: FormSnapshot): Promise<FormScriptResult> {\n return this.transaction((scripts) => scripts.recalculate(form));\n }\n\n private async run(\n txn: ScriptTransaction,\n snapshot: FormSnapshot,\n refInput: FormFieldRef | undefined,\n proposed?: FormFieldValue,\n activation?: PdfActionTree<unknown>,\n ): Promise<FormScriptResult> {\n // Recalculate's anchor resolves here (first live /CO field, else the\n // first field); a zero-field document is an honest no-op.\n const asked =\n refInput ??\n snapshot.calculationOrder.find(\n (candidate): candidate is FormFieldRef =>\n candidate !== null && snapshotField(snapshot, candidate) !== undefined,\n ) ??\n snapshot.fields[0]?.ref;\n if (!asked) {\n return { status: 'accepted', effects: [], bootEffects: [], uiEffects: [], diagnostics: [] };\n }\n const target = snapshotField(snapshot, asked);\n if (!target) {\n return this.failed([], [], scriptError(`Form field '${refKey(asked)}' no longer exists`));\n }\n // The scripts know the field by its own ref, whichever ref asked for it.\n const ref = target.ref;\n\n const original = scriptFieldsFromSnapshot(snapshot);\n const overlay: Overlay = {\n original,\n fields: cloneFields(original),\n resetKeys: new Set(),\n appearances: new Map(),\n };\n const targetInput = fieldByRef(overlay.fields, ref);\n if (!targetInput) {\n return this.failed([], [], scriptError(`Form field '${refKey(ref)}' has no script view`));\n }\n\n const hasProposedValue = proposed !== undefined;\n let proposedValue: ScriptValue = cloneValue(targetInput.value);\n if (proposed) {\n try {\n proposedValue = scriptValueFromFormValue(targetInput, proposed);\n } catch (error) {\n return this.failed(\n [],\n [],\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n }\n\n const uiEffects: FormUiEffect[] = [];\n const diagnostics: ScriptDiagnostic[] = [];\n const meta = this.options.document();\n // Document/identity/environment are host-owned now; the world carries the\n // per-field current page for `this.pageNum`.\n const pageNumber = pageNumberFor(meta, target);\n const budget = this.transactionBudget ?? DEFAULT_SCRIPT_BUDGET;\n let executionMs = 0;\n let aggregateOutputSize = 0;\n\n const consume = (\n output: ScriptOutput,\n phase: FormUiEffect['phase'],\n ): ScriptExecutionError | null => {\n aggregateOutputSize += utf8Length(JSON.stringify(output));\n // Tag every UI request with who asked — embedders suppress boot-phase\n // nags (Adobe's version-check alert) but show user-phase validation.\n uiEffects.push(...output.uiEffects.map((effect) => ({ ...effect, phase })));\n diagnostics.push(...output.diagnostics);\n if (aggregateOutputSize > budget.maxOutputBytes) {\n return {\n kind: 'budget',\n message: `Form script transaction output exceeded ${budget.maxOutputBytes} bytes`,\n };\n }\n return output.error ?? null;\n };\n const remainingBudget = (): ScriptBudget | null => {\n const remaining = budget.maxExecutionMs - executionMs;\n return remaining <= 0 ? null : { ...budget, maxExecutionMs: remaining };\n };\n const world = (\n fields: ScriptFieldInput[],\n event: ScriptWorldInput['event'],\n ): ScriptWorldInput => ({\n fields,\n pageNumber,\n event,\n });\n const run = async (\n source: string,\n input: ScriptWorldInput,\n ): Promise<{ output?: ScriptOutput; error?: ScriptExecutionError }> => {\n const remaining = remainingBudget();\n if (!remaining) {\n return { error: { kind: 'budget', message: 'Form script transaction timed out' } };\n }\n let output: ScriptOutput;\n try {\n const startedAt = Date.now();\n output = await txn.run(source, input, remaining);\n executionMs += Date.now() - startedAt;\n } catch (error) {\n return {\n error: scriptError(error instanceof Error ? error.message : String(error)),\n };\n }\n const error = consume(output, 'user');\n return error ? { error } : { output };\n };\n\n {\n // Boot runs once per realm (host-owned latch) and can only ever\n // degrade, never brick — a failure surfaces a diagnostic and this\n // transaction continues from pristine state.\n let boot: ScriptOutput | null = null;\n try {\n boot = await txn.boot(world(overlay.fields, { kind: 'name-tree-boot' }), budget);\n } catch (error) {\n diagnostics.push({\n code: 'script-error',\n message: `Document boot script failed (continuing without it): ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n if (boot) {\n const bootError = consume(boot, 'boot');\n if (!bootError) applyEffects(overlay, boot.formEffects);\n else {\n diagnostics.push({\n code: 'script-error',\n message: `Document boot script failed (continuing without it): ${bootError.message}`,\n });\n }\n }\n }\n\n const bootEffects = canonicalEffects(overlay);\n\n if (activation) {\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(activation);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (program) {\n const activated = await run(\n program,\n world(overlay.fields, {\n kind: 'widget-activate',\n target: ref,\n source: ref,\n value: targetInput.value,\n }),\n );\n if (activated.error) return this.failed(uiEffects, diagnostics, activated.error);\n applyEffects(overlay, activated.output!.formEffects);\n }\n }\n\n if (!activation && hasProposedValue && target.actions?.keystroke && target.kind === 'text') {\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(target.actions.keystroke);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (program) {\n // Acrobat fires per-typing keystroke events plus one final commit\n // event. This pipeline compresses typing into one paste-shaped\n // replacement (Acrobat's own paste contract: the whole string rides\n // `event.change`, willCommit=false) so transform/filter scripts run,\n // then fires the Acrobat-faithful willCommit pass (the full value on\n // `event.value`, empty `change`) so AF* and commit validators see\n // what Adobe's library expects.\n const oldValue = String(targetInput.value ?? '');\n const typing = await run(\n program,\n world(overlay.fields, {\n kind: 'field-keystroke',\n target: ref,\n source: ref,\n value: oldValue,\n change: String(proposedValue ?? ''),\n selStart: 0,\n selEnd: oldValue.length,\n willCommit: false,\n }),\n );\n if (typing.error && typing.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, typing.error);\n }\n if (typing.error) {\n // Fault ladder: an exception is not a rejection. Keep the typed\n // value, surface a diagnostic, and let the transaction continue.\n diagnostics.push({\n code: 'script-error',\n message: `Keystroke script failed (kept the typed value): ${typing.error.message}`,\n });\n } else {\n if (!typing.output!.event.rc) {\n return this.rejected(bootEffects, uiEffects, diagnostics);\n }\n applyEffects(overlay, typing.output!.formEffects);\n const event = typing.output!.event;\n const base = String(event.value ?? '');\n proposedValue =\n base.slice(0, event.selStart) +\n event.change +\n base.slice(Math.max(event.selStart, event.selEnd));\n }\n const commit = await run(\n program,\n world(overlay.fields, {\n kind: 'field-keystroke',\n target: ref,\n source: ref,\n value: proposedValue,\n change: '',\n selStart: 0,\n selEnd: 0,\n willCommit: true,\n }),\n );\n if (commit.error && commit.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, commit.error);\n }\n if (commit.error) {\n diagnostics.push({\n code: 'script-error',\n message: `Keystroke commit script failed (kept the typed value): ${commit.error.message}`,\n });\n } else {\n if (!commit.output!.event.rc) {\n return this.rejected(bootEffects, uiEffects, diagnostics);\n }\n applyEffects(overlay, commit.output!.formEffects);\n proposedValue = cloneValue(commit.output!.event.value);\n }\n }\n }\n\n if (!activation && hasProposedValue) {\n targetInput.value = cloneValue(proposedValue);\n overlay.resetKeys.delete(refKey(ref));\n }\n\n if (!activation && hasProposedValue && target.actions?.validate) {\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(target.actions.validate);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (program) {\n const validation = await run(\n program,\n world(overlay.fields, {\n kind: 'field-validate',\n target: ref,\n source: ref,\n value: proposedValue,\n willCommit: true,\n }),\n );\n if (validation.error && validation.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, validation.error);\n }\n if (validation.error) {\n // Fault ladder: a broken validator must not reject the value.\n diagnostics.push({\n code: 'script-error',\n message: `Validate script failed (accepted the value): ${validation.error.message}`,\n });\n } else {\n if (!validation.output!.event.rc) {\n return this.rejected(bootEffects, uiEffects, diagnostics);\n }\n targetInput.value = cloneValue(validation.output!.event.value);\n applyEffects(overlay, validation.output!.formEffects);\n }\n }\n }\n\n const formatRefs: FormFieldRef[] = !activation && hasProposedValue ? [ref] : [];\n for (const calculationRef of activation ? [] : snapshot.calculationOrder) {\n if (!calculationRef) continue;\n const calculated = snapshotField(snapshot, calculationRef);\n const tree = calculated?.actions?.calculate;\n if (!calculated || !tree) continue;\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(tree);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n const calculatedInput = fieldByRef(overlay.fields, calculationRef);\n if (program && calculatedInput) {\n const calculation = await run(\n program,\n world(overlay.fields, {\n kind: 'field-calculate',\n target: calculationRef,\n ...(hasProposedValue ? { source: ref } : {}),\n value: calculatedInput.value,\n }),\n );\n if (calculation.error && calculation.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, calculation.error);\n }\n if (calculation.error) {\n // Fault ladder: this field's calculation is skipped; the /CO chain continues.\n diagnostics.push({\n code: 'script-error',\n message: `Calculate script failed (field left unchanged): ${calculation.error.message}`,\n });\n } else {\n applyEffects(overlay, calculation.output!.formEffects);\n }\n }\n if (!formatRefs.some((candidate) => sameRef(candidate, calculationRef))) {\n formatRefs.push(calculationRef);\n }\n }\n\n for (const formatRef of formatRefs) {\n const field = snapshotField(snapshot, formatRef);\n const tree = field?.actions?.format;\n const overlayField = fieldByRef(overlay.fields, formatRef);\n if (!field || !tree || !overlayField) continue;\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(tree);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (!program) continue;\n const format = await run(\n program,\n world(overlay.fields, {\n kind: 'field-format',\n target: formatRef,\n ...(hasProposedValue ? { source: ref } : {}),\n value: overlayField.value,\n }),\n );\n if (format.error && format.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, format.error);\n }\n if (format.error) {\n // Fault ladder: formatting is cosmetic — skip it, keep the raw value.\n diagnostics.push({\n code: 'script-error',\n message: `Format script failed (kept the raw value): ${format.error.message}`,\n });\n continue;\n }\n applyEffects(overlay, format.output!.formEffects);\n }\n\n const effects = canonicalEffects(overlay);\n if (effects.length + uiEffects.length > budget.maxEffects) {\n return this.failed(uiEffects, diagnostics, {\n kind: 'budget',\n message: `Form script transaction exceeded ${budget.maxEffects} effects`,\n });\n }\n return { status: 'accepted', effects, bootEffects, uiEffects, diagnostics };\n }\n\n private failed(\n uiEffects: FormUiEffect[],\n diagnostics: ScriptDiagnostic[],\n error: ScriptExecutionError,\n ): FormScriptResult {\n return { status: 'failed', effects: [], bootEffects: [], uiEffects, diagnostics, error };\n }\n\n /** The value is refused; the open scripts' effects are still written. */\n private rejected(\n bootEffects: FormEffect[],\n uiEffects: FormUiEffect[],\n diagnostics: ScriptDiagnostic[],\n ): FormScriptResult {\n return { status: 'rejected', effects: [], bootEffects, uiEffects, diagnostics };\n }\n}\n\nexport function createFormScriptingController(\n options: FormScriptingControllerOptions,\n): FormScriptingController {\n return new FormScriptingController(options);\n}\n"],"mappings":";;AAqBA,MAAa,UAAU,QACrB,IAAI,SAAS,iBAAiB,OAAO,IAAI,iBAAiB,OAAO,IAAI;AAEvE,MAAa,WAAW,MAAoB,UAC1C,OAAO,IAAI,MAAM,OAAO,KAAK;AAE/B,MAAa,cAAc,UACzB,MAAM,QAAQ,KAAK,IAAI,CAAC,GAAG,KAAK,IAAI;AAEtC,MAAa,aAAa,MAAmB,UAC3C,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,KAAK,IACtC,KAAK,WAAW,MAAM,UAAU,KAAK,OAAO,OAAO,UAAU,UAAU,MAAM,MAAM,IACnF,SAAS;AAEf,SAAgB,YAAY,QAAgD;CAC1E,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH,KAAK,EAAE,GAAG,MAAM,IAAI;EACpB,OAAO,WAAW,MAAM,KAAK;EAC7B,cAAc,WAAW,MAAM,YAAY;EAC3C,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,KAAK,YAAY,EAAE,GAAG,OAAO,EAAE,EAAE,IAAI,CAAC;CACrF,EAAE;AACJ;AAEA,SAAgB,WACd,QACA,KACe;CACf,OAAO,OAAO,MAAM,UAAU,QAAQ,MAAM,KAAK,GAAG,CAAC;AACvD;;AAGA,SAAgB,cAAc,UAAwB,KAA0C;CAC9F,OAAO,SAAS,OAAO,MACpB,UAAU,QAAQ,MAAM,KAAK,GAAG,KAAM,IAAI,SAAS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C,SAAS,CAAC,QAAQ,CAAC,cAAc;GACtC,IAAI;GACJ,IAAI;IACF,UAAU,gCAAgC,IAAI;GAChD,SAAS,OAAO;IACd,OAAO,KAAK,OACV,WACA,aACA,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,CACpE;GACF;GACA,IAAI,CAAC,SAAS;GACd,MAAM,SAAS,MAAM,IACnB,SACA,MAAM,QAAQ,QAAQ;IACpB,MAAM;IACN,QAAQ;IACR,GAAI,mBAAmB,EAAE,QAAQ,IAAI,IAAI,CAAC;IAC1C,OAAO,aAAa;GACtB,CAAC,CACH;GACA,IAAI,OAAO,SAAS,OAAO,MAAM,SAAS,aACxC,OAAO,KAAK,OAAO,WAAW,aAAa,OAAO,KAAK;GAEzD,IAAI,OAAO,OAAO;IAEhB,YAAY,KAAK;KACf,MAAM;KACN,SAAS,8CAA8C,OAAO,MAAM;IACtE,CAAC;IACD;GACF;GACA,aAAa,SAAS,OAAO,OAAQ,WAAW;EAClD;EAEA,MAAM,UAAU,iBAAiB,OAAO;EACxC,IAAI,QAAQ,SAAS,UAAU,SAAS,OAAO,YAC7C,OAAO,KAAK,OAAO,WAAW,aAAa;GACzC,MAAM;GACN,SAAS,oCAAoC,OAAO,WAAW;EACjE,CAAC;EAEH,OAAO;GAAE,QAAQ;GAAY;GAAS;GAAa;GAAW;EAAY;CAC5E;CAEA,OACE,WACA,aACA,OACkB;EAClB,OAAO;GAAE,QAAQ;GAAU,SAAS,CAAC;GAAG,aAAa,CAAC;GAAG;GAAW;GAAa;EAAM;CACzF;;CAGA,SACE,aACA,WACA,aACkB;EAClB,OAAO;GAAE,QAAQ;GAAY,SAAS,CAAC;GAAG;GAAa;GAAW;EAAY;CAChF;AACF;AAEA,SAAgB,8BACd,SACyB;CACzB,OAAO,IAAI,wBAAwB,OAAO;AAC5C"}
@@ -22,7 +22,7 @@ function snapshotField(snapshot, ref) {
22
22
  }
23
23
  /** A written value as scripts see it: a toggle's export value (`'Off'` when clear). */
24
24
  function scriptValueFromFormValue(field, value) {
25
- switch (field.family) {
25
+ switch (field.kind) {
26
26
  case "text":
27
27
  case "combobox":
28
28
  if ("value" in value) return value.value ?? "";
@@ -43,12 +43,12 @@ function scriptValueFromFormValue(field, value) {
43
43
  if ("selectedValues" in value) return [...value.selectedValues];
44
44
  break;
45
45
  }
46
- throw new Error(`Form field '${field.name}' (${field.family}) does not take this value`);
46
+ throw new Error(`Form field '${field.name}' (${field.kind}) does not take this value`);
47
47
  }
48
- /** A script value as the engine writes it, or null for a family that holds none. */
48
+ /** A script value as the engine writes it, or null for a kind that holds none. */
49
49
  function formValueFromScriptValue(field) {
50
50
  const value = field.value;
51
- switch (field.family) {
51
+ switch (field.kind) {
52
52
  case "text": return { value: String(value ?? "") };
53
53
  case "checkbox":
54
54
  case "radio": return { value: value === null || String(value) === "Off" ? null : String(value) };
@@ -159,7 +159,7 @@ var FormScriptingController = class {
159
159
  }
160
160
  /** The realm belongs to its owner (the actions plugin, or the caller that
161
161
  * minted a detached one) — this only fences further transactions. */
162
- dispose() {
162
+ destroy() {
163
163
  this.disposed = true;
164
164
  }
165
165
  /**
@@ -313,7 +313,7 @@ var FormScriptingController = class {
313
313
  applyEffects(overlay, activated.output.formEffects);
314
314
  }
315
315
  }
316
- if (!activation && hasProposedValue && target.actions?.keystroke && target.family === "text") {
316
+ if (!activation && hasProposedValue && target.actions?.keystroke && target.kind === "text") {
317
317
  let program;
318
318
  try {
319
319
  program = (0, _embedpdf_core_acrojs.javaScriptProgramFromActionTree)(target.actions.keystroke);
@@ -511,4 +511,4 @@ Object.defineProperty(exports, "scriptError", {
511
511
  }
512
512
  });
513
513
 
514
- //# sourceMappingURL=controller-CS6tV2m1.cjs.map
514
+ //# sourceMappingURL=controller-BwbadmLW.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller-BwbadmLW.cjs","names":["DEFAULT_SCRIPT_BUDGET"],"sources":["../src/scripting/overlay.ts","../src/scripting/results.ts","../src/scripting/controller.ts"],"sourcesContent":["/**\n * The transaction overlay: a working copy of the script field view that\n * every pass mutates, and the canonical effect list diffed from it at the\n * end (values, display, appearance text; resets folded back to one effect).\n */\nimport type { ScriptFieldInput, ScriptValue } from '@embedpdf/core-acrojs';\nimport type {\n FormEffect,\n FormField,\n FormFieldRef,\n FormFieldValue,\n FormSnapshot,\n} from '@embedpdf/engine-core/runtime';\n\nexport interface Overlay {\n original: ScriptFieldInput[];\n fields: ScriptFieldInput[];\n resetKeys: Set<string>;\n appearances: Map<string, { ref: FormFieldRef; text: string }>;\n}\n\nexport const refKey = (ref: FormFieldRef): string =>\n ref.kind === 'objectNumber' ? `obj:${ref.objectNumber}` : `fqn:${ref.name}`;\n\nexport const sameRef = (left: FormFieldRef, right: FormFieldRef): boolean =>\n refKey(left) === refKey(right);\n\nexport const cloneValue = (value: ScriptValue): ScriptValue =>\n Array.isArray(value) ? [...value] : value;\n\nexport const sameValue = (left: ScriptValue, right: ScriptValue): boolean =>\n Array.isArray(left) && Array.isArray(right)\n ? left.length === right.length && left.every((value, index) => value === right[index])\n : left === right;\n\nexport function cloneFields(fields: ScriptFieldInput[]): ScriptFieldInput[] {\n return fields.map((field) => ({\n ...field,\n ref: { ...field.ref },\n value: cloneValue(field.value),\n defaultValue: cloneValue(field.defaultValue),\n ...(field.options ? { options: field.options.map((option) => ({ ...option })) } : {}),\n }));\n}\n\nexport function fieldByRef<T extends { ref: FormFieldRef }>(\n fields: T[],\n ref: FormFieldRef,\n): T | undefined {\n return fields.find((field) => sameRef(field.ref, ref));\n}\n\n/** The field a ref names: by its own ref, or by full name for `toFieldRef(name)`. */\nexport function snapshotField(snapshot: FormSnapshot, ref: FormFieldRef): FormField | undefined {\n return snapshot.fields.find(\n (field) => sameRef(field.ref, ref) || (ref.kind === 'fqn' && field.name === ref.name),\n );\n}\n\n/** A written value as scripts see it: a toggle's export value (`'Off'` when clear). */\nexport function scriptValueFromFormValue(\n field: ScriptFieldInput,\n value: FormFieldValue,\n): ScriptValue {\n switch (field.kind) {\n case 'text':\n case 'combobox':\n if ('value' in value) return value.value ?? '';\n break;\n case 'radio':\n if ('value' in value) return value.value ?? 'Off';\n break;\n case 'checkbox':\n if ('value' in value) return value.value ?? 'Off';\n if ('checked' in value) {\n if (!value.checked) return 'Off';\n const first = field.exportValues?.[0];\n if (first === undefined)\n throw new Error(`Form field '${field.name}' has no widget to check`);\n return first;\n }\n break;\n case 'listbox':\n if ('selectedValues' in value) return [...value.selectedValues];\n break;\n }\n throw new Error(`Form field '${field.name}' (${field.kind}) does not take this value`);\n}\n\n/** A script value as the engine writes it, or null for a kind that holds none. */\nexport function formValueFromScriptValue(field: ScriptFieldInput): FormFieldValue | null {\n const value = field.value;\n switch (field.kind) {\n case 'text':\n return { value: String(value ?? '') };\n case 'checkbox':\n case 'radio':\n return { value: value === null || String(value) === 'Off' ? null : String(value) };\n case 'combobox': {\n const selected = Array.isArray(value) ? value[0] : value;\n const text = selected === null || selected === undefined ? '' : String(selected);\n return { value: text === '' ? null : text };\n }\n case 'listbox':\n if (Array.isArray(value)) return { selectedValues: [...value] };\n return { selectedValues: value === null || value === '' ? [] : [String(value)] };\n default:\n return null;\n }\n}\n\nexport function applyEffects(overlay: Overlay, effects: FormEffect[]): void {\n for (const effect of effects) {\n if (effect.kind === 'reset') {\n for (const ref of effect.refs) {\n const field = fieldByRef(overlay.fields, ref);\n if (!field) continue;\n field.value = cloneValue(field.defaultValue);\n overlay.resetKeys.add(refKey(ref));\n }\n continue;\n }\n\n const field = fieldByRef(overlay.fields, effect.ref);\n if (!field) continue;\n const key = refKey(effect.ref);\n if (effect.kind === 'setValue') {\n field.value = scriptValueFromFormValue(field, effect.value);\n overlay.resetKeys.delete(key);\n } else if (effect.kind === 'setDisplay') {\n field.display = effect.display;\n } else {\n overlay.appearances.set(key, { ref: effect.ref, text: effect.text });\n }\n }\n}\n\nexport function canonicalEffects(overlay: Overlay): FormEffect[] {\n const effects: FormEffect[] = [];\n const resets: FormFieldRef[] = [];\n for (const field of overlay.fields) {\n const original = fieldByRef(overlay.original, field.ref);\n if (!original) continue;\n if (!sameValue(original.value, field.value)) {\n const key = refKey(field.ref);\n if (overlay.resetKeys.has(key) && sameValue(field.value, field.defaultValue)) {\n resets.push(field.ref);\n } else {\n const value = formValueFromScriptValue(field);\n if (value) effects.push({ kind: 'setValue', ref: field.ref, value });\n }\n }\n if (original.display !== field.display) {\n effects.push({ kind: 'setDisplay', ref: field.ref, display: field.display });\n }\n }\n if (resets.length > 0) effects.unshift({ kind: 'reset', refs: resets });\n effects.push(\n ...Array.from(overlay.appearances.values(), ({ ref, text }) => ({\n kind: 'setAppearanceText' as const,\n ref,\n text,\n })),\n );\n return effects;\n}\n","/** Result shaping for the scripting transaction: errors, budgets, page numbers. */\nimport type { DocumentMeta } from '@embedpdf/core';\nimport type { ScriptExecutionError } from '@embedpdf/core-acrojs';\nimport type { FormField } from '@embedpdf/engine-core/runtime';\n\nexport function scriptError(message: string): ScriptExecutionError {\n return { kind: 'invalid-output', message };\n}\n\nexport function utf8Length(value: string): number {\n let length = 0;\n for (let index = 0; index < value.length; index += 1) {\n const code = value.charCodeAt(index);\n if (code < 0x80) length += 1;\n else if (code < 0x800) length += 2;\n else if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length) {\n length += 4;\n index += 1;\n } else length += 3;\n }\n return length;\n}\n\nexport function pageNumberFor(meta: Pick<DocumentMeta, 'pages'> | null, field: FormField): number {\n const placed = field.widgets.find((widget) => widget.page !== null)?.page;\n if (!meta || !placed) return 0;\n const index = meta.pages.findIndex((page) => page.ref.objectNumber === placed.objectNumber);\n return Math.max(0, index);\n}\n","/**\n * The K/V/C/F passes: keystroke, validate, calculate and format scripts over\n * one working copy of the form (`overlay.ts`), inside one realm transaction.\n * The controller reads the form it is given and returns what the scripts\n * changed. Writing it is the caller's, inside the same transaction\n * (`transaction`), so the next transaction reads the form with it.\n */\nimport type { DocumentMeta } from '@embedpdf/core';\nimport {\n DEFAULT_SCRIPT_BUDGET,\n javaScriptProgramFromActionTree,\n scriptFieldsFromSnapshot,\n type ScriptBudget,\n type ScriptDiagnostic,\n type ScriptExecutionError,\n type ScriptFieldInput,\n type ScriptOutput,\n type ScriptTransaction,\n type ScriptValue,\n type ScriptWorldInput,\n} from '@embedpdf/core-acrojs';\nimport type {\n FormEffect,\n FormFieldRef,\n FormFieldValue,\n FormSnapshot,\n PdfActionTree,\n} from '@embedpdf/engine-core/runtime';\n\nimport type { FormUiEffect } from '../contract';\nimport {\n applyEffects,\n canonicalEffects,\n cloneFields,\n cloneValue,\n fieldByRef,\n refKey,\n sameRef,\n scriptValueFromFormValue,\n snapshotField,\n type Overlay,\n} from './overlay';\nimport { pageNumberFor, scriptError, utf8Length } from './results';\n\n/**\n * The controller never owns a realm. It rides a realm port — this document's\n * own (the actions plugin's per-document host) or a detached one minted by\n * the actions plugin for a document that is not displayed (stamp's\n * asset documents). Either way the owner destroys the realm; `destroy()`\n * here only fences further transactions.\n */\nexport interface FormScriptingControllerOptions {\n /** What the scripts read of the document: its name, page count and pages. */\n document(): Pick<DocumentMeta, 'name' | 'pageCount' | 'pages'> | null;\n /** The realm's transaction port ({@link ScriptTransaction}): the realm runs one at a time. */\n transaction<T>(body: (txn: ScriptTransaction) => Promise<T>): Promise<T>;\n /** The transaction aggregate (output bytes, wall-clock across passes);\n * the realm owner hands over the same budget its runs enforce. */\n budget?: ScriptBudget;\n}\n\n/** What the form's scripts made of one write, before anything is written. */\nexport interface FormScriptResult {\n /**\n * `accepted`: write `effects`. `rejected`: a keystroke or validate script refused the value,\n * so only `bootEffects` are written. `failed`: the transaction broke (a budget, a script that\n * couldn't run), so nothing is.\n */\n readonly status: 'accepted' | 'rejected' | 'failed';\n /** What the scripts changed in the form, in the order to write it (`formEffectOps`). */\n readonly effects: FormEffect[];\n /** What the document's open scripts changed: written even when the value is refused. */\n readonly bootEffects: FormEffect[];\n readonly uiEffects: FormUiEffect[];\n readonly diagnostics: ScriptDiagnostic[];\n readonly error?: ScriptExecutionError;\n}\n\n/** The scripts one transaction can run, each against the form it is given. */\nexport interface FormScripts {\n /**\n * A field's new value through its keystroke and validate scripts, then the calculations and\n * the formats. `form` is the form without the value.\n */\n commit(form: FormSnapshot, ref: FormFieldRef, value: FormFieldValue): Promise<FormScriptResult>;\n /** One widget's activation action (`/A`, with `/Next`). Only its scripts run here. */\n activate(\n form: FormSnapshot,\n ref: FormFieldRef,\n action: PdfActionTree<unknown>,\n ): Promise<FormScriptResult>;\n /** The document's open scripts (once per realm) and the calculations, without a field change. */\n recalculate(form: FormSnapshot): Promise<FormScriptResult>;\n}\n\nexport class FormScriptingController {\n private disposed = false;\n private readonly transactionBudget: ScriptBudget | undefined;\n\n constructor(private readonly options: FormScriptingControllerOptions) {\n this.transactionBudget = options.budget;\n }\n\n /** The realm belongs to its owner (the actions plugin, or the caller that\n * minted a detached one) — this only fences further transactions. */\n destroy(): void {\n this.disposed = true;\n }\n\n /**\n * One realm transaction: `body` runs its scripts and writes what they changed before the\n * next transaction starts, so that one reads the form with it.\n */\n transaction<T>(body: (scripts: FormScripts) => Promise<T>): Promise<T> {\n if (this.disposed) return Promise.reject(new Error('Form scripting controller is disposed'));\n return this.options.transaction((txn) =>\n body({\n commit: (form, ref, value) => this.run(txn, form, ref, value),\n activate: (form, ref, action) => this.run(txn, form, ref, undefined, action),\n recalculate: (form) => this.run(txn, form, undefined),\n }),\n );\n }\n\n /**\n * Load the realm before the first write needs it: the scripts' engine starts, and the\n * document's open scripts run, their effects kept for the first write as without warming.\n * Nothing is written.\n */\n async warm(form: FormSnapshot): Promise<void> {\n if (this.disposed) return;\n const budget = this.transactionBudget ?? DEFAULT_SCRIPT_BUDGET;\n await this.options.transaction((txn) =>\n txn.run(\n '',\n { fields: scriptFieldsFromSnapshot(form), event: { kind: 'name-tree-boot' } },\n budget,\n ),\n );\n }\n\n /** {@link FormScripts.commit} in a transaction of its own. */\n commit(form: FormSnapshot, ref: FormFieldRef, value: FormFieldValue): Promise<FormScriptResult> {\n return this.transaction((scripts) => scripts.commit(form, ref, value));\n }\n\n /** {@link FormScripts.activate} in a transaction of its own. */\n activate(\n form: FormSnapshot,\n ref: FormFieldRef,\n action: PdfActionTree<unknown>,\n ): Promise<FormScriptResult> {\n return this.transaction((scripts) => scripts.activate(form, ref, action));\n }\n\n /** {@link FormScripts.recalculate} in a transaction of its own. */\n recalculate(form: FormSnapshot): Promise<FormScriptResult> {\n return this.transaction((scripts) => scripts.recalculate(form));\n }\n\n private async run(\n txn: ScriptTransaction,\n snapshot: FormSnapshot,\n refInput: FormFieldRef | undefined,\n proposed?: FormFieldValue,\n activation?: PdfActionTree<unknown>,\n ): Promise<FormScriptResult> {\n // Recalculate's anchor resolves here (first live /CO field, else the\n // first field); a zero-field document is an honest no-op.\n const asked =\n refInput ??\n snapshot.calculationOrder.find(\n (candidate): candidate is FormFieldRef =>\n candidate !== null && snapshotField(snapshot, candidate) !== undefined,\n ) ??\n snapshot.fields[0]?.ref;\n if (!asked) {\n return { status: 'accepted', effects: [], bootEffects: [], uiEffects: [], diagnostics: [] };\n }\n const target = snapshotField(snapshot, asked);\n if (!target) {\n return this.failed([], [], scriptError(`Form field '${refKey(asked)}' no longer exists`));\n }\n // The scripts know the field by its own ref, whichever ref asked for it.\n const ref = target.ref;\n\n const original = scriptFieldsFromSnapshot(snapshot);\n const overlay: Overlay = {\n original,\n fields: cloneFields(original),\n resetKeys: new Set(),\n appearances: new Map(),\n };\n const targetInput = fieldByRef(overlay.fields, ref);\n if (!targetInput) {\n return this.failed([], [], scriptError(`Form field '${refKey(ref)}' has no script view`));\n }\n\n const hasProposedValue = proposed !== undefined;\n let proposedValue: ScriptValue = cloneValue(targetInput.value);\n if (proposed) {\n try {\n proposedValue = scriptValueFromFormValue(targetInput, proposed);\n } catch (error) {\n return this.failed(\n [],\n [],\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n }\n\n const uiEffects: FormUiEffect[] = [];\n const diagnostics: ScriptDiagnostic[] = [];\n const meta = this.options.document();\n // Document/identity/environment are host-owned now; the world carries the\n // per-field current page for `this.pageNum`.\n const pageNumber = pageNumberFor(meta, target);\n const budget = this.transactionBudget ?? DEFAULT_SCRIPT_BUDGET;\n let executionMs = 0;\n let aggregateOutputSize = 0;\n\n const consume = (\n output: ScriptOutput,\n phase: FormUiEffect['phase'],\n ): ScriptExecutionError | null => {\n aggregateOutputSize += utf8Length(JSON.stringify(output));\n // Tag every UI request with who asked — embedders suppress boot-phase\n // nags (Adobe's version-check alert) but show user-phase validation.\n uiEffects.push(...output.uiEffects.map((effect) => ({ ...effect, phase })));\n diagnostics.push(...output.diagnostics);\n if (aggregateOutputSize > budget.maxOutputBytes) {\n return {\n kind: 'budget',\n message: `Form script transaction output exceeded ${budget.maxOutputBytes} bytes`,\n };\n }\n return output.error ?? null;\n };\n const remainingBudget = (): ScriptBudget | null => {\n const remaining = budget.maxExecutionMs - executionMs;\n return remaining <= 0 ? null : { ...budget, maxExecutionMs: remaining };\n };\n const world = (\n fields: ScriptFieldInput[],\n event: ScriptWorldInput['event'],\n ): ScriptWorldInput => ({\n fields,\n pageNumber,\n event,\n });\n const run = async (\n source: string,\n input: ScriptWorldInput,\n ): Promise<{ output?: ScriptOutput; error?: ScriptExecutionError }> => {\n const remaining = remainingBudget();\n if (!remaining) {\n return { error: { kind: 'budget', message: 'Form script transaction timed out' } };\n }\n let output: ScriptOutput;\n try {\n const startedAt = Date.now();\n output = await txn.run(source, input, remaining);\n executionMs += Date.now() - startedAt;\n } catch (error) {\n return {\n error: scriptError(error instanceof Error ? error.message : String(error)),\n };\n }\n const error = consume(output, 'user');\n return error ? { error } : { output };\n };\n\n {\n // Boot runs once per realm (host-owned latch) and can only ever\n // degrade, never brick — a failure surfaces a diagnostic and this\n // transaction continues from pristine state.\n let boot: ScriptOutput | null = null;\n try {\n boot = await txn.boot(world(overlay.fields, { kind: 'name-tree-boot' }), budget);\n } catch (error) {\n diagnostics.push({\n code: 'script-error',\n message: `Document boot script failed (continuing without it): ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n if (boot) {\n const bootError = consume(boot, 'boot');\n if (!bootError) applyEffects(overlay, boot.formEffects);\n else {\n diagnostics.push({\n code: 'script-error',\n message: `Document boot script failed (continuing without it): ${bootError.message}`,\n });\n }\n }\n }\n\n const bootEffects = canonicalEffects(overlay);\n\n if (activation) {\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(activation);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (program) {\n const activated = await run(\n program,\n world(overlay.fields, {\n kind: 'widget-activate',\n target: ref,\n source: ref,\n value: targetInput.value,\n }),\n );\n if (activated.error) return this.failed(uiEffects, diagnostics, activated.error);\n applyEffects(overlay, activated.output!.formEffects);\n }\n }\n\n if (!activation && hasProposedValue && target.actions?.keystroke && target.kind === 'text') {\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(target.actions.keystroke);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (program) {\n // Acrobat fires per-typing keystroke events plus one final commit\n // event. This pipeline compresses typing into one paste-shaped\n // replacement (Acrobat's own paste contract: the whole string rides\n // `event.change`, willCommit=false) so transform/filter scripts run,\n // then fires the Acrobat-faithful willCommit pass (the full value on\n // `event.value`, empty `change`) so AF* and commit validators see\n // what Adobe's library expects.\n const oldValue = String(targetInput.value ?? '');\n const typing = await run(\n program,\n world(overlay.fields, {\n kind: 'field-keystroke',\n target: ref,\n source: ref,\n value: oldValue,\n change: String(proposedValue ?? ''),\n selStart: 0,\n selEnd: oldValue.length,\n willCommit: false,\n }),\n );\n if (typing.error && typing.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, typing.error);\n }\n if (typing.error) {\n // Fault ladder: an exception is not a rejection. Keep the typed\n // value, surface a diagnostic, and let the transaction continue.\n diagnostics.push({\n code: 'script-error',\n message: `Keystroke script failed (kept the typed value): ${typing.error.message}`,\n });\n } else {\n if (!typing.output!.event.rc) {\n return this.rejected(bootEffects, uiEffects, diagnostics);\n }\n applyEffects(overlay, typing.output!.formEffects);\n const event = typing.output!.event;\n const base = String(event.value ?? '');\n proposedValue =\n base.slice(0, event.selStart) +\n event.change +\n base.slice(Math.max(event.selStart, event.selEnd));\n }\n const commit = await run(\n program,\n world(overlay.fields, {\n kind: 'field-keystroke',\n target: ref,\n source: ref,\n value: proposedValue,\n change: '',\n selStart: 0,\n selEnd: 0,\n willCommit: true,\n }),\n );\n if (commit.error && commit.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, commit.error);\n }\n if (commit.error) {\n diagnostics.push({\n code: 'script-error',\n message: `Keystroke commit script failed (kept the typed value): ${commit.error.message}`,\n });\n } else {\n if (!commit.output!.event.rc) {\n return this.rejected(bootEffects, uiEffects, diagnostics);\n }\n applyEffects(overlay, commit.output!.formEffects);\n proposedValue = cloneValue(commit.output!.event.value);\n }\n }\n }\n\n if (!activation && hasProposedValue) {\n targetInput.value = cloneValue(proposedValue);\n overlay.resetKeys.delete(refKey(ref));\n }\n\n if (!activation && hasProposedValue && target.actions?.validate) {\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(target.actions.validate);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (program) {\n const validation = await run(\n program,\n world(overlay.fields, {\n kind: 'field-validate',\n target: ref,\n source: ref,\n value: proposedValue,\n willCommit: true,\n }),\n );\n if (validation.error && validation.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, validation.error);\n }\n if (validation.error) {\n // Fault ladder: a broken validator must not reject the value.\n diagnostics.push({\n code: 'script-error',\n message: `Validate script failed (accepted the value): ${validation.error.message}`,\n });\n } else {\n if (!validation.output!.event.rc) {\n return this.rejected(bootEffects, uiEffects, diagnostics);\n }\n targetInput.value = cloneValue(validation.output!.event.value);\n applyEffects(overlay, validation.output!.formEffects);\n }\n }\n }\n\n const formatRefs: FormFieldRef[] = !activation && hasProposedValue ? [ref] : [];\n for (const calculationRef of activation ? [] : snapshot.calculationOrder) {\n if (!calculationRef) continue;\n const calculated = snapshotField(snapshot, calculationRef);\n const tree = calculated?.actions?.calculate;\n if (!calculated || !tree) continue;\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(tree);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n const calculatedInput = fieldByRef(overlay.fields, calculationRef);\n if (program && calculatedInput) {\n const calculation = await run(\n program,\n world(overlay.fields, {\n kind: 'field-calculate',\n target: calculationRef,\n ...(hasProposedValue ? { source: ref } : {}),\n value: calculatedInput.value,\n }),\n );\n if (calculation.error && calculation.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, calculation.error);\n }\n if (calculation.error) {\n // Fault ladder: this field's calculation is skipped; the /CO chain continues.\n diagnostics.push({\n code: 'script-error',\n message: `Calculate script failed (field left unchanged): ${calculation.error.message}`,\n });\n } else {\n applyEffects(overlay, calculation.output!.formEffects);\n }\n }\n if (!formatRefs.some((candidate) => sameRef(candidate, calculationRef))) {\n formatRefs.push(calculationRef);\n }\n }\n\n for (const formatRef of formatRefs) {\n const field = snapshotField(snapshot, formatRef);\n const tree = field?.actions?.format;\n const overlayField = fieldByRef(overlay.fields, formatRef);\n if (!field || !tree || !overlayField) continue;\n let program: string;\n try {\n program = javaScriptProgramFromActionTree(tree);\n } catch (error) {\n return this.failed(\n uiEffects,\n diagnostics,\n scriptError(error instanceof Error ? error.message : String(error)),\n );\n }\n if (!program) continue;\n const format = await run(\n program,\n world(overlay.fields, {\n kind: 'field-format',\n target: formatRef,\n ...(hasProposedValue ? { source: ref } : {}),\n value: overlayField.value,\n }),\n );\n if (format.error && format.error.kind !== 'exception') {\n return this.failed(uiEffects, diagnostics, format.error);\n }\n if (format.error) {\n // Fault ladder: formatting is cosmetic — skip it, keep the raw value.\n diagnostics.push({\n code: 'script-error',\n message: `Format script failed (kept the raw value): ${format.error.message}`,\n });\n continue;\n }\n applyEffects(overlay, format.output!.formEffects);\n }\n\n const effects = canonicalEffects(overlay);\n if (effects.length + uiEffects.length > budget.maxEffects) {\n return this.failed(uiEffects, diagnostics, {\n kind: 'budget',\n message: `Form script transaction exceeded ${budget.maxEffects} effects`,\n });\n }\n return { status: 'accepted', effects, bootEffects, uiEffects, diagnostics };\n }\n\n private failed(\n uiEffects: FormUiEffect[],\n diagnostics: ScriptDiagnostic[],\n error: ScriptExecutionError,\n ): FormScriptResult {\n return { status: 'failed', effects: [], bootEffects: [], uiEffects, diagnostics, error };\n }\n\n /** The value is refused; the open scripts' effects are still written. */\n private rejected(\n bootEffects: FormEffect[],\n uiEffects: FormUiEffect[],\n diagnostics: ScriptDiagnostic[],\n ): FormScriptResult {\n return { status: 'rejected', effects: [], bootEffects, uiEffects, diagnostics };\n }\n}\n\nexport function createFormScriptingController(\n options: FormScriptingControllerOptions,\n): FormScriptingController {\n return new FormScriptingController(options);\n}\n"],"mappings":";;AAqBA,MAAa,UAAU,QACrB,IAAI,SAAS,iBAAiB,OAAO,IAAI,iBAAiB,OAAO,IAAI;AAEvE,MAAa,WAAW,MAAoB,UAC1C,OAAO,IAAI,MAAM,OAAO,KAAK;AAE/B,MAAa,cAAc,UACzB,MAAM,QAAQ,KAAK,IAAI,CAAC,GAAG,KAAK,IAAI;AAEtC,MAAa,aAAa,MAAmB,UAC3C,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,KAAK,IACtC,KAAK,WAAW,MAAM,UAAU,KAAK,OAAO,OAAO,UAAU,UAAU,MAAM,MAAM,IACnF,SAAS;AAEf,SAAgB,YAAY,QAAgD;CAC1E,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH,KAAK,EAAE,GAAG,MAAM,IAAI;EACpB,OAAO,WAAW,MAAM,KAAK;EAC7B,cAAc,WAAW,MAAM,YAAY;EAC3C,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ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AAO;GAAE,QAAQ;GAAY;GAAS;GAAa;GAAW;EAAY;CAC5E;CAEA,OACE,WACA,aACA,OACkB;EAClB,OAAO;GAAE,QAAQ;GAAU,SAAS,CAAC;GAAG,aAAa,CAAC;GAAG;GAAW;GAAa;EAAM;CACzF;;CAGA,SACE,aACA,WACA,aACkB;EAClB,OAAO;GAAE,QAAQ;GAAY,SAAS,CAAC;GAAG;GAAa;GAAW;EAAY;CAChF;AACF;AAEA,SAAgB,8BACd,SACyB;CACzB,OAAO,IAAI,wBAAwB,OAAO;AAC5C"}
@@ -1,12 +1,12 @@
1
- import { I as FormSetValueResult, Q as Box, a as FormCommitResult, i as FormCapability, tt as ShownWidget } from "./contract-D_9fiTkd.js";
1
+ import { I as FormSetValueResult, Q as Box, a as FormCommitResult, i as FormCapability, tt as ShownWidget } from "./contract-Djti7ew8.cjs";
2
2
  import "@embedpdf/core";
3
+ import { AnnotationRef, FormEffect, FormField, FormFieldRef, PageRef, PdfActionTargetRef, WidgetAnnotation } from "@embedpdf/engine-core/runtime";
3
4
  import { ActionContext, ActionDiagnostic, ActionOrigin, ActionSubmitRequest, PdfAnnotationEventKind, SubmitIntent } from "@embedpdf/plugin-actions/contract";
4
- import { FontCss } from "@embedpdf/plugin-fonts/contract";
5
- import { AnnotationRef, FormEffect, FormFieldDTO, FormFieldRef, PageRef, PdfActionTargetRef, WidgetAnnotation } from "@embedpdf/engine-core/runtime";
6
- import { FormCommitSinkResult } from "@embedpdf/plugin-actions/contract/host";
7
- import { SceneNode } from "@embedpdf/core-annotation";
8
5
  import { TextEditorLayout, TextEditorLayout as TextEditorLayout$1 } from "@embedpdf/core-form";
6
+ import { FormCommitSinkResult } from "@embedpdf/plugin-actions/contract/host";
7
+ import { FontCss } from "@embedpdf/plugin-fonts/contract";
9
8
  import { AppearancePicture } from "@embedpdf/plugin-render/contract/host";
9
+ import { SceneNode } from "@embedpdf/core-annotation";
10
10
  //#region src/services/looks.d.ts
11
11
  /** A widget as the painter draws it: its scene on the page (its text carries the faces it needs). */
12
12
  interface WidgetPainting {
@@ -116,4 +116,4 @@ interface FormHostCapability extends FormCapability {
116
116
  declare const FormToken: import("@embedpdf/core").CapabilityToken<FormHostCapability>;
117
117
  //#endregion
118
118
  export { WidgetPainting as a, TextEditorLayout$1 as i, FormHostCapability as n, FormToken as r, FormFocusTarget as t };
119
- //# sourceMappingURL=host-contract-DdOsYM83.d.ts.map
119
+ //# sourceMappingURL=host-contract-DO9xsBoD.d.cts.map
@@ -1,12 +1,12 @@
1
- import { I as FormSetValueResult, Q as Box, a as FormCommitResult, i as FormCapability, tt as ShownWidget } from "./contract-c_wuhKk1.cjs";
1
+ import { I as FormSetValueResult, Q as Box, a as FormCommitResult, i as FormCapability, tt as ShownWidget } from "./contract-6YEsObRl.js";
2
2
  import "@embedpdf/core";
3
- import { AnnotationRef, FormEffect, FormFieldDTO, FormFieldRef, PageRef, PdfActionTargetRef, WidgetAnnotation } from "@embedpdf/engine-core/runtime";
4
3
  import { ActionContext, ActionDiagnostic, ActionOrigin, ActionSubmitRequest, PdfAnnotationEventKind, SubmitIntent } from "@embedpdf/plugin-actions/contract";
5
- import { TextEditorLayout, TextEditorLayout as TextEditorLayout$1 } from "@embedpdf/core-form";
6
- import { FormCommitSinkResult } from "@embedpdf/plugin-actions/contract/host";
7
4
  import { FontCss } from "@embedpdf/plugin-fonts/contract";
8
- import { AppearancePicture } from "@embedpdf/plugin-render/contract/host";
5
+ import { AnnotationRef, FormEffect, FormField, FormFieldRef, PageRef, PdfActionTargetRef, WidgetAnnotation } from "@embedpdf/engine-core/runtime";
6
+ import { FormCommitSinkResult } from "@embedpdf/plugin-actions/contract/host";
9
7
  import { SceneNode } from "@embedpdf/core-annotation";
8
+ import { TextEditorLayout, TextEditorLayout as TextEditorLayout$1 } from "@embedpdf/core-form";
9
+ import { AppearancePicture } from "@embedpdf/plugin-render/contract/host";
10
10
  //#region src/services/looks.d.ts
11
11
  /** A widget as the painter draws it: its scene on the page (its text carries the faces it needs). */
12
12
  interface WidgetPainting {
@@ -116,4 +116,4 @@ interface FormHostCapability extends FormCapability {
116
116
  declare const FormToken: import("@embedpdf/core").CapabilityToken<FormHostCapability>;
117
117
  //#endregion
118
118
  export { WidgetPainting as a, TextEditorLayout$1 as i, FormHostCapability as n, FormToken as r, FormFocusTarget as t };
119
- //# sourceMappingURL=host-contract-DaauiYfw.d.cts.map
119
+ //# sourceMappingURL=host-contract-XqkfFuoy.d.ts.map