@aalis/plugin-office 0.1.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.
- package/README.md +21 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +24 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +38 -0
- package/dist/session.js.map +1 -0
- package/dist/tools/docx.d.ts +5 -0
- package/dist/tools/docx.d.ts.map +1 -0
- package/dist/tools/docx.js +640 -0
- package/dist/tools/docx.js.map +1 -0
- package/dist/tools/pdf.d.ts +6 -0
- package/dist/tools/pdf.d.ts.map +1 -0
- package/dist/tools/pdf.js +241 -0
- package/dist/tools/pdf.js.map +1 -0
- package/dist/tools/pptx.d.ts +5 -0
- package/dist/tools/pptx.d.ts.map +1 -0
- package/dist/tools/pptx.js +940 -0
- package/dist/tools/pptx.js.map +1 -0
- package/dist/tools/xlsx.d.ts +5 -0
- package/dist/tools/xlsx.d.ts.map +1 -0
- package/dist/tools/xlsx.js +509 -0
- package/dist/tools/xlsx.js.map +1 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +44 -0
- package/dist/utils.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @aalis/plugin-office
|
|
2
|
+
|
|
3
|
+
运行时插件
|
|
4
|
+
|
|
5
|
+
## 角色
|
|
6
|
+
|
|
7
|
+
运行时插件
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @aalis/plugin-office
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 文档
|
|
16
|
+
|
|
17
|
+
详见 [docs/plugins/plugin-office.md](../../docs/plugins/plugin-office.md)。
|
|
18
|
+
|
|
19
|
+
## 许可
|
|
20
|
+
|
|
21
|
+
见仓库根目录 LICENSE。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ConfigSchema, Context } from '@aalis/core';
|
|
2
|
+
import '@aalis/plugin-tools-api';
|
|
3
|
+
export declare const name = "@aalis/plugin-office";
|
|
4
|
+
export declare const displayName = "Office \u6587\u6863\u5DE5\u5177";
|
|
5
|
+
export declare const subsystem = "tools";
|
|
6
|
+
export declare const inject: {
|
|
7
|
+
required: string[];
|
|
8
|
+
optional: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare const configSchema: ConfigSchema;
|
|
11
|
+
export declare const defaultConfig: {
|
|
12
|
+
outputDir: string;
|
|
13
|
+
docx: {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
};
|
|
16
|
+
xlsx: {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
};
|
|
19
|
+
pptx: {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
};
|
|
22
|
+
pdf: {
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare function apply(ctx: Context, config: Record<string, unknown>): void;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AASzD,OAAO,yBAAyB,CAAC;AAIjC,eAAO,MAAM,IAAI,yBAAyB,CAAC;AAC3C,eAAO,MAAM,WAAW,oCAAgB,CAAC;AACzC,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,MAAM;;;CAGlB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,YA8B1B,CAAC;AAEF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;CAMzB,CAAC;AAcF,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CA4CzE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createProcessGateway } from '@aalis/plugin-process-api';
|
|
2
|
+
import { createStorageGateway } from '@aalis/plugin-storage-api';
|
|
3
|
+
import { toolsWithGroups, useToolService } from '@aalis/plugin-tools-api';
|
|
4
|
+
import { DocSessionManager } from './session.js';
|
|
5
|
+
import { registerDocxTools } from './tools/docx.js';
|
|
6
|
+
import { registerPdfTools } from './tools/pdf.js';
|
|
7
|
+
import { registerPptTools } from './tools/pptx.js';
|
|
8
|
+
import { registerExcelTools } from './tools/xlsx.js';
|
|
9
|
+
import '@aalis/plugin-tools-api';
|
|
10
|
+
// ===== 插件元数据 =====
|
|
11
|
+
export const name = '@aalis/plugin-office';
|
|
12
|
+
export const displayName = 'Office 文档工具';
|
|
13
|
+
export const subsystem = 'tools';
|
|
14
|
+
export const inject = {
|
|
15
|
+
required: ['storage', 'tools'],
|
|
16
|
+
optional: ['process'],
|
|
17
|
+
};
|
|
18
|
+
export const configSchema = {
|
|
19
|
+
outputDir: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
label: '输出目录',
|
|
22
|
+
description: '文档保存目录(storage URI,如 workspace:/ 或 data:/docs),也兼容裸名「workspace」/「data」。',
|
|
23
|
+
},
|
|
24
|
+
docx: {
|
|
25
|
+
label: 'Word 文档',
|
|
26
|
+
fields: {
|
|
27
|
+
enabled: { type: 'boolean', label: '启用 Word 工具', default: true },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
xlsx: {
|
|
31
|
+
label: 'Excel 工作簿',
|
|
32
|
+
fields: {
|
|
33
|
+
enabled: { type: 'boolean', label: '启用 Excel 工具', default: true },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
pptx: {
|
|
37
|
+
label: 'PPT 演示文稿',
|
|
38
|
+
fields: {
|
|
39
|
+
enabled: { type: 'boolean', label: '启用 PPT 工具', default: true },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
pdf: {
|
|
43
|
+
label: 'PDF 文档',
|
|
44
|
+
fields: {
|
|
45
|
+
enabled: { type: 'boolean', label: '启用 PDF 工具', default: true },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
export const defaultConfig = {
|
|
50
|
+
outputDir: 'workspace:/',
|
|
51
|
+
docx: { enabled: true },
|
|
52
|
+
xlsx: { enabled: true },
|
|
53
|
+
pptx: { enabled: true },
|
|
54
|
+
pdf: { enabled: true },
|
|
55
|
+
};
|
|
56
|
+
// ===== 插件入口 =====
|
|
57
|
+
export function apply(ctx, config) {
|
|
58
|
+
const cfg = resolveConfig(config);
|
|
59
|
+
const storage = createStorageGateway(ctx);
|
|
60
|
+
// 兼容 裸名/相对路径 → storage URI
|
|
61
|
+
function toUri(input) {
|
|
62
|
+
if (input.includes(':/'))
|
|
63
|
+
return input;
|
|
64
|
+
const s = input.trim().replace(/^\.?\/+/, '');
|
|
65
|
+
const idx = s.indexOf('/');
|
|
66
|
+
return idx > 0 ? `${s.slice(0, idx)}:/${s.slice(idx + 1)}` : `${s}:/`;
|
|
67
|
+
}
|
|
68
|
+
const outputUri = toUri(cfg.outputDir);
|
|
69
|
+
const sessions = new DocSessionManager();
|
|
70
|
+
const baseTools = useToolService(ctx);
|
|
71
|
+
baseTools.registerGroup({
|
|
72
|
+
name: 'office',
|
|
73
|
+
label: 'Office 文档工具',
|
|
74
|
+
description: '创建和编辑 Word、Excel、PPT、PDF 文档',
|
|
75
|
+
});
|
|
76
|
+
const tools = toolsWithGroups(baseTools, ['office']);
|
|
77
|
+
if (cfg.docx.enabled) {
|
|
78
|
+
registerDocxTools(tools, sessions, storage, outputUri);
|
|
79
|
+
ctx.logger.info('Word (docx) 工具已启用');
|
|
80
|
+
}
|
|
81
|
+
if (cfg.xlsx.enabled) {
|
|
82
|
+
registerExcelTools(tools, sessions, storage, outputUri);
|
|
83
|
+
ctx.logger.info('Excel (xlsx) 工具已启用');
|
|
84
|
+
}
|
|
85
|
+
if (cfg.pptx.enabled) {
|
|
86
|
+
registerPptTools(tools, sessions, storage, outputUri);
|
|
87
|
+
ctx.logger.info('PPT (pptx) 工具已启用');
|
|
88
|
+
}
|
|
89
|
+
if (cfg.pdf.enabled) {
|
|
90
|
+
const proc = ctx.hasService('process') ? createProcessGateway(ctx) : undefined;
|
|
91
|
+
registerPdfTools(tools, sessions, storage, outputUri, proc);
|
|
92
|
+
ctx.logger.info('PDF 工具已启用');
|
|
93
|
+
}
|
|
94
|
+
ctx.logger.info(`Office 文档工具插件已启动 (输出 URI: ${outputUri})`);
|
|
95
|
+
}
|
|
96
|
+
// ===== 辅助函数 =====
|
|
97
|
+
function resolveConfig(config) {
|
|
98
|
+
const docx = config.docx;
|
|
99
|
+
const xlsx = config.xlsx;
|
|
100
|
+
const pptx = config.pptx;
|
|
101
|
+
const pdf = config.pdf;
|
|
102
|
+
return {
|
|
103
|
+
outputDir: String(config.outputDir || 'workspace:/'),
|
|
104
|
+
docx: { enabled: docx?.enabled !== false },
|
|
105
|
+
xlsx: { enabled: xlsx?.enabled !== false },
|
|
106
|
+
pptx: { enabled: pptx?.enabled !== false },
|
|
107
|
+
pdf: { enabled: pdf?.enabled !== false },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,C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AAC,MAA+B;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,IAA2C,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,IAA2C,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,IAA2C,CAAC;IAChE,MAAM,GAAG,GAAG,MAAM,CAAC,GAA0C,CAAC;IAC9D,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,IAAI,aAAa,CAAC;QACpD,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,KAAK,EAAE;QAC1C,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,KAAK,EAAE;QAC1C,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,KAAK,EAAE;QAC1C,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,KAAK,EAAE;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type DocType = 'docx' | 'xlsx' | 'pptx' | 'pdf';
|
|
2
|
+
export interface DocSession {
|
|
3
|
+
id: string;
|
|
4
|
+
type: DocType;
|
|
5
|
+
filename: string;
|
|
6
|
+
/** 底层文档对象(docx.Document / ExcelJS.Workbook / pptxgen) */
|
|
7
|
+
doc: unknown;
|
|
8
|
+
createdAt: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 管理内存中的文档会话。
|
|
12
|
+
* create 返回 docId,后续操作引用该 ID,save 后释放。
|
|
13
|
+
*/
|
|
14
|
+
export declare class DocSessionManager {
|
|
15
|
+
private sessions;
|
|
16
|
+
create(type: DocType, filename: string, doc: unknown): string;
|
|
17
|
+
get(id: string): DocSession | undefined;
|
|
18
|
+
getByType<T>(id: string, type: DocType): T | undefined;
|
|
19
|
+
remove(id: string): boolean;
|
|
20
|
+
list(): DocSession[];
|
|
21
|
+
/** 获取会话或抛出错误(简化工具代码) */
|
|
22
|
+
require(id: string, expectedType?: DocType): DocSession;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAEvD,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,GAAG,EAAE,OAAO,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAiC;IAEjD,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM;IAM7D,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIvC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,CAAC,GAAG,SAAS;IAMtD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B,IAAI,IAAI,UAAU,EAAE;IAIpB,wBAAwB;IACxB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,UAAU;CAQxD"}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 管理内存中的文档会话。
|
|
3
|
+
* create 返回 docId,后续操作引用该 ID,save 后释放。
|
|
4
|
+
*/
|
|
5
|
+
export class DocSessionManager {
|
|
6
|
+
sessions = new Map();
|
|
7
|
+
create(type, filename, doc) {
|
|
8
|
+
const id = `doc-${crypto.randomUUID().slice(0, 8)}`;
|
|
9
|
+
this.sessions.set(id, { id, type, filename, doc, createdAt: Date.now() });
|
|
10
|
+
return id;
|
|
11
|
+
}
|
|
12
|
+
get(id) {
|
|
13
|
+
return this.sessions.get(id);
|
|
14
|
+
}
|
|
15
|
+
getByType(id, type) {
|
|
16
|
+
const session = this.sessions.get(id);
|
|
17
|
+
if (!session || session.type !== type)
|
|
18
|
+
return undefined;
|
|
19
|
+
return session.doc;
|
|
20
|
+
}
|
|
21
|
+
remove(id) {
|
|
22
|
+
return this.sessions.delete(id);
|
|
23
|
+
}
|
|
24
|
+
list() {
|
|
25
|
+
return [...this.sessions.values()];
|
|
26
|
+
}
|
|
27
|
+
/** 获取会话或抛出错误(简化工具代码) */
|
|
28
|
+
require(id, expectedType) {
|
|
29
|
+
const session = this.sessions.get(id);
|
|
30
|
+
if (!session)
|
|
31
|
+
throw new Error(`文档不存在: ${id}`);
|
|
32
|
+
if (expectedType && session.type !== expectedType) {
|
|
33
|
+
throw new Error(`文档类型不匹配: 期望 ${expectedType},实际 ${session.type}`);
|
|
34
|
+
}
|
|
35
|
+
return session;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACpB,QAAQ,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEjD,MAAM,CAAC,IAAa,EAAE,QAAgB,EAAE,GAAY;QAClD,MAAM,EAAE,GAAG,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1E,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,SAAS,CAAI,EAAU,EAAE,IAAa;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC;QACxD,OAAO,OAAO,CAAC,GAAQ,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,EAAU;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAED,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,wBAAwB;IACxB,OAAO,CAAC,EAAU,EAAE,YAAsB;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,YAAY,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,eAAe,YAAY,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StorageService } from '@aalis/plugin-storage-api';
|
|
2
|
+
import type { ScopedToolService } from '@aalis/plugin-tools-api';
|
|
3
|
+
import type { DocSessionManager } from '../session.js';
|
|
4
|
+
export declare function registerDocxTools(tools: ScopedToolService, sessions: DocSessionManager, storage: StorageService, outputUri: string): void;
|
|
5
|
+
//# sourceMappingURL=docx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docx.d.ts","sourceRoot":"","sources":["../../src/tools/docx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAsBjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAuGvD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,QAsmBlB"}
|