-
Notifications
You must be signed in to change notification settings - Fork 44
/
ColorProcessor.js
54 lines (38 loc) · 1.3 KB
/
ColorProcessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Brackets Themes Copyright (c) 2014 Miguel Castillo.
*
* Licensed under MIT
*/
define(function (require, exports, module) {
"use strict";
var tinycolor = require("lib/tinycolor");
function getColor(content, expression) {
var color = expression.exec(content);
if (color) {
color = color[1];
}
return color;
}
function getBackgroundColor(content) {
//http://regex101.com/r/yI2wL5/5
return getColor(content, /\.CodeMirror\s*\{[\s\S]*?(?:background(?:-color)?\s*:\s*([^;\s}]+))/gmi);
}
function getFontColor(content) {
//http://regex101.com/r/gQ4yO9/1
return getColor(content, /\.CodeMirror\s*\{[\s\S]*?(?:color\s*:\s*([^;\s}]+))/gmi);
}
function getMatchingBracketColor(content) {
//http://regex101.com/r/gQ4yO9/2
return getColor(content, /\.CodeMirror-matchingbracket\s*\{[\s\S]*?(?:color\s*:+\s*([^;\s}]+))/gmi);
}
function isDark(content) {
var backgroundColor = getBackgroundColor(content);
return backgroundColor ? tinycolor(backgroundColor).isDark() : false;
}
return {
getBackgroundColor: getBackgroundColor,
getFontColor: getFontColor,
getMatchingBracketColor: getMatchingBracketColor,
isDark: isDark
};
});