From 7b3a86475d7b28ecc682d4bbfaaf1c6e3eedf043 Mon Sep 17 00:00:00 2001 From: cvaz1306 Date: Fri, 27 Dec 2024 17:06:15 -0800 Subject: [PATCH] Add reset panzoom button to SVGPanZoom and cleanup --- src/lib/components/common/SVGPanZoom.svelte | 24 +++++++++++++++++++-- src/lib/components/icons/Reset.svelte | 8 +++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/icons/Reset.svelte diff --git a/src/lib/components/common/SVGPanZoom.svelte b/src/lib/components/common/SVGPanZoom.svelte index e576ffb06..dc7f81afd 100644 --- a/src/lib/components/common/SVGPanZoom.svelte +++ b/src/lib/components/common/SVGPanZoom.svelte @@ -2,7 +2,7 @@ import { onMount, getContext } from 'svelte'; const i18n = getContext('i18n'); - import panzoom from 'panzoom'; + import panzoom, { type PanZoom } from 'panzoom'; import DOMPurify from 'dompurify'; import DocumentDuplicate from '../icons/DocumentDuplicate.svelte'; @@ -10,12 +10,13 @@ import { toast } from 'svelte-sonner'; import Tooltip from './Tooltip.svelte'; import Clipboard from '../icons/Clipboard.svelte'; + import Reset from '../icons/Reset.svelte'; export let className = ''; export let svg = ''; export let content = ''; - let instance; + let instance: PanZoom; let sceneParentElement: HTMLElement; let sceneElement: HTMLElement; @@ -28,6 +29,12 @@ zoomSpeed: 0.065 }); } + function resetPanZoomViewport() { + console.log('Reset View') + instance.moveTo(0, 0); + instance.zoomAbs(0,0,1); + console.log(instance.getTransform()); + }
@@ -49,5 +56,18 @@
+
+ + + +
{/if} diff --git a/src/lib/components/icons/Reset.svelte b/src/lib/components/icons/Reset.svelte new file mode 100644 index 000000000..c8a16ee34 --- /dev/null +++ b/src/lib/components/icons/Reset.svelte @@ -0,0 +1,8 @@ + + + + \ No newline at end of file