@wordpress/media-editor 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/media-editor/index.cjs +212 -170
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +63 -0
- package/build/components/media-editor/use-crop-options.cjs.map +7 -0
- package/build/components/media-editor/use-save-media-editor.cjs +185 -0
- package/build/components/media-editor/use-save-media-editor.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +33 -12
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +70 -84
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs +81 -0
- package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +63 -16
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-transform-controls/index.cjs +84 -0
- package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
- package/build/components/media-form/index.cjs +19 -1
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/components/media-form/sidebar-datetime-view.cjs +53 -0
- package/build/components/media-form/sidebar-datetime-view.cjs.map +7 -0
- package/build/components/rotation-ruler/index.cjs +8 -2
- package/build/components/rotation-ruler/index.cjs.map +2 -2
- package/build/hooks/use-crop-gesture-handlers.cjs +41 -4
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/core/camera.cjs +29 -11
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +6 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +71 -34
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/crop-rect.cjs +48 -0
- package/build/image-editor/core/crop-rect.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +12 -0
- package/build/image-editor/core/index.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs +92 -0
- package/build/image-editor/core/math/sanitize.cjs.map +7 -0
- package/build/image-editor/core/setter-helpers.cjs +64 -0
- package/build/image-editor/core/setter-helpers.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +16 -14
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +20 -10
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/stencil-math.cjs +31 -20
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs +12 -6
- package/build/image-editor/core/transform-style.cjs.map +2 -2
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/index.cjs +12 -2
- package/build/image-editor/index.cjs.map +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +120 -47
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +172 -0
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +19 -9
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +71 -0
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +6 -3
- package/build/image-editor/react/hooks/index.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +113 -0
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +7 -0
- package/build/state/composite-reducer.cjs +103 -0
- package/build/state/composite-reducer.cjs.map +7 -0
- package/build/state/index.cjs +48 -0
- package/build/state/index.cjs.map +7 -0
- package/build/state/media-editor-state-provider.cjs +58 -0
- package/build/state/media-editor-state-provider.cjs.map +7 -0
- package/build/state/types.cjs +33 -0
- package/build/state/types.cjs.map +7 -0
- package/build/state/use-media-editor-state.cjs +287 -0
- package/build/state/use-media-editor-state.cjs.map +7 -0
- package/build/store/actions.cjs +4 -2
- package/build/store/actions.cjs.map +2 -2
- package/build/store/reducer.cjs +5 -3
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +5 -0
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +224 -177
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +37 -0
- package/build-module/components/media-editor/use-crop-options.mjs.map +7 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs +151 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +34 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +73 -89
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +64 -17
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
- package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
- package/build-module/components/media-form/index.mjs +9 -1
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/media-form/sidebar-datetime-view.mjs +32 -0
- package/build-module/components/media-form/sidebar-datetime-view.mjs.map +7 -0
- package/build-module/components/rotation-ruler/index.mjs +8 -2
- package/build-module/components/rotation-ruler/index.mjs.map +2 -2
- package/build-module/hooks/use-crop-gesture-handlers.mjs +41 -4
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/core/camera.mjs +34 -11
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +4 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +75 -34
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/crop-rect.mjs +23 -0
- package/build-module/image-editor/core/crop-rect.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +12 -0
- package/build-module/image-editor/core/index.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs +63 -0
- package/build-module/image-editor/core/math/sanitize.mjs.map +7 -0
- package/build-module/image-editor/core/setter-helpers.mjs +39 -0
- package/build-module/image-editor/core/setter-helpers.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +16 -14
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +25 -11
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/stencil-math.mjs +30 -19
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs +12 -6
- package/build-module/image-editor/core/transform-style.mjs.map +2 -2
- package/build-module/image-editor/index.mjs +11 -2
- package/build-module/image-editor/index.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper-provider.mjs +3 -3
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +121 -48
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +147 -0
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +19 -9
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +46 -0
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +4 -2
- package/build-module/image-editor/react/hooks/index.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +100 -0
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +7 -0
- package/build-module/state/composite-reducer.mjs +82 -0
- package/build-module/state/composite-reducer.mjs.map +7 -0
- package/build-module/state/index.mjs +26 -0
- package/build-module/state/index.mjs.map +7 -0
- package/build-module/state/media-editor-state-provider.mjs +34 -0
- package/build-module/state/media-editor-state-provider.mjs.map +7 -0
- package/build-module/state/types.mjs +8 -0
- package/build-module/state/types.mjs.map +7 -0
- package/build-module/state/use-media-editor-state.mjs +278 -0
- package/build-module/state/use-media-editor-state.mjs.map +7 -0
- package/build-module/store/actions.mjs +4 -2
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/reducer.mjs +5 -3
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +4 -0
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +97 -44
- package/build-style/style.css +97 -44
- package/build-types/components/media-editor/index.d.ts +14 -5
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +35 -0
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts +29 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +5 -10
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +6 -25
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +14 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +13 -14
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +18 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +10 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/crop-rect.d.ts +19 -0
- package/build-types/image-editor/core/crop-rect.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +3 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +5 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +70 -0
- package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -0
- package/build-types/image-editor/core/setter-helpers.d.ts +24 -0
- package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts +12 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +23 -18
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +23 -4
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/index.d.ts +4 -4
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +11 -7
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +6 -4
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +36 -0
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +2 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +47 -0
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +4 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +58 -0
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +39 -0
- package/build-types/state/composite-reducer.d.ts.map +1 -0
- package/build-types/state/index.d.ts +7 -0
- package/build-types/state/index.d.ts.map +1 -0
- package/build-types/state/media-editor-state-provider.d.ts +34 -0
- package/build-types/state/media-editor-state-provider.d.ts.map +1 -0
- package/build-types/state/types.d.ts +96 -0
- package/build-types/state/types.d.ts.map +1 -0
- package/build-types/state/use-media-editor-state.d.ts +101 -0
- package/build-types/state/use-media-editor-state.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +3 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +3 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +1 -0
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +19 -16
- package/src/components/media-editor/index.tsx +262 -229
- package/src/components/media-editor/style.scss +0 -9
- package/src/components/media-editor/test/use-crop-options.tsx +110 -0
- package/src/components/media-editor/use-crop-options.ts +79 -0
- package/src/components/media-editor/use-save-media-editor.ts +214 -0
- package/src/components/media-editor-canvas/index.tsx +57 -25
- package/src/components/media-editor-crop-panel/index.tsx +53 -87
- package/src/components/media-editor-crop-panel/test/index.tsx +46 -53
- package/src/components/media-editor-fine-rotation/index.tsx +74 -0
- package/src/components/media-editor-modal/index.tsx +70 -16
- package/src/components/media-editor-modal/style.scss +80 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +14 -0
- package/src/components/media-editor-modal/test/index.tsx +146 -0
- package/src/components/media-editor-transform-controls/index.tsx +70 -0
- package/src/components/media-editor-transform-controls/style.scss +8 -0
- package/src/components/media-form/index.tsx +15 -1
- package/src/components/media-form/sidebar-datetime-view.tsx +47 -0
- package/src/components/media-form/test/sidebar-datetime-view.test.tsx +96 -0
- package/src/components/rotation-ruler/README.md +11 -25
- package/src/components/rotation-ruler/index.tsx +17 -2
- package/src/components/rotation-ruler/style.scss +49 -13
- package/src/hooks/use-crop-gesture-handlers.ts +64 -17
- package/src/image-editor/README.md +28 -129
- package/src/image-editor/core/camera.ts +51 -26
- package/src/image-editor/core/constants.ts +19 -0
- package/src/image-editor/core/containment.ts +102 -49
- package/src/image-editor/core/crop-rect.ts +45 -0
- package/src/image-editor/core/index.ts +16 -4
- package/src/image-editor/core/interaction-controller.ts +5 -1
- package/src/image-editor/core/math/sanitize.ts +158 -0
- package/src/image-editor/core/math/test/sanitize.ts +244 -0
- package/src/image-editor/core/setter-helpers.ts +66 -0
- package/src/image-editor/core/source-region.ts +21 -14
- package/src/image-editor/core/state.ts +67 -15
- package/src/image-editor/core/stencil-math.ts +55 -35
- package/src/image-editor/core/test/camera.ts +367 -1
- package/src/image-editor/core/test/state.ts +101 -8
- package/src/image-editor/core/test/stencil-math.ts +193 -0
- package/src/image-editor/core/transform-style.ts +21 -6
- package/src/image-editor/core/types.ts +24 -4
- package/src/image-editor/docs/architecture.md +48 -89
- package/src/image-editor/docs/recipes.md +123 -659
- package/src/image-editor/index.ts +12 -3
- package/src/image-editor/react/components/cropper-provider.tsx +16 -12
- package/src/image-editor/react/components/cropper.scss +23 -4
- package/src/image-editor/react/components/cropper.tsx +194 -89
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +269 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +19 -8
- package/src/image-editor/react/components/test/cropper.tsx +55 -13
- package/src/image-editor/react/hooks/build-cropper-setters.ts +105 -0
- package/src/image-editor/react/hooks/index.ts +4 -2
- package/src/image-editor/react/hooks/test/{use-cropper-state.ts → use-cropper-reducer.ts} +142 -286
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +204 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +7 -17
- package/src/state/composite-reducer.ts +137 -0
- package/src/state/index.ts +20 -0
- package/src/state/media-editor-state-provider.tsx +70 -0
- package/src/state/test/use-media-editor-state.ts +330 -0
- package/src/state/types.ts +101 -0
- package/src/state/use-media-editor-state.ts +472 -0
- package/src/store/actions.ts +3 -0
- package/src/store/reducer.ts +6 -1
- package/src/store/selectors.ts +4 -0
- package/src/store/test/reducer.ts +9 -0
- package/src/style.scss +1 -1
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-toolbar/index.cjs +0 -214
- package/build/components/media-editor-toolbar/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-state.cjs +0 -277
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +0 -7
- package/build-module/components/media-editor-toolbar/index.mjs +0 -190
- package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +0 -262
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +0 -7
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -97
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
- package/src/components/media-editor-toolbar/index.tsx +0 -209
- package/src/components/media-editor-toolbar/style.scss +0 -49
- package/src/image-editor/docs/roadmap.md +0 -66
- package/src/image-editor/react/hooks/use-cropper-state.ts +0 -457
|
@@ -8,27 +8,36 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
// React surface.
|
|
11
|
-
export {
|
|
11
|
+
export { useCropperReducer, buildCropperSetters } from './react/hooks';
|
|
12
12
|
export { Cropper, CropperProvider, useCropper } from './react/components';
|
|
13
|
-
export type {
|
|
13
|
+
export type { CropperController, CropperSetters } from './react/hooks';
|
|
14
14
|
export type { CropperProps } from './react/components';
|
|
15
15
|
|
|
16
16
|
// State and extension types.
|
|
17
17
|
export type {
|
|
18
18
|
CropperState,
|
|
19
|
+
CropperAction,
|
|
19
20
|
TransformOperation,
|
|
20
21
|
NormalizedPoint,
|
|
21
22
|
NormalizedRect,
|
|
22
23
|
Size,
|
|
23
24
|
Flip,
|
|
24
25
|
StencilProps,
|
|
26
|
+
HandlePosition,
|
|
25
27
|
} from './core';
|
|
26
28
|
|
|
27
|
-
// Deterministic cropper helpers.
|
|
29
|
+
// Deterministic cropper helpers. The reducer + containment + state
|
|
30
|
+
// equality helpers are exported so consumers can build composite
|
|
31
|
+
// stores that delegate cropper actions (see `useMediaEditorState` for
|
|
32
|
+
// the media editor's composite store).
|
|
28
33
|
export {
|
|
29
34
|
DEFAULT_STATE,
|
|
30
35
|
DEFAULT_ASPECT_RATIOS,
|
|
31
36
|
ORIGINAL_ASPECT_RATIO,
|
|
37
|
+
cropperReducer,
|
|
38
|
+
enforceContainment,
|
|
39
|
+
areCropperStatesEqual,
|
|
40
|
+
computeInscribedRect,
|
|
32
41
|
getSourceRegion,
|
|
33
42
|
getSourceRegionPercent,
|
|
34
43
|
applyOperationToState,
|
|
@@ -7,16 +7,16 @@ import { createContext, useContext } from '@wordpress/element';
|
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
} from '../hooks/use-cropper-
|
|
10
|
+
useCropperReducer,
|
|
11
|
+
type CropperController,
|
|
12
|
+
} from '../hooks/use-cropper-reducer';
|
|
13
13
|
import type { CropperState } from '../../core/types';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The context value type for the CropperProvider.
|
|
17
|
-
* Contains the
|
|
17
|
+
* Contains the cropper controller from useCropperReducer.
|
|
18
18
|
*/
|
|
19
|
-
type CropperContextValue =
|
|
19
|
+
type CropperContextValue = CropperController | null;
|
|
20
20
|
|
|
21
21
|
const CropperContext = createContext< CropperContextValue >( null );
|
|
22
22
|
|
|
@@ -31,12 +31,16 @@ interface CropperProviderProps {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Convenience context provider that wraps
|
|
34
|
+
* Convenience context provider that wraps `useCropperReducer`.
|
|
35
35
|
*
|
|
36
|
-
* Provides the
|
|
37
|
-
* descendant components via React context.
|
|
36
|
+
* Provides the pure cropper controller (state + setters, NO undo
|
|
37
|
+
* history) to all descendant components via React context.
|
|
38
38
|
*
|
|
39
|
-
*
|
|
39
|
+
* History is a higher-layer concern owned by composite stores
|
|
40
|
+
* (see `useMediaEditorState` in media-editor/state for the media
|
|
41
|
+
* editor's composite controller with undo/redo).
|
|
42
|
+
*
|
|
43
|
+
* @param props
|
|
40
44
|
* @param props.initialState
|
|
41
45
|
* @param props.children
|
|
42
46
|
* @return The provider element wrapping children.
|
|
@@ -45,7 +49,7 @@ export function CropperProvider( {
|
|
|
45
49
|
initialState,
|
|
46
50
|
children,
|
|
47
51
|
}: CropperProviderProps ) {
|
|
48
|
-
const cropperReturn =
|
|
52
|
+
const cropperReturn = useCropperReducer( initialState );
|
|
49
53
|
|
|
50
54
|
return (
|
|
51
55
|
<CropperContext.Provider value={ cropperReturn }>
|
|
@@ -60,9 +64,9 @@ export function CropperProvider( {
|
|
|
60
64
|
* Must be used within a CropperProvider. Throws if used outside
|
|
61
65
|
* of the provider tree.
|
|
62
66
|
*
|
|
63
|
-
* @return The cropper
|
|
67
|
+
* @return The cropper controller.
|
|
64
68
|
*/
|
|
65
|
-
export function useCropper():
|
|
69
|
+
export function useCropper(): CropperController {
|
|
66
70
|
const context = useContext( CropperContext );
|
|
67
71
|
|
|
68
72
|
if ( ! context ) {
|
|
@@ -106,6 +106,20 @@ $handle-touch-target-size: 44px;
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
&__dimensions-tooltip {
|
|
110
|
+
position: absolute;
|
|
111
|
+
padding: 2px 6px;
|
|
112
|
+
background: #fff;
|
|
113
|
+
color: #1e1e1e;
|
|
114
|
+
font-size: 11px;
|
|
115
|
+
line-height: 1.4;
|
|
116
|
+
font-variant-numeric: tabular-nums;
|
|
117
|
+
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.08);
|
|
118
|
+
pointer-events: none;
|
|
119
|
+
white-space: nowrap;
|
|
120
|
+
z-index: 2;
|
|
121
|
+
}
|
|
122
|
+
|
|
109
123
|
&__stencil-rect {
|
|
110
124
|
position: absolute;
|
|
111
125
|
border: 1px solid rgba(255, 255, 255, 0.7);
|
|
@@ -117,8 +131,10 @@ $handle-touch-target-size: 44px;
|
|
|
117
131
|
// Blue border on the crop rectangle when the canvas has keyboard focus.
|
|
118
132
|
// Uses a JS-controlled class rather than :focus-visible — browsers can
|
|
119
133
|
// restore :focus-visible across programmatic focus calls, making pure
|
|
120
|
-
// CSS unreliable for pointer-to-keyboard transitions.
|
|
121
|
-
|
|
134
|
+
// CSS unreliable for pointer-to-keyboard transitions. The :focus check
|
|
135
|
+
// on the canvas ensures the outline appears only when the canvas
|
|
136
|
+
// itself is focused, not when focus is on a child handle.
|
|
137
|
+
&__canvas--focus-visible:focus &__stencil-rect {
|
|
122
138
|
border-color: var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
|
|
123
139
|
box-shadow: 0 0 0 1px var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
|
|
124
140
|
}
|
|
@@ -148,8 +164,11 @@ $handle-touch-target-size: 44px;
|
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
// Double ring (white inner + theme-color outer) for legibility
|
|
151
|
-
// over the dark dimming overlay.
|
|
152
|
-
|
|
167
|
+
// over the dark dimming overlay. Gated on the JS-controlled
|
|
168
|
+
// keyboard-active class so that mouse interactions after a
|
|
169
|
+
// keyboard session — e.g., clicking a handle to start a drag —
|
|
170
|
+
// don't leave the active ring stuck on the handle.
|
|
171
|
+
.wp-media-editor-image-editor__canvas--focus-visible &:focus {
|
|
153
172
|
background: var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
|
|
154
173
|
border-color: transparent;
|
|
155
174
|
box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
|
|
@@ -24,64 +24,38 @@ import { __ } from '@wordpress/i18n';
|
|
|
24
24
|
*/
|
|
25
25
|
import type {
|
|
26
26
|
CropperState,
|
|
27
|
+
HandlePosition,
|
|
27
28
|
StencilProps,
|
|
28
29
|
Size,
|
|
29
30
|
NormalizedRect,
|
|
30
31
|
} from '../../core/types';
|
|
31
|
-
import type {
|
|
32
|
-
import { getImageFit } from '../../core/camera';
|
|
33
|
-
import { getImageCropBounds } from '../../core/containment';
|
|
32
|
+
import type { CropperController } from '../hooks/use-cropper-reducer';
|
|
33
|
+
import { getImageFit, getRotatedBBox } from '../../core/camera';
|
|
34
|
+
import { getImageCropBounds, getMinZoom } from '../../core/containment';
|
|
35
|
+
import { MIN_CROP_PIXELS } from '../../core/constants';
|
|
36
|
+
import { computeInscribedRect } from '../../core/crop-rect';
|
|
34
37
|
import { useInteraction } from '../hooks/use-interaction';
|
|
35
38
|
import { useTransformStyle } from '../hooks/use-transform-style';
|
|
36
39
|
import { useAriaAnnouncer } from '../hooks/use-aria-announcer';
|
|
37
40
|
import { RectangleStencil } from './stencils/rectangle-stencil';
|
|
38
41
|
import { DimmingOverlay } from './overlays/dimming-overlay';
|
|
39
42
|
import { GridOverlay } from './overlays/grid-overlay';
|
|
43
|
+
import { DimensionsOverlay } from './overlays/dimensions-overlay';
|
|
44
|
+
import { getSourceRegion } from '../../core/source-region';
|
|
40
45
|
import { ViewportProvider, useViewport } from './viewport-provider';
|
|
41
46
|
import { VISUALLY_HIDDEN_STYLE } from '../visually-hidden-style';
|
|
42
47
|
|
|
43
48
|
/** Threshold for comparing normalized crop rect values. */
|
|
44
49
|
const CROP_RECT_EPSILON = 1e-6;
|
|
45
50
|
|
|
46
|
-
// Largest rect of the given pixel aspect ratio that fits inside the visual
|
|
47
|
-
// bounds, centered in [0,1] × [0,1] normalized space. Returns a full-frame
|
|
48
|
-
// rect (1×1) if `aspectRatio` is unset or non-positive.
|
|
49
|
-
function computeInscribedRect(
|
|
50
|
-
aspectRatio: number | undefined,
|
|
51
|
-
visualSize: Size
|
|
52
|
-
): NormalizedRect {
|
|
53
|
-
let w = 1;
|
|
54
|
-
let h = 1;
|
|
55
|
-
if ( aspectRatio && aspectRatio > 0 && visualSize.width > 0 ) {
|
|
56
|
-
// normalizedRatio = w/h in normalized space that produces the
|
|
57
|
-
// desired pixel aspect ratio.
|
|
58
|
-
// pixelW = w * visualW, pixelH = h * visualH
|
|
59
|
-
// pixelW / pixelH = aspectRatio
|
|
60
|
-
// => w / h = aspectRatio * visualH / visualW
|
|
61
|
-
const normalizedRatio =
|
|
62
|
-
( aspectRatio * visualSize.height ) / visualSize.width;
|
|
63
|
-
if ( normalizedRatio <= 1 ) {
|
|
64
|
-
w = normalizedRatio;
|
|
65
|
-
} else {
|
|
66
|
-
h = 1 / normalizedRatio;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
x: ( 1 - w ) / 2,
|
|
71
|
-
y: ( 1 - h ) / 2,
|
|
72
|
-
width: w,
|
|
73
|
-
height: h,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
51
|
/**
|
|
78
52
|
* Props for the Cropper component.
|
|
79
53
|
*/
|
|
80
54
|
export interface CropperProps {
|
|
81
55
|
/** Image source URL. */
|
|
82
56
|
src: string;
|
|
83
|
-
/** The
|
|
84
|
-
controller:
|
|
57
|
+
/** The cropper controller from `useCropperReducer` or a composite store. */
|
|
58
|
+
controller: CropperController;
|
|
85
59
|
/** Stencil component for the crop area. Defaults to RectangleStencil. */
|
|
86
60
|
stencil?: React.ComponentType< StencilProps >;
|
|
87
61
|
/** Show the rule-of-thirds grid overlay, or only during interactions. */
|
|
@@ -90,7 +64,9 @@ export interface CropperProps {
|
|
|
90
64
|
isPlacementActive?: boolean;
|
|
91
65
|
/** Show the dimming overlay outside the crop area. */
|
|
92
66
|
showDimming?: boolean;
|
|
93
|
-
/**
|
|
67
|
+
/** Show the live output dimensions tooltip during a resize. */
|
|
68
|
+
showDimensions?: boolean;
|
|
69
|
+
/** Minimum zoom level override. Defaults to the coverage-aware minimum. */
|
|
94
70
|
minZoom?: number;
|
|
95
71
|
/** Maximum zoom level. */
|
|
96
72
|
maxZoom?: number;
|
|
@@ -137,12 +113,13 @@ export interface CropperProps {
|
|
|
137
113
|
*
|
|
138
114
|
* @param root0 Component props implementing CropperProps.
|
|
139
115
|
* @param root0.src Image source URL.
|
|
140
|
-
* @param root0.controller The
|
|
116
|
+
* @param root0.controller The cropper controller from `useCropperReducer` or a composite store.
|
|
141
117
|
* @param root0.stencil Custom stencil component.
|
|
142
118
|
* @param root0.showGrid Grid overlay mode: false | true | 'interactive'.
|
|
143
119
|
* @param root0.isPlacementActive Keep grid visible during external placement activity.
|
|
144
120
|
* @param root0.showDimming Show dimming overlay outside crop.
|
|
145
|
-
* @param root0.
|
|
121
|
+
* @param root0.showDimensions Show live dimensions tooltip during resize.
|
|
122
|
+
* @param root0.minZoom Minimum zoom level override.
|
|
146
123
|
* @param root0.maxZoom Maximum zoom level.
|
|
147
124
|
* @param root0.aspectRatio Fixed aspect ratio (width/height).
|
|
148
125
|
* @param root0.freeformCrop Enable resize handles.
|
|
@@ -162,6 +139,7 @@ function CropperInner(
|
|
|
162
139
|
showGrid = false,
|
|
163
140
|
isPlacementActive = false,
|
|
164
141
|
showDimming = true,
|
|
142
|
+
showDimensions = true,
|
|
165
143
|
minZoom,
|
|
166
144
|
maxZoom,
|
|
167
145
|
aspectRatio,
|
|
@@ -175,7 +153,14 @@ function CropperInner(
|
|
|
175
153
|
}: CropperProps,
|
|
176
154
|
ref: React.ForwardedRef< HTMLDivElement >
|
|
177
155
|
) {
|
|
178
|
-
const {
|
|
156
|
+
const {
|
|
157
|
+
state,
|
|
158
|
+
setImage,
|
|
159
|
+
setCropRect,
|
|
160
|
+
settleCrop,
|
|
161
|
+
setVisualSize,
|
|
162
|
+
adjustCropRectForViewport,
|
|
163
|
+
} = controller;
|
|
179
164
|
const {
|
|
180
165
|
viewport: viewportState,
|
|
181
166
|
setViewportPan,
|
|
@@ -202,18 +187,20 @@ function CropperInner(
|
|
|
202
187
|
|
|
203
188
|
const handleCropAreaFocus = useCallback(
|
|
204
189
|
( event: React.FocusEvent< HTMLDivElement > ) => {
|
|
205
|
-
|
|
190
|
+
const target = event.target as HTMLElement;
|
|
191
|
+
if ( target === event.currentTarget ) {
|
|
206
192
|
setIsCropAreaFocused( true );
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
193
|
+
}
|
|
194
|
+
// Show the outline only when focus arrived via keyboard
|
|
195
|
+
// navigation. relatedTarget is null for pointer-initiated and
|
|
196
|
+
// cross-window focus, so it reliably excludes those cases
|
|
197
|
+
// without needing a separate ref or flag. Applies to focus
|
|
198
|
+
// arriving on the canvas itself or on a descendant handle.
|
|
199
|
+
if (
|
|
200
|
+
event.relatedTarget !== null &&
|
|
201
|
+
target.matches( ':focus-visible' )
|
|
202
|
+
) {
|
|
203
|
+
setIsFocusVisible( true );
|
|
217
204
|
}
|
|
218
205
|
},
|
|
219
206
|
[]
|
|
@@ -223,6 +210,15 @@ function CropperInner(
|
|
|
223
210
|
( event: React.FocusEvent< HTMLDivElement > ) => {
|
|
224
211
|
if ( event.target === event.currentTarget ) {
|
|
225
212
|
setIsCropAreaFocused( false );
|
|
213
|
+
}
|
|
214
|
+
// Reset keyboard-active styling only when focus leaves the
|
|
215
|
+
// cropper entirely. Moves between the canvas and a handle (or
|
|
216
|
+
// between handles) keep the keyboard-active state intact.
|
|
217
|
+
if (
|
|
218
|
+
! event.currentTarget.contains(
|
|
219
|
+
event.relatedTarget as Node | null
|
|
220
|
+
)
|
|
221
|
+
) {
|
|
226
222
|
setIsFocusVisible( false );
|
|
227
223
|
}
|
|
228
224
|
},
|
|
@@ -272,9 +268,47 @@ function CropperInner(
|
|
|
272
268
|
[ canvasSize, naturalWidth, naturalHeight, state.rotation ]
|
|
273
269
|
);
|
|
274
270
|
|
|
275
|
-
//
|
|
276
|
-
//
|
|
277
|
-
//
|
|
271
|
+
// Per-axis minimum crop size in normalized space, expressing a
|
|
272
|
+
// pixel floor on the captured source region. cropRect is normalized
|
|
273
|
+
// in the viewport's snap-rotation bbox; the captured source-pixel
|
|
274
|
+
// width is `cropRect.width * bbox.width / zoom`, so the normalized
|
|
275
|
+
// floor scales with `zoom` to keep the source-pixel floor constant.
|
|
276
|
+
// Without this, SETTLE_CROP zooms in proportional to the shrink and
|
|
277
|
+
// successive drags can crop arbitrarily small.
|
|
278
|
+
const minCropSize: Size | undefined = useMemo( () => {
|
|
279
|
+
if ( naturalWidth <= 0 || naturalHeight <= 0 ) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const snapRotation = Math.round( state.rotation / 90 ) * 90;
|
|
283
|
+
const bbox = getRotatedBBox(
|
|
284
|
+
naturalWidth,
|
|
285
|
+
naturalHeight,
|
|
286
|
+
snapRotation
|
|
287
|
+
);
|
|
288
|
+
return {
|
|
289
|
+
width: Math.min( 1, ( MIN_CROP_PIXELS * state.zoom ) / bbox.width ),
|
|
290
|
+
height: Math.min(
|
|
291
|
+
1,
|
|
292
|
+
( MIN_CROP_PIXELS * state.zoom ) / bbox.height
|
|
293
|
+
),
|
|
294
|
+
};
|
|
295
|
+
}, [ naturalWidth, naturalHeight, state.rotation, state.zoom ] );
|
|
296
|
+
|
|
297
|
+
// Report the rendered image size to the controller. Composite
|
|
298
|
+
// controllers need it to compute aspect-ratio reshapes from the
|
|
299
|
+
// reducer (the dropdown dispatches without DOM access); pure
|
|
300
|
+
// controllers ignore it.
|
|
301
|
+
useEffect( () => {
|
|
302
|
+
setVisualSize( visualSize );
|
|
303
|
+
}, [ visualSize, setVisualSize ] );
|
|
304
|
+
|
|
305
|
+
// In fixed-crop mode, auto-size the crop rect only when a fixed
|
|
306
|
+
// aspect ratio is selected. With "Free" selected, turning freeform
|
|
307
|
+
// handles off should preserve the user's current unconstrained
|
|
308
|
+
// crop. Uses `adjustCropRectForViewport` so window-resize-driven
|
|
309
|
+
// reshapes don't create undo entries (composite controller); the
|
|
310
|
+
// dedup at lines below avoids redundant dispatches when the
|
|
311
|
+
// reducer has already updated the cropRect for an aspect change.
|
|
278
312
|
useEffect( () => {
|
|
279
313
|
if (
|
|
280
314
|
freeformCrop ||
|
|
@@ -295,11 +329,20 @@ function CropperInner(
|
|
|
295
329
|
) {
|
|
296
330
|
return;
|
|
297
331
|
}
|
|
298
|
-
|
|
299
|
-
}, [
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
332
|
+
adjustCropRectForViewport( rect );
|
|
333
|
+
}, [
|
|
334
|
+
freeformCrop,
|
|
335
|
+
aspectRatio,
|
|
336
|
+
visualSize,
|
|
337
|
+
adjustCropRectForViewport,
|
|
338
|
+
state.cropRect,
|
|
339
|
+
] );
|
|
340
|
+
|
|
341
|
+
// In freeform mode, when aspectRatio changes, reshape the crop to
|
|
342
|
+
// the largest inscribed rect of the new ratio. Bails out when the
|
|
343
|
+
// cropRect already matches the inscribed rect — composite stores
|
|
344
|
+
// reshape atomically inside the reducer, so this effect is a
|
|
345
|
+
// no-op there.
|
|
303
346
|
const prevAspectRatioRef = useRef( aspectRatio );
|
|
304
347
|
useEffect( () => {
|
|
305
348
|
if ( prevAspectRatioRef.current === aspectRatio ) {
|
|
@@ -316,8 +359,24 @@ function CropperInner(
|
|
|
316
359
|
) {
|
|
317
360
|
return;
|
|
318
361
|
}
|
|
319
|
-
|
|
320
|
-
|
|
362
|
+
const rect = computeInscribedRect( aspectRatio, visualSize );
|
|
363
|
+
const current = state.cropRect;
|
|
364
|
+
if (
|
|
365
|
+
Math.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&
|
|
366
|
+
Math.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&
|
|
367
|
+
Math.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&
|
|
368
|
+
Math.abs( current.height - rect.height ) < CROP_RECT_EPSILON
|
|
369
|
+
) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
adjustCropRectForViewport( rect );
|
|
373
|
+
}, [
|
|
374
|
+
aspectRatio,
|
|
375
|
+
freeformCrop,
|
|
376
|
+
visualSize,
|
|
377
|
+
adjustCropRectForViewport,
|
|
378
|
+
state.cropRect,
|
|
379
|
+
] );
|
|
321
380
|
|
|
322
381
|
// Compute the crop handle bounds from the actual image footprint.
|
|
323
382
|
// Depends on the full state object because getImageCropBounds reads
|
|
@@ -330,9 +389,17 @@ function CropperInner(
|
|
|
330
389
|
}
|
|
331
390
|
return getImageCropBounds( state, elementSize, visualSize );
|
|
332
391
|
}, [ state, elementSize, visualSize ] );
|
|
392
|
+
const effectiveMinZoom =
|
|
393
|
+
minZoom !== undefined ? minZoom : getMinZoom( state );
|
|
333
394
|
const [ isResizing, setIsResizing ] = useState( false );
|
|
334
395
|
const isResizingRef = useRef( false );
|
|
335
396
|
const isSettlingRef = useRef( false );
|
|
397
|
+
// Direction of the handle the user is currently resizing — pointer or
|
|
398
|
+
// keyboard. `null` outside of an active resize. Drives the live
|
|
399
|
+
// dimensions tooltip overlay.
|
|
400
|
+
const [ activeHandle, setActiveHandle ] = useState< HandlePosition | null >(
|
|
401
|
+
null
|
|
402
|
+
);
|
|
336
403
|
|
|
337
404
|
// Use the interaction hook for mouse, touch, and keyboard events.
|
|
338
405
|
const {
|
|
@@ -342,7 +409,7 @@ function CropperInner(
|
|
|
342
409
|
isZooming,
|
|
343
410
|
isPlacementActive: isInteractionPlacementActive,
|
|
344
411
|
} = useInteraction( state, controller, canvasSize, visualSize, {
|
|
345
|
-
minZoom,
|
|
412
|
+
minZoom: effectiveMinZoom,
|
|
346
413
|
maxZoom,
|
|
347
414
|
onGestureStart,
|
|
348
415
|
onGestureEnd,
|
|
@@ -351,27 +418,31 @@ function CropperInner(
|
|
|
351
418
|
// Compose focus-visibility tracking into the canvas event handlers.
|
|
352
419
|
// Kept as a spread rather than explicit props to avoid triggering
|
|
353
420
|
// jsx-a11y/no-noninteractive-element-interactions on role="group".
|
|
421
|
+
//
|
|
422
|
+
// The pointer/key tracking lives in the capture phase so it runs
|
|
423
|
+
// before any child handler — handles call stopPropagation in their
|
|
424
|
+
// own onPointerDown / onKeyDown, which would otherwise prevent the
|
|
425
|
+
// keyboard-active state from updating when the user interacts with
|
|
426
|
+
// a handle directly.
|
|
354
427
|
const canvasHandlers = {
|
|
355
428
|
...handlers,
|
|
356
|
-
|
|
357
|
-
handlers.onPointerDown?.( event );
|
|
358
|
-
// Called after handlers so it lands last in the React batch —
|
|
359
|
-
// el.focus() inside the handler fires onFocus, which may
|
|
360
|
-
// otherwise set isFocusVisible back to true.
|
|
429
|
+
onPointerDownCapture: () => {
|
|
361
430
|
setIsFocusVisible( false );
|
|
362
431
|
},
|
|
363
|
-
|
|
364
|
-
//
|
|
365
|
-
//
|
|
366
|
-
// keypresses are excluded — they precede another key rather
|
|
367
|
-
// than indicating deliberate keyboard interaction on their own.
|
|
432
|
+
onKeyDownCapture: ( event: React.KeyboardEvent< HTMLDivElement > ) => {
|
|
433
|
+
// Modifier-only keypresses precede another key rather than
|
|
434
|
+
// indicating deliberate keyboard interaction on their own.
|
|
368
435
|
if (
|
|
369
|
-
event.target === event.currentTarget &&
|
|
370
436
|
! [ 'Shift', 'Control', 'Alt', 'Meta' ].includes( event.key )
|
|
371
437
|
) {
|
|
372
438
|
setIsFocusVisible( true );
|
|
373
439
|
}
|
|
374
|
-
|
|
440
|
+
},
|
|
441
|
+
onPointerDown: ( event: React.PointerEvent< HTMLDivElement > ) => {
|
|
442
|
+
handlers.onPointerDown?.( event );
|
|
443
|
+
// Re-assert false after handlers run — el.focus() inside the
|
|
444
|
+
// handler fires onFocus, which may otherwise set it back to true.
|
|
445
|
+
setIsFocusVisible( false );
|
|
375
446
|
},
|
|
376
447
|
};
|
|
377
448
|
|
|
@@ -485,6 +556,20 @@ function CropperInner(
|
|
|
485
556
|
isInteractiveGrid &&
|
|
486
557
|
( isInteractionPlacementActive || isResizing || isPlacementActive );
|
|
487
558
|
|
|
559
|
+
// Output crop size in source pixels — drives the live tooltip
|
|
560
|
+
// overlay. Only computed during pointer drags, so the per-frame
|
|
561
|
+
// state churn during pan/zoom doesn't pay for it.
|
|
562
|
+
const outputSize = useMemo( () => {
|
|
563
|
+
if ( ! showDimensions || ! activeHandle || ! state.image ) {
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
const region = getSourceRegion( state, {
|
|
567
|
+
width: state.image.naturalWidth,
|
|
568
|
+
height: state.image.naturalHeight,
|
|
569
|
+
} );
|
|
570
|
+
return { width: region.width, height: region.height };
|
|
571
|
+
}, [ showDimensions, activeHandle, state ] );
|
|
572
|
+
|
|
488
573
|
/**
|
|
489
574
|
* Handle Escape on a resize handle — return focus to the canvas so
|
|
490
575
|
* arrow keys pan the image rather than resize.
|
|
@@ -496,18 +581,22 @@ function CropperInner(
|
|
|
496
581
|
canvasRef.current?.focus( { preventScroll: true } );
|
|
497
582
|
}, [] );
|
|
498
583
|
|
|
499
|
-
const handleResizeStart = useCallback(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
584
|
+
const handleResizeStart = useCallback(
|
|
585
|
+
( handle?: HandlePosition ) => {
|
|
586
|
+
isResizingRef.current = true;
|
|
587
|
+
setIsResizing( true );
|
|
588
|
+
setActiveHandle( handle ?? null );
|
|
589
|
+
// Clear any in-flight settle so transitions don't apply during the
|
|
590
|
+
// new drag (rapid successive resizes would otherwise inherit the
|
|
591
|
+
// previous settle animation).
|
|
592
|
+
clearTimeout( settleTimerRef.current );
|
|
593
|
+
isSettlingRef.current = false;
|
|
594
|
+
setSettling( false );
|
|
595
|
+
resetViewport();
|
|
596
|
+
onGestureStart?.();
|
|
597
|
+
},
|
|
598
|
+
[ onGestureStart, resetViewport ]
|
|
599
|
+
);
|
|
511
600
|
|
|
512
601
|
/**
|
|
513
602
|
* Handle resize end — settle the crop rect (re-center, fill height)
|
|
@@ -516,6 +605,7 @@ function CropperInner(
|
|
|
516
605
|
const handleResizeEnd = useCallback( () => {
|
|
517
606
|
isResizingRef.current = false;
|
|
518
607
|
setIsResizing( false );
|
|
608
|
+
setActiveHandle( null );
|
|
519
609
|
isSettlingRef.current = true;
|
|
520
610
|
setSettling( true );
|
|
521
611
|
// Reset viewport pan first so it transitions back to zero in sync
|
|
@@ -622,10 +712,12 @@ function CropperInner(
|
|
|
622
712
|
'wp-media-editor-image-editor__canvas--show-grid',
|
|
623
713
|
settling &&
|
|
624
714
|
'wp-media-editor-image-editor__canvas--settling',
|
|
625
|
-
//
|
|
626
|
-
//
|
|
715
|
+
// Marks the cropper as in keyboard-interaction mode.
|
|
716
|
+
// CSS uses :focus on the canvas to show the stencil
|
|
717
|
+
// outline and :focus on a handle to show its ring,
|
|
718
|
+
// so the class applies whenever any cropper element
|
|
719
|
+
// has keyboard focus.
|
|
627
720
|
isFocusVisible &&
|
|
628
|
-
isCropAreaFocused &&
|
|
629
721
|
'wp-media-editor-image-editor__canvas--focus-visible'
|
|
630
722
|
) }
|
|
631
723
|
tabIndex={ 0 }
|
|
@@ -691,6 +783,7 @@ function CropperInner(
|
|
|
691
783
|
freeformCrop={ freeformCrop }
|
|
692
784
|
stencilTransition={ settleStencilTransition }
|
|
693
785
|
cropBounds={ cropBounds }
|
|
786
|
+
minCropSize={ minCropSize }
|
|
694
787
|
/>
|
|
695
788
|
|
|
696
789
|
{ /* Rule-of-thirds grid */ }
|
|
@@ -701,6 +794,18 @@ function CropperInner(
|
|
|
701
794
|
imageSize={ visualSize }
|
|
702
795
|
/>
|
|
703
796
|
) }
|
|
797
|
+
|
|
798
|
+
{ /* Live dimensions tooltip pinned to the dragged handle. */ }
|
|
799
|
+
{ activeHandle && outputSize && (
|
|
800
|
+
<DimensionsOverlay
|
|
801
|
+
cropRect={ state.cropRect }
|
|
802
|
+
containerSize={ canvasSize }
|
|
803
|
+
imageSize={ visualSize }
|
|
804
|
+
activeHandle={ activeHandle }
|
|
805
|
+
outputWidth={ outputSize.width }
|
|
806
|
+
outputHeight={ outputSize.height }
|
|
807
|
+
/>
|
|
808
|
+
) }
|
|
704
809
|
</div>
|
|
705
810
|
|
|
706
811
|
{ /* ARIA live region for screen reader announcements */ }
|