Skip to content

Let a caller say which end of a hex string holds alpha - #337

Merged
smelfungus merged 1 commit into
masterfrom
feat/hex-alpha-ordering
Sep 15, 2026
Merged

smelfungus merged 1 commit into
masterfrom
feat/hex-alpha-ordering

Conversation

@smelfungus

Copy link
Copy Markdown
Member

Hex here follows android.graphics.Color: alpha first, so a string pasted out of a stylesheet is read backwards. #FF000080 is a half-transparent red to CSS and an opaque navy here, and #3380CCFF, an opaque blue, arrives as a pale one at a fifth opacity. Neither fails β€” they parse, and come back a different colour. The library publishes a wasmJs target, so that is a string a caller can reasonably be holding.

Eight hex digits cannot say which convention wrote them, so there is nothing to detect and the ambiguity is named instead. HexAlpha.First stays the default and no existing string changes meaning; Last reads and writes the CSS order. Four digits parse now rather than being rejected, in whichever order was asked for, which is what #RGBA needed.

HexAlpha.None replaces the includeAlpha flag rather than sitting beside it. A boolean and a position together describe four states where there are three, and the fourth β€” no alpha, at the end β€” says nothing. Parsing with None accepts only the three and six digit forms: a caller who asks for a colour without alpha and is handed one with it should get null rather than a quiet reinterpretation.

Callers passing includeAlpha will not compile until they name a HexAlpha. That is the intended trade: the old spelling has no meaning under the new one, and a compile error is the right way to find out. The four functions' JVM signatures move with it, so anything linked against the old binaries needs recompiling too.

Hex here follows android.graphics.Color: alpha first, so a string pasted out of a stylesheet is read backwards. #FF000080 is a half-transparent red to CSS and an opaque navy here, and #3380CCFF, an opaque blue, arrives as a pale one at a fifth opacity. Neither fails β€” they parse, and come back a different colour. The library publishes a wasmJs target, so that is a string a caller can reasonably be holding.

Eight hex digits cannot say which convention wrote them, so there is nothing to detect and the ambiguity is named instead. HexAlpha.First stays the default and no existing string changes meaning; Last reads and writes the CSS order. Four digits parse now rather than being rejected, in whichever order was asked for, which is what #RGBA needed.

HexAlpha.None replaces the includeAlpha flag rather than sitting beside it. A boolean and a position together describe four states where there are three, and the fourth β€” no alpha, at the end β€” says nothing. Parsing with None accepts only the three and six digit forms: a caller who asks for a colour without alpha and is handed one with it should get null rather than a quiet reinterpretation.

Callers passing includeAlpha will not compile until they name a HexAlpha. That is the intended trade: the old spelling has no meaning under the new one, and a compile error is the right way to find out. The four functions' JVM signatures move with it, so anything linked against the old binaries needs recompiling too.
@smelfungus smelfungus self-assigned this Sep 15, 2026
@smelfungus
smelfungus merged commit c85bd99 into master Sep 15, 2026
2 checks passed
@smelfungus
smelfungus deleted the feat/hex-alpha-ordering branch September 15, 2026 22:45
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