Skip to content

fix: preserve hex color alpha precision - #1813

Open
mmporong wants to merge 1 commit into
melonjs:masterfrom
mmporong:fix/hex-alpha-precision
Open

mmporong wants to merge 1 commit into
melonjs:masterfrom
mmporong:fix/hex-alpha-precision

Conversation

@mmporong

Copy link
Copy Markdown

Description

Hex colors with alpha were rounded to one decimal when parsed, so values such as #0000FF01 became fully transparent and most 8-bit alpha values could not round-trip. toHex8() also truncated float alpha values instead of rounding them to the nearest byte.

This change preserves the full alpha value from 4- and 8-digit hex colors and rounds alpha when serializing to #RRGGBBAA. Regression coverage checks every 8-bit alpha value, every 4-bit shorthand alpha, low alpha, and rgba() serialization.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Refactoring (no functional changes)

Checklist

  • I have read the Contributing Guide
  • My code follows the existing code style (pnpm lint passes)
  • I have tested my changes locally (pnpm test passes)
  • I have added tests that cover my changes (if applicable)
  • The build succeeds (pnpm build)

The focused Chromium suite passes all 126 color tests. The complete browser suite was not run locally.

Related issues

None.

This branch has not been deployed

No deployments
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.

1 participant