office-open 0.11.0 → 0.12.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.
@@ -2,7 +2,6 @@ import { DocumentOptions } from "@office-open/docx";
2
2
  import { PresentationOptions } from "@office-open/pptx";
3
3
  import { WorkbookOptions } from "@office-open/xlsx";
4
4
  import { OutputType, OutputType as OutputType$1 } from "@office-open/core";
5
-
6
5
  //#region src/generate.d.ts
7
6
  type GenerateType = "docx" | "pptx" | "xlsx";
8
7
  interface GenerateOptionsMap {
@@ -1 +1 @@
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;EACxD,IAAA,EAAM,CAAA;EACN,OAAA,EAAS,kBAAA,CAAmB,CAAA;EAC5B,UAAA,GAAa,YAAA;AAAA;AAAA,iBAGO,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"}
1
+ {"version":3,"file":"generate.d.mts","names":[],"sources":["../src/generate.ts"],"mappings":";;;;;KAYY;UAGK;EACf,MAAM;EACN,MAAM;EACN,MAAM;;UAGS,gBAAgB,UAAU,eAAe;EACxD,MAAM;EACN,SAAS,mBAAmB;EAC5B,aAAa;;iBAGO,SAAS,UAAU,cACvC,SAAS,gBAAgB,KACxB;iBAuBmB,WAAW,gBAAgB,QAAQ;iBASnC,eAAe,oBAAoB,SAAS,kBAAkB"}
package/dist/generate.mjs CHANGED
@@ -19,10 +19,11 @@ async function parseInput(input) {
19
19
  return JSON.parse(content);
20
20
  }
21
21
  async function generateToFile(outputPath, options) {
22
- await writeFile(outputPath, await generate({
22
+ const buffer = await generate({
23
23
  ...options,
24
24
  outputType: "nodebuffer"
25
- }));
25
+ });
26
+ await writeFile(outputPath, buffer);
26
27
  }
27
28
  //#endregion
28
29
  export { generate, generateToFile, parseInput };
@@ -1 +1 @@
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 type: T;\n options: GenerateOptionsMap[T];\n 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"}
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 type: T;\n options: GenerateOptionsMap[T];\n 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;CAChG,MAAM,SAAU,MAAM,SAAS;EAAE,GAAG;EAAS,YAAY;CAAa,CAAC;CACvE,MAAM,UAAU,YAAY,MAAM;AACpC"}
@@ -1,5 +1,4 @@
1
1
  import { a as pptxSchema, i as docxSchema, n as JsonSchema, o as validateDocumentInput, r as SCHEMAS, s as xlsxSchema, t as DocumentType } from "../schemas-Dupoq6xM.mjs";
2
-
3
2
  //#region src/schemas/entries.d.ts
4
3
  interface SchemaEntry {
5
4
  name: string;
@@ -10,6 +9,12 @@ declare const SCHEMA_ROOTS: Record<DocumentType, string>;
10
9
  declare const SCHEMA_ENTRIES: Readonly<Record<DocumentType, readonly SchemaEntry[]>>;
11
10
  declare function entryNames(type: DocumentType): ReadonlySet<string>;
12
11
  //#endregion
12
+ //#region src/schemas/pointer.d.ts
13
+ type Node = Record<string, unknown>;
14
+ declare function isPropertyPointer(ref: string): boolean;
15
+ declare function pointerHost(ref: string): string;
16
+ declare function resolvePointer(root: Node, ref: string): Node | undefined;
17
+ //#endregion
13
18
  //#region src/schemas/slice.d.ts
14
19
  declare class UnknownDefinitionError extends Error {
15
20
  readonly suggestions: readonly string[];
@@ -22,5 +27,8 @@ declare function assertKnownDefinitions(type: DocumentType, definitions: readonl
22
27
  //#region src/schemas/skeleton.d.ts
23
28
  declare function getSkeletonSchema(type: DocumentType): JsonSchema;
24
29
  //#endregion
25
- export { DocumentType, JsonSchema, SCHEMAS, SCHEMA_ENTRIES, SCHEMA_ROOTS, SchemaEntry, UnknownDefinitionError, assertKnownDefinitions, docxSchema, entryNames, getSkeletonSchema, pptxSchema, sliceDocumentSchema, sliceSchema, validateDocumentInput, xlsxSchema };
30
+ //#region src/schemas/type-text.d.ts
31
+ declare function renderSliceTypeText(format: DocumentType, requested: readonly string[], slice: JsonSchema): string;
32
+ //#endregion
33
+ export { DocumentType, JsonSchema, SCHEMAS, SCHEMA_ENTRIES, SCHEMA_ROOTS, SchemaEntry, UnknownDefinitionError, assertKnownDefinitions, docxSchema, entryNames, getSkeletonSchema, isPropertyPointer, pointerHost, pptxSchema, renderSliceTypeText, resolvePointer, sliceDocumentSchema, sliceSchema, validateDocumentInput, xlsxSchema };
26
34
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/schemas/entries.ts","../../src/schemas/slice.ts","../../src/schemas/skeleton.ts"],"mappings":";;;UAqBiB,WAAA;EAEf,IAAA;EAEA,MAAA;EAEA,OAAA;AAAA;AAAA,cAIW,YAAA,EAAc,MAAM,CAAC,YAAA;AAAA,cAkSrB,cAAA,EAAgB,QAAA,CAAS,MAAA,CAAO,YAAA,WAAuB,WAAA;AAAA,iBAOpD,UAAA,CAAW,IAAA,EAAM,YAAA,GAAe,WAAW;;;cCnT9C,sBAAA,SAA+B,KAAK;EAAA,SACtC,WAAA;cACG,KAAA,qBAA0B,WAAA;AAAA;AAAA,iBA8CxB,WAAA,CACd,MAAA,EAAQ,UAAA,EACR,WAAA,qBACA,MAAA,GAAS,YAAA,GACR,UAAA;AAAA,iBA4Ca,mBAAA,CACd,IAAA,EAAM,YAAA,EACN,WAAA,sBACC,UAAU;AAAA,iBAKG,sBAAA,CAAuB,IAAA,EAAM,YAAY,EAAE,WAAA;;;iBC0D3C,iBAAA,CAAkB,IAAA,EAAM,YAAA,GAAe,UAAU"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/schemas/entries.ts","../../src/schemas/pointer.ts","../../src/schemas/slice.ts","../../src/schemas/skeleton.ts","../../src/schemas/type-text.ts"],"mappings":";;UAqBiB;EAEf;EAEA;EAEA;;cAIW,cAAc,OAAO;cA6ZrB,gBAAgB,SAAS,OAAO,uBAAuB;iBAOpD,WAAW,MAAM,eAAe;;;KCvb3C,OAAO;iBAaI,kBAAkB;iBAKlB,YAAY;iBAMZ,eAAe,MAAM,MAAM,cAAc;;;cCZ5C,+BAA+B;WACjC;EACG,YAAA,0BAA0B;;iBAkExB,YACd,QAAQ,YACR,gCACA,SAAS,eACR;iBA+Da,oBACd,MAAM,cACN,iCACC;iBAmCa,uBAAuB,MAAM,cAAc;;;iBCH3C,kBAAkB,MAAM,eAAe;;;iBCjEvC,oBACd,QAAQ,cACR,8BACA,OAAO"}
@@ -1,2 +1,2 @@
1
- import { a as sliceSchema, c as entryNames, d as pptxSchema, f as validateDocumentInput, i as sliceDocumentSchema, l as SCHEMAS, n as UnknownDefinitionError, o as SCHEMA_ENTRIES, p as xlsxSchema, r as assertKnownDefinitions, s as SCHEMA_ROOTS, t as getSkeletonSchema, u as docxSchema } from "../schemas-BKyaDGmp.mjs";
2
- export { SCHEMAS, SCHEMA_ENTRIES, SCHEMA_ROOTS, UnknownDefinitionError, assertKnownDefinitions, docxSchema, entryNames, getSkeletonSchema, pptxSchema, sliceDocumentSchema, sliceSchema, validateDocumentInput, xlsxSchema };
1
+ import { _ as xlsxSchema, a as sliceDocumentSchema, c as pointerHost, d as SCHEMA_ROOTS, f as entryNames, g as validateDocumentInput, h as pptxSchema, i as assertKnownDefinitions, l as resolvePointer, m as docxSchema, n as getSkeletonSchema, o as sliceSchema, p as SCHEMAS, r as UnknownDefinitionError, s as isPropertyPointer, t as renderSliceTypeText, u as SCHEMA_ENTRIES } from "../schemas-DhCWsZ8v.mjs";
2
+ export { SCHEMAS, SCHEMA_ENTRIES, SCHEMA_ROOTS, UnknownDefinitionError, assertKnownDefinitions, docxSchema, entryNames, getSkeletonSchema, isPropertyPointer, pointerHost, pptxSchema, renderSliceTypeText, resolvePointer, sliceDocumentSchema, sliceSchema, validateDocumentInput, xlsxSchema };