pdf-codec 1.3.1 → 1.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.
Files changed (198) hide show
  1. package/README.md +9 -0
  2. package/dist/afm-widths-BoeTOK2r.cjs +826 -0
  3. package/dist/afm-widths-Dxucrg7D.js +779 -0
  4. package/dist/afm-widths-DyDq56Ph.d.cts +19 -0
  5. package/dist/afm-widths-DyDq56Ph.d.ts +19 -0
  6. package/dist/afm-widths.cjs +4 -0
  7. package/dist/afm-widths.d.cts +2 -0
  8. package/dist/afm-widths.d.ts +2 -0
  9. package/dist/afm-widths.js +2 -0
  10. package/dist/assets/stix-two-math-font.cjs +5 -0
  11. package/dist/assets/stix-two-math-font.d.cts +4 -0
  12. package/dist/assets/stix-two-math-font.d.ts +4 -0
  13. package/dist/assets/stix-two-math-font.js +4 -0
  14. package/dist/bytes/crc32.cjs +21 -0
  15. package/dist/bytes/crc32.d.cts +4 -0
  16. package/dist/bytes/crc32.d.ts +4 -0
  17. package/dist/bytes/crc32.js +20 -0
  18. package/dist/bytes/flate.cjs +53 -0
  19. package/dist/bytes/flate.d.cts +12 -0
  20. package/dist/bytes/flate.d.ts +12 -0
  21. package/dist/bytes/flate.js +49 -0
  22. package/dist/bytes/reader.cjs +60 -0
  23. package/dist/bytes/reader.d.cts +20 -0
  24. package/dist/bytes/reader.d.ts +20 -0
  25. package/dist/bytes/reader.js +58 -0
  26. package/dist/bytes/writer.cjs +37 -0
  27. package/dist/bytes/writer.d.cts +13 -0
  28. package/dist/bytes/writer.d.ts +13 -0
  29. package/dist/bytes/writer.js +35 -0
  30. package/dist/cmap.cjs +110 -0
  31. package/dist/cmap.d.cts +8 -0
  32. package/dist/cmap.d.ts +8 -0
  33. package/dist/cmap.js +109 -0
  34. package/dist/codec.cjs +34 -0
  35. package/dist/codec.d.cts +167 -0
  36. package/dist/codec.d.ts +167 -0
  37. package/dist/codec.js +32 -0
  38. package/dist/content-read.cjs +126 -0
  39. package/dist/content-read.d.cts +21 -0
  40. package/dist/content-read.d.ts +21 -0
  41. package/dist/content-read.js +125 -0
  42. package/dist/content-write.cjs +138 -0
  43. package/dist/content-write.d.cts +24 -0
  44. package/dist/content-write.d.ts +24 -0
  45. package/dist/content-write.js +137 -0
  46. package/dist/diagnostics.cjs +21 -0
  47. package/dist/diagnostics.d.cts +19 -0
  48. package/dist/diagnostics.d.ts +19 -0
  49. package/dist/diagnostics.js +18 -0
  50. package/dist/document.cjs +162 -0
  51. package/dist/document.d.cts +12 -0
  52. package/dist/document.d.ts +12 -0
  53. package/dist/document.js +161 -0
  54. package/dist/encoding.cjs +5 -0
  55. package/dist/encoding.d.cts +6 -0
  56. package/dist/encoding.d.ts +6 -0
  57. package/dist/encoding.js +2 -0
  58. package/dist/filters.cjs +223 -0
  59. package/dist/filters.d.cts +14 -0
  60. package/dist/filters.d.ts +14 -0
  61. package/dist/filters.js +218 -0
  62. package/dist/font-read.cjs +199 -0
  63. package/dist/font-read.d.cts +23 -0
  64. package/dist/font-read.d.ts +23 -0
  65. package/dist/font-read.js +198 -0
  66. package/dist/font-style.cjs +35 -0
  67. package/dist/font-style.d.cts +14 -0
  68. package/dist/font-style.d.ts +14 -0
  69. package/dist/font-style.js +34 -0
  70. package/dist/fonts.cjs +124 -0
  71. package/dist/fonts.d.cts +15 -0
  72. package/dist/fonts.d.ts +15 -0
  73. package/dist/fonts.js +122 -0
  74. package/dist/formula.cjs +0 -0
  75. package/dist/formula.d.cts +10 -0
  76. package/dist/formula.d.ts +10 -0
  77. package/dist/formula.js +0 -0
  78. package/dist/image/jpeg-info.cjs +71 -0
  79. package/dist/image/jpeg-info.d.cts +12 -0
  80. package/dist/image/jpeg-info.d.ts +12 -0
  81. package/dist/image/jpeg-info.js +70 -0
  82. package/dist/image/png-decode.cjs +181 -0
  83. package/dist/image/png-decode.d.cts +14 -0
  84. package/dist/image/png-decode.d.ts +14 -0
  85. package/dist/image/png-decode.js +180 -0
  86. package/dist/image/png-encode.cjs +64 -0
  87. package/dist/image/png-encode.d.cts +8 -0
  88. package/dist/image/png-encode.d.ts +8 -0
  89. package/dist/image/png-encode.js +63 -0
  90. package/dist/image/png-filter.cjs +95 -0
  91. package/dist/image/png-filter.d.cts +6 -0
  92. package/dist/image/png-filter.d.ts +6 -0
  93. package/dist/image/png-filter.js +93 -0
  94. package/dist/images-read.cjs +250 -0
  95. package/dist/images-read.d.cts +13 -0
  96. package/dist/images-read.d.ts +13 -0
  97. package/dist/images-read.js +249 -0
  98. package/dist/index.cjs +45 -5912
  99. package/dist/index.d.cts +21 -483
  100. package/dist/index.d.ts +21 -483
  101. package/dist/index.js +18 -5885
  102. package/dist/interpret.cjs +587 -0
  103. package/dist/interpret.d.cts +84 -0
  104. package/dist/interpret.d.ts +84 -0
  105. package/dist/interpret.js +586 -0
  106. package/dist/lexer.cjs +180 -0
  107. package/dist/lexer.d.cts +29 -0
  108. package/dist/lexer.d.ts +29 -0
  109. package/dist/lexer.js +179 -0
  110. package/dist/math-cmap.cjs +81 -0
  111. package/dist/math-cmap.d.cts +6 -0
  112. package/dist/math-cmap.d.ts +6 -0
  113. package/dist/math-cmap.js +80 -0
  114. package/dist/math-content-write.cjs +83 -0
  115. package/dist/math-content-write.d.cts +11 -0
  116. package/dist/math-content-write.d.ts +11 -0
  117. package/dist/math-content-write.js +81 -0
  118. package/dist/math-font-write.cjs +100 -0
  119. package/dist/math-font-write.d.cts +19 -0
  120. package/dist/math-font-write.d.ts +19 -0
  121. package/dist/math-font-write.js +99 -0
  122. package/dist/math-font.cjs +103 -0
  123. package/dist/math-font.d.cts +25 -0
  124. package/dist/math-font.d.ts +25 -0
  125. package/dist/math-font.js +102 -0
  126. package/dist/math-hmtx.cjs +17 -0
  127. package/dist/math-hmtx.d.cts +8 -0
  128. package/dist/math-hmtx.d.ts +8 -0
  129. package/dist/math-hmtx.js +16 -0
  130. package/dist/math-table.cjs +117 -0
  131. package/dist/math-table.d.cts +45 -0
  132. package/dist/math-table.d.ts +45 -0
  133. package/dist/math-table.js +116 -0
  134. package/dist/math-types-Ba8qAf1p.d.cts +82 -0
  135. package/dist/math-types-Ba8qAf1p.d.ts +82 -0
  136. package/dist/math-types.cjs +0 -0
  137. package/dist/math-types.d.cts +2 -0
  138. package/dist/math-types.d.ts +2 -0
  139. package/dist/math-types.js +0 -0
  140. package/dist/matrix-B3c2_a2f.d.cts +18 -0
  141. package/dist/matrix-B3c2_a2f.d.ts +18 -0
  142. package/dist/matrix.cjs +93 -0
  143. package/dist/matrix.d.cts +2 -0
  144. package/dist/matrix.d.ts +2 -0
  145. package/dist/matrix.js +83 -0
  146. package/dist/measure.cjs +54 -0
  147. package/dist/measure.d.cts +20 -0
  148. package/dist/measure.d.ts +20 -0
  149. package/dist/measure.js +53 -0
  150. package/dist/objects.cjs +100 -0
  151. package/dist/objects.d.cts +58 -0
  152. package/dist/objects.d.ts +58 -0
  153. package/dist/objects.js +84 -0
  154. package/dist/parse.cjs +230 -0
  155. package/dist/parse.d.cts +13 -0
  156. package/dist/parse.d.ts +13 -0
  157. package/dist/parse.js +228 -0
  158. package/dist/predictors.cjs +64 -0
  159. package/dist/predictors.d.cts +13 -0
  160. package/dist/predictors.d.ts +13 -0
  161. package/dist/predictors.js +62 -0
  162. package/dist/read.cjs +418 -0
  163. package/dist/read.d.cts +21 -0
  164. package/dist/read.d.ts +21 -0
  165. package/dist/read.js +413 -0
  166. package/dist/serialize.cjs +69 -0
  167. package/dist/serialize.d.cts +8 -0
  168. package/dist/serialize.d.ts +8 -0
  169. package/dist/serialize.js +66 -0
  170. package/dist/sfnt.cjs +52 -0
  171. package/dist/sfnt.d.cts +17 -0
  172. package/dist/sfnt.d.ts +17 -0
  173. package/dist/sfnt.js +46 -0
  174. package/dist/text-layout.cjs +224 -0
  175. package/dist/text-layout.d.cts +37 -0
  176. package/dist/text-layout.d.ts +37 -0
  177. package/dist/text-layout.js +222 -0
  178. package/dist/util/abort.cjs +7 -0
  179. package/dist/util/abort.d.cts +4 -0
  180. package/dist/util/abort.d.ts +4 -0
  181. package/dist/util/abort.js +6 -0
  182. package/dist/util/base64.cjs +48 -0
  183. package/dist/util/base64.d.cts +5 -0
  184. package/dist/util/base64.d.ts +5 -0
  185. package/dist/util/base64.js +46 -0
  186. package/dist/winansi.cjs +5 -0
  187. package/dist/winansi.d.cts +20 -0
  188. package/dist/winansi.d.ts +20 -0
  189. package/dist/winansi.js +2 -0
  190. package/dist/write.cjs +421 -0
  191. package/dist/write.d.cts +16 -0
  192. package/dist/write.d.ts +16 -0
  193. package/dist/write.js +419 -0
  194. package/dist/xref.cjs +325 -0
  195. package/dist/xref.d.cts +21 -0
  196. package/dist/xref.d.ts +21 -0
  197. package/dist/xref.js +324 -0
  198. package/package.json +9 -1
