@embedpdf/models 2.9.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pdf.d.ts CHANGED
@@ -1187,9 +1187,21 @@ export declare enum PDF_FORM_FIELD_FLAG {
1187
1187
  NOEXPORT = 4,
1188
1188
  TEXT_MULTIPLINE = 4096,
1189
1189
  TEXT_PASSWORD = 8192,
1190
+ TEXT_FILESELECT = 1048576,
1191
+ TEXT_DONOTSPELLCHECK = 4194304,
1192
+ TEXT_DONOTSCROLL = 8388608,
1193
+ TEXT_COMB = 16777216,
1194
+ TEXT_RICHTEXT = 33554432,
1195
+ BUTTON_NOTOGGLETOOFF = 16384,
1196
+ BUTTON_RADIO = 32768,
1197
+ BUTTON_PUSHBUTTON = 65536,
1198
+ BUTTON_RADIOSINUNISON = 33554432,
1190
1199
  CHOICE_COMBO = 131072,
1191
1200
  CHOICE_EDIT = 262144,
1192
- CHOICE_MULTL_SELECT = 2097152
1201
+ CHOICE_SORT = 524288,
1202
+ CHOICE_MULTL_SELECT = 2097152,
1203
+ CHOICE_DONOTSPELLCHECK = 4194304,
1204
+ CHOICE_COMMITONSELCHANGE = 67108864
1193
1205
  }
1194
1206
  /**
1195
1207
  * Type of pdf object
@@ -1245,53 +1257,207 @@ export declare function flagsToNames(raw: number): PdfAnnotationFlagName[];
1245
1257
  */
1246
1258
  export declare function namesToFlags(names: readonly PdfAnnotationFlagName[]): PdfAnnotationFlags;
1247
1259
  /**
1248
- * Field of PDF widget annotation
1260
+ * Shared properties across all widget annotation field types
1249
1261
  *
1250
1262
  * @public
1251
1263
  */
1252
- export interface PdfWidgetAnnoField {
1264
+ export interface PdfWidgetAnnoFieldBase {
1265
+ flag: PDF_FORM_FIELD_FLAG;
1266
+ name: string;
1267
+ alternateName: string;
1268
+ value: string;
1269
+ fieldObjectId?: number;
1270
+ }
1271
+ /**
1272
+ * @public
1273
+ */
1274
+ export interface PdfTextWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1275
+ type: PDF_FORM_FIELD_TYPE.TEXTFIELD;
1276
+ maxLen?: number;
1277
+ }
1278
+ /**
1279
+ * @public
1280
+ */
1281
+ export interface PdfCheckboxWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1282
+ type: PDF_FORM_FIELD_TYPE.CHECKBOX;
1283
+ }
1284
+ /**
1285
+ * @public
1286
+ */
1287
+ export interface PdfRadioButtonWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1288
+ type: PDF_FORM_FIELD_TYPE.RADIOBUTTON;
1289
+ options: PdfWidgetAnnoOption[];
1290
+ }
1291
+ /**
1292
+ * @public
1293
+ */
1294
+ export interface PdfComboboxWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1295
+ type: PDF_FORM_FIELD_TYPE.COMBOBOX;
1296
+ options: PdfWidgetAnnoOption[];
1297
+ }
1298
+ /**
1299
+ * @public
1300
+ */
1301
+ export interface PdfListboxWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1302
+ type: PDF_FORM_FIELD_TYPE.LISTBOX;
1303
+ options: PdfWidgetAnnoOption[];
1304
+ }
1305
+ /**
1306
+ * @public
1307
+ */
1308
+ export interface PdfPushButtonWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1309
+ type: PDF_FORM_FIELD_TYPE.PUSHBUTTON;
1310
+ }
1311
+ /**
1312
+ * @public
1313
+ */
1314
+ export interface PdfSignatureWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1315
+ type: PDF_FORM_FIELD_TYPE.SIGNATURE;
1316
+ }
1317
+ /**
1318
+ * @public
1319
+ */
1320
+ export interface PdfUnknownWidgetAnnoField extends PdfWidgetAnnoFieldBase {
1321
+ type: PDF_FORM_FIELD_TYPE.UNKNOWN | PDF_FORM_FIELD_TYPE.XFA | PDF_FORM_FIELD_TYPE.XFA_CHECKBOX | PDF_FORM_FIELD_TYPE.XFA_COMBOBOX | PDF_FORM_FIELD_TYPE.XFA_IMAGEFIELD | PDF_FORM_FIELD_TYPE.XFA_LISTBOX | PDF_FORM_FIELD_TYPE.XFA_PUSHBUTTON | PDF_FORM_FIELD_TYPE.XFA_SIGNATURE | PDF_FORM_FIELD_TYPE.XFA_TEXTFIELD;
1322
+ }
1323
+ /**
1324
+ * Discriminated union of all widget annotation field types
1325
+ *
1326
+ * @public
1327
+ */
1328
+ export type PdfWidgetAnnoField = PdfTextWidgetAnnoField | PdfCheckboxWidgetAnnoField | PdfRadioButtonWidgetAnnoField | PdfComboboxWidgetAnnoField | PdfListboxWidgetAnnoField | PdfPushButtonWidgetAnnoField | PdfSignatureWidgetAnnoField | PdfUnknownWidgetAnnoField;
1329
+ /**
1330
+ * PDF widget object
1331
+ *
1332
+ * @public
1333
+ */
1334
+ export interface PdfWidgetAnnoObject extends PdfAnnotationObjectBase {
1335
+ /** {@inheritDoc PdfAnnotationObjectBase.type} */
1336
+ type: PdfAnnotationSubtype.WIDGET;
1253
1337
  /**
1254
- * flag of field
1338
+ * Field of pdf widget object
1255
1339
  */
1256
- flag: PDF_FORM_FIELD_FLAG;
1340
+ field: PdfWidgetAnnoField;
1257
1341
  /**
1258
- * name of field
1342
+ * The non-"Off" appearance state key from the widget's /AP/N dictionary.
1343
+ * For checkboxes this is typically "Yes"; for radio buttons it is a unique
1344
+ * identifier (usually the widget's NM). Checked state is derived:
1345
+ * `field.value === exportValue`.
1259
1346
  */
1260
- name: string;
1347
+ exportValue?: string;
1261
1348
  /**
1262
- * alternate name of field
1349
+ * font family of pdf widget object
1263
1350
  */
1264
- alternateName: string;
1351
+ fontFamily: PdfStandardFont;
1265
1352
  /**
1266
- * type of field
1353
+ * font size of pdf widget object
1267
1354
  */
1268
- type: PDF_FORM_FIELD_TYPE;
1355
+ fontSize: number;
1269
1356
  /**
1270
- * value of field
1357
+ * font color of pdf widget object
1271
1358
  */
1272
- value: string;
1359
+ fontColor: string;
1273
1360
  /**
1274
- * whether field is checked
1361
+ * MK border color (BC) as web hex string, e.g. '#FF0000'
1275
1362
  */
1276
- isChecked: boolean;
1363
+ strokeColor?: string;
1277
1364
  /**
1278
- * options of field
1365
+ * MK background color (BG) as web hex string, e.g. '#FFFFFF'
1279
1366
  */
1280
- options: PdfWidgetAnnoOption[];
1367
+ color?: string;
1368
+ /**
1369
+ * Border width in points (BS width)
1370
+ */
1371
+ strokeWidth?: number;
1281
1372
  }
