import { _tempData } from '../names' ; import iDraw from './../index' ; export async function exportDataURL ( idraw , type , quality ? ) { if ( idraw [ _tempData ] . get ( 'isDownloading' ) === true ) { return Promise . reject ( 'Busy!' ) ; } idraw [ _tempData ] . set ( 'isDownloading' , true ) ; return new Promise ( ( resolve , reject ) => { let dataURL = '' ; function listenRenderFrameComplete ( ) { idraw . off ( 'drawFrameComplete' , listenRenderFrameComplete ) ; idraw [ _tempData ] . set ( 'isDownloading' , false ) ; const ctx = idraw . __getOriginContext2D ( ) ; const canvas = ctx . canvas ; dataURL = canvas . toDataURL ( type , quality ) ; resolve ( dataURL ) ; } try { idraw . on ( 'drawFrameComplete' , listenRenderFrameComplete ) ; idraw . clearOperation ( ) ; } catch ( err ) { reject ( err ) ; } } ) ; } export function toDataURL ( idraw , type , quality ? ) { const ctx = idraw . __getOriginContext2D ( ) ; const canvas = ctx . canvas ; const dataURL = canvas . toDataURL ( type , quality ) ; return dataURL ; }