Match native catalogue previews and fit vertical title line boxes

This commit is contained in:
2026-10-28 16:12:31 +08:00
parent 4848ecc528
commit aa1509df8a
7 changed files with 34 additions and 12 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ export function slotPosition(layout:Layout,slot:Slot):CSSProperties {
export function textSize(layout:Layout,slot:Slot,text:string):number {
const [, ,w,h]=slot.box,lines=text.split('\n');
const length=(s:string)=>Array.from(s).reduce((n,c)=>n+(/[\u3400-\u9fff]/.test(c)?1:/[A-Z]/.test(c)?.8:.6),0);
if(slot.direction==='vertical')return Math.min(w*.9,h/Math.max(1,Array.from(text.replaceAll('\n','')).length)*.95);
if(slot.direction==='vertical')return Math.min(w*.9,h/Math.max(1,Array.from(text.replaceAll('\n','')).length)*.88);
if(slot.direction==='rotated')return Math.min(w*.85,h/Math.max(1,length(text)));
if(slot.direction==='curved')return Math.min(2.2,w/Math.max(1,length(text)));
return Math.min(h/(lines.length*1.15),w/Math.max(1,...lines.map(length)))*.92;