1282
1373
  /**
1283
- * PDF widget object
1374
+ * Returns whether a toggle widget (checkbox / radio button) is currently
1375
+ * in its "on" state by comparing the shared field value against this
1376
+ * widget's unique export value from the /AP/N dictionary.
1284
1377
  *
1285
1378
  * @public
1286
1379
  */
1287
- export interface PdfWidgetAnnoObject extends PdfAnnotationObjectBase {
1288
- /** {@inheritDoc PdfAnnotationObjectBase.type} */
1289
- type: PdfAnnotationSubtype.WIDGET;
1380
+ export declare function isWidgetChecked(widget: PdfWidgetAnnoObject): boolean;
1381
+ /**
1382
+ * Widget additional-action event types exposed by PDFium.
1383
+ *
1384
+ * @public
1385
+ */
1386
+ export declare enum PDF_ANNOT_AACTION_EVENT {
1387
+ KEY_STROKE = 12,
1388
+ FORMAT = 13,
1389
+ VALIDATE = 14,
1390
+ CALCULATE = 15
1391
+ }
1392
+ /**
1393
+ * Normalized widget JavaScript trigger names.
1394
+ *
1395
+ * @public
1396
+ */
1397
+ export declare enum PdfJavaScriptWidgetEventType {
1398
+ Keystroke = "keystroke",
1399
+ Format = "format",
1400
+ Validate = "validate",
1401
+ Calculate = "calculate"
1402
+ }
1403
+ /**
1404
+ * Normalized JavaScript action trigger names.
1405
+ *
1406
+ * @public
1407
+ */
1408
+ export declare enum PdfJavaScriptActionTrigger {
1409
+ DocumentNamed = "document_named",
1410
+ WidgetKeystroke = "widget_keystroke",
1411
+ WidgetFormat = "widget_format",
1412
+ WidgetValidate = "widget_validate",
1413
+ WidgetCalculate = "widget_calculate"
1414
+ }
1415
+ /**
1416
+ * Base shape shared by extracted PDF JavaScript actions.
1417
+ *
1418
+ * @public
1419
+ */
1420
+ export interface PdfJavaScriptActionObjectBase {
1290
1421
  /**
1291
- * Field of pdf widget object
1422
+ * Stable identifier for the extracted action within the current document snapshot.
1292
1423
  */
1293
- field: PdfWidgetAnnoField;
1424
+ id: string;
1425
+ /**
1426
+ * Normalized trigger classification used by higher layers.
1427
+ */
1428
+ trigger: PdfJavaScriptActionTrigger;
1429
+ /**
1430
+ * Raw JavaScript source extracted from the PDF.
1431
+ */
1432
+ script: string;
1433
+ }
1434
+ /**
1435
+ * A named document-level JavaScript action from the document JavaScript name tree.
1436
+ *
1437
+ * @public
1438
+ */
1439
+ export interface PdfDocumentJavaScriptActionObject extends PdfJavaScriptActionObjectBase {
1440
+ trigger: PdfJavaScriptActionTrigger.DocumentNamed;
1441
+ name: string;
1294
1442
  }
1443
+ /**
1444
+ * A widget-level JavaScript additional action.
1445
+ *
1446
+ * @public
1447
+ */
1448
+ export interface PdfWidgetJavaScriptActionObject extends PdfJavaScriptActionObjectBase {
1449
+ trigger: PdfJavaScriptActionTrigger.WidgetKeystroke | PdfJavaScriptActionTrigger.WidgetFormat | PdfJavaScriptActionTrigger.WidgetValidate | PdfJavaScriptActionTrigger.WidgetCalculate;
1450
+ eventType: PdfJavaScriptWidgetEventType;
1451
+ pageIndex: number;
1452
+ annotationId: string;
1453
+ fieldName: string;
1454
+ }
1455
+ /**
1456
+ * Discriminated union of supported extracted PDF JavaScript actions.
1457
+ *
1458
+ * @public
1459
+ */
1460
+ export type PdfJavaScriptActionObject = PdfDocumentJavaScriptActionObject | PdfWidgetJavaScriptActionObject;
1295
1461
  /**
1296
1462
  * Pdf file attachments annotation
1297
1463
  *
@@ -1967,6 +2133,14 @@ export interface PdfUnsupportedAnnoObject extends PdfAnnotationObjectBase {
1967
2133
  * @public
1968
2134
  */
1969
2135
  export type PdfAnnotationObject = PdfSupportedAnnoObject | PdfUnsupportedAnnoObject;
2136
+ /**
2137
+ * Extracts the concrete annotation object type for a specific subtype.
2138
+ *
2139
+ * @public
2140
+ */
2141
+ export type PdfAnnotationOf<S extends PdfAnnotationSubtype> = Extract<PdfAnnotationObject, {
2142
+ type: S;
2143
+ }>;
1970
2144
  /**
1971
2145
  * Pdf attachment
1972
2146
  *
@@ -2345,7 +2519,7 @@ export type FormFieldValue = {
2345
2519
  isSelected: boolean;
2346
2520
  } | {
2347
2521
  kind: 'checked';
2348
- isChecked: boolean;
2522
+ checked: boolean;
2349
2523
  };
2350
2524
  /**
2351
2525
  * Transformation that will be applied to annotation
@@ -2867,6 +3041,34 @@ export interface PdfEngine<T = Blob> {
2867
3041
  * @returns task contains the annotations or error
2868
3042
  */
2869
3043
  getPageAnnotations: (doc: PdfDocumentObject, page: PdfPageObject) => PdfTask<PdfAnnotationObject[]>;
3044
+ /**
3045
+ * Extract named document JavaScript actions without executing them.
3046
+ * @param doc - pdf document
3047
+ * @returns task that contains all named document JavaScript actions
3048
+ */
3049
+ getDocumentJavaScriptActions: (doc: PdfDocumentObject) => PdfTask<PdfDocumentJavaScriptActionObject[]>;
3050
+ /**
3051
+ * Get form fields of pdf page
3052
+ * @param doc - pdf document
3053
+ * @param page - pdf page
3054
+ * @returns task contains the form fields or error
3055
+ */
3056
+ getPageAnnoWidgets: (doc: PdfDocumentObject, page: PdfPageObject) => PdfTask<PdfWidgetAnnoObject[]>;
3057
+ /**
3058
+ * Extract widget additional JavaScript actions for a page without executing them.
3059
+ * @param doc - pdf document
3060
+ * @param page - pdf page
3061
+ * @returns task containing page widget JavaScript actions
3062
+ */
3063
+ getPageWidgetJavaScriptActions: (doc: PdfDocumentObject, page: PdfPageObject) => PdfTask<PdfWidgetJavaScriptActionObject[]>;
3064
+ /**
3065
+ * Regenerate appearance streams for specific widget annotations on a page.
3066
+ * @param doc - pdf document
3067
+ * @param page - pdf page
3068
+ * @param annotationIds - NM values of the annotations to regenerate
3069
+ * @returns task indicating whether any appearances were regenerated
3070
+ */
3071
+ regenerateWidgetAppearances: (doc: PdfDocumentObject, page: PdfPageObject, annotationIds: string[]) => PdfTask<boolean>;
2870
3072
  /**
2871
3073
  * Create a annotation on specified page
2872
3074
  * @param doc - pdf document
@@ -2953,6 +3155,35 @@ export interface PdfEngine<T = Blob> {
2953
3155
  * @param text - text value
2954
3156
  */
2955
3157
  setFormFieldValue: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, value: FormFieldValue) => PdfTask<boolean>;
