Files
Jyotisha/frontend/src/lib/character-remaining.ts
T
Jesse_Chen e8fa1ce4ea
Independent Staging Quality Gate / validate (push) Successful in 9m19s
Independent Staging Quality Gate / publish (push) Successful in 9m54s
fix(frontend): raise dark contrast, expand hit areas, and surface input limits
Dark muted surfaces missed WCAG AA; action and tertiary tokens plus a 32-pair contract close that. Hit targets, remaining-count, and Enter-to-send follow the interaction audit without changing visual sizes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 11:19:50 +08:00

18 lines
810 B
TypeScript

/** Show the remaining-count hint when this many characters (or fewer) are left. */
export function remainingThreshold(maxLength: number): number {
return Math.max(8, Math.min(50, Math.round(maxLength / 10)));
}
export function characterRemainingVisible(length: number, maxLength: number): boolean {
return maxLength - length <= remainingThreshold(maxLength);
}
export function characterRemainingLabel(remaining: number, maxLength: number): string {
return remaining <= 0 ? `已达 ${maxLength} 字上限` : `还剩 ${remaining}`;
}
/** Stable live text: one announcement on entering the threshold, one at the cap. */
export function characterRemainingAnnouncement(remaining: number, maxLength: number): string {
return remaining <= 0 ? `已达 ${maxLength} 字上限` : "接近字数上限";
}