@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,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes a rotation value to the range [0, 360).
|
|
3
|
-
*
|
|
4
|
-
* Negative rotations are converted to their positive clockwise equivalent.
|
|
5
|
-
* For example, -90 becomes 270, -45 becomes 315, and 450 becomes 90.
|
|
6
|
-
*
|
|
7
|
-
* @param degrees The rotation value in degrees.
|
|
8
|
-
* @return The normalized rotation in the range [0, 360).
|
|
9
|
-
*/
|
|
10
|
-
export function normalizeRotation( degrees: number ): number {
|
|
11
|
-
if ( degrees >= 0 ) {
|
|
12
|
-
return degrees % 360;
|
|
13
|
-
}
|
|
14
|
-
// For negative rotations, convert to positive clockwise equivalent.
|
|
15
|
-
return ( 360 + ( degrees % 360 ) ) % 360;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Converts an angle from degrees to radians.
|
|
20
|
-
*
|
|
21
|
-
* @param degrees The angle in degrees.
|
|
22
|
-
* @return The angle in radians.
|
|
23
|
-
*/
|
|
24
|
-
export function degreesToRadians( degrees: number ): number {
|
|
25
|
-
return ( degrees * Math.PI ) / 180;
|
|
26
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import type { CropperState, NormalizedRect, Size } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Magnitude beyond which any cropper-math input is treated as corrupt.
|
|
5
|
-
* Picks a value well above any realistic image/rotation/zoom/pan but far
|
|
6
|
-
* below `Number.MAX_VALUE`, so multiplications inside trig and matrix code
|
|
7
|
-
* can't overflow to `Infinity`.
|
|
8
|
-
*/
|
|
9
|
-
const MAX_SAFE_MAGNITUDE = 1e6;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Returns `value` if it's finite and within `[-MAX_SAFE_MAGNITUDE,
|
|
13
|
-
* MAX_SAFE_MAGNITUDE]`, otherwise `fallback`. Stricter than `Number.isFinite`
|
|
14
|
-
* because extreme finite magnitudes (e.g. `Number.MAX_VALUE`) overflow
|
|
15
|
-
* downstream trig/matrix math even though the spec reports them as finite.
|
|
16
|
-
*
|
|
17
|
-
* Note: sub-normal denormals (e.g. `Number.MIN_VALUE`) are accepted by this
|
|
18
|
-
* function — they don't overflow on their own. Protection against divisions
|
|
19
|
-
* by sub-normal values lives in `sanitizeCropperState`'s zoom guard.
|
|
20
|
-
*
|
|
21
|
-
* @param value The candidate value.
|
|
22
|
-
* @param fallback The replacement to return when `value` is unsafe.
|
|
23
|
-
* @return Either `value` or `fallback`.
|
|
24
|
-
*/
|
|
25
|
-
export function safeBoundedNumber( value: number, fallback: number ): number {
|
|
26
|
-
if ( ! Number.isFinite( value ) ) {
|
|
27
|
-
return fallback;
|
|
28
|
-
}
|
|
29
|
-
if ( Math.abs( value ) > MAX_SAFE_MAGNITUDE ) {
|
|
30
|
-
return fallback;
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Returns `true` when `value` is finite and within `[-MAX_SAFE_MAGNITUDE,
|
|
37
|
-
* MAX_SAFE_MAGNITUDE]`. The predicate companion to {@link safeBoundedNumber}
|
|
38
|
-
* for callers that need to short-circuit rather than substitute a fallback.
|
|
39
|
-
*
|
|
40
|
-
* @param value The candidate value.
|
|
41
|
-
* @return Whether `value` is safe to use in math.
|
|
42
|
-
*/
|
|
43
|
-
export function isSafeNumber( value: number ): boolean {
|
|
44
|
-
return Number.isFinite( value ) && Math.abs( value ) <= MAX_SAFE_MAGNITUDE;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Returns `true` when both dimensions are finite and within the safe
|
|
49
|
-
* range `[Number.EPSILON, MAX_SAFE_MAGNITUDE]`. The lower bound matters
|
|
50
|
-
* because sub-normal dimensions (e.g. `Number.MIN_VALUE`) pass `> 0` but
|
|
51
|
-
* make `container / dim` overflow to `Infinity` downstream in
|
|
52
|
-
* `getImageFit` / `createCamera`. Use this to short-circuit math that
|
|
53
|
-
* would otherwise produce non-finite output.
|
|
54
|
-
*
|
|
55
|
-
* @param size The size to check.
|
|
56
|
-
* @return Whether `size` is safe to use in math.
|
|
57
|
-
*/
|
|
58
|
-
export function isValidSize( size: Size ): boolean {
|
|
59
|
-
return (
|
|
60
|
-
Number.isFinite( size.width ) &&
|
|
61
|
-
Number.isFinite( size.height ) &&
|
|
62
|
-
size.width >= Number.EPSILON &&
|
|
63
|
-
size.height >= Number.EPSILON &&
|
|
64
|
-
size.width <= MAX_SAFE_MAGNITUDE &&
|
|
65
|
-
size.height <= MAX_SAFE_MAGNITUDE
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Returns a copy of `rect` with every numeric field replaced by a safe
|
|
71
|
-
* value via {@link safeBoundedNumber}. Returns the same reference when no
|
|
72
|
-
* field needed substitution so callers can keep their reference-equality
|
|
73
|
-
* short-circuits intact for clean inputs.
|
|
74
|
-
*
|
|
75
|
-
* @param rect The rect to sanitize.
|
|
76
|
-
* @return A rect with all numeric fields finite.
|
|
77
|
-
*/
|
|
78
|
-
export function sanitizeRect( rect: NormalizedRect ): NormalizedRect {
|
|
79
|
-
const x = safeBoundedNumber( rect.x, 0 );
|
|
80
|
-
const y = safeBoundedNumber( rect.y, 0 );
|
|
81
|
-
const width = safeBoundedNumber( rect.width, 0 );
|
|
82
|
-
const height = safeBoundedNumber( rect.height, 0 );
|
|
83
|
-
if (
|
|
84
|
-
x === rect.x &&
|
|
85
|
-
y === rect.y &&
|
|
86
|
-
width === rect.width &&
|
|
87
|
-
height === rect.height
|
|
88
|
-
) {
|
|
89
|
-
return rect;
|
|
90
|
-
}
|
|
91
|
-
return { x, y, width, height };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Returns a copy of `state` with the cropper-math numeric fields replaced
|
|
96
|
-
* by safe defaults. Covers `pan`, `zoom`, `rotation`, the matching base
|
|
97
|
-
* pose, and `cropRect`. The `state.image` numeric fields (naturalWidth /
|
|
98
|
-
* naturalHeight) are intentionally NOT sanitized — image dimensions reach
|
|
99
|
-
* the math layer as a separate `imageSize` argument, and cloning the
|
|
100
|
-
* image object here would break the reducer's reference-equality
|
|
101
|
-
* short-circuit.
|
|
102
|
-
*
|
|
103
|
-
* Returns the same `state` reference when no field needed substitution
|
|
104
|
-
* so callers in hot paths (every pointermove via `restrictPanZoom`) can
|
|
105
|
-
* keep their reference-equality optimizations. Sub-object references
|
|
106
|
-
* (`pan`, `basePan`, `cropRect`) are also preserved when their fields
|
|
107
|
-
* are individually clean.
|
|
108
|
-
*
|
|
109
|
-
* @param state The cropper state to sanitize.
|
|
110
|
-
* @return A cropper state with the math-relevant numeric fields finite.
|
|
111
|
-
*/
|
|
112
|
-
export function sanitizeCropperState( state: CropperState ): CropperState {
|
|
113
|
-
const panX = safeBoundedNumber( state.pan.x, 0 );
|
|
114
|
-
const panY = safeBoundedNumber( state.pan.y, 0 );
|
|
115
|
-
const basePanX = safeBoundedNumber( state.basePan.x, 0 );
|
|
116
|
-
const basePanY = safeBoundedNumber( state.basePan.y, 0 );
|
|
117
|
-
const rotation = safeBoundedNumber( state.rotation, 0 );
|
|
118
|
-
const baseRotation = safeBoundedNumber( state.baseRotation, 0 );
|
|
119
|
-
const rawZoom = safeBoundedNumber( state.zoom, 1 );
|
|
120
|
-
// Zoom must be strictly positive AND large enough that 1/zoom doesn't
|
|
121
|
-
// overflow. Sub-normals (e.g. Number.MIN_VALUE) pass `> 0` but make
|
|
122
|
-
// division explode, so guard against them with Number.EPSILON.
|
|
123
|
-
const zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;
|
|
124
|
-
const rawBaseZoom = safeBoundedNumber( state.baseZoom, 1 );
|
|
125
|
-
const baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;
|
|
126
|
-
const cropRect = sanitizeRect( state.cropRect );
|
|
127
|
-
|
|
128
|
-
const panUnchanged = panX === state.pan.x && panY === state.pan.y;
|
|
129
|
-
const basePanUnchanged =
|
|
130
|
-
basePanX === state.basePan.x && basePanY === state.basePan.y;
|
|
131
|
-
|
|
132
|
-
if (
|
|
133
|
-
panUnchanged &&
|
|
134
|
-
basePanUnchanged &&
|
|
135
|
-
zoom === state.zoom &&
|
|
136
|
-
baseZoom === state.baseZoom &&
|
|
137
|
-
rotation === state.rotation &&
|
|
138
|
-
baseRotation === state.baseRotation &&
|
|
139
|
-
cropRect === state.cropRect
|
|
140
|
-
) {
|
|
141
|
-
return state;
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
...state,
|
|
145
|
-
pan: panUnchanged ? state.pan : { x: panX, y: panY },
|
|
146
|
-
zoom,
|
|
147
|
-
rotation,
|
|
148
|
-
basePan: basePanUnchanged
|
|
149
|
-
? state.basePan
|
|
150
|
-
: { x: basePanX, y: basePanY },
|
|
151
|
-
baseZoom,
|
|
152
|
-
baseRotation,
|
|
153
|
-
cropRect,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { CropperState, NormalizedPoint, CropperAction } from './types';
|
|
2
|
-
import { MAX_ZOOM } from './constants';
|
|
3
|
-
import { getMinZoom, restrictPanZoom } from './containment';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Build the reducer action that produces a "cursorless" zoom — zoom
|
|
7
|
-
* anchored at the current crop-rect center, with pan clamped to keep
|
|
8
|
-
* the image covering the crop.
|
|
9
|
-
*
|
|
10
|
-
* The slider, the `+`/`-` keys, and the toolbar buttons have no
|
|
11
|
-
* natural focal point (unlike wheel/pinch zoom), so they default to
|
|
12
|
-
* the crop center. Returns `null` when the clamped zoom matches the
|
|
13
|
-
* current zoom (no-op).
|
|
14
|
-
*
|
|
15
|
-
* Extracted so multiple hooks (the pure `useCropperController` and the
|
|
16
|
-
* composite `useMediaEditorState`) can share the math without
|
|
17
|
-
* duplicating it.
|
|
18
|
-
*
|
|
19
|
-
* @param state The current cropper state.
|
|
20
|
-
* @param requestedZoom The zoom value the caller asked for.
|
|
21
|
-
* @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.
|
|
22
|
-
*/
|
|
23
|
-
export function buildFocalPointZoomAction(
|
|
24
|
-
state: CropperState,
|
|
25
|
-
requestedZoom: number
|
|
26
|
-
): CropperAction | null {
|
|
27
|
-
const clampedZoom = Math.min(
|
|
28
|
-
MAX_ZOOM,
|
|
29
|
-
Math.max( getMinZoom( state ), requestedZoom )
|
|
30
|
-
);
|
|
31
|
-
if ( clampedZoom === state.zoom ) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
// Crop center expressed in the same coord system as `state.pan`:
|
|
35
|
-
// container-center-relative, normalized by image rendered size.
|
|
36
|
-
// `cropRect` is image-top-left-origin (0–1), so subtract 0.5
|
|
37
|
-
// to recenter.
|
|
38
|
-
const { cropRect } = state;
|
|
39
|
-
const focalNormX = cropRect.x + cropRect.width / 2 - 0.5;
|
|
40
|
-
const focalNormY = cropRect.y + cropRect.height / 2 - 0.5;
|
|
41
|
-
const zoomRatio = 1 - clampedZoom / state.zoom;
|
|
42
|
-
const newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;
|
|
43
|
-
const newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;
|
|
44
|
-
const imageSize: { width: number; height: number } = state.image
|
|
45
|
-
? {
|
|
46
|
-
width: state.image.naturalWidth,
|
|
47
|
-
height: state.image.naturalHeight,
|
|
48
|
-
}
|
|
49
|
-
: { width: 1, height: 1 };
|
|
50
|
-
const { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(
|
|
51
|
-
{
|
|
52
|
-
...state,
|
|
53
|
-
zoom: clampedZoom,
|
|
54
|
-
pan: { x: newPanX, y: newPanY },
|
|
55
|
-
},
|
|
56
|
-
imageSize,
|
|
57
|
-
state.cropRect
|
|
58
|
-
);
|
|
59
|
-
return {
|
|
60
|
-
type: 'SET_ZOOM_AT_POINT',
|
|
61
|
-
payload: { zoom: clampedZoom, pan: clampedPan },
|
|
62
|
-
};
|
|
63
|
-
}
|
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import { mat2d, vec2 } from 'gl-matrix';
|
|
2
|
-
import type {
|
|
3
|
-
CropperState,
|
|
4
|
-
HandlePosition,
|
|
5
|
-
NormalizedRect,
|
|
6
|
-
Size,
|
|
7
|
-
} from './types';
|
|
8
|
-
import { createCamera, getRotatedBBox, getVisibleBounds } from './camera';
|
|
9
|
-
import { isValidSize, sanitizeCropperState } from './math/sanitize';
|
|
10
|
-
import { normalizeRotation } from './math/rotation';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The selected image region in source-pixel coordinates.
|
|
14
|
-
*/
|
|
15
|
-
export interface SourceRegion {
|
|
16
|
-
/** X offset in source pixels. */
|
|
17
|
-
x: number;
|
|
18
|
-
/** Y offset in source pixels. */
|
|
19
|
-
y: number;
|
|
20
|
-
/** Width in source pixels. */
|
|
21
|
-
width: number;
|
|
22
|
-
/** Height in source pixels. */
|
|
23
|
-
height: number;
|
|
24
|
-
/** Rotation in degrees (0-360). */
|
|
25
|
-
rotation: number;
|
|
26
|
-
/** Flip state. */
|
|
27
|
-
flip: { horizontal: boolean; vertical: boolean };
|
|
28
|
-
/** Zoom factor applied. */
|
|
29
|
-
zoom: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Get the selected image region in source-pixel coordinates.
|
|
34
|
-
*
|
|
35
|
-
* Converts the current crop state (normalized visual space) to the actual
|
|
36
|
-
* region of the original image that's selected. This is the bridge between
|
|
37
|
-
* the cropper's internal coordinate system and external tools (image
|
|
38
|
-
* processing libraries, AI APIs, server-side processing) that work in
|
|
39
|
-
* source-pixel coordinates.
|
|
40
|
-
*
|
|
41
|
-
* The returned rectangle accounts for pan, zoom, and the crop rect position,
|
|
42
|
-
* but expresses the crop in the unrotated image's coordinate space. Rotation
|
|
43
|
-
* and flip are included as separate fields since they represent transforms,
|
|
44
|
-
* not a region.
|
|
45
|
-
*
|
|
46
|
-
* @param state The current cropper state.
|
|
47
|
-
* @param imageSize The natural dimensions of the source image.
|
|
48
|
-
* @return The selected region in source pixels plus rotation/flip metadata.
|
|
49
|
-
*/
|
|
50
|
-
export function getSourceRegion(
|
|
51
|
-
state: CropperState,
|
|
52
|
-
imageSize: Size
|
|
53
|
-
): SourceRegion {
|
|
54
|
-
// Sanitize before the zero-size short-circuit so the early return
|
|
55
|
-
// doesn't leak raw non-finite state.rotation or state.zoom out
|
|
56
|
-
// through the metadata fields. (state.flip is boolean and isn't
|
|
57
|
-
// at risk of NaN propagation.)
|
|
58
|
-
const safeState = sanitizeCropperState( state );
|
|
59
|
-
|
|
60
|
-
if ( ! isValidSize( imageSize ) ) {
|
|
61
|
-
return {
|
|
62
|
-
x: 0,
|
|
63
|
-
y: 0,
|
|
64
|
-
width: 0,
|
|
65
|
-
height: 0,
|
|
66
|
-
rotation: safeState.rotation,
|
|
67
|
-
flip: { ...safeState.flip },
|
|
68
|
-
zoom: safeState.zoom,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Use a synthetic 1:1 container so the camera maps normalized coords
|
|
73
|
-
// to a known pixel space. The container size cancels out.
|
|
74
|
-
const syntheticContainer: Size = { width: 1000, height: 1000 };
|
|
75
|
-
const camera = createCamera( safeState, syntheticContainer, imageSize );
|
|
76
|
-
|
|
77
|
-
// Inverse camera maps screen pixels back to normalized [0,1] world coords.
|
|
78
|
-
const inv = mat2d.create();
|
|
79
|
-
mat2d.invert( inv, camera );
|
|
80
|
-
|
|
81
|
-
// The crop rect center in screen space. We need the base camera
|
|
82
|
-
// (zoom=1, no pan) to locate the visual bounds, then place the
|
|
83
|
-
// crop rect within them.
|
|
84
|
-
const baseCamera = createCamera(
|
|
85
|
-
{ ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },
|
|
86
|
-
syntheticContainer,
|
|
87
|
-
imageSize
|
|
88
|
-
);
|
|
89
|
-
const visibleBounds = getVisibleBounds( baseCamera );
|
|
90
|
-
|
|
91
|
-
const cropRect = safeState.cropRect;
|
|
92
|
-
const cropCenterScreenX =
|
|
93
|
-
visibleBounds.left +
|
|
94
|
-
( cropRect.x + cropRect.width / 2 ) * visibleBounds.width;
|
|
95
|
-
const cropCenterScreenY =
|
|
96
|
-
visibleBounds.top +
|
|
97
|
-
( cropRect.y + cropRect.height / 2 ) * visibleBounds.height;
|
|
98
|
-
|
|
99
|
-
// Transform crop center through inverse camera to get source position.
|
|
100
|
-
const srcCenter = vec2.create();
|
|
101
|
-
vec2.transformMat2d(
|
|
102
|
-
srcCenter,
|
|
103
|
-
[ cropCenterScreenX, cropCenterScreenY ],
|
|
104
|
-
inv
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
// Crop rect size in the snap-rotation visual space, divided by zoom
|
|
108
|
-
// for source-pixel dimensions. Matches the stencil's reference frame.
|
|
109
|
-
const snapRotation = Math.round( safeState.rotation / 90 ) * 90;
|
|
110
|
-
const { width: rotW, height: rotH } = getRotatedBBox(
|
|
111
|
-
imageSize.width,
|
|
112
|
-
imageSize.height,
|
|
113
|
-
snapRotation
|
|
114
|
-
);
|
|
115
|
-
const sourceW = ( cropRect.width * rotW ) / safeState.zoom;
|
|
116
|
-
const sourceH = ( cropRect.height * rotH ) / safeState.zoom;
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
x: srcCenter[ 0 ] * imageSize.width - sourceW / 2,
|
|
120
|
-
y: srcCenter[ 1 ] * imageSize.height - sourceH / 2,
|
|
121
|
-
width: sourceW,
|
|
122
|
-
height: sourceH,
|
|
123
|
-
rotation: safeState.rotation,
|
|
124
|
-
flip: { ...safeState.flip },
|
|
125
|
-
zoom: safeState.zoom,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Convert a source-pixel region back to the cropper's normalized crop rect.
|
|
131
|
-
*
|
|
132
|
-
* The math intentionally mirrors `getSourceRegion`: map the requested source
|
|
133
|
-
* center through the current camera, then express that screen point inside the
|
|
134
|
-
* same base visible bounds used to position crop overlays.
|
|
135
|
-
*
|
|
136
|
-
* @param state The current cropper state.
|
|
137
|
-
* @param imageSize The natural dimensions of the source image.
|
|
138
|
-
* @param region The source-pixel region to represent as a crop rect.
|
|
139
|
-
* @return The normalized crop rect, or null when inputs cannot be mapped.
|
|
140
|
-
*/
|
|
141
|
-
function getCropRectFromSourceRegion(
|
|
142
|
-
state: CropperState,
|
|
143
|
-
imageSize: Size,
|
|
144
|
-
region: SourceRegion
|
|
145
|
-
): NormalizedRect | null {
|
|
146
|
-
if (
|
|
147
|
-
! isValidSize( imageSize ) ||
|
|
148
|
-
region.width <= 0 ||
|
|
149
|
-
region.height <= 0
|
|
150
|
-
) {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const safeState = sanitizeCropperState( state );
|
|
155
|
-
const syntheticContainer: Size = { width: 1000, height: 1000 };
|
|
156
|
-
const baseCamera = createCamera(
|
|
157
|
-
{ ...safeState, pan: { x: 0, y: 0 }, zoom: 1 },
|
|
158
|
-
syntheticContainer,
|
|
159
|
-
imageSize
|
|
160
|
-
);
|
|
161
|
-
const visibleBounds = getVisibleBounds( baseCamera );
|
|
162
|
-
if ( visibleBounds.width <= 0 || visibleBounds.height <= 0 ) {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const sourceCenter = vec2.fromValues(
|
|
167
|
-
( region.x + region.width / 2 ) / imageSize.width,
|
|
168
|
-
( region.y + region.height / 2 ) / imageSize.height
|
|
169
|
-
);
|
|
170
|
-
const screenCenter = vec2.create();
|
|
171
|
-
const camera = createCamera( safeState, syntheticContainer, imageSize );
|
|
172
|
-
vec2.transformMat2d( screenCenter, sourceCenter, camera );
|
|
173
|
-
|
|
174
|
-
const snapRotation = Math.round( safeState.rotation / 90 ) * 90;
|
|
175
|
-
const { width: rotW, height: rotH } = getRotatedBBox(
|
|
176
|
-
imageSize.width,
|
|
177
|
-
imageSize.height,
|
|
178
|
-
snapRotation
|
|
179
|
-
);
|
|
180
|
-
if ( rotW <= 0 || rotH <= 0 ) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const width = ( region.width * safeState.zoom ) / rotW;
|
|
185
|
-
const height = ( region.height * safeState.zoom ) / rotH;
|
|
186
|
-
const centerX =
|
|
187
|
-
( screenCenter[ 0 ] - visibleBounds.left ) / visibleBounds.width;
|
|
188
|
-
const centerY =
|
|
189
|
-
( screenCenter[ 1 ] - visibleBounds.top ) / visibleBounds.height;
|
|
190
|
-
|
|
191
|
-
return {
|
|
192
|
-
x: centerX - width / 2,
|
|
193
|
-
y: centerY - height / 2,
|
|
194
|
-
width,
|
|
195
|
-
height,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
interface SourcePixelSnapEdges {
|
|
200
|
-
left: boolean;
|
|
201
|
-
top: boolean;
|
|
202
|
-
right: boolean;
|
|
203
|
-
bottom: boolean;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const CARDINAL_ROTATION_EPSILON = 1e-6;
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Check whether a rotation is effectively at a 90-degree stop.
|
|
210
|
-
*
|
|
211
|
-
* @param rotation The rotation angle in degrees.
|
|
212
|
-
* @return Whether the rotation is close enough to a cardinal angle.
|
|
213
|
-
*/
|
|
214
|
-
function isCardinalRotation( rotation: number ): boolean {
|
|
215
|
-
const normalizedRotation = normalizeRotation( rotation );
|
|
216
|
-
const nearestCardinal = Math.round( normalizedRotation / 90 ) * 90;
|
|
217
|
-
return (
|
|
218
|
-
Math.abs( normalizedRotation - nearestCardinal ) <
|
|
219
|
-
CARDINAL_ROTATION_EPSILON
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Snap a crop rect so the selected source-region edges land on whole pixels.
|
|
225
|
-
*
|
|
226
|
-
* This is a display-time affordance for visible pixel grids; it does not alter
|
|
227
|
-
* pan/zoom/rotation. Callers decide when snapping is appropriate.
|
|
228
|
-
*
|
|
229
|
-
* @param state The current cropper state.
|
|
230
|
-
* @param imageSize The natural dimensions of the source image.
|
|
231
|
-
* @param cropRect The candidate crop rect from resize math.
|
|
232
|
-
* @param handle The active resize handle. Only edges moved by the handle snap.
|
|
233
|
-
* @return A crop rect whose selected source-region edges are whole pixels.
|
|
234
|
-
*/
|
|
235
|
-
export function snapCropRectToSourcePixels(
|
|
236
|
-
state: CropperState,
|
|
237
|
-
imageSize: Size,
|
|
238
|
-
cropRect: NormalizedRect,
|
|
239
|
-
handle: HandlePosition
|
|
240
|
-
): NormalizedRect {
|
|
241
|
-
const safeState = sanitizeCropperState( state );
|
|
242
|
-
if ( ! isCardinalRotation( safeState.rotation ) ) {
|
|
243
|
-
return cropRect;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return snapCropRectEdgesToSourcePixels( safeState, imageSize, cropRect, {
|
|
247
|
-
left: handle.includes( 'w' ),
|
|
248
|
-
top: handle.includes( 'n' ),
|
|
249
|
-
right: handle.includes( 'e' ),
|
|
250
|
-
bottom: handle.includes( 's' ),
|
|
251
|
-
} );
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Snap all source-region edges for a crop rect to the nearest whole pixels.
|
|
256
|
-
*
|
|
257
|
-
* @param state The current cropper state.
|
|
258
|
-
* @param imageSize The natural dimensions of the source image.
|
|
259
|
-
* @param cropRect The crop rect to align to the source-pixel grid.
|
|
260
|
-
* @return A crop rect whose source-region edges are whole pixels.
|
|
261
|
-
*/
|
|
262
|
-
export function snapCropRectToSourcePixelGrid(
|
|
263
|
-
state: CropperState,
|
|
264
|
-
imageSize: Size,
|
|
265
|
-
cropRect: NormalizedRect
|
|
266
|
-
): NormalizedRect {
|
|
267
|
-
return snapCropRectEdgesToSourcePixels( state, imageSize, cropRect, {
|
|
268
|
-
left: true,
|
|
269
|
-
top: true,
|
|
270
|
-
right: true,
|
|
271
|
-
bottom: true,
|
|
272
|
-
} );
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function snapCropRectEdgesToSourcePixels(
|
|
276
|
-
state: CropperState,
|
|
277
|
-
imageSize: Size,
|
|
278
|
-
cropRect: NormalizedRect,
|
|
279
|
-
edges: SourcePixelSnapEdges
|
|
280
|
-
): NormalizedRect {
|
|
281
|
-
if ( ! isValidSize( imageSize ) ) {
|
|
282
|
-
return cropRect;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const stateWithCrop = sanitizeCropperState( { ...state, cropRect } );
|
|
286
|
-
const region = getSourceRegion( stateWithCrop, imageSize );
|
|
287
|
-
const shouldSnapX = edges.left || edges.right;
|
|
288
|
-
const shouldSnapY = edges.top || edges.bottom;
|
|
289
|
-
const left = edges.left ? Math.round( region.x ) : region.x;
|
|
290
|
-
const top = edges.top ? Math.round( region.y ) : region.y;
|
|
291
|
-
const right = edges.right
|
|
292
|
-
? Math.round( region.x + region.width )
|
|
293
|
-
: region.x + region.width;
|
|
294
|
-
const bottom = edges.bottom
|
|
295
|
-
? Math.round( region.y + region.height )
|
|
296
|
-
: region.y + region.height;
|
|
297
|
-
if ( right <= left || bottom <= top ) {
|
|
298
|
-
return cropRect;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const snappedCropRect = getCropRectFromSourceRegion(
|
|
302
|
-
stateWithCrop,
|
|
303
|
-
imageSize,
|
|
304
|
-
{
|
|
305
|
-
...region,
|
|
306
|
-
x: left,
|
|
307
|
-
y: top,
|
|
308
|
-
width: right - left,
|
|
309
|
-
height: bottom - top,
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
if ( ! snappedCropRect ) {
|
|
313
|
-
return cropRect;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return {
|
|
317
|
-
x: shouldSnapX ? snappedCropRect.x : cropRect.x,
|
|
318
|
-
y: shouldSnapY ? snappedCropRect.y : cropRect.y,
|
|
319
|
-
width: shouldSnapX ? snappedCropRect.width : cropRect.width,
|
|
320
|
-
height: shouldSnapY ? snappedCropRect.height : cropRect.height,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* The selected crop region expressed as percentages of the source image.
|
|
326
|
-
*/
|
|
327
|
-
export interface SourceRegionPercent {
|
|
328
|
-
/** X offset as a percentage (0–100) of the source image width. */
|
|
329
|
-
x: number;
|
|
330
|
-
/** Y offset as a percentage (0–100) of the source image height. */
|
|
331
|
-
y: number;
|
|
332
|
-
/** Width as a percentage (0–100) of the source image width. */
|
|
333
|
-
width: number;
|
|
334
|
-
/** Height as a percentage (0–100) of the source image height. */
|
|
335
|
-
height: number;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Get the selected image region as percentages of the source image dimensions.
|
|
340
|
-
*
|
|
341
|
-
* Returns `{ x, y, width, height }` where each value is a percentage (0–100)
|
|
342
|
-
* of the source image's natural width or height. This format is compatible
|
|
343
|
-
* with the WordPress REST API attachments `/edit` endpoint and CSS-based
|
|
344
|
-
* crop workflows.
|
|
345
|
-
*
|
|
346
|
-
* Internally delegates to `getSourceRegion` and divides by the image
|
|
347
|
-
* dimensions, so accuracy is identical.
|
|
348
|
-
*
|
|
349
|
-
* @param state The current cropper state.
|
|
350
|
-
* @param imageSize The natural dimensions of the source image.
|
|
351
|
-
* @return The crop region as percentages (0–100).
|
|
352
|
-
*/
|
|
353
|
-
export function getSourceRegionPercent(
|
|
354
|
-
state: CropperState,
|
|
355
|
-
imageSize: Size
|
|
356
|
-
): SourceRegionPercent {
|
|
357
|
-
if ( ! isValidSize( imageSize ) ) {
|
|
358
|
-
return { x: 0, y: 0, width: 0, height: 0 };
|
|
359
|
-
}
|
|
360
|
-
const region = getSourceRegion( state, imageSize );
|
|
361
|
-
return {
|
|
362
|
-
x: ( region.x / imageSize.width ) * 100,
|
|
363
|
-
y: ( region.y / imageSize.height ) * 100,
|
|
364
|
-
width: ( region.width / imageSize.width ) * 100,
|
|
365
|
-
height: ( region.height / imageSize.height ) * 100,
|
|
366
|
-
};
|
|
367
|
-
}
|