datastake-daf 0.6.474 → 0.6.475
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/utils/index.js +46 -5
- package/package.json +1 -1
- package/src/helpers/componentsToImages.js +52 -6
- package/src/utils.js +1 -1
package/dist/utils/index.js
CHANGED
|
@@ -21,6 +21,7 @@ require('deepmerge');
|
|
|
21
21
|
var countriesList = require('countries-list');
|
|
22
22
|
require('country-city-location');
|
|
23
23
|
require('leaflet-editable');
|
|
24
|
+
var client = require('react-dom/client');
|
|
24
25
|
var htmlToImage = require('html-to-image');
|
|
25
26
|
var docx = require('docx');
|
|
26
27
|
|
|
@@ -12639,12 +12640,10 @@ function displayMessage(type, m) {
|
|
|
12639
12640
|
antd.message[type](m);
|
|
12640
12641
|
}
|
|
12641
12642
|
|
|
12643
|
+
// src/helpers/imageCapture.js
|
|
12644
|
+
|
|
12642
12645
|
/**
|
|
12643
|
-
* Captures
|
|
12644
|
-
*
|
|
12645
|
-
* @param elements - A single element or an array of elements (or refs)
|
|
12646
|
-
* @param options - Optional html-to-image options (e.g., { cacheBust: true })
|
|
12647
|
-
* @returns Promise<string[]> - Array of base64 PNG strings (same order as input)
|
|
12646
|
+
* Captures existing DOM elements as images (requires refs)
|
|
12648
12647
|
*/
|
|
12649
12648
|
async function captureElementsAsImages(elements, options = {
|
|
12650
12649
|
cacheBust: true
|
|
@@ -12662,6 +12661,47 @@ async function captureElementsAsImages(elements, options = {
|
|
|
12662
12661
|
return captures;
|
|
12663
12662
|
}
|
|
12664
12663
|
|
|
12664
|
+
/**
|
|
12665
|
+
* Captures React components as images (no refs needed)
|
|
12666
|
+
*/
|
|
12667
|
+
async function captureComponentsAsImages(components, options = {
|
|
12668
|
+
cacheBust: true
|
|
12669
|
+
}) {
|
|
12670
|
+
const targets = Array.isArray(components) ? components : [components];
|
|
12671
|
+
const captures = await Promise.all(targets.map(async ({
|
|
12672
|
+
component,
|
|
12673
|
+
width = '100%',
|
|
12674
|
+
height = 'auto',
|
|
12675
|
+
delay = 100
|
|
12676
|
+
}) => {
|
|
12677
|
+
const container = document.createElement('div');
|
|
12678
|
+
container.style.position = 'absolute';
|
|
12679
|
+
container.style.opacity = '0';
|
|
12680
|
+
container.style.pointerEvents = 'none';
|
|
12681
|
+
container.style.top = '0';
|
|
12682
|
+
container.style.left = '0';
|
|
12683
|
+
container.style.width = typeof width === 'number' ? `${width}px` : width;
|
|
12684
|
+
container.style.height = typeof height === 'number' ? `${height}px` : height;
|
|
12685
|
+
document.body.appendChild(container);
|
|
12686
|
+
try {
|
|
12687
|
+
const root = client.createRoot(container);
|
|
12688
|
+
root.render(component);
|
|
12689
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
12690
|
+
const dataUrl = await htmlToImage.toPng(container, options);
|
|
12691
|
+
root.unmount();
|
|
12692
|
+
document.body.removeChild(container);
|
|
12693
|
+
return dataUrl;
|
|
12694
|
+
} catch (err) {
|
|
12695
|
+
console.error("Error capturing component as image:", err);
|
|
12696
|
+
if (container.parentNode) {
|
|
12697
|
+
document.body.removeChild(container);
|
|
12698
|
+
}
|
|
12699
|
+
return "";
|
|
12700
|
+
}
|
|
12701
|
+
}));
|
|
12702
|
+
return captures;
|
|
12703
|
+
}
|
|
12704
|
+
|
|
12665
12705
|
/**
|
|
12666
12706
|
* Renders different types of document elements based on type
|
|
12667
12707
|
* @param {Object} item - Configuration item
|
|
@@ -13358,6 +13398,7 @@ exports.btn = button;
|
|
|
13358
13398
|
exports.camelCaseToTitle = camelCaseToTitle;
|
|
13359
13399
|
exports.capitalize = capitalize;
|
|
13360
13400
|
exports.capitalizeAll = capitalizeAll;
|
|
13401
|
+
exports.captureComponentsAsImages = captureComponentsAsImages;
|
|
13361
13402
|
exports.captureElementsAsImages = captureElementsAsImages;
|
|
13362
13403
|
exports.changeInputMeta = changeInputMeta;
|
|
13363
13404
|
exports.convertUndefinedToNull = convertUndefinedToNull;
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
// src/helpers/imageCapture.js
|
|
2
|
+
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { toPng } from 'html-to-image';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
|
-
* Captures
|
|
5
|
-
*
|
|
6
|
-
* @param elements - A single element or an array of elements (or refs)
|
|
7
|
-
* @param options - Optional html-to-image options (e.g., { cacheBust: true })
|
|
8
|
-
* @returns Promise<string[]> - Array of base64 PNG strings (same order as input)
|
|
7
|
+
* Captures existing DOM elements as images (requires refs)
|
|
9
8
|
*/
|
|
10
9
|
export async function captureElementsAsImages(
|
|
11
10
|
elements,
|
|
@@ -27,3 +26,50 @@ export async function captureElementsAsImages(
|
|
|
27
26
|
|
|
28
27
|
return captures;
|
|
29
28
|
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Captures React components as images (no refs needed)
|
|
32
|
+
*/
|
|
33
|
+
export async function captureComponentsAsImages(
|
|
34
|
+
components,
|
|
35
|
+
options = { cacheBust: true }
|
|
36
|
+
) {
|
|
37
|
+
const targets = Array.isArray(components) ? components : [components];
|
|
38
|
+
|
|
39
|
+
const captures = await Promise.all(
|
|
40
|
+
targets.map(async ({ component, width = '100%', height = 'auto', delay = 100 }) => {
|
|
41
|
+
const container = document.createElement('div');
|
|
42
|
+
container.style.position = 'absolute';
|
|
43
|
+
container.style.opacity = '0';
|
|
44
|
+
container.style.pointerEvents = 'none';
|
|
45
|
+
container.style.top = '0';
|
|
46
|
+
container.style.left = '0';
|
|
47
|
+
container.style.width = typeof width === 'number' ? `${width}px` : width;
|
|
48
|
+
container.style.height = typeof height === 'number' ? `${height}px` : height;
|
|
49
|
+
|
|
50
|
+
document.body.appendChild(container);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const root = createRoot(container);
|
|
54
|
+
root.render(component);
|
|
55
|
+
|
|
56
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
57
|
+
|
|
58
|
+
const dataUrl = await toPng(container, options);
|
|
59
|
+
|
|
60
|
+
root.unmount();
|
|
61
|
+
document.body.removeChild(container);
|
|
62
|
+
|
|
63
|
+
return dataUrl;
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error("Error capturing component as image:", err);
|
|
66
|
+
if (container.parentNode) {
|
|
67
|
+
document.body.removeChild(container);
|
|
68
|
+
}
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return captures;
|
|
75
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -35,7 +35,7 @@ export { renderNumber, renderPercentage } from "./@daf/utils/numbers.js"
|
|
|
35
35
|
|
|
36
36
|
export { MessageTypes, displayMessage} from './helpers/messages.js'
|
|
37
37
|
|
|
38
|
-
export { captureElementsAsImages } from './helpers/componentsToImages.js'
|
|
38
|
+
export { captureElementsAsImages, captureComponentsAsImages } from './helpers/componentsToImages.js'
|
|
39
39
|
|
|
40
40
|
export { createDocument } from './@daf/core/components/Document/WordDocument/createDocument.js'
|
|
41
41
|
|