|
1 | 1 | <script lang="ts"> |
| 2 | + import fileSaver from 'file-saver'; |
| 3 | + const { saveAs } = fileSaver; |
| 4 | +
|
| 5 | + import { toast } from 'svelte-sonner'; |
| 6 | +
|
| 7 | + import panzoom, { type PanZoom } from 'panzoom'; |
| 8 | + import DOMPurify from 'dompurify'; |
| 9 | +
|
2 | 10 | import { onMount, getContext } from 'svelte'; |
3 | 11 | const i18n = getContext('i18n'); |
4 | 12 |
|
5 | | - import panzoom, { type PanZoom } from 'panzoom'; |
| 13 | + import { copyToClipboard } from '$lib/utils'; |
6 | 14 |
|
7 | | - import DOMPurify from 'dompurify'; |
8 | 15 | import DocumentDuplicate from '../icons/DocumentDuplicate.svelte'; |
9 | | - import { copyToClipboard } from '$lib/utils'; |
10 | | - import { toast } from 'svelte-sonner'; |
11 | 16 | import Tooltip from './Tooltip.svelte'; |
12 | 17 | import Clipboard from '../icons/Clipboard.svelte'; |
13 | 18 | import Reset from '../icons/Reset.svelte'; |
| 19 | + import ArrowDownTray from '../icons/ArrowDownTray.svelte'; |
14 | 20 |
|
15 | 21 | export let className = ''; |
16 | 22 | export let svg = ''; |
|
29 | 35 | zoomSpeed: 0.065 |
30 | 36 | }); |
31 | 37 | } |
32 | | - function resetPanZoomViewport() { |
33 | | - console.log('Reset View'); |
| 38 | + const resetPanZoomViewport = () => { |
34 | 39 | instance.moveTo(0, 0); |
35 | 40 | instance.zoomAbs(0, 0, 1); |
36 | 41 | console.log(instance.getTransform()); |
37 | | - } |
| 42 | + }; |
| 43 | +
|
| 44 | + const downloadAsSVG = () => { |
| 45 | + const svgBlob = new Blob([svg], { type: 'image/svg+xml' }); |
| 46 | + saveAs(svgBlob, `diagram.svg`); |
| 47 | + }; |
38 | 48 | </script> |
39 | 49 |
|
40 | 50 | <div bind:this={sceneParentElement} class="relative {className}"> |
|
44 | 54 |
|
45 | 55 | {#if content} |
46 | 56 | <div class=" absolute top-1 right-1"> |
47 | | - <Tooltip content={$i18n.t('Copy to clipboard')}> |
48 | | - <button |
49 | | - class="p-1.5 rounded-lg border border-gray-100 dark:border-none dark:bg-gray-850 hover:bg-gray-50 dark:hover:bg-gray-800 transition" |
50 | | - on:click={() => { |
51 | | - copyToClipboard(content); |
52 | | - toast.success($i18n.t('Copied to clipboard')); |
53 | | - }} |
54 | | - > |
55 | | - <Clipboard className=" size-4" strokeWidth="1.5" /> |
56 | | - </button> |
57 | | - </Tooltip> |
58 | | - </div> |
59 | | - <div class=" absolute top-1 right-10"> |
60 | | - <Tooltip content={$i18n.t('Reset view')}> |
61 | | - <button |
62 | | - class="p-1.5 rounded-lg border border-gray-100 dark:border-none dark:bg-gray-850 hover:bg-gray-50 dark:hover:bg-gray-800 transition" |
63 | | - on:click={() => { |
64 | | - resetPanZoomViewport(); |
65 | | - toast.success($i18n.t('Reset view')); |
66 | | - }} |
67 | | - > |
68 | | - <Reset className=" size-4" /> |
69 | | - </button> |
70 | | - </Tooltip> |
| 57 | + <div class="flex gap-1"> |
| 58 | + <Tooltip content={$i18n.t('Download as SVG')}> |
| 59 | + <button |
| 60 | + class="p-1.5 rounded-lg border border-gray-100 dark:border-none dark:bg-gray-850 hover:bg-gray-50 dark:hover:bg-gray-800 transition" |
| 61 | + on:click={() => { |
| 62 | + downloadAsSVG(); |
| 63 | + }} |
| 64 | + > |
| 65 | + <ArrowDownTray className=" size-4" /> |
| 66 | + </button> |
| 67 | + </Tooltip> |
| 68 | + |
| 69 | + <Tooltip content={$i18n.t('Reset view')}> |
| 70 | + <button |
| 71 | + class="p-1.5 rounded-lg border border-gray-100 dark:border-none dark:bg-gray-850 hover:bg-gray-50 dark:hover:bg-gray-800 transition" |
| 72 | + on:click={() => { |
| 73 | + resetPanZoomViewport(); |
| 74 | + }} |
| 75 | + > |
| 76 | + <Reset className=" size-4" /> |
| 77 | + </button> |
| 78 | + </Tooltip> |
| 79 | + |
| 80 | + <Tooltip content={$i18n.t('Copy to clipboard')}> |
| 81 | + <button |
| 82 | + class="p-1.5 rounded-lg border border-gray-100 dark:border-none dark:bg-gray-850 hover:bg-gray-50 dark:hover:bg-gray-800 transition" |
| 83 | + on:click={() => { |
| 84 | + copyToClipboard(content); |
| 85 | + toast.success($i18n.t('Copied to clipboard')); |
| 86 | + }} |
| 87 | + > |
| 88 | + <Clipboard className=" size-4" strokeWidth="1.5" /> |
| 89 | + </button> |
| 90 | + </Tooltip> |
| 91 | + </div> |
71 | 92 | </div> |
72 | 93 | {/if} |
73 | 94 | </div> |
0 commit comments