@wordpress/media-editor 0.20.0 → 0.22.0
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/CHANGELOG.md +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -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 → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
The image editor is the cropper engine used by the media editor:
|
|
6
6
|
|
|
7
7
|
- **Core:** state, camera math, containment, source-region, transforms, and canvas export.
|
|
8
|
-
- **React:** `<Cropper>`, `
|
|
8
|
+
- **React:** `<Cropper>`, `useCropperController`, and the optional `CropperProvider` / `useCropper` context wrapper.
|
|
9
9
|
|
|
10
|
-
`
|
|
10
|
+
`useCropperController` does not provide undo/redo. The media editor's composite state layer adds history and sidebar crop options on top of the cropper reducer, importing the reducer-level helpers from `image-editor/core` directly.
|
|
11
11
|
|
|
12
12
|
## Quick Start
|
|
13
13
|
|
|
14
14
|
```tsx
|
|
15
|
-
import { Cropper,
|
|
15
|
+
import { Cropper, useCropperController } from '../image-editor';
|
|
16
16
|
|
|
17
17
|
function ImageCropper() {
|
|
18
|
-
const controller =
|
|
18
|
+
const controller = useCropperController();
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<div style={ { width: 600, height: 400 } }>
|
|
@@ -31,7 +31,7 @@ function ImageCropper() {
|
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
`
|
|
34
|
+
`useCropperController` returns a controller object with the current `state`, named setters, `reset`, `isDirty`, and `getCroppedImage`.
|
|
35
35
|
|
|
36
36
|
## Internal APIs
|
|
37
37
|
|
|
@@ -39,17 +39,17 @@ function ImageCropper() {
|
|
|
39
39
|
|
|
40
40
|
Fills its parent container. Required props are `src` and `controller`. Common options include `freeformCrop`, `aspectRatio`, `showGrid`, `showDimming`, `showDimensions`, `onGestureStart`, and `onGestureEnd`.
|
|
41
41
|
|
|
42
|
-
### `
|
|
42
|
+
### `useCropperController( initialState? )`
|
|
43
43
|
|
|
44
44
|
Pure React state hook for the cropper reducer. Returns a `CropperController`: current state, named setters, `reset`, `isDirty`, and `getCroppedImage`.
|
|
45
45
|
|
|
46
46
|
### `CropperProvider` / `useCropper`
|
|
47
47
|
|
|
48
|
-
Convenience context wrapper around `
|
|
48
|
+
Convenience context wrapper around `useCropperController` for component trees that need shared cropper state.
|
|
49
49
|
|
|
50
50
|
## Core Helpers
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
`index.ts` also exports helpers for source-region calculation, pipeline replay, and canvas export. Use the named setters or `TransformOperation` values for state changes. The reducer-level helpers that `useMediaEditorState()` composes the cropper with are imported from `core` directly and are not part of this index.
|
|
53
53
|
|
|
54
54
|
## Styles
|
|
55
55
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __ } from '@wordpress/i18n';
|
|
2
1
|
import type { NormalizedRect, Flip, CropperState } from './types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -136,15 +135,3 @@ export interface AspectRatioPreset {
|
|
|
136
135
|
* to the image's natural width / height.
|
|
137
136
|
*/
|
|
138
137
|
export const ORIGINAL_ASPECT_RATIO = -1;
|
|
139
|
-
|
|
140
|
-
export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
|
|
141
|
-
{ label: __( 'Free' ), value: 0 },
|
|
142
|
-
{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },
|
|
143
|
-
{ label: __( 'Square (1:1)' ), value: 1 },
|
|
144
|
-
{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },
|
|
145
|
-
{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },
|
|
146
|
-
{ label: __( 'Classic (4:3)' ), value: 4 / 3 },
|
|
147
|
-
{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },
|
|
148
|
-
{ label: __( 'Photo (3:2)' ), value: 3 / 2 },
|
|
149
|
-
{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },
|
|
150
|
-
];
|
|
@@ -12,11 +12,7 @@ export type {
|
|
|
12
12
|
} from './types';
|
|
13
13
|
|
|
14
14
|
// Constants
|
|
15
|
-
export {
|
|
16
|
-
DEFAULT_STATE,
|
|
17
|
-
DEFAULT_ASPECT_RATIOS,
|
|
18
|
-
ORIGINAL_ASPECT_RATIO,
|
|
19
|
-
} from './constants';
|
|
15
|
+
export { DEFAULT_STATE, ORIGINAL_ASPECT_RATIO } from './constants';
|
|
20
16
|
export type { AspectRatioPreset } from './constants';
|
|
21
17
|
|
|
22
18
|
// Reducer + state helpers. `CropperAction` and `cropperReducer` are
|
|
@@ -12,7 +12,7 @@ import { getMinZoom, restrictPanZoom } from './containment';
|
|
|
12
12
|
* the crop center. Returns `null` when the clamped zoom matches the
|
|
13
13
|
* current zoom (no-op).
|
|
14
14
|
*
|
|
15
|
-
* Extracted so multiple hooks (the pure `
|
|
15
|
+
* Extracted so multiple hooks (the pure `useCropperController` and the
|
|
16
16
|
* composite `useMediaEditorState`) can share the math without
|
|
17
17
|
* duplicating it.
|
|
18
18
|
*
|
|
@@ -109,7 +109,7 @@ export interface CropperState {
|
|
|
109
109
|
*
|
|
110
110
|
* This type is intentionally not exported from the image-editor public barrel.
|
|
111
111
|
* Consumers should drive state through the controller returned by
|
|
112
|
-
* `
|
|
112
|
+
* `useCropperController()` (or a composite store) or through serializable
|
|
113
113
|
* `TransformOperation` values.
|
|
114
114
|
*/
|
|
115
115
|
export type CropperAction =
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
| Layer | Files | Responsibility |
|
|
6
6
|
| --- | --- | --- |
|
|
7
7
|
| Core cropper | `src/image-editor/core/` | Pure state, camera math, containment, source-region, transforms, and canvas export. |
|
|
8
|
-
| React cropper | `src/image-editor/react/` | DOM measurement, interaction hooks, overlays, stencil rendering, and the pure `
|
|
8
|
+
| React cropper | `src/image-editor/react/` | DOM measurement, interaction hooks, overlays, stencil rendering, and the pure `useCropperController` hook. |
|
|
9
9
|
| Media editor state | `src/state/` | Composite state for the media editor: cropper state, crop options, undo/redo, and gesture boundaries. |
|
|
10
10
|
|
|
11
11
|
The cropper layer does not own editor history. History belongs to the media editor session because sidebar controls and cropper gestures need one shared undo stack.
|
|
@@ -41,6 +41,10 @@ The core reducer is framework-agnostic and serializable. React and media-editor
|
|
|
41
41
|
|
|
42
42
|
`useMediaEditorState()` returns the media editor session. The session owns the source image, every editing slice, the shared undo/redo history, gesture boundaries, and whether the edits change the saved image (`hasOutputEdits`). The cropper is one participant: `session.cropper` is a geometry-only `CropperController` that a `<Cropper>` takes via its `controller` prop, and its `isDirty` covers geometry alone. Replacing the source image (`setSourceImage`, which the cropper's `setImage` also calls) starts a fresh session with default geometry and crop options, a clean baseline, and no history. Save code asks the session, not the cropper, whether image output needs saving.
|
|
43
43
|
|
|
44
|
+
The session also holds named edits other than crop: `session.edits`, set with `session.setEdit( name, value )` and removed by passing `undefined`. They share the crop history, so undo, redo and gestures treat them like any crop change, and a different source image clears them. Values are plain data (`EditValue`: strings, numbers, booleans, `null`, and arrays and objects of those), because the session compares them by content to tell a real change from a no-op. Edits do not yet count towards `hasOutputEdits`; nothing saves them.
|
|
45
|
+
|
|
46
|
+
`session.reset()` puts every slice back to its starting state in one undo entry: default geometry and crop options, no edits, same image. The Reset button calls it; it does not compose per-slice resets itself.
|
|
47
|
+
|
|
44
48
|
### Viewport
|
|
45
49
|
|
|
46
50
|
Viewport pan/zoom lets the user inspect or follow the crop area without changing the crop output. It is not part of export and should not create undo entries.
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
## Mount a Cropper
|
|
6
6
|
|
|
7
7
|
```tsx
|
|
8
|
-
import { Cropper,
|
|
8
|
+
import { Cropper, useCropperController } from '../image-editor';
|
|
9
9
|
|
|
10
10
|
function ImageCropper( { src }: { src: string } ) {
|
|
11
|
-
const controller =
|
|
11
|
+
const controller = useCropperController();
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
14
|
<div style={ { width: 600, height: 400 } }>
|
|
@@ -30,7 +30,7 @@ The cropper fills its parent. Always render it inside a sized container.
|
|
|
30
30
|
|
|
31
31
|
```tsx
|
|
32
32
|
function ImageCropperWithControls( { src }: { src: string } ) {
|
|
33
|
-
const controller =
|
|
33
|
+
const controller = useCropperController();
|
|
34
34
|
const { state, setZoom, snapRotate90, toggleFlip, reset } = controller;
|
|
35
35
|
|
|
36
36
|
return (
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Keep this barrel explicit so implementation details from `core/`,
|
|
5
5
|
* `react/hooks/`, or `react/components/` do not become supported API by
|
|
6
|
-
* accident.
|
|
7
|
-
*
|
|
6
|
+
* accident. The media editor's own state code imports the reducer-level
|
|
7
|
+
* helpers from `./core` and `./react/hooks` directly, as the package's
|
|
8
|
+
* components already do; everyone else uses what is here.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
// React surface.
|
|
11
|
-
export {
|
|
12
|
+
export { useCropperController } from './react/hooks';
|
|
12
13
|
export { Cropper, CropperProvider, useCropper } from './react/components';
|
|
13
|
-
export type { CropperController
|
|
14
|
+
export type { CropperController } from './react/hooks';
|
|
14
15
|
export type { CropperProps } from './react/components';
|
|
15
16
|
|
|
16
17
|
// State and extension types.
|
|
17
18
|
export type {
|
|
18
19
|
CropperState,
|
|
19
|
-
CropperAction,
|
|
20
20
|
TransformOperation,
|
|
21
21
|
NormalizedPoint,
|
|
22
22
|
NormalizedRect,
|
|
@@ -26,21 +26,12 @@ export type {
|
|
|
26
26
|
HandlePosition,
|
|
27
27
|
} from './core';
|
|
28
28
|
|
|
29
|
-
// Deterministic
|
|
30
|
-
//
|
|
31
|
-
// stores that delegate cropper actions (see `useMediaEditorState` for
|
|
32
|
-
// the media editor's composite store).
|
|
29
|
+
// Deterministic helpers: where the crop lands in the source, the
|
|
30
|
+
// replayable operation list, and export without a controller.
|
|
33
31
|
export {
|
|
34
|
-
DEFAULT_STATE,
|
|
35
|
-
DEFAULT_ASPECT_RATIOS,
|
|
36
32
|
ORIGINAL_ASPECT_RATIO,
|
|
37
|
-
cropperReducer,
|
|
38
|
-
enforceContainment,
|
|
39
|
-
areCropperStatesEqual,
|
|
40
|
-
computeInscribedRect,
|
|
41
33
|
getSourceRegion,
|
|
42
34
|
getSourceRegionPercent,
|
|
43
|
-
applyOperationToState,
|
|
44
35
|
stateFromPipeline,
|
|
45
36
|
exportCroppedImage,
|
|
46
37
|
applyToCanvas,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createContext, useContext } from '@wordpress/element';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
useCropperController,
|
|
4
4
|
type CropperController,
|
|
5
|
-
} from '../hooks/use-cropper-
|
|
5
|
+
} from '../hooks/use-cropper-controller';
|
|
6
6
|
import type { CropperState } from '../../core/types';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The context value type for the CropperProvider.
|
|
10
|
-
* Contains the cropper controller from
|
|
10
|
+
* Contains the cropper controller from useCropperController.
|
|
11
11
|
*/
|
|
12
12
|
type CropperContextValue = CropperController | null;
|
|
13
13
|
|
|
@@ -24,7 +24,7 @@ interface CropperProviderProps {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Convenience context provider that wraps `
|
|
27
|
+
* Convenience context provider that wraps `useCropperController`.
|
|
28
28
|
*
|
|
29
29
|
* Provides the pure cropper controller (state + setters, NO undo
|
|
30
30
|
* history) to all descendant components via React context.
|
|
@@ -42,7 +42,7 @@ export function CropperProvider( {
|
|
|
42
42
|
initialState,
|
|
43
43
|
children,
|
|
44
44
|
}: CropperProviderProps ) {
|
|
45
|
-
const cropperReturn =
|
|
45
|
+
const cropperReturn = useCropperController( initialState );
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<CropperContext.Provider value={ cropperReturn }>
|
|
@@ -8,16 +8,16 @@ import {
|
|
|
8
8
|
useLayoutEffect,
|
|
9
9
|
useId,
|
|
10
10
|
forwardRef,
|
|
11
|
+
flushSync,
|
|
11
12
|
} from '@wordpress/element';
|
|
12
13
|
import { __ } from '@wordpress/i18n';
|
|
13
14
|
import type {
|
|
14
|
-
CropperState,
|
|
15
15
|
HandlePosition,
|
|
16
16
|
StencilProps,
|
|
17
17
|
Size,
|
|
18
18
|
NormalizedRect,
|
|
19
19
|
} from '../../core/types';
|
|
20
|
-
import type { CropperController } from '../hooks/use-cropper-
|
|
20
|
+
import type { CropperController } from '../hooks/use-cropper-controller';
|
|
21
21
|
import { getImageFit, getRotatedBBox, getViewScale } from '../../core/camera';
|
|
22
22
|
import { getImageCropBounds, getMinZoom } from '../../core/containment';
|
|
23
23
|
import {
|
|
@@ -66,7 +66,7 @@ const SETTLE_STENCIL_TRANSITION = [
|
|
|
66
66
|
export interface CropperProps {
|
|
67
67
|
/** Image source URL. */
|
|
68
68
|
src: string;
|
|
69
|
-
/** The cropper controller from `
|
|
69
|
+
/** The cropper controller from `useCropperController` or a composite store. */
|
|
70
70
|
controller: CropperController;
|
|
71
71
|
/** Stencil component for the crop area. Defaults to RectangleStencil. */
|
|
72
72
|
stencil?: React.ComponentType< StencilProps >;
|
|
@@ -101,17 +101,8 @@ export interface CropperProps {
|
|
|
101
101
|
disabled?: boolean;
|
|
102
102
|
/** Callback fired when the image is loaded. */
|
|
103
103
|
onImageLoaded?: ( size: Size ) => void;
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
* during drags, so keep the handler light — no heavy work, no
|
|
107
|
-
* expensive parent re-renders. For commit-style events (drag end,
|
|
108
|
-
* settled crop), use `onGestureEnd` instead.
|
|
109
|
-
*
|
|
110
|
-
* Useful for lightweight syncing with external tools, analytics,
|
|
111
|
-
* or AI agents. Receives the full state so consumers can derive
|
|
112
|
-
* whatever they need.
|
|
113
|
-
*/
|
|
114
|
-
onStateChange?: ( state: CropperState ) => void;
|
|
104
|
+
/** Callback fired when the image fails to load. */
|
|
105
|
+
onImageError?: () => void;
|
|
115
106
|
/** Fires when a continuous gesture begins (pan drag, handle resize, pinch zoom). */
|
|
116
107
|
onGestureStart?: () => void;
|
|
117
108
|
/** Fires when a continuous gesture ends (pointerup, resize settle). */
|
|
@@ -132,7 +123,7 @@ export interface CropperProps {
|
|
|
132
123
|
*
|
|
133
124
|
* @param root0 Component props implementing CropperProps.
|
|
134
125
|
* @param root0.src Image source URL.
|
|
135
|
-
* @param root0.controller The cropper controller from `
|
|
126
|
+
* @param root0.controller The cropper controller from `useCropperController` or a composite store.
|
|
136
127
|
* @param root0.stencil Custom stencil component.
|
|
137
128
|
* @param root0.showGrid Grid overlay mode: false | true | 'interactive'.
|
|
138
129
|
* @param root0.isPlacementActive Keep grid visible during external placement activity.
|
|
@@ -145,7 +136,7 @@ export interface CropperProps {
|
|
|
145
136
|
* @param root0.focusOnMount Focus the crop area on mount.
|
|
146
137
|
* @param root0.disabled Ignore all crop interaction.
|
|
147
138
|
* @param root0.onImageLoaded Image load callback.
|
|
148
|
-
* @param root0.
|
|
139
|
+
* @param root0.onImageError Image error callback.
|
|
149
140
|
* @param root0.onGestureStart Gesture boundary start.
|
|
150
141
|
* @param root0.onGestureEnd Gesture boundary end.
|
|
151
142
|
* @param root0.className Additional CSS class.
|
|
@@ -167,7 +158,7 @@ function CropperInner(
|
|
|
167
158
|
focusOnMount = false,
|
|
168
159
|
disabled = false,
|
|
169
160
|
onImageLoaded,
|
|
170
|
-
|
|
161
|
+
onImageError,
|
|
171
162
|
onGestureStart,
|
|
172
163
|
onGestureEnd,
|
|
173
164
|
className,
|
|
@@ -254,11 +245,16 @@ function CropperInner(
|
|
|
254
245
|
const observer = new ResizeObserver( ( entries ) => {
|
|
255
246
|
for ( const entry of entries ) {
|
|
256
247
|
const { width, height } = entry.contentRect;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
248
|
+
// Render before the next paint, so the image keeps up with
|
|
249
|
+
// a container that is resizing every frame (such as while
|
|
250
|
+
// the sidebar animates) instead of trailing it by a frame.
|
|
251
|
+
flushSync( () => {
|
|
252
|
+
setCanvasSize( ( prev ) => {
|
|
253
|
+
if ( prev.width === width && prev.height === height ) {
|
|
254
|
+
return prev;
|
|
255
|
+
}
|
|
256
|
+
return { width, height };
|
|
257
|
+
} );
|
|
262
258
|
} );
|
|
263
259
|
}
|
|
264
260
|
} );
|
|
@@ -268,11 +264,6 @@ function CropperInner(
|
|
|
268
264
|
};
|
|
269
265
|
}, [] );
|
|
270
266
|
|
|
271
|
-
// Notify consumer of state changes.
|
|
272
|
-
useEffect( () => {
|
|
273
|
-
onStateChange?.( state );
|
|
274
|
-
}, [ state, onStateChange ] );
|
|
275
|
-
|
|
276
267
|
// ARIA announcements: announce significant state changes for screen readers
|
|
277
268
|
// via the centralized @wordpress/a11y speak() API called inside the hook.
|
|
278
269
|
useAriaAnnouncer( state );
|
|
@@ -967,23 +958,9 @@ function CropperInner(
|
|
|
967
958
|
};
|
|
968
959
|
}
|
|
969
960
|
|
|
970
|
-
// Forward the root element to the consumer's ref.
|
|
971
|
-
const setContainerRef = useCallback(
|
|
972
|
-
( element: HTMLDivElement | null ) => {
|
|
973
|
-
if ( typeof ref === 'function' ) {
|
|
974
|
-
ref( element );
|
|
975
|
-
} else if ( ref ) {
|
|
976
|
-
(
|
|
977
|
-
ref as React.MutableRefObject< HTMLDivElement | null >
|
|
978
|
-
).current = element;
|
|
979
|
-
}
|
|
980
|
-
},
|
|
981
|
-
[ ref ]
|
|
982
|
-
);
|
|
983
|
-
|
|
984
961
|
return (
|
|
985
962
|
<div
|
|
986
|
-
ref={
|
|
963
|
+
ref={ ref }
|
|
987
964
|
className={ clsx(
|
|
988
965
|
'wp-media-editor-image-editor',
|
|
989
966
|
isDragging && 'wp-media-editor-image-editor--dragging',
|
|
@@ -1058,6 +1035,7 @@ function CropperInner(
|
|
|
1058
1035
|
src={ src }
|
|
1059
1036
|
alt=""
|
|
1060
1037
|
onLoad={ handleImageLoad }
|
|
1038
|
+
onError={ onImageError }
|
|
1061
1039
|
style={ imageStyle }
|
|
1062
1040
|
draggable={ false }
|
|
1063
1041
|
/>
|
|
@@ -10,7 +10,7 @@ import { buildFocalPointZoomAction } from '../../core/setter-helpers';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The named cropper setters shared by every hook that drives the
|
|
13
|
-
* cropper reducer — the pure `
|
|
13
|
+
* cropper reducer — the pure `useCropperController` and any composite
|
|
14
14
|
* store that delegates cropper actions (e.g. `useMediaEditorState`).
|
|
15
15
|
*
|
|
16
16
|
* `setImage` and `reset` are intentionally NOT included: each hook
|
|
@@ -34,7 +34,7 @@ export interface CropperSetters {
|
|
|
34
34
|
* Build the named cropper setters from a dispatch function and a
|
|
35
35
|
* state getter. The two consuming hooks differ in how they dispatch:
|
|
36
36
|
*
|
|
37
|
-
* - `
|
|
37
|
+
* - `useCropperController` dispatches directly into its `useReducer`.
|
|
38
38
|
* - `useMediaEditorState` wraps cropper actions in a composite
|
|
39
39
|
* `CROPPER` envelope so the history machinery can record them.
|
|
40
40
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { CropperController } from './use-cropper-
|
|
1
|
+
export { useCropperController } from './use-cropper-controller';
|
|
2
|
+
export type { CropperController } from './use-cropper-controller';
|
|
3
3
|
export { buildCropperSetters } from './build-cropper-setters';
|
|
4
4
|
export type { CropperSetters } from './build-cropper-setters';
|
|
@@ -47,18 +47,17 @@ export interface CropperController extends CropperSetters {
|
|
|
47
47
|
*/
|
|
48
48
|
getCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* cropper hook ignores it (no-op).
|
|
50
|
+
* Called by `Cropper` whenever its rendered image size changes; not for
|
|
51
|
+
* consumers to call. A composite controller uses the size to reshape the
|
|
52
|
+
* crop for an aspect ratio. The pure cropper hook ignores it.
|
|
54
53
|
*/
|
|
55
54
|
setVisualSize: ( size: Size ) => void;
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
58
|
-
* resize
|
|
59
|
-
* composite
|
|
60
|
-
*
|
|
61
|
-
*
|
|
56
|
+
* Called by `Cropper` when the viewport changes (window or canvas
|
|
57
|
+
* resize); not for consumers to call. Like `setCropRect`, except that a
|
|
58
|
+
* composite controller records no undo entry for it, since a viewport
|
|
59
|
+
* reshape is not an editor action. The pure cropper hook aliases it to
|
|
60
|
+
* `setCropRect`.
|
|
62
61
|
*/
|
|
63
62
|
adjustCropRectForViewport: ( rect: NormalizedRect ) => void;
|
|
64
63
|
}
|
|
@@ -75,7 +74,8 @@ function areCropperImagesEqual(
|
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
/**
|
|
78
|
-
*
|
|
77
|
+
* Controller hook for the image cropper: the state, the named setters and
|
|
78
|
+
* the export helpers, without history.
|
|
79
79
|
*
|
|
80
80
|
* Wraps the framework-agnostic `cropperReducer` and exposes named
|
|
81
81
|
* setters (built from the shared `buildCropperSetters` factory).
|
|
@@ -86,7 +86,7 @@ function areCropperImagesEqual(
|
|
|
86
86
|
* @param initialState Optional partial state to merge with DEFAULT_STATE.
|
|
87
87
|
* @return The cropper controller — state, setters, and helpers.
|
|
88
88
|
*/
|
|
89
|
-
export function
|
|
89
|
+
export function useCropperController(
|
|
90
90
|
initialState?: Partial< CropperState >
|
|
91
91
|
): CropperController {
|
|
92
92
|
const [ state, dispatch ] = useReducer(
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __ } from '@wordpress/i18n';
|
|
2
|
+
import { ORIGINAL_ASPECT_RATIO, type AspectRatioPreset } from '../image-editor';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The presets the editor offers by default. The labels live here rather
|
|
6
|
+
* than in the cropper core, which has no user-facing strings.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
|
|
9
|
+
{ label: __( 'Free' ), value: 0 },
|
|
10
|
+
{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },
|
|
11
|
+
{ label: __( 'Square (1:1)' ), value: 1 },
|
|
12
|
+
{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },
|
|
13
|
+
{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },
|
|
14
|
+
{ label: __( 'Classic (4:3)' ), value: 4 / 3 },
|
|
15
|
+
{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },
|
|
16
|
+
{ label: __( 'Photo (3:2)' ), value: 3 / 2 },
|
|
17
|
+
{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },
|
|
18
|
+
];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import fastDeepEqual from 'fast-deep-equal/es6/index.js';
|
|
2
|
+
import type { CropperState } from '../image-editor';
|
|
1
3
|
import {
|
|
2
4
|
cropperReducer,
|
|
3
5
|
areCropperStatesEqual,
|
|
4
6
|
computeInscribedRect,
|
|
5
|
-
|
|
6
|
-
} from '../image-editor';
|
|
7
|
+
} from '../image-editor/core';
|
|
7
8
|
import {
|
|
8
9
|
DEFAULT_CROP_OPTIONS,
|
|
9
10
|
type CropOptionsSlice,
|
|
@@ -64,21 +65,31 @@ export function mediaEditorReducer(
|
|
|
64
65
|
payload: newCropRect,
|
|
65
66
|
} );
|
|
66
67
|
return {
|
|
68
|
+
...state,
|
|
67
69
|
cropper: nextCropper,
|
|
68
70
|
cropOptions: nextCropOptions,
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
|
-
case '
|
|
72
|
-
|
|
73
|
-
state.
|
|
74
|
-
|
|
75
|
-
)
|
|
73
|
+
case 'RESET': {
|
|
74
|
+
const next = buildInitialMediaEditorState(
|
|
75
|
+
cropperReducer( state.cropper, { type: 'RESET' } )
|
|
76
|
+
);
|
|
77
|
+
return areMediaEditorStatesEqual( state, next ) ? state : next;
|
|
78
|
+
}
|
|
79
|
+
case 'SET_EDIT': {
|
|
80
|
+
const { name, value } = action.payload;
|
|
81
|
+
if ( value === undefined ) {
|
|
82
|
+
if ( ! Object.hasOwn( state.edits, name ) ) {
|
|
83
|
+
return state;
|
|
84
|
+
}
|
|
85
|
+
const edits = { ...state.edits };
|
|
86
|
+
delete edits[ name ];
|
|
87
|
+
return { ...state, edits };
|
|
88
|
+
}
|
|
89
|
+
if ( fastDeepEqual( state.edits[ name ], value ) ) {
|
|
76
90
|
return state;
|
|
77
91
|
}
|
|
78
|
-
return {
|
|
79
|
-
...state,
|
|
80
|
-
cropOptions: { ...DEFAULT_CROP_OPTIONS },
|
|
81
|
-
};
|
|
92
|
+
return { ...state, edits: { ...state.edits, [ name ]: value } };
|
|
82
93
|
}
|
|
83
94
|
case 'RESTORE_SNAPSHOT':
|
|
84
95
|
return action.payload;
|
|
@@ -112,13 +123,14 @@ export function areMediaEditorStatesEqual(
|
|
|
112
123
|
}
|
|
113
124
|
return (
|
|
114
125
|
areCropperStatesEqual( a.cropper, b.cropper ) &&
|
|
115
|
-
a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue
|
|
126
|
+
a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&
|
|
127
|
+
fastDeepEqual( a.edits, b.edits )
|
|
116
128
|
);
|
|
117
129
|
}
|
|
118
130
|
|
|
119
131
|
/**
|
|
120
132
|
* Build the composite state a session starts from: the given cropper
|
|
121
|
-
* slice
|
|
133
|
+
* slice, default crop options, and no edits.
|
|
122
134
|
*
|
|
123
135
|
* @param cropper The cropper slice.
|
|
124
136
|
* @return Composite initial state.
|
|
@@ -129,5 +141,6 @@ export function buildInitialMediaEditorState(
|
|
|
129
141
|
return {
|
|
130
142
|
cropper,
|
|
131
143
|
cropOptions: { ...DEFAULT_CROP_OPTIONS },
|
|
144
|
+
edits: {},
|
|
132
145
|
};
|
|
133
146
|
}
|
package/src/state/index.ts
CHANGED
|
@@ -13,8 +13,11 @@ export {
|
|
|
13
13
|
buildInitialMediaEditorState,
|
|
14
14
|
} from './composite-reducer';
|
|
15
15
|
export { DEFAULT_CROP_OPTIONS } from './types';
|
|
16
|
+
export { DEFAULT_ASPECT_RATIOS } from './aspect-ratio-presets';
|
|
16
17
|
export type {
|
|
17
18
|
CropOptionsSlice,
|
|
19
|
+
EditsSlice,
|
|
20
|
+
EditValue,
|
|
18
21
|
MediaEditorState,
|
|
19
22
|
MediaEditorAction,
|
|
20
23
|
} from './types';
|
package/src/state/types.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
CropperState,
|
|
4
|
-
NormalizedRect,
|
|
5
|
-
Size,
|
|
6
|
-
} from '../image-editor';
|
|
1
|
+
import type { CropperState, NormalizedRect, Size } from '../image-editor';
|
|
2
|
+
import type { CropperAction } from '../image-editor/core';
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
* Sidebar control state for the cropper. Lives in the composite store
|
|
@@ -27,9 +23,31 @@ export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
|
|
|
27
23
|
};
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
26
|
+
* A value an edit can hold: plain data only, because the session
|
|
27
|
+
* compares values by content to tell a real change from a no-op.
|
|
28
|
+
* Anything else, such as a `Blob`, would compare equal to any other
|
|
29
|
+
* and the change would be dropped — keep bytes behind a URL instead.
|
|
30
|
+
*
|
|
31
|
+
* Objects must satisfy the index signature, so type a value with a
|
|
32
|
+
* `type` alias rather than an `interface`.
|
|
33
|
+
*/
|
|
34
|
+
export type EditValue =
|
|
35
|
+
| string
|
|
36
|
+
| number
|
|
37
|
+
| boolean
|
|
38
|
+
| null
|
|
39
|
+
| EditValue[]
|
|
40
|
+
| { [ key: string ]: EditValue };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Named edits other than crop, keyed by edit name (for example
|
|
44
|
+
* `my-plugin/vignette`). An edit that is not present means "no edit".
|
|
45
|
+
*/
|
|
46
|
+
export type EditsSlice = Record< string, EditValue >;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The full composite state for the media editor — cropper geometry,
|
|
50
|
+
* the sidebar control slice, and named edits.
|
|
33
51
|
*
|
|
34
52
|
* Every undo/redo snapshot is a full `MediaEditorState`. Slices stay
|
|
35
53
|
* referentially equal across actions that don't touch them.
|
|
@@ -37,6 +55,7 @@ export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
|
|
|
37
55
|
export interface MediaEditorState {
|
|
38
56
|
cropper: CropperState;
|
|
39
57
|
cropOptions: CropOptionsSlice;
|
|
58
|
+
edits: EditsSlice;
|
|
40
59
|
}
|
|
41
60
|
|
|
42
61
|
/**
|
|
@@ -79,8 +98,17 @@ export type MediaEditorAction =
|
|
|
79
98
|
visualSize: Size;
|
|
80
99
|
};
|
|
81
100
|
}
|
|
82
|
-
/**
|
|
83
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Put every slice back to its starting state, keeping the image:
|
|
103
|
+
* default geometry, default crop options, no edits. One action,
|
|
104
|
+
* so one undo entry.
|
|
105
|
+
*/
|
|
106
|
+
| { type: 'RESET' }
|
|
107
|
+
/** Set a named edit, or remove it when `value` is `undefined`. */
|
|
108
|
+
| {
|
|
109
|
+
type: 'SET_EDIT';
|
|
110
|
+
payload: { name: string; value: EditValue | undefined };
|
|
111
|
+
}
|
|
84
112
|
/**
|
|
85
113
|
* Replace the entire composite state with `payload`. Used by
|
|
86
114
|
* undo/redo to restore a full snapshot atomically.
|