TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
8.06k stars 1.19k forks source link

[BUG] contrastcolour cannot accept hsl color #5560

Open kookma opened 3 years ago

kookma commented 3 years ago

Describe the bug passing color to contrastcolour using hsl or hsla function does not work

TiddlyWiki Configuration (please complete the following information):

Desktop (please complete the following information):

Jermolene commented 3 years ago

Hi @kookma can you give an example that doesn't work?

This works for me:

<<contrastcolour target:"hsl(0, 100%, 50%)" colourA:red colourB:red>>

The underlying JS call works too:

> $tw.utils.parseCSSColor("hsl(0, 100%, 50%)")
 [255, 0, 0, 1]

The colour parser we use is quite old (https://github.com/deanm/css-color-parser-js), so I imagine you're using some new fangled colour format that's been introduced recently?

kookma commented 3 years ago

Hi @Jermolene My mistake! Sorry I passed a wikified hsl function as below

\define hslcolor() hsl($(hue)$, $(saturation)$%, $(lightness)$%) \define newcolor() <<contrastcolour target:$(colour)$ .... . . <$wikify name=color text=<> > .. ..

kookma commented 3 years ago

Hi @Jermolene - it seems contrastcolour does not appreciate the alpha value. Check this script in

<<contrastcolour  target:"hsla(0, 100%, 50%, 0.2)" colourA:black colourB:white>>

This should return black, but it returns white! Changing the alpha value do not change the result.

See : https://www.w3schools.com/html/html_colors_hsl.asp This works fine!

Jermolene commented 3 years ago

Hi @kookma that's what I meant about newer features: I believe that alpha channels in HSL colours in that format are relatively new, and therefore not understood by the library we're using.

I'd like to move to a newer colour parsing library, and have an even more exacting requirement: that it should be able to cope with new "wide colors" specified in the P9 colour space. This gives access to the colours offered by HDR displays that are not part of the usual RGB space.

kookma commented 3 years ago

Thank you Jeremy! Should I close this issue?

pmario commented 2 years ago

There is a new library: https://vis4.net/chromajs/ which IMO would be worth to check out