Skip to content

Commit 5927a66

Browse files
committed
npm run build
1 parent 3a9a329 commit 5927a66

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

lib/misc/colors.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export declare function getColors(selectors: {
2+
[P: string]: string;
3+
}): {
4+
[P: string]: string;
5+
};

lib/misc/colors.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
1-
'use babel'
1+
"use babel"
22

33
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'
4+
// const grammar = atom.grammars.grammarForScopeName("source.julia") // TODO ?
5+
const div = document.createElement("div")
6+
div.classList.add("editor", "editor-colors", "julia-syntax-color-selector")
7+
const styled = {}
8+
const color = {}
9+
for (const style in selectors) {
10+
const child = document.createElement("span")
11+
child.innerText = "foo"
1412
child.classList.add(...selectors[style])
1513
div.appendChild(child)
1614
styled[style] = child
1715
}
18-
1916
document.body.appendChild(div)
2017
// wait till rendered?
21-
for (let style in selectors) {
18+
for (const style in selectors) {
19+
// TODO do we need try catch
2220
try {
23-
color[style] = rgb2hex(window.getComputedStyle(styled[style])['color'])
21+
color[style] = rgb2hex(window.getComputedStyle(styled[style]).color)
2422
} catch (e) {
2523
console.error(e)
2624
}
2725
}
28-
color['background'] = rgb2hex(window.getComputedStyle(div)['backgroundColor'])
26+
color.background = rgb2hex(window.getComputedStyle(div).backgroundColor)
2927
document.body.removeChild(div)
30-
3128
return color
3229
}
3330

3431
function rgb2hex(rgb) {
35-
if (rgb.search("rgb") == -1) {
32+
if (rgb.search("rgb") === -1) {
3633
return rgb
3734
} 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);
35+
const rgb_match = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/)
36+
if (rgb_match) {
37+
return hex(rgb_match[1]) + hex(rgb_match[2]) + hex(rgb_match[3])
38+
} else {
39+
// TODO should we check for this error?
40+
console.error(rgb.concat(" isn't a rgb string!"))
41+
return "#000000" // black
4142
}
42-
return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
4343
}
4444
}
45+
46+
function hex(x) {
47+
return ("0" + parseInt(x, 10).toString(16)).slice(-2)
48+
}

0 commit comments

Comments
 (0)