@wordpress/media-editor 0.22.0 → 0.24.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 +34 -0
- package/build/components/media-editor/index.cjs +229 -126
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +41 -11
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +15 -18
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +26 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +13 -12
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +143 -37
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +12 -6
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +41 -74
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +217 -117
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +123 -41
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +12 -7
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +122 -87
- package/build-style/style.css +121 -87
- package/build-types/components/media-editor/index.d.ts +25 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- 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 +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- 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.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- 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/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +40 -54
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +27 -24
- package/src/components/media-editor/index.tsx +372 -142
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +4 -1
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +195 -37
- package/src/components/media-preview/style.scss +11 -32
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +34 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +162 -242
- package/src/style.scss +2 -1
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -6,20 +6,12 @@ import {
|
|
|
6
6
|
useState,
|
|
7
7
|
} from '@wordpress/element';
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from '../image-editor';
|
|
16
|
-
import {
|
|
17
|
-
DEFAULT_STATE,
|
|
18
|
-
areCropperStatesEqual,
|
|
19
|
-
enforceContainment,
|
|
20
|
-
type CropperAction,
|
|
21
|
-
} from '../image-editor/core';
|
|
22
|
-
import { buildCropperSetters } from '../image-editor/react/hooks';
|
|
9
|
+
createImageEditorState,
|
|
10
|
+
useImageEditor,
|
|
11
|
+
type ImageEditorController,
|
|
12
|
+
type ImageEditorState,
|
|
13
|
+
} from '@wordpress/image-editor';
|
|
14
|
+
import { ORIGINAL_ASPECT_RATIO } from './aspect-ratio-presets';
|
|
23
15
|
import {
|
|
24
16
|
mediaEditorReducer,
|
|
25
17
|
areMediaEditorStatesEqual,
|
|
@@ -35,35 +27,28 @@ import type {
|
|
|
35
27
|
|
|
36
28
|
/**
|
|
37
29
|
* Resolve an aspect-ratio preset value (the string the dropdown
|
|
38
|
-
* round-trips) into a numeric width/height ratio for the
|
|
30
|
+
* round-trips) into a numeric width/height ratio for the image editor.
|
|
39
31
|
*
|
|
40
32
|
* - `'0'` → `undefined` (Free; no lock)
|
|
41
33
|
* - `'-1'` (Original) → image's natural width / height, or `undefined`
|
|
42
34
|
* if no image is loaded.
|
|
43
35
|
* - Any positive decimal → the parsed number.
|
|
44
36
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @param presetKey Preset value from the dropdown.
|
|
49
|
-
* @param cropperImage The cropper's loaded image, or `null`.
|
|
37
|
+
* @param presetKey Preset value from the dropdown.
|
|
38
|
+
* @param image The image editor's loaded image, or `null`.
|
|
50
39
|
* @return The resolved ratio, or `undefined` for Free / unresolvable.
|
|
51
40
|
*/
|
|
52
|
-
|
|
41
|
+
function resolveAspectRatio(
|
|
53
42
|
presetKey: string,
|
|
54
|
-
|
|
43
|
+
image: ImageEditorState[ 'image' ] | null
|
|
55
44
|
): number | undefined {
|
|
56
45
|
const num = parseFloat( presetKey );
|
|
57
46
|
if ( num === 0 || Number.isNaN( num ) ) {
|
|
58
47
|
return undefined;
|
|
59
48
|
}
|
|
60
49
|
if ( num === ORIGINAL_ASPECT_RATIO ) {
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
cropperImage.naturalWidth > 0 &&
|
|
64
|
-
cropperImage.naturalHeight > 0
|
|
65
|
-
) {
|
|
66
|
-
return cropperImage.naturalWidth / cropperImage.naturalHeight;
|
|
50
|
+
if ( image && image.naturalWidth > 0 && image.naturalHeight > 0 ) {
|
|
51
|
+
return image.naturalWidth / image.naturalHeight;
|
|
67
52
|
}
|
|
68
53
|
return undefined;
|
|
69
54
|
}
|
|
@@ -73,9 +58,9 @@ export function resolveAspectRatio(
|
|
|
73
58
|
return undefined;
|
|
74
59
|
}
|
|
75
60
|
|
|
76
|
-
function
|
|
77
|
-
a:
|
|
78
|
-
b:
|
|
61
|
+
function areImagesEqual(
|
|
62
|
+
a: ImageEditorState[ 'image' ],
|
|
63
|
+
b: ImageEditorState[ 'image' ]
|
|
79
64
|
): boolean {
|
|
80
65
|
return (
|
|
81
66
|
a?.src === b?.src &&
|
|
@@ -90,28 +75,32 @@ function areCropperImagesEqual(
|
|
|
90
75
|
* The session owns what is being edited and how: the source image,
|
|
91
76
|
* every editing slice, the shared undo/redo history, gesture
|
|
92
77
|
* boundaries, and whether the edits change the saved image. The
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
78
|
+
* image editor is one participant in the session — `imageEditor` is the
|
|
79
|
+
* controller an `<ImageEditorCanvas>` takes via its `controller` prop — rather
|
|
80
|
+
* than the session itself.
|
|
96
81
|
*/
|
|
97
82
|
export interface MediaEditorSession {
|
|
98
83
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
84
|
+
* Controller for the image editor. Its setters record history in the
|
|
85
|
+
* session; its `isDirty` covers the crop only. Its `setImage` is
|
|
86
|
+
* `setSourceImage`, so the `<ImageEditorCanvas>` reporting a newly loaded
|
|
87
|
+
* image starts a fresh session.
|
|
103
88
|
*/
|
|
104
|
-
|
|
89
|
+
imageEditor: ImageEditorController;
|
|
105
90
|
/** The cropOptions slice. */
|
|
106
91
|
cropOptions: CropOptionsSlice;
|
|
107
|
-
/** Set the aspect-ratio preset
|
|
92
|
+
/** Set the aspect-ratio preset and reshape the crop in one undo entry. */
|
|
108
93
|
setAspectRatioValue: ( presetKey: string ) => void;
|
|
109
94
|
/**
|
|
110
95
|
* Put every slice back to its starting state in one undo entry:
|
|
111
|
-
* default
|
|
96
|
+
* default crop and crop options, no edits. Keeps the image.
|
|
112
97
|
*/
|
|
113
98
|
reset: () => void;
|
|
114
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* The named edits other than crop, keyed by edit name. Not an
|
|
101
|
+
* extension API: undoable and cleared by `reset`, but not counted by
|
|
102
|
+
* `hasOutputEdits` and not saved.
|
|
103
|
+
*/
|
|
115
104
|
edits: EditsSlice;
|
|
116
105
|
/**
|
|
117
106
|
* Set a named edit, or remove it by passing `undefined`. Recorded
|
|
@@ -121,11 +110,10 @@ export interface MediaEditorSession {
|
|
|
121
110
|
setEdit: ( name: string, value: EditValue | undefined ) => void;
|
|
122
111
|
/**
|
|
123
112
|
* Replace the image being edited. A different image starts a
|
|
124
|
-
* fresh session: default
|
|
125
|
-
*
|
|
126
|
-
* no-op.
|
|
113
|
+
* fresh session: default crop and crop options, a clean baseline,
|
|
114
|
+
* and no history. Reporting the same image again is a no-op.
|
|
127
115
|
*/
|
|
128
|
-
setSourceImage: ( image:
|
|
116
|
+
setSourceImage: ( image: ImageEditorState[ 'image' ] ) => void;
|
|
129
117
|
/**
|
|
130
118
|
* Whether anything in the session differs from its baseline,
|
|
131
119
|
* including editor-only state such as the aspect-ratio preset.
|
|
@@ -133,21 +121,22 @@ export interface MediaEditorSession {
|
|
|
133
121
|
isDirty: boolean;
|
|
134
122
|
/**
|
|
135
123
|
* Whether the edits change the saved image, so saving has to
|
|
136
|
-
* produce new image output rather than only metadata.
|
|
124
|
+
* produce new image output rather than only metadata. Geometry
|
|
125
|
+
* counts; named edits do not.
|
|
137
126
|
*/
|
|
138
127
|
hasOutputEdits: boolean;
|
|
139
128
|
/** Whether there's an undoable change in history. */
|
|
140
129
|
hasUndo: boolean;
|
|
141
130
|
/** Whether there's a redoable change in history. */
|
|
142
131
|
hasRedo: boolean;
|
|
143
|
-
/** Undo the last committed
|
|
132
|
+
/** Undo the last committed change across all slices. */
|
|
144
133
|
undo: () => void;
|
|
145
|
-
/** Redo the last undone
|
|
134
|
+
/** Redo the last undone change across all slices. */
|
|
146
135
|
redo: () => void;
|
|
147
136
|
/**
|
|
148
|
-
* Open a gesture boundary. During a gesture all
|
|
149
|
-
*
|
|
150
|
-
*
|
|
137
|
+
* Open a gesture boundary. During a gesture all changes coalesce
|
|
138
|
+
* into one undo entry — the snapshot taken at `beginGesture`. Pair
|
|
139
|
+
* with `endGesture` on pointer-up / key-up.
|
|
151
140
|
*/
|
|
152
141
|
beginGesture: () => void;
|
|
153
142
|
/** Close a gesture boundary and commit the pre-gesture snapshot. */
|
|
@@ -157,24 +146,23 @@ export interface MediaEditorSession {
|
|
|
157
146
|
/**
|
|
158
147
|
* The media editor session.
|
|
159
148
|
*
|
|
160
|
-
* Owns the only undo/redo history for the editor.
|
|
161
|
-
*
|
|
162
|
-
*
|
|
149
|
+
* Owns the only undo/redo history for the editor. The image editor's state,
|
|
150
|
+
* the sidebar crop options and named edits are slices of one state, so
|
|
151
|
+
* one history stack covers them all. The image editor works out its own
|
|
152
|
+
* changes and reports each next state through `onChange`.
|
|
163
153
|
*
|
|
164
154
|
* History semantics:
|
|
165
|
-
* - Each
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* - During a gesture (`beginGesture` → `endGesture`)
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* -
|
|
172
|
-
*
|
|
173
|
-
* undo entries.
|
|
155
|
+
* - Each change pushes its pre-state to the undo stack, unless a
|
|
156
|
+
* gesture is open or the change is a no-op (post-state value-equal
|
|
157
|
+
* to pre-state).
|
|
158
|
+
* - During a gesture (`beginGesture` → `endGesture`) changes coalesce:
|
|
159
|
+
* only the pre-gesture snapshot is pushed, at gesture end. Undo and
|
|
160
|
+
* redo close an open gesture first.
|
|
161
|
+
* - Changes the image editor marks as not edits (an image loading, a refit
|
|
162
|
+
* after a window resize) are never recorded.
|
|
174
163
|
*
|
|
175
|
-
* `isDirty` tracks the full
|
|
176
|
-
*
|
|
177
|
-
* needs saving.
|
|
164
|
+
* `isDirty` tracks the full session, including undoable UI state. Use
|
|
165
|
+
* `hasOutputEdits` when deciding whether the image output needs saving.
|
|
178
166
|
*
|
|
179
167
|
* The session starts empty. Call `setSourceImage` to load an image.
|
|
180
168
|
*
|
|
@@ -182,36 +170,29 @@ export interface MediaEditorSession {
|
|
|
182
170
|
*/
|
|
183
171
|
export function useMediaEditorState(): MediaEditorSession {
|
|
184
172
|
const [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>
|
|
185
|
-
buildInitialMediaEditorState(
|
|
173
|
+
buildInitialMediaEditorState( createImageEditorState() )
|
|
186
174
|
);
|
|
187
175
|
|
|
188
176
|
// The "clean" snapshot the current state is compared against for
|
|
189
|
-
// `isDirty`.
|
|
190
|
-
//
|
|
191
|
-
// a new image establishes a fresh baseline.
|
|
177
|
+
// `isDirty`. `setSourceImage` refreshes it when a new image starts a
|
|
178
|
+
// fresh session.
|
|
192
179
|
const [ initialBaseline, setInitialBaseline ] =
|
|
193
180
|
useState< MediaEditorState >( () => state );
|
|
194
181
|
|
|
195
|
-
// Latest
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
// synchronously, so multiple actions in one event see the latest
|
|
199
|
-
// reducer output before React commits.
|
|
182
|
+
// Latest state, so several actions in one event see each other's
|
|
183
|
+
// output before React commits. Every mutation path writes it
|
|
184
|
+
// synchronously.
|
|
200
185
|
const stateRef = useRef( state );
|
|
201
|
-
const visualSizeRef = useRef< Size >( { width: 0, height: 0 } );
|
|
202
186
|
|
|
203
|
-
// History stacks: full
|
|
204
|
-
//
|
|
205
|
-
// indicators for undo/redo buttons.
|
|
187
|
+
// History stacks: full snapshots. Refs avoid re-renders on every
|
|
188
|
+
// push; a boolean state pair drives the undo/redo indicators.
|
|
206
189
|
const historyRef = useRef< MediaEditorState[] >( [] );
|
|
207
190
|
const redoStackRef = useRef< MediaEditorState[] >( [] );
|
|
208
191
|
const [ hasUndo, setHasUndo ] = useState( false );
|
|
209
192
|
const [ hasRedo, setHasRedo ] = useState( false );
|
|
210
193
|
|
|
211
|
-
// Gesture state. While open, the first
|
|
212
|
-
//
|
|
213
|
-
// `endGesture` pushes the captured snapshot (or nothing, if the
|
|
214
|
-
// gesture produced no changes).
|
|
194
|
+
// Gesture state. While open, the first change captures the
|
|
195
|
+
// pre-gesture snapshot; later changes don't push.
|
|
215
196
|
const isGestureOpenRef = useRef( false );
|
|
216
197
|
const gestureSnapshotRef = useRef< MediaEditorState | null >( null );
|
|
217
198
|
|
|
@@ -226,22 +207,20 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
226
207
|
setHasRedo( false );
|
|
227
208
|
}, [] );
|
|
228
209
|
|
|
229
|
-
// Core dispatch wrapper. Synchronously computes the post-state via
|
|
230
|
-
// the pure reducer so we can skip history pushes for no-op actions
|
|
231
|
-
// and keep `stateRef` in lockstep with React's pending state.
|
|
232
210
|
const dispatchWithHistory = useCallback(
|
|
233
211
|
( action: MediaEditorAction, recordHistory = true ) => {
|
|
234
212
|
const preState = stateRef.current;
|
|
235
213
|
const postState = mediaEditorReducer( preState, action );
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
pushSnapshot( preState );
|
|
214
|
+
if (
|
|
215
|
+
recordHistory &&
|
|
216
|
+
! areMediaEditorStatesEqual( preState, postState )
|
|
217
|
+
) {
|
|
218
|
+
if ( isGestureOpenRef.current ) {
|
|
219
|
+
if ( gestureSnapshotRef.current === null ) {
|
|
220
|
+
gestureSnapshotRef.current = preState;
|
|
244
221
|
}
|
|
222
|
+
} else {
|
|
223
|
+
pushSnapshot( preState );
|
|
245
224
|
}
|
|
246
225
|
}
|
|
247
226
|
stateRef.current = postState;
|
|
@@ -258,8 +237,8 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
258
237
|
gestureSnapshotRef.current = null;
|
|
259
238
|
}, [] );
|
|
260
239
|
|
|
261
|
-
// Close a gesture (or flush a pending one before undo/redo).
|
|
262
|
-
//
|
|
240
|
+
// Close a gesture (or flush a pending one before undo/redo). Pushes
|
|
241
|
+
// the pre-gesture snapshot only if it differs from the current
|
|
263
242
|
// state. Safe to call when no gesture is open.
|
|
264
243
|
const endGesture = useCallback( () => {
|
|
265
244
|
const snapshot = gestureSnapshotRef.current;
|
|
@@ -273,95 +252,95 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
273
252
|
isGestureOpenRef.current = false;
|
|
274
253
|
}, [ pushSnapshot ] );
|
|
275
254
|
|
|
276
|
-
//
|
|
277
|
-
//
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
255
|
+
// Run several changes as one undo entry, unless a gesture is already
|
|
256
|
+
// open, which groups them anyway.
|
|
257
|
+
const asOneUndoEntry = useCallback(
|
|
258
|
+
( run: () => void ) => {
|
|
259
|
+
if ( isGestureOpenRef.current ) {
|
|
260
|
+
run();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
beginGesture();
|
|
264
|
+
run();
|
|
265
|
+
endGesture();
|
|
285
266
|
},
|
|
286
|
-
[
|
|
267
|
+
[ beginGesture, endGesture ]
|
|
287
268
|
);
|
|
288
269
|
|
|
289
|
-
const
|
|
290
|
-
() =>
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
270
|
+
const setSourceImage = useCallback(
|
|
271
|
+
( image: ImageEditorState[ 'image' ] ) => {
|
|
272
|
+
if ( areImagesEqual( stateRef.current.imageEditor.image, image ) ) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
// New image = fresh session: default crop and crop options, a
|
|
276
|
+
// clean baseline, and no history. Edits made against one
|
|
277
|
+
// image must not survive onto another.
|
|
278
|
+
const next = buildInitialMediaEditorState(
|
|
279
|
+
createImageEditorState( { image } )
|
|
280
|
+
);
|
|
281
|
+
stateRef.current = next;
|
|
282
|
+
dispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );
|
|
283
|
+
setInitialBaseline( next );
|
|
284
|
+
isGestureOpenRef.current = false;
|
|
285
|
+
gestureSnapshotRef.current = null;
|
|
286
|
+
historyRef.current = [];
|
|
287
|
+
redoStackRef.current = [];
|
|
288
|
+
setHasUndo( false );
|
|
289
|
+
setHasRedo( false );
|
|
290
|
+
},
|
|
291
|
+
[]
|
|
296
292
|
);
|
|
297
293
|
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
isGestureOpenRef.current = false;
|
|
314
|
-
gestureSnapshotRef.current = null;
|
|
315
|
-
historyRef.current = [];
|
|
316
|
-
redoStackRef.current = [];
|
|
317
|
-
setHasUndo( false );
|
|
318
|
-
setHasRedo( false );
|
|
319
|
-
}, [] );
|
|
320
|
-
|
|
321
|
-
const resetCropper = useCallback(
|
|
322
|
-
( resetState?: Partial< CropperState > ) => {
|
|
323
|
-
dispatchWithHistory( {
|
|
324
|
-
type: 'CROPPER',
|
|
325
|
-
action: { type: 'RESET', payload: resetState },
|
|
326
|
-
} );
|
|
294
|
+
const handleImageEditorChange = useCallback(
|
|
295
|
+
( nextState: ImageEditorState, { isEdit }: { isEdit: boolean } ) => {
|
|
296
|
+
if (
|
|
297
|
+
! areImagesEqual(
|
|
298
|
+
stateRef.current.imageEditor.image,
|
|
299
|
+
nextState.image
|
|
300
|
+
)
|
|
301
|
+
) {
|
|
302
|
+
setSourceImage( nextState.image );
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
dispatchWithHistory(
|
|
306
|
+
{ type: 'SET_IMAGE_EDITOR', payload: nextState },
|
|
307
|
+
isEdit
|
|
308
|
+
);
|
|
327
309
|
},
|
|
328
|
-
[ dispatchWithHistory ]
|
|
310
|
+
[ dispatchWithHistory, setSourceImage ]
|
|
329
311
|
);
|
|
330
312
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
313
|
+
const imageEditorController = useImageEditor( {
|
|
314
|
+
state: state.imageEditor,
|
|
315
|
+
onChange: handleImageEditorChange,
|
|
316
|
+
} );
|
|
334
317
|
|
|
318
|
+
// The locked ratio has two owners: the preset the sidebar shows, and
|
|
319
|
+
// the number the image editor holds. This is the only path that sets
|
|
320
|
+
// both, so call it rather than `imageEditor.setAspectRatio`, which
|
|
321
|
+
// would leave the sidebar showing a ratio the crop no longer has.
|
|
335
322
|
const setAspectRatioValue = useCallback(
|
|
336
323
|
( presetKey: string ) => {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
324
|
+
asOneUndoEntry( () => {
|
|
325
|
+
dispatchWithHistory( {
|
|
326
|
+
type: 'SET_ASPECT_RATIO_VALUE',
|
|
327
|
+
payload: presetKey,
|
|
328
|
+
} );
|
|
329
|
+
imageEditorController.setAspectRatio(
|
|
330
|
+
resolveAspectRatio(
|
|
331
|
+
presetKey,
|
|
332
|
+
stateRef.current.imageEditor.image
|
|
333
|
+
)
|
|
334
|
+
);
|
|
348
335
|
} );
|
|
349
336
|
},
|
|
350
|
-
[ dispatchWithHistory ]
|
|
337
|
+
[ asOneUndoEntry, dispatchWithHistory, imageEditorController ]
|
|
351
338
|
);
|
|
352
339
|
|
|
353
|
-
// =====================================================================
|
|
354
|
-
// Session
|
|
355
|
-
// =====================================================================
|
|
356
|
-
|
|
357
340
|
const reset = useCallback( () => {
|
|
358
341
|
dispatchWithHistory( { type: 'RESET' } );
|
|
359
342
|
}, [ dispatchWithHistory ] );
|
|
360
343
|
|
|
361
|
-
// =====================================================================
|
|
362
|
-
// Edits-slice setters
|
|
363
|
-
// =====================================================================
|
|
364
|
-
|
|
365
344
|
const setEdit = useCallback(
|
|
366
345
|
( name: string, value: EditValue | undefined ) => {
|
|
367
346
|
dispatchWithHistory( {
|
|
@@ -372,10 +351,6 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
372
351
|
[ dispatchWithHistory ]
|
|
373
352
|
);
|
|
374
353
|
|
|
375
|
-
// =====================================================================
|
|
376
|
-
// History
|
|
377
|
-
// =====================================================================
|
|
378
|
-
|
|
379
354
|
const undo = useCallback( () => {
|
|
380
355
|
endGesture();
|
|
381
356
|
const prev = historyRef.current[ historyRef.current.length - 1 ];
|
|
@@ -404,77 +379,16 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
404
379
|
dispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );
|
|
405
380
|
}, [ endGesture ] );
|
|
406
381
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
const setVisualSize = useCallback( ( size: Size ) => {
|
|
412
|
-
visualSizeRef.current = size;
|
|
413
|
-
}, [] );
|
|
414
|
-
|
|
415
|
-
const adjustCropRectForViewport = useCallback(
|
|
416
|
-
( rect: NormalizedRect ) => {
|
|
417
|
-
dispatchWithHistory(
|
|
418
|
-
{ type: 'VIEWPORT_ADJUST_CROP_RECT', payload: rect },
|
|
419
|
-
false
|
|
420
|
-
);
|
|
421
|
-
},
|
|
422
|
-
[ dispatchWithHistory ]
|
|
382
|
+
const imageEditor = useMemo< ImageEditorController >(
|
|
383
|
+
() => ( { ...imageEditorController, setImage: setSourceImage } ),
|
|
384
|
+
[ imageEditorController, setSourceImage ]
|
|
423
385
|
);
|
|
424
386
|
|
|
425
|
-
// =====================================================================
|
|
426
|
-
// Derived
|
|
427
|
-
// =====================================================================
|
|
428
|
-
|
|
429
387
|
const isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );
|
|
430
|
-
const isCropperDirty = ! areCropperStatesEqual(
|
|
431
|
-
state.cropper,
|
|
432
|
-
initialBaseline.cropper
|
|
433
|
-
);
|
|
434
|
-
|
|
435
|
-
const getCroppedImage = useCallback(
|
|
436
|
-
( mimeType?: string, quality?: number ): Promise< Blob > => {
|
|
437
|
-
if ( ! state.cropper.image ) {
|
|
438
|
-
return Promise.reject(
|
|
439
|
-
new Error( 'No image loaded — call setSourceImage first.' )
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
return exportCroppedImage(
|
|
443
|
-
state.cropper.image.src,
|
|
444
|
-
state.cropper,
|
|
445
|
-
mimeType,
|
|
446
|
-
quality
|
|
447
|
-
);
|
|
448
|
-
},
|
|
449
|
-
[ state.cropper ]
|
|
450
|
-
);
|
|
451
|
-
|
|
452
|
-
const cropper = useMemo< CropperController >(
|
|
453
|
-
() => ( {
|
|
454
|
-
...cropperSetters,
|
|
455
|
-
state: state.cropper,
|
|
456
|
-
setImage: setSourceImage,
|
|
457
|
-
reset: resetCropper,
|
|
458
|
-
isDirty: isCropperDirty,
|
|
459
|
-
getCroppedImage,
|
|
460
|
-
setVisualSize,
|
|
461
|
-
adjustCropRectForViewport,
|
|
462
|
-
} ),
|
|
463
|
-
[
|
|
464
|
-
cropperSetters,
|
|
465
|
-
state.cropper,
|
|
466
|
-
setSourceImage,
|
|
467
|
-
resetCropper,
|
|
468
|
-
isCropperDirty,
|
|
469
|
-
getCroppedImage,
|
|
470
|
-
setVisualSize,
|
|
471
|
-
adjustCropRectForViewport,
|
|
472
|
-
]
|
|
473
|
-
);
|
|
474
388
|
|
|
475
|
-
|
|
389
|
+
return useMemo(
|
|
476
390
|
() => ( {
|
|
477
|
-
|
|
391
|
+
imageEditor,
|
|
478
392
|
cropOptions: state.cropOptions,
|
|
479
393
|
setAspectRatioValue,
|
|
480
394
|
edits: state.edits,
|
|
@@ -482,8 +396,16 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
482
396
|
setSourceImage,
|
|
483
397
|
reset,
|
|
484
398
|
isDirty,
|
|
485
|
-
// Only
|
|
486
|
-
|
|
399
|
+
// Only the crop changes the saved image so far.
|
|
400
|
+
//
|
|
401
|
+
// This reads the image editor's own clean state, not the
|
|
402
|
+
// session's. The two agree because the session only ever
|
|
403
|
+
// replaces the editor's slice with a state the editor handed
|
|
404
|
+
// out, and because a fresh state for an image matches the
|
|
405
|
+
// default one on every field `isDirty` compares. Change
|
|
406
|
+
// either and this has to compare against the session's
|
|
407
|
+
// baseline instead.
|
|
408
|
+
hasOutputEdits: imageEditor.isDirty,
|
|
487
409
|
hasUndo,
|
|
488
410
|
hasRedo,
|
|
489
411
|
undo,
|
|
@@ -492,7 +414,7 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
492
414
|
endGesture,
|
|
493
415
|
} ),
|
|
494
416
|
[
|
|
495
|
-
|
|
417
|
+
imageEditor,
|
|
496
418
|
state.cropOptions,
|
|
497
419
|
setAspectRatioValue,
|
|
498
420
|
state.edits,
|
|
@@ -500,7 +422,6 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
500
422
|
setSourceImage,
|
|
501
423
|
reset,
|
|
502
424
|
isDirty,
|
|
503
|
-
isCropperDirty,
|
|
504
425
|
hasUndo,
|
|
505
426
|
hasRedo,
|
|
506
427
|
undo,
|
|
@@ -509,5 +430,4 @@ export function useMediaEditorState(): MediaEditorSession {
|
|
|
509
430
|
endGesture,
|
|
510
431
|
]
|
|
511
432
|
);
|
|
512
|
-
return session;
|
|
513
433
|
}
|
package/src/style.scss
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Import component styles
|
|
2
2
|
@use "./components/media-preview/style.scss" as *;
|
|
3
|
-
@use "
|
|
3
|
+
@use "@wordpress/image-editor/build-style/style.css" as *;
|
|
4
4
|
@use "./components/media-editor/style.scss" as *;
|
|
5
5
|
@use "./components/media-form/style.scss" as *;
|
|
6
6
|
@use "./components/media-editor-modal/style.scss" as *;
|
|
7
7
|
@use "./components/media-editor-canvas/style.scss" as *;
|
|
8
8
|
@use "./components/media-editor-image-controls/style.scss" as *;
|
|
9
|
+
@use "./components/media-editor-crop-panel/style.scss" as *;
|
|
9
10
|
@use "./components/media-editor-keyboard-shortcuts-modal/style.scss" as *;
|
|
10
11
|
@use "./components/rotation-ruler/style.scss" as *;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
/** The media types the editor tells apart, by MIME type prefix. */
|
|
2
|
+
export const MEDIA_TYPES = [
|
|
3
|
+
'image',
|
|
4
|
+
'video',
|
|
5
|
+
'audio',
|
|
6
|
+
'application',
|
|
7
|
+
] as const;
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* Media type result.
|
|
3
11
|
*/
|
|
4
12
|
export interface MediaType {
|
|
5
|
-
type:
|
|
13
|
+
type: ( typeof MEDIA_TYPES )[ number ];
|
|
6
14
|
}
|
|
7
15
|
|
|
8
16
|
/**
|
package/src/utils/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getMediaTypeFromMimeType } from './get-media-type';
|
|
1
|
+
export { getMediaTypeFromMimeType, MEDIA_TYPES } from './get-media-type';
|
|
2
2
|
export type { MediaType } from './get-media-type';
|