Fix editing colours that are not in 6 digit hex format

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color#value
This commit is contained in:
Jeremy Ruston
2025-01-08 09:59:04 +00:00
parent 5d1cf251b9
commit 6b39d6aa43
2 changed files with 22 additions and 1 deletions
+16
View File
@@ -41,4 +41,20 @@ exports.parseCSSColorObject = function(colourString) {
return c;
};
/*
Convert a Color.js colour to a CSS RGB string suitable for use with the <input type="color"> element
*/
exports.convertColorToCSSRGBString = function(colourString) {
var c = exports.parseCSSColorObject(colourString);
if(c) {
var hex = c.toString({format: "hex"});
if(hex.length === 4) {
hex = "#" + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
}
return hex;
} else {
return null;
}
};
})();