e8fa1ce4ea
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>
18 lines
810 B
TypeScript
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} 字上限` : "接近字数上限";
|
|
}
|