UNPKG

859 BTypeScriptView Raw
1import * as CSS from 'csstype';
2declare type FontFace = CSS.Properties;
3declare type Font = Pick<FontFace, 'fontFamily' | 'fontWeight' | 'fontStyle' | 'fontVariant'> & {
4 fontSize?: number;
5};
6/**
7 * 计算文本在画布中的宽度
8 */
9export declare const measureTextWidth: {
10 (...args: any[]): any;
11 cache: Map<any, any>;
12};
13/**
14 * 获取文本的 ... 文本。
15 * 算法(减少每次 measureText 的长度,measureText 的性能跟字符串时间相关):
16 * 1. 先通过 STEP 逐步计算,找到最后一个小于 maxWidth 的字符串
17 * 2. 然后对最后这个字符串二分计算
18 * @param text 需要计算的文本, 由于历史原因 除了支持string,还支持空值,number和数组等
19 * @param maxWidth
20 * @param font
21 */
22export declare const getEllipsisText: (text: any, maxWidth: number, font?: Font) => any;
23export {};