@sme.up/doc-alchemist 1.5.0 → 1.6.0-SNAPSHOT-20251212084649
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/dist/converters/pdf/pdfmake/layout-adapter.d.ts +16 -0
- package/dist/converters/pdf/pdfmake/layout-adapter.js +76 -0
- package/dist/converters/pdf/pdfmake/layout-adapter.js.map +1 -0
- package/dist/converters/pdf/pdfmake/pdfmake.types.d.ts +12 -0
- package/dist/converters/pdf/pdfmake/pdfmake.types.js.map +1 -1
- package/dist/converters/pdf-converter.js +2 -0
- package/dist/converters/pdf-converter.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ElementWithLayout, PdfMakeConverterContext } from "./pdfmake.types";
|
|
2
|
+
/**
|
|
3
|
+
* Adapts a layout object by converting static values to functions.
|
|
4
|
+
*
|
|
5
|
+
* This adapter function checks if the provided element contains a layout with static values
|
|
6
|
+
* for hLineWidth, vLineWidth, hLineColor, and vLineColor properties.
|
|
7
|
+
* If so, it converts them to functions as required by PDFMake:
|
|
8
|
+
* - hLineWidth and vLineWidth (numbers) are converted to: function(i) { return value; }
|
|
9
|
+
* - hLineColor and vLineColor (strings) are converted to: function(i) { return value; }
|
|
10
|
+
*
|
|
11
|
+
* All other properties of the layout are preserved.
|
|
12
|
+
*
|
|
13
|
+
* @returns A function that takes an element and returns the adapted element for PDFMake,
|
|
14
|
+
* or the original element if it does not contain a layout that needs adaptation.
|
|
15
|
+
*/
|
|
16
|
+
export declare const layoutAdapter: () => (element: unknown, _context: PdfMakeConverterContext) => Promise<ElementWithLayout>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.layoutAdapter = void 0;
|
|
4
|
+
const hasLayout = (element) => {
|
|
5
|
+
const layout = element.layout;
|
|
6
|
+
return typeof layout === "object" && layout !== null;
|
|
7
|
+
};
|
|
8
|
+
const needsLayoutAdaptation = (element) => {
|
|
9
|
+
if (!hasLayout(element)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const layout = element.layout;
|
|
13
|
+
// Check if any of the properties needs conversion
|
|
14
|
+
const needsHLineWidthConversion = layout.hLineWidth !== undefined && typeof layout.hLineWidth !== "function";
|
|
15
|
+
const needsVLineWidthConversion = layout.vLineWidth !== undefined && typeof layout.vLineWidth !== "function";
|
|
16
|
+
const needsHLineColorConversion = layout.hLineColor !== undefined && typeof layout.hLineColor !== "function";
|
|
17
|
+
const needsVLineColorConversion = layout.vLineColor !== undefined && typeof layout.vLineColor !== "function";
|
|
18
|
+
return (needsHLineWidthConversion ||
|
|
19
|
+
needsVLineWidthConversion ||
|
|
20
|
+
needsHLineColorConversion ||
|
|
21
|
+
needsVLineColorConversion);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Adapts a layout object by converting static values to functions.
|
|
25
|
+
*
|
|
26
|
+
* This adapter function checks if the provided element contains a layout with static values
|
|
27
|
+
* for hLineWidth, vLineWidth, hLineColor, and vLineColor properties.
|
|
28
|
+
* If so, it converts them to functions as required by PDFMake:
|
|
29
|
+
* - hLineWidth and vLineWidth (numbers) are converted to: function(i) { return value; }
|
|
30
|
+
* - hLineColor and vLineColor (strings) are converted to: function(i) { return value; }
|
|
31
|
+
*
|
|
32
|
+
* All other properties of the layout are preserved.
|
|
33
|
+
*
|
|
34
|
+
* @returns A function that takes an element and returns the adapted element for PDFMake,
|
|
35
|
+
* or the original element if it does not contain a layout that needs adaptation.
|
|
36
|
+
*/
|
|
37
|
+
const layoutAdapter = () => {
|
|
38
|
+
return async (element, _context) => {
|
|
39
|
+
if (!needsLayoutAdaptation(element)) {
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
const elementWithLayout = element;
|
|
43
|
+
const originalLayout = elementWithLayout.layout;
|
|
44
|
+
const adaptedLayout = { ...originalLayout };
|
|
45
|
+
// Convert hLineWidth if it's a number
|
|
46
|
+
if (originalLayout.hLineWidth !== undefined &&
|
|
47
|
+
typeof originalLayout.hLineWidth === "number") {
|
|
48
|
+
const value = originalLayout.hLineWidth;
|
|
49
|
+
adaptedLayout.hLineWidth = ((_i) => value);
|
|
50
|
+
}
|
|
51
|
+
// Convert vLineWidth if it's a number
|
|
52
|
+
if (originalLayout.vLineWidth !== undefined &&
|
|
53
|
+
typeof originalLayout.vLineWidth === "number") {
|
|
54
|
+
const value = originalLayout.vLineWidth;
|
|
55
|
+
adaptedLayout.vLineWidth = ((_i) => value);
|
|
56
|
+
}
|
|
57
|
+
// Convert hLineColor if it's a string
|
|
58
|
+
if (originalLayout.hLineColor !== undefined &&
|
|
59
|
+
typeof originalLayout.hLineColor === "string") {
|
|
60
|
+
const value = originalLayout.hLineColor;
|
|
61
|
+
adaptedLayout.hLineColor = ((_i) => value);
|
|
62
|
+
}
|
|
63
|
+
// Convert vLineColor if it's a string
|
|
64
|
+
if (originalLayout.vLineColor !== undefined &&
|
|
65
|
+
typeof originalLayout.vLineColor === "string") {
|
|
66
|
+
const value = originalLayout.vLineColor;
|
|
67
|
+
adaptedLayout.vLineColor = ((_i) => value);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
...elementWithLayout,
|
|
71
|
+
layout: adaptedLayout,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exports.layoutAdapter = layoutAdapter;
|
|
76
|
+
//# sourceMappingURL=layout-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-adapter.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/layout-adapter.ts"],"names":[],"mappings":";;;AAQA,MAAM,SAAS,GAAG,CAAC,OAAgB,EAAW,EAAE;IAC9C,MAAM,MAAM,GAAI,OAAmC,CAAC,MAAM,CAAC;IAC3D,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI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AAM,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC;YACxC,aAAa,CAAC,UAAU,GAAG,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,CAAuB,CAAC;QAC3E,CAAC;QAED,sCAAsC;QACtC,IACE,cAAc,CAAC,UAAU,KAAK,SAAS;YACvC,OAAO,cAAc,CAAC,UAAU,KAAK,QAAQ,EAC7C,CAAC;YACD,MAAM,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC;YACxC,aAAa,CAAC,UAAU,GAAG,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,CAAuB,CAAC;QAC3E,CAAC;QAED,sCAAsC;QACtC,IACE,cAAc,CAAC,UAAU,KAAK,SAAS;YACvC,OAAO,cAAc,CAAC,UAAU,KAAK,QAAQ,EAC7C,CAAC;YACD,MAAM,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC;YACxC,aAAa,CAAC,UAAU,GAAG,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,CAAwB,CAAC;QAC5E,CAAC;QAED,sCAAsC;QACtC,IACE,cAAc,CAAC,UAAU,KAAK,SAAS;YACvC,OAAO,cAAc,CAAC,UAAU,KAAK,QAAQ,EAC7C,CAAC;YACD,MAAM,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC;YACxC,aAAa,CAAC,UAAU,GAAG,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,CAAwB,CAAC;QAC5E,CAAC;QAED,OAAO;YACL,GAAG,iBAAiB;YACpB,MAAM,EAAE,aAAa;SACtB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAtDW,QAAA,aAAa,iBAsDxB","sourcesContent":["import {\n ElementWithLayout,\n Layout,\n LayoutColorFunction,\n LayoutLineFunction,\n PdfMakeConverterContext,\n} from \"./pdfmake.types\";\n\nconst hasLayout = (element: unknown): boolean => {\n const layout = (element as Record<string, unknown>).layout;\n return typeof layout === \"object\" && layout !== null;\n};\n\nconst needsLayoutAdaptation = (element: unknown): boolean => {\n if (!hasLayout(element)) {\n return false;\n }\n\n const layout = (element as ElementWithLayout).layout!;\n\n // Check if any of the properties needs conversion\n const needsHLineWidthConversion =\n layout.hLineWidth !== undefined && typeof layout.hLineWidth !== \"function\";\n const needsVLineWidthConversion =\n layout.vLineWidth !== undefined && typeof layout.vLineWidth !== \"function\";\n const needsHLineColorConversion =\n layout.hLineColor !== undefined && typeof layout.hLineColor !== \"function\";\n const needsVLineColorConversion =\n layout.vLineColor !== undefined && typeof layout.vLineColor !== \"function\";\n\n return (\n needsHLineWidthConversion ||\n needsVLineWidthConversion ||\n needsHLineColorConversion ||\n needsVLineColorConversion\n );\n};\n\n/**\n * Adapts a layout object by converting static values to functions.\n *\n * This adapter function checks if the provided element contains a layout with static values\n * for hLineWidth, vLineWidth, hLineColor, and vLineColor properties.\n * If so, it converts them to functions as required by PDFMake:\n * - hLineWidth and vLineWidth (numbers) are converted to: function(i) { return value; }\n * - hLineColor and vLineColor (strings) are converted to: function(i) { return value; }\n *\n * All other properties of the layout are preserved.\n *\n * @returns A function that takes an element and returns the adapted element for PDFMake,\n * or the original element if it does not contain a layout that needs adaptation.\n */\nexport const layoutAdapter = () => {\n return async (\n element: unknown,\n _context: PdfMakeConverterContext,\n ): Promise<ElementWithLayout> => {\n if (!needsLayoutAdaptation(element)) {\n return element as ElementWithLayout;\n }\n\n const elementWithLayout = element as ElementWithLayout;\n const originalLayout = elementWithLayout.layout!;\n const adaptedLayout: Layout = { ...originalLayout };\n\n // Convert hLineWidth if it's a number\n if (\n originalLayout.hLineWidth !== undefined &&\n typeof originalLayout.hLineWidth === \"number\"\n ) {\n const value = originalLayout.hLineWidth;\n adaptedLayout.hLineWidth = ((_i: number) => value) as LayoutLineFunction;\n }\n\n // Convert vLineWidth if it's a number\n if (\n originalLayout.vLineWidth !== undefined &&\n typeof originalLayout.vLineWidth === \"number\"\n ) {\n const value = originalLayout.vLineWidth;\n adaptedLayout.vLineWidth = ((_i: number) => value) as LayoutLineFunction;\n }\n\n // Convert hLineColor if it's a string\n if (\n originalLayout.hLineColor !== undefined &&\n typeof originalLayout.hLineColor === \"string\"\n ) {\n const value = originalLayout.hLineColor;\n adaptedLayout.hLineColor = ((_i: number) => value) as LayoutColorFunction;\n }\n\n // Convert vLineColor if it's a string\n if (\n originalLayout.vLineColor !== undefined &&\n typeof originalLayout.vLineColor === \"string\"\n ) {\n const value = originalLayout.vLineColor;\n adaptedLayout.vLineColor = ((_i: number) => value) as LayoutColorFunction;\n }\n\n return {\n ...elementWithLayout,\n layout: adaptedLayout,\n };\n };\n};\n"]}
|
|
@@ -57,4 +57,16 @@ export interface ElementWithTableExtension {
|
|
|
57
57
|
smeup?: SmeupExtensionTableMetadata;
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
+
export type LayoutLineFunction = (i: number, node?: unknown) => number;
|
|
61
|
+
export type LayoutColorFunction = (i: number, node?: unknown) => string;
|
|
62
|
+
export interface Layout {
|
|
63
|
+
hLineWidth?: number | LayoutLineFunction;
|
|
64
|
+
vLineWidth?: number | LayoutLineFunction;
|
|
65
|
+
hLineColor?: string | LayoutColorFunction;
|
|
66
|
+
vLineColor?: string | LayoutColorFunction;
|
|
67
|
+
}
|
|
68
|
+
export interface ElementWithLayout {
|
|
69
|
+
layout?: Layout;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
60
72
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfmake.types.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/pdfmake.types.ts"],"names":[],"mappings":";;;AA2CA,MAAa,YAAa,SAAQ,KAAK;IACrC,OAAO,CAAU;IACjB,YAAY,OAAe,EAAE,OAAgB;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AAPD,oCAOC","sourcesContent":["import { ContentImage, Table, TDocumentDefinitions } from \"pdfmake/interfaces\";\nimport { SmeupDataObj, WebupManagerData } from \"../../../types\";\nimport { SmeupDataStructure } from \"../../../types/data-structures/smeupDataStructure\";\nimport { SmeupDataTable } from \"../../../types/data-structures/smeupDataTable\";\n\n/**\n * Context passed to adapter functions during document processing.\n */\nexport interface PdfMakeConverterContext<\n T extends SmeupDataStructure = SmeupDataStructure,\n> {\n webupManagerData: WebupManagerData;\n pdfDocument?: TDocumentDefinitions;\n damSvcEndpoint?: string;\n getSmeupDataStructure?: (fun: string) => Promise<T>;\n fetchData?: (url: string) => Promise<Response>;\n}\n\n/**\n * Function that transforms an element from custom format to pdfmake standard format.\n * Adapters are pure functions that receive an element and context, and return the transformed element.\n * Can be synchronous or asynchronous.\n */\nexport type PdfmakeAdapter = (\n element: unknown,\n context: PdfMakeConverterContext,\n) => unknown | Promise<unknown>;\n\n/**\n * Registry interface for managing pdfmake adapters at runtime.\n */\nexport interface AdapterRegistry {\n /** Register an adapter for a specific element type */\n register: (elementType: string, adapter: PdfmakeAdapter) => void;\n /** Unregister an adapter for a specific element type */\n unregister: (elementType: string) => void;\n /** Process a document by applying registered adapters */\n process: (\n document: unknown,\n context: Partial<PdfMakeConverterContext>,\n ) => Promise<unknown>;\n}\n\nexport class AdapterError extends Error {\n element: unknown;\n constructor(message: string, element: unknown) {\n super(message);\n this.element = element;\n Object.setPrototypeOf(this, AdapterError.prototype);\n }\n}\n\ninterface SmeupExtensionImageMetadata {\n url?: string;\n obj?: SmeupDataObj;\n}\n\ninterface SmeupExtensionTableMetadata {\n fun?: string;\n data?: SmeupDataTable;\n}\n\nexport interface ContentImageExtension extends ContentImage {\n smeup?: SmeupExtensionImageMetadata;\n}\n\nexport interface TableExtension extends Table {\n smeup?: SmeupExtensionTableMetadata;\n}\n\nexport interface ElementWithImageExtension {\n image: ContentImage & { smeup?: SmeupExtensionImageMetadata };\n}\n\nexport interface ElementWithTableExtension {\n table: Table & { smeup?: SmeupExtensionTableMetadata };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pdfmake.types.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/pdfmake.types.ts"],"names":[],"mappings":";;;AA2CA,MAAa,YAAa,SAAQ,KAAK;IACrC,OAAO,CAAU;IACjB,YAAY,OAAe,EAAE,OAAgB;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AAPD,oCAOC","sourcesContent":["import { ContentImage, Table, TDocumentDefinitions } from \"pdfmake/interfaces\";\nimport { SmeupDataObj, WebupManagerData } from \"../../../types\";\nimport { SmeupDataStructure } from \"../../../types/data-structures/smeupDataStructure\";\nimport { SmeupDataTable } from \"../../../types/data-structures/smeupDataTable\";\n\n/**\n * Context passed to adapter functions during document processing.\n */\nexport interface PdfMakeConverterContext<\n T extends SmeupDataStructure = SmeupDataStructure,\n> {\n webupManagerData: WebupManagerData;\n pdfDocument?: TDocumentDefinitions;\n damSvcEndpoint?: string;\n getSmeupDataStructure?: (fun: string) => Promise<T>;\n fetchData?: (url: string) => Promise<Response>;\n}\n\n/**\n * Function that transforms an element from custom format to pdfmake standard format.\n * Adapters are pure functions that receive an element and context, and return the transformed element.\n * Can be synchronous or asynchronous.\n */\nexport type PdfmakeAdapter = (\n element: unknown,\n context: PdfMakeConverterContext,\n) => unknown | Promise<unknown>;\n\n/**\n * Registry interface for managing pdfmake adapters at runtime.\n */\nexport interface AdapterRegistry {\n /** Register an adapter for a specific element type */\n register: (elementType: string, adapter: PdfmakeAdapter) => void;\n /** Unregister an adapter for a specific element type */\n unregister: (elementType: string) => void;\n /** Process a document by applying registered adapters */\n process: (\n document: unknown,\n context: Partial<PdfMakeConverterContext>,\n ) => Promise<unknown>;\n}\n\nexport class AdapterError extends Error {\n element: unknown;\n constructor(message: string, element: unknown) {\n super(message);\n this.element = element;\n Object.setPrototypeOf(this, AdapterError.prototype);\n }\n}\n\ninterface SmeupExtensionImageMetadata {\n url?: string;\n obj?: SmeupDataObj;\n}\n\ninterface SmeupExtensionTableMetadata {\n fun?: string;\n data?: SmeupDataTable;\n}\n\nexport interface ContentImageExtension extends ContentImage {\n smeup?: SmeupExtensionImageMetadata;\n}\n\nexport interface TableExtension extends Table {\n smeup?: SmeupExtensionTableMetadata;\n}\n\nexport interface ElementWithImageExtension {\n image: ContentImage & { smeup?: SmeupExtensionImageMetadata };\n}\n\nexport interface ElementWithTableExtension {\n table: Table & { smeup?: SmeupExtensionTableMetadata };\n}\n\nexport type LayoutLineFunction = (i: number, node?: unknown) => number;\nexport type LayoutColorFunction = (i: number, node?: unknown) => string;\n\nexport interface Layout {\n hLineWidth?: number | LayoutLineFunction;\n vLineWidth?: number | LayoutLineFunction;\n hLineColor?: string | LayoutColorFunction;\n vLineColor?: string | LayoutColorFunction;\n}\n\nexport interface ElementWithLayout {\n layout?: Layout;\n [key: string]: unknown;\n}\n"]}
|
|
@@ -18,6 +18,7 @@ const adapter_registry_1 = require("./pdf/pdfmake/adapter-registry");
|
|
|
18
18
|
const table_adapter_1 = require("./pdf/pdfmake/table-adapter");
|
|
19
19
|
const image_adapter_1 = require("./pdf/pdfmake/image-adapter");
|
|
20
20
|
const page_element_adapter_1 = require("./pdf/pdfmake/page-element-adapter");
|
|
21
|
+
const layout_adapter_1 = require("./pdf/pdfmake/layout-adapter");
|
|
21
22
|
const schedaToPdfData = async (sch, webupManagerData) => {
|
|
22
23
|
const doc = await (0, sch_converter_1.schedaToPdfDoc)(sch);
|
|
23
24
|
return Buffer.from(doc.output("arraybuffer"));
|
|
@@ -53,6 +54,7 @@ const pdfmakeDocumentToPdfData = async (documentDefinition, context) => {
|
|
|
53
54
|
registry.register("image", (0, image_adapter_1.imageAdapter)());
|
|
54
55
|
registry.register("footer", (0, page_element_adapter_1.footerAdapter)());
|
|
55
56
|
registry.register("header", (0, page_element_adapter_1.headerAdapter)());
|
|
57
|
+
registry.register("layout", (0, layout_adapter_1.layoutAdapter)());
|
|
56
58
|
context.pdfDocument = documentDefinition;
|
|
57
59
|
// Pre-process document with adapters
|
|
58
60
|
const processedDoc = await (0, adapter_processor_1.preProcessPdfMakeDocument)(documentDefinition, context, registry);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-converter.js","sourceRoot":"","sources":["../../src/converters/pdf-converter.ts"],"names":[],"mappings":";AAAA,sDAAsD;;;AAItD,0CAIwB;AACxB,8DAA2D;AAC3D,+DAAoE;AACpE,6DAA2D;AAC3D,uDAAqD;AACrD,qCAAsC;AACtC,yDAAsD;AACtD,iDAAgD;AAChD,6DAA+D;AAG/D,mDAAoE;
|
|
1
|
+
{"version":3,"file":"pdf-converter.js","sourceRoot":"","sources":["../../src/converters/pdf-converter.ts"],"names":[],"mappings":";AAAA,sDAAsD;;;AAItD,0CAIwB;AACxB,8DAA2D;AAC3D,+DAAoE;AACpE,6DAA2D;AAC3D,uDAAqD;AACrD,qCAAsC;AACtC,yDAAsD;AACtD,iDAAgD;AAChD,6DAA+D;AAG/D,mDAAoE;AA4G3D,4FA5GA,yBAAW,OA4GA;AA3GpB,uEAA4E;AAC5E,qEAAuE;AACvE,+DAA+D;AAC/D,+DAA2D;AAC3D,6EAG4C;AAC5C,iEAA6D;AAEtD,MAAM,eAAe,GAAG,KAAK,EAClC,GAAa,EACb,gBAAkC,EACjB,EAAE;IACnB,MAAM,GAAG,GAAG,MAAM,IAAA,8BAAc,EAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AAChD,CAAC,CAAC;AANW,QAAA,eAAe,mBAM1B;AAEK,MAAM,kBAAkB,GAAG,KAAK,EACrC,SAGC,EACD,gBAAkC,EACJ,EAAE;IAChC,MAAM,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QAClC,MAAM,MAAM,GAAG,MAAM,qBAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,SAAS,CAC3C,MAAM,EACN,MAAM,CAAC,cAAc,EAAE,CACxB,CAAC;QACF,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;IAC3C,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\nimport { SmeupDataTable } from \"../types/data-structures/smeupDataTable\";\nimport { SmeupSch } from \"../types/data-structures/smeupSch\";\nimport {\n WebupManagerData,\n GenericObject,\n SupportedExportFormats,\n} from \"../types/index\";\nimport { convertToBuffer } from \"../utils/commons-utility\";\nimport { dataTableToExcelWorkbook } from \"./excel/matrix-converter\";\nimport { dataTableToPdfDoc } from \"./pdf/matrix-converter\";\nimport { schedaToPdfDoc } from \"./pdf/sch-converter\";\nimport { PDFDocument } from \"pdf-lib\";\nimport { createCoverPdf } from \"./pdf/cover-renderer\";\nimport { logoBase64 } from \"../assets/gfx-data\";\nimport { renderPdfMakeDocument } from \"./pdf/pdfmake-renderer\";\nimport type { PdfMakeConverterContext } from \"./pdf/pdfmake/pdfmake.types\";\nimport type { TDocumentDefinitions } from \"pdfmake/interfaces\";\nimport { fillPdfForm, FillPdfFormOptions } from \"./pdf/form-filler\";\nimport { preProcessPdfMakeDocument } from \"./pdf/pdfmake/adapter-processor\";\nimport { createAdapterRegistry } from \"./pdf/pdfmake/adapter-registry\";\nimport { dataTableAdapter } from \"./pdf/pdfmake/table-adapter\";\nimport { imageAdapter } from \"./pdf/pdfmake/image-adapter\";\nimport {\n footerAdapter,\n headerAdapter,\n} from \"./pdf/pdfmake/page-element-adapter\";\nimport { layoutAdapter } from \"./pdf/pdfmake/layout-adapter\";\n\nexport const schedaToPdfData = async (\n sch: SmeupSch,\n webupManagerData: WebupManagerData,\n): Promise<Buffer> => {\n const doc = await schedaToPdfDoc(sch);\n return Buffer.from(doc.output(\"arraybuffer\"));\n};\n\nexport const dataTableToPdfData = async (\n component: {\n smeupDataTable: SmeupDataTable;\n props: GenericObject;\n },\n webupManagerData: WebupManagerData,\n): Promise<Buffer | Uint8Array> => {\n const workbook = dataTableToExcelWorkbook(\n component,\n SupportedExportFormats.XLSX,\n webupManagerData,\n );\n\n const worksheet = workbook.getWorksheet(1);\n if (worksheet) {\n const title = component.smeupDataTable.cover?.titles?.[\"T01\"] ?? \"\";\n const subtitle = component.smeupDataTable.cover?.titles?.[\"T02\"] ?? \"\";\n const subtitle2 = component.smeupDataTable.cover?.titles?.[\"T03\"] ?? \"\";\n const image = component.smeupDataTable.cover?.image ?? \"\";\n const logo = component.smeupDataTable.cover?.logo ?? logoBase64;\n const cover = createCoverPdf(image, logo, title, subtitle, subtitle2);\n const pdfDoc = await dataTableToPdfDoc(worksheet, webupManagerData, {\n logoBase64: logo,\n title: title,\n subtitle: subtitle,\n });\n const pdfBuffer = pdfDoc.output(\"arraybuffer\");\n return convertToBuffer(await appendPdfDocs([cover, pdfBuffer]));\n } else {\n throw new Error(\"Worksheet not found in the workbook\");\n }\n};\n\nexport const pdfmakeDocumentToPdfData = async (\n documentDefinition: TDocumentDefinitions,\n context: Partial<PdfMakeConverterContext>,\n): Promise<Buffer> => {\n // Register adapters\n const registry = createAdapterRegistry();\n registry.register(\"table\", dataTableAdapter());\n registry.register(\"image\", imageAdapter());\n registry.register(\"footer\", footerAdapter());\n registry.register(\"header\", headerAdapter());\n registry.register(\"layout\", layoutAdapter());\n\n context.pdfDocument = documentDefinition;\n\n // Pre-process document with adapters\n const processedDoc = await preProcessPdfMakeDocument(\n documentDefinition,\n context,\n registry,\n );\n\n console.debug(\n \"Processed pdfmake document:\",\n JSON.stringify(processedDoc, null, 2),\n );\n // Render the document using pdfmake\n return renderPdfMakeDocument(processedDoc);\n};\n\n/**\n * Unisce più PDF (in formato ArrayBuffer/Uint8Array/Buffer) in un unico PDF.\n * @param pdfBuffers Array di buffer PDF (es. ottenuti da jsPDF.output(\"arraybuffer\"))\n * @returns Buffer del PDF unito\n */\nconst appendPdfDocs = async (\n pdfBuffers: (Uint8Array | ArrayBuffer | Buffer)[],\n): Promise<Uint8Array> => {\n if (!pdfBuffers.length) throw new Error(\"No PDF buffers to append\");\n\n // Crea un nuovo documento PDF vuoto\n const mergedPdf = await PDFDocument.create();\n\n for (const pdfBytes of pdfBuffers) {\n const srcPdf = await PDFDocument.load(pdfBytes);\n const copiedPages = await mergedPdf.copyPages(\n srcPdf,\n srcPdf.getPageIndices(),\n );\n copiedPages.forEach(page => mergedPdf.addPage(page));\n }\n\n const mergedBytes = await mergedPdf.save();\n return mergedBytes;\n};\n\n// Re-export form filler function and types\nexport { fillPdfForm };\nexport type { FillPdfFormOptions };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sme.up/doc-alchemist",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-SNAPSHOT-20251212084649",
|
|
4
4
|
"description": "Library for generating documents in various formats, including Excel and PDF.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Smeup LAB <info@smeup.com> (https://www.smeup.com/)",
|