From ad6e1da292700742dcf8acf8448d0ae8c5c54966 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Mon, 16 Feb 2026 15:30:00 +0300 Subject: [PATCH] fix(ComparisonSlider): change the way width is calculated to avoid transform:scale issues --- .../createCharacterComparison.svelte.ts | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/shared/lib/helpers/createCharacterComparison/createCharacterComparison.svelte.ts b/src/shared/lib/helpers/createCharacterComparison/createCharacterComparison.svelte.ts index 832d3a2..d3d426d 100644 --- a/src/shared/lib/helpers/createCharacterComparison/createCharacterComparison.svelte.ts +++ b/src/shared/lib/helpers/createCharacterComparison/createCharacterComparison.svelte.ts @@ -2,7 +2,13 @@ * Interface representing a line of text with its measured width. */ export interface LineData { + /** + * Line's text + */ text: string; + /** + * It's width + */ width: number; } @@ -80,16 +86,23 @@ export function createCharacterComparison< container: HTMLElement | undefined, measureCanvas: HTMLCanvasElement | undefined, ) { - if (!container || !measureCanvas || !fontA() || !fontB()) return; + if (!container || !measureCanvas || !fontA() || !fontB()) { + return; + } - const rect = container.getBoundingClientRect(); - containerWidth = rect.width; + // Use offsetWidth instead of getBoundingClientRect() to avoid CSS transform scaling issues + // getBoundingClientRect() returns transformed dimensions, which causes incorrect line breaking + // when PerspectivePlan applies scale() transforms (e.g., scale(0.5) in settings mode) + const width = container.offsetWidth; + containerWidth = width; // Padding considerations - matches the container padding const padding = window.innerWidth < 640 ? 48 : 96; - const availableWidth = rect.width - padding; + const availableWidth = width - padding; const ctx = measureCanvas.getContext('2d'); - if (!ctx) return; + if (!ctx) { + return; + } const controlledFontSize = size(); const fontSize = getFontSize();