Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color could be HEX format instead #52

Open
panaC opened this issue May 14, 2020 · 5 comments
Open

color could be HEX format instead #52

panaC opened this issue May 14, 2020 · 5 comments

Comments

@panaC
Copy link
Member

panaC commented May 14, 2020

color could be HEX format instead
avoids an another structure and weak impacts on the user dev.

it's an idea :)

export interface IColor {

@danielweck
Copy link
Member

@danielweck
Copy link
Member

RGB triplets + A alpha transparency is used internally:

highlightBounding.style.setProperty("background-color", `rgba(${highlight.color.red}, ${highlight.color.green}, ${highlight.color.blue}, ${opacity})`, "important");

...yeah, we could add a rgb field to the IColor interface, which would take precedence over the triplet decimal values (if they exist). This rgb field would accept the old-school #AABBCC syntax, as a convenience to navigator API users .... just need to decide how to combine the variable opacity in the highlight code :)

@JayPanoz
Copy link

Not sure it can help inform the discussion that much, but it’s probably worth mentioning as mere “anecdata” that there’s been a major lobbying + move to hsl(a) in CSS colours lately, as it’s Math-friendly and simplifies a lot of use cases – it became all the rage as a side-effect of CSS variables pretty much overnight and now hsl is the new gospel.

I won’t list everything but a few recent examples I can find in 30 seconds:

There are significant drawbacks though:

@danielweck
Copy link
Member

HSL is sooo yesterday though! ;o)

LCH is the future :)
http://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/

@danielweck
Copy link
Member

Note: a conversion function is available to transform a #FFF / #FFFFFF string to its equivalent RGB triplet, with optional alpha opacity:

export function convertColorHexadecimalToRGBA(cssHex: string, alpha?: number): string | undefined {
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(cssHex)) {
const hex = cssHex.substring(1);
const hex_ = hex.length === 3 ?
`0x${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}` :
`0x${hex[0]}${hex[1]}${hex[2]}${hex[3]}${hex[4]}${hex[5]}`;
const hexVal = parseInt(hex_, 16);
// tslint:disable-next-line: no-bitwise
return `rgb${alpha ? "a" : ""}(${(hexVal >> 16) & 255}, ${(hexVal >> 8) & 255}, ${hexVal & 255}${alpha ? `, ${alpha}` : ""})`;
}
return undefined;
}

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

No branches or pull requests

3 participants