diff --git a/validate.ts b/validate.ts index d3b7d45..1481aa4 100644 --- a/validate.ts +++ b/validate.ts @@ -7,7 +7,11 @@ import type { RenderOptions, RenderResult, Term } from "./term.ts"; const u8 = Type.Integer({ minimum: 0, maximum: 255 }); const u16 = Type.Integer({ minimum: 0, maximum: 65535 }); -const u32 = Type.Integer({ minimum: 0, maximum: 0xFFFFFFFF }); + +/* RGBA color packed as (a << 24 | r << 16 | g << 8 | b). When alpha >= 128, + * bit 31 is set and JavaScript interprets the value as a negative int32. + * Accept both signed and unsigned representations of the same bit pattern. */ +const rgba = Type.Integer({ minimum: -0x80000000, maximum: 0xFFFFFFFF }); /* ── Sizing axis (discriminated union) ────────────────────────────── */ @@ -64,7 +68,7 @@ const CornerRadius = Type.Object({ }); const Border = Type.Object({ - color: u32, + color: rgba, left: Type.Optional(u8), right: Type.Optional(u8), top: Type.Optional(u8), @@ -93,7 +97,7 @@ const OpenElement = Type.Object({ id: Type.Literal(0x02), name: Type.String(), layout: Type.Optional(Layout), - bg: Type.Optional(u32), + bg: Type.Optional(rgba), cornerRadius: Type.Optional(CornerRadius), border: Type.Optional(Border), clip: Type.Optional(Clip), @@ -103,7 +107,7 @@ const OpenElement = Type.Object({ const TextOp = Type.Object({ id: Type.Literal(0x03), content: Type.String(), - color: Type.Optional(u32), + color: Type.Optional(rgba), fontSize: Type.Optional(u8), fontId: Type.Optional(u8), wrap: Type.Optional(u8),