/** * Zod schemas for engine PDF-document geometry. Exported from `wire.ts` only * (never from `shared.ts`/`runtime`) so the zod-free runtime stays zod-free. */ import { z } from 'zod'; import type { PageBox, PagePoint, PageQuad } from './pageSpace'; import type { CalloutLine, InkList, LinePoints, PdfPoint, PdfQuad, PdfRect, PdfRotation, PdfSize, } from './primitives'; import { closed } from '../wire/reading'; export const PdfPointSchema: z.ZodType = z.object({ x: z.number(), y: z.number(), }); export const LinePointsSchema: z.ZodType = z.object({ start: PdfPointSchema, end: PdfPointSchema, }); /** `/CL` callout leader line — two points (straight) or three (knee-jointed). */ export const CalloutLineSchema: z.ZodType = z.union([ z.tuple([PdfPointSchema, PdfPointSchema]), z.tuple([PdfPointSchema, PdfPointSchema, PdfPointSchema]), ]); /** `/InkList` — an array of strokes, each an array of points. */ export const InkListSchema: z.ZodType = z.array(z.array(PdfPointSchema)); /** A rect's edges are finite, as `isFinitePdfRect` checks them on the page. */ export const PdfRectSchema: z.ZodType = z.object({ left: z.number().finite(), bottom: z.number().finite(), right: z.number().finite(), top: z.number().finite(), }); export const PdfSizeSchema: z.ZodType = z.object({ width: z.number().nonnegative(), height: z.number().nonnegative(), }); export const PdfQuadSchema: z.ZodType = z.object({ upperLeft: PdfPointSchema, upperRight: PdfPointSchema, lowerLeft: PdfPointSchema, lowerRight: PdfPointSchema, }); export const PdfRotationSchema: z.ZodType = closed( z.union([z.literal(0), z.literal(90), z.literal(180), z.literal(270)]), ); // ── page space ── export const PagePointSchema: z.ZodType = z.object({ x: z.number(), y: z.number(), }); /** A box is finite, as a rect is (`PdfRectSchema`). */ export const PageBoxSchema: z.ZodType = z.object({ x: z.number().finite(), y: z.number().finite(), width: z.number().finite().nonnegative(), height: z.number().finite().nonnegative(), }); export const PageQuadSchema: z.ZodType = z.object({ upperLeft: PagePointSchema, upperRight: PagePointSchema, lowerLeft: PagePointSchema, lowerRight: PagePointSchema, });