@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
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback, useEffect, useRef } from '@wordpress/element';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Internal dependencies
|
|
3
8
|
*/
|
|
4
|
-
import {
|
|
9
|
+
import { useMediaEditor } from '../state';
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Data attribute applied to crop control wrappers. The modal's keyboard
|
|
@@ -11,27 +16,26 @@ import { useCropper } from '../image-editor';
|
|
|
11
16
|
*/
|
|
12
17
|
export const CROP_CONTROL_ATTR = 'data-crop-control';
|
|
13
18
|
|
|
19
|
+
/** Idle window used to group repeated keyboard input into one gesture. */
|
|
20
|
+
const KEYBOARD_GESTURE_IDLE_MS = 300;
|
|
21
|
+
|
|
14
22
|
export interface UseCropGestureHandlersOptions {
|
|
15
23
|
/**
|
|
16
|
-
* When `true` (default), key-up
|
|
17
|
-
*
|
|
24
|
+
* When `true` (default), key-up closes the gesture so each
|
|
25
|
+
* discrete keypress becomes its own undo step. Set to `false` for
|
|
18
26
|
* continuous-input controls (e.g. the rotation ruler) where rapid
|
|
19
|
-
* keypresses should coalesce into a single history entry
|
|
20
|
-
*
|
|
27
|
+
* keypresses should coalesce into a single history entry across
|
|
28
|
+
* the whole gesture.
|
|
21
29
|
*/
|
|
22
30
|
commitOnKeyUp?: boolean;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* so the modal's Cmd+Z handler can identify it, and wires
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* expire.
|
|
32
|
-
*
|
|
33
|
-
* The history entry itself is recorded by the state-change debounce in
|
|
34
|
-
* `useCropperState` — no explicit gesture-start signal is needed.
|
|
34
|
+
* Event handler props to spread onto a wrapper element around a crop
|
|
35
|
+
* control. Marks the wrapper as a crop control (via `data-crop-control`)
|
|
36
|
+
* so the modal's Cmd+Z handler can identify it, and wires gesture
|
|
37
|
+
* boundaries on the composite store so a slider drag becomes a single
|
|
38
|
+
* undo entry rather than one per tick.
|
|
35
39
|
*
|
|
36
40
|
* Usage:
|
|
37
41
|
* const gestureHandlers = useCropGestureHandlers();
|
|
@@ -45,10 +49,53 @@ export function useCropGestureHandlers(
|
|
|
45
49
|
options: UseCropGestureHandlersOptions = {}
|
|
46
50
|
) {
|
|
47
51
|
const { commitOnKeyUp = true } = options;
|
|
48
|
-
const {
|
|
52
|
+
const { beginGesture, endGesture } = useMediaEditor();
|
|
53
|
+
const keyboardTimerRef = useRef< ReturnType< typeof setTimeout > >();
|
|
54
|
+
|
|
55
|
+
const clearKeyboardTimer = useCallback( () => {
|
|
56
|
+
clearTimeout( keyboardTimerRef.current );
|
|
57
|
+
}, [] );
|
|
58
|
+
|
|
59
|
+
const scheduleKeyboardEnd = useCallback( () => {
|
|
60
|
+
clearKeyboardTimer();
|
|
61
|
+
keyboardTimerRef.current = setTimeout( () => {
|
|
62
|
+
endGesture();
|
|
63
|
+
}, KEYBOARD_GESTURE_IDLE_MS );
|
|
64
|
+
}, [ clearKeyboardTimer, endGesture ] );
|
|
65
|
+
|
|
66
|
+
useEffect( () => clearKeyboardTimer, [ clearKeyboardTimer ] );
|
|
67
|
+
|
|
68
|
+
const handlePointerDownCapture = useCallback( () => {
|
|
69
|
+
clearKeyboardTimer();
|
|
70
|
+
beginGesture();
|
|
71
|
+
}, [ beginGesture, clearKeyboardTimer ] );
|
|
72
|
+
|
|
73
|
+
const handlePointerEnd = useCallback( () => {
|
|
74
|
+
clearKeyboardTimer();
|
|
75
|
+
endGesture();
|
|
76
|
+
}, [ clearKeyboardTimer, endGesture ] );
|
|
77
|
+
|
|
78
|
+
const handleKeyDownCapture = useCallback( () => {
|
|
79
|
+
beginGesture();
|
|
80
|
+
if ( ! commitOnKeyUp ) {
|
|
81
|
+
scheduleKeyboardEnd();
|
|
82
|
+
}
|
|
83
|
+
}, [ beginGesture, commitOnKeyUp, scheduleKeyboardEnd ] );
|
|
84
|
+
|
|
85
|
+
const handleKeyUp = useCallback( () => {
|
|
86
|
+
if ( commitOnKeyUp ) {
|
|
87
|
+
endGesture();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
scheduleKeyboardEnd();
|
|
91
|
+
}, [ commitOnKeyUp, endGesture, scheduleKeyboardEnd ] );
|
|
92
|
+
|
|
49
93
|
return {
|
|
50
94
|
[ CROP_CONTROL_ATTR ]: true,
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
onPointerDownCapture: handlePointerDownCapture,
|
|
96
|
+
onPointerUp: handlePointerEnd,
|
|
97
|
+
onPointerCancel: handlePointerEnd,
|
|
98
|
+
onKeyDownCapture: handleKeyDownCapture,
|
|
99
|
+
onKeyUp: handleKeyUp,
|
|
53
100
|
};
|
|
54
101
|
}
|
|
@@ -1,162 +1,61 @@
|
|
|
1
1
|
# Image Editor
|
|
2
2
|
|
|
3
|
-
> **Status: internal.** This module is not
|
|
3
|
+
> **Status: internal.** This module is not part of `@wordpress/media-editor`'s public API. Import it only from inside the media-editor package, through the local `../image-editor` barrel.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The image editor is the cropper engine used by the media editor:
|
|
6
6
|
|
|
7
|
-
- **Core
|
|
8
|
-
- **React
|
|
7
|
+
- **Core:** state, camera math, containment, source-region, transforms, and canvas export.
|
|
8
|
+
- **React:** `<Cropper>`, `useCropperReducer`, and the optional `CropperProvider` / `useCropper` context wrapper.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
`useCropperReducer` does not provide undo/redo. The media editor's composite state layer adds history and sidebar crop options on top of the cropper reducer.
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
11
13
|
|
|
12
14
|
```tsx
|
|
13
|
-
import { Cropper,
|
|
15
|
+
import { Cropper, useCropperReducer } from '../image-editor';
|
|
16
|
+
|
|
17
|
+
function ImageCropper() {
|
|
18
|
+
const controller = useCropperReducer();
|
|
14
19
|
|
|
15
|
-
function ImageEditor() {
|
|
16
|
-
const controller = useCropperState();
|
|
17
20
|
return (
|
|
18
21
|
<div style={ { width: 600, height: 400 } }>
|
|
19
22
|
<Cropper
|
|
20
23
|
src="https://example.com/photo.jpg"
|
|
21
24
|
controller={ controller }
|
|
22
|
-
showDimming
|
|
23
|
-
showGrid
|
|
24
25
|
freeformCrop
|
|
26
|
+
showDimming
|
|
27
|
+
showGrid="interactive"
|
|
25
28
|
/>
|
|
26
29
|
</div>
|
|
27
30
|
);
|
|
28
31
|
}
|
|
29
32
|
```
|
|
30
33
|
|
|
31
|
-
`
|
|
32
|
-
|
|
33
|
-
## Styles
|
|
34
|
-
|
|
35
|
-
The cropper's styles are compiled as part of `@wordpress/media-editor`'s SCSS build. Internal callers that render `<Cropper>` inherit them automatically when the package's stylesheet is loaded. All CSS classes use the `wp-media-editor-image-editor` prefix.
|
|
36
|
-
|
|
37
|
-
## Docs
|
|
38
|
-
|
|
39
|
-
- [docs/architecture.md](docs/architecture.md) — Data flow, coordinate spaces, and design decisions
|
|
40
|
-
- [docs/recipes.md](docs/recipes.md) — Getting started walkthrough, extension points, and integration patterns
|
|
41
|
-
- [docs/roadmap.md](docs/roadmap.md) — Planned follow-up work and phases
|
|
42
|
-
|
|
43
|
-
## API Reference
|
|
44
|
-
|
|
45
|
-
### React components
|
|
46
|
-
|
|
47
|
-
#### `Cropper`
|
|
48
|
-
|
|
49
|
-
Main cropper component. Fills its parent container.
|
|
50
|
-
|
|
51
|
-
| Prop | Type | Default | Description |
|
|
52
|
-
| ---------------- | ------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
53
|
-
| `src` | `string` | **required** | Image source URL |
|
|
54
|
-
| `controller` | `UseCropperStateReturn` | **required** | The full object returned by `useCropperState()` |
|
|
55
|
-
| `stencil` | `ComponentType<StencilProps>` | `RectangleStencil` | Custom crop area UI |
|
|
56
|
-
| `showGrid` | `boolean` | `false` | Rule-of-thirds grid overlay |
|
|
57
|
-
| `showDimming` | `boolean` | `true` | Dimming overlay outside crop |
|
|
58
|
-
| `minZoom` | `number` | `1` | Minimum zoom for interactive gestures (wheel, pinch, double-tap). The reducer itself clamps to `[1, 10]` regardless, so a larger `minZoom` only narrows what the user can reach through gestures. |
|
|
59
|
-
| `maxZoom` | `number` | `10` | Maximum zoom for interactive gestures. Same caveat as `minZoom`. |
|
|
60
|
-
| `aspectRatio` | `number` | — | Fixed aspect ratio (width/height) |
|
|
61
|
-
| `freeformCrop` | `boolean` | `false` | Enable resize handles |
|
|
62
|
-
| `onImageLoaded` | `(size: Size) => void` | — | Image load callback |
|
|
63
|
-
| `onStateChange` | `(state: CropperState) => void` | — | Fires on every state change (high frequency — at pointermove rate during drags). Avoid heavy work in the handler; for commit-style events use `onGestureEnd` instead. |
|
|
64
|
-
| `onGestureStart` | `() => void` | — | Gesture boundary start |
|
|
65
|
-
| `onGestureEnd` | `() => void` | — | Gesture boundary end |
|
|
66
|
-
| `className` | `string` | — | Additional CSS class |
|
|
67
|
-
|
|
68
|
-
#### `CropperProvider` / `useCropper()`
|
|
69
|
-
|
|
70
|
-
Context wrapper for deep component trees. Wraps `useCropperState` and provides it to descendants via `useCropper()`.
|
|
71
|
-
|
|
72
|
-
### React hooks
|
|
34
|
+
`useCropperReducer` returns a controller object with the current `state`, named setters, `reset`, `isDirty`, and `getCroppedImage`.
|
|
73
35
|
|
|
74
|
-
|
|
36
|
+
## Internal APIs
|
|
75
37
|
|
|
76
|
-
|
|
38
|
+
### `Cropper`
|
|
77
39
|
|
|
78
|
-
|
|
40
|
+
Fills its parent container. Required props are `src` and `controller`. Common options include `freeformCrop`, `aspectRatio`, `showGrid`, `showDimming`, `showDimensions`, `onGestureStart`, and `onGestureEnd`.
|
|
79
41
|
|
|
80
|
-
|
|
81
|
-
| ----------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
82
|
-
| `state` | `CropperState` | Current state (read-only) |
|
|
83
|
-
| `setImage` | `(image: CropperState['image']) => void` | Set the loaded image (src + natural size) |
|
|
84
|
-
| `setPan` | `(pan: NormalizedPoint) => void` | Set image pan offset |
|
|
85
|
-
| `setZoom` | `(zoom: number) => void` | Set zoom (clamped 1–10) |
|
|
86
|
-
| `setZoomAtPoint` | `(zoom: number, pan: NormalizedPoint) => void` | Set zoom and pan together for focal-point zoom |
|
|
87
|
-
| `setRotation` | `(degrees: number) => void` | Set rotation (normalized 0–360) |
|
|
88
|
-
| `setFlip` | `(flip: Flip) => void` | Set flip state |
|
|
89
|
-
| `snapRotate90` | `(direction: 1 \| -1) => void` | 90° snap rotation |
|
|
90
|
-
| `setCropRect` | `(rect: NormalizedRect) => void` | Set crop rectangle |
|
|
91
|
-
| `settleCrop` | `() => void` | Settle the crop rect after a resize drag (typically from `onResizeEnd`) |
|
|
92
|
-
| `applyOperation` | `(op: TransformOperation) => void` | Apply a pipeline operation |
|
|
93
|
-
| `reset` | `(state?: Partial<CropperState>) => void` | Reset to initial or given state |
|
|
94
|
-
| `isDirty` | `boolean` | Whether state differs from initial |
|
|
95
|
-
| `getCroppedImage` | `(mime?: string, quality?: number) => Promise<Blob>` | Export as Blob. Throws on load/CORS/context failure — wrap in try/catch to recover. |
|
|
42
|
+
### `useCropperReducer( initialState? )`
|
|
96
43
|
|
|
97
|
-
|
|
44
|
+
Pure React state hook for the cropper reducer. Returns a `CropperController`: current state, named setters, `reset`, `isDirty`, and `getCroppedImage`.
|
|
98
45
|
|
|
99
|
-
###
|
|
46
|
+
### `CropperProvider` / `useCropper`
|
|
100
47
|
|
|
101
|
-
|
|
48
|
+
Convenience context wrapper around `useCropperReducer` for component trees that need shared cropper state.
|
|
102
49
|
|
|
103
|
-
|
|
50
|
+
## Core Helpers
|
|
104
51
|
|
|
105
|
-
|
|
52
|
+
The local barrel also exposes helpers for reducer composition, source-region calculation, pipeline replay, and canvas export. Use named setters or `TransformOperation` values for normal state changes. Use reducer actions only when composing a controller such as `useMediaEditorState()`.
|
|
106
53
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
### Export
|
|
110
|
-
|
|
111
|
-
#### `exportCroppedImage( src, state, mimeType?, quality? ): Promise<Blob>`
|
|
112
|
-
|
|
113
|
-
End-to-end: load image, render with transforms, export as Blob. Browser-only (needs `HTMLCanvasElement`).
|
|
114
|
-
|
|
115
|
-
Rejects on:
|
|
116
|
-
|
|
117
|
-
- **Image load failures** (network error, 404) — the native load error is propagated.
|
|
118
|
-
- **CORS / tainted canvas** — if the source doesn't set `Access-Control-Allow-Origin`, `canvas.toBlob()` rejects because the canvas is tainted. Fix at the server: send permissive CORS headers.
|
|
119
|
-
- **Missing canvas context** — throws with a descriptive `Error`.
|
|
120
|
-
|
|
121
|
-
Wrap in `try/catch` to distinguish failure modes.
|
|
122
|
-
|
|
123
|
-
#### `applyToCanvas( source: CanvasImageSource, imageSize, state ): HTMLCanvasElement`
|
|
124
|
-
|
|
125
|
-
Applies transforms to any `CanvasImageSource` (image, canvas, video frame, offscreen canvas). For multi-step editing pipelines.
|
|
126
|
-
|
|
127
|
-
### Pipeline
|
|
128
|
-
|
|
129
|
-
#### `stateFromPipeline( operations: TransformOperation[] ): CropperState`
|
|
130
|
-
|
|
131
|
-
Replays a sequence of operations from default state. Pure function, no DOM needed. For headless/server-side processing.
|
|
132
|
-
|
|
133
|
-
#### `applyOperationToState( state, operation ): CropperState`
|
|
134
|
-
|
|
135
|
-
Applies a single operation to an existing state.
|
|
136
|
-
|
|
137
|
-
### Types
|
|
138
|
-
|
|
139
|
-
| Type | Description |
|
|
140
|
-
| ----------------------- | --------------------------------------------------------------------------------- |
|
|
141
|
-
| `CropperState` | `{ image, pan, zoom, rotation, flip, cropRect, basePan, baseZoom, baseRotation }` |
|
|
142
|
-
| `UseCropperStateReturn` | The full shape returned by `useCropperState()`: state + setters |
|
|
143
|
-
| `CropperProps` | Props for the `<Cropper>` component |
|
|
144
|
-
| `StencilProps` | Contract for pluggable stencil components |
|
|
145
|
-
| `TransformOperation` | `{ type: 'crop' \| 'rotate' \| 'flip' \| 'zoom', ... }` |
|
|
146
|
-
| `NormalizedPoint` | `{ x: number, y: number }` in [0,1] space |
|
|
147
|
-
| `NormalizedRect` | `{ x, y, width, height }` in [0,1] space |
|
|
148
|
-
| `Size` | `{ width: number, height: number }` |
|
|
149
|
-
| `Flip` | `{ horizontal: boolean, vertical: boolean }` |
|
|
150
|
-
| `SourceRegion` | `{ x, y, width, height, rotation, flip, zoom }` in source pixels |
|
|
151
|
-
| `SourceRegionPercent` | `{ x, y, width, height }` as percentages (0–100) |
|
|
152
|
-
| `AspectRatioPreset` | `{ label: string, value: number }` |
|
|
54
|
+
## Styles
|
|
153
55
|
|
|
154
|
-
|
|
56
|
+
Styles are bundled through the media-editor stylesheet. Classes use the `wp-media-editor-image-editor` prefix.
|
|
155
57
|
|
|
156
|
-
|
|
58
|
+
## More
|
|
157
59
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
| `DEFAULT_STATE` | — | Default `CropperState` |
|
|
161
|
-
| `DEFAULT_ASPECT_RATIOS` | Array | Preset aspect ratios (Free, Original, 1:1, 16:9, etc.) |
|
|
162
|
-
| `ORIGINAL_ASPECT_RATIO` | `-1` | Sentinel value for "use image's original ratio" |
|
|
60
|
+
- [docs/architecture.md](docs/architecture.md)
|
|
61
|
+
- [docs/recipes.md](docs/recipes.md)
|
|
@@ -8,6 +8,12 @@ import { mat2d, vec2 } from 'gl-matrix';
|
|
|
8
8
|
*/
|
|
9
9
|
import type { CropperState, NormalizedPoint, Size, Camera } from './types';
|
|
10
10
|
import { degreesToRadians } from './math/rotation';
|
|
11
|
+
import {
|
|
12
|
+
isSafeNumber,
|
|
13
|
+
isValidSize,
|
|
14
|
+
safeBoundedNumber,
|
|
15
|
+
sanitizeCropperState,
|
|
16
|
+
} from './math/sanitize';
|
|
11
17
|
|
|
12
18
|
// Pre-allocated scratch buffers for `screenToWorld`, which is called per
|
|
13
19
|
// pointermove. Module-level singletons — safe because usage is synchronous.
|
|
@@ -27,6 +33,19 @@ export function getRotatedBBox(
|
|
|
27
33
|
height: number,
|
|
28
34
|
rotation: number
|
|
29
35
|
): Size {
|
|
36
|
+
// Short-circuit on any unsafe input. `isSafeNumber` is stricter than
|
|
37
|
+
// `Number.isFinite`: very large but technically-finite rotations (e.g.
|
|
38
|
+
// `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then
|
|
39
|
+
// `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.
|
|
40
|
+
if (
|
|
41
|
+
! isSafeNumber( width ) ||
|
|
42
|
+
! isSafeNumber( height ) ||
|
|
43
|
+
! isSafeNumber( rotation ) ||
|
|
44
|
+
width <= 0 ||
|
|
45
|
+
height <= 0
|
|
46
|
+
) {
|
|
47
|
+
return { width: 0, height: 0 };
|
|
48
|
+
}
|
|
30
49
|
const rad = degreesToRadians( rotation );
|
|
31
50
|
const cosR = Math.abs( Math.cos( rad ) );
|
|
32
51
|
const sinR = Math.abs( Math.sin( rad ) );
|
|
@@ -54,27 +73,31 @@ export function getImageFit(
|
|
|
54
73
|
imageSize: Size,
|
|
55
74
|
rotation: number
|
|
56
75
|
): { elementSize: Size; visualSize: Size } {
|
|
57
|
-
if (
|
|
58
|
-
containerSize.width === 0 ||
|
|
59
|
-
containerSize.height === 0 ||
|
|
60
|
-
imageSize.width === 0 ||
|
|
61
|
-
imageSize.height === 0
|
|
62
|
-
) {
|
|
76
|
+
if ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {
|
|
63
77
|
return {
|
|
64
78
|
elementSize: { width: 0, height: 0 },
|
|
65
79
|
visualSize: { width: 0, height: 0 },
|
|
66
80
|
};
|
|
67
81
|
}
|
|
82
|
+
const safeRotation = safeBoundedNumber( rotation, 0 );
|
|
68
83
|
// Snap rotation to the nearest 90° multiple for layout sizing.
|
|
69
84
|
// This keeps the stencil a stable size through fine ±45° rotation
|
|
70
85
|
// (no inflation at 15°/30° etc.) while still swapping aspect at
|
|
71
86
|
// 90°/180°/270° so the snap rotate preserves the framed content.
|
|
72
|
-
const snapRotation = Math.round(
|
|
87
|
+
const snapRotation = Math.round( safeRotation / 90 ) * 90;
|
|
73
88
|
const naturalBBox = getRotatedBBox(
|
|
74
89
|
imageSize.width,
|
|
75
90
|
imageSize.height,
|
|
76
91
|
snapRotation
|
|
77
92
|
);
|
|
93
|
+
// Defensive: getRotatedBBox returns zero dims for hostile inputs, which
|
|
94
|
+
// would make fitScale infinite. Mirror the zero-container short-circuit.
|
|
95
|
+
if ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {
|
|
96
|
+
return {
|
|
97
|
+
elementSize: { width: 0, height: 0 },
|
|
98
|
+
visualSize: { width: 0, height: 0 },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
78
101
|
const fitScale = Math.min(
|
|
79
102
|
containerSize.width / naturalBBox.width,
|
|
80
103
|
containerSize.height / naturalBBox.height
|
|
@@ -113,20 +136,17 @@ export function createCamera(
|
|
|
113
136
|
): Camera {
|
|
114
137
|
const m = mat2d.create();
|
|
115
138
|
|
|
116
|
-
if (
|
|
117
|
-
containerSize.width === 0 ||
|
|
118
|
-
containerSize.height === 0 ||
|
|
119
|
-
imageSize.width === 0 ||
|
|
120
|
-
imageSize.height === 0
|
|
121
|
-
) {
|
|
139
|
+
if ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {
|
|
122
140
|
return m;
|
|
123
141
|
}
|
|
124
142
|
|
|
143
|
+
const safeState = sanitizeCropperState( state );
|
|
144
|
+
|
|
125
145
|
// Use the nearest 90° multiple for layout sizing so the stencil
|
|
126
146
|
// and visual bounds are stable through fine rotation. The actual
|
|
127
147
|
// `state.rotation` is still used for the rotation component of
|
|
128
148
|
// the matrix below.
|
|
129
|
-
const snapRotation = Math.round(
|
|
149
|
+
const snapRotation = Math.round( safeState.rotation / 90 ) * 90;
|
|
130
150
|
|
|
131
151
|
// Rotated bounding box of the natural image (at snap angle).
|
|
132
152
|
const naturalBBox = getRotatedBBox(
|
|
@@ -135,6 +155,12 @@ export function createCamera(
|
|
|
135
155
|
snapRotation
|
|
136
156
|
);
|
|
137
157
|
|
|
158
|
+
// Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror
|
|
159
|
+
// the zero-size short-circuit so `fitScale` doesn't become Infinity.
|
|
160
|
+
if ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {
|
|
161
|
+
return m;
|
|
162
|
+
}
|
|
163
|
+
|
|
138
164
|
// "Contain" fit: scale rotated bounding box to fit within container.
|
|
139
165
|
const fitScale = Math.min(
|
|
140
166
|
containerSize.width / naturalBBox.width,
|
|
@@ -162,20 +188,23 @@ export function createCamera(
|
|
|
162
188
|
] );
|
|
163
189
|
|
|
164
190
|
// Pan offset in visual-space pixels.
|
|
165
|
-
mat2d.translate( m, m, [
|
|
191
|
+
mat2d.translate( m, m, [
|
|
192
|
+
safeState.pan.x * visualW,
|
|
193
|
+
safeState.pan.y * visualH,
|
|
194
|
+
] );
|
|
166
195
|
|
|
167
196
|
// Flip (viewport-relative — composed outside rotation so horizontal
|
|
168
197
|
// flip always mirrors across the viewport's vertical axis).
|
|
169
198
|
mat2d.scale( m, m, [
|
|
170
|
-
|
|
171
|
-
|
|
199
|
+
safeState.flip.horizontal ? -1 : 1,
|
|
200
|
+
safeState.flip.vertical ? -1 : 1,
|
|
172
201
|
] );
|
|
173
202
|
|
|
174
203
|
// Rotate.
|
|
175
|
-
mat2d.rotate( m, m, degreesToRadians(
|
|
204
|
+
mat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );
|
|
176
205
|
|
|
177
206
|
// Zoom.
|
|
178
|
-
mat2d.scale( m, m, [
|
|
207
|
+
mat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );
|
|
179
208
|
|
|
180
209
|
// Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).
|
|
181
210
|
mat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );
|
|
@@ -304,15 +333,11 @@ export function createExportCamera(
|
|
|
304
333
|
outputSize: Size
|
|
305
334
|
): Camera {
|
|
306
335
|
const m = mat2d.create();
|
|
307
|
-
|
|
308
|
-
if (
|
|
309
|
-
imageSize.width === 0 ||
|
|
310
|
-
imageSize.height === 0 ||
|
|
311
|
-
outputSize.width === 0 ||
|
|
312
|
-
outputSize.height === 0
|
|
313
|
-
) {
|
|
336
|
+
if ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {
|
|
314
337
|
return m;
|
|
315
338
|
}
|
|
339
|
+
const { rotation, flip, cropRect, zoom, pan } =
|
|
340
|
+
sanitizeCropperState( state );
|
|
316
341
|
// Reference frame for cropRect/pan is the snap-rotation bbox — that's
|
|
317
342
|
// what the stencil and CSS matrix use in the preview (see createCamera
|
|
318
343
|
// and getImageFit). Using the true rotation here would position the
|
|
@@ -8,9 +8,28 @@ import { __ } from '@wordpress/i18n';
|
|
|
8
8
|
*/
|
|
9
9
|
import type { NormalizedRect, Flip, CropperState } from './types';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Default/resting zoom. A full, unrotated crop needs at least 1x to cover the
|
|
13
|
+
* crop area, but smaller/fine-rotated crops can be valid below 1x — the true
|
|
14
|
+
* floor for those comes from `getMinZoom`.
|
|
15
|
+
*/
|
|
11
16
|
export const MIN_ZOOM = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Safety floor for coverage-aware zoom. Degenerate crops can have a geometric
|
|
19
|
+
* coverage minimum of 0, but camera and inverse-matrix math need a stable,
|
|
20
|
+
* positive scale.
|
|
21
|
+
*/
|
|
22
|
+
export const ABSOLUTE_MIN_ZOOM = 0.1;
|
|
12
23
|
export const MAX_ZOOM = 10;
|
|
13
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Minimum crop rect dimension in source-image pixels, enforced per axis
|
|
27
|
+
* during resize. Prevents accidental sub-pixel crops while staying small
|
|
28
|
+
* enough to allow tight crops (favicons, icons). Adjust here to tune the
|
|
29
|
+
* floor globally.
|
|
30
|
+
*/
|
|
31
|
+
export const MIN_CROP_PIXELS = 24;
|
|
32
|
+
|
|
14
33
|
/**
|
|
15
34
|
* Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.
|
|
16
35
|
* This could be made configurable as a prop to the Cropper component.
|