pdf-codec 2.2.35 → 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.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/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ExaDev/pdf-codec) [](https://www.npmjs.com/package/pdf-codec) [](https://github.com/ExaDev/pdf-codec/releases/latest) [](https://github.com/ExaDev/pdf-codec/actions)
|
|
4
4
|
|
|
5
|
-
> A hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs into a structured, positioned-content document and generates new PDFs from one, built on
|
|
5
|
+
> A hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs into a structured, positioned-content document and generates new PDFs from one, built on its own codec-owned `LayoutDocument` item model and [Zod 4](https://zod.dev) codecs.
|
|
6
6
|
|
|
7
7
|
`pdf-codec` is the PDF-reading-and-writing half of [`documents.js`](https://github.com/ExaDev/documents.js), extracted into its own package: every layer of the PDF format — the object model, the cross-reference table, the content-stream operators, standard-font metrics, the parser's cross-reference/object-stream resolution and content-stream interpreter — is hand-written against the ISO 32000-1 specification, with no external PDF library (`pdf-lib`, `pdfjs-dist`, `mupdf`, or any other) as a dependency. The one exception is [`fflate`](https://github.com/101arrowz/fflate) for raw DEFLATE/zlib compression. The OpenType/CFF font parsing this package's own writer uses to embed a real math font (`sfnt.ts`/`math-*.ts`) is hand-written too, as are the cryptographic primitives its reader needs to open an encrypted PDF (`crypto/` — MD5, SHA-2, RC4, AES), because `node:crypto` would end this package's platform neutrality and WebCrypto offers neither MD5 nor RC4 nor a synchronous API. The one bundled binary asset is the vendored STIX Two Math font itself (OFL-1.1, see [Fidelity](#fidelity) and `assets/fonts/NOTICE.md`).
|
|
8
8
|
|
|
@@ -79,6 +79,8 @@ const layout = readPdf(pdfBytes); // -> LayoutDocument: pages of positioned text
|
|
|
79
79
|
const bytes = writePdf(layout);
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
`LayoutDocument` and its whole item family — every item/page/image-asset type and schema, plus `LAYOUT_FORMAT_VERSION` — are this package's own exports, ported from `document-schema.js` (which dropped them) so a codec's native model lives in the codec, the same family pattern as `ooxml.js`'s `Package`/`XmlElement` and `markdown-codec`'s AST. `readPdf`/`writePdf` keep their signatures; callers see the same names from a new home. `documents.js` re-exports the family onward from its own barrel — those re-exports now source from `pdf-codec` rather than `document-schema.js`, same names, new source.
|
|
83
|
+
|
|
82
84
|
An encrypted PDF that opens without a password decrypts transparently — no extra option, no password parameter; one that genuinely needs a user password throws `PdfPasswordRequiredError`. See [Gotchas](#gotchas-and-quirks) for exactly which encryption is supported.
|
|
83
85
|
|
|
84
86
|
Both accept an optional `signal` (`AbortSignal`); `readPdf` additionally takes a `sink` (`PdfDiagnosticSink`, called once per recoverable parse diagnostic — see the three-tier failure policy under [Conventions](#conventions)), and `writePdf` an `onSubstitution` callback (called once per character not representable in a standard-14 font — see [Fidelity](#fidelity)).
|
|
@@ -127,7 +129,7 @@ A stretched construction is drawn through `MathBox`'s own `MathAssembledGlyphs`
|
|
|
127
129
|
|
|
128
130
|
`MathFontMetrics.stretch` is the layout-facing form: it resolves a construction at a target size and additionally **measures** it — `inkAscentPt`/`inkDescentPt` are the whole construction's real ink extent about its drawing origin, taken from actual glyph outlines.
|
|
129
131
|
|
|
130
|
-
Building a layout engine on top of this codec (this is what `documents.js`'s own `src/layout/` does): `TextMeasurer`/`createStandardFontMeasurer` answer "how wide does this text render, and where does this line break" against standard-14 metrics; `resolveStandardFont`/`STANDARD_METRICS` map an arbitrary family/weight/style onto one of the 14 standard PDF faces. The text-wrapping primitive (`wrapRunsToWidth`) and shape-rotation geometry (`rotatePointAboutCenter`) live in documents.js (they had no internal pdf-codec caller); the port types they consume (`TextMeasurer`, `StyledRun`, `WrappedLine`, `ProvidedFont`, the `MathBox`/`MathFontMetrics` family) live in `document-schema.js`, the neutral shared-schema package.
|
|
132
|
+
Building a layout engine on top of this codec (this is what `documents.js`'s own `src/layout/` does): `TextMeasurer`/`createStandardFontMeasurer` answer "how wide does this text render, and where does this line break" against standard-14 metrics; `resolveStandardFont`/`STANDARD_METRICS` map an arbitrary family/weight/style onto one of the 14 standard PDF faces. The text-wrapping primitive (`wrapRunsToWidth`) and shape-rotation geometry (`rotatePointAboutCenter`) live in documents.js (they had no internal pdf-codec caller); the port types they consume (`TextMeasurer`, `StyledRun`, `WrappedLine`, `ProvidedFont`, the `MathBox`/`MathFontMetrics` family) live in `document-schema.js`, the neutral shared-schema package, while the `LayoutDocument` they build is this package's own type.
|
|
131
133
|
|
|
132
134
|
Embedding real fonts instead of substituting standard-14 faces, via a `FontRegistry` (see `src/font-registry.ts` for the source-document → caller-supplied → vendored-substitute → standard-14 resolution order). Pass the same registry to both the measurer and `writePdf` so what was measured and what gets drawn come from one font:
|
|
133
135
|
|
|
@@ -185,11 +187,12 @@ This works via package.json's `"./*"` wildcard export, resolving any `pdf-codec/
|
|
|
185
187
|
|
|
186
188
|
The package is layered from generic primitives outward to the codec itself:
|
|
187
189
|
|
|
188
|
-
- **`src/
|
|
190
|
+
- **`src/layout.ts`** — this package's own native document model: the `LayoutDocument` item family — Zod schemas and inferred types for text/image/rect/line/ellipse/path/link items, pages (with the hidden speaker-notes channel), the image-asset registry, and `LAYOUT_FORMAT_VERSION`. Ported verbatim from `document-schema.js`, which carried it until its 4.0.0 dropped it — a codec's native model lives in the codec, like `ooxml.js`'s `Package`/`XmlElement` and `markdown-codec`'s AST; only PDF's native model was ever a public shared-schema export, an accident of this package predating the content pivot. The item layer remains the honest boundary between what the format says (positions) and what we think it means (structure): when reconstruction misjudges a wrapped paragraph, the items stay inspectable as the PDF's actual testimony. The shared leaf shapes the family composes from (`Color`, `ContentStrokeStyleSchema`, `LayoutFont`, `LayoutMetadata`) stay in `document-schema.js` and are imported, keeping one definition of each across content and layout.
|
|
191
|
+
- **The math port types** — `MathColor`/`MathGlyphRun`/`MathRule`/`MathStroke`/`MathLayoutItem`/`MathBox`/`MathGlyphMetrics`/`MathFontMetrics` and `PositionedFormula`, sourced from `document-schema.js`'s math layout port (one shared definition across the family, not a local mirror). Deliberately not imported from `documents.js` — that would be a circular dependency once `documents.js` depends on this package. Because every one of these types is plain data (only `MathFontMetrics` carries a method), a real `MathBox` value `documents.js` produces passes into `writePdf({ formulas })` with zero cast, zero wrapper, and zero transformation.
|
|
189
192
|
- **`src/bytes/`** and **`src/image/`** — generic byte and image-container primitives with zero PDF-specific knowledge: a chunked byte writer, backtracking byte reader, CRC32, a hand-written PNG decoder/encoder, JPEG marker scanning for dimensions only (compressed bytes pass through unchanged), a hand-written CCITT Group 3/Group 4 fax decoder (ITU-T T.4/T.6), a hand-written JBIG2 decoder (ITU-T T.88 — `jbig2-arith.ts` MQ decoder, `jbig2-bitmap.ts`, `jbig2-generic.ts`, `jbig2-text.ts`, `jbig2.ts`), and a hand-written JPEG 2000 decoder (ISO/IEC 15444-1 — `jp2-boxes.ts`, `jpeg2000-codestream.ts`, `jpeg2000-tagtree.ts`, `jpeg2000-t2.ts`, `jpeg2000-t1.ts`, `jpeg2000-dwt.ts`, `jpeg2000.ts`). `src/filters.ts` owns all PDF knowledge for CCITT/JBIG2 (resolving parameters, `/JBIG2Globals`, inverting polarity); `src/images-read.ts` owns the JPEG 2000 PDF integration. `src/bytes/flate.ts` is the only file that imports `fflate`.
|
|
190
193
|
- **`src/util/`** — two small independently-duplicated copies of family-shared logic: `base64.ts` (verbatim copy of `odf.js`'s own, replacing a former `ooxml.js` dependency for this one helper) and `abort.ts` (`throwIfAborted`, called at every page loop boundary — there is no `await` point in this synchronous pipeline for cancellation to hook into implicitly).
|
|
191
194
|
- **`src/crypto/`** — MD5, SHA-256/384/512, RC4, and AES-CBC, hand-written with zero local imports. Not a preference: ISO 32000-1's key-derivation algorithms name MD5 and RC4 directly, neither offered by any portable platform crypto API, and `crypto.subtle` is asynchronous where this codec's read path is synchronous end to end. Reaching for `node:crypto` would break the browser bundle. Each module cites its specification (RFC 1321, FIPS 180-4, FIPS 197) and is tested against published conformance vectors.
|
|
192
|
-
- **The codec itself, importing only `
|
|
195
|
+
- **The codec itself, importing only `layout`/`bytes`/`image`/`crypto`/`util` plus `document-schema.js`'s port types (no OOXML or ODF knowledge):**
|
|
193
196
|
- **Write**: `objects.ts` (the `PdfObject` discriminated union), `afm-widths.ts`/`encoding.ts`/`winansi.ts`/`fonts.ts` (standard-14 metrics, WinAnsi encoding, family resolution), `font-registry.ts` (resolution port plus `resolveFaceWithRegistry`, the one step both measurer and writer resolve through so they can never disagree about which face a `LayoutFont` means), `font-face.ts` (`readFontFace`, reading a standalone font file's family/bold/italic triple off its `name`/`OS/2`/`head` tables), `measure.ts`/`text-layout.ts` (greedy line-wrapping against either standard-14 AFM widths plus per-family correction or a resolved face's own real `hmtx` advances — never both), `content-write.ts` (`LayoutItem[]` → content-stream operators, with text branching on standard-14 vs embedded face encoding, pair-kerning split into `TJ` arrays, and stroke `style` becoming real dash/line-cap state), `write.ts` (the full object graph, cross-reference table, trailer, and embedded font groups).
|
|
194
197
|
- **sfnt font tables**: `sfnt.ts` (bounds-checked table-directory reader), `cmap-table.ts` (Unicode → glyph ID, formats 4/12/6), `hmtx-table.ts` (per-glyph advance widths), `font-tables.ts` (`head`/`maxp`/`OS/2`/`post`/`name`), `glyf.ts` (`loca` offset index, per-glyph headers, composite component records, `glyphInkBounds`), `math-table.ts` (OpenType `MATH` constants/glyph-info/variants subtables). `ot-layout-common.ts` (Coverage/ClassDef, stored as sorted glyph ranges searched by bisection). `gpos-table.ts` reads `GPOS` for exactly one thing: pair-advance kerning through the `kern` feature, both PairPos formats and LookupType 9 Extension indirection — mark attachment, cursive joining, and contextual positioning have no consumer here. Every parser degrades to `undefined` on a missing/truncated table rather than throwing.
|
|
195
198
|
- **sfnt subsetting**: `sfnt-subset.ts` — a TrueType-outline glyph subsetter (Unicode code points → glyph IDs via `cmap`, transitive closure over `glyf` composite components, rebuilt sfnt carrying only used outlines). **Glyph IDs are preserved, never renumbered**, keeping composite component references valid and making CID == GID trivially true. Output rebuilds `head`/`hhea`/`maxp`/`loca`/`glyf`/`hmtx`, copies hinting programs verbatim, stubs `post`, omits `cmap`/`name`/`OS/2`/`GSUB`/`GPOS`/`kern` (none read through a `CIDFontType2` program per ISO 32000-1 9.9). Applies to `glyf`-flavoured fonts only; CFF returns `undefined`.
|
|
@@ -201,11 +204,11 @@ The package is layered from generic primitives outward to the codec itself:
|
|
|
201
204
|
- `codec.ts` — `pdfCodec`, a `z.codec()` pair over `readPdf`/`writePdf`, plus a standalone local copy of the `%PDF-` header check.
|
|
202
205
|
- **`src/test-support/`** — hand-built PDF fixtures (`pdf.ts`) built by literal byte/string concatenation and deliberately importing NOTHING from this package's own writer (a fixture built by `writePdf` would let a writer bug hide from the corresponding reader test). `encrypted-pdfs.ts` applies the same principle: real PDFs encrypted by [qpdf](https://qpdf.sourceforge.io/), embedded as base64, so a bug in key derivation cannot cancel out between write and read halves. `fonts.ts` holds the real vendored Carlito and Caladea faces as raw sfnt bytes, and asserts values read out of the `.ttf` files by a standalone script with a bare `DataView`, not by this package's own parsers — external cross-checks rather than a parser's output compared against itself.
|
|
203
206
|
|
|
204
|
-
Dependency direction is strictly downward and checkable: `
|
|
207
|
+
Dependency direction is strictly downward and checkable: `layout` imports only `zod` and `document-schema.js`'s shared leaf schemas; `bytes`/`crypto`/`util` import nothing local (`bytes/flate.ts` imports `fflate`); `image` imports `bytes` only; the codec itself imports `layout`+`bytes`+`image`+`crypto`+`util` plus `document-schema.js`'s port and leaf types, and nothing else from outside. Nothing anywhere under `src/` imports a `node:` builtin, which is what lets `tsdown`'s `platform: 'neutral'` build run unchanged in a browser bundle. No `PdfObject`/`PdfDict`/`PdfStream` type appears outside the codec's own read/write modules.
|
|
205
208
|
|
|
206
209
|
## Conventions
|
|
207
210
|
|
|
208
|
-
- **Zod-first schema/type/guard**: `PdfBytesSchema
|
|
211
|
+
- **Zod-first schema/type/guard**: `PdfBytesSchema` (in `codec.ts`) and `LayoutDocumentSchema` (in `src/layout.ts`, this package's own native model) are the only two schemas this package validates against; every other model type (`PdfObject`, `MathBox` and friends) is plain TypeScript, never Zod-validated.
|
|
209
212
|
- **`z.codec()` for the one schema-to-schema round trip**: `pdfCodec` (PDF bytes ⇄ `LayoutDocument`), wrapping the already-independently-tested `readPdf`/`writePdf` pair and adding automatic two-way schema validation. Deliberately the no-options form — `readPdf`/`writePdf` remain the primary entry points wherever a caller needs an `AbortSignal`, a `PdfDiagnosticSink`, or an `onSubstitution` callback.
|
|
210
213
|
- **`PdfObject` has no Zod schema at all**, deliberately: it never crosses a public boundary or round-trips through JSON, and is constructed exclusively by this package's own parser. It narrows natively on its own `kind` discriminant.
|
|
211
214
|
- **The `MathBox`/`MathFontMetrics` family is structurally typed on purpose, not validated by Zod** — the mechanism that lets a caller (`documents.js`) hand this package a real value produced by a completely independent module, with zero cast, zero wrapper, and no shared class or branded type.
|
|
@@ -293,7 +296,7 @@ There is a single `main` branch and no open pull request workflow established so
|
|
|
293
296
|
## References
|
|
294
297
|
|
|
295
298
|
- [documents.js](https://github.com/ExaDev/documents.js) — the package this codec was extracted from, and its principal downstream consumer: docx/pptx/odt/odp/ods/odg ⇄ PDF conversion, and MathML formula rendering (its own `src/mathml/` typesetting engine feeds a real `MathBox` into this package's `writePdf({ formulas })` with zero cast).
|
|
296
|
-
- [document-schema.js](https://github.com/ExaDev/document-schema.js) — the sibling package that owns `
|
|
299
|
+
- [document-schema.js](https://github.com/ExaDev/document-schema.js) — the sibling package that owns the canonical `ContentDocument`/`DocumentPackage` pivots the wider family shares, plus the shared leaf shapes and port types this package imports (`Color`, `LayoutFont`, `LayoutMetadata`, `TextMeasurer`, the math family). The `LayoutDocument` item family itself lived there until moving into this package.
|
|
297
300
|
- [qpdf](https://qpdf.sourceforge.io/) — the independent implementation that produces this package's encrypted-PDF test fixtures. A build-time and test-time tool only, never a dependency of the package itself.
|
|
298
301
|
- The specifications `src/crypto/` implements, each cited in the module that implements it and checked against published conformance vectors: [RFC 1321](https://www.rfc-editor.org/rfc/rfc1321) (MD5), [FIPS 180-4](https://csrc.nist.gov/pubs/fips/180-4/upd1/final) (SHA-256/384/512), [FIPS 197](https://csrc.nist.gov/pubs/fips/197/final) (AES), and [NIST SP 800-38A](https://csrc.nist.gov/pubs/sp/800/38/a/final) (CBC mode). The standard security handler is ISO 32000-1 7.6, extended for revisions 5 and 6 by ISO 32000-2 7.6.4.3.
|
|
299
302
|
- [STIX Two Math](https://github.com/stipub/stixfonts) — the embedded math font, vendored at `assets/fonts/STIXTwoMath-Regular.otf` and embedded into `dist/` as a base64 string (`src/assets/stix-two-math-font.ts`, generated by `scripts/generate-math-font-asset.mjs`). Copyright 2001-2021 The STIX Fonts Project Authors, licensed [OFL-1.1](assets/fonts/OFL.txt) — see `assets/fonts/NOTICE.md` for the exact source commit and version.
|
package/dist/codec.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_layout = require("./layout.cjs");
|
|
2
3
|
const require_write = require("./write.cjs");
|
|
3
4
|
const require_read = require("./read.cjs");
|
|
4
5
|
let zod = require("zod");
|
|
5
|
-
let document_schema_js = require("document-schema.js");
|
|
6
6
|
//#region src/codec.ts
|
|
7
7
|
const PDF_HEADER = [
|
|
8
8
|
37,
|
|
@@ -25,7 +25,7 @@ function containsBytesWithin(bytes, signature, window) {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
const PdfBytesSchema = zod.z.instanceof(Uint8Array).refine((bytes) => containsBytesWithin(bytes, PDF_HEADER, PDF_HEADER_SEARCH_WINDOW), { message: "not a valid PDF file: missing the %PDF- header" });
|
|
28
|
-
const pdfCodec = zod.z.codec(PdfBytesSchema,
|
|
28
|
+
const pdfCodec = zod.z.codec(PdfBytesSchema, require_layout.LayoutDocumentSchema, {
|
|
29
29
|
decode: (bytes) => require_read.readPdf(bytes),
|
|
30
30
|
encode: (doc) => require_write.writePdf(doc)
|
|
31
31
|
});
|
package/dist/codec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { LayoutDocumentSchema } from "./layout.js";
|
|
1
2
|
import { writePdf } from "./write.js";
|
|
2
3
|
import { readPdf } from "./read.js";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
import { LayoutDocumentSchema } from "document-schema.js";
|
|
5
5
|
//#region src/codec.ts
|
|
6
6
|
const PDF_HEADER = [
|
|
7
7
|
37,
|
package/dist/content-write.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { r as StandardFontName } from "./afm-widths-DyDq56Ph.cjs";
|
|
2
|
+
import { LayoutItem } from "./layout.cjs";
|
|
2
3
|
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-BU6Jgcof.cjs";
|
|
3
4
|
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
4
|
-
import { LayoutFont,
|
|
5
|
+
import { LayoutFont, TextMeasurer } from "document-schema.js";
|
|
5
6
|
//#region src/content-write.d.ts
|
|
6
7
|
type ResolvedFontResource = {
|
|
7
8
|
readonly kind: 'standard';
|
package/dist/content-write.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { r as StandardFontName } from "./afm-widths-DyDq56Ph.js";
|
|
2
|
+
import { LayoutItem } from "./layout.js";
|
|
2
3
|
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-fREdbxnr.js";
|
|
3
4
|
import { WinAnsiSubstitution } from "./winansi.js";
|
|
4
|
-
import { LayoutFont,
|
|
5
|
+
import { LayoutFont, TextMeasurer } from "document-schema.js";
|
|
5
6
|
//#region src/content-write.d.ts
|
|
6
7
|
type ResolvedFontResource = {
|
|
7
8
|
readonly kind: 'standard';
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_afm_widths = require("./afm-widths-BoeTOK2r.cjs");
|
|
3
|
+
const require_layout = require("./layout.cjs");
|
|
3
4
|
const require_diagnostics = require("./diagnostics.cjs");
|
|
4
5
|
const require_image_ccitt = require("./image/ccitt.cjs");
|
|
5
6
|
const require_image_jbig2_errors = require("./image/jbig2-errors.cjs");
|
|
@@ -23,6 +24,20 @@ exports.Jbig2ParseError = require_image_jbig2_errors.Jbig2ParseError;
|
|
|
23
24
|
exports.Jbig2UnsupportedError = require_image_jbig2_errors.Jbig2UnsupportedError;
|
|
24
25
|
exports.Jpeg2000ParseError = require_image_jpeg2000_errors.Jpeg2000ParseError;
|
|
25
26
|
exports.Jpeg2000UnsupportedError = require_image_jpeg2000_errors.Jpeg2000UnsupportedError;
|
|
27
|
+
exports.LAYOUT_FORMAT_VERSION = require_layout.LAYOUT_FORMAT_VERSION;
|
|
28
|
+
exports.LayoutDocumentSchema = require_layout.LayoutDocumentSchema;
|
|
29
|
+
exports.LayoutEllipseSchema = require_layout.LayoutEllipseSchema;
|
|
30
|
+
exports.LayoutImageAssetSchema = require_layout.LayoutImageAssetSchema;
|
|
31
|
+
exports.LayoutImageSchema = require_layout.LayoutImageSchema;
|
|
32
|
+
exports.LayoutItemSchema = require_layout.LayoutItemSchema;
|
|
33
|
+
exports.LayoutLineSchema = require_layout.LayoutLineSchema;
|
|
34
|
+
exports.LayoutLinkSchema = require_layout.LayoutLinkSchema;
|
|
35
|
+
exports.LayoutPageSchema = require_layout.LayoutPageSchema;
|
|
36
|
+
exports.LayoutPathSchema = require_layout.LayoutPathSchema;
|
|
37
|
+
exports.LayoutPathSegmentSchema = require_layout.LayoutPathSegmentSchema;
|
|
38
|
+
exports.LayoutRectSchema = require_layout.LayoutRectSchema;
|
|
39
|
+
exports.LayoutSubpathSchema = require_layout.LayoutSubpathSchema;
|
|
40
|
+
exports.LayoutTextSchema = require_layout.LayoutTextSchema;
|
|
26
41
|
exports.NOOP_DIAGNOSTIC_SINK = require_diagnostics.NOOP_DIAGNOSTIC_SINK;
|
|
27
42
|
exports.PdfBytesSchema = require_codec.PdfBytesSchema;
|
|
28
43
|
exports.PdfEncryptedError = require_diagnostics.PdfEncryptedError;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "
|
|
|
2
2
|
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
|
|
3
3
|
import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.cjs";
|
|
4
4
|
import { PdfBytesSchema, pdfCodec } from "./codec.cjs";
|
|
5
|
+
import { LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.cjs";
|
|
5
6
|
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-BU6Jgcof.cjs";
|
|
6
7
|
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
7
8
|
import { FontFace, FontFaceParseError, readFontFace } from "./font-face.cjs";
|
|
@@ -23,4 +24,4 @@ import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } fro
|
|
|
23
24
|
import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.cjs";
|
|
24
25
|
import { FontRegistryOptions, FontSubstitution, MathAssembledGlyphs, MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphPlacement, MathGlyphRun, MathLayoutItem, MathRule, MathStretchAxis, MathStretchGlyph, MathStretchResult, MathStroke, Point, PositionedFormula, ProvidedFont, StyledFragment, StyledRun, TextMeasurer, UnderlineMetrics, WrapOptions, WrappedLine } from "document-schema.js";
|
|
25
26
|
export * from "byte-codec";
|
|
26
|
-
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
|
27
|
+
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "
|
|
|
2
2
|
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
|
|
3
3
|
import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
|
|
4
4
|
import { PdfBytesSchema, pdfCodec } from "./codec.js";
|
|
5
|
+
import { LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.js";
|
|
5
6
|
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-fREdbxnr.js";
|
|
6
7
|
import { WinAnsiSubstitution } from "./winansi.js";
|
|
7
8
|
import { FontFace, FontFaceParseError, readFontFace } from "./font-face.js";
|
|
@@ -23,4 +24,4 @@ import { LoadedMathFont, MathFont, MathFontDescriptorMetrics, loadMathFont } fro
|
|
|
23
24
|
import { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer } from "./measure.js";
|
|
24
25
|
import { FontRegistryOptions, FontSubstitution, MathAssembledGlyphs, MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphPlacement, MathGlyphRun, MathLayoutItem, MathRule, MathStretchAxis, MathStretchGlyph, MathStretchResult, MathStroke, Point, PositionedFormula, ProvidedFont, StyledFragment, StyledRun, TextMeasurer, UnderlineMetrics, WrapOptions, WrappedLine } from "document-schema.js";
|
|
25
26
|
export * from "byte-codec";
|
|
26
|
-
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
|
27
|
+
export { type CcittFaxImage, type CcittFaxOptions, DEFAULT_VERTICAL_METRIC_POLICY, type EmbeddedFace, type EmbeddedFaceMetrics, type EmbeddedFaceSubstitution, type FontFace, FontFaceParseError, type FontMeasurerOptions, type FontMetrics, type FontRegistry, type FontRegistryOptions, type FontSubstitution, type GlyphInkBounds, type Jbig2DecodeOptions, type Jbig2Image, Jbig2ParseError, Jbig2UnsupportedError, type Jp2ChannelDefinition, type Jp2ColourSpace, type Jp2Container, type Jp2ImageHeader, type Jpeg2000ComponentMetadata, type Jpeg2000DecodeOptions, type Jpeg2000Image, type Jpeg2000Metadata, Jpeg2000ParseError, type Jpeg2000ProgressionOrder, type Jpeg2000QuantizationStyle, type Jpeg2000Transform, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutItem, LayoutItemSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema, type LoadedMathFont, type MathAssembledGlyphs, type MathBox, type MathColor, type MathFont, type MathFontDescriptorMetrics, type MathFontMetrics, type MathGlyphAssembly, type MathGlyphConstruction, type MathGlyphMetrics, type MathGlyphPart, type MathGlyphPlacement, type MathGlyphRun, type MathGlyphVariant, type MathLayoutItem, type MathRule, type MathStretchAxis, type MathStretchConstruction, type MathStretchGlyph, type MathStretchOptions, type MathStretchPlacement, type MathStretchResult, type MathStroke, type MathVariants, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, type PdfDiagnostic, type PdfDiagnosticSeverity, type PdfDiagnosticSink, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, type Point, type PositionedFormula, type ProvidedFont, type ReadPdfOptions, type ResolvedFace, type ResolvedFont, STANDARD_METRICS, type StandardFontMeasurerOptions, type StandardFontName, type StyledFragment, type StyledRun, type TextMeasurer, type UnderlineMetrics, type VerticalMetricPolicy, type WinAnsiSubstitution, type WrapOptions, type WrappedLine, type WritePdfOptions, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { t as STANDARD_METRICS } from "./afm-widths-Dxucrg7D.js";
|
|
2
|
+
import { LAYOUT_FORMAT_VERSION, LayoutDocumentSchema, LayoutEllipseSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutItemSchema, LayoutLineSchema, LayoutLinkSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema } from "./layout.js";
|
|
2
3
|
import { NOOP_DIAGNOSTIC_SINK, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError } from "./diagnostics.js";
|
|
3
4
|
import { decodeCcittFax } from "./image/ccitt.js";
|
|
4
5
|
import { Jbig2ParseError, Jbig2UnsupportedError } from "./image/jbig2-errors.js";
|
|
@@ -17,4 +18,4 @@ import { readPdf } from "./read.js";
|
|
|
17
18
|
import { PdfBytesSchema, pdfCodec } from "./codec.js";
|
|
18
19
|
import { FontFaceParseError, readFontFace } from "./font-face.js";
|
|
19
20
|
export * from "byte-codec";
|
|
20
|
-
export { DEFAULT_VERTICAL_METRIC_POLICY, FontFaceParseError, Jbig2ParseError, Jbig2UnsupportedError, Jpeg2000ParseError, Jpeg2000UnsupportedError, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
|
21
|
+
export { DEFAULT_VERTICAL_METRIC_POLICY, FontFaceParseError, Jbig2ParseError, Jbig2UnsupportedError, Jpeg2000ParseError, Jpeg2000UnsupportedError, LAYOUT_FORMAT_VERSION, LayoutDocumentSchema, LayoutEllipseSchema, LayoutImageAssetSchema, LayoutImageSchema, LayoutItemSchema, LayoutLineSchema, LayoutLinkSchema, LayoutPageSchema, LayoutPathSchema, LayoutPathSegmentSchema, LayoutRectSchema, LayoutSubpathSchema, LayoutTextSchema, NOOP_DIAGNOSTIC_SINK, PdfBytesSchema, PdfEncryptedError, PdfParseError, PdfPasswordRequiredError, STANDARD_METRICS, assembleStretchyGlyph, createFontMeasurer, createFontRegistry, createStandardFontMeasurer, decodeCcittFax, decodeJbig2Embedded, decodeJpeg2000, filterScanlines, loadMathFont, looksLikeBareCodestream, parseJp2Container, pdfCodec, readFontFace, readJpeg2000Metadata, readPdf, resolveFaceWithRegistry, resolveStandardFont, scaleMathStretchConstruction, unfilterScanlines, writePdf };
|
package/dist/layout.cjs
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
let document_schema_js = require("document-schema.js");
|
|
4
|
+
//#region src/layout.ts
|
|
5
|
+
const LAYOUT_FORMAT_VERSION = 1;
|
|
6
|
+
const LayoutTextSchema = zod.z.object({
|
|
7
|
+
kind: zod.z.literal("text"),
|
|
8
|
+
text: zod.z.string(),
|
|
9
|
+
xPt: zod.z.number(),
|
|
10
|
+
yPt: zod.z.number(),
|
|
11
|
+
font: document_schema_js.LayoutFontSchema,
|
|
12
|
+
sizePt: zod.z.number().positive(),
|
|
13
|
+
color: document_schema_js.ColorSchema,
|
|
14
|
+
widthPt: zod.z.number().nonnegative().optional(),
|
|
15
|
+
rotationDeg: zod.z.number().optional(),
|
|
16
|
+
underline: zod.z.boolean().optional(),
|
|
17
|
+
sourcePath: zod.z.string().optional()
|
|
18
|
+
});
|
|
19
|
+
const LayoutImageSchema = zod.z.object({
|
|
20
|
+
kind: zod.z.literal("image"),
|
|
21
|
+
imageId: zod.z.string(),
|
|
22
|
+
xPt: zod.z.number(),
|
|
23
|
+
yPt: zod.z.number(),
|
|
24
|
+
widthPt: zod.z.number().positive(),
|
|
25
|
+
heightPt: zod.z.number().positive(),
|
|
26
|
+
rotationDeg: zod.z.number().optional(),
|
|
27
|
+
sourcePath: zod.z.string().optional()
|
|
28
|
+
});
|
|
29
|
+
const LayoutRectSchema = zod.z.object({
|
|
30
|
+
kind: zod.z.literal("rect"),
|
|
31
|
+
xPt: zod.z.number(),
|
|
32
|
+
yPt: zod.z.number(),
|
|
33
|
+
widthPt: zod.z.number().nonnegative(),
|
|
34
|
+
heightPt: zod.z.number().nonnegative(),
|
|
35
|
+
fill: document_schema_js.ColorSchema.optional(),
|
|
36
|
+
stroke: zod.z.object({
|
|
37
|
+
color: document_schema_js.ColorSchema,
|
|
38
|
+
widthPt: zod.z.number().positive()
|
|
39
|
+
}).optional(),
|
|
40
|
+
sourcePath: zod.z.string().optional()
|
|
41
|
+
});
|
|
42
|
+
const LayoutLineSchema = zod.z.object({
|
|
43
|
+
kind: zod.z.literal("line"),
|
|
44
|
+
x1Pt: zod.z.number(),
|
|
45
|
+
y1Pt: zod.z.number(),
|
|
46
|
+
x2Pt: zod.z.number(),
|
|
47
|
+
y2Pt: zod.z.number(),
|
|
48
|
+
color: document_schema_js.ColorSchema,
|
|
49
|
+
widthPt: zod.z.number().positive(),
|
|
50
|
+
style: document_schema_js.ContentStrokeStyleSchema.optional(),
|
|
51
|
+
sourcePath: zod.z.string().optional()
|
|
52
|
+
});
|
|
53
|
+
const LayoutEllipseSchema = zod.z.object({
|
|
54
|
+
kind: zod.z.literal("ellipse"),
|
|
55
|
+
xPt: zod.z.number(),
|
|
56
|
+
yPt: zod.z.number(),
|
|
57
|
+
widthPt: zod.z.number().positive(),
|
|
58
|
+
heightPt: zod.z.number().positive(),
|
|
59
|
+
fill: document_schema_js.ColorSchema.optional(),
|
|
60
|
+
stroke: zod.z.object({
|
|
61
|
+
color: document_schema_js.ColorSchema,
|
|
62
|
+
widthPt: zod.z.number().positive()
|
|
63
|
+
}).optional(),
|
|
64
|
+
sourcePath: zod.z.string().optional()
|
|
65
|
+
});
|
|
66
|
+
const LayoutPathSegmentSchema = zod.z.discriminatedUnion("kind", [zod.z.object({
|
|
67
|
+
kind: zod.z.literal("line"),
|
|
68
|
+
xPt: zod.z.number(),
|
|
69
|
+
yPt: zod.z.number()
|
|
70
|
+
}), zod.z.object({
|
|
71
|
+
kind: zod.z.literal("cubic"),
|
|
72
|
+
c1xPt: zod.z.number(),
|
|
73
|
+
c1yPt: zod.z.number(),
|
|
74
|
+
c2xPt: zod.z.number(),
|
|
75
|
+
c2yPt: zod.z.number(),
|
|
76
|
+
xPt: zod.z.number(),
|
|
77
|
+
yPt: zod.z.number()
|
|
78
|
+
})]);
|
|
79
|
+
const LayoutSubpathSchema = zod.z.object({
|
|
80
|
+
startXPt: zod.z.number(),
|
|
81
|
+
startYPt: zod.z.number(),
|
|
82
|
+
segments: zod.z.array(LayoutPathSegmentSchema),
|
|
83
|
+
closed: zod.z.boolean()
|
|
84
|
+
});
|
|
85
|
+
const LayoutPathSchema = zod.z.object({
|
|
86
|
+
kind: zod.z.literal("path"),
|
|
87
|
+
subpaths: zod.z.array(LayoutSubpathSchema),
|
|
88
|
+
fill: document_schema_js.ColorSchema.optional(),
|
|
89
|
+
fillRule: zod.z.enum(["nonzero", "evenodd"]).optional(),
|
|
90
|
+
stroke: zod.z.object({
|
|
91
|
+
color: document_schema_js.ColorSchema,
|
|
92
|
+
widthPt: zod.z.number().positive()
|
|
93
|
+
}).optional(),
|
|
94
|
+
style: document_schema_js.ContentStrokeStyleSchema.optional(),
|
|
95
|
+
sourcePath: zod.z.string().optional()
|
|
96
|
+
});
|
|
97
|
+
const LayoutLinkSchema = zod.z.object({
|
|
98
|
+
kind: zod.z.literal("link"),
|
|
99
|
+
uri: zod.z.string(),
|
|
100
|
+
xPt: zod.z.number(),
|
|
101
|
+
yPt: zod.z.number(),
|
|
102
|
+
widthPt: zod.z.number().nonnegative(),
|
|
103
|
+
heightPt: zod.z.number().nonnegative(),
|
|
104
|
+
sourcePath: zod.z.string().optional()
|
|
105
|
+
});
|
|
106
|
+
const LayoutItemSchema = zod.z.discriminatedUnion("kind", [
|
|
107
|
+
LayoutTextSchema,
|
|
108
|
+
LayoutImageSchema,
|
|
109
|
+
LayoutRectSchema,
|
|
110
|
+
LayoutLineSchema,
|
|
111
|
+
LayoutEllipseSchema,
|
|
112
|
+
LayoutPathSchema,
|
|
113
|
+
LayoutLinkSchema
|
|
114
|
+
]);
|
|
115
|
+
const LayoutPageSchema = zod.z.object({
|
|
116
|
+
widthPt: zod.z.number().positive(),
|
|
117
|
+
heightPt: zod.z.number().positive(),
|
|
118
|
+
items: zod.z.array(LayoutItemSchema),
|
|
119
|
+
notes: zod.z.string().optional()
|
|
120
|
+
});
|
|
121
|
+
const LayoutImageAssetSchema = zod.z.object({
|
|
122
|
+
format: zod.z.enum(["png", "jpeg"]),
|
|
123
|
+
base64: zod.z.string(),
|
|
124
|
+
widthPx: zod.z.number().int().positive(),
|
|
125
|
+
heightPx: zod.z.number().int().positive()
|
|
126
|
+
});
|
|
127
|
+
const LayoutDocumentSchema = zod.z.object({
|
|
128
|
+
formatVersion: zod.z.literal(1),
|
|
129
|
+
metadata: document_schema_js.LayoutMetadataSchema,
|
|
130
|
+
pages: zod.z.array(LayoutPageSchema),
|
|
131
|
+
images: zod.z.record(zod.z.string(), LayoutImageAssetSchema)
|
|
132
|
+
});
|
|
133
|
+
//#endregion
|
|
134
|
+
exports.LAYOUT_FORMAT_VERSION = LAYOUT_FORMAT_VERSION;
|
|
135
|
+
exports.LayoutDocumentSchema = LayoutDocumentSchema;
|
|
136
|
+
exports.LayoutEllipseSchema = LayoutEllipseSchema;
|
|
137
|
+
exports.LayoutImageAssetSchema = LayoutImageAssetSchema;
|
|
138
|
+
exports.LayoutImageSchema = LayoutImageSchema;
|
|
139
|
+
exports.LayoutItemSchema = LayoutItemSchema;
|
|
140
|
+
exports.LayoutLineSchema = LayoutLineSchema;
|
|
141
|
+
exports.LayoutLinkSchema = LayoutLinkSchema;
|
|
142
|
+
exports.LayoutPageSchema = LayoutPageSchema;
|
|
143
|
+
exports.LayoutPathSchema = LayoutPathSchema;
|
|
144
|
+
exports.LayoutPathSegmentSchema = LayoutPathSegmentSchema;
|
|
145
|
+
exports.LayoutRectSchema = LayoutRectSchema;
|
|
146
|
+
exports.LayoutSubpathSchema = LayoutSubpathSchema;
|
|
147
|
+
exports.LayoutTextSchema = LayoutTextSchema;
|