pdf-codec 3.3.1 → 3.4.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/README.md +1 -1
- package/dist/codec.d.cts +8 -1
- package/dist/codec.d.ts +8 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/interpret.cjs +26 -9
- package/dist/interpret.d.cts +5 -0
- package/dist/interpret.d.ts +5 -0
- package/dist/interpret.js +26 -9
- package/dist/layout.cjs +17 -0
- package/dist/layout.d.cts +36 -1
- package/dist/layout.d.ts +36 -1
- package/dist/layout.js +17 -1
- package/dist/read.cjs +15 -3
- package/dist/read.js +15 -3
- package/dist/structure.cjs +184 -0
- package/dist/structure.d.cts +12 -0
- package/dist/structure.d.ts +12 -0
- package/dist/structure.js +183 -0
- package/package.json +1 -1
package/dist/layout.d.cts
CHANGED
|
@@ -29,6 +29,7 @@ declare const LayoutTextSchema: z.ZodObject<{
|
|
|
29
29
|
layer: z.ZodOptional<z.ZodString>;
|
|
30
30
|
actualText: z.ZodOptional<z.ZodString>;
|
|
31
31
|
alt: z.ZodOptional<z.ZodString>;
|
|
32
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
32
33
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
33
34
|
}, z.core.$strip>;
|
|
34
35
|
type LayoutText = z.infer<typeof LayoutTextSchema>;
|
|
@@ -41,6 +42,7 @@ declare const LayoutImageSchema: z.ZodObject<{
|
|
|
41
42
|
heightPt: z.ZodNumber;
|
|
42
43
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
43
44
|
layer: z.ZodOptional<z.ZodString>;
|
|
45
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
44
46
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
45
47
|
}, z.core.$strip>;
|
|
46
48
|
type LayoutImage = z.infer<typeof LayoutImageSchema>;
|
|
@@ -64,6 +66,7 @@ declare const LayoutRectSchema: z.ZodObject<{
|
|
|
64
66
|
widthPt: z.ZodNumber;
|
|
65
67
|
}, z.core.$strip>>;
|
|
66
68
|
layer: z.ZodOptional<z.ZodString>;
|
|
69
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
67
70
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
68
71
|
}, z.core.$strip>;
|
|
69
72
|
type LayoutRect = z.infer<typeof LayoutRectSchema>;
|
|
@@ -86,6 +89,7 @@ declare const LayoutLineSchema: z.ZodObject<{
|
|
|
86
89
|
double: "double";
|
|
87
90
|
}>>;
|
|
88
91
|
layer: z.ZodOptional<z.ZodString>;
|
|
92
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
89
93
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
90
94
|
}, z.core.$strip>;
|
|
91
95
|
type LayoutLine = z.infer<typeof LayoutLineSchema>;
|
|
@@ -109,6 +113,7 @@ declare const LayoutEllipseSchema: z.ZodObject<{
|
|
|
109
113
|
widthPt: z.ZodNumber;
|
|
110
114
|
}, z.core.$strip>>;
|
|
111
115
|
layer: z.ZodOptional<z.ZodString>;
|
|
116
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
112
117
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
113
118
|
}, z.core.$strip>;
|
|
114
119
|
type LayoutEllipse = z.infer<typeof LayoutEllipseSchema>;
|
|
@@ -189,6 +194,7 @@ declare const LayoutPathSchema: z.ZodObject<{
|
|
|
189
194
|
double: "double";
|
|
190
195
|
}>>;
|
|
191
196
|
layer: z.ZodOptional<z.ZodString>;
|
|
197
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
192
198
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
193
199
|
}, z.core.$strip>;
|
|
194
200
|
type LayoutPath = z.infer<typeof LayoutPathSchema>;
|
|
@@ -241,6 +247,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
241
247
|
layer: z.ZodOptional<z.ZodString>;
|
|
242
248
|
actualText: z.ZodOptional<z.ZodString>;
|
|
243
249
|
alt: z.ZodOptional<z.ZodString>;
|
|
250
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
244
251
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
245
252
|
}, z.core.$strip>, z.ZodObject<{
|
|
246
253
|
kind: z.ZodLiteral<"image">;
|
|
@@ -251,6 +258,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
251
258
|
heightPt: z.ZodNumber;
|
|
252
259
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
253
260
|
layer: z.ZodOptional<z.ZodString>;
|
|
261
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
254
262
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
255
263
|
}, z.core.$strip>, z.ZodObject<{
|
|
256
264
|
kind: z.ZodLiteral<"rect">;
|
|
@@ -272,6 +280,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
272
280
|
widthPt: z.ZodNumber;
|
|
273
281
|
}, z.core.$strip>>;
|
|
274
282
|
layer: z.ZodOptional<z.ZodString>;
|
|
283
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
275
284
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
276
285
|
}, z.core.$strip>, z.ZodObject<{
|
|
277
286
|
kind: z.ZodLiteral<"line">;
|
|
@@ -292,6 +301,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
292
301
|
double: "double";
|
|
293
302
|
}>>;
|
|
294
303
|
layer: z.ZodOptional<z.ZodString>;
|
|
304
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
295
305
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
296
306
|
}, z.core.$strip>, z.ZodObject<{
|
|
297
307
|
kind: z.ZodLiteral<"ellipse">;
|
|
@@ -313,6 +323,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
313
323
|
widthPt: z.ZodNumber;
|
|
314
324
|
}, z.core.$strip>>;
|
|
315
325
|
layer: z.ZodOptional<z.ZodString>;
|
|
326
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
316
327
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
317
328
|
}, z.core.$strip>, z.ZodObject<{
|
|
318
329
|
kind: z.ZodLiteral<"path">;
|
|
@@ -358,6 +369,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
358
369
|
double: "double";
|
|
359
370
|
}>>;
|
|
360
371
|
layer: z.ZodOptional<z.ZodString>;
|
|
372
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
361
373
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
362
374
|
}, z.core.$strip>, z.ZodObject<{
|
|
363
375
|
kind: z.ZodLiteral<"link">;
|
|
@@ -464,6 +476,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
464
476
|
layer: z.ZodOptional<z.ZodString>;
|
|
465
477
|
actualText: z.ZodOptional<z.ZodString>;
|
|
466
478
|
alt: z.ZodOptional<z.ZodString>;
|
|
479
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
467
480
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
468
481
|
}, z.core.$strip>, z.ZodObject<{
|
|
469
482
|
kind: z.ZodLiteral<"image">;
|
|
@@ -474,6 +487,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
474
487
|
heightPt: z.ZodNumber;
|
|
475
488
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
476
489
|
layer: z.ZodOptional<z.ZodString>;
|
|
490
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
477
491
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
478
492
|
}, z.core.$strip>, z.ZodObject<{
|
|
479
493
|
kind: z.ZodLiteral<"rect">;
|
|
@@ -495,6 +509,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
495
509
|
widthPt: z.ZodNumber;
|
|
496
510
|
}, z.core.$strip>>;
|
|
497
511
|
layer: z.ZodOptional<z.ZodString>;
|
|
512
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
498
513
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
499
514
|
}, z.core.$strip>, z.ZodObject<{
|
|
500
515
|
kind: z.ZodLiteral<"line">;
|
|
@@ -515,6 +530,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
515
530
|
double: "double";
|
|
516
531
|
}>>;
|
|
517
532
|
layer: z.ZodOptional<z.ZodString>;
|
|
533
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
518
534
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
519
535
|
}, z.core.$strip>, z.ZodObject<{
|
|
520
536
|
kind: z.ZodLiteral<"ellipse">;
|
|
@@ -536,6 +552,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
536
552
|
widthPt: z.ZodNumber;
|
|
537
553
|
}, z.core.$strip>>;
|
|
538
554
|
layer: z.ZodOptional<z.ZodString>;
|
|
555
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
539
556
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
540
557
|
}, z.core.$strip>, z.ZodObject<{
|
|
541
558
|
kind: z.ZodLiteral<"path">;
|
|
@@ -581,6 +598,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
581
598
|
double: "double";
|
|
582
599
|
}>>;
|
|
583
600
|
layer: z.ZodOptional<z.ZodString>;
|
|
601
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
584
602
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
585
603
|
}, z.core.$strip>, z.ZodObject<{
|
|
586
604
|
kind: z.ZodLiteral<"link">;
|
|
@@ -731,6 +749,16 @@ declare const LayoutLayerSchema: z.ZodObject<{
|
|
|
731
749
|
visible: z.ZodBoolean;
|
|
732
750
|
}, z.core.$strip>;
|
|
733
751
|
type LayoutLayer = z.infer<typeof LayoutLayerSchema>;
|
|
752
|
+
declare const LayoutStructureElementSchema: z.ZodType<LayoutStructureElement, LayoutStructureElement>;
|
|
753
|
+
interface LayoutStructureElement {
|
|
754
|
+
readonly id: string;
|
|
755
|
+
readonly type: string;
|
|
756
|
+
readonly title?: string;
|
|
757
|
+
readonly language?: string;
|
|
758
|
+
readonly alt?: string;
|
|
759
|
+
readonly actualText?: string;
|
|
760
|
+
readonly children: readonly LayoutStructureElement[];
|
|
761
|
+
}
|
|
734
762
|
declare const LayoutDocumentSchema: z.ZodObject<{
|
|
735
763
|
formatVersion: z.ZodLiteral<1>;
|
|
736
764
|
metadata: z.ZodObject<{
|
|
@@ -775,6 +803,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
775
803
|
layer: z.ZodOptional<z.ZodString>;
|
|
776
804
|
actualText: z.ZodOptional<z.ZodString>;
|
|
777
805
|
alt: z.ZodOptional<z.ZodString>;
|
|
806
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
778
807
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
779
808
|
}, z.core.$strip>, z.ZodObject<{
|
|
780
809
|
kind: z.ZodLiteral<"image">;
|
|
@@ -785,6 +814,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
785
814
|
heightPt: z.ZodNumber;
|
|
786
815
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
787
816
|
layer: z.ZodOptional<z.ZodString>;
|
|
817
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
788
818
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
789
819
|
}, z.core.$strip>, z.ZodObject<{
|
|
790
820
|
kind: z.ZodLiteral<"rect">;
|
|
@@ -806,6 +836,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
806
836
|
widthPt: z.ZodNumber;
|
|
807
837
|
}, z.core.$strip>>;
|
|
808
838
|
layer: z.ZodOptional<z.ZodString>;
|
|
839
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
809
840
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
810
841
|
}, z.core.$strip>, z.ZodObject<{
|
|
811
842
|
kind: z.ZodLiteral<"line">;
|
|
@@ -826,6 +857,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
826
857
|
double: "double";
|
|
827
858
|
}>>;
|
|
828
859
|
layer: z.ZodOptional<z.ZodString>;
|
|
860
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
829
861
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
830
862
|
}, z.core.$strip>, z.ZodObject<{
|
|
831
863
|
kind: z.ZodLiteral<"ellipse">;
|
|
@@ -847,6 +879,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
847
879
|
widthPt: z.ZodNumber;
|
|
848
880
|
}, z.core.$strip>>;
|
|
849
881
|
layer: z.ZodOptional<z.ZodString>;
|
|
882
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
850
883
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
851
884
|
}, z.core.$strip>, z.ZodObject<{
|
|
852
885
|
kind: z.ZodLiteral<"path">;
|
|
@@ -892,6 +925,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
892
925
|
double: "double";
|
|
893
926
|
}>>;
|
|
894
927
|
layer: z.ZodOptional<z.ZodString>;
|
|
928
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
895
929
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
896
930
|
}, z.core.$strip>, z.ZodObject<{
|
|
897
931
|
kind: z.ZodLiteral<"link">;
|
|
@@ -994,6 +1028,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
994
1028
|
name: z.ZodString;
|
|
995
1029
|
visible: z.ZodBoolean;
|
|
996
1030
|
}, z.core.$strip>>>;
|
|
1031
|
+
structure: z.ZodOptional<z.ZodArray<z.ZodType<LayoutStructureElement, LayoutStructureElement, z.core.$ZodTypeInternals<LayoutStructureElement, LayoutStructureElement>>>>;
|
|
997
1032
|
form: z.ZodOptional<z.ZodArray<z.ZodType<LayoutFormField, LayoutFormField, z.core.$ZodTypeInternals<LayoutFormField, LayoutFormField>>>>;
|
|
998
1033
|
source: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
999
1034
|
format: z.ZodEnum<{
|
|
@@ -1015,4 +1050,4 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1015
1050
|
}, z.core.$strip>;
|
|
1016
1051
|
type LayoutDocument = z.infer<typeof LayoutDocumentSchema>;
|
|
1017
1052
|
//#endregion
|
|
1018
|
-
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema };
|
|
1053
|
+
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema };
|
package/dist/layout.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ declare const LayoutTextSchema: z.ZodObject<{
|
|
|
29
29
|
layer: z.ZodOptional<z.ZodString>;
|
|
30
30
|
actualText: z.ZodOptional<z.ZodString>;
|
|
31
31
|
alt: z.ZodOptional<z.ZodString>;
|
|
32
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
32
33
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
33
34
|
}, z.core.$strip>;
|
|
34
35
|
type LayoutText = z.infer<typeof LayoutTextSchema>;
|
|
@@ -41,6 +42,7 @@ declare const LayoutImageSchema: z.ZodObject<{
|
|
|
41
42
|
heightPt: z.ZodNumber;
|
|
42
43
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
43
44
|
layer: z.ZodOptional<z.ZodString>;
|
|
45
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
44
46
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
45
47
|
}, z.core.$strip>;
|
|
46
48
|
type LayoutImage = z.infer<typeof LayoutImageSchema>;
|
|
@@ -64,6 +66,7 @@ declare const LayoutRectSchema: z.ZodObject<{
|
|
|
64
66
|
widthPt: z.ZodNumber;
|
|
65
67
|
}, z.core.$strip>>;
|
|
66
68
|
layer: z.ZodOptional<z.ZodString>;
|
|
69
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
67
70
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
68
71
|
}, z.core.$strip>;
|
|
69
72
|
type LayoutRect = z.infer<typeof LayoutRectSchema>;
|
|
@@ -86,6 +89,7 @@ declare const LayoutLineSchema: z.ZodObject<{
|
|
|
86
89
|
double: "double";
|
|
87
90
|
}>>;
|
|
88
91
|
layer: z.ZodOptional<z.ZodString>;
|
|
92
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
89
93
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
90
94
|
}, z.core.$strip>;
|
|
91
95
|
type LayoutLine = z.infer<typeof LayoutLineSchema>;
|
|
@@ -109,6 +113,7 @@ declare const LayoutEllipseSchema: z.ZodObject<{
|
|
|
109
113
|
widthPt: z.ZodNumber;
|
|
110
114
|
}, z.core.$strip>>;
|
|
111
115
|
layer: z.ZodOptional<z.ZodString>;
|
|
116
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
112
117
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
113
118
|
}, z.core.$strip>;
|
|
114
119
|
type LayoutEllipse = z.infer<typeof LayoutEllipseSchema>;
|
|
@@ -189,6 +194,7 @@ declare const LayoutPathSchema: z.ZodObject<{
|
|
|
189
194
|
double: "double";
|
|
190
195
|
}>>;
|
|
191
196
|
layer: z.ZodOptional<z.ZodString>;
|
|
197
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
192
198
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
193
199
|
}, z.core.$strip>;
|
|
194
200
|
type LayoutPath = z.infer<typeof LayoutPathSchema>;
|
|
@@ -241,6 +247,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
241
247
|
layer: z.ZodOptional<z.ZodString>;
|
|
242
248
|
actualText: z.ZodOptional<z.ZodString>;
|
|
243
249
|
alt: z.ZodOptional<z.ZodString>;
|
|
250
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
244
251
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
245
252
|
}, z.core.$strip>, z.ZodObject<{
|
|
246
253
|
kind: z.ZodLiteral<"image">;
|
|
@@ -251,6 +258,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
251
258
|
heightPt: z.ZodNumber;
|
|
252
259
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
253
260
|
layer: z.ZodOptional<z.ZodString>;
|
|
261
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
254
262
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
255
263
|
}, z.core.$strip>, z.ZodObject<{
|
|
256
264
|
kind: z.ZodLiteral<"rect">;
|
|
@@ -272,6 +280,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
272
280
|
widthPt: z.ZodNumber;
|
|
273
281
|
}, z.core.$strip>>;
|
|
274
282
|
layer: z.ZodOptional<z.ZodString>;
|
|
283
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
275
284
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
276
285
|
}, z.core.$strip>, z.ZodObject<{
|
|
277
286
|
kind: z.ZodLiteral<"line">;
|
|
@@ -292,6 +301,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
292
301
|
double: "double";
|
|
293
302
|
}>>;
|
|
294
303
|
layer: z.ZodOptional<z.ZodString>;
|
|
304
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
295
305
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
296
306
|
}, z.core.$strip>, z.ZodObject<{
|
|
297
307
|
kind: z.ZodLiteral<"ellipse">;
|
|
@@ -313,6 +323,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
313
323
|
widthPt: z.ZodNumber;
|
|
314
324
|
}, z.core.$strip>>;
|
|
315
325
|
layer: z.ZodOptional<z.ZodString>;
|
|
326
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
316
327
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
317
328
|
}, z.core.$strip>, z.ZodObject<{
|
|
318
329
|
kind: z.ZodLiteral<"path">;
|
|
@@ -358,6 +369,7 @@ declare const LayoutItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
358
369
|
double: "double";
|
|
359
370
|
}>>;
|
|
360
371
|
layer: z.ZodOptional<z.ZodString>;
|
|
372
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
361
373
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
362
374
|
}, z.core.$strip>, z.ZodObject<{
|
|
363
375
|
kind: z.ZodLiteral<"link">;
|
|
@@ -464,6 +476,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
464
476
|
layer: z.ZodOptional<z.ZodString>;
|
|
465
477
|
actualText: z.ZodOptional<z.ZodString>;
|
|
466
478
|
alt: z.ZodOptional<z.ZodString>;
|
|
479
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
467
480
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
468
481
|
}, z.core.$strip>, z.ZodObject<{
|
|
469
482
|
kind: z.ZodLiteral<"image">;
|
|
@@ -474,6 +487,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
474
487
|
heightPt: z.ZodNumber;
|
|
475
488
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
476
489
|
layer: z.ZodOptional<z.ZodString>;
|
|
490
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
477
491
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
478
492
|
}, z.core.$strip>, z.ZodObject<{
|
|
479
493
|
kind: z.ZodLiteral<"rect">;
|
|
@@ -495,6 +509,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
495
509
|
widthPt: z.ZodNumber;
|
|
496
510
|
}, z.core.$strip>>;
|
|
497
511
|
layer: z.ZodOptional<z.ZodString>;
|
|
512
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
498
513
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
499
514
|
}, z.core.$strip>, z.ZodObject<{
|
|
500
515
|
kind: z.ZodLiteral<"line">;
|
|
@@ -515,6 +530,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
515
530
|
double: "double";
|
|
516
531
|
}>>;
|
|
517
532
|
layer: z.ZodOptional<z.ZodString>;
|
|
533
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
518
534
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
519
535
|
}, z.core.$strip>, z.ZodObject<{
|
|
520
536
|
kind: z.ZodLiteral<"ellipse">;
|
|
@@ -536,6 +552,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
536
552
|
widthPt: z.ZodNumber;
|
|
537
553
|
}, z.core.$strip>>;
|
|
538
554
|
layer: z.ZodOptional<z.ZodString>;
|
|
555
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
539
556
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
540
557
|
}, z.core.$strip>, z.ZodObject<{
|
|
541
558
|
kind: z.ZodLiteral<"path">;
|
|
@@ -581,6 +598,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
581
598
|
double: "double";
|
|
582
599
|
}>>;
|
|
583
600
|
layer: z.ZodOptional<z.ZodString>;
|
|
601
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
584
602
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
585
603
|
}, z.core.$strip>, z.ZodObject<{
|
|
586
604
|
kind: z.ZodLiteral<"link">;
|
|
@@ -731,6 +749,16 @@ declare const LayoutLayerSchema: z.ZodObject<{
|
|
|
731
749
|
visible: z.ZodBoolean;
|
|
732
750
|
}, z.core.$strip>;
|
|
733
751
|
type LayoutLayer = z.infer<typeof LayoutLayerSchema>;
|
|
752
|
+
declare const LayoutStructureElementSchema: z.ZodType<LayoutStructureElement, LayoutStructureElement>;
|
|
753
|
+
interface LayoutStructureElement {
|
|
754
|
+
readonly id: string;
|
|
755
|
+
readonly type: string;
|
|
756
|
+
readonly title?: string;
|
|
757
|
+
readonly language?: string;
|
|
758
|
+
readonly alt?: string;
|
|
759
|
+
readonly actualText?: string;
|
|
760
|
+
readonly children: readonly LayoutStructureElement[];
|
|
761
|
+
}
|
|
734
762
|
declare const LayoutDocumentSchema: z.ZodObject<{
|
|
735
763
|
formatVersion: z.ZodLiteral<1>;
|
|
736
764
|
metadata: z.ZodObject<{
|
|
@@ -775,6 +803,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
775
803
|
layer: z.ZodOptional<z.ZodString>;
|
|
776
804
|
actualText: z.ZodOptional<z.ZodString>;
|
|
777
805
|
alt: z.ZodOptional<z.ZodString>;
|
|
806
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
778
807
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
779
808
|
}, z.core.$strip>, z.ZodObject<{
|
|
780
809
|
kind: z.ZodLiteral<"image">;
|
|
@@ -785,6 +814,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
785
814
|
heightPt: z.ZodNumber;
|
|
786
815
|
rotationDeg: z.ZodOptional<z.ZodNumber>;
|
|
787
816
|
layer: z.ZodOptional<z.ZodString>;
|
|
817
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
788
818
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
789
819
|
}, z.core.$strip>, z.ZodObject<{
|
|
790
820
|
kind: z.ZodLiteral<"rect">;
|
|
@@ -806,6 +836,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
806
836
|
widthPt: z.ZodNumber;
|
|
807
837
|
}, z.core.$strip>>;
|
|
808
838
|
layer: z.ZodOptional<z.ZodString>;
|
|
839
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
809
840
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
810
841
|
}, z.core.$strip>, z.ZodObject<{
|
|
811
842
|
kind: z.ZodLiteral<"line">;
|
|
@@ -826,6 +857,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
826
857
|
double: "double";
|
|
827
858
|
}>>;
|
|
828
859
|
layer: z.ZodOptional<z.ZodString>;
|
|
860
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
829
861
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
830
862
|
}, z.core.$strip>, z.ZodObject<{
|
|
831
863
|
kind: z.ZodLiteral<"ellipse">;
|
|
@@ -847,6 +879,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
847
879
|
widthPt: z.ZodNumber;
|
|
848
880
|
}, z.core.$strip>>;
|
|
849
881
|
layer: z.ZodOptional<z.ZodString>;
|
|
882
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
850
883
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
851
884
|
}, z.core.$strip>, z.ZodObject<{
|
|
852
885
|
kind: z.ZodLiteral<"path">;
|
|
@@ -892,6 +925,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
892
925
|
double: "double";
|
|
893
926
|
}>>;
|
|
894
927
|
layer: z.ZodOptional<z.ZodString>;
|
|
928
|
+
structure: z.ZodOptional<z.ZodString>;
|
|
895
929
|
sourcePath: z.ZodOptional<z.ZodString>;
|
|
896
930
|
}, z.core.$strip>, z.ZodObject<{
|
|
897
931
|
kind: z.ZodLiteral<"link">;
|
|
@@ -994,6 +1028,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
994
1028
|
name: z.ZodString;
|
|
995
1029
|
visible: z.ZodBoolean;
|
|
996
1030
|
}, z.core.$strip>>>;
|
|
1031
|
+
structure: z.ZodOptional<z.ZodArray<z.ZodType<LayoutStructureElement, LayoutStructureElement, z.core.$ZodTypeInternals<LayoutStructureElement, LayoutStructureElement>>>>;
|
|
997
1032
|
form: z.ZodOptional<z.ZodArray<z.ZodType<LayoutFormField, LayoutFormField, z.core.$ZodTypeInternals<LayoutFormField, LayoutFormField>>>>;
|
|
998
1033
|
source: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
999
1034
|
format: z.ZodEnum<{
|
|
@@ -1015,4 +1050,4 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1015
1050
|
}, z.core.$strip>;
|
|
1016
1051
|
type LayoutDocument = z.infer<typeof LayoutDocumentSchema>;
|
|
1017
1052
|
//#endregion
|
|
1018
|
-
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema };
|
|
1053
|
+
export { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema };
|
package/dist/layout.js
CHANGED
|
@@ -16,6 +16,7 @@ const LayoutTextSchema = z.object({
|
|
|
16
16
|
layer: z.string().optional(),
|
|
17
17
|
actualText: z.string().optional(),
|
|
18
18
|
alt: z.string().optional(),
|
|
19
|
+
structure: z.string().optional(),
|
|
19
20
|
sourcePath: z.string().optional()
|
|
20
21
|
});
|
|
21
22
|
const LayoutImageSchema = z.object({
|
|
@@ -27,6 +28,7 @@ const LayoutImageSchema = z.object({
|
|
|
27
28
|
heightPt: z.number().positive(),
|
|
28
29
|
rotationDeg: z.number().optional(),
|
|
29
30
|
layer: z.string().optional(),
|
|
31
|
+
structure: z.string().optional(),
|
|
30
32
|
sourcePath: z.string().optional()
|
|
31
33
|
});
|
|
32
34
|
const LayoutRectSchema = z.object({
|
|
@@ -41,6 +43,7 @@ const LayoutRectSchema = z.object({
|
|
|
41
43
|
widthPt: z.number().positive()
|
|
42
44
|
}).optional(),
|
|
43
45
|
layer: z.string().optional(),
|
|
46
|
+
structure: z.string().optional(),
|
|
44
47
|
sourcePath: z.string().optional()
|
|
45
48
|
});
|
|
46
49
|
const LayoutLineSchema = z.object({
|
|
@@ -53,6 +56,7 @@ const LayoutLineSchema = z.object({
|
|
|
53
56
|
widthPt: z.number().positive(),
|
|
54
57
|
style: ContentStrokeStyleSchema.optional(),
|
|
55
58
|
layer: z.string().optional(),
|
|
59
|
+
structure: z.string().optional(),
|
|
56
60
|
sourcePath: z.string().optional()
|
|
57
61
|
});
|
|
58
62
|
const LayoutEllipseSchema = z.object({
|
|
@@ -67,6 +71,7 @@ const LayoutEllipseSchema = z.object({
|
|
|
67
71
|
widthPt: z.number().positive()
|
|
68
72
|
}).optional(),
|
|
69
73
|
layer: z.string().optional(),
|
|
74
|
+
structure: z.string().optional(),
|
|
70
75
|
sourcePath: z.string().optional()
|
|
71
76
|
});
|
|
72
77
|
const LayoutPathSegmentSchema = z.discriminatedUnion("kind", [z.object({
|
|
@@ -99,6 +104,7 @@ const LayoutPathSchema = z.object({
|
|
|
99
104
|
}).optional(),
|
|
100
105
|
style: ContentStrokeStyleSchema.optional(),
|
|
101
106
|
layer: z.string().optional(),
|
|
107
|
+
structure: z.string().optional(),
|
|
102
108
|
sourcePath: z.string().optional()
|
|
103
109
|
});
|
|
104
110
|
const LayoutLinkSchema = z.object({
|
|
@@ -237,6 +243,15 @@ const LayoutLayerSchema = z.object({
|
|
|
237
243
|
name: z.string(),
|
|
238
244
|
visible: z.boolean()
|
|
239
245
|
});
|
|
246
|
+
const LayoutStructureElementSchema = z.lazy(() => z.object({
|
|
247
|
+
id: z.string(),
|
|
248
|
+
type: z.string(),
|
|
249
|
+
title: z.string().optional(),
|
|
250
|
+
language: z.string().optional(),
|
|
251
|
+
alt: z.string().optional(),
|
|
252
|
+
actualText: z.string().optional(),
|
|
253
|
+
children: z.array(LayoutStructureElementSchema)
|
|
254
|
+
}));
|
|
240
255
|
const LayoutDocumentSchema = z.object({
|
|
241
256
|
formatVersion: z.literal(1),
|
|
242
257
|
metadata: LayoutMetadataSchema,
|
|
@@ -246,8 +261,9 @@ const LayoutDocumentSchema = z.object({
|
|
|
246
261
|
outline: z.array(LayoutOutlineItemSchema).optional(),
|
|
247
262
|
attachments: z.array(LayoutAttachmentSchema).optional(),
|
|
248
263
|
layers: z.array(LayoutLayerSchema).optional(),
|
|
264
|
+
structure: z.array(LayoutStructureElementSchema).optional(),
|
|
249
265
|
form: z.array(LayoutFormFieldSchema).optional(),
|
|
250
266
|
source: z.record(z.string(), SourceResidueSchema).optional()
|
|
251
267
|
});
|
|
252
268
|
//#endregion
|
|
253
|
-
export { LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema };
|
|
269
|
+
export { LAYOUT_FORMAT_VERSION, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachmentSchema, LayoutDestinationSchema, LayoutDestinationTargetSchema, LayoutDocumentSchema, LayoutEllipseSchema, LayoutFormFieldSchema, LayoutFormWidgetSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLinkSchema, LayoutItemSchema, LayoutLayerSchema, LayoutLineSchema, LayoutLinkSchema, LayoutOutlineItemSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutStructureElementSchema, LayoutSubpathSchema, LayoutTextSchema };
|
package/dist/read.cjs
CHANGED
|
@@ -13,6 +13,7 @@ const require_bytes_crc32 = require("./bytes/crc32.cjs");
|
|
|
13
13
|
const require_form = require("./form.cjs");
|
|
14
14
|
const require_xmp = require("./xmp.cjs");
|
|
15
15
|
const require_optional_content = require("./optional-content.cjs");
|
|
16
|
+
const require_structure = require("./structure.cjs");
|
|
16
17
|
require("./layout.cjs");
|
|
17
18
|
const require_diagnostics = require("./diagnostics.cjs");
|
|
18
19
|
const require_document = require("./document.cjs");
|
|
@@ -52,11 +53,12 @@ function readPdf(bytes, options) {
|
|
|
52
53
|
const attachments = require_attachments.readAttachments(doc.catalog, pageDicts, doc, sink);
|
|
53
54
|
const optionalContent = require_optional_content.readOptionalContent(doc.catalog, doc, sink);
|
|
54
55
|
const form = require_form.readAcroForm(doc.catalog, doc, (obj) => doc.pageIndex(obj), sink);
|
|
56
|
+
const structure = require_structure.readStructure(doc.catalog, pageDicts, doc, sink);
|
|
55
57
|
const source = readDocumentResidue(doc, sink);
|
|
56
58
|
const pageBoxRows = [];
|
|
57
59
|
const pages = pageDicts.map((pageDict, index) => {
|
|
58
60
|
require_util_abort.throwIfAborted(signal);
|
|
59
|
-
return readPage(index, pageDict, doc, fontResolver, images, imageIdCache, destinationRegistry, optionalContent.layerNameOf, pageBoxRows, sink);
|
|
61
|
+
return readPage(index, pageDict, doc, fontResolver, images, imageIdCache, destinationRegistry, optionalContent.layerNameOf, structure.ownerOf, pageBoxRows, sink);
|
|
60
62
|
});
|
|
61
63
|
if (pageBoxRows.length > 0) source["page-boxes"] = {
|
|
62
64
|
format: "pdf",
|
|
@@ -72,6 +74,7 @@ function readPdf(bytes, options) {
|
|
|
72
74
|
...attachments.length > 0 ? { attachments } : {},
|
|
73
75
|
...optionalContent.layers.length > 0 ? { layers: [...optionalContent.layers] } : {},
|
|
74
76
|
...form.length > 0 ? { form } : {},
|
|
77
|
+
...structure.tree.length > 0 ? { structure: [...structure.tree] } : {},
|
|
75
78
|
...Object.keys(source).length > 0 ? { source } : {}
|
|
76
79
|
};
|
|
77
80
|
}
|
|
@@ -272,7 +275,7 @@ function pageBoxResidueEntry(pageIndex, page, mediaBox, cropBox) {
|
|
|
272
275
|
for (const [key, value] of declaredBoxes) if (value !== void 0) entries[key] = value;
|
|
273
276
|
return require_objects.pdfDict(entries);
|
|
274
277
|
}
|
|
275
|
-
function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache, destinationRegistry, layerNameOf, pageBoxRows, sink) {
|
|
278
|
+
function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache, destinationRegistry, layerNameOf, structureOwnerOf, pageBoxRows, sink) {
|
|
276
279
|
const resources = resolver.resolveDict(require_objects.dictGet(page, "Resources"));
|
|
277
280
|
const mediaBox = readMediaBox(page);
|
|
278
281
|
let cropBox = readDeclaredPageBox(page, "CropBox") ?? mediaBox;
|
|
@@ -303,7 +306,9 @@ function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache,
|
|
|
303
306
|
});
|
|
304
307
|
for (const item of extracted) {
|
|
305
308
|
const converted = convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink);
|
|
306
|
-
if (converted
|
|
309
|
+
if (converted === void 0 || !itemIntersectsVisibleRegion(converted, widthPt, heightPt)) continue;
|
|
310
|
+
const owner = item.mcid === void 0 ? void 0 : structureOwnerOf(pageIndex, item.mcid);
|
|
311
|
+
items.push(owner === void 0 ? converted : withStructure(converted, owner));
|
|
307
312
|
}
|
|
308
313
|
} else sink({
|
|
309
314
|
code: "pdf/object-missing-value",
|
|
@@ -321,6 +326,13 @@ function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache,
|
|
|
321
326
|
...annotations.length > 0 ? { annotations } : {}
|
|
322
327
|
};
|
|
323
328
|
}
|
|
329
|
+
function withStructure(item, structure) {
|
|
330
|
+
if (item.kind === "link" || item.kind === "internalLink") return item;
|
|
331
|
+
return {
|
|
332
|
+
...item,
|
|
333
|
+
structure
|
|
334
|
+
};
|
|
335
|
+
}
|
|
324
336
|
function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
|
|
325
337
|
if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
|
|
326
338
|
if (item.kind === "rect") return convertRect(item, pageMatrix);
|
package/dist/read.js
CHANGED
|
@@ -12,6 +12,7 @@ import { crc32 } from "./bytes/crc32.js";
|
|
|
12
12
|
import { readAcroForm } from "./form.js";
|
|
13
13
|
import { readXmpMetadata } from "./xmp.js";
|
|
14
14
|
import { readOptionalContent } from "./optional-content.js";
|
|
15
|
+
import { readStructure } from "./structure.js";
|
|
15
16
|
import "./layout.js";
|
|
16
17
|
import { NOOP_DIAGNOSTIC_SINK, PdfParseError } from "./diagnostics.js";
|
|
17
18
|
import { openPdfDocument } from "./document.js";
|
|
@@ -51,11 +52,12 @@ function readPdf(bytes, options) {
|
|
|
51
52
|
const attachments = readAttachments(doc.catalog, pageDicts, doc, sink);
|
|
52
53
|
const optionalContent = readOptionalContent(doc.catalog, doc, sink);
|
|
53
54
|
const form = readAcroForm(doc.catalog, doc, (obj) => doc.pageIndex(obj), sink);
|
|
55
|
+
const structure = readStructure(doc.catalog, pageDicts, doc, sink);
|
|
54
56
|
const source = readDocumentResidue(doc, sink);
|
|
55
57
|
const pageBoxRows = [];
|
|
56
58
|
const pages = pageDicts.map((pageDict, index) => {
|
|
57
59
|
throwIfAborted(signal);
|
|
58
|
-
return readPage(index, pageDict, doc, fontResolver, images, imageIdCache, destinationRegistry, optionalContent.layerNameOf, pageBoxRows, sink);
|
|
60
|
+
return readPage(index, pageDict, doc, fontResolver, images, imageIdCache, destinationRegistry, optionalContent.layerNameOf, structure.ownerOf, pageBoxRows, sink);
|
|
59
61
|
});
|
|
60
62
|
if (pageBoxRows.length > 0) source["page-boxes"] = {
|
|
61
63
|
format: "pdf",
|
|
@@ -71,6 +73,7 @@ function readPdf(bytes, options) {
|
|
|
71
73
|
...attachments.length > 0 ? { attachments } : {},
|
|
72
74
|
...optionalContent.layers.length > 0 ? { layers: [...optionalContent.layers] } : {},
|
|
73
75
|
...form.length > 0 ? { form } : {},
|
|
76
|
+
...structure.tree.length > 0 ? { structure: [...structure.tree] } : {},
|
|
74
77
|
...Object.keys(source).length > 0 ? { source } : {}
|
|
75
78
|
};
|
|
76
79
|
}
|
|
@@ -271,7 +274,7 @@ function pageBoxResidueEntry(pageIndex, page, mediaBox, cropBox) {
|
|
|
271
274
|
for (const [key, value] of declaredBoxes) if (value !== void 0) entries[key] = value;
|
|
272
275
|
return pdfDict(entries);
|
|
273
276
|
}
|
|
274
|
-
function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache, destinationRegistry, layerNameOf, pageBoxRows, sink) {
|
|
277
|
+
function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache, destinationRegistry, layerNameOf, structureOwnerOf, pageBoxRows, sink) {
|
|
275
278
|
const resources = resolver.resolveDict(dictGet(page, "Resources"));
|
|
276
279
|
const mediaBox = readMediaBox(page);
|
|
277
280
|
let cropBox = readDeclaredPageBox(page, "CropBox") ?? mediaBox;
|
|
@@ -302,7 +305,9 @@ function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache,
|
|
|
302
305
|
});
|
|
303
306
|
for (const item of extracted) {
|
|
304
307
|
const converted = convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink);
|
|
305
|
-
if (converted
|
|
308
|
+
if (converted === void 0 || !itemIntersectsVisibleRegion(converted, widthPt, heightPt)) continue;
|
|
309
|
+
const owner = item.mcid === void 0 ? void 0 : structureOwnerOf(pageIndex, item.mcid);
|
|
310
|
+
items.push(owner === void 0 ? converted : withStructure(converted, owner));
|
|
306
311
|
}
|
|
307
312
|
} else sink({
|
|
308
313
|
code: "pdf/object-missing-value",
|
|
@@ -320,6 +325,13 @@ function readPage(pageIndex, page, resolver, fontResolver, images, imageIdCache,
|
|
|
320
325
|
...annotations.length > 0 ? { annotations } : {}
|
|
321
326
|
};
|
|
322
327
|
}
|
|
328
|
+
function withStructure(item, structure) {
|
|
329
|
+
if (item.kind === "link" || item.kind === "internalLink") return item;
|
|
330
|
+
return {
|
|
331
|
+
...item,
|
|
332
|
+
structure
|
|
333
|
+
};
|
|
334
|
+
}
|
|
323
335
|
function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
|
|
324
336
|
if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
|
|
325
337
|
if (item.kind === "rect") return convertRect(item, pageMatrix);
|