@@ -46,10 +46,12 @@ export class PreviewShapeUtil extends BaseBoxShapeUtil<PreviewShape> {
46
46
_ctx : SvgExportContext
47
47
) : SVGElement | Promise < SVGElement > {
48
48
const g = document . createElementNS ( "http://www.w3.org/2000/svg" , "g" ) ;
49
- // while screenshot is the same as the old one, keep waiting for a new one
50
- return new Promise ( ( resolve , _ ) => {
51
- if ( window === undefined ) return resolve ( g ) ;
52
49
50
+ if ( ! this . iframeRef . current ?. contentWindow ) return g ;
51
+
52
+ const contentWindow = this . iframeRef . current . contentWindow ;
53
+
54
+ return new Promise ( ( resolve , _ ) => {
53
55
const windowListener = ( event : MessageEvent ) => {
54
56
if ( event . data . screenshot && event . data ?. shapeid === shape . id ) {
55
57
const image = document . createElementNS (
@@ -61,8 +63,8 @@ export class PreviewShapeUtil extends BaseBoxShapeUtil<PreviewShape> {
61
63
"href" ,
62
64
event . data . screenshot
63
65
) ;
64
- image . setAttribute ( "width" , shape . props . w . toString ( ) ) ;
65
- image . setAttribute ( "height" , shape . props . h . toString ( ) ) ;
66
+ image . setAttribute ( "width" , ( shape . props . w * 2 ) . toString ( ) ) ;
67
+ image . setAttribute ( "height" , ( shape . props . h * 2 ) . toString ( ) ) ;
66
68
g . appendChild ( image ) ;
67
69
window . removeEventListener ( "message" , windowListener ) ;
68
70
clearTimeout ( timeOut ) ;
@@ -77,14 +79,10 @@ export class PreviewShapeUtil extends BaseBoxShapeUtil<PreviewShape> {
77
79
window . addEventListener ( "message" , windowListener ) ;
78
80
//request new screenshot
79
81
80
- if ( this . iframeRef . current ?. contentWindow ) {
81
- this . iframeRef . current . contentWindow . postMessage (
82
- { action : "take-screenshot" , shapeid : shape . id } ,
83
- "*"
84
- ) ;
85
- } else {
86
- console . log ( "iframe not found or not accessible" ) ;
87
- }
82
+ contentWindow . postMessage (
83
+ { action : "take-screenshot" , shapeid : shape . id } ,
84
+ "*"
85
+ ) ;
88
86
} ) ;
89
87
}
90
88
0 commit comments