@wordpress/media-editor 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/components/media-editor/index.cjs +533 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +76 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -710
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +134 -112
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -294
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -673
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +98 -96
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +68 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +106 -90
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -686
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -90
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -286
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +4 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +1 -0
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +2 -1
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/media-editor/index.tsx +215 -162
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -2
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +16 -26
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-preview/index.tsx +66 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +19 -27
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +2 -2
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +2 -6
- package/src/state/use-media-editor-state.ts +7 -5
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
|
@@ -1,426 +1,367 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx
|
|
21
|
-
var rectangle_stencil_exports = {};
|
|
22
|
-
__export(rectangle_stencil_exports, {
|
|
23
|
-
RectangleStencil: () => RectangleStencil
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"w"
|
|
6
|
+
let _wordpress_element = require("@wordpress/element");
|
|
7
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
8
|
+
let _________core_constants_ts = require("../../../core/constants.cjs");
|
|
9
|
+
let _________core_stencil_math_ts = require("../../../core/stencil-math.cjs");
|
|
10
|
+
let ______visually_hidden_style_ts = require("../../visually-hidden-style.cjs");
|
|
11
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
|
+
// packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx
|
|
13
|
+
/**
|
|
14
|
+
* Corner handle positions only — used when aspect ratio is locked.
|
|
15
|
+
* Ordered clockwise from top-left for logical tab order.
|
|
16
|
+
*/
|
|
17
|
+
const CORNER_POSITIONS = [
|
|
18
|
+
"nw",
|
|
19
|
+
"ne",
|
|
20
|
+
"se",
|
|
21
|
+
"sw"
|
|
42
22
|
];
|
|
23
|
+
/**
|
|
24
|
+
* All handle positions rendered by the stencil.
|
|
25
|
+
* Ordered clockwise from top-left for logical tab order.
|
|
26
|
+
*/
|
|
27
|
+
const ALL_POSITIONS = [
|
|
28
|
+
"nw",
|
|
29
|
+
"n",
|
|
30
|
+
"ne",
|
|
31
|
+
"e",
|
|
32
|
+
"se",
|
|
33
|
+
"s",
|
|
34
|
+
"sw",
|
|
35
|
+
"w"
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* Get the translated aria-label for a resize handle position.
|
|
39
|
+
*
|
|
40
|
+
* @param pos The handle position identifier.
|
|
41
|
+
* @return The translated label string.
|
|
42
|
+
*/
|
|
43
43
|
function getHandleLabel(pos) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return (0, import_i18n.__)("Resize from top-left corner");
|
|
55
|
-
case "ne":
|
|
56
|
-
return (0, import_i18n.__)("Resize from top-right corner");
|
|
57
|
-
case "sw":
|
|
58
|
-
return (0, import_i18n.__)("Resize from bottom-left corner");
|
|
59
|
-
case "se":
|
|
60
|
-
return (0, import_i18n.__)("Resize from bottom-right corner");
|
|
61
|
-
}
|
|
44
|
+
switch (pos) {
|
|
45
|
+
case "n": return (0, _wordpress_i18n.__)("Resize from top edge");
|
|
46
|
+
case "s": return (0, _wordpress_i18n.__)("Resize from bottom edge");
|
|
47
|
+
case "e": return (0, _wordpress_i18n.__)("Resize from right edge");
|
|
48
|
+
case "w": return (0, _wordpress_i18n.__)("Resize from left edge");
|
|
49
|
+
case "nw": return (0, _wordpress_i18n.__)("Resize from top-left corner");
|
|
50
|
+
case "ne": return (0, _wordpress_i18n.__)("Resize from top-right corner");
|
|
51
|
+
case "sw": return (0, _wordpress_i18n.__)("Resize from bottom-left corner");
|
|
52
|
+
case "se": return (0, _wordpress_i18n.__)("Resize from bottom-right corner");
|
|
53
|
+
}
|
|
62
54
|
}
|
|
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
|
-
top,
|
|
373
|
-
width,
|
|
374
|
-
height,
|
|
375
|
-
transition: stencilTransition
|
|
376
|
-
},
|
|
377
|
-
children: [
|
|
378
|
-
freeformCrop && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
379
|
-
"div",
|
|
380
|
-
{
|
|
381
|
-
id: resizeHandleDescriptionId,
|
|
382
|
-
style: import_visually_hidden_style.VISUALLY_HIDDEN_STYLE,
|
|
383
|
-
children: (0, import_i18n.__)(
|
|
384
|
-
"Use arrow keys to resize the crop area. Hold Shift for larger steps."
|
|
385
|
-
)
|
|
386
|
-
}
|
|
387
|
-
),
|
|
388
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
389
|
-
"div",
|
|
390
|
-
{
|
|
391
|
-
className: "wp-media-editor-image-editor__stencil-rect",
|
|
392
|
-
style: {
|
|
393
|
-
width: "100%",
|
|
394
|
-
height: "100%",
|
|
395
|
-
top: 0,
|
|
396
|
-
left: 0
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
),
|
|
400
|
-
freeformCrop && handles.map((pos) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
401
|
-
"button",
|
|
402
|
-
{
|
|
403
|
-
type: "button",
|
|
404
|
-
className: `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${pos}`,
|
|
405
|
-
onPointerDown: (event) => handlePointerDown(pos, event),
|
|
406
|
-
onTouchStart: (event) => {
|
|
407
|
-
if (event.touches.length < 2) {
|
|
408
|
-
event.stopPropagation();
|
|
409
|
-
}
|
|
410
|
-
},
|
|
411
|
-
onKeyDown: (event) => handleKeyDown(pos, event),
|
|
412
|
-
disabled: isResizeDisabled,
|
|
413
|
-
"aria-label": getHandleLabel(pos),
|
|
414
|
-
"aria-describedby": resizeHandleDescriptionId
|
|
415
|
-
},
|
|
416
|
-
pos
|
|
417
|
-
))
|
|
418
|
-
]
|
|
419
|
-
}
|
|
420
|
-
);
|
|
55
|
+
/** Delay before keyboard resize triggers settle (ms). */
|
|
56
|
+
const KEYBOARD_SETTLE_DELAY = 500;
|
|
57
|
+
/**
|
|
58
|
+
* A rectangular crop stencil with resize handles.
|
|
59
|
+
*
|
|
60
|
+
* In freeform mode, handles resize the crop area. Clicks inside the
|
|
61
|
+
* crop pass through to the container for image panning. The crop
|
|
62
|
+
* auto-centers after resize via SETTLE_CROP.
|
|
63
|
+
*
|
|
64
|
+
* @param props Component props implementing StencilProps.
|
|
65
|
+
* @param props.cropRect The crop rectangle in normalized coordinates.
|
|
66
|
+
* @param props.containerSize The container element dimensions in pixels.
|
|
67
|
+
* @param props.imageSize The rendered image dimensions in pixels.
|
|
68
|
+
* @param props.onCropChange Callback fired when the crop rect changes.
|
|
69
|
+
* @param props.onResizeStart Callback fired when a resize drag starts.
|
|
70
|
+
* @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).
|
|
71
|
+
* @param props.aspectRatio Optional fixed aspect ratio (width / height).
|
|
72
|
+
* @param props.freeformCrop Whether resize handles are shown.
|
|
73
|
+
* @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.
|
|
74
|
+
* @param props.stencilTransition CSS transition string for settle animation.
|
|
75
|
+
* @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).
|
|
76
|
+
* @param props.onEscape Called when Escape is pressed on a resize handle.
|
|
77
|
+
* @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.
|
|
78
|
+
* @param props.snapCropRect Optional post-processor for freeform resize output.
|
|
79
|
+
* @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.
|
|
80
|
+
* @return The rectangle stencil element.
|
|
81
|
+
*/
|
|
82
|
+
function RectangleStencil({ cropRect, containerSize, imageSize, onCropChange, onResizeStart, onResizeEnd, aspectRatio, freeformCrop = false, isResizeDisabled = false, stencilTransition, cropBounds, onEscape, minCropSize, snapCropRect, keyboardResizeStep }) {
|
|
83
|
+
const boundsMinX = cropBounds?.minX ?? 0;
|
|
84
|
+
const boundsMinY = cropBounds?.minY ?? 0;
|
|
85
|
+
const boundsMaxX = cropBounds?.maxX ?? 1;
|
|
86
|
+
const boundsMaxY = cropBounds?.maxY ?? 1;
|
|
87
|
+
const bounds = (0, _wordpress_element.useMemo)(() => ({
|
|
88
|
+
minX: boundsMinX,
|
|
89
|
+
minY: boundsMinY,
|
|
90
|
+
maxX: boundsMaxX,
|
|
91
|
+
maxY: boundsMaxY
|
|
92
|
+
}), [
|
|
93
|
+
boundsMinX,
|
|
94
|
+
boundsMinY,
|
|
95
|
+
boundsMaxX,
|
|
96
|
+
boundsMaxY
|
|
97
|
+
]);
|
|
98
|
+
const keyboardSettleTimerRef = (0, _wordpress_element.useRef)(void 0);
|
|
99
|
+
const keyboardResizeActiveRef = (0, _wordpress_element.useRef)(false);
|
|
100
|
+
const resizeHandleDescriptionId = (0, _wordpress_element.useId)();
|
|
101
|
+
const hasLockedRatio = !!(aspectRatio && aspectRatio > 0);
|
|
102
|
+
const activePointerResizeRef = (0, _wordpress_element.useRef)(null);
|
|
103
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
104
|
+
return () => {
|
|
105
|
+
clearTimeout(keyboardSettleTimerRef.current);
|
|
106
|
+
keyboardResizeActiveRef.current = false;
|
|
107
|
+
activePointerResizeRef.current?.cancel(false);
|
|
108
|
+
};
|
|
109
|
+
}, []);
|
|
110
|
+
const latestHandlersRef = (0, _wordpress_element.useRef)(null);
|
|
111
|
+
const normalizedRatio = (0, _wordpress_element.useMemo)(() => {
|
|
112
|
+
if (!hasLockedRatio || imageSize.width === 0) return 0;
|
|
113
|
+
return aspectRatio * imageSize.height / imageSize.width;
|
|
114
|
+
}, [
|
|
115
|
+
aspectRatio,
|
|
116
|
+
hasLockedRatio,
|
|
117
|
+
imageSize.width,
|
|
118
|
+
imageSize.height
|
|
119
|
+
]);
|
|
120
|
+
const offsetX = (containerSize.width - imageSize.width) / 2;
|
|
121
|
+
const offsetY = (containerSize.height - imageSize.height) / 2;
|
|
122
|
+
const left = offsetX + cropRect.x * imageSize.width;
|
|
123
|
+
const top = offsetY + cropRect.y * imageSize.height;
|
|
124
|
+
const width = cropRect.width * imageSize.width;
|
|
125
|
+
const height = cropRect.height * imageSize.height;
|
|
126
|
+
/**
|
|
127
|
+
* Start a resize drag on a handle. Registers pointer listeners
|
|
128
|
+
* synchronously so no events are missed between capture and the
|
|
129
|
+
* next React commit.
|
|
130
|
+
*/
|
|
131
|
+
const handlePointerDown = (0, _wordpress_element.useCallback)((handle, event) => {
|
|
132
|
+
if (isResizeDisabled || event.pointerType === "touch" && event.isPrimary === false) {
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
event.stopPropagation();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (event.button !== 0) return;
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
event.stopPropagation();
|
|
140
|
+
const ownerDoc = event.currentTarget.ownerDocument;
|
|
141
|
+
if (ownerDoc.activeElement instanceof HTMLElement) ownerDoc.activeElement.blur();
|
|
142
|
+
const el = event.currentTarget;
|
|
143
|
+
el.setPointerCapture(event.pointerId);
|
|
144
|
+
const drag = {
|
|
145
|
+
handle,
|
|
146
|
+
startX: event.clientX,
|
|
147
|
+
startY: event.clientY,
|
|
148
|
+
startRect: { ...cropRect }
|
|
149
|
+
};
|
|
150
|
+
let rafId = 0;
|
|
151
|
+
let latestX = event.clientX;
|
|
152
|
+
let latestY = event.clientY;
|
|
153
|
+
let latestShift = event.shiftKey;
|
|
154
|
+
const onMove = (e) => {
|
|
155
|
+
const pe = e;
|
|
156
|
+
latestX = pe.clientX;
|
|
157
|
+
latestY = pe.clientY;
|
|
158
|
+
latestShift = pe.shiftKey;
|
|
159
|
+
if (rafId) return;
|
|
160
|
+
rafId = requestAnimationFrame(() => {
|
|
161
|
+
rafId = 0;
|
|
162
|
+
const h = latestHandlersRef.current;
|
|
163
|
+
if (!h) return;
|
|
164
|
+
let newRect;
|
|
165
|
+
if (h.hasLockedRatio) newRect = h.computeLockedRect(drag, latestX, latestY);
|
|
166
|
+
else if (latestShift) newRect = h.computeShiftLockedRect(drag, latestX, latestY);
|
|
167
|
+
else {
|
|
168
|
+
newRect = h.computeFreeRect(drag, latestX, latestY);
|
|
169
|
+
newRect = h.snapCropRect?.(newRect, drag.handle) ?? newRect;
|
|
170
|
+
}
|
|
171
|
+
h.onCropChange(newRect);
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
let ended = false;
|
|
175
|
+
const endResize = (notifyResizeEnd = true, restoreFocus = true) => {
|
|
176
|
+
if (ended) return;
|
|
177
|
+
ended = true;
|
|
178
|
+
if (rafId) {
|
|
179
|
+
cancelAnimationFrame(rafId);
|
|
180
|
+
rafId = 0;
|
|
181
|
+
}
|
|
182
|
+
el.removeEventListener("pointermove", onMove);
|
|
183
|
+
el.removeEventListener("pointerup", onEnd);
|
|
184
|
+
el.removeEventListener("lostpointercapture", onEnd);
|
|
185
|
+
activePointerResizeRef.current = null;
|
|
186
|
+
if (notifyResizeEnd) latestHandlersRef.current?.onResizeEnd?.();
|
|
187
|
+
if (restoreFocus) el.focus({ preventScroll: true });
|
|
188
|
+
};
|
|
189
|
+
const cancelResize = (notifyResizeEnd = true) => endResize(notifyResizeEnd, false);
|
|
190
|
+
const onEnd = () => endResize();
|
|
191
|
+
el.addEventListener("pointermove", onMove);
|
|
192
|
+
el.addEventListener("pointerup", onEnd);
|
|
193
|
+
el.addEventListener("lostpointercapture", onEnd);
|
|
194
|
+
activePointerResizeRef.current = { cancel: cancelResize };
|
|
195
|
+
onResizeStart?.(handle);
|
|
196
|
+
clearTimeout(keyboardSettleTimerRef.current);
|
|
197
|
+
keyboardResizeActiveRef.current = false;
|
|
198
|
+
}, [
|
|
199
|
+
cropRect,
|
|
200
|
+
isResizeDisabled,
|
|
201
|
+
onResizeStart
|
|
202
|
+
]);
|
|
203
|
+
/**
|
|
204
|
+
* Compute the new crop rect for a free (no aspect ratio) resize.
|
|
205
|
+
* Delegates to the pure function in core/stencil-math.ts.
|
|
206
|
+
*/
|
|
207
|
+
const computeFreeRect = (0, _wordpress_element.useCallback)((drag, clientX, clientY) => (0, _________core_stencil_math_ts.computeFreeResizeRect)(drag, clientX, clientY, imageSize, bounds, minCropSize), [
|
|
208
|
+
imageSize,
|
|
209
|
+
bounds,
|
|
210
|
+
minCropSize
|
|
211
|
+
]);
|
|
212
|
+
/**
|
|
213
|
+
* Compute the new crop rect for a locked-aspect-ratio corner resize.
|
|
214
|
+
* Delegates to the pure function in core/stencil-math.ts.
|
|
215
|
+
*/
|
|
216
|
+
const computeLockedRect = (0, _wordpress_element.useCallback)((drag, clientX, clientY, driverAxis) => (0, _________core_stencil_math_ts.computeLockedResizeRect)(drag, clientX, clientY, imageSize, bounds, normalizedRatio, minCropSize, driverAxis), [
|
|
217
|
+
imageSize,
|
|
218
|
+
bounds,
|
|
219
|
+
normalizedRatio,
|
|
220
|
+
minCropSize
|
|
221
|
+
]);
|
|
222
|
+
latestHandlersRef.current = {
|
|
223
|
+
hasLockedRatio,
|
|
224
|
+
computeLockedRect,
|
|
225
|
+
computeFreeRect,
|
|
226
|
+
computeShiftLockedRect: (0, _wordpress_element.useCallback)((drag, clientX, clientY) => (0, _________core_stencil_math_ts.computeShiftLockedResizeRect)(drag, clientX, clientY, imageSize, bounds, minCropSize), [
|
|
227
|
+
imageSize,
|
|
228
|
+
bounds,
|
|
229
|
+
minCropSize
|
|
230
|
+
]),
|
|
231
|
+
onCropChange,
|
|
232
|
+
onResizeEnd,
|
|
233
|
+
snapCropRect
|
|
234
|
+
};
|
|
235
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
236
|
+
if (!isResizeDisabled) return;
|
|
237
|
+
activePointerResizeRef.current?.cancel();
|
|
238
|
+
if (keyboardResizeActiveRef.current) {
|
|
239
|
+
clearTimeout(keyboardSettleTimerRef.current);
|
|
240
|
+
keyboardResizeActiveRef.current = false;
|
|
241
|
+
latestHandlersRef.current?.onResizeEnd?.();
|
|
242
|
+
}
|
|
243
|
+
}, [isResizeDisabled]);
|
|
244
|
+
/**
|
|
245
|
+
* Handle keyboard events on a resize handle.
|
|
246
|
+
* Arrow keys resize; Escape returns focus to the canvas.
|
|
247
|
+
* Shift multiplies the step size by 10 for coarser movement.
|
|
248
|
+
*/
|
|
249
|
+
const handleKeyDown = (0, _wordpress_element.useCallback)((handle, event) => {
|
|
250
|
+
const key = event.key;
|
|
251
|
+
if (isResizeDisabled) return;
|
|
252
|
+
if (key === "Escape") {
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
event.stopPropagation();
|
|
255
|
+
onEscape?.();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (key !== "ArrowUp" && key !== "ArrowDown" && key !== "ArrowLeft" && key !== "ArrowRight") return;
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
event.stopPropagation();
|
|
261
|
+
if (!keyboardResizeActiveRef.current) {
|
|
262
|
+
keyboardResizeActiveRef.current = true;
|
|
263
|
+
onResizeStart?.(handle);
|
|
264
|
+
}
|
|
265
|
+
const scheduleKeyboardResizeEnd = () => {
|
|
266
|
+
clearTimeout(keyboardSettleTimerRef.current);
|
|
267
|
+
keyboardSettleTimerRef.current = setTimeout(() => {
|
|
268
|
+
keyboardResizeActiveRef.current = false;
|
|
269
|
+
onResizeEnd?.();
|
|
270
|
+
}, KEYBOARD_SETTLE_DELAY);
|
|
271
|
+
};
|
|
272
|
+
const stepMultiplier = event.shiftKey ? _________core_constants_ts.KEYBOARD_SHIFT_STEP_MULTIPLIER : 1;
|
|
273
|
+
const stepX = keyboardResizeStep?.width ?? _________core_constants_ts.DEFAULT_KEYBOARD_STEP;
|
|
274
|
+
const stepY = keyboardResizeStep?.height ?? _________core_constants_ts.DEFAULT_KEYBOARD_STEP;
|
|
275
|
+
const adjustedStepX = stepX * stepMultiplier;
|
|
276
|
+
const adjustedStepY = stepY * stepMultiplier;
|
|
277
|
+
let dx = 0;
|
|
278
|
+
let dy = 0;
|
|
279
|
+
if (key === "ArrowLeft") dx = -adjustedStepX;
|
|
280
|
+
if (key === "ArrowRight") dx = adjustedStepX;
|
|
281
|
+
if (key === "ArrowUp") dy = -adjustedStepY;
|
|
282
|
+
if (key === "ArrowDown") dy = adjustedStepY;
|
|
283
|
+
const keyboardDriverAxis = dx !== 0 ? "width" : "height";
|
|
284
|
+
if (hasLockedRatio) {
|
|
285
|
+
const syntheticDrag = {
|
|
286
|
+
handle,
|
|
287
|
+
startX: 0,
|
|
288
|
+
startY: 0,
|
|
289
|
+
startRect: { ...cropRect }
|
|
290
|
+
};
|
|
291
|
+
const clientX = dx * imageSize.width;
|
|
292
|
+
const clientY = dy * imageSize.height;
|
|
293
|
+
onCropChange(computeLockedRect(syntheticDrag, clientX, clientY, keyboardDriverAxis));
|
|
294
|
+
scheduleKeyboardResizeEnd();
|
|
295
|
+
} else {
|
|
296
|
+
const syntheticDrag = {
|
|
297
|
+
handle,
|
|
298
|
+
startX: 0,
|
|
299
|
+
startY: 0,
|
|
300
|
+
startRect: { ...cropRect }
|
|
301
|
+
};
|
|
302
|
+
const clientX = dx * imageSize.width;
|
|
303
|
+
const clientY = dy * imageSize.height;
|
|
304
|
+
const rect = computeFreeRect(syntheticDrag, clientX, clientY);
|
|
305
|
+
onCropChange(snapCropRect?.(rect, handle) ?? rect);
|
|
306
|
+
scheduleKeyboardResizeEnd();
|
|
307
|
+
}
|
|
308
|
+
}, [
|
|
309
|
+
cropRect,
|
|
310
|
+
hasLockedRatio,
|
|
311
|
+
imageSize.width,
|
|
312
|
+
imageSize.height,
|
|
313
|
+
computeLockedRect,
|
|
314
|
+
computeFreeRect,
|
|
315
|
+
onCropChange,
|
|
316
|
+
onResizeStart,
|
|
317
|
+
onResizeEnd,
|
|
318
|
+
onEscape,
|
|
319
|
+
keyboardResizeStep,
|
|
320
|
+
snapCropRect,
|
|
321
|
+
isResizeDisabled
|
|
322
|
+
]);
|
|
323
|
+
if (containerSize.width === 0 || containerSize.height === 0) return null;
|
|
324
|
+
const handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;
|
|
325
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
326
|
+
className: "wp-media-editor-image-editor__stencil",
|
|
327
|
+
"data-testid": "cropper-stencil",
|
|
328
|
+
style: {
|
|
329
|
+
left,
|
|
330
|
+
top,
|
|
331
|
+
width,
|
|
332
|
+
height,
|
|
333
|
+
transition: stencilTransition
|
|
334
|
+
},
|
|
335
|
+
children: [
|
|
336
|
+
freeformCrop && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
337
|
+
id: resizeHandleDescriptionId,
|
|
338
|
+
style: ______visually_hidden_style_ts.VISUALLY_HIDDEN_STYLE,
|
|
339
|
+
children: (0, _wordpress_i18n.__)("Use arrow keys to resize the crop area. Hold Shift for larger steps.")
|
|
340
|
+
}),
|
|
341
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
342
|
+
className: "wp-media-editor-image-editor__stencil-rect",
|
|
343
|
+
style: {
|
|
344
|
+
width: "100%",
|
|
345
|
+
height: "100%",
|
|
346
|
+
top: 0,
|
|
347
|
+
left: 0
|
|
348
|
+
}
|
|
349
|
+
}),
|
|
350
|
+
freeformCrop && handles.map((pos) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
351
|
+
type: "button",
|
|
352
|
+
className: `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${pos}`,
|
|
353
|
+
onPointerDown: (event) => handlePointerDown(pos, event),
|
|
354
|
+
onTouchStart: (event) => {
|
|
355
|
+
if (event.touches.length < 2) event.stopPropagation();
|
|
356
|
+
},
|
|
357
|
+
onKeyDown: (event) => handleKeyDown(pos, event),
|
|
358
|
+
disabled: isResizeDisabled,
|
|
359
|
+
"aria-label": getHandleLabel(pos),
|
|
360
|
+
"aria-describedby": resizeHandleDescriptionId
|
|
361
|
+
}, pos))
|
|
362
|
+
]
|
|
363
|
+
});
|
|
421
364
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
});
|
|
426
|
-
//# sourceMappingURL=rectangle-stencil.cjs.map
|
|
365
|
+
exports.RectangleStencil = RectangleStencil;
|
|
366
|
+
|
|
367
|
+
//# sourceMappingURL=rectangle-stencil.cjs.map
|