|
1 | 1 | ;(function() { |
2 | 2 | const vscode = acquireVsCodeApi() |
3 | 3 |
|
| 4 | + let target = 'container' |
| 5 | + |
4 | 6 | vscode.postMessage({ |
5 | | - type: 'getAndUpdateBgColor' |
| 7 | + type: 'getAndUpdateCacheAndSettings' |
6 | 8 | }) |
7 | 9 |
|
8 | 10 | const snippetNode = document.getElementById('snippet') |
|
57 | 59 | } |
58 | 60 | function getSnippetBgColor(html) { |
59 | 61 | const match = html.match(/background-color: (#[a-fA-F0-9]+)/) |
60 | | - return match[1] ? match[1] : undefined; |
| 62 | + return match ? match[1] : undefined; |
61 | 63 | } |
62 | 64 |
|
63 | 65 | function updateEnvironment(snippetBgColor) { |
|
124 | 126 | }) |
125 | 127 |
|
126 | 128 | obturateur.addEventListener('click', () => { |
| 129 | + if (target === 'container') { |
| 130 | + shootAll() |
| 131 | + } else { |
| 132 | + shootSnippet() |
| 133 | + } |
| 134 | + }) |
| 135 | + |
| 136 | + function shootAll() { |
127 | 137 | const width = snippetContainerNode.offsetWidth * 2 |
128 | 138 | const height = snippetContainerNode.offsetHeight * 2 |
129 | 139 | const config = { |
130 | 140 | width, |
131 | 141 | height, |
132 | 142 | style: { |
133 | 143 | transform: 'scale(2)', |
134 | | - 'transform-origin': 'left top' |
| 144 | + 'transform-origin': 'center' |
135 | 145 | } |
136 | 146 | } |
137 | 147 |
|
| 148 | + // Hide resizer before capture |
| 149 | + snippetNode.style.resize = 'none' |
| 150 | + snippetContainerNode.style.resize = 'none' |
| 151 | + |
138 | 152 | domtoimage.toBlob(snippetContainerNode, config).then(blob => { |
| 153 | + snippetNode.style.resize = '' |
| 154 | + snippetContainerNode.style.resize = '' |
139 | 155 | serializeBlob(blob, serializedBlob => { |
140 | 156 | shoot(serializedBlob) |
141 | 157 | }) |
142 | 158 | }) |
143 | | - }) |
| 159 | + } |
| 160 | + |
| 161 | + function shootSnippet() { |
| 162 | + const width = snippetNode.offsetWidth * 2 |
| 163 | + const height = snippetNode.offsetHeight * 2 |
| 164 | + const config = { |
| 165 | + width, |
| 166 | + height, |
| 167 | + style: { |
| 168 | + transform: 'scale(2)', |
| 169 | + 'transform-origin': 'center', |
| 170 | + padding: 0, |
| 171 | + background: 'none' |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + // Hide resizer before capture |
| 176 | + snippetNode.style.resize = 'none' |
| 177 | + snippetContainerNode.style.resize = 'none' |
| 178 | + |
| 179 | + domtoimage.toBlob(snippetContainerNode, config).then(blob => { |
| 180 | + snippetNode.style.resize = '' |
| 181 | + snippetContainerNode.style.resize = '' |
| 182 | + serializeBlob(blob, serializedBlob => { |
| 183 | + shoot(serializedBlob) |
| 184 | + }) |
| 185 | + }) |
| 186 | + } |
144 | 187 |
|
145 | 188 | let isInAnimation = false |
146 | 189 |
|
|
190 | 233 | updateEnvironment(e.data.bgColor) |
191 | 234 | } else if (e.data.type === 'restoreBgColor') { |
192 | 235 | updateEnvironment(e.data.bgColor) |
| 236 | + } else if (e.data.type === 'updateSettings') { |
| 237 | + snippet.style.boxShadow = e.data.shadow |
| 238 | + target = e.data.target |
| 239 | + snippetContainerNode.style.background = e.data.background |
193 | 240 | } |
194 | 241 | } |
195 | 242 | }) |
|
0 commit comments