Skip to content

Commit 92577d4

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 92577d4

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

validate.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import type { RenderOptions, RenderResult, Term } from "./term.ts";
77

88
const u8 = Type.Integer({ minimum: 0, maximum: 255 });
99
const u16 = Type.Integer({ minimum: 0, maximum: 65535 });
10-
const u32 = Type.Integer({ minimum: 0, maximum: 0xFFFFFFFF });
11-
const color = Type.Integer({ minimum: -0x80000000, maximum: 0xFFFFFFFF });
10+
11+
/* RGBA color packed as (a << 24 | r << 16 | g << 8 | b). When alpha >= 128,
12+
* bit 31 is set and JavaScript interprets the value as a negative int32.
13+
* Accept both signed and unsigned representations of the same bit pattern. */
14+
const rgba = Type.Integer({ minimum: -0x80000000, maximum: 0xFFFFFFFF });
1215

1316
/* ── Sizing axis (discriminated union) ────────────────────────────── */
1417

@@ -65,7 +68,7 @@ const CornerRadius = Type.Object({
6568
});
6669

6770
const Border = Type.Object({
68-
color: color,
71+
color: rgba,
6972
left: Type.Optional(u8),
7073
right: Type.Optional(u8),
7174
top: Type.Optional(u8),
@@ -94,7 +97,7 @@ const OpenElement = Type.Object({
9497
id: Type.Literal(0x02),
9598
name: Type.String(),
9699
layout: Type.Optional(Layout),
97-
bg: Type.Optional(color),
100+
bg: Type.Optional(rgba),
98101
cornerRadius: Type.Optional(CornerRadius),
99102
border: Type.Optional(Border),
100103
clip: Type.Optional(Clip),
@@ -104,7 +107,7 @@ const OpenElement = Type.Object({
104107
const TextOp = Type.Object({
105108
id: Type.Literal(0x03),
106109
content: Type.String(),
107-
color: Type.Optional(color),
110+
color: Type.Optional(rgba),
108111
fontSize: Type.Optional(u8),
109112
fontId: Type.Optional(u8),
110113
wrap: Type.Optional(u8),

0 commit comments

Comments
 (0)