From a8fb07137d4aed7969feef38f75619decf5d9461 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 3 Nov 2024 16:13:09 +0000 Subject: [PATCH] Add expertimental colour-oklch operator --- core/modules/filters/colour-ops.js | 13 +++++++++++-- .../data/operators/colour/ColourOklchL.tid | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 editions/test/tiddlers/tests/data/operators/colour/ColourOklchL.tid diff --git a/core/modules/filters/colour-ops.js b/core/modules/filters/colour-ops.js index 3ce9d1dca..1044f92a7 100644 --- a/core/modules/filters/colour-ops.js +++ b/core/modules/filters/colour-ops.js @@ -14,14 +14,23 @@ Filter operators for colour operations var Color = require("$:/core/modules/utils/dom/color.js").Color; -exports["colour-lighten"] = makeColourOperator(function (c, operator, operands) { +exports["colour-lighten"] = makeColourOperator(function (c, operator, options) { return c.lighten($tw.utils.parseNumber(operator.operand)); }); -exports["colour-darken"] = makeColourOperator(function (c, operator, operands) { +exports["colour-darken"] = makeColourOperator(function (c, operator, options) { return c.darken($tw.utils.parseNumber(operator.operand)); }); +exports["colour-oklch"] = makeColourOperator(function (c, operator, options) { + var prop = ((operator.suffixes || [])[0] || ["l"])[0]; +console.log("Prop",prop,$tw.utils.parseNumber(operator.operand)) + if(["l","c","h"].indexOf(prop) !== -1) { + c.oklch[prop] = $tw.utils.parseNumber(operator.operand); + } + return c; +}); + function makeColourOperator(fn) { return function (source, operator, options) { var results = []; diff --git a/editions/test/tiddlers/tests/data/operators/colour/ColourOklchL.tid b/editions/test/tiddlers/tests/data/operators/colour/ColourOklchL.tid new file mode 100644 index 000000000..22d6767f8 --- /dev/null +++ b/editions/test/tiddlers/tests/data/operators/colour/ColourOklchL.tid @@ -0,0 +1,18 @@ +title: Operators/Colour/ColourOklchL +description: Oklch colour function +type: text/vnd.tiddlywiki-multiple +tags: [[$:/tags/wiki-test-spec]] + +title: Output + +\parsermode inline +\import [subfilter{$:/core/config/GlobalImportFilter}] +<$text text={{{ [subfilter{Filter}] }}}/> ++ +title: Filter + +=[function[colour],[primary]colour-oklch[0.5]] =[function[colour],[primary]colour-oklch:l[0.5]] +[join[,]] ++ +title: ExpectedResult + +#3d5bb8,#3d5bb8 \ No newline at end of file