From 82b0db671ca5cce588c313f777aa1829caf7ba01 Mon Sep 17 00:00:00 2001 From: rajun Date: Tue, 27 Oct 2026 16:28:51 +0530 Subject: [PATCH] feat: add AR page options schema --- app/schemas/projects/ar-page.ts | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/schemas/projects/ar-page.ts diff --git a/app/schemas/projects/ar-page.ts b/app/schemas/projects/ar-page.ts new file mode 100644 index 0000000..4242ca7 --- /dev/null +++ b/app/schemas/projects/ar-page.ts @@ -0,0 +1,34 @@ +import { z } from 'zod'; +import { AR_PAGE_DEFAULTS, BUTTON_CUSTOM_LIMITS } from '~/data/projects/constants'; +import { hexColor } from '~/schemas/color'; +import type { ArPageSettings, ButtonCustomSize } from '~/types/project'; + +function px(key: keyof typeof BUTTON_CUSTOM_LIMITS) { + const { label, min, max } = BUTTON_CUSTOM_LIMITS[key]; + const message = `${label} must be ${min} to ${max} px`; + return z.number({ error: message }).int(message).min(min, message).max(max, message); +} + +export const buttonCustomSchema = z.object({ + height: px('height'), + width: px('width').nullable(), + paddingX: px('paddingX'), + radius: px('radius'), + borderWidth: px('borderWidth'), + borderColor: hexColor, +}) satisfies z.ZodType; + +export const arPageSchema = z.object({ + bars: z.boolean(), + modelName: z.boolean(), + logoBacking: z.boolean(), + thobLogo: z.boolean(), + buttonSize: z.enum(['sm', 'md', 'lg', 'full', 'custom']), + buttonCustom: buttonCustomSchema, +}) satisfies z.ZodType; + +// Saved options over the defaults; anything missing or invalid keeps its default +export function readArPage(value: unknown): ArPageSettings { + const result = arPageSchema.partial().safeParse(value); + return { ...AR_PAGE_DEFAULTS, ...(result.success ? result.data : {}) }; +}