pdf-lite 1.3.2 → 1.3.3

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.
@@ -62,7 +62,7 @@ export declare class PdfAcroFormField extends PdfIndirectObject<PdfDictionary<{
62
62
  MaxLen?: PdfNumber;
63
63
  Opt?: PdfArray<PdfString>;
64
64
  }>> {
65
- parent?: PdfAcroFormField;
65
+ private _parent?;
66
66
  defaultGenerateAppearance: boolean;
67
67
  private _appearanceStream?;
68
68
  private _appearanceStreamYes?;
@@ -71,6 +71,11 @@ export declare class PdfAcroFormField extends PdfIndirectObject<PdfDictionary<{
71
71
  other?: PdfIndirectObject;
72
72
  form?: PdfAcroForm;
73
73
  });
74
+ get parent(): PdfAcroFormField | undefined;
75
+ set parent(field: PdfAcroFormField | undefined);
76
+ get children(): PdfAcroFormField[];
77
+ set children(fields: PdfAcroFormField[]);
78
+ get siblings(): PdfAcroFormField[];
74
79
  get encodingMap(): Map<number, string> | undefined;
75
80
  /**
76
81
  * Convenience method to check if field dictionary is modified
@@ -18,7 +18,7 @@ export const PdfFieldType = {
18
18
  Signature: 'Sig',
19
19
  };
20
20
  export class PdfAcroFormField extends PdfIndirectObject {
21
- parent;
21
+ _parent;
22
22
  defaultGenerateAppearance = true;
23
23
  _appearanceStream;
24
24
  _appearanceStreamYes; // For button fields: checked state
@@ -28,6 +28,50 @@ export class PdfAcroFormField extends PdfIndirectObject {
28
28
  new PdfIndirectObject({ content: new PdfDictionary() }));
29
29
  this.form = options?.form;
30
30
  }
31
+ get parent() {
32
+ if (this._parent)
33
+ return this._parent;
34
+ if (!this.form)
35
+ return undefined;
36
+ return this.form.fields.find((f) => f !== this &&
37
+ f.kids.some((k) => k.objectNumber === this.objectNumber &&
38
+ k.generationNumber === this.generationNumber));
39
+ }
40
+ set parent(field) {
41
+ // Remove from old parent's Kids
42
+ if (this._parent) {
43
+ this._parent.kids = this._parent.kids.filter((k) => k.objectNumber !== this.objectNumber ||
44
+ k.generationNumber !== this.generationNumber);
45
+ }
46
+ this._parent = field;
47
+ // Add to new parent's Kids
48
+ if (field) {
49
+ const alreadyInKids = field.kids.some((k) => k.objectNumber === this.objectNumber &&
50
+ k.generationNumber === this.generationNumber);
51
+ if (!alreadyInKids) {
52
+ field.kids = [...field.kids, this.reference];
53
+ }
54
+ }
55
+ }
56
+ get children() {
57
+ if (!this.form)
58
+ return [];
59
+ return this.form.fields.filter((f) => f.parent === this);
60
+ }
61
+ set children(fields) {
62
+ // Clear existing children's parent
63
+ for (const child of this.children) {
64
+ child._parent = undefined;
65
+ }
66
+ // Set new children and update Kids array
67
+ this.kids = fields.map((f) => f.reference);
68
+ for (const child of fields) {
69
+ child._parent = this;
70
+ }
71
+ }
72
+ get siblings() {
73
+ return this.parent?.children ?? [];
74
+ }
31
75
  get encodingMap() {
32
76
  const fontName = this.fontName;
33
77
  if (!fontName)
@@ -190,6 +234,14 @@ export class PdfAcroFormField extends PdfIndirectObject {
190
234
  }
191
235
  if (this.defaultGenerateAppearance) {
192
236
  this.generateAppearance();
237
+ // If this is a child widget with siblings, regenerate their appearances too
238
+ for (const sibling of this.siblings) {
239
+ if (sibling !== this &&
240
+ sibling.rect &&
241
+ sibling.defaultGenerateAppearance) {
242
+ sibling.generateAppearance();
243
+ }
244
+ }
193
245
  }
194
246
  }
195
247
  get checked() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-lite",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "exports": {