@wordpress/media-editor 0.22.0 → 0.24.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 +34 -0
- package/build/components/media-editor/index.cjs +229 -126
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +41 -11
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +15 -18
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +26 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +13 -12
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +143 -37
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +12 -6
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +41 -74
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +217 -117
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +123 -41
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +12 -7
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +122 -87
- package/build-style/style.css +121 -87
- package/build-types/components/media-editor/index.d.ts +25 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- 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/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +40 -54
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +27 -24
- package/src/components/media-editor/index.tsx +372 -142
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +4 -1
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +195 -37
- package/src/components/media-preview/style.scss +11 -32
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +34 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +162 -242
- package/src/style.scss +2 -1
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import type { NormalizedRect, Flip, CropperState } from './types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Default/resting zoom. A full, unrotated crop needs at least 1x to cover the
|
|
5
|
-
* crop area, but smaller/fine-rotated crops can be valid below 1x — the true
|
|
6
|
-
* floor for those comes from `getMinZoom`.
|
|
7
|
-
*/
|
|
8
|
-
export const MIN_ZOOM = 1;
|
|
9
|
-
/**
|
|
10
|
-
* Safety floor for coverage-aware zoom. Degenerate crops can have a geometric
|
|
11
|
-
* coverage minimum of 0, but camera and inverse-matrix math need a stable,
|
|
12
|
-
* positive scale.
|
|
13
|
-
*/
|
|
14
|
-
export const ABSOLUTE_MIN_ZOOM = 0.1;
|
|
15
|
-
export const MAX_ZOOM = 10;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Minimum crop rect dimension in source-image pixels, enforced per axis
|
|
19
|
-
* during resize. Prevents accidental sub-pixel crops while staying small
|
|
20
|
-
* enough to allow tight crops (favicons, icons). Adjust here to tune the
|
|
21
|
-
* floor globally.
|
|
22
|
-
*/
|
|
23
|
-
export const MIN_CROP_PIXELS = 16;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Minimum on-screen crop rect dimension in CSS pixels. The source-pixel
|
|
27
|
-
* floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large
|
|
28
|
-
* image fit into a small canvas it can render only a few CSS pixels wide —
|
|
29
|
-
* too small to grab the resize handles. This floor keeps the crop operable
|
|
30
|
-
* regardless of display scale; it binds when zoomed out and yields to the
|
|
31
|
-
* source-pixel floor once the image is shown large enough. Sized to one
|
|
32
|
-
* handle touch target (`$handle-touch-target-size` in `cropper.scss`).
|
|
33
|
-
*/
|
|
34
|
-
export const MIN_CROP_SCREEN_PX = 44;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Fraction of the constraining canvas axis the settled crop should occupy on
|
|
38
|
-
* screen. When a crop is shown smaller than this (e.g. a square crop in a tall
|
|
39
|
-
* image, capped by the contain-fit footprint's narrow axis), the view magnifies
|
|
40
|
-
* to fill the canvas. `1` = always fill the canvas; lower = rescue only the
|
|
41
|
-
* under-filled cases. See `getViewScale`.
|
|
42
|
-
*/
|
|
43
|
-
export const SETTLE_TARGET_CANVAS_FILL = 0.8;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Upper bound on the presentational view magnification (`getViewScale`).
|
|
47
|
-
* Prevents a near-degenerate crop from magnifying the scene without limit.
|
|
48
|
-
*/
|
|
49
|
-
export const MAX_VIEW_SCALE = 8;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* CSS pixels per source pixel required before resize handles snap the selected
|
|
53
|
-
* source region to whole-pixel edges. Below 1:1, a source pixel is sub-pixel on
|
|
54
|
-
* screen, so snapping would feel notchy without a visible pixel boundary.
|
|
55
|
-
*/
|
|
56
|
-
export const PIXEL_SNAP_DISPLAY_SCALE = 1;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.
|
|
60
|
-
* This could be made configurable as a prop to the Cropper component.
|
|
61
|
-
*/
|
|
62
|
-
export const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;
|
|
63
|
-
|
|
64
|
-
/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */
|
|
65
|
-
export const DEFAULT_KEYBOARD_STEP = 0.01;
|
|
66
|
-
|
|
67
|
-
/** Coarse keyboard movement multiplier when Shift is held. */
|
|
68
|
-
export const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Maximum free-rotation offset in degrees from the nearest 90° step.
|
|
72
|
-
* The rotation slider allows ±45° around the current cardinal angle.
|
|
73
|
-
*/
|
|
74
|
-
export const MAX_ROTATION_OFFSET = 45;
|
|
75
|
-
|
|
76
|
-
const DEFAULT_CROP_RECT: NormalizedRect = {
|
|
77
|
-
x: 0,
|
|
78
|
-
y: 0,
|
|
79
|
-
width: 1,
|
|
80
|
-
height: 1,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const DEFAULT_FLIP: Flip = {
|
|
84
|
-
horizontal: false,
|
|
85
|
-
vertical: false,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const DEFAULT_PAN: { x: number; y: number } = {
|
|
89
|
-
x: 0,
|
|
90
|
-
y: 0,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const DEFAULT_STATE: CropperState = {
|
|
94
|
-
image: null,
|
|
95
|
-
pan: { ...DEFAULT_PAN },
|
|
96
|
-
zoom: MIN_ZOOM,
|
|
97
|
-
rotation: 0,
|
|
98
|
-
basePan: { ...DEFAULT_PAN },
|
|
99
|
-
baseZoom: MIN_ZOOM,
|
|
100
|
-
baseRotation: 0,
|
|
101
|
-
flip: { ...DEFAULT_FLIP },
|
|
102
|
-
cropRect: { ...DEFAULT_CROP_RECT },
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* An aspect ratio preset with a human-readable label.
|
|
107
|
-
*/
|
|
108
|
-
export interface AspectRatioPreset {
|
|
109
|
-
/** Display label (e.g., "Square (1:1)"). */
|
|
110
|
-
label: string;
|
|
111
|
-
/** The aspect ratio value (width / height). 0 = free / original. */
|
|
112
|
-
value: number;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Default aspect ratio presets. Consumers can use these as-is, override
|
|
117
|
-
* with their own list, or extend with additional presets.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* // Use defaults:
|
|
121
|
-
* <CropControls presets={ DEFAULT_ASPECT_RATIOS } />
|
|
122
|
-
*
|
|
123
|
-
* // Custom presets:
|
|
124
|
-
* const socialPresets = [
|
|
125
|
-
* { label: 'Instagram Post', value: 1 },
|
|
126
|
-
* { label: 'Instagram Story', value: 9 / 16 },
|
|
127
|
-
* { label: 'YouTube Thumbnail', value: 16 / 9 },
|
|
128
|
-
* ];
|
|
129
|
-
*
|
|
130
|
-
* // Extend defaults:
|
|
131
|
-
* const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];
|
|
132
|
-
*/
|
|
133
|
-
/**
|
|
134
|
-
* Sentinel value for "Original" aspect ratio — resolved at runtime
|
|
135
|
-
* to the image's natural width / height.
|
|
136
|
-
*/
|
|
137
|
-
export const ORIGINAL_ASPECT_RATIO = -1;
|
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
import { mat2d, vec2 } from 'gl-matrix';
|
|
2
|
-
import type { CropperState, NormalizedRect, Size } from './types';
|
|
3
|
-
import { ABSOLUTE_MIN_ZOOM, MAX_ZOOM, MIN_ZOOM } from './constants';
|
|
4
|
-
import { degreesToRadians } from './math/rotation';
|
|
5
|
-
import {
|
|
6
|
-
isValidSize,
|
|
7
|
-
safeBoundedNumber,
|
|
8
|
-
sanitizeCropperState,
|
|
9
|
-
sanitizeRect,
|
|
10
|
-
} from './math/sanitize';
|
|
11
|
-
import { createCamera, getRotatedBBox, getVisibleBounds } from './camera';
|
|
12
|
-
|
|
13
|
-
/** Floating-point epsilon for "close enough to equal" comparisons. */
|
|
14
|
-
const EPSILON = 1e-9;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Compute the visual (rotated) bounding-box dimensions in pixel-proportional
|
|
18
|
-
* units where the unrotated image is `a × 1` (renderedW = a, renderedH = 1).
|
|
19
|
-
*
|
|
20
|
-
* @param rotation Rotation angle in degrees.
|
|
21
|
-
* @param imageAspectRatio Image width / height ratio.
|
|
22
|
-
* @return Visual dimensions and trig helpers.
|
|
23
|
-
*/
|
|
24
|
-
function getVisualDimensions(
|
|
25
|
-
rotation: number,
|
|
26
|
-
imageAspectRatio: number
|
|
27
|
-
): { visualW: number; visualH: number; absC: number; absS: number } {
|
|
28
|
-
const rad = degreesToRadians( rotation );
|
|
29
|
-
const absC = Math.abs( Math.cos( rad ) );
|
|
30
|
-
const absS = Math.abs( Math.sin( rad ) );
|
|
31
|
-
const bbox = getRotatedBBox( imageAspectRatio, 1, rotation );
|
|
32
|
-
return {
|
|
33
|
-
visualW: bbox.width,
|
|
34
|
-
visualH: bbox.height,
|
|
35
|
-
absC,
|
|
36
|
-
absS,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The geometric minimum zoom required for the rotated image to fully cover the
|
|
42
|
-
* crop rectangle. Works in pixel-proportional space where the unrotated image
|
|
43
|
-
* is a×1; the crop rect lives in visual-normalized space and is scaled by the
|
|
44
|
-
* rotation-dependent visual dimensions before projecting into the image-local
|
|
45
|
-
* frame.
|
|
46
|
-
*
|
|
47
|
-
* Returns 0 for a degenerate (zero-area) crop — callers compose the result
|
|
48
|
-
* with their own floor (typically the current zoom or `MIN_ZOOM`).
|
|
49
|
-
*
|
|
50
|
-
* @param rotation Rotation angle in degrees.
|
|
51
|
-
* @param imageAspectRatio Image width / height ratio.
|
|
52
|
-
* @param cropRect The crop rectangle in normalized coordinates.
|
|
53
|
-
* @return The minimum zoom factor needed for coverage.
|
|
54
|
-
*/
|
|
55
|
-
function getMinZoomForCover(
|
|
56
|
-
rotation: number,
|
|
57
|
-
imageAspectRatio: number,
|
|
58
|
-
cropRect: NormalizedRect
|
|
59
|
-
): number {
|
|
60
|
-
const aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );
|
|
61
|
-
// The crop rect lives in the SNAP-rotation visual bbox — that's how the
|
|
62
|
-
// stencil and preview position it (see createCamera / getImageFit). Use
|
|
63
|
-
// the snap-rotation dimensions to convert crop fractions to pixels.
|
|
64
|
-
const snapRotation = Math.round( rotation / 90 ) * 90;
|
|
65
|
-
const { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(
|
|
66
|
-
snapRotation,
|
|
67
|
-
aspectRatio
|
|
68
|
-
);
|
|
69
|
-
// Projection into the image-local frame uses the TRUE rotation angle —
|
|
70
|
-
// that's the actual orientation of the image under the stencil.
|
|
71
|
-
const { absC, absS } = getVisualDimensions( rotation, aspectRatio );
|
|
72
|
-
|
|
73
|
-
// Crop half-extents in pixel-proportional space.
|
|
74
|
-
const cropHalfW = ( cropRect.width * snapVisualW ) / 2;
|
|
75
|
-
const cropHalfH = ( cropRect.height * snapVisualH ) / 2;
|
|
76
|
-
|
|
77
|
-
// AABB of the crop rect projected into the image-local (unrotated) frame.
|
|
78
|
-
const spanAlpha = cropHalfW * absC + cropHalfH * absS;
|
|
79
|
-
const spanBeta = cropHalfW * absS + cropHalfH * absC;
|
|
80
|
-
|
|
81
|
-
// Image half-extents at zoom z: (aspectRatio*z/2, z/2).
|
|
82
|
-
// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.
|
|
83
|
-
const zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;
|
|
84
|
-
const zoomFromBeta = 2 * spanBeta;
|
|
85
|
-
|
|
86
|
-
return Math.max( zoomFromAlpha, zoomFromBeta );
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Resolves the effective minimum zoom for the current state — the coverage-
|
|
91
|
-
* aware floor when an image is loaded, falling back to `MIN_ZOOM` otherwise.
|
|
92
|
-
* Used by both the cropper's interaction layer and the zoom slider so the
|
|
93
|
-
* floor stays consistent across surfaces.
|
|
94
|
-
*
|
|
95
|
-
* @param state The current cropper state.
|
|
96
|
-
* @return The minimum zoom factor.
|
|
97
|
-
*/
|
|
98
|
-
export function getMinZoom( state: CropperState ): number {
|
|
99
|
-
if ( ! state.image ) {
|
|
100
|
-
return MIN_ZOOM;
|
|
101
|
-
}
|
|
102
|
-
const imageSize = {
|
|
103
|
-
width: state.image.naturalWidth,
|
|
104
|
-
height: state.image.naturalHeight,
|
|
105
|
-
};
|
|
106
|
-
if ( ! isValidSize( imageSize ) ) {
|
|
107
|
-
return MIN_ZOOM;
|
|
108
|
-
}
|
|
109
|
-
const safeState = sanitizeCropperState( state );
|
|
110
|
-
const aspectRatio = imageSize.width / imageSize.height;
|
|
111
|
-
return Math.max(
|
|
112
|
-
ABSOLUTE_MIN_ZOOM,
|
|
113
|
-
getMinZoomForCover(
|
|
114
|
-
safeState.rotation,
|
|
115
|
-
aspectRatio,
|
|
116
|
-
safeState.cropRect
|
|
117
|
-
)
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Compute the crop handle bounds in normalized visual space — the
|
|
123
|
-
* axis-aligned bounding box (AABB) of the actual image footprint at the
|
|
124
|
-
* current pan/zoom/rotation.
|
|
125
|
-
*
|
|
126
|
-
* Returns the full image AABB without intersecting with the container
|
|
127
|
-
* viewport. The viewport pan mechanism in the Cropper component allows
|
|
128
|
-
* the canvas to scroll so handles can reach the image edge even when it
|
|
129
|
-
* lies outside the visible canvas area.
|
|
130
|
-
*
|
|
131
|
-
* Unlike a static centerline-based calculation, this accounts for the
|
|
132
|
-
* current pan position — if the user pans right, the left bound tightens
|
|
133
|
-
* because the image's left edge has moved right.
|
|
134
|
-
*
|
|
135
|
-
* @param state The current cropper state (crop, zoom, rotation, flip).
|
|
136
|
-
* @param elementSize The fitted (unrotated) image element dimensions in pixels.
|
|
137
|
-
* @param visualSize The visual (rotated) image bounding box in pixels.
|
|
138
|
-
* @return The min/max x and y that a crop rect edge can reach in normalized space.
|
|
139
|
-
*/
|
|
140
|
-
export function getImageCropBounds(
|
|
141
|
-
state: CropperState,
|
|
142
|
-
elementSize: Size,
|
|
143
|
-
visualSize: Size
|
|
144
|
-
): { minX: number; minY: number; maxX: number; maxY: number } {
|
|
145
|
-
if ( ! isValidSize( elementSize ) || ! isValidSize( visualSize ) ) {
|
|
146
|
-
return { minX: 0, minY: 0, maxX: 1, maxY: 1 };
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const safeState = sanitizeCropperState( state );
|
|
150
|
-
|
|
151
|
-
// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.
|
|
152
|
-
// Flip is outside rotation so it acts in viewport axes (see createCamera).
|
|
153
|
-
const tx = safeState.pan.x * visualSize.width;
|
|
154
|
-
const ty = safeState.pan.y * visualSize.height;
|
|
155
|
-
const rad = degreesToRadians( safeState.rotation );
|
|
156
|
-
const cos = Math.cos( rad );
|
|
157
|
-
const sin = Math.sin( rad );
|
|
158
|
-
const sx = safeState.flip.horizontal ? -1 : 1;
|
|
159
|
-
const sy = safeState.flip.vertical ? -1 : 1;
|
|
160
|
-
const z = safeState.zoom;
|
|
161
|
-
const ma = sx * cos * z;
|
|
162
|
-
const mb = sy * sin * z;
|
|
163
|
-
const mc = -sx * sin * z;
|
|
164
|
-
const md = sy * cos * z;
|
|
165
|
-
|
|
166
|
-
// Image element corners relative to element center.
|
|
167
|
-
const hw = elementSize.width / 2;
|
|
168
|
-
const hh = elementSize.height / 2;
|
|
169
|
-
const corners = [
|
|
170
|
-
[ -hw, -hh ],
|
|
171
|
-
[ hw, -hh ],
|
|
172
|
-
[ hw, hh ],
|
|
173
|
-
[ -hw, hh ],
|
|
174
|
-
];
|
|
175
|
-
|
|
176
|
-
let imgMinX = Infinity;
|
|
177
|
-
let imgMaxX = -Infinity;
|
|
178
|
-
let imgMinY = Infinity;
|
|
179
|
-
let imgMaxY = -Infinity;
|
|
180
|
-
|
|
181
|
-
for ( const [ cx, cy ] of corners ) {
|
|
182
|
-
// Screen offset from element center after CSS matrix.
|
|
183
|
-
const screenX = ma * cx + mc * cy + tx;
|
|
184
|
-
const screenY = mb * cx + md * cy + ty;
|
|
185
|
-
// Convert to normalized visual space.
|
|
186
|
-
// The element center is at the visual image center, which is at
|
|
187
|
-
// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.
|
|
188
|
-
const nx = screenX / visualSize.width + 0.5;
|
|
189
|
-
const ny = screenY / visualSize.height + 0.5;
|
|
190
|
-
imgMinX = Math.min( imgMinX, nx );
|
|
191
|
-
imgMaxX = Math.max( imgMaxX, nx );
|
|
192
|
-
imgMinY = Math.min( imgMinY, ny );
|
|
193
|
-
imgMaxY = Math.max( imgMaxY, ny );
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
minX: imgMinX,
|
|
198
|
-
minY: imgMinY,
|
|
199
|
-
maxX: imgMaxX,
|
|
200
|
-
maxY: imgMaxY,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.
|
|
206
|
-
* If the crop rect is too large for the current zoom and rotation, it is scaled
|
|
207
|
-
* down proportionally and re-centered.
|
|
208
|
-
*
|
|
209
|
-
* Works in pixel-proportional space where the unrotated image is a×1.
|
|
210
|
-
*
|
|
211
|
-
* @param cropRect The crop rectangle in normalized coordinates.
|
|
212
|
-
* @param zoom The current zoom factor.
|
|
213
|
-
* @param rotation The rotation angle in degrees.
|
|
214
|
-
* @param imageAspectRatio The image width / height ratio.
|
|
215
|
-
* @return The restricted crop rectangle.
|
|
216
|
-
*/
|
|
217
|
-
export function restrictCropRect(
|
|
218
|
-
cropRect: NormalizedRect,
|
|
219
|
-
zoom: number,
|
|
220
|
-
rotation: number,
|
|
221
|
-
imageAspectRatio: number
|
|
222
|
-
): NormalizedRect {
|
|
223
|
-
// Guard against non-finite inputs. The reducer normalizes these, but
|
|
224
|
-
// programmatic callers or deserialized state could still send NaN/±Infinity
|
|
225
|
-
// through here, where it would silently propagate into the crop rect.
|
|
226
|
-
const safeRect = sanitizeRect( cropRect );
|
|
227
|
-
const zoomCandidate = safeBoundedNumber( zoom, 1 );
|
|
228
|
-
const safeZoom = zoomCandidate >= Number.EPSILON ? zoomCandidate : 1;
|
|
229
|
-
const safeRotation = safeBoundedNumber( rotation, 0 );
|
|
230
|
-
const safeAspect = safeBoundedNumber( imageAspectRatio, 1 );
|
|
231
|
-
const aspectRatio = Math.max( safeAspect, Number.EPSILON );
|
|
232
|
-
// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil
|
|
233
|
-
// layout); projection into the image-local frame uses the TRUE rotation.
|
|
234
|
-
const snapRotation = Math.round( safeRotation / 90 ) * 90;
|
|
235
|
-
const { visualW, visualH } = getVisualDimensions(
|
|
236
|
-
snapRotation,
|
|
237
|
-
aspectRatio
|
|
238
|
-
);
|
|
239
|
-
const { absC, absS } = getVisualDimensions( safeRotation, aspectRatio );
|
|
240
|
-
const W = safeRect.width;
|
|
241
|
-
const H = safeRect.height;
|
|
242
|
-
|
|
243
|
-
// Crop full-extents in pixel-proportional space, projected to image-local frame.
|
|
244
|
-
const cropWPx = W * visualW;
|
|
245
|
-
const cropHPx = H * visualH;
|
|
246
|
-
const spanAlpha = cropWPx * absC + cropHPx * absS;
|
|
247
|
-
const spanBeta = cropWPx * absS + cropHPx * absC;
|
|
248
|
-
|
|
249
|
-
// Image full-extents at zoom z: (aspectRatio*z, z).
|
|
250
|
-
const limitAlpha = aspectRatio * safeZoom;
|
|
251
|
-
const limitBeta = safeZoom;
|
|
252
|
-
|
|
253
|
-
let t = 1;
|
|
254
|
-
if ( spanAlpha > 0 ) {
|
|
255
|
-
t = Math.min( t, limitAlpha / spanAlpha );
|
|
256
|
-
}
|
|
257
|
-
if ( spanBeta > 0 ) {
|
|
258
|
-
t = Math.min( t, limitBeta / spanBeta );
|
|
259
|
-
}
|
|
260
|
-
if ( t >= 1 - EPSILON ) {
|
|
261
|
-
// Crop fits at the current zoom — no size change needed.
|
|
262
|
-
// Return the sanitized rect (not the raw arg) so non-finite fields
|
|
263
|
-
// don't slip through this path. Position is handled by restrictPanZoom.
|
|
264
|
-
return safeRect;
|
|
265
|
-
}
|
|
266
|
-
const newW = W * t;
|
|
267
|
-
const newH = H * t;
|
|
268
|
-
const centerX = safeRect.x + W / 2;
|
|
269
|
-
const centerY = safeRect.y + H / 2;
|
|
270
|
-
let newX = centerX - newW / 2;
|
|
271
|
-
let newY = centerY - newH / 2;
|
|
272
|
-
newX = Math.max( 0, Math.min( newX, 1 - newW ) );
|
|
273
|
-
newY = Math.max( 0, Math.min( newY, 1 - newH ) );
|
|
274
|
-
return { x: newX, y: newY, width: newW, height: newH };
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Canonical container used internally by restrictPanZoom.
|
|
279
|
-
* Containment is scale-invariant, so the actual size doesn't matter —
|
|
280
|
-
* only the relative geometry between stencil and image matters.
|
|
281
|
-
*/
|
|
282
|
-
const CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };
|
|
283
|
-
|
|
284
|
-
// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on
|
|
285
|
-
// every pointermove) to avoid Float32Array allocation per call.
|
|
286
|
-
const _scratchMat = mat2d.create();
|
|
287
|
-
const _scratchVec = vec2.create();
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers
|
|
291
|
-
* the crop rectangle.
|
|
292
|
-
*
|
|
293
|
-
* Uses the camera matrix to project: builds a camera from the candidate state,
|
|
294
|
-
* maps the stencil corners (axis-aligned in the visual bounding box) to world
|
|
295
|
-
* space via the inverse camera, and checks that all world points lie within
|
|
296
|
-
* [0,1]×[0,1]. If any point is outside, computes the minimal pan correction.
|
|
297
|
-
*
|
|
298
|
-
* @param state The current cropper state.
|
|
299
|
-
* @param imageSize The natural size of the image in pixels.
|
|
300
|
-
* @param cropRect The crop rectangle in normalized coordinates.
|
|
301
|
-
* @return The restricted crop pan and zoom values.
|
|
302
|
-
*/
|
|
303
|
-
export function restrictPanZoom(
|
|
304
|
-
state: CropperState,
|
|
305
|
-
imageSize: Size,
|
|
306
|
-
cropRect: NormalizedRect
|
|
307
|
-
): { pan: { x: number; y: number }; zoom: number } {
|
|
308
|
-
// Algorithm overview:
|
|
309
|
-
// 1. Ensure zoom is high enough for the rotated image to cover the crop.
|
|
310
|
-
// 2. Build a camera (world→screen matrix) with the candidate state.
|
|
311
|
-
// 3. Build a base camera (no pan, zoom=1) to find where the stencil
|
|
312
|
-
// sits in screen space — the stencil is anchored to the container,
|
|
313
|
-
// not the image, so it doesn't move with pan or scale with zoom.
|
|
314
|
-
// 4. Project the 4 stencil corners through the INVERSE of the main
|
|
315
|
-
// camera to get world-space positions. A world point outside [0,1]
|
|
316
|
-
// means that corner of the stencil isn't covered by the image.
|
|
317
|
-
// 5. Compute the minimal translation in world space to push all corners
|
|
318
|
-
// back inside [0,1].
|
|
319
|
-
// 6. Convert the world-space correction to a pan-field correction by
|
|
320
|
-
// mapping it through the camera's linear part back to screen space,
|
|
321
|
-
// then dividing by the visual bounds.
|
|
322
|
-
const safeState = sanitizeCropperState( state );
|
|
323
|
-
const safeCropRect = sanitizeRect( cropRect );
|
|
324
|
-
// Use `isValidSize` rather than a bare `> 0` check so Infinity dims
|
|
325
|
-
// don't drive `Infinity / Infinity = NaN` into `getMinZoomForCover`
|
|
326
|
-
// and leak as `zoom: NaN` through the no-correction early return.
|
|
327
|
-
const aspectRatio = isValidSize( imageSize )
|
|
328
|
-
? imageSize.width / imageSize.height
|
|
329
|
-
: 1;
|
|
330
|
-
const minZoom = Math.max(
|
|
331
|
-
ABSOLUTE_MIN_ZOOM,
|
|
332
|
-
getMinZoomForCover( safeState.rotation, aspectRatio, safeCropRect )
|
|
333
|
-
);
|
|
334
|
-
const zoom = Math.min( MAX_ZOOM, Math.max( safeState.zoom, minZoom ) );
|
|
335
|
-
|
|
336
|
-
// Step 2: build camera with candidate pan and corrected zoom.
|
|
337
|
-
const candidateState = { ...safeState, zoom };
|
|
338
|
-
const camera = createCamera(
|
|
339
|
-
candidateState,
|
|
340
|
-
CANONICAL_CONTAINER,
|
|
341
|
-
imageSize
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
// Build a base camera (zero pan, zoom=1) to get stencil positions.
|
|
345
|
-
// The stencil is anchored to the container and laid out using the
|
|
346
|
-
// nearest 90° rotation (matching `getImageFit`), so it's stable
|
|
347
|
-
// through fine rotation. CSS zoom only affects the <img> element,
|
|
348
|
-
// not the stencil.
|
|
349
|
-
const snapRotation = Math.round( safeState.rotation / 90 ) * 90;
|
|
350
|
-
const baseCamera = createCamera(
|
|
351
|
-
{
|
|
352
|
-
...candidateState,
|
|
353
|
-
pan: { x: 0, y: 0 },
|
|
354
|
-
zoom: 1,
|
|
355
|
-
rotation: snapRotation,
|
|
356
|
-
},
|
|
357
|
-
CANONICAL_CONTAINER,
|
|
358
|
-
imageSize
|
|
359
|
-
);
|
|
360
|
-
const visibleBounds = getVisibleBounds( baseCamera );
|
|
361
|
-
|
|
362
|
-
// Stencil corners in screen space (axis-aligned rect within visual bounds).
|
|
363
|
-
const stencilCorners: [ number, number ][] = [
|
|
364
|
-
[
|
|
365
|
-
visibleBounds.left + safeCropRect.x * visibleBounds.width,
|
|
366
|
-
visibleBounds.top + safeCropRect.y * visibleBounds.height,
|
|
367
|
-
],
|
|
368
|
-
[
|
|
369
|
-
visibleBounds.left +
|
|
370
|
-
( safeCropRect.x + safeCropRect.width ) * visibleBounds.width,
|
|
371
|
-
visibleBounds.top + safeCropRect.y * visibleBounds.height,
|
|
372
|
-
],
|
|
373
|
-
[
|
|
374
|
-
visibleBounds.left +
|
|
375
|
-
( safeCropRect.x + safeCropRect.width ) * visibleBounds.width,
|
|
376
|
-
visibleBounds.top +
|
|
377
|
-
( safeCropRect.y + safeCropRect.height ) * visibleBounds.height,
|
|
378
|
-
],
|
|
379
|
-
[
|
|
380
|
-
visibleBounds.left + safeCropRect.x * visibleBounds.width,
|
|
381
|
-
visibleBounds.top +
|
|
382
|
-
( safeCropRect.y + safeCropRect.height ) * visibleBounds.height,
|
|
383
|
-
],
|
|
384
|
-
];
|
|
385
|
-
|
|
386
|
-
// Map stencil corners to world space via inverse camera.
|
|
387
|
-
// If a world point is outside [0,1], the image doesn't cover that spot.
|
|
388
|
-
// Reuse module-level scratch buffers to avoid allocation per frame.
|
|
389
|
-
mat2d.invert( _scratchMat, camera );
|
|
390
|
-
|
|
391
|
-
let minWx = Infinity;
|
|
392
|
-
let maxWx = -Infinity;
|
|
393
|
-
let minWy = Infinity;
|
|
394
|
-
let maxWy = -Infinity;
|
|
395
|
-
|
|
396
|
-
for ( const corner of stencilCorners ) {
|
|
397
|
-
vec2.transformMat2d( _scratchVec, corner, _scratchMat );
|
|
398
|
-
const w = _scratchVec;
|
|
399
|
-
if ( w[ 0 ] < minWx ) {
|
|
400
|
-
minWx = w[ 0 ];
|
|
401
|
-
}
|
|
402
|
-
if ( w[ 0 ] > maxWx ) {
|
|
403
|
-
maxWx = w[ 0 ];
|
|
404
|
-
}
|
|
405
|
-
if ( w[ 1 ] < minWy ) {
|
|
406
|
-
minWy = w[ 1 ];
|
|
407
|
-
}
|
|
408
|
-
if ( w[ 1 ] > maxWy ) {
|
|
409
|
-
maxWy = w[ 1 ];
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// If all world points are in [0,1], no correction needed.
|
|
414
|
-
if (
|
|
415
|
-
minWx >= -EPSILON &&
|
|
416
|
-
maxWx <= 1 + EPSILON &&
|
|
417
|
-
minWy >= -EPSILON &&
|
|
418
|
-
maxWy <= 1 + EPSILON
|
|
419
|
-
) {
|
|
420
|
-
return { pan: safeState.pan, zoom };
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// Compute world-space correction needed.
|
|
424
|
-
// If minWx < 0, we need to shift world points right by |minWx|.
|
|
425
|
-
// If maxWx > 1, we need to shift world points left by (maxWx - 1).
|
|
426
|
-
// If both, we're over-constrained (crop too big) — getMinZoomForCover
|
|
427
|
-
// should have prevented this.
|
|
428
|
-
let dwx = 0;
|
|
429
|
-
let dwy = 0;
|
|
430
|
-
|
|
431
|
-
if ( minWx < 0 && maxWx <= 1 + EPSILON ) {
|
|
432
|
-
dwx = -minWx;
|
|
433
|
-
} else if ( maxWx > 1 && minWx >= -EPSILON ) {
|
|
434
|
-
dwx = 1 - maxWx;
|
|
435
|
-
} else if ( minWx < 0 && maxWx > 1 ) {
|
|
436
|
-
// Over-constrained: center it.
|
|
437
|
-
dwx = ( 1 - maxWx - minWx ) / 2;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
if ( minWy < 0 && maxWy <= 1 + EPSILON ) {
|
|
441
|
-
dwy = -minWy;
|
|
442
|
-
} else if ( maxWy > 1 && minWy >= -EPSILON ) {
|
|
443
|
-
dwy = 1 - maxWy;
|
|
444
|
-
} else if ( minWy < 0 && maxWy > 1 ) {
|
|
445
|
-
dwy = ( 1 - maxWy - minWy ) / 2;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// Convert world-space correction to screen-space correction.
|
|
449
|
-
// The camera's 2×2 linear part (indices [0,1,2,3]) maps world deltas
|
|
450
|
-
// to screen deltas: screenDelta = linear * worldDelta.
|
|
451
|
-
const dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;
|
|
452
|
-
const dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;
|
|
453
|
-
|
|
454
|
-
// Convert screen-space correction to pan-field correction.
|
|
455
|
-
// Pan in screen pixels = pan.x * visualW, pan.y * visualH.
|
|
456
|
-
// The correction is subtractive: a positive world shift (dw > 0) means
|
|
457
|
-
// the image needs to move opposite to pan direction, so pan decreases.
|
|
458
|
-
const newPanX =
|
|
459
|
-
safeState.pan.x -
|
|
460
|
-
( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );
|
|
461
|
-
const newPanY =
|
|
462
|
-
safeState.pan.y -
|
|
463
|
-
( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );
|
|
464
|
-
|
|
465
|
-
return {
|
|
466
|
-
pan: { x: newPanX, y: newPanY },
|
|
467
|
-
zoom,
|
|
468
|
-
};
|
|
469
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { NormalizedRect, Size } from './types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Largest rect of the given pixel aspect ratio that fits inside the
|
|
5
|
-
* visual bounds, centered in [0,1] × [0,1] normalized space. Returns
|
|
6
|
-
* a full-frame rect (1×1) if `aspectRatio` is unset or non-positive.
|
|
7
|
-
*
|
|
8
|
-
* The returned rect is the same in either freeform or fixed-crop
|
|
9
|
-
* mode — it's the canonical "centered crop for this ratio at this
|
|
10
|
-
* canvas size".
|
|
11
|
-
*
|
|
12
|
-
* @param aspectRatio Desired pixel width/height ratio. `undefined`
|
|
13
|
-
* (or 0/negative) means no lock — returns full frame.
|
|
14
|
-
* @param visualSize Rendered image dimensions in pixels.
|
|
15
|
-
*/
|
|
16
|
-
export function computeInscribedRect(
|
|
17
|
-
aspectRatio: number | undefined,
|
|
18
|
-
visualSize: Size
|
|
19
|
-
): NormalizedRect {
|
|
20
|
-
let w = 1;
|
|
21
|
-
let h = 1;
|
|
22
|
-
if ( aspectRatio && aspectRatio > 0 && visualSize.width > 0 ) {
|
|
23
|
-
// normalizedRatio = w/h in normalized space that produces the
|
|
24
|
-
// desired pixel aspect ratio.
|
|
25
|
-
// pixelW = w * visualW, pixelH = h * visualH
|
|
26
|
-
// pixelW / pixelH = aspectRatio
|
|
27
|
-
// => w / h = aspectRatio * visualH / visualW
|
|
28
|
-
const normalizedRatio =
|
|
29
|
-
( aspectRatio * visualSize.height ) / visualSize.width;
|
|
30
|
-
if ( normalizedRatio <= 1 ) {
|
|
31
|
-
w = normalizedRatio;
|
|
32
|
-
} else {
|
|
33
|
-
h = 1 / normalizedRatio;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
x: ( 1 - w ) / 2,
|
|
38
|
-
y: ( 1 - h ) / 2,
|
|
39
|
-
width: w,
|
|
40
|
-
height: h,
|
|
41
|
-
};
|
|
42
|
-
}
|