UNPKG

jianghh-canvas

Version:

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

21 lines (20 loc) 868 B
const h = { pointerdown({ offsetX: i, offsetY: s }) { this.points.push({ x: i >> 0, y: s >> 0 }), this.ctx.beginPath(), this.ctx.arc(this.beginPoint.x, this.beginPoint.y, this.lineWidth / 2, 0, 2 * Math.PI), this.ctx.fill(), this.ctx.closePath(); }, pointermove({ offsetX: i, offsetY: s }) { if (this.points.push({ x: i >> 0, y: s >> 0 }), this.points.length < 3) return; const t = this.points.slice(-2), o = t[0], n = { x: (t[0].x + t[1].x) / 2, y: (t[0].y + t[1].y) / 2 }; this.ctx.beginPath(), this.ctx.moveTo(this.beginPoint.x, this.beginPoint.y), this.ctx.quadraticCurveTo(o.x, o.y, n.x, n.y), this.ctx.stroke(), this.beginPoint = n; }, pointerup() { this.ctx.beginPath(), this.ctx.arc(this.beginPoint.x, this.beginPoint.y, this.lineWidth / 2, 0, 2 * Math.PI), this.ctx.fill(); } }; export { h as Marker };