41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
import * as z from "zod/v4";
|
|
import { FONT_TYPES } from "./constants.js";
|
|
const WeightSchema = z.union([z.string(), z.number()]);
|
|
const StyleSchema = z.enum(["normal", "italic", "oblique"]);
|
|
const DisplaySchema = z.enum(["auto", "block", "swap", "fallback", "optional"]);
|
|
const FormatSchema = z.enum(FONT_TYPES);
|
|
const _FontProviderSchema = z.strictObject({
|
|
name: z.string(),
|
|
config: z.record(z.string(), z.any()).optional(),
|
|
init: z.custom((v) => typeof v === "function").optional(),
|
|
resolveFont: z.custom((v) => typeof v === "function"),
|
|
listFonts: z.custom((v) => typeof v === "function").optional()
|
|
});
|
|
const FontProviderSchema = z.custom((v) => {
|
|
return _FontProviderSchema.safeParse(v).success;
|
|
}, "Invalid FontProvider object");
|
|
const FontFamilySchema = z.object({
|
|
name: z.string(),
|
|
cssVariable: z.string(),
|
|
provider: FontProviderSchema,
|
|
weights: z.tuple([WeightSchema], WeightSchema).optional(),
|
|
styles: z.tuple([StyleSchema], StyleSchema).optional(),
|
|
subsets: z.tuple([z.string()], z.string()).optional(),
|
|
formats: z.tuple([FormatSchema], FormatSchema).optional(),
|
|
fallbacks: z.array(z.string()).optional(),
|
|
optimizedFallbacks: z.boolean().optional(),
|
|
display: DisplaySchema.optional(),
|
|
stretch: z.string().optional(),
|
|
featureSettings: z.string().optional(),
|
|
variationSettings: z.string().optional(),
|
|
unicodeRange: z.tuple([z.string()], z.string()).optional(),
|
|
options: z.record(z.string(), z.any()).optional()
|
|
}).strict();
|
|
export {
|
|
DisplaySchema,
|
|
FontFamilySchema,
|
|
FontProviderSchema,
|
|
StyleSchema,
|
|
WeightSchema
|
|
};
|