datastake-daf 0.6.476 → 0.6.477
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 +8 -22
- package/package.json +1 -1
- package/src/helpers/componentsToImages.js +8 -23
package/dist/utils/index.js
CHANGED
|
@@ -12672,44 +12672,30 @@ async function captureComponentsAsImages(components, options = {
|
|
|
12672
12672
|
component,
|
|
12673
12673
|
width = '100%',
|
|
12674
12674
|
height = 'auto',
|
|
12675
|
-
delay =
|
|
12675
|
+
delay = 200
|
|
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 = '0';
|
|
12682
|
+
container.style.left = '0';
|
|
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';
|
|
12686
12685
|
document.body.appendChild(container);
|
|
12687
12686
|
try {
|
|
12688
12687
|
const root = client.createRoot(container);
|
|
12689
12688
|
root.render(component);
|
|
12690
12689
|
|
|
12691
|
-
// Wait for
|
|
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
|
|
12690
|
+
// Wait for render and styled-components CSS injection
|
|
12700
12691
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
12701
12692
|
|
|
12702
|
-
//
|
|
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
|
|
12693
|
+
// Capture the actual component (first child), not the wrapper
|
|
12694
|
+
const element = container.firstChild || container;
|
|
12709
12695
|
const dataUrl = await htmlToImage.toPng(element, {
|
|
12710
12696
|
...options,
|
|
12711
|
-
backgroundColor:
|
|
12712
|
-
pixelRatio: 2
|
|
12697
|
+
backgroundColor: null,
|
|
12698
|
+
pixelRatio: 2
|
|
12713
12699
|
});
|
|
12714
12700
|
root.unmount();
|
|
12715
12701
|
document.body.removeChild(container);
|
package/package.json
CHANGED
|
@@ -37,16 +37,15 @@ 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 = 200 }) => {
|
|
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 = '0';
|
|
46
|
+
container.style.left = '0';
|
|
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';
|
|
50
49
|
|
|
51
50
|
document.body.appendChild(container);
|
|
52
51
|
|
|
@@ -54,29 +53,15 @@ export async function captureComponentsAsImages(
|
|
|
54
53
|
const root = createRoot(container);
|
|
55
54
|
root.render(component);
|
|
56
55
|
|
|
57
|
-
// Wait for
|
|
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
|
+
// Wait for render and styled-components CSS injection
|
|
66
57
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
67
58
|
|
|
68
|
-
//
|
|
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
|
|
59
|
+
// Capture the actual component (first child), not the wrapper
|
|
60
|
+
const element = container.firstChild || container;
|
|
76
61
|
const dataUrl = await toPng(element, {
|
|
77
62
|
...options,
|
|
78
|
-
backgroundColor:
|
|
79
|
-
pixelRatio: 2
|
|
63
|
+
backgroundColor: null,
|
|
64
|
+
pixelRatio: 2
|
|
80
65
|
});
|
|
81
66
|
|
|
82
67
|
root.unmount();
|