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