From 754f87eaca9d42553dcc61a1fac49a503e020f87 Mon Sep 17 00:00:00 2001 From: sHa Date: Thu, 29 May 2025 23:27:18 +0300 Subject: [PATCH] feat: update SVG handling to support active color sets and improve URL copying --- src/components/Actions.svelte | 36 ++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/components/Actions.svelte b/src/components/Actions.svelte index 674553a..e21b673 100644 --- a/src/components/Actions.svelte +++ b/src/components/Actions.svelte @@ -18,7 +18,7 @@ // Notification state let showNotification = false; let notificationText = ''; - let notificationType = 'success'; // 'success' or 'error' + let notificationType = 'success'; function showCopyNotification(text, type = 'success') { notificationText = text; @@ -27,7 +27,7 @@ // Force the notification to be visible in the preview setTimeout(() => { - showNotification = true; // Re-trigger the notification in case it was missed + showNotification = true; }, 50); } @@ -99,9 +99,19 @@ return filename.split('/').pop().replace(/\.[^.]+$/, ''); } + function getSvgPath(logo) { + // If a color set is active, use the generated variant + if (logo._activeSet) { + return `/logos_gen/${getBaseName(logo.path)}__${logo._activeSet}.svg`; + } + // Otherwise use the original SVG + return logo.path; + } + function getPngUrl(logo) { // Adjust this endpoint to match your backend - return `/api/svg2png?file=${encodeURIComponent(logo.path)}`; + const svgPath = getSvgPath(logo); + return `/api/svg2png?file=${encodeURIComponent(svgPath)}`; } function getPngLink(logo) { @@ -154,10 +164,11 @@ async function handleCopyUrlClick(e) { e.stopPropagation(); - const url = window.location.origin + '/' + logo.path; + const svgPath = getSvgPath(logo); + const url = window.location.origin + '/' + svgPath; navigator.clipboard.writeText(url) - .then(() => showCopyNotification('URL copied!', 'success')) - .catch(() => showCopyNotification('Failed to copy URL', 'error')); + .then(() => showCopyNotification('SVG URL copied!', 'success')) + .catch(() => showCopyNotification('Failed to copy SVG URL', 'error')); closeCopyMenu(); } @@ -231,8 +242,9 @@ showCopyNotification('Failed to copy SVG source', 'error'); } } else { - // Use the standard method for grid/list view - const success = await copySvgSource(logo.path); + // Use the correct SVG path (original or generated variant) + const svgPath = getSvgPath(logo); + const success = await copySvgSource(svgPath); if (success) { showCopyNotification('SVG source copied!', 'success'); } else { @@ -276,7 +288,13 @@ - {#if logo.format === 'SVG'}