diff --git a/desktop/sources/scripts/dotgrid.js b/desktop/sources/scripts/dotgrid.js index 5363544..c4d8d83 100644 --- a/desktop/sources/scripts/dotgrid.js +++ b/desktop/sources/scripts/dotgrid.js @@ -48,8 +48,8 @@ function Dotgrid () { window.addEventListener('drop', this.drag) this.acels.set('File', 'New', 'CmdOrCtrl+N', () => { this.source.new() }) - this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.save('export.grid', dotgrid.tool.export(), 'text/plain') }) - this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.download('export.png', this.surface.el.toDataURL('image/png', 1.0), 'image/png') }) + this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.save('export.grid', this.tool.export(), 'text/plain') }) + this.acels.set('File', 'Export Vector', 'CmdOrCtrl+E', () => { this.source.download('export.svg', this.manager.toString(), 'image/svg+xml') }) this.acels.set('File', 'Open', 'CmdOrCtrl+O', () => { this.source.open('grid', this.whenOpen) }) this.acels.set('File', 'Revert', 'CmdOrCtrl+W', () => { this.source.revert() }) this.acels.set('History', 'Undo', 'CmdOrCtrl+Z', () => { this.history.undo() }) diff --git a/desktop/sources/scripts/lib/source.js b/desktop/sources/scripts/lib/source.js index 8176c61..7c007c1 100644 --- a/desktop/sources/scripts/lib/source.js +++ b/desktop/sources/scripts/lib/source.js @@ -55,14 +55,14 @@ function Source () { reader.readAsText(file, 'UTF-8') } - this.download = (name, content, type) => { + this.download = (name, content, type, settings = 'charset=utf-8') => { console.info('Source', `Downloading ${name}(${type})`) const link = document.createElement('a') link.setAttribute('download', name) if (type === 'image/png' || type === 'image/jpeg') { link.setAttribute('href', content) } else { - link.setAttribute('href', 'data:' + type + ';charset=utf-8,' + encodeURIComponent(content)) + link.setAttribute('href', 'data:' + type + ';' + settings + ',' + encodeURIComponent(content)) } link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })) } diff --git a/desktop/sources/scripts/manager.js b/desktop/sources/scripts/manager.js index 3b276df..638ebe6 100644 --- a/desktop/sources/scripts/manager.js +++ b/desktop/sources/scripts/manager.js @@ -86,4 +86,8 @@ function Manager (dotgrid) { const file = new Blob([text], { type: 'text/plain' }) callback(URL.createObjectURL(file), 'export.grid') } + + this.toString = () => { + return new XMLSerializer().serializeToString(this.el) + } }