File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
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 ( / ^ r g b a ? \( ( \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
+ }
You can’t perform that action at this time.
0 commit comments