feat(ComparisonSlider): migrate from displayStore to comparisonStore
This commit is contained in:
@@ -10,23 +10,21 @@
|
|||||||
- Performance optimized using offscreen canvas for measurements and transform-based animations.
|
- Performance optimized using offscreen canvas for measurements and transform-based animations.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { displayedFontsStore } from '$features/DisplayFont';
|
|
||||||
import {
|
import {
|
||||||
createCharacterComparison,
|
createCharacterComparison,
|
||||||
createTypographyControl,
|
createTypographyControl,
|
||||||
} from '$shared/lib';
|
} from '$shared/lib';
|
||||||
import type { LineData } from '$shared/lib';
|
import type { LineData } from '$shared/lib';
|
||||||
|
import { comparisonStore } from '$widgets/ComparisonSlider/model';
|
||||||
import { Spring } from 'svelte/motion';
|
import { Spring } from 'svelte/motion';
|
||||||
import CharacterSlot from './components/CharacterSlot.svelte';
|
import CharacterSlot from './components/CharacterSlot.svelte';
|
||||||
import ControlsWrapper from './components/ControlsWrapper.svelte';
|
import ControlsWrapper from './components/ControlsWrapper.svelte';
|
||||||
import Labels from './components/Labels.svelte';
|
import Labels from './components/Labels.svelte';
|
||||||
import SliderLine from './components/SliderLine.svelte';
|
import SliderLine from './components/SliderLine.svelte';
|
||||||
|
|
||||||
// Displayed text
|
|
||||||
let text = $state('The quick brown fox jumps over the lazy dog...');
|
|
||||||
// Pair of fonts to compare
|
// Pair of fonts to compare
|
||||||
const fontA = $derived(displayedFontsStore.fontA);
|
const fontA = $derived(comparisonStore.fontA);
|
||||||
const fontB = $derived(displayedFontsStore.fontB);
|
const fontB = $derived(comparisonStore.fontB);
|
||||||
|
|
||||||
let container: HTMLElement | undefined = $state();
|
let container: HTMLElement | undefined = $state();
|
||||||
let controlsWrapperElement = $state<HTMLDivElement | null>(null);
|
let controlsWrapperElement = $state<HTMLDivElement | null>(null);
|
||||||
@@ -59,7 +57,7 @@ const sizeControl = createTypographyControl({
|
|||||||
* Manages line breaking and character state based on fonts and container dimensions.
|
* Manages line breaking and character state based on fonts and container dimensions.
|
||||||
*/
|
*/
|
||||||
const charComparison = createCharacterComparison(
|
const charComparison = createCharacterComparison(
|
||||||
() => text,
|
() => comparisonStore.text,
|
||||||
() => fontA,
|
() => fontA,
|
||||||
() => fontB,
|
() => fontB,
|
||||||
() => weightControl.value,
|
() => weightControl.value,
|
||||||
@@ -85,7 +83,10 @@ function handleMove(e: PointerEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startDragging(e: PointerEvent) {
|
function startDragging(e: PointerEvent) {
|
||||||
if (e.target === controlsWrapperElement || controlsWrapperElement?.contains(e.target as Node)) {
|
if (
|
||||||
|
e.target === controlsWrapperElement
|
||||||
|
|| controlsWrapperElement?.contains(e.target as Node)
|
||||||
|
) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -109,7 +110,7 @@ $effect(() => {
|
|||||||
// Re-run line breaking when container resizes or dependencies change
|
// Re-run line breaking when container resizes or dependencies change
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
// React on text and typography settings changes
|
// React on text and typography settings changes
|
||||||
const _text = text;
|
const _text = comparisonStore.text;
|
||||||
const _weight = weightControl.value;
|
const _weight = weightControl.value;
|
||||||
const _size = sizeControl.value;
|
const _size = sizeControl.value;
|
||||||
const _height = heightControl.value;
|
const _height = heightControl.value;
|
||||||
@@ -125,9 +126,7 @@ $effect(() => {
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
if (
|
if (container && measureCanvas) {
|
||||||
container && measureCanvas
|
|
||||||
) {
|
|
||||||
charComparison.breakIntoLines(container, measureCanvas);
|
charComparison.breakIntoLines(container, measureCanvas);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -215,17 +214,17 @@ $effect(() => {
|
|||||||
<SliderLine {sliderPos} {isDragging} />
|
<SliderLine {sliderPos} {isDragging} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Labels fontA={fontA} fontB={fontB} {sliderPos} />
|
<Labels {fontA} {fontB} {sliderPos} weight={weightControl.value} />
|
||||||
<!-- Since there're slider controls inside we put them outside the main one -->
|
<!-- Since there're slider controls inside we put them outside the main one -->
|
||||||
<ControlsWrapper
|
<ControlsWrapper
|
||||||
bind:wrapper={controlsWrapperElement}
|
bind:wrapper={controlsWrapperElement}
|
||||||
{sliderPos}
|
{sliderPos}
|
||||||
{isDragging}
|
{isDragging}
|
||||||
bind:text={text}
|
bind:text={comparisonStore.text}
|
||||||
containerWidth={container?.clientWidth}
|
containerWidth={container?.clientWidth}
|
||||||
weightControl={weightControl}
|
{weightControl}
|
||||||
sizeControl={sizeControl}
|
{sizeControl}
|
||||||
heightControl={heightControl}
|
{heightControl}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user