@@ -90,33 +90,41 @@ export default class XPgInputPixelEditorBasic extends HTMLElement {
9090 } ) ;
9191 this . $file . addEventListener ( 'change' , this . handleFile . bind ( this ) ) ;
9292 this . $saveSvg . addEventListener ( 'click' , async ( ) => {
93- // @ts -ignore
94- const handle = await window . showSaveFilePicker ( {
95- suggestedName : 'Canvas' ,
96- types : [ {
97- description : 'SVG Document' ,
98- accept : { 'image/svg+xml' : [ '.svg' ] } ,
99- } ] ,
100- } ) ;
101- const writable = await handle . createWritable ( ) ;
102- await writable . write ( `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${ this . $width . value } ${ this . $height . value } ">` ) ;
103- await writable . write ( `<path d="${ 'test' } " />` ) ;
104- await writable . write ( '</svg>' ) ;
105- await writable . close ( ) ;
93+ try {
94+ // @ts -ignore
95+ const handle = await window . showSaveFilePicker ( {
96+ suggestedName : 'Canvas' ,
97+ types : [ {
98+ description : 'SVG Document' ,
99+ accept : { 'image/svg+xml' : [ '.svg' ] } ,
100+ } ] ,
101+ } ) ;
102+ const writable = await handle . createWritable ( ) ;
103+ await writable . write ( `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${ this . $width . value } ${ this . $height . value } ">` ) ;
104+ await writable . write ( `<path d="${ 'test' } " />` ) ;
105+ await writable . write ( '</svg>' ) ;
106+ await writable . close ( ) ;
107+ } catch ( e : any ) {
108+ // no save
109+ }
106110 } ) ;
107111 this . $savePng . addEventListener ( 'click' , async ( ) => {
108- // @ts -ignore
109- const handle = await window . showSaveFilePicker ( {
110- suggestedName : 'CanvasName' ,
111- types : [ {
112- description : 'SVG Document' ,
113- accept : { 'image/svg+xml' : [ '.svg' ] } ,
114- } ] ,
115- } ) ;
116- const writable = await handle . createWritable ( ) ;
117- await writable . write ( 'something' ) ;
118- await writable . write
119- await writable . close ( ) ;
112+ try {
113+ // @ts -ignore
114+ const handle = await window . showSaveFilePicker ( {
115+ suggestedName : 'CanvasName' ,
116+ types : [ {
117+ description : 'SVG Document' ,
118+ accept : { 'image/svg+xml' : [ '.svg' ] } ,
119+ } ] ,
120+ } ) ;
121+ const writable = await handle . createWritable ( ) ;
122+ await writable . write ( 'something' ) ;
123+ await writable . write
124+ await writable . close ( ) ;
125+ } catch ( e : any ) {
126+ // no save
127+ }
120128 } ) ;
121129 }
122130
0 commit comments