@agile-team/mach-report 2.1.0 → 2.2.0

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.
Files changed (43) hide show
  1. package/README.md +97 -12
  2. package/dist/ReportPreview-BWrQCj9M.js +1643 -0
  3. package/dist/ReportPreview-DY0PGGqF.cjs +6 -0
  4. package/dist/grid-geometry-DBH9ExuY.cjs +1 -0
  5. package/dist/grid-geometry-DONcjshk.js +130 -0
  6. package/dist/index.cjs +5 -5
  7. package/dist/index.d.cts +79 -11
  8. package/dist/index.d.ts +79 -11
  9. package/dist/index.js +1039 -712
  10. package/dist/page-window-index-CIuT4BAv.js +43 -0
  11. package/dist/page-window-index-DEjnM6IB.cjs +1 -0
  12. package/dist/pdf.cjs +46 -46
  13. package/dist/pdf.d.cts +4 -0
  14. package/dist/pdf.d.ts +4 -0
  15. package/dist/pdf.js +6 -6
  16. package/dist/{plugin-Bl00j_CP.cjs → plugin-BMoMUxrw.cjs} +1 -1
  17. package/dist/{plugin-DVScnZ4C.js → plugin-CAcNe0FT.js} +2 -2
  18. package/dist/report-params-B3Fia6JO.js +10 -0
  19. package/dist/report-params-D1gZ1DME.cjs +1 -0
  20. package/dist/style.css +1 -1
  21. package/dist/textwrap-DdaewxAd.js +117 -0
  22. package/dist/textwrap-DqiFwAV3.cjs +3 -0
  23. package/dist/vue/async.d.cts +53 -2
  24. package/dist/vue/async.d.ts +53 -2
  25. package/dist/vue/index.d.cts +65 -12
  26. package/dist/vue/index.d.ts +65 -12
  27. package/dist/vue-async.cjs +1 -1
  28. package/dist/vue-async.js +3 -3
  29. package/dist/vue.cjs +1 -1
  30. package/dist/vue.js +4 -4
  31. package/dist/xlsx.cjs +14 -14
  32. package/dist/xlsx.d.cts +8 -0
  33. package/dist/xlsx.d.ts +8 -0
  34. package/dist/xlsx.js +1087 -1053
  35. package/package.json +3 -2
  36. package/dist/ReportPreview-Dwdsyk9b.js +0 -1558
  37. package/dist/ReportPreview-VHAIfsz1.cjs +0 -6
  38. package/dist/grid-geometry-BXpOxznT.cjs +0 -1
  39. package/dist/grid-geometry-Bs8QXz1X.js +0 -65
  40. package/dist/report-params-BB85g7mg.js +0 -10
  41. package/dist/report-params-D1NeY-eR.cjs +0 -1
  42. package/dist/style-CFZ-HE2s.cjs +0 -3
  43. package/dist/style-DnmtG7Gl.js +0 -180
package/dist/index.d.cts CHANGED
@@ -102,14 +102,7 @@ export declare interface ComponentStyle {
102
102
  rotateDeg?: number;
103
103
  }
104
104
 
105
- /**
106
- * 页级视口虚拟化:给定每页高度与滚动位置,返回需要真实渲染的页区间
107
- * 与上下占位高度。start/end 为闭区间索引。
108
- *
109
- * 布局模型:每页占据 height + gap(gap 为页间距,默认 0),
110
- * padTop/padBottom 同口径累计,保证 占位+渲染页+间距 还原总滚动高度。
111
- * 内部用前缀和 + 二分定位覆盖页与可见终点。
112
- */
105
+ /** 页级视口虚拟化;单次计算入口保留兼容,预览内部复用已建立的几何索引。 */
113
106
  export declare function computePageWindow(input: PageWindowInput): PageWindow;
114
107
 
115
108
  /**
@@ -147,6 +140,9 @@ export declare function createTableTemplate(options: TableTemplateOptions): Repo
147
140
 
148
141
  export declare function createTemplate(): TemplateBuilder;
149
142
 
143
+ /** 存储无关的模板目录;后台 CRUD、权限、发布审批与持久化由宿主接入。 */
144
+ export declare function createTemplateRegistry(documents?: readonly ReportTemplateDocument[]): ReportTemplateRegistry;
145
+
150
146
  export declare const CSS_DPI = 96;
