4
4
let target = 'container'
5
5
let transparentBackground = false
6
6
let backgroundColor = '#f2f2f2'
7
- let fontFamily
8
7
9
8
vscode . postMessage ( {
10
9
type : 'getAndUpdateCacheAndSettings'
15
14
const obturateur = document . getElementById ( 'save' )
16
15
17
16
snippetContainerNode . style . opacity = '1'
18
- const oldState = vscode . getState ( )
17
+ const oldState = vscode . getState ( ) ;
19
18
if ( oldState && oldState . innerHTML ) {
20
19
snippetNode . innerHTML = oldState . innerHTML
21
20
}
22
21
23
- const getInitialHtml = ff => {
22
+ const getInitialHtml = fontFamily => {
24
23
const cameraWithFlashEmoji = String . fromCodePoint ( 128248 )
25
- const monoFontStack = `${ ff } ,SFMono-Regular,Consolas,DejaVu Sans Mono,Ubuntu Mono,Liberation Mono,Menlo,Courier,monospace`
26
- fontFamily = monoFontStack
24
+ const monoFontStack = `${ fontFamily } ,SFMono-Regular,Consolas,DejaVu Sans Mono,Ubuntu Mono,Liberation Mono,Menlo,Courier,monospace`
27
25
return `<meta charset="utf-8"><div style="color: #d8dee9;background-color: #2e3440; font-family: ${ monoFontStack } ;font-weight: normal;font-size: 12px;line-height: 18px;white-space: pre;"><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">0. Run command \`Polacode ${ cameraWithFlashEmoji } \`</span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">1. Copy some code</span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">2. Paste into Polacode view</span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">3. Click the button ${ cameraWithFlashEmoji } </span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div></div></div>`
28
26
}
29
27
63
61
}
64
62
function getSnippetBgColor ( html ) {
65
63
const match = html . match ( / b a c k g r o u n d - c o l o r : ( # [ a - f A - F 0 - 9 ] + ) / )
66
- return match ? match [ 1 ] : undefined
64
+ return match ? match [ 1 ] : undefined ;
67
65
}
68
66
69
67
function updateEnvironment ( snippetBgColor ) {
104
102
}
105
103
106
104
document . addEventListener ( 'paste' , e => {
107
- const div = document . createElement ( 'div' )
108
- div . innerHTML = e . clipboardData . getData ( 'text/html' )
109
- div . querySelector ( 'div' ) . style . fontFamily = fontFamily
110
- const innerHTML = div . innerHTML
105
+ const innerHTML = e . clipboardData . getData ( 'text/html' )
111
106
112
107
const code = e . clipboardData . getData ( 'text/plain' )
113
108
const minIndent = getMinIndent ( code )
134
129
135
130
obturateur . addEventListener ( 'click' , ( ) => {
136
131
if ( target === 'container' ) {
137
- shootAll ( )
132
+ shootAll ( )
138
133
} else {
139
134
shootSnippet ( )
140
135
}
233
228
} else {
234
229
snippetContainerNode . style . background = 'none'
235
230
}
231
+
236
232
} else if ( e . data . type === 'update' ) {
237
233
document . execCommand ( 'paste' )
238
234
} else if ( e . data . type === 'restore' ) {
257
253
} ) ( )
258
254
259
255
function getRgba ( hex , transparentBackground ) {
260
- const bigint = parseInt ( hex . slice ( 1 ) , 16 )
261
- const r = ( bigint >> 16 ) & 255
262
- const g = ( bigint >> 8 ) & 255
263
- const b = bigint & 255
256
+ const bigint = parseInt ( hex . slice ( 1 ) , 16 ) ;
257
+ const r = ( bigint >> 16 ) & 255 ;
258
+ const g = ( bigint >> 8 ) & 255 ;
259
+ const b = bigint & 255 ;
264
260
const a = transparentBackground ? 0 : 1
265
261
return `rgba(${ r } , ${ g } , ${ b } , ${ a } )`
266
- }
262
+ }
0 commit comments