xiaodao-spreader 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,100 @@
1
+ export declare const NF_CUSTOM = "__nf_custom__";
2
+ export declare const NF_MIXED = "\u0001";
3
+ export declare const NF_GENERAL = "";
4
+ export declare const NF_TEXT = "@";
5
+ /**
6
+ * formatNumber 的特殊返回值:表示"当前格式+数值组合在 Excel 语义下非法",
7
+ * 例如 date 格式 序列号<0/≥2958466、duration 格式 序列号<0。
8
+ * 渲染端必须把该字符串按列宽替换为连续 '#' 填充(不显示此标识符本身)。
9
+ */
10
+ export declare const NF_INVALID_VALUE = "__NF_INVALID__";
11
+ /** Excel 1900 日期系统最大合法序列号(对应 9999-12-31)。超过或为负 → 整格 ###。 */
12
+ export declare const EXCEL_DATE_MAX_SERIAL = 2958465;
13
+ /** Excel 1900 日期系统最小合法序列号(0 = 1900-01-00,作为下界兜底,实际 UI 一般从 1 开始)。 */
14
+ export declare const EXCEL_DATE_MIN_SERIAL = 0;
15
+ /** 判断格式代码是否为 General(含空串、undefined、'General'、'GENERAL' 等) */
16
+ export declare function isGeneralFormat(format: string | undefined | null): boolean;
17
+ export type NFKind = 'general' | 'text' | 'number' | 'date' | 'duration';
18
+ export interface NFSection {
19
+ /** 是否含有数字占位符(0/#/?);无占位符的区段视为纯文本字面量 */
20
+ hasDigits: boolean;
21
+ /** 小数最大位数(0/#/? 的总数) */
22
+ decimals: number;
23
+ /** 强制小数位数(0 的个数,决定尾随 0 的数量) */
24
+ minDecimals: number;
25
+ /** 整数部分强制最少位数(0 的个数) */
26
+ minIntDigits: number;
27
+ /** 是否使用千位分隔符 */
28
+ thousands: boolean;
29
+ /** 缩放倍数(百分比为 100) */
30
+ scale: number;
31
+ /** 科学计数法 */
32
+ scientific: boolean;
33
+ /** 数字前的字面量(货币符号等) */
34
+ prefix: string;
35
+ /** 数字后的字面量(如 %) */
36
+ suffix: string;
37
+ /** 区段颜色([Red] 等,渲染层可忽略) */
38
+ color?: string;
39
+ }
40
+ export type NFDateTokenType = 'literal' | 'year' | 'month' | 'monthName' | 'day' | 'weekday' | 'hour' | 'minute' | 'second' | 'ampm';
41
+ export interface NFToken {
42
+ type: NFDateTokenType;
43
+ /** literal 类型的原始文本 */
44
+ text?: string;
45
+ /** 占位符长度(如 yyyy → 4) */
46
+ len: number;
47
+ }
48
+ export interface NFParsed {
49
+ kind: NFKind;
50
+ /** 数值区段(number 类型使用;可能含正/负/零/文本多个区段) */
51
+ sections: NFSection[];
52
+ /** 日期/时间/持续时间的 token 序列 */
53
+ tokens: NFToken[];
54
+ /** 是否为持续时间(含 [h]/[mm]/[ss]) */
55
+ isDuration: boolean;
56
+ raw: string;
57
+ }
58
+ export interface NFOption {
59
+ label: string;
60
+ value: string;
61
+ }
62
+ export declare function parseNumberFormat(format: string): NFParsed;
63
+ /** 清空解析缓存(主要用于测试/资源释放) */
64
+ export declare function clearNumberFormatCache(): void;
65
+ /**
66
+ * 将单元格原始字符串值按格式代码格式化为显示文本。
67
+ * 绝不修改传入的 value。
68
+ */
69
+ export declare function formatNumber(value: string, format: string | undefined | null, locale: string): string;
70
+ export type NFDialogCategory = 'general' | 'number' | 'currency' | 'currencyRounded' | 'accounting' | 'financial' | 'percent' | 'scientific' | 'date' | 'time' | 'dateTime' | 'duration' | 'text' | 'custom';
71
+ export declare const NF_DIALOG_CATEGORIES: NFDialogCategory[];
72
+ /**
73
+ * 判断单元格在「未指定水平对齐」时,是否应该按「数值」默认右对齐显示。
74
+ * 规则(与 Excel 对齐语义保持一致,仅用于显示,不写入存储):
75
+ * 1. 格式代码为 '@'(文本)→ 否,保持左对齐
76
+ * 2. 常规格式(含空串 / undefined / 'General'):对原始 value 做 Number() 解析,
77
+ * 能解析为有限数字且非空字符串 → 视为数值 → 右对齐
78
+ * 3. 显式设置为数值类格式(number/currency/currencyRounded/accounting/financial/
79
+ * percent/scientific 以及 custom 中分类属于数值 kind 并含数字占位符)→ 右对齐
80
+ * 4. 日期、时间、日期时间、持续时间 → 不算数值(按 Excel 默认左对齐或居中,这里保持左对齐默认)
81
+ * 5. 其他 custom 中无法判断的 → 回退左对齐
82
+ */
83
+ export declare function shouldAlignRightByDefault(value: string, format: string | undefined | null): boolean;
84
+ /**
85
+ * 当前格式在列宽不足时,是否按 Excel 规则替换为连续 '#' 填充:
86
+ * - General / 文本 '@' / 未设置 → 不会(General 自动科学计数或允许裁切;文本就是原样裁切)
87
+ * - date / duration 类格式 → 是
88
+ * - number 类格式且含有数字占位符 → 是
89
+ * - 纯文本区段的自定义 number(如"前缀"无 0/#/?)→ 按纯文本,不需要 #
90
+ */
91
+ export declare function isFormatOverflowsToHashes(format: string | undefined | null): boolean;
92
+ /**
93
+ * 对给定 (value, format) 快速判断是否是 Excel 语义下的"非法值"(需要渲染为 # 填充)。
94
+ * 主要用于渲染端直接复用,避免再次 parseNumberFormat。
95
+ */
96
+ export declare function isInvalidDisplayValue(value: string, format: string | undefined | null): boolean;
97
+ /** 根据分类 + 小数位数 + 千位分隔符生成格式代码 */
98
+ export declare function buildNumberFormatCode(locale: string, category: NFDialogCategory, decimals: number, thousands: boolean): string;
99
+ /** 构造工具栏下拉框的选项(含「格式…」自定义项) */
100
+ export declare function buildNumberFormatPresets(locale: string): NFOption[];