151
147
 
152
148
  export declare type DatasetRows = Record<string, Record<string, unknown>[]>;
@@ -168,6 +164,11 @@ export declare function defineReport<TData>(definition: ReportDefinitionOptions<
168
164
 
169
165
  export declare function defineReport(definition: ReportDefinition): ReportDefinition;
170
166
 
167
+ /** 创建带文档版本的模板快照,使用侧无需记忆 schemaVersion 常量。 */
168
+ export declare function defineReportTemplate(document: Omit<ReportTemplateDocument, "schemaVersion"> & {
169
+ schemaVersion?: typeof REPORT_TEMPLATE_DOCUMENT_VERSION;
170
+ }): ReportTemplateDocument;
171
+
171
172
  /**
172
173
  * 规则求值语义:
173
174
  * - 空值(null/undefined/"")永不命中(避免 Number("")===0 把空当 0 的隐式陷阱)
@@ -188,6 +189,10 @@ declare type Geometry = Partial<Pick<PlanComponent, "leftMm" | "topMm" | "widthM
188
189
  export declare interface GridCell {
189
190
  text?: string;
190
191
  rawText?: string;
192
+ /** 原始值,仅供 Excel raw 模式消费;不参与预览、分页与 PDF 绘制。 */
193
+ value?: string | number | boolean | null;
194
+ /** Excel 数字格式(例如 #,##0.00 / 0.00%),不改变 text。 */
195
+ numberFormat?: string;
191
196
  children?: PlanComponent[];
192
197
  colSpan?: number;
193
198
  rowSpan?: number;
@@ -248,11 +253,20 @@ export declare function isRichText(comp: PlanComponent): boolean;
248
253
  /** 默认行高倍数(基线距 = 字号 × 该系数) */
249
254
  export declare const LINE_HEIGHT = 1.35;
250
255
 
256
+ /** auto:真实数字/显式数值格式居右,日期与布尔居中,其他内容居左。 */
257
+ export declare type ListAlignment = NonNullable<ComponentStyle["align"]> | "auto";
258
+
251
259
  export declare interface ListColumn {
252
260
  header: string;
253
261
  field: string;
254
262
  widthMm: number;
255
263
  style?: ComponentStyle;
264
+ /** 内容对齐,优先于 style.align;数值字符串不会自动判为数字。 */
265
+ align?: ListAlignment;
266
+ /** 独立的表头对齐,不改变内容对齐。 */
267
+ headerAlign?: ComponentStyle["align"];
268
+ /** 独立的表头样式,优先于列表级表头样式。 */
269
+ headerStyle?: ComponentStyle;
256
270
  /** 值格式化(声明式):千分位/小数位、百分比、日期 pattern */
257
271
  format?: ColumnFormat;
258
272
  /** 条件格式规则(声明式,命中合并进单元格样式;如负数红字) */
@@ -273,6 +287,11 @@ export declare interface ListComponent {
273
287
  paddingMm?: number;
274
288
  headerEveryPage?: boolean;
275
289
  headerBackgroundColor?: string;
290
+ /** 内容默认对齐,列配置可覆盖;低层模板缺省仍为 left。 */
291
+ align?: ListAlignment;
292
+ /** 表头默认对齐,列配置可覆盖。 */
293
+ headerAlign?: ComponentStyle["align"];
294
+ headerStyle?: ComponentStyle;
276
295
  border?: boolean;
277
296
  /** 分组小计(组头/组尾小计/组头防孤行) */
278
297
  groupBy?: ListGroupBy;
@@ -351,7 +370,7 @@ export declare interface PageWindowInput {
351
370
  viewportHeightPx: number;
352
371
  scrollTopPx: number;
353
372
  overscan?: number;
354
- /** 页间距(px)。占位高度按“每页高度+间距”累计,与 margin-bottom 布局一致;默认 0 */
373
+ /** 页间距(px),默认 0;与每页 margin-bottom 使用同一口径。 */
355
374
  gapPx?: number;
356
375
  }
357
376
 
@@ -380,6 +399,9 @@ export declare type PaperName = keyof typeof PAPER_SIZES;
380
399
  /** 日历日字符串 → 本地 Date(不含时间的纯日期,杜绝 UTC 偏移) */
381
400
  export declare function parseDateLocal(input: string): Date | null;
382
401
 
402
+ /** 校验文件 JSON 文本或接口返回的未知对象,返回独立模板快照。 */
403
+ export declare function parseReportTemplate(input: unknown): ReportTemplateDocument;
404
+
383
405
  export declare interface PlanComponent {
384
406
  kind: ComponentKind;
385
407
  leftMm: number;
@@ -462,12 +484,16 @@ export declare function renderPlanToCanvas(plan: RenderPlan, options?: CanvasRen
462
484
  */
463
485
  export declare function renderPlanToImages(plan: RenderPlan, options?: ImageRenderOptions): Promise<ImageRenderResult>;
464
486
 
487
+ /** 模板存储文档版本;与渲染计划版本独立演进。 */
488
+ export declare const REPORT_TEMPLATE_DOCUMENT_VERSION: "1.0";
489
+
465
490
  export declare interface ReportDefinition {
466
- template: ReportTemplate;
491
+ /** 静态模板或宿主提供的异步模板加载器;动态模板默认每次重新读取,不缓存版本。 */
492
+ template: ReportTemplate | ReportTemplateLoader;
467
493
  /** 静态数据;load 存在时优先使用 load 的结果。 */
468
494
  datasets?: DatasetRows;
469
495
  load?: (context: ReportLoadContext) => DatasetRows | Promise<DatasetRows>;
470
- /** 覆盖模板参数定义,未提供时自动使用 template.params。 */
496
+ /** 覆盖模板参数定义;动态模板应在此声明查询面板元数据,避免查询前先请求模板。 */
471
497
  params?: ReportParamDef[];
472
498
  pagination?: PaginateOptions;
473
499
  }
@@ -534,6 +560,37 @@ export declare interface ReportTemplate {
534
560
  pages: TemplatePage[];
535
561
  }
536
562
 
563
+ /** 可存入数据库/文件的纯 JSON 模板;数据、接口与鉴权仍由宿主提供。 */
564
+ export declare interface ReportTemplateDocument {
565
+ schemaVersion: typeof REPORT_TEMPLATE_DOCUMENT_VERSION;
566
+ id: string;
567
+ name: string;
568
+ /** 宿主的发布版本/乐观锁标识,不由引擎自动递增。 */
569
+ revision?: string;
570
+ description?: string;
571
+ template: ReportTemplate;
572
+ }
573
+
574
+ export declare class ReportTemplateError extends Error {
575
+ readonly errors: readonly ValidationError[];
576
+ constructor(errors: readonly ValidationError[]);
577
+ }
578
+
579
+ export declare type ReportTemplateLoader = (context: ReportLoadContext) => ReportTemplate | Promise<ReportTemplate>;
580
+
581
+ export declare interface ReportTemplateRegistry {
582
+ /** 返回独立快照,调用方编辑不会改变目录中的已注册模板。 */
583
+ get(id: string): ReportTemplateDocument | undefined;
584
+ list(): ReportTemplateSummary[];
585
+ /** 重复 ID 默认拒绝;更新必须显式 replace:true。 */
586
+ register(document: ReportTemplateDocument, options?: {
587
+ replace?: boolean;
588
+ }): void;
589
+ remove(id: string): boolean;
590
+ }
591
+
592
+ export declare type ReportTemplateSummary = Omit<ReportTemplateDocument, "template">;
593
+
537
594
  /**
538
595
  * 边框开关解析:
539
596
  * - 未声明(undefined)→ 四边全开(与既有 rect 总有边框的行为兼容)
@@ -604,6 +661,9 @@ export declare function round(value: number, digits: number): number;
604
661
  /** RenderPlan 正式 schema 版本(core 分页引擎产出) */
605
662
  export declare const SCHEMA_VERSION_MACH = "1.0.0-mach";
606
663
 
664
+ /** 格式化输出已校验的纯模板 JSON,不静默丢弃函数或非法数字。 */
665
+ export declare function serializeReportTemplate(document: ReportTemplateDocument): string;
666
+
607
667
  /** 条件格式规则求值(声明式,见 ListColumn.rules) */
608
668
  export declare interface StyleRule {
609
669
  when: {
@@ -706,6 +766,9 @@ export declare interface TextMeasurer {
706
766
  measureMm(text: string, options: TextMeasureOptions): number;
707
767
  }
708
768
 
769
+ /** 数值型 Excel 导出的显示格式;日期/对象仍使用显示文本,不做隐式类型转换。 */
770
+ export declare function toExcelNumberFormat(format?: ColumnFormat): string | undefined;
771
+
709
772
  export declare function toNumber(value: unknown): number | null;
710
773
 
711
774
  export declare function validateComponent(comp: unknown, path: string, errors: ValidationError[], warnings?: ValidationError[]): void;
@@ -714,6 +777,11 @@ export declare function validatePage(page: unknown, path: string, errors: Valida
714
777
 
715
778
  export declare function validateRenderPlan(input: unknown): ValidationResult;
716
779
 
780
+ /** 对入库/导入模板做声明式校验,不执行分页或数据请求。 */
781
+ export declare function validateReportTemplate(input: unknown): ValidationResult;
782
+
783
+ export declare function validateReportTemplateDocument(input: unknown): ValidationResult;
784
+
717
785
  export declare interface ValidationError {
718
786
  path: string;
719
787
  message: string;
package/dist/index.d.ts CHANGED
@@ -102,14 +102,7 @@ export declare interface ComponentStyle {
102
102
  rotateDeg?: number;
103
103
  }
104
104
 
105
- /**
106
- * 页级视口虚拟化:给定每页高度与滚动位置,返回需要真实渲染的页区间
107
- * 与上下占位高度。start/end 为闭区间索引。
108
- *
109
- * 布局模型:每页占据 height + gap(gap 为页间距,默认 0),
110
- * padTop/padBottom 同口径累计,保证 占位+渲染页+间距 还原总滚动高度。
111
- * 内部用前缀和 + 二分定位覆盖页与可见终点。
112
- */
105
+ /** 页级视口虚拟化;单次计算入口保留兼容,预览内部复用已建立的几何索引。 */
113
106
  export declare function computePageWindow(input: PageWindowInput): PageWindow;
114
107
 
115
108
  /**
@@ -147,6 +140,9 @@ export declare function createTableTemplate(options: TableTemplateOptions): Repo
147
140
 
148
141
  export declare function createTemplate(): TemplateBuilder;
149
142
 
143
+ /** 存储无关的模板目录;后台 CRUD、权限、发布审批与持久化由宿主接入。 */
144
+ export declare function createTemplateRegistry(documents?: readonly ReportTemplateDocument[]): ReportTemplateRegistry;
145
+
150
146
  export declare const CSS_DPI = 96;
151
147
 
152
148
  export declare type DatasetRows = Record<string, Record<string, unknown>[]>;
@@ -168,6 +164,11 @@ export declare function defineReport<TData>(definition: ReportDefinitionOptions<
168
164
 
169
165
  export declare function defineReport(definition: ReportDefinition): ReportDefinition;
170
166
 
167
+ /** 创建带文档版本的模板快照,使用侧无需记忆 schemaVersion 常量。 */
168
+ export declare function defineReportTemplate(document: Omit<ReportTemplateDocument, "schemaVersion"> & {
169
+ schemaVersion?: typeof REPORT_TEMPLATE_DOCUMENT_VERSION;
170
+ }): ReportTemplateDocument;
171
+
171
172
  /**
172
173
  * 规则求值语义:
173
174
  * - 空值(null/undefined/"")永不命中(避免 Number("")===0 把空当 0 的隐式陷阱)
@@ -188,6 +189,10 @@ declare type Geometry = Partial<Pick<PlanComponent, "leftMm" | "topMm" | "widthM
188
189
  export declare interface GridCell {
189
190
  text?: string;
190
191
  rawText?: string;
192
+ /** 原始值,仅供 Excel raw 模式消费;不参与预览、分页与 PDF 绘制。 */
193
+ value?: string | number | boolean | null;
194
+ /** Excel 数字格式(例如 #,##0.00 / 0.00%),不改变 text。 */
195
+ numberFormat?: string;
191
196
  children?: PlanComponent[];
192
197
  colSpan?: number;
193
198
  rowSpan?: number;
@@ -248,11 +253,20 @@ export declare function isRichText(comp: PlanComponent): boolean;
248
253
  /** 默认行高倍数(基线距 = 字号 × 该系数) */
249
254
  export declare const LINE_HEIGHT = 1.35;
250
255
 
256
+ /** auto:真实数字/显式数值格式居右,日期与布尔居中,其他内容居左。 */
257
+ export declare type ListAlignment = NonNullable<ComponentStyle["align"]> | "auto";
258
+
251
259
  export declare interface ListColumn {
252
260
  header: string;
253
261
  field: string;
254
262
  widthMm: number;
255
263
  style?: ComponentStyle;
264
+ /** 内容对齐,优先于 style.align;数值字符串不会自动判为数字。 */
265
+ align?: ListAlignment;
266
+ /** 独立的表头对齐,不改变内容对齐。 */
267
+ headerAlign?: ComponentStyle["align"];
268
+ /** 独立的表头样式,优先于列表级表头样式。 */
269
+ headerStyle?: ComponentStyle;
256
270
  /** 值格式化(声明式):千分位/小数位、百分比、日期 pattern */
257
271
  format?: ColumnFormat;
258
272
  /** 条件格式规则(声明式,命中合并进单元格样式;如负数红字) */
@@ -273,6 +287,11 @@ export declare interface ListComponent {
273
287
  paddingMm?: number;
274
288
  headerEveryPage?: boolean;
275
289
  headerBackgroundColor?: string;
290
+ /** 内容默认对齐,列配置可覆盖;低层模板缺省仍为 left。 */
291
+ align?: ListAlignment;
292
+ /** 表头默认对齐,列配置可覆盖。 */
293
+ headerAlign?: ComponentStyle["align"];
294
+ headerStyle?: ComponentStyle;
276
295
  border?: boolean;
277
296
  /** 分组小计(组头/组尾小计/组头防孤行) */
278
297
  groupBy?: ListGroupBy;
@@ -351,7 +370,7 @@ export declare interface PageWindowInput {
351
370
  viewportHeightPx: number;
352
371
  scrollTopPx: number;
353
372
  overscan?: number;
354
- /** 页间距(px)。占位高度按“每页高度+间距”累计,与 margin-bottom 布局一致;默认 0 */
373
+ /** 页间距(px),默认 0;与每页 margin-bottom 使用同一口径。 */
355
374
  gapPx?: number;
356
375
  }
357
376
 
@@ -380,6 +399,9 @@ export declare type PaperName = keyof typeof PAPER_SIZES;
380
399
  /** 日历日字符串 → 本地 Date(不含时间的纯日期,杜绝 UTC 偏移) */
381
400
  export declare function parseDateLocal(input: string): Date | null;
382
401
 
402
+ /** 校验文件 JSON 文本或接口返回的未知对象,返回独立模板快照。 */
403
+ export declare function parseReportTemplate(input: unknown): ReportTemplateDocument;
404
+
383
405
  export declare interface PlanComponent {
384
406
  kind: ComponentKind;
385
407
  leftMm: number;
@@ -462,12 +484,16 @@ export declare function renderPlanToCanvas(plan: RenderPlan, options?: CanvasRen
462
484
  */
463
485
  export declare function renderPlanToImages(plan: RenderPlan, options?: ImageRenderOptions): Promise<ImageRenderResult>;
464
486
 
487
+ /** 模板存储文档版本;与渲染计划版本独立演进。 */
488
+ export declare const REPORT_TEMPLATE_DOCUMENT_VERSION: "1.0";
489
+
465
490
  export declare interface ReportDefinition {
466
- template: ReportTemplate;
491
+ /** 静态模板或宿主提供的异步模板加载器;动态模板默认每次重新读取,不缓存版本。 */
492
+ template: ReportTemplate | ReportTemplateLoader;
467
493
  /** 静态数据;load 存在时优先使用 load 的结果。 */
468
494
  datasets?: DatasetRows;
469
495
  load?: (context: ReportLoadContext) => DatasetRows | Promise<DatasetRows>;
470
- /** 覆盖模板参数定义,未提供时自动使用 template.params。 */
496
+ /** 覆盖模板参数定义;动态模板应在此声明查询面板元数据,避免查询前先请求模板。 */
471
497
  params?: ReportParamDef[];
472
498
  pagination?: PaginateOptions;
473
499
  }
@@ -534,6 +560,37 @@ export declare interface ReportTemplate {
534
560
  pages: TemplatePage[];
535
561
  }
536
562
 
563
+ /** 可存入数据库/文件的纯 JSON 模板;数据、接口与鉴权仍由宿主提供。 */
564
+ export declare interface ReportTemplateDocument {
565
+ schemaVersion: typeof REPORT_TEMPLATE_DOCUMENT_VERSION;
566
+ id: string;
567
+ name: string;
568
+ /** 宿主的发布版本/乐观锁标识,不由引擎自动递增。 */
569
+ revision?: string;
570
+ description?: string;
571
+ template: ReportTemplate;
572
+ }
573
+
574
+ export declare class ReportTemplateError extends Error {
575
+ readonly errors: readonly ValidationError[];
576
+ constructor(errors: readonly ValidationError[]);
577
+ }
578
+
579
+ export declare type ReportTemplateLoader = (context: ReportLoadContext) => ReportTemplate | Promise<ReportTemplate>;
580
+
581
+ export declare interface ReportTemplateRegistry {
582
+ /** 返回独立快照,调用方编辑不会改变目录中的已注册模板。 */
583
+ get(id: string): ReportTemplateDocument | undefined;
584
+ list(): ReportTemplateSummary[];
585
+ /** 重复 ID 默认拒绝;更新必须显式 replace:true。 */
586
+ register(document: ReportTemplateDocument, options?: {
587
+ replace?: boolean;
588
+ }): void;
589
+ remove(id: string): boolean;
590
+ }
591
+
592
+ export declare type ReportTemplateSummary = Omit<ReportTemplateDocument, "template">;
593
+
537
594
  /**
538
595
  * 边框开关解析:
539
596
  * - 未声明(undefined)→ 四边全开(与既有 rect 总有边框的行为兼容)
@@ -604,6 +661,9 @@ export declare function round(value: number, digits: number): number;
604
661
  /** RenderPlan 正式 schema 版本(core 分页引擎产出) */
605
662
  export declare const SCHEMA_VERSION_MACH = "1.0.0-mach";
606
663
 
664
+ /** 格式化输出已校验的纯模板 JSON,不静默丢弃函数或非法数字。 */
665
+ export declare function serializeReportTemplate(document: ReportTemplateDocument): string;
666
+
607
667
  /** 条件格式规则求值(声明式,见 ListColumn.rules) */
608
668
  export declare interface StyleRule {
609
669
  when: {
@@ -706,6 +766,9 @@ export declare interface TextMeasurer {
706
766
  measureMm(text: string, options: TextMeasureOptions): number;
707
767
  }
708
768
 
769
+ /** 数值型 Excel 导出的显示格式;日期/对象仍使用显示文本,不做隐式类型转换。 */
770
+ export declare function toExcelNumberFormat(format?: ColumnFormat): string | undefined;
771
+
709
772
  export declare function toNumber(value: unknown): number | null;
710
773
 
711
774
  export declare function validateComponent(comp: unknown, path: string, errors: ValidationError[], warnings?: ValidationError[]): void;
@@ -714,6 +777,11 @@ export declare function validatePage(page: unknown, path: string, errors: Valida
714
777
 
715
778
  export declare function validateRenderPlan(input: unknown): ValidationResult;
716
779
 
780
+ /** 对入库/导入模板做声明式校验,不执行分页或数据请求。 */
781
+ export declare function validateReportTemplate(input: unknown): ValidationResult;
782
+
783
+ export declare function validateReportTemplateDocument(input: unknown): ValidationResult;
784
+
717
785
  export declare interface ValidationError {
718
786
  path: string;
719
787
  message: string;