3158
+ /**
3159
+ * Restore a widget annotation to the full field state described by `field`.
3160
+ * Unlike `setFormFieldValue`, this accepts a complete `PdfWidgetAnnoField`
3161
+ * snapshot and applies all writable state in a single call.
3162
+ * @param doc - pdf document
3163
+ * @param page - pdf page
3164
+ * @param annotation - pdf widget annotation
3165
+ * @param field - the desired field state to apply
3166
+ */
3167
+ setFormFieldState: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, field: PdfWidgetAnnoField) => PdfTask<boolean>;
3168
+ /**
3169
+ * Rename the logical form field associated with a widget annotation.
3170
+ * This updates the field dictionary rather than patching only a single widget snapshot.
3171
+ * @param doc - pdf document
3172
+ * @param page - pdf page containing the widget annotation
3173
+ * @param annotation - pdf widget annotation
3174
+ * @param name - the desired partial field name (/T)
3175
+ */
3176
+ renameWidgetField: (doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, name: string) => PdfTask<boolean>;
3177
+ /**
3178
+ * Attach the source widget's logical field to the target widget's logical field.
3179
+ * This is a structural field operation and may merge multiple widget kids under one parent.
3180
+ * @param doc - pdf document
3181
+ * @param sourcePage - page containing the source widget annotation
3182
+ * @param sourceAnnotation - widget whose field should be shared into the target field
3183
+ * @param targetPage - page containing the target widget annotation
3184
+ * @param targetAnnotation - widget whose logical field should be reused
3185
+ */
3186
+ shareWidgetField: (doc: PdfDocumentObject, sourcePage: PdfPageObject, sourceAnnotation: PdfWidgetAnnoObject, targetPage: PdfPageObject, targetAnnotation: PdfWidgetAnnoObject) => PdfTask<boolean>;
2956
3187
  /**
2957
3188
  * Flatten annotations and form fields into the page contents.
2958
3189
  * @param doc - pdf document
@@ -3171,7 +3402,14 @@ export interface IPdfiumExecutor {
3171
3402
  addAttachment(doc: PdfDocumentObject, params: PdfAddAttachmentParams): PdfTask<boolean>;
3172
3403
  removeAttachment(doc: PdfDocumentObject, attachment: PdfAttachmentObject): PdfTask<boolean>;
3173
3404
  readAttachmentContent(doc: PdfDocumentObject, attachment: PdfAttachmentObject): PdfTask<ArrayBuffer>;
3405
+ getDocumentJavaScriptActions(doc: PdfDocumentObject): PdfTask<PdfDocumentJavaScriptActionObject[]>;
3406
+ getPageAnnoWidgets(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfWidgetAnnoObject[]>;
3407
+ getPageWidgetJavaScriptActions(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfWidgetJavaScriptActionObject[]>;
3408
+ regenerateWidgetAppearances(doc: PdfDocumentObject, page: PdfPageObject, annotationIds: string[]): PdfTask<boolean>;
3174
3409
  setFormFieldValue(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, value: FormFieldValue): PdfTask<boolean>;
3410
+ setFormFieldState(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, field: PdfWidgetAnnoField): PdfTask<boolean>;
3411
+ renameWidgetField(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, name: string): PdfTask<boolean>;
3412
+ shareWidgetField(doc: PdfDocumentObject, sourcePage: PdfPageObject, sourceAnnotation: PdfWidgetAnnoObject, targetPage: PdfPageObject, targetAnnotation: PdfWidgetAnnoObject): PdfTask<boolean>;
3175
3413
  flattenPage(doc: PdfDocumentObject, page: PdfPageObject, options?: PdfFlattenPageOptions): PdfTask<PdfPageFlattenResult>;
3176
3414
  extractPages(doc: PdfDocumentObject, pageIndexes: number[]): PdfTask<ArrayBuffer>;
3177
3415
  extractText(doc: PdfDocumentObject, pageIndexes: number[]): PdfTask<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/models",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "private": false,
5
5
  "description": "Shared type definitions, data models, and utility helpers (geometry, tasks, logging, PDF primitives) that underpin every package in the EmbedPDF ecosystem.",
6
6
  "type": "module",