pathfinder
pathfinder copied to clipboard
add reset method for CanvasRenderingContext2D
In Web Browsers, If width or height of a Canvas reassigned, even the value not changed, the canvas would reset it's state, includes state stack and current properties.
var canvas = new OffscreenCanvas(100, 100);
var ctx = canvas.getContext('2d')
ctx.font = 'menu'
console.log(ctx.font) // "16px Arial"
ctx.fillStyle = "red"
console.log(ctx.fillStyle) // "#ff0000"
// reassign width or height, the context state should reset to initial value
canvas.width = canvas.width
console.log(ctx.font) // "10px sans-serif"
console.log(ctx.fillStyle) // "#000000"