@embedpdf/engine-core 3.0.0-next.14 → 3.0.0-next.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/AnnotationList-DcyhF2kU.d.cts +27691 -0
  2. package/dist/AnnotationList-DcyhF2kU.d.ts +27691 -0
  3. package/dist/Change-Ct-dB8D5.cjs +1133 -0
  4. package/dist/Change-Ct-dB8D5.cjs.map +1 -0
  5. package/dist/Change-tMR34hTU.js +978 -0
  6. package/dist/Change-tMR34hTU.js.map +1 -0
  7. package/dist/DocumentRenderService-9IjSQEIU.cjs +121 -0
  8. package/dist/DocumentRenderService-9IjSQEIU.cjs.map +1 -0
  9. package/dist/DocumentRenderService-DFrZ9wfW.js +86 -0
  10. package/dist/DocumentRenderService-DFrZ9wfW.js.map +1 -0
  11. package/dist/{DocumentSecurityService-Ca6EK3-3.d.ts → DocumentSecurityService-D2zA4NKi.d.cts} +100 -112
  12. package/dist/{DocumentSecurityService-CIx1MT0T.d.cts → DocumentSecurityService-YJV9df8P.d.ts} +100 -112
  13. package/dist/LocalDocumentHandle-D02FMm-Z.cjs +53 -0
  14. package/dist/LocalDocumentHandle-D02FMm-Z.cjs.map +1 -0
  15. package/dist/LocalDocumentHandle-DAPdaOt_.js +30 -0
  16. package/dist/LocalDocumentHandle-DAPdaOt_.js.map +1 -0
  17. package/dist/LocalEngine-DBt2-GWF.d.ts +1649 -0
  18. package/dist/LocalEngine-IA9zh3Jh.d.cts +1649 -0
  19. package/dist/PageInsertBlankInput-CXHAM7l6.cjs +17 -0
  20. package/dist/PageInsertBlankInput-CXHAM7l6.cjs.map +1 -0
  21. package/dist/PageInsertBlankInput-DhVYVJ_S.js +12 -0
  22. package/dist/PageInsertBlankInput-DhVYVJ_S.js.map +1 -0
  23. package/dist/authority-BFp6XM04.cjs +2997 -0
  24. package/dist/authority-BFp6XM04.cjs.map +1 -0
  25. package/dist/authority-PuxpGFhJ.js +2506 -0
  26. package/dist/authority-PuxpGFhJ.js.map +1 -0
  27. package/dist/builders-DV62HA3I.js +165 -0
  28. package/dist/builders-DV62HA3I.js.map +1 -0
  29. package/dist/builders-DgTAj_tP.cjs +188 -0
  30. package/dist/builders-DgTAj_tP.cjs.map +1 -0
  31. package/dist/calibrate-DJbi1wuK.cjs +3012 -0
  32. package/dist/calibrate-DJbi1wuK.cjs.map +1 -0
  33. package/dist/calibrate-nQFgCuki.js +2461 -0
  34. package/dist/calibrate-nQFgCuki.js.map +1 -0
  35. package/dist/charmap-Cprti1ta.js +239 -0
  36. package/dist/charmap-Cprti1ta.js.map +1 -0
  37. package/dist/charmap-aYlefQP9.cjs +304 -0
  38. package/dist/charmap-aYlefQP9.cjs.map +1 -0
  39. package/dist/conformance.cjs +18146 -5258
  40. package/dist/conformance.cjs.map +1 -1
  41. package/dist/conformance.d.cts +1024 -170
  42. package/dist/conformance.d.ts +1024 -170
  43. package/dist/conformance.js +18148 -5309
  44. package/dist/conformance.js.map +1 -1
  45. package/dist/format-Bp3QFSH1.cjs +574 -0
  46. package/dist/format-Bp3QFSH1.cjs.map +1 -0
  47. package/dist/format-Dgg428Kb.js +461 -0
  48. package/dist/format-Dgg428Kb.js.map +1 -0
  49. package/dist/index.cjs +342 -116
  50. package/dist/index.d.cts +2 -2
  51. package/dist/index.d.ts +2 -2
  52. package/dist/index.js +14 -5
  53. package/dist/pageRefs-B3ur7Ckm.cjs +51 -0
  54. package/dist/pageRefs-B3ur7Ckm.cjs.map +1 -0
  55. package/dist/pageRefs-DkbuxSCV.js +40 -0
  56. package/dist/pageRefs-DkbuxSCV.js.map +1 -0
  57. package/dist/public.cjs +59 -0
  58. package/dist/public.d.cts +5 -0
  59. package/dist/public.d.ts +5 -0
  60. package/dist/public.js +9 -0
  61. package/dist/resolveAnnotationDraft-7Ke4nV7F.cjs +3646 -0
  62. package/dist/resolveAnnotationDraft-7Ke4nV7F.cjs.map +1 -0
  63. package/dist/resolveAnnotationDraft-CUpf0SMh.js +3167 -0
  64. package/dist/resolveAnnotationDraft-CUpf0SMh.js.map +1 -0
  65. package/dist/{resolver-inAVzsWt.js → resolver-BBggAxQc.js} +298 -145
  66. package/dist/resolver-BBggAxQc.js.map +1 -0
  67. package/dist/{resolver-CYVNV4hn.cjs → resolver-BWSWSF6R.cjs} +351 -144
  68. package/dist/resolver-BWSWSF6R.cjs.map +1 -0
  69. package/dist/runtime-BaDKjxiu.d.ts +1959 -0
  70. package/dist/runtime-CWEuiwbk.d.cts +1959 -0
  71. package/dist/runtime.cjs +986 -297
  72. package/dist/runtime.cjs.map +1 -1
  73. package/dist/runtime.d.cts +5 -1372
  74. package/dist/runtime.d.ts +5 -1372
  75. package/dist/runtime.js +634 -179
  76. package/dist/runtime.js.map +1 -1
  77. package/dist/schema-6S2VmlAj.js +2087 -0
  78. package/dist/schema-6S2VmlAj.js.map +1 -0
  79. package/dist/schema-miH6tWQC.cjs +3046 -0
  80. package/dist/schema-miH6tWQC.cjs.map +1 -0
  81. package/dist/schemas-BE2QGOit.js +1851 -0
  82. package/dist/schemas-BE2QGOit.js.map +1 -0
  83. package/dist/schemas-DljJR9ut.cjs +2798 -0
  84. package/dist/schemas-DljJR9ut.cjs.map +1 -0
  85. package/dist/subtype-CG4WpIRj.js +129 -0
  86. package/dist/subtype-CG4WpIRj.js.map +1 -0
  87. package/dist/subtype-aDt5TFmK.cjs +158 -0
  88. package/dist/subtype-aDt5TFmK.cjs.map +1 -0
  89. package/dist/validation.cjs +578 -0
  90. package/dist/validation.cjs.map +1 -0
  91. package/dist/validation.d.cts +174 -0
  92. package/dist/validation.d.ts +174 -0
  93. package/dist/validation.js +571 -0
  94. package/dist/validation.js.map +1 -0
  95. package/dist/value-BFS1R8ek.cjs +435 -0
  96. package/dist/value-BFS1R8ek.cjs.map +1 -0
  97. package/dist/value-Dhc8eYcx.js +340 -0
  98. package/dist/value-Dhc8eYcx.js.map +1 -0
  99. package/dist/viewport-CHG9qQUb.cjs +671 -0
  100. package/dist/viewport-CHG9qQUb.cjs.map +1 -0
  101. package/dist/viewport-DQR5LyX3.js +540 -0
  102. package/dist/viewport-DQR5LyX3.js.map +1 -0
  103. package/dist/wire.cjs +1242 -420
  104. package/dist/wire.cjs.map +1 -1
  105. package/dist/wire.d.cts +14840 -830
  106. package/dist/wire.d.ts +14840 -830
  107. package/dist/wire.js +985 -261
  108. package/dist/wire.js.map +1 -1
  109. package/package.json +10 -1
  110. package/dist/AbortError-DwuHPK_I.js +0 -27
  111. package/dist/AbortError-DwuHPK_I.js.map +0 -1
  112. package/dist/AbortError-P0RU0Mgg.cjs +0 -38
  113. package/dist/AbortError-P0RU0Mgg.cjs.map +0 -1
  114. package/dist/AnnotationListSnapshot-D9R5n2Kf.d.cts +0 -7101
  115. package/dist/AnnotationListSnapshot-D9R5n2Kf.d.ts +0 -7101
  116. package/dist/Engine-EWWHhEIi.d.ts +0 -1277
  117. package/dist/Engine-FNaAEjfb.d.cts +0 -1277
  118. package/dist/derive-BbsDk_Kz.cjs +0 -880
  119. package/dist/derive-BbsDk_Kz.cjs.map +0 -1
  120. package/dist/derive-DAFJolWu.js +0 -647
  121. package/dist/derive-DAFJolWu.js.map +0 -1
  122. package/dist/format-Bbphf4zR.js +0 -435
  123. package/dist/format-Bbphf4zR.js.map +0 -1
  124. package/dist/format-D_epWlob.cjs +0 -518
  125. package/dist/format-D_epWlob.cjs.map +0 -1
  126. package/dist/resolver-CYVNV4hn.cjs.map +0 -1
  127. package/dist/resolver-inAVzsWt.js.map +0 -1
  128. package/dist/schemas-CFQGvWiu.js +0 -3243
  129. package/dist/schemas-CFQGvWiu.js.map +0 -1
  130. package/dist/schemas-D0g6tKa9.cjs +0 -4694
  131. package/dist/schemas-D0g6tKa9.cjs.map +0 -1
  132. package/dist/viewport-BWeNHZmb.cjs +0 -3503
  133. package/dist/viewport-BWeNHZmb.cjs.map +0 -1
  134. package/dist/viewport-CvMcadfQ.js +0 -3072
  135. package/dist/viewport-CvMcadfQ.js.map +0 -1
