feat(displayedFontsStore): fix store to work with fontA and fontB to compare
This commit is contained in:
@@ -15,18 +15,9 @@ export class DisplayedFontsStore {
|
|||||||
return selectedFontsStore.all;
|
return selectedFontsStore.all;
|
||||||
});
|
});
|
||||||
|
|
||||||
#fontPairs = $derived.by(() => {
|
#fontA = $state<UnifiedFont | undefined>(undefined);
|
||||||
const fonts = this.#displayedFonts;
|
|
||||||
const pairs = fonts.flatMap((v1, i) =>
|
|
||||||
fonts.slice(i + 1).map<[UnifiedFont, UnifiedFont]>(v2 => [v1, v2])
|
|
||||||
);
|
|
||||||
if (pairs.length && this.isSelectedPairEmpty()) {
|
|
||||||
this.selectedPair = pairs[0];
|
|
||||||
}
|
|
||||||
return pairs;
|
|
||||||
});
|
|
||||||
|
|
||||||
#selectedPair = $state<Partial<[UnifiedFont, UnifiedFont]>>([]);
|
#fontB = $state<UnifiedFont | undefined>(undefined);
|
||||||
|
|
||||||
#hasAnySelectedFonts = $derived(this.#displayedFonts.length > 0);
|
#hasAnySelectedFonts = $derived(this.#displayedFonts.length > 0);
|
||||||
|
|
||||||
@@ -34,18 +25,20 @@ export class DisplayedFontsStore {
|
|||||||
return this.#displayedFonts;
|
return this.#displayedFonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
get pairs() {
|
get fontA() {
|
||||||
return this.#fontPairs;
|
return this.#fontA ?? this.#displayedFonts[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
get selectedPair() {
|
set fontA(font: UnifiedFont | undefined) {
|
||||||
return this.#selectedPair;
|
this.#fontA = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
set selectedPair(pair: Partial<[UnifiedFont, UnifiedFont]>) {
|
get fontB() {
|
||||||
const [first, second] = this.#selectedPair;
|
return this.#fontB ?? this.#displayedFonts[1];
|
||||||
const [newFist, newSecond] = pair;
|
}
|
||||||
this.#selectedPair = [newFist ?? first, newSecond ?? second];
|
|
||||||
|
set fontB(font: UnifiedFont | undefined) {
|
||||||
|
this.#fontB = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
get text() {
|
get text() {
|
||||||
@@ -60,9 +53,8 @@ export class DisplayedFontsStore {
|
|||||||
return this.#hasAnySelectedFonts;
|
return this.#hasAnySelectedFonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
isSelectedPairEmpty(): boolean {
|
getById(id: string): UnifiedFont | undefined {
|
||||||
const [font1, font2] = this.#selectedPair;
|
return selectedFontsStore.getById(id);
|
||||||
return !font1 || !font2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user