@jcyao/print-sdk 1.0.0 → 1.0.1
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.
- package/README.md +190 -20
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +196 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +197 -16
- package/dist/index.js.map +1 -1
- package/dist/printEngine/renderers/PageNumberRenderer.d.ts +22 -0
- package/dist/printEngine/renderers/index.d.ts +1 -0
- package/dist/printEngine.d.ts +11 -0
- package/dist/sdk.d.ts +2 -2
- package/dist/types.d.ts +25 -0
- package/dist/utils/resourceLoader.d.ts +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 页码组件渲染器
|
|
3
|
+
* 支持三种格式:
|
|
4
|
+
* - simple: 1, 2, 3
|
|
5
|
+
* - text: 第1页 共3页
|
|
6
|
+
* - slash: 1/3
|
|
7
|
+
*/
|
|
8
|
+
import type { ComponentNode } from '../../types';
|
|
9
|
+
import type { ComponentRenderer, RenderContext } from '../types';
|
|
10
|
+
export declare class PageNumberRenderer implements ComponentRenderer {
|
|
11
|
+
readonly type = "pageNumber";
|
|
12
|
+
render(component: ComponentNode, context: RenderContext): string;
|
|
13
|
+
calculateHeight(component: ComponentNode): number;
|
|
14
|
+
/**
|
|
15
|
+
* 格式化页码文本
|
|
16
|
+
*/
|
|
17
|
+
private formatPageNumber;
|
|
18
|
+
/**
|
|
19
|
+
* HTML 转义
|
|
20
|
+
*/
|
|
21
|
+
private escapeHtml;
|
|
22
|
+
}
|
package/dist/printEngine.d.ts
CHANGED
|
@@ -77,8 +77,19 @@ export declare class PrintEngine {
|
|
|
77
77
|
* 计算表格行高度(mm)
|
|
78
78
|
*/
|
|
79
79
|
private calculateTableRowHeight;
|
|
80
|
+
/**
|
|
81
|
+
* 渲染页码(根据页面配置)
|
|
82
|
+
*/
|
|
83
|
+
private renderPageNumber;
|
|
84
|
+
/**
|
|
85
|
+
* HTML 转义
|
|
86
|
+
*/
|
|
87
|
+
private escapeHtml;
|
|
80
88
|
/**
|
|
81
89
|
* 渲染单个页面(直接渲染,不做智能布局)
|
|
90
|
+
* @param components 组件列表
|
|
91
|
+
* @param pageNumber 当前页码(可选)
|
|
92
|
+
* @param totalPages 总页数(可选)
|
|
82
93
|
*/
|
|
83
94
|
private renderSinglePage;
|
|
84
95
|
/**
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 打印 SDK 统一导出
|
|
3
|
-
* 这个文件将来可以直接独立为 @
|
|
3
|
+
* 这个文件将来可以直接独立为 @jcyao/print-sdk 包
|
|
4
4
|
*/
|
|
5
5
|
export { PrintSDK, createPrintSDK } from './PrintSDK';
|
|
6
6
|
export type { PrintOptions, BatchPrintOptions, BatchPrintProgress, } from './PrintSDK';
|
|
@@ -9,4 +9,4 @@ export type { ComponentRenderer, RenderContext } from './printEngine';
|
|
|
9
9
|
export { MM_TO_PX, COMPONENT_DEFAULT_SIZE, TABLE_DEFAULT, STYLE_DEFAULT, TABLE_STYLE_DEFAULT, BARCODE_CONFIG, QRCODE_CONFIG } from './printEngine/constants';
|
|
10
10
|
export { generatePrintPageStyles, generateBatchPrintStyles, generatePrintHTML, getPageSizeFromConfig, } from './printEngine/htmlTemplate';
|
|
11
11
|
export { TextRenderer, TableRenderer, ImageRenderer, RectRenderer, LineRenderer, QRCodeRenderer, BarcodeRenderer, } from './printEngine/renderers';
|
|
12
|
-
export type { PrintTemplate, ComponentNode, DataBinding, PipeConfig, PageConfig, ComponentType, SchemaField, SchemaDictionary, MockData, } from './types';
|
|
12
|
+
export type { PrintTemplate, ComponentNode, DataBinding, PipeConfig, PageConfig, PageNumberConfig, ComponentType, SchemaField, SchemaDictionary, MockData, TableProps, TableColumn, } from './types';
|
package/dist/types.d.ts
CHANGED
|
@@ -19,6 +19,21 @@ export interface SchemaDictionary {
|
|
|
19
19
|
version?: string;
|
|
20
20
|
description?: string;
|
|
21
21
|
}
|
|
22
|
+
export interface PageNumberConfig {
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
position: 'bottom-center' | 'bottom-right' | 'bottom-left' | 'top-center' | 'top-right' | 'top-left';
|
|
25
|
+
format?: 'simple' | 'text' | 'slash';
|
|
26
|
+
prefix?: string;
|
|
27
|
+
suffix?: string;
|
|
28
|
+
separator?: string;
|
|
29
|
+
offsetX?: number;
|
|
30
|
+
offsetY?: number;
|
|
31
|
+
style?: {
|
|
32
|
+
fontSize?: number;
|
|
33
|
+
color?: string;
|
|
34
|
+
fontWeight?: 'normal' | 'bold';
|
|
35
|
+
};
|
|
36
|
+
}
|
|
22
37
|
export interface PageConfig {
|
|
23
38
|
size: 'A4' | 'A5' | 'CUSTOM' | 'CONTINUOUS';
|
|
24
39
|
widthMm?: number;
|
|
@@ -31,6 +46,7 @@ export interface PageConfig {
|
|
|
31
46
|
bottom: number;
|
|
32
47
|
left: number;
|
|
33
48
|
};
|
|
49
|
+
pageNumber?: PageNumberConfig;
|
|
34
50
|
}
|
|
35
51
|
export type ComponentType = 'text' | 'image' | 'rect' | 'container' | 'table' | 'line' | 'qrcode' | 'barcode';
|
|
36
52
|
export interface PipeConfig {
|
|
@@ -64,6 +80,15 @@ export interface TableSummaryStyle {
|
|
|
64
80
|
fontWeight?: string;
|
|
65
81
|
fontSize?: number;
|
|
66
82
|
}
|
|
83
|
+
export interface PageNumberProps {
|
|
84
|
+
format?: 'simple' | 'text' | 'slash';
|
|
85
|
+
align?: 'left' | 'center' | 'right';
|
|
86
|
+
prefix?: string;
|
|
87
|
+
suffix?: string;
|
|
88
|
+
separator?: string;
|
|
89
|
+
_currentPage?: number;
|
|
90
|
+
_totalPages?: number;
|
|
91
|
+
}
|
|
67
92
|
export interface TableProps {
|
|
68
93
|
columns: TableColumn[];
|
|
69
94
|
showHeader?: boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 资源加载工具
|
|
3
|
+
* 用于等待图片、二维码、条形码等异步资源加载完成
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 等待文档中所有图片加载完成
|
|
7
|
+
* @param doc 文档对象(可以是 window.document 或 iframe.contentDocument)
|
|
8
|
+
* @param timeout 超时时间(毫秒),默认 10000ms
|
|
9
|
+
* @returns Promise<void>
|
|
10
|
+
*/
|
|
11
|
+
export declare function waitForImagesLoaded(doc: Document, timeout?: number): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* 等待所有打印资源加载完成
|
|
14
|
+
* 包括:图片、二维码(已转base64)、条形码(已转base64)
|
|
15
|
+
* 注意:二维码和条形码在渲染时已同步生成为 base64,所以主要等待外部图片
|
|
16
|
+
* @param doc 文档对象
|
|
17
|
+
* @param timeout 超时时间(毫秒),默认 10000ms
|
|
18
|
+
*/
|
|
19
|
+
export declare function waitForPrintResourcesReady(doc: Document, timeout?: number): Promise<void>;
|