improve library header title size calculation

This commit is contained in:
jeffvli
2025-12-30 16:13:04 -08:00
parent b99ea61115
commit 4e213ea79e
3 changed files with 49 additions and 3 deletions
@@ -113,8 +113,6 @@ const AlbumMetadataTags = ({ album }: AlbumMetadataTagsProps) => {
value: label, value: label,
})) || []; })) || [];
console.log('album', album);
const items: Array<{ id: string; value: ReactNode | string | undefined }> = []; const items: Array<{ id: string; value: ReactNode | string | undefined }> = [];
items.push( items.push(
@@ -99,6 +99,7 @@
display: flex; display: flex;
margin: 0; margin: 0;
font-size: clamp(1.75rem, 3dvw, 2.75rem); font-size: clamp(1.75rem, 3dvw, 2.75rem);
font-weight: 800;
line-height: 1.2; line-height: 1.2;
} }
@@ -155,8 +155,43 @@ export const LibraryHeader = forwardRef(
}, },
); );
const isAsianCharacter = (char: string): boolean => {
const codePoint = char.codePointAt(0);
if (!codePoint) return false;
// CJK Unified Ideographs: U+4E00U+9FFF
if (codePoint >= 0x4e00 && codePoint <= 0x9fff) return true;
// Hiragana: U+3040U+309F
if (codePoint >= 0x3040 && codePoint <= 0x309f) return true;
// Katakana: U+30A0U+30FF
if (codePoint >= 0x30a0 && codePoint <= 0x30ff) return true;
// CJK Extension A: U+3400U+4DBF
if (codePoint >= 0x3400 && codePoint <= 0x4dbf) return true;
// CJK Compatibility Ideographs: U+F900U+FAFF
if (codePoint >= 0xf900 && codePoint <= 0xfaff) return true;
// Fullwidth forms (some Asian characters): U+FF00U+FFEF
// Only count fullwidth letters/numbers as Asian
if (codePoint >= 0xff01 && codePoint <= 0xff5e) return true;
return false;
};
const calculateWeightedLength = (str: string): number => {
let length = 0;
for (const char of str) {
length += isAsianCharacter(char) ? 2.5 : 1;
}
return length;
};
const calculateTitleSize = (title: string) => { const calculateTitleSize = (title: string) => {
const titleLength = title.length; const titleLength = calculateWeightedLength(title);
let baseSize = '3dvw'; let baseSize = '3dvw';
if (titleLength > 20) { if (titleLength > 20) {
@@ -179,6 +214,18 @@ const calculateTitleSize = (title: string) => {
baseSize = '1.75dvw'; baseSize = '1.75dvw';
} }
if (titleLength > 70) {
baseSize = '1.5dvw';
}
if (titleLength > 80) {
baseSize = '1.4dvw';
}
if (titleLength > 90) {
baseSize = '1.3dvw';
}
return `clamp(1.75rem, ${baseSize}, 2.75rem)`; return `clamp(1.75rem, ${baseSize}, 2.75rem)`;
}; };