markupr 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/review-feedback.md +47 -0
- package/.eslintrc.json +35 -0
- package/.github/CODEOWNERS +16 -0
- package/.github/FUNDING.yml +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +56 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +54 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +89 -0
- package/.github/dependabot.yml +70 -0
- package/.github/workflows/ci.yml +184 -0
- package/.github/workflows/deploy-landing.yml +134 -0
- package/.github/workflows/nightly.yml +288 -0
- package/.github/workflows/release.yml +318 -0
- package/CHANGELOG.md +127 -0
- package/CLAUDE.md +137 -0
- package/CODE_OF_CONDUCT.md +9 -0
- package/CONTRIBUTING.md +390 -0
- package/LICENSE +21 -0
- package/PRODUCT_VISION.md +277 -0
- package/README.md +517 -0
- package/SECURITY.md +51 -0
- package/SIGNING_INSTRUCTIONS.md +284 -0
- package/assets/DMG_BACKGROUND_INSTRUCTIONS.md +130 -0
- package/assets/svg-source/dmg-background.svg +70 -0
- package/assets/svg-source/icon.svg +20 -0
- package/assets/svg-source/tray-icon-processing.svg +7 -0
- package/assets/svg-source/tray-icon-recording.svg +7 -0
- package/assets/svg-source/tray-icon.svg +6 -0
- package/assets/tray-complete.png +0 -0
- package/assets/tray-complete@2x.png +0 -0
- package/assets/tray-completeTemplate.png +0 -0
- package/assets/tray-completeTemplate@2x.png +0 -0
- package/assets/tray-error.png +0 -0
- package/assets/tray-error@2x.png +0 -0
- package/assets/tray-errorTemplate.png +0 -0
- package/assets/tray-errorTemplate@2x.png +0 -0
- package/assets/tray-icon-processing.png +0 -0
- package/assets/tray-icon-processing@2x.png +0 -0
- package/assets/tray-icon-processingTemplate.png +0 -0
- package/assets/tray-icon-processingTemplate@2x.png +0 -0
- package/assets/tray-icon-recording.png +0 -0
- package/assets/tray-icon-recording@2x.png +0 -0
- package/assets/tray-icon-recordingTemplate.png +0 -0
- package/assets/tray-icon-recordingTemplate@2x.png +0 -0
- package/assets/tray-icon.png +0 -0
- package/assets/tray-icon@2x.png +0 -0
- package/assets/tray-iconTemplate.png +0 -0
- package/assets/tray-iconTemplate@2x.png +0 -0
- package/assets/tray-idle.png +0 -0
- package/assets/tray-idle@2x.png +0 -0
- package/assets/tray-idleTemplate.png +0 -0
- package/assets/tray-idleTemplate@2x.png +0 -0
- package/assets/tray-processing-0.png +0 -0
- package/assets/tray-processing-0@2x.png +0 -0
- package/assets/tray-processing-0Template.png +0 -0
- package/assets/tray-processing-0Template@2x.png +0 -0
- package/assets/tray-processing-1.png +0 -0
- package/assets/tray-processing-1@2x.png +0 -0
- package/assets/tray-processing-1Template.png +0 -0
- package/assets/tray-processing-1Template@2x.png +0 -0
- package/assets/tray-processing-2.png +0 -0
- package/assets/tray-processing-2@2x.png +0 -0
- package/assets/tray-processing-2Template.png +0 -0
- package/assets/tray-processing-2Template@2x.png +0 -0
- package/assets/tray-processing-3.png +0 -0
- package/assets/tray-processing-3@2x.png +0 -0
- package/assets/tray-processing-3Template.png +0 -0
- package/assets/tray-processing-3Template@2x.png +0 -0
- package/assets/tray-processing.png +0 -0
- package/assets/tray-processing@2x.png +0 -0
- package/assets/tray-processingTemplate.png +0 -0
- package/assets/tray-processingTemplate@2x.png +0 -0
- package/assets/tray-recording.png +0 -0
- package/assets/tray-recording@2x.png +0 -0
- package/assets/tray-recordingTemplate.png +0 -0
- package/assets/tray-recordingTemplate@2x.png +0 -0
- package/build/DMG_BACKGROUND_SPEC.md +50 -0
- package/build/dmg-background.png +0 -0
- package/build/dmg-background@2x.png +0 -0
- package/build/entitlements.mac.inherit.plist +27 -0
- package/build/entitlements.mac.plist +41 -0
- package/build/favicon-16.png +0 -0
- package/build/favicon-180.png +0 -0
- package/build/favicon-192.png +0 -0
- package/build/favicon-32.png +0 -0
- package/build/favicon-48.png +0 -0
- package/build/favicon-512.png +0 -0
- package/build/favicon-64.png +0 -0
- package/build/icon-128.png +0 -0
- package/build/icon-16.png +0 -0
- package/build/icon-24.png +0 -0
- package/build/icon-256.png +0 -0
- package/build/icon-32.png +0 -0
- package/build/icon-48.png +0 -0
- package/build/icon-64.png +0 -0
- package/build/icon.icns +0 -0
- package/build/icon.ico +0 -0
- package/build/icon.iconset/icon_128x128.png +0 -0
- package/build/icon.iconset/icon_128x128@2x.png +0 -0
- package/build/icon.iconset/icon_16x16.png +0 -0
- package/build/icon.iconset/icon_16x16@2x.png +0 -0
- package/build/icon.iconset/icon_256x256.png +0 -0
- package/build/icon.iconset/icon_256x256@2x.png +0 -0
- package/build/icon.iconset/icon_32x32.png +0 -0
- package/build/icon.iconset/icon_32x32@2x.png +0 -0
- package/build/icon.iconset/icon_512x512.png +0 -0
- package/build/icon.iconset/icon_512x512@2x.png +0 -0
- package/build/icon.png +0 -0
- package/build/installer-header.bmp +0 -0
- package/build/installer-header.png +0 -0
- package/build/installer-sidebar.bmp +0 -0
- package/build/installer-sidebar.png +0 -0
- package/build/installer.nsh +45 -0
- package/build/overlay-processing.png +0 -0
- package/build/overlay-recording.png +0 -0
- package/build/toolbar-record.png +0 -0
- package/build/toolbar-screenshot.png +0 -0
- package/build/toolbar-settings.png +0 -0
- package/build/toolbar-stop.png +0 -0
- package/dist/main/index.mjs +12612 -0
- package/dist/preload/index.mjs +907 -0
- package/dist/renderer/assets/index-CCmUjl9K.js +19495 -0
- package/dist/renderer/assets/index-CUqz_Gs6.css +2270 -0
- package/dist/renderer/index.html +27 -0
- package/docs/AI_AGENT_QUICKSTART.md +42 -0
- package/docs/AI_PIPELINE_DESIGN.md +595 -0
- package/docs/API.md +514 -0
- package/docs/ARCHITECTURE.md +460 -0
- package/docs/CONFIGURATION.md +336 -0
- package/docs/DEVELOPMENT.md +508 -0
- package/docs/EXPORT_FORMATS.md +451 -0
- package/docs/GETTING_STARTED.md +236 -0
- package/docs/KEYBOARD_SHORTCUTS.md +334 -0
- package/docs/TROUBLESHOOTING.md +418 -0
- package/docs/landing/index.html +672 -0
- package/docs/landing/script.js +342 -0
- package/docs/landing/styles.css +1543 -0
- package/electron-builder.yml +140 -0
- package/electron.vite.config.ts +63 -0
- package/package.json +108 -0
- package/railway.json +12 -0
- package/scripts/build.mjs +51 -0
- package/scripts/generate-icons.mjs +314 -0
- package/scripts/generate-installer-images.cjs +253 -0
- package/scripts/generate-tray-icons.mjs +258 -0
- package/scripts/notarize.cjs +180 -0
- package/scripts/one-click-clean-test.sh +147 -0
- package/scripts/postinstall.mjs +36 -0
- package/scripts/setup-markupr.sh +55 -0
- package/setup +17 -0
- package/site/index.html +1835 -0
- package/site/package.json +11 -0
- package/site/railway.json +12 -0
- package/site/server.js +31 -0
- package/src/main/AutoUpdater.ts +392 -0
- package/src/main/CrashRecovery.ts +655 -0
- package/src/main/ErrorHandler.ts +703 -0
- package/src/main/HotkeyManager.ts +399 -0
- package/src/main/MenuManager.ts +529 -0
- package/src/main/PermissionManager.ts +420 -0
- package/src/main/SessionController.ts +1465 -0
- package/src/main/TrayManager.ts +540 -0
- package/src/main/ai/AIPipelineManager.ts +199 -0
- package/src/main/ai/ClaudeAnalyzer.ts +339 -0
- package/src/main/ai/ImageOptimizer.ts +176 -0
- package/src/main/ai/StructuredMarkdownBuilder.ts +379 -0
- package/src/main/ai/index.ts +16 -0
- package/src/main/ai/types.ts +258 -0
- package/src/main/analysis/ClarificationGenerator.ts +385 -0
- package/src/main/analysis/FeedbackAnalyzer.ts +531 -0
- package/src/main/analysis/index.ts +19 -0
- package/src/main/audio/AudioCapture.ts +978 -0
- package/src/main/audio/audioUtils.ts +100 -0
- package/src/main/audio/index.ts +20 -0
- package/src/main/capture/index.ts +1 -0
- package/src/main/index.ts +1693 -0
- package/src/main/ipc/captureHandlers.ts +272 -0
- package/src/main/ipc/index.ts +45 -0
- package/src/main/ipc/outputHandlers.ts +302 -0
- package/src/main/ipc/sessionHandlers.ts +56 -0
- package/src/main/ipc/settingsHandlers.ts +471 -0
- package/src/main/ipc/types.ts +56 -0
- package/src/main/ipc/windowHandlers.ts +277 -0
- package/src/main/output/ClipboardService.ts +369 -0
- package/src/main/output/ExportService.ts +539 -0
- package/src/main/output/FileManager.ts +416 -0
- package/src/main/output/MarkdownGenerator.ts +791 -0
- package/src/main/output/MarkdownPatcher.ts +299 -0
- package/src/main/output/index.ts +186 -0
- package/src/main/output/sessionAdapter.ts +207 -0
- package/src/main/output/templates/html-template.ts +553 -0
- package/src/main/pipeline/FrameExtractor.ts +330 -0
- package/src/main/pipeline/PostProcessor.ts +399 -0
- package/src/main/pipeline/TranscriptAnalyzer.ts +226 -0
- package/src/main/pipeline/index.ts +36 -0
- package/src/main/platform/WindowsTaskbar.ts +600 -0
- package/src/main/platform/index.ts +16 -0
- package/src/main/settings/SettingsManager.ts +730 -0
- package/src/main/settings/index.ts +19 -0
- package/src/main/transcription/ModelDownloadManager.ts +494 -0
- package/src/main/transcription/TierManager.ts +219 -0
- package/src/main/transcription/TranscriptionRecoveryService.ts +340 -0
- package/src/main/transcription/WhisperService.ts +748 -0
- package/src/main/transcription/index.ts +56 -0
- package/src/main/transcription/types.ts +135 -0
- package/src/main/windows/PopoverManager.ts +284 -0
- package/src/main/windows/TaskbarIntegration.ts +452 -0
- package/src/main/windows/index.ts +23 -0
- package/src/preload/index.ts +1047 -0
- package/src/renderer/App.tsx +515 -0
- package/src/renderer/AppWrapper.tsx +28 -0
- package/src/renderer/assets/logo-dark.svg +7 -0
- package/src/renderer/assets/logo.svg +7 -0
- package/src/renderer/audio/AudioCaptureRenderer.ts +454 -0
- package/src/renderer/capture/ScreenRecordingRenderer.ts +492 -0
- package/src/renderer/components/AnnotationOverlay.tsx +836 -0
- package/src/renderer/components/AudioWaveform.tsx +811 -0
- package/src/renderer/components/ClarificationQuestions.tsx +656 -0
- package/src/renderer/components/CountdownTimer.tsx +495 -0
- package/src/renderer/components/CrashRecoveryDialog.tsx +632 -0
- package/src/renderer/components/DonateButton.tsx +127 -0
- package/src/renderer/components/ErrorBoundary.tsx +308 -0
- package/src/renderer/components/ExportDialog.tsx +872 -0
- package/src/renderer/components/HotkeyHint.tsx +261 -0
- package/src/renderer/components/KeyboardShortcuts.tsx +787 -0
- package/src/renderer/components/ModelDownloadDialog.tsx +844 -0
- package/src/renderer/components/Onboarding.tsx +1830 -0
- package/src/renderer/components/ProcessingOverlay.tsx +157 -0
- package/src/renderer/components/RecordingOverlay.tsx +423 -0
- package/src/renderer/components/SessionHistory.tsx +1746 -0
- package/src/renderer/components/SessionReview.tsx +1321 -0
- package/src/renderer/components/SettingsPanel.tsx +217 -0
- package/src/renderer/components/Skeleton.tsx +347 -0
- package/src/renderer/components/StatusIndicator.tsx +86 -0
- package/src/renderer/components/ThemeProvider.tsx +429 -0
- package/src/renderer/components/Tooltip.tsx +370 -0
- package/src/renderer/components/TranscriptionPreview.tsx +183 -0
- package/src/renderer/components/TranscriptionTierSelector.tsx +640 -0
- package/src/renderer/components/UpdateNotification.tsx +377 -0
- package/src/renderer/components/WindowSelector.tsx +947 -0
- package/src/renderer/components/index.ts +99 -0
- package/src/renderer/components/primitives/ApiKeyInput.tsx +98 -0
- package/src/renderer/components/primitives/ColorPicker.tsx +65 -0
- package/src/renderer/components/primitives/DangerButton.tsx +45 -0
- package/src/renderer/components/primitives/DirectoryPicker.tsx +41 -0
- package/src/renderer/components/primitives/Dropdown.tsx +34 -0
- package/src/renderer/components/primitives/KeyRecorder.tsx +117 -0
- package/src/renderer/components/primitives/SettingsSection.tsx +32 -0
- package/src/renderer/components/primitives/Slider.tsx +43 -0
- package/src/renderer/components/primitives/Toggle.tsx +36 -0
- package/src/renderer/components/primitives/index.ts +10 -0
- package/src/renderer/components/settings/AdvancedTab.tsx +174 -0
- package/src/renderer/components/settings/AppearanceTab.tsx +77 -0
- package/src/renderer/components/settings/GeneralTab.tsx +40 -0
- package/src/renderer/components/settings/HotkeysTab.tsx +79 -0
- package/src/renderer/components/settings/RecordingTab.tsx +84 -0
- package/src/renderer/components/settings/index.ts +9 -0
- package/src/renderer/components/settings/settingsStyles.ts +673 -0
- package/src/renderer/components/settings/tabConfig.tsx +85 -0
- package/src/renderer/components/settings/useSettingsPanel.ts +447 -0
- package/src/renderer/contexts/ProcessingContext.tsx +227 -0
- package/src/renderer/contexts/RecordingContext.tsx +683 -0
- package/src/renderer/contexts/UIContext.tsx +326 -0
- package/src/renderer/contexts/index.ts +24 -0
- package/src/renderer/donateMessages.ts +69 -0
- package/src/renderer/hooks/index.ts +75 -0
- package/src/renderer/hooks/useAnimation.tsx +544 -0
- package/src/renderer/hooks/useTheme.ts +313 -0
- package/src/renderer/index.html +26 -0
- package/src/renderer/main.tsx +52 -0
- package/src/renderer/styles/animations.css +1093 -0
- package/src/renderer/styles/app-shell.css +662 -0
- package/src/renderer/styles/globals.css +515 -0
- package/src/renderer/styles/theme.ts +578 -0
- package/src/renderer/types/electron.d.ts +385 -0
- package/src/shared/hotkeys.ts +283 -0
- package/src/shared/types.ts +809 -0
- package/tests/clipboard.test.ts +228 -0
- package/tests/e2e/criticalPaths.test.ts +594 -0
- package/tests/feedbackAnalyzer.test.ts +303 -0
- package/tests/integration/sessionFlow.test.ts +583 -0
- package/tests/markdownGenerator.test.ts +418 -0
- package/tests/output.test.ts +96 -0
- package/tests/setup.ts +486 -0
- package/tests/unit/appIntegration.test.ts +676 -0
- package/tests/unit/appViewState.test.ts +281 -0
- package/tests/unit/audioIpcChannels.test.ts +17 -0
- package/tests/unit/exportService.test.ts +492 -0
- package/tests/unit/hotkeys.test.ts +92 -0
- package/tests/unit/navigationPreload.test.ts +94 -0
- package/tests/unit/onboardingFlow.test.ts +345 -0
- package/tests/unit/permissionManager.test.ts +175 -0
- package/tests/unit/permissionManagerExpanded.test.ts +296 -0
- package/tests/unit/screenRecordingRenderer.test.ts +368 -0
- package/tests/unit/sessionController.test.ts +515 -0
- package/tests/unit/tierManager.test.ts +61 -0
- package/tests/unit/tierManagerExpanded.test.ts +142 -0
- package/tests/unit/transcriptAnalyzer.test.ts +64 -0
- package/tsconfig.json +25 -0
- package/vitest.config.ts +46 -0
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Annotation Overlay Component
|
|
3
|
+
*
|
|
4
|
+
* A professional screenshot annotation tool allowing users to:
|
|
5
|
+
* - Draw shapes: Circle, Arrow, Rectangle, Freehand
|
|
6
|
+
* - Pick colors: Red (default), Blue, Yellow, Green, White
|
|
7
|
+
* - Undo/Redo with full history support
|
|
8
|
+
* - Clear all annotations
|
|
9
|
+
* - Save annotated screenshot
|
|
10
|
+
*
|
|
11
|
+
* Keyboard shortcuts:
|
|
12
|
+
* - 1: Arrow tool
|
|
13
|
+
* - 2: Circle tool
|
|
14
|
+
* - 3: Rectangle tool
|
|
15
|
+
* - 4: Freehand tool
|
|
16
|
+
* - Z / Cmd+Z: Undo
|
|
17
|
+
* - Y / Cmd+Shift+Z: Redo
|
|
18
|
+
* - C: Clear all
|
|
19
|
+
* - Escape: Cancel
|
|
20
|
+
* - Enter: Save
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import React, {
|
|
24
|
+
useState,
|
|
25
|
+
useEffect,
|
|
26
|
+
useRef,
|
|
27
|
+
useCallback,
|
|
28
|
+
useMemo,
|
|
29
|
+
} from 'react';
|
|
30
|
+
import type { Screenshot } from '../../shared/types';
|
|
31
|
+
|
|
32
|
+
// =============================================================================
|
|
33
|
+
// Types
|
|
34
|
+
// =============================================================================
|
|
35
|
+
|
|
36
|
+
type Tool = 'circle' | 'arrow' | 'rectangle' | 'freehand';
|
|
37
|
+
|
|
38
|
+
interface Point {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface Annotation {
|
|
44
|
+
id: string;
|
|
45
|
+
type: Tool;
|
|
46
|
+
points: Point[];
|
|
47
|
+
color: string;
|
|
48
|
+
strokeWidth: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface AnnotationOverlayProps {
|
|
52
|
+
screenshot: Screenshot;
|
|
53
|
+
isActive: boolean;
|
|
54
|
+
onSave: (annotatedDataUrl: string) => void;
|
|
55
|
+
onCancel: () => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// Constants
|
|
60
|
+
// =============================================================================
|
|
61
|
+
|
|
62
|
+
const TOOLS: { id: Tool; icon: string; label: string; shortcut: string }[] = [
|
|
63
|
+
{ id: 'arrow', icon: '\u2197', label: 'Arrow', shortcut: '1' },
|
|
64
|
+
{ id: 'circle', icon: '\u25CB', label: 'Circle', shortcut: '2' },
|
|
65
|
+
{ id: 'rectangle', icon: '\u25A1', label: 'Rectangle', shortcut: '3' },
|
|
66
|
+
{ id: 'freehand', icon: '\u270E', label: 'Freehand', shortcut: '4' },
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
const COLORS = [
|
|
70
|
+
{ value: '#FF3B30', name: 'Red' },
|
|
71
|
+
{ value: '#007AFF', name: 'Blue' },
|
|
72
|
+
{ value: '#FFCC00', name: 'Yellow' },
|
|
73
|
+
{ value: '#34C759', name: 'Green' },
|
|
74
|
+
{ value: '#FFFFFF', name: 'White' },
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const DEFAULT_STROKE_WIDTH = 3;
|
|
78
|
+
const ARROWHEAD_LENGTH = 15;
|
|
79
|
+
|
|
80
|
+
// =============================================================================
|
|
81
|
+
// Drawing Utilities
|
|
82
|
+
// =============================================================================
|
|
83
|
+
|
|
84
|
+
function generateId(): string {
|
|
85
|
+
return `ann_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function drawArrow(
|
|
89
|
+
ctx: CanvasRenderingContext2D,
|
|
90
|
+
from: Point,
|
|
91
|
+
to: Point,
|
|
92
|
+
color: string,
|
|
93
|
+
strokeWidth: number
|
|
94
|
+
): void {
|
|
95
|
+
const angle = Math.atan2(to.y - from.y, to.x - from.x);
|
|
96
|
+
const headLength = ARROWHEAD_LENGTH;
|
|
97
|
+
|
|
98
|
+
ctx.strokeStyle = color;
|
|
99
|
+
ctx.lineWidth = strokeWidth;
|
|
100
|
+
ctx.lineCap = 'round';
|
|
101
|
+
ctx.lineJoin = 'round';
|
|
102
|
+
|
|
103
|
+
// Draw the line
|
|
104
|
+
ctx.beginPath();
|
|
105
|
+
ctx.moveTo(from.x, from.y);
|
|
106
|
+
ctx.lineTo(to.x, to.y);
|
|
107
|
+
ctx.stroke();
|
|
108
|
+
|
|
109
|
+
// Draw the arrowhead
|
|
110
|
+
ctx.beginPath();
|
|
111
|
+
ctx.moveTo(to.x, to.y);
|
|
112
|
+
ctx.lineTo(
|
|
113
|
+
to.x - headLength * Math.cos(angle - Math.PI / 6),
|
|
114
|
+
to.y - headLength * Math.sin(angle - Math.PI / 6)
|
|
115
|
+
);
|
|
116
|
+
ctx.stroke();
|
|
117
|
+
|
|
118
|
+
ctx.beginPath();
|
|
119
|
+
ctx.moveTo(to.x, to.y);
|
|
120
|
+
ctx.lineTo(
|
|
121
|
+
to.x - headLength * Math.cos(angle + Math.PI / 6),
|
|
122
|
+
to.y - headLength * Math.sin(angle + Math.PI / 6)
|
|
123
|
+
);
|
|
124
|
+
ctx.stroke();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function drawAnnotation(
|
|
128
|
+
ctx: CanvasRenderingContext2D,
|
|
129
|
+
annotation: Annotation
|
|
130
|
+
): void {
|
|
131
|
+
ctx.strokeStyle = annotation.color;
|
|
132
|
+
ctx.lineWidth = annotation.strokeWidth;
|
|
133
|
+
ctx.lineCap = 'round';
|
|
134
|
+
ctx.lineJoin = 'round';
|
|
135
|
+
|
|
136
|
+
switch (annotation.type) {
|
|
137
|
+
case 'circle': {
|
|
138
|
+
if (annotation.points.length < 2) return;
|
|
139
|
+
const [start, end] = annotation.points;
|
|
140
|
+
const radius = Math.hypot(end.x - start.x, end.y - start.y);
|
|
141
|
+
ctx.beginPath();
|
|
142
|
+
ctx.arc(start.x, start.y, radius, 0, Math.PI * 2);
|
|
143
|
+
ctx.stroke();
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
case 'arrow': {
|
|
148
|
+
if (annotation.points.length < 2) return;
|
|
149
|
+
drawArrow(
|
|
150
|
+
ctx,
|
|
151
|
+
annotation.points[0],
|
|
152
|
+
annotation.points[1],
|
|
153
|
+
annotation.color,
|
|
154
|
+
annotation.strokeWidth
|
|
155
|
+
);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
case 'rectangle': {
|
|
160
|
+
if (annotation.points.length < 2) return;
|
|
161
|
+
const [p1, p2] = annotation.points;
|
|
162
|
+
ctx.beginPath();
|
|
163
|
+
ctx.rect(p1.x, p1.y, p2.x - p1.x, p2.y - p1.y);
|
|
164
|
+
ctx.stroke();
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
case 'freehand': {
|
|
169
|
+
if (annotation.points.length < 2) return;
|
|
170
|
+
ctx.beginPath();
|
|
171
|
+
annotation.points.forEach((point, i) => {
|
|
172
|
+
if (i === 0) {
|
|
173
|
+
ctx.moveTo(point.x, point.y);
|
|
174
|
+
} else {
|
|
175
|
+
ctx.lineTo(point.x, point.y);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
ctx.stroke();
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// =============================================================================
|
|
185
|
+
// Toolbar Component
|
|
186
|
+
// =============================================================================
|
|
187
|
+
|
|
188
|
+
interface ToolbarProps {
|
|
189
|
+
tool: Tool;
|
|
190
|
+
color: string;
|
|
191
|
+
onToolChange: (tool: Tool) => void;
|
|
192
|
+
onColorChange: (color: string) => void;
|
|
193
|
+
onUndo: () => void;
|
|
194
|
+
onRedo: () => void;
|
|
195
|
+
onClear: () => void;
|
|
196
|
+
onSave: () => void;
|
|
197
|
+
onCancel: () => void;
|
|
198
|
+
canUndo: boolean;
|
|
199
|
+
canRedo: boolean;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const Toolbar: React.FC<ToolbarProps> = ({
|
|
203
|
+
tool,
|
|
204
|
+
color,
|
|
205
|
+
onToolChange,
|
|
206
|
+
onColorChange,
|
|
207
|
+
onUndo,
|
|
208
|
+
onRedo,
|
|
209
|
+
onClear,
|
|
210
|
+
onSave,
|
|
211
|
+
onCancel,
|
|
212
|
+
canUndo,
|
|
213
|
+
canRedo,
|
|
214
|
+
}) => {
|
|
215
|
+
return (
|
|
216
|
+
<div style={toolbarStyles.container}>
|
|
217
|
+
{/* Tool buttons */}
|
|
218
|
+
<div style={toolbarStyles.section}>
|
|
219
|
+
{TOOLS.map((t) => (
|
|
220
|
+
<button
|
|
221
|
+
key={t.id}
|
|
222
|
+
onClick={() => onToolChange(t.id)}
|
|
223
|
+
style={{
|
|
224
|
+
...toolbarStyles.button,
|
|
225
|
+
...(tool === t.id ? toolbarStyles.buttonActive : {}),
|
|
226
|
+
}}
|
|
227
|
+
title={`${t.label} (${t.shortcut})`}
|
|
228
|
+
>
|
|
229
|
+
<span style={toolbarStyles.buttonIcon}>{t.icon}</span>
|
|
230
|
+
</button>
|
|
231
|
+
))}
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
<div style={toolbarStyles.divider} />
|
|
235
|
+
|
|
236
|
+
{/* Color picker */}
|
|
237
|
+
<div style={toolbarStyles.section}>
|
|
238
|
+
{COLORS.map((c) => (
|
|
239
|
+
<button
|
|
240
|
+
key={c.value}
|
|
241
|
+
onClick={() => onColorChange(c.value)}
|
|
242
|
+
style={{
|
|
243
|
+
...toolbarStyles.colorButton,
|
|
244
|
+
backgroundColor: c.value,
|
|
245
|
+
...(color === c.value ? toolbarStyles.colorButtonActive : {}),
|
|
246
|
+
}}
|
|
247
|
+
title={c.name}
|
|
248
|
+
/>
|
|
249
|
+
))}
|
|
250
|
+
</div>
|
|
251
|
+
|
|
252
|
+
<div style={toolbarStyles.divider} />
|
|
253
|
+
|
|
254
|
+
{/* History controls */}
|
|
255
|
+
<div style={toolbarStyles.section}>
|
|
256
|
+
<button
|
|
257
|
+
onClick={onUndo}
|
|
258
|
+
disabled={!canUndo}
|
|
259
|
+
style={{
|
|
260
|
+
...toolbarStyles.button,
|
|
261
|
+
...(canUndo ? {} : toolbarStyles.buttonDisabled),
|
|
262
|
+
}}
|
|
263
|
+
title="Undo (Z)"
|
|
264
|
+
>
|
|
265
|
+
<span style={toolbarStyles.buttonIcon}>{'\u21A9'}</span>
|
|
266
|
+
</button>
|
|
267
|
+
<button
|
|
268
|
+
onClick={onRedo}
|
|
269
|
+
disabled={!canRedo}
|
|
270
|
+
style={{
|
|
271
|
+
...toolbarStyles.button,
|
|
272
|
+
...(canRedo ? {} : toolbarStyles.buttonDisabled),
|
|
273
|
+
}}
|
|
274
|
+
title="Redo (Y)"
|
|
275
|
+
>
|
|
276
|
+
<span style={toolbarStyles.buttonIcon}>{'\u21AA'}</span>
|
|
277
|
+
</button>
|
|
278
|
+
<button
|
|
279
|
+
onClick={onClear}
|
|
280
|
+
style={{
|
|
281
|
+
...toolbarStyles.button,
|
|
282
|
+
...toolbarStyles.buttonDanger,
|
|
283
|
+
}}
|
|
284
|
+
title="Clear All (C)"
|
|
285
|
+
>
|
|
286
|
+
<span style={toolbarStyles.buttonIcon}>{'\u2715'}</span>
|
|
287
|
+
</button>
|
|
288
|
+
</div>
|
|
289
|
+
|
|
290
|
+
<div style={toolbarStyles.divider} />
|
|
291
|
+
|
|
292
|
+
{/* Action buttons */}
|
|
293
|
+
<div style={toolbarStyles.section}>
|
|
294
|
+
<button
|
|
295
|
+
onClick={onCancel}
|
|
296
|
+
style={{
|
|
297
|
+
...toolbarStyles.actionButton,
|
|
298
|
+
...toolbarStyles.cancelButton,
|
|
299
|
+
}}
|
|
300
|
+
title="Cancel (Escape)"
|
|
301
|
+
>
|
|
302
|
+
Cancel
|
|
303
|
+
</button>
|
|
304
|
+
<button
|
|
305
|
+
onClick={onSave}
|
|
306
|
+
style={{
|
|
307
|
+
...toolbarStyles.actionButton,
|
|
308
|
+
...toolbarStyles.saveButton,
|
|
309
|
+
}}
|
|
310
|
+
title="Save (Enter)"
|
|
311
|
+
>
|
|
312
|
+
Save
|
|
313
|
+
</button>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const toolbarStyles: Record<string, React.CSSProperties> = {
|
|
320
|
+
container: {
|
|
321
|
+
position: 'fixed',
|
|
322
|
+
top: 16,
|
|
323
|
+
left: '50%',
|
|
324
|
+
transform: 'translateX(-50%)',
|
|
325
|
+
display: 'flex',
|
|
326
|
+
alignItems: 'center',
|
|
327
|
+
gap: 8,
|
|
328
|
+
padding: '8px 12px',
|
|
329
|
+
backgroundColor: 'rgba(17, 24, 39, 0.95)',
|
|
330
|
+
borderRadius: 12,
|
|
331
|
+
backdropFilter: 'blur(12px)',
|
|
332
|
+
WebkitBackdropFilter: 'blur(12px)',
|
|
333
|
+
boxShadow: `
|
|
334
|
+
0 4px 6px -1px rgba(0, 0, 0, 0.1),
|
|
335
|
+
0 2px 4px -1px rgba(0, 0, 0, 0.06),
|
|
336
|
+
0 0 0 1px rgba(75, 85, 99, 0.5)
|
|
337
|
+
`,
|
|
338
|
+
zIndex: 10001,
|
|
339
|
+
userSelect: 'none',
|
|
340
|
+
},
|
|
341
|
+
section: {
|
|
342
|
+
display: 'flex',
|
|
343
|
+
alignItems: 'center',
|
|
344
|
+
gap: 4,
|
|
345
|
+
},
|
|
346
|
+
divider: {
|
|
347
|
+
width: 1,
|
|
348
|
+
height: 24,
|
|
349
|
+
backgroundColor: 'rgba(75, 85, 99, 0.5)',
|
|
350
|
+
margin: '0 4px',
|
|
351
|
+
},
|
|
352
|
+
button: {
|
|
353
|
+
display: 'flex',
|
|
354
|
+
alignItems: 'center',
|
|
355
|
+
justifyContent: 'center',
|
|
356
|
+
width: 36,
|
|
357
|
+
height: 36,
|
|
358
|
+
padding: 0,
|
|
359
|
+
backgroundColor: 'transparent',
|
|
360
|
+
border: 'none',
|
|
361
|
+
borderRadius: 8,
|
|
362
|
+
cursor: 'pointer',
|
|
363
|
+
transition: 'all 0.15s ease',
|
|
364
|
+
color: 'var(--text-primary)',
|
|
365
|
+
},
|
|
366
|
+
buttonActive: {
|
|
367
|
+
backgroundColor: 'var(--accent-default)',
|
|
368
|
+
},
|
|
369
|
+
buttonDisabled: {
|
|
370
|
+
opacity: 0.4,
|
|
371
|
+
cursor: 'not-allowed',
|
|
372
|
+
},
|
|
373
|
+
buttonDanger: {
|
|
374
|
+
color: 'var(--status-error)',
|
|
375
|
+
},
|
|
376
|
+
buttonIcon: {
|
|
377
|
+
fontSize: 18,
|
|
378
|
+
lineHeight: 1,
|
|
379
|
+
},
|
|
380
|
+
colorButton: {
|
|
381
|
+
width: 24,
|
|
382
|
+
height: 24,
|
|
383
|
+
padding: 0,
|
|
384
|
+
border: '2px solid transparent',
|
|
385
|
+
borderRadius: '50%',
|
|
386
|
+
cursor: 'pointer',
|
|
387
|
+
transition: 'all 0.15s ease',
|
|
388
|
+
},
|
|
389
|
+
colorButtonActive: {
|
|
390
|
+
borderColor: 'var(--text-inverse)',
|
|
391
|
+
transform: 'scale(1.1)',
|
|
392
|
+
},
|
|
393
|
+
actionButton: {
|
|
394
|
+
padding: '6px 14px',
|
|
395
|
+
border: 'none',
|
|
396
|
+
borderRadius: 8,
|
|
397
|
+
fontSize: 13,
|
|
398
|
+
fontWeight: 600,
|
|
399
|
+
cursor: 'pointer',
|
|
400
|
+
transition: 'all 0.15s ease',
|
|
401
|
+
},
|
|
402
|
+
cancelButton: {
|
|
403
|
+
backgroundColor: 'rgba(75, 85, 99, 0.5)',
|
|
404
|
+
color: 'var(--text-primary)',
|
|
405
|
+
},
|
|
406
|
+
saveButton: {
|
|
407
|
+
backgroundColor: 'var(--status-success)',
|
|
408
|
+
color: 'var(--text-inverse)',
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// =============================================================================
|
|
413
|
+
// Hint Overlay Component
|
|
414
|
+
// =============================================================================
|
|
415
|
+
|
|
416
|
+
const HintOverlay: React.FC = () => {
|
|
417
|
+
const [visible, setVisible] = useState(true);
|
|
418
|
+
|
|
419
|
+
useEffect(() => {
|
|
420
|
+
const timer = setTimeout(() => setVisible(false), 4000);
|
|
421
|
+
return () => clearTimeout(timer);
|
|
422
|
+
}, []);
|
|
423
|
+
|
|
424
|
+
if (!visible) return null;
|
|
425
|
+
|
|
426
|
+
return (
|
|
427
|
+
<div style={hintStyles.container}>
|
|
428
|
+
<div style={hintStyles.badge}>
|
|
429
|
+
<span style={hintStyles.text}>
|
|
430
|
+
Draw to annotate | Press <kbd style={hintStyles.kbd}>1-4</kbd> for
|
|
431
|
+
tools | <kbd style={hintStyles.kbd}>Z</kbd> to undo
|
|
432
|
+
</span>
|
|
433
|
+
</div>
|
|
434
|
+
</div>
|
|
435
|
+
);
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const hintStyles: Record<string, React.CSSProperties> = {
|
|
439
|
+
container: {
|
|
440
|
+
position: 'fixed',
|
|
441
|
+
bottom: 24,
|
|
442
|
+
left: '50%',
|
|
443
|
+
transform: 'translateX(-50%)',
|
|
444
|
+
zIndex: 10001,
|
|
445
|
+
animation: 'toolbarFadeInUp 0.3s ease-out, fadeOut 0.3s ease-in 3.7s forwards',
|
|
446
|
+
},
|
|
447
|
+
badge: {
|
|
448
|
+
padding: '8px 16px',
|
|
449
|
+
backgroundColor: 'rgba(17, 24, 39, 0.9)',
|
|
450
|
+
borderRadius: 20,
|
|
451
|
+
backdropFilter: 'blur(8px)',
|
|
452
|
+
},
|
|
453
|
+
text: {
|
|
454
|
+
color: 'var(--text-secondary)',
|
|
455
|
+
fontSize: 13,
|
|
456
|
+
},
|
|
457
|
+
kbd: {
|
|
458
|
+
display: 'inline-block',
|
|
459
|
+
padding: '2px 6px',
|
|
460
|
+
marginLeft: 2,
|
|
461
|
+
marginRight: 2,
|
|
462
|
+
backgroundColor: 'rgba(75, 85, 99, 0.5)',
|
|
463
|
+
borderRadius: 4,
|
|
464
|
+
fontSize: 11,
|
|
465
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
466
|
+
color: 'var(--text-primary)',
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// =============================================================================
|
|
471
|
+
// Main Component
|
|
472
|
+
// =============================================================================
|
|
473
|
+
|
|
474
|
+
export const AnnotationOverlay: React.FC<AnnotationOverlayProps> = ({
|
|
475
|
+
screenshot,
|
|
476
|
+
isActive,
|
|
477
|
+
onSave,
|
|
478
|
+
onCancel,
|
|
479
|
+
}) => {
|
|
480
|
+
// Canvas refs
|
|
481
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
482
|
+
const imageRef = useRef<HTMLImageElement | null>(null);
|
|
483
|
+
|
|
484
|
+
// Drawing state
|
|
485
|
+
const [tool, setTool] = useState<Tool>('arrow');
|
|
486
|
+
const [color, setColor] = useState(COLORS[0].value);
|
|
487
|
+
const [annotations, setAnnotations] = useState<Annotation[]>([]);
|
|
488
|
+
const [currentAnnotation, setCurrentAnnotation] = useState<Annotation | null>(
|
|
489
|
+
null
|
|
490
|
+
);
|
|
491
|
+
const [isDrawing, setIsDrawing] = useState(false);
|
|
492
|
+
|
|
493
|
+
// History state (for undo/redo)
|
|
494
|
+
const [history, setHistory] = useState<Annotation[][]>([[]]);
|
|
495
|
+
const [historyIndex, setHistoryIndex] = useState(0);
|
|
496
|
+
|
|
497
|
+
// Compute derived state
|
|
498
|
+
const canUndo = historyIndex > 0;
|
|
499
|
+
const canRedo = historyIndex < history.length - 1;
|
|
500
|
+
|
|
501
|
+
// Get image source from screenshot
|
|
502
|
+
const imageSrc = useMemo(() => {
|
|
503
|
+
if (screenshot.base64) {
|
|
504
|
+
return `data:image/png;base64,${screenshot.base64}`;
|
|
505
|
+
}
|
|
506
|
+
// Fallback to file path with file:// protocol
|
|
507
|
+
return `file://${screenshot.imagePath}`;
|
|
508
|
+
}, [screenshot]);
|
|
509
|
+
|
|
510
|
+
// ==========================================================================
|
|
511
|
+
// Canvas Rendering
|
|
512
|
+
// ==========================================================================
|
|
513
|
+
|
|
514
|
+
const redrawCanvas = useCallback(() => {
|
|
515
|
+
const canvas = canvasRef.current;
|
|
516
|
+
const img = imageRef.current;
|
|
517
|
+
if (!canvas || !img) return;
|
|
518
|
+
|
|
519
|
+
const ctx = canvas.getContext('2d');
|
|
520
|
+
if (!ctx) return;
|
|
521
|
+
|
|
522
|
+
// Clear and draw image
|
|
523
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
524
|
+
ctx.drawImage(img, 0, 0);
|
|
525
|
+
|
|
526
|
+
// Draw all annotations
|
|
527
|
+
annotations.forEach((ann) => drawAnnotation(ctx, ann));
|
|
528
|
+
|
|
529
|
+
// Draw current annotation in progress
|
|
530
|
+
if (currentAnnotation) {
|
|
531
|
+
drawAnnotation(ctx, currentAnnotation);
|
|
532
|
+
}
|
|
533
|
+
}, [annotations, currentAnnotation]);
|
|
534
|
+
|
|
535
|
+
// Load image and set up canvas
|
|
536
|
+
useEffect(() => {
|
|
537
|
+
const img = new Image();
|
|
538
|
+
img.crossOrigin = 'anonymous';
|
|
539
|
+
|
|
540
|
+
img.onload = () => {
|
|
541
|
+
imageRef.current = img;
|
|
542
|
+
const canvas = canvasRef.current;
|
|
543
|
+
if (canvas) {
|
|
544
|
+
canvas.width = img.naturalWidth;
|
|
545
|
+
canvas.height = img.naturalHeight;
|
|
546
|
+
redrawCanvas();
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
img.onerror = () => {
|
|
551
|
+
console.error('Failed to load screenshot for annotation');
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
img.src = imageSrc;
|
|
555
|
+
}, [imageSrc, redrawCanvas]);
|
|
556
|
+
|
|
557
|
+
// Redraw when annotations change
|
|
558
|
+
useEffect(() => {
|
|
559
|
+
redrawCanvas();
|
|
560
|
+
}, [redrawCanvas]);
|
|
561
|
+
|
|
562
|
+
// ==========================================================================
|
|
563
|
+
// History Management
|
|
564
|
+
// ==========================================================================
|
|
565
|
+
|
|
566
|
+
const pushToHistory = useCallback(
|
|
567
|
+
(newAnnotations: Annotation[]) => {
|
|
568
|
+
// Remove any redo states
|
|
569
|
+
const newHistory = history.slice(0, historyIndex + 1);
|
|
570
|
+
newHistory.push(newAnnotations);
|
|
571
|
+
|
|
572
|
+
// Limit history to prevent memory issues
|
|
573
|
+
if (newHistory.length > 50) {
|
|
574
|
+
newHistory.shift();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
setHistory(newHistory);
|
|
578
|
+
setHistoryIndex(newHistory.length - 1);
|
|
579
|
+
},
|
|
580
|
+
[history, historyIndex]
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
const undo = useCallback(() => {
|
|
584
|
+
if (historyIndex > 0) {
|
|
585
|
+
const newIndex = historyIndex - 1;
|
|
586
|
+
setHistoryIndex(newIndex);
|
|
587
|
+
setAnnotations(history[newIndex]);
|
|
588
|
+
}
|
|
589
|
+
}, [history, historyIndex]);
|
|
590
|
+
|
|
591
|
+
const redo = useCallback(() => {
|
|
592
|
+
if (historyIndex < history.length - 1) {
|
|
593
|
+
const newIndex = historyIndex + 1;
|
|
594
|
+
setHistoryIndex(newIndex);
|
|
595
|
+
setAnnotations(history[newIndex]);
|
|
596
|
+
}
|
|
597
|
+
}, [history, historyIndex]);
|
|
598
|
+
|
|
599
|
+
const clearAll = useCallback(() => {
|
|
600
|
+
setAnnotations([]);
|
|
601
|
+
pushToHistory([]);
|
|
602
|
+
}, [pushToHistory]);
|
|
603
|
+
|
|
604
|
+
// ==========================================================================
|
|
605
|
+
// Drawing Handlers
|
|
606
|
+
// ==========================================================================
|
|
607
|
+
|
|
608
|
+
const getCanvasCoordinates = useCallback(
|
|
609
|
+
(e: React.MouseEvent<HTMLCanvasElement>): Point => {
|
|
610
|
+
const canvas = canvasRef.current;
|
|
611
|
+
if (!canvas) return { x: 0, y: 0 };
|
|
612
|
+
|
|
613
|
+
const rect = canvas.getBoundingClientRect();
|
|
614
|
+
const scaleX = canvas.width / rect.width;
|
|
615
|
+
const scaleY = canvas.height / rect.height;
|
|
616
|
+
|
|
617
|
+
return {
|
|
618
|
+
x: (e.clientX - rect.left) * scaleX,
|
|
619
|
+
y: (e.clientY - rect.top) * scaleY,
|
|
620
|
+
};
|
|
621
|
+
},
|
|
622
|
+
[]
|
|
623
|
+
);
|
|
624
|
+
|
|
625
|
+
const handleMouseDown = useCallback(
|
|
626
|
+
(e: React.MouseEvent<HTMLCanvasElement>) => {
|
|
627
|
+
if (e.button !== 0) return; // Only left click
|
|
628
|
+
|
|
629
|
+
const point = getCanvasCoordinates(e);
|
|
630
|
+
setIsDrawing(true);
|
|
631
|
+
|
|
632
|
+
const newAnnotation: Annotation = {
|
|
633
|
+
id: generateId(),
|
|
634
|
+
type: tool,
|
|
635
|
+
points: [point],
|
|
636
|
+
color,
|
|
637
|
+
strokeWidth: DEFAULT_STROKE_WIDTH,
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
setCurrentAnnotation(newAnnotation);
|
|
641
|
+
},
|
|
642
|
+
[tool, color, getCanvasCoordinates]
|
|
643
|
+
);
|
|
644
|
+
|
|
645
|
+
const handleMouseMove = useCallback(
|
|
646
|
+
(e: React.MouseEvent<HTMLCanvasElement>) => {
|
|
647
|
+
if (!isDrawing || !currentAnnotation) return;
|
|
648
|
+
|
|
649
|
+
const point = getCanvasCoordinates(e);
|
|
650
|
+
|
|
651
|
+
setCurrentAnnotation((prev) => {
|
|
652
|
+
if (!prev) return null;
|
|
653
|
+
|
|
654
|
+
if (prev.type === 'freehand') {
|
|
655
|
+
// Freehand: add all points
|
|
656
|
+
return {
|
|
657
|
+
...prev,
|
|
658
|
+
points: [...prev.points, point],
|
|
659
|
+
};
|
|
660
|
+
} else {
|
|
661
|
+
// Other tools: keep start point, update end point
|
|
662
|
+
return {
|
|
663
|
+
...prev,
|
|
664
|
+
points: [prev.points[0], point],
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
},
|
|
669
|
+
[isDrawing, currentAnnotation, getCanvasCoordinates]
|
|
670
|
+
);
|
|
671
|
+
|
|
672
|
+
const handleMouseUp = useCallback(() => {
|
|
673
|
+
if (!isDrawing || !currentAnnotation) return;
|
|
674
|
+
|
|
675
|
+
// Only save if annotation has enough points
|
|
676
|
+
if (currentAnnotation.points.length >= 2) {
|
|
677
|
+
const newAnnotations = [...annotations, currentAnnotation];
|
|
678
|
+
setAnnotations(newAnnotations);
|
|
679
|
+
pushToHistory(newAnnotations);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
setIsDrawing(false);
|
|
683
|
+
setCurrentAnnotation(null);
|
|
684
|
+
}, [isDrawing, currentAnnotation, annotations, pushToHistory]);
|
|
685
|
+
|
|
686
|
+
// ==========================================================================
|
|
687
|
+
// Save Handler
|
|
688
|
+
// ==========================================================================
|
|
689
|
+
|
|
690
|
+
const handleSave = useCallback(() => {
|
|
691
|
+
const canvas = canvasRef.current;
|
|
692
|
+
if (!canvas) return;
|
|
693
|
+
|
|
694
|
+
// Export canvas as data URL
|
|
695
|
+
const dataUrl = canvas.toDataURL('image/png');
|
|
696
|
+
onSave(dataUrl);
|
|
697
|
+
}, [onSave]);
|
|
698
|
+
|
|
699
|
+
// ==========================================================================
|
|
700
|
+
// Keyboard Shortcuts
|
|
701
|
+
// ==========================================================================
|
|
702
|
+
|
|
703
|
+
useEffect(() => {
|
|
704
|
+
if (!isActive) return;
|
|
705
|
+
|
|
706
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
707
|
+
// Don't handle if typing in an input
|
|
708
|
+
if (
|
|
709
|
+
e.target instanceof HTMLInputElement ||
|
|
710
|
+
e.target instanceof HTMLTextAreaElement
|
|
711
|
+
) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// Tool shortcuts
|
|
716
|
+
switch (e.key) {
|
|
717
|
+
case '1':
|
|
718
|
+
setTool('arrow');
|
|
719
|
+
break;
|
|
720
|
+
case '2':
|
|
721
|
+
setTool('circle');
|
|
722
|
+
break;
|
|
723
|
+
case '3':
|
|
724
|
+
setTool('rectangle');
|
|
725
|
+
break;
|
|
726
|
+
case '4':
|
|
727
|
+
setTool('freehand');
|
|
728
|
+
break;
|
|
729
|
+
case 'z':
|
|
730
|
+
case 'Z':
|
|
731
|
+
if (e.metaKey || e.ctrlKey) {
|
|
732
|
+
if (e.shiftKey) {
|
|
733
|
+
redo();
|
|
734
|
+
} else {
|
|
735
|
+
undo();
|
|
736
|
+
}
|
|
737
|
+
e.preventDefault();
|
|
738
|
+
} else if (!e.shiftKey) {
|
|
739
|
+
undo();
|
|
740
|
+
}
|
|
741
|
+
break;
|
|
742
|
+
case 'y':
|
|
743
|
+
case 'Y':
|
|
744
|
+
redo();
|
|
745
|
+
break;
|
|
746
|
+
case 'c':
|
|
747
|
+
case 'C':
|
|
748
|
+
if (!e.metaKey && !e.ctrlKey) {
|
|
749
|
+
clearAll();
|
|
750
|
+
}
|
|
751
|
+
break;
|
|
752
|
+
case 'Escape':
|
|
753
|
+
onCancel();
|
|
754
|
+
break;
|
|
755
|
+
case 'Enter':
|
|
756
|
+
handleSave();
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
762
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
763
|
+
}, [isActive, undo, redo, clearAll, onCancel, handleSave]);
|
|
764
|
+
|
|
765
|
+
// ==========================================================================
|
|
766
|
+
// Render
|
|
767
|
+
// ==========================================================================
|
|
768
|
+
|
|
769
|
+
if (!isActive) return null;
|
|
770
|
+
|
|
771
|
+
return (
|
|
772
|
+
<>
|
|
773
|
+
{/* toolbarFadeInUp, fadeOut, pageFadeIn keyframes provided by animations.css */}
|
|
774
|
+
|
|
775
|
+
{/* Backdrop */}
|
|
776
|
+
<div
|
|
777
|
+
style={{
|
|
778
|
+
position: 'fixed',
|
|
779
|
+
inset: 0,
|
|
780
|
+
backgroundColor: 'rgba(0, 0, 0, 0.85)',
|
|
781
|
+
zIndex: 10000,
|
|
782
|
+
animation: 'pageFadeIn 0.2s ease-out',
|
|
783
|
+
}}
|
|
784
|
+
/>
|
|
785
|
+
|
|
786
|
+
{/* Canvas container */}
|
|
787
|
+
<div
|
|
788
|
+
style={{
|
|
789
|
+
position: 'fixed',
|
|
790
|
+
inset: 0,
|
|
791
|
+
display: 'flex',
|
|
792
|
+
alignItems: 'center',
|
|
793
|
+
justifyContent: 'center',
|
|
794
|
+
padding: 60,
|
|
795
|
+
zIndex: 10000,
|
|
796
|
+
}}
|
|
797
|
+
>
|
|
798
|
+
<canvas
|
|
799
|
+
ref={canvasRef}
|
|
800
|
+
style={{
|
|
801
|
+
maxWidth: '100%',
|
|
802
|
+
maxHeight: '100%',
|
|
803
|
+
objectFit: 'contain',
|
|
804
|
+
borderRadius: 8,
|
|
805
|
+
boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.5)',
|
|
806
|
+
cursor: tool === 'freehand' ? 'crosshair' : 'crosshair',
|
|
807
|
+
}}
|
|
808
|
+
onMouseDown={handleMouseDown}
|
|
809
|
+
onMouseMove={handleMouseMove}
|
|
810
|
+
onMouseUp={handleMouseUp}
|
|
811
|
+
onMouseLeave={handleMouseUp}
|
|
812
|
+
/>
|
|
813
|
+
</div>
|
|
814
|
+
|
|
815
|
+
{/* Toolbar */}
|
|
816
|
+
<Toolbar
|
|
817
|
+
tool={tool}
|
|
818
|
+
color={color}
|
|
819
|
+
onToolChange={setTool}
|
|
820
|
+
onColorChange={setColor}
|
|
821
|
+
onUndo={undo}
|
|
822
|
+
onRedo={redo}
|
|
823
|
+
onClear={clearAll}
|
|
824
|
+
onSave={handleSave}
|
|
825
|
+
onCancel={onCancel}
|
|
826
|
+
canUndo={canUndo}
|
|
827
|
+
canRedo={canRedo}
|
|
828
|
+
/>
|
|
829
|
+
|
|
830
|
+
{/* Hint overlay */}
|
|
831
|
+
<HintOverlay />
|
|
832
|
+
</>
|
|
833
|
+
);
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
export default AnnotationOverlay;
|