locusing 0.1.2
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/LICENSE +21 -0
- package/README.md +147 -0
- package/dist/chunk-3XW6GBD6.mjs +445 -0
- package/dist/chunk-HNU2F3GX.mjs +586 -0
- package/dist/chunk-TQQRYA5H.mjs +58 -0
- package/dist/chunk-Y4M467JV.mjs +607 -0
- package/dist/diagram-Djxa_kGR.d.mts +1945 -0
- package/dist/diagram-Djxa_kGR.d.ts +1945 -0
- package/dist/export.d.mts +194 -0
- package/dist/export.d.ts +194 -0
- package/dist/export.js +528 -0
- package/dist/export.mjs +305 -0
- package/dist/index.d.mts +6883 -0
- package/dist/index.d.ts +6883 -0
- package/dist/index.global.js +79540 -0
- package/dist/index.js +15785 -0
- package/dist/index.mjs +14350 -0
- package/dist/transform-4WYIJSLH.mjs +23 -0
- package/dist/transform-7YKZIQ3I.mjs +22 -0
- package/package.json +117 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { D as Diagram, S as Scene } from './diagram-Djxa_kGR.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @locusing/export - 类型定义
|
|
5
|
+
*
|
|
6
|
+
* Playwright 图片导出相关类型
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 导出格式
|
|
10
|
+
*/
|
|
11
|
+
type ExportFormat = 'png' | 'jpeg' | 'webp';
|
|
12
|
+
/**
|
|
13
|
+
* 导出选项
|
|
14
|
+
*/
|
|
15
|
+
interface ExportOptions {
|
|
16
|
+
/** 输出格式,默认 'png' */
|
|
17
|
+
format?: ExportFormat;
|
|
18
|
+
/** 图片质量 (0-100),仅对 jpeg/webp 有效,默认 90 */
|
|
19
|
+
quality?: number;
|
|
20
|
+
/** 像素密度 (1 = 72dpi, 2 = 144dpi),默认 2 */
|
|
21
|
+
deviceScaleFactor?: number;
|
|
22
|
+
/** 画布宽度 (像素),默认 1920 */
|
|
23
|
+
width?: number;
|
|
24
|
+
/** 画布高度 (像素),默认 1080 */
|
|
25
|
+
height?: number;
|
|
26
|
+
/** 背景色,默认透明 */
|
|
27
|
+
background?: string;
|
|
28
|
+
/** 是否等待字体加载,默认 true */
|
|
29
|
+
waitForFonts?: boolean;
|
|
30
|
+
/** 渲染等待时间 (毫秒),默认 100 */
|
|
31
|
+
renderDelay?: number;
|
|
32
|
+
/** 是否使用 Frame 模式,默认 true */
|
|
33
|
+
frame?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 导出结果
|
|
37
|
+
*/
|
|
38
|
+
interface ExportResult {
|
|
39
|
+
/** 图片 Buffer */
|
|
40
|
+
buffer: Buffer;
|
|
41
|
+
/** MIME 类型 */
|
|
42
|
+
mimeType: string;
|
|
43
|
+
/** 实际宽度 (像素) */
|
|
44
|
+
width: number;
|
|
45
|
+
/** 实际高度 (像素) */
|
|
46
|
+
height: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* PlaywrightExporter 配置
|
|
50
|
+
*/
|
|
51
|
+
interface PlaywrightExporterOptions {
|
|
52
|
+
/** 是否使用无头模式,默认 true */
|
|
53
|
+
headless?: boolean;
|
|
54
|
+
/** 浏览器类型,默认 'chromium' */
|
|
55
|
+
browser?: 'chromium' | 'firefox' | 'webkit';
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Scene 导出选项
|
|
59
|
+
*/
|
|
60
|
+
interface SceneExportOptions extends ExportOptions {
|
|
61
|
+
/** 导出特定帧的时间点 (秒),默认 0 (第一帧) */
|
|
62
|
+
frameTime?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @locusing/export - Playwright 导出器
|
|
67
|
+
*
|
|
68
|
+
* 使用 Playwright 截图实现高保真图片导出
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Playwright 导出器
|
|
73
|
+
*
|
|
74
|
+
* 使用真实浏览器渲染 SVG 并截图,确保与浏览器显示效果完全一致。
|
|
75
|
+
* 支持 TeX 公式等复杂内容的导出。
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { PlaywrightExporter, circle, tex, combine } from 'locusing';
|
|
80
|
+
*
|
|
81
|
+
* const exporter = new PlaywrightExporter();
|
|
82
|
+
* await exporter.launch();
|
|
83
|
+
*
|
|
84
|
+
* const diagram = combine(
|
|
85
|
+
* circle(1).fill('#EA580C'),
|
|
86
|
+
* tex('E = mc^2').move([0, -2])
|
|
87
|
+
* );
|
|
88
|
+
*
|
|
89
|
+
* const result = await exporter.exportDiagram(diagram, {
|
|
90
|
+
* width: 1920,
|
|
91
|
+
* height: 1080,
|
|
92
|
+
* deviceScaleFactor: 2,
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* await fs.writeFile('output.png', result.buffer);
|
|
96
|
+
* await exporter.close();
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare class PlaywrightExporter {
|
|
100
|
+
private browser;
|
|
101
|
+
private page;
|
|
102
|
+
private options;
|
|
103
|
+
constructor(options?: PlaywrightExporterOptions);
|
|
104
|
+
/**
|
|
105
|
+
* 启动浏览器
|
|
106
|
+
*
|
|
107
|
+
* @throws 如果 Playwright 未安装
|
|
108
|
+
*/
|
|
109
|
+
launch(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* 关闭浏览器
|
|
112
|
+
*/
|
|
113
|
+
close(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* 获取页面实例,确保已启动
|
|
116
|
+
*/
|
|
117
|
+
private getPage;
|
|
118
|
+
/**
|
|
119
|
+
* 导出 Diagram 为图片
|
|
120
|
+
*
|
|
121
|
+
* @param diagram - 要导出的 Diagram
|
|
122
|
+
* @param options - 导出选项
|
|
123
|
+
* @returns 导出结果
|
|
124
|
+
*/
|
|
125
|
+
exportDiagram(diagram: Diagram, options?: ExportOptions): Promise<ExportResult>;
|
|
126
|
+
/**
|
|
127
|
+
* 导出 Scene 为图片(静态帧)
|
|
128
|
+
*
|
|
129
|
+
* @param SceneClass - Scene 类
|
|
130
|
+
* @param options - 导出选项
|
|
131
|
+
* @returns 导出结果
|
|
132
|
+
*/
|
|
133
|
+
exportScene(SceneClass: new () => Scene, options?: SceneExportOptions): Promise<ExportResult>;
|
|
134
|
+
/**
|
|
135
|
+
* 导出 SVG 字符串为图片
|
|
136
|
+
*
|
|
137
|
+
* @param svgString - SVG 字符串
|
|
138
|
+
* @param options - 导出选项
|
|
139
|
+
* @returns 导出结果
|
|
140
|
+
*/
|
|
141
|
+
exportSVGString(svgString: string, options?: ExportOptions): Promise<ExportResult>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 便捷函数:一次性导出 Diagram 为 PNG
|
|
145
|
+
*
|
|
146
|
+
* @param diagram - 要导出的 Diagram
|
|
147
|
+
* @param outputPath - 输出文件路径
|
|
148
|
+
* @param options - 导出选项
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* import { exportToPNG, circle } from 'locusing';
|
|
153
|
+
*
|
|
154
|
+
* await exportToPNG(circle(1).fill('#EA580C'), 'circle.png', {
|
|
155
|
+
* width: 800,
|
|
156
|
+
* height: 600
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function exportToPNG(diagram: Diagram, outputPath: string, options?: ExportOptions): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* 便捷函数:一次性导出 SVG 字符串为 PNG
|
|
163
|
+
*
|
|
164
|
+
* @param svgString - SVG 字符串
|
|
165
|
+
* @param outputPath - 输出文件路径
|
|
166
|
+
* @param options - 导出选项
|
|
167
|
+
*/
|
|
168
|
+
declare function exportSVGToPNG(svgString: string, outputPath: string, options?: ExportOptions): Promise<void>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @locusing/export - HTML 模板生成
|
|
172
|
+
*
|
|
173
|
+
* 生成用于 Playwright 截图的 HTML 页面
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 生成导出用的 HTML 模板
|
|
178
|
+
*
|
|
179
|
+
* @param svgContent - SVG 字符串内容
|
|
180
|
+
* @param options - 导出选项
|
|
181
|
+
* @returns 完整的 HTML 字符串
|
|
182
|
+
*/
|
|
183
|
+
declare function generateExportHTML(svgContent: string, options: Pick<ExportOptions, 'width' | 'height' | 'background'>): string;
|
|
184
|
+
/**
|
|
185
|
+
* 内联 KaTeX CSS(用于离线导出)
|
|
186
|
+
*
|
|
187
|
+
* @param katexCSS - KaTeX CSS 内容
|
|
188
|
+
* @param svgContent - SVG 字符串内容
|
|
189
|
+
* @param options - 导出选项
|
|
190
|
+
* @returns 包含内联 CSS 的 HTML 字符串
|
|
191
|
+
*/
|
|
192
|
+
declare function generateExportHTMLWithInlineCSS(katexCSS: string, svgContent: string, options: Pick<ExportOptions, 'width' | 'height' | 'background'>): string;
|
|
193
|
+
|
|
194
|
+
export { type ExportFormat, type ExportOptions, type ExportResult, PlaywrightExporter, type PlaywrightExporterOptions, type SceneExportOptions, exportSVGToPNG, exportToPNG, generateExportHTML, generateExportHTMLWithInlineCSS };
|
package/dist/export.d.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { D as Diagram, S as Scene } from './diagram-Djxa_kGR.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @locusing/export - 类型定义
|
|
5
|
+
*
|
|
6
|
+
* Playwright 图片导出相关类型
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 导出格式
|
|
10
|
+
*/
|
|
11
|
+
type ExportFormat = 'png' | 'jpeg' | 'webp';
|
|
12
|
+
/**
|
|
13
|
+
* 导出选项
|
|
14
|
+
*/
|
|
15
|
+
interface ExportOptions {
|
|
16
|
+
/** 输出格式,默认 'png' */
|
|
17
|
+
format?: ExportFormat;
|
|
18
|
+
/** 图片质量 (0-100),仅对 jpeg/webp 有效,默认 90 */
|
|
19
|
+
quality?: number;
|
|
20
|
+
/** 像素密度 (1 = 72dpi, 2 = 144dpi),默认 2 */
|
|
21
|
+
deviceScaleFactor?: number;
|
|
22
|
+
/** 画布宽度 (像素),默认 1920 */
|
|
23
|
+
width?: number;
|
|
24
|
+
/** 画布高度 (像素),默认 1080 */
|
|
25
|
+
height?: number;
|
|
26
|
+
/** 背景色,默认透明 */
|
|
27
|
+
background?: string;
|
|
28
|
+
/** 是否等待字体加载,默认 true */
|
|
29
|
+
waitForFonts?: boolean;
|
|
30
|
+
/** 渲染等待时间 (毫秒),默认 100 */
|
|
31
|
+
renderDelay?: number;
|
|
32
|
+
/** 是否使用 Frame 模式,默认 true */
|
|
33
|
+
frame?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 导出结果
|
|
37
|
+
*/
|
|
38
|
+
interface ExportResult {
|
|
39
|
+
/** 图片 Buffer */
|
|
40
|
+
buffer: Buffer;
|
|
41
|
+
/** MIME 类型 */
|
|
42
|
+
mimeType: string;
|
|
43
|
+
/** 实际宽度 (像素) */
|
|
44
|
+
width: number;
|
|
45
|
+
/** 实际高度 (像素) */
|
|
46
|
+
height: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* PlaywrightExporter 配置
|
|
50
|
+
*/
|
|
51
|
+
interface PlaywrightExporterOptions {
|
|
52
|
+
/** 是否使用无头模式,默认 true */
|
|
53
|
+
headless?: boolean;
|
|
54
|
+
/** 浏览器类型,默认 'chromium' */
|
|
55
|
+
browser?: 'chromium' | 'firefox' | 'webkit';
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Scene 导出选项
|
|
59
|
+
*/
|
|
60
|
+
interface SceneExportOptions extends ExportOptions {
|
|
61
|
+
/** 导出特定帧的时间点 (秒),默认 0 (第一帧) */
|
|
62
|
+
frameTime?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @locusing/export - Playwright 导出器
|
|
67
|
+
*
|
|
68
|
+
* 使用 Playwright 截图实现高保真图片导出
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Playwright 导出器
|
|
73
|
+
*
|
|
74
|
+
* 使用真实浏览器渲染 SVG 并截图,确保与浏览器显示效果完全一致。
|
|
75
|
+
* 支持 TeX 公式等复杂内容的导出。
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { PlaywrightExporter, circle, tex, combine } from 'locusing';
|
|
80
|
+
*
|
|
81
|
+
* const exporter = new PlaywrightExporter();
|
|
82
|
+
* await exporter.launch();
|
|
83
|
+
*
|
|
84
|
+
* const diagram = combine(
|
|
85
|
+
* circle(1).fill('#EA580C'),
|
|
86
|
+
* tex('E = mc^2').move([0, -2])
|
|
87
|
+
* );
|
|
88
|
+
*
|
|
89
|
+
* const result = await exporter.exportDiagram(diagram, {
|
|
90
|
+
* width: 1920,
|
|
91
|
+
* height: 1080,
|
|
92
|
+
* deviceScaleFactor: 2,
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* await fs.writeFile('output.png', result.buffer);
|
|
96
|
+
* await exporter.close();
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare class PlaywrightExporter {
|
|
100
|
+
private browser;
|
|
101
|
+
private page;
|
|
102
|
+
private options;
|
|
103
|
+
constructor(options?: PlaywrightExporterOptions);
|
|
104
|
+
/**
|
|
105
|
+
* 启动浏览器
|
|
106
|
+
*
|
|
107
|
+
* @throws 如果 Playwright 未安装
|
|
108
|
+
*/
|
|
109
|
+
launch(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* 关闭浏览器
|
|
112
|
+
*/
|
|
113
|
+
close(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* 获取页面实例,确保已启动
|
|
116
|
+
*/
|
|
117
|
+
private getPage;
|
|
118
|
+
/**
|
|
119
|
+
* 导出 Diagram 为图片
|
|
120
|
+
*
|
|
121
|
+
* @param diagram - 要导出的 Diagram
|
|
122
|
+
* @param options - 导出选项
|
|
123
|
+
* @returns 导出结果
|
|
124
|
+
*/
|
|
125
|
+
exportDiagram(diagram: Diagram, options?: ExportOptions): Promise<ExportResult>;
|
|
126
|
+
/**
|
|
127
|
+
* 导出 Scene 为图片(静态帧)
|
|
128
|
+
*
|
|
129
|
+
* @param SceneClass - Scene 类
|
|
130
|
+
* @param options - 导出选项
|
|
131
|
+
* @returns 导出结果
|
|
132
|
+
*/
|
|
133
|
+
exportScene(SceneClass: new () => Scene, options?: SceneExportOptions): Promise<ExportResult>;
|
|
134
|
+
/**
|
|
135
|
+
* 导出 SVG 字符串为图片
|
|
136
|
+
*
|
|
137
|
+
* @param svgString - SVG 字符串
|
|
138
|
+
* @param options - 导出选项
|
|
139
|
+
* @returns 导出结果
|
|
140
|
+
*/
|
|
141
|
+
exportSVGString(svgString: string, options?: ExportOptions): Promise<ExportResult>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 便捷函数:一次性导出 Diagram 为 PNG
|
|
145
|
+
*
|
|
146
|
+
* @param diagram - 要导出的 Diagram
|
|
147
|
+
* @param outputPath - 输出文件路径
|
|
148
|
+
* @param options - 导出选项
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* import { exportToPNG, circle } from 'locusing';
|
|
153
|
+
*
|
|
154
|
+
* await exportToPNG(circle(1).fill('#EA580C'), 'circle.png', {
|
|
155
|
+
* width: 800,
|
|
156
|
+
* height: 600
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function exportToPNG(diagram: Diagram, outputPath: string, options?: ExportOptions): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* 便捷函数:一次性导出 SVG 字符串为 PNG
|
|
163
|
+
*
|
|
164
|
+
* @param svgString - SVG 字符串
|
|
165
|
+
* @param outputPath - 输出文件路径
|
|
166
|
+
* @param options - 导出选项
|
|
167
|
+
*/
|
|
168
|
+
declare function exportSVGToPNG(svgString: string, outputPath: string, options?: ExportOptions): Promise<void>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @locusing/export - HTML 模板生成
|
|
172
|
+
*
|
|
173
|
+
* 生成用于 Playwright 截图的 HTML 页面
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 生成导出用的 HTML 模板
|
|
178
|
+
*
|
|
179
|
+
* @param svgContent - SVG 字符串内容
|
|
180
|
+
* @param options - 导出选项
|
|
181
|
+
* @returns 完整的 HTML 字符串
|
|
182
|
+
*/
|
|
183
|
+
declare function generateExportHTML(svgContent: string, options: Pick<ExportOptions, 'width' | 'height' | 'background'>): string;
|
|
184
|
+
/**
|
|
185
|
+
* 内联 KaTeX CSS(用于离线导出)
|
|
186
|
+
*
|
|
187
|
+
* @param katexCSS - KaTeX CSS 内容
|
|
188
|
+
* @param svgContent - SVG 字符串内容
|
|
189
|
+
* @param options - 导出选项
|
|
190
|
+
* @returns 包含内联 CSS 的 HTML 字符串
|
|
191
|
+
*/
|
|
192
|
+
declare function generateExportHTMLWithInlineCSS(katexCSS: string, svgContent: string, options: Pick<ExportOptions, 'width' | 'height' | 'background'>): string;
|
|
193
|
+
|
|
194
|
+
export { type ExportFormat, type ExportOptions, type ExportResult, PlaywrightExporter, type PlaywrightExporterOptions, type SceneExportOptions, exportSVGToPNG, exportToPNG, generateExportHTML, generateExportHTMLWithInlineCSS };
|