pdf-parser.js 5.2.30 → 5.3.1

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.
Files changed (189) hide show
  1. package/dist/{afm-widths-BHD2HZIL.cjs → afm-widths-C6U0SQj9.cjs} +5 -1448
  2. package/dist/{afm-widths-B_IGbGky.js → afm-widths-p3UfaXme.js} +3 -1398
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.d.cts +3 -3
  6. package/dist/annotations.d.ts +3 -3
  7. package/dist/attachments.d.cts +2 -2
  8. package/dist/attachments.d.ts +2 -2
  9. package/dist/builtin-encoding.cjs +4 -3
  10. package/dist/builtin-encoding.js +2 -1
  11. package/dist/cmap.d.cts +1 -1
  12. package/dist/cmap.d.ts +1 -1
  13. package/dist/content-read.d.cts +1 -1
  14. package/dist/content-read.d.ts +1 -1
  15. package/dist/content-write.cjs +1 -1
  16. package/dist/content-write.d.cts +1 -1
  17. package/dist/content-write.d.ts +1 -1
  18. package/dist/content-write.js +1 -1
  19. package/dist/diagnostics-C9FxfZ6H.d.cts +22 -0
  20. package/dist/diagnostics-C9FxfZ6H.d.ts +22 -0
  21. package/dist/diagnostics.d.cts +1 -21
  22. package/dist/diagnostics.d.ts +1 -21
  23. package/dist/document.d.cts +1 -1
  24. package/dist/document.d.ts +1 -1
  25. package/dist/{embedded-font-ByD7ZiQS.d.ts → embedded-font-CQZbTTDM.d.ts} +1 -1
  26. package/dist/{embedded-font-DgVBedw6.d.cts → embedded-font-CqePfvrl.d.cts} +1 -1
  27. package/dist/embedded-font-write.d.cts +1 -1
  28. package/dist/embedded-font-write.d.ts +1 -1
  29. package/dist/embedded-font.cjs +2 -2
  30. package/dist/embedded-font.d.cts +1 -1
  31. package/dist/embedded-font.d.ts +1 -1
  32. package/dist/embedded-font.js +2 -2
  33. package/dist/encoding-glyph-unicode.cjs +353 -0
  34. package/dist/encoding-glyph-unicode.d.cts +4 -0
  35. package/dist/encoding-glyph-unicode.d.ts +4 -0
  36. package/dist/encoding-glyph-unicode.js +352 -0
  37. package/dist/encoding-standard-tables.cjs +531 -0
  38. package/dist/encoding-standard-tables.d.cts +7 -0
  39. package/dist/encoding-standard-tables.d.ts +7 -0
  40. package/dist/encoding-standard-tables.js +527 -0
  41. package/dist/encoding-symbol-tables.cjs +533 -0
  42. package/dist/encoding-symbol-tables.d.cts +7 -0
  43. package/dist/encoding-symbol-tables.d.ts +7 -0
  44. package/dist/encoding-symbol-tables.js +529 -0
  45. package/dist/encoding.cjs +1 -9
  46. package/dist/encoding.d.cts +1 -9
  47. package/dist/encoding.d.ts +1 -9
  48. package/dist/encoding.js +2 -2
  49. package/dist/encrypt.d.cts +1 -1
  50. package/dist/encrypt.d.ts +1 -1
  51. package/dist/filters.d.cts +1 -1
  52. package/dist/filters.d.ts +1 -1
  53. package/dist/font-read.cjs +4 -3
  54. package/dist/font-read.d.cts +2 -2
  55. package/dist/font-read.d.ts +2 -2
  56. package/dist/font-read.js +2 -1
  57. package/dist/font-registry.d.cts +1 -1
  58. package/dist/font-registry.d.ts +1 -1
  59. package/dist/form.d.cts +2 -2
  60. package/dist/form.d.ts +2 -2
  61. package/dist/gdef-table-D0Hzn4KD.d.cts +15 -0
  62. package/dist/gdef-table-DL0V8wEZ.d.ts +15 -0
  63. package/dist/gdef-table.d.cts +1 -14
  64. package/dist/gdef-table.d.ts +1 -14
  65. package/dist/glyf-contours.d.cts +12 -1
  66. package/dist/glyf-contours.d.ts +12 -1
  67. package/dist/gsub-context.cjs +13 -0
  68. package/dist/gsub-context.d.cts +34 -0
  69. package/dist/gsub-context.d.ts +34 -0
  70. package/dist/gsub-context.js +2 -0
  71. package/dist/gsub-table-BDpJWqpf.d.ts +52 -0
  72. package/dist/gsub-table-D6niKeLi.js +556 -0
  73. package/dist/gsub-table-DW7Wmi9V.d.cts +52 -0
  74. package/dist/gsub-table-hFfYmf1W.cjs +741 -0
  75. package/dist/gsub-table.cjs +21 -556
  76. package/dist/gsub-table.d.cts +2 -2
  77. package/dist/gsub-table.d.ts +2 -2
  78. package/dist/gsub-table.js +2 -554
  79. package/dist/images-read.d.cts +2 -2
  80. package/dist/images-read.d.ts +2 -2
  81. package/dist/index.cjs +6 -6
  82. package/dist/index.d.cts +2 -2
  83. package/dist/index.d.ts +2 -2
  84. package/dist/index.js +6 -6
  85. package/dist/interpret-CqXdXgkY.cjs +712 -0
  86. package/dist/interpret-aWWhdIzr.js +677 -0
  87. package/dist/interpret-colors.cjs +6 -0
  88. package/dist/interpret-colors.d.cts +9 -0
  89. package/dist/interpret-colors.d.ts +9 -0
  90. package/dist/interpret-colors.js +2 -0
  91. package/dist/interpret-marked.cjs +25 -0
  92. package/dist/interpret-marked.d.cts +11 -0
  93. package/dist/interpret-marked.d.ts +11 -0
  94. package/dist/interpret-marked.js +23 -0
  95. package/dist/interpret-shapes.cjs +212 -0
  96. package/dist/interpret-shapes.d.cts +32 -0
  97. package/dist/interpret-shapes.d.ts +32 -0
  98. package/dist/interpret-shapes.js +199 -0
  99. package/dist/interpret-types.cjs +0 -0
  100. package/dist/interpret-types.d.cts +123 -0
  101. package/dist/interpret-types.d.ts +123 -0
  102. package/dist/interpret-types.js +0 -0
  103. package/dist/interpret.cjs +3 -887
  104. package/dist/interpret.d.cts +5 -116
  105. package/dist/interpret.d.ts +5 -116
  106. package/dist/interpret.js +2 -887
  107. package/dist/math-font.cjs +1 -1
  108. package/dist/math-font.js +1 -1
  109. package/dist/measure.cjs +1 -1
  110. package/dist/measure.js +1 -1
  111. package/dist/names.d.cts +2 -2
  112. package/dist/names.d.ts +2 -2
  113. package/dist/navigation.d.cts +2 -2
  114. package/dist/navigation.d.ts +2 -2
  115. package/dist/optional-content.d.cts +2 -2
  116. package/dist/optional-content.d.ts +2 -2
  117. package/dist/ot-layout-common-BcsGRFBS.d.cts +10 -0
  118. package/dist/ot-layout-common-BcsGRFBS.d.ts +10 -0
  119. package/dist/ot-layout-common.d.cts +1 -9
  120. package/dist/ot-layout-common.d.ts +1 -9
  121. package/dist/parse.d.cts +1 -1
  122. package/dist/parse.d.ts +1 -1
  123. package/dist/predictors.d.cts +1 -1
  124. package/dist/predictors.d.ts +1 -1
  125. package/dist/raster-Cdm3idP_.js +794 -0
  126. package/dist/raster-EG2KYRZ0.cjs +829 -0
  127. package/dist/raster-text.cjs +5 -0
  128. package/dist/raster-text.d.cts +20 -0
  129. package/dist/raster-text.d.ts +20 -0
  130. package/dist/raster-text.js +2 -0
  131. package/dist/raster.cjs +4 -795
  132. package/dist/raster.d.cts +17 -6
  133. package/dist/raster.d.ts +17 -6
  134. package/dist/raster.js +2 -792
  135. package/dist/read-convert.cjs +310 -0
  136. package/dist/read-convert.d.cts +58 -0
  137. package/dist/read-convert.d.ts +58 -0
  138. package/dist/read-convert.js +295 -0
  139. package/dist/read.cjs +5 -293
  140. package/dist/read.d.cts +1 -1
  141. package/dist/read.d.ts +1 -1
  142. package/dist/read.js +4 -292
  143. package/dist/structure.d.cts +2 -2
  144. package/dist/structure.d.ts +2 -2
  145. package/dist/winansi.cjs +1 -1
  146. package/dist/winansi.js +1 -1
  147. package/dist/write-annotations.cjs +132 -0
  148. package/dist/write-annotations.d.cts +29 -0
  149. package/dist/write-annotations.d.ts +29 -0
  150. package/dist/write-annotations.js +121 -0
  151. package/dist/write-font-objects.cjs +76 -0
  152. package/dist/write-font-objects.d.cts +35 -0
  153. package/dist/write-font-objects.d.ts +35 -0
  154. package/dist/write-font-objects.js +75 -0
  155. package/dist/write-form.cjs +91 -0
  156. package/dist/write-form.d.cts +19 -0
  157. package/dist/write-form.d.ts +19 -0
  158. package/dist/write-form.js +89 -0
  159. package/dist/write-images.cjs +148 -0
  160. package/dist/write-images.d.cts +25 -0
  161. package/dist/write-images.d.ts +25 -0
  162. package/dist/write-images.js +140 -0
  163. package/dist/write-outline.cjs +46 -0
  164. package/dist/write-outline.d.cts +18 -0
  165. package/dist/write-outline.d.ts +18 -0
  166. package/dist/write-outline.js +45 -0
  167. package/dist/write-page-emit.cjs +97 -0
  168. package/dist/write-page-emit.d.cts +63 -0
  169. package/dist/write-page-emit.d.ts +63 -0
  170. package/dist/write-page-emit.js +96 -0
  171. package/dist/write-pages.cjs +37 -0
  172. package/dist/write-pages.d.cts +21 -0
  173. package/dist/write-pages.d.ts +21 -0
  174. package/dist/write-pages.js +36 -0
  175. package/dist/write-strings.cjs +41 -0
  176. package/dist/write-strings.d.cts +9 -0
  177. package/dist/write-strings.d.ts +9 -0
  178. package/dist/write-strings.js +37 -0
  179. package/dist/write.cjs +53 -553
  180. package/dist/write.d.cts +1 -1
  181. package/dist/write.d.ts +1 -1
  182. package/dist/write.js +49 -549
  183. package/dist/xref.d.cts +1 -1
  184. package/dist/xref.d.ts +1 -1
  185. package/package.json +1 -1
  186. package/dist/glyf-contours-B1PsI9oA.d.ts +0 -13
  187. package/dist/glyf-contours-NHBpgks-.d.cts +0 -13
  188. package/dist/gsub-table-Bm9kSMzk.d.cts +0 -16
  189. package/dist/gsub-table-CdfESH2-.d.ts +0 -16
