@wordpress/media-editor 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/build/components/media-editor/index.cjs +229 -126
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +41 -11
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +15 -18
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +26 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +13 -12
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +143 -37
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +12 -6
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +41 -74
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +217 -117
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +123 -41
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +12 -7
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +122 -87
- package/build-style/style.css +121 -87
- package/build-types/components/media-editor/index.d.ts +25 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +40 -54
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +27 -24
- package/src/components/media-editor/index.tsx +372 -142
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +4 -1
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +195 -37
- package/src/components/media-preview/style.scss +11 -32
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +34 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +162 -242
- package/src/style.scss +2 -1
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CropperAction,
|
|
3
|
-
CropperState,
|
|
4
|
-
Flip,
|
|
5
|
-
NormalizedPoint,
|
|
6
|
-
NormalizedRect,
|
|
7
|
-
TransformOperation,
|
|
8
|
-
} from '../../core/types';
|
|
9
|
-
import { buildFocalPointZoomAction } from '../../core/setter-helpers';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The named cropper setters shared by every hook that drives the
|
|
13
|
-
* cropper reducer — the pure `useCropperController` and any composite
|
|
14
|
-
* store that delegates cropper actions (e.g. `useMediaEditorState`).
|
|
15
|
-
*
|
|
16
|
-
* `setImage` and `reset` are intentionally NOT included: each hook
|
|
17
|
-
* has additional bookkeeping for them (dirty-baseline, history clear)
|
|
18
|
-
* that doesn't fit a shared factory.
|
|
19
|
-
*/
|
|
20
|
-
export interface CropperSetters {
|
|
21
|
-
setPan: ( pan: NormalizedPoint ) => void;
|
|
22
|
-
setZoom: ( zoom: number ) => void;
|
|
23
|
-
setZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;
|
|
24
|
-
setRotation: ( rotation: number ) => void;
|
|
25
|
-
setFlip: ( flip: Flip ) => void;
|
|
26
|
-
toggleFlip: ( direction: 'horizontal' | 'vertical' ) => void;
|
|
27
|
-
snapRotate90: ( direction: 1 | -1 ) => void;
|
|
28
|
-
setCropRect: ( rect: NormalizedRect ) => void;
|
|
29
|
-
settleCrop: () => void;
|
|
30
|
-
applyOperation: ( op: TransformOperation ) => void;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Build the named cropper setters from a dispatch function and a
|
|
35
|
-
* state getter. The two consuming hooks differ in how they dispatch:
|
|
36
|
-
*
|
|
37
|
-
* - `useCropperController` dispatches directly into its `useReducer`.
|
|
38
|
-
* - `useMediaEditorState` wraps cropper actions in a composite
|
|
39
|
-
* `CROPPER` envelope so the history machinery can record them.
|
|
40
|
-
*
|
|
41
|
-
* Both pass their own dispatch function and a getter that returns
|
|
42
|
-
* the current `CropperState`. The factory shape keeps the two hooks
|
|
43
|
-
* in lockstep — add a setter here once, both hooks get it.
|
|
44
|
-
*
|
|
45
|
-
* @param dispatchCropperAction Apply a `CropperAction` to the
|
|
46
|
-
* underlying reducer.
|
|
47
|
-
* @param getCropperState Return the current `CropperState`.
|
|
48
|
-
* Used by setters that need to read
|
|
49
|
-
* the latest state to compute their
|
|
50
|
-
* payload (focal-point zoom, flip toggle).
|
|
51
|
-
* @return The named cropper setters.
|
|
52
|
-
*/
|
|
53
|
-
export function buildCropperSetters(
|
|
54
|
-
dispatchCropperAction: ( action: CropperAction ) => void,
|
|
55
|
-
getCropperState: () => CropperState
|
|
56
|
-
): CropperSetters {
|
|
57
|
-
return {
|
|
58
|
-
setPan: ( pan ) =>
|
|
59
|
-
dispatchCropperAction( { type: 'SET_PAN', payload: pan } ),
|
|
60
|
-
setZoom: ( zoom ) => {
|
|
61
|
-
const action = buildFocalPointZoomAction( getCropperState(), zoom );
|
|
62
|
-
if ( action ) {
|
|
63
|
-
dispatchCropperAction( action );
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
setZoomAtPoint: ( zoom, pan ) =>
|
|
67
|
-
dispatchCropperAction( {
|
|
68
|
-
type: 'SET_ZOOM_AT_POINT',
|
|
69
|
-
payload: { zoom, pan },
|
|
70
|
-
} ),
|
|
71
|
-
setRotation: ( rotation ) =>
|
|
72
|
-
dispatchCropperAction( {
|
|
73
|
-
type: 'SET_ROTATION',
|
|
74
|
-
payload: rotation,
|
|
75
|
-
} ),
|
|
76
|
-
setFlip: ( flip ) =>
|
|
77
|
-
dispatchCropperAction( { type: 'SET_FLIP', payload: flip } ),
|
|
78
|
-
toggleFlip: ( direction ) => {
|
|
79
|
-
const { flip } = getCropperState();
|
|
80
|
-
dispatchCropperAction( {
|
|
81
|
-
type: 'SET_FLIP',
|
|
82
|
-
payload: { ...flip, [ direction ]: ! flip[ direction ] },
|
|
83
|
-
} );
|
|
84
|
-
},
|
|
85
|
-
snapRotate90: ( direction ) =>
|
|
86
|
-
dispatchCropperAction( {
|
|
87
|
-
type: 'SNAP_ROTATE_90',
|
|
88
|
-
payload: { direction },
|
|
89
|
-
} ),
|
|
90
|
-
setCropRect: ( rect ) =>
|
|
91
|
-
dispatchCropperAction( {
|
|
92
|
-
type: 'SET_CROP_RECT',
|
|
93
|
-
payload: rect,
|
|
94
|
-
} ),
|
|
95
|
-
settleCrop: () => dispatchCropperAction( { type: 'SETTLE_CROP' } ),
|
|
96
|
-
applyOperation: ( op ) =>
|
|
97
|
-
dispatchCropperAction( {
|
|
98
|
-
type: 'APPLY_OPERATION',
|
|
99
|
-
payload: op,
|
|
100
|
-
} ),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { speak } from '@wordpress/a11y';
|
|
2
|
-
import { useEffect, useLayoutEffect, useRef } from '@wordpress/element';
|
|
3
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
4
|
-
import type { CropperState } from '../../core/types';
|
|
5
|
-
import { getSourceRegion } from '../../core/source-region';
|
|
6
|
-
|
|
7
|
-
/** Debounce delay for ARIA live announcements (ms). */
|
|
8
|
-
const ARIA_DEBOUNCE_MS = 300;
|
|
9
|
-
|
|
10
|
-
function getFlipAnnouncement(
|
|
11
|
-
state: CropperState,
|
|
12
|
-
previousState: CropperState | null
|
|
13
|
-
): string | undefined {
|
|
14
|
-
if (
|
|
15
|
-
! previousState ||
|
|
16
|
-
( previousState.flip.horizontal === state.flip.horizontal &&
|
|
17
|
-
previousState.flip.vertical === state.flip.vertical )
|
|
18
|
-
) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
const { horizontal, vertical } = state.flip;
|
|
22
|
-
if ( horizontal && vertical ) {
|
|
23
|
-
return __( 'Flipped horizontally and vertically' );
|
|
24
|
-
}
|
|
25
|
-
if ( horizontal ) {
|
|
26
|
-
return __( 'Flipped horizontally' );
|
|
27
|
-
}
|
|
28
|
-
if ( vertical ) {
|
|
29
|
-
return __( 'Flipped vertically' );
|
|
30
|
-
}
|
|
31
|
-
return __( 'Flip removed' );
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getRotationAnnouncement(
|
|
35
|
-
state: CropperState,
|
|
36
|
-
previousState: CropperState | null
|
|
37
|
-
): string | undefined {
|
|
38
|
-
if (
|
|
39
|
-
previousState &&
|
|
40
|
-
Math.round( previousState.rotation ) === Math.round( state.rotation )
|
|
41
|
-
) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
// Announce the visual rotation — what the user perceives on screen. A
|
|
45
|
-
// single-axis flip mirrors the image, reversing the entire on-screen
|
|
46
|
-
// rotation relative to the stored field (the same S·R·S inversion the
|
|
47
|
-
// reducer applies), so negate the whole angle in that case.
|
|
48
|
-
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
49
|
-
const visualDir = singleFlip ? -1 : 1;
|
|
50
|
-
// Normalize to (-180, 180] so the sign indicates direction.
|
|
51
|
-
let visualRotation = ( Math.round( state.rotation ) * visualDir ) % 360;
|
|
52
|
-
if ( visualRotation > 180 ) {
|
|
53
|
-
visualRotation -= 360;
|
|
54
|
-
}
|
|
55
|
-
if ( visualRotation <= -180 ) {
|
|
56
|
-
visualRotation += 360;
|
|
57
|
-
}
|
|
58
|
-
if ( visualRotation === 0 ) {
|
|
59
|
-
return previousState ? __( 'Rotation 0 degrees' ) : undefined;
|
|
60
|
-
}
|
|
61
|
-
if ( visualRotation > 0 ) {
|
|
62
|
-
return sprintf(
|
|
63
|
-
/* translators: %d: rotation angle in degrees. */
|
|
64
|
-
__( 'Rotated %d degrees clockwise' ),
|
|
65
|
-
visualRotation
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
return sprintf(
|
|
69
|
-
/* translators: %d: rotation angle in degrees. */
|
|
70
|
-
__( 'Rotated %d degrees counterclockwise' ),
|
|
71
|
-
Math.abs( visualRotation )
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getCropAnnouncement(
|
|
76
|
-
state: CropperState,
|
|
77
|
-
previousState: CropperState | null
|
|
78
|
-
): string | undefined {
|
|
79
|
-
if ( ! state.image ) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
const imageSize = {
|
|
83
|
-
width: state.image.naturalWidth,
|
|
84
|
-
height: state.image.naturalHeight,
|
|
85
|
-
};
|
|
86
|
-
const region = getSourceRegion( state, imageSize );
|
|
87
|
-
// Announce only when the crop's pixel dimensions change. Measuring both the
|
|
88
|
-
// previous and current crop rects under the current rotation and zoom keeps
|
|
89
|
-
// the comparison in the same pixel units we announce, and leaves a zoom-only
|
|
90
|
-
// change — which doesn't move the crop rect — silent.
|
|
91
|
-
if ( previousState?.image ) {
|
|
92
|
-
const previousRegion = getSourceRegion(
|
|
93
|
-
{ ...state, cropRect: previousState.cropRect },
|
|
94
|
-
imageSize
|
|
95
|
-
);
|
|
96
|
-
if (
|
|
97
|
-
Math.round( previousRegion.width ) === Math.round( region.width ) &&
|
|
98
|
-
Math.round( previousRegion.height ) === Math.round( region.height )
|
|
99
|
-
) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return sprintf(
|
|
104
|
-
/* translators: 1: crop width in pixels, 2: crop height in pixels. */
|
|
105
|
-
__( 'Crop %1$d by %2$d pixels' ),
|
|
106
|
-
Math.round( region.width ),
|
|
107
|
-
Math.round( region.height )
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function getZoomAnnouncement(
|
|
112
|
-
state: CropperState,
|
|
113
|
-
previousState: CropperState | null
|
|
114
|
-
): string | undefined {
|
|
115
|
-
if (
|
|
116
|
-
previousState &&
|
|
117
|
-
Math.round( previousState.zoom * 100 ) ===
|
|
118
|
-
Math.round( state.zoom * 100 )
|
|
119
|
-
) {
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
return sprintf(
|
|
123
|
-
/* translators: %d: zoom level as a percentage. */
|
|
124
|
-
__( 'Zoom %d%%' ),
|
|
125
|
-
Math.round( state.zoom * 100 )
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function buildAnnouncement(
|
|
130
|
-
state: CropperState,
|
|
131
|
-
previousState: CropperState | null
|
|
132
|
-
): string {
|
|
133
|
-
// Flip changes are announced alone.
|
|
134
|
-
const flip = getFlipAnnouncement( state, previousState );
|
|
135
|
-
if ( flip ) {
|
|
136
|
-
return flip;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const parts = [
|
|
140
|
-
getRotationAnnouncement( state, previousState ),
|
|
141
|
-
getZoomAnnouncement( state, previousState ),
|
|
142
|
-
getCropAnnouncement( state, previousState ),
|
|
143
|
-
].filter( ( part ): part is string => part !== undefined );
|
|
144
|
-
|
|
145
|
-
return parts.join( ', ' );
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Debounce and dedupe ARIA-live announcements for screen readers as the
|
|
150
|
-
* cropper state changes. Calls `speak()` from `@wordpress/a11y` to use the
|
|
151
|
-
* centralized, persistent live region instead of a local one that may be
|
|
152
|
-
* dynamically mounted.
|
|
153
|
-
*
|
|
154
|
-
* Debouncing avoids flooding announcements during drag/pointermove bursts;
|
|
155
|
-
* deduping avoids re-announcing the same state.
|
|
156
|
-
*
|
|
157
|
-
* @param state The current cropper state to announce.
|
|
158
|
-
*/
|
|
159
|
-
export function useAriaAnnouncer( state: CropperState ): void {
|
|
160
|
-
const timerRef = useRef< ReturnType< typeof setTimeout > | undefined >(
|
|
161
|
-
undefined
|
|
162
|
-
);
|
|
163
|
-
const prevMessageRef = useRef( '' );
|
|
164
|
-
const prevStateRef = useRef< CropperState | null >( null );
|
|
165
|
-
const latestStateRef = useRef( state );
|
|
166
|
-
useLayoutEffect( () => {
|
|
167
|
-
latestStateRef.current = state;
|
|
168
|
-
}, [ state ] );
|
|
169
|
-
|
|
170
|
-
useEffect( () => {
|
|
171
|
-
clearTimeout( timerRef.current );
|
|
172
|
-
timerRef.current = setTimeout( () => {
|
|
173
|
-
const current = latestStateRef.current;
|
|
174
|
-
const msg = buildAnnouncement( current, prevStateRef.current );
|
|
175
|
-
prevStateRef.current = current;
|
|
176
|
-
if ( msg !== prevMessageRef.current ) {
|
|
177
|
-
prevMessageRef.current = msg;
|
|
178
|
-
speak( msg );
|
|
179
|
-
}
|
|
180
|
-
}, ARIA_DEBOUNCE_MS );
|
|
181
|
-
|
|
182
|
-
return () => {
|
|
183
|
-
clearTimeout( timerRef.current );
|
|
184
|
-
};
|
|
185
|
-
}, [
|
|
186
|
-
state.zoom,
|
|
187
|
-
state.rotation,
|
|
188
|
-
state.cropRect.width,
|
|
189
|
-
state.cropRect.height,
|
|
190
|
-
state.flip.horizontal,
|
|
191
|
-
state.flip.vertical,
|
|
192
|
-
] );
|
|
193
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useReducer,
|
|
3
|
-
useCallback,
|
|
4
|
-
useMemo,
|
|
5
|
-
useRef,
|
|
6
|
-
useState,
|
|
7
|
-
} from '@wordpress/element';
|
|
8
|
-
import type {
|
|
9
|
-
CropperState,
|
|
10
|
-
CropperAction,
|
|
11
|
-
NormalizedRect,
|
|
12
|
-
Size,
|
|
13
|
-
} from '../../core/types';
|
|
14
|
-
import { DEFAULT_STATE } from '../../core/constants';
|
|
15
|
-
import { exportCroppedImage } from '../../core/export/canvas-renderer';
|
|
16
|
-
import {
|
|
17
|
-
cropperReducer,
|
|
18
|
-
enforceContainment,
|
|
19
|
-
isStateDirty,
|
|
20
|
-
} from '../../core/state';
|
|
21
|
-
import {
|
|
22
|
-
buildCropperSetters,
|
|
23
|
-
type CropperSetters,
|
|
24
|
-
} from './build-cropper-setters';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The cropper controller surface — the contract the Cropper component
|
|
28
|
-
* and its interaction hooks consume.
|
|
29
|
-
*
|
|
30
|
-
* History (undo / redo / commitHistory) is intentionally NOT part of
|
|
31
|
-
* this interface. The cropper is a pure state machine; history is a
|
|
32
|
-
* higher-layer concern owned by a composite store
|
|
33
|
-
* (see media-editor/src/state).
|
|
34
|
-
*/
|
|
35
|
-
export interface CropperController extends CropperSetters {
|
|
36
|
-
/** The current cropper state (read-only). */
|
|
37
|
-
state: CropperState;
|
|
38
|
-
/** Set the loaded image (natural size and src). */
|
|
39
|
-
setImage: ( image: CropperState[ 'image' ] ) => void;
|
|
40
|
-
/** Reset the state. Optionally merge partial state overrides. */
|
|
41
|
-
reset: ( resetState?: Partial< CropperState > ) => void;
|
|
42
|
-
/** Whether the current state differs from the initial state. */
|
|
43
|
-
isDirty: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Export the cropped image as a Blob. Throws on failure — see
|
|
46
|
-
* `exportCroppedImage` for error semantics.
|
|
47
|
-
*/
|
|
48
|
-
getCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;
|
|
49
|
-
/**
|
|
50
|
-
* Called by `Cropper` whenever its rendered image size changes; not for
|
|
51
|
-
* consumers to call. A composite controller uses the size to reshape the
|
|
52
|
-
* crop for an aspect ratio. The pure cropper hook ignores it.
|
|
53
|
-
*/
|
|
54
|
-
setVisualSize: ( size: Size ) => void;
|
|
55
|
-
/**
|
|
56
|
-
* Called by `Cropper` when the viewport changes (window or canvas
|
|
57
|
-
* resize); not for consumers to call. Like `setCropRect`, except that a
|
|
58
|
-
* composite controller records no undo entry for it, since a viewport
|
|
59
|
-
* reshape is not an editor action. The pure cropper hook aliases it to
|
|
60
|
-
* `setCropRect`.
|
|
61
|
-
*/
|
|
62
|
-
adjustCropRectForViewport: ( rect: NormalizedRect ) => void;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function areCropperImagesEqual(
|
|
66
|
-
a: CropperState[ 'image' ],
|
|
67
|
-
b: CropperState[ 'image' ]
|
|
68
|
-
): boolean {
|
|
69
|
-
return (
|
|
70
|
-
a?.src === b?.src &&
|
|
71
|
-
a?.naturalWidth === b?.naturalWidth &&
|
|
72
|
-
a?.naturalHeight === b?.naturalHeight
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Controller hook for the image cropper: the state, the named setters and
|
|
78
|
-
* the export helpers, without history.
|
|
79
|
-
*
|
|
80
|
-
* Wraps the framework-agnostic `cropperReducer` and exposes named
|
|
81
|
-
* setters (built from the shared `buildCropperSetters` factory).
|
|
82
|
-
* Does NOT manage undo/redo history — that responsibility belongs to
|
|
83
|
-
* the surrounding application (see `useMediaEditorState` for the
|
|
84
|
-
* composite store used by the media editor).
|
|
85
|
-
*
|
|
86
|
-
* @param initialState Optional partial state to merge with DEFAULT_STATE.
|
|
87
|
-
* @return The cropper controller — state, setters, and helpers.
|
|
88
|
-
*/
|
|
89
|
-
export function useCropperController(
|
|
90
|
-
initialState?: Partial< CropperState >
|
|
91
|
-
): CropperController {
|
|
92
|
-
const [ state, dispatch ] = useReducer(
|
|
93
|
-
cropperReducer,
|
|
94
|
-
initialState,
|
|
95
|
-
( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// The "clean" snapshot the current state is compared against for
|
|
99
|
-
// `isDirty`. Stored in state (not a ref) so the comparison reads
|
|
100
|
-
// a value, not a ref's `current`. `setImage` and `reset` refresh
|
|
101
|
-
// this when the consumer establishes a new baseline.
|
|
102
|
-
const [ initialBaseline, setInitialBaseline ] = useState< CropperState >(
|
|
103
|
-
() => enforceContainment( { ...DEFAULT_STATE, ...initialState } )
|
|
104
|
-
);
|
|
105
|
-
// Latest-state ref used by setters that need to read fresh state
|
|
106
|
-
// (focal-point zoom, toggleFlip, reset, setImage). Updated
|
|
107
|
-
// synchronously inside `dispatchAndSync` so multiple actions in
|
|
108
|
-
// one event see each other's output before React commits.
|
|
109
|
-
const stateRef = useRef( state );
|
|
110
|
-
|
|
111
|
-
const dispatchAndSync = useCallback( ( action: CropperAction ) => {
|
|
112
|
-
const next = cropperReducer( stateRef.current, action );
|
|
113
|
-
stateRef.current = next;
|
|
114
|
-
dispatch( action );
|
|
115
|
-
return next;
|
|
116
|
-
}, [] );
|
|
117
|
-
|
|
118
|
-
const setImage = useCallback(
|
|
119
|
-
( image: CropperState[ 'image' ] ) => {
|
|
120
|
-
if ( areCropperImagesEqual( stateRef.current.image, image ) ) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const next = dispatchAndSync( {
|
|
124
|
-
type: 'SET_IMAGE',
|
|
125
|
-
payload: image,
|
|
126
|
-
} );
|
|
127
|
-
// Refresh the "clean" snapshot to match the post-load state
|
|
128
|
-
// produced by the reducer. Otherwise containment can nudge
|
|
129
|
-
// pan/zoom by tiny amounts on load and `isDirty` would
|
|
130
|
-
// report true from the start.
|
|
131
|
-
setInitialBaseline( next );
|
|
132
|
-
},
|
|
133
|
-
[ dispatchAndSync ]
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const reset = useCallback(
|
|
137
|
-
( resetState?: Partial< CropperState > ) => {
|
|
138
|
-
const nextInitialState = dispatchAndSync( {
|
|
139
|
-
type: 'RESET',
|
|
140
|
-
payload: resetState,
|
|
141
|
-
} );
|
|
142
|
-
// Mirror the reducer's RESET exactly so isDirty stays in
|
|
143
|
-
// sync. The containment step can tweak pan/zoom/cropRect by
|
|
144
|
-
// float ulp; fold those into the "initial" snapshot or
|
|
145
|
-
// isDirty would report true after a reset.
|
|
146
|
-
setInitialBaseline( nextInitialState );
|
|
147
|
-
},
|
|
148
|
-
[ dispatchAndSync ]
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
const setters = useMemo(
|
|
152
|
-
() => buildCropperSetters( dispatchAndSync, () => stateRef.current ),
|
|
153
|
-
[ dispatchAndSync ]
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
const isDirty = isStateDirty( state, initialBaseline );
|
|
157
|
-
|
|
158
|
-
const getCroppedImage = useCallback(
|
|
159
|
-
( mimeType?: string, quality?: number ): Promise< Blob > => {
|
|
160
|
-
if ( ! state.image ) {
|
|
161
|
-
return Promise.reject(
|
|
162
|
-
new Error( 'No image loaded — call setImage first.' )
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return exportCroppedImage(
|
|
166
|
-
state.image.src,
|
|
167
|
-
state,
|
|
168
|
-
mimeType,
|
|
169
|
-
quality
|
|
170
|
-
);
|
|
171
|
-
},
|
|
172
|
-
[ state ]
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// No-op for the pure hook — visualSize matters only when a
|
|
176
|
-
// composite store needs to compute aspect-ratio reshapes
|
|
177
|
-
// (see useMediaEditorState). Typed to accept a Size so it
|
|
178
|
-
// satisfies the controller surface; the value is intentionally
|
|
179
|
-
// ignored.
|
|
180
|
-
const setVisualSize = useCallback( () => {}, [] );
|
|
181
|
-
|
|
182
|
-
// In the pure hook, history isn't a concern — viewport-driven
|
|
183
|
-
// reshape is identical to setCropRect.
|
|
184
|
-
const adjustCropRectForViewport = setters.setCropRect;
|
|
185
|
-
|
|
186
|
-
const controller: CropperController = {
|
|
187
|
-
...setters,
|
|
188
|
-
state,
|
|
189
|
-
setImage,
|
|
190
|
-
reset,
|
|
191
|
-
isDirty,
|
|
192
|
-
getCroppedImage,
|
|
193
|
-
setVisualSize,
|
|
194
|
-
adjustCropRectForViewport,
|
|
195
|
-
};
|
|
196
|
-
return controller;
|
|
197
|
-
}
|