const defaultOptions = {
    autoresize: true,
    // aspectratio: false
}

const canvas2d = (canvas, options) => {
    const opts = Object.assign({}, defaultOptions, options)
    const ctx = canvas.getContext('2d')

    const resize = () => {
        const rect = canvas.getBoundingClientRect()

        canvas.width = rect.width
        canvas.height = rect.height
    }

    if (opts.autoresize) {
        resize()
        window.addEventListener('resize', () => resize())
    }

    return ctx
}

export default canvas2d
