9494 </div >
9595 </div >
9696 </PerfectScrollbar >
97- <div
98- ref =" previewRef"
99- class =" preview"
100- />
10197 </div >
10298</template >
10399
104100<script setup lang="ts">
105101import { useAppStore } from ' @/store/app'
106102import hljs from ' highlight.js'
107- import html2canvas from ' html2canvas'
108103import interact from ' interactjs'
109104import { computed , onMounted , ref , watch } from ' vue'
110105import { useHljsTheme } from ' @/composable'
111106import { store , track , i18n } from ' @/electron'
112107import { useSnippetStore } from ' @/store/snippets'
113108import { useMagicKeys } from ' @vueuse/core'
109+ import domToImage from ' dom-to-image'
114110
115111const GUTTER_RIGHT_OFFSET = 10
116112const GUTTER_WIDTH = 8
@@ -131,7 +127,6 @@ const { escape } = useMagicKeys()
131127
132128const frameRef = ref <HTMLElement >()
133129const snippetRef = ref <HTMLElement >()
134- const previewRef = ref <HTMLElement >()
135130const gutterRef = ref <HTMLElement >()
136131
137132const gutterWidth = ref (GUTTER_WIDTH + ' px' )
@@ -180,17 +175,13 @@ const init = () => {
180175}
181176
182177const onSaveScreenshot = async () => {
183- const canvas = await html2canvas (snippetRef .value ! , {
184- backgroundColor: null
185- })
186- previewRef .value ?.appendChild (canvas )
178+ const data = await domToImage .toPng (snippetRef .value ! )
187179
188180 const a = document .createElement (' a' )
189- const img = canvas .toDataURL (' image/png' )
190-
191- a .href = img
181+ a .href = data
192182 a .download = ` ${props .name }.png `
193183 a .click ()
184+
194185 track (' snippets/create-screenshot' )
195186}
196187
0 commit comments