@@ -23,6 +23,7 @@ import {
2323} from '$lib/components/file-list/FileList' ;
2424import type { RoutingControls } from '$lib/components/toolbar/tools/routing/RoutingControls' ;
2525import { SplitType } from '$lib/components/toolbar/tools/scissors/Scissors.svelte' ;
26+ import FileSaver from 'file-saver' ;
2627import JSZip from 'jszip' ;
2728
2829const { fileOrder } = settings ;
@@ -407,28 +408,6 @@ export function updateSelectionFromKey(down: boolean, shift: boolean) {
407408 }
408409}
409410
410- async function exportFilesAsZip ( fileIds : string [ ] , exclude : string [ ] ) {
411- const zip = new JSZip ( ) ;
412- for ( const fileId of fileIds ) {
413- const file = getFile ( fileId ) ;
414- if ( file ) {
415- const gpx = buildGPX ( file , exclude ) ;
416- zip . file ( file . metadata . name + '.gpx' , gpx ) ;
417- }
418- }
419- if ( Object . keys ( zip . files ) . length > 0 ) {
420- const content = await zip . generateAsync ( { type : 'blob' } ) ;
421- const link = document . createElement ( 'a' ) ;
422- link . href = URL . createObjectURL ( content ) ;
423- link . download = 'gpx-export.zip' ;
424- link . style . display = 'none' ;
425- document . body . appendChild ( link ) ;
426- link . click ( ) ;
427- document . body . removeChild ( link ) ;
428- URL . revokeObjectURL ( link . href ) ;
429- }
430- }
431-
432411async function exportFiles ( fileIds : string [ ] , exclude : string [ ] ) {
433412 if ( fileIds . length > 1 ) {
434413 await exportFilesAsZip ( fileIds , exclude )
@@ -455,14 +434,24 @@ export async function exportAllFiles(exclude: string[]) {
455434 await exportFiles ( get ( fileOrder ) , exclude ) ;
456435}
457436
458- export function exportFile ( file : GPXFile , exclude : string [ ] ) {
459- let blob = new Blob ( [ buildGPX ( file , exclude ) ] , { type : 'application/gpx+xml' } ) ;
460- let url = URL . createObjectURL ( blob ) ;
461- let a = document . createElement ( 'a' ) ;
462- a . href = url ;
463- a . download = file . metadata . name + '.gpx' ;
464- a . click ( ) ;
465- URL . revokeObjectURL ( url ) ;
437+ function exportFile ( file : GPXFile , exclude : string [ ] ) {
438+ const blob = new Blob ( [ buildGPX ( file , exclude ) ] , { type : 'application/gpx+xml' } ) ;
439+ FileSaver . saveAs ( blob , `${ file . metadata . name } .gpx` ) ;
440+ }
441+
442+ async function exportFilesAsZip ( fileIds : string [ ] , exclude : string [ ] ) {
443+ const zip = new JSZip ( ) ;
444+ for ( const fileId of fileIds ) {
445+ const file = getFile ( fileId ) ;
446+ if ( file ) {
447+ const gpx = buildGPX ( file , exclude ) ;
448+ zip . file ( file . metadata . name + '.gpx' , gpx ) ;
449+ }
450+ }
451+ if ( Object . keys ( zip . files ) . length > 0 ) {
452+ const blob = await zip . generateAsync ( { type : 'blob' } ) ;
453+ FileSaver . saveAs ( blob , 'gpx-files.zip' ) ;
454+ }
466455}
467456
468457export const allHidden = writable ( false ) ;
0 commit comments