pdf-codec 1.3.1 → 1.4.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.
- package/README.md +13 -0
- package/dist/afm-widths-BoeTOK2r.cjs +826 -0
- package/dist/afm-widths-Dxucrg7D.js +779 -0
- package/dist/afm-widths-DyDq56Ph.d.cts +19 -0
- package/dist/afm-widths-DyDq56Ph.d.ts +19 -0
- package/dist/afm-widths.cjs +4 -0
- package/dist/afm-widths.d.cts +2 -0
- package/dist/afm-widths.d.ts +2 -0
- package/dist/afm-widths.js +2 -0
- package/dist/assets/stix-two-math-font.cjs +5 -0
- package/dist/assets/stix-two-math-font.d.cts +4 -0
- package/dist/assets/stix-two-math-font.d.ts +4 -0
- package/dist/assets/stix-two-math-font.js +4 -0
- package/dist/bytes/crc32.cjs +21 -0
- package/dist/bytes/crc32.d.cts +4 -0
- package/dist/bytes/crc32.d.ts +4 -0
- package/dist/bytes/crc32.js +20 -0
- package/dist/bytes/flate.cjs +53 -0
- package/dist/bytes/flate.d.cts +12 -0
- package/dist/bytes/flate.d.ts +12 -0
- package/dist/bytes/flate.js +49 -0
- package/dist/bytes/reader.cjs +60 -0
- package/dist/bytes/reader.d.cts +20 -0
- package/dist/bytes/reader.d.ts +20 -0
- package/dist/bytes/reader.js +58 -0
- package/dist/bytes/writer.cjs +37 -0
- package/dist/bytes/writer.d.cts +13 -0
- package/dist/bytes/writer.d.ts +13 -0
- package/dist/bytes/writer.js +35 -0
- package/dist/cmap.cjs +110 -0
- package/dist/cmap.d.cts +8 -0
- package/dist/cmap.d.ts +8 -0
- package/dist/cmap.js +109 -0
- package/dist/codec.cjs +34 -0
- package/dist/codec.d.cts +167 -0
- package/dist/codec.d.ts +167 -0
- package/dist/codec.js +32 -0
- package/dist/content-read.cjs +126 -0
- package/dist/content-read.d.cts +21 -0
- package/dist/content-read.d.ts +21 -0
- package/dist/content-read.js +125 -0
- package/dist/content-write.cjs +138 -0
- package/dist/content-write.d.cts +24 -0
- package/dist/content-write.d.ts +24 -0
- package/dist/content-write.js +137 -0
- package/dist/diagnostics.cjs +21 -0
- package/dist/diagnostics.d.cts +19 -0
- package/dist/diagnostics.d.ts +19 -0
- package/dist/diagnostics.js +18 -0
- package/dist/document.cjs +162 -0
- package/dist/document.d.cts +12 -0
- package/dist/document.d.ts +12 -0
- package/dist/document.js +161 -0
- package/dist/encoding.cjs +5 -0
- package/dist/encoding.d.cts +6 -0
- package/dist/encoding.d.ts +6 -0
- package/dist/encoding.js +2 -0
- package/dist/filters.cjs +223 -0
- package/dist/filters.d.cts +14 -0
- package/dist/filters.d.ts +14 -0
- package/dist/filters.js +218 -0
- package/dist/font-read.cjs +199 -0
- package/dist/font-read.d.cts +23 -0
- package/dist/font-read.d.ts +23 -0
- package/dist/font-read.js +198 -0
- package/dist/font-style.cjs +35 -0
- package/dist/font-style.d.cts +14 -0
- package/dist/font-style.d.ts +14 -0
- package/dist/font-style.js +34 -0
- package/dist/fonts.cjs +124 -0
- package/dist/fonts.d.cts +15 -0
- package/dist/fonts.d.ts +15 -0
- package/dist/fonts.js +122 -0
- package/dist/formula.cjs +0 -0
- package/dist/formula.d.cts +10 -0
- package/dist/formula.d.ts +10 -0
- package/dist/formula.js +0 -0
- package/dist/image/jpeg-info.cjs +71 -0
- package/dist/image/jpeg-info.d.cts +12 -0
- package/dist/image/jpeg-info.d.ts +12 -0
- package/dist/image/jpeg-info.js +70 -0
- package/dist/image/png-decode.cjs +181 -0
- package/dist/image/png-decode.d.cts +14 -0
- package/dist/image/png-decode.d.ts +14 -0
- package/dist/image/png-decode.js +180 -0
- package/dist/image/png-encode.cjs +64 -0
- package/dist/image/png-encode.d.cts +8 -0
- package/dist/image/png-encode.d.ts +8 -0
- package/dist/image/png-encode.js +63 -0
- package/dist/image/png-filter.cjs +95 -0
- package/dist/image/png-filter.d.cts +6 -0
- package/dist/image/png-filter.d.ts +6 -0
- package/dist/image/png-filter.js +93 -0
- package/dist/images-read.cjs +250 -0
- package/dist/images-read.d.cts +13 -0
- package/dist/images-read.d.ts +13 -0
- package/dist/images-read.js +249 -0
- package/dist/index.cjs +45 -5912
- package/dist/index.d.cts +21 -483
- package/dist/index.d.ts +21 -483
- package/dist/index.js +18 -5885
- package/dist/interpret.cjs +587 -0
- package/dist/interpret.d.cts +84 -0
- package/dist/interpret.d.ts +84 -0
- package/dist/interpret.js +586 -0
- package/dist/lexer.cjs +180 -0
- package/dist/lexer.d.cts +29 -0
- package/dist/lexer.d.ts +29 -0
- package/dist/lexer.js +179 -0
- package/dist/math-cmap.cjs +81 -0
- package/dist/math-cmap.d.cts +6 -0
- package/dist/math-cmap.d.ts +6 -0
- package/dist/math-cmap.js +80 -0
- package/dist/math-content-write.cjs +83 -0
- package/dist/math-content-write.d.cts +11 -0
- package/dist/math-content-write.d.ts +11 -0
- package/dist/math-content-write.js +81 -0
- package/dist/math-font-write.cjs +100 -0
- package/dist/math-font-write.d.cts +19 -0
- package/dist/math-font-write.d.ts +19 -0
- package/dist/math-font-write.js +99 -0
- package/dist/math-font.cjs +103 -0
- package/dist/math-font.d.cts +25 -0
- package/dist/math-font.d.ts +25 -0
- package/dist/math-font.js +102 -0
- package/dist/math-hmtx.cjs +17 -0
- package/dist/math-hmtx.d.cts +8 -0
- package/dist/math-hmtx.d.ts +8 -0
- package/dist/math-hmtx.js +16 -0
- package/dist/math-table.cjs +117 -0
- package/dist/math-table.d.cts +45 -0
- package/dist/math-table.d.ts +45 -0
- package/dist/math-table.js +116 -0
- package/dist/math-types-Ba8qAf1p.d.cts +82 -0
- package/dist/math-types-Ba8qAf1p.d.ts +82 -0
- package/dist/math-types.cjs +0 -0
- package/dist/math-types.d.cts +2 -0
- package/dist/math-types.d.ts +2 -0
- package/dist/math-types.js +0 -0
- package/dist/matrix-B3c2_a2f.d.cts +18 -0
- package/dist/matrix-B3c2_a2f.d.ts +18 -0
- package/dist/matrix.cjs +93 -0
- package/dist/matrix.d.cts +2 -0
- package/dist/matrix.d.ts +2 -0
- package/dist/matrix.js +83 -0
- package/dist/measure.cjs +54 -0
- package/dist/measure.d.cts +20 -0
- package/dist/measure.d.ts +20 -0
- package/dist/measure.js +53 -0
- package/dist/objects.cjs +100 -0
- package/dist/objects.d.cts +58 -0
- package/dist/objects.d.ts +58 -0
- package/dist/objects.js +84 -0
- package/dist/parse.cjs +230 -0
- package/dist/parse.d.cts +13 -0
- package/dist/parse.d.ts +13 -0
- package/dist/parse.js +228 -0
- package/dist/predictors.cjs +64 -0
- package/dist/predictors.d.cts +13 -0
- package/dist/predictors.d.ts +13 -0
- package/dist/predictors.js +62 -0
- package/dist/read.cjs +418 -0
- package/dist/read.d.cts +21 -0
- package/dist/read.d.ts +21 -0
- package/dist/read.js +413 -0
- package/dist/serialize.cjs +69 -0
- package/dist/serialize.d.cts +8 -0
- package/dist/serialize.d.ts +8 -0
- package/dist/serialize.js +66 -0
- package/dist/sfnt.cjs +52 -0
- package/dist/sfnt.d.cts +17 -0
- package/dist/sfnt.d.ts +17 -0
- package/dist/sfnt.js +46 -0
- package/dist/text-layout.cjs +224 -0
- package/dist/text-layout.d.cts +37 -0
- package/dist/text-layout.d.ts +37 -0
- package/dist/text-layout.js +222 -0
- package/dist/util/abort.cjs +7 -0
- package/dist/util/abort.d.cts +4 -0
- package/dist/util/abort.d.ts +4 -0
- package/dist/util/abort.js +6 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/winansi.cjs +5 -0
- package/dist/winansi.d.cts +20 -0
- package/dist/winansi.d.ts +20 -0
- package/dist/winansi.js +2 -0
- package/dist/write.cjs +421 -0
- package/dist/write.d.cts +16 -0
- package/dist/write.d.ts +16 -0
- package/dist/write.js +419 -0
- package/dist/xref.cjs +325 -0
- package/dist/xref.d.cts +21 -0
- package/dist/xref.d.ts +21 -0
- package/dist/xref.js +324 -0
- 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 };
|
package/dist/measure.cjs
ADDED
|
@@ -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 };
|
package/dist/measure.js
ADDED
|
@@ -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 };
|
package/dist/objects.cjs
ADDED
|
@@ -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 };
|
package/dist/objects.js
ADDED
|
@@ -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 };
|