diff --git a/core/modules/filters/colour-ops.js b/core/modules/filters/colour-ops.js index f03841a0f4..9a38ee36de 100644 --- a/core/modules/filters/colour-ops.js +++ b/core/modules/filters/colour-ops.js @@ -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 ++ +title: Filter + +[[red]] [[blue]] [[notacolour]] +[colour-best-contrast[]] ++ +title: ExpectedResult + +0 \ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/operators/colour/ColourGetOklchAchromatic.tid b/editions/test/tiddlers/tests/data/operators/colour/ColourGetOklchAchromatic.tid new file mode 100644 index 0000000000..e08f674f6d --- /dev/null +++ b/editions/test/tiddlers/tests/data/operators/colour/ColourGetOklchAchromatic.tid @@ -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 \ No newline at end of file