Add freeform headline box editing and text alignment
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { savedSignSchema } from "./sign";
|
||||
|
||||
test("dragged headline positions persist and reject invalid coordinates", () => {
|
||||
const base = { title: "Wedding", headline: "Share", message: "Welcome", paper: "card6x4", ink: "black" };
|
||||
expect(savedSignSchema.parse(base).headlinePosition).toBeUndefined();
|
||||
const moved = { ...base, headlinePosition: { x: 12.5, y: 14, width: 42, height: 28 }, headlineAlign: "center", headlineVerticalAlign: "middle" };
|
||||
expect(savedSignSchema.parse(JSON.parse(JSON.stringify(moved)))).toEqual(moved);
|
||||
for (const headlinePosition of [{ x: -1, y: 0 }, { x: 0, y: 101 }, { x: NaN, y: 2 }, { x: 1, y: Infinity }, { x: "5", y: 0 }, { x: 0, y: 0, z: 2 }]) {
|
||||
expect(savedSignSchema.safeParse({ ...base, headlinePosition }).success).toBe(false);
|
||||
}
|
||||
for (const patch of [{ headlineAlign: "justify" }, { headlineVerticalAlign: "center" }, { headlinePosition: { x: 0, y: 0, width: 0 } }, { headlinePosition: { x: 0, y: 0, height: 101 } }]) {
|
||||
expect(savedSignSchema.safeParse({ ...base, ...patch }).success).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
test("text sizing survives saved design round trips and rejects invalid scales", () => {
|
||||
const base = { title: "Event", headline: "Share", message: "Welcome", paper: "letter", ink: "indigo" };
|
||||
expect(savedSignSchema.parse(base).headlineScale).toBeUndefined();
|
||||
|
||||
@@ -40,6 +40,12 @@ export const savedSignSchema = z.object({
|
||||
decoration: z.enum(["arch", "frame", "minimal"]).optional(), showBrand: z.boolean().optional(),
|
||||
backgroundImage: image, logoImage: image,
|
||||
showUrl: z.boolean().optional(),
|
||||
headlinePosition: z.object({
|
||||
x: z.number().finite().min(0).max(100), y: z.number().finite().min(0).max(100),
|
||||
width: z.number().finite().positive().max(100).optional(), height: z.number().finite().positive().max(100).optional(),
|
||||
}).strict().optional(),
|
||||
headlineAlign: z.enum(["left", "center", "right"]).optional(),
|
||||
headlineVerticalAlign: z.enum(["top", "middle", "bottom"]).optional(),
|
||||
}).strict().superRefine((design, ctx) => {
|
||||
if (design.paper !== "custom") return;
|
||||
const divisor = design.unit === "mm" ? 25.4 : 1;
|
||||
|
||||
Reference in New Issue
Block a user