@@ -0,0 +1,76 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objects = require("./objects.cjs");
3
+ const require_math_content_write = require("./math-content-write.cjs");
4
+ const require_math_font = require("./math-font.cjs");
5
+ const require_sfnt_subset = require("./sfnt-subset.cjs");
6
+ const require_math_font_write = require("./math-font-write.cjs");
7
+ const require_embedded_font_write = require("./embedded-font-write.cjs");
8
+ const require_embedded_font = require("./embedded-font.cjs");
9
+ //#region src/write-font-objects.ts
10
+ function emitFontObjects(state) {
11
+ const { objects, formulas, mathFontAlloc, embeddedAllocs, compress } = state;
12
+ const mathFont = mathFontAlloc === void 0 ? void 0 : require_math_font.loadMathFont();
13
+ const usedGlyphs = mathFontAlloc === void 0 || mathFont === void 0 ? void 0 : require_math_content_write.collectUsedGlyphs(formulas, mathFont.font);
14
+ if (mathFontAlloc !== void 0 && mathFont !== void 0 && usedGlyphs !== void 0) {
15
+ const built = require_math_font_write.buildMathFontObjects(mathFont.font, usedGlyphs, {
16
+ cidFontRef: require_objects.pdfRef(mathFontAlloc.cidFontNum, 0),
17
+ descriptorRef: require_objects.pdfRef(mathFontAlloc.descriptorNum, 0),
18
+ fontFileRef: require_objects.pdfRef(mathFontAlloc.fontFileNum, 0),
19
+ toUnicodeRef: require_objects.pdfRef(mathFontAlloc.toUnicodeNum, 0)
20
+ }, compress);
21
+ objects.push({
22
+ num: mathFontAlloc.type0Num,
23
+ value: built.type0
24
+ });
25
+ objects.push({
26
+ num: mathFontAlloc.cidFontNum,
27
+ value: built.cidFont
28
+ });
29
+ objects.push({
30
+ num: mathFontAlloc.descriptorNum,
31
+ value: built.descriptor
32
+ });
33
+ objects.push({
34
+ num: mathFontAlloc.fontFileNum,
35
+ value: built.fontFile
36
+ });
37
+ objects.push({
38
+ num: mathFontAlloc.toUnicodeNum,
39
+ value: built.toUnicode
40
+ });
41
+ }
42
+ for (const [face, alloc] of embeddedAllocs) {
43
+ const faceUsedGlyphs = require_embedded_font.collectEmbeddedGlyphs(alloc.texts, face);
44
+ const subset = require_sfnt_subset.subsetSfnt(face.font, [...alloc.codePoints], [...faceUsedGlyphs.keys()]);
45
+ if (subset === void 0) throw new Error(`font "${face.postScriptName}" resolved to an embeddable face, but its glyph outlines could not be subsetted — only TrueType-outline ('glyf') fonts can be embedded, so supply a TrueType face for this family or drop it from the registry`);
46
+ const built = require_embedded_font_write.buildEmbeddedFontObjects(face, subset, faceUsedGlyphs, {
47
+ cidFontRef: require_objects.pdfRef(alloc.cidFontNum, 0),
48
+ descriptorRef: require_objects.pdfRef(alloc.descriptorNum, 0),
49
+ fontFileRef: require_objects.pdfRef(alloc.fontFileNum, 0),
50
+ toUnicodeRef: require_objects.pdfRef(alloc.toUnicodeNum, 0)
51
+ }, compress);
52
+ objects.push({
53
+ num: alloc.type0Num,
54
+ value: built.type0
55
+ });
56
+ objects.push({
57
+ num: alloc.cidFontNum,
58
+ value: built.cidFont
59
+ });
60
+ objects.push({
61
+ num: alloc.descriptorNum,
62
+ value: built.descriptor
63
+ });
64
+ objects.push({
65
+ num: alloc.fontFileNum,
66
+ value: built.fontFile
67
+ });
68
+ objects.push({
69
+ num: alloc.toUnicodeNum,
70
+ value: built.toUnicode
71
+ });
72
+ }
73
+ return mathFont === void 0 ? void 0 : { font: mathFont };
74
+ }
75
+ //#endregion
76
+ exports.emitFontObjects = emitFontObjects;
@@ -0,0 +1,35 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ import { t as EmbeddedFace } from "./embedded-font-CqePfvrl.cjs";
3
+ import { loadMathFont } from "./math-font.cjs";
4
+ import { PositionedFormula } from "document-schema.js";
5
+ //#region src/write-font-objects.d.ts
6
+ interface FontObjectEmitState {
7
+ readonly objects: {
8
+ num: number;
9
+ value: PdfObject;
10
+ }[];
11
+ readonly formulas: readonly PositionedFormula[];
12
+ readonly mathFontAlloc: {
13
+ type0Num: number;
14
+ cidFontNum: number;
15
+ descriptorNum: number;
16
+ fontFileNum: number;
17
+ toUnicodeNum: number;
18
+ } | undefined;
19
+ readonly embeddedAllocs: Iterable<[EmbeddedFace, {
20
+ type0Num: number;
21
+ cidFontNum: number;
22
+ descriptorNum: number;
23
+ fontFileNum: number;
24
+ toUnicodeNum: number;
25
+ texts: readonly string[];
26
+ resourceName: string;
27
+ codePoints: ReadonlySet<number>;
28
+ }]>;
29
+ readonly compress: boolean;
30
+ }
31
+ declare function emitFontObjects(state: FontObjectEmitState): {
32
+ font: ReturnType<typeof loadMathFont>;
33
+ } | undefined;
34
+ //#endregion
35
+ export { FontObjectEmitState, emitFontObjects };
@@ -0,0 +1,35 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ import { t as EmbeddedFace } from "./embedded-font-CQZbTTDM.js";
3
+ import { loadMathFont } from "./math-font.js";
4
+ import { PositionedFormula } from "document-schema.js";
5
+ //#region src/write-font-objects.d.ts
6
+ interface FontObjectEmitState {
7
+ readonly objects: {
8
+ num: number;
9
+ value: PdfObject;
10
+ }[];
11
+ readonly formulas: readonly PositionedFormula[];
12
+ readonly mathFontAlloc: {
13
+ type0Num: number;
14
+ cidFontNum: number;
15
+ descriptorNum: number;
16
+ fontFileNum: number;
17
+ toUnicodeNum: number;
18
+ } | undefined;
19
+ readonly embeddedAllocs: Iterable<[EmbeddedFace, {
20
+ type0Num: number;
21
+ cidFontNum: number;
22
+ descriptorNum: number;
23
+ fontFileNum: number;
24
+ toUnicodeNum: number;
25
+ texts: readonly string[];
26
+ resourceName: string;
27
+ codePoints: ReadonlySet<number>;
28
+ }]>;
29
+ readonly compress: boolean;
30
+ }
31
+ declare function emitFontObjects(state: FontObjectEmitState): {
32
+ font: ReturnType<typeof loadMathFont>;
33
+ } | undefined;
34
+ //#endregion
35
+ export { FontObjectEmitState, emitFontObjects };
@@ -0,0 +1,75 @@
1
+ import { pdfRef } from "./objects.js";
2
+ import { collectUsedGlyphs } from "./math-content-write.js";
3
+ import { loadMathFont } from "./math-font.js";
4
+ import { subsetSfnt } from "./sfnt-subset.js";
5
+ import { buildMathFontObjects } from "./math-font-write.js";
6
+ import { buildEmbeddedFontObjects } from "./embedded-font-write.js";
7
+ import { collectEmbeddedGlyphs } from "./embedded-font.js";
8
+ //#region src/write-font-objects.ts
9
+ function emitFontObjects(state) {
10
+ const { objects, formulas, mathFontAlloc, embeddedAllocs, compress } = state;
11
+ const mathFont = mathFontAlloc === void 0 ? void 0 : loadMathFont();
12
+ const usedGlyphs = mathFontAlloc === void 0 || mathFont === void 0 ? void 0 : collectUsedGlyphs(formulas, mathFont.font);
13
+ if (mathFontAlloc !== void 0 && mathFont !== void 0 && usedGlyphs !== void 0) {
14
+ const built = buildMathFontObjects(mathFont.font, usedGlyphs, {
15
+ cidFontRef: pdfRef(mathFontAlloc.cidFontNum, 0),
16
+ descriptorRef: pdfRef(mathFontAlloc.descriptorNum, 0),
17
+ fontFileRef: pdfRef(mathFontAlloc.fontFileNum, 0),
18
+ toUnicodeRef: pdfRef(mathFontAlloc.toUnicodeNum, 0)
19
+ }, compress);
20
+ objects.push({
21
+ num: mathFontAlloc.type0Num,
22
+ value: built.type0
23
+ });
24
+ objects.push({
25
+ num: mathFontAlloc.cidFontNum,
26
+ value: built.cidFont
27
+ });
28
+ objects.push({
29
+ num: mathFontAlloc.descriptorNum,
30
+ value: built.descriptor
31
+ });
32
+ objects.push({
33
+ num: mathFontAlloc.fontFileNum,
34
+ value: built.fontFile
35
+ });
36
+ objects.push({
37
+ num: mathFontAlloc.toUnicodeNum,
38
+ value: built.toUnicode
39
+ });
40
+ }
41
+ for (const [face, alloc] of embeddedAllocs) {
42
+ const faceUsedGlyphs = collectEmbeddedGlyphs(alloc.texts, face);
43
+ const subset = subsetSfnt(face.font, [...alloc.codePoints], [...faceUsedGlyphs.keys()]);
44
+ if (subset === void 0) throw new Error(`font "${face.postScriptName}" resolved to an embeddable face, but its glyph outlines could not be subsetted — only TrueType-outline ('glyf') fonts can be embedded, so supply a TrueType face for this family or drop it from the registry`);
45
+ const built = buildEmbeddedFontObjects(face, subset, faceUsedGlyphs, {
46
+ cidFontRef: pdfRef(alloc.cidFontNum, 0),
47
+ descriptorRef: pdfRef(alloc.descriptorNum, 0),
48
+ fontFileRef: pdfRef(alloc.fontFileNum, 0),
49
+ toUnicodeRef: pdfRef(alloc.toUnicodeNum, 0)
50
+ }, compress);
51
+ objects.push({
52
+ num: alloc.type0Num,
53
+ value: built.type0
54
+ });
55
+ objects.push({
56
+ num: alloc.cidFontNum,
57
+ value: built.cidFont
58
+ });
59
+ objects.push({
60
+ num: alloc.descriptorNum,
61
+ value: built.descriptor
62
+ });
63
+ objects.push({
64
+ num: alloc.fontFileNum,
65
+ value: built.fontFile
66
+ });
67
+ objects.push({
68
+ num: alloc.toUnicodeNum,
69
+ value: built.toUnicode
70
+ });
71
+ }
72
+ return mathFont === void 0 ? void 0 : { font: mathFont };
73
+ }
74
+ //#endregion
75
+ export { emitFontObjects };
@@ -0,0 +1,91 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objects = require("./objects.cjs");
3
+ //#region src/write-form.ts
4
+ function noteWidgetAnnot(state, widget, ref) {
5
+ const existing = state.widgetAnnotsByPage.get(widget.pageIndex);
6
+ if (existing === void 0) state.widgetAnnotsByPage.set(widget.pageIndex, [ref]);
7
+ else existing.push(ref);
8
+ }
9
+ function widgetRectArray(widget) {
10
+ return require_objects.pdfArray([
11
+ widget.xPt,
12
+ widget.yPt,
13
+ widget.xPt + widget.widthPt,
14
+ widget.yPt + widget.heightPt
15
+ ].map((n) => require_objects.pdfNum(n)));
16
+ }
17
+ function widgetDict(state, widget) {
18
+ return require_objects.pdfDict({
19
+ Subtype: require_objects.pdfName("Widget"),
20
+ Rect: widgetRectArray(widget),
21
+ P: require_objects.pdfRef(state.pageAllocs[widget.pageIndex].pageNum, 0)
22
+ });
23
+ }
24
+ const FIELD_TYPE_PDF_NAME = {
25
+ text: "Tx",
26
+ checkbox: "Btn",
27
+ radio: "Btn",
28
+ button: "Btn",
29
+ listbox: "Ch",
30
+ combobox: "Ch",
31
+ signature: "Sig"
32
+ };
33
+ function emitFormObjectsWalk(state, fields, parentName) {
34
+ for (const field of fields) {
35
+ const ownName = parentName === void 0 ? field.name : field.name.startsWith(`${parentName}.`) ? field.name.slice(parentName.length + 1) : field.name;
36
+ const entries = [];
37
+ if (ownName.length > 0) entries.push(["T", require_objects.pdfLiteralString(new TextEncoder().encode(ownName))]);
38
+ if (field.alias !== void 0) entries.push(["TU", require_objects.pdfLiteralString(new TextEncoder().encode(field.alias))]);
39
+ if (field.fieldType === "group") entries.push(["Kids", require_objects.pdfArray(field.children.map((child) => require_objects.pdfRef(state.formNumOf(child), 0)))]);
40
+ else {
41
+ entries.push(["FT", require_objects.pdfName(FIELD_TYPE_PDF_NAME[field.fieldType])]);
42
+ const FLAG_READ_ONLY = 1;
43
+ const FLAG_PUSHBUTTON = 4;
44
+ const FLAG_RADIO = 32768;
45
+ const FLAG_COMBO = 131072;
46
+ let flags = 0;
47
+ if (field.readOnly === true) flags |= FLAG_READ_ONLY;
48
+ if (field.fieldType === "button") flags |= FLAG_PUSHBUTTON;
49
+ if (field.fieldType === "radio") flags |= FLAG_RADIO;
50
+ if (field.fieldType === "combobox") flags |= FLAG_COMBO;
51
+ if (flags !== 0) entries.push(["Ff", require_objects.pdfNum(flags)]);
52
+ if (field.fieldType === "text" || field.fieldType === "listbox" || field.fieldType === "combobox") {
53
+ if (field.value !== void 0) entries.push(["V", require_objects.pdfLiteralString(new TextEncoder().encode(field.value))]);
54
+ } else if (field.fieldType === "checkbox" || field.fieldType === "radio") entries.push(["V", require_objects.pdfName(field.value ?? (field.checked === true ? "Yes" : "Off"))]);
55
+ if (field.options !== void 0) entries.push(["Opt", require_objects.pdfArray(field.options.map((option) => require_objects.pdfLiteralString(new TextEncoder().encode(option))))]);
56
+ const firstWidget = field.widgets[0];
57
+ if (field.widgets.length === 1 && firstWidget !== void 0) {
58
+ entries.push(["Subtype", require_objects.pdfName("Widget")]);
59
+ entries.push(["Rect", widgetRectArray(firstWidget)]);
60
+ entries.push(["P", require_objects.pdfRef(state.pageAllocs[firstWidget.pageIndex].pageNum, 0)]);
61
+ noteWidgetAnnot(state, firstWidget, require_objects.pdfRef(state.formNumOf(field), 0));
62
+ } else if (state.formExtraWidgetNums.has(field)) {
63
+ const extraNums = state.formExtraWidgetNums.get(field) ?? [];
64
+ entries.push(["Kids", require_objects.pdfArray(extraNums.map((num) => require_objects.pdfRef(num, 0)))]);
65
+ for (const [index, num] of extraNums.entries()) {
66
+ const widget = field.widgets[index];
67
+ if (widget !== void 0) noteWidgetAnnot(state, widget, require_objects.pdfRef(num, 0));
68
+ }
69
+ }
70
+ }
71
+ state.objects.push({
72
+ num: state.formNumOf(field),
73
+ value: require_objects.pdfDict(Object.fromEntries(entries))
74
+ });
75
+ const extraNums = state.formExtraWidgetNums.get(field) ?? [];
76
+ for (const [index, num] of extraNums.entries()) {
77
+ const widget = field.widgets[index];
78
+ if (widget !== void 0) state.objects.push({
79
+ num,
80
+ value: widgetDict(state, widget)
81
+ });
82
+ }
83
+ emitFormObjectsWalk(state, field.children, field.name);
84
+ }
85
+ }
86
+ function emitFormObjects(state, fields) {
87
+ emitFormObjectsWalk(state, fields, void 0);
88
+ }
89
+ //#endregion
90
+ exports.emitFormObjects = emitFormObjects;
91
+ exports.emitFormObjectsWalk = emitFormObjectsWalk;
@@ -0,0 +1,19 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.cjs";
2
+ import { LayoutFormField } from "./layout.cjs";
3
+ //#region src/write-form.d.ts
4
+ interface FormEmitState {
5
+ readonly objects: {
6
+ num: number;
7
+ value: PdfObject;
8
+ }[];
9
+ readonly widgetAnnotsByPage: Map<number, PdfObject[]>;
10
+ readonly pageAllocs: readonly {
11
+ pageNum: number;
12
+ }[];
13
+ readonly formNumOf: (field: LayoutFormField) => number;
14
+ readonly formExtraWidgetNums: ReadonlyMap<LayoutFormField, number[]>;
15
+ }
16
+ declare function emitFormObjectsWalk(state: FormEmitState, fields: readonly LayoutFormField[], parentName: string | undefined): void;
17
+ declare function emitFormObjects(state: FormEmitState, fields: readonly LayoutFormField[]): void;
18
+ //#endregion
19
+ export { FormEmitState, emitFormObjects, emitFormObjectsWalk };
@@ -0,0 +1,19 @@
1
+ import { r as PdfObject } from "./objects-e2RS3-yT.js";
2
+ import { LayoutFormField } from "./layout.js";
3
+ //#region src/write-form.d.ts
4
+ interface FormEmitState {
5
+ readonly objects: {
6
+ num: number;
7
+ value: PdfObject;
8
+ }[];
9
+ readonly widgetAnnotsByPage: Map<number, PdfObject[]>;
10
+ readonly pageAllocs: readonly {
11
+ pageNum: number;
12
+ }[];
13
+ readonly formNumOf: (field: LayoutFormField) => number;
14
+ readonly formExtraWidgetNums: ReadonlyMap<LayoutFormField, number[]>;
15
+ }
16
+ declare function emitFormObjectsWalk(state: FormEmitState, fields: readonly LayoutFormField[], parentName: string | undefined): void;
17
+ declare function emitFormObjects(state: FormEmitState, fields: readonly LayoutFormField[]): void;
18
+ //#endregion
19
+ export { FormEmitState, emitFormObjects, emitFormObjectsWalk };
@@ -0,0 +1,89 @@
1
+ import { pdfArray, pdfDict, pdfLiteralString, pdfName, pdfNum, pdfRef } from "./objects.js";
2
+ //#region src/write-form.ts
3
+ function noteWidgetAnnot(state, widget, ref) {
4
+ const existing = state.widgetAnnotsByPage.get(widget.pageIndex);
5
+ if (existing === void 0) state.widgetAnnotsByPage.set(widget.pageIndex, [ref]);
6
+ else existing.push(ref);
7
+ }
8
+ function widgetRectArray(widget) {
9
+ return pdfArray([
10
+ widget.xPt,
11
+ widget.yPt,
12
+ widget.xPt + widget.widthPt,
13
+ widget.yPt + widget.heightPt
14
+ ].map((n) => pdfNum(n)));
15
+ }
16
+ function widgetDict(state, widget) {
17
+ return pdfDict({
18
+ Subtype: pdfName("Widget"),
19
+ Rect: widgetRectArray(widget),
20
+ P: pdfRef(state.pageAllocs[widget.pageIndex].pageNum, 0)
21
+ });
22
+ }
23
+ const FIELD_TYPE_PDF_NAME = {
24
+ text: "Tx",
25
+ checkbox: "Btn",
26
+ radio: "Btn",
27
+ button: "Btn",
28
+ listbox: "Ch",
29
+ combobox: "Ch",
30
+ signature: "Sig"
31
+ };
32
+ function emitFormObjectsWalk(state, fields, parentName) {
33
+ for (const field of fields) {
34
+ const ownName = parentName === void 0 ? field.name : field.name.startsWith(`${parentName}.`) ? field.name.slice(parentName.length + 1) : field.name;
35
+ const entries = [];
36
+ if (ownName.length > 0) entries.push(["T", pdfLiteralString(new TextEncoder().encode(ownName))]);
37
+ if (field.alias !== void 0) entries.push(["TU", pdfLiteralString(new TextEncoder().encode(field.alias))]);
38
+ if (field.fieldType === "group") entries.push(["Kids", pdfArray(field.children.map((child) => pdfRef(state.formNumOf(child), 0)))]);
39
+ else {
40
+ entries.push(["FT", pdfName(FIELD_TYPE_PDF_NAME[field.fieldType])]);
41
+ const FLAG_READ_ONLY = 1;
42
+ const FLAG_PUSHBUTTON = 4;
43
+ const FLAG_RADIO = 32768;
44
+ const FLAG_COMBO = 131072;
45
+ let flags = 0;
46
+ if (field.readOnly === true) flags |= FLAG_READ_ONLY;
47
+ if (field.fieldType === "button") flags |= FLAG_PUSHBUTTON;
48
+ if (field.fieldType === "radio") flags |= FLAG_RADIO;
49
+ if (field.fieldType === "combobox") flags |= FLAG_COMBO;
50
+ if (flags !== 0) entries.push(["Ff", pdfNum(flags)]);
51
+ if (field.fieldType === "text" || field.fieldType === "listbox" || field.fieldType === "combobox") {
52
+ if (field.value !== void 0) entries.push(["V", pdfLiteralString(new TextEncoder().encode(field.value))]);
53
+ } else if (field.fieldType === "checkbox" || field.fieldType === "radio") entries.push(["V", pdfName(field.value ?? (field.checked === true ? "Yes" : "Off"))]);
54
+ if (field.options !== void 0) entries.push(["Opt", pdfArray(field.options.map((option) => pdfLiteralString(new TextEncoder().encode(option))))]);
55
+ const firstWidget = field.widgets[0];
56
+ if (field.widgets.length === 1 && firstWidget !== void 0) {
57
+ entries.push(["Subtype", pdfName("Widget")]);
58
+ entries.push(["Rect", widgetRectArray(firstWidget)]);
59
+ entries.push(["P", pdfRef(state.pageAllocs[firstWidget.pageIndex].pageNum, 0)]);
60
+ noteWidgetAnnot(state, firstWidget, pdfRef(state.formNumOf(field), 0));
61
+ } else if (state.formExtraWidgetNums.has(field)) {
62
+ const extraNums = state.formExtraWidgetNums.get(field) ?? [];
63
+ entries.push(["Kids", pdfArray(extraNums.map((num) => pdfRef(num, 0)))]);
64
+ for (const [index, num] of extraNums.entries()) {
65
+ const widget = field.widgets[index];
66
+ if (widget !== void 0) noteWidgetAnnot(state, widget, pdfRef(num, 0));
67
+ }
68
+ }
69
+ }
70
+ state.objects.push({
71
+ num: state.formNumOf(field),
72
+ value: pdfDict(Object.fromEntries(entries))
73
+ });
74
+ const extraNums = state.formExtraWidgetNums.get(field) ?? [];
75
+ for (const [index, num] of extraNums.entries()) {
76
+ const widget = field.widgets[index];
77
+ if (widget !== void 0) state.objects.push({
78
+ num,
79
+ value: widgetDict(state, widget)
80
+ });
81
+ }
82
+ emitFormObjectsWalk(state, field.children, field.name);
83
+ }
84
+ }
85
+ function emitFormObjects(state, fields) {
86
+ emitFormObjectsWalk(state, fields, void 0);
87
+ }
88
+ //#endregion
89
+ export { emitFormObjects, emitFormObjectsWalk };
@@ -0,0 +1,148 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_objects = require("./objects.cjs");
3
+ const require_bytes_flate = require("./bytes/flate.cjs");
4
+ const require_image_ccitt_encode = require("./image/ccitt-encode.cjs");
5
+ const require_image_png_decode = require("./image/png-decode.cjs");
6
+ const require_image_jpeg_info = require("./image/jpeg-info.cjs");
7
+ let byte_codec = require("byte-codec");
8
+ //#region src/write-images.ts
9
+ const BITS_PER_BYTE = 8;
10
+ const BYTE_SHIFT = Math.log2(8);
11
+ const BYTE_MASK = 255;
12
+ const PACKED_BIT_MSB_MASK = 128;
13
+ const BIT_INDEX_MASK = 7;
14
+ const JPEG_COMPONENTS_CMYK = 4;
15
+ function prepareJpegImage(bytes) {
16
+ const info = require_image_jpeg_info.readJpegInfo(bytes);
17
+ const colorSpace = info.components === 1 ? "DeviceGray" : info.components === JPEG_COMPONENTS_CMYK ? "DeviceCMYK" : "DeviceRGB";
18
+ const entries = /* @__PURE__ */ new Map([
19
+ ["Type", require_objects.pdfName("XObject")],
20
+ ["Subtype", require_objects.pdfName("Image")],
21
+ ["Width", require_objects.pdfNum(info.width)],
22
+ ["Height", require_objects.pdfNum(info.height)],
23
+ ["ColorSpace", require_objects.pdfName(colorSpace)],
24
+ ["BitsPerComponent", require_objects.pdfNum(info.precision)],
25
+ ["Filter", require_objects.pdfName("DCTDecode")]
26
+ ]);
27
+ if (info.components === JPEG_COMPONENTS_CMYK && (info.adobeTransform === 2 || info.adobeTransform === void 0)) entries.set("Decode", require_objects.pdfArray([
28
+ 1,
29
+ 0,
30
+ 1,
31
+ 0,
32
+ 1,
33
+ 0,
34
+ 1,
35
+ 0
36
+ ].map((n) => require_objects.pdfNum(n))));
37
+ return {
38
+ dict: require_objects.pdfDict(entries),
39
+ raw: bytes
40
+ };
41
+ }
42
+ function pngImageDict(width, height, colorSpace, compress) {
43
+ const entries = /* @__PURE__ */ new Map([
44
+ ["Type", require_objects.pdfName("XObject")],
45
+ ["Subtype", require_objects.pdfName("Image")],
46
+ ["Width", require_objects.pdfNum(width)],
47
+ ["Height", require_objects.pdfNum(height)],
48
+ ["ColorSpace", require_objects.pdfName(colorSpace)],
49
+ ["BitsPerComponent", require_objects.pdfNum(8)]
50
+ ]);
51
+ if (compress) entries.set("Filter", require_objects.pdfName("FlateDecode"));
52
+ return require_objects.pdfDict(entries);
53
+ }
54
+ function packBilevel(raw) {
55
+ const rowBytes = raw.width + BIT_INDEX_MASK >> BYTE_SHIFT;
56
+ const packed = new Uint8Array(rowBytes * raw.height);
57
+ const view = new DataView(packed.buffer);
58
+ for (let index = 0; index < raw.data.length; index++) {
59
+ const sample = raw.data[index];
60
+ if (sample !== 0 && sample !== 255) return;
61
+ if (sample === 255) {
62
+ const x = index % raw.width;
63
+ const byteIndex = Math.floor(index / raw.width) * rowBytes + (x >> BYTE_SHIFT);
64
+ view.setUint8(byteIndex, view.getUint8(byteIndex) | PACKED_BIT_MSB_MASK >> (x & BIT_INDEX_MASK));
65
+ }
66
+ }
67
+ return packed;
68
+ }
69
+ function preparePngImage(bytes, compress) {
70
+ const raw = require_image_png_decode.decodePng(bytes);
71
+ const colorSpace = raw.channels === 1 ? "DeviceGray" : "DeviceRGB";
72
+ if (compress && raw.channels === 1 && raw.alpha === void 0) {
73
+ const bilevel = packBilevel(raw);
74
+ if (bilevel !== void 0) {
75
+ const flate = require_bytes_flate.deflate(raw.data);
76
+ const g4 = require_image_ccitt_encode.encodeCcittFax(bilevel, {
77
+ columns: raw.width,
78
+ rows: raw.height,
79
+ maxBytes: flate.length
80
+ });
81
+ if (g4 !== void 0) return {
82
+ dict: require_objects.pdfDict(/* @__PURE__ */ new Map([
83
+ ["Type", require_objects.pdfName("XObject")],
84
+ ["Subtype", require_objects.pdfName("Image")],
85
+ ["Width", require_objects.pdfNum(raw.width)],
86
+ ["Height", require_objects.pdfNum(raw.height)],
87
+ ["ColorSpace", require_objects.pdfName("DeviceGray")],
88
+ ["BitsPerComponent", require_objects.pdfNum(1)],
89
+ ["Filter", require_objects.pdfName("CCITTFaxDecode")],
90
+ ["DecodeParms", require_objects.pdfDict(/* @__PURE__ */ new Map([
91
+ ["K", require_objects.pdfNum(-1)],
92
+ ["Columns", require_objects.pdfNum(raw.width)],
93
+ ["Rows", require_objects.pdfNum(raw.height)],
94
+ ["BlackIs1", require_objects.pdfBool(false)]
95
+ ]))]
96
+ ])),
97
+ raw: g4,
98
+ alpha: void 0
99
+ };
100
+ return {
101
+ dict: pngImageDict(raw.width, raw.height, colorSpace, true),
102
+ raw: flate,
103
+ alpha: void 0
104
+ };
105
+ }
106
+ }
107
+ return {
108
+ dict: pngImageDict(raw.width, raw.height, colorSpace, compress),
109
+ raw: compress ? require_bytes_flate.deflate(raw.data) : raw.data,
110
+ alpha: raw.alpha === void 0 ? void 0 : {
111
+ dict: pngImageDict(raw.width, raw.height, "DeviceGray", compress),
112
+ raw: compress ? require_bytes_flate.deflate(raw.alpha) : raw.alpha
113
+ }
114
+ };
115
+ }
116
+ function preparePassthroughImage(asset, original, compress) {
117
+ const png = preparePngImage((0, byte_codec.base64ToBytes)(asset.base64), compress);
118
+ const entries = /* @__PURE__ */ new Map([
119
+ ["Type", require_objects.pdfName("XObject")],
120
+ ["Subtype", require_objects.pdfName("Image")],
121
+ ["Width", require_objects.pdfNum(asset.widthPx)],
122
+ ["Height", require_objects.pdfNum(asset.heightPx)],
123
+ ["Filter", require_objects.pdfName(original.filter === "jbig2" ? "JBIG2Decode" : "JPXDecode")]
124
+ ]);
125
+ if (original.filter === "jbig2") {
126
+ entries.set("ColorSpace", require_objects.pdfName("DeviceGray"));
127
+ entries.set("BitsPerComponent", require_objects.pdfNum(1));
128
+ }
129
+ return {
130
+ dict: require_objects.pdfDict(entries),
131
+ raw: (0, byte_codec.base64ToBytes)(original.base64),
132
+ alpha: png.alpha
133
+ };
134
+ }
135
+ function prepareImage(asset, compress) {
136
+ if (asset.original !== void 0) return preparePassthroughImage(asset, asset.original, compress);
137
+ const bytes = (0, byte_codec.base64ToBytes)(asset.base64);
138
+ return asset.format === "jpeg" ? prepareJpegImage(bytes) : preparePngImage(bytes, compress);
139
+ }
140
+ //#endregion
141
+ exports.BITS_PER_BYTE = BITS_PER_BYTE;
142
+ exports.BYTE_MASK = BYTE_MASK;
143
+ exports.packBilevel = packBilevel;
144
+ exports.pngImageDict = pngImageDict;
145
+ exports.prepareImage = prepareImage;
146
+ exports.prepareJpegImage = prepareJpegImage;
147
+ exports.preparePassthroughImage = preparePassthroughImage;
148
+ exports.preparePngImage = preparePngImage;
@@ -0,0 +1,25 @@
1
+ import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
2
+ import { LayoutImageAsset } from "./layout.cjs";
3
+ //#region src/write-images.d.ts
4
+ declare const BITS_PER_BYTE = 8;
5
+ declare const BYTE_MASK: number;
6
+ interface PreparedImage {
7
+ readonly dict: PdfDict;
8
+ readonly raw: Uint8Array<ArrayBuffer>;
9
+ readonly alpha?: {
10
+ readonly dict: PdfDict;
11
+ readonly raw: Uint8Array<ArrayBuffer>;
12
+ };
13
+ }
14
+ declare function prepareJpegImage(bytes: Uint8Array<ArrayBuffer>): PreparedImage;
15
+ declare function pngImageDict(width: number, height: number, colorSpace: "DeviceGray" | "DeviceRGB", compress: boolean): PdfDict;
16
+ declare function packBilevel(raw: {
17
+ readonly width: number;
18
+ readonly height: number;
19
+ readonly data: Uint8Array;
20
+ }): Uint8Array | undefined;
21
+ declare function preparePngImage(bytes: Uint8Array<ArrayBuffer>, compress: boolean): PreparedImage;
22
+ declare function preparePassthroughImage(asset: LayoutImageAsset, original: Readonly<NonNullable<LayoutImageAsset["original"]>>, compress: boolean): PreparedImage;
23
+ declare function prepareImage(asset: LayoutImageAsset, compress: boolean): PreparedImage;
24
+ //#endregion
25
+ export { BITS_PER_BYTE, BYTE_MASK, PreparedImage, packBilevel, pngImageDict, prepareImage, prepareJpegImage, preparePassthroughImage, preparePngImage };
@@ -0,0 +1,25 @@
1
+ import { n as PdfDict } from "./objects-e2RS3-yT.js";
2
+ import { LayoutImageAsset } from "./layout.js";
3
+ //#region src/write-images.d.ts
4
+ declare const BITS_PER_BYTE = 8;
5
+ declare const BYTE_MASK: number;
6
+ interface PreparedImage {
7
+ readonly dict: PdfDict;
8
+ readonly raw: Uint8Array<ArrayBuffer>;
9
+ readonly alpha?: {
10
+ readonly dict: PdfDict;
11
+ readonly raw: Uint8Array<ArrayBuffer>;
12
+ };
13
+ }
14
+ declare function prepareJpegImage(bytes: Uint8Array<ArrayBuffer>): PreparedImage;
15
+ declare function pngImageDict(width: number, height: number, colorSpace: "DeviceGray" | "DeviceRGB", compress: boolean): PdfDict;
16
+ declare function packBilevel(raw: {
17
+ readonly width: number;
18
+ readonly height: number;
19
+ readonly data: Uint8Array;
20
+ }): Uint8Array | undefined;
21
+ declare function preparePngImage(bytes: Uint8Array<ArrayBuffer>, compress: boolean): PreparedImage;
22
+ declare function preparePassthroughImage(asset: LayoutImageAsset, original: Readonly<NonNullable<LayoutImageAsset["original"]>>, compress: boolean): PreparedImage;
23
+ declare function prepareImage(asset: LayoutImageAsset, compress: boolean): PreparedImage;
24
+ //#endregion
25
+ export { BITS_PER_BYTE, BYTE_MASK, PreparedImage, packBilevel, pngImageDict, prepareImage, prepareJpegImage, preparePassthroughImage, preparePngImage };