Skip to content

Commit 0dca3e3

Browse files
Algorithm5838github-actions[bot]
authored andcommitted
perf: replace JS transition with CSS animation in CodespanToken
1 parent b66adfb commit 0dca3e3

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import { copyToClipboard, unescapeHtml } from '$lib/utils';
33
import { toast } from 'svelte-sonner';
4-
import { fade } from 'svelte/transition';
54
65
import { getContext } from 'svelte';
76
@@ -13,21 +12,24 @@
1312

1413
<!-- svelte-ignore a11y-click-events-have-key-events -->
1514
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
16-
{#if done}
17-
<code
18-
class="codespan cursor-pointer"
19-
on:click={() => {
20-
copyToClipboard(unescapeHtml(token.text));
21-
toast.success($i18n.t('Copied to clipboard'));
22-
}}>{unescapeHtml(token.text)}</code
23-
>
24-
{:else}
25-
<code
26-
transition:fade={{ duration: 100 }}
27-
class="codespan cursor-pointer"
28-
on:click={() => {
29-
copyToClipboard(unescapeHtml(token.text));
30-
toast.success($i18n.t('Copied to clipboard'));
31-
}}>{unescapeHtml(token.text)}</code
32-
>
33-
{/if}
15+
<code
16+
class="codespan cursor-pointer {!done ? 'fade-in-token' : ''}"
17+
on:click={() => {
18+
copyToClipboard(unescapeHtml(token.text));
19+
toast.success($i18n.t('Copied to clipboard'));
20+
}}>{unescapeHtml(token.text)}</code
21+
>
22+
23+
<style>
24+
@keyframes fade-in-token {
25+
from {
26+
opacity: 0;
27+
}
28+
to {
29+
opacity: 1;
30+
}
31+
}
32+
.fade-in-token {
33+
animation: fade-in-token 100ms ease-out;
34+
}
35+
</style>

0 commit comments

Comments
 (0)