UNPKG

jianghh-canvas

Version:

canvas画板,支持笔写、手写、鼠标流畅绘图,自动保存,撤销重做

18 lines (17 loc) 822 B
const i = { buffer: !0, pointerdown({ offsetX: t, offsetY: s }) { const e = this.eraseSize / 2; this.points.push({ x: t, y: s }), this.bufferCtx.lineWidth = 1, this.bufferCtx.moveTo(t - e, s - e), this.bufferCtx.beginPath(), this.bufferCtx.rect(t - e, s - e, this.eraseSize, this.eraseSize), this.bufferCtx.stroke(); }, pointermove({ offsetX: t, offsetY: s }) { const e = this.eraseSize / 2; this.ctx.clearRect(t - e, s - e, this.eraseSize, this.eraseSize), this.bufferCtx.clearRect(0, 0, this.el.width, this.el.height), this.bufferCtx.moveTo(t - e, s - e), this.bufferCtx.beginPath(), this.bufferCtx.rect(t - e, s - e, this.eraseSize, this.eraseSize), this.bufferCtx.stroke(); }, pointerup() { this.bufferCtx.clearRect(0, 0, this.el.width, this.el.height); } }; export { i as Erase };