@embedpdf/plugin-form 3.0.0-next.11 → 3.0.0-next.13

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,2 +1,2 @@
1
- import { a as FormHostCapability, l as FormToken } from "../types-Blr4QQM5.cjs";
1
+ import { a as FormHostCapability, c as FormToken } from "../types-Bpc32Qmx.cjs";
2
2
  export { type FormHostCapability, FormToken };
@@ -1,2 +1,2 @@
1
- import { a as FormHostCapability, l as FormToken } from "../types-BlXdnNRf.js";
1
+ import { a as FormHostCapability, c as FormToken } from "../types-DRirhZKr.js";
2
2
  export { type FormHostCapability, FormToken };
@@ -1 +1 @@
1
- {"version":3,"file":"contract.cjs","names":["FormHostToken"],"sources":["../src/contract.ts"],"sourcesContent":["/** Public form capability protocol without the form engine implementation. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { FormToken as FormHostToken } from './types';\nimport type { FormCapability } from './types';\n\nexport const FormToken = FormHostToken as unknown as CapabilityToken<FormCapability>;\nexport type {\n Box,\n FieldKey,\n FillItem,\n FormAction,\n FormCapability,\n FormCommitResult,\n FormCommitStatus,\n FormPluginOptions,\n FormScriptingOptions,\n FormState,\n FormUiEffect,\n PlacedField,\n PlaceFieldInput,\n WidgetActivationResult,\n} from './types';\nexport type { FormFieldDTO, FormFieldPatch, WidgetAppearance } from '@embedpdf/engine-core/runtime';\n"],"mappings":";;AAMA,MAAa,0CAAYA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"contract.cjs","names":["FormHostToken"],"sources":["../src/contract.ts"],"sourcesContent":["/** Public form capability protocol without the form engine implementation. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { FormToken as FormHostToken } from './types';\nimport type { FormCapability } from './types';\n\nexport const FormToken = FormHostToken as unknown as CapabilityToken<FormCapability>;\nexport type {\n Box,\n FieldKey,\n FillItem,\n FormAction,\n FormCapability,\n FormCommitResult,\n FormCommitStatus,\n FormPluginOptions,\n FormState,\n FormUiEffect,\n PlacedField,\n PlaceFieldInput,\n WidgetActivationResult,\n WidgetHit,\n} from './types';\nexport type {\n FormFieldDTO,\n FormFieldPatch,\n FormFieldRef,\n WidgetAppearance,\n} from '@embedpdf/engine-core/runtime';\n"],"mappings":";;AAMA,MAAa,0CAAYA,CAAAA,CAAAA"}
@@ -1,8 +1,8 @@
1
- import { c as FormState, d as PlaceFieldInput, f as PlacedField, g as FieldKey, h as Box, i as FormCommitStatus, m as FillItem, n as FormCapability, o as FormPluginOptions, p as WidgetActivationResult, r as FormCommitResult, s as FormScriptingOptions, t as FormAction, u as FormUiEffect } from "./types-Blr4QQM5.cjs";
1
+ import { _ as FillItem, b as WidgetHit, d as PlacedField, f as WidgetActivationResult, i as FormCommitStatus, l as FormUiEffect, n as FormCapability, o as FormPluginOptions, r as FormCommitResult, s as FormState, t as FormAction, u as PlaceFieldInput, v as Box, y as FieldKey } from "./types-Bpc32Qmx.cjs";
2
2
  import { CapabilityToken } from "@embedpdf/core";
3
- import { FormFieldDTO, FormFieldPatch, WidgetAppearance } from "@embedpdf/engine-core/runtime";
3
+ import { FormFieldDTO, FormFieldPatch, FormFieldRef, WidgetAppearance } from "@embedpdf/engine-core/runtime";
4
4
  //#region src/contract.d.ts
5
5
  declare const FormToken: CapabilityToken<FormCapability>;
6
6
  //#endregion
7
- export { type Box, type FieldKey, type FillItem, type FormAction, type FormCapability, type FormCommitResult, type FormCommitStatus, type FormFieldDTO, type FormFieldPatch, type FormPluginOptions, type FormScriptingOptions, type FormState, FormToken, type FormUiEffect, type PlaceFieldInput, type PlacedField, type WidgetActivationResult, type WidgetAppearance };
7
+ export { type Box, type FieldKey, type FillItem, type FormAction, type FormCapability, type FormCommitResult, type FormCommitStatus, type FormFieldDTO, type FormFieldPatch, type FormFieldRef, type FormPluginOptions, type FormState, FormToken, type FormUiEffect, type PlaceFieldInput, type PlacedField, type WidgetActivationResult, type WidgetAppearance, type WidgetHit };
8
8
  //# sourceMappingURL=contract.d.cts.map
@@ -1,8 +1,8 @@
1
- import { c as FormState, d as PlaceFieldInput, f as PlacedField, g as FieldKey, h as Box, i as FormCommitStatus, m as FillItem, n as FormCapability, o as FormPluginOptions, p as WidgetActivationResult, r as FormCommitResult, s as FormScriptingOptions, t as FormAction, u as FormUiEffect } from "./types-BlXdnNRf.js";
1
+ import { _ as FillItem, b as WidgetHit, d as PlacedField, f as WidgetActivationResult, i as FormCommitStatus, l as FormUiEffect, n as FormCapability, o as FormPluginOptions, r as FormCommitResult, s as FormState, t as FormAction, u as PlaceFieldInput, v as Box, y as FieldKey } from "./types-DRirhZKr.js";
2
2
  import { CapabilityToken } from "@embedpdf/core";
3
- import { FormFieldDTO, FormFieldPatch, WidgetAppearance } from "@embedpdf/engine-core/runtime";
3
+ import { FormFieldDTO, FormFieldPatch, FormFieldRef, WidgetAppearance } from "@embedpdf/engine-core/runtime";
4
4
  //#region src/contract.d.ts
5
5
  declare const FormToken: CapabilityToken<FormCapability>;
6
6
  //#endregion
7
- export { type Box, type FieldKey, type FillItem, type FormAction, type FormCapability, type FormCommitResult, type FormCommitStatus, type FormFieldDTO, type FormFieldPatch, type FormPluginOptions, type FormScriptingOptions, type FormState, FormToken, type FormUiEffect, type PlaceFieldInput, type PlacedField, type WidgetActivationResult, type WidgetAppearance };
7
+ export { type Box, type FieldKey, type FillItem, type FormAction, type FormCapability, type FormCommitResult, type FormCommitStatus, type FormFieldDTO, type FormFieldPatch, type FormFieldRef, type FormPluginOptions, type FormState, FormToken, type FormUiEffect, type PlaceFieldInput, type PlacedField, type WidgetActivationResult, type WidgetAppearance, type WidgetHit };
8
8
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","names":["FormHostToken"],"sources":["../src/contract.ts"],"sourcesContent":["/** Public form capability protocol without the form engine implementation. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { FormToken as FormHostToken } from './types';\nimport type { FormCapability } from './types';\n\nexport const FormToken = FormHostToken as unknown as CapabilityToken<FormCapability>;\nexport type {\n Box,\n FieldKey,\n FillItem,\n FormAction,\n FormCapability,\n FormCommitResult,\n FormCommitStatus,\n FormPluginOptions,\n FormScriptingOptions,\n FormState,\n FormUiEffect,\n PlacedField,\n PlaceFieldInput,\n WidgetActivationResult,\n} from './types';\nexport type { FormFieldDTO, FormFieldPatch, WidgetAppearance } from '@embedpdf/engine-core/runtime';\n"],"mappings":";;AAMA,MAAa,YAAYA"}
1
+ {"version":3,"file":"contract.js","names":["FormHostToken"],"sources":["../src/contract.ts"],"sourcesContent":["/** Public form capability protocol without the form engine implementation. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { FormToken as FormHostToken } from './types';\nimport type { FormCapability } from './types';\n\nexport const FormToken = FormHostToken as unknown as CapabilityToken<FormCapability>;\nexport type {\n Box,\n FieldKey,\n FillItem,\n FormAction,\n FormCapability,\n FormCommitResult,\n FormCommitStatus,\n FormPluginOptions,\n FormState,\n FormUiEffect,\n PlacedField,\n PlaceFieldInput,\n WidgetActivationResult,\n WidgetHit,\n} from './types';\nexport type {\n FormFieldDTO,\n FormFieldPatch,\n FormFieldRef,\n WidgetAppearance,\n} from '@embedpdf/engine-core/runtime';\n"],"mappings":";;AAMA,MAAa,YAAYA"}
package/dist/index.cjs CHANGED
@@ -198,6 +198,29 @@ const fieldForWidget = (model, annotObjectNumber) => {
198
198
  const i = model.byWidget[annotObjectNumber];
199
199
  return i === void 0 ? null : model.snapshot?.fields[i] ?? null;
200
200
  };
201
+ const contains = (b, p) => p.x >= b.x && p.x <= b.x + b.width && p.y >= b.y && p.y <= b.y + b.height;
202
+ /**
203
+ * The widget under a content-space point, from the model's loaded geometry
204
+ * for that page (null when the page's geometry has not arrived, or nothing
205
+ * is there). Nested widgets resolve to the smallest containing box.
206
+ */
207
+ const widgetAt = (model, pageObjectNumber, point) => {
208
+ const geom = model.geom[pageObjectNumber];
209
+ if (!geom) return null;
210
+ let best = null;
211
+ for (const [key, box] of Object.entries(geom)) {
212
+ if (!contains(box, point)) continue;
213
+ const annotObjectNumber = Number(key);
214
+ const field = fieldForWidget(model, annotObjectNumber);
215
+ if (!field) continue;
216
+ if (!best || box.width * box.height < best.box.width * best.box.height) best = {
217
+ annotObjectNumber,
218
+ field,
219
+ box
220
+ };
221
+ }
222
+ return best;
223
+ };
201
224
  //#endregion
202
225
  //#region src/core/fill-items.ts
203
226
  const ZERO_BOX = {
@@ -211,7 +234,7 @@ const ZERO_BOX = {
211
234
  * caller: the page projection reads the model's widget geometry; a consumer
212
235
  * that already owns a live box (the annotation plane's RenderItem) passes it —
213
236
  * or nothing, when only the semantics matter. Null for families with no fill
214
- * control (signature/unknown: rendered by the annotation plane only).
237
+ * control (unknown: rendered by the annotation plane only).
215
238
  */
216
239
  function projectWidget(model, field, annotObjectNumber, box = ZERO_BOX) {
217
240
  const key = fieldKeyOf(field);
@@ -274,6 +297,11 @@ function projectWidget(model, field, annotObjectNumber, box = ZERO_BOX) {
274
297
  ...base,
275
298
  control: "button"
276
299
  };
300
+ case "signature": return {
301
+ ...base,
302
+ control: "signature",
303
+ signed: field.valueEntry.kind !== "none"
304
+ };
277
305
  default: return null;
278
306
  }
279
307
  }
@@ -355,28 +383,21 @@ function createFormCapability(ctx, options = {}) {
355
383
  };
356
384
  const enqueueMutation = createSerialMutationQueue();
357
385
  const actionsHost = ctx.tryGet(_embedpdf_plugin_actions_contract_host.ActionsToken);
358
- const scriptPort = actionsHost?.scriptTransaction?.bind(actionsHost) ?? null;
359
- const scripting = scriptPort && ctx.doc ? require_scripting.createFormScriptingController({
386
+ const realm = actionsHost?.scriptRealm ?? null;
387
+ const scripting = realm && ctx.doc ? require_scripting.createFormScriptingController({
360
388
  doc: ctx.doc,
361
389
  document: () => ctx.document(),
362
- transaction: scriptPort
390
+ transaction: realm.transaction.bind(realm),
391
+ budget: realm.budget
363
392
  }) : null;
364
393
  if (scripting) ctx.cleanup(() => scripting.dispose());
365
394
  /** Every script surface (UI effects, diagnostics, errors) flows through
366
395
  * the actions plugin's ONE port — origin/phase attached (D9). */
367
396
  const surfaceViaActions = (result, origin) => {
368
- if (!actionsHost) return;
369
- for (const phase of ["boot", "user"]) {
370
- const uiEffects = result.uiEffects.filter((effect) => effect.phase === phase);
371
- if (uiEffects.length === 0 && phase === "boot") continue;
372
- actionsHost.surfaceScriptResult({
373
- uiEffects,
374
- diagnostics: phase === "user" ? result.diagnostics : [],
375
- ...phase === "user" && result.error ? { error: result.error } : {},
376
- origin,
377
- phase
378
- });
379
- }
397
+ actionsHost?.surfaceScriptCommit(result, {
398
+ origin,
399
+ realm: "document"
400
+ });
380
401
  };
381
402
  const can = (cap) => ctx.doc?.security.allows(cap) ?? false;
382
403
  let refreshPromise = null;
@@ -421,6 +442,26 @@ function createFormCapability(ctx, options = {}) {
421
442
  geomLoading.delete(pon);
422
443
  });
423
444
  };
445
+ const widgetAt$1 = (pon, point) => {
446
+ const m = model();
447
+ ensureGeom(pon);
448
+ if (m.geom[pon]) return widgetAt(m, pon, point);
449
+ if (!annotationHost) return null;
450
+ let best = null;
451
+ for (const item of annotationHost.pageItems(pon)) {
452
+ if (!item.subtype.startsWith("widget") || item.ref?.kind !== "objectNumber") continue;
453
+ const box = item.box;
454
+ if (!(point.x >= box.x && point.x <= box.x + box.width && point.y >= box.y && point.y <= box.y + box.height)) continue;
455
+ const field = fieldForWidget(m, item.ref.annotObjectNumber);
456
+ if (!field) continue;
457
+ if (!best || box.width * box.height < best.box.width * best.box.height) best = {
458
+ annotObjectNumber: item.ref.annotObjectNumber,
459
+ field,
460
+ box
461
+ };
462
+ }
463
+ return best;
464
+ };
424
465
  const fuseFill = (item, fillable) => item === null || fillable || item.disabled ? item : {
425
466
  ...item,
426
467
  disabled: true
@@ -769,6 +810,7 @@ function createFormCapability(ctx, options = {}) {
769
810
  ensureGeom,
770
811
  field: (key) => fieldByKey(model(), key),
771
812
  fieldForWidget: (annotObjectNumber) => fieldForWidget(model(), annotObjectNumber),
813
+ widgetAt: widgetAt$1,
772
814
  setText: (key, value) => write(key, {
773
815
  type: "text",
774
816
  value
@@ -987,6 +1029,10 @@ function registerFormEffects(ctx) {
987
1029
  refresh();
988
1030
  return;
989
1031
  }
1032
+ if (event.type === "document.versioned" || event.type === "signature.completed") {
1033
+ refresh();
1034
+ return;
1035
+ }
990
1036
  if (!event.type.startsWith("form.") || !("origin" in event)) return;
991
1037
  const structural = STRUCTURAL.has(event.type);
992
1038
  if (event.origin.kind !== "remote" && !structural) return;
@@ -1071,6 +1117,17 @@ const FORM_TOOLS = [
1071
1117
  fontSize: 12
1072
1118
  },
1073
1119
  cursor: "crosshair"
1120
+ },
1121
+ {
1122
+ id: "form-signature",
1123
+ family: "signature",
1124
+ visualKind: "widget-box",
1125
+ clickCreate: {
1126
+ width: 160,
1127
+ height: 48
1128
+ },
1129
+ defaults: FIELD_CHROME,
1130
+ cursor: "crosshair"
1074
1131
  }
1075
1132
  ];
1076
1133
  const FORM_TOOL_BY_ID = new Map(FORM_TOOLS.map((t) => [t.id, t]));