Repository navigation
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +1.96 kB (+0.03%) Total Size: 7.75 MB 📦 View Changed
ℹ️ View Unchanged
|
ebf9782 to
21ebbf7
Compare
21ebbf7 to
a181b7c
Compare
77b6aba to
3ed6539
Compare
3c52e83 to
36f5412
Compare
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
andrewserong
left a comment
There was a problem hiding this comment.
Awesome work, I'm loving the direction of this. I think it makes pragmatic sense to include it within the media-editor package so that it's effectively private and we could then hack on creating modals, interfaces, etc, to put it through its paces. It could then eventually graduate to its own package once it's deemed stable / if we think it'd benefit as its own thing (which it really could!)
It's testing well for me in Storybook and I like the overall architecture. As it's a very large PR, I've read through most of the code itself and the readmes, but skipped over reading the tests directly. A few thoughts from the perspective of "could we get this into Gutenberg-proper to keep iterating on building a media editor":
- The camera and Camera type in TS is really just a
mat2d. Can we add a comment elaborating on that in types, or clarify somewhere that it's a 2d camera as 2d vs 3d cameras would use different matrix types? The main reason I mention it is that my naive view in looking at a Camera type, I thought it'd be an object rather than a matrix. - For the recipes / examples doc, I'd drop all non vanilla JS and React examples for now (e.g. Vue)
- Does the lazy loading example in the docs work? My guess is that it won't because I believe Gutenberg packages need to be configured for specific modules to be built in an
"exports"object inpackage.json. So for now, I'd probably drop that example until we look at integrating this in Gutenberg / adding in the lazy loading support.
What else do you think might be tasks to address before proposing this in a Gutenberg PR directly? It's a very comprehensive implementation. Prior to AI coding tools I'd have been a bit nervous about proposing something like this in Gutenberg, but given that image cropping is such an important feature and the fact that 3rd party libraries have varying levels of support, I quite like the idea of this becoming part of the suite of packages in GB / WP.
At the very least, I'm really keen for us to try this out in the media editor (behind an experiment) and where we can always toss it out if it doesn't seem viable.
Nice work again!
Will do. What do you think of that abstraction conceptually? Is it worth keeping the Camera/World/Screen paradigm? |
I'll trim the public API for starters 😄 Get rid of the JSON schemas, add Also some of the stories are probably an overkill, I can remove probably half of them. I'll update the demo image too. I'll do all that so we can reassess. Thank you for going through this large PR! |
|
I've updated and improved a few things. I guess we should squash the commits too. I'll take another, slower look tomorrow. Thanks! |
Yes, I really like camera/world/screen for a few reasons. I think it helps separate the concepts and transformations nicely, but it also opens up scope for this to be expanded into a compositor and not just a cropper. In fact I was wondering if it'd be worth renaming it to |
ec65ea2 to
f0d4a9c
Compare
…not to its siblings (WordPress#77408) Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: coreyworrell <coreyw@git.wordpress.org>
aff52fc to
30a087b
Compare
Introduce an experimental image editor inside @wordpress/media-editor. Provides an interactive image cropping component with pan, zoom, rotate, and flip, plus a pluggable stencil system, JSON-serializable transform pipeline, and browser-based export (Blob / canvas / source region). Architecture: - core/ — framework-agnostic state, math, camera (gl-matrix), export. Pure TypeScript with zero React or DOM dependencies outside of core/export/ (which uses HTMLCanvasElement for rendering). - react/ — thin React adapter: <Cropper>, useCropperState, CropperProvider. Every framework-specific concern lives here. Key invariants: - Preview ↔ export parity: the pixels the user sees inside the stencil are the pixels produced on export. Locked in by a parametric test suite sweeping rotation × zoom × pan × flip × crop × output size. - Viewport-relative flip: flip mirrors across the viewport axes regardless of rotation. - Visual rotation: snapRotate90(+1) and pipeline \`rotate\` ops always rotate the image clockwise on screen, even when a single axis is flipped. - Framing preservation: pan/rotate/flip operations keep the same image content framed inside the stencil. Marked status-experimental in Storybook; exported from the @wordpress/media-editor package root but not yet promoted for wider consumption. See packages/media-editor/src/image-editor/docs/ for architecture, recipes, and roadmap. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
30a087b to
de87cf5
Compare
Remove the image editor barrel re-export from @wordpress/media-editor's public surface. The module is only intended for internal consumers inside the package (via relative paths); it's not ready to be part of the published API. Update README and recipes docs: replace the @wordpress/media-editor import paths with the internal `../image-editor` path, add a "Status: internal" banner to both, and drop the "WordPress integration patterns" and "REST API and media library" sections that implied a public API and external-consumer patterns that don't exist yet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| https://github.com/WordPress/wordpress-develop/pull/11598 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/77408 No newline at end of file |
There was a problem hiding this comment.
Are this and the changes in lib/block-supports/layout.php and phpunit/block-supports/layout-test.php an accidental rebase / merge?
There was a problem hiding this comment.
Whoops, ignore me, I thought I had open https://github.com/WordPress/gutenberg/pull/77479/changes and didn't double-check the url bar... sorry!
There was a problem hiding this comment.
No worries :) This was a booboo (yes accidentally merged)
There was a problem hiding this comment.
Actually, it was just noise. This branch was comparing against my fork's trunk which is stale (this one tracks upstream)
|
Closing in favor of WordPress#77479 |
Summary
A modular image cropper inside
@wordpress/media-editor. Replaces the react-easy-crop wrapper (@wordpress/image-cropper) with a custom implementation built ongl-matrixfor precise 2D transforms.Kapture.2026-04-17.at.14.08.43.mp4
Architecture
Two layers in one package:
core/) — Framework-agnostic pure functions. Zero React dependency.react/) — Thin adapter: hooks wrapping core functions, and components for rendering.Features
onGestureStart/onGestureEndcallbacksTransformOperation[]) for AI agent integrationapplyToCanvas()accepts anyCanvasImageSourcefor multi-step editing pipelinesgetSourceRegion()/getSourceRegionPercent()for server-side processing (FFmpeg, WP REST API)stateFromPipeline()replays operations without DOMStencilPropsinterface.wp-media-editor-image-cropper__*)Public API (26 exports)
React:
Cropper,CropperProvider,useCropper,useCropperStateFunctions:
getSourceRegion,getSourceRegionPercent,exportCroppedImage,applyToCanvas,stateFromPipeline,applyOperationToStateConstants:
DEFAULT_STATE,DEFAULT_ASPECT_RATIOS,ORIGINAL_ASPECT_RATIOTypes:
CropperState,CropperAction,TransformOperation,NormalizedRect,NormalizedPoint,Size,Flip,StencilProps,SourceRegion,SourceRegionPercent,AspectRatioPreset,CropperProps,UseCropperStateReturnNew dependency:
gl-matrixThe cropper uses
gl-matrix(v3) for 2D affine matrix math — specificallymat2d(5 functions) andvec2(2 functions). This provides:mat2dmatrixFloat32Array-backed operationsmat2d+vec2+commonare included;sideEffects: falseenables tree-shaking)The alternative — hand-rolling 2D affine math — would save ~15 KB but introduce maintenance surface for matrix inversion and composition with no user-visible benefit.
Documentation
README.md— Full public API referencedocs/architecture.md— Coordinate spaces, data flow, design decisionsdocs/recipes.md— Getting started, extension points, integration patternsTest coverage
254 unit tests across 5 core test suites:
Test plan
Automated
npx wp-scripts test-unit-js --testPathPattern="image-editor/core/test"— 254 tests passnpx tsc --project tsconfig.json --noEmit— zero errorsStorybook (manual)
Run
npm run storybookand test each story underMediaEditor/ImageEditor:Touch (manual, on mobile/tablet)
Keyboard (manual)
🤖 Generated with Claude Code