datastake-daf 0.6.475 → 0.6.476
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 +27 -4
- package/package.json +1 -1
- package/src/helpers/componentsToImages.js +26 -4
package/dist/utils/index.js
CHANGED
|
@@ -12672,22 +12672,45 @@ async function captureComponentsAsImages(components, options = {
|
|
|
12672
12672
|
component,
|
|
12673
12673
|
width = '100%',
|
|
12674
12674
|
height = 'auto',
|
|
12675
|
-
delay =
|
|
12675
|
+
delay = 300
|
|
12676
12676
|
}) => {
|
|
12677
12677
|
const container = document.createElement('div');
|
|
12678
12678
|
container.style.position = 'absolute';
|
|
12679
12679
|
container.style.opacity = '0';
|
|
12680
12680
|
container.style.pointerEvents = 'none';
|
|
12681
|
-
container.style.top = '
|
|
12682
|
-
container.style.left = '
|
|
12681
|
+
container.style.top = '-9999px';
|
|
12682
|
+
container.style.left = '-9999px';
|
|
12683
12683
|
container.style.width = typeof width === 'number' ? `${width}px` : width;
|
|
12684
12684
|
container.style.height = typeof height === 'number' ? `${height}px` : height;
|
|
12685
|
+
container.style.display = 'inline-block';
|
|
12685
12686
|
document.body.appendChild(container);
|
|
12686
12687
|
try {
|
|
12687
12688
|
const root = client.createRoot(container);
|
|
12688
12689
|
root.render(component);
|
|
12690
|
+
|
|
12691
|
+
// Wait for React to render
|
|
12692
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
12693
|
+
|
|
12694
|
+
// Wait for styled-components to inject styles
|
|
12695
|
+
await new Promise(resolve => requestAnimationFrame(() => {
|
|
12696
|
+
requestAnimationFrame(resolve);
|
|
12697
|
+
}));
|
|
12698
|
+
|
|
12699
|
+
// Additional delay for fonts/styles
|
|
12689
12700
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
12690
|
-
|
|
12701
|
+
|
|
12702
|
+
// Get the actual rendered element (first child)
|
|
12703
|
+
const element = container.firstChild;
|
|
12704
|
+
if (!element) {
|
|
12705
|
+
throw new Error('No element was rendered');
|
|
12706
|
+
}
|
|
12707
|
+
|
|
12708
|
+
// Capture the actual element, not the container
|
|
12709
|
+
const dataUrl = await htmlToImage.toPng(element, {
|
|
12710
|
+
...options,
|
|
12711
|
+
backgroundColor: 'transparent',
|
|
12712
|
+
pixelRatio: 2 // Higher quality
|
|
12713
|
+
});
|
|
12691
12714
|
root.unmount();
|
|
12692
12715
|
document.body.removeChild(container);
|
|
12693
12716
|
return dataUrl;
|
package/package.json
CHANGED
|
@@ -37,15 +37,16 @@ export async function captureComponentsAsImages(
|
|
|
37
37
|
const targets = Array.isArray(components) ? components : [components];
|
|
38
38
|
|
|
39
39
|
const captures = await Promise.all(
|
|
40
|
-
targets.map(async ({ component, width = '100%', height = 'auto', delay =
|
|
40
|
+
targets.map(async ({ component, width = '100%', height = 'auto', delay = 300 }) => {
|
|
41
41
|
const container = document.createElement('div');
|
|
42
42
|
container.style.position = 'absolute';
|
|
43
43
|
container.style.opacity = '0';
|
|
44
44
|
container.style.pointerEvents = 'none';
|
|
45
|
-
container.style.top = '
|
|
46
|
-
container.style.left = '
|
|
45
|
+
container.style.top = '-9999px';
|
|
46
|
+
container.style.left = '-9999px';
|
|
47
47
|
container.style.width = typeof width === 'number' ? `${width}px` : width;
|
|
48
48
|
container.style.height = typeof height === 'number' ? `${height}px` : height;
|
|
49
|
+
container.style.display = 'inline-block';
|
|
49
50
|
|
|
50
51
|
document.body.appendChild(container);
|
|
51
52
|
|
|
@@ -53,9 +54,30 @@ export async function captureComponentsAsImages(
|
|
|
53
54
|
const root = createRoot(container);
|
|
54
55
|
root.render(component);
|
|
55
56
|
|
|
57
|
+
// Wait for React to render
|
|
58
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
59
|
+
|
|
60
|
+
// Wait for styled-components to inject styles
|
|
61
|
+
await new Promise(resolve => requestAnimationFrame(() => {
|
|
62
|
+
requestAnimationFrame(resolve);
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
// Additional delay for fonts/styles
|
|
56
66
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
57
67
|
|
|
58
|
-
|
|
68
|
+
// Get the actual rendered element (first child)
|
|
69
|
+
const element = container.firstChild;
|
|
70
|
+
|
|
71
|
+
if (!element) {
|
|
72
|
+
throw new Error('No element was rendered');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Capture the actual element, not the container
|
|
76
|
+
const dataUrl = await toPng(element, {
|
|
77
|
+
...options,
|
|
78
|
+
backgroundColor: 'transparent',
|
|
79
|
+
pixelRatio: 2 // Higher quality
|
|
80
|
+
});
|
|
59
81
|
|
|
60
82
|
root.unmount();
|
|
61
83
|
document.body.removeChild(container);
|