Skip to content

Commit fb9c0d6

Browse files
committed
Replace 12 year old CSS colour parsing library
The replacement library from https://colorjs.io/ is much, much larger but I think we can develop a custom build that uses treeshaking to whittle the code down to the bits that we need. @linonetwo does that sound feasible? I intend the explore further improvements but I wanted to start by establishing a library that can do modern P3 and OKLCH colour calculations.
1 parent a0caa0f commit fb9c0d6

File tree

5 files changed

+7553
-203
lines changed

5 files changed

+7553
-203
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*\
2+
title: $:/core/modules/utils/color-utils.js
3+
type: application/javascript
4+
module-type: utils
5+
6+
Color.js related utilities
7+
8+
\*/
9+
(function(){
10+
11+
/*jslint node: true, browser: true */
12+
/*global $tw: false */
13+
"use strict";
14+
15+
exports.parseCSSColor = function(colourString) {
16+
var Color = require("$:/core/modules/utils/dom/color.js").Color,
17+
c = null;
18+
try {
19+
c = new Color(colourString);
20+
} catch(e) {
21+
// Do nothing on an error
22+
}
23+
if(c) {
24+
var rgb = c.srgb;
25+
return [rgb[0],rgb[1],rgb[2],c.alpha];
26+
} else {
27+
return null;
28+
}
29+
};
30+
31+
})();

0 commit comments

Comments
 (0)