open-webui/src/lib/components/common/SVGPanZoom.svelte

54 lines
1.4 KiB
Svelte
Raw Normal View History

2024-10-06 19:51:29 +00:00
<script lang="ts">
2024-10-11 07:10:00 +00:00
import { onMount, getContext } from 'svelte';
const i18n = getContext('i18n');
2024-10-06 19:51:29 +00:00
import panzoom from 'panzoom';
import DOMPurify from 'dompurify';
2024-10-11 07:10:00 +00:00
import DocumentDuplicate from '../icons/DocumentDuplicate.svelte';
import { copyToClipboard } from '$lib/utils';
import { toast } from 'svelte-sonner';
import Tooltip from './Tooltip.svelte';
import Clipboard from '../icons/Clipboard.svelte';
2024-10-06 19:51:29 +00:00
export let className = '';
export let svg = '';
2024-10-11 07:10:00 +00:00
export let content = '';
2024-10-06 19:51:29 +00:00
let instance;
let sceneParentElement: HTMLElement;
let sceneElement: HTMLElement;
$: if (sceneElement) {
instance = panzoom(sceneElement, {
bounds: true,
boundsPadding: 0.1,
zoomSpeed: 0.065
});
}
</script>
2024-10-11 07:10:00 +00:00
<div bind:this={sceneParentElement} class="relative {className}">
2024-10-06 19:51:29 +00:00
<div bind:this={sceneElement} class="flex h-full max-h-full justify-center items-center">
{@html svg}
</div>
2024-10-11 07:10:00 +00:00
{#if content}
<div class=" absolute top-1 right-1">
<Tooltip content={$i18n.t('Copy to clipboard')}>
<button
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"
on:click={() => {
copyToClipboard(content);
toast.success($i18n.t('Copied to clipboard'));
}}
>
<Clipboard className=" size-4" strokeWidth="1.5" />
</button>
</Tooltip>
</div>
{/if}
2024-10-06 19:51:29 +00:00
</div>