@sme.up/doc-alchemist 1.5.0-SNAPSHOT-20251121152517 → 1.5.0-SNAPSHOT-20251126090326
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/adapter-processor.d.ts +3 -2
- package/dist/converters/pdf/pdfmake/adapter-processor.js +27 -19
- package/dist/converters/pdf/pdfmake/adapter-processor.js.map +1 -1
- package/dist/converters/pdf/pdfmake/adapter-registry.d.ts +1 -1
- package/dist/converters/pdf/pdfmake/adapter-registry.js +8 -6
- package/dist/converters/pdf/pdfmake/adapter-registry.js.map +1 -1
- package/dist/converters/pdf/pdfmake/image-adapter.d.ts +19 -0
- package/dist/converters/pdf/pdfmake/image-adapter.js +137 -0
- package/dist/converters/pdf/pdfmake/image-adapter.js.map +1 -0
- package/dist/converters/pdf/pdfmake/page-element-adapter.d.ts +8 -0
- package/dist/converters/pdf/pdfmake/page-element-adapter.js +83 -0
- package/dist/converters/pdf/pdfmake/page-element-adapter.js.map +1 -0
- package/dist/converters/pdf/pdfmake/pdfmake.types.d.ts +33 -8
- package/dist/converters/pdf/pdfmake/pdfmake.types.js.map +1 -1
- package/dist/converters/pdf/pdfmake/table-adapter.d.ts +4 -4
- package/dist/converters/pdf/pdfmake/table-adapter.js +55 -47
- package/dist/converters/pdf/pdfmake/table-adapter.js.map +1 -1
- package/dist/converters/pdf-converter.d.ts +2 -1
- package/dist/converters/pdf-converter.js +8 -2
- package/dist/converters/pdf-converter.js.map +1 -1
- package/dist/utils/commons-utility.d.ts +1 -0
- package/dist/utils/commons-utility.js +47 -2
- package/dist/utils/commons-utility.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PdfMakeConverterContext, PdfmakeAdapter, AdapterRegistry } from "./pdfmake.types";
|
|
2
|
+
import type { TDocumentDefinitions } from "pdfmake/interfaces";
|
|
2
3
|
/**
|
|
3
4
|
* Processes a document recursively, applying adapters to matching elements.
|
|
4
5
|
*
|
|
@@ -7,5 +8,5 @@ import { PdfMakeConverterContext, PdfmakeAdapter, AdapterRegistry } from "./pdfm
|
|
|
7
8
|
* @param context - Current processing context
|
|
8
9
|
* @returns The transformed element
|
|
9
10
|
*/
|
|
10
|
-
export declare
|
|
11
|
-
export declare const preProcessPdfMakeDocument: (documentDefinition:
|
|
11
|
+
export declare const processDocument: (element: unknown, adapters: Map<string, PdfmakeAdapter>, context: PdfMakeConverterContext) => Promise<unknown>;
|
|
12
|
+
export declare const preProcessPdfMakeDocument: (documentDefinition: TDocumentDefinitions, context: Partial<PdfMakeConverterContext>, registry?: AdapterRegistry) => Promise<TDocumentDefinitions>;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.preProcessPdfMakeDocument = void 0;
|
|
4
|
-
exports.processDocument = processDocument;
|
|
3
|
+
exports.preProcessPdfMakeDocument = exports.processDocument = void 0;
|
|
5
4
|
const pdfmake_types_1 = require("./pdfmake.types");
|
|
6
5
|
/**
|
|
7
6
|
* Helper to check if a value is a plain object
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
const isPlainObject = (value) => {
|
|
10
9
|
return (typeof value === "object" &&
|
|
11
10
|
value !== null &&
|
|
12
11
|
!Array.isArray(value) &&
|
|
13
12
|
Object.prototype.toString.call(value) === "[object Object]");
|
|
14
|
-
}
|
|
13
|
+
};
|
|
15
14
|
/**
|
|
16
15
|
* Processes a document recursively, applying adapters to matching elements.
|
|
17
16
|
*
|
|
@@ -20,7 +19,7 @@ function isPlainObject(value) {
|
|
|
20
19
|
* @param context - Current processing context
|
|
21
20
|
* @returns The transformed element
|
|
22
21
|
*/
|
|
23
|
-
async
|
|
22
|
+
const processDocument = async (element, adapters, context) => {
|
|
24
23
|
// Handle null/undefined
|
|
25
24
|
if (element == null) {
|
|
26
25
|
return element;
|
|
@@ -28,11 +27,7 @@ async function processDocument(element, adapters, context) {
|
|
|
28
27
|
try {
|
|
29
28
|
// Handle arrays - process each item
|
|
30
29
|
if (Array.isArray(element)) {
|
|
31
|
-
return await Promise.all(element.map(
|
|
32
|
-
...context,
|
|
33
|
-
path: [...context.path, String(index)],
|
|
34
|
-
depth: context.depth + 1,
|
|
35
|
-
})));
|
|
30
|
+
return await Promise.all(element.map(item => (0, exports.processDocument)(item, adapters, context)));
|
|
36
31
|
}
|
|
37
32
|
// Handle plain objects
|
|
38
33
|
if (isPlainObject(element)) {
|
|
@@ -61,18 +56,14 @@ async function processDocument(element, adapters, context) {
|
|
|
61
56
|
if (!isPlainObject(element)) {
|
|
62
57
|
return element;
|
|
63
58
|
}
|
|
64
|
-
|
|
59
|
+
// Continue to apply other adapters (e.g., both header and footer)
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
// Recursively process all properties
|
|
69
64
|
const processed = {};
|
|
70
65
|
for (const [key, value] of Object.entries(element)) {
|
|
71
|
-
processed[key] = await processDocument(value, adapters,
|
|
72
|
-
...context,
|
|
73
|
-
path: [...context.path, key],
|
|
74
|
-
depth: context.depth + 1,
|
|
75
|
-
});
|
|
66
|
+
processed[key] = await (0, exports.processDocument)(value, adapters, context);
|
|
76
67
|
}
|
|
77
68
|
return processed;
|
|
78
69
|
}
|
|
@@ -82,13 +73,30 @@ async function processDocument(element, adapters, context) {
|
|
|
82
73
|
catch (err) {
|
|
83
74
|
throw new pdfmake_types_1.AdapterError(err, element);
|
|
84
75
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
76
|
+
};
|
|
77
|
+
exports.processDocument = processDocument;
|
|
78
|
+
const preProcessPdfMakeDocument = async (documentDefinition, context, registry) => {
|
|
87
79
|
if (!registry) {
|
|
88
80
|
return Promise.resolve(documentDefinition);
|
|
89
81
|
}
|
|
90
82
|
else {
|
|
91
|
-
|
|
83
|
+
const processedDoc = (await registry?.process(documentDefinition, context));
|
|
84
|
+
// Merge all first-level properties from pdfDocument
|
|
85
|
+
// (excluding content, header, footer which are already processed)
|
|
86
|
+
if (context.pdfDocument) {
|
|
87
|
+
for (const [key, value] of Object.entries(context.pdfDocument)) {
|
|
88
|
+
if (key === "content" || key === "header" || key === "footer") {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (value !== undefined && isPlainObject(value)) {
|
|
92
|
+
processedDoc[key] = {
|
|
93
|
+
...(documentDefinition[key] || {}),
|
|
94
|
+
...value,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return processedDoc;
|
|
92
100
|
}
|
|
93
101
|
};
|
|
94
102
|
exports.preProcessPdfMakeDocument = preProcessPdfMakeDocument;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-processor.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/adapter-processor.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"adapter-processor.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/adapter-processor.ts"],"names":[],"mappings":";;;AAAA,mDAKyB;AAGzB;;GAEG;AACH,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE;IACzE,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACrB,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAC5D,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,OAAgB,EAChB,QAAqC,EACrC,OAAgC,EACd,EAAE;IACpB,wBAAwB;IACxB,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,CAAC;QACH,oCAAoC;QACpC,IAAI,KAAK,CAAC,OA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AAG,CAAG,kBAAyD,CAC7D,GAAG,CACO,IAAI,EAAE,CAAC;wBACnB,GAAG,KAAK;qBACT,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;AACH,CAAC,CAAC;AAjCW,QAAA,yBAAyB,6BAiCpC","sourcesContent":["import {\n PdfMakeConverterContext,\n AdapterError,\n PdfmakeAdapter,\n AdapterRegistry,\n} from \"./pdfmake.types\";\nimport type { TDocumentDefinitions } from \"pdfmake/interfaces\";\n\n/**\n * Helper to check if a value is a plain object\n */\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n Object.prototype.toString.call(value) === \"[object Object]\"\n );\n};\n\n/**\n * Processes a document recursively, applying adapters to matching elements.\n *\n * @param element - The current element to process\n * @param adapters - Map of element types to their adapter functions\n * @param context - Current processing context\n * @returns The transformed element\n */\nexport const processDocument = async (\n element: unknown,\n adapters: Map<string, PdfmakeAdapter>,\n context: PdfMakeConverterContext,\n): Promise<unknown> => {\n // Handle null/undefined\n if (element == null) {\n return element;\n }\n try {\n // Handle arrays - process each item\n if (Array.isArray(element)) {\n return await Promise.all(\n element.map(item => processDocument(item, adapters, context)),\n );\n }\n\n // Handle plain objects\n if (isPlainObject(element)) {\n // Try to apply adapters based on element type\n const elementType = element.type as string | undefined;\n if (elementType && adapters.has(elementType)) {\n const adapter = adapters.get(elementType)!;\n element = await adapter(element, context);\n\n // After transformation, element might not be a plain object anymore\n if (!isPlainObject(element)) {\n return element;\n }\n }\n\n // Also try adapters based on properties (e.g., \"table\" property)\n for (const [key, adapter] of adapters.entries()) {\n // Skip type-based adapters already processed\n if (key === elementType) continue;\n\n // Apply adapter if it matches a property name\n if (key in element) {\n const transformed = await adapter(element, context);\n // Only accept transformation if adapter actually changed something\n if (transformed !== element) {\n element = transformed;\n // After transformation, element might not be a plain object anymore\n if (!isPlainObject(element)) {\n return element;\n }\n // Continue to apply other adapters (e.g., both header and footer)\n }\n }\n }\n\n // Recursively process all properties\n const processed: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(\n element as Record<string, unknown>,\n )) {\n processed[key] = await processDocument(value, adapters, context);\n }\n return processed;\n }\n\n // Primitive values - return as-is\n return element;\n } catch (err) {\n throw new AdapterError(err as string, element);\n }\n};\n\nexport const preProcessPdfMakeDocument = async (\n documentDefinition: TDocumentDefinitions,\n context: Partial<PdfMakeConverterContext>,\n registry?: AdapterRegistry,\n): Promise<TDocumentDefinitions> => {\n if (!registry) {\n return Promise.resolve(documentDefinition);\n } else {\n const processedDoc = (await registry?.process(\n documentDefinition,\n context,\n )) as TDocumentDefinitions;\n\n // Merge all first-level properties from pdfDocument\n // (excluding content, header, footer which are already processed)\n if (context.pdfDocument) {\n for (const [key, value] of Object.entries(context.pdfDocument)) {\n if (key === \"content\" || key === \"header\" || key === \"footer\") {\n continue;\n }\n if (value !== undefined && isPlainObject(value)) {\n (processedDoc as unknown as Record<string, unknown>)[key] = {\n ...(((documentDefinition as unknown as Record<string, unknown>)[\n key\n ] as object) || {}),\n ...value,\n };\n }\n }\n }\n\n return processedDoc;\n }\n};\n"]}
|
|
@@ -19,4 +19,4 @@ import { AdapterRegistry } from "./pdfmake.types";
|
|
|
19
19
|
* const transformed = registry.process(documentDefinition, { webupManagerData });
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
export declare
|
|
22
|
+
export declare const createAdapterRegistry: () => AdapterRegistry;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAdapterRegistry =
|
|
3
|
+
exports.createAdapterRegistry = void 0;
|
|
4
4
|
const adapter_processor_1 = require("./adapter-processor");
|
|
5
5
|
/**
|
|
6
6
|
* Creates a new adapter registry for runtime registration and processing of pdfmake adapters.
|
|
@@ -22,7 +22,7 @@ const adapter_processor_1 = require("./adapter-processor");
|
|
|
22
22
|
* const transformed = registry.process(documentDefinition, { webupManagerData });
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
const createAdapterRegistry = () => {
|
|
26
26
|
const adapters = new Map();
|
|
27
27
|
return {
|
|
28
28
|
register(elementType, adapter) {
|
|
@@ -33,14 +33,16 @@ function createAdapterRegistry() {
|
|
|
33
33
|
},
|
|
34
34
|
async process(document, context) {
|
|
35
35
|
const fullContext = {
|
|
36
|
-
webupManagerData: context
|
|
36
|
+
webupManagerData: context.webupManagerData,
|
|
37
37
|
getSmeupDataStructure: context?.getSmeupDataStructure,
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
fetchData: context?.fetchData,
|
|
39
|
+
pdfDocument: context?.pdfDocument,
|
|
40
|
+
damSvcEndpoint: context?.damSvcEndpoint,
|
|
40
41
|
};
|
|
41
42
|
const processed = await (0, adapter_processor_1.processDocument)(document, adapters, fullContext);
|
|
42
43
|
return processed;
|
|
43
44
|
},
|
|
44
45
|
};
|
|
45
|
-
}
|
|
46
|
+
};
|
|
47
|
+
exports.createAdapterRegistry = createAdapterRegistry;
|
|
46
48
|
//# sourceMappingURL=adapter-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-registry.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/adapter-registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter-registry.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/adapter-registry.ts"],"names":[],"mappings":";;;AAKA,2DAAsD;AAEtD;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,qBAAqB,GAAG,GAAoB,EAAE;IACzD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEnD,OAAO;QACL,QAAQ,CAAC,WAAmB,EAAE,OAAuB;YACnD,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACrC,CAAC;QAED,UAAU,CAAC,WAAmB;YAC5B,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC;QAED,KAAK,CAAC,OAAO,CACX,QAAiB,EACjB,OAAyC;YAEzC,MAAM,WAAW,GAA4B;gBAC3C,gBAAgB,EAAE,OAAO,CAAC,gBAAiB;gBAC3C,qBAAqB,EAAE,OAAO,EAAE,qBAAqB;gBACrD,SAAS,EAAE,OAAO,EAAE,SAAS;gBAC7B,WAAW,EAAE,OAAO,EAAE,WAAW;gBACjC,cAAc,EAAE,OAAO,EAAE,cAAc;aACxC,CAAC;YACF,MAAM,SAAS,GAAG,MAAM,IAAA,mCAAe,EAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;YACzE,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AA3BW,QAAA,qBAAqB,yBA2BhC","sourcesContent":["import {\n AdapterRegistry,\n PdfmakeAdapter,\n PdfMakeConverterContext,\n} from \"./pdfmake.types\";\nimport { processDocument } from \"./adapter-processor\";\n\n/**\n * Creates a new adapter registry for runtime registration and processing of pdfmake adapters.\n * Each registry is independent and maintains its own set of adapters.\n *\n * @returns A new AdapterRegistry instance\n *\n * @example\n * ```typescript\n * const registry = createAdapterRegistry();\n *\n * // Register an adapter for tables\n * registry.register('table', (element, context) => {\n * // Transform custom table format to pdfmake format\n * return { table: { body: transformData(element.data) } };\n * });\n *\n * // Process a document\n * const transformed = registry.process(documentDefinition, { webupManagerData });\n * ```\n */\nexport const createAdapterRegistry = (): AdapterRegistry => {\n const adapters = new Map<string, PdfmakeAdapter>();\n\n return {\n register(elementType: string, adapter: PdfmakeAdapter): void {\n adapters.set(elementType, adapter);\n },\n\n unregister(elementType: string): void {\n adapters.delete(elementType);\n },\n\n async process(\n document: unknown,\n context: Partial<PdfMakeConverterContext>,\n ): Promise<unknown> {\n const fullContext: PdfMakeConverterContext = {\n webupManagerData: context.webupManagerData!,\n getSmeupDataStructure: context?.getSmeupDataStructure,\n fetchData: context?.fetchData,\n pdfDocument: context?.pdfDocument,\n damSvcEndpoint: context?.damSvcEndpoint,\n };\n const processed = await processDocument(document, adapters, fullContext);\n return processed;\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ContentImageExtension, ElementWithImageExtension, PdfMakeConverterContext } from "./pdfmake.types";
|
|
2
|
+
/**
|
|
3
|
+
* Adapts a Smeup image structure to the PDFMake image format.
|
|
4
|
+
*
|
|
5
|
+
* This adapter function checks if the provided element contains an image with a smeup URL.
|
|
6
|
+
* If so, it downloads the image using the fetchData callback from context, validates the
|
|
7
|
+
* content-type, and transforms it into a data URL format that PDFMake can use.
|
|
8
|
+
* The data URL is stored in context.pdfDocument.images to avoid redundancy when the same
|
|
9
|
+
* image is referenced multiple times.
|
|
10
|
+
* All properties of the original image except `smeup` are preserved.
|
|
11
|
+
*
|
|
12
|
+
* @returns An async function that takes an element and returns the adapted element for PDFMake,
|
|
13
|
+
* or the original element if it does not contain a valid smeup image.
|
|
14
|
+
* @throws If the context does not provide a fetchData function when the smeup image is used.
|
|
15
|
+
* @throws If the image download fails or the content-type is not a valid image MIME type.
|
|
16
|
+
*/
|
|
17
|
+
export declare const urlToImageAdapter: () => (element: unknown, context: PdfMakeConverterContext) => Promise<ContentImageExtension>;
|
|
18
|
+
export declare const objectToUrlAdapter: () => (element: unknown, context: PdfMakeConverterContext) => Promise<ElementWithImageExtension>;
|
|
19
|
+
export declare const imageAdapter: () => (element: unknown, context: PdfMakeConverterContext) => Promise<ContentImageExtension>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageAdapter = exports.objectToUrlAdapter = exports.urlToImageAdapter = void 0;
|
|
4
|
+
const hasSmeupUrl = (element) => {
|
|
5
|
+
const image = element
|
|
6
|
+
.image;
|
|
7
|
+
const url = image?.smeup?.url;
|
|
8
|
+
return typeof url === "string" && url.length > 0;
|
|
9
|
+
};
|
|
10
|
+
function hasSmeupObject(element) {
|
|
11
|
+
const image = element
|
|
12
|
+
.image;
|
|
13
|
+
const obj = image?.smeup?.obj;
|
|
14
|
+
return typeof obj === "object" && obj !== null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Downloads an image from a URL and converts it to a data URL format.
|
|
18
|
+
* Validates that the content-type is an image MIME type.
|
|
19
|
+
*
|
|
20
|
+
* @param url - The URL of the image to download
|
|
21
|
+
* @param fetchData - Callback function to fetch the image data
|
|
22
|
+
* @returns A data URL string in the format: data:image/jpeg;base64,<base64>
|
|
23
|
+
* @throws If the download fails, content-type is not an image, or network error occurs
|
|
24
|
+
*/
|
|
25
|
+
const downloadImageAsDataUrl = async (url, fetchData) => {
|
|
26
|
+
const response = await fetchData(url);
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
throw new Error(`Failed to download image from ${url}: ${response.status} ${response.statusText}`);
|
|
29
|
+
}
|
|
30
|
+
// Extract content-type from headers
|
|
31
|
+
const contentType = response.headers.get("content-type") || "image/jpeg";
|
|
32
|
+
// Validate that content-type is an image
|
|
33
|
+
if (!contentType.startsWith("image/")) {
|
|
34
|
+
throw new Error(`Invalid content-type for image: expected image/*, got ${contentType}`);
|
|
35
|
+
}
|
|
36
|
+
// Get image data and convert to base64
|
|
37
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
38
|
+
const base64 = Buffer.from(arrayBuffer).toString("base64");
|
|
39
|
+
return `data:${contentType};base64,${base64}`;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Adapts a Smeup image structure to the PDFMake image format.
|
|
43
|
+
*
|
|
44
|
+
* This adapter function checks if the provided element contains an image with a smeup URL.
|
|
45
|
+
* If so, it downloads the image using the fetchData callback from context, validates the
|
|
46
|
+
* content-type, and transforms it into a data URL format that PDFMake can use.
|
|
47
|
+
* The data URL is stored in context.pdfDocument.images to avoid redundancy when the same
|
|
48
|
+
* image is referenced multiple times.
|
|
49
|
+
* All properties of the original image except `smeup` are preserved.
|
|
50
|
+
*
|
|
51
|
+
* @returns An async function that takes an element and returns the adapted element for PDFMake,
|
|
52
|
+
* or the original element if it does not contain a valid smeup image.
|
|
53
|
+
* @throws If the context does not provide a fetchData function when the smeup image is used.
|
|
54
|
+
* @throws If the image download fails or the content-type is not a valid image MIME type.
|
|
55
|
+
*/
|
|
56
|
+
const urlToImageAdapter = () => {
|
|
57
|
+
return async (element, context) => {
|
|
58
|
+
if (!hasSmeupUrl(element)) {
|
|
59
|
+
return element;
|
|
60
|
+
}
|
|
61
|
+
if (!context.fetchData) {
|
|
62
|
+
throw new Error("fetchData function is required in context when the smeup image property is used");
|
|
63
|
+
}
|
|
64
|
+
const elementImage = element;
|
|
65
|
+
const url = elementImage.image.smeup.url;
|
|
66
|
+
// Ensure pdfDocument exists in context
|
|
67
|
+
if (!context.pdfDocument) {
|
|
68
|
+
throw new Error("pdfDocument is required in context when the smeup image property is used");
|
|
69
|
+
}
|
|
70
|
+
// Initialize images dictionary if not present
|
|
71
|
+
if (!context.pdfDocument.images) {
|
|
72
|
+
context.pdfDocument.images = {};
|
|
73
|
+
}
|
|
74
|
+
// Download and cache the image only if not already present
|
|
75
|
+
if (!context.pdfDocument.images[url]) {
|
|
76
|
+
const dataUrl = await downloadImageAsDataUrl(url, context.fetchData);
|
|
77
|
+
context.pdfDocument.images[url] = dataUrl;
|
|
78
|
+
}
|
|
79
|
+
// Extract all properties except 'smeup' from the image object
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
81
|
+
const { smeup, ...imageRest } = elementImage.image;
|
|
82
|
+
return {
|
|
83
|
+
...elementImage,
|
|
84
|
+
image: url,
|
|
85
|
+
...imageRest,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.urlToImageAdapter = urlToImageAdapter;
|
|
90
|
+
const objectToUrlAdapter = () => {
|
|
91
|
+
return async (element, context) => {
|
|
92
|
+
if (!hasSmeupObject(element)) {
|
|
93
|
+
return element;
|
|
94
|
+
}
|
|
95
|
+
if (!context.getSmeupDataStructure || !context.damSvcEndpoint) {
|
|
96
|
+
throw new Error("getSmeupDataStructure function and damSvcEndpoint prop are required in context when the smeup image obj property is used");
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const elementImage = element;
|
|
100
|
+
const obj = elementImage.image.smeup?.obj;
|
|
101
|
+
if (!obj || !obj.t || !obj.p || !obj.k) {
|
|
102
|
+
throw new Error("Smeup object must have t, p, and k properties to build GET.PATH function");
|
|
103
|
+
}
|
|
104
|
+
const funToGetPATH = `F(TRE;JASER_12W;GET.PATH) 1(${obj.t};${obj.p};${obj.k})`;
|
|
105
|
+
const dataTree = (await context.getSmeupDataStructure(funToGetPATH));
|
|
106
|
+
if (dataTree.children?.length === 0) {
|
|
107
|
+
throw new Error(`No data found for function ${funToGetPATH}`);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const pathNode = dataTree.children[0].value.replace(/\\/g, "/");
|
|
111
|
+
const pathEncoded = encodeURIComponent(pathNode);
|
|
112
|
+
const url = context.damSvcEndpoint + "/" + pathEncoded;
|
|
113
|
+
// Extract all properties except 'smeup' from the image object
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
|
+
const { smeup, ...imageRest } = elementImage.image;
|
|
116
|
+
return {
|
|
117
|
+
...elementImage,
|
|
118
|
+
image: {
|
|
119
|
+
smeup: {
|
|
120
|
+
url,
|
|
121
|
+
},
|
|
122
|
+
...imageRest,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
exports.objectToUrlAdapter = objectToUrlAdapter;
|
|
130
|
+
const imageAdapter = () => {
|
|
131
|
+
return async (element, context) => {
|
|
132
|
+
const adaptedElement = await (0, exports.objectToUrlAdapter)()(element, context);
|
|
133
|
+
return (0, exports.urlToImageAdapter)()(adaptedElement, context);
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
exports.imageAdapter = imageAdapter;
|
|
137
|
+
//# sourceMappingURL=image-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-adapter.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/image-adapter.ts"],"names":[],"mappings":";;;AAOA,MAAM,WAAW,GAAG,CAAC,OAAgB,EAAW,EAAE;IAChD,MAAM,KAAK,GAAI,OAAmC;SAC/C,KAA8B,CAAC;IAClC,MAAM,GAAG,GAAG,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC;IAC9B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,SAAS,cAAc,CAAC,OAAgB;IACtC,MAAM,KAAK,GAAI,OAAmC;SAC/C,KAA8B,CAAC;IAClC,MAAM,GAAG,GAAG,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC;IAC9B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC;AACjD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,sBAAsB,GAAG,KAAK,EAClC,GAAW,EACX,SAA6C,EAC5B,EAAE;IACnB,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;IAEtC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CACb,iCAAiC,GAAG,KAAK,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAClF,CAAC;IACJ,CAAC;IAED,oCAAoC;IACpC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,YAAY,CAAC;IAEzE,yCAAyC;IACzC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ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BACpC,MAAM,IAAI,KAAK,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;YAChE,CAAC;iBAAM,CAAC;gBACN,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBAChE,MAAM,WAAW,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;gBACjD,MAAM,GAAG,GAAG,OAAO,CAAC,cAAc,GAAG,GAAG,GAAG,WAAW,CAAC;gBAEvD,8DAA8D;gBAC9D,6DAA6D;gBAC7D,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC;gBAEnD,OAAO;oBACL,GAAG,YAAY;oBACf,KAAK,EAAE;wBACL,KAAK,EAAE;4BACL,GAAG;yBACJ;wBACD,GAAG,SAAS;qBACb;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AA/CW,QAAA,kBAAkB,sBA+C7B;AAEK,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,OAAO,KAAK,EACV,OAAgB,EAChB,OAAgC,EACA,EAAE;QAClC,MAAM,cAAc,GAAG,MAAM,IAAA,0BAAkB,GAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACpE,OAAO,IAAA,yBAAiB,GAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,YAAY,gBAQvB","sourcesContent":["import { SmeupDataTree } from \"../../../types/data-structures/smeupDataTree\";\nimport {\n ContentImageExtension,\n ElementWithImageExtension,\n PdfMakeConverterContext,\n} from \"./pdfmake.types\";\n\nconst hasSmeupUrl = (element: unknown): boolean => {\n const image = (element as Record<string, unknown>)\n .image as ContentImageExtension;\n const url = image?.smeup?.url;\n return typeof url === \"string\" && url.length > 0;\n};\n\nfunction hasSmeupObject(element: unknown): boolean {\n const image = (element as Record<string, unknown>)\n .image as ContentImageExtension;\n const obj = image?.smeup?.obj;\n return typeof obj === \"object\" && obj !== null;\n}\n\n/**\n * Downloads an image from a URL and converts it to a data URL format.\n * Validates that the content-type is an image MIME type.\n *\n * @param url - The URL of the image to download\n * @param fetchData - Callback function to fetch the image data\n * @returns A data URL string in the format: data:image/jpeg;base64,<base64>\n * @throws If the download fails, content-type is not an image, or network error occurs\n */\nconst downloadImageAsDataUrl = async (\n url: string,\n fetchData: (url: string) => Promise<Response>,\n): Promise<string> => {\n const response = await fetchData(url);\n\n if (!response.ok) {\n throw new Error(\n `Failed to download image from ${url}: ${response.status} ${response.statusText}`,\n );\n }\n\n // Extract content-type from headers\n const contentType = response.headers.get(\"content-type\") || \"image/jpeg\";\n\n // Validate that content-type is an image\n if (!contentType.startsWith(\"image/\")) {\n throw new Error(\n `Invalid content-type for image: expected image/*, got ${contentType}`,\n );\n }\n\n // Get image data and convert to base64\n const arrayBuffer = await response.arrayBuffer();\n const base64 = Buffer.from(arrayBuffer).toString(\"base64\");\n\n return `data:${contentType};base64,${base64}`;\n};\n\n/**\n * Adapts a Smeup image structure to the PDFMake image format.\n *\n * This adapter function checks if the provided element contains an image with a smeup URL.\n * If so, it downloads the image using the fetchData callback from context, validates the\n * content-type, and transforms it into a data URL format that PDFMake can use.\n * The data URL is stored in context.pdfDocument.images to avoid redundancy when the same\n * image is referenced multiple times.\n * All properties of the original image except `smeup` are preserved.\n *\n * @returns An async function that takes an element and returns the adapted element for PDFMake,\n * or the original element if it does not contain a valid smeup image.\n * @throws If the context does not provide a fetchData function when the smeup image is used.\n * @throws If the image download fails or the content-type is not a valid image MIME type.\n */\nexport const urlToImageAdapter = () => {\n return async (\n element: unknown,\n context: PdfMakeConverterContext,\n ): Promise<ContentImageExtension> => {\n if (!hasSmeupUrl(element)) {\n return element as ContentImageExtension;\n }\n\n if (!context.fetchData) {\n throw new Error(\n \"fetchData function is required in context when the smeup image property is used\",\n );\n }\n\n const elementImage = element as { image: { smeup: { url: string } } };\n const url = elementImage.image.smeup.url;\n\n // Ensure pdfDocument exists in context\n if (!context.pdfDocument) {\n throw new Error(\n \"pdfDocument is required in context when the smeup image property is used\",\n );\n }\n\n // Initialize images dictionary if not present\n if (!context.pdfDocument.images) {\n context.pdfDocument.images = {};\n }\n\n // Download and cache the image only if not already present\n if (!context.pdfDocument.images[url]) {\n const dataUrl = await downloadImageAsDataUrl(url, context.fetchData);\n context.pdfDocument.images[url] = dataUrl;\n }\n\n // Extract all properties except 'smeup' from the image object\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { smeup, ...imageRest } = elementImage.image;\n\n return {\n ...elementImage,\n image: url,\n ...imageRest,\n };\n };\n};\n\nexport const objectToUrlAdapter = () => {\n return async (\n element: unknown,\n context: PdfMakeConverterContext,\n ): Promise<ElementWithImageExtension> => {\n if (!hasSmeupObject(element)) {\n return element as ElementWithImageExtension;\n }\n if (!context.getSmeupDataStructure || !context.damSvcEndpoint) {\n throw new Error(\n \"getSmeupDataStructure function and damSvcEndpoint prop are required in context when the smeup image obj property is used\",\n );\n } else {\n const elementImage = element as ElementWithImageExtension;\n const obj = elementImage.image.smeup?.obj;\n if (!obj || !obj.t || !obj.p || !obj.k) {\n throw new Error(\n \"Smeup object must have t, p, and k properties to build GET.PATH function\",\n );\n }\n const funToGetPATH = `F(TRE;JASER_12W;GET.PATH) 1(${obj.t};${obj.p};${obj.k})`;\n const dataTree = (await context.getSmeupDataStructure(\n funToGetPATH,\n )) as SmeupDataTree;\n if (dataTree.children?.length === 0) {\n throw new Error(`No data found for function ${funToGetPATH}`);\n } else {\n const pathNode = dataTree.children[0].value.replace(/\\\\/g, \"/\");\n const pathEncoded = encodeURIComponent(pathNode);\n const url = context.damSvcEndpoint + \"/\" + pathEncoded;\n\n // Extract all properties except 'smeup' from the image object\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { smeup, ...imageRest } = elementImage.image;\n\n return {\n ...elementImage,\n image: {\n smeup: {\n url,\n },\n ...imageRest,\n },\n };\n }\n }\n };\n};\n\nexport const imageAdapter = () => {\n return async (\n element: unknown,\n context: PdfMakeConverterContext,\n ): Promise<ContentImageExtension> => {\n const adaptedElement = await objectToUrlAdapter()(element, context);\n return urlToImageAdapter()(adaptedElement, context);\n };\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter for header elements with page number placeholder support.
|
|
3
|
+
*/
|
|
4
|
+
export declare const headerAdapter: () => (element: unknown) => unknown;
|
|
5
|
+
/**
|
|
6
|
+
* Adapter for footer elements with page number placeholder support.
|
|
7
|
+
*/
|
|
8
|
+
export declare const footerAdapter: () => (element: unknown) => unknown;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.footerAdapter = exports.headerAdapter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to check if an element has a specific property
|
|
6
|
+
*/
|
|
7
|
+
const hasProperty = (element, propertyName) => {
|
|
8
|
+
return (element !== null &&
|
|
9
|
+
typeof element === "object" &&
|
|
10
|
+
propertyName in element &&
|
|
11
|
+
element[propertyName] !== undefined);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Recursively searches for [CurrentPage] and [PageCount] placeholders in an object
|
|
15
|
+
* and replaces them with the actual values.
|
|
16
|
+
*
|
|
17
|
+
* @param obj - The object to process
|
|
18
|
+
* @param currentPage - The current page number
|
|
19
|
+
* @param pageCount - The total page count
|
|
20
|
+
* @returns The processed object with replaced placeholders
|
|
21
|
+
*/
|
|
22
|
+
const replacePlaceholders = (obj, currentPage, pageCount) => {
|
|
23
|
+
if (typeof obj === "string") {
|
|
24
|
+
return obj
|
|
25
|
+
.replace(/\[CurrentPage\]/g, String(currentPage))
|
|
26
|
+
.replace(/\[PageCount\]/g, String(pageCount));
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(obj)) {
|
|
29
|
+
return obj.map(item => replacePlaceholders(item, currentPage, pageCount));
|
|
30
|
+
}
|
|
31
|
+
if (obj !== null && typeof obj === "object") {
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
34
|
+
result[key] = replacePlaceholders(value, currentPage, pageCount);
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
return obj;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Adapts a header or footer to support dynamic page number placeholders.
|
|
42
|
+
*
|
|
43
|
+
* This adapter function checks if the provided element contains the specified property (header or footer).
|
|
44
|
+
* - If the property is already a function, it leaves it unchanged.
|
|
45
|
+
* - If the property is an object, it wraps it in a function that replaces
|
|
46
|
+
* [CurrentPage] with the current page number and [PageCount] with the total
|
|
47
|
+
* page count at rendering time.
|
|
48
|
+
*
|
|
49
|
+
* @param propertyName - The name of the property to adapt ('header' or 'footer')
|
|
50
|
+
* @returns A function that takes an element and returns the adapted element for PDFMake,
|
|
51
|
+
* or the original element if it does not contain the specified property.
|
|
52
|
+
*/
|
|
53
|
+
const createPageElementAdapter = (propertyName) => {
|
|
54
|
+
return (element) => {
|
|
55
|
+
if (!hasProperty(element, propertyName)) {
|
|
56
|
+
return element;
|
|
57
|
+
}
|
|
58
|
+
const propertyValue = element[propertyName];
|
|
59
|
+
// If property is already a function, leave it as is
|
|
60
|
+
if (typeof propertyValue === "function") {
|
|
61
|
+
return element;
|
|
62
|
+
}
|
|
63
|
+
// If property is an object, wrap it in a function that replaces placeholders
|
|
64
|
+
const dynamicContent = (currentPage, pageCount) => {
|
|
65
|
+
return replacePlaceholders(propertyValue, currentPage, pageCount);
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
...element,
|
|
69
|
+
[propertyName]: dynamicContent,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Adapter for header elements with page number placeholder support.
|
|
75
|
+
*/
|
|
76
|
+
const headerAdapter = () => createPageElementAdapter("header");
|
|
77
|
+
exports.headerAdapter = headerAdapter;
|
|
78
|
+
/**
|
|
79
|
+
* Adapter for footer elements with page number placeholder support.
|
|
80
|
+
*/
|
|
81
|
+
const footerAdapter = () => createPageElementAdapter("footer");
|
|
82
|
+
exports.footerAdapter = footerAdapter;
|
|
83
|
+
//# sourceMappingURL=page-element-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-element-adapter.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/page-element-adapter.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAM,WAAW,GAAG,CAClB,OAAgB,EAChB,YAAe,EACiC,EAAE;IAClD,OAAO,CACL,OAAO,KAAK,IAAI;QAChB,OAAO,OAAO,KAAK,QAAQ;QAC3B,YAAY,IAAI,OAAO;QACtB,OAAmC,CAAC,YAAY,CAAC,KAAK,SAAS,CACjE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,mBAAmB,GAAG,CAC1B,GAAY,EACZ,WAAmB,EACnB,SAAiB,EACR,EAAE;IACX,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG;aACP,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;aAChD,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5C,MAAM,M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Type guard to check if an element has a specific property\n */\nconst hasProperty = <T extends string>(\n element: unknown,\n propertyName: T,\n): element is Record<T, Content | DynamicContent> => {\n return (\n element !== null &&\n typeof element === \"object\" &&\n propertyName in element &&\n (element as Record<string, unknown>)[propertyName] !== undefined\n );\n};\n\n/**\n * Recursively searches for [CurrentPage] and [PageCount] placeholders in an object\n * and replaces them with the actual values.\n *\n * @param obj - The object to process\n * @param currentPage - The current page number\n * @param pageCount - The total page count\n * @returns The processed object with replaced placeholders\n */\nconst replacePlaceholders = (\n obj: unknown,\n currentPage: number,\n pageCount: number,\n): unknown => {\n if (typeof obj === \"string\") {\n return obj\n .replace(/\\[CurrentPage\\]/g, String(currentPage))\n .replace(/\\[PageCount\\]/g, String(pageCount));\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => replacePlaceholders(item, currentPage, pageCount));\n }\n\n if (obj !== null && typeof obj === \"object\") {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = replacePlaceholders(value, currentPage, pageCount);\n }\n return result;\n }\n\n return obj;\n};\n\n/**\n * Adapts a header or footer to support dynamic page number placeholders.\n *\n * This adapter function checks if the provided element contains the specified property (header or footer).\n * - If the property is already a function, it leaves it unchanged.\n * - If the property is an object, it wraps it in a function that replaces\n * [CurrentPage] with the current page number and [PageCount] with the total\n * page count at rendering time.\n *\n * @param propertyName - The name of the property to adapt ('header' or 'footer')\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 the specified property.\n */\nconst createPageElementAdapter = (propertyName: \"header\" | \"footer\") => {\n return (element: unknown): unknown => {\n if (!hasProperty(element, propertyName)) {\n return element;\n }\n\n const propertyValue = element[propertyName];\n\n // If property is already a function, leave it as is\n if (typeof propertyValue === \"function\") {\n return element;\n }\n\n // If property is an object, wrap it in a function that replaces placeholders\n const dynamicContent: DynamicContent = (currentPage, pageCount) => {\n return replacePlaceholders(\n propertyValue,\n currentPage,\n pageCount,\n ) as Content;\n };\n\n return {\n ...element,\n [propertyName]: dynamicContent,\n };\n };\n};\n\n/**\n * Adapter for header elements with page number placeholder support.\n */\nexport const headerAdapter = () => createPageElementAdapter(\"header\");\n\n/**\n * Adapter for footer elements with page number placeholder support.\n */\nexport const footerAdapter = () => createPageElementAdapter(\"footer\");\n"]}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContentImage, Table, TDocumentDefinitions } from "pdfmake/interfaces";
|
|
2
|
+
import { SmeupDataObj, WebupManagerData } from "../../../types";
|
|
2
3
|
import { SmeupDataStructure } from "../../../types/data-structures/smeupDataStructure";
|
|
4
|
+
import { SmeupDataTable } from "../../../types/data-structures/smeupDataTable";
|
|
3
5
|
/**
|
|
4
6
|
* Context passed to adapter functions during document processing.
|
|
5
7
|
*/
|
|
6
8
|
export interface PdfMakeConverterContext<T extends SmeupDataStructure = SmeupDataStructure> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
path: string[];
|
|
11
|
-
/** Current depth in the document tree */
|
|
12
|
-
depth: number;
|
|
9
|
+
webupManagerData: WebupManagerData;
|
|
10
|
+
pdfDocument?: TDocumentDefinitions;
|
|
11
|
+
damSvcEndpoint?: string;
|
|
13
12
|
getSmeupDataStructure?: (fun: string) => Promise<T>;
|
|
13
|
+
fetchData?: (url: string) => Promise<Response>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Function that transforms an element from custom format to pdfmake standard format.
|
|
@@ -27,9 +27,34 @@ export interface AdapterRegistry {
|
|
|
27
27
|
/** Unregister an adapter for a specific element type */
|
|
28
28
|
unregister: (elementType: string) => void;
|
|
29
29
|
/** Process a document by applying registered adapters */
|
|
30
|
-
process: (document: unknown, context
|
|
30
|
+
process: (document: unknown, context: Partial<PdfMakeConverterContext>) => Promise<unknown>;
|
|
31
31
|
}
|
|
32
32
|
export declare class AdapterError extends Error {
|
|
33
33
|
element: unknown;
|
|
34
34
|
constructor(message: string, element: unknown);
|
|
35
35
|
}
|
|
36
|
+
interface SmeupExtensionImageMetadata {
|
|
37
|
+
url?: string;
|
|
38
|
+
obj?: SmeupDataObj;
|
|
39
|
+
}
|
|
40
|
+
interface SmeupExtensionTableMetadata {
|
|
41
|
+
fun?: string;
|
|
42
|
+
data?: SmeupDataTable;
|
|
43
|
+
}
|
|
44
|
+
export interface ContentImageExtension extends ContentImage {
|
|
45
|
+
smeup?: SmeupExtensionImageMetadata;
|
|
46
|
+
}
|
|
47
|
+
export interface TableExtension extends Table {
|
|
48
|
+
smeup?: SmeupExtensionTableMetadata;
|
|
49
|
+
}
|
|
50
|
+
export interface ElementWithImageExtension {
|
|
51
|
+
image: ContentImage & {
|
|
52
|
+
smeup?: SmeupExtensionImageMetadata;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface ElementWithTableExtension {
|
|
56
|
+
table: Table & {
|
|
57
|
+
smeup?: SmeupExtensionTableMetadata;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
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 { WebupManagerData } from \"../../../types\";\nimport { SmeupDataStructure } from \"../../../types/data-structures/smeupDataStructure\";\n\n/**\n * Context passed to adapter functions during document processing.\n */\nexport interface PdfMakeConverterContext<\n T extends SmeupDataStructure = SmeupDataStructure,\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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PdfMakeConverterContext } from "./pdfmake.types";
|
|
1
|
+
import { ElementWithTableExtension, PdfMakeConverterContext } from "./pdfmake.types";
|
|
2
2
|
/**
|
|
3
3
|
* Adapts a Smeup table structure to the PDFMake table format.
|
|
4
4
|
*
|
|
@@ -10,7 +10,7 @@ import { PdfMakeConverterContext } from "./pdfmake.types";
|
|
|
10
10
|
* @returns A function that takes an element and returns the adapted element for PDFMake,
|
|
11
11
|
* or the original element if it does not contain a valid table with data.
|
|
12
12
|
*/
|
|
13
|
-
export declare
|
|
13
|
+
export declare const smeupTableToPdfMakeTableAdapter: () => (element: unknown, context: PdfMakeConverterContext) => ElementWithTableExtension;
|
|
14
14
|
/**
|
|
15
15
|
* Adapter function for converting a table element with a `fun` property to a Smeup table structure.
|
|
16
16
|
*
|
|
@@ -27,5 +27,5 @@ export declare function smeupTableToPdfMakeTableAdapter(): (element: unknown) =>
|
|
|
27
27
|
* @param element - The input element to be adapted.
|
|
28
28
|
* @param context - The conversion context, which must provide `getSmeupDataStructure` if the `fun` property is present.
|
|
29
29
|
*/
|
|
30
|
-
export declare
|
|
31
|
-
export declare
|
|
30
|
+
export declare const funToSmeupTableAdapter: () => (element: unknown, context: PdfMakeConverterContext) => Promise<ElementWithTableExtension>;
|
|
31
|
+
export declare const dataTableAdapter: () => (element: unknown, context: PdfMakeConverterContext) => Promise<ElementWithTableExtension>;
|
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.smeupTableToPdfMakeTableAdapter =
|
|
4
|
-
|
|
5
|
-
exports.dataTableAdapter = dataTableAdapter;
|
|
3
|
+
exports.dataTableAdapter = exports.funToSmeupTableAdapter = exports.smeupTableToPdfMakeTableAdapter = void 0;
|
|
4
|
+
const types_1 = require("../../../types");
|
|
6
5
|
const smeupDataStructure_1 = require("../../../types/data-structures/smeupDataStructure");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
element.table.data.type ===
|
|
21
|
-
smeupDataStructure_1.SmeupDataStructureType.SmeupDataTable &&
|
|
22
|
-
"rows" in element.table.data &&
|
|
23
|
-
"columns" in
|
|
24
|
-
element.table.data);
|
|
25
|
-
}
|
|
26
|
-
function hasTableWithFun(element) {
|
|
27
|
-
return (typeof element.table.fun === "string" &&
|
|
28
|
-
element.table.fun.length > 0);
|
|
29
|
-
}
|
|
6
|
+
const commons_utility_1 = require("../../../utils/commons-utility");
|
|
7
|
+
const hasTableWithDataTable = (element) => {
|
|
8
|
+
const table = element?.table;
|
|
9
|
+
const data = table?.smeup?.data;
|
|
10
|
+
return (data?.type === smeupDataStructure_1.SmeupDataStructureType.SmeupDataTable &&
|
|
11
|
+
data?.rows !== undefined &&
|
|
12
|
+
data?.columns !== undefined);
|
|
13
|
+
};
|
|
14
|
+
const hasTableWithFun = (element) => {
|
|
15
|
+
const table = element?.table;
|
|
16
|
+
const fun = table?.smeup?.fun;
|
|
17
|
+
return typeof fun === "string" && fun.length > 0;
|
|
18
|
+
};
|
|
30
19
|
/**
|
|
31
20
|
* Adapts a Smeup table structure to the PDFMake table format.
|
|
32
21
|
*
|
|
@@ -38,35 +27,44 @@ function hasTableWithFun(element) {
|
|
|
38
27
|
* @returns A function that takes an element and returns the adapted element for PDFMake,
|
|
39
28
|
* or the original element if it does not contain a valid table with data.
|
|
40
29
|
*/
|
|
41
|
-
|
|
42
|
-
return (element) => {
|
|
30
|
+
const smeupTableToPdfMakeTableAdapter = () => {
|
|
31
|
+
return (element, context) => {
|
|
43
32
|
if (!hasTableWithDataTable(element)) {
|
|
44
33
|
return element;
|
|
45
34
|
}
|
|
46
|
-
const { columns, rows } = element.table.data;
|
|
35
|
+
const { columns, rows } = element.table.smeup.data;
|
|
47
36
|
// Build header row from column titles
|
|
48
37
|
const headerRow = columns.map(col => col.title);
|
|
49
38
|
// Build data rows by extracting values in column order
|
|
50
39
|
const dataRows = rows.map(row => columns.map(col => {
|
|
51
40
|
const cell = row.cells?.[col.name];
|
|
52
|
-
const value = cell
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
const value = (0, commons_utility_1.calculateCellValue)(cell, types_1.SupportedExportFormats.PDF, context.webupManagerData);
|
|
42
|
+
return {
|
|
43
|
+
text: value != null ? String(value) : "",
|
|
44
|
+
alignment: col.obj?.t === "NR" ? "right" : "left",
|
|
45
|
+
};
|
|
55
46
|
}));
|
|
56
47
|
// Combine header and data rows
|
|
57
48
|
const body = [headerRow, ...dataRows];
|
|
58
|
-
// Extract all properties except 'data' from the
|
|
49
|
+
// Extract all properties except 'data' from the smeup object
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
+
const { data, ...smeupRest } = element.table.smeup;
|
|
52
|
+
// Extract all properties except 'smeup' from the table object
|
|
59
53
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
60
|
-
const {
|
|
54
|
+
const { smeup, ...tableRest } = element.table;
|
|
61
55
|
return {
|
|
62
56
|
...element,
|
|
63
57
|
table: {
|
|
64
58
|
...tableRest,
|
|
59
|
+
smeup: {
|
|
60
|
+
...smeupRest,
|
|
61
|
+
},
|
|
65
62
|
body,
|
|
66
63
|
},
|
|
67
64
|
};
|
|
68
65
|
};
|
|
69
|
-
}
|
|
66
|
+
};
|
|
67
|
+
exports.smeupTableToPdfMakeTableAdapter = smeupTableToPdfMakeTableAdapter;
|
|
70
68
|
/**
|
|
71
69
|
* Adapter function for converting a table element with a `fun` property to a Smeup table structure.
|
|
72
70
|
*
|
|
@@ -83,7 +81,7 @@ function smeupTableToPdfMakeTableAdapter() {
|
|
|
83
81
|
* @param element - The input element to be adapted.
|
|
84
82
|
* @param context - The conversion context, which must provide `getSmeupDataStructure` if the `fun` property is present.
|
|
85
83
|
*/
|
|
86
|
-
|
|
84
|
+
const funToSmeupTableAdapter = () => {
|
|
87
85
|
return async (element, context) => {
|
|
88
86
|
if (!hasTableWithFun(element)) {
|
|
89
87
|
return element;
|
|
@@ -93,26 +91,36 @@ function funToSmeupTableAdapter() {
|
|
|
93
91
|
throw new Error("getSmeupDataStructure function is required in context when the fun property is used");
|
|
94
92
|
}
|
|
95
93
|
else {
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
94
|
+
const elementWithTable = element;
|
|
95
|
+
const funStr = elementWithTable.table.smeup.fun;
|
|
96
|
+
const dataTable = (await context.getSmeupDataStructure(funStr));
|
|
97
|
+
// Extract all properties except 'fun' from the smeup object
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
+
const { fun, ...smeupRest } = elementWithTable.table.smeup;
|
|
100
|
+
// Extract all properties except 'smeup' from the table object
|
|
99
101
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
|
-
const {
|
|
102
|
+
const { smeup, ...tableRest } = elementWithTable.table;
|
|
101
103
|
return {
|
|
102
|
-
...
|
|
104
|
+
...elementWithTable,
|
|
103
105
|
table: {
|
|
104
106
|
...tableRest,
|
|
105
|
-
|
|
107
|
+
body: tableRest.body,
|
|
108
|
+
smeup: {
|
|
109
|
+
...smeupRest,
|
|
110
|
+
data: dataTable,
|
|
111
|
+
},
|
|
106
112
|
},
|
|
107
113
|
};
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
};
|
|
111
|
-
}
|
|
112
|
-
|
|
117
|
+
};
|
|
118
|
+
exports.funToSmeupTableAdapter = funToSmeupTableAdapter;
|
|
119
|
+
const dataTableAdapter = () => {
|
|
113
120
|
return async (element, context) => {
|
|
114
|
-
const adaptedElement = await funToSmeupTableAdapter()(element, context);
|
|
115
|
-
return await smeupTableToPdfMakeTableAdapter()(adaptedElement);
|
|
121
|
+
const adaptedElement = await (0, exports.funToSmeupTableAdapter)()(element, context);
|
|
122
|
+
return (await (0, exports.smeupTableToPdfMakeTableAdapter)()(adaptedElement, context));
|
|
116
123
|
};
|
|
117
|
-
}
|
|
124
|
+
};
|
|
125
|
+
exports.dataTableAdapter = dataTableAdapter;
|
|
118
126
|
//# sourceMappingURL=table-adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-adapter.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/table-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"table-adapter.js","sourceRoot":"","sources":["../../../../src/converters/pdf/pdfmake/table-adapter.ts"],"names":[],"mappings":";;;AACA,0CAAwD;AACxD,0FAA2F;AAK3F,oEAAoE;AAOpE,MAAM,qBAAqB,GAAG,CAC5B,OAAgB,EACsB,EAAE;IACxC,MAAM,KAAK,GAAI,OAAmC,EAAE,KAAuB,CAAC;IAC5E,MAAM,IAAI,GAAG,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC;IAChC,OAAO,CACL,IAAI,EAAE,IAAI,KAAK,2CAAsB,CAAC,cAAc;QACpD,IAAI,EAAE,IAAI,KAAK,SAAS;QACxB,IAAI,EAAE,OAAO,KAAK,SAAS,CAC5B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,OAAgB,EACsB,EAAE;IACxC,MAAM,KAAK,GAAI,OAAmC,EAAE,KAAuB,CAAC;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AAG,gBAAgB,CAAC,KAAK,CAAC;gBAEvD,OAAO;oBACL,GAAG,gBAAgB;oBACnB,KAAK,EAAE;wBACL,GAAG,SAAS;wBACZ,IAAI,EAAE,SAAS,CAAC,IAAI;wBACpB,KAAK,EAAE;4BACL,GAAG,SAAS;4BACZ,IAAI,EAAE,SAAS;yBAChB;qBACF;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAvCW,QAAA,sBAAsB,0BAuCjC;AAEK,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,KAAK,EACV,OAAgB,EAChB,OAAgC,EACI,EAAE;QACtC,MAAM,cAAc,GAAG,MAAM,IAAA,8BAAsB,GAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxE,OAAO,CAAC,MAAM,IAAA,uCAA+B,GAAE,CAC7C,cAAc,EACd,OAAO,CACR,CAA8B,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW3B","sourcesContent":["import { TableCell } from \"pdfmake/interfaces\";\nimport { SupportedExportFormats } from \"../../../types\";\nimport { SmeupDataStructureType } from \"../../../types/data-structures/smeupDataStructure\";\nimport {\n SmeupDataCell,\n SmeupDataTable,\n} from \"../../../types/data-structures/smeupDataTable\";\nimport { calculateCellValue } from \"../../../utils/commons-utility\";\nimport {\n ElementWithTableExtension,\n PdfMakeConverterContext,\n TableExtension,\n} from \"./pdfmake.types\";\n\nconst hasTableWithDataTable = (\n element: unknown,\n): element is ElementWithTableExtension => {\n const table = (element as Record<string, unknown>)?.table as TableExtension;\n const data = table?.smeup?.data;\n return (\n data?.type === SmeupDataStructureType.SmeupDataTable &&\n data?.rows !== undefined &&\n data?.columns !== undefined\n );\n};\n\nconst hasTableWithFun = (\n element: unknown,\n): element is ElementWithTableExtension => {\n const table = (element as Record<string, unknown>)?.table as TableExtension;\n const fun = table?.smeup?.fun;\n return typeof fun === \"string\" && fun.length > 0;\n};\n\n/**\n * Adapts a Smeup table structure to the PDFMake table format.\n *\n * This adapter function checks if the provided element contains a table with data.\n * If so, it transforms the table's columns and rows into the PDFMake `body` format,\n * where the first row is the header (column titles) and subsequent rows are the data.\n * All properties of the original table except `data` 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 valid table with data.\n */\nexport const smeupTableToPdfMakeTableAdapter = () => {\n return (\n element: unknown,\n context: PdfMakeConverterContext,\n ): ElementWithTableExtension => {\n if (!hasTableWithDataTable(element)) {\n return element as ElementWithTableExtension;\n }\n\n const { columns, rows } = element.table.smeup!.data!;\n\n // Build header row from column titles\n const headerRow = columns.map(col => col.title);\n\n // Build data rows by extracting values in column order\n const dataRows = rows.map(row =>\n columns.map(col => {\n const cell = row.cells?.[col.name] as SmeupDataCell;\n const value = calculateCellValue(\n cell,\n SupportedExportFormats.PDF,\n context.webupManagerData,\n );\n return {\n text: value != null ? String(value) : \"\",\n alignment: col.obj?.t === \"NR\" ? \"right\" : \"left\",\n };\n }),\n );\n\n // Combine header and data rows\n const body = [headerRow, ...dataRows] as TableCell[][];\n\n // Extract all properties except 'data' from the smeup object\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { data, ...smeupRest } = element.table.smeup!;\n // Extract all properties except 'smeup' from the table object\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { smeup, ...tableRest } = element.table;\n\n return {\n ...element,\n table: {\n ...tableRest,\n smeup: {\n ...smeupRest,\n },\n body,\n },\n };\n };\n};\n\n/**\n * Adapter function for converting a table element with a `fun` property to a Smeup table structure.\n *\n * This function returns an asynchronous converter that checks if the provided element contains\n * a table with a `fun` property. If present, it uses the `getSmeupDataStructure` function from\n * the context to fetch the table data corresponding to the `fun` string, and replaces the original\n * table's `fun` property with the fetched data under the `data` property. All other properties\n * of the table are preserved.\n *\n * @returns An asynchronous function that takes an element and a context, and returns the adapted element.\n *\n * @throws If the context does not provide a `getSmeupDataStructure` function when the `fun` property is used.\n *\n * @param element - The input element to be adapted.\n * @param context - The conversion context, which must provide `getSmeupDataStructure` if the `fun` property is present.\n */\nexport const funToSmeupTableAdapter = () => {\n return async (\n element: unknown,\n context: PdfMakeConverterContext,\n ): Promise<ElementWithTableExtension> => {\n if (!hasTableWithFun(element)) {\n return element as ElementWithTableExtension;\n } else {\n if (!context.getSmeupDataStructure) {\n throw new Error(\n \"getSmeupDataStructure function is required in context when the fun property is used\",\n );\n } else {\n const elementWithTable = element as ElementWithTableExtension;\n const funStr = elementWithTable.table.smeup!.fun!;\n const dataTable = (await context.getSmeupDataStructure(\n funStr,\n )) as SmeupDataTable;\n // Extract all properties except 'fun' from the smeup object\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { fun, ...smeupRest } = elementWithTable.table.smeup!;\n // Extract all properties except 'smeup' from the table object\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { smeup, ...tableRest } = elementWithTable.table;\n\n return {\n ...elementWithTable,\n table: {\n ...tableRest,\n body: tableRest.body,\n smeup: {\n ...smeupRest,\n data: dataTable,\n },\n },\n };\n }\n }\n };\n};\n\nexport const dataTableAdapter = () => {\n return async (\n element: unknown,\n context: PdfMakeConverterContext,\n ): Promise<ElementWithTableExtension> => {\n const adaptedElement = await funToSmeupTableAdapter()(element, context);\n return (await smeupTableToPdfMakeTableAdapter()(\n adaptedElement,\n context,\n )) as ElementWithTableExtension;\n };\n};\n"]}
|
|
@@ -2,12 +2,13 @@ import { SmeupDataTable } from "../types/data-structures/smeupDataTable";
|
|
|
2
2
|
import { SmeupSch } from "../types/data-structures/smeupSch";
|
|
3
3
|
import { WebupManagerData, GenericObject } from "../types/index";
|
|
4
4
|
import type { PdfMakeConverterContext } from "./pdf/pdfmake/pdfmake.types";
|
|
5
|
+
import type { TDocumentDefinitions } from "pdfmake/interfaces";
|
|
5
6
|
import { fillPdfForm, FillPdfFormOptions } from "./pdf/form-filler";
|
|
6
7
|
export declare const schedaToPdfData: (sch: SmeupSch, webupManagerData: WebupManagerData) => Promise<Buffer>;
|
|
7
8
|
export declare const dataTableToPdfData: (component: {
|
|
8
9
|
smeupDataTable: SmeupDataTable;
|
|
9
10
|
props: GenericObject;
|
|
10
11
|
}, webupManagerData: WebupManagerData) => Promise<Buffer | Uint8Array>;
|
|
11
|
-
export declare const pdfmakeDocumentToPdfData: (documentDefinition:
|
|
12
|
+
export declare const pdfmakeDocumentToPdfData: (documentDefinition: TDocumentDefinitions, context: Partial<PdfMakeConverterContext>) => Promise<Buffer>;
|
|
12
13
|
export { fillPdfForm };
|
|
13
14
|
export type { FillPdfFormOptions };
|
|
@@ -16,6 +16,8 @@ Object.defineProperty(exports, "fillPdfForm", { enumerable: true, get: function
|
|
|
16
16
|
const adapter_processor_1 = require("./pdf/pdfmake/adapter-processor");
|
|
17
17
|
const adapter_registry_1 = require("./pdf/pdfmake/adapter-registry");
|
|
18
18
|
const table_adapter_1 = require("./pdf/pdfmake/table-adapter");
|
|
19
|
+
const image_adapter_1 = require("./pdf/pdfmake/image-adapter");
|
|
20
|
+
const page_element_adapter_1 = require("./pdf/pdfmake/page-element-adapter");
|
|
19
21
|
const schedaToPdfData = async (sch, webupManagerData) => {
|
|
20
22
|
const doc = await (0, sch_converter_1.schedaToPdfDoc)(sch);
|
|
21
23
|
return Buffer.from(doc.output("arraybuffer"));
|
|
@@ -48,9 +50,13 @@ const pdfmakeDocumentToPdfData = async (documentDefinition, context) => {
|
|
|
48
50
|
// Register adapters
|
|
49
51
|
const registry = (0, adapter_registry_1.createAdapterRegistry)();
|
|
50
52
|
registry.register("table", (0, table_adapter_1.dataTableAdapter)());
|
|
53
|
+
registry.register("image", (0, image_adapter_1.imageAdapter)());
|
|
54
|
+
registry.register("footer", (0, page_element_adapter_1.footerAdapter)());
|
|
55
|
+
registry.register("header", (0, page_element_adapter_1.headerAdapter)());
|
|
56
|
+
context.pdfDocument = documentDefinition;
|
|
51
57
|
// Pre-process document with adapters
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
const processedDoc = await (0, adapter_processor_1.preProcessPdfMakeDocument)(documentDefinition, context, registry);
|
|
59
|
+
console.debug("Processed pdfmake document:", JSON.stringify(processedDoc, null, 2));
|
|
54
60
|
// Render the document using pdfmake
|
|
55
61
|
return (0, pdfmake_renderer_1.renderPdfMakeDocument)(processedDoc);
|
|
56
62
|
};
|
|
@@ -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;
|
|
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;AA0G3D,4FA1GA,yBAAW,OA0GA;AAzGpB,uEAA4E;AAC5E,qEAAuE;AACvE,+DAA+D;AAC/D,+DAA2D;AAC3D,6EAG4C;AAErC,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,QAAQ,GAAG,IAAA,2CAAwB,EACvC,SAAS,EACT,8BAAsB,CAAC,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ACN,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\";\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\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"]}
|
|
@@ -60,3 +60,4 @@ export declare const loadImageAsBase64: (imageUrl: string) => Promise<string | n
|
|
|
60
60
|
* Converts a hexadecimal color string (e.g., "#RRGGBB" or "0xRRGGBB") to an RGB tuple.
|
|
61
61
|
*/
|
|
62
62
|
export declare const convertColorToRgb: (color: string) => [number, number, number];
|
|
63
|
+
export declare const customFetch: (url: string) => Promise<Response>;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertColorToRgb = exports.loadImageAsBase64 = exports.convertToBuffer = exports.hexToArgb = exports.calculateValue = exports.calculateCellValue = exports.sortRows = exports.isFilterMatchValue = exports.filterRows = exports.updateMaxValueLength = exports.getFilteredColumns = void 0;
|
|
6
|
+
exports.customFetch = exports.convertColorToRgb = exports.loadImageAsBase64 = exports.convertToBuffer = exports.hexToArgb = exports.calculateValue = exports.calculateCellValue = exports.sortRows = exports.isFilterMatchValue = exports.filterRows = exports.updateMaxValueLength = exports.getFilteredColumns = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
4
9
|
const excel_converter_types_1 = require("../converters/excel/excel-converter.types");
|
|
5
10
|
const component_props_1 = require("../types/component-props");
|
|
6
11
|
const dates_utility_1 = require("./dates-utility");
|
|
@@ -238,7 +243,7 @@ const calculateValue = (value, obj, bookType, webupManagerData) => {
|
|
|
238
243
|
? numValue
|
|
239
244
|
: "";
|
|
240
245
|
}
|
|
241
|
-
return (0, formatter_utility_1.sanitizeString)(value
|
|
246
|
+
return (0, formatter_utility_1.sanitizeString)(value ?? "");
|
|
242
247
|
};
|
|
243
248
|
exports.calculateValue = calculateValue;
|
|
244
249
|
/**
|
|
@@ -315,4 +320,44 @@ const convertColorToRgb = (color) => {
|
|
|
315
320
|
return [r, g, b];
|
|
316
321
|
};
|
|
317
322
|
exports.convertColorToRgb = convertColorToRgb;
|
|
323
|
+
// Custom fetch function that handles both HTTP and file:// URLs
|
|
324
|
+
const customFetch = async (url) => {
|
|
325
|
+
if (url.startsWith("file://")) {
|
|
326
|
+
// Handle file:// URLs by reading from filesystem
|
|
327
|
+
const filePath = url.replace(/^file:\/\/\//, "");
|
|
328
|
+
try {
|
|
329
|
+
const buffer = await promises_1.default.readFile(filePath);
|
|
330
|
+
const ext = path_1.default.extname(filePath).toLowerCase();
|
|
331
|
+
// Determine MIME type from extension
|
|
332
|
+
const mimeTypes = {
|
|
333
|
+
".png": "image/png",
|
|
334
|
+
".jpg": "image/jpeg",
|
|
335
|
+
".jpeg": "image/jpeg",
|
|
336
|
+
".gif": "image/gif",
|
|
337
|
+
".svg": "image/svg+xml",
|
|
338
|
+
".webp": "image/webp",
|
|
339
|
+
};
|
|
340
|
+
const contentType = mimeTypes[ext] || "application/octet-stream";
|
|
341
|
+
return new Response(buffer, {
|
|
342
|
+
status: 200,
|
|
343
|
+
headers: {
|
|
344
|
+
"content-type": contentType,
|
|
345
|
+
"content-length": buffer.length.toString(),
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
console.error(`Error reading file at ${filePath}:`, error);
|
|
351
|
+
return new Response(null, {
|
|
352
|
+
status: 404,
|
|
353
|
+
statusText: `File not found: ${filePath}`,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
// Use standard fetch for HTTP(S) URLs
|
|
359
|
+
return fetch(url);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
exports.customFetch = customFetch;
|
|
318
363
|
//# sourceMappingURL=commons-utility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commons-utility.js","sourceRoot":"","sources":["../../src/utils/commons-utility.ts"],"names":[],"mappings":";;;AAAA,qFAAyF;AACzF,8DAAgE;AAchE,mDAA2E;AAC3E,2DAAqD;AACrD,iDAGwB;AACxB,uDAI2B;AAEpB,MAAM,kBAAkB,GAAG,CAChC,OAA0B,EAC1B,KAAoB,EACpB,cAAsD,EAAE,EACxD,EAAE;IACF,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAC/B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CACH,CAAC;IAEvB,MAAM,eAAe,GAAsB,EAAE,CAAC;IAE9C,IAAI,KAAK,CAAC,cAAc,IAAK,KAAK,CAAC,cAA2B,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzE,KAAK,CAAC,cAA2B,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;YACzD,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;YAC7D,IAAI,WAAW,EAAE,CAAC;gBAChB,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,e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AAA,iBAAiB,qBAK5B","sourcesContent":["import { exportTypeSupportsFormatting } from \"../converters/excel/excel-converter.types\";\nimport { SortMode, SortObject } from \"../types/component-props\";\nimport {\n SmeupDataColumn,\n SmeupDataTable,\n SmeupDataCell,\n SmeupDataRow,\n} from \"../types/data-structures/smeupDataTable\";\nimport {\n SmeupDataObj,\n ColumnFilter,\n WebupManagerData,\n SupportedExportFormats,\n GenericObject,\n} from \"../types/index\";\nimport { datesIsIsoDate, datesToDate, datesFormat } from \"./dates-utility\";\nimport { sanitizeString } from \"./formatter-utility\";\nimport {\n mathNumberStringToFormattedString,\n mathCountDecimals,\n} from \"./math-utility\";\nimport {\n objectsIsVoCodVer,\n objectsIsDate,\n objectsIsNumber,\n} from \"./objects-utility\";\n\nexport const getFilteredColumns = (\n columns: SmeupDataColumn[],\n props: GenericObject,\n groupsArray: { column: string; visible: boolean }[] = [],\n) => {\n if (!columns) return [];\n\n const mutableColumns = JSON.parse(\n JSON.stringify(columns),\n ) as SmeupDataColumn[];\n\n const filteredColumns: SmeupDataColumn[] = [];\n\n if (props.visibleColumns && (props.visibleColumns as string[]).length > 0) {\n (props.visibleColumns as string[]).forEach((col: string) => {\n const foundColumn = mutableColumns.find(c => c.name === col);\n if (foundColumn) {\n filteredColumns.push({ ...foundColumn });\n }\n });\n } else {\n filteredColumns.push(...mutableColumns);\n }\n\n // Set the visibility of columns based on groups and props\n filteredColumns.forEach((col: SmeupDataColumn) => {\n const isGroupedColumn = groupsArray.filter(g => g.column === col.name);\n col.visible = props.visibleColumns\n ? (props.visibleColumns as string[]).includes(col.name)\n : col.visible;\n col.visible =\n isGroupedColumn.length > 0 ? isGroupedColumn[0].visible : col.visible;\n });\n\n return filteredColumns.filter(column => {\n const dataObject = {\n ...column.obj,\n k: \"\",\n } as SmeupDataObj;\n return column.obj?.t !== \"J4\" && !objectsIsVoCodVer(dataObject);\n });\n};\n\n/**\n * By passing the map, length value and column name\n * creates or updates a map record with\n * @param map Contains columnNames and their longest cell's length\n * @param text The text to use in length calculation\n * @param colName The column to check\n */\nexport const updateMaxValueLength = (\n map: { [key: string]: number },\n text: string | undefined | null,\n colName: string,\n) => {\n if (!map || !text || !colName) return;\n\n const value = Math.max(...text.split(\"\\n\").map(line => line.length));\n if (map[colName]) {\n if (map[colName] < value) {\n map[colName] = value;\n }\n } else {\n map[colName] = value;\n }\n};\n\nexport const filterRows = (\n smeupDataTable: SmeupDataTable,\n filteredColumns: SmeupDataColumn[],\n filters: { [key: string]: ColumnFilter },\n) => {\n if (filters) {\n return smeupDataTable.rows.filter(row => {\n return smeupDataTable.columns.every(col => {\n const cellValue = row.cells?.[col.name]?.value;\n const columnFilter = filters[col.name];\n if (columnFilter?.checkBoxes?.length) {\n const allowedValues = columnFilter.checkBoxes.map(item => item.value);\n return (\n typeof cellValue === \"string\" && allowedValues.includes(cellValue)\n );\n }\n if (columnFilter?.textField) {\n return (\n typeof cellValue === \"string\" &&\n isFilterMatchValue(cellValue, columnFilter.textField)\n );\n }\n return true;\n });\n });\n } else {\n return smeupDataTable.rows;\n }\n};\n\nexport const isFilterMatchValue = (value: string, filter: string): boolean => {\n if (value == null) value = \"\";\n if (filter == null) filter = \"\";\n\n value = value.trim();\n filter = filter.trim();\n\n // Regex for operators and filter\n // Examples: !'text', >'aa', >= 'ab', <'cza', <= 'asd', 'text', 'text%', '%text', '%text%'\n const regex = /^([!><]=?|)(?:'(%?)(.*?)(%?)')?$/;\n const match = filter.match(regex);\n if (!match) {\n // fallback: inclusion\n return value.includes(filter);\n }\n\n const operator = match[1];\n const startWildcard = match[2] === \"%\";\n const filterText = match[3] ?? \"\";\n const endWildcard = match[4] === \"%\";\n\n // Handle '' (void)\n if (filterText === \"\" && match[0].includes(\"''\")) {\n if (operator === \"!\") {\n return value !== \"\";\n }\n return value === \"\";\n }\n\n // Handle operators of comparison\n if ([\">\", \">=\", \"<\", \"<=\"].includes(operator)) {\n if (operator === \">\") {\n return value > filterText;\n }\n if (operator === \">=\") {\n return value >= filterText;\n }\n if (operator === \"<\") {\n return value < filterText;\n }\n if (operator === \"<=\") {\n return value <= filterText;\n }\n }\n\n // Negation\n if (operator === \"!\") {\n // Match negation\n if (startWildcard && endWildcard) {\n return !value.includes(filterText);\n }\n if (startWildcard) {\n return !value.endsWith(filterText);\n }\n if (endWildcard) {\n return !value.startsWith(filterText);\n }\n // Exact match negation\n return value !== filterText;\n }\n\n // Wildcard\n if (startWildcard && endWildcard) {\n return value.includes(filterText);\n }\n if (startWildcard) {\n return value.endsWith(filterText);\n }\n if (endWildcard) {\n return value.startsWith(filterText);\n }\n\n // Exact match between quotes\n if (filter.startsWith(\"'\") && filter.endsWith(\"'\")) {\n return value === filterText;\n }\n\n // Fallback: inclusion\n return value.includes(filterText);\n};\n\nexport const sortRows = (\n rows: SmeupDataRow[],\n sortObject: SortObject[],\n activeGroups?: string[],\n) => {\n const sort = sortObject?.[0];\n\n if (!sort && !activeGroups) {\n return;\n }\n\n if (!sort && activeGroups) {\n rows.sort((a, b) => {\n for (const group of activeGroups) {\n const valA = a.cells?.[group]?.value ?? \"\";\n const valB = b.cells?.[group]?.value ?? \"\";\n\n if (valA !== valB) {\n return valA.localeCompare(valB);\n }\n }\n return 0;\n });\n return;\n }\n\n sortObject?.forEach(sort => {\n rows.sort((a, b) => {\n const valA = a.cells?.[sort.column]?.value ?? \"\";\n const valB = b.cells?.[sort.column]?.value ?? \"\";\n\n switch (sort.sortMode) {\n case SortMode.A:\n if (valA !== valB) {\n return valA.localeCompare(valB);\n }\n return 0;\n case SortMode.D:\n if (valA !== valB) {\n return valB.localeCompare(valA);\n }\n return 0;\n }\n });\n });\n};\n\n/**\n * Returns a converted and formatted cell value (string, date, number)\n * @param cell - SmeupDataCell\n * @param bookType - SupportedExportFormats\n * @param webupManagerData - WebupManagerData\n * @returns\n */\nexport const calculateCellValue = (\n cell: SmeupDataCell,\n bookType: SupportedExportFormats,\n webupManagerData: WebupManagerData,\n) => {\n return calculateValue(\n cell.value,\n cell.obj ?? ({ t: \"\", p: \"\", k: \"\" } as SmeupDataObj),\n bookType,\n webupManagerData,\n );\n};\n\n/**\n * Calculates and formats a value based on its type and export format.\n *\n * - If the value is a date and the object indicates a date type, it returns a formatted date string or a Date object,\n * depending on the export format.\n * - If the value is a number and the object indicates a number type, it returns a formatted number string or a numeric value,\n * depending on the export format.\n * - Otherwise, it returns the original value or an empty string if the value is null or undefined.\n *\n * @param bookType - The export format type.\n * @param webupManagerData - Data containing locale and formatting information.\n * @param value - The value to be calculated and formatted.\n * @param obj - Optional object describing the type of the value.\n * @returns The formatted value, a Date object, a number, or the original value as a string.\n */\nexport const calculateValue = (\n value: string,\n obj: {\n t: string;\n p: string;\n k: string;\n },\n bookType: SupportedExportFormats,\n webupManagerData: WebupManagerData,\n) => {\n if (obj && objectsIsDate(obj) && datesIsIsoDate(value)) {\n return exportTypeSupportsFormatting[bookType]\n ? new Date(datesToDate(value, webupManagerData.datesLocale))\n : datesFormat(value, webupManagerData.datesLocale);\n }\n\n if (obj && objectsIsNumber(obj)) {\n if (!exportTypeSupportsFormatting[bookType]) {\n return (\n mathNumberStringToFormattedString(\n value,\n mathCountDecimals(Number(value) || 0),\n \"\",\n webupManagerData.mathLocale,\n ) || \"\"\n );\n }\n\n const numValue = Number(value);\n return !isNaN(numValue) && !(Math.abs(numValue) === Infinity)\n ? numValue\n : \"\";\n }\n\n return sanitizeString(value) ?? \"\";\n};\n\n/**\n * Conversion from Hexadecimal color to an AlphaRGB\n * @param hex string - Hexadecimal value, it can bot have and don't have the # prefix\n * @returns ARGB string code\n */\nexport const hexToArgb = (hex: string): string => {\n // Hex validation\n if (hex.startsWith(\"#\")) hex = hex.slice(1);\n if (hex.length !== 6) return \"\";\n\n // Value Parse and return\n const red = parseInt(hex.slice(0, 2), 16);\n const green = parseInt(hex.slice(2, 4), 16);\n const blue = parseInt(hex.slice(4, 6), 16);\n return `FF${red.toString(16).padStart(2, \"0\")}${green\n .toString(16)\n .padStart(2, \"0\")}${blue.toString(16).padStart(2, \"0\")}`;\n};\n\n// Utility function to detect if Buffer is available\nconst isBufferAvailable = (): boolean => {\n try {\n return typeof Buffer !== \"undefined\" && typeof Buffer.from === \"function\";\n } catch {\n return false;\n }\n};\n\n// Utility function to convert ArrayBuffer to Buffer or Uint8Array\nexport const convertToBuffer = (\n arrayBuffer: ArrayBuffer | Uint8Array,\n): Buffer | Uint8Array => {\n if (arrayBuffer instanceof Uint8Array) {\n return arrayBuffer;\n }\n if (isBufferAvailable()) {\n return Buffer.from(arrayBuffer);\n } else {\n return new Uint8Array(arrayBuffer);\n }\n};\n\n// Function to load an image as base64 (browser version, async)\nexport const loadImageAsBase64 = async (\n imageUrl: string,\n): Promise<string | null> => {\n try {\n const response = await fetch(imageUrl);\n if (!response.ok) return null;\n const blob = await response.blob();\n return await new Promise<string | null>((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n resolve(reader.result as string);\n };\n reader.onerror = () => reject(null);\n reader.readAsDataURL(blob);\n });\n } catch (error) {\n console.warn(\"Unable to load asset image:\", error);\n return null;\n }\n};\n\n/**\n * Converts a hexadecimal color string (e.g., \"#RRGGBB\" or \"0xRRGGBB\") to an RGB tuple.\n */\nexport const convertColorToRgb = (color: string): [number, number, number] => {\n const r = parseInt(color.substring(2, 4), 16);\n const g = parseInt(color.substring(4, 6), 16);\n const b = parseInt(color.substring(6, 8), 16);\n return [r, g, b];\n};\n\n"]}
|
|
1
|
+
{"version":3,"file":"commons-utility.js","sourceRoot":"","sources":["../../src/utils/commons-utility.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,2DAA6B;AAC7B,qFAAyF;AACzF,8DAAgE;AAchE,mDAA2E;AAC3E,2DAAqD;AACrD,iDAGwB;AACxB,uDAI2B;AAEpB,MAAM,kBAAkB,GAAG,CAChC,OAA0B,EAC1B,KAAoB,EACpB,cAAsD,EAAE,EACxD,EAAE;IACF,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAExB,MAAM,cAAc,GAAG,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0BAA0B,CAAC;YAEjE,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;gBAC1B,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE;oBACP,cAAc,EAAE,WAAW;oBAC3B,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;iBAC3C;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;YAC3D,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;gBACxB,MAAM,EAAE,GAAG;gBACX,UAAU,EAAE,mBAAmB,QAAQ,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;SAAM,CAAC;QACN,sCAAsC;QACtC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;AACH,CAAC,CAAC;AArCW,QAAA,WAAW,eAqCtB","sourcesContent":["import path from \"path\";\nimport fs from \"fs/promises\";\nimport { exportTypeSupportsFormatting } from \"../converters/excel/excel-converter.types\";\nimport { SortMode, SortObject } from \"../types/component-props\";\nimport {\n SmeupDataColumn,\n SmeupDataTable,\n SmeupDataCell,\n SmeupDataRow,\n} from \"../types/data-structures/smeupDataTable\";\nimport {\n SmeupDataObj,\n ColumnFilter,\n WebupManagerData,\n SupportedExportFormats,\n GenericObject,\n} from \"../types/index\";\nimport { datesIsIsoDate, datesToDate, datesFormat } from \"./dates-utility\";\nimport { sanitizeString } from \"./formatter-utility\";\nimport {\n mathNumberStringToFormattedString,\n mathCountDecimals,\n} from \"./math-utility\";\nimport {\n objectsIsVoCodVer,\n objectsIsDate,\n objectsIsNumber,\n} from \"./objects-utility\";\n\nexport const getFilteredColumns = (\n columns: SmeupDataColumn[],\n props: GenericObject,\n groupsArray: { column: string; visible: boolean }[] = [],\n) => {\n if (!columns) return [];\n\n const mutableColumns = JSON.parse(\n JSON.stringify(columns),\n ) as SmeupDataColumn[];\n\n const filteredColumns: SmeupDataColumn[] = [];\n\n if (props.visibleColumns && (props.visibleColumns as string[]).length > 0) {\n (props.visibleColumns as string[]).forEach((col: string) => {\n const foundColumn = mutableColumns.find(c => c.name === col);\n if (foundColumn) {\n filteredColumns.push({ ...foundColumn });\n }\n });\n } else {\n filteredColumns.push(...mutableColumns);\n }\n\n // Set the visibility of columns based on groups and props\n filteredColumns.forEach((col: SmeupDataColumn) => {\n const isGroupedColumn = groupsArray.filter(g => g.column === col.name);\n col.visible = props.visibleColumns\n ? (props.visibleColumns as string[]).includes(col.name)\n : col.visible;\n col.visible =\n isGroupedColumn.length > 0 ? isGroupedColumn[0].visible : col.visible;\n });\n\n return filteredColumns.filter(column => {\n const dataObject = {\n ...column.obj,\n k: \"\",\n } as SmeupDataObj;\n return column.obj?.t !== \"J4\" && !objectsIsVoCodVer(dataObject);\n });\n};\n\n/**\n * By passing the map, length value and column name\n * creates or updates a map record with\n * @param map Contains columnNames and their longest cell's length\n * @param text The text to use in length calculation\n * @param colName The column to check\n */\nexport const updateMaxValueLength = (\n map: { [key: string]: number },\n text: string | undefined | null,\n colName: string,\n) => {\n if (!map || !text || !colName) return;\n\n const value = Math.max(...text.split(\"\\n\").map(line => line.length));\n if (map[colName]) {\n if (map[colName] < value) {\n map[colName] = value;\n }\n } else {\n map[colName] = value;\n }\n};\n\nexport const filterRows = (\n smeupDataTable: SmeupDataTable,\n filteredColumns: SmeupDataColumn[],\n filters: { [key: string]: ColumnFilter },\n) => {\n if (filters) {\n return smeupDataTable.rows.filter(row => {\n return smeupDataTable.columns.every(col => {\n const cellValue = row.cells?.[col.name]?.value;\n const columnFilter = filters[col.name];\n if (columnFilter?.checkBoxes?.length) {\n const allowedValues = columnFilter.checkBoxes.map(item => item.value);\n return (\n typeof cellValue === \"string\" && allowedValues.includes(cellValue)\n );\n }\n if (columnFilter?.textField) {\n return (\n typeof cellValue === \"string\" &&\n isFilterMatchValue(cellValue, columnFilter.textField)\n );\n }\n return true;\n });\n });\n } else {\n return smeupDataTable.rows;\n }\n};\n\nexport const isFilterMatchValue = (value: string, filter: string): boolean => {\n if (value == null) value = \"\";\n if (filter == null) filter = \"\";\n\n value = value.trim();\n filter = filter.trim();\n\n // Regex for operators and filter\n // Examples: !'text', >'aa', >= 'ab', <'cza', <= 'asd', 'text', 'text%', '%text', '%text%'\n const regex = /^([!><]=?|)(?:'(%?)(.*?)(%?)')?$/;\n const match = filter.match(regex);\n if (!match) {\n // fallback: inclusion\n return value.includes(filter);\n }\n\n const operator = match[1];\n const startWildcard = match[2] === \"%\";\n const filterText = match[3] ?? \"\";\n const endWildcard = match[4] === \"%\";\n\n // Handle '' (void)\n if (filterText === \"\" && match[0].includes(\"''\")) {\n if (operator === \"!\") {\n return value !== \"\";\n }\n return value === \"\";\n }\n\n // Handle operators of comparison\n if ([\">\", \">=\", \"<\", \"<=\"].includes(operator)) {\n if (operator === \">\") {\n return value > filterText;\n }\n if (operator === \">=\") {\n return value >= filterText;\n }\n if (operator === \"<\") {\n return value < filterText;\n }\n if (operator === \"<=\") {\n return value <= filterText;\n }\n }\n\n // Negation\n if (operator === \"!\") {\n // Match negation\n if (startWildcard && endWildcard) {\n return !value.includes(filterText);\n }\n if (startWildcard) {\n return !value.endsWith(filterText);\n }\n if (endWildcard) {\n return !value.startsWith(filterText);\n }\n // Exact match negation\n return value !== filterText;\n }\n\n // Wildcard\n if (startWildcard && endWildcard) {\n return value.includes(filterText);\n }\n if (startWildcard) {\n return value.endsWith(filterText);\n }\n if (endWildcard) {\n return value.startsWith(filterText);\n }\n\n // Exact match between quotes\n if (filter.startsWith(\"'\") && filter.endsWith(\"'\")) {\n return value === filterText;\n }\n\n // Fallback: inclusion\n return value.includes(filterText);\n};\n\nexport const sortRows = (\n rows: SmeupDataRow[],\n sortObject: SortObject[],\n activeGroups?: string[],\n) => {\n const sort = sortObject?.[0];\n\n if (!sort && !activeGroups) {\n return;\n }\n\n if (!sort && activeGroups) {\n rows.sort((a, b) => {\n for (const group of activeGroups) {\n const valA = a.cells?.[group]?.value ?? \"\";\n const valB = b.cells?.[group]?.value ?? \"\";\n\n if (valA !== valB) {\n return valA.localeCompare(valB);\n }\n }\n return 0;\n });\n return;\n }\n\n sortObject?.forEach(sort => {\n rows.sort((a, b) => {\n const valA = a.cells?.[sort.column]?.value ?? \"\";\n const valB = b.cells?.[sort.column]?.value ?? \"\";\n\n switch (sort.sortMode) {\n case SortMode.A:\n if (valA !== valB) {\n return valA.localeCompare(valB);\n }\n return 0;\n case SortMode.D:\n if (valA !== valB) {\n return valB.localeCompare(valA);\n }\n return 0;\n }\n });\n });\n};\n\n/**\n * Returns a converted and formatted cell value (string, date, number)\n * @param cell - SmeupDataCell\n * @param bookType - SupportedExportFormats\n * @param webupManagerData - WebupManagerData\n * @returns\n */\nexport const calculateCellValue = (\n cell: SmeupDataCell,\n bookType: SupportedExportFormats,\n webupManagerData: WebupManagerData,\n) => {\n return calculateValue(\n cell.value,\n cell.obj ?? ({ t: \"\", p: \"\", k: \"\" } as SmeupDataObj),\n bookType,\n webupManagerData,\n );\n};\n\n/**\n * Calculates and formats a value based on its type and export format.\n *\n * - If the value is a date and the object indicates a date type, it returns a formatted date string or a Date object,\n * depending on the export format.\n * - If the value is a number and the object indicates a number type, it returns a formatted number string or a numeric value,\n * depending on the export format.\n * - Otherwise, it returns the original value or an empty string if the value is null or undefined.\n *\n * @param bookType - The export format type.\n * @param webupManagerData - Data containing locale and formatting information.\n * @param value - The value to be calculated and formatted.\n * @param obj - Optional object describing the type of the value.\n * @returns The formatted value, a Date object, a number, or the original value as a string.\n */\nexport const calculateValue = (\n value: string,\n obj: {\n t: string;\n p: string;\n k: string;\n },\n bookType: SupportedExportFormats,\n webupManagerData: WebupManagerData,\n) => {\n if (obj && objectsIsDate(obj) && datesIsIsoDate(value)) {\n return exportTypeSupportsFormatting[bookType]\n ? new Date(datesToDate(value, webupManagerData.datesLocale))\n : datesFormat(value, webupManagerData.datesLocale);\n }\n\n if (obj && objectsIsNumber(obj)) {\n if (!exportTypeSupportsFormatting[bookType]) {\n return (\n mathNumberStringToFormattedString(\n value,\n mathCountDecimals(Number(value) || 0),\n \"\",\n webupManagerData.mathLocale,\n ) || \"\"\n );\n }\n\n const numValue = Number(value);\n return !isNaN(numValue) && !(Math.abs(numValue) === Infinity)\n ? numValue\n : \"\";\n }\n\n return sanitizeString(value ?? \"\");\n};\n\n/**\n * Conversion from Hexadecimal color to an AlphaRGB\n * @param hex string - Hexadecimal value, it can bot have and don't have the # prefix\n * @returns ARGB string code\n */\nexport const hexToArgb = (hex: string): string => {\n // Hex validation\n if (hex.startsWith(\"#\")) hex = hex.slice(1);\n if (hex.length !== 6) return \"\";\n\n // Value Parse and return\n const red = parseInt(hex.slice(0, 2), 16);\n const green = parseInt(hex.slice(2, 4), 16);\n const blue = parseInt(hex.slice(4, 6), 16);\n return `FF${red.toString(16).padStart(2, \"0\")}${green\n .toString(16)\n .padStart(2, \"0\")}${blue.toString(16).padStart(2, \"0\")}`;\n};\n\n// Utility function to detect if Buffer is available\nconst isBufferAvailable = (): boolean => {\n try {\n return typeof Buffer !== \"undefined\" && typeof Buffer.from === \"function\";\n } catch {\n return false;\n }\n};\n\n// Utility function to convert ArrayBuffer to Buffer or Uint8Array\nexport const convertToBuffer = (\n arrayBuffer: ArrayBuffer | Uint8Array,\n): Buffer | Uint8Array => {\n if (arrayBuffer instanceof Uint8Array) {\n return arrayBuffer;\n }\n if (isBufferAvailable()) {\n return Buffer.from(arrayBuffer);\n } else {\n return new Uint8Array(arrayBuffer);\n }\n};\n\n// Function to load an image as base64 (browser version, async)\nexport const loadImageAsBase64 = async (\n imageUrl: string,\n): Promise<string | null> => {\n try {\n const response = await fetch(imageUrl);\n if (!response.ok) return null;\n const blob = await response.blob();\n return await new Promise<string | null>((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n resolve(reader.result as string);\n };\n reader.onerror = () => reject(null);\n reader.readAsDataURL(blob);\n });\n } catch (error) {\n console.warn(\"Unable to load asset image:\", error);\n return null;\n }\n};\n\n/**\n * Converts a hexadecimal color string (e.g., \"#RRGGBB\" or \"0xRRGGBB\") to an RGB tuple.\n */\nexport const convertColorToRgb = (color: string): [number, number, number] => {\n const r = parseInt(color.substring(2, 4), 16);\n const g = parseInt(color.substring(4, 6), 16);\n const b = parseInt(color.substring(6, 8), 16);\n return [r, g, b];\n};\n\n// Custom fetch function that handles both HTTP and file:// URLs\nexport const customFetch = async (url: string): Promise<Response> => {\n if (url.startsWith(\"file://\")) {\n // Handle file:// URLs by reading from filesystem\n const filePath = url.replace(/^file:\\/\\/\\//, \"\");\n try {\n const buffer = await fs.readFile(filePath);\n const ext = path.extname(filePath).toLowerCase();\n\n // Determine MIME type from extension\n const mimeTypes: Record<string, string> = {\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".svg\": \"image/svg+xml\",\n \".webp\": \"image/webp\",\n };\n const contentType = mimeTypes[ext] || \"application/octet-stream\";\n\n return new Response(buffer, {\n status: 200,\n headers: {\n \"content-type\": contentType,\n \"content-length\": buffer.length.toString(),\n },\n });\n } catch (error) {\n console.error(`Error reading file at ${filePath}:`, error);\n return new Response(null, {\n status: 404,\n statusText: `File not found: ${filePath}`,\n });\n }\n } else {\n // Use standard fetch for HTTP(S) URLs\n return fetch(url);\n }\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sme.up/doc-alchemist",
|
|
3
|
-
"version": "1.5.0-SNAPSHOT-
|
|
3
|
+
"version": "1.5.0-SNAPSHOT-20251126090326",
|
|
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/)",
|