office-open 0.8.1 → 0.9.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 +3 -3
- package/dist/ai/index.d.mts.map +1 -1
- package/dist/ai/index.mjs.map +1 -1
- package/dist/generate.d.mts +13 -5
- package/dist/generate.d.mts.map +1 -1
- package/dist/generate.mjs +9 -19
- package/dist/generate.mjs.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -87,9 +87,9 @@ try {
|
|
|
87
87
|
### Import from Sub-Packages
|
|
88
88
|
|
|
89
89
|
```typescript
|
|
90
|
-
import {
|
|
91
|
-
import {
|
|
92
|
-
import {
|
|
90
|
+
import { generateDocument, parseDocument, patchDocument } from "office-open/docx";
|
|
91
|
+
import { generatePresentation, parsePresentation, patchPresentation } from "office-open/pptx";
|
|
92
|
+
import { generateWorkbook, parseWorkbook, patchWorkbook } from "office-open/xlsx";
|
|
93
93
|
import { convertInchesToTwip } from "office-open/core";
|
|
94
94
|
import { xml2js, js2xml } from "office-open/xml";
|
|
95
95
|
```
|
package/dist/ai/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/ai/index.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/ai/index.ts"],"mappings":";cAWa,QAAA,eAAQ,IAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsBR,QAAA,eAAQ,IAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsBR,QAAA,eAAQ,IAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsBR,eAAA;EAAA"}
|
package/dist/ai/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/ai/index.ts"],"sourcesContent":["import { tool } from \"ai\";\n\nimport { generate } from \"../generate\";\nimport { validateDocumentInput } from \"../schemas\";\nimport { docxSchema } from \"../schemas/docx\";\nimport { pptxSchema } from \"../schemas/pptx\";\nimport { xlsxSchema } from \"../schemas/xlsx\";\n\nexport const docxTool = tool({\n description:\n \"Generate a .docx Word document. \" +\n \"The input is the document options directly — must include a 'sections' array. \" +\n \"Each section has 'children' (paragraphs, tables, etc.). \" +\n \"Paragraphs use { paragraph: { children: [{ text: '...' }] }}, tables use { table: { rows: [...] } }. \" +\n \"Optional metadata: title, creator, subject, styles, numbering, comments, footnotes, endnotes, background, features.\",\n inputSchema: docxSchema,\n execute: async (options) => {\n const validated = validateDocumentInput(\"docx\", options);\n const base64 = (await generate({\n type: \"docx\",\n options: validated,\n outputType: \"base64\",\n })) as string;\n return {\n base64,\n mimeType: \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n };\n },\n});\n\nexport const pptxTool = tool({\n description:\n \"Generate a .pptx PowerPoint presentation. \" +\n \"The input is the document options directly — must include a 'slides' array. \" +\n \"Each slide has 'children' (shapes, pictures, tables, charts, groups, etc.). \" +\n \"Shapes use { shape: { x, y, width, height, text?, fill?, ... } }. \" +\n \"Optional: size ('16:9' or '4:3' or { width, height }), title, creator, masters, show.\",\n inputSchema: pptxSchema,\n execute: async (options) => {\n const validated = validateDocumentInput(\"pptx\", options);\n const base64 = (await generate({\n type: \"pptx\",\n options: validated,\n outputType: \"base64\",\n })) as string;\n return {\n base64,\n mimeType: \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n };\n },\n});\n\nexport const xlsxTool = tool({\n description:\n \"Generate a .xlsx Excel spreadsheet. \" +\n \"The input is the document options directly — must include a 'worksheets' array. \" +\n \"Each worksheet has 'rows' — an array of row objects, each with 'cells'. \" +\n \"Cell values: string, number, boolean. Use 'style' for formatting. \" +\n \"Optional: columns, mergeCells, freezePanes, autoFilter, images, charts, dataValidations, conditionalFormats.\",\n inputSchema: xlsxSchema,\n execute: async (options) => {\n const validated = validateDocumentInput(\"xlsx\", options);\n const base64 = (await generate({\n type: \"xlsx\",\n options: validated,\n outputType: \"base64\",\n })) as string;\n return {\n base64,\n mimeType: \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n };\n },\n});\n\nexport const officeOpenTools = {\n \"generate-docx\": docxTool,\n \"generate-pptx\": pptxTool,\n \"generate-xlsx\": xlsxTool,\n} as const;\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/ai/index.ts"],"sourcesContent":["import type { DocumentOptions } from \"@office-open/docx\";\nimport type { PresentationOptions } from \"@office-open/pptx\";\nimport type { WorkbookOptions } from \"@office-open/xlsx\";\nimport { tool } from \"ai\";\n\nimport { generate } from \"../generate\";\nimport { validateDocumentInput } from \"../schemas\";\nimport { docxSchema } from \"../schemas/docx\";\nimport { pptxSchema } from \"../schemas/pptx\";\nimport { xlsxSchema } from \"../schemas/xlsx\";\n\nexport const docxTool = tool({\n description:\n \"Generate a .docx Word document. \" +\n \"The input is the document options directly — must include a 'sections' array. \" +\n \"Each section has 'children' (paragraphs, tables, etc.). \" +\n \"Paragraphs use { paragraph: { children: [{ text: '...' }] }}, tables use { table: { rows: [...] } }. \" +\n \"Optional metadata: title, creator, subject, styles, numbering, comments, footnotes, endnotes, background, features.\",\n inputSchema: docxSchema,\n execute: async (options) => {\n const validated = validateDocumentInput(\"docx\", options);\n const base64 = (await generate({\n type: \"docx\",\n options: validated as unknown as DocumentOptions,\n outputType: \"base64\",\n })) as string;\n return {\n base64,\n mimeType: \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n };\n },\n});\n\nexport const pptxTool = tool({\n description:\n \"Generate a .pptx PowerPoint presentation. \" +\n \"The input is the document options directly — must include a 'slides' array. \" +\n \"Each slide has 'children' (shapes, pictures, tables, charts, groups, etc.). \" +\n \"Shapes use { shape: { x, y, width, height, text?, fill?, ... } }. \" +\n \"Optional: size ('16:9' or '4:3' or { width, height }), title, creator, masters, show.\",\n inputSchema: pptxSchema,\n execute: async (options) => {\n const validated = validateDocumentInput(\"pptx\", options);\n const base64 = (await generate({\n type: \"pptx\",\n options: validated as PresentationOptions,\n outputType: \"base64\",\n })) as string;\n return {\n base64,\n mimeType: \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n };\n },\n});\n\nexport const xlsxTool = tool({\n description:\n \"Generate a .xlsx Excel spreadsheet. \" +\n \"The input is the document options directly — must include a 'worksheets' array. \" +\n \"Each worksheet has 'rows' — an array of row objects, each with 'cells'. \" +\n \"Cell values: string, number, boolean. Use 'style' for formatting. \" +\n \"Optional: columns, mergeCells, freezePanes, autoFilter, images, charts, dataValidations, conditionalFormats.\",\n inputSchema: xlsxSchema,\n execute: async (options) => {\n const validated = validateDocumentInput(\"xlsx\", options);\n const base64 = (await generate({\n type: \"xlsx\",\n options: validated as WorkbookOptions,\n outputType: \"base64\",\n })) as string;\n return {\n base64,\n mimeType: \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n };\n },\n});\n\nexport const officeOpenTools = {\n \"generate-docx\": docxTool,\n \"generate-pptx\": pptxTool,\n \"generate-xlsx\": xlsxTool,\n} as const;\n"],"mappings":";;;;AAWA,MAAa,WAAW,KAAK;CAC3B,aACE;CAKF,aAAa;CACb,SAAS,OAAO,YAAY;EAO1B,OAAO;GACL,QAAA,MANoB,SAAS;IAC7B,MAAM;IACN,SAHgB,sBAAsB,QAAQ,OAG7B;IACjB,YAAY;GACd,CAAC;GAGC,UAAU;EACZ;CACF;AACF,CAAC;AAED,MAAa,WAAW,KAAK;CAC3B,aACE;CAKF,aAAa;CACb,SAAS,OAAO,YAAY;EAO1B,OAAO;GACL,QAAA,MANoB,SAAS;IAC7B,MAAM;IACN,SAHgB,sBAAsB,QAAQ,OAG7B;IACjB,YAAY;GACd,CAAC;GAGC,UAAU;EACZ;CACF;AACF,CAAC;AAED,MAAa,WAAW,KAAK;CAC3B,aACE;CAKF,aAAa;CACb,SAAS,OAAO,YAAY;EAO1B,OAAO;GACL,QAAA,MANoB,SAAS;IAC7B,MAAM;IACN,SAHgB,sBAAsB,QAAQ,OAG7B;IACjB,YAAY;GACd,CAAC;GAGC,UAAU;EACZ;CACF;AACF,CAAC;AAED,MAAa,kBAAkB;CAC7B,iBAAiB;CACjB,iBAAiB;CACjB,iBAAiB;AACnB"}
|
package/dist/generate.d.mts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
import { DocumentOptions } from "@office-open/docx";
|
|
2
|
+
import { PresentationOptions } from "@office-open/pptx";
|
|
3
|
+
import { WorkbookOptions } from "@office-open/xlsx";
|
|
1
4
|
import { OutputType, OutputType as OutputType$1 } from "@office-open/core";
|
|
2
5
|
|
|
3
6
|
//#region src/generate.d.ts
|
|
4
7
|
type GenerateType = "docx" | "pptx" | "xlsx";
|
|
5
|
-
interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
interface GenerateOptionsMap {
|
|
9
|
+
docx: DocumentOptions;
|
|
10
|
+
pptx: PresentationOptions;
|
|
11
|
+
xlsx: WorkbookOptions;
|
|
12
|
+
}
|
|
13
|
+
interface GenerateOptions<T extends GenerateType = GenerateType> {
|
|
14
|
+
readonly type: T;
|
|
15
|
+
readonly options: GenerateOptionsMap[T];
|
|
8
16
|
readonly outputType?: OutputType$1;
|
|
9
17
|
}
|
|
10
|
-
declare function generate(options: GenerateOptions): Promise<unknown>;
|
|
18
|
+
declare function generate<T extends GenerateType>(options: GenerateOptions<T>): Promise<unknown>;
|
|
11
19
|
declare function parseInput(input: string): Promise<Record<string, unknown>>;
|
|
12
20
|
declare function generateToFile(outputPath: string, options: GenerateOptions): Promise<void>;
|
|
13
21
|
//#endregion
|
|
14
|
-
export { GenerateOptions, GenerateType, type OutputType, generate, generateToFile, parseInput };
|
|
22
|
+
export { GenerateOptions, GenerateOptionsMap, GenerateType, type OutputType, generate, generateToFile, parseInput };
|
|
15
23
|
//# sourceMappingURL=generate.d.mts.map
|
package/dist/generate.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.mts","names":[],"sources":["../src/generate.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.d.mts","names":[],"sources":["../src/generate.ts"],"mappings":";;;;;;KAYY,YAAA;AAAA,UAGK,kBAAA;EACf,IAAA,EAAM,eAAA;EACN,IAAA,EAAM,mBAAA;EACN,IAAA,EAAM,eAAA;AAAA;AAAA,UAGS,eAAA,WAA0B,YAAA,GAAe,YAAA;EAAA,SAC/C,IAAA,EAAM,CAAA;EAAA,SACN,OAAA,EAAS,kBAAA,CAAmB,CAAA;EAAA,SAC5B,UAAA,GAAa,YAAA;AAAA;AAAA,iBAGF,QAAA,WAAmB,YAAA,EACvC,OAAA,EAAS,eAAA,CAAgB,CAAA,IACxB,OAAA;AAAA,iBAuBmB,UAAA,CAAW,KAAA,WAAgB,OAAO,CAAC,MAAA;AAAA,iBASnC,cAAA,CAAe,UAAA,UAAoB,OAAA,EAAS,eAAA,GAAkB,OAAO"}
|
package/dist/generate.mjs
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { generateDocument } from "@office-open/docx";
|
|
3
|
+
import { generatePresentation } from "@office-open/pptx";
|
|
4
|
+
import { generateWorkbook } from "@office-open/xlsx";
|
|
5
5
|
//#region src/generate.ts
|
|
6
|
-
const PACKERS = {
|
|
7
|
-
docx: {
|
|
8
|
-
newFile: (opts) => new Document(opts),
|
|
9
|
-
pack: (file, type) => Packer.pack(file, type)
|
|
10
|
-
},
|
|
11
|
-
pptx: {
|
|
12
|
-
newFile: (opts) => new Presentation(opts),
|
|
13
|
-
pack: (file, type) => Packer$1.pack(file, type)
|
|
14
|
-
},
|
|
15
|
-
xlsx: {
|
|
16
|
-
newFile: (opts) => new Workbook(opts),
|
|
17
|
-
pack: (file, type) => Packer$2.pack(file, type)
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
6
|
async function generate(options) {
|
|
21
7
|
const { type, options: docOptions, outputType = "nodebuffer" } = options;
|
|
22
|
-
const {
|
|
23
|
-
|
|
8
|
+
const packerOpts = { type: outputType };
|
|
9
|
+
switch (type) {
|
|
10
|
+
case "docx": return generateDocument(docOptions, packerOpts);
|
|
11
|
+
case "pptx": return generatePresentation(docOptions, packerOpts);
|
|
12
|
+
case "xlsx": return generateWorkbook(docOptions, packerOpts);
|
|
13
|
+
}
|
|
24
14
|
}
|
|
25
15
|
async function parseInput(input) {
|
|
26
16
|
const trimmed = input.trim();
|
package/dist/generate.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.mjs","names":[
|
|
1
|
+
{"version":3,"file":"generate.mjs","names":[],"sources":["../src/generate.ts"],"sourcesContent":["import { readFile, writeFile } from \"node:fs/promises\";\n\nimport type { OutputType, PackerOptions } from \"@office-open/core\";\nexport { type OutputType } from \"@office-open/core\";\n\nimport { generateDocument } from \"@office-open/docx\";\nimport type { DocumentOptions } from \"@office-open/docx\";\nimport { generatePresentation } from \"@office-open/pptx\";\nimport type { PresentationOptions } from \"@office-open/pptx\";\nimport { generateWorkbook } from \"@office-open/xlsx\";\nimport type { WorkbookOptions } from \"@office-open/xlsx\";\n\nexport type GenerateType = \"docx\" | \"pptx\" | \"xlsx\";\n\n/** Map from type string to the corresponding options type. */\nexport interface GenerateOptionsMap {\n docx: DocumentOptions;\n pptx: PresentationOptions;\n xlsx: WorkbookOptions;\n}\n\nexport interface GenerateOptions<T extends GenerateType = GenerateType> {\n readonly type: T;\n readonly options: GenerateOptionsMap[T];\n readonly outputType?: OutputType;\n}\n\nexport async function generate<T extends GenerateType>(\n options: GenerateOptions<T>,\n): Promise<unknown> {\n const { type, options: docOptions, outputType = \"nodebuffer\" as OutputType } = options;\n const packerOpts = { type: outputType } as PackerOptions<OutputType>;\n\n switch (type) {\n case \"docx\":\n return generateDocument(\n docOptions as DocumentOptions,\n packerOpts as PackerOptions<\"nodebuffer\">,\n );\n case \"pptx\":\n return generatePresentation(\n docOptions as PresentationOptions,\n packerOpts as PackerOptions<\"nodebuffer\">,\n );\n case \"xlsx\":\n return generateWorkbook(\n docOptions as WorkbookOptions,\n packerOpts as PackerOptions<\"nodebuffer\">,\n );\n }\n}\n\nexport async function parseInput(input: string): Promise<Record<string, unknown>> {\n const trimmed = input.trim();\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n return JSON.parse(trimmed) as Record<string, unknown>;\n }\n const content = await readFile(trimmed, \"utf-8\");\n return JSON.parse(content) as Record<string, unknown>;\n}\n\nexport async function generateToFile(outputPath: string, options: GenerateOptions): Promise<void> {\n const buffer = (await generate({ ...options, outputType: \"nodebuffer\" })) as Buffer;\n await writeFile(outputPath, buffer);\n}\n"],"mappings":";;;;;AA2BA,eAAsB,SACpB,SACkB;CAClB,MAAM,EAAE,MAAM,SAAS,YAAY,aAAa,iBAA+B;CAC/E,MAAM,aAAa,EAAE,MAAM,WAAW;CAEtC,QAAQ,MAAR;EACE,KAAK,QACH,OAAO,iBACL,YACA,UACF;EACF,KAAK,QACH,OAAO,qBACL,YACA,UACF;EACF,KAAK,QACH,OAAO,iBACL,YACA,UACF;CACJ;AACF;AAEA,eAAsB,WAAW,OAAiD;CAChF,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GACnD,OAAO,KAAK,MAAM,OAAO;CAE3B,MAAM,UAAU,MAAM,SAAS,SAAS,OAAO;CAC/C,OAAO,KAAK,MAAM,OAAO;AAC3B;AAEA,eAAsB,eAAe,YAAoB,SAAyC;CAEhG,MAAM,UAAU,YAAY,MADN,SAAS;EAAE,GAAG;EAAS,YAAY;CAAa,CAAC,CACrC;AACpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "office-open",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Unified Office document toolkit — CLI, AI SDK tools, Zod schemas, and all packages in one install",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "Demo Macro",
|
|
23
23
|
"email": "abc@imst.xyz",
|
|
24
|
-
"url": "https://
|
|
24
|
+
"url": "https://www.demomacro.com/"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"citty": "0.2.2",
|
|
79
79
|
"zod": "4.4.3",
|
|
80
|
-
"@office-open/
|
|
81
|
-
"@office-open/core": "0.
|
|
82
|
-
"@office-open/
|
|
83
|
-
"@office-open/
|
|
84
|
-
"@office-open/
|
|
80
|
+
"@office-open/docx": "0.9.0",
|
|
81
|
+
"@office-open/core": "0.9.0",
|
|
82
|
+
"@office-open/xlsx": "0.9.0",
|
|
83
|
+
"@office-open/pptx": "0.9.0",
|
|
84
|
+
"@office-open/xml": "0.9.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"ai": "^6.0.0"
|