import { z } from 'zod'; export const sectionSchema = z.any().superRefine((x, ctx) => { const schemas = [z.object({ "type": z.literal("page"), "align": z.enum(["top","center","bottom"]).describe("Vertical alignment of page content").default("top"), "startY": z.number().gte(0).lte(50).describe("Y position in cm (overrides align)").optional(), "content": z.array(z.any()).min(1).max(100).describe("Page content elements") }).strict().describe("Styled single page with custom positioning"), z.object({ "type": z.literal("flow"), "newPage": z.boolean().describe("Start this section on a new page (default: true)").default(true), "content": z.array(z.any()).min(1).max(200).describe("Flow content elements") }).strict().describe("Flowing content across multiple pages")]; const errors = schemas.reduce( (errors, schema) => ((result) => result.error ? [...errors, result.error] : errors)( schema.safeParse(x), ), [], ); if (schemas.length - errors.length !== 1) { ctx.addIssue({ path: ctx.path, code: "invalid_union", unionErrors: errors, message: "Invalid input: Should pass single schema", }); } }).describe("JSON schema for section configuration (extracted from document schema)")