mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-13 06:24:54 +10:00
fix: auto-select 2 font weights when picking a new font-family
This commit is contained in:
@@ -53,6 +53,11 @@
|
||||
text-underline-offset: 0.15rem;
|
||||
}
|
||||
|
||||
hr {
|
||||
margin: 1rem 0;
|
||||
border-color: var(--page-text-color);
|
||||
}
|
||||
|
||||
strong {
|
||||
font-weight: var(--page-body-font-weight-bold);
|
||||
}
|
||||
|
||||
@@ -37,11 +37,28 @@ function buildWebFontMap() {
|
||||
|
||||
const webFontMap: Map<string, WebFont> = buildWebFontMap();
|
||||
|
||||
export function getNextWeight(fontFamily: string): Weight | null {
|
||||
export function getNextWeights(fontFamily: string): Weight[] | null {
|
||||
const fontData = webFontMap.get(fontFamily);
|
||||
if (!fontData || !Array.isArray(fontData.weights) || fontData.weights.length === 0) return null;
|
||||
if (fontData.weights.includes("400")) return "400";
|
||||
return fontData.weights[0] as Weight;
|
||||
|
||||
const uniqueWeights = Array.from(new Set(fontData.weights)) as Weight[];
|
||||
|
||||
// Try to pick 400 and 600 if available
|
||||
const weights: Weight[] = [];
|
||||
|
||||
if (uniqueWeights.includes("400")) weights.push("400");
|
||||
if (uniqueWeights.includes("600")) weights.push("600");
|
||||
|
||||
// If we didn't find both, fill in with first/last, ensuring uniqueness
|
||||
while (weights.length < 2 && uniqueWeights.length > 0) {
|
||||
// candidateIndex: 0 (first), 1 (last)
|
||||
const lastIndex = uniqueWeights.length - 1;
|
||||
const candidate = weights.length === 0 ? uniqueWeights[0] : uniqueWeights[lastIndex];
|
||||
if (!weights.includes(candidate)) weights.push(candidate);
|
||||
else break;
|
||||
}
|
||||
|
||||
return weights.length > 0 ? weights : null;
|
||||
}
|
||||
|
||||
type FontFamilyComboboxProps = Omit<ComboboxProps, "options">;
|
||||
|
||||
@@ -122,6 +122,7 @@ export const printerService = {
|
||||
const page = await browser.newPage();
|
||||
|
||||
// Wait for the page to fully load (network idle + custom loaded attribute)
|
||||
await page.emulateMediaType("print");
|
||||
await page.setViewport(pageDimensionsAsPixels[format]);
|
||||
await page.goto(url, { waitUntil: "networkidle0" });
|
||||
await page.waitForFunction(() => document.body.getAttribute("data-wf-loaded") === "true", { timeout: 5_000 });
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Trans } from "@lingui/react/macro";
|
||||
import { useForm } from "react-hook-form";
|
||||
import type z from "zod";
|
||||
import { useResumeStore } from "@/components/resume/store/resume";
|
||||
import { FontFamilyCombobox, FontWeightCombobox, getNextWeight } from "@/components/typography/combobox";
|
||||
import { FontFamilyCombobox, FontWeightCombobox, getNextWeights } from "@/components/typography/combobox";
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
||||
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@/components/ui/input-group";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
@@ -68,9 +68,9 @@ function TypographySectionForm() {
|
||||
onValueChange={(value) => {
|
||||
if (value === null) return;
|
||||
field.onChange(value);
|
||||
const nextWeight = getNextWeight(value);
|
||||
if (nextWeight !== null) {
|
||||
form.setValue("body.fontWeights", [nextWeight], { shouldDirty: true });
|
||||
const nextWeights = getNextWeights(value);
|
||||
if (nextWeights !== null) {
|
||||
form.setValue("body.fontWeights", nextWeights, { shouldDirty: true });
|
||||
}
|
||||
form.handleSubmit(onSubmit)();
|
||||
}}
|
||||
@@ -189,9 +189,9 @@ function TypographySectionForm() {
|
||||
onValueChange={(value) => {
|
||||
if (value === null) return;
|
||||
field.onChange(value);
|
||||
const nextWeight = getNextWeight(value);
|
||||
if (nextWeight !== null) {
|
||||
form.setValue("heading.fontWeights", [nextWeight], { shouldDirty: true });
|
||||
const nextWeights = getNextWeights(value);
|
||||
if (nextWeights !== null) {
|
||||
form.setValue("heading.fontWeights", nextWeights, { shouldDirty: true });
|
||||
}
|
||||
form.handleSubmit(onSubmit)();
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user