Add colour-lighten and colour-darken operators

This commit is contained in:
Jeremy Ruston
2024-10-24 12:01:50 +01:00
parent 96b85edfa2
commit d372729ed0
4 changed files with 98 additions and 7 deletions
+21 -7
View File
@@ -12,14 +12,13 @@ Color.js related utilities
/*global $tw: false */
"use strict";
var Color = require("$:/core/modules/utils/dom/color.js").Color;
/*
For backwards compatibility
*/
exports.parseCSSColor = function(colourString) {
var Color = require("$:/core/modules/utils/dom/color.js").Color,
c = null;
try {
c = new Color(colourString);
} catch(e) {
// Do nothing on an error
}
var c = exports.parseCSSColorObject(colourString);
if(c) {
var rgb = c.srgb;
return [rgb[0],rgb[1],rgb[2],c.alpha];
@@ -28,4 +27,19 @@ exports.parseCSSColor = function(colourString) {
}
};
/*
Preferred way to parse a Color.js colour
*/
exports.parseCSSColorObject = function(colourString) {
var Color = require("$:/core/modules/utils/dom/color.js").Color,
c = null;
try {
c = new Color(colourString);
} catch(e) {
// Return null if there is an error
}
return c;
};
})();