import { Formatter } from './attribute'; import { Slot } from './slot'; /** * 格式或属性的值,必须为可被 JSON 序列化的字面量 */ export type FormatValue = NonNullable; /** * 一组格式 */ export type Formats = [formatter: Formatter, value: T][]; /** * 标识格式的范围 */ export interface FormatRange { startIndex: number; endIndex: number; value: T; } /** * 格式的字面量 */ export interface FormatLiteral { [key: string]: FormatRange[]; } /** * 格式的详情 */ export interface FormatItem extends FormatRange { formatter: Formatter; } /** * 格式树 */ export interface FormatTree { startIndex: number; endIndex: number; children?: FormatTree[]; formats?: FormatItem[]; } export declare class PendingErasure { erasureAll: boolean; value?: T | undefined; constructor(erasureAll: boolean, value?: T | undefined); } /** * Textbus 格式管理类 * Format 类为 Slot 的私有属性,在实际场景中,开发者不需在关注此类,也不需要访问或操作此类 */ export declare class Format { private slot; private map; constructor(slot: Slot); /** * 将新样式合并到现有样式中 * @param formatter * @param value * @param background */ merge(formatter: Formatter, value: FormatRange, background?: boolean): this; /** * 将 index 后的样式起始和结束位置均增加 count 大小 * @param index * @param count */ stretch(index: number, count: number): this; /** * 将指定 index 位置后的样式向后平移 distance 长度 * @param index * @param distance */ split(index: number, distance: number): this; /** * 从指定 index 位置的样式删除 count * @param startIndex * @param count */ shrink(startIndex: number, count: number): this; /** * 提取指定范围内的样式 * @param startIndex * @param endIndex * @param formatter */ extract(startIndex: number, endIndex: number, formatter?: Formatter[]): Format; /** * 生成一个重置位置的 format * @param slot * @param startIndex * @param endIndex */ createFormatByRange(slot: Slot, startIndex: number, endIndex: number): Format; /** * 通过 formatter 提取指定范围内的样式数据 * @param startIndex * @param endIndex * @param formatter */ extractFormatRangesByFormatter(startIndex: number, endIndex: number, formatter: Formatter): FormatRange[]; /** * 丢弃指定范围内的样式 * @param formatter * @param startIndex * @param endIndex */ discard(formatter: Formatter, startIndex: number, endIndex: number): this; extractFormatsByIndex(index: number): Formats; toGrid(): number[]; toJSON(): FormatLiteral; toTree(startIndex: number, endIndex: number): FormatTree; /** * 从 workingCopy 中提取完全覆盖 [L, R) 的格式。 * 非 segmented 格式会从 map 中移除(stackable 只移除匹配的那一条,非 stackable 移除全部)。 * segmented 格式保留在 map 中以参与子节点的分段。 */ private static extractNodeFormats; /** * 在 workingCopy 中找到最靠左的非 ghost range 作为递归分割点。 * ghost 指 segmented 格式中完全覆盖当前区间的 range,它们不参与 hasChildren 判断。 * 返回 null 表示无需继续分割。 */ private static findFirstSplit; /** * 如果子树有 formats 则原样返回(作为单个 child), * 如果子树无 formats 但有 children 则展平返回其 children(消除空中间节点), * 否则原样返回。 */ private static unwrapOrFlatten; toArray(): FormatItem[]; private normalizeFormatRange; static equal(left: FormatValue, right: FormatValue): boolean; /** 保留 range 在 [cutStart, cutEnd) 之外的片段 */ private static clipRangeOutside; /** 在 [eraseStart, eraseEnd) 内按条件擦除;不相交区间原样保留 */ private static applyErasure; /** 相邻且取值相同的区间合并为一项(按取值分组,避免排序后中间夹着其它取值而无法合并) */ private static mergeAdjacentSameValue; private static mergeStackableValue; private static mergeNonStackableValue; private static mergeRanges; }