@wordpress/media-editor 0.21.0 → 0.22.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 +12 -0
- package/build/components/media-editor/index.cjs +533 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.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 +76 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -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/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -710
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.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 +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +134 -112
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- 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 +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -294
- 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 +490 -673
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -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 +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +98 -96
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +43 -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 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.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 +68 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +106 -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/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -686
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.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 +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -90
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- 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 +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -286
- 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 +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +4 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- 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.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.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/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +1 -0
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +2 -1
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/media-editor/index.tsx +215 -162
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -2
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +16 -26
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-preview/index.tsx +66 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +19 -27
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +2 -2
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +2 -6
- package/src/state/use-media-editor-state.ts +7 -5
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.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/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.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/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/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
|
@@ -1,260 +1,288 @@
|
|
|
1
|
+
import { ABSOLUTE_MIN_ZOOM, DEFAULT_STATE, MAX_ZOOM, MIN_ZOOM } from "./constants.mjs";
|
|
2
|
+
import { degreesToRadians, normalizeRotation } from "./math/rotation.mjs";
|
|
3
|
+
import { restrictCropRect, restrictPanZoom } from "./containment.mjs";
|
|
1
4
|
// packages/media-editor/src/image-editor/core/state.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
DEFAULT_STATE,
|
|
5
|
-
MAX_ZOOM,
|
|
6
|
-
MIN_ZOOM
|
|
7
|
-
} from "./constants.mjs";
|
|
8
|
-
import { normalizeRotation, degreesToRadians } from "./math/rotation.mjs";
|
|
9
|
-
import { restrictPanZoom, restrictCropRect } from "./containment.mjs";
|
|
10
|
-
var STATE_EPSILON = 1e-6;
|
|
5
|
+
/** Small tolerance for cropper floating-point comparisons. */
|
|
6
|
+
const STATE_EPSILON = 1e-6;
|
|
11
7
|
function nearlyEqual(a, b) {
|
|
12
|
-
|
|
8
|
+
return Math.abs(a - b) < STATE_EPSILON;
|
|
13
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Value-equality check for two cropper states.
|
|
12
|
+
*
|
|
13
|
+
* Used by history machinery to dedup snapshots and detect no-op
|
|
14
|
+
* transitions. Compares every field that participates in the rendered
|
|
15
|
+
* output; ignores reference identity.
|
|
16
|
+
*
|
|
17
|
+
* @param a First cropper state.
|
|
18
|
+
* @param b Second cropper state.
|
|
19
|
+
* @return Whether the two states are value-equal across all tracked fields.
|
|
20
|
+
*/
|
|
14
21
|
function areCropperStatesEqual(a, b) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
const aImage = a.image;
|
|
23
|
+
const bImage = b.image;
|
|
24
|
+
return aImage?.src === bImage?.src && aImage?.naturalWidth === bImage?.naturalWidth && aImage?.naturalHeight === bImage?.naturalHeight && nearlyEqual(a.pan.x, b.pan.x) && nearlyEqual(a.pan.y, b.pan.y) && nearlyEqual(a.zoom, b.zoom) && nearlyEqual(a.rotation, b.rotation) && a.flip.horizontal === b.flip.horizontal && a.flip.vertical === b.flip.vertical && nearlyEqual(a.cropRect.x, b.cropRect.x) && nearlyEqual(a.cropRect.y, b.cropRect.y) && nearlyEqual(a.cropRect.width, b.cropRect.width) && nearlyEqual(a.cropRect.height, b.cropRect.height);
|
|
18
25
|
}
|
|
19
26
|
function clampRequestedZoom(state, zoom) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom));
|
|
27
|
+
if (state.image) return Math.min(MAX_ZOOM, Math.max(ABSOLUTE_MIN_ZOOM, zoom));
|
|
28
|
+
return Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, zoom));
|
|
24
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Translate a pipeline transform operation into the equivalent
|
|
32
|
+
* reducer action. Pipeline ops aren't 1:1 with reducer actions —
|
|
33
|
+
* `rotate` is a delta here, whereas SET_ROTATION takes an absolute
|
|
34
|
+
* angle — so deltas are resolved against the current state.
|
|
35
|
+
*
|
|
36
|
+
* Used by APPLY_OPERATION (and by the pipeline module's
|
|
37
|
+
* `applyOperationToState`, which is now a thin wrapper around the
|
|
38
|
+
* reducer) so that pipeline replay produces identical bounded
|
|
39
|
+
* state to UI interaction or direct setters.
|
|
40
|
+
*
|
|
41
|
+
* @param state The current cropper state.
|
|
42
|
+
* @param op The pipeline operation.
|
|
43
|
+
* @return The equivalent reducer action.
|
|
44
|
+
*/
|
|
25
45
|
function operationToAction(state, op) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
switch (op.type) {
|
|
47
|
+
case "crop": return {
|
|
48
|
+
type: "SET_CROP_RECT",
|
|
49
|
+
payload: { ...op.rect }
|
|
50
|
+
};
|
|
51
|
+
case "rotate": {
|
|
52
|
+
const fieldDelta = state.flip.horizontal !== state.flip.vertical ? -op.degrees : op.degrees;
|
|
53
|
+
return {
|
|
54
|
+
type: "SET_ROTATION",
|
|
55
|
+
payload: normalizeRotation(state.rotation + fieldDelta)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
case "flip": return {
|
|
59
|
+
type: "SET_FLIP",
|
|
60
|
+
payload: {
|
|
61
|
+
...state.flip,
|
|
62
|
+
[op.direction]: !state.flip[op.direction]
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
case "zoom": return {
|
|
66
|
+
type: "SET_ZOOM",
|
|
67
|
+
payload: op.factor
|
|
68
|
+
};
|
|
69
|
+
}
|
|
48
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Enforces containment: restricts the crop rect to fit within the
|
|
73
|
+
* rotated image, computes minimum zoom, clamps zoom, and restricts
|
|
74
|
+
* the pan position so the image always covers the crop area.
|
|
75
|
+
* Called after every relevant state transition.
|
|
76
|
+
*
|
|
77
|
+
* @param state The state to enforce containment on.
|
|
78
|
+
* @return The state with cropRect, zoom, and position restricted.
|
|
79
|
+
*/
|
|
49
80
|
function enforceContainment(state) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
({ pan } = restrictPanZoom(
|
|
72
|
-
{ ...state, zoom, cropRect },
|
|
73
|
-
imageSize,
|
|
74
|
-
cropRect
|
|
75
|
-
));
|
|
76
|
-
}
|
|
77
|
-
if (pan.x === state.pan.x && pan.y === state.pan.y && zoom === state.zoom && cropRect === state.cropRect) {
|
|
78
|
-
return state;
|
|
79
|
-
}
|
|
80
|
-
return { ...state, pan, zoom, cropRect };
|
|
81
|
+
if (!state.image) return state;
|
|
82
|
+
const imageSize = {
|
|
83
|
+
width: state.image.naturalWidth,
|
|
84
|
+
height: state.image.naturalHeight
|
|
85
|
+
};
|
|
86
|
+
const imageAspectRatio = imageSize.width / imageSize.height;
|
|
87
|
+
const { pan: panAfterZoom, zoom } = restrictPanZoom(state, imageSize, state.cropRect);
|
|
88
|
+
const cropRect = restrictCropRect(state.cropRect, zoom, state.rotation, imageAspectRatio);
|
|
89
|
+
let pan = panAfterZoom;
|
|
90
|
+
if (cropRect !== state.cropRect) ({pan} = restrictPanZoom({
|
|
91
|
+
...state,
|
|
92
|
+
zoom,
|
|
93
|
+
cropRect
|
|
94
|
+
}, imageSize, cropRect));
|
|
95
|
+
if (pan.x === state.pan.x && pan.y === state.pan.y && zoom === state.zoom && cropRect === state.cropRect) return state;
|
|
96
|
+
return {
|
|
97
|
+
...state,
|
|
98
|
+
pan,
|
|
99
|
+
zoom,
|
|
100
|
+
cropRect
|
|
101
|
+
};
|
|
81
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Snapshot the current `crop`, `zoom`, and `rotation` into the
|
|
105
|
+
* corresponding `basePan`, `baseZoom`, `baseRotation` fields. Called
|
|
106
|
+
* by every committing action so that the next SET_ROTATION derives
|
|
107
|
+
* its transient pan from a fresh base (not from a drifted one).
|
|
108
|
+
*
|
|
109
|
+
* SET_ROTATION is the only action that does NOT commit base — it
|
|
110
|
+
* reads the base, computes a transient pan, and leaves the base
|
|
111
|
+
* alone. This is what eliminates rotation drift near edges.
|
|
112
|
+
*
|
|
113
|
+
* @param next The post-containment state to commit.
|
|
114
|
+
* @return The state with base fields synced to current.
|
|
115
|
+
*/
|
|
82
116
|
function commitBase(next) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
117
|
+
if (next.basePan.x === next.pan.x && next.basePan.y === next.pan.y && next.baseZoom === next.zoom && next.baseRotation === next.rotation) return next;
|
|
118
|
+
return {
|
|
119
|
+
...next,
|
|
120
|
+
basePan: {
|
|
121
|
+
x: next.pan.x,
|
|
122
|
+
y: next.pan.y
|
|
123
|
+
},
|
|
124
|
+
baseZoom: next.zoom,
|
|
125
|
+
baseRotation: next.rotation
|
|
126
|
+
};
|
|
92
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Reducer function for cropper state management.
|
|
130
|
+
*
|
|
131
|
+
* Every state transition that could invalidate the containment invariant
|
|
132
|
+
* (crop, zoom, rotation, cropRect, flip) is followed by enforceContainment
|
|
133
|
+
* to ensure the image always covers the crop area.
|
|
134
|
+
*
|
|
135
|
+
* Committing actions (everything except SET_ROTATION) also call
|
|
136
|
+
* `commitBase` to snapshot the post-containment state as the new
|
|
137
|
+
* base pose. SET_ROTATION derives from that base without mutating
|
|
138
|
+
* it, which prevents accumulated-clamp drift during continuous fine
|
|
139
|
+
* rotation.
|
|
140
|
+
*
|
|
141
|
+
* @param state The current cropper state.
|
|
142
|
+
* @param action The action to process.
|
|
143
|
+
* @return The new cropper state.
|
|
144
|
+
*/
|
|
93
145
|
function cropperReducer(state, action) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
zoom: state.zoom * s,
|
|
223
|
-
pan: {
|
|
224
|
-
x: (state.pan.x - oldCx + 0.5) * s,
|
|
225
|
-
y: (state.pan.y - oldCy + 0.5) * s
|
|
226
|
-
},
|
|
227
|
-
cropRect: {
|
|
228
|
-
x: (1 - newW) / 2,
|
|
229
|
-
y: (1 - newH) / 2,
|
|
230
|
-
width: newW,
|
|
231
|
-
height: newH
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
case "APPLY_OPERATION":
|
|
237
|
-
return cropperReducer(
|
|
238
|
-
state,
|
|
239
|
-
operationToAction(state, action.payload)
|
|
240
|
-
);
|
|
241
|
-
case "RESET":
|
|
242
|
-
return commitBase(
|
|
243
|
-
enforceContainment({
|
|
244
|
-
...DEFAULT_STATE,
|
|
245
|
-
image: state.image,
|
|
246
|
-
...action.payload
|
|
247
|
-
})
|
|
248
|
-
);
|
|
249
|
-
}
|
|
146
|
+
switch (action.type) {
|
|
147
|
+
case "SET_IMAGE": return commitBase(enforceContainment({
|
|
148
|
+
...state,
|
|
149
|
+
image: action.payload
|
|
150
|
+
}));
|
|
151
|
+
case "SET_PAN": return commitBase(enforceContainment({
|
|
152
|
+
...state,
|
|
153
|
+
pan: action.payload
|
|
154
|
+
}));
|
|
155
|
+
case "SET_ZOOM": {
|
|
156
|
+
const z = clampRequestedZoom(state, action.payload);
|
|
157
|
+
return commitBase(enforceContainment({
|
|
158
|
+
...state,
|
|
159
|
+
zoom: z
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
case "SET_ZOOM_AT_POINT": {
|
|
163
|
+
const z = clampRequestedZoom(state, action.payload.zoom);
|
|
164
|
+
return commitBase(enforceContainment({
|
|
165
|
+
...state,
|
|
166
|
+
zoom: z,
|
|
167
|
+
pan: action.payload.pan
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
case "SET_ROTATION": {
|
|
171
|
+
const newRotation = normalizeRotation(action.payload);
|
|
172
|
+
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
173
|
+
const deltaRad = degreesToRadians(newRotation - state.baseRotation);
|
|
174
|
+
const cos = Math.cos(deltaRad);
|
|
175
|
+
const sin = Math.sin(deltaRad) * (singleFlip ? -1 : 1);
|
|
176
|
+
const cropCx = state.cropRect.x + state.cropRect.width / 2;
|
|
177
|
+
const cropCy = state.cropRect.y + state.cropRect.height / 2;
|
|
178
|
+
const ox = cropCx - .5;
|
|
179
|
+
const oy = cropCy - .5;
|
|
180
|
+
const dx = state.basePan.x - ox;
|
|
181
|
+
const dy = state.basePan.y - oy;
|
|
182
|
+
return enforceContainment({
|
|
183
|
+
...state,
|
|
184
|
+
rotation: newRotation,
|
|
185
|
+
zoom: state.baseZoom,
|
|
186
|
+
pan: {
|
|
187
|
+
x: ox + cos * dx - sin * dy,
|
|
188
|
+
y: oy + sin * dx + cos * dy
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
case "SNAP_ROTATE_90": {
|
|
193
|
+
const rawDir = action.payload.direction;
|
|
194
|
+
const fieldDir = state.flip.horizontal !== state.flip.vertical ? -rawDir : rawDir;
|
|
195
|
+
const rot90 = normalizeRotation(state.rotation + fieldDir * 90);
|
|
196
|
+
const rect = state.cropRect;
|
|
197
|
+
const cx = rect.x + rect.width / 2;
|
|
198
|
+
const cy = rect.y + rect.height / 2;
|
|
199
|
+
const newPanX = rawDir === 1 ? -state.pan.y : state.pan.y;
|
|
200
|
+
const newPanY = rawDir === 1 ? state.pan.x : -state.pan.x;
|
|
201
|
+
return commitBase(enforceContainment({
|
|
202
|
+
...state,
|
|
203
|
+
rotation: rot90,
|
|
204
|
+
zoom: state.baseZoom,
|
|
205
|
+
pan: {
|
|
206
|
+
x: newPanX,
|
|
207
|
+
y: newPanY
|
|
208
|
+
},
|
|
209
|
+
cropRect: {
|
|
210
|
+
x: cx - rect.height / 2,
|
|
211
|
+
y: cy - rect.width / 2,
|
|
212
|
+
width: rect.height,
|
|
213
|
+
height: rect.width
|
|
214
|
+
}
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
case "SET_FLIP": {
|
|
218
|
+
const oldFlip = state.flip;
|
|
219
|
+
const newFlip = action.payload;
|
|
220
|
+
const flippedH = oldFlip.horizontal !== newFlip.horizontal;
|
|
221
|
+
const flippedV = oldFlip.vertical !== newFlip.vertical;
|
|
222
|
+
const rect = state.cropRect;
|
|
223
|
+
return commitBase(enforceContainment({
|
|
224
|
+
...state,
|
|
225
|
+
flip: newFlip,
|
|
226
|
+
pan: {
|
|
227
|
+
x: flippedH ? -state.pan.x : state.pan.x,
|
|
228
|
+
y: flippedV ? -state.pan.y : state.pan.y
|
|
229
|
+
},
|
|
230
|
+
cropRect: {
|
|
231
|
+
x: flippedH ? 1 - rect.x - rect.width : rect.x,
|
|
232
|
+
y: flippedV ? 1 - rect.y - rect.height : rect.y,
|
|
233
|
+
width: rect.width,
|
|
234
|
+
height: rect.height
|
|
235
|
+
}
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
case "SET_CROP_RECT": return commitBase(enforceContainment({
|
|
239
|
+
...state,
|
|
240
|
+
cropRect: action.payload
|
|
241
|
+
}));
|
|
242
|
+
case "SETTLE_CROP": {
|
|
243
|
+
const rect = state.cropRect;
|
|
244
|
+
if (rect.width === 0 || rect.height === 0 || !state.image) return state;
|
|
245
|
+
const fitScale = 1 / Math.max(rect.width, rect.height);
|
|
246
|
+
const zoomCap = state.zoom > 0 ? MAX_ZOOM / state.zoom : fitScale;
|
|
247
|
+
const s = Math.min(fitScale, zoomCap);
|
|
248
|
+
const newW = rect.width * s;
|
|
249
|
+
const newH = rect.height * s;
|
|
250
|
+
const oldCx = rect.x + rect.width / 2;
|
|
251
|
+
const oldCy = rect.y + rect.height / 2;
|
|
252
|
+
return commitBase(enforceContainment({
|
|
253
|
+
...state,
|
|
254
|
+
zoom: state.zoom * s,
|
|
255
|
+
pan: {
|
|
256
|
+
x: (state.pan.x - oldCx + .5) * s,
|
|
257
|
+
y: (state.pan.y - oldCy + .5) * s
|
|
258
|
+
},
|
|
259
|
+
cropRect: {
|
|
260
|
+
x: (1 - newW) / 2,
|
|
261
|
+
y: (1 - newH) / 2,
|
|
262
|
+
width: newW,
|
|
263
|
+
height: newH
|
|
264
|
+
}
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
case "APPLY_OPERATION": return cropperReducer(state, operationToAction(state, action.payload));
|
|
268
|
+
case "RESET": return commitBase(enforceContainment({
|
|
269
|
+
...DEFAULT_STATE,
|
|
270
|
+
image: state.image,
|
|
271
|
+
...action.payload
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
250
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Shallow comparison of key cropper state fields to determine if
|
|
277
|
+
* the state has been modified from an initial snapshot.
|
|
278
|
+
*
|
|
279
|
+
* @param current The current cropper state.
|
|
280
|
+
* @param initial The initial cropper state snapshot.
|
|
281
|
+
* @return True if any tracked field differs.
|
|
282
|
+
*/
|
|
251
283
|
function isStateDirty(current, initial) {
|
|
252
|
-
|
|
284
|
+
return !nearlyEqual(current.pan.x, initial.pan.x) || !nearlyEqual(current.pan.y, initial.pan.y) || !nearlyEqual(current.zoom, initial.zoom) || !nearlyEqual(current.rotation, initial.rotation) || current.flip.horizontal !== initial.flip.horizontal || current.flip.vertical !== initial.flip.vertical || !nearlyEqual(current.cropRect.x, initial.cropRect.x) || !nearlyEqual(current.cropRect.y, initial.cropRect.y) || !nearlyEqual(current.cropRect.width, initial.cropRect.width) || !nearlyEqual(current.cropRect.height, initial.cropRect.height);
|
|
253
285
|
}
|
|
254
|
-
export {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
enforceContainment,
|
|
258
|
-
isStateDirty
|
|
259
|
-
};
|
|
260
|
-
//# sourceMappingURL=state.mjs.map
|
|
286
|
+
export { areCropperStatesEqual, cropperReducer, enforceContainment, isStateDirty };
|
|
287
|
+
|
|
288
|
+
//# sourceMappingURL=state.mjs.map
|