import type { Draw } from '../src/view'; export function paint(ctx: CanvasRenderingContext2D, commands: Draw[]): void { for (const d of commands) { ctx.save(); ctx.globalAlpha = d.alpha ?? 1; ctx.fillStyle = d.fill || 'transparent'; ctx.strokeStyle = d.stroke || 'transparent'; ctx.lineWidth = d.width || 1; ctx.lineCap = 'round'; ctx.lineJoin = 'round'; ctx.beginPath(); if (d.type === 'circle') ctx.arc(d.x, d.y, Math.max(0, d.r), 0, Math.PI * 2); else if (d.type === 'ellipse') ctx.ellipse(d.x, d.y, d.rx, d.ry, 0, 0, Math.PI * 2); else if (d.type === 'path') { if (d.dash) ctx.setLineDash(d.dash); d.points.forEach((p, i) => i ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y)); if (d.close) ctx.closePath(); } else { ctx.font = `${d.weight || 600} ${d.size}px "Avenir Next", "Nunito", "PingFang SC", sans-serif`; ctx.textAlign = d.align || 'center'; ctx.textBaseline = 'middle'; if (d.stroke) ctx.strokeText(d.text, d.x, d.y); ctx.fillText(d.text, d.x, d.y); ctx.restore(); continue; } if (d.fill) ctx.fill(); if (d.stroke) ctx.stroke(); ctx.restore(); } }