@wordpress/media-editor 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,665 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
computeFreeResizeRect,
|
|
4
|
-
computeLockedResizeRect,
|
|
5
|
-
computeShiftLockedResizeRect,
|
|
6
|
-
getMinCropPixels,
|
|
7
|
-
type CropBounds,
|
|
8
|
-
type ResizeDragState,
|
|
9
|
-
} from '../stencil-math';
|
|
10
|
-
import {
|
|
11
|
-
DEFAULT_KEYBOARD_STEP,
|
|
12
|
-
MIN_CROP_PIXELS,
|
|
13
|
-
MIN_CROP_SCREEN_PX,
|
|
14
|
-
} from '../constants';
|
|
15
|
-
import type { Size } from '../types';
|
|
16
|
-
|
|
17
|
-
describe( 'getMinCropPixels — operable on-screen floor', () => {
|
|
18
|
-
it( 'returns the source-pixel hard floor when the image is shown large enough', () => {
|
|
19
|
-
const displayScale = ( MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS ) * 1.1;
|
|
20
|
-
|
|
21
|
-
expect( getMinCropPixels( displayScale ) ).toBe( MIN_CROP_PIXELS );
|
|
22
|
-
} );
|
|
23
|
-
|
|
24
|
-
it( 'raises the floor so the crop stays operable when the image is shown small', () => {
|
|
25
|
-
// A large image fit into a small window: ~0.2 CSS px per source px.
|
|
26
|
-
// The source-pixel floor would render too small on screen. The
|
|
27
|
-
// usability term (44 / 0.2 = 220 source px) must win.
|
|
28
|
-
expect( getMinCropPixels( 0.2 ) ).toBeCloseTo(
|
|
29
|
-
MIN_CROP_SCREEN_PX / 0.2,
|
|
30
|
-
5
|
|
31
|
-
);
|
|
32
|
-
expect( getMinCropPixels( 0.2 ) ).toBeGreaterThan( MIN_CROP_PIXELS );
|
|
33
|
-
} );
|
|
34
|
-
|
|
35
|
-
it( 'crosses over from usability floor to hard floor at displayScale = MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS', () => {
|
|
36
|
-
const crossover = MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS;
|
|
37
|
-
expect( getMinCropPixels( crossover ) ).toBeCloseTo(
|
|
38
|
-
MIN_CROP_PIXELS,
|
|
39
|
-
5
|
|
40
|
-
);
|
|
41
|
-
// Just below the crossover, the usability term exceeds the hard floor.
|
|
42
|
-
expect( getMinCropPixels( crossover * 0.99 ) ).toBeGreaterThan(
|
|
43
|
-
MIN_CROP_PIXELS
|
|
44
|
-
);
|
|
45
|
-
} );
|
|
46
|
-
|
|
47
|
-
it( 'falls back to the hard floor for a non-positive display scale', () => {
|
|
48
|
-
expect( getMinCropPixels( 0 ) ).toBe( MIN_CROP_PIXELS );
|
|
49
|
-
expect( getMinCropPixels( -1 ) ).toBe( MIN_CROP_PIXELS );
|
|
50
|
-
} );
|
|
51
|
-
} );
|
|
52
|
-
|
|
53
|
-
const FULL_BOUNDS: CropBounds = { minX: 0, minY: 0, maxX: 1, maxY: 1 };
|
|
54
|
-
|
|
55
|
-
describe( 'computeLockedResizeRect — driver-axis selection', () => {
|
|
56
|
-
// On non-square images, the locked-ratio resize must pick the
|
|
57
|
-
// driving axis based on which the user moved more in *pixel* space,
|
|
58
|
-
// compared against the *pixel* aspect ratio. Comparing pixel motion
|
|
59
|
-
// against the normalized w/h ratio is a unit mismatch and produces
|
|
60
|
-
// the wrong axis on non-square images.
|
|
61
|
-
//
|
|
62
|
-
// Setup: a wide 1600×900 image, locked to a square (1:1) crop.
|
|
63
|
-
// Drag from the NW corner of a (degenerate) start rect, anchored at
|
|
64
|
-
// (0, 0), so distW/distH after the drag equals the drag offset.
|
|
65
|
-
const imageSize: Size = { width: 1600, height: 900 };
|
|
66
|
-
const aspectRatio = 1;
|
|
67
|
-
// The stencil normalizes the pixel ratio for the math:
|
|
68
|
-
// normalizedRatio = aspectRatio * imageH / imageW.
|
|
69
|
-
const normalizedRatio =
|
|
70
|
-
( aspectRatio * imageSize.height ) / imageSize.width;
|
|
71
|
-
const startRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
72
|
-
|
|
73
|
-
it( 'lets height drive when the user moves more pixels vertically than horizontally (between normalized and pixel thresholds)', () => {
|
|
74
|
-
// Drag SE corner to (144px, 160px) from anchor (0, 0).
|
|
75
|
-
// pixelDistW=144, pixelDistH=160, ratio=0.9 — comfortably above
|
|
76
|
-
// MIN_CROP_SIZE (0.05 = 80px on a 1600px image), so neither axis
|
|
77
|
-
// is at the min-clamp boundary. The ratio (0.9) sits between the
|
|
78
|
-
// old buggy threshold (normalizedRatio=0.5625) and the correct
|
|
79
|
-
// pixel-space threshold (aspectRatio=1) — that's the gap where
|
|
80
|
-
// the unit mismatch produced the wrong driver axis.
|
|
81
|
-
// Correct: 0.9 < aspectRatio(1) → height drives → 160×160 pixels.
|
|
82
|
-
const drag: ResizeDragState = {
|
|
83
|
-
handle: 'se',
|
|
84
|
-
startX: 0,
|
|
85
|
-
startY: 0,
|
|
86
|
-
startRect,
|
|
87
|
-
};
|
|
88
|
-
const rect = computeLockedResizeRect(
|
|
89
|
-
drag,
|
|
90
|
-
144,
|
|
91
|
-
160,
|
|
92
|
-
imageSize,
|
|
93
|
-
FULL_BOUNDS,
|
|
94
|
-
normalizedRatio
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
const pixelW = rect.width * imageSize.width;
|
|
98
|
-
const pixelH = rect.height * imageSize.height;
|
|
99
|
-
|
|
100
|
-
expect( pixelW / pixelH ).toBeCloseTo( 1, 5 );
|
|
101
|
-
expect( pixelH ).toBeCloseTo( 160, 5 );
|
|
102
|
-
expect( pixelW ).toBeCloseTo( 160, 5 );
|
|
103
|
-
} );
|
|
104
|
-
|
|
105
|
-
it( 'returns the start rect unchanged when normalizedRatio is 0 (image not loaded)', () => {
|
|
106
|
-
// Reachable in practice: keyboard arrows on a focused resize
|
|
107
|
-
// handle before the image's natural size is known make the
|
|
108
|
-
// stencil pass `normalizedRatio === 0`.
|
|
109
|
-
const preLoadStart = { x: 0.1, y: 0.2, width: 0.3, height: 0.4 };
|
|
110
|
-
const drag: ResizeDragState = {
|
|
111
|
-
handle: 'se',
|
|
112
|
-
startX: 0,
|
|
113
|
-
startY: 0,
|
|
114
|
-
startRect: preLoadStart,
|
|
115
|
-
};
|
|
116
|
-
const rect = computeLockedResizeRect(
|
|
117
|
-
drag,
|
|
118
|
-
100,
|
|
119
|
-
100,
|
|
120
|
-
{ width: 0, height: 0 },
|
|
121
|
-
FULL_BOUNDS,
|
|
122
|
-
0
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
expect( rect ).toEqual( preLoadStart );
|
|
126
|
-
} );
|
|
127
|
-
|
|
128
|
-
it( 'lets width drive when the user moves more pixels horizontally than vertically', () => {
|
|
129
|
-
// Drag SE corner to (200px, 50px) from anchor (0, 0).
|
|
130
|
-
// pixelDistW=200, pixelDistH=50, ratio=4 > aspectRatio(1).
|
|
131
|
-
// Width drives. Result: 200×200 pixels.
|
|
132
|
-
const drag: ResizeDragState = {
|
|
133
|
-
handle: 'se',
|
|
134
|
-
startX: 0,
|
|
135
|
-
startY: 0,
|
|
136
|
-
startRect,
|
|
137
|
-
};
|
|
138
|
-
const rect = computeLockedResizeRect(
|
|
139
|
-
drag,
|
|
140
|
-
200,
|
|
141
|
-
50,
|
|
142
|
-
imageSize,
|
|
143
|
-
FULL_BOUNDS,
|
|
144
|
-
normalizedRatio
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const pixelW = rect.width * imageSize.width;
|
|
148
|
-
const pixelH = rect.height * imageSize.height;
|
|
149
|
-
|
|
150
|
-
expect( pixelW / pixelH ).toBeCloseTo( 1, 5 );
|
|
151
|
-
expect( pixelW ).toBeCloseTo( 200, 5 );
|
|
152
|
-
expect( pixelH ).toBeCloseTo( 200, 5 );
|
|
153
|
-
} );
|
|
154
|
-
|
|
155
|
-
it( 'keeps pointer resize continuous near the pixel-motion threshold', () => {
|
|
156
|
-
const originalImageSize: Size = { width: 600, height: 400 };
|
|
157
|
-
const fullImageCrop = { x: 0, y: 0, width: 1, height: 1 };
|
|
158
|
-
const drag: ResizeDragState = {
|
|
159
|
-
handle: 'nw',
|
|
160
|
-
startX: 0,
|
|
161
|
-
startY: 0,
|
|
162
|
-
startRect: fullImageCrop,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const beforeThreshold = computeLockedResizeRect(
|
|
166
|
-
drag,
|
|
167
|
-
60,
|
|
168
|
-
-39.6,
|
|
169
|
-
originalImageSize,
|
|
170
|
-
FULL_BOUNDS,
|
|
171
|
-
1
|
|
172
|
-
);
|
|
173
|
-
const afterThreshold = computeLockedResizeRect(
|
|
174
|
-
drag,
|
|
175
|
-
60,
|
|
176
|
-
-40.4,
|
|
177
|
-
originalImageSize,
|
|
178
|
-
FULL_BOUNDS,
|
|
179
|
-
1
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
expect(
|
|
183
|
-
Math.abs( beforeThreshold.width - afterThreshold.width )
|
|
184
|
-
).toBeLessThan( 0.01 );
|
|
185
|
-
expect(
|
|
186
|
-
Math.abs( beforeThreshold.height - afterThreshold.height )
|
|
187
|
-
).toBeLessThan( 0.01 );
|
|
188
|
-
} );
|
|
189
|
-
|
|
190
|
-
it( 'shrinks a locked-ratio crop from horizontal keyboard movement', () => {
|
|
191
|
-
const squareImageSize: Size = { width: 500, height: 500 };
|
|
192
|
-
const lockedStartRect = { x: 0.1, y: 0.1, width: 0.8, height: 0.8 };
|
|
193
|
-
const drag: ResizeDragState = {
|
|
194
|
-
handle: 'nw',
|
|
195
|
-
startX: 0,
|
|
196
|
-
startY: 0,
|
|
197
|
-
startRect: lockedStartRect,
|
|
198
|
-
};
|
|
199
|
-
const rect = computeLockedResizeRect(
|
|
200
|
-
drag,
|
|
201
|
-
DEFAULT_KEYBOARD_STEP * squareImageSize.width,
|
|
202
|
-
0,
|
|
203
|
-
squareImageSize,
|
|
204
|
-
FULL_BOUNDS,
|
|
205
|
-
1,
|
|
206
|
-
undefined,
|
|
207
|
-
'width'
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
expect( rect.x ).toBeCloseTo(
|
|
211
|
-
lockedStartRect.x + DEFAULT_KEYBOARD_STEP,
|
|
212
|
-
5
|
|
213
|
-
);
|
|
214
|
-
expect( rect.y ).toBeCloseTo(
|
|
215
|
-
lockedStartRect.y + DEFAULT_KEYBOARD_STEP,
|
|
216
|
-
5
|
|
217
|
-
);
|
|
218
|
-
expect( rect.width ).toBeCloseTo(
|
|
219
|
-
lockedStartRect.width - DEFAULT_KEYBOARD_STEP,
|
|
220
|
-
5
|
|
221
|
-
);
|
|
222
|
-
expect( rect.height ).toBeCloseTo(
|
|
223
|
-
lockedStartRect.height - DEFAULT_KEYBOARD_STEP,
|
|
224
|
-
5
|
|
225
|
-
);
|
|
226
|
-
} );
|
|
227
|
-
|
|
228
|
-
it( 'shrinks a locked-ratio crop from vertical keyboard movement', () => {
|
|
229
|
-
const squareImageSize: Size = { width: 500, height: 500 };
|
|
230
|
-
const lockedStartRect = { x: 0.1, y: 0.1, width: 0.8, height: 0.8 };
|
|
231
|
-
const drag: ResizeDragState = {
|
|
232
|
-
handle: 'nw',
|
|
233
|
-
startX: 0,
|
|
234
|
-
startY: 0,
|
|
235
|
-
startRect: lockedStartRect,
|
|
236
|
-
};
|
|
237
|
-
const rect = computeLockedResizeRect(
|
|
238
|
-
drag,
|
|
239
|
-
0,
|
|
240
|
-
DEFAULT_KEYBOARD_STEP * squareImageSize.height,
|
|
241
|
-
squareImageSize,
|
|
242
|
-
FULL_BOUNDS,
|
|
243
|
-
1,
|
|
244
|
-
undefined,
|
|
245
|
-
'height'
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
expect( rect.x ).toBeCloseTo(
|
|
249
|
-
lockedStartRect.x + DEFAULT_KEYBOARD_STEP,
|
|
250
|
-
5
|
|
251
|
-
);
|
|
252
|
-
expect( rect.y ).toBeCloseTo(
|
|
253
|
-
lockedStartRect.y + DEFAULT_KEYBOARD_STEP,
|
|
254
|
-
5
|
|
255
|
-
);
|
|
256
|
-
expect( rect.width ).toBeCloseTo(
|
|
257
|
-
lockedStartRect.width - DEFAULT_KEYBOARD_STEP,
|
|
258
|
-
5
|
|
259
|
-
);
|
|
260
|
-
expect( rect.height ).toBeCloseTo(
|
|
261
|
-
lockedStartRect.height - DEFAULT_KEYBOARD_STEP,
|
|
262
|
-
5
|
|
263
|
-
);
|
|
264
|
-
} );
|
|
265
|
-
} );
|
|
266
|
-
|
|
267
|
-
const IMAGE: Size = { width: 1000, height: 500 };
|
|
268
|
-
|
|
269
|
-
const START_RECT = { x: 0.2, y: 0.2, width: 0.4, height: 0.6 };
|
|
270
|
-
|
|
271
|
-
function makeDrag(
|
|
272
|
-
handle: ResizeDragState[ 'handle' ],
|
|
273
|
-
startX = 500,
|
|
274
|
-
startY = 250
|
|
275
|
-
): ResizeDragState {
|
|
276
|
-
return {
|
|
277
|
-
handle,
|
|
278
|
-
startX,
|
|
279
|
-
startY,
|
|
280
|
-
startRect: { ...START_RECT },
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
describe( 'computeShiftLockedResizeRect', () => {
|
|
285
|
-
describe( 'corner handles', () => {
|
|
286
|
-
it( 'preserves the start rect ratio when dragging the SE corner outward', () => {
|
|
287
|
-
const drag = makeDrag( 'se' );
|
|
288
|
-
// Drag right by 200px and down by 50px — width is the bigger
|
|
289
|
-
// pixel motion, so it drives.
|
|
290
|
-
const rect = computeShiftLockedResizeRect(
|
|
291
|
-
drag,
|
|
292
|
-
700,
|
|
293
|
-
300,
|
|
294
|
-
IMAGE,
|
|
295
|
-
FULL_BOUNDS
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
const startPixelRatio =
|
|
299
|
-
( START_RECT.width * IMAGE.width ) /
|
|
300
|
-
( START_RECT.height * IMAGE.height );
|
|
301
|
-
const newPixelRatio =
|
|
302
|
-
( rect.width * IMAGE.width ) / ( rect.height * IMAGE.height );
|
|
303
|
-
|
|
304
|
-
expect( newPixelRatio ).toBeCloseTo( startPixelRatio, 5 );
|
|
305
|
-
// SE drag anchors at the NW corner of the start rect.
|
|
306
|
-
expect( rect.x ).toBeCloseTo( START_RECT.x, 5 );
|
|
307
|
-
expect( rect.y ).toBeCloseTo( START_RECT.y, 5 );
|
|
308
|
-
} );
|
|
309
|
-
|
|
310
|
-
it( 'preserves the start rect ratio when dragging the NW corner inward', () => {
|
|
311
|
-
const drag = makeDrag( 'nw' );
|
|
312
|
-
const rect = computeShiftLockedResizeRect(
|
|
313
|
-
drag,
|
|
314
|
-
600,
|
|
315
|
-
300,
|
|
316
|
-
IMAGE,
|
|
317
|
-
FULL_BOUNDS
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
const startPixelRatio =
|
|
321
|
-
( START_RECT.width * IMAGE.width ) /
|
|
322
|
-
( START_RECT.height * IMAGE.height );
|
|
323
|
-
const newPixelRatio =
|
|
324
|
-
( rect.width * IMAGE.width ) / ( rect.height * IMAGE.height );
|
|
325
|
-
expect( newPixelRatio ).toBeCloseTo( startPixelRatio, 5 );
|
|
326
|
-
// NW drag anchors at the SE corner of the start rect.
|
|
327
|
-
expect( rect.x + rect.width ).toBeCloseTo(
|
|
328
|
-
START_RECT.x + START_RECT.width,
|
|
329
|
-
5
|
|
330
|
-
);
|
|
331
|
-
expect( rect.y + rect.height ).toBeCloseTo(
|
|
332
|
-
START_RECT.y + START_RECT.height,
|
|
333
|
-
5
|
|
334
|
-
);
|
|
335
|
-
} );
|
|
336
|
-
} );
|
|
337
|
-
|
|
338
|
-
describe( 'edge handles — symmetric expansion', () => {
|
|
339
|
-
it( 'east edge: expands height symmetrically around the start rect center', () => {
|
|
340
|
-
const drag = makeDrag( 'e' );
|
|
341
|
-
// Expand width by 100px to the right.
|
|
342
|
-
const rect = computeShiftLockedResizeRect(
|
|
343
|
-
drag,
|
|
344
|
-
600,
|
|
345
|
-
250,
|
|
346
|
-
IMAGE,
|
|
347
|
-
FULL_BOUNDS
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
const startCenterY = START_RECT.y + START_RECT.height / 2;
|
|
351
|
-
expect( rect.y + rect.height / 2 ).toBeCloseTo( startCenterY, 5 );
|
|
352
|
-
// x-anchored to start.x.
|
|
353
|
-
expect( rect.x ).toBeCloseTo( START_RECT.x, 5 );
|
|
354
|
-
// Ratio preserved.
|
|
355
|
-
const startPixelRatio =
|
|
356
|
-
( START_RECT.width * IMAGE.width ) /
|
|
357
|
-
( START_RECT.height * IMAGE.height );
|
|
358
|
-
const newPixelRatio =
|
|
359
|
-
( rect.width * IMAGE.width ) / ( rect.height * IMAGE.height );
|
|
360
|
-
expect( newPixelRatio ).toBeCloseTo( startPixelRatio, 5 );
|
|
361
|
-
} );
|
|
362
|
-
|
|
363
|
-
it( 'north edge: expands width symmetrically around the start rect center', () => {
|
|
364
|
-
const drag = makeDrag( 'n' );
|
|
365
|
-
// Drag the top edge up by 50px (taller crop).
|
|
366
|
-
const rect = computeShiftLockedResizeRect(
|
|
367
|
-
drag,
|
|
368
|
-
500,
|
|
369
|
-
200,
|
|
370
|
-
IMAGE,
|
|
371
|
-
FULL_BOUNDS
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
const startCenterX = START_RECT.x + START_RECT.width / 2;
|
|
375
|
-
expect( rect.x + rect.width / 2 ).toBeCloseTo( startCenterX, 5 );
|
|
376
|
-
// Bottom edge stays anchored.
|
|
377
|
-
expect( rect.y + rect.height ).toBeCloseTo(
|
|
378
|
-
START_RECT.y + START_RECT.height,
|
|
379
|
-
5
|
|
380
|
-
);
|
|
381
|
-
const startPixelRatio =
|
|
382
|
-
( START_RECT.width * IMAGE.width ) /
|
|
383
|
-
( START_RECT.height * IMAGE.height );
|
|
384
|
-
const newPixelRatio =
|
|
385
|
-
( rect.width * IMAGE.width ) / ( rect.height * IMAGE.height );
|
|
386
|
-
expect( newPixelRatio ).toBeCloseTo( startPixelRatio, 5 );
|
|
387
|
-
} );
|
|
388
|
-
} );
|
|
389
|
-
|
|
390
|
-
describe( 'minimum size clamping preserves ratio', () => {
|
|
391
|
-
it( 'east edge: clamps a tall crop without breaking ratio when width hits MIN_CROP_SIZE', () => {
|
|
392
|
-
// Tall start rect — small ratio (0.0625 in normalized space).
|
|
393
|
-
const tallStart = { x: 0.2, y: 0.1, width: 0.05, height: 0.8 };
|
|
394
|
-
const drag: ResizeDragState = {
|
|
395
|
-
handle: 'e',
|
|
396
|
-
startX: 250,
|
|
397
|
-
startY: 250,
|
|
398
|
-
startRect: tallStart,
|
|
399
|
-
};
|
|
400
|
-
// Drag the east edge inward — width tries to shrink below MIN.
|
|
401
|
-
const rect = computeShiftLockedResizeRect(
|
|
402
|
-
drag,
|
|
403
|
-
200,
|
|
404
|
-
250,
|
|
405
|
-
IMAGE,
|
|
406
|
-
FULL_BOUNDS
|
|
407
|
-
);
|
|
408
|
-
|
|
409
|
-
const startRatio = tallStart.width / tallStart.height;
|
|
410
|
-
const newRatio = rect.width / rect.height;
|
|
411
|
-
expect( newRatio ).toBeCloseTo( startRatio, 5 );
|
|
412
|
-
expect( rect.width ).toBeGreaterThanOrEqual( 0.05 - 1e-9 );
|
|
413
|
-
expect( rect.height ).toBeGreaterThanOrEqual( 0.05 - 1e-9 );
|
|
414
|
-
} );
|
|
415
|
-
|
|
416
|
-
it( 'north edge: clamps a wide crop without breaking ratio when height hits MIN_CROP_SIZE', () => {
|
|
417
|
-
// Wide start rect — large ratio (16 in normalized space).
|
|
418
|
-
const wideStart = { x: 0.1, y: 0.4, width: 0.8, height: 0.05 };
|
|
419
|
-
const drag: ResizeDragState = {
|
|
420
|
-
handle: 'n',
|
|
421
|
-
startX: 500,
|
|
422
|
-
startY: 200,
|
|
423
|
-
startRect: wideStart,
|
|
424
|
-
};
|
|
425
|
-
// Drag the north edge down — height tries to shrink below MIN.
|
|
426
|
-
const rect = computeShiftLockedResizeRect(
|
|
427
|
-
drag,
|
|
428
|
-
500,
|
|
429
|
-
220,
|
|
430
|
-
IMAGE,
|
|
431
|
-
FULL_BOUNDS
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
const startRatio = wideStart.width / wideStart.height;
|
|
435
|
-
const newRatio = rect.width / rect.height;
|
|
436
|
-
expect( newRatio ).toBeCloseTo( startRatio, 5 );
|
|
437
|
-
expect( rect.width ).toBeGreaterThanOrEqual( 0.05 - 1e-9 );
|
|
438
|
-
expect( rect.height ).toBeGreaterThanOrEqual( 0.05 - 1e-9 );
|
|
439
|
-
} );
|
|
440
|
-
} );
|
|
441
|
-
|
|
442
|
-
describe( 'bounds clamping', () => {
|
|
443
|
-
it( 'east edge: clamps height to the symmetric bounds limit and shrinks width to keep ratio', () => {
|
|
444
|
-
// Center-y of START_RECT is 0.5; tightest bounds are bounds.minY=0.4
|
|
445
|
-
// and bounds.maxY=0.6 → max half-height = 0.1, so max height = 0.2.
|
|
446
|
-
const tightBounds: CropBounds = {
|
|
447
|
-
minX: 0,
|
|
448
|
-
minY: 0.4,
|
|
449
|
-
maxX: 1,
|
|
450
|
-
maxY: 0.6,
|
|
451
|
-
};
|
|
452
|
-
const drag = makeDrag( 'e' );
|
|
453
|
-
// Drag far right — height would otherwise exceed the bound.
|
|
454
|
-
const rect = computeShiftLockedResizeRect(
|
|
455
|
-
drag,
|
|
456
|
-
1000,
|
|
457
|
-
250,
|
|
458
|
-
IMAGE,
|
|
459
|
-
tightBounds
|
|
460
|
-
);
|
|
461
|
-
|
|
462
|
-
expect( rect.height ).toBeLessThanOrEqual( 0.2 + 1e-9 );
|
|
463
|
-
// Centered around 0.5.
|
|
464
|
-
expect( rect.y + rect.height / 2 ).toBeCloseTo( 0.5, 5 );
|
|
465
|
-
const startPixelRatio =
|
|
466
|
-
( START_RECT.width * IMAGE.width ) /
|
|
467
|
-
( START_RECT.height * IMAGE.height );
|
|
468
|
-
const newPixelRatio =
|
|
469
|
-
( rect.width * IMAGE.width ) / ( rect.height * IMAGE.height );
|
|
470
|
-
expect( newPixelRatio ).toBeCloseTo( startPixelRatio, 5 );
|
|
471
|
-
} );
|
|
472
|
-
} );
|
|
473
|
-
} );
|
|
474
|
-
|
|
475
|
-
describe( 'per-axis minCropSize', () => {
|
|
476
|
-
// Cover the explicit per-axis floor introduced for the source-pixel
|
|
477
|
-
// minimum. The defaults (0.05, 0.05) are already covered by the
|
|
478
|
-
// suites above; these tests pass `minCropSize` explicitly to lock in
|
|
479
|
-
// the math the cropper relies on.
|
|
480
|
-
const IMAGE_NON_SQUARE: Size = { width: 1000, height: 500 };
|
|
481
|
-
|
|
482
|
-
describe( 'computeFreeResizeRect', () => {
|
|
483
|
-
it( 'clamps the dragged edge to the per-axis floor (width)', () => {
|
|
484
|
-
// SE handle from a wide start rect; drag left far enough that
|
|
485
|
-
// width would collapse without the floor.
|
|
486
|
-
const startRect = { x: 0.1, y: 0.1, width: 0.6, height: 0.6 };
|
|
487
|
-
const drag: ResizeDragState = {
|
|
488
|
-
handle: 'e',
|
|
489
|
-
startX: 700,
|
|
490
|
-
startY: 350,
|
|
491
|
-
startRect,
|
|
492
|
-
};
|
|
493
|
-
const minCropSize: Size = { width: 0.2, height: 0.05 };
|
|
494
|
-
const rect = computeFreeResizeRect(
|
|
495
|
-
drag,
|
|
496
|
-
0,
|
|
497
|
-
350,
|
|
498
|
-
IMAGE_NON_SQUARE,
|
|
499
|
-
FULL_BOUNDS,
|
|
500
|
-
minCropSize
|
|
501
|
-
);
|
|
502
|
-
expect( rect.width ).toBeCloseTo( minCropSize.width, 5 );
|
|
503
|
-
// Left edge anchored at start; right edge pulled in to the floor.
|
|
504
|
-
expect( rect.x ).toBeCloseTo( startRect.x, 5 );
|
|
505
|
-
} );
|
|
506
|
-
|
|
507
|
-
it( 'clamps the dragged edge to the per-axis floor (height)', () => {
|
|
508
|
-
const startRect = { x: 0.1, y: 0.1, width: 0.6, height: 0.6 };
|
|
509
|
-
const drag: ResizeDragState = {
|
|
510
|
-
handle: 's',
|
|
511
|
-
startX: 500,
|
|
512
|
-
startY: 350,
|
|
513
|
-
startRect,
|
|
514
|
-
};
|
|
515
|
-
const minCropSize: Size = { width: 0.05, height: 0.3 };
|
|
516
|
-
const rect = computeFreeResizeRect(
|
|
517
|
-
drag,
|
|
518
|
-
500,
|
|
519
|
-
0,
|
|
520
|
-
IMAGE_NON_SQUARE,
|
|
521
|
-
FULL_BOUNDS,
|
|
522
|
-
minCropSize
|
|
523
|
-
);
|
|
524
|
-
expect( rect.height ).toBeCloseTo( minCropSize.height, 5 );
|
|
525
|
-
expect( rect.y ).toBeCloseTo( startRect.y, 5 );
|
|
526
|
-
} );
|
|
527
|
-
|
|
528
|
-
it( 'uses width vs height independently — different floors per axis', () => {
|
|
529
|
-
// Drag NW corner inward far past both floors. The per-axis
|
|
530
|
-
// floors clamp x-collapse and y-collapse independently.
|
|
531
|
-
const startRect = { x: 0.1, y: 0.1, width: 0.8, height: 0.8 };
|
|
532
|
-
const drag: ResizeDragState = {
|
|
533
|
-
handle: 'nw',
|
|
534
|
-
startX: 100,
|
|
535
|
-
startY: 50,
|
|
536
|
-
startRect,
|
|
537
|
-
};
|
|
538
|
-
const minCropSize: Size = { width: 0.4, height: 0.1 };
|
|
539
|
-
const rect = computeFreeResizeRect(
|
|
540
|
-
drag,
|
|
541
|
-
1000,
|
|
542
|
-
500,
|
|
543
|
-
IMAGE_NON_SQUARE,
|
|
544
|
-
FULL_BOUNDS,
|
|
545
|
-
minCropSize
|
|
546
|
-
);
|
|
547
|
-
// Both floors hit at the same time on different axes.
|
|
548
|
-
expect( rect.width ).toBeCloseTo( minCropSize.width, 5 );
|
|
549
|
-
expect( rect.height ).toBeCloseTo( minCropSize.height, 5 );
|
|
550
|
-
} );
|
|
551
|
-
} );
|
|
552
|
-
|
|
553
|
-
describe( 'computeLockedResizeRect — per-axis floor projects through the ratio', () => {
|
|
554
|
-
// Wide image, square aspect ratio. The per-axis floor projection
|
|
555
|
-
// in `minDistW = max(minCropSize.width, minCropSize.height * normalizedRatio)`
|
|
556
|
-
// is the load-bearing piece for non-equal per-axis floors.
|
|
557
|
-
const imageSize: Size = { width: 2000, height: 1000 };
|
|
558
|
-
const aspectRatio = 1; // pixel-square
|
|
559
|
-
const normalizedRatio =
|
|
560
|
-
( aspectRatio * imageSize.height ) / imageSize.width; // 0.5
|
|
561
|
-
const startRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
562
|
-
|
|
563
|
-
it( 'lifts width to satisfy the height floor when the height floor is the binding axis', () => {
|
|
564
|
-
// Drag SE inward to zero — both axes try to collapse. With
|
|
565
|
-
// minCropSize = { 0.01, 0.05 } and normalizedRatio 0.5,
|
|
566
|
-
// minDistW = max(0.01, 0.05 * 0.5) = 0.025, minDistH = 0.05.
|
|
567
|
-
// Driver: pixel motion equal → height drives → distW = distH/2.
|
|
568
|
-
const drag: ResizeDragState = {
|
|
569
|
-
handle: 'se',
|
|
570
|
-
startX: 0,
|
|
571
|
-
startY: 0,
|
|
572
|
-
startRect,
|
|
573
|
-
};
|
|
574
|
-
const minCropSize: Size = { width: 0.01, height: 0.05 };
|
|
575
|
-
const rect = computeLockedResizeRect(
|
|
576
|
-
drag,
|
|
577
|
-
1,
|
|
578
|
-
1,
|
|
579
|
-
imageSize,
|
|
580
|
-
FULL_BOUNDS,
|
|
581
|
-
normalizedRatio,
|
|
582
|
-
minCropSize
|
|
583
|
-
);
|
|
584
|
-
// Height floor binds: width is `height * normalizedRatio`.
|
|
585
|
-
expect( rect.height ).toBeCloseTo( minCropSize.height, 5 );
|
|
586
|
-
expect( rect.width ).toBeCloseTo(
|
|
587
|
-
minCropSize.height * normalizedRatio,
|
|
588
|
-
5
|
|
589
|
-
);
|
|
590
|
-
} );
|
|
591
|
-
|
|
592
|
-
it( 'lifts height to satisfy the width floor when the width floor binds', () => {
|
|
593
|
-
// minDistW = max(0.2, 0.05 * 0.5) = 0.2, minDistH = 0.4.
|
|
594
|
-
const drag: ResizeDragState = {
|
|
595
|
-
handle: 'se',
|
|
596
|
-
startX: 0,
|
|
597
|
-
startY: 0,
|
|
598
|
-
startRect,
|
|
599
|
-
};
|
|
600
|
-
const minCropSize: Size = { width: 0.2, height: 0.05 };
|
|
601
|
-
const rect = computeLockedResizeRect(
|
|
602
|
-
drag,
|
|
603
|
-
1,
|
|
604
|
-
1,
|
|
605
|
-
imageSize,
|
|
606
|
-
FULL_BOUNDS,
|
|
607
|
-
normalizedRatio,
|
|
608
|
-
minCropSize
|
|
609
|
-
);
|
|
610
|
-
expect( rect.width ).toBeCloseTo( 0.2, 5 );
|
|
611
|
-
expect( rect.height ).toBeCloseTo( 0.4, 5 );
|
|
612
|
-
} );
|
|
613
|
-
} );
|
|
614
|
-
|
|
615
|
-
describe( 'computeShiftLockedResizeRect — edge handles', () => {
|
|
616
|
-
// Shift-locked edge resize must enforce the floor on the driver
|
|
617
|
-
// axis and on the perpendicular axis after projecting through
|
|
618
|
-
// the start rect's normalized ratio.
|
|
619
|
-
const imageSize: Size = { width: 1000, height: 500 };
|
|
620
|
-
// Wide start rect — normalizedRatio = 0.4/0.4 = 1.
|
|
621
|
-
const startRect = { x: 0.3, y: 0.3, width: 0.4, height: 0.4 };
|
|
622
|
-
|
|
623
|
-
it( 'east edge: width-driver respects width floor and projects to height', () => {
|
|
624
|
-
const drag: ResizeDragState = {
|
|
625
|
-
handle: 'e',
|
|
626
|
-
startX: 700,
|
|
627
|
-
startY: 400,
|
|
628
|
-
startRect,
|
|
629
|
-
};
|
|
630
|
-
// Drag well past the floor toward the start anchor.
|
|
631
|
-
const minCropSize: Size = { width: 0.2, height: 0.05 };
|
|
632
|
-
const rect = computeShiftLockedResizeRect(
|
|
633
|
-
drag,
|
|
634
|
-
300,
|
|
635
|
-
400,
|
|
636
|
-
imageSize,
|
|
637
|
-
FULL_BOUNDS,
|
|
638
|
-
minCropSize
|
|
639
|
-
);
|
|
640
|
-
// Width clamped at the per-axis floor; height follows ratio (1:1).
|
|
641
|
-
expect( rect.width ).toBeCloseTo( minCropSize.width, 5 );
|
|
642
|
-
expect( rect.height ).toBeCloseTo( minCropSize.width, 5 );
|
|
643
|
-
} );
|
|
644
|
-
|
|
645
|
-
it( 'north edge: height-driver respects height floor and projects to width', () => {
|
|
646
|
-
const drag: ResizeDragState = {
|
|
647
|
-
handle: 'n',
|
|
648
|
-
startX: 500,
|
|
649
|
-
startY: 300,
|
|
650
|
-
startRect,
|
|
651
|
-
};
|
|
652
|
-
const minCropSize: Size = { width: 0.05, height: 0.2 };
|
|
653
|
-
const rect = computeShiftLockedResizeRect(
|
|
654
|
-
drag,
|
|
655
|
-
500,
|
|
656
|
-
700,
|
|
657
|
-
imageSize,
|
|
658
|
-
FULL_BOUNDS,
|
|
659
|
-
minCropSize
|
|
660
|
-
);
|
|
661
|
-
expect( rect.height ).toBeCloseTo( minCropSize.height, 5 );
|
|
662
|
-
expect( rect.width ).toBeCloseTo( minCropSize.height, 5 );
|
|
663
|
-
} );
|
|
664
|
-
} );
|
|
665
|
-
} );
|