4
4
let target = 'container'
5
5
let transparentBackground = false
6
6
let backgroundColor = '#f2f2f2'
7
+ let fontFamily
7
8
8
9
vscode . postMessage ( {
9
10
type : 'getAndUpdateCacheAndSettings'
14
15
const obturateur = document . getElementById ( 'save' )
15
16
16
17
snippetContainerNode . style . opacity = '1'
17
- const oldState = vscode . getState ( ) ;
18
+ const oldState = vscode . getState ( )
18
19
if ( oldState && oldState . innerHTML ) {
19
20
snippetNode . innerHTML = oldState . innerHTML
20
21
}
21
22
22
- const getInitialHtml = fontFamily => {
23
+ const getInitialHtml = ff => {
23
24
const cameraWithFlashEmoji = String . fromCodePoint ( 128248 )
24
- const monoFontStack = `${ fontFamily } ,SFMono-Regular,Consolas,DejaVu Sans Mono,Ubuntu Mono,Liberation Mono,Menlo,Courier,monospace`
25
+ const monoFontStack = `${ ff } ,SFMono-Regular,Consolas,DejaVu Sans Mono,Ubuntu Mono,Liberation Mono,Menlo,Courier,monospace`
26
+ fontFamily = monoFontStack
25
27
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>`
26
28
}
27
29
61
63
}
62
64
function getSnippetBgColor ( html ) {
63
65
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 ] + ) / )
64
- return match ? match [ 1 ] : undefined ;
66
+ return match ? match [ 1 ] : undefined
65
67
}
66
68
67
69
function updateEnvironment ( snippetBgColor ) {
102
104
}
103
105
104
106
document . addEventListener ( 'paste' , e => {
105
- const innerHTML = e . clipboardData . getData ( 'text/html' )
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
106
111
107
112
const code = e . clipboardData . getData ( 'text/plain' )
108
113
const minIndent = getMinIndent ( code )
129
134
130
135
obturateur . addEventListener ( 'click' , ( ) => {
131
136
if ( target === 'container' ) {
132
- shootAll ( )
137
+ shootAll ( )
133
138
} else {
134
139
shootSnippet ( )
135
140
}
228
233
} else {
229
234
snippetContainerNode . style . background = 'none'
230
235
}
231
-
232
236
} else if ( e . data . type === 'update' ) {
233
237
document . execCommand ( 'paste' )
234
238
} else if ( e . data . type === 'restore' ) {
253
257
} ) ( )
254
258
255
259
function getRgba ( hex , transparentBackground ) {
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 ;
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
260
264
const a = transparentBackground ? 0 : 1
261
265
return `rgba(${ r } , ${ g } , ${ b } , ${ a } )`
262
- }
266
+ }
0 commit comments