Skip to content

Commit d402924

Browse files
authored
Merge pull request #7 from thefrontside/validate-colors
Accept signed int32 colors in validator
2 parents 0a70d40 + 92577d4 commit d402924

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
@@ -7,7 +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 });
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 });
1115

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

@@ -64,7 +68,7 @@ const CornerRadius = Type.Object({
6468
});
6569

6670
const Border = Type.Object({
67-
color: u32,
71+
color: rgba,
6872
left: Type.Optional(u8),
6973
right: Type.Optional(u8),
7074
top: Type.Optional(u8),
@@ -93,7 +97,7 @@ const OpenElement = Type.Object({
9397
id: Type.Literal(0x02),
9498
name: Type.String(),
9599
layout: Type.Optional(Layout),
96-
bg: Type.Optional(u32),
100+
bg: Type.Optional(rgba),
97101
cornerRadius: Type.Optional(CornerRadius),
98102
border: Type.Optional(Border),
99103
clip: Type.Optional(Clip),
@@ -103,7 +107,7 @@ const OpenElement = Type.Object({
103107
const TextOp = Type.Object({
104108
id: Type.Literal(0x03),
105109
content: Type.String(),
106-
color: Type.Optional(u32),
110+
color: Type.Optional(rgba),
107111
fontSize: Type.Optional(u8),
108112
fontId: Type.Optional(u8),
109113
wrap: Type.Optional(u8),

0 commit comments

Comments
 (0)