pdf-codec 2.2.36 → 3.0.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 +10 -7
- package/dist/codec.cjs +2 -2
- package/dist/codec.d.cts +2 -2
- package/dist/codec.d.ts +2 -2
- package/dist/codec.js +1 -1
- package/dist/content-write.d.cts +2 -1
- package/dist/content-write.d.ts +2 -1
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/layout.cjs +147 -0
- package/dist/layout.d.cts +684 -0
- package/dist/layout.d.ts +684 -0
- package/dist/layout.js +133 -0
- package/dist/read.cjs +2 -2
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +2 -2
- package/dist/write.d.cts +2 -1
- package/dist/write.d.ts +2 -1
- package/package.json +3 -3
package/dist/layout.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ColorSchema, ContentStrokeStyleSchema, LayoutFontSchema, LayoutMetadataSchema } from "document-schema.js";
|
|
3
|
+
//#region src/layout.ts
|
|
4
|
+
const LAYOUT_FORMAT_VERSION = 1;
|
|
5
|
+
const LayoutTextSchema = z.object({
|
|
6
|
+
kind: z.literal("text"),
|
|
7
|
+
text: z.string(),
|
|
8
|
+
xPt: z.number(),
|
|
9
|
+
yPt: z.number(),
|
|
10
|
+
font: LayoutFontSchema,
|
|
11
|
+
sizePt: z.number().positive(),
|
|
12
|
+
color: ColorSchema,
|
|
13
|
+
widthPt: z.number().nonnegative().optional(),
|
|
14
|
+
rotationDeg: z.number().optional(),
|
|
15
|
+
underline: z.boolean().optional(),
|
|
16
|
+
sourcePath: z.string().optional()
|
|
17
|
+
});
|
|
18
|
+
const LayoutImageSchema = z.object({
|
|
19
|
+
kind: z.literal("image"),
|
|
20
|
+
imageId: z.string(),
|
|
21
|
+
xPt: z.number(),
|
|
22
|
+
yPt: z.number(),
|
|
23
|
+
widthPt: z.number().positive(),
|
|
24
|
+
heightPt: z.number().positive(),
|
|
25
|
+
rotationDeg: z.number().optional(),
|
|
26
|
+
sourcePath: z.string().optional()
|
|
27
|
+
});
|
|
28
|
+
const LayoutRectSchema = z.object({
|
|
29
|
+
kind: z.literal("rect"),
|
|
30
|
+
xPt: z.number(),
|
|
31
|
+
yPt: z.number(),
|
|
32
|
+
widthPt: z.number().nonnegative(),
|
|
33
|
+
heightPt: z.number().nonnegative(),
|
|
34
|
+
fill: ColorSchema.optional(),
|
|
35
|
+
stroke: z.object({
|
|
36
|
+
color: ColorSchema,
|
|
37
|
+
widthPt: z.number().positive()
|
|
38
|
+
}).optional(),
|
|
39
|
+
sourcePath: z.string().optional()
|
|
40
|
+
});
|
|
41
|
+
const LayoutLineSchema = z.object({
|
|
42
|
+
kind: z.literal("line"),
|
|
43
|
+
x1Pt: z.number(),
|
|
44
|
+
y1Pt: z.number(),
|
|
45
|
+
x2Pt: z.number(),
|
|
46
|
+
y2Pt: z.number(),
|
|
47
|
+
color: ColorSchema,
|
|
48
|
+
widthPt: z.number().positive(),
|
|
49
|
+
style: ContentStrokeStyleSchema.optional(),
|
|
50
|
+
sourcePath: z.string().optional()
|
|
51
|
+
});
|
|
52
|
+
const LayoutEllipseSchema = z.object({
|
|
53
|
+
kind: z.literal("ellipse"),
|
|
54
|
+
xPt: z.number(),
|
|
55
|
+
yPt: z.number(),
|
|
56
|
+
widthPt: z.number().positive(),
|
|
57
|
+
heightPt: z.number().positive(),
|
|
58
|
+
fill: ColorSchema.optional(),
|
|
59
|
+
stroke: z.object({
|
|
60
|
+
color: ColorSchema,
|
|
61
|
+
widthPt: z.number().positive()
|
|
62
|
+
}).optional(),
|
|
63
|
+
sourcePath: z.string().optional()
|
|
64
|
+
});
|
|
65
|
+
const LayoutPathSegmentSchema = z.discriminatedUnion("kind", [z.object({
|
|
66
|
+
kind: z.literal("line"),
|
|
67
|
+
xPt: z.number(),
|
|
68
|
+
yPt: z.number()
|
|
69
|
+
}), z.object({
|
|
70
|
+
kind: z.literal("cubic"),
|
|
71
|
+
c1xPt: z.number(),
|
|
72
|
+
c1yPt: z.number(),
|
|
73
|
+
c2xPt: z.number(),
|
|
74
|
+
c2yPt: z.number(),
|
|
75
|
+
xPt: z.number(),
|
|
76
|
+
yPt: z.number()
|
|
77
|
+
})]);
|
|
78
|
+
const LayoutSubpathSchema = z.object({
|
|
79
|
+
startXPt: z.number(),
|
|
80
|
+
startYPt: z.number(),
|
|
81
|
+
segments: z.array(LayoutPathSegmentSchema),
|
|
82
|
+
closed: z.boolean()
|
|
83
|
+
});
|
|
84
|
+
const LayoutPathSchema = z.object({
|
|
85
|
+
kind: z.literal("path"),
|
|
86
|
+
subpaths: z.array(LayoutSubpathSchema),
|
|
87
|
+
fill: ColorSchema.optional(),
|
|
88
|
+
fillRule: z.enum(["nonzero", "evenodd"]).optional(),
|
|
89
|
+
stroke: z.object({
|
|
90
|
+
color: ColorSchema,
|
|
91
|
+
widthPt: z.number().positive()
|
|
92
|
+
}).optional(),
|
|
93
|
+
style: ContentStrokeStyleSchema.optional(),
|
|
94
|
+
sourcePath: z.string().optional()
|
|
95
|
+
});
|
|
96
|
+
const LayoutLinkSchema = z.object({
|
|
97
|
+
kind: z.literal("link"),
|
|
98
|
+
uri: z.string(),
|
|
99
|
+
xPt: z.number(),
|
|
100
|
+
yPt: z.number(),
|
|
101
|
+
widthPt: z.number().nonnegative(),
|
|
102
|
+
heightPt: z.number().nonnegative(),
|
|
103
|
+
sourcePath: z.string().optional()
|
|
104
|
+
});
|
|
105
|
+
const LayoutItemSchema = z.discriminatedUnion("kind", [
|
|
106
|
+
LayoutTextSchema,
|
|
107
|
+
LayoutImageSchema,
|
|
108
|
+
LayoutRectSchema,
|
|
109
|
+
LayoutLineSchema,
|
|
110
|
+
LayoutEllipseSchema,
|
|
111
|
+
LayoutPathSchema,
|
|
112
|
+
LayoutLinkSchema
|
|
113
|
+
]);
|
|
114
|
+
const LayoutPageSchema = z.object({
|
|
115
|
+
widthPt: z.number().positive(),
|
|
116
|
+
heightPt: z.number().positive(),
|
|
117
|
+
items: z.array(LayoutItemSchema),
|
|
118
|
+
notes: z.string().optional()
|
|
119
|
+
});
|
|
120
|
+
const LayoutImageAssetSchema = z.object({
|
|
121
|
+
format: z.enum(["png", "jpeg"]),
|
|
122
|
+
base64: z.string(),
|
|
123
|
+
widthPx: z.number().int().positive(),
|
|
124
|
+
heightPx: z.number().int().positive()
|
|
125
|
+
});
|
|
126
|
+
const LayoutDocumentSchema = z.object({
|
|
127
|
+
formatVersion: z.literal(1),
|
|
128
|
+
metadata: LayoutMetadataSchema,
|
|
129
|
+
pages: z.array(LayoutPageSchema),
|
|
130
|
+
images: z.record(z.string(), LayoutImageAssetSchema)
|
|
131
|
+
});
|
|
132
|
+
//#endregion
|
|
133
|
+
export { LAYOUT_FORMAT_VERSION, LayoutDocumentSchema, LayoutEllipseSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutItemSchema, LayoutLineSchema, LayoutLinkSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema };
|
package/dist/read.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_util_base64 = require("./util/base64.cjs");
|
|
3
3
|
const require_bytes_crc32 = require("./bytes/crc32.cjs");
|
|
4
4
|
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
5
|
+
require("./layout.cjs");
|
|
5
6
|
const require_diagnostics = require("./diagnostics.cjs");
|
|
6
7
|
const require_objects = require("./objects.cjs");
|
|
7
8
|
const require_filters = require("./filters.cjs");
|
|
@@ -12,7 +13,6 @@ const require_images_read = require("./images-read.cjs");
|
|
|
12
13
|
const require_matrix = require("./matrix.cjs");
|
|
13
14
|
const require_interpret = require("./interpret.cjs");
|
|
14
15
|
require("./write.cjs");
|
|
15
|
-
let document_schema_js = require("document-schema.js");
|
|
16
16
|
//#region src/read.ts
|
|
17
17
|
const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
|
|
18
18
|
const HEADER_SEARCH_WINDOW = 1024;
|
|
@@ -42,7 +42,7 @@ function readPdf(bytes, options) {
|
|
|
42
42
|
return readPage(pageDict, doc, fontResolver, images, imageIdCache, sink);
|
|
43
43
|
});
|
|
44
44
|
return {
|
|
45
|
-
formatVersion:
|
|
45
|
+
formatVersion: 1,
|
|
46
46
|
metadata: readMetadata(doc.trailer, doc),
|
|
47
47
|
pages,
|
|
48
48
|
images
|
package/dist/read.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
+
import { LayoutDocument } from "./layout.cjs";
|
|
2
3
|
import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
|
|
3
|
-
import { LayoutDocument } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
|
6
6
|
readonly sink?: PdfDiagnosticSink;
|
package/dist/read.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
+
import { LayoutDocument } from "./layout.js";
|
|
2
3
|
import { r as Matrix } from "./matrix-B7_SBKQ5.js";
|
|
3
|
-
import { LayoutDocument } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
|
6
6
|
readonly sink?: PdfDiagnosticSink;
|
package/dist/read.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bytesToBase64 } from "./util/base64.js";
|
|
2
2
|
import { crc32 } from "./bytes/crc32.js";
|
|
3
3
|
import { concatBytes } from "./bytes/writer.js";
|
|
4
|
+
import "./layout.js";
|
|
4
5
|
import { NOOP_DIAGNOSTIC_SINK, PdfParseError } from "./diagnostics.js";
|
|
5
6
|
import { asArray, asName, asNumber, dictGet } from "./objects.js";
|
|
6
7
|
import { decodeStream } from "./filters.js";
|
|
@@ -11,7 +12,6 @@ import { readImageXObject } from "./images-read.js";
|
|
|
11
12
|
import { applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, translationMatrix } from "./matrix.js";
|
|
12
13
|
import { interpretContentStream } from "./interpret.js";
|
|
13
14
|
import "./write.js";
|
|
14
|
-
import { LAYOUT_FORMAT_VERSION } from "document-schema.js";
|
|
15
15
|
//#region src/read.ts
|
|
16
16
|
const PDF_HEADER_BYTES = new TextEncoder().encode("%PDF-");
|
|
17
17
|
const HEADER_SEARCH_WINDOW = 1024;
|
|
@@ -41,7 +41,7 @@ function readPdf(bytes, options) {
|
|
|
41
41
|
return readPage(pageDict, doc, fontResolver, images, imageIdCache, sink);
|
|
42
42
|
});
|
|
43
43
|
return {
|
|
44
|
-
formatVersion:
|
|
44
|
+
formatVersion: 1,
|
|
45
45
|
metadata: readMetadata(doc.trailer, doc),
|
|
46
46
|
pages,
|
|
47
47
|
images
|
package/dist/write.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { LayoutDocument } from "./layout.cjs";
|
|
1
2
|
import { r as EmbeddedFaceSubstitution } from "./embedded-font-BU6Jgcof.cjs";
|
|
2
3
|
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
3
4
|
import { FontRegistry } from "./font-registry.cjs";
|
|
4
|
-
import {
|
|
5
|
+
import { PositionedFormula } from "document-schema.js";
|
|
5
6
|
//#region src/write.d.ts
|
|
6
7
|
interface WritePdfOptions {
|
|
7
8
|
readonly compress?: boolean;
|
package/dist/write.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { LayoutDocument } from "./layout.js";
|
|
1
2
|
import { r as EmbeddedFaceSubstitution } from "./embedded-font-fREdbxnr.js";
|
|
2
3
|
import { WinAnsiSubstitution } from "./winansi.js";
|
|
3
4
|
import { FontRegistry } from "./font-registry.js";
|
|
4
|
-
import {
|
|
5
|
+
import { PositionedFormula } from "document-schema.js";
|
|
5
6
|
//#region src/write.d.ts
|
|
6
7
|
interface WritePdfOptions {
|
|
7
8
|
readonly compress?: boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-codec",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"packageManager": "pnpm@11.6.0",
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"byte-codec": "^1.1.8",
|
|
84
|
-
"document-schema.js": "^
|
|
84
|
+
"document-schema.js": "^4.0.0",
|
|
85
85
|
"fflate": "^0.8.3",
|
|
86
86
|
"zod": "^4.4.3"
|
|
87
87
|
},
|