Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a util for image zoom #48

Merged
merged 1 commit into from
Mar 17, 2025
Merged

feat: Add a util for image zoom #48

merged 1 commit into from
Mar 17, 2025

Conversation

iamsivin
Copy link
Member

@iamsivin iamsivin commented Mar 17, 2025

Image Zoom and Rotation Helpers

This PR adds three utility functions for handling image zoom and rotation based on cursor position. Ref: chatwoot/chatwoot#11040

Key Features:

  1. calculateCenterOffset: Calculates the relative position of the cursor from the center of an image element. This helps establish the reference point for zooming operations.

  2. applyRotationTransform: Applies a rotation matrix to coordinates, allowing adjustments to mouse coordinates based on the current rotation angle of the image. This ensures zoom operations work correctly even when the image is rotated.

  3. normalizeToPercentage: Converts the calculated rotated coordinates to percentage values (0-100%) relative to the image dimensions. These values are used for CSS transform-origin properties.

Use Cases:

  • Double-click zooming that centers on the mouse cursor position
  • Maintaining proper zoom origin point when the image is rotated
  • Providing natural zoom behavior that follows the user's cursor

Copy link

size-limit report 📦

Path Size
dist/utils.cjs.production.min.js 6.98 KB (+2.59% 🔺)
dist/utils.esm.js 6.4 KB (+2.27% 🔺)

@iamsivin iamsivin requested a review from scmmishra March 17, 2025 09:03
@scmmishra scmmishra merged commit 04ffd6b into main Mar 17, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants