Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(annotations): let an arrow's box start before the frame

EtienneLescot599eeb5164bb
diff --git a/src/lib/ai-edition/schema/index.test.ts b/src/lib/ai-edition/schema/index.test.ts
index edc37804a..38aabd870 100644
--- a/src/lib/ai-edition/schema/index.test.ts
+++ b/src/lib/ai-edition/schema/index.test.ts
@@ -198,6 +198,23 @@ describe("axcut-schema v8", () => {
expect([sizeOf(0), sizeOf(24), sizeOf(500)]).toEqual([8, 24, 200]);
});
+ it("opens an arrow drawn against the frame's edge, whose box starts before it", () => {
+ const at = (type: "figure" | "text", x: number) => () =>
+ annotationRegionSchema.parse({
+ id: "ann_1",
+ startMs: 0,
+ endMs: 1500,
+ type,
+ position: { x, y: -5 },
+ size: { width: 30, height: 53 },
+ style: {},
+ zIndex: 1,
+ });
+ // A right arrow with a 6 px stroke, dragged to the left edge (`arrowBox`).
+ expect(at("figure", -17)().position).toEqual({ x: -17, y: -5 });
+ expect(at("text", -17)).toThrow("position must be at least 0");
+ });
+
it("zoomRegionSchema rejects unknown depths", () => {
expect(() =>
zoomRegionSchema.parse({
diff --git a/src/lib/ai-edition/schema/index.ts b/src/lib/ai-edition/schema/index.ts
index 39acf68d6..9c5760f19 100644
--- a/src/lib/ai-edition/schema/index.ts
+++ b/src/lib/ai-edition/schema/index.ts
@@ -466,9 +466,10 @@ export const annotationRegionSchema = endGteStart(
// what it hides, and every annotation saved before frame placement existed. See
// `annotations/placement.ts`.
space: z.literal("frame").optional(),
+ // At least 0 too, except for an arrow: see the refine below.
position: z.object({
- x: z.number().min(0).max(100),
- y: z.number().min(0).max(100),
+ x: z.number().max(100),
+ y: z.number().max(100),
}),
size: z.object({
width: z.number().positive(),
@@ -482,6 +483,12 @@ export const annotationRegionSchema = endGteStart(
}),
"endMs",
"startMs",
+).refine(
+ // The compositor draws an arrow in the middle of its square box, so an arrow drawn against the
+ // frame's left or top edge has a box that starts before the frame (`annotations/arrowBounds.ts`).
+ // Its strokes stay inside. Every other box starts inside the frame.
+ (region) => region.type === "figure" || (region.position.x >= 0 && region.position.y >= 0),
+ { message: "position must be at least 0", path: ["position"] },
);
export const zoomRegionSchema = endGteStart(