@@ -27,7 +27,7 @@ const STAGE_HEIGHT = 2200;
2727const GRID_SIZE = 32 ;
2828const MIN_SCALE = 0.45 ;
2929const MAX_SCALE = 2.4 ;
30- const DEFAULT_VIEW = { x : 120 , y : 120 , scale : 1 } ;
30+ const DEFAULT_VIEW = { x : 0 , y : 0 , scale : 1 } ;
3131const SYMBOL_EXPORT_SIZE = 62 ;
3232const SYMBOL_EXPORT_OFFSET_X = 30 ;
3333const SYMBOL_EXPORT_OFFSET_Y = 8 ;
@@ -432,7 +432,10 @@ export default function PatchEditor() {
432432 } ;
433433 }
434434
435- async function buildPatchSvgMarkup ( ) {
435+ async function buildPatchSvgMarkup ( {
436+ includeBackground = true ,
437+ includeGrid = true
438+ } = { } ) {
436439 const bounds = getExportBounds ( ) ;
437440 const symbolEntries = await Promise . all (
438441 [ ...new Set ( nodes . map ( ( node ) => node . symbolId ) ) ] . map ( async ( symbolId ) => [
@@ -523,8 +526,8 @@ export default function PatchEditor() {
523526
524527 return `
525528 <svg xmlns="http://www.w3.org/2000/svg" width="${ bounds . width } " height="${ bounds . height } " viewBox="${ bounds . left } ${ bounds . top } ${ bounds . width } ${ bounds . height } ">
526- <rect x="${ bounds . left } " y="${ bounds . top } " width="${ bounds . width } " height="${ bounds . height } " fill="#eef1e8" />
527- <g opacity="0.55">
529+ ${ includeBackground ? ` <rect x="${ bounds . left } " y="${ bounds . top } " width="${ bounds . width } " height="${ bounds . height } " fill="#eef1e8" />` : "" }
530+ ${ includeGrid ? ` <g opacity="0.55">
528531 ${ Array . from ( { length : Math . ceil ( bounds . height / GRID_SIZE ) + 1 } , ( _ , index ) => {
529532 const y = bounds . top + index * GRID_SIZE ;
530533 return `<line x1="${ bounds . left } " y1="${ y } " x2="${ bounds . left + bounds . width } " y2="${ y } " stroke="#ffffff" stroke-opacity="0.6" stroke-width="1" />` ;
@@ -533,7 +536,7 @@ export default function PatchEditor() {
533536 const x = bounds . left + index * GRID_SIZE ;
534537 return `<line x1="${ x } " y1="${ bounds . top } " x2="${ x } " y2="${ bounds . top + bounds . height } " stroke="#ffffff" stroke-opacity="0.6" stroke-width="1" />` ;
535538 } ) . join ( "" ) }
536- </g>
539+ </g>` : "" }
537540 ${ connectionMarkup }
538541 ${ nodeMarkup }
539542 </svg>
@@ -567,7 +570,10 @@ export default function PatchEditor() {
567570 async function handleExportPng ( ) {
568571 try {
569572 const stamp = new Date ( ) . toISOString ( ) . replace ( / [: .] / g, "-" ) ;
570- const svg = await buildPatchSvgMarkup ( ) ;
573+ const svg = await buildPatchSvgMarkup ( {
574+ includeBackground : false ,
575+ includeGrid : false
576+ } ) ;
571577 const blob = new Blob ( [ svg ] , { type : "image/svg+xml;charset=utf-8" } ) ;
572578 const url = URL . createObjectURL ( blob ) ;
573579 const image = new Image ( ) ;
@@ -583,6 +589,7 @@ export default function PatchEditor() {
583589 return ;
584590 }
585591
592+ context . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
586593 context . drawImage ( image , 0 , 0 ) ;
587594 canvas . toBlob ( ( pngBlob ) => {
588595 URL . revokeObjectURL ( url ) ;
0 commit comments