@@ -1,3243 +0,0 @@
1
- import { f as PdfAnnotationSubtypeCode, m as EngineErrorCode, n as validNumberFormat, o as charMapViolation } from "./format-Bbphf4zR.js";
2
- import { z } from "zod";
3
- //#region src/geometry/schemas.ts
4
- /**
5
- * Zod schemas for engine PDF-document geometry. Exported from `wire.ts` ONLY
6
- * (never from `shared.ts`/`runtime`) so the zod-free runtime stays zod-free.
7
- */
8
- const PdfPointSchema = z.object({
9
- x: z.number(),
10
- y: z.number()
11
- });
12
- const LinePointsSchema = z.object({
13
- start: PdfPointSchema,
14
- end: PdfPointSchema
15
- });
16
- /** `/CL` callout leader line — two points (straight) or three (knee-jointed). */
17
- const CalloutLineSchema = z.union([z.tuple([PdfPointSchema, PdfPointSchema]), z.tuple([
18
- PdfPointSchema,
19
- PdfPointSchema,
20
- PdfPointSchema
21
- ])]);
22
- /** `/InkList` — an array of strokes, each an array of points. */
23
- const InkListSchema = z.array(z.array(PdfPointSchema));
24
- const PdfRectSchema = z.object({
25
- left: z.number(),
26
- bottom: z.number(),
27
- right: z.number(),
28
- top: z.number()
29
- });
30
- const PdfSizeSchema = z.object({
31
- width: z.number().nonnegative(),
32
- height: z.number().nonnegative()
33
- });
34
- const PdfQuadSchema = z.object({
35
- p1: PdfPointSchema,
36
- p2: PdfPointSchema,
37
- p3: PdfPointSchema,
38
- p4: PdfPointSchema
39
- });
40
- const PdfRotationSchema = z.union([
41
- z.literal(0),
42
- z.literal(90),
43
- z.literal(180),
44
- z.literal(270)
45
- ]);
46
- //#endregion
47
- //#region src/dto/PdfDestination.schema.ts
48
- const pageObjectNumber = z.number().int().positive();
49
- /** Spec-nullable axis value: absent and `null` both mean "retain current". */
50
- const axis = z.number().nullable().optional();
51
- /**
52
- * Runtime schema for {@link PdfDestination}. Lives beside its DTO in `dto/`
53
- * so every destination-shaped surface (link targets, action-node payloads,
54
- * the document `openDestination`) shares one schema without an import cycle
55
- * through the annotation tree.
56
- */
57
- const PdfDestinationSchema = z.discriminatedUnion("kind", [
58
- z.object({
59
- kind: z.literal("xyz"),
60
- pageObjectNumber,
61
- left: axis,
62
- top: axis,
63
- zoom: axis
64
- }),
65
- z.object({
66
- kind: z.literal("fit"),
67
- pageObjectNumber
68
- }),
69
- z.object({
70
- kind: z.literal("fitH"),
71
- pageObjectNumber,
72
- top: axis
73
- }),
74
- z.object({
75
- kind: z.literal("fitV"),
76
- pageObjectNumber,
77
- left: axis
78
- }),
79
- z.object({
80
- kind: z.literal("fitR"),
81
- pageObjectNumber,
82
- left: z.number(),
83
- bottom: z.number(),
84
- right: z.number(),
85
- top: z.number()
86
- }),
87
- z.object({
88
- kind: z.literal("fitB"),
89
- pageObjectNumber
90
- }),
91
- z.object({
92
- kind: z.literal("fitBH"),
93
- pageObjectNumber,
94
- top: axis
95
- }),
96
- z.object({
97
- kind: z.literal("fitBV"),
98
- pageObjectNumber,
99
- left: axis
100
- })
101
- ]);
102
- //#endregion
103
- //#region src/dto/PdfAction.schema.ts
104
- const PdfActionTargetRefSchema = z.discriminatedUnion("kind", [z.object({
105
- kind: z.literal("name"),
106
- name: z.string()
107
- }), z.object({
108
- kind: z.literal("objectNumber"),
109
- objectNumber: z.number().int().positive()
110
- })]);
111
- /** Fields every node arm repeats — zod 3's discriminatedUnion needs plain
112
- * object options, so the recursion (`next`) lives inline per arm and the
113
- * whole union sits behind one `z.lazy`. */
114
- const nodeCommon = {
115
- subtype: z.string(),
116
- next: z.array(z.lazy(() => PdfActionNodeSchema))
117
- };
118
- const arm = (type, shape = {}) => z.object({
119
- type: z.literal(type),
120
- ...nodeCommon,
121
- ...shape
122
- });
123
- const SubmitFormFlagsSchema = z.object({
124
- raw: z.number().int().nonnegative(),
125
- exclude: z.boolean(),
126
- includeNoValueFields: z.boolean(),
127
- format: z.enum([
128
- "fdf",
129
- "html",
130
- "xfdf",
131
- "pdf"
132
- ]),
133
- method: z.enum(["post", "get"]),
134
- submitCoordinates: z.boolean(),
135
- includeAppendSaves: z.boolean(),
136
- includeAnnotations: z.boolean(),
137
- canonicalFormat: z.boolean(),
138
- exclNonUserAnnots: z.boolean(),
139
- exclFKey: z.boolean(),
140
- embedForm: z.boolean()
141
- });
142
- const PDF_ACTION_NODE_ARMS = [
143
- arm("javascript", { script: z.string() }),
144
- arm("goto", { destination: PdfDestinationSchema }),
145
- arm("uri", {
146
- uri: z.string(),
147
- isMap: z.boolean()
148
- }),
149
- arm("named", { name: z.string() }),
150
- arm("hide", {
151
- targets: z.array(PdfActionTargetRefSchema),
152
- hide: z.boolean()
153
- }),
154
- arm("reset-form", {
155
- fields: z.array(PdfActionTargetRefSchema).nullable(),
156
- exclude: z.boolean()
157
- }),
158
- arm("goto-remote", { filePath: z.string() }),
159
- arm("goto-embedded", { filePath: z.string() }),
160
- arm("launch", { filePath: z.string() }),
161
- arm("rendition", { script: z.string().optional() }),
162
- arm("submit-form", { payload: z.object({
163
- url: z.string(),
164
- fields: z.array(PdfActionTargetRefSchema).nullable(),
165
- flags: SubmitFormFlagsSchema,
166
- charSet: z.string().optional()
167
- }).optional() }),
168
- arm("thread"),
169
- arm("sound"),
170
- arm("movie"),
171
- arm("import-data"),
172
- arm("set-ocg-state"),
173
- arm("transition"),
174
- arm("goto-3d-view"),
175
- arm("unknown")
176
- ];
177
- const PdfActionNodeSchema = z.lazy(() => z.discriminatedUnion("type", [...PDF_ACTION_NODE_ARMS]));
178
- /** The `/S` vocabulary, derived from the union arms so it cannot drift. */
179
- const PdfActionTypeSchema = z.enum(PDF_ACTION_NODE_ARMS.map((option) => option.shape.type.value));
180
- const PdfActionTreeSchema = z.object({
181
- root: PdfActionNodeSchema.nullable(),
182
- incomplete: z.boolean(),
183
- warningFlags: z.number().int().nonnegative(),
184
- warnings: z.array(z.enum([
185
- "cycle-dropped",
186
- "malformed-next",
187
- "incomplete",
188
- "payload-dropped"
189
- ]))
190
- });
191
- const PdfFieldActionsSchema = z.object({
192
- keystroke: PdfActionTreeSchema.optional(),
193
- format: PdfActionTreeSchema.optional(),
194
- validate: PdfActionTreeSchema.optional(),
195
- calculate: PdfActionTreeSchema.optional()
196
- });
197
- const PdfPageActionsSchema = z.object({
198
- open: PdfActionTreeSchema.optional(),
199
- close: PdfActionTreeSchema.optional()
200
- });
201
- const PdfAnnotationActionsSchema = z.object({
202
- activate: PdfActionTreeSchema.optional(),
203
- cursorEnter: PdfActionTreeSchema.optional(),
204
- cursorExit: PdfActionTreeSchema.optional(),
205
- mouseDown: PdfActionTreeSchema.optional(),
206
- mouseUp: PdfActionTreeSchema.optional(),
207
- focus: PdfActionTreeSchema.optional(),
208
- blur: PdfActionTreeSchema.optional(),
209
- pageOpen: PdfActionTreeSchema.optional(),
210
- pageClose: PdfActionTreeSchema.optional(),
211
- pageVisible: PdfActionTreeSchema.optional(),
212
- pageInvisible: PdfActionTreeSchema.optional()
213
- });
214
- const DocumentActionsSnapshotSchema = z.object({
215
- nameTreeScripts: z.array(z.object({
216
- name: z.string(),
217
- action: PdfActionTreeSchema
218
- })),
219
- openAction: PdfActionTreeSchema.nullable(),
220
- openDestination: PdfDestinationSchema.nullable().default(null),
221
- willClose: PdfActionTreeSchema.optional(),
222
- willSave: PdfActionTreeSchema.optional(),
223
- didSave: PdfActionTreeSchema.optional(),
224
- willPrint: PdfActionTreeSchema.optional(),
225
- didPrint: PdfActionTreeSchema.optional()
226
- }).superRefine((snapshot, context) => {
227
- if (snapshot.openAction !== null && (snapshot.openDestination ?? null) !== null) context.addIssue({
228
- code: z.ZodIssueCode.custom,
229
- message: "openAction and openDestination are mutually exclusive",
230
- path: ["openDestination"]
231
- });
232
- });
233
- /**
234
- * Stable public component names for generators that project the action wire
235
- * model into OpenAPI or another schema format. Keep reusable boundaries here;
236
- * individual action arms remain owned by `PdfActionNodeSchema`.
237
- */
238
- const PdfActionWireComponents = {
239
- PdfActionTargetRef: PdfActionTargetRefSchema,
240
- PdfDestination: PdfDestinationSchema,
241
- PdfActionNode: PdfActionNodeSchema,
242
- PdfActionTree: PdfActionTreeSchema,
243
- PdfFieldActions: PdfFieldActionsSchema,
244
- PdfPageActions: PdfPageActionsSchema,
245
- PdfAnnotationActions: PdfAnnotationActionsSchema,
246
- DocumentActionsSnapshot: DocumentActionsSnapshotSchema
247
- };
248
- //#endregion
249
- //#region src/annotation/base.schema.ts
250
- /** @deprecated Use `PdfPointSchema` from `../geometry/schemas`. */
251
- const PointSchema = PdfPointSchema;
252
- /** @deprecated Use `PdfRectSchema` from `../geometry/schemas`. */
253
- const RectSchema = PdfRectSchema;
254
- const ColorSchema = z.object({
255
- r: z.number().int().min(0).max(255),
256
- g: z.number().int().min(0).max(255),
257
- b: z.number().int().min(0).max(255)
258
- });
259
- const AnnotationBorderStyleSchema = z.enum([
260
- "solid",
261
- "dashed",
262
- "beveled",
263
- "inset"
264
- ]);
265
- const PdfRectDifferencesSchema = z.object({
266
- left: z.number().nonnegative(),
267
- top: z.number().nonnegative(),
268
- right: z.number().nonnegative(),
269
- bottom: z.number().nonnegative()
270
- });
271
- const LineEndingSchema = z.enum([
272
- "none",
273
- "square",
274
- "circle",
275
- "diamond",
276
- "open-arrow",
277
- "closed-arrow",
278
- "butt",
279
- "r-open-arrow",
280
- "r-closed-arrow",
281
- "slash"
282
- ]);
283
- const LineEndingsSchema = z.object({
284
- start: LineEndingSchema,
285
- end: LineEndingSchema
286
- });
287
- const StandardFontSchema = z.enum([
288
- "courier",
289
- "courier-bold",
290
- "courier-bold-oblique",
291
- "courier-oblique",
292
- "helvetica",
293
- "helvetica-bold",
294
- "helvetica-bold-oblique",
295
- "helvetica-oblique",
296
- "times-roman",
297
- "times-bold",
298
- "times-bold-italic",
299
- "times-italic",
300
- "symbol",
301
- "zapf-dingbats"
302
- ]);
303
- const TextAlignmentSchema = z.enum([
304
- "left",
305
- "center",
306
- "right"
307
- ]);
308
- const FreeTextIntentSchema = z.enum(["free-text", "free-text-callout"]);
309
- const CaretIntentSchema = z.literal("replace");
310
- const StrikeoutIntentSchema = z.literal("strikeout-text-edit");
311
- const InkIntentSchema = z.literal("ink-highlight");
312
- const BlendModeSchema = z.enum([
313
- "normal",
314
- "multiply",
315
- "screen",
316
- "overlay",
317
- "darken",
318
- "lighten",
319
- "color-dodge",
320
- "color-burn",
321
- "hard-light",
322
- "soft-light",
323
- "difference",
324
- "exclusion",
325
- "hue",
326
- "saturation",
327
- "color",
328
- "luminosity"
329
- ]);
330
- const AnnotationFlagsSchema = z.object({
331
- invisible: z.boolean(),
332
- hidden: z.boolean(),
333
- print: z.boolean(),
334
- noZoom: z.boolean(),
335
- noRotate: z.boolean(),
336
- noView: z.boolean(),
337
- readOnly: z.boolean(),
338
- locked: z.boolean(),
339
- toggleNoView: z.boolean(),
340
- lockedContents: z.boolean()
341
- });
342
- /**
343
- * Partial flag set authorable on a Draft or Patch — every key optional so
344
- * callers set only the bits they care about. The engine merges these onto
345
- * the annotation's current `/F` bitset.
346
- */
347
- const AnnotationFlagsPartialSchema = z.object({
348
- invisible: z.boolean(),
349
- hidden: z.boolean(),
350
- print: z.boolean(),
351
- noZoom: z.boolean(),
352
- noRotate: z.boolean(),
353
- noView: z.boolean(),
354
- readOnly: z.boolean(),
355
- locked: z.boolean(),
356
- toggleNoView: z.boolean(),
357
- lockedContents: z.boolean()
358
- }).partial();
359
- const AnnotationStableIdSchema = z.discriminatedUnion("kind", [z.object({
360
- kind: z.literal("objectNumber"),
361
- value: z.number().int().nonnegative()
362
- }), z.object({
363
- kind: z.literal("nm"),
364
- value: z.string()
365
- })]);
366
- const RevisionTokenSchema = z.object({
367
- docSessionId: z.string(),
368
- pageObjectNumber: z.number().int().positive(),
369
- generation: z.number().int().nonnegative()
370
- });
371
- const AnnotationRefSchema = z.discriminatedUnion("kind", [
372
- z.object({
373
- kind: z.literal("objectNumber"),
374
- pageObjectNumber: z.number().int().positive(),
375
- annotObjectNumber: z.number().int().positive()
376
- }),
377
- z.object({
378
- kind: z.literal("nm"),
379
- pageObjectNumber: z.number().int().positive(),
380
- nm: z.string()
381
- }),
382
- z.object({
383
- kind: z.literal("index"),
384
- pageObjectNumber: z.number().int().positive(),
385
- index: z.number().int().nonnegative(),
386
- revision: RevisionTokenSchema
387
- })
388
- ]);
389
- /**
390
- * Shared object literal for every per-subtype DTO schema. Each kind's
391
- * `dto.schema.ts` extends this with its own `subtype` literal and
392
- * subtype-specific fields. Note that we do NOT include `subtype` here —
393
- * each kind sets its own literal so `z.discriminatedUnion('subtype', ...)`
394
- * works at the catalog level.
395
- */
396
- const AnnotationBaseShape = {
397
- ref: AnnotationRefSchema,
398
- pageObjectNumber: z.number().int().positive(),
399
- index: z.number().int().nonnegative(),
400
- identityQuality: z.enum(["durable", "weak"]),
401
- nm: z.string().nullable(),
402
- flags: AnnotationFlagsSchema,
403
- rect: PdfRectSchema,
404
- contents: z.string().nullable(),
405
- subject: z.string().nullable(),
406
- author: z.string().nullable(),
407
- created: z.string().datetime().nullable(),
408
- modified: z.string().datetime().nullable(),
409
- blendMode: BlendModeSchema,
410
- inReplyTo: AnnotationRefSchema.nullable(),
411
- replyType: z.enum(["reply", "group"]).nullable(),
412
- userId: z.string().optional(),
413
- groupId: z.string().optional(),
414
- createdBy: z.string().optional(),
415
- updatedBy: z.string().optional(),
416
- actions: PdfAnnotationActionsSchema.optional()
417
- };
418
- /**
419
- * Annotation-wide fields shared by every Draft. Per-kind draft schemas
420
- * spread this alongside their family-specific shape.
421
- *
422
- * Authorial identity (/T, /EMBD_Metadata UserID/GroupID) is set by the
423
- * server from the caller's JWT identity — see the AnnotationDraftBase
424
- * docstring.
425
- */
426
- const AnnotationDraftBaseShape = {
427
- contents: z.string().nullable().optional(),
428
- subject: z.string().nullable().optional(),
429
- blendMode: BlendModeSchema.optional(),
430
- nm: z.string().optional(),
431
- flags: AnnotationFlagsPartialSchema.optional(),
432
- inReplyTo: AnnotationRefSchema.optional(),
433
- replyType: z.enum(["reply", "group"]).optional()
434
- };
435
- /**
436
- * Annotation-wide fields shared by every Patch. `nm` is monotonic per
437
- * annotation; clients target an existing annotation via AnnotationRef
438
- * instead of renaming.
439
- *
440
- * `groupId` is the only identity-shaped field on a patch — it
441
- * represents organizational ownership, and reassignment runs through
442
- * `checkSetGroup`. See AnnotationPatchBase for the full immutability
443
- * rules.
444
- */
445
- const AnnotationPatchBaseShape = {
446
- contents: z.string().nullable().optional(),
447
- subject: z.string().nullable().optional(),
448
- blendMode: BlendModeSchema.optional(),
449
- groupId: z.string().min(1).optional(),
450
- flags: AnnotationFlagsPartialSchema.optional(),
451
- inReplyTo: AnnotationRefSchema.nullable().optional(),
452
- replyType: z.enum(["reply", "group"]).optional()
453
- };
454
- //#endregion
455
- //#region src/annotation/kinds/style.shared.ts
456
- const ColorStyleDTOShape = {
457
- color: ColorSchema,
458
- opacity: z.number().min(0).max(1)
459
- };
460
- const ColorStyleDraftShape = {
461
- color: ColorSchema.optional(),
462
- opacity: z.number().min(0).max(1).optional()
463
- };
464
- const ColorStylePatchShape = ColorStyleDraftShape;
465
- const GeometryStyleDTOShape = {
466
- ...ColorStyleDTOShape,
467
- strokeWidth: z.number().nonnegative(),
468
- borderStyle: AnnotationBorderStyleSchema,
469
- dashArray: z.array(z.number().nonnegative()).optional()
470
- };
471
- const GeometryStyleDraftShape = {
472
- ...ColorStyleDraftShape,
473
- strokeWidth: z.number().nonnegative().optional(),
474
- borderStyle: AnnotationBorderStyleSchema.optional(),
475
- dashArray: z.array(z.number().nonnegative()).optional()
476
- };
477
- const GeometryStylePatchShape = GeometryStyleDraftShape;
478
- const FilledStyleDTOShape = {
479
- ...GeometryStyleDTOShape,
480
- interiorColor: ColorSchema.nullable()
481
- };
482
- const FilledStyleDraftShape = {
483
- ...GeometryStyleDraftShape,
484
- interiorColor: ColorSchema.nullable().optional()
485
- };
486
- const FilledStylePatchShape = FilledStyleDraftShape;
487
- //#endregion
488
- //#region src/annotation/kinds/caret/schema.ts
489
- const CaretDTOSchema = z.object({
490
- ...AnnotationBaseShape,
491
- ...ColorStyleDTOShape,
492
- intent: CaretIntentSchema.nullable(),
493
- rectDifferences: PdfRectDifferencesSchema.nullable(),
494
- rotation: z.number().optional(),
495
- unrotatedRect: PdfRectSchema.optional(),
496
- subtype: z.literal("caret")
497
- });
498
- const CaretDraftSchema = z.object({
499
- ...ColorStyleDraftShape,
500
- ...AnnotationDraftBaseShape,
501
- intent: CaretIntentSchema.optional(),
502
- rect: PdfRectSchema,
503
- rectDifferences: PdfRectDifferencesSchema.nullable().optional(),
504
- rotation: z.number().nullable().optional(),
505
- unrotatedRect: PdfRectSchema.nullable().optional(),
506
- subtype: z.literal("caret")
507
- });
508
- const CaretPatchSchema = z.object({
509
- ...ColorStylePatchShape,
510
- ...AnnotationPatchBaseShape,
511
- intent: CaretIntentSchema.optional(),
512
- rect: PdfRectSchema.optional(),
513
- rectDifferences: PdfRectDifferencesSchema.nullable().optional(),
514
- rotation: z.number().nullable().optional(),
515
- unrotatedRect: PdfRectSchema.nullable().optional(),
516
- subtype: z.literal("caret")
517
- });
518
- //#endregion
519
- //#region src/annotation/kinds/caret/index.ts
520
- const CaretKind = {
521
- subtype: "caret",
522
- pdfSubtypeCode: PdfAnnotationSubtypeCode.CARET,
523
- dtoSchema: CaretDTOSchema,
524
- draftSchema: CaretDraftSchema,
525
- patchSchema: CaretPatchSchema
526
- };
527
- //#endregion
528
- //#region src/annotation/kinds/shape.shared.ts
529
- const ShapeDTOShape = {
530
- ...AnnotationBaseShape,
531
- ...FilledStyleDTOShape,
532
- cloudyIntensity: z.number().positive().nullable(),
533
- rectDifferences: PdfRectDifferencesSchema.nullable(),
534
- rotation: z.number().optional(),
535
- unrotatedRect: PdfRectSchema.optional()
536
- };
537
- const ShapeDraftShape = {
538
- ...FilledStyleDraftShape,
539
- rect: PdfRectSchema,
540
- cloudyIntensity: z.number().positive().nullable().optional(),
541
- rectDifferences: PdfRectDifferencesSchema.nullable().optional(),
542
- rotation: z.number().nullable().optional(),
543
- unrotatedRect: PdfRectSchema.nullable().optional()
544
- };
545
- const ShapePatchShape = {
546
- ...FilledStylePatchShape,
547
- rect: PdfRectSchema.optional(),
548
- cloudyIntensity: z.number().positive().nullable().optional(),
549
- rectDifferences: PdfRectDifferencesSchema.nullable().optional(),
550
- rotation: z.number().nullable().optional(),
551
- unrotatedRect: PdfRectSchema.nullable().optional()
552
- };
553
- //#endregion
554
- //#region src/annotation/kinds/circle/schema.ts
555
- const CircleDTOSchema = z.object({
556
- ...ShapeDTOShape,
557
- subtype: z.literal("circle")
558
- });
559
- const CircleDraftSchema = z.object({
560
- ...ShapeDraftShape,
561
- ...AnnotationDraftBaseShape,
562
- subtype: z.literal("circle")
563
- });
564
- const CirclePatchSchema = z.object({
565
- ...ShapePatchShape,
566
- ...AnnotationPatchBaseShape,
567
- subtype: z.literal("circle")
568
- });
569
- //#endregion
570
- //#region src/annotation/kinds/circle/index.ts
571
- const CircleKind = {
572
- subtype: "circle",
573
- pdfSubtypeCode: PdfAnnotationSubtypeCode.CIRCLE,
574
- dtoSchema: CircleDTOSchema,
575
- draftSchema: CircleDraftSchema,
576
- patchSchema: CirclePatchSchema
577
- };
578
- //#endregion
579
- //#region src/dto/Attachment.schema.ts
580
- /**
581
- * Wire schemas for the attachment read vocabulary (see `Attachment.ts`).
582
- * The write-side `AttachmentFileSource` carries inline bytes and never
583
- * appears on the wire — its post-normalization form is the kind-owned
584
- * `WireAttachmentFile` (see `annotation/kinds/file-attachment/schema.ts`).
585
- */
586
- const AttachmentFileInfoSchema = z.object({
587
- name: z.string(),
588
- mimeType: z.string().optional(),
589
- description: z.string().optional(),
590
- size: z.number().int().nonnegative().optional(),
591
- checksum: z.string().optional(),
592
- creationDate: z.string().optional()
593
- });
594
- const EmbeddedFileRefSchema = z.object({
595
- kind: z.literal("key"),
596
- key: z.string().min(1)
597
- });
598
- const EmbeddedFileItemSchema = z.object({
599
- key: z.string(),
600
- name: z.string(),
601
- mimeType: z.string().optional(),
602
- description: z.string().optional(),
603
- size: z.number().int().nonnegative().optional(),
604
- checksum: z.string().optional(),
605
- creationDate: z.string().optional(),
606
- index: z.number().int().nonnegative()
607
- });
608
- //#endregion
609
- //#region src/annotation/kinds/file-attachment/schema.ts
610
- const FileAttachmentIconSchema = z.enum([
611
- "push-pin",
612
- "paperclip",
613
- "graph",
614
- "tag"
615
- ]);
616
- /** Post-normalization form of the attached file: metadata + resource ref. */
617
- const WireAttachmentFileSchema = z.object({
618
- resource: z.string().min(1),
619
- name: z.string().min(1),
620
- mimeType: z.string().optional(),
621
- description: z.string().optional()
622
- });
623
- const FileAttachmentDTOSchema = z.object({
624
- ...AnnotationBaseShape,
625
- ...ColorStyleDTOShape,
626
- icon: FileAttachmentIconSchema,
627
- file: AttachmentFileInfoSchema,
628
- subtype: z.literal("file-attachment")
629
- });
630
- const FileAttachmentWireDraftSchema = z.object({
631
- ...ColorStyleDraftShape,
632
- ...AnnotationDraftBaseShape,
633
- rect: PdfRectSchema,
634
- file: WireAttachmentFileSchema,
635
- icon: FileAttachmentIconSchema.optional(),
636
- subtype: z.literal("file-attachment")
637
- });
638
- const FileAttachmentPatchSchema = z.object({
639
- ...ColorStylePatchShape,
640
- ...AnnotationPatchBaseShape,
641
- rect: PdfRectSchema.optional(),
642
- icon: FileAttachmentIconSchema.optional(),
643
- subtype: z.literal("file-attachment")
644
- });
645
- //#endregion
646
- //#region src/annotation/kinds/file-attachment/index.ts
647
- /**
648
- * WIRE-typed like `StampKind`: the draft schema validates the
649
- * post-normalization form (`file` as metadata + resource ref). The
650
- * authoring `FileAttachmentDraft` (inline bytes) is swapped into the
651
- * public `AnnotationDraft` union in `kinds/index.ts`. The patch carries
652
- * no binary (`file` is create-only), so its authoring and wire forms are
653
- * the same type.
654
- */
655
- const FileAttachmentKind = {
656
- subtype: "file-attachment",
657
- pdfSubtypeCode: PdfAnnotationSubtypeCode.FILEATTACHMENT,
658
- dtoSchema: FileAttachmentDTOSchema,
659
- draftSchema: FileAttachmentWireDraftSchema,
660
- patchSchema: FileAttachmentPatchSchema
661
- };
662
- //#endregion
663
- //#region src/annotation/kinds/free-text/schema.ts
664
- /** Authoring `fontFamily`: a standard font name OR a registered font `key`.
665
- * Any non-empty string is accepted; the writer resolves which it is (and a
666
- * key that was never registered fails loud there). The read-back DTO keeps the
667
- * narrower {@link StandardFontSchema}. */
668
- const FreeTextFontSchema = z.string().min(1);
669
- const HexColorSchema = z.string().regex(/^#[0-9a-fA-F]{6}$/);
670
- const RichTextRunStyleShape = {
671
- family: z.string().min(1),
672
- weight: z.number().int().min(100).max(900),
673
- italic: z.boolean(),
674
- size: z.number().nonnegative(),
675
- color: HexColorSchema,
676
- decoration: z.array(z.enum([
677
- "underline",
678
- "line-through",
679
- "word"
680
- ])),
681
- script: z.enum([
682
- "normal",
683
- "sub",
684
- "super"
685
- ]),
686
- letterSpacing: z.number(),
687
- horizontalScale: z.number().positive(),
688
- unknown: z.string().optional()
689
- };
690
- const RichTextParagraphPropsShape = {
691
- align: z.enum([
692
- "left",
693
- "center",
694
- "right",
695
- "justify"
696
- ]),
697
- dir: z.enum(["ltr", "rtl"]),
698
- lineHeight: z.number().positive().optional(),
699
- margins: z.object({
700
- top: z.number(),
701
- bottom: z.number(),
702
- left: z.number(),
703
- right: z.number()
704
- }).optional(),
705
- textIndent: z.number().optional(),
706
- unknown: z.string().optional()
707
- };
708
- const RichTextRunStyleDeltaSchema = z.object(RichTextRunStyleShape).partial();
709
- const RichTextParagraphSchema = z.object({
710
- ...RichTextParagraphPropsShape,
711
- runs: z.array(z.object({
712
- text: z.string(),
713
- style: RichTextRunStyleDeltaSchema.optional()
714
- }))
715
- }).partial({
716
- align: true,
717
- dir: true
718
- });
719
- const RichTextDocumentSchema = z.object({
720
- body: z.object({
721
- ...RichTextRunStyleShape,
722
- ...RichTextParagraphPropsShape
723
- }),
724
- paragraphs: z.array(RichTextParagraphSchema)
725
- });
726
- const RichTextDocumentInputSchema = z.object({
727
- body: z.object({
728
- ...RichTextRunStyleShape,
729
- ...RichTextParagraphPropsShape
730
- }).partial().optional(),
731
- paragraphs: z.array(RichTextParagraphSchema)
732
- });
733
- const FreeTextDTOSchema = z.object({
734
- ...AnnotationBaseShape,
735
- intent: FreeTextIntentSchema,
736
- fontFamily: FreeTextFontSchema,
737
- fontSize: z.number().positive(),
738
- textAlign: TextAlignmentSchema,
739
- richText: RichTextDocumentSchema,
740
- color: ColorSchema,
741
- fontColor: ColorSchema.optional(),
742
- interiorColor: ColorSchema.nullable(),
743
- opacity: z.number().min(0).max(1),
744
- strokeWidth: z.number().nonnegative(),
745
- borderStyle: AnnotationBorderStyleSchema,
746
- dashArray: z.array(z.number().nonnegative()).optional(),
747
- rectDifferences: PdfRectDifferencesSchema.nullable(),
748
- calloutLine: CalloutLineSchema.optional(),
749
- lineEnding: LineEndingSchema.optional(),
750
- rotation: z.number().optional(),
751
- unrotatedRect: PdfRectSchema.optional(),
752
- subtype: z.literal("free-text")
753
- });
754
- const FreeTextDraftSchema = z.object({
755
- ...AnnotationDraftBaseShape,
756
- intent: FreeTextIntentSchema,
757
- fontFamily: FreeTextFontSchema,
758
- fontSize: z.number().positive(),
759
- textAlign: TextAlignmentSchema,
760
- richText: RichTextDocumentInputSchema.optional(),
761
- rect: PdfRectSchema,
762
- color: ColorSchema.optional(),
763
- fontColor: ColorSchema.optional(),
764
- interiorColor: ColorSchema.nullable().optional(),
765
- opacity: z.number().min(0).max(1).optional(),
766
- strokeWidth: z.number().nonnegative().optional(),
767
- borderStyle: AnnotationBorderStyleSchema.optional(),
768
- dashArray: z.array(z.number().nonnegative()).optional(),
769
- rectDifferences: PdfRectDifferencesSchema.nullable().optional(),
770
- calloutLine: CalloutLineSchema.optional(),
771
- lineEnding: LineEndingSchema.optional(),
772
- rotation: z.number().nullable().optional(),
773
- unrotatedRect: PdfRectSchema.nullable().optional(),
774
- subtype: z.literal("free-text")
775
- });
776
- const FreeTextPatchSchema = z.object({
777
- ...AnnotationPatchBaseShape,
778
- intent: FreeTextIntentSchema.optional(),
779
- fontFamily: FreeTextFontSchema.optional(),
780
- fontSize: z.number().positive().optional(),
781
- textAlign: TextAlignmentSchema.optional(),
782
- richText: RichTextDocumentInputSchema.optional(),
783
- rect: PdfRectSchema.optional(),
784
- color: ColorSchema.optional(),
785
- fontColor: ColorSchema.optional(),
786
- interiorColor: ColorSchema.nullable().optional(),
787
- opacity: z.number().min(0).max(1).optional(),
788
- strokeWidth: z.number().nonnegative().optional(),
789
- borderStyle: AnnotationBorderStyleSchema.optional(),
790
- dashArray: z.array(z.number().nonnegative()).optional(),
791
- rectDifferences: PdfRectDifferencesSchema.nullable().optional(),
792
- calloutLine: CalloutLineSchema.optional(),
793
- lineEnding: LineEndingSchema.optional(),
794
- rotation: z.number().nullable().optional(),
795
- unrotatedRect: PdfRectSchema.nullable().optional(),
796
- subtype: z.literal("free-text")
797
- });
798
- //#endregion
799
- //#region src/annotation/kinds/free-text/index.ts
800
- const FreeTextKind = {
801
- subtype: "free-text",
802
- pdfSubtypeCode: PdfAnnotationSubtypeCode.FREETEXT,
803
- dtoSchema: FreeTextDTOSchema,
804
- draftSchema: FreeTextDraftSchema,
805
- patchSchema: FreeTextPatchSchema
806
- };
807
- //#endregion
808
- //#region src/annotation/kinds/text-markup.shared.ts
809
- const TextMarkupDTOShape = {
810
- ...AnnotationBaseShape,
811
- ...ColorStyleDTOShape,
812
- quadPoints: z.array(PdfQuadSchema)
813
- };
814
- const TextMarkupDraftShape = {
815
- ...ColorStyleDraftShape,
816
- quadPoints: z.array(PdfQuadSchema)
817
- };
818
- const TextMarkupPatchShape = {
819
- ...ColorStylePatchShape,
820
- quadPoints: z.array(PdfQuadSchema).optional()
821
- };
822
- //#endregion
823
- //#region src/annotation/kinds/highlight/schema.ts
824
- const HighlightDTOSchema = z.object({
825
- ...TextMarkupDTOShape,
826
- subtype: z.literal("highlight")
827
- });
828
- const HighlightDraftSchema = z.object({
829
- ...TextMarkupDraftShape,
830
- ...AnnotationDraftBaseShape,
831
- subtype: z.literal("highlight")
832
- });
833
- const HighlightPatchSchema = z.object({
834
- ...TextMarkupPatchShape,
835
- ...AnnotationPatchBaseShape,
836
- subtype: z.literal("highlight")
837
- });
838
- //#endregion
839
- //#region src/annotation/kinds/highlight/index.ts
840
- const HighlightKind = {
841
- subtype: "highlight",
842
- pdfSubtypeCode: PdfAnnotationSubtypeCode.HIGHLIGHT,
843
- dtoSchema: HighlightDTOSchema,
844
- draftSchema: HighlightDraftSchema,
845
- patchSchema: HighlightPatchSchema
846
- };
847
- //#endregion
848
- //#region src/annotation/kinds/ink/schema.ts
849
- const InkDTOSchema = z.object({
850
- ...AnnotationBaseShape,
851
- ...GeometryStyleDTOShape,
852
- intent: InkIntentSchema.nullable(),
853
- inkList: InkListSchema,
854
- rotation: z.number().optional(),
855
- subtype: z.literal("ink")
856
- });
857
- const InkDraftSchema = z.object({
858
- ...GeometryStyleDraftShape,
859
- ...AnnotationDraftBaseShape,
860
- intent: InkIntentSchema.optional(),
861
- inkList: InkListSchema,
862
- rect: PdfRectSchema,
863
- rotation: z.number().nullable().optional(),
864
- subtype: z.literal("ink")
865
- });
866
- const InkPatchSchema = z.object({
867
- ...GeometryStylePatchShape,
868
- ...AnnotationPatchBaseShape,
869
- intent: InkIntentSchema.optional(),
870
- inkList: InkListSchema.optional(),
871
- rect: PdfRectSchema.optional(),
872
- rotation: z.number().nullable().optional(),
873
- subtype: z.literal("ink")
874
- });
875
- //#endregion
876
- //#region src/annotation/kinds/ink/index.ts
877
- const InkKind = {
878
- subtype: "ink",
879
- pdfSubtypeCode: PdfAnnotationSubtypeCode.INK,
880
- dtoSchema: InkDTOSchema,
881
- draftSchema: InkDraftSchema,
882
- patchSchema: InkPatchSchema
883
- };
884
- //#endregion
885
- //#region src/dto/Measure.schema.ts
886
- const float = z.number().finite().refine((n) => Number.isFinite(Math.fround(n)), "Outside PDF float range");
887
- const point = z.object({
888
- x: float,
889
- y: float
890
- }).strict();
891
- const positive = float.refine((n) => Math.fround(n) > 0, "Must be positive in PDF float precision");
892
- const PdfNumberFormatSchema = z.object({
893
- unit: z.string(),
894
- conversion: float.optional(),
895
- fraction: z.enum([
896
- "decimal",
897
- "fraction",
898
- "round",
899
- "truncate"
900
- ]).optional(),
901
- precision: z.number().int().optional(),
902
- fixed: z.boolean().optional(),
903
- thousands: z.string().optional(),
904
- decimal: z.string().optional(),
905
- prefixSpacing: z.string().optional(),
906
- suffixSpacing: z.string().optional(),
907
- labelPosition: z.enum(["suffix", "prefix"]).optional()
908
- });
909
- const PdfMeasureSchema = z.object({
910
- subtype: z.literal("RL"),
911
- ratio: z.string().optional(),
912
- x: z.array(PdfNumberFormatSchema),
913
- y: z.array(PdfNumberFormatSchema).optional(),
914
- distance: z.array(PdfNumberFormatSchema),
915
- area: z.array(PdfNumberFormatSchema),
916
- angle: z.array(PdfNumberFormatSchema).optional(),
917
- slope: z.array(PdfNumberFormatSchema).optional(),
918
- origin: point.optional(),
919
- cyx: float.optional()
920
- });
921
- const writableFormat = PdfNumberFormatSchema.extend({
922
- conversion: positive,
923
- precision: z.number().int().min(1).max(2147483647).optional()
924
- }).refine(validNumberFormat, "Invalid number format precision");
925
- const PdfMeasureWriteSchema = PdfMeasureSchema.extend({
926
- x: z.array(writableFormat),
927
- y: z.array(writableFormat).optional(),
928
- distance: z.array(writableFormat),
929
- area: z.array(writableFormat),
930
- angle: z.array(writableFormat).optional(),
931
- slope: z.array(writableFormat).optional(),
932
- cyx: positive.optional()
933
- });
934
- const geoMeasure = z.object({ subtype: z.literal("GEO") });
935
- const unknownMeasure = z.object({ subtype: z.literal("unknown") });
936
- const PdfForeignMeasureSchema = z.union([geoMeasure, unknownMeasure]);
937
- const PageScaleInputSchema = z.object({ measure: PdfMeasureWriteSchema.nullable() });
938
- const PdfMeasurementSchema = z.discriminatedUnion("subtype", [
939
- PdfMeasureSchema,
940
- geoMeasure,
941
- unknownMeasure
942
- ]);
943
- const PageMeasurementViewportSchema = z.object({
944
- bbox: PdfRectSchema,
945
- name: z.string().optional(),
946
- measure: PdfMeasurementSchema.optional(),
947
- owned: z.boolean()
948
- });
949
- const LineIntentSchema = z.enum(["LineArrow", "LineDimension"]);
950
- const PolygonIntentSchema = z.enum(["PolygonCloud", "PolygonDimension"]);
951
- const PolylineIntentSchema = z.literal("PolyLineDimension");
952
- const offset = z.object({
953
- along: float,
954
- perpendicular: float
955
- }).strict();
956
- const LineDimensionCaptionSchema = z.object({
957
- enabled: z.boolean(),
958
- position: z.enum(["inline", "top"]).optional(),
959
- offset: offset.optional()
960
- }).strict();
961
- const ShapeDimensionCaptionSchema = z.object({
962
- enabled: z.boolean(),
963
- center: point.optional()
964
- }).strict();
965
- const LineCaptionPatchSchema = z.object({
966
- enabled: z.boolean().optional(),
967
- position: z.enum(["inline", "top"]).nullable().optional(),
968
- offset: offset.nullable().optional()
969
- }).strict();
970
- const ShapeCaptionPatchSchema = z.object({
971
- enabled: z.boolean().optional(),
972
- center: point.nullable().optional()
973
- }).strict();
974
- const LineLeaderSchema = z.object({
975
- length: float,
976
- extension: float.refine((n) => n >= 0).optional(),
977
- offset: float.refine((n) => n >= 0).optional()
978
- }).strict();
979
- //#endregion
980
- //#region src/annotation/kinds/line/schema.ts
981
- const LineDTOSchema = z.object({
982
- intent: LineIntentSchema.optional(),
983
- measure: PdfMeasurementSchema.optional(),
984
- caption: LineDimensionCaptionSchema.optional(),
985
- leader: LineLeaderSchema.optional(),
986
- ...AnnotationBaseShape,
987
- ...FilledStyleDTOShape,
988
- linePoints: LinePointsSchema,
989
- lineEndings: LineEndingsSchema,
990
- rotation: z.number().optional(),
991
- subtype: z.literal("line")
992
- });
993
- const LineDraftSchema = z.object({
994
- intent: LineIntentSchema.nullable().optional(),
995
- measure: PdfMeasureWriteSchema.nullable().optional(),
996
- caption: LineDimensionCaptionSchema.nullable().optional(),
997
- leader: LineLeaderSchema.nullable().optional(),
998
- ...FilledStyleDraftShape,
999
- ...AnnotationDraftBaseShape,
1000
- linePoints: LinePointsSchema,
1001
- rect: PdfRectSchema,
1002
- lineEndings: LineEndingsSchema.optional(),
1003
- rotation: z.number().nullable().optional(),
1004
- subtype: z.literal("line")
1005
- });
1006
- const LinePatchSchema = z.object({
1007
- intent: LineIntentSchema.nullable().optional(),
1008
- measure: PdfMeasureWriteSchema.nullable().optional(),
1009
- caption: LineCaptionPatchSchema.nullable().optional(),
1010
- leader: LineLeaderSchema.nullable().optional(),
1011
- ...FilledStylePatchShape,
1012
- ...AnnotationPatchBaseShape,
1013
- linePoints: LinePointsSchema.optional(),
1014
- rect: PdfRectSchema.optional(),
1015
- lineEndings: LineEndingsSchema.optional(),
1016
- rotation: z.number().nullable().optional(),
1017
- subtype: z.literal("line")
1018
- });
1019
- //#endregion
1020
- //#region src/annotation/kinds/line/index.ts
1021
- const LineKind = {
1022
- subtype: "line",
1023
- pdfSubtypeCode: PdfAnnotationSubtypeCode.LINE,
1024
- dtoSchema: LineDTOSchema,
1025
- draftSchema: LineDraftSchema,
1026
- patchSchema: LinePatchSchema
1027
- };
1028
- //#endregion
1029
- //#region src/annotation/kinds/link/schema.ts
1030
- const GotoTargetSchema = z.object({
1031
- kind: z.literal("goto"),
1032
- destination: PdfDestinationSchema
1033
- });
1034
- const UriTargetSchema = z.object({
1035
- kind: z.literal("uri"),
1036
- uri: z.string()
1037
- });
1038
- const PdfLinkTargetSchema = z.discriminatedUnion("kind", [
1039
- GotoTargetSchema,
1040
- UriTargetSchema,
1041
- z.object({
1042
- kind: z.literal("goto-remote"),
1043
- file: z.string()
1044
- }),
1045
- z.object({
1046
- kind: z.literal("launch"),
1047
- path: z.string()
1048
- }),
1049
- z.object({ kind: z.literal("javascript") }),
1050
- z.object({
1051
- kind: z.literal("named"),
1052
- name: z.string()
1053
- }),
1054
- z.object({ kind: z.literal("unsupported") })
1055
- ]);
1056
- /** Drafts/patches only author `goto`/`uri` — see {@link PdfLinkTargetWritable}. */
1057
- const PdfLinkTargetWritableSchema = z.discriminatedUnion("kind", [GotoTargetSchema, UriTargetSchema]);
1058
- const LinkDTOSchema = z.object({
1059
- ...AnnotationBaseShape,
1060
- subtype: z.literal("link"),
1061
- target: PdfLinkTargetSchema.nullable()
1062
- });
1063
- const LinkDraftSchema = z.object({
1064
- ...AnnotationDraftBaseShape,
1065
- subtype: z.literal("link"),
1066
- rect: PdfRectSchema,
1067
- target: PdfLinkTargetWritableSchema.nullable()
1068
- });
1069
- const LinkPatchSchema = z.object({
1070
- ...AnnotationPatchBaseShape,
1071
- subtype: z.literal("link"),
1072
- rect: PdfRectSchema.optional(),
1073
- target: PdfLinkTargetWritableSchema.nullable().optional()
1074
- });
1075
- //#endregion
1076
- //#region src/annotation/kinds/link/index.ts
1077
- const LinkKind = {
1078
- subtype: "link",
1079
- pdfSubtypeCode: PdfAnnotationSubtypeCode.LINK,
1080
- dtoSchema: LinkDTOSchema,
1081
- draftSchema: LinkDraftSchema,
1082
- patchSchema: LinkPatchSchema
1083
- };
1084
- //#endregion
1085
- //#region src/annotation/kinds/vertex.shared.ts
1086
- const VertexDTOShape = {
1087
- ...AnnotationBaseShape,
1088
- ...FilledStyleDTOShape,
1089
- vertices: z.array(PdfPointSchema),
1090
- rotation: z.number().optional()
1091
- };
1092
- const VertexDraftShape = {
1093
- ...FilledStyleDraftShape,
1094
- vertices: z.array(PdfPointSchema),
1095
- rect: PdfRectSchema,
1096
- rotation: z.number().nullable().optional()
1097
- };
1098
- const VertexPatchShape = {
1099
- ...FilledStylePatchShape,
1100
- vertices: z.array(PdfPointSchema).optional(),
1101
- rect: PdfRectSchema.optional(),
1102
- rotation: z.number().nullable().optional()
1103
- };
1104
- //#endregion
1105
- //#region src/annotation/kinds/polygon/schema.ts
1106
- const PolygonDTOSchema = z.object({
1107
- intent: PolygonIntentSchema.optional(),
1108
- measure: PdfMeasurementSchema.optional(),
1109
- caption: ShapeDimensionCaptionSchema.optional(),
1110
- ...VertexDTOShape,
1111
- vertices: z.array(PdfPointSchema).min(3),
1112
- cloudyIntensity: z.number().positive().nullable(),
1113
- subtype: z.literal("polygon")
1114
- });
1115
- const PolygonDraftSchema = z.object({
1116
- intent: PolygonIntentSchema.nullable().optional(),
1117
- measure: PdfMeasureWriteSchema.nullable().optional(),
1118
- caption: ShapeDimensionCaptionSchema.nullable().optional(),
1119
- ...VertexDraftShape,
1120
- ...AnnotationDraftBaseShape,
1121
- vertices: z.array(PdfPointSchema).min(3),
1122
- cloudyIntensity: z.number().positive().nullable().optional(),
1123
- subtype: z.literal("polygon")
1124
- });
1125
- const PolygonPatchSchema = z.object({
1126
- intent: PolygonIntentSchema.nullable().optional(),
1127
- measure: PdfMeasureWriteSchema.nullable().optional(),
1128
- caption: ShapeCaptionPatchSchema.nullable().optional(),
1129
- ...VertexPatchShape,
1130
- ...AnnotationPatchBaseShape,
1131
- vertices: z.array(PdfPointSchema).min(3).optional(),
1132
- cloudyIntensity: z.number().positive().nullable().optional(),
1133
- subtype: z.literal("polygon")
1134
- });
1135
- //#endregion
1136
- //#region src/annotation/kinds/polygon/index.ts
1137
- const PolygonKind = {
1138
- subtype: "polygon",
1139
- pdfSubtypeCode: PdfAnnotationSubtypeCode.POLYGON,
1140
- dtoSchema: PolygonDTOSchema,
1141
- draftSchema: PolygonDraftSchema,
1142
- patchSchema: PolygonPatchSchema
1143
- };
1144
- //#endregion
1145
- //#region src/annotation/kinds/polyline/schema.ts
1146
- const PolylineDTOSchema = z.object({
1147
- intent: PolylineIntentSchema.optional(),
1148
- measure: PdfMeasurementSchema.optional(),
1149
- caption: ShapeDimensionCaptionSchema.optional(),
1150
- ...VertexDTOShape,
1151
- vertices: z.array(PdfPointSchema).min(2),
1152
- lineEndings: LineEndingsSchema,
1153
- subtype: z.literal("polyline")
1154
- });
1155
- const PolylineDraftSchema = z.object({
1156
- intent: PolylineIntentSchema.nullable().optional(),
1157
- measure: PdfMeasureWriteSchema.nullable().optional(),
1158
- caption: ShapeDimensionCaptionSchema.nullable().optional(),
1159
- ...VertexDraftShape,
1160
- ...AnnotationDraftBaseShape,
1161
- vertices: z.array(PdfPointSchema).min(2),
1162
- lineEndings: LineEndingsSchema.optional(),
1163
- subtype: z.literal("polyline")
1164
- });
1165
- const PolylinePatchSchema = z.object({
1166
- intent: PolylineIntentSchema.nullable().optional(),
1167
- measure: PdfMeasureWriteSchema.nullable().optional(),
1168
- caption: ShapeCaptionPatchSchema.nullable().optional(),
1169
- ...VertexPatchShape,
1170
- ...AnnotationPatchBaseShape,
1171
- vertices: z.array(PdfPointSchema).min(2).optional(),
1172
- lineEndings: LineEndingsSchema.optional(),
1173
- subtype: z.literal("polyline")
1174
- });
1175
- //#endregion
1176
- //#region src/annotation/kinds/polyline/index.ts
1177
- const PolylineKind = {
1178
- subtype: "polyline",
1179
- pdfSubtypeCode: PdfAnnotationSubtypeCode.POLYLINE,
1180
- dtoSchema: PolylineDTOSchema,
1181
- draftSchema: PolylineDraftSchema,
1182
- patchSchema: PolylinePatchSchema
1183
- };
1184
- //#endregion
1185
- //#region src/annotation/kinds/redact/schema.ts
1186
- /** Authoring `fontFamily`: a standard font name OR a registered font `key`.
1187
- * Any non-empty string is accepted; the writer resolves which it is (and a
1188
- * key that was never registered fails loud there). The read-back DTO keeps
1189
- * the narrower {@link StandardFontSchema}. */
1190
- const RedactFontSchema = z.string().min(1);
1191
- /** `/DA` size — unlike free text, `0` is meaningful for a redaction label:
1192
- * auto-fit to the region. */
1193
- const RedactFontSizeSchema = z.number().nonnegative();
1194
- const RedactDTOSchema = z.object({
1195
- ...AnnotationBaseShape,
1196
- quadPoints: z.array(PdfQuadSchema),
1197
- color: ColorSchema,
1198
- opacity: z.number().min(0).max(1),
1199
- interiorColor: ColorSchema.nullable(),
1200
- overlayText: z.string().nullable(),
1201
- repeat: z.boolean(),
1202
- fontFamily: StandardFontSchema,
1203
- fontSize: RedactFontSizeSchema,
1204
- fontColor: ColorSchema,
1205
- textAlign: TextAlignmentSchema,
1206
- subtype: z.literal("redact")
1207
- });
1208
- const RedactDraftSchema = z.object({
1209
- ...AnnotationDraftBaseShape,
1210
- rect: PdfRectSchema,
1211
- quadPoints: z.array(PdfQuadSchema).optional(),
1212
- color: ColorSchema.optional(),
1213
- opacity: z.number().min(0).max(1).optional(),
1214
- interiorColor: ColorSchema.nullable().optional(),
1215
- overlayText: z.string().optional(),
1216
- repeat: z.boolean().optional(),
1217
- fontFamily: RedactFontSchema.optional(),
1218
- fontSize: RedactFontSizeSchema.optional(),
1219
- fontColor: ColorSchema.optional(),
1220
- textAlign: TextAlignmentSchema.optional(),
1221
- subtype: z.literal("redact")
1222
- });
1223
- const RedactPatchSchema = z.object({
1224
- ...AnnotationPatchBaseShape,
1225
- rect: PdfRectSchema.optional(),
1226
- quadPoints: z.array(PdfQuadSchema).optional(),
1227
- color: ColorSchema.optional(),
1228
- opacity: z.number().min(0).max(1).optional(),
1229
- interiorColor: ColorSchema.nullable().optional(),
1230
- overlayText: z.string().nullable().optional(),
1231
- repeat: z.boolean().optional(),
1232
- fontFamily: RedactFontSchema.optional(),
1233
- fontSize: RedactFontSizeSchema.optional(),
1234
- fontColor: ColorSchema.optional(),
1235
- textAlign: TextAlignmentSchema.optional(),
1236
- subtype: z.literal("redact")
1237
- });
1238
- //#endregion
1239
- //#region src/annotation/kinds/redact/index.ts
1240
- const RedactKind = {
1241
- subtype: "redact",
1242
- pdfSubtypeCode: PdfAnnotationSubtypeCode.REDACT,
1243
- dtoSchema: RedactDTOSchema,
1244
- draftSchema: RedactDraftSchema,
1245
- patchSchema: RedactPatchSchema
1246
- };
1247
- //#endregion
1248
- //#region src/annotation/kinds/square/schema.ts
1249
- const SquareDTOSchema = z.object({
1250
- ...ShapeDTOShape,
1251
- subtype: z.literal("square")
1252
- });
1253
- const SquareDraftSchema = z.object({
1254
- ...ShapeDraftShape,
1255
- ...AnnotationDraftBaseShape,
1256
- subtype: z.literal("square")
1257
- });
1258
- const SquarePatchSchema = z.object({
1259
- ...ShapePatchShape,
1260
- ...AnnotationPatchBaseShape,
1261
- subtype: z.literal("square")
1262
- });
1263
- //#endregion
1264
- //#region src/annotation/kinds/square/index.ts
1265
- const SquareKind = {
1266
- subtype: "square",
1267
- pdfSubtypeCode: PdfAnnotationSubtypeCode.SQUARE,
1268
- dtoSchema: SquareDTOSchema,
1269
- draftSchema: SquareDraftSchema,
1270
- patchSchema: SquarePatchSchema
1271
- };
1272
- //#endregion
1273
- //#region src/annotation/kinds/squiggly/schema.ts
1274
- const SquigglyDTOSchema = z.object({
1275
- ...TextMarkupDTOShape,
1276
- subtype: z.literal("squiggly")
1277
- });
1278
- const SquigglyDraftSchema = z.object({
1279
- ...TextMarkupDraftShape,
1280
- ...AnnotationDraftBaseShape,
1281
- subtype: z.literal("squiggly")
1282
- });
1283
- const SquigglyPatchSchema = z.object({
1284
- ...TextMarkupPatchShape,
1285
- ...AnnotationPatchBaseShape,
1286
- subtype: z.literal("squiggly")
1287
- });
1288
- //#endregion
1289
- //#region src/annotation/kinds/squiggly/index.ts
1290
- const SquigglyKind = {
1291
- subtype: "squiggly",
1292
- pdfSubtypeCode: PdfAnnotationSubtypeCode.SQUIGGLY,
1293
- dtoSchema: SquigglyDTOSchema,
1294
- draftSchema: SquigglyDraftSchema,
1295
- patchSchema: SquigglyPatchSchema
1296
- };
1297
- //#endregion
1298
- //#region src/annotation/kinds/stamp/schema.ts
1299
- /**
1300
- * Schemas validate the WIRE forms. The authoring types (`StampDraft`,
1301
- * `StampPatch`) carry inline `BinarySource` bytes and are normalized to
1302
- * these shapes before validation — see `annotation/normalize.ts`.
1303
- */
1304
- const ResourceRefSchema = z.object({ resource: z.string().min(1) });
1305
- const StampFitSchema = z.enum([
1306
- "contain",
1307
- "cover",
1308
- "fill"
1309
- ]);
1310
- const StampDTOSchema = z.object({
1311
- ...AnnotationBaseShape,
1312
- name: z.string().nullable(),
1313
- rotation: z.number().optional(),
1314
- unrotatedRect: PdfRectSchema.optional(),
1315
- subtype: z.literal("stamp")
1316
- });
1317
- const StampWireDraftSchema = z.object({
1318
- ...AnnotationDraftBaseShape,
1319
- rect: PdfRectSchema,
1320
- source: ResourceRefSchema,
1321
- name: z.string().min(1).optional(),
1322
- fit: StampFitSchema.optional(),
1323
- rotation: z.number().nullable().optional(),
1324
- unrotatedRect: PdfRectSchema.nullable().optional(),
1325
- subtype: z.literal("stamp")
1326
- });
1327
- const StampWirePatchSchema = z.object({
1328
- ...AnnotationPatchBaseShape,
1329
- rect: PdfRectSchema.optional(),
1330
- source: ResourceRefSchema.optional(),
1331
- name: z.string().min(1).nullable().optional(),
1332
- fit: StampFitSchema.optional(),
1333
- rotation: z.number().nullable().optional(),
1334
- unrotatedRect: PdfRectSchema.nullable().optional(),
1335
- subtype: z.literal("stamp")
1336
- });
1337
- //#endregion
1338
- //#region src/annotation/kinds/stamp/index.ts
1339
- /**
1340
- * The kind module is WIRE-typed (schemas validate the post-normalization
1341
- * form). The authoring types with inline bytes (`StampDraft`, `StampPatch`)
1342
- * are swapped into the public `AnnotationDraft`/`AnnotationPatch` unions in
1343
- * `kinds/index.ts`; `annotation/normalize.ts` bridges the two.
1344
- */
1345
- const StampKind = {
1346
- subtype: "stamp",
1347
- pdfSubtypeCode: PdfAnnotationSubtypeCode.STAMP,
1348
- dtoSchema: StampDTOSchema,
1349
- draftSchema: StampWireDraftSchema,
1350
- patchSchema: StampWirePatchSchema
1351
- };
1352
- //#endregion
1353
- //#region src/annotation/kinds/strikeout/schema.ts
1354
- const StrikeoutDTOSchema = z.object({
1355
- ...TextMarkupDTOShape,
1356
- intent: StrikeoutIntentSchema.nullable(),
1357
- subtype: z.literal("strikeout")
1358
- });
1359
- const StrikeoutDraftSchema = z.object({
1360
- ...TextMarkupDraftShape,
1361
- ...AnnotationDraftBaseShape,
1362
- intent: StrikeoutIntentSchema.optional(),
1363
- subtype: z.literal("strikeout")
1364
- });
1365
- const StrikeoutPatchSchema = z.object({
1366
- ...TextMarkupPatchShape,
1367
- ...AnnotationPatchBaseShape,
1368
- intent: StrikeoutIntentSchema.optional(),
1369
- subtype: z.literal("strikeout")
1370
- });
1371
- //#endregion
1372
- //#region src/annotation/kinds/strikeout/index.ts
1373
- const StrikeoutKind = {
1374
- subtype: "strikeout",
1375
- pdfSubtypeCode: PdfAnnotationSubtypeCode.STRIKEOUT,
1376
- dtoSchema: StrikeoutDTOSchema,
1377
- draftSchema: StrikeoutDraftSchema,
1378
- patchSchema: StrikeoutPatchSchema
1379
- };
1380
- //#endregion
1381
- //#region src/annotation/kinds/text/schema.ts
1382
- const NoteIconSchema = z.enum([
1383
- "comment",
1384
- "key",
1385
- "note",
1386
- "help",
1387
- "new-paragraph",
1388
- "paragraph",
1389
- "insert"
1390
- ]);
1391
- const TextDTOSchema = z.object({
1392
- ...AnnotationBaseShape,
1393
- ...ColorStyleDTOShape,
1394
- icon: NoteIconSchema,
1395
- state: z.string().nullable(),
1396
- stateModel: z.string().nullable(),
1397
- subtype: z.literal("text")
1398
- });
1399
- const TextDraftSchema = z.object({
1400
- ...ColorStyleDraftShape,
1401
- ...AnnotationDraftBaseShape,
1402
- rect: PdfRectSchema,
1403
- icon: NoteIconSchema.optional(),
1404
- state: z.string().min(1).optional(),
1405
- stateModel: z.string().min(1).optional(),
1406
- subtype: z.literal("text")
1407
- });
1408
- const TextPatchSchema = z.object({
1409
- ...ColorStylePatchShape,
1410
- ...AnnotationPatchBaseShape,
1411
- rect: PdfRectSchema.optional(),
1412
- icon: NoteIconSchema.optional(),
1413
- state: z.string().min(1).nullable().optional(),
1414
- stateModel: z.string().min(1).nullable().optional(),
1415
- subtype: z.literal("text")
1416
- });
1417
- //#endregion
1418
- //#region src/annotation/kinds/text/index.ts
1419
- const TextKind = {
1420
- subtype: "text",
1421
- pdfSubtypeCode: PdfAnnotationSubtypeCode.TEXT,
1422
- dtoSchema: TextDTOSchema,
1423
- draftSchema: TextDraftSchema,
1424
- patchSchema: TextPatchSchema
1425
- };
1426
- //#endregion
1427
- //#region src/annotation/kinds/underline/schema.ts
1428
- const UnderlineDTOSchema = z.object({
1429
- ...TextMarkupDTOShape,
1430
- subtype: z.literal("underline")
1431
- });
1432
- const UnderlineDraftSchema = z.object({
1433
- ...TextMarkupDraftShape,
1434
- ...AnnotationDraftBaseShape,
1435
- subtype: z.literal("underline")
1436
- });
1437
- const UnderlinePatchSchema = z.object({
1438
- ...TextMarkupPatchShape,
1439
- ...AnnotationPatchBaseShape,
1440
- subtype: z.literal("underline")
1441
- });
1442
- //#endregion
1443
- //#region src/annotation/kinds/underline/index.ts
1444
- const UnderlineKind = {
1445
- subtype: "underline",
1446
- pdfSubtypeCode: PdfAnnotationSubtypeCode.UNDERLINE,
1447
- dtoSchema: UnderlineDTOSchema,
1448
- draftSchema: UnderlineDraftSchema,
1449
- patchSchema: UnderlinePatchSchema
1450
- };
1451
- //#endregion
1452
- //#region src/annotation/kinds/unsupported/schema.ts
1453
- const UnsupportedDTOSchema = z.object({
1454
- ...AnnotationBaseShape,
1455
- subtype: z.literal("unsupported"),
1456
- rawSubtypeCode: z.number().int(),
1457
- rawSubtypeName: z.string().nullable()
1458
- });
1459
- const UnsupportedDraftSchema = z.never();
1460
- const UnsupportedPatchSchema = z.never();
1461
- //#endregion
1462
- //#region src/annotation/kinds/unsupported/index.ts
1463
- const UnsupportedKind = {
1464
- subtype: "unsupported",
1465
- pdfSubtypeCode: PdfAnnotationSubtypeCode.UNKNOWN,
1466
- dtoSchema: UnsupportedDTOSchema,
1467
- draftSchema: UnsupportedDraftSchema,
1468
- patchSchema: UnsupportedPatchSchema
1469
- };
1470
- //#endregion
1471
- //#region src/annotation/kinds/widget.shared.ts
1472
- const WidgetStyleDTOShape = {
1473
- color: ColorSchema.nullable(),
1474
- interiorColor: ColorSchema.nullable(),
1475
- strokeWidth: z.number().nonnegative(),
1476
- borderStyle: AnnotationBorderStyleSchema,
1477
- fontFamily: StandardFontSchema.optional(),
1478
- fontSize: z.number().nonnegative().optional(),
1479
- fontColor: ColorSchema.optional(),
1480
- textAlign: TextAlignmentSchema
1481
- };
1482
- const WidgetStyleDraftShape = {
1483
- color: ColorSchema.nullable().optional(),
1484
- interiorColor: ColorSchema.nullable().optional(),
1485
- strokeWidth: z.number().nonnegative().optional(),
1486
- borderStyle: AnnotationBorderStyleSchema.optional(),
1487
- fontFamily: StandardFontSchema.optional(),
1488
- fontSize: z.number().nonnegative().optional(),
1489
- fontColor: ColorSchema.optional(),
1490
- textAlign: TextAlignmentSchema.optional()
1491
- };
1492
- const WidgetStylePatchShape = WidgetStyleDraftShape;
1493
- const WidgetAppearanceSchema = z.object(WidgetStyleDraftShape);
1494
- //#endregion
1495
- //#region src/annotation/kinds/widget/schema.ts
1496
- const WidgetDTOSchema = z.object({
1497
- ...AnnotationBaseShape,
1498
- ...WidgetStyleDTOShape,
1499
- subtype: z.literal("widget"),
1500
- fieldObjectNumber: z.number().int().nonnegative(),
1501
- fieldFamily: z.enum([
1502
- "text",
1503
- "checkbox",
1504
- "radio",
1505
- "combobox",
1506
- "listbox",
1507
- "pushbutton",
1508
- "signature",
1509
- "unknown"
1510
- ])
1511
- });
1512
- const WidgetDraftSchema = z.object({
1513
- ...AnnotationDraftBaseShape,
1514
- ...WidgetStyleDraftShape,
1515
- subtype: z.literal("widget"),
1516
- rect: PdfRectSchema
1517
- });
1518
- const WidgetPatchSchema = z.object({
1519
- ...AnnotationPatchBaseShape,
1520
- ...WidgetStylePatchShape,
1521
- subtype: z.literal("widget"),
1522
- rect: PdfRectSchema.optional()
1523
- });
1524
- //#endregion
1525
- //#region src/annotation/kinds/widget/index.ts
1526
- const WidgetKind = {
1527
- subtype: "widget",
1528
- pdfSubtypeCode: PdfAnnotationSubtypeCode.WIDGET,
1529
- dtoSchema: WidgetDTOSchema,
1530
- draftSchema: WidgetDraftSchema,
1531
- patchSchema: WidgetPatchSchema
1532
- };
1533
- //#endregion
1534
- //#region src/annotation/kinds/index.ts
1535
- /**
1536
- * The closed-world catalog of currently-implemented annotation kinds.
1537
- *
1538
- * Adding a new subtype is one folder under `kinds/<name>/` exporting the
1539
- * five files (dto, draft, patch, schema, index) and one entry in this
1540
- * tuple. The discriminated unions and zod discriminator below regenerate
1541
- * automatically; no other file in the package needs to change.
1542
- *
1543
- * Every subtype the engine has not yet wired up rides on
1544
- * `UnsupportedKind`. The wire format is stable: when a per-subtype reader
1545
- * lands later, the engine starts emitting the dedicated DTO instead of
1546
- * `unsupported`, and existing clients widen their handling without a
1547
- * version bump.
1548
- */
1549
- const ANNOTATION_KINDS = [
1550
- HighlightKind,
1551
- UnderlineKind,
1552
- SquigglyKind,
1553
- StrikeoutKind,
1554
- CircleKind,
1555
- SquareKind,
1556
- PolygonKind,
1557
- PolylineKind,
1558
- LineKind,
1559
- LinkKind,
1560
- InkKind,
1561
- FreeTextKind,
1562
- CaretKind,
1563
- TextKind,
1564
- StampKind,
1565
- FileAttachmentKind,
1566
- WidgetKind,
1567
- RedactKind,
1568
- UnsupportedKind
1569
- ];
1570
- /**
1571
- * Lookup helper for the engine's reader catalog and identity resolver.
1572
- * O(1) by `subtype` literal at runtime.
1573
- */
1574
- const KIND_BY_SUBTYPE = Object.freeze(Object.fromEntries(ANNOTATION_KINDS.map((kind) => [kind.subtype, kind])));
1575
- /**
1576
- * Runtime zod schema for the discriminated union. The cast unwinds the
1577
- * generic schema map into the specific tuple form `discriminatedUnion`
1578
- * needs. Servers and cloud clients use this to validate every annotation
1579
- * payload on the wire.
1580
- */
1581
- const AnnotationDTOSchema = z.discriminatedUnion("subtype", [
1582
- HighlightKind.dtoSchema,
1583
- UnderlineKind.dtoSchema,
1584
- SquigglyKind.dtoSchema,
1585
- StrikeoutKind.dtoSchema,
1586
- CircleKind.dtoSchema,
1587
- SquareKind.dtoSchema,
1588
- PolygonKind.dtoSchema,
1589
- PolylineKind.dtoSchema,
1590
- LineKind.dtoSchema,
1591
- LinkKind.dtoSchema,
1592
- InkKind.dtoSchema,
1593
- FreeTextKind.dtoSchema,
1594
- CaretKind.dtoSchema,
1595
- TextKind.dtoSchema,
1596
- StampKind.dtoSchema,
1597
- FileAttachmentKind.dtoSchema,
1598
- WidgetKind.dtoSchema,
1599
- RedactKind.dtoSchema,
1600
- UnsupportedKind.dtoSchema
1601
- ]);
1602
- /**
1603
- * Validates the WIRE draft form (post-normalization) — binary-carrying
1604
- * kinds appear here with `{ resource }` refs, never inline bytes.
1605
- */
1606
- const AnnotationDraftSchema = z.discriminatedUnion("subtype", [
1607
- HighlightKind.draftSchema,
1608
- UnderlineKind.draftSchema,
1609
- SquigglyKind.draftSchema,
1610
- StrikeoutKind.draftSchema,
1611
- CircleKind.draftSchema,
1612
- SquareKind.draftSchema,
1613
- PolygonKind.draftSchema,
1614
- PolylineKind.draftSchema,
1615
- LineKind.draftSchema,
1616
- LinkKind.draftSchema,
1617
- InkKind.draftSchema,
1618
- FreeTextKind.draftSchema,
1619
- CaretKind.draftSchema,
1620
- TextKind.draftSchema,
1621
- StampKind.draftSchema,
1622
- FileAttachmentKind.draftSchema,
1623
- WidgetKind.draftSchema,
1624
- RedactKind.draftSchema
1625
- ]);
1626
- /** Validates the WIRE patch form (post-normalization). */
1627
- const AnnotationPatchSchema = z.discriminatedUnion("subtype", [
1628
- HighlightKind.patchSchema,
1629
- UnderlineKind.patchSchema,
1630
- SquigglyKind.patchSchema,
1631
- StrikeoutKind.patchSchema,
1632
- CircleKind.patchSchema,
1633
- SquareKind.patchSchema,
1634
- PolygonKind.patchSchema,
1635
- PolylineKind.patchSchema,
1636
- LineKind.patchSchema,
1637
- LinkKind.patchSchema,
1638
- InkKind.patchSchema,
1639
- FreeTextKind.patchSchema,
1640
- CaretKind.patchSchema,
1641
- TextKind.patchSchema,
1642
- StampKind.patchSchema,
1643
- FileAttachmentKind.patchSchema,
1644
- WidgetKind.patchSchema,
1645
- RedactKind.patchSchema
1646
- ]);
1647
- //#endregion
1648
- //#region src/forms/schema.ts
1649
- const FormFieldRefSchema = z.discriminatedUnion("kind", [z.object({
1650
- kind: z.literal("objectNumber"),
1651
- fieldObjectNumber: z.number().int().positive()
1652
- }), z.object({
1653
- kind: z.literal("fqn"),
1654
- name: z.string().min(1)
1655
- })]);
1656
- const FormWidgetRefShape = {
1657
- annotObjectNumber: z.number().int().nonnegative(),
1658
- pageObjectNumber: z.number().int().nonnegative()
1659
- };
1660
- const FormWidgetRefSchema = z.object(FormWidgetRefShape);
1661
- const FormFieldFlagsSchema = z.object({
1662
- readOnly: z.boolean(),
1663
- required: z.boolean(),
1664
- noExport: z.boolean(),
1665
- raw: z.number().int().nonnegative()
1666
- });
1667
- const ToggleFieldWidgetSchema = z.object({
1668
- ...FormWidgetRefShape,
1669
- onState: z.string(),
1670
- exportValue: z.string(),
1671
- checked: z.boolean()
1672
- });
1673
- const FormFieldOptionSchema = z.object({
1674
- label: z.string(),
1675
- value: z.string(),
1676
- selected: z.boolean()
1677
- });
1678
- const FormValueEntrySchema = z.discriminatedUnion("kind", [
1679
- z.object({ kind: z.literal("none") }),
1680
- z.object({
1681
- kind: z.literal("scalar"),
1682
- value: z.string()
1683
- }),
1684
- z.object({
1685
- kind: z.literal("array"),
1686
- values: z.array(z.string())
1687
- }),
1688
- z.object({ kind: z.literal("unsupported") })
1689
- ]);
1690
- const FormFieldBaseShape = {
1691
- ref: FormFieldRefSchema,
1692
- fieldObjectNumber: z.number().int().nonnegative(),
1693
- name: z.string(),
1694
- origin: z.enum(["acroform", "recovered"]),
1695
- flags: FormFieldFlagsSchema,
1696
- alternateName: z.string().nullable(),
1697
- mappingName: z.string().nullable(),
1698
- valueEntry: FormValueEntrySchema,
1699
- defaultValueEntry: FormValueEntrySchema,
1700
- actions: PdfFieldActionsSchema.optional(),
1701
- widgets: z.array(FormWidgetRefSchema)
1702
- };
1703
- const FormFieldDTOSchema = z.discriminatedUnion("family", [
1704
- z.object({
1705
- ...FormFieldBaseShape,
1706
- family: z.literal("text"),
1707
- value: z.string(),
1708
- defaultValue: z.string(),
1709
- maxLength: z.number().int().positive().nullable(),
1710
- multiline: z.boolean(),
1711
- password: z.boolean(),
1712
- comb: z.boolean()
1713
- }),
1714
- z.object({
1715
- ...FormFieldBaseShape,
1716
- family: z.literal("checkbox"),
1717
- checked: z.boolean(),
1718
- exportValue: z.string(),
1719
- widgets: z.array(ToggleFieldWidgetSchema)
1720
- }),
1721
- z.object({
1722
- ...FormFieldBaseShape,
1723
- family: z.literal("radio"),
1724
- value: z.string(),
1725
- radiosInUnison: z.boolean(),
1726
- noToggleToOff: z.boolean(),
1727
- widgets: z.array(ToggleFieldWidgetSchema)
1728
- }),
1729
- z.object({
1730
- ...FormFieldBaseShape,
1731
- family: z.literal("combobox"),
1732
- value: z.string(),
1733
- defaultValue: z.string(),
1734
- edit: z.boolean(),
1735
- options: z.array(FormFieldOptionSchema)
1736
- }),
1737
- z.object({
1738
- ...FormFieldBaseShape,
1739
- family: z.literal("listbox"),
1740
- selectedValues: z.array(z.string()),
1741
- multiSelect: z.boolean(),
1742
- options: z.array(FormFieldOptionSchema)
1743
- }),
1744
- z.object({
1745
- ...FormFieldBaseShape,
1746
- family: z.literal("pushbutton")
1747
- }),
1748
- z.object({
1749
- ...FormFieldBaseShape,
1750
- family: z.literal("signature")
1751
- }),
1752
- z.object({
1753
- ...FormFieldBaseShape,
1754
- family: z.literal("unknown"),
1755
- rawValue: z.string()
1756
- })
1757
- ]);
1758
- const FormKindSchema = z.enum([
1759
- "none",
1760
- "acroform",
1761
- "xfa"
1762
- ]);
1763
- const FormSnapshotSchema = z.object({
1764
- formKind: FormKindSchema,
1765
- needsAppearances: z.boolean(),
1766
- fields: z.array(FormFieldDTOSchema),
1767
- calculationOrder: z.array(FormFieldRefSchema.nullable())
1768
- });
1769
- const FormFieldValueSchema = z.discriminatedUnion("type", [
1770
- z.object({
1771
- type: z.literal("text"),
1772
- value: z.string()
1773
- }),
1774
- z.object({
1775
- type: z.literal("toggle"),
1776
- state: z.string().nullable()
1777
- }),
1778
- z.object({
1779
- type: z.literal("choice"),
1780
- values: z.array(z.string())
1781
- })
1782
- ]);
1783
- const FormDataFormatSchema = z.enum(["fdf", "xfdf"]);
1784
- const WidgetPlacementSchema = z.object({
1785
- pageObjectNumber: z.number().int().positive(),
1786
- rect: PdfRectSchema,
1787
- onState: z.string().min(1).optional(),
1788
- appearance: WidgetAppearanceSchema.optional()
1789
- });
1790
- const FormFieldOptionInputSchema = z.object({
1791
- label: z.string(),
1792
- value: z.string()
1793
- });
1794
- const FormFieldDraftBaseShape = {
1795
- name: z.string().min(1),
1796
- readOnly: z.boolean().optional(),
1797
- required: z.boolean().optional(),
1798
- noExport: z.boolean().optional(),
1799
- alternateName: z.string().optional(),
1800
- mappingName: z.string().optional()
1801
- };
1802
- const FormFieldDraftSchema = z.discriminatedUnion("family", [
1803
- z.object({
1804
- ...FormFieldDraftBaseShape,
1805
- family: z.literal("text"),
1806
- defaultValue: z.string().optional(),
1807
- maxLength: z.number().int().positive().optional(),
1808
- multiline: z.boolean().optional(),
1809
- password: z.boolean().optional(),
1810
- comb: z.boolean().optional(),
1811
- widget: WidgetPlacementSchema.optional()
1812
- }),
1813
- z.object({
1814
- ...FormFieldDraftBaseShape,
1815
- family: z.literal("checkbox"),
1816
- widget: WidgetPlacementSchema.optional()
1817
- }),
1818
- z.object({
1819
- ...FormFieldDraftBaseShape,
1820
- family: z.literal("radio"),
1821
- radiosInUnison: z.boolean().optional(),
1822
- noToggleToOff: z.boolean().optional(),
1823
- widgets: z.array(WidgetPlacementSchema).optional()
1824
- }),
1825
- z.object({
1826
- ...FormFieldDraftBaseShape,
1827
- family: z.literal("combobox"),
1828
- edit: z.boolean().optional(),
1829
- options: z.array(FormFieldOptionInputSchema).optional(),
1830
- defaultValue: z.string().optional(),
1831
- widget: WidgetPlacementSchema.optional()
1832
- }),
1833
- z.object({
1834
- ...FormFieldDraftBaseShape,
1835
- family: z.literal("listbox"),
1836
- multiSelect: z.boolean().optional(),
1837
- options: z.array(FormFieldOptionInputSchema).optional(),
1838
- widget: WidgetPlacementSchema.optional()
1839
- }),
1840
- z.object({
1841
- ...FormFieldDraftBaseShape,
1842
- family: z.literal("signature"),
1843
- widget: WidgetPlacementSchema.optional()
1844
- })
1845
- ]);
1846
- const FormFieldPatchBaseShape = {
1847
- name: z.string().min(1).optional(),
1848
- readOnly: z.boolean().optional(),
1849
- required: z.boolean().optional(),
1850
- noExport: z.boolean().optional(),
1851
- alternateName: z.string().nullable().optional(),
1852
- mappingName: z.string().nullable().optional()
1853
- };
1854
- const FormFieldPatchSchema = z.discriminatedUnion("family", [
1855
- z.object({
1856
- ...FormFieldPatchBaseShape,
1857
- family: z.literal("text"),
1858
- defaultValue: z.string().nullable().optional(),
1859
- maxLength: z.number().int().positive().nullable().optional(),
1860
- multiline: z.boolean().optional(),
1861
- password: z.boolean().optional(),
1862
- comb: z.boolean().optional()
1863
- }),
1864
- z.object({
1865
- ...FormFieldPatchBaseShape,
1866
- family: z.literal("checkbox")
1867
- }),
1868
- z.object({
1869
- ...FormFieldPatchBaseShape,
1870
- family: z.literal("radio"),
1871
- radiosInUnison: z.boolean().optional(),
1872
- noToggleToOff: z.boolean().optional()
1873
- }),
1874
- z.object({
1875
- ...FormFieldPatchBaseShape,
1876
- family: z.literal("combobox"),
1877
- edit: z.boolean().optional(),
1878
- defaultValue: z.string().nullable().optional(),
1879
- options: z.array(FormFieldOptionInputSchema).optional()
1880
- }),
1881
- z.object({
1882
- ...FormFieldPatchBaseShape,
1883
- family: z.literal("listbox"),
1884
- multiSelect: z.boolean().optional(),
1885
- options: z.array(FormFieldOptionInputSchema).optional()
1886
- })
1887
- ]);
1888
- //#endregion
1889
- //#region src/wire/schemas.ts
1890
- const DocumentMetadataSchema = z.object({
1891
- title: z.string().nullable(),
1892
- author: z.string().nullable(),
1893
- subject: z.string().nullable(),
1894
- keywords: z.string().nullable(),
1895
- producer: z.string().nullable(),
1896
- creator: z.string().nullable(),
1897
- created: z.string().datetime().nullable(),
1898
- modified: z.string().datetime().nullable(),
1899
- trapped: z.enum([
1900
- "true",
1901
- "false",
1902
- "unknown"
1903
- ]),
1904
- custom: z.record(z.string(), z.string())
1905
- });
1906
- /**
1907
- * Three-state metadata patch. Mirrors annotation patch semantics:
1908
- * `undefined` leaves a field, `null` clears it, a value sets it. `custom`
1909
- * is a per-key three-state map (string set / null clear / absent leave).
1910
- */
1911
- const MetadataPatchSchema = z.object({
1912
- title: z.string().nullable().optional(),
1913
- author: z.string().nullable().optional(),
1914
- subject: z.string().nullable().optional(),
1915
- keywords: z.string().nullable().optional(),
1916
- producer: z.string().nullable().optional(),
1917
- creator: z.string().nullable().optional(),
1918
- created: z.string().datetime().nullable().optional(),
1919
- modified: z.string().datetime().nullable().optional(),
1920
- trapped: z.enum([
1921
- "true",
1922
- "false",
1923
- "unknown"
1924
- ]).optional(),
1925
- custom: z.record(z.string(), z.string().nullable()).optional()
1926
- }).strict();
1927
- const OpenDocumentResponseSchema = z.object({ id: z.string() });
1928
- /**
1929
- * Wire shape of `GET /v1/docs/:docId/head`. Mirrors the server-side
1930
- * `DocumentHead` interface; the schema is the source of truth so
1931
- * older SDKs talking to newer servers degrade gracefully (extra
1932
- * fields are accepted and ignored).
1933
- *
1934
- * `docVersion` is the single monotonic integer per doc; it bumps on
1935
- * ANY mutation that could change the manifest's content (page list,
1936
- * per-page content, per-page annotations, per-page weak-flag), which
1937
- * makes `/manifest@docVersion=N` fully content-addressed and cache-friendly.
1938
- * Phase 4 hard-codes it to `1`; Phase 5's mutation handler is what
1939
- * actually bumps it.
1940
- */
1941
- const DocumentHeadSchema = z.object({
1942
- id: z.string(),
1943
- baseSha: z.string(),
1944
- storageSizeBytes: z.number().int().nonnegative(),
1945
- docVersion: z.number().int().positive(),
1946
- state: z.enum([
1947
- "pending",
1948
- "ready",
1949
- "failed",
1950
- "deleting"
1951
- ]),
1952
- encryption: z.object({
1953
- state: z.enum([
1954
- "unknown",
1955
- "none",
1956
- "encrypted",
1957
- "unsupported"
1958
- ]),
1959
- requiresPassword: z.boolean().nullable()
1960
- }),
1961
- permissions: z.object({
1962
- known: z.boolean(),
1963
- bits: z.number().int().nonnegative().nullable(),
1964
- allAllowed: z.boolean().nullable(),
1965
- openedAs: z.enum([
1966
- "none",
1967
- "user",
1968
- "owner"
1969
- ]).nullable(),
1970
- securityHandlerRevision: z.number().int().nullable(),
1971
- canUpgradeToOwner: z.boolean()
1972
- }),
1973
- access: z.object({
1974
- required: z.boolean(),
1975
- reasons: z.array(z.enum([
1976
- "password",
1977
- "cdn",
1978
- "permissions-unknown"
1979
- ])),
1980
- endpoint: z.string().optional()
1981
- })
1982
- });
1983
- const AccessRequestSchema = z.object({
1984
- /** Deprecated: identity now rides the PATH
1985
- * (`/v1/docs/:docId/layers/:layerName/access`). Kept optional for the
1986
- * legacy `/v1/access` alias, which requires `docId` in the body. */
1987
- docId: z.string().min(1).optional(),
1988
- layerName: z.string().min(1).optional(),
1989
- password: z.string().optional(),
1990
- passwordGrant: z.string().optional(),
1991
- mode: z.enum(["any", "owner"]).optional()
1992
- });
1993
- /**
1994
- * Typed boolean view of the PDF user-access permission word. Names
1995
- * mirror the `PdfBits` shape in @embedpdf/engine-core/auth/scope; ISO
1996
- * bit numbers (3, 4, 5, 6, 9, 10, 11, 12).
1997
- */
1998
- const PdfBitsObjectSchema = z.object({
1999
- bit3: z.boolean(),
2000
- bit4: z.boolean(),
2001
- bit5: z.boolean(),
2002
- bit6: z.boolean(),
2003
- bit9: z.boolean(),
2004
- bit10: z.boolean(),
2005
- bit11: z.boolean(),
2006
- bit12: z.boolean()
2007
- });
2008
- /**
2009
- * Capability-shaped advisory for the client UI. Mirrors
2010
- * `PdfPermissionAdvisory` in @embedpdf/engine-core/runtime; one
2011
- * boolean per UI badge.
2012
- */
2013
- const PdfPermissionAdvisoryObjectSchema = z.object({
2014
- canPrint: z.boolean(),
2015
- canPrintHigh: z.boolean(),
2016
- canCopy: z.boolean(),
2017
- canAnnotate: z.boolean(),
2018
- canFillForms: z.boolean(),
2019
- canModifyForms: z.boolean(),
2020
- canModifyPages: z.boolean(),
2021
- canAssemble: z.boolean()
2022
- });
2023
- const PdfPermissionInfoSchema = z.object({
2024
- known: z.boolean(),
2025
- allAllowed: z.boolean().nullable(),
2026
- bits: z.number().int().nonnegative().nullable(),
2027
- openedAs: z.enum([
2028
- "none",
2029
- "user",
2030
- "owner"
2031
- ]).nullable(),
2032
- securityHandlerRevision: z.number().int().nullable(),
2033
- flags: PdfBitsObjectSchema.optional(),
2034
- advisory: PdfPermissionAdvisoryObjectSchema.optional()
2035
- }).nullable();
2036
- const DocumentSecurityStateSchema = z.object({
2037
- encryption: z.object({
2038
- state: z.enum([
2039
- "unknown",
2040
- "none",
2041
- "encrypted",
2042
- "unsupported"
2043
- ]),
2044
- requiresPassword: z.boolean().nullable()
2045
- }),
2046
- permissions: z.object({
2047
- known: z.boolean(),
2048
- bits: z.number().int().nonnegative().nullable(),
2049
- allAllowed: z.boolean().nullable(),
2050
- openedAs: z.enum([
2051
- "none",
2052
- "user",
2053
- "owner"
2054
- ]).nullable(),
2055
- securityHandlerRevision: z.number().int().nullable(),
2056
- canUpgradeToOwner: z.boolean()
2057
- }),
2058
- access: z.object({
2059
- required: z.boolean(),
2060
- reasons: z.array(z.enum([
2061
- "password",
2062
- "cdn",
2063
- "permissions-unknown"
2064
- ])),
2065
- endpoint: z.string().optional()
2066
- })
2067
- });
2068
- const AccessResponseSchema = z.object({
2069
- security: DocumentSecurityStateSchema,
2070
- cdn: z.object({
2071
- adapter: z.enum([
2072
- "none",
2073
- "cloudfront",
2074
- "cloud-cdn",
2075
- "bunny",
2076
- "azure-fd",
2077
- "custom-hmac"
2078
- ]),
2079
- expiresAt: z.number().int().positive(),
2080
- cache: z.object({
2081
- scope: z.enum(["browser-private", "edge-shared"]),
2082
- immutableVersionedReads: z.boolean()
2083
- }),
2084
- baseUrlOverrides: z.record(z.string(), z.string()).nullable(),
2085
- authHeader: z.object({
2086
- name: z.string(),
2087
- value: z.string()
2088
- }).nullable(),
2089
- signedQueryParams: z.record(z.string(), z.string()).nullable(),
2090
- signedCookies: z.array(z.object({
2091
- name: z.string(),
2092
- value: z.string(),
2093
- domain: z.string().optional(),
2094
- path: z.string().optional(),
2095
- expires: z.number().int().optional()
2096
- })).nullable(),
2097
- signedPathPolicies: z.array(z.object({
2098
- pathPrefix: z.string(),
2099
- queryParams: z.record(z.string(), z.string())
2100
- })).nullable()
2101
- }),
2102
- passwordGrant: z.string().nullable(),
2103
- pdfPermissions: PdfPermissionInfoSchema,
2104
- scope: z.array(z.string()),
2105
- /**
2106
- * Concrete capability set granted to this caller after expanding
2107
- * `pdf.permissions` and applying resolver implication rules. Client
2108
- * UI should drive feature visibility off this, not off raw `scope`.
2109
- * Always present in /access responses (server populates from
2110
- * `expandRawScope`). Sorted alphabetically for stable change
2111
- * detection.
2112
- */
2113
- effectiveScope: z.array(z.string()),
2114
- identity: z.object({
2115
- user_id: z.string().optional(),
2116
- group_id: z.string().optional(),
2117
- groups: z.array(z.string()).optional(),
2118
- display_name: z.string().optional()
2119
- }),
2120
- originPasswordPolicy: z.object({ mode: z.enum([
2121
- "not-needed",
2122
- "client-retry",
2123
- "server-session"
2124
- ]) }),
2125
- expiresAt: z.number().int().positive(),
2126
- /**
2127
- * The deployment's render lattice — the canonical parameter points the
2128
- * server treats as durable, CDN-shared artifacts. Lives HERE and never in
2129
- * the manifest: manifests are version-pinned immutable objects; the
2130
- * lattice is mutable deployment policy. The SDK exposes it (and a pure
2131
- * `snap` helper) but NEVER conforms requests implicitly — the same render
2132
- * call must not return different pixels on local vs cloud. When
2133
- * `enforced` is true the server rejects off-lattice render tokens with
2134
- * 400; when false, off-lattice renders are computed but not persisted.
2135
- * Absent on older servers → treat as unenforced/unknown.
2136
- */
2137
- renderPolicy: z.object({
2138
- /**
2139
- * Full-page renders quantize on `viewport.width` — the bounded
2140
- * quantity is OUTPUT PIXELS, never zoom (PDF page space is
2141
- * effectively unbounded, so a scale lattice bounds artifact count
2142
- * but not size).
2143
- */
2144
- fullPage: z.object({ widths: z.array(z.number().int().positive()) }),
2145
- /**
2146
- * RESERVED for deep-zoom tile support: scale-based pyramid ×
2147
- * fixed tile size, constant per-job cost. Absent until the tiling
2148
- * plugin ships.
2149
- */
2150
- tiles: z.object({
2151
- tileSizes: z.array(z.number().int().positive()),
2152
- scales: z.array(z.number().positive())
2153
- }).optional(),
2154
- /**
2155
- * Annotation-appearance lattice — SCALE-based (appearances are sized
2156
- * by `rect × scale` and must track the page's effective render scale
2157
- * for crisp composites).
2158
- */
2159
- appearances: z.object({ scales: z.array(z.number().positive()) }).optional(),
2160
- /** Worker-side output budget for degenerate page geometry. */
2161
- maxRenderPixels: z.number().int().positive().optional(),
2162
- formats: z.array(z.enum(["webp", "png"])),
2163
- background: z.enum(["white"]),
2164
- enforced: z.boolean()
2165
- }).optional()
2166
- });
2167
- const PdfSaveModeSchema = z.enum(["incremental", "rewrite"]);
2168
- const engineErrorCodeValues = Object.values(EngineErrorCode);
2169
- const EngineErrorPayloadSchema = z.object({
2170
- name: z.literal("EngineError"),
2171
- code: z.enum(engineErrorCodeValues),
2172
- message: z.string(),
2173
- details: z.record(z.string(), z.unknown()).optional()
2174
- });
2175
- const WeakAnnotationStateSchema = z.discriminatedUnion("kind", [z.object({ kind: z.literal("unknown") }), z.object({
2176
- kind: z.literal("known"),
2177
- hasAnyWeakAnnotations: z.boolean()
2178
- })]);
2179
- const PageStateSchema = z.object({
2180
- pageObjectNumber: z.number().int().positive(),
2181
- revision: RevisionTokenSchema,
2182
- weakAnnotationState: WeakAnnotationStateSchema
2183
- });
2184
- const CachePinsSchema = z.object({
2185
- contentVersion: z.number().int().positive(),
2186
- annotationVersion: z.number().int().positive()
2187
- });
2188
- /**
2189
- * Plane scopes are DERIVED from the version counters at every emission
2190
- * point (layer manifests, mutation cache envelopes, SSE rows), never stored.
2191
- * Additive/optional both ways: old clients ignore it, old servers omit it
2192
- * (consumers treat absence as all-'layer' — never wrong, only unshared).
2193
- */
2194
- const LayerScopeValueSchema = z.enum(["base", "layer"]);
2195
- const LayerScopesSchema = z.object({
2196
- content: LayerScopeValueSchema,
2197
- annotations: LayerScopeValueSchema,
2198
- layout: LayerScopeValueSchema,
2199
- attachments: LayerScopeValueSchema,
2200
- metadata: LayerScopeValueSchema,
2201
- actions: LayerScopeValueSchema
2202
- });
2203
- /**
2204
- * Per-page envelope inside `DocumentManifest`. Carries the full
2205
- * `PageState` plus the cache-busting integers the SDK embeds in
2206
- * leaf URLs (`/pages/:pon/text@contentVersion=N`, `/pages/:pon/annotations@annotationVersion=N`).
2207
- *
2208
- * `contentVersion` bumps when the page's content stream changes
2209
- * (text, page reorder doesn't, the pon is durable). `annotationVersion`
2210
- * bumps when /Annots gains/loses entries or when a tracked annotation
2211
- * mutates. `hasWeakAnnotations` is hoisted from `PageState` so the
2212
- * SDK can decide whether to display a "stale-on-reorder" badge
2213
- * without re-fetching the page.
2214
- *
2215
- * Phase 4 hard-codes all three to (1, 1, false); Phase 5's
2216
- * `layer_pages` table drives the real values.
2217
- */
2218
- const ManifestPageSchema = z.object({
2219
- state: PageStateSchema,
2220
- cache: CachePinsSchema
2221
- }).superRefine((page, ctx) => {
2222
- if (page.state.weakAnnotationState.kind !== "known") ctx.addIssue({
2223
- code: z.ZodIssueCode.custom,
2224
- path: ["state", "weakAnnotationState"],
2225
- message: "manifest pages must have a known weak annotation state"
2226
- });
2227
- });
2228
- /**
2229
- * Wire shape of `GET /v1/docs/:docId/manifest@docVersion=N`. Content-addressed
2230
- * by `docVersion`; safe to cache with `Cache-Control: public,
2231
- * max-age=31536000, immutable`.
2232
- */
2233
- const DocumentManifestSchema = z.object({
2234
- docVersion: z.number().int().positive(),
2235
- layoutVersion: z.number().int().positive(),
2236
- metadataVersion: z.number().int().positive(),
2237
- actionsVersion: z.number().int().positive().default(1),
2238
- attachmentsVersion: z.number().int().positive().default(1),
2239
- annotationsVersion: z.number().int().positive().default(1),
2240
- auditHead: z.number().int().nonnegative(),
2241
- baseSha: z.string(),
2242
- layerVersion: z.number().int().nonnegative().default(0),
2243
- working: z.boolean().default(false),
2244
- baseByteLength: z.number().int().nonnegative().default(0),
2245
- scopes: LayerScopesSchema.optional(),
2246
- pages: z.array(ManifestPageSchema)
2247
- });
2248
- const AnnotationListPageSnapshotSchema = z.object({
2249
- pageState: PageStateSchema,
2250
- annotations: z.array(AnnotationDTOSchema)
2251
- });
2252
- const AnnotationListSnapshotAllPagesSchema = z.object({
2253
- pages: z.array(AnnotationListPageSnapshotSchema),
2254
- auditHead: z.number().int().nonnegative().optional()
2255
- });
2256
- /**
2257
- * Wire shape of `GET …/text/pages/:pon/data@<contentVersion>` and the
2258
- * `pages.text` worker result: the UTF-16-faithful extraction, the CHARACTER
2259
- * space size (`charCount` — the space geometry runs tile; NOT `text.length`),
2260
- * and the optional character→text anchor map. Malformed maps are rejected
2261
- * here with the shared `charMapViolation` invariants — absent/empty map
2262
- * REQUIRES `charCount === text.length` (identity).
2263
- */
2264
- const PageTextSnapshotSchema = z.object({
2265
- text: z.string(),
2266
- charCount: z.number().int().nonnegative(),
2267
- charMap: z.array(z.tuple([z.number().int().nonnegative(), z.number().int().nonnegative()])).optional()
2268
- }).superRefine((snapshot, ctx) => {
2269
- const violation = charMapViolation(snapshot.charCount, snapshot.text.length, snapshot.charMap);
2270
- if (violation !== null) ctx.addIssue({
2271
- code: z.ZodIssueCode.custom,
2272
- path: ["charMap"],
2273
- message: violation
2274
- });
2275
- });
2276
- const PageGeometryGlyphSchema = z.object({
2277
- looseBox: PdfRectSchema,
2278
- flags: z.number().int().nonnegative(),
2279
- tightBox: PdfRectSchema.optional()
2280
- });
2281
- const RotatedGeometryGlyphSchema = z.object({
2282
- looseQuad: PdfQuadSchema,
2283
- flags: z.number().int().nonnegative(),
2284
- tightQuad: PdfQuadSchema.optional()
2285
- });
2286
- const UprightGeometryRunSchema = z.object({
2287
- rect: PdfRectSchema,
2288
- charStart: z.number().int().nonnegative(),
2289
- glyphs: z.array(PageGeometryGlyphSchema),
2290
- fontSize: z.number().optional()
2291
- });
2292
- const RotatedGeometryRunSchema = z.object({
2293
- rect: PdfRectSchema,
2294
- charStart: z.number().int().nonnegative(),
2295
- glyphs: z.array(RotatedGeometryGlyphSchema),
2296
- rotation: z.number(),
2297
- ascentFlip: z.boolean(),
2298
- fontSize: z.number().optional()
2299
- });
2300
- const PageGeometryRunSchema = z.union([RotatedGeometryRunSchema, UprightGeometryRunSchema]);
2301
- const PageGeometrySnapshotSchema = z.object({ runs: z.array(PageGeometryRunSchema) });
2302
- /**
2303
- * Search wire shapes: the request body of the layer search route and the
2304
- * `search.query` worker/route result. The server re-validates the query
2305
- * semantics (`validateSearchQuery`: regex dialect + flag combos) after
2306
- * parse — the schema only checks structure.
2307
- */
2308
- const SearchQuerySchema = z.object({
2309
- text: z.string(),
2310
- regex: z.boolean().optional(),
2311
- matchCase: z.boolean().optional(),
2312
- wholeWord: z.boolean().optional(),
2313
- matchDiacritics: z.boolean().optional(),
2314
- ignoreWhitespace: z.boolean().optional()
2315
- });
2316
- const SearchModeSchema = z.enum(["rects", "full"]);
2317
- const SearchRequestSchema = z.object({
2318
- query: SearchQuerySchema,
2319
- mode: SearchModeSchema.optional(),
2320
- cursor: z.string().optional(),
2321
- startPage: z.number().int().positive().optional(),
2322
- skip: z.number().int().nonnegative().optional(),
2323
- budget: z.object({
2324
- maxMatches: z.number().int().positive().optional(),
2325
- maxPages: z.number().int().positive().optional()
2326
- }).optional()
2327
- });
2328
- const SearchSnippetSchema = z.object({
2329
- text: z.string(),
2330
- matchStart: z.number().int().nonnegative(),
2331
- matchLength: z.number().int().positive()
2332
- });
2333
- const PdfTextSegmentSchema = z.object({
2334
- quad: PdfQuadSchema,
2335
- rect: PdfRectSchema,
2336
- advance: z.union([z.literal(1), z.literal(-1)])
2337
- });
2338
- const SearchMatchSchema = z.object({
2339
- pageObjectNumber: z.number().int().positive(),
2340
- charStart: z.number().int().nonnegative(),
2341
- charCount: z.number().int().positive(),
2342
- segments: z.array(PdfTextSegmentSchema),
2343
- snippet: SearchSnippetSchema.optional()
2344
- });
2345
- const SearchSliceSchema = z.object({
2346
- matches: z.array(SearchMatchSchema),
2347
- nextCursor: z.string().nullable(),
2348
- scannedPages: z.number().int().nonnegative(),
2349
- totalPages: z.number().int().nonnegative()
2350
- });
2351
- const PageNetworkRenderFormatSchema = z.enum(["png", "webp"]);
2352
- /**
2353
- * Wire schema for the cloud render endpoints, applied to the **nested**
2354
- * shape produced by `unflatten(...)` of the parsed token or query string.
2355
- *
2356
- * Adding a new render option is one change here (a new field plus any
2357
- * cross-field rule in `superRefine`) plus one entry in
2358
- * `RenderTokenSchema.fields`. The token codec, flatten/unflatten helpers,
2359
- * route handlers, and SDK URL builder are all generic and pick the new
2360
- * field up automatically.
2361
- *
2362
- * Coercion: token fields and query strings both arrive as strings, so every
2363
- * scalar uses `z.coerce.*`. Discriminated unions on `viewport.kind` and
2364
- * `target.kind` enforce viewport / rect coherence by construction — no
2365
- * superRefine for "fields must appear together" rules.
2366
- */
2367
- const RenderViewportSchema = z.discriminatedUnion("kind", [z.object({
2368
- kind: z.literal("width"),
2369
- width: z.coerce.number().positive().finite()
2370
- }).strict(), z.object({
2371
- kind: z.literal("scale"),
2372
- scale: z.coerce.number().positive().finite().optional()
2373
- }).strict()]);
2374
- const RenderTargetSchema = z.discriminatedUnion("kind", [z.object({ kind: z.literal("page") }).strict(), z.object({
2375
- kind: z.literal("rect"),
2376
- rect: z.object({
2377
- left: z.coerce.number().finite(),
2378
- bottom: z.coerce.number().finite(),
2379
- right: z.coerce.number().finite(),
2380
- top: z.coerce.number().finite()
2381
- }).strict()
2382
- }).strict()]);
2383
- const RenderRotationSchema = z.preprocess((raw) => raw === void 0 ? void 0 : Number(raw), z.number().refine((n) => n === 0 || n === 90 || n === 180 || n === 270, { message: "render rotation must be 0, 90, 180, or 270" }));
2384
- const RenderBackgroundSchema = z.enum(["white", "transparent"]);
2385
- const RenderQualitySchema = z.coerce.number().int().min(1).max(100);
2386
- /**
2387
- * Token/path rule: annotatedness is PATH-expressed —
2388
- * the render FAMILY the route belongs to — never token/query-expressed.
2389
- * Each family therefore gets its own query schema, built from one shared
2390
- * base:
2391
- *
2392
- * - the annotation-free family (`…/render/pages/`) has NO
2393
- * `annotationVersion` field at all — `.strict()` rejects it as an
2394
- * unrecognized key, so the illegal combination is unrepresentable;
2395
- * - the annotated family (`…/render/annotated/pages/`) REQUIRES
2396
- * `annotationVersion` on versioned requests — its artifact depends on
2397
- * the `annotations` plane, so the pin must be in the cache key.
2398
- *
2399
- * Both transforms stamp `includeAnnotations` onto the parsed SDK options
2400
- * from the family, so downstream consumers (worker options, classify) are
2401
- * family-blind.
2402
- */
2403
- function buildPageRenderQuerySchema(annotated) {
2404
- return z.object({
2405
- contentVersion: z.coerce.number().int().positive().optional(),
2406
- ...annotated ? { annotationVersion: z.coerce.number().int().positive().optional() } : {},
2407
- format: PageNetworkRenderFormatSchema.optional(),
2408
- viewport: RenderViewportSchema.optional(),
2409
- target: RenderTargetSchema.optional(),
2410
- rotation: RenderRotationSchema.optional(),
2411
- background: RenderBackgroundSchema.optional(),
2412
- quality: RenderQualitySchema.optional()
2413
- }).strict().superRefine((v, ctx) => {
2414
- const pins = v;
2415
- if (pins.contentVersion !== void 0 && v.format === void 0) ctx.addIssue({
2416
- code: z.ZodIssueCode.custom,
2417
- path: ["format"],
2418
- message: "versioned render requires format"
2419
- });
2420
- if (annotated && pins.annotationVersion !== void 0 && pins.contentVersion === void 0) ctx.addIssue({
2421
- code: z.ZodIssueCode.custom,
2422
- path: ["annotationVersion"],
2423
- message: "annotationVersion requires contentVersion"
2424
- });
2425
- if (annotated && pins.contentVersion !== void 0 && pins.annotationVersion === void 0) ctx.addIssue({
2426
- code: z.ZodIssueCode.custom,
2427
- path: ["annotationVersion"],
2428
- message: "versioned annotated render requires annotationVersion"
2429
- });
2430
- }).transform((v) => {
2431
- const pins = v;
2432
- return {
2433
- options: {
2434
- ...v.target ? { target: v.target } : {},
2435
- ...v.viewport ? { viewport: v.viewport } : {},
2436
- ...v.rotation !== void 0 ? { rotation: v.rotation } : {},
2437
- ...v.background !== void 0 ? { background: v.background } : {},
2438
- ...v.quality !== void 0 ? { quality: v.quality } : {},
2439
- ...v.format !== void 0 ? { format: v.format } : {},
2440
- includeAnnotations: annotated
2441
- },
2442
- ...pins.contentVersion !== void 0 ? { contentVersion: pins.contentVersion } : {},
2443
- ...pins.annotationVersion !== void 0 ? { annotationVersion: pins.annotationVersion } : {}
2444
- };
2445
- });
2446
- }
2447
- /** Query/token schema for the annotation-free render family (`page-render`). */
2448
- const PageRenderQuerySchema = buildPageRenderQuerySchema(false);
2449
- /** Query/token schema for the annotated render family (`page-render-annotated`). */
2450
- const PageRenderAnnotatedQuerySchema = buildPageRenderQuerySchema(true);
2451
- /**
2452
- * Query/token schema for the batch annotation-appearance render endpoint.
2453
- * Mirrors `PageRenderQuerySchema` but without page target/viewport/background
2454
- * or `includeAnnotations` (appearances are always annotation-derived), and
2455
- * keyed by `annotationVersion` only — appearance bitmaps do not depend on
2456
- * page base content, so `contentVersion` is not part of the cache key. The
2457
- * endpoint renders the Normal appearance only.
2458
- */
2459
- const AnnotationAppearancesQuerySchema = z.object({
2460
- annotationVersion: z.coerce.number().int().positive().optional(),
2461
- format: PageNetworkRenderFormatSchema.optional(),
2462
- rotation: RenderRotationSchema.optional(),
2463
- scale: z.coerce.number().positive().finite().optional(),
2464
- quality: RenderQualitySchema.optional()
2465
- }).strict().superRefine((v, ctx) => {
2466
- if (v.annotationVersion !== void 0 && v.format === void 0) ctx.addIssue({
2467
- code: z.ZodIssueCode.custom,
2468
- path: ["format"],
2469
- message: "versioned appearance render requires format"
2470
- });
2471
- }).transform((v) => {
2472
- return {
2473
- options: {
2474
- ...v.rotation !== void 0 ? { rotation: v.rotation } : {},
2475
- ...v.scale !== void 0 ? { scale: v.scale } : {},
2476
- ...v.quality !== void 0 ? { quality: v.quality } : {},
2477
- ...v.format !== void 0 ? { format: v.format } : {}
2478
- },
2479
- ...v.annotationVersion !== void 0 ? { annotationVersion: v.annotationVersion } : {}
2480
- };
2481
- });
2482
- /**
2483
- * The JSON manifest part of the appearance `multipart/form-data` response.
2484
- * Wire-stable; the cloud client validates the parsed `manifest` part against
2485
- * this before reconstructing image handles from the binary parts.
2486
- */
2487
- const AnnotationAppearanceManifestSchema = z.object({
2488
- pageState: PageStateSchema,
2489
- appearances: z.array(z.object({
2490
- part: z.string().min(1),
2491
- ref: AnnotationRefSchema,
2492
- mode: z.enum([
2493
- "normal",
2494
- "rollover",
2495
- "down"
2496
- ]),
2497
- rect: PdfRectSchema,
2498
- width: z.number().int().positive(),
2499
- height: z.number().int().positive(),
2500
- format: PageNetworkRenderFormatSchema,
2501
- contentType: z.string().min(1)
2502
- }))
2503
- });
2504
- /**
2505
- * Reasons a mutation tells the client its old snapshot is stale. Wire-stable;
2506
- * extend with care (forward-compat clients accept only known values).
2507
- */
2508
- const RefetchReasonSchema = z.enum([
2509
- "weakRefsInvalidated",
2510
- "externalChange",
2511
- "pageRebuilt"
2512
- ]);
2513
- const CacheDeltaSchema = z.object({
2514
- previousDocVersion: z.number().int().positive(),
2515
- docVersion: z.number().int().positive(),
2516
- annotationsVersion: z.number().int().positive().optional(),
2517
- layerVersion: z.number().int().nonnegative().optional(),
2518
- working: z.boolean().optional(),
2519
- pages: z.array(z.object({
2520
- pageObjectNumber: z.number().int().positive(),
2521
- cache: CachePinsSchema
2522
- }))
2523
- });
2524
- const MutationMetaSchema = z.object({
2525
- affectedPages: z.array(PageStateSchema),
2526
- cacheDelta: CacheDeltaSchema.nullable()
2527
- });
2528
- /**
2529
- * Per-page side-effect envelope every annotation mutation returns. Mirrors
2530
- * `AnnotationListMutationMeta`. The `shouldRefetch` field is `null` when the
2531
- * client's existing index-based references remain valid; non-null only when
2532
- * the engine knows for sure the snapshot is stale.
2533
- */
2534
- const AnnotationListMutationMetaSchema = z.object({
2535
- affectedPages: z.array(PageStateSchema),
2536
- cacheDelta: CacheDeltaSchema.nullable(),
2537
- changed: z.array(AnnotationStableIdSchema),
2538
- weakRefsInvalidated: z.boolean(),
2539
- shouldRefetch: z.object({ reason: RefetchReasonSchema }).nullable()
2540
- });
2541
- const AnnotationCreateResultSchema = z.object({
2542
- created: AnnotationDTOSchema,
2543
- meta: AnnotationListMutationMetaSchema
2544
- });
2545
- /** The engine's `/AP` verdict riding every update result (see engine-core
2546
- * `annotation/appearance.ts`). `changed` drives client raster invalidation. */
2547
- const AppearanceOutcomeSchema = z.object({
2548
- action: z.enum([
2549
- "preserved",
2550
- "regenerated",
2551
- "generation-unavailable"
2552
- ]),
2553
- changed: z.boolean()
2554
- });
2555
- const AnnotationUpdateResultSchema = z.object({
2556
- updated: AnnotationDTOSchema,
2557
- appearance: AppearanceOutcomeSchema,
2558
- meta: AnnotationListMutationMetaSchema
2559
- });
2560
- /**
2561
- * `deleted` is nullable: a weak annotation (no /NM, no indirect object
2562
- * number) has no durable id to report after removal. Cloud server and local
2563
- * worker both emit `null` in that case so callers don't have to special-case
2564
- * a sentinel.
2565
- */
2566
- const AnnotationDeleteResultSchema = z.object({
2567
- deleted: AnnotationStableIdSchema.nullable(),
2568
- meta: AnnotationListMutationMetaSchema
2569
- });
2570
- /**
2571
- * Batch annotation move (contiguous-block, symmetric with `pages.move`).
2572
- * `moved` is in caller order; each `moved[i]` lives at index `toIndex + i`
2573
- * after the move. ONE structural envelope per batch.
2574
- */
2575
- const AnnotationMoveResultSchema = z.object({
2576
- moved: z.array(AnnotationDTOSchema),
2577
- meta: AnnotationListMutationMetaSchema
2578
- });
2579
- const FormSetValueResultSchema = z.object({
2580
- field: FormFieldDTOSchema,
2581
- changedWidgets: z.array(FormWidgetRefSchema),
2582
- meta: MutationMetaSchema
2583
- });
2584
- const FormEffectSchema = z.discriminatedUnion("kind", [
2585
- z.object({
2586
- kind: z.literal("setValue"),
2587
- ref: FormFieldRefSchema,
2588
- value: FormFieldValueSchema
2589
- }),
2590
- z.object({
2591
- kind: z.literal("setDisplay"),
2592
- ref: FormFieldRefSchema,
2593
- display: z.enum([
2594
- "visible",
2595
- "hidden",
2596
- "noPrint",
2597
- "noView"
2598
- ])
2599
- }),
2600
- z.object({
2601
- kind: z.literal("setAppearanceText"),
2602
- ref: FormFieldRefSchema,
2603
- text: z.string()
2604
- }),
2605
- z.object({
2606
- kind: z.literal("reset"),
2607
- refs: z.array(FormFieldRefSchema)
2608
- })
2609
- ]);
2610
- const FormEffectsResultSchema = z.object({
2611
- results: z.array(z.object({
2612
- index: z.number().int().nonnegative(),
2613
- status: z.enum([
2614
- "applied",
2615
- "unchanged",
2616
- "rejected",
2617
- "failed",
2618
- "skipped"
2619
- ]),
2620
- fields: z.array(FormFieldDTOSchema),
2621
- changedWidgets: z.array(FormWidgetRefSchema),
2622
- error: EngineErrorPayloadSchema.optional()
2623
- })),
2624
- changedWidgets: z.array(FormWidgetRefSchema),
2625
- meta: MutationMetaSchema.nullable()
2626
- });
2627
- const FormImportResultSchema = z.object({
2628
- fieldsTotal: z.number().int().nonnegative(),
2629
- fieldsApplied: z.number().int().nonnegative(),
2630
- fieldsSkipped: z.number().int().nonnegative(),
2631
- widgetsChanged: z.number().int().nonnegative(),
2632
- snapshot: FormSnapshotSchema,
2633
- meta: MutationMetaSchema
2634
- });
2635
- const FormFieldCreateResultSchema = z.object({
2636
- field: FormFieldDTOSchema,
2637
- meta: MutationMetaSchema
2638
- });
2639
- const FormFieldUpdateResultSchema = z.object({
2640
- field: FormFieldDTOSchema,
2641
- meta: MutationMetaSchema
2642
- });
2643
- const FormFieldDeleteResultSchema = z.object({
2644
- deletedFieldObjectNumber: z.number().int().positive(),
2645
- removedWidgets: z.array(FormWidgetRefSchema),
2646
- meta: MutationMetaSchema
2647
- });
2648
- const FormWidgetLinkResultSchema = z.object({
2649
- field: FormFieldDTOSchema,
2650
- meta: MutationMetaSchema
2651
- });
2652
- const FormRepairResultSchema = z.object({
2653
- acroformCreated: z.boolean(),
2654
- fieldsLinked: z.number().int().nonnegative(),
2655
- widgetsLinked: z.number().int().nonnegative(),
2656
- fieldsUnrepairable: z.number().int().nonnegative(),
2657
- appearancesBaked: z.number().int().nonnegative(),
2658
- needAppearancesCleared: z.boolean(),
2659
- meta: MutationMetaSchema
2660
- });
2661
- const PageBoxesSchema = z.object({
2662
- media: PdfRectSchema,
2663
- crop: PdfRectSchema,
2664
- bleed: PdfRectSchema.optional(),
2665
- trim: PdfRectSchema.optional(),
2666
- art: PdfRectSchema.optional()
2667
- });
2668
- /**
2669
- * Pure geometry for one page (`pages.list()` element). No annotation
2670
- * liveness — that lives on annotation reads and the manifest.
2671
- */
2672
- const PageLayoutSchema = z.object({
2673
- index: z.number().int().nonnegative(),
2674
- pageObjectNumber: z.number().int().positive(),
2675
- label: z.string().nullable(),
2676
- size: PdfSizeSchema,
2677
- rotation: PdfRotationSchema,
2678
- userUnit: z.number().positive(),
2679
- boxes: PageBoxesSchema,
2680
- actions: PdfPageActionsSchema.optional()
2681
- });
2682
- const PageFlattenResultSchema = z.object({
2683
- pageObjectNumbers: z.array(z.number().int().positive()),
2684
- usage: z.enum(["display", "print"]),
2685
- results: z.array(z.object({
2686
- pageObjectNumber: z.number().int().positive(),
2687
- status: z.enum([
2688
- "applied",
2689
- "unchanged",
2690
- "failed",
2691
- "skipped"
2692
- ]),
2693
- error: EngineErrorPayloadSchema.optional()
2694
- })),
2695
- meta: MutationMetaSchema.nullable()
2696
- });
2697
- /** See `AnnotationFlattenResult`. */
2698
- const AnnotationFlattenResultSchema = z.object({
2699
- pageObjectNumber: z.number().int().positive(),
2700
- usage: z.enum(["display", "print"]),
2701
- results: z.array(z.object({
2702
- ref: AnnotationRefSchema,
2703
- status: z.enum(["applied", "skipped"])
2704
- })),
2705
- meta: MutationMetaSchema.nullable()
2706
- });
2707
- /** `annotations.flatten` input — see `AnnotationFlattenInput`. */
2708
- const AnnotationFlattenInputSchema = z.object({
2709
- refs: z.array(AnnotationRefSchema).min(1),
2710
- usage: z.enum(["display", "print"])
2711
- });
2712
- /** `annotations.exportAppearance` input — see `AnnotationAppearanceExportInput`. */
2713
- const AnnotationAppearanceExportInputSchema = z.object({ refs: z.array(AnnotationRefSchema).min(1) });
2714
- const PageFlattenInputSchema = z.object({
2715
- pageObjectNumbers: z.array(z.number().int().positive()),
2716
- usage: z.enum(["display", "print"])
2717
- });
2718
- const RedactionApplyScopeSchema = z.discriminatedUnion("kind", [z.object({
2719
- kind: z.literal("pages"),
2720
- pageObjectNumbers: z.array(z.number().int().positive())
2721
- }), z.object({
2722
- kind: z.literal("annotations"),
2723
- refs: z.array(AnnotationRefSchema)
2724
- })]);
2725
- const RedactionApplyResultSchema = z.object({
2726
- scope: RedactionApplyScopeSchema,
2727
- results: z.array(z.object({
2728
- pageObjectNumber: z.number().int().positive(),
2729
- status: z.enum([
2730
- "applied",
2731
- "unchanged",
2732
- "failed",
2733
- "skipped"
2734
- ]),
2735
- removedAnnotationCount: z.number().int().nonnegative(),
2736
- error: EngineErrorPayloadSchema.optional()
2737
- })),
2738
- removedAnnotationCount: z.number().int().nonnegative(),
2739
- meta: MutationMetaSchema.nullable()
2740
- });
2741
- /**
2742
- * Snapshot of every page in display order. Pages are addressed by
2743
- * `pageObjectNumber` everywhere except the per-element `index`, which is
2744
- * display order and intentionally not an identity. Carries geometry only.
2745
- */
2746
- /** See `NamedPageEntry`: decoded key + what it resolves to. */
2747
- const NamedPageEntrySchema = z.object({
2748
- name: z.string(),
2749
- target: z.discriminatedUnion("kind", [
2750
- z.object({
2751
- kind: z.literal("page"),
2752
- pageObjectNumber: z.number().int().positive()
2753
- }),
2754
- z.object({
2755
- kind: z.literal("template"),
2756
- objectNumber: z.number().int().positive()
2757
- }),
2758
- z.object({ kind: z.literal("dangling") })
2759
- ])
2760
- });
2761
- const PageListSnapshotSchema = z.object({
2762
- pageCount: z.number().int().nonnegative(),
2763
- pages: z.array(PageLayoutSchema),
2764
- namedPages: z.array(NamedPageEntrySchema).optional()
2765
- });
2766
- /** `pages.setName` input — see `PageNameInput`. */
2767
- const PageNameInputSchema = z.object({
2768
- name: z.string().min(1),
2769
- pageObjectNumber: z.number().int().positive(),
2770
- replace: z.string().min(1).optional()
2771
- });
2772
- /** `pages.removeName` input — see `PageRemoveNameInput`. */
2773
- const PageRemoveNameInputSchema = z.object({ name: z.string().min(1) });
2774
- /**
2775
- * Page reorder input. Pages are always addressed by `pageObjectNumber`;
2776
- * `destIndex` is the insertion point in the post-removal index space.
2777
- */
2778
- const PageMoveInputSchema = z.object({
2779
- pageObjectNumbers: z.array(z.number().int().positive()),
2780
- destIndex: z.number().int().nonnegative()
2781
- });
2782
- /**
2783
- * Coherence pins shared by every page-STRUCTURE result (move/rotate/delete) —
2784
- * see `PageStructureCache`. Nullable at each use site (local engines).
2785
- */
2786
- const PageStructureCacheSchema = z.object({
2787
- previousDocVersion: z.number().int().nonnegative(),
2788
- docVersion: z.number().int().positive(),
2789
- layoutVersion: z.number().int().positive()
2790
- });
2791
- /**
2792
- * Page reorder result. No revision is bumped (no doc-level revision exists,
2793
- * and per-page revisions intentionally survive a page reorder). The full
2794
- * post-move order is returned so callers can swap their snapshot directly.
2795
- */
2796
- const PageMoveResultSchema = z.object({
2797
- layout: PageListSnapshotSchema,
2798
- cache: PageStructureCacheSchema.nullable()
2799
- });
2800
- /** Named-page mutation result — layout-shaped, see `PageNameResult`. */
2801
- const PageNameResultSchema = z.object({
2802
- layout: PageListSnapshotSchema,
2803
- cache: PageStructureCacheSchema.nullable()
2804
- });
2805
- /**
2806
- * Page rotate input. ABSOLUTE rotation (idempotent — see `PageRotateInput`),
2807
- * one value applied to every listed page.
2808
- */
2809
- const PageRotateInputSchema = z.object({
2810
- pageObjectNumbers: z.array(z.number().int().positive()),
2811
- rotation: PdfRotationSchema
2812
- });
2813
- /**
2814
- * Page rotate result. Rotation is presentation metadata over normalized
2815
- * content: nothing per-page invalidates; the new `layout` carries the
2816
- * rotation values (see `PageRotateResult`).
2817
- */
2818
- const PageRotateResultSchema = z.object({
2819
- layout: PageListSnapshotSchema,
2820
- cache: PageStructureCacheSchema.nullable()
2821
- });
2822
- /** Page delete input. Deleting every page is rejected server/worker-side. */
2823
- const PageDeleteInputSchema = z.object({ pageObjectNumbers: z.array(z.number().int().positive()) });
2824
- /**
2825
- * Page delete result. Deleted PONs are retired (never recycled); surviving
2826
- * pages keep identity + revisions (see `PageDeleteResult`).
2827
- */
2828
- const PageDeleteResultSchema = z.object({
2829
- layout: PageListSnapshotSchema,
2830
- cache: PageStructureCacheSchema.nullable()
2831
- });
2832
- /**
2833
- * Page insert (bytes) input — the JSON `body` part of the multipart
2834
- * mutation envelope; the PDF itself rides the `resource:source` part.
2835
- * `destIndex` omitted → append.
2836
- */
2837
- const PageInsertInputSchema = z.object({ destIndex: z.number().int().nonnegative().optional() });
2838
- /**
2839
- * Blank-page insert input — plain JSON, pages.insert minus the bytes.
2840
- * `size` is in PDF points (un-rotated); `count` shares the contract cap
2841
- * with the worker so a request the schema accepts cannot then fail the
2842
- * worker's own guard.
2843
- */
2844
- const PageInsertBlankInputSchema = z.object({
2845
- size: z.object({
2846
- width: z.number().positive().finite(),
2847
- height: z.number().positive().finite()
2848
- }),
2849
- count: z.number().int().min(1).max(100).optional(),
2850
- destIndex: z.number().int().nonnegative().optional()
2851
- });
2852
- /** Page extract input: the pages to export, in the order they should appear. */
2853
- const PageExtractInputSchema = z.object({ pageObjectNumbers: z.array(z.number().int().positive()).min(1) });
2854
- /**
2855
- * Page insert result — shared by bytes-insert and blank-insert: the fresh
2856
- * PONs in insertion order plus the full new layout (see `PageInsertResult`).
2857
- */
2858
- const PageInsertResultSchema = z.object({
2859
- insertedPageObjectNumbers: z.array(z.number().int().positive()),
2860
- layout: PageListSnapshotSchema,
2861
- cache: PageStructureCacheSchema.nullable()
2862
- });
2863
- /**
2864
- * Metadata write result. The Info dict is rewritten in place, so the
2865
- * result returns the re-read `metadata` plus cloud coherence pins. No
2866
- * `layoutVersion` is touched — a metadata edit bumps only `docVersion`
2867
- * and `metadataVersion`. `cache` is `null` for local engines.
2868
- */
2869
- const AttachmentsCacheSchema = z.object({
2870
- previousDocVersion: z.number().int().nonnegative(),
2871
- docVersion: z.number().int().positive(),
2872
- attachmentsVersion: z.number().int().positive()
2873
- });
2874
- const AttachmentCreateResultSchema = z.object({
2875
- created: EmbeddedFileItemSchema,
2876
- cache: AttachmentsCacheSchema.nullable()
2877
- });
2878
- const AttachmentDeleteResultSchema = z.object({
2879
- deleted: EmbeddedFileRefSchema,
2880
- cache: AttachmentsCacheSchema.nullable()
2881
- });
2882
- const MetadataUpdateResultSchema = z.object({
2883
- metadata: DocumentMetadataSchema,
2884
- cache: z.object({
2885
- previousDocVersion: z.number().int().nonnegative(),
2886
- docVersion: z.number().int().positive(),
2887
- metadataVersion: z.number().int().positive()
2888
- }).nullable()
2889
- });
2890
- const WeakAnnotationSessionResponseSchema = z.object({
2891
- sessionId: z.string().min(1),
2892
- expiresAt: z.number().int().positive(),
2893
- heartbeatIntervalMs: z.number().int().positive(),
2894
- pageObjectNumbers: z.array(z.number().int().positive())
2895
- });
2896
- const WeakAnnotationSessionPagesRequestSchema = z.object({ pageObjectNumbers: z.array(z.number().int().positive()).transform((pages) => [...new Set(pages)]) });
2897
- const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2898
- /** Standard base64 (padded). Dependency-free: no Buffer, runs in browsers too. */
2899
- function toBase64(bytes) {
2900
- let out = "";
2901
- for (let i = 0; i < bytes.length; i += 3) {
2902
- const b0 = bytes[i];
2903
- const b1 = bytes[i + 1];
2904
- const b2 = bytes[i + 2];
2905
- out += BASE64_ALPHABET[b0 >> 2];
2906
- out += BASE64_ALPHABET[(b0 & 3) << 4 | (b1 ?? 0) >> 4];
2907
- out += b1 === void 0 ? "=" : BASE64_ALPHABET[(b1 & 15) << 2 | (b2 ?? 0) >> 6];
2908
- out += b2 === void 0 ? "=" : BASE64_ALPHABET[b2 & 63];
2909
- }
2910
- return out;
2911
- }
2912
- function fromBase64(encoded) {
2913
- let end = encoded.length;
2914
- while (end > 0 && encoded[end - 1] === "=") end -= 1;
2915
- const clean = encoded.slice(0, end);
2916
- if (clean.length % 4 === 1 || /[^A-Za-z0-9+/]/.test(clean)) throw new Error("malformed base64");
2917
- const bytes = [];
2918
- let buffer = 0;
2919
- let bits = 0;
2920
- for (const ch of clean) {
2921
- buffer = buffer << 6 | BASE64_ALPHABET.indexOf(ch);
2922
- bits += 6;
2923
- if (bits >= 8) {
2924
- bits -= 8;
2925
- bytes.push(buffer >> bits & 255);
2926
- }
2927
- }
2928
- return Uint8Array.from(bytes);
2929
- }
2930
- const Base64Schema = z.string().regex(/^[A-Za-z0-9+/]*={0,2}$/, "base64");
2931
- const DocumentVersionRefSchema = z.object({
2932
- baseSha256: z.string().regex(/^[0-9a-f]{64}$/),
2933
- editsVersion: z.number().int().nonnegative()
2934
- });
2935
- const ByteRangeSchema = z.tuple([
2936
- z.number().int().nonnegative(),
2937
- z.number().int().nonnegative(),
2938
- z.number().int().nonnegative(),
2939
- z.number().int().nonnegative()
2940
- ]);
2941
- /** `SignaturePrepared` with the digest as base64. */
2942
- const SignaturePreparedWireSchema = z.object({
2943
- signingId: z.string().min(1),
2944
- digest: Base64Schema,
2945
- algorithm: z.enum([
2946
- "sha256",
2947
- "sha384",
2948
- "sha512"
2949
- ]),
2950
- byteRange: ByteRangeSchema,
2951
- contentsSize: z.number().int().positive(),
2952
- subFilter: z.string(),
2953
- expectedVersion: DocumentVersionRefSchema,
2954
- expiresAt: z.string().nullable()
2955
- });
2956
- function encodePrepared(prepared) {
2957
- return {
2958
- ...prepared,
2959
- digest: toBase64(prepared.digest)
2960
- };
2961
- }
2962
- function decodePrepared(wire) {
2963
- return {
2964
- ...wire,
2965
- digest: fromBase64(wire.digest),
2966
- subFilter: wire.subFilter
2967
- };
2968
- }
2969
- /** The JSON body of a completion: the CMS as base64 beside the fence. */
2970
- const SignatureCompleteBodySchema = z.object({
2971
- cms: Base64Schema.refine((v) => v.length > 0, "cms is required"),
2972
- expectedVersion: DocumentVersionRefSchema
2973
- });
2974
- const DocMdpPermissionSchema = z.union([
2975
- z.literal(1),
2976
- z.literal(2),
2977
- z.literal(3)
2978
- ]);
2979
- const ModificationLevelSchema = z.enum([
2980
- "none",
2981
- "lta",
2982
- "fill",
2983
- "annotate"
2984
- ]);
2985
- const DigestAlgorithmSchema = z.enum([
2986
- "sha1",
2987
- "sha256",
2988
- "sha384",
2989
- "sha512"
2990
- ]);
2991
- const FieldLockSpecSchema = z.object({
2992
- action: z.enum([
2993
- "all",
2994
- "include",
2995
- "exclude"
2996
- ]),
2997
- fields: z.array(z.string()),
2998
- permission: DocMdpPermissionSchema.optional()
2999
- });
3000
- const SignatureSeedValueSchema = z.object({
3001
- requiredFlags: z.number().int(),
3002
- presentFlags: z.number().int(),
3003
- version: z.number().int().nullable(),
3004
- mdp: z.union([
3005
- z.literal(0),
3006
- z.literal(1),
3007
- z.literal(2),
3008
- z.literal(3)
3009
- ]).nullable(),
3010
- filter: z.string().nullable(),
3011
- subFilters: z.array(z.string()),
3012
- digestMethods: z.array(z.string()),
3013
- reasons: z.array(z.string()),
3014
- unsupportedRequired: z.boolean()
3015
- });
3016
- const SignatureDTOSchema = z.object({
3017
- index: z.number().int().nonnegative(),
3018
- field: FormFieldRefSchema,
3019
- fieldName: z.string(),
3020
- widget: FormWidgetRefSchema.nullable(),
3021
- signed: z.boolean(),
3022
- kind: z.enum(["signature", "timestamp"]),
3023
- filter: z.string().nullable(),
3024
- subFilter: z.string().nullable(),
3025
- byteRange: ByteRangeSchema.nullable(),
3026
- contentsSize: z.number().int().nonnegative(),
3027
- coverage: z.enum([
3028
- "whole-revision",
3029
- "partial",
3030
- "malformed"
3031
- ]).nullable(),
3032
- revisionIndex: z.number().int().nonnegative().nullable(),
3033
- signer: z.object({
3034
- name: z.string().nullable(),
3035
- reason: z.string().nullable(),
3036
- location: z.string().nullable(),
3037
- contactInfo: z.string().nullable(),
3038
- claimedTime: z.string().nullable()
3039
- }),
3040
- docMdp: DocMdpPermissionSchema.nullable(),
3041
- catalogCertification: z.boolean(),
3042
- fieldMdp: FieldLockSpecSchema.nullable(),
3043
- lock: FieldLockSpecSchema.nullable(),
3044
- seedValue: SignatureSeedValueSchema.nullable()
3045
- });
3046
- const DocumentProtectionSchema = z.object({
3047
- enforced: ModificationLevelSchema.nullable(),
3048
- judged: ModificationLevelSchema.nullable(),
3049
- certification: z.object({
3050
- signatureIndex: z.number().int().nonnegative(),
3051
- permission: DocMdpPermissionSchema
3052
- }).nullable(),
3053
- fieldLocks: z.array(z.object({
3054
- signatureIndex: z.number().int().nonnegative(),
3055
- source: z.enum(["fieldmdp", "lock"]),
3056
- spec: FieldLockSpecSchema
3057
- })),
3058
- policyVersion: z.number().int()
3059
- });
3060
- const PdfRevisionSchema = z.object({
3061
- index: z.number().int().nonnegative(),
3062
- end: z.number().int().nonnegative(),
3063
- xrefOffset: z.number().int().nonnegative(),
3064
- signatureIndex: z.number().int().nonnegative().nullable()
3065
- });
3066
- const SignatureSnapshotSchema = z.object({
3067
- chainValid: z.boolean(),
3068
- revisions: z.array(PdfRevisionSchema),
3069
- signatures: z.array(SignatureDTOSchema),
3070
- protection: DocumentProtectionSchema
3071
- });
3072
- const BaseVersionInfoSchema = z.object({
3073
- sha256: z.string().regex(/^[0-9a-f]{64}$/),
3074
- byteLength: z.number().int().nonnegative()
3075
- });
3076
- const SignatureCompleteResultSchema = z.object({
3077
- status: z.enum(["completed", "already-completed"]),
3078
- signature: SignatureDTOSchema,
3079
- version: BaseVersionInfoSchema,
3080
- previous: DocumentVersionRefSchema,
3081
- protection: DocumentProtectionSchema,
3082
- meta: MutationMetaSchema
3083
- });
3084
- const SignatureAbortResultSchema = z.object({ status: z.enum([
3085
- "aborted",
3086
- "already-completed",
3087
- "unknown"
3088
- ]) });
3089
- const ChangeFindingSchema = z.object({
3090
- rule: z.string(),
3091
- verdict: z.enum([
3092
- "permitted",
3093
- "forbidden",
3094
- "incomplete"
3095
- ]),
3096
- objectNumber: z.number().int().nonnegative(),
3097
- edge: z.string().optional(),
3098
- detail: z.string().optional()
3099
- });
3100
- const AnalysisDetailSchema = z.enum(["summary", "full"]);
3101
- /** The analysis: one verdict (`current`) with its findings, the restrictions it was judged under, and facts about the revisions in between. */
3102
- const ChangeAnalysisSchema = z.object({
3103
- mode: z.enum(["authoritative", "exploratory"]),
3104
- policyVersion: z.number().int(),
3105
- basis: z.object({
3106
- version: BaseVersionInfoSchema,
3107
- editsVersion: z.number().int().nonnegative(),
3108
- source: z.enum(["persisted", "working-copy"])
3109
- }),
3110
- since: z.object({
3111
- revisionIndex: z.number().int().nonnegative(),
3112
- signatureIndex: z.number().int().nonnegative().nullable()
3113
- }),
3114
- until: z.object({ revisionIndex: z.number().int().nonnegative() }),
3115
- restrictions: z.array(z.object({
3116
- signatureIndex: z.number().int().nonnegative(),
3117
- revisionIndex: z.number().int().nonnegative(),
3118
- source: z.enum([
3119
- "docmdp",
3120
- "fieldmdp",
3121
- "lock"
3122
- ]),
3123
- own: z.boolean(),
3124
- permission: z.union([
3125
- z.literal(1),
3126
- z.literal(2),
3127
- z.literal(3)
3128
- ]).optional(),
3129
- fields: z.unknown().optional()
3130
- })),
3131
- current: z.object({
3132
- verdict: z.enum([
3133
- "unchanged",
3134
- "permitted",
3135
- "forbidden",
3136
- "indeterminate"
3137
- ]),
3138
- complete: z.boolean(),
3139
- primary: ChangeFindingSchema.optional(),
3140
- findings: z.array(ChangeFindingSchema),
3141
- method: z.enum(["net-state", "net-state+replay"])
3142
- }),
3143
- later: z.object({
3144
- revisionCount: z.number().int().nonnegative(),
3145
- undoneObjectNumbers: z.array(z.number().int().nonnegative())
3146
- }),
3147
- /** Equals `current.verdict`. */
3148
- verdict: z.enum([
3149
- "unchanged",
3150
- "permitted",
3151
- "forbidden",
3152
- "indeterminate"
3153
- ]),
3154
- /** The step DTOs are large and evolving; carried verbatim. */
3155
- steps: z.array(z.unknown())
3156
- });
3157
- const SignatureAttributionSchema = z.object({
3158
- name: z.string().optional(),
3159
- reason: z.string().optional(),
3160
- location: z.string().optional(),
3161
- contactInfo: z.string().optional()
3162
- });
3163
- /** The JSON part of a visual signature fill (multipart envelope): which resource part holds the PDF, and its page. */
3164
- const SignatureAppearanceBodySchema = z.object({
3165
- resource: z.string().min(1),
3166
- pageIndex: z.number().int().nonnegative().optional()
3167
- });
3168
- /**
3169
- * The JSON part of a prepare (multipart envelope): `SignaturePrepareInput`
3170
- * with the appearance artwork referenced by its resource part instead of
3171
- * inline bytes.
3172
- */
3173
- const SignaturePrepareBodySchema = z.object({
3174
- field: FormFieldRefSchema,
3175
- kind: z.enum(["signature", "timestamp"]).optional(),
3176
- subFilter: z.enum(["adbe.pkcs7.detached", "ETSI.CAdES.detached"]).optional(),
3177
- digest: z.enum([
3178
- "sha256",
3179
- "sha384",
3180
- "sha512"
3181
- ]).optional(),
3182
- contentsSize: z.number().int().positive().optional(),
3183
- attribution: SignatureAttributionSchema.optional(),
3184
- /** @deprecated the pre-rename spelling of `attribution`; servers read either. */
3185
- signer: SignatureAttributionSchema.optional(),
3186
- signingTime: z.string().optional(),
3187
- certify: z.object({ permission: DocMdpPermissionSchema }).optional(),
3188
- lock: FieldLockSpecSchema.optional(),
3189
- appearance: z.object({
3190
- resource: z.string().min(1),
3191
- pageIndex: z.number().int().nonnegative().optional()
3192
- }).optional()
3193
- });
3194
- const optionalIndex = z.coerce.number().int().nonnegative().optional();
3195
- /** Layer analysis query (the current form): exactly one `since.*`; the working copy is the end. */
3196
- const LayerAnalysisQuerySchema = z.object({
3197
- "since.signature": optionalIndex,
3198
- "since.revision": optionalIndex,
3199
- level: ModificationLevelSchema.optional(),
3200
- detail: AnalysisDetailSchema.optional()
3201
- }).refine((q) => q["since.signature"] === void 0 !== (q["since.revision"] === void 0), { message: "exactly one of since.signature / since.revision is required" });
3202
- /** Version analysis query: as the layer's, plus `until` (a revision index; default the last). */
3203
- const VersionAnalysisQuerySchema = z.object({
3204
- "since.signature": optionalIndex,
3205
- "since.revision": optionalIndex,
3206
- until: optionalIndex,
3207
- level: ModificationLevelSchema.optional(),
3208
- detail: AnalysisDetailSchema.optional(),
3209
- /** The judging policy version the caller expects — a cache key, not an input (version responses are immutable). */
3210
- policy: optionalIndex
3211
- }).refine((q) => q["since.signature"] === void 0 !== (q["since.revision"] === void 0), { message: "exactly one of since.signature / since.revision is required" });
3212
- function analyzeInputFromQuery(query, until) {
3213
- return {
3214
- since: query["since.signature"] !== void 0 ? { signatureIndex: query["since.signature"] } : { revisionIndex: query["since.revision"] ?? 0 },
3215
- ...until !== void 0 ? { until } : {},
3216
- ...query.level !== void 0 ? { exploratoryLevel: query.level } : {},
3217
- ...query.detail !== void 0 ? { detail: query.detail } : {}
3218
- };
3219
- }
3220
- /** One row of the document's version catalog. */
3221
- const DocumentVersionSchema = z.object({
3222
- sha256: z.string().regex(/^[0-9a-f]{64}$/),
3223
- byteLength: z.number().int().nonnegative(),
3224
- number: z.number().int().positive(),
3225
- parentSha256: z.string().nullable(),
3226
- producer: z.enum(["upload", "signature"]),
3227
- signingId: z.string().nullable(),
3228
- createdAt: z.number().int()
3229
- });
3230
- const DocumentVersionsSchema = z.object({
3231
- /** `documents.base_sha`: the version every layer is over, or behind. */
3232
- head: z.string().regex(/^[0-9a-f]{64}$/),
3233
- /** Oldest first. */
3234
- versions: z.array(DocumentVersionSchema)
3235
- });
3236
- const PageScaleResultSchema = z.object({
3237
- pageObjectNumber: z.number().int().positive(),
3238
- meta: MutationMetaSchema
3239
- });
3240
- //#endregion
3241
- export { PageBoxesSchema as $, PdfLinkTargetWritableSchema as $n, InkIntentSchema as $r, FormDataFormatSchema as $t, DocumentVersionRefSchema as A, StrikeoutDTOSchema as An, FileAttachmentWireDraftSchema as Ar, SearchMatchSchema as At, FormImportResultSchema as B, SquareDTOSchema as Bn, CaretPatchSchema as Br, SignatureDTOSchema as Bt, ChangeAnalysisSchema as C, PdfQuadSchema as Ci, UnderlineDTOSchema as Cn, HighlightPatchSchema as Cr, PageStructureCacheSchema as Ct, DocumentMetadataSchema as D, TextDTOSchema as Dn, FileAttachmentDTOSchema as Dr, RedactionApplyResultSchema as Dt, DocumentManifestSchema as E, PdfSizeSchema as Ei, NoteIconSchema as En, FreeTextPatchSchema as Er, PdfSaveModeSchema as Et, FormEffectSchema as F, StampWireDraftSchema as Fn, CircleDTOSchema as Fr, SearchSnippetSchema as Ft, LayerScopesSchema as G, PolylinePatchSchema as Gn, AnnotationFlagsSchema as Gr, VersionAnalysisQuerySchema as Gt, FormSetValueResultSchema as H, SquarePatchSchema as Hn, AnnotationBorderStyleSchema as Hr, SignaturePreparedWireSchema as Ht, FormEffectsResultSchema as I, StampWirePatchSchema as In, CircleDraftSchema as Ir, SignatureAbortResultSchema as It, MetadataUpdateResultSchema as J, PolygonPatchSchema as Jn, AnnotationStableIdSchema as Jr, analyzeInputFromQuery as Jt, ManifestPageSchema as K, PolygonDTOSchema as Kn, AnnotationPatchBaseShape as Kr, WeakAnnotationSessionPagesRequestSchema as Kt, FormFieldCreateResultSchema as L, SquigglyDTOSchema as Ln, CirclePatchSchema as Lr, SignatureAppearanceBodySchema as Lt, DocumentVersionsSchema as M, StrikeoutPatchSchema as Mn, AttachmentFileInfoSchema as Mr, SearchQuerySchema as Mt, EngineErrorPayloadSchema as N, ResourceRefSchema as Nn, EmbeddedFileItemSchema as Nr, SearchRequestSchema as Nt, DocumentProtectionSchema as O, TextDraftSchema as On, FileAttachmentIconSchema as Or, RedactionApplyScopeSchema as Ot, FieldLockSpecSchema as P, StampDTOSchema as Pn, EmbeddedFileRefSchema as Pr, SearchSliceSchema as Pt, OpenDocumentResponseSchema as Q, PdfLinkTargetSchema as Qn, FreeTextIntentSchema as Qr, toBase64 as Qt, FormFieldDeleteResultSchema as R, SquigglyDraftSchema as Rn, CaretDTOSchema as Rr, SignatureCompleteBodySchema as Rt, CachePinsSchema as S, PdfPointSchema as Si, UnsupportedPatchSchema as Sn, HighlightDraftSchema as Sr, PageStateSchema as St, DocumentHeadSchema as T, PdfRotationSchema as Ti, UnderlinePatchSchema as Tn, FreeTextDraftSchema as Tr, PdfRevisionSchema as Tt, FormWidgetLinkResultSchema as U, PolylineDTOSchema as Un, AnnotationDraftBaseShape as Ur, SignatureSeedValueSchema as Ut, FormRepairResultSchema as V, SquareDraftSchema as Vn, AnnotationBaseShape as Vr, SignaturePrepareBodySchema as Vt, LayerAnalysisQuerySchema as W, PolylineDraftSchema as Wn, AnnotationFlagsPartialSchema as Wr, SignatureSnapshotSchema as Wt, MutationMetaSchema as X, LinkDraftSchema as Xn, CaretIntentSchema as Xr, encodePrepared as Xt, ModificationLevelSchema as Y, LinkDTOSchema as Yn, BlendModeSchema as Yr, decodePrepared as Yt, NamedPageEntrySchema as Z, LinkPatchSchema as Zn, ColorSchema as Zr, fromBase64 as Zt, AttachmentDeleteResultSchema as _, PdfPageActionsSchema as _i, AnnotationPatchSchema as _n, ShapeDimensionCaptionSchema as _r, PageRenderAnnotatedQuerySchema as _t, AnnotationAppearancesQuerySchema as a, RevisionTokenSchema as ai, FormFieldPatchSchema as an, LineIntentSchema as ar, PageGeometrySnapshotSchema as at, ByteRangeSchema as b, InkListSchema as bi, UnsupportedDTOSchema as bn, InkPatchSchema as br, PageRotateResultSchema as bt, AnnotationFlattenInputSchema as c, TextAlignmentSchema as ci, FormKindSchema as cn, PageScaleInputSchema as cr, PageInsertResultSchema as ct, AnnotationListPageSnapshotSchema as d, PdfActionTargetRefSchema as di, FormWidgetRefSchema as dn, PdfMeasureWriteSchema as dr, PageMoveInputSchema as dt, LineEndingSchema as ei, FormFieldDTOSchema as en, LineDTOSchema as er, PageDeleteInputSchema as et, AnnotationListSnapshotAllPagesSchema as f, PdfActionTreeSchema as fi, ToggleFieldWidgetSchema as fn, PdfMeasurementSchema as fr, PageMoveResultSchema as ft, AttachmentCreateResultSchema as g, PdfFieldActionsSchema as gi, AnnotationDraftSchema as gn, ShapeCaptionPatchSchema as gr, PageRemoveNameInputSchema as gt, AppearanceOutcomeSchema as h, PdfAnnotationActionsSchema as hi, AnnotationDTOSchema as hn, PolylineIntentSchema as hr, PageNetworkRenderFormatSchema as ht, AnnotationAppearanceManifestSchema as i, RectSchema as ii, FormFieldOptionSchema as in, LineDimensionCaptionSchema as ir, PageFlattenResultSchema as it, DocumentVersionSchema as j, StrikeoutDraftSchema as jn, WireAttachmentFileSchema as jr, SearchModeSchema as jt, DocumentSecurityStateSchema as k, TextPatchSchema as kn, FileAttachmentPatchSchema as kr, RefetchReasonSchema as kt, AnnotationFlattenResultSchema as l, DocumentActionsSnapshotSchema as li, FormSnapshotSchema as ln, PdfForeignMeasureSchema as lr, PageLayoutSchema as lt, AnnotationUpdateResultSchema as m, PdfActionWireComponents as mi, ANNOTATION_KINDS as mn, PolygonIntentSchema as mr, PageNameResultSchema as mt, AccessResponseSchema as n, PdfRectDifferencesSchema as ni, FormFieldFlagsSchema as nn, LinePatchSchema as nr, PageExtractInputSchema as nt, AnnotationCreateResultSchema as o, StandardFontSchema as oi, FormFieldRefSchema as on, LineLeaderSchema as or, PageInsertBlankInputSchema as ot, AnnotationMoveResultSchema as p, PdfActionTypeSchema as pi, WidgetPlacementSchema as pn, PdfNumberFormatSchema as pr, PageNameInputSchema as pt, MetadataPatchSchema as q, PolygonDraftSchema as qn, AnnotationRefSchema as qr, WeakAnnotationSessionResponseSchema as qt, AnnotationAppearanceExportInputSchema as r, PointSchema as ri, FormFieldOptionInputSchema as rn, LineCaptionPatchSchema as rr, PageFlattenInputSchema as rt, AnnotationDeleteResultSchema as s, StrikeoutIntentSchema as si, FormFieldValueSchema as sn, PageMeasurementViewportSchema as sr, PageInsertInputSchema as st, AccessRequestSchema as t, LineEndingsSchema as ti, FormFieldDraftSchema as tn, LineDraftSchema as tr, PageDeleteResultSchema as tt, AnnotationListMutationMetaSchema as u, PdfActionNodeSchema as ui, FormValueEntrySchema as un, PdfMeasureSchema as ur, PageListSnapshotSchema as ut, AttachmentsCacheSchema as v, PdfDestinationSchema as vi, KIND_BY_SUBTYPE as vn, InkDTOSchema as vr, PageRenderQuerySchema as vt, DigestAlgorithmSchema as w, PdfRectSchema as wi, UnderlineDraftSchema as wn, FreeTextDTOSchema as wr, PageTextSnapshotSchema as wt, CacheDeltaSchema as x, LinePointsSchema as xi, UnsupportedDraftSchema as xn, HighlightDTOSchema as xr, PageScaleResultSchema as xt, BaseVersionInfoSchema as y, CalloutLineSchema as yi, WidgetAppearanceSchema as yn, InkDraftSchema as yr, PageRotateInputSchema as yt, FormFieldUpdateResultSchema as z, SquigglyPatchSchema as zn, CaretDraftSchema as zr, SignatureCompleteResultSchema as zt };
3242
-
3243
- //# sourceMappingURL=schemas-CFQGvWiu.js.map