@@ -215,7 +215,7 @@ export const createCanvasSlice: StateCreator<
215215 * elements. Therefore, the caller must save the
216216 * layers and elements themselves.
217217 */
218- async function prepareForSave ( ) : Promise < SavedCanvasProperties > {
218+ function prepareForSave ( ) : SavedCanvasProperties {
219219 const { layers, elements } = get ( ) ;
220220
221221 return { layers, elements } ;
@@ -270,7 +270,7 @@ export const createCanvasSlice: StateCreator<
270270 return lines ;
271271 }
272272
273- async function prepareForExport ( quality : number = 1 ) : Promise < Blob > {
273+ function prepareForExport ( quality : number = 1 ) : Promise < Blob > {
274274 const accountForDPI = true ; // Consider DPI for better quality exports
275275
276276 const substituteCanvas = document . createElement ( "canvas" ) ;
@@ -317,7 +317,7 @@ export const createCanvasSlice: StateCreator<
317317
318318 function drawCanvas ( canvas : HTMLCanvasElement , layerId ?: string ) {
319319 let elements = get ( ) . elements ;
320- const { background, layers, dpi, width : canvasWidth } = get ( ) ;
320+ const { background, layers, dpi, width : canvasWidth , height : canvasHeight } = get ( ) ;
321321
322322 if ( layers . length === 0 ) {
323323 throw new Error ( "No layers available to draw on the canvas." ) ;
@@ -357,15 +357,14 @@ export const createCanvasSlice: StateCreator<
357357
358358 if ( isPreviewCanvas ) {
359359 // If the canvas is a preview canvas, scale it down.
360- const scale = canvas . width / ( canvasWidth * dpi ) ;
360+ const scaleX = canvas . width / ( canvasWidth * dpi ) ;
361+ const scaleY = canvas . height / ( canvasHeight * dpi ) ;
361362 // Save the current transform state.
362363 ctx . save ( ) ;
363364
364- ctx . scale ( scale , scale ) ;
365+ ctx . scale ( scaleX , scaleY ) ;
365366 }
366367
367- console . log ( "drawing..." , layers , elements ) ;
368-
369368 for ( const element of elements ) {
370369 const { x, y, width, height } = element ;
371370
@@ -442,6 +441,9 @@ export const createCanvasSlice: StateCreator<
442441 }
443442 }
444443
444+ if ( isPreviewCanvas ) {
445+ ctx . restore ( ) ; // Restore the previous transform state.
446+ }
445447 // Finally, draw the background behind all elements.
446448 ctx . fillStyle = background ;
447449
@@ -450,16 +452,13 @@ export const createCanvasSlice: StateCreator<
450452 ctx . globalCompositeOperation = "destination-over" ;
451453 ctx . fillRect ( canvasX , canvasY , canvas . width , canvas . height ) ;
452454
453- if ( isPreviewCanvas ) {
454- ctx . restore ( ) ; // Restore the previous transform state.
455- }
456455 }
457456
458457 return {
459458 width : 400 ,
460459 height : 400 ,
461460 mode : "move" ,
462- background : "white " ,
461+ background : "#ffffff " ,
463462 shape : "rectangle" ,
464463 shapeMode : "fill" ,
465464 color : "#000000" ,
0 commit comments