From 9a863676e05f5ddc4dc000818c4bda964a0bce9b Mon Sep 17 00:00:00 2001 From: Robert Rosman Date: Mon, 3 Jun 2024 08:50:09 +0200 Subject: [PATCH] fix: scope the svgStyle to prevent style bleeding --- src/components/VpImage.vue | 18 +++- src/composables/tools/useMove/useMove.ts | 46 +++++----- .../tools/useTextarea/useTextarea.ts | 87 ++++++++++--------- src/types.ts | 6 +- src/utils/randomId.test.ts | 11 ++- src/utils/randomId.ts | 9 +- 6 files changed, 103 insertions(+), 74 deletions(-) diff --git a/src/components/VpImage.vue b/src/components/VpImage.vue index 9528a14..f3d2870 100644 --- a/src/components/VpImage.vue +++ b/src/components/VpImage.vue @@ -2,6 +2,7 @@ import { computed, ref, toRefs, unref } from 'vue' import type { Shape, Tool, ToolType } from '../types' import { useSimplifiedHistory } from '@/composables/useSimplifiedHistory'; +import { randomId } from '@/utils/randomId'; const props = defineProps<{ tools: Tool[] @@ -12,6 +13,7 @@ const props = defineProps<{ }>() const svg = ref() +const svgId = ref(randomId()) defineExpose({ svg @@ -21,7 +23,19 @@ function getTool(toolType: ToolType) { return props.tools.find((tool) => tool.type === toolType) } -const style = computed(() => props.tools.map((tool) => tool.svgStyle ? unref(tool.svgStyle) : '').join('\n')) +const style = computed(() => { + return props.tools.map((tool) => { + if (!tool.svgStyle) { + return '' + } + else if (typeof tool.svgStyle === 'function') { + return tool.svgStyle({ svgId: svgId.value }) + } + else { + return unref(tool.svgStyle) + } + }).join('\n') +}) const { simplifiedHistory } = useSimplifiedHistory({ ...toRefs(props), includeActiveShape: false }) @@ -38,7 +52,7 @@ const highLayers = computed(() =>