@wordpress/media-editor 0.22.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 +18 -0
- package/build/components/media-editor/index.cjs +74 -21
- 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 +23 -3
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +6 -11
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +17 -1
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +4 -5
- 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 +1 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- 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 +0 -1
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +10 -4
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +32 -67
- 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-module/components/media-editor/index.mjs +78 -25
- 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 +23 -3
- 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 +1 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- 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 +0 -1
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +10 -5
- 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-style/style-rtl.css +104 -57
- package/build-style/style.css +103 -57
- package/build-types/components/media-editor/index.d.ts +17 -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-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 +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 +163 -28
- 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 +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-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +0 -1
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +32 -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 +155 -240
- package/src/style.scss +2 -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,484 +0,0 @@
|
|
|
1
|
-
import type { CropperAction, CropperState, TransformOperation } from './types';
|
|
2
|
-
import {
|
|
3
|
-
ABSOLUTE_MIN_ZOOM,
|
|
4
|
-
DEFAULT_STATE,
|
|
5
|
-
MAX_ZOOM,
|
|
6
|
-
MIN_ZOOM,
|
|
7
|
-
} from './constants';
|
|
8
|
-
import { normalizeRotation, degreesToRadians } from './math/rotation';
|
|
9
|
-
import { restrictPanZoom, restrictCropRect } from './containment';
|
|
10
|
-
|
|
11
|
-
/** Small tolerance for cropper floating-point comparisons. */
|
|
12
|
-
const STATE_EPSILON = 1e-6;
|
|
13
|
-
|
|
14
|
-
function nearlyEqual( a: number, b: number ): boolean {
|
|
15
|
-
return Math.abs( a - b ) < STATE_EPSILON;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Value-equality check for two cropper states.
|
|
20
|
-
*
|
|
21
|
-
* Used by history machinery to dedup snapshots and detect no-op
|
|
22
|
-
* transitions. Compares every field that participates in the rendered
|
|
23
|
-
* output; ignores reference identity.
|
|
24
|
-
*
|
|
25
|
-
* @param a First cropper state.
|
|
26
|
-
* @param b Second cropper state.
|
|
27
|
-
* @return Whether the two states are value-equal across all tracked fields.
|
|
28
|
-
*/
|
|
29
|
-
export function areCropperStatesEqual(
|
|
30
|
-
a: CropperState,
|
|
31
|
-
b: CropperState
|
|
32
|
-
): boolean {
|
|
33
|
-
const aImage = a.image;
|
|
34
|
-
const bImage = b.image;
|
|
35
|
-
return (
|
|
36
|
-
aImage?.src === bImage?.src &&
|
|
37
|
-
aImage?.naturalWidth === bImage?.naturalWidth &&
|
|
38
|
-
aImage?.naturalHeight === bImage?.naturalHeight &&
|
|
39
|
-
nearlyEqual( a.pan.x, b.pan.x ) &&
|
|
40
|
-
nearlyEqual( a.pan.y, b.pan.y ) &&
|
|
41
|
-
nearlyEqual( a.zoom, b.zoom ) &&
|
|
42
|
-
nearlyEqual( a.rotation, b.rotation ) &&
|
|
43
|
-
a.flip.horizontal === b.flip.horizontal &&
|
|
44
|
-
a.flip.vertical === b.flip.vertical &&
|
|
45
|
-
nearlyEqual( a.cropRect.x, b.cropRect.x ) &&
|
|
46
|
-
nearlyEqual( a.cropRect.y, b.cropRect.y ) &&
|
|
47
|
-
nearlyEqual( a.cropRect.width, b.cropRect.width ) &&
|
|
48
|
-
nearlyEqual( a.cropRect.height, b.cropRect.height )
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function clampRequestedZoom( state: CropperState, zoom: number ): number {
|
|
53
|
-
// With an image, enforceContainment raises zoom to the coverage-aware
|
|
54
|
-
// floor below. Without an image, no enforcement runs, so MIN_ZOOM stays
|
|
55
|
-
// the conservative resting default.
|
|
56
|
-
if ( state.image ) {
|
|
57
|
-
return Math.min( MAX_ZOOM, Math.max( ABSOLUTE_MIN_ZOOM, zoom ) );
|
|
58
|
-
}
|
|
59
|
-
return Math.min( MAX_ZOOM, Math.max( MIN_ZOOM, zoom ) );
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Translate a pipeline transform operation into the equivalent
|
|
64
|
-
* reducer action. Pipeline ops aren't 1:1 with reducer actions —
|
|
65
|
-
* `rotate` is a delta here, whereas SET_ROTATION takes an absolute
|
|
66
|
-
* angle — so deltas are resolved against the current state.
|
|
67
|
-
*
|
|
68
|
-
* Used by APPLY_OPERATION (and by the pipeline module's
|
|
69
|
-
* `applyOperationToState`, which is now a thin wrapper around the
|
|
70
|
-
* reducer) so that pipeline replay produces identical bounded
|
|
71
|
-
* state to UI interaction or direct setters.
|
|
72
|
-
*
|
|
73
|
-
* @param state The current cropper state.
|
|
74
|
-
* @param op The pipeline operation.
|
|
75
|
-
* @return The equivalent reducer action.
|
|
76
|
-
*/
|
|
77
|
-
function operationToAction(
|
|
78
|
-
state: CropperState,
|
|
79
|
-
op: TransformOperation
|
|
80
|
-
): CropperAction {
|
|
81
|
-
switch ( op.type ) {
|
|
82
|
-
case 'crop':
|
|
83
|
-
return { type: 'SET_CROP_RECT', payload: { ...op.rect } };
|
|
84
|
-
case 'rotate': {
|
|
85
|
-
// `op.degrees` is the visual rotation the caller wants (positive
|
|
86
|
-
// = CW on screen). A single-axis flip inverts on-screen rotation
|
|
87
|
-
// relative to the rotation field, so negate the field delta in
|
|
88
|
-
// that case — this keeps `{ type: 'rotate', degrees: 90 }` a
|
|
89
|
-
// reliable "90° clockwise visually" instruction across flip
|
|
90
|
-
// states, matching the SNAP_ROTATE_90 convention.
|
|
91
|
-
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
92
|
-
const fieldDelta = singleFlip ? -op.degrees : op.degrees;
|
|
93
|
-
return {
|
|
94
|
-
type: 'SET_ROTATION',
|
|
95
|
-
payload: normalizeRotation( state.rotation + fieldDelta ),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
case 'flip':
|
|
99
|
-
return {
|
|
100
|
-
type: 'SET_FLIP',
|
|
101
|
-
payload: {
|
|
102
|
-
...state.flip,
|
|
103
|
-
[ op.direction ]: ! state.flip[ op.direction ],
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
case 'zoom':
|
|
107
|
-
return { type: 'SET_ZOOM', payload: op.factor };
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Enforces containment: restricts the crop rect to fit within the
|
|
113
|
-
* rotated image, computes minimum zoom, clamps zoom, and restricts
|
|
114
|
-
* the pan position so the image always covers the crop area.
|
|
115
|
-
* Called after every relevant state transition.
|
|
116
|
-
*
|
|
117
|
-
* @param state The state to enforce containment on.
|
|
118
|
-
* @return The state with cropRect, zoom, and position restricted.
|
|
119
|
-
*/
|
|
120
|
-
export function enforceContainment( state: CropperState ): CropperState {
|
|
121
|
-
if ( ! state.image ) {
|
|
122
|
-
return state;
|
|
123
|
-
}
|
|
124
|
-
const imageSize = {
|
|
125
|
-
width: state.image.naturalWidth,
|
|
126
|
-
height: state.image.naturalHeight,
|
|
127
|
-
};
|
|
128
|
-
const imageAspectRatio = imageSize.width / imageSize.height;
|
|
129
|
-
|
|
130
|
-
// 1. First bump zoom so the image can cover the crop rect as-is.
|
|
131
|
-
// This ensures that explicit crop rect changes (e.g., fixed-crop
|
|
132
|
-
// mode during rotation) get zoom accommodation, not crop shrinkage.
|
|
133
|
-
const { pan: panAfterZoom, zoom } = restrictPanZoom(
|
|
134
|
-
state,
|
|
135
|
-
imageSize,
|
|
136
|
-
state.cropRect
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
// 2. Now restrict the crop rect at the (possibly bumped) zoom.
|
|
140
|
-
// This handles cases where the crop rect is still too large
|
|
141
|
-
// (e.g., if zoom hit MAX_ZOOM).
|
|
142
|
-
const cropRect = restrictCropRect(
|
|
143
|
-
state.cropRect,
|
|
144
|
-
zoom,
|
|
145
|
-
state.rotation,
|
|
146
|
-
imageAspectRatio
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
// 3. If the crop rect was shrunk, re-restrict pan for the new rect.
|
|
150
|
-
let pan = panAfterZoom;
|
|
151
|
-
if ( cropRect !== state.cropRect ) {
|
|
152
|
-
( { pan } = restrictPanZoom(
|
|
153
|
-
{ ...state, zoom, cropRect },
|
|
154
|
-
imageSize,
|
|
155
|
-
cropRect
|
|
156
|
-
) );
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
pan.x === state.pan.x &&
|
|
161
|
-
pan.y === state.pan.y &&
|
|
162
|
-
zoom === state.zoom &&
|
|
163
|
-
cropRect === state.cropRect
|
|
164
|
-
) {
|
|
165
|
-
return state;
|
|
166
|
-
}
|
|
167
|
-
return { ...state, pan, zoom, cropRect };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Snapshot the current `crop`, `zoom`, and `rotation` into the
|
|
172
|
-
* corresponding `basePan`, `baseZoom`, `baseRotation` fields. Called
|
|
173
|
-
* by every committing action so that the next SET_ROTATION derives
|
|
174
|
-
* its transient pan from a fresh base (not from a drifted one).
|
|
175
|
-
*
|
|
176
|
-
* SET_ROTATION is the only action that does NOT commit base — it
|
|
177
|
-
* reads the base, computes a transient pan, and leaves the base
|
|
178
|
-
* alone. This is what eliminates rotation drift near edges.
|
|
179
|
-
*
|
|
180
|
-
* @param next The post-containment state to commit.
|
|
181
|
-
* @return The state with base fields synced to current.
|
|
182
|
-
*/
|
|
183
|
-
function commitBase( next: CropperState ): CropperState {
|
|
184
|
-
if (
|
|
185
|
-
next.basePan.x === next.pan.x &&
|
|
186
|
-
next.basePan.y === next.pan.y &&
|
|
187
|
-
next.baseZoom === next.zoom &&
|
|
188
|
-
next.baseRotation === next.rotation
|
|
189
|
-
) {
|
|
190
|
-
return next;
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
...next,
|
|
194
|
-
basePan: { x: next.pan.x, y: next.pan.y },
|
|
195
|
-
baseZoom: next.zoom,
|
|
196
|
-
baseRotation: next.rotation,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Reducer function for cropper state management.
|
|
202
|
-
*
|
|
203
|
-
* Every state transition that could invalidate the containment invariant
|
|
204
|
-
* (crop, zoom, rotation, cropRect, flip) is followed by enforceContainment
|
|
205
|
-
* to ensure the image always covers the crop area.
|
|
206
|
-
*
|
|
207
|
-
* Committing actions (everything except SET_ROTATION) also call
|
|
208
|
-
* `commitBase` to snapshot the post-containment state as the new
|
|
209
|
-
* base pose. SET_ROTATION derives from that base without mutating
|
|
210
|
-
* it, which prevents accumulated-clamp drift during continuous fine
|
|
211
|
-
* rotation.
|
|
212
|
-
*
|
|
213
|
-
* @param state The current cropper state.
|
|
214
|
-
* @param action The action to process.
|
|
215
|
-
* @return The new cropper state.
|
|
216
|
-
*/
|
|
217
|
-
export function cropperReducer(
|
|
218
|
-
state: CropperState,
|
|
219
|
-
action: CropperAction
|
|
220
|
-
): CropperState {
|
|
221
|
-
// Every action runs through enforceContainment to maintain the invariant:
|
|
222
|
-
// the image always fully covers the crop area.
|
|
223
|
-
switch ( action.type ) {
|
|
224
|
-
case 'SET_IMAGE':
|
|
225
|
-
return commitBase(
|
|
226
|
-
enforceContainment( {
|
|
227
|
-
...state,
|
|
228
|
-
image: action.payload,
|
|
229
|
-
} )
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
case 'SET_PAN':
|
|
233
|
-
return commitBase(
|
|
234
|
-
enforceContainment( {
|
|
235
|
-
...state,
|
|
236
|
-
pan: action.payload,
|
|
237
|
-
} )
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
case 'SET_ZOOM': {
|
|
241
|
-
const z = clampRequestedZoom( state, action.payload );
|
|
242
|
-
return commitBase(
|
|
243
|
-
enforceContainment( {
|
|
244
|
-
...state,
|
|
245
|
-
zoom: z,
|
|
246
|
-
} )
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
case 'SET_ZOOM_AT_POINT': {
|
|
251
|
-
const z = clampRequestedZoom( state, action.payload.zoom );
|
|
252
|
-
return commitBase(
|
|
253
|
-
enforceContainment( {
|
|
254
|
-
...state,
|
|
255
|
-
zoom: z,
|
|
256
|
-
pan: action.payload.pan,
|
|
257
|
-
} )
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
case 'SET_ROTATION': {
|
|
262
|
-
// Rotate the base pan around the crop-rect center by the
|
|
263
|
-
// delta from the base rotation. Deriving each tick from
|
|
264
|
-
// the fixed base — rather than compounding on the previous
|
|
265
|
-
// tick — prevents accumulated-clamp drift. Rotating
|
|
266
|
-
// 0°→30°→0° now returns to the exact base pan.
|
|
267
|
-
//
|
|
268
|
-
// Zoom starts from baseZoom; enforceContainment may bump it
|
|
269
|
-
// up to cover the rotated crop, but never raises the base.
|
|
270
|
-
//
|
|
271
|
-
// SET_ROTATION is the only action that does NOT call
|
|
272
|
-
// commitBase — the base pose stays pinned at the user's
|
|
273
|
-
// last committed pan/zoom/rotation.
|
|
274
|
-
const newRotation = normalizeRotation( action.payload );
|
|
275
|
-
// With viewport-relative flip, pan rotation is conjugated by
|
|
276
|
-
// the flip (S * R * S) — which reverses direction when exactly
|
|
277
|
-
// one axis is flipped. Negate sin in that case so the crop
|
|
278
|
-
// stays framed on the same image content through rotation.
|
|
279
|
-
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
280
|
-
const deltaRad = degreesToRadians(
|
|
281
|
-
newRotation - state.baseRotation
|
|
282
|
-
);
|
|
283
|
-
const cos = Math.cos( deltaRad );
|
|
284
|
-
const sin = Math.sin( deltaRad ) * ( singleFlip ? -1 : 1 );
|
|
285
|
-
const cropCx = state.cropRect.x + state.cropRect.width / 2;
|
|
286
|
-
const cropCy = state.cropRect.y + state.cropRect.height / 2;
|
|
287
|
-
const ox = cropCx - 0.5;
|
|
288
|
-
const oy = cropCy - 0.5;
|
|
289
|
-
const dx = state.basePan.x - ox;
|
|
290
|
-
const dy = state.basePan.y - oy;
|
|
291
|
-
return enforceContainment( {
|
|
292
|
-
...state,
|
|
293
|
-
rotation: newRotation,
|
|
294
|
-
zoom: state.baseZoom,
|
|
295
|
-
pan: {
|
|
296
|
-
x: ox + cos * dx - sin * dy,
|
|
297
|
-
y: oy + sin * dx + cos * dy,
|
|
298
|
-
},
|
|
299
|
-
} );
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
case 'SNAP_ROTATE_90': {
|
|
303
|
-
// 90° snap: the crop rect rotates 90° around its own center
|
|
304
|
-
// (width/height swap), and the pan rotates 90° around the
|
|
305
|
-
// pan-space origin. The combination keeps the same image
|
|
306
|
-
// slice framed — just viewed through a rotated window.
|
|
307
|
-
//
|
|
308
|
-
// `direction` is the visual rotation the caller wants: +1
|
|
309
|
-
// means "rotate the image CW on screen", −1 means "CCW".
|
|
310
|
-
// With a single-axis flip active, rotation on screen appears
|
|
311
|
-
// reversed relative to the rotation field (S·R·S conjugation),
|
|
312
|
-
// so internally we negate the direction applied to the
|
|
313
|
-
// `rotation` field. Pan rotates in the caller's direction —
|
|
314
|
-
// that way the same image content stays framed after the
|
|
315
|
-
// snap regardless of flip state.
|
|
316
|
-
const rawDir = action.payload.direction;
|
|
317
|
-
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
318
|
-
const fieldDir = singleFlip ? -rawDir : rawDir;
|
|
319
|
-
const rot90 = normalizeRotation( state.rotation + fieldDir * 90 );
|
|
320
|
-
const rect = state.cropRect;
|
|
321
|
-
const cx = rect.x + rect.width / 2;
|
|
322
|
-
const cy = rect.y + rect.height / 2;
|
|
323
|
-
|
|
324
|
-
// Rotate pan vector 90° around origin.
|
|
325
|
-
// CW (rawDir=+1): (px, py) → (-py, px)
|
|
326
|
-
// CCW (rawDir=-1): (px, py) → (py, -px)
|
|
327
|
-
const newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;
|
|
328
|
-
const newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;
|
|
329
|
-
|
|
330
|
-
return commitBase(
|
|
331
|
-
enforceContainment( {
|
|
332
|
-
...state,
|
|
333
|
-
rotation: rot90,
|
|
334
|
-
zoom: state.baseZoom,
|
|
335
|
-
pan: { x: newPanX, y: newPanY },
|
|
336
|
-
cropRect: {
|
|
337
|
-
x: cx - rect.height / 2,
|
|
338
|
-
y: cy - rect.width / 2,
|
|
339
|
-
width: rect.height,
|
|
340
|
-
height: rect.width,
|
|
341
|
-
},
|
|
342
|
-
} )
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
case 'SET_FLIP': {
|
|
347
|
-
// Mirror the crop rect and pan so the same image content stays
|
|
348
|
-
// framed after a flip. Flip in the camera matrix is composed
|
|
349
|
-
// outside rotation (viewport-relative), so both `pan` and
|
|
350
|
-
// `cropRect` live in viewport-aligned space: negating the flipped
|
|
351
|
-
// axis on each is enough — no rotation math needed.
|
|
352
|
-
const oldFlip = state.flip;
|
|
353
|
-
const newFlip = action.payload;
|
|
354
|
-
const flippedH = oldFlip.horizontal !== newFlip.horizontal;
|
|
355
|
-
const flippedV = oldFlip.vertical !== newFlip.vertical;
|
|
356
|
-
const rect = state.cropRect;
|
|
357
|
-
|
|
358
|
-
return commitBase(
|
|
359
|
-
enforceContainment( {
|
|
360
|
-
...state,
|
|
361
|
-
flip: newFlip,
|
|
362
|
-
pan: {
|
|
363
|
-
x: flippedH ? -state.pan.x : state.pan.x,
|
|
364
|
-
y: flippedV ? -state.pan.y : state.pan.y,
|
|
365
|
-
},
|
|
366
|
-
cropRect: {
|
|
367
|
-
x: flippedH ? 1 - rect.x - rect.width : rect.x,
|
|
368
|
-
y: flippedV ? 1 - rect.y - rect.height : rect.y,
|
|
369
|
-
width: rect.width,
|
|
370
|
-
height: rect.height,
|
|
371
|
-
},
|
|
372
|
-
} )
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
case 'SET_CROP_RECT':
|
|
377
|
-
return commitBase(
|
|
378
|
-
enforceContainment( {
|
|
379
|
-
...state,
|
|
380
|
-
cropRect: action.payload,
|
|
381
|
-
} )
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
case 'SETTLE_CROP': {
|
|
385
|
-
// After a resize drag ends: expand the crop to fill the
|
|
386
|
-
// available height (maintaining its aspect ratio), center it,
|
|
387
|
-
// and adjust zoom/pan so the exact same image content that
|
|
388
|
-
// was visible inside the old crop is visible in the new one.
|
|
389
|
-
const rect = state.cropRect;
|
|
390
|
-
if ( rect.width === 0 || rect.height === 0 || ! state.image ) {
|
|
391
|
-
return state;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// Scale factor: how much the crop grows. fitScale fills the
|
|
395
|
-
// larger axis to 1 (viewport-filling settle). Cap so the
|
|
396
|
-
// resulting zoom stays at or below MAX_ZOOM — tight crops
|
|
397
|
-
// would otherwise push state.zoom past the user-facing cap
|
|
398
|
-
// and break wheel/slider interactions, which clamp to
|
|
399
|
-
// MAX_ZOOM and snap state.zoom down on the first input.
|
|
400
|
-
const fitScale = 1 / Math.max( rect.width, rect.height );
|
|
401
|
-
const zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;
|
|
402
|
-
const s = Math.min( fitScale, zoomCap );
|
|
403
|
-
|
|
404
|
-
const newW = rect.width * s;
|
|
405
|
-
const newH = rect.height * s;
|
|
406
|
-
|
|
407
|
-
// The old crop center in normalized visual space.
|
|
408
|
-
const oldCx = rect.x + rect.width / 2;
|
|
409
|
-
const oldCy = rect.y + rect.height / 2;
|
|
410
|
-
|
|
411
|
-
// Zoom scales by s so the same image region fills the new
|
|
412
|
-
// crop at the same relative size. When s is capped, the new
|
|
413
|
-
// crop is smaller than the viewport but the visible content
|
|
414
|
-
// inside it remains the source region the user framed.
|
|
415
|
-
// Pan: the visible content center was at
|
|
416
|
-
// (cropCx - crop.x, cropCy - crop.y)
|
|
417
|
-
// in visual-normalized space. After centering the crop to
|
|
418
|
-
// (0.5, 0.5), the pan must place that same content at
|
|
419
|
-
// the new center. Both pan and zoom scale by s because
|
|
420
|
-
// the CSS translate is independent of zoom.
|
|
421
|
-
return commitBase(
|
|
422
|
-
enforceContainment( {
|
|
423
|
-
...state,
|
|
424
|
-
zoom: state.zoom * s,
|
|
425
|
-
pan: {
|
|
426
|
-
x: ( state.pan.x - oldCx + 0.5 ) * s,
|
|
427
|
-
y: ( state.pan.y - oldCy + 0.5 ) * s,
|
|
428
|
-
},
|
|
429
|
-
cropRect: {
|
|
430
|
-
x: ( 1 - newW ) / 2,
|
|
431
|
-
y: ( 1 - newH ) / 2,
|
|
432
|
-
width: newW,
|
|
433
|
-
height: newH,
|
|
434
|
-
},
|
|
435
|
-
} )
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
case 'APPLY_OPERATION':
|
|
440
|
-
// Route through the action equivalent so a pipeline replay
|
|
441
|
-
// yields the same bounded state as the matching UI/setter
|
|
442
|
-
// path (containment, baseZoom relaxation, pan rotation
|
|
443
|
-
// around crop center, etc.).
|
|
444
|
-
return cropperReducer(
|
|
445
|
-
state,
|
|
446
|
-
operationToAction( state, action.payload )
|
|
447
|
-
);
|
|
448
|
-
|
|
449
|
-
case 'RESET':
|
|
450
|
-
return commitBase(
|
|
451
|
-
enforceContainment( {
|
|
452
|
-
...DEFAULT_STATE,
|
|
453
|
-
image: state.image,
|
|
454
|
-
...action.payload,
|
|
455
|
-
} )
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Shallow comparison of key cropper state fields to determine if
|
|
462
|
-
* the state has been modified from an initial snapshot.
|
|
463
|
-
*
|
|
464
|
-
* @param current The current cropper state.
|
|
465
|
-
* @param initial The initial cropper state snapshot.
|
|
466
|
-
* @return True if any tracked field differs.
|
|
467
|
-
*/
|
|
468
|
-
export function isStateDirty(
|
|
469
|
-
current: CropperState,
|
|
470
|
-
initial: CropperState
|
|
471
|
-
): boolean {
|
|
472
|
-
return (
|
|
473
|
-
! nearlyEqual( current.pan.x, initial.pan.x ) ||
|
|
474
|
-
! nearlyEqual( current.pan.y, initial.pan.y ) ||
|
|
475
|
-
! nearlyEqual( current.zoom, initial.zoom ) ||
|
|
476
|
-
! nearlyEqual( current.rotation, initial.rotation ) ||
|
|
477
|
-
current.flip.horizontal !== initial.flip.horizontal ||
|
|
478
|
-
current.flip.vertical !== initial.flip.vertical ||
|
|
479
|
-
! nearlyEqual( current.cropRect.x, initial.cropRect.x ) ||
|
|
480
|
-
! nearlyEqual( current.cropRect.y, initial.cropRect.y ) ||
|
|
481
|
-
! nearlyEqual( current.cropRect.width, initial.cropRect.width ) ||
|
|
482
|
-
! nearlyEqual( current.cropRect.height, initial.cropRect.height )
|
|
483
|
-
);
|
|
484
|
-
}
|