@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
|
@@ -15,7 +15,7 @@ export interface MediaPreviewProps {
|
|
|
15
15
|
* Props for MediaPreviewContent component.
|
|
16
16
|
*/
|
|
17
17
|
interface MediaPreviewContentProps {
|
|
18
|
-
|
|
18
|
+
previewType: string;
|
|
19
19
|
mediaUrl: string;
|
|
20
20
|
altText?: string;
|
|
21
21
|
displayTitle?: string;
|
|
@@ -25,8 +25,35 @@ interface MediaPreviewContentProps {
|
|
|
25
25
|
loadingState: 'loading' | 'loaded' | 'error';
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
interface MediaPreviewFileInfoProps {
|
|
29
|
+
mediaUrl: string;
|
|
30
|
+
displayTitle?: string;
|
|
31
|
+
mimeType?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function MediaPreviewFileInfo( {
|
|
35
|
+
mediaUrl,
|
|
36
|
+
displayTitle,
|
|
37
|
+
mimeType,
|
|
38
|
+
}: MediaPreviewFileInfoProps ) {
|
|
39
|
+
return (
|
|
40
|
+
<div className="media-editor-preview__file-info">
|
|
41
|
+
<p className="media-editor-preview__file-name">{ displayTitle }</p>
|
|
42
|
+
<p className="media-editor-preview__mime-type">{ mimeType }</p>
|
|
43
|
+
{ /* eslint-disable-next-line react/jsx-no-target-blank */ }
|
|
44
|
+
<a
|
|
45
|
+
href={ mediaUrl }
|
|
46
|
+
target="_blank"
|
|
47
|
+
className="media-editor-preview__download-link"
|
|
48
|
+
>
|
|
49
|
+
{ __( 'View file' ) }
|
|
50
|
+
</a>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
28
55
|
function MediaPreviewContent( {
|
|
29
|
-
|
|
56
|
+
previewType,
|
|
30
57
|
mediaUrl,
|
|
31
58
|
altText,
|
|
32
59
|
displayTitle,
|
|
@@ -35,7 +62,7 @@ function MediaPreviewContent( {
|
|
|
35
62
|
onError,
|
|
36
63
|
loadingState,
|
|
37
64
|
}: MediaPreviewContentProps ) {
|
|
38
|
-
switch (
|
|
65
|
+
switch ( previewType ) {
|
|
39
66
|
case 'image':
|
|
40
67
|
return (
|
|
41
68
|
<img
|
|
@@ -58,25 +85,33 @@ function MediaPreviewContent( {
|
|
|
58
85
|
{ displayTitle }
|
|
59
86
|
</audio>
|
|
60
87
|
);
|
|
88
|
+
case 'pdf':
|
|
89
|
+
// The browser renders the children instead of the PDF when it
|
|
90
|
+
// can't display it, e.g. when the request fails.
|
|
91
|
+
return (
|
|
92
|
+
<object
|
|
93
|
+
className="media-editor-preview__pdf"
|
|
94
|
+
// Ask the viewer to fit the whole page rather than the
|
|
95
|
+
// width. Chrome reads `view`, Firefox reads `zoom`, and
|
|
96
|
+
// Safari ignores both.
|
|
97
|
+
data={ `${ mediaUrl }#view=Fit&zoom=page-fit` }
|
|
98
|
+
type="application/pdf"
|
|
99
|
+
aria-label={ __( 'Embed of the selected PDF file.' ) }
|
|
100
|
+
>
|
|
101
|
+
<MediaPreviewFileInfo
|
|
102
|
+
mediaUrl={ mediaUrl }
|
|
103
|
+
displayTitle={ displayTitle }
|
|
104
|
+
mimeType={ mimeType }
|
|
105
|
+
/>
|
|
106
|
+
</object>
|
|
107
|
+
);
|
|
61
108
|
default:
|
|
62
109
|
return (
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{ mimeType }
|
|
69
|
-
</p>
|
|
70
|
-
{ /* eslint-disable-next-line react/jsx-no-target-blank */ }
|
|
71
|
-
<a
|
|
72
|
-
href={ mediaUrl }
|
|
73
|
-
target="_blank"
|
|
74
|
-
rel="noopener"
|
|
75
|
-
className="media-editor-preview__download-link"
|
|
76
|
-
>
|
|
77
|
-
{ __( 'View file' ) }
|
|
78
|
-
</a>
|
|
79
|
-
</div>
|
|
110
|
+
<MediaPreviewFileInfo
|
|
111
|
+
mediaUrl={ mediaUrl }
|
|
112
|
+
displayTitle={ displayTitle }
|
|
113
|
+
mimeType={ mimeType }
|
|
114
|
+
/>
|
|
80
115
|
);
|
|
81
116
|
}
|
|
82
117
|
}
|
|
@@ -103,6 +138,13 @@ export default function MediaPreview( props: MediaPreviewProps ) {
|
|
|
103
138
|
|
|
104
139
|
const mediaType = getMediaTypeFromMimeType( mimeType );
|
|
105
140
|
|
|
141
|
+
// Without a built-in PDF viewer (e.g. on most mobile browsers), show
|
|
142
|
+
// the file info instead of an embed that can't render.
|
|
143
|
+
const previewType =
|
|
144
|
+
mimeType === 'application/pdf' && window.navigator.pdfViewerEnabled
|
|
145
|
+
? 'pdf'
|
|
146
|
+
: mediaType.type;
|
|
147
|
+
|
|
106
148
|
if ( ! mediaUrl ) {
|
|
107
149
|
return (
|
|
108
150
|
<div className="media-editor-preview media-editor-preview--empty">
|
|
@@ -126,15 +168,15 @@ export default function MediaPreview( props: MediaPreviewProps ) {
|
|
|
126
168
|
return (
|
|
127
169
|
<div
|
|
128
170
|
{ ...props }
|
|
129
|
-
className={ `media-editor-preview media-editor-preview--${
|
|
171
|
+
className={ `media-editor-preview media-editor-preview--${ previewType }` }
|
|
130
172
|
>
|
|
131
|
-
{
|
|
173
|
+
{ previewType === 'image' && loadingState === 'loading' && (
|
|
132
174
|
<div className="media-editor-preview__spinner">
|
|
133
175
|
<WCSpinner />
|
|
134
176
|
</div>
|
|
135
177
|
) }
|
|
136
178
|
<MediaPreviewContent
|
|
137
|
-
|
|
179
|
+
previewType={ previewType }
|
|
138
180
|
mediaUrl={ mediaUrl }
|
|
139
181
|
altText={ altText }
|
|
140
182
|
displayTitle={ displayTitle }
|
|
@@ -48,11 +48,25 @@
|
|
|
48
48
|
max-width: 100%;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
&--
|
|
52
|
-
|
|
51
|
+
&--pdf {
|
|
52
|
+
align-items: stretch;
|
|
53
|
+
width: 100%;
|
|
54
|
+
max-width: $wide-content-width;
|
|
55
|
+
margin-inline: auto;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&__pdf {
|
|
59
|
+
display: flex;
|
|
60
|
+
flex: 1;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
min-width: 0;
|
|
64
|
+
border: 0;
|
|
65
|
+
border-radius: $radius-small;
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
&__file-info {
|
|
69
|
+
text-align: center;
|
|
56
70
|
background: $gray-100;
|
|
57
71
|
padding: $grid-unit-30;
|
|
58
72
|
border-radius: 2px;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
+
@use "@wordpress/base-styles/mixins" as *;
|
|
2
3
|
@use "@wordpress/base-styles/variables" as *;
|
|
3
4
|
|
|
4
5
|
// Default to WordPress core's admin theme blue when the host hasn't
|
|
@@ -17,8 +18,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
17
18
|
height: 32px;
|
|
18
19
|
padding: 0 $grid-unit-10;
|
|
19
20
|
box-sizing: border-box;
|
|
20
|
-
|
|
21
|
-
font-family: $font-family-body;
|
|
21
|
+
font-family: var(--wpds-typography-font-family-body);
|
|
22
22
|
user-select: none;
|
|
23
23
|
touch-action: none;
|
|
24
24
|
cursor: ew-resize;
|
|
@@ -38,8 +38,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
&:has(.rotation-ruler__input:focus-visible) {
|
|
41
|
-
|
|
42
|
-
outline-offset: 2px;
|
|
41
|
+
@include outset-ring__focus();
|
|
43
42
|
border-radius: 4px;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
@@ -70,6 +69,10 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
70
69
|
border-radius: 1px;
|
|
71
70
|
transform: translateX(-50%);
|
|
72
71
|
pointer-events: none;
|
|
72
|
+
|
|
73
|
+
@media (forced-colors: active) {
|
|
74
|
+
background: CanvasText;
|
|
75
|
+
}
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
.rotation-ruler__strip {
|
|
@@ -85,6 +88,8 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
85
88
|
|
|
86
89
|
.rotation-ruler__ticks {
|
|
87
90
|
position: absolute;
|
|
91
|
+
// Keep SVG ticks visible when the browser forces dark colors.
|
|
92
|
+
color: CanvasText;
|
|
88
93
|
// The tick offset is applied as a JS-set inline `transform: translateX()`
|
|
89
94
|
// (see rotation-ruler/index.tsx), which rtlcss can't mirror. If rtlcss
|
|
90
95
|
// flipped this `left` to `right`, the anchor and the transform would
|
|
@@ -141,7 +146,6 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
141
146
|
font-size: 12px;
|
|
142
147
|
font-weight: var(--wpds-typography-font-weight-emphasis);
|
|
143
148
|
line-height: 14px;
|
|
144
|
-
color: $gray-900;
|
|
145
149
|
pointer-events: none;
|
|
146
150
|
|
|
147
151
|
&::before {
|
|
@@ -94,12 +94,9 @@ export function useRulerDrag(
|
|
|
94
94
|
onPointerDownStart,
|
|
95
95
|
} = options;
|
|
96
96
|
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
// effect (not at render time) to satisfy `react-hooks/refs`; the
|
|
101
|
-
// effect flushes after commit, so by the time any pointer handler
|
|
102
|
-
// runs, the ref reflects the latest committed `value`.
|
|
97
|
+
// Per-drag state, including the last emitted value. Pointermove
|
|
98
|
+
// handlers fire far faster than React commits, so they cannot read
|
|
99
|
+
// `value` from closure. Pointerdown seeds it from the committed `value`.
|
|
103
100
|
const latestRef = useRef< {
|
|
104
101
|
value: number;
|
|
105
102
|
startX: number;
|
|
@@ -119,9 +116,6 @@ export function useRulerDrag(
|
|
|
119
116
|
capturePointerId: 0,
|
|
120
117
|
windowPointerUp: null,
|
|
121
118
|
} );
|
|
122
|
-
useEffect( () => {
|
|
123
|
-
latestRef.current.value = value;
|
|
124
|
-
}, [ value ] );
|
|
125
119
|
|
|
126
120
|
const endDrag = useCallback( () => {
|
|
127
121
|
const state = latestRef.current;
|
|
@@ -170,7 +164,8 @@ export function useRulerDrag(
|
|
|
170
164
|
state.captureElement = event.currentTarget;
|
|
171
165
|
state.capturePointerId = event.pointerId;
|
|
172
166
|
state.startX = event.clientX;
|
|
173
|
-
state.
|
|
167
|
+
state.value = value;
|
|
168
|
+
state.startValue = value;
|
|
174
169
|
state.activeStep = event.shiftKey ? step / 2 : step;
|
|
175
170
|
state.dragging = true;
|
|
176
171
|
onPointerDownStart?.();
|
|
@@ -186,7 +181,7 @@ export function useRulerDrag(
|
|
|
186
181
|
window.addEventListener( 'pointerup', onWindowUp );
|
|
187
182
|
window.addEventListener( 'pointercancel', onWindowUp );
|
|
188
183
|
},
|
|
189
|
-
[ disabled, onPointerDownStart, endDrag, step ]
|
|
184
|
+
[ disabled, onPointerDownStart, endDrag, step, value ]
|
|
190
185
|
);
|
|
191
186
|
|
|
192
187
|
const onPointerMove = useCallback(
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Media Editor Session
|
|
2
|
+
|
|
3
|
+
The media editor's session owns its undo and redo history. The image editor's state from `@wordpress/image-editor` is one slice of the session's state, next to the sidebar crop options and named edits, kept through `useImageEditor( { state, onChange } )`, so one history covers them all.
|
|
4
|
+
|
|
5
|
+
`useMediaEditorState()` creates a media editor session; `<MediaEditorStateProvider>` calls it, and `useMediaEditor()` reads the one it made. Calling `useMediaEditorState()` again inside the provider makes a second session that shares nothing with the first, so components use `useMediaEditor()`. The session owns the source image, every editing slice, the shared undo/redo history, gesture boundaries, and whether the edits change the saved image (`hasOutputEdits`). The image editor is one participant: `session.imageEditor` is a geometry-only `ImageEditorController` that an `<ImageEditorCanvas>` takes via its `controller` prop, and its `isDirty` covers geometry alone. Replacing the source image (`setSourceImage`, which the image editor's `setImage` also calls) starts a fresh session with default geometry and crop options, a clean baseline, and no history. Save code asks the session, not the image editor, whether image output needs saving.
|
|
6
|
+
|
|
7
|
+
The session also holds named edits other than crop: `session.edits`, set with `session.setEdit( name, value )` and removed by passing `undefined`. They share the crop history, so undo, redo and gestures treat them like any crop change, and a different source image clears them. Values are plain data (`EditValue`: strings, numbers, booleans, `null`, and arrays and objects of those), because the session compares them by content to tell a real change from a no-op. Edits do not yet count towards `hasOutputEdits`; nothing saves them.
|
|
8
|
+
|
|
9
|
+
`session.reset()` puts every slice back to its starting state in one undo entry: default geometry and crop options, no edits, same image. The Reset button calls it; it does not compose per-slice resets itself.
|
|
10
|
+
|
|
11
|
+
## Use the Session With the Canvas
|
|
12
|
+
|
|
13
|
+
Use the media editor session when image editor state must share history with controls such as aspect ratio. The session owns history and gesture boundaries; pass its `imageEditor` controller to `<ImageEditorCanvas>`.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { ImageEditorCanvas } from '@wordpress/image-editor';
|
|
17
|
+
import { useMediaEditor } from '../state';
|
|
18
|
+
|
|
19
|
+
function MediaEditorCanvas( { src }: { src: string } ) {
|
|
20
|
+
const session = useMediaEditor();
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<ImageEditorCanvas
|
|
24
|
+
src={ src }
|
|
25
|
+
controller={ session.imageEditor }
|
|
26
|
+
freeformCrop
|
|
27
|
+
onGestureStart={ session.beginGesture }
|
|
28
|
+
onGestureEnd={ session.endGesture }
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { __ } from '@wordpress/i18n';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An aspect ratio preset with a human-readable label.
|
|
5
|
+
*/
|
|
6
|
+
export interface AspectRatioPreset {
|
|
7
|
+
/** Display label (e.g., "Square (1:1)"). */
|
|
8
|
+
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* The aspect ratio value (width / height). 0 = free,
|
|
11
|
+
* `ORIGINAL_ASPECT_RATIO` = the image's own ratio.
|
|
12
|
+
*/
|
|
13
|
+
value: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sentinel value for "Original" aspect ratio — resolved at runtime
|
|
18
|
+
* to the image's natural width / height.
|
|
19
|
+
*/
|
|
20
|
+
export const ORIGINAL_ASPECT_RATIO = -1;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The presets the editor offers by default. They live here rather than
|
|
24
|
+
* in the image editor package, because which ratios to offer, and what
|
|
25
|
+
* to call them, is a product choice. The package takes a plain number.
|
|
26
|
+
*/
|
|
27
|
+
export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
|
|
28
|
+
{ label: __( 'Free' ), value: 0 },
|
|
29
|
+
{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },
|
|
30
|
+
{ label: __( 'Square (1:1)' ), value: 1 },
|
|
31
|
+
{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },
|
|
32
|
+
{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },
|
|
33
|
+
{ label: __( 'Classic (4:3)' ), value: 4 / 3 },
|
|
34
|
+
{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },
|
|
35
|
+
{ label: __( 'Photo (3:2)' ), value: 3 / 2 },
|
|
36
|
+
{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },
|
|
37
|
+
];
|
|
@@ -1,81 +1,47 @@
|
|
|
1
1
|
import fastDeepEqual from 'fast-deep-equal/es6/index.js';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '../image-editor';
|
|
3
|
+
areImageEditorStatesEqual,
|
|
4
|
+
createImageEditorState,
|
|
5
|
+
type ImageEditorState,
|
|
6
|
+
} from '@wordpress/image-editor';
|
|
8
7
|
import {
|
|
9
8
|
DEFAULT_CROP_OPTIONS,
|
|
10
|
-
type CropOptionsSlice,
|
|
11
9
|
type MediaEditorAction,
|
|
12
10
|
type MediaEditorState,
|
|
13
11
|
} from './types';
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
|
-
* Pure
|
|
14
|
+
* Pure reducer for the media editor.
|
|
17
15
|
*
|
|
18
|
-
*
|
|
19
|
-
* `
|
|
20
|
-
*
|
|
21
|
-
* in one transaction (used by undo/redo).
|
|
16
|
+
* The image editor works out its own next state (through the controller from
|
|
17
|
+
* `@wordpress/image-editor`) and this reducer stores it. The reducer
|
|
18
|
+
* also owns the sidebar crop options and the named edits.
|
|
22
19
|
*
|
|
23
|
-
*
|
|
24
|
-
* stacks live in the `useMediaEditorState` hook that wraps it.
|
|
20
|
+
* This reducer keeps no history; `useMediaEditorState` does.
|
|
25
21
|
*
|
|
26
|
-
* @param state Current
|
|
22
|
+
* @param state Current state.
|
|
27
23
|
* @param action Action to apply.
|
|
28
|
-
* @return Next
|
|
24
|
+
* @return Next state.
|
|
29
25
|
*/
|
|
30
26
|
export function mediaEditorReducer(
|
|
31
27
|
state: MediaEditorState,
|
|
32
28
|
action: MediaEditorAction
|
|
33
29
|
): MediaEditorState {
|
|
34
30
|
switch ( action.type ) {
|
|
35
|
-
case '
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
resolved > 0 &&
|
|
50
|
-
visualSize.width > 0 &&
|
|
51
|
-
visualSize.height > 0;
|
|
52
|
-
const nextCropOptions: CropOptionsSlice = {
|
|
53
|
-
...state.cropOptions,
|
|
54
|
-
aspectRatioValue: presetKey,
|
|
55
|
-
};
|
|
56
|
-
if ( ! shouldReshape ) {
|
|
57
|
-
if ( state.cropOptions.aspectRatioValue === presetKey ) {
|
|
58
|
-
return state;
|
|
59
|
-
}
|
|
60
|
-
return { ...state, cropOptions: nextCropOptions };
|
|
61
|
-
}
|
|
62
|
-
const newCropRect = computeInscribedRect( resolved, visualSize );
|
|
63
|
-
const nextCropper = cropperReducer( state.cropper, {
|
|
64
|
-
type: 'SET_CROP_RECT',
|
|
65
|
-
payload: newCropRect,
|
|
66
|
-
} );
|
|
67
|
-
return {
|
|
68
|
-
...state,
|
|
69
|
-
cropper: nextCropper,
|
|
70
|
-
cropOptions: nextCropOptions,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
case 'RESET': {
|
|
74
|
-
const next = buildInitialMediaEditorState(
|
|
75
|
-
cropperReducer( state.cropper, { type: 'RESET' } )
|
|
76
|
-
);
|
|
77
|
-
return areMediaEditorStatesEqual( state, next ) ? state : next;
|
|
78
|
-
}
|
|
31
|
+
case 'SET_IMAGE_EDITOR':
|
|
32
|
+
return action.payload === state.imageEditor
|
|
33
|
+
? state
|
|
34
|
+
: { ...state, imageEditor: action.payload };
|
|
35
|
+
case 'SET_ASPECT_RATIO_VALUE':
|
|
36
|
+
return state.cropOptions.aspectRatioValue === action.payload
|
|
37
|
+
? state
|
|
38
|
+
: {
|
|
39
|
+
...state,
|
|
40
|
+
cropOptions: {
|
|
41
|
+
...state.cropOptions,
|
|
42
|
+
aspectRatioValue: action.payload,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
79
45
|
case 'SET_EDIT': {
|
|
80
46
|
const { name, value } = action.payload;
|
|
81
47
|
if ( value === undefined ) {
|
|
@@ -91,27 +57,23 @@ export function mediaEditorReducer(
|
|
|
91
57
|
}
|
|
92
58
|
return { ...state, edits: { ...state.edits, [ name ]: value } };
|
|
93
59
|
}
|
|
60
|
+
case 'RESET': {
|
|
61
|
+
const next = buildInitialMediaEditorState(
|
|
62
|
+
createImageEditorState( { image: state.imageEditor.image } )
|
|
63
|
+
);
|
|
64
|
+
return areMediaEditorStatesEqual( state, next ) ? state : next;
|
|
65
|
+
}
|
|
94
66
|
case 'RESTORE_SNAPSHOT':
|
|
95
67
|
return action.payload;
|
|
96
|
-
case 'VIEWPORT_ADJUST_CROP_RECT': {
|
|
97
|
-
const nextCropper = cropperReducer( state.cropper, {
|
|
98
|
-
type: 'SET_CROP_RECT',
|
|
99
|
-
payload: action.payload,
|
|
100
|
-
} );
|
|
101
|
-
if ( nextCropper === state.cropper ) {
|
|
102
|
-
return state;
|
|
103
|
-
}
|
|
104
|
-
return { ...state, cropper: nextCropper };
|
|
105
|
-
}
|
|
106
68
|
}
|
|
107
69
|
}
|
|
108
70
|
|
|
109
71
|
/**
|
|
110
|
-
* Value-equality check for two
|
|
111
|
-
*
|
|
72
|
+
* Value-equality check for two media editor states. The history uses it
|
|
73
|
+
* to skip snapshots when an action turned out to be a no-op.
|
|
112
74
|
*
|
|
113
|
-
* @param a First
|
|
114
|
-
* @param b Second
|
|
75
|
+
* @param a First state.
|
|
76
|
+
* @param b Second state.
|
|
115
77
|
* @return Whether `a` and `b` are value-equal across all slices.
|
|
116
78
|
*/
|
|
117
79
|
export function areMediaEditorStatesEqual(
|
|
@@ -122,24 +84,24 @@ export function areMediaEditorStatesEqual(
|
|
|
122
84
|
return true;
|
|
123
85
|
}
|
|
124
86
|
return (
|
|
125
|
-
|
|
87
|
+
areImageEditorStatesEqual( a.imageEditor, b.imageEditor ) &&
|
|
126
88
|
a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&
|
|
127
89
|
fastDeepEqual( a.edits, b.edits )
|
|
128
90
|
);
|
|
129
91
|
}
|
|
130
92
|
|
|
131
93
|
/**
|
|
132
|
-
* Build the
|
|
133
|
-
*
|
|
94
|
+
* Build the state a session starts from: the given image editor state,
|
|
95
|
+
* default crop options, and no edits.
|
|
134
96
|
*
|
|
135
|
-
* @param
|
|
136
|
-
* @return
|
|
97
|
+
* @param imageEditor The image editor state.
|
|
98
|
+
* @return Initial state.
|
|
137
99
|
*/
|
|
138
100
|
export function buildInitialMediaEditorState(
|
|
139
|
-
|
|
101
|
+
imageEditor: ImageEditorState
|
|
140
102
|
): MediaEditorState {
|
|
141
103
|
return {
|
|
142
|
-
|
|
104
|
+
imageEditor,
|
|
143
105
|
cropOptions: { ...DEFAULT_CROP_OPTIONS },
|
|
144
106
|
edits: {},
|
|
145
107
|
};
|
package/src/state/index.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
useMediaEditorState,
|
|
3
|
-
resolveAspectRatio,
|
|
4
|
-
} from './use-media-editor-state';
|
|
1
|
+
export { useMediaEditorState } from './use-media-editor-state';
|
|
5
2
|
export type { MediaEditorSession } from './use-media-editor-state';
|
|
6
3
|
export {
|
|
7
4
|
MediaEditorStateProvider,
|
|
8
5
|
useMediaEditor,
|
|
9
6
|
} from './media-editor-state-provider';
|
|
10
|
-
export {
|
|
11
|
-
mediaEditorReducer,
|
|
12
|
-
areMediaEditorStatesEqual,
|
|
13
|
-
buildInitialMediaEditorState,
|
|
14
|
-
} from './composite-reducer';
|
|
15
|
-
export { DEFAULT_CROP_OPTIONS } from './types';
|
|
16
|
-
export type {
|
|
17
|
-
CropOptionsSlice,
|
|
18
|
-
EditsSlice,
|
|
19
|
-
EditValue,
|
|
20
|
-
MediaEditorState,
|
|
21
|
-
MediaEditorAction,
|
|
22
|
-
} from './types';
|
|
7
|
+
export type { EditsSlice, EditValue, MediaEditorState } from './types';
|
package/src/state/types.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CropperAction,
|
|
3
|
-
CropperState,
|
|
4
|
-
NormalizedRect,
|
|
5
|
-
Size,
|
|
6
|
-
} from '../image-editor';
|
|
1
|
+
import type { ImageEditorState } from '@wordpress/image-editor';
|
|
7
2
|
|
|
8
3
|
/**
|
|
9
|
-
* Sidebar control state for the
|
|
10
|
-
*
|
|
4
|
+
* Sidebar control state for the image editor, kept in the same undo history
|
|
5
|
+
* as the crop.
|
|
11
6
|
*/
|
|
12
7
|
export interface CropOptionsSlice {
|
|
13
8
|
/**
|
|
14
9
|
* Selected aspect-ratio preset as a string (round-trippable through
|
|
15
10
|
* `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive
|
|
16
|
-
* decimal = fixed ratio.
|
|
11
|
+
* decimal = fixed ratio. The image editor holds the resolved ratio itself.
|
|
17
12
|
*/
|
|
18
13
|
aspectRatioValue: string;
|
|
19
14
|
}
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
|
-
*
|
|
23
|
-
* used by the sidebar before the user has touched anything.
|
|
17
|
+
* The crop options a session starts from.
|
|
24
18
|
*/
|
|
25
19
|
export const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {
|
|
26
20
|
aspectRatioValue: '0',
|
|
@@ -50,81 +44,33 @@ export type EditValue =
|
|
|
50
44
|
export type EditsSlice = Record< string, EditValue >;
|
|
51
45
|
|
|
52
46
|
/**
|
|
53
|
-
* The full
|
|
54
|
-
*
|
|
47
|
+
* The full state of the media editor: the image editor's state, the sidebar
|
|
48
|
+
* crop options and named edits.
|
|
55
49
|
*
|
|
56
50
|
* Every undo/redo snapshot is a full `MediaEditorState`. Slices stay
|
|
57
51
|
* referentially equal across actions that don't touch them.
|
|
58
52
|
*/
|
|
59
53
|
export interface MediaEditorState {
|
|
60
|
-
|
|
54
|
+
imageEditor: ImageEditorState;
|
|
61
55
|
cropOptions: CropOptionsSlice;
|
|
62
56
|
edits: EditsSlice;
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
/**
|
|
66
|
-
* Composite reducer action union.
|
|
67
|
-
*
|
|
68
|
-
* Cropper geometry actions are wrapped in a `CROPPER` envelope and
|
|
69
|
-
* delegated to the pure `cropperReducer`. Sidebar and history
|
|
70
|
-
* concerns are first-class actions on this reducer.
|
|
71
|
-
*/
|
|
59
|
+
/** Actions the media editor reducer handles. */
|
|
72
60
|
export type MediaEditorAction =
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*/
|
|
78
|
-
| {
|
|
79
|
-
type: 'CROPPER';
|
|
80
|
-
action: CropperAction;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Set the aspect-ratio preset. Atomically updates the preset key
|
|
84
|
-
* and the cropRect (computed from the resolved ratio and the
|
|
85
|
-
* current visualSize). One transaction = one undo entry.
|
|
86
|
-
*/
|
|
87
|
-
| {
|
|
88
|
-
type: 'SET_ASPECT_RATIO_VALUE';
|
|
89
|
-
payload: {
|
|
90
|
-
/** Preset key as it appears in the dropdown. */
|
|
91
|
-
presetKey: string;
|
|
92
|
-
/**
|
|
93
|
-
* Resolved width/height ratio. `undefined` = Free
|
|
94
|
-
* (no lock; cropRect stays where it is).
|
|
95
|
-
*/
|
|
96
|
-
resolved: number | undefined;
|
|
97
|
-
/**
|
|
98
|
-
* Rendered image size used to compute the inscribed
|
|
99
|
-
* rect. Caller supplies it because the reducer is
|
|
100
|
-
* framework-agnostic and has no DOM access.
|
|
101
|
-
*/
|
|
102
|
-
visualSize: Size;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Put every slice back to its starting state, keeping the image:
|
|
107
|
-
* default geometry, default crop options, no edits. One action,
|
|
108
|
-
* so one undo entry.
|
|
109
|
-
*/
|
|
110
|
-
| { type: 'RESET' }
|
|
61
|
+
/** Replace the image editor's state with the next one it reports. */
|
|
62
|
+
| { type: 'SET_IMAGE_EDITOR'; payload: ImageEditorState }
|
|
63
|
+
/** Set the aspect-ratio preset the dropdown shows. */
|
|
64
|
+
| { type: 'SET_ASPECT_RATIO_VALUE'; payload: string }
|
|
111
65
|
/** Set a named edit, or remove it when `value` is `undefined`. */
|
|
112
66
|
| {
|
|
113
67
|
type: 'SET_EDIT';
|
|
114
68
|
payload: { name: string; value: EditValue | undefined };
|
|
115
69
|
}
|
|
116
70
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
71
|
+
* Put every slice back to its starting state, keeping the image. One
|
|
72
|
+
* action, so one undo entry.
|
|
119
73
|
*/
|
|
120
|
-
| { type: '
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
* (e.g., window resize). Behaviorally identical to a `CROPPER
|
|
124
|
-
* SET_CROP_RECT` dispatch, but tagged so the hook layer can skip
|
|
125
|
-
* history recording — viewport reshapes aren't editor actions.
|
|
126
|
-
*/
|
|
127
|
-
| {
|
|
128
|
-
type: 'VIEWPORT_ADJUST_CROP_RECT';
|
|
129
|
-
payload: NormalizedRect;
|
|
130
|
-
};
|
|
74
|
+
| { type: 'RESET' }
|
|
75
|
+
/** Replace the whole state with a snapshot (undo/redo). */
|
|
76
|
+
| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState };
|