/**
 *
 * @type {WeakMap<HTMLCanvasElement, CanvasRenderingContext2D>}
 */
const context_cache = new WeakMap();

/**
 *
 * @param {HTMLCanvasElement} canvas
 * @returns {CanvasRenderingContext2D}
 */
export function html_canvas_to_rendering_context2d_cached(canvas) {
    let context = context_cache.get(canvas);

    if (context === undefined) {
        context = canvas.getContext("2d");
        context_cache.set(canvas, context);
    }
    return context;
}