@@ -5,16 +5,13 @@ import example2 from './exampleData/2'
55import example3 from './exampleData/3'
66import type { Options , MindElixirData , MindElixirInstance } from './types/index'
77import type { Operation } from './utils/pubsub'
8- import { exportSvg , exportPng } from './plugin/exportImage'
8+ import { exportPng } from './plugin/exportImage'
99
10- window . exportSvg = exportSvg
11- window . exportPng = exportPng
1210interface Window {
1311 m : MindElixirInstance
1412 M : MindElixirCtor
1513 E : typeof MindElixir . E
16- exportSvg : typeof exportSvg
17- exportPng : typeof exportPng
14+ downloadPng : typeof downloadPng
1815}
1916
2017declare let window : Window
@@ -104,6 +101,19 @@ mind.bus.addListener('selectNode', node => {
104101mind . bus . addListener ( 'expandNode' , node => {
105102 console . log ( 'expandNode: ' , node )
106103} )
104+
105+ const downloadPng = async ( ) => {
106+ const blob = await mind . exportPng ( )
107+ if ( ! blob ) return
108+ const url = URL . createObjectURL ( blob )
109+ const a = document . createElement ( 'a' )
110+ a . href = url
111+ a . download = 'filename.png'
112+ a . click ( )
113+ URL . revokeObjectURL ( url )
114+ }
115+
116+ window . downloadPng = downloadPng
107117window . m = mind
108118// window.m2 = mind2
109119window . M = MindElixir
0 commit comments