Repository navigation
feat(shape): support custom crop shapes - #107
Merged
Merged
Conversation
Accept a CropperShapeDefinition (SVG path + viewBox) as the shape. One geometry drives the on-screen SVG outline, the export mask and the preview clip, so they always match. Custom shapes lock the selection to the viewBox ratio unless stretch is set, default the rectangular outline and grid off, and fall back to rect with a dev warning when invalid. Adds a polygonShape helper. Closes #104
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #107 +/- ##
==========================================
+ Coverage 99.75% 99.80% +0.04%
==========================================
Files 7 9 +2
Lines 831 1041 +210
Branches 144 194 +50
==========================================
+ Hits 829 1039 +210
Misses 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds custom crop shapes:
shapenow also accepts aCropperShapeDefinition(SVGpath+viewBox). One geometry drives the on-screen outline, the export mask and the preview clip, so they cannot drift apart.Changes
CropperShapeDefinition { path, viewBox, stretch? }.viewBoxtakes[minX, minY, w, h]or the SVG string form.maskToPathclips toPath2D(path), mapped by per-axis scale and the viewBox origin, on a fresh canvas. JPEG fill follows the existing rule.ShapeOverlaySVG inside<cropper-selection>:preserveAspectRatio="none",non-scaling-stroke,overflow: visible,pointer-events: none. Stroke themable via--react-cropper-2-shape-stroke.stretch: true. A conflictingaspectRatiowarns in dev.outlinedandgriddefault tofalsefor custom shapes. Explicit props win.rect/circleunchanged.CropperPreviewclips with anobjectBoundingBox<clipPath>, so it scales with the thumbnail.M, or an unusable viewBox, falls back torectwith a dev warning.polygonShape(points)helper.CustomShapestory. README section.Testing
rect/circletests unchanged.Closes #104