diff --git a/public/logos/mikrotik.svg b/public/logos/mikrotik.svg index e0baa1a..c156dcc 100644 --- a/public/logos/mikrotik.svg +++ b/public/logos/mikrotik.svg @@ -1,4 +1,4 @@ - {#if viewMode === 'grid'} openPreview(e.detail)} /> {:else} openPreview(e.detail)} /> {/if} diff --git a/src/components/Preview.svelte b/src/components/Preview.svelte index a1fdb6e..7bf6750 100644 --- a/src/components/Preview.svelte +++ b/src/components/Preview.svelte @@ -5,11 +5,18 @@ export let show = false; export let logo = null; + export let theme; + export let logos = []; + export let openLogoByAnchor = () => {}; const dispatch = createEventDispatcher(); function close() { dispatch('close'); + // Remove preview anchor from URL + if (window.location.hash.startsWith('#preview-')) { + history.replaceState(null, '', window.location.pathname + window.location.search); + } } function handleKeydown(event) { @@ -22,9 +29,7 @@ return logo && logo.format && logo.format.toLowerCase() === 'svg'; } - // Always use $theme directly, do not cache in a function - export let theme; -$: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme); + $: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme); // Improved debug logging for color and theme $: { @@ -35,47 +40,89 @@ $: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme); } } + // Update URL hash when opening/closing preview + $: if (show && logo) { + const anchor = '#preview-' + encodeURIComponent(logo.name.replace(/\s+/g, '-').toLowerCase()); + if (window.location.hash !== anchor) { + history.replaceState(null, '', window.location.pathname + window.location.search + anchor); + } + } + + // On mount, check for preview anchor and open if present onMount(() => { document.addEventListener('keydown', handleKeydown); + if (window.location.hash.startsWith('#preview-')) { + openLogoByAnchor(window.location.hash); + } + window.addEventListener('hashchange', onHashChange); }); onDestroy(() => { document.removeEventListener('keydown', handleKeydown); + window.removeEventListener('hashchange', onHashChange); }); + + function onHashChange() { + if (window.location.hash.startsWith('#preview-')) { + openLogoByAnchor(window.location.hash); + } else { + dispatch('close'); + } + } + + // Svelte action to remove width/height from SVGs for responsive scaling + function removeSvgSize(node) { + function cleanSvg() { + const svgs = node.querySelectorAll('svg'); + svgs.forEach(svg => { + svg.removeAttribute('width'); + svg.removeAttribute('height'); + svg.style.width = '100%'; + svg.style.height = '100%'; + }); + } + cleanSvg(); + // In case SVG is loaded async (e.g. InlineSvg), observe for changes + const observer = new MutationObserver(cleanSvg); + observer.observe(node, { childList: true, subtree: true }); + return { + destroy() { + observer.disconnect(); + } + }; + } -