Skip to content

Add hex <-> sRGB color conversions and tests#14

Closed
mck wants to merge 1 commit into
mainfrom
fix/to-hex
Closed

Add hex <-> sRGB color conversions and tests#14
mck wants to merge 1 commit into
mainfrom
fix/to-hex

Conversation

@mck

@mck mck commented Jan 26, 2026

Copy link
Copy Markdown
Collaborator

Introduces Tokenscript implementations for converting between hexadecimal and sRGB color formats. Updates the sRGB color schema to include these conversions and adds comprehensive unit tests to verify correctness and round-trip consistency.

Introduces Tokenscript implementations for converting between hexadecimal and sRGB color formats. Updates the sRGB color schema to include these conversions and adds comprehensive unit tests to verify correctness and round-trip consistency.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds bidirectional color conversion between hexadecimal and sRGB formats, enabling seamless transformations between the web-standard hex notation (e.g., #ff0000) and the normalized sRGB color space (0-1 range). The implementation mirrors the existing RGB-to-hex conversion patterns and includes comprehensive test coverage.

Changes:

  • Added from-hex.tokenscript to convert hex colors to sRGB (supports both 3-digit and 6-digit formats)
  • Added to-hex.tokenscript to convert sRGB colors to hex format
  • Updated srgb-color schema.json to register both conversion directions

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/schemas/types/srgb-color/from-hex.tokenscript Implements hex to sRGB conversion by parsing hex strings and normalizing RGB values to 0-1 range
src/schemas/types/srgb-color/to-hex.tokenscript Implements sRGB to hex conversion by scaling 0-1 values to 0-255 and formatting as hex strings
src/schemas/types/srgb-color/schema.json Registers bidirectional hex conversion definitions with lossless flags
src/schemas/types/srgb-color/unit.test.ts Adds comprehensive test suites for conversions including edge cases, boundary values, and round-trip consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +17
variable rgba: List = {input}.r * 255, {input}.g * 255, {input}.b * 255;
variable hex: String = "#";
variable i: Number = 0;
variable value: Number = 0;

while(i < 3) [
value = round(rgba.get(i));

Copilot AI Jan 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is named rgba but only contains RGB values (no alpha channel). Consider renaming to rgb for clarity, as sRGB colors in this conversion don't include an alpha channel. Compare with rgb-color/to-hex.tokenscript where the rgba name is justified because that type can include an optional alpha property that is handled later in the script.

Suggested change
variable rgba: List = {input}.r * 255, {input}.g * 255, {input}.b * 255;
variable hex: String = "#";
variable i: Number = 0;
variable value: Number = 0;
while(i < 3) [
value = round(rgba.get(i));
variable rgb: List = {input}.r * 255, {input}.g * 255, {input}.b * 255;
variable hex: String = "#";
variable i: Number = 0;
variable value: Number = 0;
while(i < 3) [
value = round(rgb.get(i));

Copilot uses AI. Check for mistakes.
@mck mck closed this Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants