mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
improve library header title size calculation
This commit is contained in:
@@ -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+4E00–U+9FFF
|
||||||
|
if (codePoint >= 0x4e00 && codePoint <= 0x9fff) return true;
|
||||||
|
|
||||||
|
// Hiragana: U+3040–U+309F
|
||||||
|
if (codePoint >= 0x3040 && codePoint <= 0x309f) return true;
|
||||||
|
|
||||||
|
// Katakana: U+30A0–U+30FF
|
||||||
|
if (codePoint >= 0x30a0 && codePoint <= 0x30ff) return true;
|
||||||
|
|
||||||
|
// CJK Extension A: U+3400–U+4DBF
|
||||||
|
if (codePoint >= 0x3400 && codePoint <= 0x4dbf) return true;
|
||||||
|
|
||||||
|
// CJK Compatibility Ideographs: U+F900–U+FAFF
|
||||||
|
if (codePoint >= 0xf900 && codePoint <= 0xfaff) return true;
|
||||||
|
|
||||||
|
// Fullwidth forms (some Asian characters): U+FF00–U+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)`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user