Skip to content

Commit e09d806

Browse files
committed
copy misc/colors.js to lib_src
1 parent a7e1fd7 commit e09d806

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lib_src/misc/colors.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use babel'
2+
3+
export function getColors(selectors) {
4+
let grammar = atom.grammars.grammarForScopeName("source.julia")
5+
6+
let styled = {}
7+
let color = {}
8+
let div = document.createElement('div')
9+
div.classList.add('editor', 'editor-colors', 'julia-syntax-color-selector')
10+
11+
for (let style in selectors) {
12+
let child = document.createElement('span')
13+
child.innerText = 'foo'
14+
child.classList.add(...selectors[style])
15+
div.appendChild(child)
16+
styled[style] = child
17+
}
18+
19+
document.body.appendChild(div)
20+
// wait till rendered?
21+
for (let style in selectors) {
22+
try {
23+
color[style] = rgb2hex(window.getComputedStyle(styled[style])['color'])
24+
} catch (e) {
25+
console.error(e)
26+
}
27+
}
28+
color['background'] = rgb2hex(window.getComputedStyle(div)['backgroundColor'])
29+
document.body.removeChild(div)
30+
31+
return color
32+
}
33+
34+
function rgb2hex(rgb) {
35+
if (rgb.search("rgb") == -1) {
36+
return rgb
37+
} else {
38+
rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/)
39+
function hex(x) {
40+
return ("0" + parseInt(x).toString(16)).slice(-2);
41+
}
42+
return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
43+
}
44+
}

0 commit comments

Comments
 (0)