mirror of
https://github.com/pheralb/svgl.git
synced 2025-02-06 15:17:58 +08:00
🚀 Fixed copy & download wordmark svg version.
This commit is contained in:
parent
e5cf8e48c0
commit
86a1b5fa8f
@ -17,7 +17,7 @@
|
|||||||
PackageIcon,
|
PackageIcon,
|
||||||
PaintBucket,
|
PaintBucket,
|
||||||
ChevronsRight,
|
ChevronsRight,
|
||||||
CaseSensitive
|
Baseline
|
||||||
} from 'lucide-svelte';
|
} from 'lucide-svelte';
|
||||||
|
|
||||||
// Main Card:
|
// Main Card:
|
||||||
@ -64,6 +64,19 @@
|
|||||||
zip.file(`${svgInfo.title}.svg`, lightSvg);
|
zip.file(`${svgInfo.title}.svg`, lightSvg);
|
||||||
zip.file(`${svgInfo.title}.dark.svg`, darkSvg);
|
zip.file(`${svgInfo.title}.dark.svg`, darkSvg);
|
||||||
|
|
||||||
|
if (svgInfo.wordmark) {
|
||||||
|
if (typeof svgInfo.wordmark === 'string') {
|
||||||
|
downloadSvg(svgInfo.wordmark);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lightWordmarkSvg = await getSvgContent(svgInfo.wordmark.light, false);
|
||||||
|
const darkWordmarkSvg = await getSvgContent(svgInfo.wordmark.dark, false);
|
||||||
|
|
||||||
|
zip.file(`${svgInfo.title}.wordmark.svg`, lightWordmarkSvg);
|
||||||
|
zip.file(`${svgInfo.title}.wordmark.dark.svg`, darkWordmarkSvg);
|
||||||
|
}
|
||||||
|
|
||||||
zip.generateAsync({ type: 'blob' }).then((content) => {
|
zip.generateAsync({ type: 'blob' }).then((content) => {
|
||||||
download(content, `${svgInfo.title}.zip`, 'application/zip');
|
download(content, `${svgInfo.title}.zip`, 'application/zip');
|
||||||
});
|
});
|
||||||
@ -82,14 +95,28 @@
|
|||||||
if (isInFigma) {
|
if (isInFigma) {
|
||||||
const content = (await getSvgContent(url, false)) as string;
|
const content = (await getSvgContent(url, false)) as string;
|
||||||
figmaCopyToClipboard(content);
|
figmaCopyToClipboard(content);
|
||||||
} else {
|
}
|
||||||
try {
|
|
||||||
const clipboardItem = new ClipboardItem(data);
|
try {
|
||||||
await navigator.clipboard.write([clipboardItem]);
|
const clipboardItem = new ClipboardItem(data);
|
||||||
} catch (error) {
|
await navigator.clipboard.write([clipboardItem]);
|
||||||
const content = (await getSvgContent(url, false)) as string;
|
} catch (error) {
|
||||||
await navigator.clipboard.writeText(content);
|
const content = (await getSvgContent(url, false)) as string;
|
||||||
}
|
await navigator.clipboard.writeText(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInFigma) {
|
||||||
|
toast.success('Ready to paste in Figma!', {
|
||||||
|
description: `${svgInfo.title} - ${svgInfo.category}`
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wordmarkSvg) {
|
||||||
|
toast.success('Copied wordmark SVG to clipboard!', {
|
||||||
|
description: `${svgInfo.title} - ${svgInfo.category}`
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success('Copied to clipboard!', {
|
toast.success('Copied to clipboard!', {
|
||||||
@ -113,14 +140,18 @@
|
|||||||
{#if wordmarkSvg == true}
|
{#if wordmarkSvg == true}
|
||||||
<img
|
<img
|
||||||
class="hidden dark:block mb-4 mt-2 h-10"
|
class="hidden dark:block mb-4 mt-2 h-10"
|
||||||
src={typeof svgInfo.wordmark !== 'string' ? svgInfo.wordmark?.dark || '' : svgInfo.wordmark || ''}
|
src={typeof svgInfo.wordmark !== 'string'
|
||||||
|
? svgInfo.wordmark?.dark || ''
|
||||||
|
: svgInfo.wordmark || ''}
|
||||||
alt={svgInfo.title}
|
alt={svgInfo.title}
|
||||||
title={svgInfo.title}
|
title={svgInfo.title}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
class="block dark:hidden mb-4 mt-2 h-10"
|
class="block dark:hidden mb-4 mt-2 h-10"
|
||||||
src={typeof svgInfo.wordmark !== 'string' ? svgInfo.wordmark?.light || '' : svgInfo.wordmark || ''}
|
src={typeof svgInfo.wordmark !== 'string'
|
||||||
|
? svgInfo.wordmark?.light || ''
|
||||||
|
: svgInfo.wordmark || ''}
|
||||||
alt={svgInfo.title}
|
alt={svgInfo.title}
|
||||||
title={svgInfo.title}
|
title={svgInfo.title}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
@ -184,35 +215,65 @@
|
|||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<button
|
{#if wordmarkSvg}
|
||||||
title="Copy to clipboard"
|
<button
|
||||||
on:click={() => {
|
title="Copy wordmark SVG to clipboard"
|
||||||
const svgHasTheme = typeof svgInfo.route !== 'string';
|
on:click={() => {
|
||||||
const svgWordmarkHasTheme = typeof svgInfo.wordmark !== 'string';
|
const svgHasTheme = typeof svgInfo.wordmark !== 'string';
|
||||||
|
|
||||||
|
if (!svgHasTheme) {
|
||||||
|
copyToClipboard(
|
||||||
|
typeof svgInfo.wordmark === 'string'
|
||||||
|
? svgInfo.wordmark
|
||||||
|
: "Something went wrong. Couldn't copy the SVG."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dark = document.documentElement.classList.contains('dark');
|
||||||
|
|
||||||
if (!svgHasTheme) {
|
|
||||||
copyToClipboard(
|
copyToClipboard(
|
||||||
typeof svgInfo.route === 'string'
|
typeof svgInfo.wordmark !== 'string'
|
||||||
? svgInfo.route
|
? dark
|
||||||
: "Something went wrong. Couldn't copy the SVG."
|
? svgInfo.wordmark?.dark
|
||||||
|
: svgInfo.wordmark?.light
|
||||||
|
: svgInfo.wordmark
|
||||||
);
|
);
|
||||||
return;
|
}}
|
||||||
}
|
class="flex items-center space-x-2 rounded-md p-2 duration-100 hover:bg-neutral-200 dark:hover:bg-neutral-700/40"
|
||||||
|
>
|
||||||
|
<CopyIcon size={iconSize} strokeWidth={iconStroke} />
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
title="Copy to clipboard"
|
||||||
|
on:click={() => {
|
||||||
|
const svgHasTheme = typeof svgInfo.route !== 'string';
|
||||||
|
|
||||||
const dark = document.documentElement.classList.contains('dark');
|
if (!svgHasTheme) {
|
||||||
|
copyToClipboard(
|
||||||
|
typeof svgInfo.route === 'string'
|
||||||
|
? svgInfo.route
|
||||||
|
: "Something went wrong. Couldn't copy the SVG."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
copyToClipboard(
|
const dark = document.documentElement.classList.contains('dark');
|
||||||
typeof svgInfo.route !== 'string'
|
|
||||||
? dark
|
copyToClipboard(
|
||||||
? svgInfo.route.dark
|
typeof svgInfo.route !== 'string'
|
||||||
: svgInfo.route.light
|
? dark
|
||||||
: svgInfo.route
|
? svgInfo.route.dark
|
||||||
);
|
: svgInfo.route.light
|
||||||
}}
|
: svgInfo.route
|
||||||
class="flex items-center space-x-2 rounded-md p-2 duration-100 hover:bg-neutral-200 dark:hover:bg-neutral-700/40"
|
);
|
||||||
>
|
}}
|
||||||
<CopyIcon size={iconSize} strokeWidth={iconStroke} />
|
class="flex items-center space-x-2 rounded-md p-2 duration-100 hover:bg-neutral-200 dark:hover:bg-neutral-700/40"
|
||||||
</button>
|
>
|
||||||
|
<CopyIcon size={iconSize} strokeWidth={iconStroke} />
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if typeof svgInfo.route !== 'string'}
|
{#if typeof svgInfo.route !== 'string'}
|
||||||
<DropdownMenu.Root>
|
<DropdownMenu.Root>
|
||||||
@ -235,7 +296,7 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PackageIcon class="mr-2" size={18} />
|
<PackageIcon class="mr-2" size={18} />
|
||||||
<p>Light & Dark variants</p>
|
<p>Light & dark variants</p>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
title="Download only {document.documentElement.classList.contains('dark')
|
title="Download only {document.documentElement.classList.contains('dark')
|
||||||
@ -292,13 +353,13 @@
|
|||||||
</a>
|
</a>
|
||||||
{#if svgInfo.wordmark !== undefined}
|
{#if svgInfo.wordmark !== undefined}
|
||||||
<button
|
<button
|
||||||
title="Wordmark SVG"
|
title="Show wordmark SVG"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
wordmarkSvg = !wordmarkSvg;
|
wordmarkSvg = !wordmarkSvg;
|
||||||
}}
|
}}
|
||||||
class="flex items-center space-x-2 rounded-md p-2 duration-100 hover:bg-neutral-200 dark:hover:bg-neutral-700/40"
|
class="flex items-center space-x-2 rounded-md p-2 duration-100 hover:bg-neutral-200 dark:hover:bg-neutral-700/40"
|
||||||
>
|
>
|
||||||
<CaseSensitive size={iconSize} strokeWidth={iconStroke} />
|
<Baseline size={iconSize} strokeWidth={iconStroke} />
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user