Skip to content

Commit 25f9863

Browse files
committed
🐛 accept signed int32 colors in validator
The rgba() function returns signed int32 when alpha >= 128 (bit 31 set). The validator's u32 type rejected these negative values. Add a color type that accepts the full signed-to-unsigned 32-bit range.
1 parent 7602722 commit 25f9863

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

validate.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type { RenderOptions, RenderResult, Term } from "./term.ts";
88
const u8 = Type.Integer({ minimum: 0, maximum: 255 });
99
const u16 = Type.Integer({ minimum: 0, maximum: 65535 });
1010
const u32 = Type.Integer({ minimum: 0, maximum: 0xFFFFFFFF });
11-
const color = Type.Integer({ minimum: -0x80000000, maximum: 0xFFFFFFFF });
11+
12+
/* RGBA color packed as (a << 24 | r << 16 | g << 8 | b). When alpha >= 128,
13+
* bit 31 is set and JavaScript interprets the value as a negative int32.
14+
* Accept both signed and unsigned representations of the same bit pattern. */
15+
const rgba = Type.Integer({ minimum: -0x80000000, maximum: 0xFFFFFFFF });
1216

1317
/* ── Sizing axis (discriminated union) ────────────────────────────── */
1418

@@ -65,7 +69,7 @@ const CornerRadius = Type.Object({
6569
});
6670

6771
const Border = Type.Object({
68-
color: color,
72+
color: rgba,
6973
left: Type.Optional(u8),
7074
right: Type.Optional(u8),
7175
top: Type.Optional(u8),
@@ -94,7 +98,7 @@ const OpenElement = Type.Object({
9498
id: Type.Literal(0x02),
9599
name: Type.String(),
96100
layout: Type.Optional(Layout),
97-
bg: Type.Optional(color),
101+
bg: Type.Optional(rgba),
98102
cornerRadius: Type.Optional(CornerRadius),
99103
border: Type.Optional(Border),
100104
clip: Type.Optional(Clip),
@@ -104,7 +108,7 @@ const OpenElement = Type.Object({
104108
const TextOp = Type.Object({
105109
id: Type.Literal(0x03),
106110
content: Type.String(),
107-
color: Type.Optional(color),
111+
color: Type.Optional(rgba),
108112
fontSize: Type.Optional(u8),
109113
fontId: Type.Optional(u8),
110114
wrap: Type.Optional(u8),

0 commit comments

Comments
 (0)