feat(figure): add image zoom functionality with multiple modes#1139
Conversation
Fixes AppliedBased on @linawolf's testing feedback, the following issues have been resolved: 🔧 Lightbox (was: "does nothing")
🔧 Gallery (was: "opens empty")
🔧 Lens (was: "looks wrong")
🔧 Inline
✅ Additional Changes
Note: Changes from #1140 are now integrated into this PR. |
|
Happy to see you are working on this, please ping me when you require my review |
Add :zoom: option to figure and image directives supporting four modes:
- lightbox: Click to open full-size in modal dialog overlay
- gallery: Click to open with navigation between grouped images
- inline: Mouse wheel zoom directly on image with pan support
- lens: Magnifying lens follows cursor showing zoomed view
Features:
- :zoom: option accepts lightbox|gallery|inline|lens
- :gallery: option groups images for gallery navigation
- :zoom-indicator: option to show/hide the zoom icon (default: show)
- Zoom indicator with appropriate cursor (zoom-in or crosshair)
- Tooltips on indicators ("Click to enlarge", "Scroll to zoom")
- Click/scroll events pass through indicator to image
- Keyboard accessibility for all zoom modes
- Respects prefers-reduced-motion
- Works with border/shadow styling classes
Technical:
- New FigureDirective.php extending SubDirective
- New image.html.twig template for standalone images
- JavaScript in image-zoom.js bundled into theme.min.js
- CSS in _component_image_zoom.scss imported into theme.scss
6d82fc2 to
9767659
Compare
|
Hi @linawolf, IMO it should be ready now for a review. |
- Remove dead CSS .zoom-enabled class (never used by JS) - Add :zoom-factor: option support for figures (was image-only) - Add zoom value validation (only lightbox|gallery|inline|lens) - Add image load error handling in gallery mode - Rebuild assets with fixes
- Add pinch-to-zoom and touch pan for gallery and inline modes - Add helper functions for pinch gesture detection - Make zoom limits configurable via data attributes: - data-max-zoom: maximum zoom level - data-min-zoom: minimum zoom level - data-zoom-step: zoom increment per scroll - Update FigureDirective docblock with accurate documentation
|
I just tested it as a non-a11y-expert. Really cool to see them accessible. is it also possibel with actual RsT parser to have a automatic rendered thumbnail/image in the normal view and an original image in the lightbox? |
|
I added an integration test. In my eyes we can remove draft status |
|
@josefglatz Good question! Currently the zoom modes use the same image source for both the inline view and the lightbox/gallery. To support separate thumbnail/original images, we'd need to add a new directive option like .. figure:: /images/screenshot-thumbnail.png
:zoom: lightbox
:zoom-src: /images/screenshot-original.png
:alt: Screenshot
Click to see full resolutionThis would be a nice enhancement for a follow-up PR. Would you like to create a feature request issue for it? |
|
To clarify - there are two possible approaches:
The automatic approach would be more user-friendly but requires image processing capabilities in the render pipeline (resizing, caching, output path management). This is likely out of scope for render-guides as it's primarily a documentation renderer, not an image processing tool. For automatic thumbnails, this might be better handled at the infrastructure level (e.g., via a CDN/image service that serves resized versions on-the-fly) rather than in render-guides itself. @linawolf what's your take on this? |
Extend the zoom integration test to cover: - All four zoom modes (lightbox, gallery, inline, lens) - Gallery mode with grouping option - Lens mode with zoom-factor option - Image directive with zoom (not just figure) - zoom-indicator: false option This provides comprehensive test coverage for the image zoom feature.
|
oh, yes, tests, sorry, totally forgot about them 🤦 |
Changes: - Change FigureDirective to extend BaseDirective instead of SubDirective to have full control over option processing - Add CompilerPass to remove base library's FigureDirective during container compilation, ensuring our custom implementation is used - Validate zoom values and set invalid values to null (not remove) so they override raw options during post-processing - Add explicit $startingRule service binding in DI configuration - Add integration test for invalid zoom value validation
|
I would suggest that we first get this PR merged and then deal with different images for preview and the zoom box itself in follow ups. I am not very familiar with how the rendering pipeline actually works so I would be hesistant to change it unless someone really knows what they are doing. New features are nice, but it also means that we have more things we need to maintain and promise for the indefinate future. Also ppl actually using such features are usually quite a small group. So I would prefer a lowtech variant like :zoom-src: /images/screenshot-original.png In such a case we should also link the original picture so it is accessible without javascript |
linawolf
left a comment
There was a problem hiding this comment.
Thanks a lot for these changes
Summary
Add
:zoom:option to figure and image directives supporting four zoom modes:Usage
Features
:zoom:option acceptslightbox|gallery|inline|lens:gallery:option groups images for gallery navigation:zoom-indicator:option to show/hide the zoom icon (default: show)zoom-inorcrosshair)prefers-reduced-motionmedia querywith-borderandwith-shadowstyling classesTechnical Changes
FigureDirective.phpextendingSubDirectiveimage.html.twigtemplate for standalone images with zoomimage-zoom.jsbundled intotheme.min.js_component_image_zoom.scssimported intotheme.scssfigure.html.twigwith zoom data attributesTest plan
:zoom-indicator: falsehides the indicator