Skip to content

Commit

Permalink
npm run build
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 13, 2020
1 parent 3a9a329 commit 5927a66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
5 changes: 5 additions & 0 deletions lib/misc/colors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare function getColors(selectors: {
[P: string]: string;
}): {
[P: string]: string;
};
46 changes: 25 additions & 21 deletions lib/misc/colors.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
'use babel'
"use babel"

export function getColors(selectors) {
let grammar = atom.grammars.grammarForScopeName("source.julia")

let styled = {}
let color = {}
let div = document.createElement('div')
div.classList.add('editor', 'editor-colors', 'julia-syntax-color-selector')

for (let style in selectors) {
let child = document.createElement('span')
child.innerText = 'foo'
// const grammar = atom.grammars.grammarForScopeName("source.julia") // TODO ?
const div = document.createElement("div")
div.classList.add("editor", "editor-colors", "julia-syntax-color-selector")
const styled = {}
const color = {}
for (const style in selectors) {
const child = document.createElement("span")
child.innerText = "foo"
child.classList.add(...selectors[style])
div.appendChild(child)
styled[style] = child
}

document.body.appendChild(div)
// wait till rendered?
for (let style in selectors) {
for (const style in selectors) {
// TODO do we need try catch
try {
color[style] = rgb2hex(window.getComputedStyle(styled[style])['color'])
color[style] = rgb2hex(window.getComputedStyle(styled[style]).color)
} catch (e) {
console.error(e)
}
}
color['background'] = rgb2hex(window.getComputedStyle(div)['backgroundColor'])
color.background = rgb2hex(window.getComputedStyle(div).backgroundColor)
document.body.removeChild(div)

return color
}

function rgb2hex(rgb) {
if (rgb.search("rgb") == -1) {
if (rgb.search("rgb") === -1) {
return rgb
} else {
rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/)
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
const rgb_match = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/)
if (rgb_match) {
return hex(rgb_match[1]) + hex(rgb_match[2]) + hex(rgb_match[3])
} else {
// TODO should we check for this error?
console.error(rgb.concat(" isn't a rgb string!"))
return "#000000" // black
}
return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
}

function hex(x) {
return ("0" + parseInt(x, 10).toString(16)).slice(-2)
}

0 comments on commit 5927a66

Please sign in to comment.