@wordpress/media-editor 0.21.0 → 0.23.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 +30 -0
- package/build/components/media-editor/index.cjs +586 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +42 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +131 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +117 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +81 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +61 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +181 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +82 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +113 -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/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 +59 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +100 -113
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +22 -45
- 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 +11 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +227 -296
- 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 +545 -675
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +37 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +95 -98
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +171 -238
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +74 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -90
- 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/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 +53 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +80 -91
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +3 -26
- 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 +7 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +223 -288
- 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 +145 -61
- package/build-style/style.css +144 -61
- package/build-types/components/media-editor/index.d.ts +20 -2
- 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-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/state/aspect-ratio-presets.d.ts +24 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- 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 -4
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -63
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +355 -167
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +9 -10
- package/src/components/media-editor/use-save-media-editor.ts +48 -10
- package/src/components/media-editor-canvas/index.tsx +30 -51
- 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 +15 -11
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +65 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +9 -5
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +37 -0
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -17
- package/src/state/types.ts +18 -72
- package/src/state/use-media-editor-state.ts +155 -238
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
- package/build/image-editor/core/camera.cjs +0 -225
- package/build/image-editor/core/camera.cjs.map +0 -7
- package/build/image-editor/core/constants.cjs +0 -108
- package/build/image-editor/core/constants.cjs.map +0 -7
- package/build/image-editor/core/containment.cjs +0 -276
- package/build/image-editor/core/containment.cjs.map +0 -7
- package/build/image-editor/core/crop-rect.cjs +0 -48
- package/build/image-editor/core/crop-rect.cjs.map +0 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
- package/build/image-editor/core/index.cjs +0 -62
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/interaction-controller.cjs +0 -654
- package/build/image-editor/core/interaction-controller.cjs.map +0 -7
- package/build/image-editor/core/math/rotation.cjs +0 -41
- package/build/image-editor/core/math/rotation.cjs.map +0 -7
- package/build/image-editor/core/math/sanitize.cjs +0 -92
- package/build/image-editor/core/math/sanitize.cjs.map +0 -7
- package/build/image-editor/core/setter-helpers.cjs +0 -64
- package/build/image-editor/core/setter-helpers.cjs.map +0 -7
- package/build/image-editor/core/source-region.cjs +0 -206
- package/build/image-editor/core/source-region.cjs.map +0 -7
- package/build/image-editor/core/state.cjs +0 -283
- package/build/image-editor/core/state.cjs.map +0 -7
- package/build/image-editor/core/stencil-math.cjs +0 -216
- package/build/image-editor/core/stencil-math.cjs.map +0 -7
- package/build/image-editor/core/transform-style.cjs +0 -52
- package/build/image-editor/core/transform-style.cjs.map +0 -7
- package/build/image-editor/core/transforms/pipeline.cjs +0 -43
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
- package/build/image-editor/core/types.cjs +0 -19
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/core/viewport-state.cjs +0 -50
- package/build/image-editor/core/viewport-state.cjs.map +0 -7
- package/build/image-editor/index.cjs +0 -67
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/cropper-provider.cjs +0 -50
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
- package/build/image-editor/react/components/cropper.cjs +0 -722
- package/build/image-editor/react/components/cropper.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs +0 -36
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
- package/build/image-editor/react/components/viewport-provider.cjs +0 -51
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs +0 -34
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
- package/build/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.cjs +0 -213
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
- package/build/image-editor/react/visually-hidden-style.cjs +0 -41
- package/build/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.mjs +0 -66
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
- package/build-module/image-editor/core/camera.mjs +0 -198
- package/build-module/image-editor/core/camera.mjs.map +0 -7
- package/build-module/image-editor/core/constants.mjs +0 -69
- package/build-module/image-editor/core/constants.mjs.map +0 -7
- package/build-module/image-editor/core/containment.mjs +0 -253
- package/build-module/image-editor/core/containment.mjs.map +0 -7
- package/build-module/image-editor/core/crop-rect.mjs +0 -23
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
- package/build-module/image-editor/core/index.mjs +0 -36
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -635
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
- package/build-module/image-editor/core/math/rotation.mjs +0 -15
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
- package/build-module/image-editor/core/math/sanitize.mjs +0 -63
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
- package/build-module/image-editor/core/setter-helpers.mjs +0 -39
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
- package/build-module/image-editor/core/source-region.mjs +0 -178
- package/build-module/image-editor/core/source-region.mjs.map +0 -7
- package/build-module/image-editor/core/state.mjs +0 -260
- package/build-module/image-editor/core/state.mjs.map +0 -7
- package/build-module/image-editor/core/stencil-math.mjs +0 -187
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
- package/build-module/image-editor/core/transform-style.mjs +0 -27
- package/build-module/image-editor/core/transform-style.mjs.map +0 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/core/viewport-state.mjs +0 -24
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
- package/build-module/image-editor/index.mjs +0 -39
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper.mjs +0 -704
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs +0 -9
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs +0 -8
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
- package/build-module/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.mjs +0 -190
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
- package/build-module/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.d.ts +0 -80
- 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 -99
- 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 -16
- 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 -63
- 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-reducer.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-reducer.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 -161
- 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 -150
- 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 -47
- 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 -52
- 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 -1116
- 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-reducer.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
|
@@ -51,8 +51,13 @@
|
|
|
51
51
|
// canvas takes whatever the 320px panel leaves — about 200px at
|
|
52
52
|
// 600px, 380px at 782px. Cramped, but a cramped preview beside
|
|
53
53
|
// reachable controls beats a panel that hides the image outright.
|
|
54
|
+
// The right gutter goes when the sidebar opens beside the canvas. It
|
|
55
|
+
// moves with the sidebar's width animation, so it uses the same
|
|
56
|
+
// duration and easing.
|
|
54
57
|
@include break-small() {
|
|
55
58
|
margin: 0 $grid-unit-30;
|
|
59
|
+
transition: margin-right 0.3s cubic-bezier(0.6, 0, 0.4, 1);
|
|
60
|
+
@include reduce-motion("transition");
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
// Promise the canvas a floor only where the body is wide enough to
|
|
@@ -123,6 +128,20 @@
|
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
|
|
131
|
+
// Animates its width when the sidebar opens or closes. The sidebar keeps
|
|
132
|
+
// its own width inside, so its contents are clipped rather than reflowed.
|
|
133
|
+
.media-editor__sidebar-container {
|
|
134
|
+
display: flex;
|
|
135
|
+
flex: 1;
|
|
136
|
+
min-width: 0;
|
|
137
|
+
min-height: 0;
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
|
|
140
|
+
@include break-small() {
|
|
141
|
+
flex: none;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
126
145
|
// Settings panel. Below `small` it takes the whole body: there is no room
|
|
127
146
|
// to put a 320px column beside a canvas worth looking at, and that is
|
|
128
147
|
// also where the transform controls fall back to a row under the canvas.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useMemo } from '@wordpress/element';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_ASPECT_RATIOS,
|
|
4
|
+
type AspectRatioPreset,
|
|
5
|
+
} from '../../state/aspect-ratio-presets';
|
|
6
|
+
import { useMediaEditor } from '../../state';
|
|
5
7
|
|
|
6
8
|
interface UseCropOptionsArgs {
|
|
7
9
|
aspectRatioPresets?: AspectRatioPreset[];
|
|
@@ -35,8 +37,7 @@ export function getAspectRatioOptions(
|
|
|
35
37
|
/**
|
|
36
38
|
* Thin selector over the composite media-editor store for the Crop
|
|
37
39
|
* sidebar tab. Reads the cropOptions slice (preset key) and exposes
|
|
38
|
-
* the corresponding setters plus
|
|
39
|
-
* derivation.
|
|
40
|
+
* the corresponding setters plus the ratio the image editor has locked.
|
|
40
41
|
*
|
|
41
42
|
* No local React state, no refs, no synchronization effects — the
|
|
42
43
|
* composite store is the single source of truth.
|
|
@@ -49,17 +50,15 @@ export function useCropOptions( {
|
|
|
49
50
|
}: UseCropOptionsArgs = {} ): UseCropOptionsReturn {
|
|
50
51
|
const controller = useMediaEditor();
|
|
51
52
|
const { aspectRatioValue } = controller.cropOptions;
|
|
52
|
-
const cropperImage = controller.cropper.state.image;
|
|
53
53
|
|
|
54
54
|
const aspectRatioOptions = useMemo(
|
|
55
55
|
() => getAspectRatioOptions( aspectRatioPresets ),
|
|
56
56
|
[ aspectRatioPresets ]
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
59
|
+
// The image editor owns the locked ratio; the preset is what the
|
|
60
|
+
// dropdown shows.
|
|
61
|
+
const resolvedAspectRatio = controller.imageEditor.state.aspectRatio;
|
|
63
62
|
|
|
64
63
|
return {
|
|
65
64
|
aspectRatioValue,
|
|
@@ -4,12 +4,36 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
4
4
|
import { useCallback, useState } from '@wordpress/element';
|
|
5
5
|
import { __, sprintf } from '@wordpress/i18n';
|
|
6
6
|
import { store as noticesStore } from '@wordpress/notices';
|
|
7
|
+
import { getImageEdit, mapImageEdit } from '@wordpress/image-editor';
|
|
7
8
|
import type { Media } from '../media-editor-provider';
|
|
8
9
|
import type { MediaEditorSession } from '../../state';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A single modifier in the Core REST `/edit` payload. Order is
|
|
13
|
+
* significant — the server applies modifiers sequentially (see
|
|
14
|
+
* `WP_REST_Attachments_Controller::edit_media_item`).
|
|
15
|
+
*
|
|
16
|
+
* Shape/units:
|
|
17
|
+
* - `flip`: booleans per axis.
|
|
18
|
+
* - `rotate`: `angle` in degrees, clockwise-positive (matches the
|
|
19
|
+
* image editor's own convention; Core negates it internally for
|
|
20
|
+
* `WP_Image_Editor::rotate`, which is counterclockwise-positive).
|
|
21
|
+
* - `crop`: percentages (0–100) of the image's dimensions **at the
|
|
22
|
+
* moment the crop is applied**. Because modifiers are applied in
|
|
23
|
+
* order, after a preceding `rotate` the server's
|
|
24
|
+
* `WP_Image_Editor::get_size()` reports the full post-rotate AABB,
|
|
25
|
+
* so the percentages are of that AABB. Origin is top-left.
|
|
26
|
+
*/
|
|
27
|
+
type Modifier =
|
|
28
|
+
| {
|
|
29
|
+
type: 'flip';
|
|
30
|
+
args: { flip: { horizontal: boolean; vertical: boolean } };
|
|
31
|
+
}
|
|
32
|
+
| { type: 'rotate'; args: { angle: number } }
|
|
33
|
+
| {
|
|
34
|
+
type: 'crop';
|
|
35
|
+
args: { left: number; top: number; width: number; height: number };
|
|
36
|
+
};
|
|
13
37
|
|
|
14
38
|
// Details-tab edits are bundled into transformed `/edit` requests. Core's
|
|
15
39
|
// endpoint only accepts this whitelist.
|
|
@@ -62,13 +86,27 @@ interface UseSaveMediaEditorReturn {
|
|
|
62
86
|
}
|
|
63
87
|
|
|
64
88
|
function getCropModifiers( session: MediaEditorSession ): Modifier[] {
|
|
65
|
-
|
|
66
|
-
|
|
89
|
+
if ( ! session.hasOutputEdits ) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const edit = getImageEdit( session.imageEditor.state );
|
|
93
|
+
if ( ! edit ) {
|
|
67
94
|
return [];
|
|
68
95
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
96
|
+
|
|
97
|
+
// Core applies modifiers in the order they arrive.
|
|
98
|
+
return mapImageEdit< Modifier >( edit, {
|
|
99
|
+
flip: ( flip ) => ( { type: 'flip', args: { flip } } ),
|
|
100
|
+
rotation: ( angle ) => ( { type: 'rotate', args: { angle } } ),
|
|
101
|
+
crop: ( { x, y, width, height } ) => ( {
|
|
102
|
+
type: 'crop',
|
|
103
|
+
args: {
|
|
104
|
+
left: x * 100,
|
|
105
|
+
top: y * 100,
|
|
106
|
+
width: width * 100,
|
|
107
|
+
height: height * 100,
|
|
108
|
+
},
|
|
109
|
+
} ),
|
|
72
110
|
} );
|
|
73
111
|
}
|
|
74
112
|
|
|
@@ -194,7 +232,7 @@ export function useSaveMediaEditor( {
|
|
|
194
232
|
|
|
195
233
|
if ( next && next.id ) {
|
|
196
234
|
if ( next.id === id ) {
|
|
197
|
-
session.
|
|
235
|
+
session.reset();
|
|
198
236
|
}
|
|
199
237
|
onSaved?.( {
|
|
200
238
|
id: next.id,
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
|
-
import { useCallback, useEffect,
|
|
2
|
+
import { useCallback, useEffect, useState } from '@wordpress/element';
|
|
3
3
|
import { Spinner as WCSpinner } from '@wordpress/components';
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { ImageEditorCanvas } from '@wordpress/image-editor';
|
|
5
6
|
import { useMediaEditorContext } from '../media-editor-provider';
|
|
6
7
|
import { getMediaTypeFromMimeType } from '../../utils';
|
|
7
|
-
import {
|
|
8
|
-
import { useMediaEditor, resolveAspectRatio } from '../../state';
|
|
8
|
+
import { useMediaEditor } from '../../state';
|
|
9
9
|
|
|
10
10
|
export interface MediaEditorCanvasProps {
|
|
11
11
|
/** Whether external placement activity should reveal the grid. */
|
|
12
12
|
isPlacementActive?: boolean;
|
|
13
|
-
/** Fires when a canvas
|
|
13
|
+
/** Fires when a canvas gesture begins. */
|
|
14
14
|
onGestureStart?: () => void;
|
|
15
|
-
/** Fires when a canvas
|
|
15
|
+
/** Fires when a canvas gesture ends. */
|
|
16
16
|
onGestureEnd?: () => void;
|
|
17
17
|
/**
|
|
18
18
|
* Disable crop interaction on the canvas. Set while the edit is saving,
|
|
@@ -23,7 +23,7 @@ export interface MediaEditorCanvasProps {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Editing surface for image media in the media editor modal. Pulls
|
|
26
|
-
* its
|
|
26
|
+
* its image editor controller from the surrounding `<MediaEditorStateProvider>`
|
|
27
27
|
* so the bottom bar and Crop sidebar tab share the same state.
|
|
28
28
|
*
|
|
29
29
|
* Returns `null` for missing or non-image media so the modal's outer
|
|
@@ -43,25 +43,17 @@ export default function MediaEditorCanvas( {
|
|
|
43
43
|
}: MediaEditorCanvasProps ) {
|
|
44
44
|
const { media } = useMediaEditorContext();
|
|
45
45
|
const session = useMediaEditor();
|
|
46
|
-
const { aspectRatioValue } = session.cropOptions;
|
|
47
|
-
const cropperImage = session.cropper.state.image;
|
|
48
46
|
const { beginGesture, endGesture, setSourceImage } = session;
|
|
49
47
|
|
|
50
|
-
// Tracks whether the image pixels have actually loaded. The
|
|
48
|
+
// Tracks whether the image pixels have actually loaded. The image editor's
|
|
51
49
|
// geometry is driven by the known media dimensions, so its handles and
|
|
52
50
|
// overlays would otherwise appear before the image finishes streaming in.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// store this number — only the preset key — so it's a render-time
|
|
60
|
-
// derivation here.
|
|
61
|
-
const aspectRatio = useMemo(
|
|
62
|
-
() => resolveAspectRatio( aspectRatioValue, cropperImage ),
|
|
63
|
-
[ aspectRatioValue, cropperImage ]
|
|
64
|
-
);
|
|
51
|
+
// Stored with the URL it is for, so a new URL (restoring the original
|
|
52
|
+
// swaps it in place) counts as loading until the image editor reports back.
|
|
53
|
+
const [ settled, setSettled ] = useState< {
|
|
54
|
+
url: string | undefined;
|
|
55
|
+
status: 'loaded' | 'error';
|
|
56
|
+
} >();
|
|
65
57
|
|
|
66
58
|
const handleGestureStart = useCallback( () => {
|
|
67
59
|
beginGesture();
|
|
@@ -96,29 +88,14 @@ export default function MediaEditorCanvas( {
|
|
|
96
88
|
}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );
|
|
97
89
|
|
|
98
90
|
const isImage = mediaType.type === 'image';
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
setStatus( 'loading' );
|
|
109
|
-
const probe = new window.Image();
|
|
110
|
-
probe.onload = () => setStatus( 'loaded' );
|
|
111
|
-
probe.onerror = () => setStatus( 'error' );
|
|
112
|
-
probe.src = mediaUrl;
|
|
113
|
-
// Cached images may already be complete before listeners attach.
|
|
114
|
-
if ( probe.complete ) {
|
|
115
|
-
setStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );
|
|
116
|
-
}
|
|
117
|
-
return () => {
|
|
118
|
-
probe.onload = null;
|
|
119
|
-
probe.onerror = null;
|
|
120
|
-
};
|
|
121
|
-
}, [ mediaUrl, isImage ] );
|
|
91
|
+
const status =
|
|
92
|
+
settled && settled.url === mediaUrl ? settled.status : 'loading';
|
|
93
|
+
const handleImageLoaded = useCallback( () => {
|
|
94
|
+
setSettled( { url: mediaUrl, status: 'loaded' } );
|
|
95
|
+
}, [ mediaUrl ] );
|
|
96
|
+
const handleImageError = useCallback( () => {
|
|
97
|
+
setSettled( { url: mediaUrl, status: 'error' } );
|
|
98
|
+
}, [ mediaUrl ] );
|
|
122
99
|
|
|
123
100
|
if ( ! mediaUrl || ! isImage ) {
|
|
124
101
|
return null;
|
|
@@ -142,7 +119,7 @@ export default function MediaEditorCanvas( {
|
|
|
142
119
|
</div>
|
|
143
120
|
) }
|
|
144
121
|
{ /*
|
|
145
|
-
* The
|
|
122
|
+
* The image editor stays mounted while loading (hidden behind the
|
|
146
123
|
* spinner) so the image decodes off-screen and reveals in one paint
|
|
147
124
|
* instead of streaming in top-to-bottom. Until it's revealed it's
|
|
148
125
|
* non-interactive (`pointer-events: none` in CSS).
|
|
@@ -152,19 +129,21 @@ export default function MediaEditorCanvas( {
|
|
|
152
129
|
* by tabbing to it.
|
|
153
130
|
*/ }
|
|
154
131
|
<div
|
|
155
|
-
className={ clsx( 'media-editor-
|
|
132
|
+
className={ clsx( 'media-editor-canvas__image-editor', {
|
|
156
133
|
'is-loaded': status === 'loaded',
|
|
157
134
|
} ) }
|
|
158
135
|
>
|
|
159
|
-
<
|
|
136
|
+
<ImageEditorCanvas
|
|
160
137
|
src={ mediaUrl }
|
|
161
|
-
controller={ session.
|
|
162
|
-
aspectRatio={ aspectRatio }
|
|
138
|
+
controller={ session.imageEditor }
|
|
163
139
|
freeformCrop
|
|
164
|
-
|
|
165
|
-
|
|
140
|
+
// Keep the grid up while a sidebar placement control is in
|
|
141
|
+
// use; otherwise show it only while the crop is changing.
|
|
142
|
+
showGrid={ isPlacementActive ? true : 'interactive' }
|
|
166
143
|
onGestureStart={ handleGestureStart }
|
|
167
144
|
onGestureEnd={ handleGestureEnd }
|
|
145
|
+
onImageLoaded={ handleImageLoaded }
|
|
146
|
+
onImageError={ handleImageError }
|
|
168
147
|
disabled={ disabled }
|
|
169
148
|
/>
|
|
170
149
|
</div>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/animations" as *;
|
|
2
2
|
@use "@wordpress/base-styles/colors" as *;
|
|
3
3
|
|
|
4
|
-
// The canvas wrapper fills the modal's canvas area so the
|
|
5
|
-
// sized parent (the
|
|
4
|
+
// The canvas wrapper fills the modal's canvas area so the image editor has a
|
|
5
|
+
// sized parent (the image editor uses 100% width/height of its container).
|
|
6
6
|
// `position: relative` establishes a stacking context for any future
|
|
7
7
|
// overlays rendered inside the canvas.
|
|
8
8
|
.media-editor-canvas {
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
width: 100%;
|
|
11
11
|
height: 100%;
|
|
12
12
|
|
|
13
|
-
// The
|
|
13
|
+
// The image editor stays mounted while loading so the image decodes behind the
|
|
14
14
|
// spinner and reveals in one paint. It's hidden and non-interactive until
|
|
15
15
|
// the image has loaded, then fades in.
|
|
16
|
-
&
|
|
16
|
+
&__image-editor {
|
|
17
17
|
width: 100%;
|
|
18
18
|
height: 100%;
|
|
19
19
|
opacity: 0;
|
|
20
20
|
pointer-events: none;
|
|
21
21
|
|
|
22
22
|
// Explicit `opacity: 1` (not just the animation's fill mode) keeps the
|
|
23
|
-
//
|
|
23
|
+
// image editor visible for reduced-motion users, since `animation__fade-in`
|
|
24
24
|
// is gated behind `@media not (prefers-reduced-motion)`.
|
|
25
25
|
&.is-loaded {
|
|
26
26
|
opacity: 1;
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
transform: translate(-50%, -50%);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// Centered fallback shown in place of the
|
|
39
|
+
// Centered fallback shown in place of the image editor when the image
|
|
40
40
|
// fails to load.
|
|
41
41
|
&__error {
|
|
42
42
|
display: flex;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';
|
|
2
2
|
import { __ } from '@wordpress/i18n';
|
|
3
|
+
import { Icon, getAspectRatioIcon } from '@wordpress/icons';
|
|
4
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
3
5
|
import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
|
|
4
6
|
import MediaEditorImageControls from '../media-editor-image-controls';
|
|
5
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
6
7
|
|
|
7
8
|
export interface MediaEditorCropPanelProps {
|
|
8
9
|
/**
|
|
@@ -66,7 +67,42 @@ export default function MediaEditorCropPanel( {
|
|
|
66
67
|
} }
|
|
67
68
|
disabled={ disabled }
|
|
68
69
|
items={ items }
|
|
69
|
-
|
|
70
|
+
trigger={
|
|
71
|
+
<SelectControl.Trigger>
|
|
72
|
+
{ ( item ) => (
|
|
73
|
+
<span className="media-editor-crop-panel__aspect-ratio-option">
|
|
74
|
+
<Icon
|
|
75
|
+
icon={ getAspectRatioIcon(
|
|
76
|
+
Number( item.value )
|
|
77
|
+
) }
|
|
78
|
+
/>
|
|
79
|
+
<span className="media-editor-crop-panel__aspect-ratio-label">
|
|
80
|
+
{ item.label }
|
|
81
|
+
</span>
|
|
82
|
+
</span>
|
|
83
|
+
) }
|
|
84
|
+
</SelectControl.Trigger>
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
{ items.map( ( item ) => (
|
|
88
|
+
<SelectControl.Item
|
|
89
|
+
key={ item.value }
|
|
90
|
+
value={ item }
|
|
91
|
+
label={ item.label }
|
|
92
|
+
>
|
|
93
|
+
<SelectControl.ItemLabel>
|
|
94
|
+
<span className="media-editor-crop-panel__aspect-ratio-option">
|
|
95
|
+
<Icon
|
|
96
|
+
icon={ getAspectRatioIcon(
|
|
97
|
+
Number( item.value )
|
|
98
|
+
) }
|
|
99
|
+
/>
|
|
100
|
+
{ item.label }
|
|
101
|
+
</span>
|
|
102
|
+
</SelectControl.ItemLabel>
|
|
103
|
+
</SelectControl.Item>
|
|
104
|
+
) ) }
|
|
105
|
+
</SelectControl>
|
|
70
106
|
</Stack>
|
|
71
107
|
);
|
|
72
108
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
2
|
+
|
|
3
|
+
.media-editor-crop-panel__aspect-ratio-option {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: $grid-unit-10;
|
|
7
|
+
// Allow the label to shrink so that it can be truncated.
|
|
8
|
+
min-width: 0;
|
|
9
|
+
|
|
10
|
+
svg {
|
|
11
|
+
flex-shrink: 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The trigger truncates its value with an ellipsis, which doesn't apply
|
|
16
|
+
// through the flex wrapper, so truncate the label itself.
|
|
17
|
+
.media-editor-crop-panel__aspect-ratio-label {
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
text-overflow: ellipsis;
|
|
20
|
+
white-space: nowrap;
|
|
21
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __ } from '@wordpress/i18n';
|
|
2
2
|
import { useMediaEditor } from '../../state';
|
|
3
3
|
import { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';
|
|
4
|
-
import { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';
|
|
5
4
|
import RotationRuler from '../rotation-ruler';
|
|
6
5
|
|
|
7
6
|
export interface MediaEditorFineRotationProps {
|
|
@@ -28,7 +27,8 @@ export default function MediaEditorFineRotation( {
|
|
|
28
27
|
onPlacementControlInteraction,
|
|
29
28
|
disabled = false,
|
|
30
29
|
}: MediaEditorFineRotationProps ) {
|
|
31
|
-
const { state, setRotation } =
|
|
30
|
+
const { state, setRotation, maxRotationOffset } =
|
|
31
|
+
useMediaEditor().imageEditor;
|
|
32
32
|
// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce
|
|
33
33
|
// into one undo entry via the gesture idle window. Pointer-up still
|
|
34
34
|
// closes pointer drags immediately.
|
|
@@ -50,8 +50,8 @@ export default function MediaEditorFineRotation( {
|
|
|
50
50
|
// causing subsequent events to spiral.
|
|
51
51
|
const EPS = 0.01;
|
|
52
52
|
const clamped = Math.max(
|
|
53
|
-
-
|
|
54
|
-
Math.min(
|
|
53
|
+
-maxRotationOffset + EPS,
|
|
54
|
+
Math.min( maxRotationOffset - EPS, value )
|
|
55
55
|
);
|
|
56
56
|
onPlacementControlInteraction?.();
|
|
57
57
|
setRotation( baseAngle + clamped * visualDir );
|
|
@@ -65,8 +65,8 @@ export default function MediaEditorFineRotation( {
|
|
|
65
65
|
>
|
|
66
66
|
<RotationRuler
|
|
67
67
|
label={ __( 'Fine rotation' ) }
|
|
68
|
-
min={ -
|
|
69
|
-
max={
|
|
68
|
+
min={ -maxRotationOffset }
|
|
69
|
+
max={ maxRotationOffset }
|
|
70
70
|
value={ fineOffset }
|
|
71
71
|
onChange={ handleRotationSlider }
|
|
72
72
|
disabled={ disabled }
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Button } from '@wordpress/components';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.
|
|
4
|
+
Menu,
|
|
5
|
+
} from '@wordpress/ui';
|
|
4
6
|
import { __ } from '@wordpress/i18n';
|
|
5
7
|
import {
|
|
6
8
|
aspectRatio as aspectRatioIcon,
|
|
9
|
+
getAspectRatioIcon,
|
|
7
10
|
rotateLeft,
|
|
8
11
|
rotateRight,
|
|
9
12
|
flipHorizontal,
|
|
@@ -12,11 +15,7 @@ import {
|
|
|
12
15
|
plus,
|
|
13
16
|
} from '@wordpress/icons';
|
|
14
17
|
import { useMediaEditor } from '../../state';
|
|
15
|
-
import {
|
|
16
|
-
MAX_ZOOM,
|
|
17
|
-
type AspectRatioPreset,
|
|
18
|
-
} from '../../image-editor/core/constants';
|
|
19
|
-
import { getMinZoom } from '../../image-editor/core/containment';
|
|
18
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
20
19
|
import { useCropOptions } from '../media-editor/use-crop-options';
|
|
21
20
|
|
|
22
21
|
/**
|
|
@@ -77,14 +76,14 @@ export default function MediaEditorImageControls( {
|
|
|
77
76
|
zoomFactor = DEFAULT_ZOOM_FACTOR,
|
|
78
77
|
disabled = false,
|
|
79
78
|
}: MediaEditorImageControlsProps ) {
|
|
80
|
-
const { state, setFlip, snapRotate90, setZoom } =
|
|
79
|
+
const { state, setFlip, snapRotate90, setZoom, minZoom, maxZoom } =
|
|
80
|
+
useMediaEditor().imageEditor;
|
|
81
81
|
const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =
|
|
82
82
|
useCropOptions( { aspectRatioPresets } );
|
|
83
83
|
const hasAspectRatioControl = ! withLabels && showAspectRatioControl;
|
|
84
|
-
const minZoom = getMinZoom( state );
|
|
85
84
|
const zoomByFactor = ( factor: number ) => {
|
|
86
85
|
setZoom(
|
|
87
|
-
Math.min(
|
|
86
|
+
Math.min( maxZoom, Math.max( minZoom, state.zoom * factor ) )
|
|
88
87
|
);
|
|
89
88
|
};
|
|
90
89
|
|
|
@@ -153,7 +152,7 @@ export default function MediaEditorImageControls( {
|
|
|
153
152
|
icon={ plus }
|
|
154
153
|
label={ __( 'Zoom in' ) }
|
|
155
154
|
showTooltip
|
|
156
|
-
disabled={ disabled || state.zoom >=
|
|
155
|
+
disabled={ disabled || state.zoom >= maxZoom }
|
|
157
156
|
accessibleWhenDisabled
|
|
158
157
|
onClick={ () => zoomByFactor( zoomFactor ) }
|
|
159
158
|
/>
|
|
@@ -200,6 +199,11 @@ export default function MediaEditorImageControls( {
|
|
|
200
199
|
value={ preset.value.toString() }
|
|
201
200
|
closeOnClick
|
|
202
201
|
disabled={ disabled }
|
|
202
|
+
prefix={
|
|
203
|
+
<Menu.PrefixIcon
|
|
204
|
+
icon={ getAspectRatioIcon( preset.value ) }
|
|
205
|
+
/>
|
|
206
|
+
}
|
|
203
207
|
>
|
|
204
208
|
<Menu.ItemLabel>{ preset.label }</Menu.ItemLabel>
|
|
205
209
|
</Menu.RadioItem>
|
|
@@ -5,11 +5,11 @@ import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
|
|
|
5
5
|
import { store as noticesStore } from '@wordpress/notices';
|
|
6
6
|
import type { Field, Form } from '@wordpress/dataviews';
|
|
7
7
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
8
|
+
import type { AspectRatioPreset } from '../../state/aspect-ratio-presets';
|
|
8
9
|
import MediaEditor from '../media-editor';
|
|
9
10
|
import type { Media } from '../media-editor-provider';
|
|
10
11
|
import { store as mediaEditorStore } from '../../store';
|
|
11
12
|
import type { MediaEditorModalUpdate } from '../../store/actions';
|
|
12
|
-
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
13
13
|
|
|
14
14
|
interface MediaEditorModalProps {
|
|
15
15
|
/**
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Active (enabled) undo/redo icon buttons take the admin accent colour so
|
|
44
|
-
// they read as live alongside the
|
|
44
|
+
// they read as live alongside the Cancel/Save actions. Disabled
|
|
45
45
|
// buttons (rendered with `aria-disabled` via `accessibleWhenDisabled`)
|
|
46
46
|
// keep the default muted icon colour.
|
|
47
47
|
// Scoped to the modal: the package ships one stylesheet, so an unscoped
|