@wordpress/media-editor 0.20.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 +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- 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 -68
- 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 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- 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 -720
- 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 +136 -89
- 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 -281
- 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 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- 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 +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- 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 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- 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 -696
- 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 -75
- 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 -273
- 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 +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -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-crop-panel/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-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/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 +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- 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 +5 -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 +20 -42
- 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 +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- 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
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
// packages/media-editor/src/image-editor/react/components/cropper.tsx
|
|
2
1
|
import clsx from "clsx";
|
|
3
|
-
import {
|
|
4
|
-
useState,
|
|
5
|
-
useCallback,
|
|
6
|
-
useMemo,
|
|
7
|
-
useRef,
|
|
8
|
-
useEffect,
|
|
9
|
-
useLayoutEffect,
|
|
10
|
-
useId,
|
|
11
|
-
forwardRef
|
|
12
|
-
} from "@wordpress/element";
|
|
2
|
+
import { flushSync, forwardRef, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "@wordpress/element";
|
|
13
3
|
import { __ } from "@wordpress/i18n";
|
|
14
4
|
import { getImageFit, getRotatedBBox, getViewScale } from "../../core/camera.mjs";
|
|
15
5
|
import { getImageCropBounds, getMinZoom } from "../../core/containment.mjs";
|
|
16
|
-
import {
|
|
17
|
-
MAX_VIEW_SCALE,
|
|
18
|
-
PIXEL_SNAP_DISPLAY_SCALE,
|
|
19
|
-
SETTLE_TARGET_CANVAS_FILL
|
|
20
|
-
} from "../../core/constants.mjs";
|
|
6
|
+
import { MAX_VIEW_SCALE, PIXEL_SNAP_DISPLAY_SCALE, SETTLE_TARGET_CANVAS_FILL } from "../../core/constants.mjs";
|
|
21
7
|
import { computeInscribedRect } from "../../core/crop-rect.mjs";
|
|
22
8
|
import { getMinCropPixels } from "../../core/stencil-math.mjs";
|
|
23
9
|
import { useInteraction } from "../hooks/use-interaction.mjs";
|
|
@@ -27,688 +13,556 @@ import { RectangleStencil } from "./stencils/rectangle-stencil.mjs";
|
|
|
27
13
|
import { DimmingOverlay } from "./overlays/dimming-overlay.mjs";
|
|
28
14
|
import { GridOverlay } from "./overlays/grid-overlay.mjs";
|
|
29
15
|
import { DimensionsOverlay } from "./overlays/dimensions-overlay.mjs";
|
|
30
|
-
import {
|
|
31
|
-
getSourceRegion,
|
|
32
|
-
snapCropRectToSourcePixelGrid,
|
|
33
|
-
snapCropRectToSourcePixels
|
|
34
|
-
} from "../../core/source-region.mjs";
|
|
16
|
+
import { getSourceRegion, snapCropRectToSourcePixelGrid, snapCropRectToSourcePixels } from "../../core/source-region.mjs";
|
|
35
17
|
import { ViewportProvider, useViewport } from "./viewport-provider.mjs";
|
|
36
18
|
import { VISUALLY_HIDDEN_STYLE } from "../visually-hidden-style.mjs";
|
|
37
19
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
20
|
+
// packages/media-editor/src/image-editor/react/components/cropper.tsx
|
|
21
|
+
/** Threshold for comparing normalized crop rect values. */
|
|
22
|
+
const CROP_RECT_EPSILON = 1e-6;
|
|
23
|
+
/** Threshold for deciding whether rotation is at a 90-degree stop. */
|
|
24
|
+
const CARDINAL_ROTATION_EPSILON = 1e-6;
|
|
25
|
+
/** Duration of the settle transform transition after resize end. */
|
|
26
|
+
const SETTLE_TRANSITION_DURATION_MS = 200;
|
|
27
|
+
const SETTLE_TRANSITION_FALLBACK_MS = 300;
|
|
28
|
+
const SETTLE_TRANSFORM_TRANSITION = `transform ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`;
|
|
29
|
+
const SETTLE_STENCIL_TRANSITION = [
|
|
30
|
+
`left ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
|
|
31
|
+
`top ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
|
|
32
|
+
`width ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`,
|
|
33
|
+
`height ${SETTLE_TRANSITION_DURATION_MS}ms ease-out`
|
|
48
34
|
].join(", ");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
575
|
-
const setContainerRef = useCallback(
|
|
576
|
-
(element) => {
|
|
577
|
-
if (typeof ref === "function") {
|
|
578
|
-
ref(element);
|
|
579
|
-
} else if (ref) {
|
|
580
|
-
ref.current = element;
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
|
-
[ref]
|
|
584
|
-
);
|
|
585
|
-
return /* @__PURE__ */ jsx(
|
|
586
|
-
"div",
|
|
587
|
-
{
|
|
588
|
-
ref: setContainerRef,
|
|
589
|
-
className: clsx(
|
|
590
|
-
"wp-media-editor-image-editor",
|
|
591
|
-
isDragging && "wp-media-editor-image-editor--dragging",
|
|
592
|
-
className
|
|
593
|
-
),
|
|
594
|
-
children: /* @__PURE__ */ jsxs(
|
|
595
|
-
"div",
|
|
596
|
-
{
|
|
597
|
-
ref: canvasRef,
|
|
598
|
-
className: clsx(
|
|
599
|
-
"wp-media-editor-image-editor__canvas",
|
|
600
|
-
isInteractiveGrid && "wp-media-editor-image-editor__canvas--grid-interactive",
|
|
601
|
-
showInteractiveGrid && "wp-media-editor-image-editor__canvas--show-grid",
|
|
602
|
-
settling && "wp-media-editor-image-editor__canvas--settling",
|
|
603
|
-
// Marks the cropper as in keyboard-interaction mode.
|
|
604
|
-
// CSS uses :focus on the canvas to show the stencil
|
|
605
|
-
// outline and :focus on a handle to show its ring,
|
|
606
|
-
// so the class applies whenever any cropper element
|
|
607
|
-
// has keyboard focus.
|
|
608
|
-
isFocusVisible && "wp-media-editor-image-editor__canvas--focus-visible"
|
|
609
|
-
),
|
|
610
|
-
tabIndex: 0,
|
|
611
|
-
role: "group",
|
|
612
|
-
"aria-label": __("Crop area"),
|
|
613
|
-
"aria-describedby": isCropAreaFocused ? cropAreaDescriptionId : void 0,
|
|
614
|
-
onFocus: handleCropAreaFocus,
|
|
615
|
-
onBlur: handleCropAreaBlur,
|
|
616
|
-
...canvasHandlers,
|
|
617
|
-
children: [
|
|
618
|
-
/* @__PURE__ */ jsx(
|
|
619
|
-
"div",
|
|
620
|
-
{
|
|
621
|
-
id: cropAreaDescriptionId,
|
|
622
|
-
style: VISUALLY_HIDDEN_STYLE,
|
|
623
|
-
children: __(
|
|
624
|
-
"When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls."
|
|
625
|
-
)
|
|
626
|
-
}
|
|
627
|
-
),
|
|
628
|
-
/* @__PURE__ */ jsxs(
|
|
629
|
-
"div",
|
|
630
|
-
{
|
|
631
|
-
className: "wp-media-editor-image-editor__stage",
|
|
632
|
-
"data-testid": "cropper-stage",
|
|
633
|
-
style: stageStyle,
|
|
634
|
-
onTransitionEnd: handleSettleTransitionEnd,
|
|
635
|
-
children: [
|
|
636
|
-
/* @__PURE__ */ jsx(
|
|
637
|
-
"img",
|
|
638
|
-
{
|
|
639
|
-
className: "wp-media-editor-image-editor__image",
|
|
640
|
-
"data-testid": "cropper-image",
|
|
641
|
-
src,
|
|
642
|
-
alt: "",
|
|
643
|
-
onLoad: handleImageLoad,
|
|
644
|
-
style: imageStyle,
|
|
645
|
-
draggable: false
|
|
646
|
-
}
|
|
647
|
-
),
|
|
648
|
-
showDimming && /* @__PURE__ */ jsx(
|
|
649
|
-
DimmingOverlay,
|
|
650
|
-
{
|
|
651
|
-
cropRect: state.cropRect,
|
|
652
|
-
containerSize: canvasSize,
|
|
653
|
-
imageSize: scaledVisualSize,
|
|
654
|
-
transition: settleStencilTransition
|
|
655
|
-
}
|
|
656
|
-
),
|
|
657
|
-
/* @__PURE__ */ jsx(
|
|
658
|
-
StencilComponent,
|
|
659
|
-
{
|
|
660
|
-
cropRect: state.cropRect,
|
|
661
|
-
containerSize: canvasSize,
|
|
662
|
-
imageSize: scaledVisualSize,
|
|
663
|
-
onCropChange: handleCropChange,
|
|
664
|
-
onResizeStart: handleResizeStart,
|
|
665
|
-
onResizeEnd: handleResizeEnd,
|
|
666
|
-
onEscape: handleEscape,
|
|
667
|
-
aspectRatio,
|
|
668
|
-
freeformCrop,
|
|
669
|
-
isResizeDisabled: isTouchPinching || disabled,
|
|
670
|
-
stencilTransition: settleStencilTransition,
|
|
671
|
-
cropBounds,
|
|
672
|
-
minCropSize,
|
|
673
|
-
snapCropRect,
|
|
674
|
-
keyboardResizeStep
|
|
675
|
-
}
|
|
676
|
-
),
|
|
677
|
-
(showGrid === true || isInteractiveGrid) && /* @__PURE__ */ jsx(
|
|
678
|
-
GridOverlay,
|
|
679
|
-
{
|
|
680
|
-
cropRect: state.cropRect,
|
|
681
|
-
containerSize: canvasSize,
|
|
682
|
-
imageSize: scaledVisualSize
|
|
683
|
-
}
|
|
684
|
-
),
|
|
685
|
-
activeHandle && outputSize && /* @__PURE__ */ jsx(
|
|
686
|
-
DimensionsOverlay,
|
|
687
|
-
{
|
|
688
|
-
cropRect: state.cropRect,
|
|
689
|
-
containerSize: canvasSize,
|
|
690
|
-
imageSize: scaledVisualSize,
|
|
691
|
-
activeHandle,
|
|
692
|
-
outputWidth: outputSize.width,
|
|
693
|
-
outputHeight: outputSize.height
|
|
694
|
-
}
|
|
695
|
-
)
|
|
696
|
-
]
|
|
697
|
-
}
|
|
698
|
-
)
|
|
699
|
-
]
|
|
700
|
-
}
|
|
701
|
-
)
|
|
702
|
-
}
|
|
703
|
-
);
|
|
35
|
+
/**
|
|
36
|
+
* The main image cropper component.
|
|
37
|
+
*
|
|
38
|
+
* Renders an image within a container with interactive crop overlays.
|
|
39
|
+
* Creates the camera once per render via getImageFit, then passes
|
|
40
|
+
* derived values to stencil, overlays, and interaction hooks.
|
|
41
|
+
*
|
|
42
|
+
* The component fills its parent container (100% width and height).
|
|
43
|
+
* Wrap it in a sized container to control its dimensions.
|
|
44
|
+
*
|
|
45
|
+
* @param root0 Component props implementing CropperProps.
|
|
46
|
+
* @param root0.src Image source URL.
|
|
47
|
+
* @param root0.controller The cropper controller from `useCropperController` or a composite store.
|
|
48
|
+
* @param root0.stencil Custom stencil component.
|
|
49
|
+
* @param root0.showGrid Grid overlay mode: false | true | 'interactive'.
|
|
50
|
+
* @param root0.isPlacementActive Keep grid visible during external placement activity.
|
|
51
|
+
* @param root0.showDimming Show dimming overlay outside crop.
|
|
52
|
+
* @param root0.showDimensions Show live dimensions tooltip during resize.
|
|
53
|
+
* @param root0.minZoom Minimum zoom level override.
|
|
54
|
+
* @param root0.maxZoom Maximum zoom level.
|
|
55
|
+
* @param root0.aspectRatio Fixed aspect ratio (width/height).
|
|
56
|
+
* @param root0.freeformCrop Enable resize handles.
|
|
57
|
+
* @param root0.focusOnMount Focus the crop area on mount.
|
|
58
|
+
* @param root0.disabled Ignore all crop interaction.
|
|
59
|
+
* @param root0.onImageLoaded Image load callback.
|
|
60
|
+
* @param root0.onImageError Image error callback.
|
|
61
|
+
* @param root0.onGestureStart Gesture boundary start.
|
|
62
|
+
* @param root0.onGestureEnd Gesture boundary end.
|
|
63
|
+
* @param root0.className Additional CSS class.
|
|
64
|
+
* @param ref Forwarded ref for the container div.
|
|
65
|
+
*/
|
|
66
|
+
function CropperInner({ src, controller, stencil: StencilComponent = RectangleStencil, showGrid = false, isPlacementActive = false, showDimming = true, showDimensions = true, minZoom, maxZoom, aspectRatio, freeformCrop = false, focusOnMount = false, disabled = false, onImageLoaded, onImageError, onGestureStart, onGestureEnd, className }, ref) {
|
|
67
|
+
const { state, setImage, setCropRect, settleCrop, setVisualSize, adjustCropRectForViewport } = controller;
|
|
68
|
+
const { viewport: viewportState, setViewportPan, resetViewport } = useViewport();
|
|
69
|
+
const canvasRef = useRef(null);
|
|
70
|
+
const cropAreaDescriptionId = useId();
|
|
71
|
+
const [isCropAreaFocused, setIsCropAreaFocused] = useState(focusOnMount);
|
|
72
|
+
const [isFocusVisible, setIsFocusVisible] = useState(false);
|
|
73
|
+
const [canvasSize, setCanvasSize] = useState({
|
|
74
|
+
width: 0,
|
|
75
|
+
height: 0
|
|
76
|
+
});
|
|
77
|
+
useLayoutEffect(() => {
|
|
78
|
+
if (focusOnMount) canvasRef.current?.focus({ preventScroll: true });
|
|
79
|
+
}, [focusOnMount]);
|
|
80
|
+
const handleCropAreaFocus = useCallback((event) => {
|
|
81
|
+
const target = event.target;
|
|
82
|
+
if (target === event.currentTarget) setIsCropAreaFocused(true);
|
|
83
|
+
if (event.relatedTarget !== null && target.matches(":focus-visible")) setIsFocusVisible(true);
|
|
84
|
+
}, []);
|
|
85
|
+
const handleCropAreaBlur = useCallback((event) => {
|
|
86
|
+
if (event.target === event.currentTarget) setIsCropAreaFocused(false);
|
|
87
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setIsFocusVisible(false);
|
|
88
|
+
}, []);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
const element = canvasRef.current;
|
|
91
|
+
if (!element) return;
|
|
92
|
+
const observer = new ResizeObserver((entries) => {
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const { width, height } = entry.contentRect;
|
|
95
|
+
flushSync(() => {
|
|
96
|
+
setCanvasSize((prev) => {
|
|
97
|
+
if (prev.width === width && prev.height === height) return prev;
|
|
98
|
+
return {
|
|
99
|
+
width,
|
|
100
|
+
height
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
observer.observe(element);
|
|
107
|
+
return () => {
|
|
108
|
+
observer.disconnect();
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
111
|
+
useAriaAnnouncer(state);
|
|
112
|
+
const naturalWidth = state.image?.naturalWidth ?? 0;
|
|
113
|
+
const naturalHeight = state.image?.naturalHeight ?? 0;
|
|
114
|
+
const { elementSize, visualSize } = useMemo(() => getImageFit(canvasSize, {
|
|
115
|
+
width: naturalWidth,
|
|
116
|
+
height: naturalHeight
|
|
117
|
+
}, state.rotation), [
|
|
118
|
+
canvasSize,
|
|
119
|
+
naturalWidth,
|
|
120
|
+
naturalHeight,
|
|
121
|
+
state.rotation
|
|
122
|
+
]);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
setVisualSize(visualSize);
|
|
125
|
+
}, [visualSize, setVisualSize]);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (freeformCrop || visualSize.width === 0 || visualSize.height === 0 || !aspectRatio || aspectRatio <= 0) return;
|
|
128
|
+
const rect = computeInscribedRect(aspectRatio, visualSize);
|
|
129
|
+
const current = state.cropRect;
|
|
130
|
+
if (Math.abs(current.x - rect.x) < CROP_RECT_EPSILON && Math.abs(current.y - rect.y) < CROP_RECT_EPSILON && Math.abs(current.width - rect.width) < CROP_RECT_EPSILON && Math.abs(current.height - rect.height) < CROP_RECT_EPSILON) return;
|
|
131
|
+
adjustCropRectForViewport(rect);
|
|
132
|
+
}, [
|
|
133
|
+
freeformCrop,
|
|
134
|
+
aspectRatio,
|
|
135
|
+
visualSize,
|
|
136
|
+
adjustCropRectForViewport,
|
|
137
|
+
state.cropRect
|
|
138
|
+
]);
|
|
139
|
+
const prevAspectRatioRef = useRef(aspectRatio);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (prevAspectRatioRef.current === aspectRatio) return;
|
|
142
|
+
prevAspectRatioRef.current = aspectRatio;
|
|
143
|
+
if (!freeformCrop || visualSize.width === 0 || visualSize.height === 0 || !aspectRatio || aspectRatio <= 0) return;
|
|
144
|
+
const rect = computeInscribedRect(aspectRatio, visualSize);
|
|
145
|
+
const current = state.cropRect;
|
|
146
|
+
if (Math.abs(current.x - rect.x) < CROP_RECT_EPSILON && Math.abs(current.y - rect.y) < CROP_RECT_EPSILON && Math.abs(current.width - rect.width) < CROP_RECT_EPSILON && Math.abs(current.height - rect.height) < CROP_RECT_EPSILON) return;
|
|
147
|
+
adjustCropRectForViewport(rect);
|
|
148
|
+
}, [
|
|
149
|
+
aspectRatio,
|
|
150
|
+
freeformCrop,
|
|
151
|
+
visualSize,
|
|
152
|
+
adjustCropRectForViewport,
|
|
153
|
+
state.cropRect
|
|
154
|
+
]);
|
|
155
|
+
const cropBounds = useMemo(() => {
|
|
156
|
+
if (!state.image || elementSize.width === 0) return;
|
|
157
|
+
return getImageCropBounds(state, elementSize, visualSize);
|
|
158
|
+
}, [
|
|
159
|
+
state,
|
|
160
|
+
elementSize,
|
|
161
|
+
visualSize
|
|
162
|
+
]);
|
|
163
|
+
const effectiveMinZoom = minZoom !== void 0 ? minZoom : getMinZoom(state);
|
|
164
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
165
|
+
const isResizingRef = useRef(false);
|
|
166
|
+
const isSettlingRef = useRef(false);
|
|
167
|
+
const [isTouchPinching, setIsTouchPinchingState] = useState(false);
|
|
168
|
+
const isTouchPinchingRef = useRef(false);
|
|
169
|
+
const setTouchPinching = useCallback((isPinching) => {
|
|
170
|
+
isTouchPinchingRef.current = isPinching;
|
|
171
|
+
setIsTouchPinchingState(isPinching);
|
|
172
|
+
}, []);
|
|
173
|
+
const [activeHandle, setActiveHandle] = useState(null);
|
|
174
|
+
const viewScaleRest = useMemo(() => getViewScale(state.cropRect, canvasSize, visualSize, SETTLE_TARGET_CANVAS_FILL, MAX_VIEW_SCALE), [
|
|
175
|
+
state.cropRect,
|
|
176
|
+
canvasSize,
|
|
177
|
+
visualSize
|
|
178
|
+
]);
|
|
179
|
+
const [frozenViewScale, setFrozenViewScale] = useState(1);
|
|
180
|
+
const viewScale = isResizing ? frozenViewScale : viewScaleRest;
|
|
181
|
+
const scaledVisualSize = useMemo(() => ({
|
|
182
|
+
width: visualSize.width * viewScale,
|
|
183
|
+
height: visualSize.height * viewScale
|
|
184
|
+
}), [
|
|
185
|
+
visualSize.width,
|
|
186
|
+
visualSize.height,
|
|
187
|
+
viewScale
|
|
188
|
+
]);
|
|
189
|
+
const displayScale = naturalWidth > 0 ? elementSize.width / naturalWidth * state.zoom * viewScale : 0;
|
|
190
|
+
const keyboardResizeStep = useMemo(() => {
|
|
191
|
+
if (displayScale < PIXEL_SNAP_DISPLAY_SCALE || aspectRatio && aspectRatio > 0 || naturalWidth <= 0 || naturalHeight <= 0) return;
|
|
192
|
+
const snapRotation = Math.round(state.rotation / 90) * 90;
|
|
193
|
+
if (Math.abs(state.rotation - snapRotation) >= CARDINAL_ROTATION_EPSILON) return;
|
|
194
|
+
const bbox = getRotatedBBox(naturalWidth, naturalHeight, snapRotation);
|
|
195
|
+
if (bbox.width <= 0 || bbox.height <= 0) return;
|
|
196
|
+
return {
|
|
197
|
+
width: state.zoom / bbox.width,
|
|
198
|
+
height: state.zoom / bbox.height
|
|
199
|
+
};
|
|
200
|
+
}, [
|
|
201
|
+
displayScale,
|
|
202
|
+
aspectRatio,
|
|
203
|
+
naturalWidth,
|
|
204
|
+
naturalHeight,
|
|
205
|
+
state.rotation,
|
|
206
|
+
state.zoom
|
|
207
|
+
]);
|
|
208
|
+
const minCropSize = useMemo(() => {
|
|
209
|
+
if (naturalWidth <= 0 || naturalHeight <= 0) return;
|
|
210
|
+
const snapRotation = Math.round(state.rotation / 90) * 90;
|
|
211
|
+
const bbox = getRotatedBBox(naturalWidth, naturalHeight, snapRotation);
|
|
212
|
+
const minPixels = getMinCropPixels(displayScale);
|
|
213
|
+
return {
|
|
214
|
+
width: Math.min(1, minPixels * state.zoom / bbox.width),
|
|
215
|
+
height: Math.min(1, minPixels * state.zoom / bbox.height)
|
|
216
|
+
};
|
|
217
|
+
}, [
|
|
218
|
+
naturalWidth,
|
|
219
|
+
naturalHeight,
|
|
220
|
+
state.rotation,
|
|
221
|
+
state.zoom,
|
|
222
|
+
displayScale
|
|
223
|
+
]);
|
|
224
|
+
const snapCropRect = useCallback((rect, handle) => {
|
|
225
|
+
if (displayScale < PIXEL_SNAP_DISPLAY_SCALE || naturalWidth <= 0 || naturalHeight <= 0) return rect;
|
|
226
|
+
return snapCropRectToSourcePixels(state, {
|
|
227
|
+
width: naturalWidth,
|
|
228
|
+
height: naturalHeight
|
|
229
|
+
}, rect, handle);
|
|
230
|
+
}, [
|
|
231
|
+
displayScale,
|
|
232
|
+
naturalWidth,
|
|
233
|
+
naturalHeight,
|
|
234
|
+
state
|
|
235
|
+
]);
|
|
236
|
+
const wasPixelSnapEnabledRef = useRef(false);
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
const isPixelSnapEnabled = freeformCrop && (!aspectRatio || aspectRatio <= 0) && displayScale >= PIXEL_SNAP_DISPLAY_SCALE && naturalWidth > 0 && naturalHeight > 0;
|
|
239
|
+
const wasPixelSnapEnabled = wasPixelSnapEnabledRef.current;
|
|
240
|
+
wasPixelSnapEnabledRef.current = isPixelSnapEnabled;
|
|
241
|
+
if (!isPixelSnapEnabled || wasPixelSnapEnabled) return;
|
|
242
|
+
const snappedCropRect = snapCropRectToSourcePixelGrid(state, {
|
|
243
|
+
width: naturalWidth,
|
|
244
|
+
height: naturalHeight
|
|
245
|
+
}, state.cropRect);
|
|
246
|
+
const currentCropRect = state.cropRect;
|
|
247
|
+
if (Math.abs(currentCropRect.x - snappedCropRect.x) < CROP_RECT_EPSILON && Math.abs(currentCropRect.y - snappedCropRect.y) < CROP_RECT_EPSILON && Math.abs(currentCropRect.width - snappedCropRect.width) < CROP_RECT_EPSILON && Math.abs(currentCropRect.height - snappedCropRect.height) < CROP_RECT_EPSILON) return;
|
|
248
|
+
adjustCropRectForViewport(snappedCropRect);
|
|
249
|
+
}, [
|
|
250
|
+
adjustCropRectForViewport,
|
|
251
|
+
aspectRatio,
|
|
252
|
+
displayScale,
|
|
253
|
+
freeformCrop,
|
|
254
|
+
naturalWidth,
|
|
255
|
+
naturalHeight,
|
|
256
|
+
state
|
|
257
|
+
]);
|
|
258
|
+
const { handlers, onWheelNative, isDragging, isZooming, isPlacementActive: isInteractionPlacementActive } = useInteraction(state, controller, canvasSize, scaledVisualSize, {
|
|
259
|
+
minZoom: effectiveMinZoom,
|
|
260
|
+
maxZoom,
|
|
261
|
+
onGestureStart,
|
|
262
|
+
onGestureEnd,
|
|
263
|
+
disabled
|
|
264
|
+
});
|
|
265
|
+
const canvasHandlers = {
|
|
266
|
+
...handlers,
|
|
267
|
+
onPointerDownCapture: () => {
|
|
268
|
+
setIsFocusVisible(false);
|
|
269
|
+
},
|
|
270
|
+
onTouchStartCapture: (event) => {
|
|
271
|
+
if (event.touches.length > 1) setTouchPinching(true);
|
|
272
|
+
},
|
|
273
|
+
onTouchMoveCapture: (event) => {
|
|
274
|
+
if (event.touches.length > 1) setTouchPinching(true);
|
|
275
|
+
},
|
|
276
|
+
onTouchEndCapture: (event) => {
|
|
277
|
+
if (event.touches.length === 0) setTouchPinching(false);
|
|
278
|
+
},
|
|
279
|
+
onTouchCancelCapture: (event) => {
|
|
280
|
+
if (event.touches.length === 0) setTouchPinching(false);
|
|
281
|
+
},
|
|
282
|
+
onKeyDownCapture: (event) => {
|
|
283
|
+
if (![
|
|
284
|
+
"Shift",
|
|
285
|
+
"Control",
|
|
286
|
+
"Alt",
|
|
287
|
+
"Meta"
|
|
288
|
+
].includes(event.key)) setIsFocusVisible(true);
|
|
289
|
+
},
|
|
290
|
+
onPointerDown: (event) => {
|
|
291
|
+
if (disabled || isResizingRef.current || isTouchPinchingRef.current || event.pointerType === "touch" && event.isPrimary === false) {
|
|
292
|
+
event.preventDefault();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
handlers.onPointerDown?.(event);
|
|
296
|
+
setIsFocusVisible(false);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
const el = canvasRef.current;
|
|
301
|
+
if (!el) return;
|
|
302
|
+
const handleWheel = (event) => {
|
|
303
|
+
if (isResizingRef.current || isSettlingRef.current) {
|
|
304
|
+
event.preventDefault();
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
onWheelNative(event);
|
|
308
|
+
};
|
|
309
|
+
el.addEventListener("wheel", handleWheel, { passive: false });
|
|
310
|
+
return () => {
|
|
311
|
+
el.removeEventListener("wheel", handleWheel);
|
|
312
|
+
};
|
|
313
|
+
}, [onWheelNative]);
|
|
314
|
+
const transformString = useTransformStyle(state, visualSize);
|
|
315
|
+
/**
|
|
316
|
+
* Handle the image load event.
|
|
317
|
+
*/
|
|
318
|
+
const handleImageLoad = useCallback((event) => {
|
|
319
|
+
const img = event.currentTarget;
|
|
320
|
+
const size = {
|
|
321
|
+
width: img.naturalWidth,
|
|
322
|
+
height: img.naturalHeight
|
|
323
|
+
};
|
|
324
|
+
setImage({
|
|
325
|
+
src,
|
|
326
|
+
naturalWidth: size.width,
|
|
327
|
+
naturalHeight: size.height
|
|
328
|
+
});
|
|
329
|
+
onImageLoaded?.(size);
|
|
330
|
+
}, [
|
|
331
|
+
src,
|
|
332
|
+
setImage,
|
|
333
|
+
onImageLoaded
|
|
334
|
+
]);
|
|
335
|
+
const handleCropChange = useCallback((rect) => {
|
|
336
|
+
if (isTouchPinchingRef.current) return;
|
|
337
|
+
setCropRect(rect);
|
|
338
|
+
if (isResizingRef.current && scaledVisualSize.width > 0 && scaledVisualSize.height > 0) {
|
|
339
|
+
const offsetX = (canvasSize.width - scaledVisualSize.width) / 2;
|
|
340
|
+
const offsetY = (canvasSize.height - scaledVisualSize.height) / 2;
|
|
341
|
+
const rightOverflow = Math.max(0, offsetX + (rect.x + rect.width) * scaledVisualSize.width - canvasSize.width);
|
|
342
|
+
const leftOverflow = Math.max(0, -(offsetX + rect.x * scaledVisualSize.width));
|
|
343
|
+
const bottomOverflow = Math.max(0, offsetY + (rect.y + rect.height) * scaledVisualSize.height - canvasSize.height);
|
|
344
|
+
const topOverflow = Math.max(0, -(offsetY + rect.y * scaledVisualSize.height));
|
|
345
|
+
setViewportPan({
|
|
346
|
+
x: -rightOverflow + leftOverflow,
|
|
347
|
+
y: -bottomOverflow + topOverflow
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}, [
|
|
351
|
+
setCropRect,
|
|
352
|
+
setViewportPan,
|
|
353
|
+
canvasSize,
|
|
354
|
+
scaledVisualSize
|
|
355
|
+
]);
|
|
356
|
+
const [settling, setSettling] = useState(false);
|
|
357
|
+
const settleTimerRef = useRef(void 0);
|
|
358
|
+
const finishSettling = useCallback(() => {
|
|
359
|
+
clearTimeout(settleTimerRef.current);
|
|
360
|
+
isSettlingRef.current = false;
|
|
361
|
+
setSettling(false);
|
|
362
|
+
}, []);
|
|
363
|
+
useEffect(() => {
|
|
364
|
+
return () => {
|
|
365
|
+
clearTimeout(settleTimerRef.current);
|
|
366
|
+
};
|
|
367
|
+
}, []);
|
|
368
|
+
const isInteractiveGrid = showGrid === "interactive";
|
|
369
|
+
const showInteractiveGrid = isInteractiveGrid && (isInteractionPlacementActive || isResizing || isPlacementActive);
|
|
370
|
+
const outputSize = useMemo(() => {
|
|
371
|
+
if (!showDimensions || !activeHandle || !state.image) return null;
|
|
372
|
+
const region = getSourceRegion(state, {
|
|
373
|
+
width: state.image.naturalWidth,
|
|
374
|
+
height: state.image.naturalHeight
|
|
375
|
+
});
|
|
376
|
+
return {
|
|
377
|
+
width: region.width,
|
|
378
|
+
height: region.height
|
|
379
|
+
};
|
|
380
|
+
}, [
|
|
381
|
+
showDimensions,
|
|
382
|
+
activeHandle,
|
|
383
|
+
state
|
|
384
|
+
]);
|
|
385
|
+
/**
|
|
386
|
+
* Handle Escape on a resize handle — return focus to the canvas so
|
|
387
|
+
* arrow keys pan the image rather than resize.
|
|
388
|
+
*/
|
|
389
|
+
const handleEscape = useCallback(() => {
|
|
390
|
+
setIsFocusVisible(true);
|
|
391
|
+
canvasRef.current?.focus({ preventScroll: true });
|
|
392
|
+
}, []);
|
|
393
|
+
const handleResizeStart = useCallback((handle) => {
|
|
394
|
+
if (isTouchPinchingRef.current) return;
|
|
395
|
+
setFrozenViewScale(viewScaleRest);
|
|
396
|
+
isResizingRef.current = true;
|
|
397
|
+
setIsResizing(true);
|
|
398
|
+
setActiveHandle(handle ?? null);
|
|
399
|
+
finishSettling();
|
|
400
|
+
resetViewport();
|
|
401
|
+
onGestureStart?.();
|
|
402
|
+
}, [
|
|
403
|
+
finishSettling,
|
|
404
|
+
onGestureStart,
|
|
405
|
+
resetViewport,
|
|
406
|
+
viewScaleRest
|
|
407
|
+
]);
|
|
408
|
+
/**
|
|
409
|
+
* Handle resize end — settle the crop rect (re-center, fill height)
|
|
410
|
+
* and reset the viewport pan back to neutral.
|
|
411
|
+
*/
|
|
412
|
+
const handleResizeEnd = useCallback(() => {
|
|
413
|
+
const isCancellingForPinch = isTouchPinchingRef.current;
|
|
414
|
+
isResizingRef.current = false;
|
|
415
|
+
setIsResizing(false);
|
|
416
|
+
setActiveHandle(null);
|
|
417
|
+
clearTimeout(settleTimerRef.current);
|
|
418
|
+
if (isCancellingForPinch) {
|
|
419
|
+
finishSettling();
|
|
420
|
+
resetViewport();
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
isSettlingRef.current = true;
|
|
424
|
+
setSettling(true);
|
|
425
|
+
resetViewport();
|
|
426
|
+
settleCrop();
|
|
427
|
+
onGestureEnd?.();
|
|
428
|
+
settleTimerRef.current = setTimeout(finishSettling, SETTLE_TRANSITION_FALLBACK_MS);
|
|
429
|
+
}, [
|
|
430
|
+
finishSettling,
|
|
431
|
+
settleCrop,
|
|
432
|
+
onGestureEnd,
|
|
433
|
+
resetViewport
|
|
434
|
+
]);
|
|
435
|
+
/**
|
|
436
|
+
* Finish settling when the settle transform transition actually completes.
|
|
437
|
+
* The handler lives on the stage, but in the common (un-panned) case the
|
|
438
|
+
* transform transition runs on the image layer and its `transitionend`
|
|
439
|
+
* bubbles up to here. Other transitionend events (stencil left/top/width/
|
|
440
|
+
* height) also bubble up, so only the transform transition should clear the
|
|
441
|
+
* settle state.
|
|
442
|
+
*/
|
|
443
|
+
const handleSettleTransitionEnd = useCallback((event) => {
|
|
444
|
+
if (!isSettlingRef.current || event.propertyName !== "transform") return;
|
|
445
|
+
finishSettling();
|
|
446
|
+
}, [finishSettling]);
|
|
447
|
+
let imageTransition;
|
|
448
|
+
if (settling) imageTransition = SETTLE_TRANSFORM_TRANSITION;
|
|
449
|
+
else if (isZooming) imageTransition = "transform 150ms linear";
|
|
450
|
+
const settleStencilTransition = settling ? SETTLE_STENCIL_TRANSITION : void 0;
|
|
451
|
+
const imageStyle = useMemo(() => {
|
|
452
|
+
if (elementSize.width === 0 || elementSize.height === 0) return {};
|
|
453
|
+
const centerX = (canvasSize.width - elementSize.width) / 2;
|
|
454
|
+
const centerY = (canvasSize.height - elementSize.height) / 2;
|
|
455
|
+
return {
|
|
456
|
+
width: elementSize.width,
|
|
457
|
+
height: elementSize.height,
|
|
458
|
+
maxWidth: elementSize.width,
|
|
459
|
+
maxHeight: elementSize.height,
|
|
460
|
+
left: centerX,
|
|
461
|
+
top: centerY,
|
|
462
|
+
transform: `scale(${viewScale}) ${transformString}`,
|
|
463
|
+
transition: imageTransition,
|
|
464
|
+
imageRendering: displayScale > 1 ? "pixelated" : void 0
|
|
465
|
+
};
|
|
466
|
+
}, [
|
|
467
|
+
canvasSize,
|
|
468
|
+
elementSize,
|
|
469
|
+
transformString,
|
|
470
|
+
imageTransition,
|
|
471
|
+
displayScale,
|
|
472
|
+
viewScale
|
|
473
|
+
]);
|
|
474
|
+
const settleTransition = settling ? SETTLE_TRANSFORM_TRANSITION : void 0;
|
|
475
|
+
const willChange = isResizing || settling ? "transform" : void 0;
|
|
476
|
+
let stageStyle;
|
|
477
|
+
if (viewportState.pan.x !== 0 || viewportState.pan.y !== 0) stageStyle = {
|
|
478
|
+
transform: `translate(${viewportState.pan.x}px, ${viewportState.pan.y}px)`,
|
|
479
|
+
transition: settleTransition,
|
|
480
|
+
willChange
|
|
481
|
+
};
|
|
482
|
+
else if (settling) stageStyle = {
|
|
483
|
+
transform: "translate(0px, 0px)",
|
|
484
|
+
transition: settleTransition,
|
|
485
|
+
willChange
|
|
486
|
+
};
|
|
487
|
+
return /* @__PURE__ */ jsx("div", {
|
|
488
|
+
ref,
|
|
489
|
+
className: clsx("wp-media-editor-image-editor", isDragging && "wp-media-editor-image-editor--dragging", className),
|
|
490
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
491
|
+
ref: canvasRef,
|
|
492
|
+
className: clsx("wp-media-editor-image-editor__canvas", isInteractiveGrid && "wp-media-editor-image-editor__canvas--grid-interactive", showInteractiveGrid && "wp-media-editor-image-editor__canvas--show-grid", settling && "wp-media-editor-image-editor__canvas--settling", isFocusVisible && "wp-media-editor-image-editor__canvas--focus-visible"),
|
|
493
|
+
tabIndex: 0,
|
|
494
|
+
role: "group",
|
|
495
|
+
"aria-label": __("Crop area"),
|
|
496
|
+
"aria-describedby": isCropAreaFocused ? cropAreaDescriptionId : void 0,
|
|
497
|
+
onFocus: handleCropAreaFocus,
|
|
498
|
+
onBlur: handleCropAreaBlur,
|
|
499
|
+
...canvasHandlers,
|
|
500
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
501
|
+
id: cropAreaDescriptionId,
|
|
502
|
+
style: VISUALLY_HIDDEN_STYLE,
|
|
503
|
+
children: __("When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.")
|
|
504
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
505
|
+
className: "wp-media-editor-image-editor__stage",
|
|
506
|
+
"data-testid": "cropper-stage",
|
|
507
|
+
style: stageStyle,
|
|
508
|
+
onTransitionEnd: handleSettleTransitionEnd,
|
|
509
|
+
children: [
|
|
510
|
+
/* @__PURE__ */ jsx("img", {
|
|
511
|
+
className: "wp-media-editor-image-editor__image",
|
|
512
|
+
"data-testid": "cropper-image",
|
|
513
|
+
src,
|
|
514
|
+
alt: "",
|
|
515
|
+
onLoad: handleImageLoad,
|
|
516
|
+
onError: onImageError,
|
|
517
|
+
style: imageStyle,
|
|
518
|
+
draggable: false
|
|
519
|
+
}),
|
|
520
|
+
showDimming && /* @__PURE__ */ jsx(DimmingOverlay, {
|
|
521
|
+
cropRect: state.cropRect,
|
|
522
|
+
containerSize: canvasSize,
|
|
523
|
+
imageSize: scaledVisualSize,
|
|
524
|
+
transition: settleStencilTransition
|
|
525
|
+
}),
|
|
526
|
+
/* @__PURE__ */ jsx(StencilComponent, {
|
|
527
|
+
cropRect: state.cropRect,
|
|
528
|
+
containerSize: canvasSize,
|
|
529
|
+
imageSize: scaledVisualSize,
|
|
530
|
+
onCropChange: handleCropChange,
|
|
531
|
+
onResizeStart: handleResizeStart,
|
|
532
|
+
onResizeEnd: handleResizeEnd,
|
|
533
|
+
onEscape: handleEscape,
|
|
534
|
+
aspectRatio,
|
|
535
|
+
freeformCrop,
|
|
536
|
+
isResizeDisabled: isTouchPinching || disabled,
|
|
537
|
+
stencilTransition: settleStencilTransition,
|
|
538
|
+
cropBounds,
|
|
539
|
+
minCropSize,
|
|
540
|
+
snapCropRect,
|
|
541
|
+
keyboardResizeStep
|
|
542
|
+
}),
|
|
543
|
+
(showGrid === true || isInteractiveGrid) && /* @__PURE__ */ jsx(GridOverlay, {
|
|
544
|
+
cropRect: state.cropRect,
|
|
545
|
+
containerSize: canvasSize,
|
|
546
|
+
imageSize: scaledVisualSize
|
|
547
|
+
}),
|
|
548
|
+
activeHandle && outputSize && /* @__PURE__ */ jsx(DimensionsOverlay, {
|
|
549
|
+
cropRect: state.cropRect,
|
|
550
|
+
containerSize: canvasSize,
|
|
551
|
+
imageSize: scaledVisualSize,
|
|
552
|
+
activeHandle,
|
|
553
|
+
outputWidth: outputSize.width,
|
|
554
|
+
outputHeight: outputSize.height
|
|
555
|
+
})
|
|
556
|
+
]
|
|
557
|
+
})]
|
|
558
|
+
})
|
|
559
|
+
});
|
|
704
560
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
};
|
|
714
|
-
//# sourceMappingURL=cropper.mjs.map
|
|
561
|
+
const CropperInnerWithRef = forwardRef(CropperInner);
|
|
562
|
+
const Cropper = forwardRef((props, ref) => /* @__PURE__ */ jsx(ViewportProvider, { children: /* @__PURE__ */ jsx(CropperInnerWithRef, {
|
|
563
|
+
...props,
|
|
564
|
+
ref
|
|
565
|
+
}) }));
|
|
566
|
+
export { Cropper };
|
|
567
|
+
|
|
568
|
+
//# sourceMappingURL=cropper.mjs.map
|