@hussmartinez/pdf-sdk 0.2.0 → 0.3.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/dist/index.js CHANGED
@@ -1 +1,233 @@
1
- export { a as PDF_MAX_CANVAS_PIXELS, d as PdfError, c as addRotation, i as createPdfJsEngine, r as createPdfProcessor, n as createPdfSession, f as isPdfError, o as linkDestination, l as pdfLimitDefinitions, u as pdfLimits, t as pdfMessages, s as safeLinkUrl } from "./shared/en-BYB_GHqG.js";
1
+ import { C as PdfError, S as pdfLimits, _ as PDF_MAX_CANVAS_PIXELS, a as checkId, b as addRotation, c as isRecord, d as PDF_MAX_STROKE_POINTS, f as PDF_MAX_TEXT_LENGTH, g as createPdfJsEngine, h as createPdfProcessor, i as checkAnnotation, l as PDF_MAX_FIELD_NAME_LENGTH, m as longerThan, n as createPdfSession, o as fields, p as PDF_POSITION_GRID, r as Invalid, s as invalid, t as pdfMessages, u as PDF_MAX_ID_LENGTH, v as linkDestination, w as isPdfError, x as pdfLimitDefinitions, y as safeLinkUrl } from "./shared/en-CQX26xju.js";
2
+ // src/core/format/plan-document.ts
3
+ var PDF_PLAN_FORMAT = "hm-pdf-plan";
4
+ var PDF_PLAN_VERSION = 1;
5
+ var DOCUMENT_FIELDS = [
6
+ "format",
7
+ "version",
8
+ "sources",
9
+ "pages",
10
+ "formValues"
11
+ ];
12
+ var PAGE_FIELDS = [
13
+ "key",
14
+ "source",
15
+ "pageIndex",
16
+ "rotation",
17
+ "annotations"
18
+ ];
19
+ var ASSET_FIELDS = [
20
+ "asset",
21
+ "mediaType",
22
+ "size"
23
+ ];
24
+ var ASSET_ID = /^sha256:[0-9a-f]{64}$/;
25
+ var MEDIA_TYPE = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/;
26
+ var ROTATIONS = [
27
+ 0,
28
+ 90,
29
+ 180,
30
+ 270
31
+ ];
32
+ function malformed(message) {
33
+ return invalid("malformed-command", message);
34
+ }
35
+ var isCount = (value, min) => Number.isSafeInteger(value) && value >= min;
36
+ function fromGrid(value, what) {
37
+ if (!Number.isSafeInteger(value)) malformed(`${what} is whole millionths of the page`);
38
+ return value / PDF_POSITION_GRID;
39
+ }
40
+ var toGridUnits = (fraction) => Math.round(fraction * PDF_POSITION_GRID);
41
+ function pointFromDocument(value, what) {
42
+ if (!isRecord(value)) return value;
43
+ return Object.fromEntries(Object.entries(value).map(([name, entry]) => [name, name === "x" || name === "y" ? fromGrid(entry, `${what}.${name}`) : entry]));
44
+ }
45
+ function annotationFromDocument(value) {
46
+ if (!isRecord(value)) return value;
47
+ const { type } = value;
48
+ if (type !== "pen" && type !== "highlight" && type !== "text") return value;
49
+ return Object.fromEntries(Object.entries(value).map(([name, entry]) => {
50
+ if (name === "width" || name === "size") return [name, fromGrid(entry, name)];
51
+ if (name === "at") return [name, pointFromDocument(entry, "at")];
52
+ if (name === "points" && Array.isArray(entry)) return [name, entry.map((point) => pointFromDocument(point, "a point"))];
53
+ return [name, entry];
54
+ }));
55
+ }
56
+ function annotationToDocument(annotation) {
57
+ const point = ({ x, y }) => ({
58
+ x: toGridUnits(x),
59
+ y: toGridUnits(y)
60
+ });
61
+ switch (annotation.type) {
62
+ case "pen":
63
+ case "highlight": return {
64
+ id: annotation.id,
65
+ type: annotation.type,
66
+ points: annotation.points.map(point),
67
+ color: annotation.color,
68
+ width: toGridUnits(annotation.width)
69
+ };
70
+ case "text": return {
71
+ id: annotation.id,
72
+ type: "text",
73
+ at: point(annotation.at),
74
+ text: annotation.text,
75
+ size: toGridUnits(annotation.size),
76
+ color: annotation.color
77
+ };
78
+ default: throw new TypeError("hm-pdf-plan version 1 can't hold signature annotations.");
79
+ }
80
+ }
81
+ function readAsset(value) {
82
+ if (!isRecord(value)) malformed("an asset is an object");
83
+ fields(value, ASSET_FIELDS, "an asset");
84
+ const { asset, mediaType, size } = value;
85
+ if (typeof asset !== "string" || !ASSET_ID.test(asset)) malformed("an asset id is sha256:<hex>");
86
+ if (typeof mediaType !== "string" || mediaType.length > 255 || !MEDIA_TYPE.test(mediaType)) malformed("a media type is type/subtype, in lowercase");
87
+ if (!isCount(size, 0)) malformed("an asset's size is a whole number of bytes");
88
+ return {
89
+ asset,
90
+ mediaType,
91
+ size
92
+ };
93
+ }
94
+ function readSources(value) {
95
+ if (!isRecord(value)) malformed("sources is an object");
96
+ return Object.fromEntries(Object.entries(value).map(([id, source]) => {
97
+ checkId(id, "a source id");
98
+ if (!isRecord(source)) malformed("a source is an object");
99
+ fields(source, ["pageCount"], "a source", ["asset"]);
100
+ if (!isCount(source.pageCount, 1)) malformed("a source's page count is at least 1");
101
+ return [id, source.asset === void 0 ? { pageCount: source.pageCount } : {
102
+ pageCount: source.pageCount,
103
+ asset: readAsset(source.asset)
104
+ }];
105
+ }));
106
+ }
107
+ function readPage(value) {
108
+ if (!isRecord(value)) malformed("a page is an object");
109
+ fields(value, PAGE_FIELDS, "a page");
110
+ const key = checkId(value.key, "a page key");
111
+ const source = checkId(value.source, "a source id");
112
+ if (!isCount(value.pageIndex, 0)) malformed("a page index is a whole number from 0");
113
+ if (typeof value.rotation !== "number") malformed("a page's rotation is a number");
114
+ if (!ROTATIONS.includes(value.rotation)) invalid("invalid-rotation", "a page's rotation is 0, 90, 180 or 270");
115
+ if (!Array.isArray(value.annotations)) malformed("a page's annotations are a list");
116
+ const annotations = value.annotations.map((annotation) => checkAnnotation(annotationFromDocument(annotation)));
117
+ return {
118
+ key,
119
+ source,
120
+ pageIndex: value.pageIndex,
121
+ rotation: value.rotation,
122
+ annotations
123
+ };
124
+ }
125
+ function readFieldValue(value) {
126
+ if (typeof value === "boolean") return value;
127
+ if (typeof value !== "string") malformed("a field's value is text or a boolean");
128
+ if (longerThan(value, 1e4)) invalid("text-too-long", `a field's value has more than ${PDF_MAX_TEXT_LENGTH} code points`);
129
+ return value;
130
+ }
131
+ function readFormValues(value) {
132
+ if (!isRecord(value)) malformed("formValues is an object");
133
+ return Object.fromEntries(Object.entries(value).map(([source, values]) => {
134
+ checkId(source, "a source id");
135
+ if (!isRecord(values) || Object.keys(values).length === 0) malformed("a source's form values are an object with at least one field");
136
+ return [source, Object.fromEntries(Object.entries(values).map(([field, entry]) => {
137
+ if (field === "") malformed("a field's name is text");
138
+ if (longerThan(field, 1e3)) invalid("field-name-too-long", `a field's name has at most ${PDF_MAX_FIELD_NAME_LENGTH} code points`);
139
+ return [field, readFieldValue(entry)];
140
+ }))];
141
+ }));
142
+ }
143
+ function read(value) {
144
+ if (!isRecord(value)) malformed("a document is an object");
145
+ const { format, version } = value;
146
+ if (typeof format !== "string") malformed("format is text");
147
+ if (format !== "hm-pdf-plan") throw new PdfError("UNSUPPORTED_FORMAT", `This isn't an ${PDF_PLAN_FORMAT} document.`, { details: {
148
+ format: PDF_PLAN_FORMAT,
149
+ reason: "unknown-format"
150
+ } });
151
+ if (Number.isSafeInteger(version) && version > 1) throw new PdfError("UNSUPPORTED_FORMAT", `This ${PDF_PLAN_FORMAT} document is a later version than this release reads.`, { details: {
152
+ format: PDF_PLAN_FORMAT,
153
+ reason: "unknown-format-version"
154
+ } });
155
+ if (version !== 1) malformed("version is 1");
156
+ fields(value, DOCUMENT_FIELDS, "a document");
157
+ const sources = readSources(value.sources);
158
+ if (!Array.isArray(value.pages) || value.pages.length === 0) malformed("pages is a list of at least one page");
159
+ const pages = value.pages.map(readPage);
160
+ const formValues = readFormValues(value.formValues);
161
+ const keys = /* @__PURE__ */ new Set();
162
+ for (const page of pages) {
163
+ if (keys.has(page.key)) invalid("duplicate-key", `two pages have the key ${page.key}`);
164
+ keys.add(page.key);
165
+ const source = Object.hasOwn(sources, page.source) ? sources[page.source] : void 0;
166
+ if (source === void 0) invalid("unknown-source", `the document doesn't list source ${page.source}`);
167
+ if (page.pageIndex >= source.pageCount) invalid("page-out-of-range", `source ${page.source} has no page index ${page.pageIndex}`);
168
+ if (new Set(page.annotations.map(({ id }) => id)).size !== page.annotations.length) invalid("duplicate-annotation", `page ${page.key} has two annotations with one id`);
169
+ }
170
+ for (const source of Object.keys(formValues)) if (!Object.hasOwn(sources, source)) invalid("unknown-source", `the document doesn't list source ${source}`);
171
+ return {
172
+ plan: {
173
+ pages,
174
+ formValues
175
+ },
176
+ sources
177
+ };
178
+ }
179
+ function readPdfPlanDocument(value) {
180
+ try {
181
+ return read(value);
182
+ } catch (error) {
183
+ if (!(error instanceof Invalid)) throw error;
184
+ const reason = error.reason === "malformed-command" ? "malformed-document" : error.reason;
185
+ throw new PdfError("INVALID_DOCUMENT", `Invalid ${PDF_PLAN_FORMAT} document: ${error.message}.`, { details: {
186
+ format: PDF_PLAN_FORMAT,
187
+ reason
188
+ } });
189
+ }
190
+ }
191
+ function toPdfPlanDocument(plan, sources) {
192
+ for (const source of [...plan.pages.map((page) => page.source), ...Object.keys(plan.formValues)]) if (!Object.hasOwn(sources, source)) throw new TypeError(`The sources don't include ${source}, which the plan uses.`);
193
+ return {
194
+ format: PDF_PLAN_FORMAT,
195
+ version: 1,
196
+ sources: Object.fromEntries(Object.entries(sources).map(([id, { pageCount, asset }]) => [id, asset === void 0 ? { pageCount } : {
197
+ pageCount,
198
+ asset: { ...asset }
199
+ }])),
200
+ pages: plan.pages.map((page) => ({
201
+ key: page.key,
202
+ source: page.source,
203
+ pageIndex: page.pageIndex,
204
+ rotation: page.rotation,
205
+ annotations: page.annotations.map(annotationToDocument)
206
+ })),
207
+ formValues: Object.fromEntries(Object.entries(plan.formValues).map(([source, values]) => [source, Object.fromEntries(Object.entries(values))]))
208
+ };
209
+ }
210
+ function readPdfCommandDocument(value) {
211
+ try {
212
+ if (!isRecord(value)) return value;
213
+ if (value["type"] === "pdf.restorePages") invalid("unknown-command", "pdf.restorePages isn't a command of the portable format");
214
+ if (value["type"] !== "pdf.addAnnotation") return value;
215
+ return Object.fromEntries(Object.entries(value).map(([name, entry]) => [name, name === "annotation" ? annotationFromDocument(entry) : entry]));
216
+ } catch (error) {
217
+ if (!(error instanceof Invalid)) throw error;
218
+ throw new PdfError("INVALID_COMMAND", `Invalid command: ${error.message}.`, { details: { reason: error.reason } });
219
+ }
220
+ }
221
+ function toPdfCommandDocument(command) {
222
+ if (command.type === "pdf.restorePages") throw new TypeError("pdf.restorePages isn't a command of the portable format.");
223
+ if (command.type !== "pdf.addAnnotation") return structuredClone(command);
224
+ return {
225
+ type: "pdf.addAnnotation",
226
+ page: command.page,
227
+ annotation: annotationToDocument(command.annotation),
228
+ ...command.index === void 0 ? {} : { index: command.index }
229
+ };
230
+ }
231
+ export { PDF_MAX_CANVAS_PIXELS, PDF_MAX_FIELD_NAME_LENGTH, PDF_MAX_ID_LENGTH, PDF_MAX_STROKE_POINTS, PDF_MAX_TEXT_LENGTH, PDF_PLAN_FORMAT, PDF_PLAN_VERSION, PDF_POSITION_GRID, PdfError, addRotation, createPdfJsEngine, createPdfProcessor, createPdfSession, isPdfError, linkDestination, pdfLimitDefinitions, pdfLimits, pdfMessages, readPdfCommandDocument, readPdfPlanDocument, safeLinkUrl, toPdfCommandDocument, toPdfPlanDocument };
232
+
233
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/core/format/plan-document.ts"],"sourcesContent":["import { PdfError } from \"../errors/pdf-error.js\";\nimport type { PdfAnnotation, PdfColor } from \"../model/annotations.js\";\nimport type { PdfFieldValue } from \"../model/document.js\";\nimport type { PdfRotation } from \"../model/geometry.js\";\nimport type { PdfPlan, PdfPlanPage } from \"../model/plan.js\";\nimport {\n longerThan,\n PDF_MAX_FIELD_NAME_LENGTH,\n PDF_MAX_TEXT_LENGTH,\n PDF_POSITION_GRID,\n} from \"../model/portable.js\";\nimport {\n checkAnnotation,\n checkId,\n fields,\n Invalid,\n invalid,\n isRecord,\n type PdfAddAnnotationCommand,\n type PdfCommand,\n type PdfRestorePagesCommand,\n} from \"../operations/commands.js\";\n\n/**\n * The name of the plan's portable format (sdk-core ADR 0045).\n *\n * @public\n */\nexport const PDF_PLAN_FORMAT = \"hm-pdf-plan\";\n\n/**\n * The version of {@link PDF_PLAN_FORMAT} this release writes, and the latest\n * it reads.\n *\n * @public\n */\nexport const PDF_PLAN_VERSION = 1;\n\n/**\n * A content-addressed reference to binary data, such as a source's file\n * (sdk-core ADR 0045). Documents never inline bytes.\n *\n * @public\n */\nexport interface PdfAssetReference {\n /** `sha256:` and the lowercase hex SHA-256 of the bytes. */\n readonly asset: string;\n /** The bytes' media type, such as `application/pdf`, in lowercase. */\n readonly mediaType: string;\n /** The size of the bytes. */\n readonly size: number;\n}\n\n/**\n * A source, as a plan document records it: its page count, which the pages\n * that use it must fit, and, once documents travel with their files, its\n * content.\n *\n * @public\n */\nexport interface PdfPlanDocumentSource {\n readonly pageCount: number;\n readonly asset?: PdfAssetReference;\n}\n\n/**\n * A point in a plan document: whole millionths of the page, from 0 to\n * {@link PDF_POSITION_GRID}.\n *\n * @public\n */\nexport interface PdfDocumentPoint {\n readonly x: number;\n readonly y: number;\n}\n\n/**\n * A pen or highlighter stroke in a plan document. Its points and width are\n * whole millionths of the page.\n *\n * @public\n */\nexport interface PdfStrokeAnnotationDocument {\n readonly id: string;\n readonly type: \"pen\" | \"highlight\";\n readonly points: readonly PdfDocumentPoint[];\n readonly color: PdfColor;\n readonly width: number;\n}\n\n/**\n * A text note in a plan document. Its position and size are whole\n * millionths of the page.\n *\n * @public\n */\nexport interface PdfTextAnnotationDocument {\n readonly id: string;\n readonly type: \"text\";\n readonly at: PdfDocumentPoint;\n readonly text: string;\n readonly size: number;\n readonly color: PdfColor;\n}\n\n/**\n * An annotation in a plan document. Version 1 has no signatures: their image\n * needs an asset, whose design comes with the signature tool (docs/adr/0003).\n *\n * @public\n */\nexport type PdfAnnotationDocument = PdfStrokeAnnotationDocument | PdfTextAnnotationDocument;\n\n/**\n * A page in a plan document.\n *\n * @public\n */\nexport interface PdfPlanDocumentPage {\n readonly key: string;\n readonly source: string;\n readonly pageIndex: number;\n readonly rotation: PdfRotation;\n readonly annotations: readonly PdfAnnotationDocument[];\n}\n\n/**\n * The plan as portable JSON: `hm-pdf-plan` version 1, which\n * `formats/hm-pdf-plan/v1.schema.json` describes\n * (docs/formats/hm-pdf-plan.md). Positions and sizes are whole millionths of\n * the page, and pages name their sources by ids the document lists.\n *\n * @public\n */\nexport interface PdfPlanDocument {\n readonly format: typeof PDF_PLAN_FORMAT;\n readonly version: typeof PDF_PLAN_VERSION;\n readonly sources: Readonly<Record<string, PdfPlanDocumentSource>>;\n readonly pages: readonly PdfPlanDocumentPage[];\n readonly formValues: Readonly<Record<string, Readonly<Record<string, PdfFieldValue>>>>;\n}\n\n/**\n * `pdf.addAnnotation` as `hm-pdf-command` writes it, with the annotation's\n * positions and sizes in whole millionths of the page.\n *\n * @public\n */\nexport interface PdfAddAnnotationCommandDocument {\n readonly type: \"pdf.addAnnotation\";\n readonly page: string;\n readonly annotation: PdfAnnotationDocument;\n readonly index?: number;\n}\n\n/**\n * A user-level command as portable JSON: `hm-pdf-command` version 1, which\n * `formats/hm-pdf-command/v1.schema.json` describes. Every command but\n * `pdf.restorePages`, an inverse that carries whole pages; only\n * `pdf.addAnnotation` differs from the command in memory.\n *\n * @public\n */\nexport type PdfCommandDocument =\n | Exclude<PdfCommand, PdfRestorePagesCommand | PdfAddAnnotationCommand>\n | PdfAddAnnotationCommandDocument;\n\n/**\n * Why a plan document was refused, as a stable token: `details.reason` on\n * the error (sdk-core ADR 0045).\n *\n * - With `UNSUPPORTED_FORMAT`: `unknown-format`, a document of another\n * format, and `unknown-format-version`, a later version than this release\n * reads.\n * - With `INVALID_DOCUMENT`: `malformed-document`, a document that isn't\n * shaped as the schema says; `unknown-source`, a page or form values for a\n * source the document doesn't list; `page-out-of-range`, a page index its\n * source doesn't have; `duplicate-key`, two pages with one key;\n * `duplicate-annotation`, two annotations with one id on a page; and, as\n * for commands, `invalid-rotation`, `outside-page`, `invalid-size`,\n * `too-many-points`, `invalid-color`, `unsupported-annotation`,\n * `field-name-too-long` and `text-too-long`.\n *\n * @public\n */\nexport type PdfDocumentRejection =\n | \"unknown-format\"\n | \"unknown-format-version\"\n | \"malformed-document\"\n | \"unknown-source\"\n | \"page-out-of-range\"\n | \"duplicate-key\"\n | \"duplicate-annotation\"\n | \"invalid-rotation\"\n | \"outside-page\"\n | \"invalid-size\"\n | \"too-many-points\"\n | \"invalid-color\"\n | \"unsupported-annotation\"\n | \"field-name-too-long\"\n | \"text-too-long\";\n\nconst DOCUMENT_FIELDS = [\"format\", \"version\", \"sources\", \"pages\", \"formValues\"];\nconst PAGE_FIELDS = [\"key\", \"source\", \"pageIndex\", \"rotation\", \"annotations\"];\nconst ASSET_FIELDS = [\"asset\", \"mediaType\", \"size\"];\n/** The patterns the schema uses too, so both accept the same documents. */\nconst ASSET_ID = /^sha256:[0-9a-f]{64}$/;\nconst MEDIA_TYPE = /^[a-z0-9][a-z0-9!#$&^_.+-]*\\/[a-z0-9][a-z0-9!#$&^_.+-]*$/;\nconst ROTATIONS: readonly number[] = [0, 90, 180, 270];\n\nfunction malformed(message: string): never {\n return invalid(\"malformed-command\", message);\n}\n\nconst isCount = (value: unknown, min: number): value is number =>\n Number.isSafeInteger(value) && (value as number) >= min;\n\n/** Millionths to a fraction. The reducer's checks then see the fraction. */\nfunction fromGrid(value: unknown, what: string): number {\n if (!Number.isSafeInteger(value)) malformed(`${what} is whole millionths of the page`);\n return (value as number) / PDF_POSITION_GRID;\n}\n\nconst toGridUnits = (fraction: number) => Math.round(fraction * PDF_POSITION_GRID);\n\nfunction pointFromDocument(value: unknown, what: string): unknown {\n if (!isRecord<Record<string, unknown>>(value)) return value;\n return Object.fromEntries(\n Object.entries(value).map(([name, entry]) => [\n name,\n name === \"x\" || name === \"y\" ? fromGrid(entry, `${what}.${name}`) : entry,\n ]),\n );\n}\n\n/**\n * An annotation's JSON form in memory: its millionths become fractions, and\n * everything else is left for {@link checkAnnotation}, which refuses what\n * doesn't fit.\n */\nfunction annotationFromDocument(value: unknown): unknown {\n if (!isRecord<Record<string, unknown>>(value)) return value;\n const { type } = value;\n if (type !== \"pen\" && type !== \"highlight\" && type !== \"text\") return value;\n return Object.fromEntries(\n Object.entries(value).map(([name, entry]) => {\n if (name === \"width\" || name === \"size\") return [name, fromGrid(entry, name)];\n if (name === \"at\") return [name, pointFromDocument(entry, \"at\")];\n if (name === \"points\" && Array.isArray(entry)) {\n return [name, entry.map((point) => pointFromDocument(point, \"a point\"))];\n }\n return [name, entry];\n }),\n );\n}\n\nfunction annotationToDocument(annotation: PdfAnnotation): PdfAnnotationDocument {\n const point = ({ x, y }: { x: number; y: number }) => ({ x: toGridUnits(x), y: toGridUnits(y) });\n switch (annotation.type) {\n case \"pen\":\n case \"highlight\":\n return {\n id: annotation.id,\n type: annotation.type,\n points: annotation.points.map(point),\n color: annotation.color,\n width: toGridUnits(annotation.width),\n };\n case \"text\":\n return {\n id: annotation.id,\n type: \"text\",\n at: point(annotation.at),\n text: annotation.text,\n size: toGridUnits(annotation.size),\n color: annotation.color,\n };\n default:\n throw new TypeError(\"hm-pdf-plan version 1 can't hold signature annotations.\");\n }\n}\n\nfunction readAsset(value: unknown): PdfAssetReference {\n if (!isRecord<PdfAssetReference>(value)) malformed(\"an asset is an object\");\n fields(value, ASSET_FIELDS, \"an asset\");\n const { asset, mediaType, size } = value;\n if (typeof asset !== \"string\" || !ASSET_ID.test(asset)) malformed(\"an asset id is sha256:<hex>\");\n if (typeof mediaType !== \"string\" || mediaType.length > 255 || !MEDIA_TYPE.test(mediaType)) {\n malformed(\"a media type is type/subtype, in lowercase\");\n }\n if (!isCount(size, 0)) malformed(\"an asset's size is a whole number of bytes\");\n return { asset, mediaType, size };\n}\n\nfunction readSources(value: unknown): Record<string, PdfPlanDocumentSource> {\n if (!isRecord<Record<string, unknown>>(value)) malformed(\"sources is an object\");\n // Object.fromEntries keeps ids such as __proto__ as own, ordinary keys.\n return Object.fromEntries(\n Object.entries(value).map(([id, source]) => {\n checkId(id, \"a source id\");\n if (!isRecord<PdfPlanDocumentSource>(source)) malformed(\"a source is an object\");\n fields(source, [\"pageCount\"], \"a source\", [\"asset\"]);\n if (!isCount(source.pageCount, 1)) malformed(\"a source's page count is at least 1\");\n const entry: PdfPlanDocumentSource =\n source.asset === undefined\n ? { pageCount: source.pageCount }\n : { pageCount: source.pageCount, asset: readAsset(source.asset) };\n return [id, entry];\n }),\n );\n}\n\n/** A page's shape, before what depends on the rest of the document. */\nfunction readPage(value: unknown): PdfPlanPage {\n if (!isRecord<PdfPlanDocumentPage>(value)) malformed(\"a page is an object\");\n fields(value, PAGE_FIELDS, \"a page\");\n const key = checkId(value.key, \"a page key\");\n const source = checkId(value.source, \"a source id\");\n if (!isCount(value.pageIndex, 0)) malformed(\"a page index is a whole number from 0\");\n if (typeof value.rotation !== \"number\") malformed(\"a page's rotation is a number\");\n if (!ROTATIONS.includes(value.rotation)) {\n invalid(\"invalid-rotation\", \"a page's rotation is 0, 90, 180 or 270\");\n }\n if (!Array.isArray(value.annotations)) malformed(\"a page's annotations are a list\");\n const annotations = value.annotations.map((annotation) =>\n checkAnnotation(annotationFromDocument(annotation)),\n );\n return { key, source, pageIndex: value.pageIndex, rotation: value.rotation, annotations };\n}\n\nfunction readFieldValue(value: unknown): PdfFieldValue {\n if (typeof value === \"boolean\") return value;\n if (typeof value !== \"string\") malformed(\"a field's value is text or a boolean\");\n if (longerThan(value, PDF_MAX_TEXT_LENGTH)) {\n invalid(\"text-too-long\", `a field's value has more than ${PDF_MAX_TEXT_LENGTH} code points`);\n }\n return value;\n}\n\nfunction readFormValues(value: unknown): PdfPlan[\"formValues\"] {\n if (!isRecord<Record<string, unknown>>(value)) malformed(\"formValues is an object\");\n return Object.fromEntries(\n Object.entries(value).map(([source, values]) => {\n checkId(source, \"a source id\");\n if (!isRecord<Record<string, unknown>>(values) || Object.keys(values).length === 0) {\n malformed(\"a source's form values are an object with at least one field\");\n }\n return [\n source,\n Object.fromEntries(\n Object.entries(values).map(([field, entry]) => {\n if (field === \"\") malformed(\"a field's name is text\");\n if (longerThan(field, PDF_MAX_FIELD_NAME_LENGTH)) {\n invalid(\n \"field-name-too-long\",\n `a field's name has at most ${PDF_MAX_FIELD_NAME_LENGTH} code points`,\n );\n }\n return [field, readFieldValue(entry)];\n }),\n ),\n ];\n }),\n );\n}\n\nfunction read(value: unknown): {\n plan: PdfPlan;\n sources: Record<string, PdfPlanDocumentSource>;\n} {\n if (!isRecord<PdfPlanDocument>(value)) malformed(\"a document is an object\");\n const { format, version } = value;\n if (typeof format !== \"string\") malformed(\"format is text\");\n if (format !== PDF_PLAN_FORMAT) {\n throw new PdfError(\"UNSUPPORTED_FORMAT\", `This isn't an ${PDF_PLAN_FORMAT} document.`, {\n details: { format: PDF_PLAN_FORMAT, reason: \"unknown-format\" },\n });\n }\n if (Number.isSafeInteger(version) && (version as number) > PDF_PLAN_VERSION) {\n throw new PdfError(\n \"UNSUPPORTED_FORMAT\",\n `This ${PDF_PLAN_FORMAT} document is a later version than this release reads.`,\n { details: { format: PDF_PLAN_FORMAT, reason: \"unknown-format-version\" } },\n );\n }\n if (version !== PDF_PLAN_VERSION) malformed(\"version is 1\");\n fields(value, DOCUMENT_FIELDS, \"a document\");\n\n // First everything a schema checks, then what depends on the whole\n // document, so a refusal's reason says whether the schema refuses it too.\n const sources = readSources(value.sources);\n if (!Array.isArray(value.pages) || value.pages.length === 0) {\n malformed(\"pages is a list of at least one page\");\n }\n const pages = value.pages.map(readPage);\n const formValues = readFormValues(value.formValues);\n\n const keys = new Set<string>();\n for (const page of pages) {\n if (keys.has(page.key)) invalid(\"duplicate-key\", `two pages have the key ${page.key}`);\n keys.add(page.key);\n const source = Object.hasOwn(sources, page.source) ? sources[page.source] : undefined;\n if (source === undefined) {\n invalid(\"unknown-source\", `the document doesn't list source ${page.source}`);\n }\n if (page.pageIndex >= source.pageCount) {\n invalid(\"page-out-of-range\", `source ${page.source} has no page index ${page.pageIndex}`);\n }\n const ids = new Set(page.annotations.map(({ id }) => id));\n if (ids.size !== page.annotations.length) {\n invalid(\"duplicate-annotation\", `page ${page.key} has two annotations with one id`);\n }\n }\n for (const source of Object.keys(formValues)) {\n if (!Object.hasOwn(sources, source)) {\n invalid(\"unknown-source\", `the document doesn't list source ${source}`);\n }\n }\n return { plan: { pages, formValues }, sources };\n}\n\n/**\n * Reads a plan document, such as one parsed from JSON, checking it as\n * {@link PdfPlanDocument}'s schema does and more: every page's source must\n * be one the document lists, with the page's index, and page keys and each\n * page's annotation ids must be unique. Unknown fields are refused, never\n * dropped.\n *\n * @param value - The parsed JSON.\n * @returns The plan, with positions as fractions of the page, and its\n * sources by id.\n * @throws `PdfError` with `UNSUPPORTED_FORMAT` for another format or a later\n * version, and `INVALID_DOCUMENT` for anything else that's wrong, with a\n * {@link PdfDocumentRejection} as `details.reason`.\n * @public\n */\nexport function readPdfPlanDocument(value: unknown): {\n readonly plan: PdfPlan;\n readonly sources: Readonly<Record<string, PdfPlanDocumentSource>>;\n} {\n try {\n return read(value);\n } catch (error) {\n if (!(error instanceof Invalid)) throw error;\n const reason = error.reason === \"malformed-command\" ? \"malformed-document\" : error.reason;\n throw new PdfError(\n \"INVALID_DOCUMENT\",\n `Invalid ${PDF_PLAN_FORMAT} document: ${error.message}.`,\n {\n details: { format: PDF_PLAN_FORMAT, reason },\n },\n );\n }\n}\n\n/**\n * Writes a plan as a {@link PdfPlanDocument}, plain JSON-ready data, with\n * positions and sizes in whole millionths of the page.\n *\n * @param plan - The plan, such as a session snapshot's.\n * @param sources - The sources by id, with at least every one the plan's\n * pages and form values use. They're written as given.\n * @throws `TypeError` if a source the plan uses is missing from `sources`,\n * or the plan has a signature annotation, which version 1 can't hold.\n * @public\n */\nexport function toPdfPlanDocument(\n plan: PdfPlan,\n sources: Readonly<Record<string, PdfPlanDocumentSource>>,\n): PdfPlanDocument {\n for (const source of [\n ...plan.pages.map((page) => page.source),\n ...Object.keys(plan.formValues),\n ]) {\n if (!Object.hasOwn(sources, source)) {\n throw new TypeError(`The sources don't include ${source}, which the plan uses.`);\n }\n }\n return {\n format: PDF_PLAN_FORMAT,\n version: PDF_PLAN_VERSION,\n sources: Object.fromEntries(\n Object.entries(sources).map(([id, { pageCount, asset }]) => [\n id,\n asset === undefined ? { pageCount } : { pageCount, asset: { ...asset } },\n ]),\n ),\n pages: plan.pages.map((page) => ({\n key: page.key,\n source: page.source,\n pageIndex: page.pageIndex,\n rotation: page.rotation,\n annotations: page.annotations.map(annotationToDocument),\n })),\n formValues: Object.fromEntries(\n Object.entries(plan.formValues).map(([source, values]) => [\n source,\n Object.fromEntries(Object.entries(values)),\n ]),\n ),\n };\n}\n\n/**\n * Reads a command in its portable form, `hm-pdf-command` version 1, such as\n * one parsed from JSON, into the command the session executes: an\n * annotation's millionths become fractions of the page. The session's\n * reducer checks everything else when the command runs.\n *\n * @param value - The parsed JSON.\n * @throws `PdfError` with `INVALID_COMMAND` and `malformed-command` for a\n * position or size that isn't whole millionths, and `unknown-command` for\n * `pdf.restorePages`, which isn't part of the format.\n * @public\n */\nexport function readPdfCommandDocument(value: unknown): PdfCommand {\n try {\n if (!isRecord<Record<string, unknown>>(value)) return value as PdfCommand;\n if (value[\"type\"] === \"pdf.restorePages\") {\n invalid(\"unknown-command\", \"pdf.restorePages isn't a command of the portable format\");\n }\n if (value[\"type\"] !== \"pdf.addAnnotation\") return value as unknown as PdfCommand;\n return Object.fromEntries(\n Object.entries(value).map(([name, entry]) => [\n name,\n name === \"annotation\" ? annotationFromDocument(entry) : entry,\n ]),\n ) as unknown as PdfCommand;\n } catch (error) {\n if (!(error instanceof Invalid)) throw error;\n throw new PdfError(\"INVALID_COMMAND\", `Invalid command: ${error.message}.`, {\n details: { reason: error.reason },\n });\n }\n}\n\n/**\n * Writes a command in its portable form, `hm-pdf-command` version 1, with an\n * annotation's positions and sizes in whole millionths of the page.\n *\n * @param command - A command the session applied, so its values are on the\n * grid.\n * @throws `TypeError` for `pdf.restorePages`, which isn't part of the\n * format, and for a signature annotation, which version 1 can't hold.\n * @public\n */\nexport function toPdfCommandDocument(command: PdfCommand): PdfCommandDocument {\n if (command.type === \"pdf.restorePages\") {\n throw new TypeError(\"pdf.restorePages isn't a command of the portable format.\");\n }\n if (command.type !== \"pdf.addAnnotation\") return structuredClone(command);\n return {\n type: \"pdf.addAnnotation\",\n page: command.page,\n annotation: annotationToDocument(command.annotation),\n ...(command.index === undefined ? {} : { index: command.index }),\n };\n}\n"],"mappings":";;AA4BA,IAAa,kBAAkB;AAQ/B,IAAa,mBAAmB;AAsKhC,IAAM,kBAAkB;CAAC;CAAU;CAAW;CAAW;CAAS;AAAY;AAC9E,IAAM,cAAc;CAAC;CAAO;CAAU;CAAa;CAAY;AAAa;AAC5E,IAAM,eAAe;CAAC;CAAS;CAAa;AAAM;AAElD,IAAM,WAAW;AACjB,IAAM,aAAa;AACnB,IAAM,YAA+B;CAAC;CAAG;CAAI;CAAK;AAAG;AAErD,SAAS,UAAU,SAAwB;CACzC,OAAO,QAAQ,qBAAqB,OAAO;AAC7C;AAEA,IAAM,WAAW,OAAgB,QAC/B,OAAO,cAAc,KAAK,KAAM,SAAoB;AAGtD,SAAS,SAAS,OAAgB,MAAsB;CACtD,IAAI,CAAC,OAAO,cAAc,KAAK,GAAG,UAAU,GAAG,KAAK,iCAAiC;CACrF,OAAQ,QAAmB;AAC7B;AAEA,IAAM,eAAe,aAAqB,KAAK,MAAM,WAAW,iBAAiB;AAEjF,SAAS,kBAAkB,OAAgB,MAAuB;CAChE,IAAI,CAAC,SAAkC,KAAK,GAAG,OAAO;CACtD,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC3C,MACA,SAAS,OAAO,SAAS,MAAM,SAAS,OAAO,GAAG,KAAK,GAAG,MAAM,IAAI,KACtE,CAAC,CACH;AACF;AAOA,SAAS,uBAAuB,OAAyB;CACvD,IAAI,CAAC,SAAkC,KAAK,GAAG,OAAO;CACtD,MAAM,EAAE,SAAS;CACjB,IAAI,SAAS,SAAS,SAAS,eAAe,SAAS,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