小组件换行文案更新
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { MeasureWidthImpl } from './measure/types';
|
||||
import type { ScoreTerm } from './scoring/types';
|
||||
import type { Weights } from './scoring/types';
|
||||
|
||||
export type OverflowMode = 'ELLIPSIS' | 'CLIP' | 'SYSTEM_DEFAULT';
|
||||
export type LineMode = 'AUTO' | 'FIXED';
|
||||
@@ -26,6 +27,21 @@ export type WrapTextInput = {
|
||||
fontSpec?: Partial<FontSpecInput> | null;
|
||||
/** 可选注入测量实现(APP 场景强烈建议提供;WIDGET 默认不启用) */
|
||||
measureWidthImpl?: MeasureWidthImpl;
|
||||
/**
|
||||
* 可选评分偏好(用于 UI 场景“更好看”的排版风格)。
|
||||
* - 不传:使用算法默认 v1 权重与口径(更贴近文档 10.3)
|
||||
* - 传入:仅在本次 wrapText 调用内生效,不影响全局
|
||||
*/
|
||||
scoringOverrides?: {
|
||||
/** 覆盖/微调默认权重(整数)。建议只改少数项,例如 TC 的标点断行奖励。 */
|
||||
weights?: Partial<Weights>;
|
||||
/** 覆盖理想行宽比例(0~1)。更小会更倾向“提前换行”。 */
|
||||
idealWidthRatio?: Partial<Record<TextWrapContext, number>>;
|
||||
/** 最短偏好比例(相对 idealWidth)。更小会更宽容“短行”。 */
|
||||
minPreferredRatio?: number;
|
||||
/** 末行过短惩罚阈值比例(相对 idealWidth)。更小会更宽容“短末行”。 */
|
||||
shortLastLineRatio?: number;
|
||||
};
|
||||
/**
|
||||
* 测量缓存隔离 key(可选)。
|
||||
* 口径建议:`APP|ios|<scale?>` / `WIDGET|small`。
|
||||
|
||||
@@ -3,6 +3,7 @@ import { normalizeWhitespace, tokenizeEN } from './core/index';
|
||||
import { segmentGraphemes } from './grapheme/index';
|
||||
import { generateBreakpoints } from './breakpoints/index';
|
||||
import { DEFAULT_LEXICONS, DEFAULT_WEIGHTS } from './scoring/index';
|
||||
import { mergeWeights } from './scoring/weights';
|
||||
import { searchBestLayoutApp } from './searchApp/index';
|
||||
import { searchBestLayoutWidget } from './searchWidget/index';
|
||||
import { applyOverflowFallback } from './overflow/index';
|
||||
@@ -45,12 +46,23 @@ export async function wrapText(input: WrapTextInput): Promise<WrapTextOutput> {
|
||||
// scoring:protectedPhrases 从 constraints 注入
|
||||
const lexicons = { ...DEFAULT_LEXICONS, protectedPhrases: input.constraints?.protectedPhrases ?? DEFAULT_LEXICONS.protectedPhrases };
|
||||
const tcPunctuations: string[] = [',', '。', '!', '?', ';', ':', '、'];
|
||||
|
||||
// 评分偏好(可选):用于 UI 侧“更好看”的排版风格微调
|
||||
const scoringOverrides = input.scoringOverrides ?? null;
|
||||
const weights = scoringOverrides?.weights ? mergeWeights(scoringOverrides.weights) : DEFAULT_WEIGHTS;
|
||||
const idealWidthRatio = {
|
||||
APP: scoringOverrides?.idealWidthRatio?.APP ?? 0.9,
|
||||
WIDGET: scoringOverrides?.idealWidthRatio?.WIDGET ?? 0.95,
|
||||
};
|
||||
const scoringConfig = {
|
||||
weights: DEFAULT_WEIGHTS,
|
||||
idealWidthRatio: { APP: 0.9, WIDGET: 0.95 },
|
||||
weights,
|
||||
idealWidthRatio,
|
||||
ellipsisToken: '…',
|
||||
tcParticleWhitelist: [],
|
||||
tcPunctuations,
|
||||
// 下面两项默认由 score.ts 内部给出;此处仅在有 overrides 时注入
|
||||
minPreferredRatio: scoringOverrides?.minPreferredRatio,
|
||||
shortLastLineRatio: scoringOverrides?.shortLastLineRatio,
|
||||
};
|
||||
|
||||
// 搜索
|
||||
|
||||
Reference in New Issue
Block a user