Feature/adaptive crossfade window #50

Merged
ilia merged 7 commits from feature/adaptive-crossfade-window into main 2026-06-06 06:05:09 +00:00
2 changed files with 5 additions and 12 deletions
Showing only changes of commit 744cdc9d19 - Show all commits
@@ -10,6 +10,7 @@
import { import {
type ComparisonLine, type ComparisonLine,
computeLineRenderModel, computeLineRenderModel,
windowSizeForLine,
} from '$entities/Font'; } from '$entities/Font';
import { getTypographySettingsStore } from '$features/AdjustTypography'; import { getTypographySettingsStore } from '$features/AdjustTypography';
import { getComparisonStore } from '../../model'; import { getComparisonStore } from '../../model';
@@ -24,16 +25,14 @@ interface Props {
* Count of chars the slider has passed, from `findSplitIndex`. * Count of chars the slider has passed, from `findSplitIndex`.
*/ */
split: number; split: number;
/**
* Number of chars in the crossfade window around the split.
*/
windowSize: number;
} }
let { line, split, windowSize }: Props = $props(); let { line, split }: Props = $props();
const comparisonStore = getComparisonStore(); const comparisonStore = getComparisonStore();
const windowSize = $derived(windowSizeForLine(line.chars.length));
const model = $derived(computeLineRenderModel(line, split, windowSize)); const model = $derived(computeLineRenderModel(line, split, windowSize));
const typography = getTypographySettingsStore(); const typography = getTypographySettingsStore();
@@ -107,12 +107,6 @@ const layout = new DualFontLayout();
let layoutResult = $state<ComparisonResult>({ lines: [], totalHeight: 0 }); let layoutResult = $state<ComparisonResult>({ lines: [], totalHeight: 0 });
/**
* N-window size for the per-char crossfade zone around the slider split.
* Tuned so chars complete their 100ms opacity crossfade before exiting the window.
*/
const WINDOW_SIZE = 5;
// Track container width changes (window resize, sidebar toggle, etc.) // Track container width changes (window resize, sidebar toggle, etc.)
$effect(() => { $effect(() => {
if (!container) { if (!container) {
@@ -344,7 +338,7 @@ $effect(() => {
> >
{#each layoutResult.lines as line, lineIdx (lineIdx)} {#each layoutResult.lines as line, lineIdx (lineIdx)}
{@const split = findSplitIndex(line, sliderPos, containerWidth)} {@const split = findSplitIndex(line, sliderPos, containerWidth)}
<Line {line} {split} windowSize={WINDOW_SIZE} /> <Line {line} {split} />
{/each} {/each}
</div> </div>