package/dist/matrix.js ADDED
@@ -0,0 +1,83 @@
1
+ //#region src/matrix.ts
2
+ const IDENTITY_MATRIX = [
3
+ 1,
4
+ 0,
5
+ 0,
6
+ 1,
7
+ 0,
8
+ 0
9
+ ];
10
+ function multiplyMatrices(m, n) {
11
+ const [a1, b1, c1, d1, e1, f1] = m;
12
+ const [a2, b2, c2, d2, e2, f2] = n;
13
+ return [
14
+ a1 * a2 + b1 * c2,
15
+ a1 * b2 + b1 * d2,
16
+ c1 * a2 + d1 * c2,
17
+ c1 * b2 + d1 * d2,
18
+ e1 * a2 + f1 * c2 + e2,
19
+ e1 * b2 + f1 * d2 + f2
20
+ ];
21
+ }
22
+ function applyMatrix(m, point) {
23
+ const [a, b, c, d, e, f] = m;
24
+ return {
25
+ x: point.x * a + point.y * c + e,
26
+ y: point.x * b + point.y * d + f
27
+ };
28
+ }
29
+ function translationMatrix(x, y) {
30
+ return [
31
+ 1,
32
+ 0,
33
+ 0,
34
+ 1,
35
+ x,
36
+ y
37
+ ];
38
+ }
39
+ function scaleMatrix(sx, sy) {
40
+ return [
41
+ sx,
42
+ 0,
43
+ 0,
44
+ sy,
45
+ 0,
46
+ 0
47
+ ];
48
+ }
49
+ function rotationMatrix(degrees) {
50
+ const radians = degrees * Math.PI / 180;
51
+ const cos = Math.cos(radians);
52
+ const sin = Math.sin(radians);
53
+ return [
54
+ cos,
55
+ sin,
56
+ -sin,
57
+ cos,
58
+ 0,
59
+ 0
60
+ ];
61
+ }
62
+ function matrixScaleX(m) {
63
+ return Math.hypot(m[0], m[1]);
64
+ }
65
+ function matrixScaleY(m) {
66
+ return Math.hypot(m[2], m[3]);
67
+ }
68
+ function matrixRotationDegrees(m) {
69
+ return Math.atan2(m[1], m[0]) * 180 / Math.PI;
70
+ }
71
+ function rotatePointAboutCenter(point, center, degrees) {
72
+ const relative = {
73
+ x: point.x - center.x,
74
+ y: point.y - center.y
75
+ };
76
+ const rotated = applyMatrix(rotationMatrix(degrees), relative);
77
+ return {
78
+ x: rotated.x + center.x,
79
+ y: rotated.y + center.y
80
+ };
81
+ }
82
+ //#endregion
83
+ export { IDENTITY_MATRIX, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
@@ -0,0 +1,54 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_afm_widths = require("./afm-widths-BoeTOK2r.cjs");
3
+ const require_fonts = require("./fonts.cjs");
4
+ //#region src/measure.ts
5
+ const DEFAULT_WIDTH_CORRECTIONS = {
6
+ calibri: .92,
7
+ aptos: .93,
8
+ aptosdisplay: .93,
9
+ cambria: .96,
10
+ verdana: 1.09,
11
+ tahoma: 1.02
12
+ };
13
+ function normalizeFamilyKey(family) {
14
+ return family.toLowerCase().replace(/[^a-z0-9]/g, "");
15
+ }
16
+ function createStandardFontMeasurer(options = {}) {
17
+ const corrections = {
18
+ ...DEFAULT_WIDTH_CORRECTIONS,
19
+ ...options.widthCorrectionByFamily
20
+ };
21
+ function correctionFor(family) {
22
+ return corrections[normalizeFamilyKey(family)] ?? 1;
23
+ }
24
+ function standardNameFor(font) {
25
+ return require_fonts.resolveStandardFont(font.family, font.weight === "bold", font.style === "italic").standardName;
26
+ }
27
+ return {
28
+ widthOfTextAtSize(text, font, sizePt) {
29
+ const { width1000 } = require_afm_widths.encodeForShow(text, standardNameFor(font));
30
+ return width1000 / 1e3 * sizePt * correctionFor(font.family);
31
+ },
32
+ lineHeightAtSize(font, sizePt) {
33
+ return require_afm_widths.STANDARD_METRICS[standardNameFor(font)].lineHeightEm * sizePt;
34
+ },
35
+ ascenderAtSize(font, sizePt) {
36
+ return require_afm_widths.STANDARD_METRICS[standardNameFor(font)].ascender / 1e3 * sizePt;
37
+ },
38
+ descenderAtSize(font, sizePt) {
39
+ return require_afm_widths.STANDARD_METRICS[standardNameFor(font)].descender / 1e3 * sizePt;
40
+ },
41
+ underlineAtSize(font, sizePt) {
42
+ const metrics = require_afm_widths.STANDARD_METRICS[standardNameFor(font)];
43
+ return {
44
+ offsetPt: metrics.underlinePosition / 1e3 * sizePt,
45
+ thicknessPt: metrics.underlineThickness / 1e3 * sizePt
46
+ };
47
+ },
48
+ horizontalScaleFor(font) {
49
+ return correctionFor(font.family);
50
+ }
51
+ };
52
+ }
53
+ //#endregion
54
+ exports.createStandardFontMeasurer = createStandardFontMeasurer;
@@ -0,0 +1,20 @@
1
+ import { LayoutFont } from "document-schema.js";
2
+ //#region src/measure.d.ts
3
+ interface UnderlineMetrics {
4
+ readonly offsetPt: number;
5
+ readonly thicknessPt: number;
6
+ }
7
+ interface TextMeasurer {
8
+ widthOfTextAtSize(text: string, font: LayoutFont, sizePt: number): number;
9
+ lineHeightAtSize(font: LayoutFont, sizePt: number): number;
10
+ ascenderAtSize(font: LayoutFont, sizePt: number): number;
11
+ descenderAtSize(font: LayoutFont, sizePt: number): number;
12
+ underlineAtSize(font: LayoutFont, sizePt: number): UnderlineMetrics;
13
+ horizontalScaleFor(font: LayoutFont): number;
14
+ }
15
+ interface StandardFontMeasurerOptions {
16
+ readonly widthCorrectionByFamily?: Readonly<Record<string, number>>;
17
+ }
18
+ declare function createStandardFontMeasurer(options?: StandardFontMeasurerOptions): TextMeasurer;
19
+ //#endregion
20
+ export { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer };
@@ -0,0 +1,20 @@
1
+ import { LayoutFont } from "document-schema.js";
2
+ //#region src/measure.d.ts
3
+ interface UnderlineMetrics {
4
+ readonly offsetPt: number;
5
+ readonly thicknessPt: number;
6
+ }
7
+ interface TextMeasurer {
8
+ widthOfTextAtSize(text: string, font: LayoutFont, sizePt: number): number;
9
+ lineHeightAtSize(font: LayoutFont, sizePt: number): number;
10
+ ascenderAtSize(font: LayoutFont, sizePt: number): number;
11
+ descenderAtSize(font: LayoutFont, sizePt: number): number;
12
+ underlineAtSize(font: LayoutFont, sizePt: number): UnderlineMetrics;
13
+ horizontalScaleFor(font: LayoutFont): number;
14
+ }
15
+ interface StandardFontMeasurerOptions {
16
+ readonly widthCorrectionByFamily?: Readonly<Record<string, number>>;
17
+ }
18
+ declare function createStandardFontMeasurer(options?: StandardFontMeasurerOptions): TextMeasurer;
19
+ //#endregion
20
+ export { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer };
@@ -0,0 +1,53 @@
1
+ import { o as encodeForShow, t as STANDARD_METRICS } from "./afm-widths-Dxucrg7D.js";
2
+ import { resolveStandardFont } from "./fonts.js";
3
+ //#region src/measure.ts
4
+ const DEFAULT_WIDTH_CORRECTIONS = {
5
+ calibri: .92,
6
+ aptos: .93,
7
+ aptosdisplay: .93,
8
+ cambria: .96,
9
+ verdana: 1.09,
10
+ tahoma: 1.02
11
+ };
12
+ function normalizeFamilyKey(family) {
13
+ return family.toLowerCase().replace(/[^a-z0-9]/g, "");
14
+ }
15
+ function createStandardFontMeasurer(options = {}) {
16
+ const corrections = {
17
+ ...DEFAULT_WIDTH_CORRECTIONS,
18
+ ...options.widthCorrectionByFamily
19
+ };
20
+ function correctionFor(family) {
21
+ return corrections[normalizeFamilyKey(family)] ?? 1;
22
+ }
23
+ function standardNameFor(font) {
24
+ return resolveStandardFont(font.family, font.weight === "bold", font.style === "italic").standardName;
25
+ }
26
+ return {
27
+ widthOfTextAtSize(text, font, sizePt) {
28
+ const { width1000 } = encodeForShow(text, standardNameFor(font));
29
+ return width1000 / 1e3 * sizePt * correctionFor(font.family);
30
+ },
31
+ lineHeightAtSize(font, sizePt) {
32
+ return STANDARD_METRICS[standardNameFor(font)].lineHeightEm * sizePt;
33
+ },
34
+ ascenderAtSize(font, sizePt) {
35
+ return STANDARD_METRICS[standardNameFor(font)].ascender / 1e3 * sizePt;
36
+ },
37
+ descenderAtSize(font, sizePt) {
38
+ return STANDARD_METRICS[standardNameFor(font)].descender / 1e3 * sizePt;
39
+ },
40
+ underlineAtSize(font, sizePt) {
41
+ const metrics = STANDARD_METRICS[standardNameFor(font)];
42
+ return {
43
+ offsetPt: metrics.underlinePosition / 1e3 * sizePt,
44
+ thicknessPt: metrics.underlineThickness / 1e3 * sizePt
45
+ };
46
+ },
47
+ horizontalScaleFor(font) {
48
+ return correctionFor(font.family);
49
+ }
50
+ };
51
+ }
52
+ //#endregion
53
+ export { createStandardFontMeasurer };
@@ -0,0 +1,100 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/objects.ts
3
+ function pdfNull() {
4
+ return { kind: "null" };
5
+ }
6
+ function pdfBool(value) {
7
+ return {
8
+ kind: "bool",
9
+ value
10
+ };
11
+ }
12
+ function pdfNum(value) {
13
+ return {
14
+ kind: "number",
15
+ value
16
+ };
17
+ }
18
+ function pdfName(name) {
19
+ return {
20
+ kind: "name",
21
+ name
22
+ };
23
+ }
24
+ function pdfHexString(bytes) {
25
+ return {
26
+ kind: "string",
27
+ bytes,
28
+ hex: true
29
+ };
30
+ }
31
+ function pdfLiteralString(bytes) {
32
+ return {
33
+ kind: "string",
34
+ bytes,
35
+ hex: false
36
+ };
37
+ }
38
+ function pdfArray(items) {
39
+ return {
40
+ kind: "array",
41
+ items
42
+ };
43
+ }
44
+ function pdfDict(entries) {
45
+ return {
46
+ kind: "dict",
47
+ entries: entries instanceof Map ? entries : new Map(Object.entries(entries))
48
+ };
49
+ }
50
+ function pdfStream(dict, raw) {
51
+ return {
52
+ kind: "stream",
53
+ dict,
54
+ raw
55
+ };
56
+ }
57
+ function pdfRef(num, gen) {
58
+ return {
59
+ kind: "ref",
60
+ num,
61
+ gen
62
+ };
63
+ }
64
+ function isName(obj, name) {
65
+ return obj?.kind === "name" && obj.name === name;
66
+ }
67
+ function asNumber(obj) {
68
+ return obj?.kind === "number" ? obj.value : void 0;
69
+ }
70
+ function asName(obj) {
71
+ return obj?.kind === "name" ? obj.name : void 0;
72
+ }
73
+ function asArray(obj) {
74
+ return obj?.kind === "array" ? obj.items : void 0;
75
+ }
76
+ function asDict(obj) {
77
+ if (obj === void 0) return;
78
+ if (obj.kind === "dict") return obj;
79
+ if (obj.kind === "stream") return obj.dict;
80
+ }
81
+ function dictGet(dict, key) {
82
+ return dict.entries.get(key);
83
+ }
84
+ //#endregion
85
+ exports.asArray = asArray;
86
+ exports.asDict = asDict;
87
+ exports.asName = asName;
88
+ exports.asNumber = asNumber;
89
+ exports.dictGet = dictGet;
90
+ exports.isName = isName;
91
+ exports.pdfArray = pdfArray;
92
+ exports.pdfBool = pdfBool;
93
+ exports.pdfDict = pdfDict;
94
+ exports.pdfHexString = pdfHexString;
95
+ exports.pdfLiteralString = pdfLiteralString;
96
+ exports.pdfName = pdfName;
97
+ exports.pdfNull = pdfNull;
98
+ exports.pdfNum = pdfNum;
99
+ exports.pdfRef = pdfRef;
100
+ exports.pdfStream = pdfStream;
@@ -0,0 +1,58 @@
1
+ //#region src/objects.d.ts
2
+ type PdfObject = {
3
+ kind: 'null';
4
+ } | {
5
+ kind: 'bool';
6
+ value: boolean;
7
+ } | {
8
+ kind: 'number';
9
+ value: number;
10
+ } | {
11
+ kind: 'name';
12
+ name: string;
13
+ } | {
14
+ kind: 'string';
15
+ bytes: Uint8Array<ArrayBuffer>;
16
+ hex: boolean;
17
+ } | {
18
+ kind: 'array';
19
+ items: PdfObject[];
20
+ } | {
21
+ kind: 'dict';
22
+ entries: Map<string, PdfObject>;
23
+ } | {
24
+ kind: 'stream';
25
+ dict: PdfDict;
26
+ raw: Uint8Array<ArrayBuffer>;
27
+ } | {
28
+ kind: 'ref';
29
+ num: number;
30
+ gen: number;
31
+ };
32
+ type PdfDict = Extract<PdfObject, {
33
+ kind: 'dict';
34
+ }>;
35
+ type PdfArray = Extract<PdfObject, {
36
+ kind: 'array';
37
+ }>;
38
+ type PdfStream = Extract<PdfObject, {
39
+ kind: 'stream';
40
+ }>;
41
+ declare function pdfNull(): PdfObject;
42
+ declare function pdfBool(value: boolean): PdfObject;
43
+ declare function pdfNum(value: number): PdfObject;
44
+ declare function pdfName(name: string): PdfObject;
45
+ declare function pdfHexString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
46
+ declare function pdfLiteralString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
47
+ declare function pdfArray(items: PdfObject[]): PdfObject;
48
+ declare function pdfDict(entries: Record<string, PdfObject> | Map<string, PdfObject>): PdfDict;
49
+ declare function pdfStream(dict: PdfDict, raw: Uint8Array<ArrayBuffer>): PdfObject;
50
+ declare function pdfRef(num: number, gen: number): PdfObject;
51
+ declare function isName(obj: PdfObject | undefined, name: string): boolean;
52
+ declare function asNumber(obj: PdfObject | undefined): number | undefined;
53
+ declare function asName(obj: PdfObject | undefined): string | undefined;
54
+ declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
55
+ declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
56
+ declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
57
+ //#endregion
58
+ export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
@@ -0,0 +1,58 @@
1
+ //#region src/objects.d.ts
2
+ type PdfObject = {
3
+ kind: 'null';
4
+ } | {
5
+ kind: 'bool';
6
+ value: boolean;
7
+ } | {
8
+ kind: 'number';
9
+ value: number;
10
+ } | {
11
+ kind: 'name';
12
+ name: string;
13
+ } | {
14
+ kind: 'string';
15
+ bytes: Uint8Array<ArrayBuffer>;
16
+ hex: boolean;
17
+ } | {
18
+ kind: 'array';
19
+ items: PdfObject[];
20
+ } | {
21
+ kind: 'dict';
22
+ entries: Map<string, PdfObject>;
23
+ } | {
24
+ kind: 'stream';
25
+ dict: PdfDict;
26
+ raw: Uint8Array<ArrayBuffer>;
27
+ } | {
28
+ kind: 'ref';
29
+ num: number;
30
+ gen: number;
31
+ };
32
+ type PdfDict = Extract<PdfObject, {
33
+ kind: 'dict';
34
+ }>;
35
+ type PdfArray = Extract<PdfObject, {
36
+ kind: 'array';
37
+ }>;
38
+ type PdfStream = Extract<PdfObject, {
39
+ kind: 'stream';
40
+ }>;
41
+ declare function pdfNull(): PdfObject;
42
+ declare function pdfBool(value: boolean): PdfObject;
43
+ declare function pdfNum(value: number): PdfObject;
44
+ declare function pdfName(name: string): PdfObject;
45
+ declare function pdfHexString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
46
+ declare function pdfLiteralString(bytes: Uint8Array<ArrayBuffer>): PdfObject;
47
+ declare function pdfArray(items: PdfObject[]): PdfObject;
48
+ declare function pdfDict(entries: Record<string, PdfObject> | Map<string, PdfObject>): PdfDict;
49
+ declare function pdfStream(dict: PdfDict, raw: Uint8Array<ArrayBuffer>): PdfObject;
50
+ declare function pdfRef(num: number, gen: number): PdfObject;
51
+ declare function isName(obj: PdfObject | undefined, name: string): boolean;
52
+ declare function asNumber(obj: PdfObject | undefined): number | undefined;
53
+ declare function asName(obj: PdfObject | undefined): string | undefined;
54
+ declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
55
+ declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
56
+ declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
57
+ //#endregion
58
+ export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
@@ -0,0 +1,84 @@
1
+ //#region src/objects.ts
2
+ function pdfNull() {
3
+ return { kind: "null" };
4
+ }
5
+ function pdfBool(value) {
6
+ return {
7
+ kind: "bool",
8
+ value
9
+ };
10
+ }
11
+ function pdfNum(value) {
12
+ return {
13
+ kind: "number",
14
+ value
15
+ };
16
+ }
17
+ function pdfName(name) {
18
+ return {
19
+ kind: "name",
20
+ name
21
+ };
22
+ }
23
+ function pdfHexString(bytes) {
24
+ return {
25
+ kind: "string",
26
+ bytes,
27
+ hex: true
28
+ };
29
+ }
30
+ function pdfLiteralString(bytes) {
31
+ return {
32
+ kind: "string",
33
+ bytes,
34
+ hex: false
35
+ };
36
+ }
37
+ function pdfArray(items) {
38
+ return {
39
+ kind: "array",
40
+ items
41
+ };
42
+ }
43
+ function pdfDict(entries) {
44
+ return {
45
+ kind: "dict",
46
+ entries: entries instanceof Map ? entries : new Map(Object.entries(entries))
47
+ };
48
+ }
49
+ function pdfStream(dict, raw) {
50
+ return {
51
+ kind: "stream",
52
+ dict,
53
+ raw
54
+ };
55
+ }
56
+ function pdfRef(num, gen) {
57
+ return {
58
+ kind: "ref",
59
+ num,
60
+ gen
61
+ };
62
+ }
63
+ function isName(obj, name) {
64
+ return obj?.kind === "name" && obj.name === name;
65
+ }
66
+ function asNumber(obj) {
67
+ return obj?.kind === "number" ? obj.value : void 0;
68
+ }
69
+ function asName(obj) {
70
+ return obj?.kind === "name" ? obj.name : void 0;
71
+ }
72
+ function asArray(obj) {
73
+ return obj?.kind === "array" ? obj.items : void 0;
74
+ }
75
+ function asDict(obj) {
76
+ if (obj === void 0) return;
77
+ if (obj.kind === "dict") return obj;
78
+ if (obj.kind === "stream") return obj.dict;
79
+ }
80
+ function dictGet(dict, key) {
81
+ return dict.entries.get(key);
82
+ }
83
+ //#endregion
84
+ export { asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };