Spaces:
Running
Running
File size: 4,665 Bytes
e8a57cb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | # Revision Notes Preact Overhaul
## Overview
Complete rewrite of the revision notes/annotation system using Preact (no build setup) with modern features and improved UX.
## New Features
### 1. **Image Upload & Reference Panel**
- Drag & drop image upload
- Multiple reference images support
- Image grid with selection
- Upload from file browser
### 2. **Enhanced Toolbar**
- Modern glassmorphism design
- Tool selection: Pen, Marker, Eraser
- Color picker with 6 colors
- Adjustable brush size (1-30)
- Undo functionality
- Clear all with confirmation
### 3. **History Panel**
- Visual history states
- Click to restore any previous state
- Up to 30 states stored
### 4. **Improved Drawing**
- Unified pointer events (mouse, touch, pen)
- Smooth stroke rendering
- Pressure-sensitive stylus support (where available)
- Optimized canvas performance
### 5. **Responsive Design**
- Full-screen modal
- Mobile-friendly touch controls
- Adaptive layout
## File Structure
```
templates/
βββ _revision_notes_preact.html # New Preact-based notes modal
βββ question_entry_v2.html # Updated to use new notes
image_routes.py # Added upload endpoint
```
## Routes
### Existing (Unchanged)
- `/save_note_json` - Save annotations
- `/get_note_json/<image_id>` - Load annotations
- `/delete_note` - Delete note
- `/toggle_note_in_pdf` - Include/exclude from PDF
### New
- `/upload_note_reference` - Upload reference images
## Usage
### Opening the Notes Editor
```javascript
openNotesModal(imageId, refImageUrl, sessionId, csrfToken);
```
### Example Button
```html
<button onclick="openNotesModal('{{ image.id }}', '/image/processed/{{ image.processed_filename }}', '{{ session_id }}', '{{ csrf_token() }}')">
<i class="bi bi-pencil"></i> Edit Notes
</button>
```
## Component Architecture
### Main Components
1. **`NotesEditor`** - Main canvas and toolbar
2. **`ToolButton`** - Reusable tool button
3. **`ColorPicker`** - Color selection
4. **`ReferencePanel`** - Image upload & references
5. **`HistoryPanel`** - Undo history
### State Management
Uses Preact hooks (`useState`, `useEffect`, `useCallback`) for reactive state.
## Technical Details
### Canvas Optimization
```javascript
// Will-read-frequently for better performance
const ctx = canvas.getContext('2d', { willReadFrequently: false });
// Smooth rendering
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.imageSmoothingEnabled = true;
```
### Pointer Events
Unified handling for all input types:
```javascript
canvas.onpointerdown = handlePointerDown;
canvas.onpointermove = handlePointerMove;
canvas.onpointerup = handlePointerUp;
```
### Tool Modes
| Tool | Behavior | Opacity |
|------|----------|---------|
| Pen | Solid line | 100% |
| Marker | Thick line | 35% |
| Eraser | Large eraser | 100% |
## Migration from Old System
### Old Code
```html
{% include '_revision_notes.html' %}
<script>
window.openNotesModal = function(id, ref) { ... };
</script>
```
### New Code
```html
{% include '_revision_notes_preact.html' %}
<!-- Global functions automatically available -->
```
## Performance Improvements
1. **Faster rendering** - Preact virtual DOM
2. **Optimized canvas** - Reduced redraws
3. **Lazy loading** - Images loaded on demand
4. **Efficient history** - Max 30 states, auto-cleanup
## Browser Support
- Chrome/Edge (recommended)
- Firefox
- Safari
- Mobile browsers (touch-optimized)
## Future Enhancements
- [ ] Text annotations
- [ ] Shape tools (rectangle, circle, arrow)
- [ ] Freehand highlighter
- [ ] Export annotations as PDF
- [ ] Collaborative editing
- [ ] Voice notes
- [ ] OCR from reference images
## Testing
Test the following scenarios:
1. **Basic Drawing**
- Pen tool with different colors
- Marker transparency
- Eraser functionality
2. **Image Upload**
- Drag & drop
- File browser
- Multiple images
3. **History**
- Undo multiple times
- Restore old states
4. **Save/Load**
- Save annotations
- Reload page
- Verify persistence
5. **Mobile**
- Touch drawing
- Responsive layout
- Reference panel
## Troubleshooting
### Canvas not drawing
- Check browser console for errors
- Verify Preact loaded from CDN
- Ensure container has dimensions
### Images not uploading
- Check file size limits
- Verify TEMP_FOLDER permissions
- Check CSRF token
### History not working
- Ensure saveState() called after each stroke
- Check history array length
## Credits
Built with:
- [Preact](https://preactjs.com/) - Fast 3KB React alternative
- [HTM](https://github.com/developit/htm) - Hyperscript Tagged Markup
- Bootstrap Icons - Icon library
|