mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-09 11:29:12 +00:00
Guard colour operators against achromatic hues and unparseable target colours
This commit is contained in:
@@ -25,6 +25,10 @@ exports["colour-get-oklch"] = makeSerialColourOperator(function (colour, operato
|
||||
var prop = ((operator.suffixes || [])[0] || ["l"])[0];
|
||||
if(["l","c","h"].indexOf(prop) !== -1) {
|
||||
colour = colour.oklch[prop];
|
||||
// Hue is null for achromatic colours
|
||||
if(colour === null || colour === undefined || Number.isNaN(colour)) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return colour.toString();
|
||||
});
|
||||
@@ -63,6 +67,9 @@ exports["colour-best-contrast"] = makeParallelColourOperator(function (colours,
|
||||
return [];
|
||||
}
|
||||
var targetColour = colours[colours.length - 1];
|
||||
if(!targetColour) {
|
||||
return [];
|
||||
}
|
||||
for(var t=0; t<colours.length; t++) {
|
||||
var colour = colours[t];
|
||||
if(colour) {
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
title: Operators/Colour/ColourBestContrastInvalidTarget
|
||||
description: colour-best-contrast with an unparseable target colour returns nothing instead of crashing
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\parsermode inline
|
||||
<$text text={{{ [subfilter{Filter}] +[count[]] }}}/>
|
||||
+
|
||||
title: Filter
|
||||
|
||||
[[red]] [[blue]] [[notacolour]] +[colour-best-contrast[]]
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
0
|
||||
@@ -0,0 +1,20 @@
|
||||
title: Operators/Colour/ColourGetOklchAchromatic
|
||||
description: colour-get-oklch hue of achromatic colours returns empty instead of crashing
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\parsermode inline
|
||||
<$text text={{{ [subfilter{Filter}] }}}/>
|
||||
+
|
||||
title: Filter
|
||||
|
||||
=[[white]colour-get-oklch:h[]]
|
||||
=[[#808080]colour-get-oklch:h[]]
|
||||
=[[red]colour-get-oklch:h[]fixed[3]]
|
||||
+[join[,]]
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
,,29.234
|
||||
Reference in New Issue
Block a user