(e: React.MouseEvent<HTMLCanvasElement>)
| 423 | } |
| 424 | |
| 425 | const handleMouseUp = (e: React.MouseEvent<HTMLCanvasElement>) => { |
| 426 | if (!isDrawing) return |
| 427 | |
| 428 | if ((drawMode === 'rect' || drawMode === 'arrow') && startPoint) { |
| 429 | // 完成矩形或箭头绘制 |
| 430 | const canvas = canvasRef.current |
| 431 | if (!canvas) return |
| 432 | |
| 433 | const rect = canvas.getBoundingClientRect() |
| 434 | const x = (e.clientX - rect.left) / scale |
| 435 | const y = (e.clientY - rect.top) / scale |
| 436 | |
| 437 | const ctx = canvas.getContext('2d') |
| 438 | if (!ctx) return |
| 439 | |
| 440 | // 恢复历史状态 |
| 441 | if (currentHistoryIndex >= 0) { |
| 442 | ctx.putImageData(history[currentHistoryIndex].imageData, 0, 0) |
| 443 | } |
| 444 | |
| 445 | if (drawMode === 'rect') { |
| 446 | // 绘制最终矩形 |
| 447 | ctx.strokeStyle = drawColor |
| 448 | ctx.lineWidth = 3 |
| 449 | const width = x - startPoint.x |
| 450 | const height = y - startPoint.y |
| 451 | ctx.strokeRect(startPoint.x, startPoint.y, width, height) |
| 452 | } else if (drawMode === 'arrow') { |
| 453 | // 绘制最终箭头 |
| 454 | drawArrow(ctx, startPoint.x, startPoint.y, x, y, drawColor, 3) |
| 455 | } |
| 456 | |
| 457 | setStartPoint(null) |
| 458 | saveToHistory() |
| 459 | } else if (drawMode === 'highlight' && highlightCanvasRef.current) { |
| 460 | // 高亮模式:合成临时canvas到主canvas |
| 461 | const canvas = canvasRef.current |
| 462 | if (!canvas) return |
| 463 | |
| 464 | const ctx = canvas.getContext('2d') |
| 465 | if (!ctx) return |
| 466 | |
| 467 | ctx.globalAlpha = 0.3 |
| 468 | ctx.drawImage(highlightCanvasRef.current, 0, 0) |
| 469 | ctx.globalAlpha = 1 |
| 470 | |
| 471 | highlightCanvasRef.current = null |
| 472 | saveToHistory() |
| 473 | } else if (isDrawing) { |
| 474 | saveToHistory() |
| 475 | } |
| 476 | |
| 477 | setIsDrawing(false) |
| 478 | setLastDrawPoint(null) |
| 479 | } |
| 480 | |
| 481 | const draw = (x: number, y: number, isStart: boolean) => { |
| 482 | const canvas = canvasRef.current |
nothing calls this directly
no test coverage detected