@lichens-innovation/ts-common 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/dist/csv.cjs +37 -0
- package/dist/csv.cjs.map +1 -0
- package/dist/csv.d.cts +5 -0
- package/dist/csv.d.ts +5 -0
- package/dist/csv.js +29 -0
- package/dist/csv.js.map +1 -0
- package/dist/dimensions.utils-BwIBA5op.d.cts +6 -0
- package/dist/dimensions.utils-BwIBA5op.d.ts +6 -0
- package/dist/excel.cjs +177 -0
- package/dist/excel.cjs.map +1 -0
- package/dist/excel.d.cts +109 -0
- package/dist/excel.d.ts +109 -0
- package/dist/excel.js +167 -0
- package/dist/excel.js.map +1 -0
- package/dist/index.cjs +115 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -7
- package/dist/index.d.ts +21 -7
- package/dist/index.js +40 -95
- package/dist/index.js.map +1 -1
- package/dist/mime.cjs +20 -0
- package/dist/mime.cjs.map +1 -0
- package/dist/mime.d.cts +3 -0
- package/dist/mime.d.ts +3 -0
- package/dist/mime.js +14 -0
- package/dist/mime.js.map +1 -0
- package/dist/pdf.cjs +273 -0
- package/dist/pdf.cjs.map +1 -0
- package/dist/pdf.d.cts +140 -0
- package/dist/pdf.d.ts +140 -0
- package/dist/pdf.js +264 -0
- package/dist/pdf.js.map +1 -0
- package/dist/web.cjs +235 -0
- package/dist/web.cjs.map +1 -0
- package/dist/web.d.cts +82 -0
- package/dist/web.d.ts +82 -0
- package/dist/web.js +219 -0
- package/dist/web.js.map +1 -0
- package/package.json +55 -13
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { D as Dimensions } from './dimensions.utils-BwIBA5op.js';
|
|
2
|
+
|
|
3
|
+
declare const getCurrentUrl: () => string;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a Blob to a data URI string.
|
|
7
|
+
*/
|
|
8
|
+
declare const blobToDataUri: (blob: Blob) => Promise<string | null>;
|
|
9
|
+
/**
|
|
10
|
+
* Fetches a resource by URL and returns its content as a data URI.
|
|
11
|
+
* Content type is inferred from the response Content-Type header when possible.
|
|
12
|
+
*/
|
|
13
|
+
declare const fetchUrlAsDataUri: (url: string) => Promise<string | null>;
|
|
14
|
+
|
|
15
|
+
declare const hasRechartsElements: (svg: SVGSVGElement) => boolean;
|
|
16
|
+
declare const findRechartsSvg: (svgs: NodeListOf<SVGSVGElement> | SVGSVGElement[]) => SVGSVGElement | null;
|
|
17
|
+
declare const getElement: (id: string) => HTMLElement | null;
|
|
18
|
+
interface GetRechartsSvgFromElementArgs {
|
|
19
|
+
chartElement: HTMLElement;
|
|
20
|
+
chartElementId: string;
|
|
21
|
+
}
|
|
22
|
+
declare const getRechartsSvgFromElement: ({ chartElement, chartElementId, }: GetRechartsSvgFromElementArgs) => SVGSVGElement | null;
|
|
23
|
+
declare const getSvgDimensions: (svgElement: SVGSVGElement) => Dimensions;
|
|
24
|
+
interface PrepareSvgCloneArgs {
|
|
25
|
+
svgElement: SVGSVGElement;
|
|
26
|
+
dimensions: Dimensions;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Clones an SVG element and ensures it has the required width and height attributes.
|
|
30
|
+
*
|
|
31
|
+
* This function is necessary for two main reasons:
|
|
32
|
+
*
|
|
33
|
+
* 1. **Defensive cloning**: Cloning prevents modifying the original SVG element in the DOM.
|
|
34
|
+
* Although `XMLSerializer.serializeToString()` does not modify the element, cloning ensures
|
|
35
|
+
* that no accidental modifications are made to the source element.
|
|
36
|
+
*
|
|
37
|
+
* 2. **Required width/height attributes**: When converting SVG → PNG via `svgToPngDataUri`,
|
|
38
|
+
* the HTML Image element requires the SVG to have explicit intrinsic dimensions.
|
|
39
|
+
* Without width/height attributes, the SVG may not render correctly on the canvas,
|
|
40
|
+
* resulting in an incorrect or empty PNG image.
|
|
41
|
+
*
|
|
42
|
+
* @param svgElement - The original SVG element to clone
|
|
43
|
+
* @param dimensions - The dimensions to apply to the cloned SVG if attributes are missing
|
|
44
|
+
* @returns A new cloned SVG element with guaranteed width/height attributes
|
|
45
|
+
*/
|
|
46
|
+
declare const prepareSvgClone: ({ svgElement, dimensions }: PrepareSvgCloneArgs) => SVGSVGElement;
|
|
47
|
+
declare const convertSvgToDataUri: (svgXml: string) => string;
|
|
48
|
+
interface ResizeSvgXmlArgs {
|
|
49
|
+
svgXml: string;
|
|
50
|
+
targetWidth: number;
|
|
51
|
+
targetHeight: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Modifies SVG XML to set the root <svg> width and height attributes.
|
|
55
|
+
* Used to resize the SVG before converting to PNG at target dimensions (e.g. from PDF layout).
|
|
56
|
+
*/
|
|
57
|
+
declare const resizeSvgXml: ({ svgXml, targetWidth, targetHeight }: ResizeSvgXmlArgs) => string;
|
|
58
|
+
interface GetChartAsPngDataUriArgs {
|
|
59
|
+
chartElementId: string;
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Gets the Recharts chart as a PNG data URI at the given dimensions (e.g. from PDF zone).
|
|
65
|
+
* Resizes the SVG via resizeSvgXml before conversion; does not use the SVG's intrinsic dimensions.
|
|
66
|
+
*/
|
|
67
|
+
declare const getChartAsPngDataUri: ({ chartElementId, width, height, }: GetChartAsPngDataUriArgs) => Promise<string | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the SVG from a Recharts chart element and converts it to SVG base64
|
|
70
|
+
* @param chartElementId - The ID of the element containing the chart
|
|
71
|
+
* @returns The SVG encoded in base64 with data URI prefix (data:image/svg+xml;base64,...), or null if an error occurs
|
|
72
|
+
*/
|
|
73
|
+
declare const getSvgAsBase64DataUri: (chartElementId: string) => string | null;
|
|
74
|
+
declare const getRechartSvgXml: (chartElementId: string) => string | null;
|
|
75
|
+
interface SvgToPngArgs {
|
|
76
|
+
svgDataUri?: string | null;
|
|
77
|
+
dimensions: Dimensions;
|
|
78
|
+
backgroundColor?: string;
|
|
79
|
+
}
|
|
80
|
+
declare const svgToPngDataUri: ({ svgDataUri, dimensions, backgroundColor, }: SvgToPngArgs) => Promise<string | null>;
|
|
81
|
+
|
|
82
|
+
export { type GetChartAsPngDataUriArgs, type GetRechartsSvgFromElementArgs, type PrepareSvgCloneArgs, type ResizeSvgXmlArgs, type SvgToPngArgs, blobToDataUri, convertSvgToDataUri, fetchUrlAsDataUri, findRechartsSvg, getChartAsPngDataUri, getCurrentUrl, getElement, getRechartSvgXml, getRechartsSvgFromElement, getSvgAsBase64DataUri, getSvgDimensions, hasRechartsElements, prepareSvgClone, resizeSvgXml, svgToPngDataUri };
|
package/dist/web.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// src/web/browser.utils.ts
|
|
2
|
+
var getCurrentUrl = () => {
|
|
3
|
+
if (typeof window === "undefined") {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
return window.location.href;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/utils/errors.utils.ts
|
|
10
|
+
var getErrorMessage = (error) => {
|
|
11
|
+
if (!error) {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
if (typeof error === "string") {
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
if (typeof error === "object" && "message" in error) {
|
|
18
|
+
return error.message;
|
|
19
|
+
}
|
|
20
|
+
return JSON.stringify(error);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/web/fetch.utils.ts
|
|
24
|
+
var blobToDataUri = (blob) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const reader = new FileReader();
|
|
27
|
+
reader.onerror = () => reject(reader.error);
|
|
28
|
+
reader.onloadend = () => {
|
|
29
|
+
const { result } = reader;
|
|
30
|
+
resolve(typeof result === "string" ? result : null);
|
|
31
|
+
};
|
|
32
|
+
reader.readAsDataURL(blob);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var fetchUrlAsDataUri = async (url) => {
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(url);
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
console.warn(`[fetchUrlAsDataUri] Response not ok (${response.status}). url: "${url}"`);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const blob = await response.blob();
|
|
43
|
+
return blobToDataUri(blob);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
const message = getErrorMessage(e);
|
|
46
|
+
console.error(`[fetchUrlAsDataUri] "${message}". url: "${url}"`, e);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/web/image.utils.ts
|
|
52
|
+
var hasRechartsElements = (svg) => {
|
|
53
|
+
return svg.querySelector("g.recharts-layer") !== null || svg.querySelector("g.recharts-cartesian-axis") !== null || svg.querySelector("g.recharts-cartesian-grid") !== null || svg.querySelector("path.recharts-curve") !== null;
|
|
54
|
+
};
|
|
55
|
+
var findRechartsSvg = (svgs) => {
|
|
56
|
+
for (const svg of Array.from(svgs)) {
|
|
57
|
+
if (hasRechartsElements(svg)) {
|
|
58
|
+
return svg;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
var getElement = (id) => {
|
|
64
|
+
const element = document?.getElementById(id);
|
|
65
|
+
if (!element) {
|
|
66
|
+
console.info(`[getElement] Element with id "${id}" not found`);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return element;
|
|
70
|
+
};
|
|
71
|
+
var getRechartsSvgFromElement = ({
|
|
72
|
+
chartElement,
|
|
73
|
+
chartElementId
|
|
74
|
+
}) => {
|
|
75
|
+
const allSvgs = chartElement.querySelectorAll("svg");
|
|
76
|
+
if (allSvgs.length === 0) {
|
|
77
|
+
console.info(`[getRechartsSvgFromElement] SVG element not found inside element with id "${chartElementId}"`);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const rechartSvg = findRechartsSvg(allSvgs);
|
|
81
|
+
if (!rechartSvg) {
|
|
82
|
+
console.info(`[getRechartsSvgFromElement] No Recharts SVG element found inside element with id "${chartElementId}"`);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return rechartSvg;
|
|
86
|
+
};
|
|
87
|
+
var getSvgDimensions = (svgElement) => {
|
|
88
|
+
const width = svgElement.clientWidth || parseInt(svgElement.getAttribute("width") || "800", 10);
|
|
89
|
+
const height = svgElement.clientHeight || parseInt(svgElement.getAttribute("height") || "600", 10);
|
|
90
|
+
return { width, height };
|
|
91
|
+
};
|
|
92
|
+
var prepareSvgClone = ({ svgElement, dimensions }) => {
|
|
93
|
+
const clonedSvg = svgElement.cloneNode(true);
|
|
94
|
+
if (!clonedSvg.hasAttribute("width")) {
|
|
95
|
+
clonedSvg.setAttribute("width", dimensions.width.toString());
|
|
96
|
+
}
|
|
97
|
+
if (!clonedSvg.hasAttribute("height")) {
|
|
98
|
+
clonedSvg.setAttribute("height", dimensions.height.toString());
|
|
99
|
+
}
|
|
100
|
+
return clonedSvg;
|
|
101
|
+
};
|
|
102
|
+
var convertSvgToDataUri = (svgXml) => {
|
|
103
|
+
const encoder = new TextEncoder();
|
|
104
|
+
const data = encoder.encode(svgXml);
|
|
105
|
+
let binaryString = "";
|
|
106
|
+
for (let i = 0; i < data.length; i++) {
|
|
107
|
+
binaryString += String.fromCharCode(data[i]);
|
|
108
|
+
}
|
|
109
|
+
const base64 = btoa(binaryString);
|
|
110
|
+
return `data:image/svg+xml;base64,${base64}`;
|
|
111
|
+
};
|
|
112
|
+
var resizeSvgXml = ({ svgXml, targetWidth, targetHeight }) => {
|
|
113
|
+
const widthAttr = `width="${targetWidth}"`;
|
|
114
|
+
const heightAttr = `height="${targetHeight}"`;
|
|
115
|
+
let result = svgXml.replace(/\bwidth=["'][^"']*["']/, widthAttr);
|
|
116
|
+
if (!/\bwidth\s*=/.test(result)) {
|
|
117
|
+
result = result.replace(/<svg/, `<svg ${widthAttr}`);
|
|
118
|
+
}
|
|
119
|
+
result = result.replace(/\bheight=["'][^"']*["']/, heightAttr);
|
|
120
|
+
if (!/\bheight\s*=/.test(result)) {
|
|
121
|
+
result = result.replace(/<svg/, `<svg ${heightAttr}`);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
var getChartAsPngDataUri = async ({
|
|
126
|
+
chartElementId,
|
|
127
|
+
width,
|
|
128
|
+
height
|
|
129
|
+
}) => {
|
|
130
|
+
if (!chartElementId) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const chartElement = getElement(chartElementId);
|
|
134
|
+
if (!chartElement) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const svgElement = getRechartsSvgFromElement({ chartElement, chartElementId });
|
|
138
|
+
if (!svgElement) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const svgXml = new XMLSerializer().serializeToString(svgElement);
|
|
142
|
+
const resizedXml = resizeSvgXml({ svgXml, targetWidth: width, targetHeight: height });
|
|
143
|
+
const svgDataUri = convertSvgToDataUri(resizedXml);
|
|
144
|
+
return svgToPngDataUri({
|
|
145
|
+
svgDataUri,
|
|
146
|
+
dimensions: { width, height },
|
|
147
|
+
backgroundColor: "white"
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
var getSvgAsBase64DataUri = (chartElementId) => {
|
|
151
|
+
const svgXml = getRechartSvgXml(chartElementId);
|
|
152
|
+
if (!svgXml) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
return convertSvgToDataUri(svgXml);
|
|
156
|
+
};
|
|
157
|
+
var getRechartSvgXml = (chartElementId) => {
|
|
158
|
+
if (!chartElementId) {
|
|
159
|
+
console.info(`[getRechartSvgXml] No chart element id provided`);
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
const chartElement = getElement(chartElementId);
|
|
163
|
+
if (!chartElement) {
|
|
164
|
+
console.info(`[getRechartSvgXml] Element with id "${chartElementId}" not found`);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const svgElement = getRechartsSvgFromElement({ chartElement, chartElementId });
|
|
168
|
+
if (!svgElement) {
|
|
169
|
+
console.info(`[getRechartSvgXml] No SVG element found inside element with id "${chartElementId}"`);
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const dimensions = getSvgDimensions(svgElement);
|
|
173
|
+
const clonedSvg = prepareSvgClone({ svgElement, dimensions });
|
|
174
|
+
const svgXml = new XMLSerializer().serializeToString(clonedSvg);
|
|
175
|
+
return svgXml;
|
|
176
|
+
};
|
|
177
|
+
var svgToPngDataUri = async ({
|
|
178
|
+
svgDataUri,
|
|
179
|
+
dimensions,
|
|
180
|
+
backgroundColor
|
|
181
|
+
}) => {
|
|
182
|
+
if (!svgDataUri) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const { width, height } = dimensions;
|
|
186
|
+
return new Promise((resolve, reject) => {
|
|
187
|
+
const img = new Image();
|
|
188
|
+
img.onload = () => {
|
|
189
|
+
try {
|
|
190
|
+
const canvas = document.createElement("canvas");
|
|
191
|
+
canvas.width = width;
|
|
192
|
+
canvas.height = height;
|
|
193
|
+
const ctx = canvas.getContext("2d");
|
|
194
|
+
if (!ctx) {
|
|
195
|
+
reject(new Error("Failed to get canvas 2D context"));
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (backgroundColor) {
|
|
199
|
+
ctx.fillStyle = backgroundColor;
|
|
200
|
+
ctx.fillRect(0, 0, width, height);
|
|
201
|
+
}
|
|
202
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
203
|
+
const pngDataUri = canvas.toDataURL("image/png");
|
|
204
|
+
resolve(pngDataUri);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
reject(error);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
img.onerror = (error) => {
|
|
210
|
+
const message = getErrorMessage(error);
|
|
211
|
+
reject(new Error(`Failed to load SVG image: ${message}`));
|
|
212
|
+
};
|
|
213
|
+
img.src = svgDataUri;
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export { blobToDataUri, convertSvgToDataUri, fetchUrlAsDataUri, findRechartsSvg, getChartAsPngDataUri, getCurrentUrl, getElement, getRechartSvgXml, getRechartsSvgFromElement, getSvgAsBase64DataUri, getSvgDimensions, hasRechartsElements, prepareSvgClone, resizeSvgXml, svgToPngDataUri };
|
|
218
|
+
//# sourceMappingURL=web.js.map
|
|
219
|
+
//# sourceMappingURL=web.js.map
|
package/dist/web.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/web/browser.utils.ts","../src/utils/errors.utils.ts","../src/web/fetch.utils.ts","../src/web/image.utils.ts"],"names":[],"mappings":";AAAO,IAAM,gBAAgB,MAAc;AACzC,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,EAAA;AAAA,EACT;AAEA,EAAA,OAAO,OAAO,QAAA,CAAS,IAAA;AACzB;;;ACNO,IAAM,eAAA,GAAkB,CAAC,KAAA,KAA2B;AACzD,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,OAAO,EAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,SAAA,IAAa,KAAA,EAAO;AACnD,IAAA,OAAQ,KAAA,CAA8B,OAAA;AAAA,EACxC;AAEA,EAAA,OAAO,IAAA,CAAK,UAAU,KAAK,CAAA;AAC7B,CAAA;;;ACTO,IAAM,aAAA,GAAgB,CAAC,IAAA,KAAuC;AACnE,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACtC,IAAA,MAAM,MAAA,GAAS,IAAI,UAA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ACpB,SAAS,KAAA,EAAO;AACd,QAAA,MAAA,CAAO,KAAK,CAAA;AAAA,MACd;AAAA,IACF,CAAA;AAEA,IAAA,GAAA,CAAI,OAAA,GAAU,CAAC,KAAA,KAAU;AACvB,MAAA,MAAM,OAAA,GAAU,gBAAgB,KAAK,CAAA;AACrC,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,CAAA,0BAAA,EAA6B,OAAO,EAAE,CAAC,CAAA;AAAA,IAC1D,CAAA;AAEA,IAAA,GAAA,CAAI,GAAA,GAAM,UAAA;AAAA,EACZ,CAAC,CAAA;AACH","file":"web.js","sourcesContent":["export const getCurrentUrl = (): string => {\n if (typeof window === \"undefined\") {\n return \"\";\n }\n\n return window.location.href;\n};\n","export const getErrorMessage = (error: unknown): string => {\n if (!error) {\n return \"\";\n }\n\n if (typeof error === \"string\") {\n return error;\n }\n\n if (typeof error === \"object\" && \"message\" in error) {\n return (error as { message: string }).message;\n }\n\n return JSON.stringify(error);\n};\n","import { getErrorMessage } from \"../utils\";\n\n/**\n * Converts a Blob to a data URI string.\n */\nexport const blobToDataUri = (blob: Blob): Promise<string | null> => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n\n reader.onerror = () => reject(reader.error);\n reader.onloadend = () => {\n const { result } = reader;\n resolve(typeof result === \"string\" ? result : null);\n };\n\n reader.readAsDataURL(blob);\n });\n};\n\n/**\n * Fetches a resource by URL and returns its content as a data URI.\n * Content type is inferred from the response Content-Type header when possible.\n */\nexport const fetchUrlAsDataUri = async (url: string): Promise<string | null> => {\n try {\n const response = await fetch(url);\n if (!response.ok) {\n console.warn(`[fetchUrlAsDataUri] Response not ok (${response.status}). url: \"${url}\"`);\n return null;\n }\n\n const blob = await response.blob();\n return blobToDataUri(blob);\n } catch (e: unknown) {\n const message = getErrorMessage(e);\n console.error(`[fetchUrlAsDataUri] \"${message}\". url: \"${url}\"`, e);\n return null;\n }\n};\n","import { getErrorMessage, type Dimensions } from \"../utils\";\n\nexport const hasRechartsElements = (svg: SVGSVGElement): boolean => {\n return (\n svg.querySelector(\"g.recharts-layer\") !== null ||\n svg.querySelector(\"g.recharts-cartesian-axis\") !== null ||\n svg.querySelector(\"g.recharts-cartesian-grid\") !== null ||\n svg.querySelector(\"path.recharts-curve\") !== null\n );\n};\n\nexport const findRechartsSvg = (svgs: NodeListOf<SVGSVGElement> | SVGSVGElement[]): SVGSVGElement | null => {\n for (const svg of Array.from(svgs)) {\n if (hasRechartsElements(svg)) {\n return svg;\n }\n }\n\n return null;\n};\n\nexport const getElement = (id: string): HTMLElement | null => {\n const element = document?.getElementById(id);\n if (!element) {\n console.info(`[getElement] Element with id \"${id}\" not found`);\n return null;\n }\n\n return element;\n};\n\nexport interface GetRechartsSvgFromElementArgs {\n chartElement: HTMLElement;\n chartElementId: string;\n}\n\nexport const getRechartsSvgFromElement = ({\n chartElement,\n chartElementId,\n}: GetRechartsSvgFromElementArgs): SVGSVGElement | null => {\n const allSvgs = chartElement.querySelectorAll<SVGSVGElement>(\"svg\");\n if (allSvgs.length === 0) {\n console.info(`[getRechartsSvgFromElement] SVG element not found inside element with id \"${chartElementId}\"`);\n return null;\n }\n\n const rechartSvg = findRechartsSvg(allSvgs);\n if (!rechartSvg) {\n console.info(`[getRechartsSvgFromElement] No Recharts SVG element found inside element with id \"${chartElementId}\"`);\n return null;\n }\n\n return rechartSvg;\n};\n\nexport const getSvgDimensions = (svgElement: SVGSVGElement): Dimensions => {\n const width = svgElement.clientWidth || parseInt(svgElement.getAttribute(\"width\") || \"800\", 10);\n const height = svgElement.clientHeight || parseInt(svgElement.getAttribute(\"height\") || \"600\", 10);\n return { width, height };\n};\n\nexport interface PrepareSvgCloneArgs {\n svgElement: SVGSVGElement;\n dimensions: Dimensions;\n}\n\n/**\n * Clones an SVG element and ensures it has the required width and height attributes.\n *\n * This function is necessary for two main reasons:\n *\n * 1. **Defensive cloning**: Cloning prevents modifying the original SVG element in the DOM.\n * Although `XMLSerializer.serializeToString()` does not modify the element, cloning ensures\n * that no accidental modifications are made to the source element.\n *\n * 2. **Required width/height attributes**: When converting SVG → PNG via `svgToPngDataUri`,\n * the HTML Image element requires the SVG to have explicit intrinsic dimensions.\n * Without width/height attributes, the SVG may not render correctly on the canvas,\n * resulting in an incorrect or empty PNG image.\n *\n * @param svgElement - The original SVG element to clone\n * @param dimensions - The dimensions to apply to the cloned SVG if attributes are missing\n * @returns A new cloned SVG element with guaranteed width/height attributes\n */\nexport const prepareSvgClone = ({ svgElement, dimensions }: PrepareSvgCloneArgs): SVGSVGElement => {\n const clonedSvg = svgElement.cloneNode(true) as SVGSVGElement;\n\n if (!clonedSvg.hasAttribute(\"width\")) {\n clonedSvg.setAttribute(\"width\", dimensions.width.toString());\n }\n if (!clonedSvg.hasAttribute(\"height\")) {\n clonedSvg.setAttribute(\"height\", dimensions.height.toString());\n }\n\n return clonedSvg;\n};\n\nexport const convertSvgToDataUri = (svgXml: string): string => {\n const encoder = new TextEncoder();\n const data = encoder.encode(svgXml);\n let binaryString = \"\";\n for (let i = 0; i < data.length; i++) {\n binaryString += String.fromCharCode(data[i]);\n }\n const base64 = btoa(binaryString);\n return `data:image/svg+xml;base64,${base64}`;\n};\n\nexport interface ResizeSvgXmlArgs {\n svgXml: string;\n targetWidth: number;\n targetHeight: number;\n}\n\n/**\n * Modifies SVG XML to set the root <svg> width and height attributes.\n * Used to resize the SVG before converting to PNG at target dimensions (e.g. from PDF layout).\n */\nexport const resizeSvgXml = ({ svgXml, targetWidth, targetHeight }: ResizeSvgXmlArgs): string => {\n const widthAttr = `width=\"${targetWidth}\"`;\n const heightAttr = `height=\"${targetHeight}\"`;\n\n let result = svgXml.replace(/\\bwidth=[\"'][^\"']*[\"']/, widthAttr);\n if (!/\\bwidth\\s*=/.test(result)) {\n result = result.replace(/<svg/, `<svg ${widthAttr}`);\n }\n\n result = result.replace(/\\bheight=[\"'][^\"']*[\"']/, heightAttr);\n if (!/\\bheight\\s*=/.test(result)) {\n result = result.replace(/<svg/, `<svg ${heightAttr}`);\n }\n\n return result;\n};\n\nexport interface GetChartAsPngDataUriArgs {\n chartElementId: string;\n width: number;\n height: number;\n}\n\n/**\n * Gets the Recharts chart as a PNG data URI at the given dimensions (e.g. from PDF zone).\n * Resizes the SVG via resizeSvgXml before conversion; does not use the SVG's intrinsic dimensions.\n */\nexport const getChartAsPngDataUri = async ({\n chartElementId,\n width,\n height,\n}: GetChartAsPngDataUriArgs): Promise<string | null> => {\n if (!chartElementId) {\n return null;\n }\n\n const chartElement: HTMLElement | null = getElement(chartElementId);\n if (!chartElement) {\n return null;\n }\n\n const svgElement: SVGSVGElement | null = getRechartsSvgFromElement({ chartElement, chartElementId });\n if (!svgElement) {\n return null;\n }\n\n const svgXml: string = new XMLSerializer().serializeToString(svgElement);\n const resizedXml: string = resizeSvgXml({ svgXml, targetWidth: width, targetHeight: height });\n const svgDataUri: string = convertSvgToDataUri(resizedXml);\n\n return svgToPngDataUri({\n svgDataUri,\n dimensions: { width, height },\n backgroundColor: \"white\",\n });\n};\n\n/**\n * Retrieves the SVG from a Recharts chart element and converts it to SVG base64\n * @param chartElementId - The ID of the element containing the chart\n * @returns The SVG encoded in base64 with data URI prefix (data:image/svg+xml;base64,...), or null if an error occurs\n */\nexport const getSvgAsBase64DataUri = (chartElementId: string): string | null => {\n const svgXml = getRechartSvgXml(chartElementId);\n if (!svgXml) {\n return null;\n }\n\n return convertSvgToDataUri(svgXml);\n};\n\nexport const getRechartSvgXml = (chartElementId: string): string | null => {\n if (!chartElementId) {\n console.info(`[getRechartSvgXml] No chart element id provided`);\n return null;\n }\n\n const chartElement: HTMLElement | null = getElement(chartElementId);\n if (!chartElement) {\n console.info(`[getRechartSvgXml] Element with id \"${chartElementId}\" not found`);\n return null;\n }\n\n const svgElement: SVGSVGElement | null = getRechartsSvgFromElement({ chartElement, chartElementId });\n if (!svgElement) {\n console.info(`[getRechartSvgXml] No SVG element found inside element with id \"${chartElementId}\"`);\n return null;\n }\n\n const dimensions = getSvgDimensions(svgElement);\n const clonedSvg: SVGSVGElement = prepareSvgClone({ svgElement, dimensions });\n const svgXml: string = new XMLSerializer().serializeToString(clonedSvg);\n\n return svgXml;\n};\n\nexport interface SvgToPngArgs {\n svgDataUri?: string | null;\n dimensions: Dimensions;\n backgroundColor?: string;\n}\n\nexport const svgToPngDataUri = async ({\n svgDataUri,\n dimensions,\n backgroundColor,\n}: SvgToPngArgs): Promise<string | null> => {\n if (!svgDataUri) {\n return null;\n }\n\n const { width, height } = dimensions;\n\n return new Promise((resolve, reject) => {\n const img = new Image();\n\n img.onload = () => {\n try {\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n reject(new Error(\"Failed to get canvas 2D context\"));\n return;\n }\n\n if (backgroundColor) {\n ctx.fillStyle = backgroundColor;\n ctx.fillRect(0, 0, width, height);\n }\n\n ctx.drawImage(img, 0, 0, width, height);\n const pngDataUri = canvas.toDataURL(\"image/png\");\n resolve(pngDataUri);\n } catch (error) {\n reject(error);\n }\n };\n\n img.onerror = (error) => {\n const message = getErrorMessage(error);\n reject(new Error(`Failed to load SVG image: ${message}`));\n };\n\n img.src = svgDataUri;\n });\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lichens-innovation/ts-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Reusable generic typescript utilities, types, constants, helpers",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"typescript",
|
|
7
|
-
"utilities",
|
|
8
|
-
"utils",
|
|
9
|
-
"helpers",
|
|
10
|
-
"common"
|
|
11
|
-
],
|
|
5
|
+
"keywords": ["typescript", "utilities", "utils", "helpers", "common"],
|
|
12
6
|
"main": "dist/index.cjs",
|
|
13
7
|
"module": "dist/index.js",
|
|
14
8
|
"types": "dist/index.d.ts",
|
|
@@ -18,12 +12,40 @@
|
|
|
18
12
|
"import": "./dist/index.js",
|
|
19
13
|
"require": "./dist/index.cjs",
|
|
20
14
|
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./excel": {
|
|
17
|
+
"types": "./dist/excel.d.ts",
|
|
18
|
+
"import": "./dist/excel.js",
|
|
19
|
+
"require": "./dist/excel.cjs",
|
|
20
|
+
"default": "./dist/excel.js"
|
|
21
|
+
},
|
|
22
|
+
"./csv": {
|
|
23
|
+
"types": "./dist/csv.d.ts",
|
|
24
|
+
"import": "./dist/csv.js",
|
|
25
|
+
"require": "./dist/csv.cjs",
|
|
26
|
+
"default": "./dist/csv.js"
|
|
27
|
+
},
|
|
28
|
+
"./pdf": {
|
|
29
|
+
"types": "./dist/pdf.d.ts",
|
|
30
|
+
"import": "./dist/pdf.js",
|
|
31
|
+
"require": "./dist/pdf.cjs",
|
|
32
|
+
"default": "./dist/pdf.js"
|
|
33
|
+
},
|
|
34
|
+
"./web": {
|
|
35
|
+
"types": "./dist/web.d.ts",
|
|
36
|
+
"import": "./dist/web.js",
|
|
37
|
+
"require": "./dist/web.cjs",
|
|
38
|
+
"default": "./dist/web.js"
|
|
39
|
+
},
|
|
40
|
+
"./mime": {
|
|
41
|
+
"types": "./dist/mime.d.ts",
|
|
42
|
+
"import": "./dist/mime.js",
|
|
43
|
+
"require": "./dist/mime.cjs",
|
|
44
|
+
"default": "./dist/mime.js"
|
|
21
45
|
}
|
|
22
46
|
},
|
|
23
47
|
"sideEffects": false,
|
|
24
|
-
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
],
|
|
48
|
+
"files": ["dist"],
|
|
27
49
|
"repository": "git@github.com:Lichens-Innovation/ts-common.git",
|
|
28
50
|
"author": "Lichens Innovation",
|
|
29
51
|
"license": "MIT",
|
|
@@ -44,6 +66,20 @@
|
|
|
44
66
|
"dependencies": {
|
|
45
67
|
"date-fns": "^3.0.0"
|
|
46
68
|
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"exceljs": "^4.4.0",
|
|
71
|
+
"papaparse": "^5.4.1",
|
|
72
|
+
"jspdf": "^4.1.0",
|
|
73
|
+
"jspdf-autotable": "^5.0.7",
|
|
74
|
+
"mime": "^4.1.0"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"exceljs": { "optional": true },
|
|
78
|
+
"papaparse": { "optional": true },
|
|
79
|
+
"jspdf": { "optional": true },
|
|
80
|
+
"jspdf-autotable": { "optional": true },
|
|
81
|
+
"mime": { "optional": true }
|
|
82
|
+
},
|
|
47
83
|
"engines": {
|
|
48
84
|
"node": ">=20.0.0"
|
|
49
85
|
},
|
|
@@ -53,18 +89,24 @@
|
|
|
53
89
|
"@eslint/js": "^9.39.1",
|
|
54
90
|
"@faker-js/faker": "^10.1.0",
|
|
55
91
|
"@types/node": "^24.10.0",
|
|
92
|
+
"@types/papaparse": "^5.3.14",
|
|
56
93
|
"@vitest/coverage-v8": "4.0.8",
|
|
57
94
|
"commitlint": "^20.1.0",
|
|
58
95
|
"cross-env": "^10.1.0",
|
|
59
96
|
"eslint": "^9.39.1",
|
|
97
|
+
"exceljs": "^4.4.0",
|
|
60
98
|
"husky": "^9.1.7",
|
|
99
|
+
"jspdf": "^4.1.0",
|
|
100
|
+
"jspdf-autotable": "^5.0.7",
|
|
101
|
+
"mime": "^4.1.0",
|
|
102
|
+
"papaparse": "^5.4.1",
|
|
61
103
|
"prettier": "^3.6.2",
|
|
62
104
|
"rimraf": "^6.1.0",
|
|
63
105
|
"typescript": "~5.9.3",
|
|
64
106
|
"typescript-eslint": "^8.46.3",
|
|
107
|
+
"tsup": "^8.3.5",
|
|
65
108
|
"vite": "^7.2.2",
|
|
66
109
|
"vite-tsconfig-paths": "^5.1.4",
|
|
67
|
-
"vitest": "^4.0.8"
|
|
68
|
-
"tsup": "^8.3.5"
|
|
110
|
+
"vitest": "^4.0.8"
|
|
69
111
|
}
|
|
70
112
|
}
|