import { parseHTMLToDataURL , parseSVGToDataURL } from './parser' ; const { Image } = window ; export function loadImage ( src ) { return new Promise ( ( resolve , reject ) => { const img = new Image ; img . onload = function ( ) { resolve ( img ) ; } ; img . onabort = reject ; img . onerror = reject ; img . src = src ; } ) ; } export async function loadSVG ( svg ) { const dataURL = await parseSVGToDataURL ( svg ) ; const image = await loadImage ( dataURL ) ; return image ; } export async function loadHTML ( html , opts ) { const dataURL = await parseHTMLToDataURL ( html , opts ) ; const image = await loadImage ( dataURL ) ; return image ; }